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
|
/*
* Copyright (C) 2006
* Siraj Razick <[email protected]>
* PhobosK <[email protected]>
* see Also AUTHORS
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License version 2 as
* published by the Free Software Foundation
*
* 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 Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <config.h>
#include "kbfxbutton.h"
bool KbfxButton::m_sizeHeight = TRUE;
int KbfxButton::m_size = 0;
KbfxButton::KbfxButton ( TQWidget * tqparent, const char *name) :
TQLabel ( tqparent,name,TQt::WStaticContents | TQt::WNoAutoErase |TQt::WPaintDesktop )
{
setLineWidth ( 0 );
setScaledContents ( false );
setAcceptDrops ( true );
m_dcopClient = new DCOPClient ();
m_dcopClient->attach ();
m_fadeTime = ConfigInit().m_fadeTime;
/* Init normal size first */
m_kicker_auto_adjust = TRUE;
loadSkins();
m_kicker_auto_adjust = ConfigInit().m_ToolBarResize;
m_toggle = false;
TQTimer * timer = new TQTimer ( this,"Update Timer" );
connect ( timer,TQT_SIGNAL ( timeout() ),this,TQT_SLOT ( update() ) );
timer->start ( 25,false );
fade_timer = new TQTimer ( this,"Fade Timer" );
connect ( fade_timer,TQT_SIGNAL ( timeout() ),this,TQT_SLOT ( fade() ) );
}
KbfxButton::~KbfxButton()
{
}
void KbfxButton::loadSkins()
{
TQImage _tmpHover, _tmpPressed, _tmpNormal;
_tmpHover = ( KbfxPlasmaPixmapProvider::PixmapPathCheck ( ConfigInit ().m_KbfxHoverButtonPath ) ) ?
TQImage ( ConfigInit ().m_KbfxHoverButtonPath )
: TQImage ( ConfigInit ().m_KbfxHoverButtonPathDefault );
_tmpPressed = ( KbfxPlasmaPixmapProvider::PixmapPathCheck ( ConfigInit ().m_KbfxPressedButtonPath ) ) ?
TQImage ( ConfigInit ().m_KbfxPressedButtonPath )
: TQImage ( ConfigInit ().m_KbfxPressedButtonPathDefault );
_tmpNormal = ( KbfxPlasmaPixmapProvider::PixmapPathCheck ( ConfigInit ().m_KbfxNormalButtonPath ) ) ?
TQImage ( ConfigInit ().m_KbfxNormalButtonPath )
: TQImage ( ConfigInit ().m_KbfxNormalButtonPathDefault );
TQSize _sizeNormal = _tmpNormal.size();
_tmpHover = _tmpHover.smoothScale ( _sizeNormal, TQ_ScaleFree );
_tmpPressed = _tmpPressed.smoothScale ( _sizeNormal, TQ_ScaleFree );
if ( !m_kicker_auto_adjust )
{
if ( m_sizeHeight )
{
_tmpHover = _tmpHover.smoothScale ( _tmpHover.width(), m_size, TQ_ScaleMin );
_tmpPressed = _tmpPressed.smoothScale ( _tmpPressed.width(), m_size, TQ_ScaleMin );
_tmpNormal = _tmpNormal.smoothScale ( _tmpNormal.width(), m_size, TQ_ScaleMin );
}
else
{
_tmpHover = _tmpHover.smoothScale ( m_size, _tmpHover.height(), TQ_ScaleMin );
_tmpPressed = _tmpPressed.smoothScale ( m_size, _tmpPressed.height(), TQ_ScaleMin );
_tmpNormal = _tmpNormal.smoothScale ( m_size, _tmpNormal.height(), TQ_ScaleMin );
}
}
m_over_skin = TQPixmap ( _tmpHover );
m_normal_skin = TQPixmap ( _tmpNormal );
m_pressed_skin = TQPixmap ( _tmpPressed );
m_current_skin = m_normal_skin;
this->resize ( m_current_skin.width(),m_current_skin.height() );
this->tqrepaint();
}
TQCString KbfxButton::findPanel()
{
TQCString m_AppletPanel = TQCString ("kicker");
QCStringList objects=m_dcopClient->remoteObjects("kicker");
for( QCStringList::ConstIterator it = objects.begin();
it != objects.end();
++it)
{
if ( (*it).tqcontains ( "Panel" ) > 0 )
{
DCOPRef _dcop_obj ( "kicker", (*it) );
TQStringList _dcop_obj_applets =_dcop_obj.call ( "listApplets()" );
for ( TQStringList::Iterator _it = _dcop_obj_applets.begin();
_it != _dcop_obj_applets.end();
_it++ )
{
if ( ( *_it ).tqcontains ( "kbfx" ) )
{
m_AppletPanel = (*it);
break;
}
}
}
}
kdDebug () << "KBFX resides on panel: " << m_AppletPanel << endl;
return m_AppletPanel;
}
void KbfxButton::readjust( bool _how )
{
/* _how = TRUE is for height, _how = FALSE is for width readjust */
TQCString _panel = findPanel();
int _tmp_size;
if ( _how )
{
_tmp_size = this->height ();
kdDebug () << "Readjusting " << _panel << " to height: " << _tmp_size << endl;
}
else
{
_tmp_size = this->width ();
kdDebug () << "Readjusting " << _panel << " to width: " << _tmp_size << endl;
}
TQByteArray data;
TQDataStream arg ( data, IO_WriteOnly );
arg << _tmp_size ;
if ( !m_dcopClient->send ( "kicker", _panel, "setPanelSize(int)", data ) )
kdWarning ()
<< "Could not send DCOP command to:"
<< _panel
<< endl;
}
void KbfxButton::enterEvent ( TQEvent * e )
{
e = e;
if ( m_toggle == true )
{
// m_current_skin = m_pressed_skin; // no fade code
m_fadePix = m_pressed_skin;
}
else
{
// m_current_skin = m_over_skin; // no fade code
m_fadePix = m_over_skin;
emit showToolTip ();
}
fade();
}
void KbfxButton::fade ( )
{
if ( m_fadeTime == 0 )
{
m_current_skin = m_fadePix;
}
else
{
TQImage _final = m_fadePix.convertToImage ();
TQImage _current = m_current_skin.convertToImage ();
if ( !fade_timer->isActive ())
{
m_opacity = 0;
fade_timer->start( m_fadeTime, false);
}
if ( m_opacity > 0.9 )
fade_timer->stop();
m_opacity += 0.1;
KImageEffect::blend ( _final, _current, m_opacity);
m_current_skin = TQPixmap ( _current );
}
this->resize ( m_current_skin.size() );
this->update();
}
void KbfxButton::leaveEvent ( TQEvent * e )
{
e = e;
if ( m_toggle )
{
// m_current_skin = m_pressed_skin; // no fade code
m_fadePix = m_pressed_skin;
}
else
{
// m_current_skin = m_normal_skin; // no fade code
m_fadePix = m_normal_skin;
}
fade();
emit leave ();
}
void KbfxButton::toggle()
{
if (this->hasMouse() ) {
m_fadePix = m_over_skin;
}else {
m_fadePix = m_normal_skin;
m_toggle = false;
}
fade();
}
void KbfxButton::toggleKMenu()
{
// m_current_skin = m_normal_skin;
m_fadePix = m_normal_skin;
fade();
m_toggle = false;
}
void KbfxButton::mousePressEvent ( TQMouseEvent * e )
{
e->accept();
if ( e->button() == Qt::LeftButton )
{
if ( m_toggle == false )
{
// m_current_skin = m_pressed_skin; // no fade code
m_toggle = true;
m_fadePix = m_pressed_skin;
fade();
emit pressed();
}
else
{
// m_current_skin = m_normal_skin; // no fade code
m_toggle = false;
if (hasMouse() ) {
m_fadePix = m_over_skin;
}else {
m_fadePix = m_normal_skin;
}
fade();
emit hideMenu();
}
emit clicked ();
}
if ( e->button() == Qt::RightButton )
{
m_fadePix = m_normal_skin;
fade();
m_toggle = false;
TQPopupMenu *popup = new TQPopupMenu();
popup->insertItem ( SmallIcon ( "remove" ), i18n ( "Remove KBFX from Pannel" ),
this, TQT_SLOT ( selfDeleter() ) );
popup->insertItem ( SmallIcon ( "reload" ),i18n ( "Reload KBFX" ),
this, TQT_SLOT ( reloadConfig() ) );
popup->insertSeparator();
popup->insertItem ( SmallIcon ( "kbfxconfigapp" ), i18n ( "Configure KBFX" ),
this, TQT_SLOT ( openConfigDialog() ) );
popup->insertItem ( SmallIcon ( "kmenuedit" ),i18n ( "Edit Applications Menu" ),
this, TQT_SLOT ( openKmenuEdit() ) );
popup->exec ( e->globalPos() );
delete popup;
}
}
void KbfxButton::reloadConfig()
{
/*
DCOPRef m_kickerkbfxDevelnterface ( "kicker","KBFXInterface" );
m_kickerkbfxDevelnterface.call ( "notifyConfigChange()" );
m_kickerkbfxDevelnterface.call ( "notifyConfigChange()" );
*/
DCOPRef m_kickerPanel("kicker", findPanel());
m_kickerPanel.call("restart()");
}
void KbfxButton::selfDeleter()
{
DCOPRef m_kickerPanel ( "kicker", findPanel() );
TQStringList returnTQStringList =m_kickerPanel.call ( "listApplets()" );
int _myIndex = 0;
TQStringList::Iterator it;
for ( it = returnTQStringList.begin();it != returnTQStringList.end();it++ )
{
if ( ( *it ).tqcontains ( "kbfx" ) )
{
break;
}
else
_myIndex++;
}
m_kickerPanel.call ( "removeApplet(int)", _myIndex );
}
void KbfxButton::openKmenuEdit()
{
#ifdef HAVE_MANDRAKE
KRun::runCommand ( "menudrake" );
#else
KRun::runCommand ( "kmenuedit" );
#endif
}
void KbfxButton::openConfigDialog()
{
KRun::runCommand ( "kbfxconfigapp" );
}
void KbfxButton::paintEvent ( TQPaintEvent * pe )
{
TQPainter p;
if ( !m_current_skin.isNull () )
{
TQRect r = TQRect ( pe->rect().x(),pe->rect().y(),m_current_skin.width(),m_current_skin.height() );
m_buffer = new TQPixmap();
m_buffer->resize ( r.size() );
m_buffer->fill ( this, r.topLeft() );
p.tqbegin ( m_buffer,this );
p.translate ( -r.x(), -r.y() );
p.drawPixmap ( r,m_current_skin );
p.end ();
bitBlt ( this, r.x(), r.y(),m_buffer, 0, 0,m_current_skin.width(), m_current_skin.height() );
delete m_buffer;
}
}
void KbfxButton::dragEnterEvent ( TQDragEnterEvent * e )
{
e->accept ( TQUriDrag::canDecode ( e ) );
kdDebug() << "Accepting KBFX button drag..." << endl;
}
void KbfxButton::dropEvent ( TQDropEvent * e )
{
TQStringList filelist;
TQString _hover, _normal, _pressed, _tmp;
TQImage _hover_pix, _normal_pix, _pressed_pix;
TQUriDrag::decodeLocalFiles ( e, filelist );
for ( TQStringList::Iterator it = filelist.begin(); it != filelist.end(); ++it )
{
_tmp = ( *it );
kdDebug() << "KBFX button dropped file: " << _tmp << endl;
if ( _tmp.tqcontains ( "hover", FALSE ) > 0 )
{
_hover = _tmp;
_hover_pix = TQImage ( _tmp );
}
if ( _tmp.tqcontains ( "normal", FALSE ) > 0 )
{
_normal = _tmp;
_normal_pix = TQImage ( _tmp );
}
if ( _tmp.tqcontains ( "pressed", FALSE ) > 0 )
{
_pressed = _tmp;
_pressed_pix = TQImage ( _tmp );
}
}
kdDebug() << "KBFX button hover: " << _hover << endl
<< "KBFX button normal: " << _normal << endl
<< "KBFX button pressed: " << _pressed << endl;
if ( _hover_pix.isNull () ||
_normal_pix.isNull () ||
_pressed_pix.isNull () )
{
KMessageBox::error ( 0,
tr2i18n ( "Invalid images were dropped!"
"\nCannot set the KBFX button to use these images!" ),
tr2i18n ( "Error setting KBFX button images" ) );
return;
}
ConfigInit ().m_KbfxNormalButtonPath = _normal;
ConfigInit ().m_KbfxHoverButtonPath = _hover;
ConfigInit ().m_KbfxPressedButtonPath = _pressed;
ConfigInit().writeThemerc ( ConfigInit().m_SpinxThemeName );
/* Init normal size first */
m_kicker_auto_adjust = TRUE;
loadSkins();
m_kicker_auto_adjust = ConfigInit().m_ToolBarResize;
}
#include "kbfxbutton.moc"
|