1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
|
/***************************************************************************
* $Id: popupMessage.cpp,v 1.17 2008/07/31 19:56:26 hoganrobert Exp $
* Copyright (C) 2006 - 2008 Robert Hogan *
* robert@roberthogan.net *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
/***************************************************************************
* Copyright (C) 2005 by Max Howell <max.howell@methylblue.com> *
* 2005 by Seb Ruiz <me@sebruiz.net> *
* *
* Dissolve Mask (c) Kicker Authors kickertip.cpp, 2005/08/17 *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Steet, Fifth Floor, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "popupMessage.h"
#include "torkconfig.h"
#include <kactivelabel.h>
#include <kpushbutton.h>
#include <kstdguiitem.h>
#include <qfont.h>
#include <qframe.h>
#include <qlabel.h>
#include <qmessagebox.h>
#include <qpainter.h>
#include <qtimer.h>
#include <qcheckbox.h>
namespace KDE
{
PopupMessage::PopupMessage( QWidget *parent, QWidget *anchor, int timeout, const char *name )
: OverlayWidget( parent, anchor, name )
, m_anchor( anchor )
, m_parent( parent )
, m_maskEffect( Dissolve )
, m_dissolveSize( 0 )
, m_dissolveDelta( -1 )
, m_offset( 0 )
, m_counter( 0 )
, m_stage( 1 )
, m_timeout( timeout )
, m_showCounter( true )
, m_respondedTo( false )
, m_name( name )
{
setFrameStyle( QFrame::Panel | QFrame::Raised );
setFrameShape( QFrame::StyledPanel );
setWFlags( Qt::WX11BypassWM );
QHBoxLayout *hbox;
QLabel *label;
KActiveLabel *alabel;
m_layout = new QVBoxLayout( this, 9 /*margin*/, 6 /*spacing*/ );
hbox = new QHBoxLayout( m_layout, 12 );
hbox->addWidget( m_countdownFrame = new QFrame( this, "counterVisual" ) );
m_countdownFrame->setFixedWidth( fontMetrics().width( "X" ) );
m_countdownFrame->setFrameStyle( QFrame::Plain | QFrame::Box );
m_countdownFrame->setPaletteForegroundColor( paletteBackgroundColor().dark() );
label = new QLabel( this, "image" );
hbox->add( label );
alabel = new KActiveLabel( this, "label" );
alabel->setTextFormat( Qt::RichText );
alabel->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Preferred );
hbox->add( alabel );
hbox = new QHBoxLayout( m_layout );
if (configurableType()){
hbox->add( new QCheckBox( this, "showWarnings" ) );
static_cast<QCheckBox*>(child( "showWarnings" ))->setText(QString("%1 in Future.").arg(m_name));
static_cast<QCheckBox*>(child( "showWarnings" ))->setChecked(TRUE);
connect( child( "showWarnings" ), SIGNAL(toggled( bool )), SLOT(toggled( bool )) );
}
hbox->addItem( new QSpacerItem( 4, 4, QSizePolicy::Expanding, QSizePolicy::Preferred ) );
hbox->add( new KPushButton( KStdGuiItem::yes(), this, "yesButton" ) );
hbox->add( new KPushButton( KStdGuiItem::no(), this, "closeButton" ) );
hbox->add( new KPushButton( KStdGuiItem::ok(), this, "okButton" ) );
connect( child( "yesButton" ), SIGNAL(clicked()), SLOT(yes()) );
connect( child( "closeButton" ), SIGNAL(clicked()), SLOT(no()) );
connect( child( "okButton" ), SIGNAL(clicked()), SLOT(no()) );
}
void PopupMessage::addWidget( QWidget *widget )
{
m_layout->add( widget );
adjustSize();
}
void PopupMessage::showBothButton( const bool show )
{
static_cast<KPushButton*>(child( "yesButton" ))->setShown( show );
static_cast<KPushButton*>(child( "closeButton" ))->setShown( show );
static_cast<KPushButton*>(child( "okButton" ))->setShown( !show );
adjustSize();
}
void PopupMessage::showOkButton( const bool show )
{
static_cast<KPushButton*>(child( "yesButton" ))->setShown( !show );
static_cast<KPushButton*>(child( "closeButton" ))->setShown( !show );
static_cast<KPushButton*>(child( "okButton" ))->setShown( show );
adjustSize();
}
void PopupMessage::showCounter( const bool show )
{
m_showCounter = show;
static_cast<QFrame*>(child( "counterVisual" ))->setShown( show );
adjustSize();
}
void PopupMessage::setText( const QString &text )
{
static_cast<KActiveLabel*>(child( "label" ))->setText( text );
adjustSize();
}
void PopupMessage::setImage( const QString &location )
{
static_cast<QLabel*>(child( "image" ))->setPixmap( QPixmap( location ) );
adjustSize();
}
void PopupMessage::setImage( const QPixmap &pix )
{
static_cast<QLabel*>(child( "image" ))->setPixmap( pix );
adjustSize();
}
////////////////////////////////////////////////////////////////////////
// Public Slots
////////////////////////////////////////////////////////////////////////
void PopupMessage::yes() //SLOT
{
m_respondedTo = true;
close();
emit yesClicked( );
}
void PopupMessage::no() //SLOT
{
m_respondedTo = true;
close();
emit noClicked();
}
void PopupMessage::close() //SLOT
{
m_stage = 3;
killTimer( m_timerId );
m_timerId = startTimer( 10 );
}
void PopupMessage::toggled( bool on) //SLOT
{
QString mtype = QString("%1").arg(m_name);
if (mtype.contains("Usage"))
TorkConfig::setShowUsageWarnings(on);
else if (mtype.contains("DNS"))
TorkConfig::setShowDNSLeaks(on);
else if (mtype.contains("Feedback"))
TorkConfig::setShowGuideQuestions(on);
else if (mtype.contains("Settings"))
TorkConfig::setShowApplySettingsQuestions(on);
else if (mtype.contains("Security"))
TorkConfig::setShowSecurityWarnings(on);
}
bool PopupMessage::configurableType() //SLOT
{
QString mtype = QString(m_name);
if ((mtype.contains("Usage"))
|| (mtype.contains("DNS"))
|| (mtype.contains("Security"))
|| (mtype.contains("Apply"))
|| (mtype.contains("Feedback")))
return true;
return false;
}
void PopupMessage::display() //SLOT
{
m_dissolveSize = 24;
m_dissolveDelta = -1;
if( m_maskEffect == Dissolve )
{
// necessary to create the mask
m_mask.resize( width(), height() );
// make the mask empty and hence will not show widget with show() called below
dissolveMask();
m_timerId = startTimer( 1000 / 30 );
}
else
{
m_timerId = startTimer( 1 );
}
show();
}
////////////////////////////////////////////////////////////////////////
// Protected
////////////////////////////////////////////////////////////////////////
void PopupMessage::timerEvent( QTimerEvent* )
{
switch( m_maskEffect )
{
case Plain:
plainMask();
break;
case Slide:
slideMask();
break;
case Dissolve:
dissolveMask();
break;
}
}
void PopupMessage::countDown()
{
if( !m_timeout )
{
killTimer( m_timerId );
return;
}
QFrame *&h = m_countdownFrame;
if( m_counter < h->height() - 3 )
QPainter( h ).fillRect( 2, 2, h->width() - 4, m_counter, palette().active().highlight() );
if( !hasMouse() )
m_counter++;
if( m_counter > h->height() )
{
m_stage = 3;
killTimer( m_timerId );
m_timerId = startTimer( 1 );
}
else
{
killTimer( m_timerId );
m_timerId = startTimer( m_timeout / h->height() );
}
}
void PopupMessage::dissolveMask()
{
if( m_stage == 1 )
{
repaint( false );
QPainter maskPainter(&m_mask);
m_mask.fill(Qt::black);
maskPainter.setBrush(Qt::white);
maskPainter.setPen(Qt::white);
maskPainter.drawRect( m_mask.rect() );
m_dissolveSize += m_dissolveDelta;
if( m_dissolveSize > 0 )
{
maskPainter.setRasterOp( Qt::EraseROP );
int x, y, s;
const int size = 16;
for (y = 0; y < height() + size; y += size)
{
x = width();
s = m_dissolveSize * x / 128;
for ( ; x > size; x -= size, s -= 2 )
{
if (s < 0)
break;
maskPainter.drawEllipse(x - s / 2, y - s / 2, s, s);
}
}
}
else if( m_dissolveSize < 0 )
{
m_dissolveDelta = 1;
killTimer( m_timerId );
if( m_timeout )
{
m_timerId = startTimer( 40 );
m_stage = 2;
}
}
setMask(m_mask);
}
else if ( m_stage == 2 )
{
countDown();
}
else
{
if (!m_respondedTo)
emit Closed();
deleteLater();
}
}
void PopupMessage::plainMask()
{
switch( m_stage )
{
case 1: // Raise
killTimer( m_timerId );
if( m_timeout )
{
m_timerId = startTimer( 40 );
m_stage = 2;
}
break;
case 2: // Counter
countDown();
break;
case 3: // Lower/Remove
if (!m_respondedTo)
emit Closed();
deleteLater();
}
}
void PopupMessage::slideMask()
{
switch( m_stage )
{
case 1: //raise
move( 0, m_parent->y() - m_offset );
m_offset=m_offset + 5;
if( m_offset > height() )
{
killTimer( m_timerId );
if( m_timeout )
{
m_timerId = startTimer( 40 );
m_stage = 2;
}
}
break;
case 2: //fill in pause timer bar
countDown();
break;
case 3: //lower
m_offset=m_offset-5;
move( 0, m_parent->y() - m_offset );
if( m_offset < 0 ){
if (!m_respondedTo)
emit Closed();
deleteLater();
}
}
}
}
#include "popupMessage.moc"
|