@ -123,11 +123,39 @@ void KPassivePopup::setView( const TQString &caption, const TQString &text,
setView ( standardView ( caption , text , icon , this ) ) ;
}
TQVBox * KPassivePopup : : standardView ( const TQString & caption ,
static void truncateStringToFit ( TQString & string , TQFont font , int max_width ) {
bool truncated = false ;
TQFontMetrics fm ( font ) ;
while ( fm . width ( string ) > max_width ) {
string . truncate ( string . length ( ) - 1 ) ;
truncated = true ;
}
if ( truncated ) {
string + = " ... " ;
}
}
TQVBox * KPassivePopup : : standardView ( const TQString & caption ,
const TQString & text ,
const TQPixmap & icon ,
TQWidget * parent )
TQWidget * parent )
{
TQString sizedCaption = caption ;
TQString sizedText = text ;
# ifdef Q_WS_X11
int max_width ;
NETRootInfo info ( tqt_xdisplay ( ) ,
NET : : NumberOfDesktops |
NET : : CurrentDesktop |
NET : : WorkArea ,
- 1 , false ) ;
info . activate ( ) ;
NETRect workArea = info . workArea ( info . currentDesktop ( ) ) ;
max_width = workArea . size . width / 3 ;
# endif
TQVBox * vb = new TQVBox ( parent ? parent : this ) ;
vb - > setSpacing ( KDialog : : spacingHint ( ) ) ;
@ -141,18 +169,46 @@ TQVBox * KPassivePopup::standardView( const TQString& caption,
ttlIcon - > setAlignment ( AlignLeft ) ;
}
if ( ! c aption. isEmpty ( ) ) {
ttl = new TQLabel ( c aption, hb ? hb : vb , " title_label " ) ;
if ( ! sizedC aption. isEmpty ( ) ) {
ttl = new TQLabel ( sizedC aption, hb ? hb : vb , " title_label " ) ;
TQFont fnt = ttl - > font ( ) ;
# ifdef Q_WS_X11
truncateStringToFit ( sizedCaption , fnt , max_width ) ;
ttl - > setText ( sizedCaption ) ;
# endif
fnt . setBold ( true ) ;
ttl - > setFont ( fnt ) ;
ttl - > setAlignment ( Qt : : AlignHCenter ) ;
if ( hb )
if ( hb ) {
hb - > setStretchFactor ( ttl , 10 ) ; // enforce centering
}
}
if ( ! text . isEmpty ( ) ) {
msg = new TQLabel ( text , vb , " msg_label " ) ;
if ( ! sizedText . isEmpty ( ) ) {
msg = new TQLabel ( sizedText , vb , " msg_label " ) ;
# ifdef Q_WS_X11
TQStringList textLines = TQStringList : : split ( " \n " , sizedText , true ) ;
for ( TQStringList : : Iterator it = textLines . begin ( ) ; it ! = textLines . end ( ) ; + + it ) {
truncateStringToFit ( * it , msg - > font ( ) , max_width ) ;
}
// Limit message to 5 lines of text
if ( textLines . count ( ) > 5 ) {
int count = 3 ;
TQStringList truncatedLines ;
for ( TQStringList : : Iterator it = textLines . begin ( ) ; it ! = textLines . end ( ) ; + + it ) {
truncatedLines . append ( * it ) ;
if ( count > 5 ) {
truncatedLines . append ( " ... " ) ;
break ;
}
count + + ;
}
textLines = truncatedLines ;
}
sizedText = textLines . join ( " \n " ) ;
msg - > setText ( sizedText ) ;
# endif
msg - > setAlignment ( AlignLeft ) ;
}
@ -194,16 +250,22 @@ void KPassivePopup::mouseReleaseEvent( TQMouseEvent *e )
void KPassivePopup : : show ( )
{
if ( size ( ) ! = sizeHint ( ) )
resize ( sizeHint ( ) ) ;
TQSize desiredSize = sizeHint ( ) ;
if ( d - > fixedPosition . isNull ( ) )
if ( size ( ) ! = desiredSize ) {
resize ( desiredSize ) ;
}
if ( d - > fixedPosition . isNull ( ) ) {
positionSelf ( ) ;
}
else {
if ( d - > popupStyle = = Balloon )
setAnchor ( d - > fixedPosition ) ;
else
move ( d - > fixedPosition ) ;
if ( d - > popupStyle = = Balloon ) {
setAnchor ( d - > fixedPosition ) ;
}
else {
move ( d - > fixedPosition ) ;
}
}
TQFrame : : show ( ) ;
@ -346,13 +408,14 @@ void KPassivePopup::setAnchor(const TQPoint &anchor)
void KPassivePopup : : paintEvent ( TQPaintEvent * pe )
{
if ( d - > popupStyle = = Balloon )
{
if ( d - > popupStyle = = Balloon ) {
TQPainter p ;
p . begin ( this ) ;
p . drawPolygon ( d - > surround ) ;
} else
}
else {
TQFrame : : paintEvent ( pe ) ;
}
}
void KPassivePopup : : updateMask ( )