~ubuntu-branches/ubuntu/karmic/psi/karmic

« back to all changes in this revision

Viewing changes to src/widgets/psiwidgets.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2008-04-14 18:57:30 UTC
  • mfrom: (2.1.9 hardy)
  • Revision ID: james.westby@ubuntu.com-20080414185730-528re3zp0m2hdlhi
Tags: 0.11-8
* added CONFIG -= link_prl to .pro files and removed dependencies
  which are made unnecessary by this change
* Fix segfault when closing last chat tab with qt4.4
  (This is from upstream svn, rev. 1101) (Closes: Bug#476122)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * psiwidgets.cpp - plugin for loading Psi's custom widgets into Qt Designer
 
3
 * Copyright (C) 2003-2005  Michail Pishchagin
 
4
 *
 
5
 * This library is free software; you can redistribute it and/or
 
6
 * modify it under the terms of the GNU Lesser General Public
 
7
 * License as published by the Free Software Foundation; either
 
8
 * version 2.1 of the License, or (at your option) any later version.
 
9
 *
 
10
 * This library is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
13
 * Lesser General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU Lesser General Public
 
16
 * License along with this library; if not, write to the Free Software
 
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
18
 *
 
19
 */
 
20
 
 
21
#include "psiwidgets.h"
 
22
 
 
23
#include "busywidget.h"
 
24
#include "fancylabel.h"
 
25
#include "iconwidget.h"
 
26
#include "iconlabel.h"
 
27
#include "iconbutton.h"
 
28
#include "iconsetselect.h"
 
29
#include "iconsetdisplay.h"
 
30
#include "icontoolbutton.h"
 
31
#include "urllabel.h"
 
32
#include "psitextview.h"
 
33
 
 
34
static const char *psiwidget_data[] = {
 
35
"16 16 5 1",
 
36
". c None",
 
37
"# c #000000",
 
38
"c c #57acda",
 
39
"b c #72bde6",
 
40
"a c #cde9f8",
 
41
".###..####..###.",
 
42
"#aaa#.#aa#.#aaa#",
 
43
"#abbb##ac##abcc#",
 
44
".##ab##ac##ac##.",
 
45
"..#abc#ac#abc#..",
 
46
"..#abc#ac#abc#..",
 
47
"..#abc#ac#abc#..",
 
48
"..#abc#ac#abc#..",
 
49
"..#abbbbbbbbc#..",
 
50
"...#abbbbbcc#...",
 
51
"....##cccc##....",
 
52
"......#ac#......",
 
53
"......#ac#......",
 
54
"......#ac#......",
 
55
"......#ac#......",
 
56
"......####......"};
 
57
 
 
58
//----------------------------------------------------------------------------
 
59
// PsiWidgetPlugin - base plugin class to avoid code duplication
 
60
//----------------------------------------------------------------------------
 
61
 
 
62
PsiWidgetPlugin::PsiWidgetPlugin( QObject *parent )
 
63
        : QObject( parent )
 
64
{
 
65
        initialized = false;
 
66
}
 
67
 
 
68
QWidget *PsiWidgetPlugin::createWidget(QWidget */* parent */)
 
69
{
 
70
        return 0;
 
71
}
 
72
 
 
73
QString PsiWidgetPlugin::name() const
 
74
{
 
75
        return "Psi Plugin";
 
76
}
 
77
 
 
78
QString PsiWidgetPlugin::group() const
 
79
{
 
80
        return "Psi";
 
81
}
 
82
 
 
83
QString PsiWidgetPlugin::toolTip() const
 
84
{
 
85
        return name();
 
86
}
 
87
 
 
88
QString PsiWidgetPlugin::whatsThis() const
 
89
{
 
90
        return "Psi Widget";
 
91
}
 
92
 
 
93
QString PsiWidgetPlugin::includeFile() const
 
94
{
 
95
        return "psiwidget.h";
 
96
}
 
97
 
 
98
QString PsiWidgetPlugin::codeTemplate() const
 
99
{
 
100
        return QString();
 
101
}
 
102
 
 
103
QString PsiWidgetPlugin::domXml() const
 
104
{
 
105
        return QString();
 
106
}
 
107
 
 
108
QIcon PsiWidgetPlugin::icon() const
 
109
{
 
110
        return QIconSet( QPixmap( (const char **)psiwidget_data ) );
 
111
}
 
112
 
 
113
bool PsiWidgetPlugin::isContainer() const
 
114
{
 
115
        return false;
 
116
}
 
117
 
 
118
void PsiWidgetPlugin::initialize( QDesignerFormEditorInterface * )
 
119
{
 
120
        if ( initialized )
 
121
                return;
 
122
 
 
123
        initialized = true;
 
124
}
 
125
 
 
126
bool PsiWidgetPlugin::isInitialized() const
 
127
{
 
128
        return initialized;
 
129
}
 
130
 
 
131
//----------------------------------------------------------------------------
 
132
// BusyWidgetPlugin
 
133
//----------------------------------------------------------------------------
 
134
 
 
135
class BusyWidgetPlugin : public PsiWidgetPlugin
 
136
{
 
137
        Q_OBJECT
 
138
public:
 
139
        BusyWidgetPlugin( QObject *parent = 0 )
 
140
                : PsiWidgetPlugin( parent )
 
141
        {
 
142
                // nothing to do
 
143
        }
 
144
 
 
145
        QWidget *createWidget(QWidget *parent)
 
146
        {
 
147
                return new BusyWidget( parent );
 
148
        }
 
149
 
 
150
        QString name() const
 
151
        {
 
152
                return "BusyWidget";
 
153
        }
 
154
 
 
155
        QString domXml() const
 
156
        {
 
157
                return "<widget class=\"BusyWidget\" name=\"busyWidget\">\n"
 
158
                       "</widget>\n";
 
159
        }
 
160
 
 
161
        QString whatsThis() const
 
162
        {
 
163
                return "Widget for indicating that program is doing something.";
 
164
        }
 
165
 
 
166
        QString includeFile() const
 
167
        {
 
168
                return "busywidget.h";
 
169
        }
 
170
};
 
171
 
 
172
 
 
173
//----------------------------------------------------------------------------
 
174
// IconLabelPlugin
 
175
//----------------------------------------------------------------------------
 
176
 
 
177
class IconLabelPlugin : public PsiWidgetPlugin
 
178
{
 
179
        Q_OBJECT
 
180
public:
 
181
        IconLabelPlugin( QObject *parent = 0 )
 
182
                : PsiWidgetPlugin( parent )
 
183
        {
 
184
                // nothing to do
 
185
        }
 
186
 
 
187
        QWidget *createWidget(QWidget *parent)
 
188
        {
 
189
                return new IconLabel( parent );
 
190
        }
 
191
 
 
192
        QString name() const
 
193
        {
 
194
                return "IconLabel";
 
195
        }
 
196
 
 
197
        QString domXml() const
 
198
        {
 
199
                return "<widget class=\"IconLabel\" name=\"iconLabel\">\n"
 
200
                       " <property name=\"geometry\">\n"
 
201
                       "  <rect>\n"
 
202
                       "   <x>0</x>\n"
 
203
                       "   <y>0</y>\n"
 
204
                       "   <width>100</width>\n"
 
205
                       "   <height>100</height>\n"
 
206
                       "  </rect>\n"
 
207
                       " </property>\n"
 
208
                       "</widget>\n";
 
209
        }
 
210
 
 
211
        QString whatsThis() const
 
212
        {
 
213
                return "Label that can contain animated PsiIcon.";
 
214
        }
 
215
 
 
216
        QString includeFile() const
 
217
        {
 
218
                return "iconlabel.h";
 
219
        }
 
220
};
 
221
 
 
222
//----------------------------------------------------------------------------
 
223
// FancyLabelPlugin
 
224
//----------------------------------------------------------------------------
 
225
 
 
226
class FancyLabelPlugin : public PsiWidgetPlugin
 
227
{
 
228
        Q_OBJECT
 
229
public:
 
230
        FancyLabelPlugin( QObject *parent = 0 )
 
231
                : PsiWidgetPlugin( parent )
 
232
        {
 
233
                // nothing to do
 
234
        }
 
235
 
 
236
        QWidget *createWidget(QWidget *parent)
 
237
        {
 
238
                return new FancyLabel( parent );
 
239
        }
 
240
 
 
241
        QString name() const
 
242
        {
 
243
                return "FancyLabel";
 
244
        }
 
245
 
 
246
        QString domXml() const
 
247
        {
 
248
                return "<widget class=\"FancyLabel\" name=\"fancyLabel\">\n"
 
249
                       " <property name=\"geometry\">\n"
 
250
                       "  <rect>\n"
 
251
                       "   <x>0</x>\n"
 
252
                       "   <y>0</y>\n"
 
253
                       "   <width>100</width>\n"
 
254
                       "   <height>100</height>\n"
 
255
                       "  </rect>\n"
 
256
                       " </property>\n"
 
257
                       "</widget>\n";
 
258
        }
 
259
 
 
260
        QString whatsThis() const
 
261
        {
 
262
                return "Just a Fancy Label. Use it for decoration of dialogs. ;-)";
 
263
        }
 
264
 
 
265
        QString includeFile() const
 
266
        {
 
267
                return "fancylabel.h";
 
268
        }
 
269
};
 
270
 
 
271
//----------------------------------------------------------------------------
 
272
// IconsetSelectPlugin
 
273
//----------------------------------------------------------------------------
 
274
 
 
275
class IconsetSelectPlugin : public PsiWidgetPlugin
 
276
{
 
277
        Q_OBJECT
 
278
public:
 
279
        IconsetSelectPlugin( QObject *parent = 0 )
 
280
                : PsiWidgetPlugin( parent )
 
281
        {
 
282
                // nothing to do
 
283
        }
 
284
 
 
285
        QWidget *createWidget(QWidget *parent)
 
286
        {
 
287
                return new IconsetSelect( parent );
 
288
        }
 
289
 
 
290
        QString name() const
 
291
        {
 
292
                return "IconsetSelect";
 
293
        }
 
294
 
 
295
        QString domXml() const
 
296
        {
 
297
                return "<widget class=\"IconsetSelect\" name=\"iconsetSelect\">\n"
 
298
                       "</widget>\n";
 
299
        }
 
300
 
 
301
        QString whatsThis() const
 
302
        {
 
303
                return "Widget for Iconset selection.";
 
304
        }
 
305
 
 
306
        QString includeFile() const
 
307
        {
 
308
                return "iconsetselect.h";
 
309
        }
 
310
};
 
311
 
 
312
//----------------------------------------------------------------------------
 
313
// IconsetDisplayPlugin
 
314
//----------------------------------------------------------------------------
 
315
 
 
316
class IconsetDisplayPlugin : public PsiWidgetPlugin
 
317
{
 
318
        Q_OBJECT
 
319
public:
 
320
        IconsetDisplayPlugin( QObject *parent = 0 )
 
321
                : PsiWidgetPlugin( parent )
 
322
        {
 
323
                // nothing to do
 
324
        }
 
325
 
 
326
        QWidget *createWidget(QWidget *parent)
 
327
        {
 
328
                return new IconsetDisplay( parent );
 
329
        }
 
330
 
 
331
        QString name() const
 
332
        {
 
333
                return "IconsetDisplay";
 
334
        }
 
335
 
 
336
        QString domXml() const
 
337
        {
 
338
                return "<widget class=\"IconsetDisplay\" name=\"iconsetDisplay\">\n"
 
339
                       "</widget>\n";
 
340
        }
 
341
 
 
342
        QString whatsThis() const
 
343
        {
 
344
                return "Displays all icons in Iconset.";
 
345
        }
 
346
 
 
347
        QString includeFile() const
 
348
        {
 
349
                return "iconsetdisplay.h";
 
350
        }
 
351
};
 
352
 
 
353
//----------------------------------------------------------------------------
 
354
// IconButtonPlugin
 
355
//----------------------------------------------------------------------------
 
356
 
 
357
class IconButtonPlugin : public PsiWidgetPlugin
 
358
{
 
359
        Q_OBJECT
 
360
public:
 
361
        IconButtonPlugin( QObject *parent = 0 )
 
362
                : PsiWidgetPlugin( parent )
 
363
        {
 
364
                // nothing to do
 
365
        }
 
366
 
 
367
        QWidget *createWidget(QWidget *parent)
 
368
        {
 
369
                return new IconButton( parent );
 
370
        }
 
371
 
 
372
        QString name() const
 
373
        {
 
374
                return "IconButton";
 
375
        }
 
376
 
 
377
        QString domXml() const
 
378
        {
 
379
                return "<widget class=\"IconButton\" name=\"iconButton\">\n"
 
380
                       "</widget>\n";
 
381
        }
 
382
 
 
383
        QString whatsThis() const
 
384
        {
 
385
                return "PushButton that can contain animated PsiIcon.";
 
386
        }
 
387
 
 
388
        QString includeFile() const
 
389
        {
 
390
                return "iconbutton.h";
 
391
        }
 
392
};
 
393
 
 
394
//----------------------------------------------------------------------------
 
395
// IconToolButtonPlugin
 
396
//----------------------------------------------------------------------------
 
397
 
 
398
class IconToolButtonPlugin : public PsiWidgetPlugin
 
399
{
 
400
        Q_OBJECT
 
401
public:
 
402
        IconToolButtonPlugin( QObject *parent = 0 )
 
403
                : PsiWidgetPlugin( parent )
 
404
        {
 
405
                // nothing to do
 
406
        }
 
407
 
 
408
        QWidget *createWidget(QWidget *parent)
 
409
        {
 
410
                return new IconToolButton( parent );
 
411
        }
 
412
 
 
413
        QString name() const
 
414
        {
 
415
                return "IconToolButton";
 
416
        }
 
417
 
 
418
        QString domXml() const
 
419
        {
 
420
                return "<widget class=\"IconToolButton\" name=\"iconToolButton\">\n"
 
421
                       "</widget>\n";
 
422
        }
 
423
 
 
424
        QString whatsThis() const
 
425
        {
 
426
                return "ToolButton that can contain animated PsiIcon.";
 
427
        }
 
428
 
 
429
        QString includeFile() const
 
430
        {
 
431
                return "icontoolbutton.h";
 
432
        }
 
433
};
 
434
 
 
435
//----------------------------------------------------------------------------
 
436
// PsiTextViewPlugin
 
437
//----------------------------------------------------------------------------
 
438
 
 
439
class PsiTextViewPlugin : public PsiWidgetPlugin
 
440
{
 
441
        Q_OBJECT
 
442
public:
 
443
        PsiTextViewPlugin( QObject *parent = 0 )
 
444
                : PsiWidgetPlugin( parent )
 
445
        {
 
446
                // nothing to do
 
447
        }
 
448
 
 
449
        QWidget *createWidget(QWidget *parent)
 
450
        {
 
451
                return new PsiTextView( parent );
 
452
        }
 
453
 
 
454
        QString name() const
 
455
        {
 
456
                return "PsiTextView";
 
457
        }
 
458
 
 
459
        QString domXml() const
 
460
        {
 
461
                return "<widget class=\"PsiTextView\" name=\"PsiTextView\">\n"
 
462
                       "</widget>\n";
 
463
        }
 
464
 
 
465
        QString whatsThis() const
 
466
        {
 
467
                return "Widget for displaying rich-text data, with inline Icons.";
 
468
        }
 
469
 
 
470
        QString includeFile() const
 
471
        {
 
472
                return "psitextview.h";
 
473
        }
 
474
};
 
475
 
 
476
 
 
477
//----------------------------------------------------------------------------
 
478
// URLLabelPlugin
 
479
//----------------------------------------------------------------------------
 
480
 
 
481
class URLLabelPlugin : public PsiWidgetPlugin
 
482
{
 
483
        Q_OBJECT
 
484
public:
 
485
        URLLabelPlugin( QObject *parent = 0 )
 
486
                : PsiWidgetPlugin( parent )
 
487
        {
 
488
                // nothing to do
 
489
        }
 
490
 
 
491
        QWidget *createWidget(QWidget *parent)
 
492
        {
 
493
                return new URLLabel( parent );
 
494
        }
 
495
 
 
496
        QString name() const
 
497
        {
 
498
                return "URLLabel";
 
499
        }
 
500
 
 
501
        QString domXml() const
 
502
        {
 
503
                return "<widget class=\"URLLabel\" name=\"URLLabel\">\n"
 
504
                       " <property name=\"url\">\n"
 
505
                       "  <string>http://host</string>\n"
 
506
                       " </property>\n"
 
507
                       " <property name=\"title\">\n"
 
508
                       "  <string>The Title</string>\n"
 
509
                       " </property>\n"
 
510
                       "</widget>\n";
 
511
        }
 
512
 
 
513
        QString whatsThis() const
 
514
        {
 
515
                return "Widget for displaying clickable URLs.";
 
516
        }
 
517
 
 
518
        QString includeFile() const
 
519
        {
 
520
                return "urllabel.h";
 
521
        }
 
522
};
 
523
 
 
524
//----------------------------------------------------------------------------
 
525
// AllPsiWidgetsPlugin
 
526
//----------------------------------------------------------------------------
 
527
 
 
528
class AllPsiWidgetsPlugin : public QObject, public QDesignerCustomWidgetCollectionInterface
 
529
{
 
530
        Q_OBJECT
 
531
        Q_INTERFACES(QDesignerCustomWidgetCollectionInterface)
 
532
public:
 
533
        AllPsiWidgetsPlugin(QObject *parent = 0)
 
534
                : QObject( parent )
 
535
        {
 
536
                plugins.append( new BusyWidgetPlugin( this ) );
 
537
                plugins.append( new IconLabelPlugin( this ) );
 
538
                plugins.append( new FancyLabelPlugin( this ) );
 
539
                plugins.append( new IconsetSelectPlugin( this ) );
 
540
                plugins.append( new IconsetDisplayPlugin( this ) );
 
541
                plugins.append( new IconButtonPlugin( this ) );
 
542
                plugins.append( new IconToolButtonPlugin( this ) );
 
543
                plugins.append( new PsiTextViewPlugin( this ) );
 
544
                plugins.append( new URLLabelPlugin( this ) );
 
545
        }
 
546
 
 
547
        virtual QList<QDesignerCustomWidgetInterface*> customWidgets() const
 
548
        {
 
549
                return plugins;
 
550
        }
 
551
 
 
552
private:
 
553
        QList<QDesignerCustomWidgetInterface*> plugins;
 
554
};
 
555
 
 
556
Q_EXPORT_PLUGIN( AllPsiWidgetsPlugin );
 
557
 
 
558
#include "psiwidgets.moc"