summaryrefslogtreecommitdiffstats
path: root/kcontrol/icons/icons.cpp
blob: 0e1e5154173f73e0f1387e8b509df82284d528b7 (plain)
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
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
/* vi: ts=8 sts=4 sw=4
 *
 * This file is part of the KDE project, module kcmdisplay.
 * Copyright (C) 2000 Geert Jansen <jansen@kde.org>
 * with minor additions and based on ideas from
 * Torsten Rahn <torsten@kde.org>                                                *
 *
 * You can Freely distribute this program under the GNU General Public
 * License. See the file "COPYING" for the exact licensing terms.
 */

#include <stdlib.h>

#include <tqcheckbox.h>
#include <tqcombobox.h>
#include <tqgroupbox.h>
#include <tqlabel.h>
#include <tqlayout.h>
#include <tqslider.h>

#include <kapplication.h>
#include <kcolorbutton.h>
#include <kconfig.h>
#include <kdebug.h>
#include <kiconeffect.h>
#include <kiconloader.h>
#include <kipc.h>
#include <klocale.h>
#include <kseparator.h>
#include <kglobalsettings.h>
#include <dcopclient.h>

#include "icons.h"

/**** KIconConfig ****/

KIconConfig::KIconConfig(TQWidget *parent, const char *name)
    : KCModule(parent, name)
{

    TQGridLayout *top = new TQGridLayout(this, 4, 2,
                                       KDialog::marginHint(),
                                       KDialog::spacingHint());
    top->setColStretch(0, 1);
    top->setColStretch(1, 1);

    // Use of Icon at (0,0) - (1, 0)
    TQGroupBox *gbox = new TQGroupBox(i18n("Use of Icon"), this);
    top->addMultiCellWidget(gbox, 0, 1, 0, 0);
    TQBoxLayout *g_vlay = new TQVBoxLayout(gbox,
                                        KDialog::marginHint(),
                                        KDialog::spacingHint());
    g_vlay->addSpacing(fontMetrics().lineSpacing());
    mpUsageList = new TQListBox(gbox);
    connect(mpUsageList, TQT_SIGNAL(highlighted(int)), TQT_SLOT(slotUsage(int)));
    g_vlay->addWidget(mpUsageList);

    KSeparator *sep = new KSeparator( KSeparator::HLine, this );
    top->addWidget(sep, 1, 1);
    // Preview at (2,0) - (2, 1)
    TQGridLayout *g_lay = new TQGridLayout(4, 3, KDialog::marginHint(), 0);
    top->addMultiCellLayout(g_lay, 2, 2, 0, 1);
    g_lay->addRowSpacing(0, fontMetrics().lineSpacing());

    TQPushButton *push;

    mPreviewButton1 = addPreviewIcon(0, i18n("Default"), this, g_lay);
    connect(mPreviewButton1, TQT_SIGNAL(clicked()), TQT_SLOT(slotEffectSetup0()));
    mPreviewButton2 = addPreviewIcon(1, i18n("Active"), this, g_lay);
    connect(mPreviewButton2, TQT_SIGNAL(clicked()), TQT_SLOT(slotEffectSetup1()));
    mPreviewButton3 = addPreviewIcon(2, i18n("Disabled"), this, g_lay);
    connect(mPreviewButton3, TQT_SIGNAL(clicked()), TQT_SLOT(slotEffectSetup2()));

    m_pTab1 = new TQWidget(this, "General Tab");
    top->addWidget(m_pTab1, 0, 1);

    TQGridLayout *grid = new TQGridLayout(m_pTab1, 4, 3, 10, 10);
    grid->setColStretch(1, 1);
    grid->setColStretch(2, 1);

    // Size
    TQLabel *lbl = new TQLabel(i18n("Size:"), m_pTab1);
    lbl->setFixedSize(lbl->sizeHint());
    grid->addWidget(lbl, 0, 0, Qt::AlignLeft);
    mpSizeBox = new TQComboBox(m_pTab1);
    connect(mpSizeBox, TQT_SIGNAL(activated(int)), TQT_SLOT(slotSize(int)));
    lbl->setBuddy(mpSizeBox);
    grid->addWidget(mpSizeBox, 0, 1, Qt::AlignLeft);

    mpDPCheck = new TQCheckBox(i18n("Double-sized pixels"), m_pTab1);
    connect(mpDPCheck, TQT_SIGNAL(toggled(bool)), TQT_SLOT(slotDPCheck(bool)));
    grid->addMultiCellWidget(mpDPCheck, 1, 1, 0, 1, Qt::AlignLeft);

    mpAnimatedCheck = new TQCheckBox(i18n("Animate icons"), m_pTab1);
    connect(mpAnimatedCheck, TQT_SIGNAL(toggled(bool)), TQT_SLOT(slotAnimatedCheck(bool)));
    grid->addMultiCellWidget(mpAnimatedCheck, 2, 2, 0, 1, Qt::AlignLeft);

    mpRoundedCheck = new TQCheckBox(i18n("Rounded text selection"), m_pTab1);
    connect(mpRoundedCheck, TQT_SIGNAL(toggled(bool)), TQT_SLOT(slotRoundedCheck(bool)));
    grid->addMultiCellWidget(mpRoundedCheck, 3, 3, 0, 1, Qt::AlignLeft);

    top->activate();

    mpSystrayConfig = new KSimpleConfig( TQString::fromLatin1( "systemtray_panelappletrc" ));
    mpKickerConfig = new KSimpleConfig( TQString::fromLatin1( "kickerrc" ));

    init();
    read();
    apply();
    preview();
}

KIconConfig::~KIconConfig()
{
  delete mpSystrayConfig;
  delete mpEffect;
}

TQPushButton *KIconConfig::addPreviewIcon(int i, const TQString &str, TQWidget *parent, TQGridLayout *lay)
{
    TQLabel *lab = new TQLabel(str, parent);
    lay->addWidget(lab, 1, i, AlignCenter);
    mpPreview[i] = new TQLabel(parent);
    mpPreview[i]->setAlignment(AlignCenter);
    mpPreview[i]->setMinimumSize(105, 105);
    lay->addWidget(mpPreview[i], 2, i);
    TQPushButton *push = new TQPushButton(i18n("Set Effect..."), parent);
    lay->addWidget(push, 3, i, AlignCenter);
    return push;
}

void KIconConfig::init()
{
    mpLoader = KGlobal::iconLoader();
    mpConfig = KGlobal::config();
    mpEffect = new KIconEffect;
    mpTheme = mpLoader->theme();
    mUsage = 0;
    for (int i=0; i<KIcon::LastGroup; i++)
	mbChanged[i] = false;

    // Fill list/checkboxen
    mpUsageList->insertItem(i18n("Desktop/File Manager"));
    mpUsageList->insertItem(i18n("Toolbar"));
    mpUsageList->insertItem(i18n("Main Toolbar"));
    mpUsageList->insertItem(i18n("Small Icons"));
    mpUsageList->insertItem(i18n("Panel"));
    mpUsageList->insertItem(i18n("All Icons"));
    mpUsageList->insertItem(i18n("Panel Buttons"));
    mpUsageList->insertItem(i18n("System Tray Icons"));

    // For reading the configuration
    mGroups += "Desktop";
    mGroups += "Toolbar";
    mGroups += "MainToolbar";
    mGroups += "Small";
    mGroups += "Panel";

    mStates += "Default";
    mStates += "Active";
    mStates += "Disabled";
}

void KIconConfig::initDefaults()
{
    mDefaultEffect[0].type = KIconEffect::NoEffect;
    mDefaultEffect[1].type = KIconEffect::NoEffect;
    mDefaultEffect[2].type = KIconEffect::ToGray;
    mDefaultEffect[0].transparant = false;
    mDefaultEffect[1].transparant = false;
    mDefaultEffect[2].transparant = true;
    mDefaultEffect[0].value = 1.0;
    mDefaultEffect[1].value = 1.0;
    mDefaultEffect[2].value = 1.0;
    mDefaultEffect[0].color = TQColor(144,128,248);
    mDefaultEffect[1].color = TQColor(169,156,255);
    mDefaultEffect[2].color = TQColor(34,202,0);
    mDefaultEffect[0].color2 = TQColor(0,0,0);
    mDefaultEffect[1].color2 = TQColor(0,0,0);
    mDefaultEffect[2].color2 = TQColor(0,0,0);

    const int defDefSizes[] = { 32, 22, 22, 16, 32 };

    KIcon::Group i;
    TQStringList::ConstIterator it;
    for(it=mGroups.begin(), i=KIcon::FirstGroup; it!=mGroups.end(); ++it, i++)
    {
	mbDP[i] = false;
	mbChanged[i] = true;
	mbAnimated[i] = false;
	if (mpTheme)
	    mSizes[i] = mpTheme->defaultSize(i);
	else
	    mSizes[i] = defDefSizes[i];

	mEffects[i][0] = mDefaultEffect[0];
	mEffects[i][1] = mDefaultEffect[1];
	mEffects[i][2] = mDefaultEffect[2];
    }
    // Animate desktop icons by default
    int group = mGroups.findIndex( "Desktop" );
    if ( group != -1 )
        mbAnimated[group] = true;

    // This is the new default in KDE 2.2, in sync with the kiconeffect of kdelibs Nolden 2001/06/11
    int activeState = mStates.findIndex( "Active" );
    if ( activeState != -1 )
    {
        int group = mGroups.findIndex( "Desktop" );
        if ( group != -1 )
        {
            mEffects[ group ][ activeState ].type = KIconEffect::ToGamma;
            mEffects[ group ][ activeState ].value = 0.7;
        }

        group = mGroups.findIndex( "Panel" );
        if ( group != -1 )
        {
            mEffects[ group ][ activeState ].type = KIconEffect::ToGamma;
            mEffects[ group ][ activeState ].value = 0.7;
        }
    }
}

void KIconConfig::read()
{
    if (mpTheme)
    {
        for (KIcon::Group i=KIcon::FirstGroup; i<KIcon::LastGroup; i++)
            mAvSizes[i] = mpTheme->querySizes(i);

        mTheme = mpTheme->current();
        mExample = mpTheme->example();
    }
    else
    {
        for (KIcon::Group i=KIcon::FirstGroup; i<KIcon::LastGroup; i++)
            mAvSizes[i] = TQValueList<int>();

        mTheme = TQString::null;
        mExample = TQString::null;
    }

    initDefaults();

    int i, j, effect;
    TQStringList::ConstIterator it, it2;
    for (it=mGroups.begin(), i=0; it!=mGroups.end(); ++it, i++)
    {
        mbChanged[i] = false;

	mpConfig->setGroup(*it + "Icons");
	mSizes[i] = mpConfig->readNumEntry("Size", mSizes[i]);
	mbDP[i] = mpConfig->readBoolEntry("DoublePixels", mbDP[i]);
	mbAnimated[i] = mpConfig->readBoolEntry("Animated", mbAnimated[i]);

	for (it2=mStates.begin(), j=0; it2!=mStates.end(); ++it2, j++)
	{
	    TQString tmp = mpConfig->readEntry(*it2 + "Effect");
	    if (tmp == "togray")
		effect = KIconEffect::ToGray;
	    else if (tmp == "colorize")
		effect = KIconEffect::Colorize;
	    else if (tmp == "togamma")
		effect = KIconEffect::ToGamma;
	    else if (tmp == "desaturate")
		effect = KIconEffect::DeSaturate;
	    else if (tmp == "tomonochrome")
		effect = KIconEffect::ToMonochrome;
	    else if (tmp == "none")
		effect = KIconEffect::NoEffect;
	    else continue;
	    mEffects[i][j].type = effect;
	    mEffects[i][j].value = mpConfig->readDoubleNumEntry(*it2 + "Value");
	    mEffects[i][j].color = mpConfig->readColorEntry(*it2 + "Color");
	    mEffects[i][j].color2 = mpConfig->readColorEntry(*it2 + "Color2");
	    mEffects[i][j].transparant = mpConfig->readBoolEntry(*it2 + "SemiTransparent");
	}
    }


    mpSystrayConfig->setGroup("System Tray");
    mSysTraySize = mpSystrayConfig->readNumEntry("systrayIconWidth", 22);

    mpKickerConfig->setGroup("General");
    mQuickLaunchSize = mpKickerConfig->readNumEntry("panelIconWidth", KIcon::SizeLarge);

    mpConfig->setGroup("KDE");
    mpRoundedCheck.setChecked(config->readBoolEntry("IconsUseRoundedRect", KDE_DEFAULT_ICONTEXTROUNDED));
}

void KIconConfig::apply()
{
    int i;

    mpUsageList->setCurrentItem(mUsage);

    if (mpUsageList->currentText() == i18n("Panel Buttons")) {
        mpSizeBox->clear();
        mpSizeBox->insertItem(TQString().setNum(16));
        mpSizeBox->insertItem(TQString().setNum(22));
        mpSizeBox->insertItem(TQString().setNum(32));
        mpSizeBox->insertItem(TQString().setNum(48));
        mpSizeBox->insertItem(TQString().setNum(64));
        mpSizeBox->insertItem(TQString().setNum(128));
        for (i=0;i<(mpSizeBox->count());i++) {
            if (mpSizeBox->text(i) == TQString().setNum(mQuickLaunchSize)) {
                mpSizeBox->setCurrentItem(i);
            }
        }
    }
    else if (mpUsageList->currentText() == i18n("System Tray Icons")) {
        mpSizeBox->clear();
        mpSizeBox->insertItem(TQString().setNum(16));
        mpSizeBox->insertItem(TQString().setNum(22));
        mpSizeBox->insertItem(TQString().setNum(32));
        mpSizeBox->insertItem(TQString().setNum(48));
        mpSizeBox->insertItem(TQString().setNum(64));
        mpSizeBox->insertItem(TQString().setNum(128));
        for (i=0;i<(mpSizeBox->count());i++) {
            if (mpSizeBox->text(i) == TQString().setNum(mSysTraySize)) {
                mpSizeBox->setCurrentItem(i);
            }
        }
    }
    else {
        int delta = 1000, dw, index = -1, size = 0, i;
        TQValueList<int>::Iterator it;
        mpSizeBox->clear();
        if (mUsage < KIcon::LastGroup) {
            for (it=mAvSizes[mUsage].begin(), i=0; it!=mAvSizes[mUsage].end(); ++it, i++)
            {
                mpSizeBox->insertItem(TQString().setNum(*it));
                dw = abs(mSizes[mUsage] - *it);
                if (dw < delta)
                {
                    delta = dw;
                    index = i;
                    size = *it;
                }
            }
            if (index != -1)
            {
                mpSizeBox->setCurrentItem(index);
                mSizes[mUsage] = size; // best or exact match
            }
            mpDPCheck->setChecked(mbDP[mUsage]);
            mpAnimatedCheck->setChecked(mbAnimated[mUsage]);
        }
    }
}

void KIconConfig::preview(int i)
{
    // Apply effects ourselves because we don't want to sync
    // the configuration every preview.

    int viewedGroup;
    if (mpUsageList->text(mUsage) == i18n("Panel Buttons")) {
        viewedGroup = KIcon::FirstGroup;
    }
    else if (mpUsageList->text(mUsage) == i18n("System Tray Icons")) {
        viewedGroup = KIcon::FirstGroup;
    }
    else {
        viewedGroup = (mUsage == KIcon::LastGroup) ? KIcon::FirstGroup : mUsage;
    }

    TQPixmap pm;
    if (mpUsageList->text(mUsage) == i18n("Panel Buttons")) {
        pm = mpLoader->loadIcon(mExample, KIcon::NoGroup, mQuickLaunchSize);
    }
    else if (mpUsageList->text(mUsage) == i18n("System Tray Icons")) {
        pm = mpLoader->loadIcon(mExample, KIcon::NoGroup, mSysTraySize);
    }
    else {
        pm = mpLoader->loadIcon(mExample, KIcon::NoGroup, mSizes[viewedGroup]);
    }
    TQImage img = pm.convertToImage();
    if (mbDP[viewedGroup])
    {
        int w = img.width() * 2;
        img = img.smoothScale(w, w);
    }

    Effect &effect = mEffects[viewedGroup][i];

    img = mpEffect->apply(img, effect.type,
        effect.value, effect.color, effect.color2, effect.transparant);
    pm.convertFromImage(img);
    mpPreview[i]->setPixmap(pm);
}

void KIconConfig::preview()
{
    preview(0);
    preview(1);
    preview(2);
}

void KIconConfig::load()
{
    load( false );
}

void KIconConfig::load( bool useDefaults )
{
    mpConfig = KGlobal::config();
    mpConfig->setReadDefaults( useDefaults );
    read();
    apply();
    for (int i=0; i<KIcon::LastGroup; i++)
	mbChanged[i] = false;
    preview();
    emit changed( useDefaults );
}


void KIconConfig::save()
{
    int i, j;
    TQStringList::ConstIterator it, it2;
    for (it=mGroups.begin(), i=0; it!=mGroups.end(); ++it, i++)
    {
	mpConfig->setGroup(*it + "Icons");
	mpConfig->writeEntry("Size", mSizes[i], true, true);
	mpConfig->writeEntry("DoublePixels", mbDP[i], true, true);
	mpConfig->writeEntry("Animated", mbAnimated[i], true, true);
	for (it2=mStates.begin(), j=0; it2!=mStates.end(); ++it2, j++)
	{
	    TQString tmp;
	    switch (mEffects[i][j].type)
	    {
	    case KIconEffect::ToGray:
		tmp = "togray";
		break;
	    case KIconEffect::ToGamma:
		tmp = "togamma";
		break;
	    case KIconEffect::Colorize:
		tmp = "colorize";
		break;
	    case KIconEffect::DeSaturate:
		tmp = "desaturate";
		break;
	    case KIconEffect::ToMonochrome:
		tmp = "tomonochrome";
		break;
	    default:
		tmp = "none";
		break;
	    }
	    mpConfig->writeEntry(*it2 + "Effect", tmp, true, true);
	    mpConfig->writeEntry(*it2 + "Value", mEffects[i][j].value, true, true);
            mpConfig->writeEntry(*it2 + "Color", mEffects[i][j].color, true, true);
            mpConfig->writeEntry(*it2 + "Color2", mEffects[i][j].color2, true, true);
            mpConfig->writeEntry(*it2 + "SemiTransparent", mEffects[i][j].transparant, true, true);
	}
    }

    // Reload kicker/systray configuration files; we have no way of knowing if any other parameters changed
    // from initial read to this write request
    mpSystrayConfig->reparseConfiguration();
    mpKickerConfig->reparseConfiguration();

    mpSystrayConfig->setGroup("System Tray");
    mpSystrayConfig->writeEntry("systrayIconWidth", mSysTraySize);
    mpKickerConfig->setGroup("General");
    mpKickerConfig->writeEntry("panelIconWidth", mQuickLaunchSize);
    mpConfig->setGroup("KDE");
    mpConfig->writeEntry("IconsUseRoundedRect", mpRoundedCheck.isChecked());

    mpConfig->sync();
    mpSystrayConfig->sync();
    mpKickerConfig->sync();

    emit changed(false);

    // Emit KIPC change message.
    for (int i=0; i<KIcon::LastGroup; i++)
    {
	if (mbChanged[i])
	{
	    KIPC::sendMessageAll(KIPC::IconChanged, i);
	    mbChanged[i] = false;
	}
    }

    // Signal kicker to reload icon configuration
    kapp->dcopClient()->send("kicker", "kicker", "configure()", TQByteArray());

    // Signal system tray to reload icon configuration
    kapp->dcopClient()->send("kicker", "SystemTrayApplet", "iconSizeChanged()", TQByteArray());
}

void KIconConfig::defaults()
{
    load( true );
}

void KIconConfig::QLSizeLockedChanged(bool checked) {
    emit changed();
}

void KIconConfig::slotUsage(int index)
{
    mUsage = index;
    if (mpUsageList->text(index) == i18n("Panel Buttons")) {
        mpSizeBox->setEnabled(true);
        mpDPCheck->setEnabled(false);
        mpAnimatedCheck->setEnabled(false);
        mPreviewButton1->setEnabled(false);
        mPreviewButton2->setEnabled(false);
        mPreviewButton3->setEnabled(false);
    }
    else if (mpUsageList->text(index) == i18n("System Tray Icons")) {
        mpSizeBox->setEnabled(true);
        mpDPCheck->setEnabled(false);
        mpAnimatedCheck->setEnabled(false);
        mPreviewButton1->setEnabled(false);
        mPreviewButton2->setEnabled(false);
        mPreviewButton3->setEnabled(false);
    }
    else if ( mUsage == KIcon::Panel || mUsage == KIcon::LastGroup )
    {
        mpSizeBox->setEnabled(false);
        mpDPCheck->setEnabled(false);
	mpAnimatedCheck->setEnabled( mUsage == KIcon::Panel );
        mPreviewButton1->setEnabled(true);
        mPreviewButton2->setEnabled(true);
        mPreviewButton3->setEnabled(true);
    }
    else
    {
        mpSizeBox->setEnabled(true);
        mpDPCheck->setEnabled(true);
	mpAnimatedCheck->setEnabled( mUsage == KIcon::Desktop );
        mPreviewButton1->setEnabled(true);
        mPreviewButton2->setEnabled(true);
        mPreviewButton3->setEnabled(true);
    }

    apply();
    preview();
}

void KIconConfig::EffectSetup(int state)
{
    int viewedGroup = (mUsage == KIcon::LastGroup) ? KIcon::FirstGroup : mUsage;

    if (mpUsageList->currentText() == i18n("Panel Buttons")) {
        return;
    }
    if (mpUsageList->currentText() == i18n("System Tray Icons")) {
        return;
    }

    TQPixmap pm = mpLoader->loadIcon(mExample, KIcon::NoGroup, mSizes[viewedGroup]);
    TQImage img = pm.convertToImage();
    if (mbDP[viewedGroup])
    {
	int w = img.width() * 2;
	img = img.smoothScale(w, w);
    }

    TQString caption;
    switch (state)
    {
    case 0 : caption = i18n("Setup Default Icon Effect"); break;
    case 1 : caption = i18n("Setup Active Icon Effect"); break;
    case 2 : caption = i18n("Setup Disabled Icon Effect"); break;
    }

    KIconEffectSetupDialog dlg(mEffects[viewedGroup][state], mDefaultEffect[state], caption, img);

    if (dlg.exec() == TQDialog::Accepted)
    {
        if (mUsage == KIcon::LastGroup) {
            for (int i=0; i<KIcon::LastGroup; i++)
                mEffects[i][state] = dlg.effect();
        } else {
            mEffects[mUsage][state] = dlg.effect();
        }

        // AK - can this call be moved therefore removing
        //      code duplication?

        emit changed(true);

        if (mUsage == KIcon::LastGroup) {
            for (int i=0; i<KIcon::LastGroup; i++)
                mbChanged[i] = true;
        } else {
            mbChanged[mUsage] = true;
        }
    }
    preview(state);
}

void KIconConfig::slotSize(int index)
{
    if (mpUsageList->currentText() == i18n("Panel Buttons")) {
        mQuickLaunchSize = mpSizeBox->currentText().toInt();
        preview();
        emit changed(true);
    }
    else if (mpUsageList->currentText() == i18n("System Tray Icons")) {
        mSysTraySize = mpSizeBox->currentText().toInt();
        preview();
        emit changed(true);
    }
    else {
        Q_ASSERT(mUsage < KIcon::LastGroup);
        mSizes[mUsage] = mAvSizes[mUsage][index];
        preview();
        emit changed(true);
        mbChanged[mUsage] = true;
    }
}

void KIconConfig::slotDPCheck(bool check)
{
    Q_ASSERT(mUsage < KIcon::LastGroup);
    if (mbDP[mUsage] != check)
    {
        mbDP[mUsage] = check;
        emit changed(true);
        mbChanged[mUsage] = true;
    }
    preview();

}

void KIconConfig::slotAnimatedCheck(bool check)
{
    Q_ASSERT(mUsage < KIcon::LastGroup);
    if (mbAnimated[mUsage] != check)
    {
        mbAnimated[mUsage] = check;
        emit changed(true);
        mbChanged[mUsage] = true;
    }
}

void KIconConfig::slotRoundedCheck(bool check)
{
    // Do nothing
}

KIconEffectSetupDialog::KIconEffectSetupDialog(const Effect &effect,
    const Effect &defaultEffect,
    const TQString &caption, const TQImage &image,
    TQWidget *parent, char *name)
    : KDialogBase(parent, name, true, caption,
	Default|Ok|Cancel, Ok, true),
      mEffect(effect),
      mDefaultEffect(defaultEffect),
      mExample(image)
{
    mpEffect = new KIconEffect;

    TQLabel *lbl;
    TQGroupBox *frame;
    TQGridLayout *grid;

    TQWidget *page = new TQWidget(this);
    setMainWidget(page);

    TQGridLayout *top = new TQGridLayout(page, 4, 2, 0, spacingHint());
    top->setColStretch(0,1);
    top->addColSpacing(1,10);
    top->setColStretch(2,2);
    top->setRowStretch(1,1);

    lbl = new TQLabel(i18n("&Effect:"), page);
    lbl->setFixedSize(lbl->sizeHint());
    top->addWidget(lbl, 0, 0, Qt::AlignLeft);
    mpEffectBox = new TQListBox(page);
    mpEffectBox->insertItem(i18n("No Effect"));
    mpEffectBox->insertItem(i18n("To Gray"));
    mpEffectBox->insertItem(i18n("Colorize"));
    mpEffectBox->insertItem(i18n("Gamma"));
    mpEffectBox->insertItem(i18n("Desaturate"));
    mpEffectBox->insertItem(i18n("To Monochrome"));
    mpEffectBox->setMinimumWidth( 100 );
    connect(mpEffectBox, TQT_SIGNAL(highlighted(int)), TQT_SLOT(slotEffectType(int)));
    top->addMultiCellWidget(mpEffectBox, 1, 2, 0, 0, Qt::AlignLeft);
    lbl->setBuddy(mpEffectBox);

    mpSTCheck = new TQCheckBox(i18n("&Semi-transparent"), page);
    connect(mpSTCheck, TQT_SIGNAL(toggled(bool)), TQT_SLOT(slotSTCheck(bool)));
    top->addWidget(mpSTCheck, 3, 0, Qt::AlignLeft);

    frame = new TQGroupBox(i18n("Preview"), page);
    top->addMultiCellWidget(frame, 0, 1, 1, 1);
    grid = new TQGridLayout(frame, 2, 1, marginHint(), spacingHint());
    grid->addRowSpacing(0, fontMetrics().lineSpacing());
    grid->setRowStretch(1, 1);

    mpPreview = new TQLabel(frame);
    mpPreview->setAlignment(AlignCenter);
    mpPreview->setMinimumSize(105, 105);
    grid->addWidget(mpPreview, 1, 0);

    mpEffectGroup = new TQGroupBox(i18n("Effect Parameters"), page);
    top->addMultiCellWidget(mpEffectGroup, 2, 3, 1, 1);
    grid = new TQGridLayout(mpEffectGroup, 3, 2, marginHint(), spacingHint());
    grid->addRowSpacing(0, fontMetrics().lineSpacing());

    mpEffectLabel = new TQLabel(i18n("&Amount:"), mpEffectGroup);
    grid->addWidget(mpEffectLabel, 1, 0);
    mpEffectSlider = new TQSlider(0, 100, 5, 10, TQSlider::Horizontal, mpEffectGroup);
    mpEffectLabel->setBuddy( mpEffectSlider );
    connect(mpEffectSlider, TQT_SIGNAL(valueChanged(int)), TQT_SLOT(slotEffectValue(int)));
    grid->addWidget(mpEffectSlider, 1, 1);

    mpEffectColor = new TQLabel(i18n("Co&lor:"), mpEffectGroup);
    grid->addWidget(mpEffectColor, 2, 0);
    mpEColButton = new KColorButton(mpEffectGroup);
    mpEffectColor->setBuddy( mpEColButton );
    connect(mpEColButton, TQT_SIGNAL(changed(const TQColor &)),
		TQT_SLOT(slotEffectColor(const TQColor &)));
    grid->addWidget(mpEColButton, 2, 1);

    mpEffectColor2 = new TQLabel(i18n("&Second color:"), mpEffectGroup);
    grid->addWidget(mpEffectColor2, 3, 0);
    mpECol2Button = new KColorButton(mpEffectGroup);
    mpEffectColor2->setBuddy( mpECol2Button );
    connect(mpECol2Button, TQT_SIGNAL(changed(const TQColor &)),
		TQT_SLOT(slotEffectColor2(const TQColor &)));
    grid->addWidget(mpECol2Button, 3, 1);

    init();
    preview();
}

KIconEffectSetupDialog::~KIconEffectSetupDialog()
{
  delete mpEffect;
}

void KIconEffectSetupDialog::init()
{
    mpEffectBox->setCurrentItem(mEffect.type);
    mpEffectSlider->setEnabled(mEffect.type != KIconEffect::NoEffect);
    mpEColButton->setEnabled(mEffect.type == KIconEffect::Colorize || mEffect.type == KIconEffect::ToMonochrome);
    mpECol2Button->setEnabled(mEffect.type == KIconEffect::ToMonochrome);
    mpEffectSlider->setValue((int) (100.0 * mEffect.value + 0.5));
    mpEColButton->setColor(mEffect.color);
    mpECol2Button->setColor(mEffect.color2);
    mpSTCheck->setChecked(mEffect.transparant);
}

void KIconEffectSetupDialog::slotEffectValue(int value)
{
     mEffect.value = 0.01 * value;
     preview();
}

void KIconEffectSetupDialog::slotEffectColor(const TQColor &col)
{
     mEffect.color = col;
     preview();
}

void KIconEffectSetupDialog::slotEffectColor2(const TQColor &col)
{
     mEffect.color2 = col;
     preview();
}

void KIconEffectSetupDialog::slotEffectType(int type)
{
    mEffect.type = type;
    mpEffectGroup->setEnabled(mEffect.type != KIconEffect::NoEffect);
    mpEffectSlider->setEnabled(mEffect.type != KIconEffect::NoEffect);
    mpEffectColor->setEnabled(mEffect.type == KIconEffect::Colorize || mEffect.type == KIconEffect::ToMonochrome);
    mpEColButton->setEnabled(mEffect.type == KIconEffect::Colorize || mEffect.type == KIconEffect::ToMonochrome);
    mpEffectColor2->setEnabled(mEffect.type == KIconEffect::ToMonochrome);
    mpECol2Button->setEnabled(mEffect.type == KIconEffect::ToMonochrome);
    preview();
}

void KIconEffectSetupDialog::slotSTCheck(bool b)
{
     mEffect.transparant = b;
     preview();
}

void KIconEffectSetupDialog::slotDefault()
{
     mEffect = mDefaultEffect;
     init();
     preview();
}

void KIconEffectSetupDialog::preview()
{
    TQPixmap pm;
    TQImage img = mExample.copy();
    img = mpEffect->apply(img, mEffect.type,
          mEffect.value, mEffect.color, mEffect.color2, mEffect.transparant);
    pm.convertFromImage(img);
    mpPreview->setPixmap(pm);
}

#include "icons.moc"