11 #include <tqapplication.h>
16 #include <tqpainter.h>
17 #include <tqtooltip.h>
19 #include <tqpointarray.h>
24 #include <kpixmapeffect.h>
25 #include <kglobalsettings.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, TQT_SIGNAL(
timeout() ), TQT_SLOT( hide() ) );
100 connect(
this, TQT_SIGNAL(
clicked() ), TQT_SLOT( hide() ) );
115 topLayout->addWidget( msgView );
116 topLayout->activate();
120 const TQPixmap &icon )
127 const TQString& text,
128 const TQPixmap& icon,
131 TQVBox *vb =
new TQVBox( parent ? parent :
this );
135 if ( !icon.isNull() ) {
136 hb =
new TQHBox( vb );
139 ttlIcon =
new TQLabel( hb,
"title_icon" );
140 ttlIcon->setPixmap( icon );
141 ttlIcon->setAlignment( AlignLeft );
144 if ( !caption.isEmpty() ) {
145 ttl =
new TQLabel( caption, hb ? hb : vb,
"title_label" );
146 TQFont fnt = ttl->font();
149 ttl->setAlignment( Qt::AlignHCenter );
151 hb->setStretchFactor( ttl, 10 );
154 if ( !text.isEmpty() ) {
155 msg =
new TQLabel( text, vb,
"msg_label" );
156 msg->setAlignment( AlignLeft );
164 setView( caption, text, TQPixmap() );
170 if( hideTimer->isActive() )
173 hideTimer->changeInterval( delay );
197 if ( size() != sizeHint() )
198 resize( sizeHint() );
200 if ( d->fixedPosition.isNull() )
206 move( d->fixedPosition );
210 int delay = hideDelay;
212 delay = DEFAULT_POPUP_TIME;
216 hideTimer->start( delay );
222 d->fixedPosition = p;
237 NETRootInfo info( qt_xdisplay(),
243 NETRect workArea = info.workArea( info.currentDesktop() );
245 r.setRect( workArea.
pos.
x, workArea.
pos.
y, 0, 0 );
249 r.setRect( 100, 100, 200, 200 );
264 NETWinInfo ni( qt_xdisplay(), window, qt_xrootwin(),
269 if ( ni.kdeSystemTrayWinFor() ) {
271 ni.kdeGeometry( frame, win );
272 target.setRect( win.
pos.
x, win.
pos.
y,
281 if ( target.isNull() ) {
283 ni.kdeGeometry( dummy, r );
297 TQPoint pos = target.topLeft();
308 if( x + w > r.width() ){
309 x = x + target.width();
312 if( y + h > r.height() ){
313 y = y + target.height();
317 if ( x < r.center().x() )
318 x = x + target.width();
323 if ( (y + h) > r.bottom() )
326 if ( (x + w) > r.right() )
353 p.drawPolygon( d->surround );
355 TQFrame::paintEvent( pe );
364 int xh = 70, xl = 40;
367 else if( width() < 110 )
370 bool bottom = (d->anchor.y() + height()) > ((deskRect.y() + deskRect.height()-48));
371 bool right = (d->anchor.x() + width()) > ((deskRect.x() + deskRect.width()-48));
373 TQPoint corners[4] = {
374 TQPoint( width() - 50, 10 ),
376 TQPoint( 10, height() - 50 ),
377 TQPoint( width() - 50, height() - 50 )
380 TQBitmap mask( width(), height(),
true );
381 TQPainter p( &mask );
382 TQBrush brush( Qt::white, Qt::SolidPattern );
388 corner.makeArc(corners[i].x(), corners[i].y(), 40, 40, i * 16 * 90, 16 * 90);
390 d->surround.resize( z + corner.count() );
391 for (
unsigned int s = 0; s < corner.count() - 1; s++) {
392 d->surround.setPoint( z++, corner[s] );
395 if (bottom && i == 2) {
397 d->surround.resize( z + 3 );
398 d->surround.setPoint( z++, TQPoint( width() - xh, height() - 11 ) );
399 d->surround.setPoint( z++, TQPoint( width() - 20, height() ) );
400 d->surround.setPoint( z++, TQPoint( width() - xl, height() - 11 ) );
402 d->surround.resize( z + 3 );
403 d->surround.setPoint( z++, TQPoint( xl, height() - 11 ) );
404 d->surround.setPoint( z++, TQPoint( 20, height() ) );
405 d->surround.setPoint( z++, TQPoint( xh, height() - 11 ) );
407 }
else if (!bottom && i == 0) {
409 d->surround.resize( z + 3 );
410 d->surround.setPoint( z++, TQPoint( width() - xl, 10 ) );
411 d->surround.setPoint( z++, TQPoint( width() - 20, 0 ) );
412 d->surround.setPoint( z++, TQPoint( width() - xh, 10 ) );
414 d->surround.resize( z + 3 );
415 d->surround.setPoint( z++, TQPoint( xh, 10 ) );
416 d->surround.setPoint( z++, TQPoint( 20, 0 ) );
417 d->surround.setPoint( z++, TQPoint( xl, 10 ) );
422 d->surround.resize( z + 1 );
423 d->surround.setPoint( z, d->surround[0] );
424 p.drawPolygon( d->surround );
427 move( right ? d->anchor.x() - width() + 20 : ( d->anchor.x() < 11 ? 11 : d->anchor.x() - 20 ),
428 bottom ? d->anchor.y() - height() : ( d->anchor.y() < 11 ? 11 : d->anchor.y() ) );
438 const TQPixmap &icon,
439 TQWidget *parent,
const char *name,
int timeout )
441 return message( DEFAULT_POPUP_TYPE, caption, text, icon, parent, name, timeout );
446 return message( DEFAULT_POPUP_TYPE, TQString::null, text, TQPixmap(), parent, name );
450 TQWidget *parent,
const char *name )
452 return message( DEFAULT_POPUP_TYPE, caption, text, TQPixmap(), parent, name );
456 const TQPixmap &icon, WId parent,
const char *name,
int timeout )
458 return message( DEFAULT_POPUP_TYPE, caption, text, icon, parent, name, timeout );
462 const TQPixmap &icon,
463 TQWidget *parent,
const char *name,
int timeout )
467 pop->
setView( caption, text, icon );
476 return message( popupStyle, TQString::null, text, TQPixmap(), parent, name );
480 TQWidget *parent,
const char *name )
482 return message( popupStyle, caption, text, TQPixmap(), parent, name );
486 const TQPixmap &icon, WId parent,
const char *name,
int timeout )
490 pop->
setView( caption, text, icon );