11 #include <tqapplication.h>
16 #include <tqpainter.h>
17 #include <tqtooltip.h>
19 #include <tqpointarray.h>
24 #include <kpixmapeffect.h>
25 #include <tdeglobalsettings.h>
32 #include "kpassivepopup.h"
33 #include "kpassivepopup.moc"
35 class KPassivePopup::Private
39 TQPointArray surround;
41 TQPoint fixedPosition;
45 static const int DEFAULT_POPUP_TIME = 6*1000;
46 static const int POPUP_FLAGS = TQt::WStyle_Customize | TQt::WDestructiveClose | TQt::WX11BypassWM
47 | TQt::WStyle_StaysOnTop | TQt::WStyle_Tool | TQt::WStyle_NoBorder;
50 : TQFrame( 0, name, (WFlags)(f ? (int)f : POPUP_FLAGS) ),
51 window( parent ? parent->winId() : 0L ), msgView( 0 ), topLayout( 0 ),
52 hideDelay( DEFAULT_POPUP_TIME ), hideTimer( new TQTimer( this,
"hide_timer" ) ),
55 init( DEFAULT_POPUP_TYPE );
59 : TQFrame( 0, name, (WFlags)(f ? (int)f : POPUP_FLAGS) ),
60 window( win ), msgView( 0 ), topLayout( 0 ),
61 hideDelay( DEFAULT_POPUP_TIME ), hideTimer( new TQTimer( this,
"hide_timer" ) ),
64 init( DEFAULT_POPUP_TYPE );
68 : TQFrame( 0, name, (WFlags)(f ? (int)f : POPUP_FLAGS) ),
69 window( parent ? parent->winId() : 0L ), msgView( 0 ), topLayout( 0 ),
70 hideDelay( DEFAULT_POPUP_TIME ), hideTimer( new TQTimer( this,
"hide_timer" ) ),
77 : TQFrame( 0, name, (WFlags)(f ? (int)f : POPUP_FLAGS) ),
78 window( win ), msgView( 0 ), topLayout( 0 ),
79 hideDelay( DEFAULT_POPUP_TIME ), hideTimer( new TQTimer( this,
"hide_timer" ) ),
85 void KPassivePopup::init(
int popupStyle )
88 d->popupStyle = popupStyle;
89 if( popupStyle ==
Boxed )
91 setFrameStyle( TQFrame::Box| TQFrame::Plain );
94 else if( popupStyle ==
Balloon )
96 setPalette(TQToolTip::palette());
99 connect( hideTimer, TQ_SIGNAL(
timeout() ), TQ_SLOT( hide() ) );
100 connect(
this, TQ_SIGNAL(
clicked() ), TQ_SLOT( hide() ) );
115 topLayout->addWidget( msgView );
116 topLayout->activate();
120 const TQPixmap &icon )
126 static void truncateStringToFit(TQString &
string, TQFont font,
int max_width) {
127 bool truncated =
false;
128 TQFontMetrics fm(font);
129 while (fm.width(
string) > max_width) {
130 string.truncate(
string.length() - 1);
139 const TQString& text,
140 const TQPixmap& icon,
143 TQString sizedCaption = caption;
144 TQString sizedText = text;
149 NETRootInfo info( tqt_xdisplay(),
150 NET::NumberOfDesktops |
151 NET::CurrentDesktop |
155 NETRect workArea = info.workArea(info.currentDesktop());
159 TQVBox *vb =
new TQVBox( parent ? parent :
this );
163 if ( !icon.isNull() ) {
164 hb =
new TQHBox( vb );
167 ttlIcon =
new TQLabel( hb,
"title_icon" );
168 ttlIcon->setPixmap( icon );
169 ttlIcon->setAlignment( AlignLeft );
172 if ( !sizedCaption.isEmpty() ) {
173 ttl =
new TQLabel( sizedCaption, hb ? hb : vb,
"title_label" );
174 TQFont fnt = ttl->font();
176 truncateStringToFit(sizedCaption, fnt, max_width);
177 ttl->setText(sizedCaption);
181 ttl->setAlignment( TQt::AlignHCenter );
183 hb->setStretchFactor( ttl, 10 );
187 if ( !sizedText.isEmpty() ) {
188 msg =
new TQLabel( sizedText, vb,
"msg_label" );
190 TQStringList textLines = TQStringList::split(
"\n", sizedText,
true);
191 for (TQStringList::Iterator it = textLines.begin(); it != textLines.end(); ++it) {
192 truncateStringToFit(*it, msg->font(), max_width);
196 if (textLines.count() > 5) {
198 TQStringList truncatedLines;
199 for (TQStringList::Iterator it = textLines.begin(); it != textLines.end(); ++it) {
200 truncatedLines.append(*it);
202 truncatedLines.append(
"...");
207 textLines = truncatedLines;
209 sizedText = textLines.join(
"\n");
210 msg->setText(sizedText);
212 msg->setAlignment( AlignLeft );
220 setView( caption, text, TQPixmap() );
226 if( hideTimer->isActive() )
229 hideTimer->changeInterval( delay );
253 TQSize desiredSize = sizeHint();
255 if (size() != desiredSize) {
259 if (d->fixedPosition.isNull()) {
263 if( d->popupStyle ==
Balloon ) {
267 move(d->fixedPosition);
272 int delay = hideDelay;
274 delay = DEFAULT_POPUP_TIME;
278 hideTimer->start( delay );
284 d->fixedPosition = p;
299 NETRootInfo info( tqt_xdisplay(),
300 NET::NumberOfDesktops |
301 NET::CurrentDesktop |
305 NETRect workArea = info.workArea( info.currentDesktop() );
307 r.setRect( workArea.
pos.
x, workArea.
pos.
y, 0, 0 );
311 r.setRect( 100, 100, 200, 200 );
326 NETWinInfo ni( tqt_xdisplay(), window, tqt_xrootwin(),
327 NET::WMIconGeometry | NET::WMKDESystemTrayWinFor );
331 if ( ni.kdeSystemTrayWinFor() ) {
333 ni.kdeGeometry( frame, win );
334 target.setRect( win.
pos.
x, win.
pos.
y,
337 else if ( ni.state() & NET::SkipTaskbar ) {
343 if ( target.isNull() ) {
345 ni.kdeGeometry( dummy, r );
359 TQPoint pos = target.topLeft();
370 if( x + w > r.width() ){
371 x = x + target.width();
374 if( y + h > r.height() ){
375 y = y + target.height();
379 if ( x < r.center().x() )
380 x = x + target.width();
385 if ( (y + h) > r.bottom() )
388 if ( (x + w) > r.right() )
411 if( d->popupStyle ==
Balloon ) {
414 p.drawPolygon( d->surround );
417 TQFrame::paintEvent( pe );
427 int xh = 70, xl = 40;
430 else if( width() < 110 )
433 bool bottom = (d->anchor.y() + height()) > ((deskRect.y() + deskRect.height()-48));
434 bool right = (d->anchor.x() + width()) > ((deskRect.x() + deskRect.width()-48));
436 TQPoint corners[4] = {
437 TQPoint( width() - 50, 10 ),
439 TQPoint( 10, height() - 50 ),
440 TQPoint( width() - 50, height() - 50 )
443 TQBitmap mask( width(), height(),
true );
444 TQPainter p( &mask );
445 TQBrush brush( TQt::white, TQt::SolidPattern );
451 corner.makeArc(corners[i].x(), corners[i].y(), 40, 40, i * 16 * 90, 16 * 90);
453 d->surround.resize( z + corner.count() );
454 for (
unsigned int s = 0; s < corner.count() - 1; s++) {
455 d->surround.setPoint( z++, corner[s] );
458 if (bottom && i == 2) {
460 d->surround.resize( z + 3 );
461 d->surround.setPoint( z++, TQPoint( width() - xh, height() - 11 ) );
462 d->surround.setPoint( z++, TQPoint( width() - 20, height() ) );
463 d->surround.setPoint( z++, TQPoint( width() - xl, height() - 11 ) );
465 d->surround.resize( z + 3 );
466 d->surround.setPoint( z++, TQPoint( xl, height() - 11 ) );
467 d->surround.setPoint( z++, TQPoint( 20, height() ) );
468 d->surround.setPoint( z++, TQPoint( xh, height() - 11 ) );
470 }
else if (!bottom && i == 0) {
472 d->surround.resize( z + 3 );
473 d->surround.setPoint( z++, TQPoint( width() - xl, 10 ) );
474 d->surround.setPoint( z++, TQPoint( width() - 20, 0 ) );
475 d->surround.setPoint( z++, TQPoint( width() - xh, 10 ) );
477 d->surround.resize( z + 3 );
478 d->surround.setPoint( z++, TQPoint( xh, 10 ) );
479 d->surround.setPoint( z++, TQPoint( 20, 0 ) );
480 d->surround.setPoint( z++, TQPoint( xl, 10 ) );
485 d->surround.resize( z + 1 );
486 d->surround.setPoint( z, d->surround[0] );
487 p.drawPolygon( d->surround );
490 move( right ? d->anchor.x() - width() + 20 : ( d->anchor.x() < 11 ? 11 : d->anchor.x() - 20 ),
491 bottom ? d->anchor.y() - height() : ( d->anchor.y() < 11 ? 11 : d->anchor.y() ) );
501 const TQPixmap &icon,
502 TQWidget *parent,
const char *name,
int timeout )
504 return message( DEFAULT_POPUP_TYPE, caption, text, icon, parent, name,
timeout );
509 return message( DEFAULT_POPUP_TYPE, TQString::null, text, TQPixmap(), parent, name );
513 TQWidget *parent,
const char *name )
515 return message( DEFAULT_POPUP_TYPE, caption, text, TQPixmap(), parent, name );
519 const TQPixmap &icon, WId parent,
const char *name,
int timeout )
521 return message( DEFAULT_POPUP_TYPE, caption, text, icon, parent, name,
timeout );
525 const TQPixmap &icon,
526 TQWidget *parent,
const char *name,
int timeout )
530 pop->
setView( caption, text, icon );
539 return message( popupStyle, TQString::null, text, TQPixmap(), parent, name );
543 TQWidget *parent,
const char *name )
545 return message( popupStyle, caption, text, TQPixmap(), parent, name );
549 const TQPixmap &icon, WId parent,
const char *name,
int timeout )
553 pop->
setView( caption, text, icon );
static int marginHint()
Return the number of pixels you shall use between a dialog edge and the outermost widget(s) according...
static int spacingHint()
Return the number of pixels you shall use between widgets inside a dialog according to the KDE standa...
static TQRect desktopGeometry(const TQPoint &point)