~ubuntu-branches/ubuntu/dapper/psi/dapper

« back to all changes in this revision

Viewing changes to libpsi/psiwidgets/iconwidget.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2004-06-15 00:10:41 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040615001041-enywb6pcpe4sjsw6
Tags: 0.9.2-1
* New upstream release
* Set KDEDIR for ./configure so kde specific files get installed
* Don't install libpsiwidgets.so. It got installed in /usr/share
  where it doesn't belong. May be included (at a better location)
  later.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * iconwidget.cpp - misc. Iconset- and Icon-aware widgets
 
3
 * Copyright (C) 2003  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 "iconwidget.h"
 
22
 
 
23
#include <qapplication.h>
 
24
#include <qpainter.h>
 
25
 
 
26
#ifndef WIDGET_PLUGIN
 
27
#       include "iconset.h"
 
28
#       include <qstyle.h>
 
29
#       include <qbitmap.h>
 
30
#       include <qmap.h>
 
31
#else
 
32
#       include <qimage.h>
 
33
 
 
34
static const char *cancel_xpm[] = {
 
35
"22 22 60 1",
 
36
"       c None",
 
37
".      c #E84300",
 
38
"+      c #E63F00",
 
39
"@      c #D11E00",
 
40
"#      c #D11B00",
 
41
"$      c #F69D50",
 
42
"%      c #F59A4D",
 
43
"&      c #E23800",
 
44
"*      c #EE5F1F",
 
45
"=      c #ED5A1D",
 
46
"-      c #CD1700",
 
47
";      c #FECBA2",
 
48
">      c #FEC69A",
 
49
",      c #F39045",
 
50
"'      c #DE3200",
 
51
")      c #FE7B3C",
 
52
"!      c #FE7234",
 
53
"~      c #EC4C15",
 
54
"{      c #CC1100",
 
55
"]      c #FEC091",
 
56
"^      c #FEBA89",
 
57
"/      c #F2873D",
 
58
"(      c #DA2C00",
 
59
"_      c #FE692C",
 
60
":      c #EB4712",
 
61
"<      c #CA0F00",
 
62
"[      c #FEB480",
 
63
"}      c #FEAE78",
 
64
"|      c #F07D35",
 
65
"1      c #D62600",
 
66
"2      c #FEA870",
 
67
"3      c #FEA166",
 
68
"4      c #EF722D",
 
69
"5      c #D32100",
 
70
"6      c #FE9B5F",
 
71
"7      c #FE9356",
 
72
"8      c #F16C2A",
 
73
"9      c #F16525",
 
74
"0      c #FE8B4D",
 
75
"a      c #FE8445",
 
76
"b      c #EE4B15",
 
77
"c      c #FE6025",
 
78
"d      c #EE4310",
 
79
"e      c #C90E00",
 
80
"f      c #FE561D",
 
81
"g      c #FE4B16",
 
82
"h      c #EA2F08",
 
83
"i      c #C70900",
 
84
"j      c #FE4010",
 
85
"k      c #FE350B",
 
86
"l      c #EA1D03",
 
87
"m      c #C60700",
 
88
"n      c #FE2906",
 
89
"o      c #FE1A02",
 
90
"p      c #E90900",
 
91
"q      c #C50300",
 
92
"r      c #FE0A00",
 
93
"s      c #FE0000",
 
94
"t      c #E90000",
 
95
"u      c #C40000",
 
96
"                      ",
 
97
"                      ",
 
98
"    .+          @#    ",
 
99
"   .$%&        @*=-   ",
 
100
"  .$;>,'      @*)!~{  ",
 
101
"  +%>]^/(    @*)!_:<  ",
 
102
"   &,^[}|1  @*)!_:<   ",
 
103
"    '/}2345@*)!_:<    ",
 
104
"     (|36789)!_:<     ",
 
105
"      1470a)!_:<      ",
 
106
"       58a)!_b<       ",
 
107
"       @9)!_cde       ",
 
108
"      @*)!_cfghi      ",
 
109
"     @*)!_bdgjklm     ",
 
110
"    @*)!_:<ehknopq    ",
 
111
"   @*)!_:<  ilorstu   ",
 
112
"  @*)!_:<    mpssstu  ",
 
113
"  #=!_:<      qtsstu  ",
 
114
"   -~:<        uttu   ",
 
115
"    {<          uu    ",
 
116
"                      ",
 
117
"                      "};
 
118
 
 
119
// dammit MSVC6
 
120
class Iconset {
 
121
public:
 
122
        Iconset() { }
 
123
};
 
124
#endif
 
125
 
 
126
//----------------------------------------------------------------------------
 
127
// IconsetSelect
 
128
//----------------------------------------------------------------------------
 
129
 
 
130
class IconsetSelectItem : public IconWidgetItem
 
131
{
 
132
        Q_OBJECT
 
133
private:
 
134
        static const int margin;
 
135
        static const int displayNumIcons;
 
136
#ifndef WIDGET_PLUGIN
 
137
        Iconset iss;
 
138
        QMap<Icon*, QRect> iconRects;
 
139
#endif
 
140
        int w, h;
 
141
        mutable int fullW, fullH;
 
142
 
 
143
public:
 
144
        IconsetSelectItem(QListBox *parent, IconsetSelectItem *after, const Iconset &_iconset)
 
145
        : IconWidgetItem(parent, after)
 
146
        {
 
147
#ifndef WIDGET_PLUGIN
 
148
                iss = _iconset;
 
149
                setText( iss.name() );
 
150
 
 
151
                w = margin;
 
152
                h = 2*margin;
 
153
 
 
154
                int count;
 
155
 
 
156
                QPtrListIterator<Icon> it = iss.iterator();
 
157
                for (count = 0; it.current(); ++it) {
 
158
                        if ( count++ >= displayNumIcons )
 
159
                                break; // display only first displayNumIcons icons
 
160
 
 
161
                        QPixmap pix = it.current()->pixmap();
 
162
 
 
163
                        iconRects[it.current()] = QRect( w, margin, pix.width(), pix.height() );
 
164
 
 
165
                        w += pix.width() + margin;
 
166
                        h = QMAX( h, pix.height() + 2*margin );
 
167
 
 
168
                        connect (it.current(), SIGNAL(pixmapChanged(const QPixmap &)), SLOT(iconUpdated(const QPixmap &)));
 
169
                        it.current()->activated(false); // start animation
 
170
                }
 
171
 
 
172
                QMap<Icon*, QRect>::Iterator it2;
 
173
                for (it2 = iconRects.begin(); it2 != iconRects.end(); it2++) {
 
174
                        QRect r = it2.data();
 
175
                        it2.data() = QRect( r.x(), (h - r.height())/2, r.width(), r.height() );
 
176
                }
 
177
#endif
 
178
        }
 
179
 
 
180
        ~IconsetSelectItem()
 
181
        {
 
182
#ifndef WIDGET_PLUGIN
 
183
                QMap<Icon*, QRect>::Iterator it;
 
184
                for (it = iconRects.begin(); it != iconRects.end(); it++)
 
185
                        it.key()->stop();
 
186
#endif
 
187
        }
 
188
 
 
189
        const Iconset *iconset() const
 
190
        {
 
191
#ifndef WIDGET_PLUGIN
 
192
                return &iss;
 
193
#else
 
194
                return 0;
 
195
#endif
 
196
        }
 
197
 
 
198
        int height( const QListBox *lb ) const
 
199
        {
 
200
                fullH = lb->fontMetrics().lineSpacing() + 2 + h;
 
201
                return QMAX( fullH, QApplication::globalStrut().height() );
 
202
        }
 
203
 
 
204
        int width( const QListBox *lb ) const
 
205
        {
 
206
                fullW = QMAX(lb->fontMetrics().width( text() ) + 6, w + 10);
 
207
                return QMAX( fullW, QApplication::globalStrut().width() );
 
208
        }
 
209
 
 
210
        void paint(QPainter *painter)
 
211
        {
 
212
#ifndef WIDGET_PLUGIN
 
213
                QFontMetrics fm = painter->fontMetrics();
 
214
                painter->drawText( 3, fm.ascent() + (fm.leading()+1)/2 + 1, text() );
 
215
 
 
216
                QMap<Icon*, QRect>::Iterator it;
 
217
                for (it = iconRects.begin(); it != iconRects.end(); it++) {
 
218
                        Icon *icon = it.key();
 
219
                        QRect r = it.data();
 
220
                        painter->drawPixmap(QPoint(10 + r.left(), fm.lineSpacing() + 2 + r.top()), icon->pixmap());
 
221
                }
 
222
#else
 
223
                Q_UNUSED(painter);
 
224
#endif
 
225
        }
 
226
 
 
227
private slots:
 
228
        void iconUpdated(const QPixmap &)
 
229
        {
 
230
#ifndef WIDGET_PLUGIN
 
231
                IconsetSelect *issel = (IconsetSelect *)listBox();
 
232
                issel->updateItem (this);
 
233
#endif
 
234
        }
 
235
};
 
236
const int IconsetSelectItem::margin = 3;
 
237
const int IconsetSelectItem::displayNumIcons = 10;
 
238
 
 
239
class IconsetSelect::Private
 
240
{
 
241
public:
 
242
        Private()
 
243
        {
 
244
                lastItem = 0;
 
245
        }
 
246
 
 
247
        IconsetSelectItem *lastItem;
 
248
};
 
249
 
 
250
IconsetSelect::IconsetSelect(QWidget *parent, const char *name)
 
251
: QListBox(parent, name)
 
252
{
 
253
        d = new Private;
 
254
}
 
255
 
 
256
IconsetSelect::~IconsetSelect()
 
257
{
 
258
        delete d;
 
259
}
 
260
 
 
261
void IconsetSelect::insert(const Iconset &iconset)
 
262
{
 
263
#ifndef WIDGET_PLUGIN
 
264
        IconsetSelectItem *item = new IconsetSelectItem(this, d->lastItem, iconset);
 
265
        d->lastItem = item;
 
266
#else
 
267
        Q_UNUSED(iconset);
 
268
#endif
 
269
}
 
270
 
 
271
void IconsetSelect::moveItemUp()
 
272
{
 
273
        if ( currentItem() < 1 )
 
274
                return;
 
275
 
 
276
        IconsetSelectItem *i = (IconsetSelectItem *)item(currentItem());
 
277
        if ( !i )
 
278
                return;
 
279
        QListBoxItem *prev = i->prev()->prev();
 
280
        takeItem (i);
 
281
        insertItem (i, prev);
 
282
        setSelected (i, true);
 
283
        setCurrentItem (i);
 
284
}
 
285
 
 
286
void IconsetSelect::moveItemDown()
 
287
{
 
288
        if ( currentItem() == -1 || currentItem() > (int)count() - 2 )
 
289
                return;
 
290
 
 
291
        IconsetSelectItem *i = (IconsetSelectItem *)item(currentItem());
 
292
        if ( !i )
 
293
                return;
 
294
        QListBoxItem *next = i->next();
 
295
        takeItem (i);
 
296
        insertItem (i, next);
 
297
        setCurrentItem (i);
 
298
}
 
299
 
 
300
const Iconset *IconsetSelect::iconset() const
 
301
{
 
302
        IconsetSelectItem *i = (IconsetSelectItem *)selectedItem();
 
303
        if ( !i )
 
304
                i = (IconsetSelectItem *)item(currentItem());
 
305
        if ( i )
 
306
                return i->iconset();
 
307
        return 0;
 
308
}
 
309
 
 
310
void IconsetSelect::paintCell(QPainter *p, int row, int col)
 
311
{
 
312
        // we'll do some caching to avoid flicker
 
313
        QListBoxItem *item = QListBox::item(row);
 
314
 
 
315
        if ( !item ) {
 
316
                QListBox::paintCell(p, row, col);
 
317
                return;
 
318
        }
 
319
 
 
320
        int w = contentsWidth();
 
321
        int h = item->height(this);
 
322
        QPixmap pix(w, h);
 
323
        QPainter p2;
 
324
        p2.begin (&pix);
 
325
        QListBox::paintCell(&p2, row, col);
 
326
        p2.end ();
 
327
 
 
328
        p->drawPixmap(QPoint(0, 0), pix);
 
329
}
 
330
 
 
331
 
 
332
//----------------------------------------------------------------------------
 
333
// IconsetDisplay
 
334
//----------------------------------------------------------------------------
 
335
 
 
336
class IconsetDisplayItem : public IconWidgetItem
 
337
{
 
338
        Q_OBJECT
 
339
private:
 
340
        static const int margin;
 
341
        Icon *icon;
 
342
        int w, h;
 
343
 
 
344
public:
 
345
        IconsetDisplayItem(QListBox *parent, IconsetDisplayItem *after, Icon *i, int iconW)
 
346
        : IconWidgetItem(parent, after)
 
347
        {
 
348
#ifndef WIDGET_PLUGIN
 
349
                icon = i;
 
350
                w = iconW;
 
351
 
 
352
                connect (icon, SIGNAL(pixmapChanged(const QPixmap &)), SLOT(iconUpdated(const QPixmap &)));
 
353
                icon->activated(false);
 
354
 
 
355
                h = icon->pixmap().height();
 
356
 
 
357
                QString str;
 
358
                QDictIterator<QString> it ( icon->text() );
 
359
                for ( ; it.current(); ++it) {
 
360
                        if ( !str.isEmpty() )
 
361
                                str += ", ";
 
362
                        str += **it;
 
363
                }
 
364
                if ( !str.isEmpty() )
 
365
                        setText(str);
 
366
                else
 
367
                        setText(tr("Name: '%1'").arg(icon->name()));
 
368
#endif
 
369
        }
 
370
 
 
371
        ~IconsetDisplayItem()
 
372
        {
 
373
#ifndef WIDGET_PLUGIN
 
374
                icon->stop();
 
375
#endif
 
376
        }
 
377
 
 
378
        int height( const QListBox *lb ) const
 
379
        {
 
380
                int hh = QMAX(h + 2*margin, lb->fontMetrics().lineSpacing() + 2);
 
381
                return QMAX( hh, QApplication::globalStrut().height() );
 
382
        }
 
383
 
 
384
        int width( const QListBox *lb ) const
 
385
        {
 
386
                int ww = lb->fontMetrics().width( text() ) + 6 + w + 2*margin;
 
387
                return QMAX( ww, QApplication::globalStrut().width() );
 
388
        }
 
389
 
 
390
        void paint(QPainter *painter)
 
391
        {
 
392
#ifndef WIDGET_PLUGIN
 
393
                painter->drawPixmap(QPoint((2*margin+w - icon->pixmap().width())/2, margin), icon->pixmap());
 
394
                QFontMetrics fm = painter->fontMetrics();
 
395
                //int hh = QMAX(h + 2*margin, fm.lineSpacing() + 2);
 
396
                painter->drawText( w + 2*margin + 3, fm.ascent() + (fm.leading()+1)/2 + 1, text() );
 
397
                //painter->drawText( w + 2*margin + 3, (hh - fm.lineSpacing())/2, text() );
 
398
#else
 
399
                Q_UNUSED(painter);
 
400
#endif
 
401
        }
 
402
 
 
403
private slots:
 
404
        void iconUpdated(const QPixmap &)
 
405
        {
 
406
                IconsetDisplay *issel = (IconsetDisplay *)listBox();
 
407
                issel->updateItem (this);
 
408
        }
 
409
};
 
410
const int IconsetDisplayItem::margin = 3;
 
411
 
 
412
class IconsetDisplay::Private
 
413
{
 
414
public:
 
415
        Private()
 
416
        {
 
417
                lastItem = 0;
 
418
        }
 
419
 
 
420
        IconsetDisplayItem *lastItem;
 
421
};
 
422
 
 
423
IconsetDisplay::IconsetDisplay(QWidget *parent, const char *name)
 
424
: QListBox(parent, name, WStaticContents | WResizeNoErase | WRepaintNoErase)
 
425
{
 
426
        d = new Private;
 
427
}
 
428
 
 
429
IconsetDisplay::~IconsetDisplay()
 
430
{
 
431
        delete d;
 
432
}
 
433
 
 
434
void IconsetDisplay::setIconset(const Iconset &iconset)
 
435
{
 
436
#ifndef WIDGET_PLUGIN
 
437
        int w = 0;
 
438
        QPtrListIterator<Icon> it = iconset.iterator();
 
439
        for ( ; it.current(); ++it) {
 
440
                w = QMAX(w, it.current()->pixmap().width());
 
441
        }
 
442
 
 
443
        it = iconset.iterator();
 
444
        for ( ; it.current(); ++it) {
 
445
                IconsetDisplayItem *item = new IconsetDisplayItem(this, d->lastItem, it.current(), w);
 
446
                d->lastItem = item;
 
447
        }
 
448
#else
 
449
        Q_UNUSED(iconset);
 
450
#endif
 
451
}
 
452
 
 
453
void IconsetDisplay::paintCell(QPainter *p, int row, int col)
 
454
{
 
455
        // we'll do some caching to avoid flicker
 
456
        QListBoxItem *item = QListBox::item(row);
 
457
 
 
458
        if ( !item ) {
 
459
                QListBox::paintCell(p, row, col);
 
460
                return;
 
461
        }
 
462
 
 
463
        int w = contentsWidth();
 
464
        int h = item->height(this);
 
465
        QPixmap pix(w, h);
 
466
        QPainter p2;
 
467
        p2.begin (&pix);
 
468
        QListBox::paintCell(&p2, row, col);
 
469
        p2.end ();
 
470
 
 
471
        p->drawPixmap(QPoint(0, 0), pix);
 
472
}
 
473
 
 
474
 
 
475
//----------------------------------------------------------------------------
 
476
// IconButton
 
477
//----------------------------------------------------------------------------
 
478
 
 
479
class IconButton::Private : public QObject
 
480
{
 
481
        Q_OBJECT
 
482
public:
 
483
        Icon *icon;
 
484
        IconButton *button;
 
485
        bool textVisible;
 
486
        bool activate, forced;
 
487
#ifdef WIDGET_PLUGIN
 
488
        QString iconName;
 
489
#endif
 
490
 
 
491
public:
 
492
        Private(IconButton *b)
 
493
        {
 
494
                icon = 0;
 
495
                button = b;
 
496
                textVisible = true;
 
497
                forced = false;
 
498
        }
 
499
 
 
500
        ~Private()
 
501
        {
 
502
                iconStop();
 
503
        }
 
504
 
 
505
        void setIcon(Icon *i)
 
506
        {
 
507
#ifndef WIDGET_PLUGIN
 
508
                iconStop();
 
509
                if ( i )
 
510
                        icon = new Icon(*i);
 
511
                iconStart();
 
512
#endif
 
513
        }
 
514
 
 
515
        void iconStart()
 
516
        {
 
517
#ifndef WIDGET_PLUGIN
 
518
                if ( icon ) {
 
519
                        connect(icon, SIGNAL(pixmapChanged(const QPixmap &)), SLOT(iconUpdated(const QPixmap &)));
 
520
                        if ( activate )
 
521
                                icon->activated(true); // FIXME: should icon play sound when it's activated on button?
 
522
                        iconUpdated( icon->pixmap() );
 
523
                }
 
524
                else
 
525
                        iconUpdated( QPixmap() );
 
526
#endif
 
527
        }
 
528
 
 
529
        void iconStop()
 
530
        {
 
531
#ifndef WIDGET_PLUGIN
 
532
                if ( icon ) {
 
533
                        disconnect(icon, 0, this, 0 );
 
534
                        if ( activate )
 
535
                                icon->stop();
 
536
 
 
537
                        delete icon;
 
538
                        icon = 0;
 
539
                }
 
540
#endif
 
541
        }
 
542
 
 
543
        void update()
 
544
        {
 
545
#ifndef WIDGET_PLUGIN
 
546
                if ( icon )
 
547
                        iconUpdated( icon->pixmap() );
 
548
#endif
 
549
        }
 
550
 
 
551
public slots:
 
552
        void iconUpdated(const QPixmap &pix)
 
553
        {
 
554
                button->setUpdatesEnabled(FALSE);
 
555
                if ( textVisible )
 
556
                        button->setIconSet(pix);
 
557
                else
 
558
                        button->setPixmap(pix);
 
559
                button->setUpdatesEnabled(TRUE);
 
560
                button->update();
 
561
        }
 
562
};
 
563
 
 
564
IconButton::IconButton(QWidget *parent, const char *name)
 
565
: QPushButton(parent, name)
 
566
{
 
567
        setWFlags(getWFlags() | WRepaintNoErase); // no nasty flicker anymore :)
 
568
        d = new Private(this);
 
569
}
 
570
 
 
571
IconButton::~IconButton()
 
572
{
 
573
        delete d;
 
574
}
 
575
 
 
576
void IconButton::setIcon(const QPixmap &p)
 
577
{
 
578
        QPushButton::setIcon(p);
 
579
}
 
580
 
 
581
void IconButton::forceSetIcon(const Icon *i, bool activate)
 
582
{
 
583
        d->activate = activate;
 
584
        d->setIcon ((Icon *)i);
 
585
        d->forced = true;
 
586
}
 
587
 
 
588
void IconButton::setIcon(const Icon *i, bool activate)
 
589
{
 
590
#ifndef Q_WS_X11
 
591
        if ( !text().isEmpty() )
 
592
                return;
 
593
#endif
 
594
 
 
595
        forceSetIcon(i, activate);
 
596
        d->forced = false;
 
597
}
 
598
 
 
599
void IconButton::setIcon(const QString &name)
 
600
{
 
601
#ifndef WIDGET_PLUGIN
 
602
        setIcon( IconsetFactory::iconPtr(name) );
 
603
#else
 
604
        d->iconName = name;
 
605
 
 
606
        if ( !name.isEmpty() ) {
 
607
                QPixmap pix((char **)cancel_xpm);
 
608
                d->iconUpdated(QPixmap( pix ));
 
609
        }
 
610
        else
 
611
                d->iconUpdated(QPixmap());
 
612
#endif
 
613
}
 
614
 
 
615
const QString &IconButton::iconName() const
 
616
{
 
617
#ifndef WIDGET_PLUGIN
 
618
        if ( d->icon )
 
619
                return d->icon->name();
 
620
        return QString::null;
 
621
#else
 
622
        return d->iconName;
 
623
#endif
 
624
}
 
625
 
 
626
void IconButton::setText(const QString &text)
 
627
{
 
628
#ifndef Q_WS_X11
 
629
        if ( !d->forced )
 
630
                setIcon(0);
 
631
#endif
 
632
 
 
633
        QPushButton::setText( text );
 
634
}
 
635
 
 
636
bool IconButton::textVisible() const
 
637
{
 
638
        return d->textVisible;
 
639
}
 
640
 
 
641
void IconButton::setTextVisible(bool v)
 
642
{
 
643
        d->textVisible = v;
 
644
        d->update();
 
645
}
 
646
 
 
647
void IconButton::drawButtonLabel(QPainter *p)
 
648
{
 
649
        QPushButton::drawButtonLabel(p);
 
650
}
 
651
 
 
652
//----------------------------------------------------------------------------
 
653
// IconToolButton
 
654
//----------------------------------------------------------------------------
 
655
 
 
656
class IconToolButton::Private : public QObject
 
657
{
 
658
        Q_OBJECT
 
659
public:
 
660
        Icon *icon;
 
661
        IconToolButton *button;
 
662
        bool activate;
 
663
#ifdef WIDGET_PLUGIN
 
664
        QString iconName;
 
665
#endif
 
666
 
 
667
public:
 
668
        Private(IconToolButton *b)
 
669
        {
 
670
                icon = 0;
 
671
                button = b;
 
672
        }
 
673
 
 
674
        ~Private()
 
675
        {
 
676
                iconStop();
 
677
        }
 
678
 
 
679
        void setIcon(Icon *i)
 
680
        {
 
681
#ifndef WIDGET_PLUGIN
 
682
                iconStop();
 
683
                if ( i )
 
684
                        icon = new Icon(*i);
 
685
                iconStart();
 
686
#endif
 
687
        }
 
688
 
 
689
        void iconStart()
 
690
        {
 
691
#ifndef WIDGET_PLUGIN
 
692
                if ( icon ) {
 
693
                        connect(icon, SIGNAL(pixmapChanged(const QPixmap &)), SLOT(iconUpdated(const QPixmap &)));
 
694
                        if ( activate )
 
695
                                icon->activated(true); // FIXME: should icon play sound when it's activated on button?
 
696
                        iconUpdated( icon->pixmap() );
 
697
                }
 
698
                else
 
699
                        iconUpdated( QPixmap() );
 
700
#endif
 
701
        }
 
702
 
 
703
        void iconStop()
 
704
        {
 
705
#ifndef WIDGET_PLUGIN
 
706
                if ( icon ) {
 
707
                        disconnect(icon, 0, this, 0 );
 
708
                        if ( activate )
 
709
                                icon->stop();
 
710
 
 
711
                        delete icon;
 
712
                        icon = 0;
 
713
                }
 
714
#endif
 
715
        }
 
716
 
 
717
        void update()
 
718
        {
 
719
#ifndef WIDGET_PLUGIN
 
720
                if ( icon )
 
721
                        iconUpdated( icon->pixmap() );
 
722
#endif
 
723
        }
 
724
 
 
725
private slots:
 
726
        void iconUpdated(const QPixmap &pix)
 
727
        {
 
728
                button->setUpdatesEnabled(FALSE);
 
729
                //if ( textVisible )
 
730
                        button->setIconSet(pix);
 
731
                //else
 
732
                //      button->setPixmap(pix);
 
733
                button->setUpdatesEnabled(TRUE);
 
734
                button->update();
 
735
        }
 
736
};
 
737
 
 
738
IconToolButton::IconToolButton(QWidget *parent, const char *name)
 
739
: QToolButton(parent, name)
 
740
{
 
741
        setWFlags(getWFlags() | WRepaintNoErase);
 
742
        d = new Private(this);
 
743
}
 
744
 
 
745
IconToolButton::~IconToolButton()
 
746
{
 
747
        delete d;
 
748
}
 
749
 
 
750
void IconToolButton::setIcon(const QPixmap &p)
 
751
{
 
752
        QToolButton::setIcon(p);
 
753
}
 
754
 
 
755
void IconToolButton::setIcon(const Icon *i, bool activate)
 
756
{
 
757
        d->activate = activate;
 
758
        d->setIcon ((Icon *)i);
 
759
}
 
760
 
 
761
void IconToolButton::setIcon(const QString &name)
 
762
{
 
763
#ifndef WIDGET_PLUGIN
 
764
        setIcon( IconsetFactory::iconPtr(name) );
 
765
#else
 
766
        d->iconName = name;
 
767
#endif
 
768
}
 
769
 
 
770
const QString &IconToolButton::iconName() const
 
771
{
 
772
#ifndef WIDGET_PLUGIN
 
773
        if ( d->icon )
 
774
                return d->icon->name();
 
775
        return QString::null;
 
776
#else
 
777
        return d->iconName;
 
778
#endif
 
779
}
 
780
 
 
781
void IconToolButton::drawButtonLabel(QPainter *p)
 
782
{
 
783
        QToolButton::drawButtonLabel(p);
 
784
}
 
785
 
 
786
#include "iconwidget.moc"