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
|
/*
* Copyright (C) 2006
* Siraj Razick <siraj@kdemail.net>
* PhobosK <phobosk@mail.kbfx.org>
* 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 "kbfxplasmacanvasitem.h"
KbfxPlasmaCanvasItem::KbfxPlasmaCanvasItem ( QCanvasPixmapArray * a , QCanvas * canvas ) :KbfxPlasmaCanvasAbstractItem ( a, canvas )
{
this->setItemMode ( 1 );
setAnimated ( false );
m_desktopFile = 0L;
m_isCurrent = false;
// m_pixmapArray = a;
QPixmap * _img = this->image ( 0 );
m_commentText ="No Comment Set By Plugin";
m_height =_img->height();
m_width =_img->width();
connect ( this,SIGNAL ( clicked() ),this,SLOT ( exec() ) );
m_type = OTHER;
// ConfigInit().read();
m_noComments = ConfigInit().m_noComments;
m_source = 0;
m_margin = ConfigInit().m_commentMargine;
m_lineColor = ConfigInit().m_lineColor;
m_iconSize = ConfigInit().m_iconSize;
m_commentColor = ConfigInit().m_fontAppCommentColor;
m_commentFont = ConfigInit().m_fontAppCommentFont;
m_fontAppNameColor = ConfigInit().m_fontAppNameColor;
m_fontAppNameFont = ConfigInit().m_fontAppNameFont;
m_sepNameFont = ConfigInit().m_sepNameFont;
m_boldFonts = ConfigInit().m_fontHoverBold;
}
KbfxPlasmaCanvasItem::~KbfxPlasmaCanvasItem()
{
setCanvas ( 0L );
}
/*
QCanvasPixmapArray * KbfxPlasmaCanvasItem::getPixmapArray()
{
return m_pixmapArray;
}
*/
void
KbfxPlasmaCanvasItem::setLabelText ( QString str )
{
QFont * _font = new QFont ( m_fontAppNameFont );
QFontMetrics fm ( *_font );
int _commentWidth = fm.width ( str+"..." );
int _strLen = str.length();
if ( _commentWidth > ( this->width() - m_margin ) )
{
for ( int i = 0; i < _strLen /*&& ( fm.width(str+"...") < width()-40 )*/ ;i++ )
{
str.truncate ( str.length()-2 );
if ( fm.width ( str+"..." ) < width() - m_margin )
break;
}
str+="...";
}
m_labelText = str ;
}
bool
KbfxPlasmaCanvasItem::lookup ( QString str )
{
if ( str.isNull() )
return false;
if ( m_type == SEPARATOR || m_type == INDEX )
return false;
if ( m_labelText.contains ( str,false ) > 0 )
return true;
if ( m_commentText.contains ( str,false ) > 0 )
return true;
if ( m_exec.contains ( str,false ) >0 )
return true;
return false;
}
void
KbfxPlasmaCanvasItem::setExec ( QString desktopfile )
{
m_desktopFile = new KDesktopFile ( desktopfile );
m_desktopFilePath = desktopfile;
bool check = m_desktopFile->isAuthorizedDesktopFile ( desktopfile );
setLabelText ( m_desktopFile->readName() );
setComment ( m_desktopFile->readComment() );
setIconPath ( m_desktopFile->readIcon() );
if ( check == 0 )
{
m_restricted = true;
m_error = "Adiministrator Blocked";
delete m_desktopFile;
return ;
}
delete m_desktopFile;
}
void
KbfxPlasmaCanvasItem::setIconPath ( QString str )
{
KIconLoader *iconload = KGlobal::iconLoader ();
m_iconPath = iconload->iconPath ( str, KIcon::Desktop, false );
// m_icon.load(m_iconPath);
QImage _img ( m_iconPath );
if ( _img.height() > 128 )
{
_img = _img.smoothScale ( 32,32 );
}
m_icon.convertFromImage ( _img );
}
void
KbfxPlasmaCanvasItem::setIcon ( QPixmap pixmap )
{
m_icon = pixmap;
}
void
KbfxPlasmaCanvasItem::setSource ( KbfxDataSource src )
{
m_source = new KbfxDataSource();
*m_source = src;
if ( src.type() == KbfxDataSource::DESKTOP )
{
this->setExec ( src.desktopFile () );
}
else
{
setLabelText ( src.name() );
setName ( src.name() );
setComment ( src.comment() );
setIconPath ( src.icon() );
}
}
void
KbfxPlasmaCanvasItem::hideit ()
{
m_hidden = 0;
this->hide ();
}
void
KbfxPlasmaCanvasItem::setType ( Type t )
{
m_type = t;
}
bool KbfxPlasmaCanvasItem::itemMode ()
{
return m_skined;
}
void
KbfxPlasmaCanvasItem::setItemMode ( bool mode )
{
m_skined = mode;
}
void
KbfxPlasmaCanvasItem::drawBackDrop ( QPainter * pe,QRect & r )
{
r = r ;
if ( pe == NULL )
return ;
}
/*
void
KbfxPlasmaCanvasItem::drawText(QPainter * pe,QString str)
{
}
*/
void
KbfxPlasmaCanvasItem::draw ( QPainter & pe )
{
drawContent ( &pe );
}
QPixmap
KbfxPlasmaCanvasItem::dragPixmap()
{
double _x = x();
double _y = y();
setX ( 0.0 );
setY ( 0.0 );
QPixmap dragpixmap ( this->width(),this->height() );
dragpixmap.fill ( QColor ( 255,255,255 ) );
QPainter p;
p.begin ( &dragpixmap );
this->drawContent ( &p );
p.end();
setX ( _x );
setY ( _y );
return dragpixmap;
}
void
KbfxPlasmaCanvasItem::drawContent ( QPainter * pe )
{
if ( m_isCurrent )
{
this->setFrame ( 1 );
}
else
{
this->setFrame ( 0 );
}
//int _currentFrame =
QCanvasPixmap *cp = this->image ( this->frame () );
m_height = cp->height();
m_width = cp->width();
//Draw the Background
if ( m_skined == true )
{
pe->drawPixmap ( this->boundingRect (), *cp );
}
else
{
pe->setPen ( QColor ( 91,178,62 ) );
pe->drawRect ( this->boundingRect() );
pe->setPen ( QColor ( 0,10,0 ) );
}
/**
We will split the Item box into two
**/
QRect tmp ( 0,0,0,0 );
//TODO: Should be read from kbfxconfig.cpp
//
QRect * rectTop = new QRect ( m_margin, ( int ) y(), cp->width() - m_margin, cp->height() /2 );
QRect * rectBot = new QRect ( m_margin, ( int ) y() + rectTop->height(), cp->width() - m_margin, cp->height() /2 );
///Draw Icon
//TODO::remover hard coded icon size : read from config
if ( !m_isCurrent )
pe->drawPixmap ( QRect ( ( m_margin-m_iconSize ) /2, ( int ) y() + ( cp->height()-m_iconSize ) /2,m_iconSize,m_iconSize ),m_icon );
else
pe->drawPixmap ( QRect ( ( m_margin-m_iconSize ) /2, ( int ) y() + ( cp->height()-m_iconSize ) /2,m_iconSize+2,m_iconSize+2 ),m_icon );
//End of DrawIcon
QFont * _font = new QFont ( m_fontAppNameFont );
QFont * _font_comment = new QFont ( m_commentFont );
QFont * _font_separator = new QFont ( m_sepNameFont );
pe->setFont ( *_font );
if ( this->type() == EXECUTABLE )
{
pe->setPen ( m_fontAppNameColor );
if ( m_noComments == false )
{
if ( m_isCurrent && m_boldFonts == true ) { _font->setBold ( true );pe->setFont ( *_font ); }
pe->drawText ( *rectTop, Qt::AlignLeft| Qt::AlignBottom ,QString ( m_labelText ), -1, &tmp,0 );
pe->setPen ( m_lineColor );
pe->drawLine ( m_margin, ( int ) y() + rectTop->height(), ( int ) cp->width() - 2, ( int ) y() + rectTop->height() );
pe->setFont ( *_font_comment );
pe->setPen ( m_commentColor );
pe->drawText ( *rectBot, Qt::AlignLeft| Qt::AlignTop ,QString ( m_commentText ), -1, &tmp,0 );
}
else
{
pe->drawText ( QRect ( m_margin+1, ( int ) y()+1,cp->width(),cp->height() ), Qt::AlignLeft | Qt::AlignVCenter ,QString ( m_labelText ), -1, &tmp,0 );
// pe->drawText ( QRect ( m_margin, ( int ) y(),cp->width(),cp->height() ), Qt::AlignLeft | Qt::AlignVCenter ,QString ( m_labelText ), -1, &tmp,0 );
}
}
else
{
if ( this->type() == SEPARATOR )
{
pe->setFont ( *_font_separator );
pe->setPen ( ConfigInit().m_sepNameColor );
}
else
{
pe->setPen ( m_fontAppNameColor );
}
pe->drawText ( QRect ( ( int ) x(), ( int ) y(),cp->width(),cp->height() ), Qt::AlignCenter ,QString ( m_labelText ), -1, &tmp,0 );
}
///Draw the line
delete rectTop;
delete rectBot;
delete _font;
delete _font_comment;
delete _font_separator;
}
void::KbfxPlasmaCanvasItem::setComment ( QString str )
{
QFont * _font = new QFont ( m_commentFont );
QFontMetrics fm ( *_font );
int _commentWidth = fm.width ( str+"..." );
int _strLen = str.length();
if ( _commentWidth > ( this->width()-m_margin ) )
{
for ( int i = 0; i < _strLen /*&& ( fm.width(str+"...") < width()-40 )*/ ;i++ )
{
str.truncate ( str.length()-2 );
if ( fm.width ( str+"..." ) < width()-m_margin )
break;
}
str+="...";
}
m_commentText = str;
}
void
KbfxPlasmaCanvasItem::advance ( int phase )
{
if ( phase == 0 )
{
setXVelocity ( 0 );
setYVelocity ( yVelocity () * 1 - 0.001 );
}
else
{
move ( x () + xVelocity (), y () + yVelocity () );
}
}
#include "kbfxplasmacanvasitem.moc"
|