21 #include "kpassivepopup.moc"
24 #include <QApplication>
28 #include <QMouseEvent>
30 #include <QPainterPath>
34 #include <QSystemTrayIcon>
44 #include <qx11info_x11.h>
52 static const Qt::WindowFlags
POPUP_FLAGS = Qt::Tool | Qt::X11BypassWindowManagerHint | Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint;
54 class KPassivePopup::Private
75 QBoxLayout *topLayout;
90 init( parent ? parent->effectiveWinId() : 0L );
100 #if 0 // These break macos and win32 where the definition of WId makes them ambiguous
105 init( parent ? parent->winId() : 0L );
118 void KPassivePopup::init( WId window )
121 d->hideTimer =
new QTimer(
this );
124 setFrameStyle( QFrame::Box| QFrame::Plain );
127 if( d->popupStyle ==
Boxed )
129 setFrameStyle( QFrame::Box| QFrame::Plain );
132 else if( d->popupStyle ==
Balloon )
134 setPalette(QToolTip::palette());
137 connect( d->hideTimer, SIGNAL(
timeout()), SLOT(hide()) );
138 connect(
this, SIGNAL(
clicked()), SLOT(hide()) );
148 if ( d->popupStyle == popupstyle )
151 d->popupStyle = popupstyle;
152 if( d->popupStyle ==
Boxed )
154 setFrameStyle( QFrame::Box| QFrame::Plain );
157 else if( d->popupStyle ==
Balloon )
159 setPalette(QToolTip::palette());
170 d->topLayout =
new QVBoxLayout(
this );
171 if ( d->popupStyle ==
Balloon ) {
174 d->topLayout->addWidget( d->msgView );
175 d->topLayout->activate();
179 const QPixmap &icon )
191 KVBox *vb =
new KVBox( parent ? parent :
this );
195 if ( !icon.isNull() ) {
196 hb =
new KHBox( vb );
199 d->ttlIcon =
new QLabel( hb );
200 d->ttlIcon->setPixmap( icon );
201 d->ttlIcon->setAlignment( Qt::AlignLeft );
204 if ( !caption.isEmpty() ) {
205 d->ttl =
new QLabel( caption, hb ? hb : vb );
206 QFont fnt = d->ttl->font();
208 d->ttl->setFont( fnt );
209 d->ttl->setAlignment( Qt::AlignHCenter );
215 if ( !text.isEmpty() ) {
216 d->msg =
new QLabel( text, vb );
217 d->msg->setAlignment( Qt::AlignLeft );
218 d->msg->setTextInteractionFlags(Qt::LinksAccessibleByMouse);
219 d->msg->setOpenExternalLinks(
true);
227 setView( caption, text, QPixmap() );
242 d->hideDelay = delay;
243 if( d->hideTimer->isActive() )
246 d->hideTimer->start( delay );
248 d->hideTimer->stop();
255 return d->autoDelete;
276 QFrame::setVisible( visible );
280 if ( size() != sizeHint() )
281 resize( sizeHint() );
283 if ( d->fixedPosition.isNull() )
289 move( d->fixedPosition );
291 QFrame::setVisible(
true );
293 int delay = d->hideDelay;
299 d->hideTimer->start( delay );
310 d->fixedPosition = p;
316 d->hideTimer->stop();
330 NETRect workArea = info.workArea( info.currentDesktop() );
332 r.setRect( workArea.
pos.
x, workArea.
pos.
y, 0, 0 );
336 r.setRect( 100, 100, 200, 200 );
351 NETWinInfo ni( QX11Info::display(), d->window, QX11Info::appRootWindow(),
362 if ( target.isNull() ) {
382 move( pos.x(), pos.y() );
386 QPoint pos = target.topLeft();
389 int w = minimumSizeHint().width();
390 int h = minimumSizeHint().height();
397 if( x + w > r.width() ){
398 x = x + target.width();
401 if( y + h > r.height() ){
402 y = y + target.height();
406 if ( x < r.center().x() )
407 x = x + target.width();
412 if ( (y + h) > r.bottom() )
415 if ( (x + w) > r.right() )
444 p.drawPolygon( d->surround );
446 QFrame::paintEvent( pe );
455 int xh = 70, xl = 40;
458 else if( width() < 110 )
461 bool bottom = (d->anchor.y() + height()) > ((deskRect.y() + deskRect.height()-48));
462 bool right = (d->anchor.x() + width()) > ((deskRect.x() + deskRect.width()-48));
465 QPoint( width() - 50, 10 ),
467 QPoint( 10, height() - 50 ),
468 QPoint( width() - 50, height() - 50 )
471 QBitmap
mask( width(), height() );
474 QBrush brush( Qt::color1, Qt::SolidPattern );
480 path.moveTo(corners[i].x(),corners[i].y());
481 path.arcTo(corners[i].x(),corners[i].y(),40,40, i * 90 , 90);
482 QPolygon corner = path.toFillPolygon().toPolygon();
484 d->surround.resize( z + corner.count() - 1 );
485 for (
int s = 1; s < corner.count() - 1; s++, z++) {
486 d->surround.setPoint( z, corner[s] );
489 if (bottom && i == 2) {
491 d->surround.resize( z + 3 );
492 d->surround.setPoint( z++,
QPoint( width() - xh, height() - 10 ) );
493 d->surround.setPoint( z++,
QPoint( width() - 20, height() ) );
494 d->surround.setPoint( z++,
QPoint( width() - xl, height() - 10 ) );
496 d->surround.resize( z + 3 );
497 d->surround.setPoint( z++,
QPoint( xl, height() - 10 ) );
498 d->surround.setPoint( z++,
QPoint( 20, height() ) );
499 d->surround.setPoint( z++,
QPoint( xh, height() - 10 ) );
501 }
else if (!bottom && i == 0) {
503 d->surround.resize( z + 3 );
504 d->surround.setPoint( z++,
QPoint( width() - xl, 10 ) );
505 d->surround.setPoint( z++,
QPoint( width() - 20, 0 ) );
506 d->surround.setPoint( z++,
QPoint( width() - xh, 10 ) );
508 d->surround.resize( z + 3 );
509 d->surround.setPoint( z++,
QPoint( xh, 10 ) );
510 d->surround.setPoint( z++,
QPoint( 20, 0 ) );
511 d->surround.setPoint( z++,
QPoint( xl, 10 ) );
516 d->surround.resize( z + 1 );
517 d->surround.setPoint( z, d->surround[0] );
518 p.drawPolygon( d->surround );
521 move( right ? d->anchor.x() - width() + 20 : ( d->anchor.x() < 11 ? 11 : d->anchor.x() - 20 ),
522 bottom ? d->anchor.y() - height() : ( d->anchor.y() < 11 ? 11 : d->anchor.y() ) );
550 const QPixmap &icon, WId parent,
int timeout )
581 pop->
setView( caption, text, icon );
596 return message( popupStyle, caption, text, QPixmap(), parent );
600 const QPixmap &icon, WId parent,
int timeout )
605 pop->
setView( caption, text, icon );
619 pop->
setView( caption, text, icon );
636 return message( popupStyle, caption, text, QPixmap(), parent );