1
///This is blatently a copy of KPassivePopup I've ripped from KDE, original License below, (Kevin Smith):
3
* copyright : (C) 2001-2002 by Richard Moore
4
* License : This file is released under the terms of the LGPL, version 2.
10
#include <qapplication.h>
17
#include <qpointarray.h>
19
#include "qpassivepopup.h"
21
static const int DEFAULT_POPUP_TIME = 6*1000;
22
static const int POPUP_FLAGS = Qt::WStyle_Customize | Qt::WDestructiveClose | Qt::WX11BypassWM
23
| Qt::WStyle_StaysOnTop | Qt::WStyle_Tool | Qt::WStyle_NoBorder;
26
QPassivePopup::QPassivePopup( QWidget *parent, const char *name, WFlags f )
27
: QFrame( 0, name, f | POPUP_FLAGS ),
28
window( parent->winId() ), msgView( 0 ), layout( 0 ),
29
hideDelay( DEFAULT_POPUP_TIME ), hideTimer( new QTimer( this, "hide_timer" ) ), m_autoDelete( false ), d( 0 )
34
QPassivePopup::QPassivePopup( const char *name, WFlags f )
35
: QFrame( 0, name, f | POPUP_FLAGS ),
36
window( 0 ), msgView( 0 ), layout( 0 ),
37
hideDelay( DEFAULT_POPUP_TIME ), hideTimer( new QTimer( this, "hide_timer" ) ), m_autoDelete( false ), d( 0 )
42
QPassivePopup::QPassivePopup( WId win, const char *name, WFlags f )
43
: QFrame( 0, name, f | POPUP_FLAGS ),
44
window( win ), msgView( 0 ), layout( 0 ),
45
hideDelay( DEFAULT_POPUP_TIME ), hideTimer( new QTimer( this, "hide_timer" ) ), m_autoDelete( false ), d( 0 )
50
void QPassivePopup::init()
52
setFrameStyle( QFrame::Box| QFrame::Plain );
54
connect( hideTimer, SIGNAL( timeout() ), SLOT( hide() ) );
55
connect( this, SIGNAL( clicked() ), SLOT( hide() ) );
58
QPassivePopup::~QPassivePopup()
62
void QPassivePopup::setView( QWidget *child )
68
//layout = new QVBoxLayout( this, KDialog::marginHint(), KDialog::spacingHint() );//KEVIN
70
this->setFrameStyle(PopupPanel);
71
this->setFrameShadow(Raised);
72
this->setLineWidth(3);
73
this->setPalette(QToolTip::palette());
74
this->setAutoMask(true);
76
layout = new QVBoxLayout( this );//KEVIN
77
layout->addWidget( msgView );
81
void QPassivePopup::setView( const QString &caption, const QString &text,
84
QVBox *vb = new QVBox( this );
85
//vb->setSpacing( KDialog::spacingHint() ); //KEVIN
86
vb->setSpacing(5);//KEVIN
88
if ( !icon.isNull() ) {
90
//hb->setMargin( KDialog::marginHint() );//KEVIN
91
//hb->setSpacing( KDialog::spacingHint() );//KEVIN
92
hb->setMargin( 5 );//KEVIN
93
hb->setSpacing( 5 );//KEVIN
94
ttlIcon = new QLabel( hb, "title_icon" );
95
ttlIcon->setPixmap( icon );
98
if ( !caption.isNull() ) {
99
ttl = new QLabel( caption, hb ? hb : vb, "title_label" );
100
QFont fnt = ttl->font();
103
ttl->setAlignment( Qt::AlignHCenter );
106
//KEVIN thinks that text should be centred by default.
107
msg = new QLabel( text, vb, "msg_label" );
108
msg->setAlignment(Qt::AlignHCenter);
112
void QPassivePopup::setView( const QString &caption, const QString &text )
114
setView( caption, text, QPixmap() );
117
void QPassivePopup::setTimeout( int delay )
120
if( hideTimer->isActive() )
121
hideTimer->changeInterval( delay );
124
void QPassivePopup::setAutoDelete( bool autoDelete )
126
m_autoDelete = autoDelete;
129
void QPassivePopup::mouseReleaseEvent( QMouseEvent *e )
132
emit clicked( e->pos() );
136
// Main Implementation
139
void QPassivePopup::show()
141
if ( size() != sizeHint() )
142
resize( sizeHint() );
147
int delay = hideDelay;
149
delay = DEFAULT_POPUP_TIME;
152
hideTimer->start( delay );
156
void QPassivePopup::hideEvent( QHideEvent * )
163
void QPassivePopup::positionSelf()
165
//This is all KDE-specifix stuff, I've had to comment out (KEVIN)
167
NETWinInfo ni( qt_xdisplay(), window, qt_xrootwin(),
168
NET::WMIconGeometry | NET::WMKDESystemTrayWinFor );
170
// Figure out where to put the popup. Note that we must handle
171
// windows that skip the taskbar cleanly
173
if ( ni.kdeSystemTrayWinFor() ) {
175
ni.kdeGeometry( frame, win );
176
target.setRect( win.pos.x, win.pos.y, win.size.width, win.size.height );
178
else if ( ni.state() & NET::SkipTaskbar ) {
179
target.setRect( 0, 0, 0, 0 );
182
NETRect r = ni.iconGeometry();
183
target.setRect( r.pos.x, r.pos.y, r.size.width, r.size.height );
189
target.setRect((qApp->desktop()->width()/20)*19,qApp->desktop()->height(),0,0);
195
void QPassivePopup::moveNear( QRect target )
197
QPoint pos = target.topLeft();
203
if ( x < ( qApp->desktop()->width() / 2 ) )
204
x = x + target.width();
208
// It's apparently trying to go off screen, so display it ALL at the bottom.
209
if ( (y + h) > qApp->desktop()->height() )
210
y = qApp->desktop()->height() - h;
221
// Convenience Methods
224
QPassivePopup *QPassivePopup::message( const QString &caption, const QString &text,
226
QWidget *parent, const char *name, int timeout )
228
QPassivePopup *pop = new QPassivePopup( parent, name );
229
pop->setAutoDelete( true );
230
pop->setView( caption, text, icon );
231
pop->hideDelay = timeout;
237
QPassivePopup *QPassivePopup::message( const QString &text, QWidget *parent, const char *name )
239
return message( QString::null, text, QPixmap(), parent, name );
242
QPassivePopup *QPassivePopup::message( const QString &caption, const QString &text,
243
QWidget *parent, const char *name )
245
return message( caption, text, QPixmap(), parent, name );
248
QPassivePopup *QPassivePopup::message( const QString &caption, const QString &text,
249
const QPixmap &icon, WId parent, const char *name, int timeout )
251
QPassivePopup *pop = new QPassivePopup( parent, name );
252
pop->setAutoDelete( true );
254
pop->setView( caption, text, icon );
255
pop->hideDelay = timeout;
260
QString *QPassivePopup::splitMessage(QString caption, uint splitsize, uint maxsize){
261
QString *splitcaption;
262
printf("Splitting message of length %d with splitsize %d and maxsize %d \n", caption.length(), splitsize, maxsize);
263
if (caption.length()>maxsize){
264
splitcaption=new QString(caption.left(maxsize));}
266
splitcaption=new QString(caption);}
267
for (uint i=splitsize;i<caption.length();i+=splitsize){
268
bool truncated=false;
269
for (uint j=i-5;j<i+5;j++){
270
if (splitcaption->at(j).isSpace()) {
271
QString* old=splitcaption;
272
printf("Split on char %c, number %d\n", splitcaption->at(j).latin1(),j);
273
splitcaption=new QString(splitcaption->left(j)+"\n"+splitcaption->right(splitcaption->length()-j));
281
QString *old=splitcaption;
282
printf("forced to split at %d\n",i);
283
splitcaption=new QString(splitcaption->left(i)+"-\n "+splitcaption->right(splitcaption->length()-i));
290
void QPassivePopup::updateMask()
292
//QRegion mask(10, 10, width() - 20, height() - 20);
293
QRegion mask(0, 0, width(), height());
294
/*QPoint corners[8] = {
295
QPoint(width() - 50, 10),
297
QPoint(10, height() - 50),
298
QPoint(width() - 50, height() - 50),
299
QPoint(width() - 10, 10),
301
QPoint(10, height() - 10),
302
QPoint(width() - 10, height() - 10)
304
QPoint corners[8] = {
305
QPoint(width()-40, 0),
307
QPoint(0, height()-40),
308
QPoint(width()-40, height()-40),
312
QPoint(width(), height())
314
for (int i = 0; i < 2; ++i)
317
corner.makeArc(corners[i].x(), corners[i].y(), 40, 40, i * 16 * 90, 16 * 90);
318
corner.resize(corner.size() + 1);
319
corner.setPoint(corner.size() - 1, corners[i + 4]);
323
QDesktopWidget* tmp = QApplication::desktop();
325
// get screen-geometry for screen our anchor is on
326
// (geometry can differ from screen to screen!
327
deskRect = tmp->screenGeometry( tmp->screenNumber(this->pos()) );
328
bottom = this->pos().y() + height() > deskRect.height() - 48;
329
right = this->pos().x() + width() > deskRect.width() - 48;
331
/*QPointArray arrow(4);
332
arrow.setPoint(0, QPoint(right ? width() : 0, bottom ? height() : 0));
333
arrow.setPoint(1, QPoint(right ? width() - 10 : 10, bottom ? height() - 30 : 30));
334
arrow.setPoint(2, QPoint(right ? width() - 30 : 30, bottom ? height() - 10 : 10));
335
arrow.setPoint(3, arrow[0]);
338
/*move(right ? this->pos().x() - width() : this->pos().x(),
339
bottom ? this->pos().y() - height() : this->pos().y());*/