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
|
/*
*
* $Id: sourceheader 511311 2006-02-19 14:51:05Z trueg $
* Copyright (C) 2006 Sebastian Trueg <trueg@k3b.org>
*
* This file is part of the K3b project.
* Copyright (C) 1998-2007 Sebastian Trueg <trueg@k3b.org>
*
* 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.
* See the file "COPYING" for the exact licensing terms.
*/
#include "k3bpassivepopup.h"
#include "k3bwidgetshoweffect.h"
#include "k3btimeoutwidget.h"
#include "k3bminibutton.h"
#include "k3bthememanager.h"
#include <k3bapplication.h>
#include <kapplication.h>
#include <klocale.h>
#include <kiconloader.h>
#include <kguiitem.h>
#include <kpushbutton.h>
#include <kactivelabel.h>
#include <tqtimer.h>
#include <tqlayout.h>
#include <tqlabel.h>
#include <tqmainwindow.h>
#include <tqmessagebox.h>
#include <tqstyle.h>
#include <tqtooltip.h>
#include <tqfont.h>
static const char* const sticky_xpm[] = {
"5 5 2 1",
"# c black",
". c None",
"#####",
"#...#",
"#...#",
"#...#",
"#####"
};
static TQPixmap themedMessageBoxIcon( K3bPassivePopup::MessageType mt )
{
TQString icon_name;
TQMessageBox::Icon qIcon;
switch( mt ) {
case K3bPassivePopup::Information:
qIcon = TQMessageBox::Information;
icon_name = "messagebox_info";
break;
case K3bPassivePopup::Warning:
qIcon = TQMessageBox::Warning;
icon_name = "messagebox_warning";
break;
case K3bPassivePopup::Error:
qIcon = TQMessageBox::Critical;
icon_name = "messagebox_critical";
break;
default:
return TQPixmap();
break;
}
TQPixmap ret = TDEApplication::kApplication()->iconLoader()->loadIcon(icon_name, KIcon::NoGroup, KIcon::SizeMedium, KIcon::DefaultState, 0, true);
if( ret.isNull() )
return TQMessageBox::standardIcon( qIcon );
else
return ret;
}
class K3bPassivePopup::Private
{
public:
int timeout;
int showEffect;
K3bTimeoutWidget* timeoutWidget;
TQLabel* titleLabel;
KActiveLabel* messageLabel;
TQLabel* pixmapLabel;
K3bMiniButton* closeButton;
K3bMiniButton* stickyButton;
};
K3bPassivePopup::K3bPassivePopup( TQWidget* parent )
: TQFrame( parent )
{
d = new Private;
d->timeout = 6000;
d->showEffect = 0;
setFrameStyle( TQFrame::StyledPanel | TQFrame::Raised );
// setWFlags( TQt::WX11BypassWM );
TQVBoxLayout* mainLay = new TQVBoxLayout( this );
mainLay->setMargin( frameWidth() );
mainLay->setSpacing( 0 );
TQGridLayout* grid = new TQGridLayout;
grid->setMargin( 9 );
grid->setSpacing( 6 );
d->titleLabel = new TQLabel( this );
d->titleLabel->setMargin( 5 );
d->titleLabel->setAlignment( TQt::AlignCenter );
TQFont fnt( d->titleLabel->font() );
fnt.setBold( true );
d->titleLabel->setFont( fnt );
d->messageLabel = new KActiveLabel( this );
d->pixmapLabel = new TQLabel( this );
d->pixmapLabel->setAlignment( TQt::AlignTop );
d->timeoutWidget = new K3bTimeoutWidget( this );
connect( d->timeoutWidget, TQT_SIGNAL(timeout()), this, TQT_SLOT(slotClose()) );
d->closeButton = new K3bMiniButton( d->titleLabel );
d->closeButton->setPixmap( style().stylePixmap( TQStyle::SP_TitleBarCloseButton, this ) );
d->closeButton->setFixedSize( d->closeButton->pixmap()->width(), d->closeButton->pixmap()->height() );
TQToolTip::add( d->closeButton, i18n("Close") );
connect( d->closeButton, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotClose()) );
d->stickyButton = new K3bMiniButton( d->titleLabel );
d->stickyButton->setToggleButton( true );
d->stickyButton->setPixmap( const_cast< const char** >( sticky_xpm ) );
d->stickyButton->setFixedSize( d->closeButton->pixmap()->width(), d->closeButton->pixmap()->height() );
TQToolTip::add( d->stickyButton, i18n("Keep Open") );
connect( d->stickyButton, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotSticky(bool)) );
grid->addWidget( d->pixmapLabel, 0, 0 );
grid->addWidget( d->messageLabel, 0, 1 );
grid->addWidget( d->timeoutWidget, 0, 2 );
grid->setColStretch( 1, 1 );
mainLay->addWidget( d->titleLabel );
mainLay->addLayout( grid, 1 );
TQHBoxLayout* titleLay = new TQHBoxLayout( d->titleLabel );
titleLay->setMargin( d->titleLabel->margin() );
titleLay->setSpacing( 2 );
titleLay->addStretch();
titleLay->addWidget( d->stickyButton );
titleLay->addWidget( d->closeButton );
if( K3bTheme* theme = k3bappcore->themeManager()->currentTheme() ) {
d->titleLabel->setPaletteBackgroundColor( theme->backgroundColor() );
d->titleLabel->setPaletteForegroundColor( theme->foregroundColor() );
}
setTitle( TQString() );
setMessageType( Information );
}
K3bPassivePopup::~K3bPassivePopup()
{
delete d;
}
void K3bPassivePopup::setShowCloseButton( bool b )
{
d->closeButton->setShown( b );
adjustSize();
}
void K3bPassivePopup::setShowCountdown( bool b )
{
d->timeoutWidget->setShown( b );
d->stickyButton->setShown( b );
}
void K3bPassivePopup::setMessage( const TQString& m )
{
d->messageLabel->setText( "<qt>" + m );
adjustSize();
}
void K3bPassivePopup::setTitle( const TQString& t )
{
d->titleLabel->setText( t );
// d->titleLabel->setShown( !t.isEmpty() );
adjustSize();
}
void K3bPassivePopup::setTimeout( int msecs )
{
d->timeout = msecs;
}
void K3bPassivePopup::setMessageType( MessageType m )
{
d->pixmapLabel->setPixmap( themedMessageBoxIcon( m ) );
adjustSize();
}
void K3bPassivePopup::slideIn()
{
d->showEffect = K3bWidgetShowEffect::Slide;
connect( K3bWidgetShowEffect::showWidget( this, (K3bWidgetShowEffect::Effect)d->showEffect ), TQT_SIGNAL(widgetShown(TQWidget*)),
this, TQT_SLOT(slotShown()) );
}
void K3bPassivePopup::slotShown()
{
if( d->timeoutWidget->isVisible() ) {
d->timeoutWidget->setTimeout( d->timeout );
d->timeoutWidget->start();
}
else
TQTimer::singleShot( d->timeout, this, TQT_SLOT(slotClose()) );
}
void K3bPassivePopup::slotHidden()
{
deleteLater();
}
void K3bPassivePopup::slotClose()
{
if( d->showEffect != 0 ) {
connect( K3bWidgetShowEffect::hideWidget( this, (K3bWidgetShowEffect::Effect)d->showEffect ), TQT_SIGNAL(widgetHidden(TQWidget*)),
this, TQT_SLOT(slotHidden()) );
}
else
deleteLater();
}
void K3bPassivePopup::slotSticky( bool b )
{
if( b ) {
d->timeoutWidget->pause();
}
else {
d->timeoutWidget->resume();
}
}
void K3bPassivePopup::showPopup( const TQString& message,
const TQString& title,
MessageType messageType,
bool countdown,
bool button )
{
K3bPassivePopup* pop = new K3bPassivePopup( static_cast<TQMainWindow*>(tqApp->mainWidget())->centralWidget() );
pop->setMessage( message );
pop->setTitle( title );
pop->setMessageType( messageType );
pop->setShowCloseButton( button );
pop->setShowCountdown( countdown );
pop->slideIn();
}
#include "k3bpassivepopup.moc"
|