~ubuntu-branches/ubuntu/gutsy/kdebase-workspace/gutsy

« back to all changes in this revision

Viewing changes to kcontrol/colors/colorscm.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2007-10-11 14:04:48 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20071011140448-v0eb7lxbb24zagca
Tags: 3.94.0-0ubuntu1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// KDE Display color scheme setup module
2
 
//
3
 
// Copyright (c)  Mark Donohoe 1997
4
 
//
5
 
// Converted to a kcc module by Matthias Hoelzer 1997
6
 
// Ported to Qt-2.0 by Matthias Ettrich 1999
7
 
// Ported to kcontrol2 by Geert Jansen 1999
8
 
// Made maintainable by Waldo Bastian 2000
9
 
 
10
 
#include <assert.h>
11
 
#include <config-workspace.h>
12
 
#include <stdlib.h>
13
 
#include <unistd.h>
14
 
 
15
 
#include <QCheckBox>
16
 
#include <QComboBox>
17
 
#include <QDir>
18
 
#include <QLabel>
19
 
#include <QLayout>
20
 
#include <QPainter>
21
 
#include <QSlider>
22
 
#include <QSplitter>
23
 
#include <Qt3Support/Q3GroupBox>
24
 
#include <Q3PtrList>
25
 
 
26
 
#include <kcolorbutton.h>
27
 
#include <kcursor.h>
28
 
#include <kfiledialog.h>
29
 
#include <kgenericfactory.h>
30
 
#include <kglobalsettings.h>
31
 
#include <kinputdialog.h>
32
 
#include <kio/netaccess.h>
33
 
#include <kmessagebox.h>
34
 
#include <kstandarddirs.h>
35
 
#include <kaboutdata.h>
36
 
#include <klistwidget.h>
37
 
#include <kvbox.h>
38
 
#include "../krdb/krdb.h"
 
1
/* KDE Display color scheme setup module
 
2
 * Copyright (C) 2007 Matthew Woehlke <mw_triad@users.sourceforge.net>
 
3
 * Copyright (C) 2007 Jeremy Whiting <jeremy@scitools.com>
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or modify
 
6
 * it under the terms of the GNU General Public License as published by
 
7
 * the Free Software Foundation; either version 2 of the License, or
 
8
 * (at your option) any later version.
 
9
 *
 
10
 * This program 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
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program; see the file COPYING.  If not, write to
 
17
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
18
 * Boston, MA 02110-1301, USA.
 
19
 */
39
20
 
40
21
#include "colorscm.h"
41
 
#include "kcolortreewidget.h"
42
 
 
43
 
#if defined Q_WS_X11
44
 
#include <QX11Info>
45
 
#include <X11/Xlib.h>
46
 
#include <X11/Xatom.h>
47
 
#endif
48
 
 
49
 
K_PLUGIN_FACTORY(KolorFactory,
50
 
        registerPlugin<KColorScheme>();
51
 
        )
52
 
K_EXPORT_PLUGIN(KolorFactory("kcmcolors"))
53
 
 
54
 
class KColorSchemeEntry {
55
 
public:
56
 
    KColorSchemeEntry(const QString &_path, const QString &_name, bool _local)
57
 
        : path(_path), name(_name), local(_local) { }
58
 
 
59
 
    QString path;
60
 
    QString name;
61
 
    bool local;
62
 
};
63
 
 
64
 
class KColorSchemeList : public Q3PtrList<KColorSchemeEntry> {
65
 
public:
66
 
    KColorSchemeList()
67
 
        { setAutoDelete(true); }
68
 
 
69
 
    int compareItems(Q3PtrCollection::Item item1, Q3PtrCollection::Item item2)
70
 
        {
71
 
           KColorSchemeEntry *i1 = (KColorSchemeEntry*)item1;
72
 
           KColorSchemeEntry *i2 = (KColorSchemeEntry*)item2;
73
 
           if (i1->local != i2->local)
74
 
              return i1->local ? -1 : 1;
75
 
           return i1->name.localeAwareCompare(i2->name);
76
 
        }
77
 
};
78
 
 
79
 
#define SIZE 8
80
 
 
81
 
// make a 24 * 8 pixmap with the main colors in a scheme
82
 
QPixmap mkColorPreview(const WidgetCanvas *cs)
83
 
{
84
 
   QPixmap group(SIZE*3,SIZE);
85
 
   QPixmap block(SIZE,SIZE);
86
 
   group.fill(QColor(0,0,0));
87
 
   block.fill(cs->back);   bitBlt(&group,0*SIZE,0,&block,0,0,SIZE,SIZE);
88
 
   block.fill(cs->window); bitBlt(&group,1*SIZE,0,&block,0,0,SIZE,SIZE);
89
 
   block.fill(cs->aTitle); bitBlt(&group,2*SIZE,0,&block,0,0,SIZE,SIZE);
90
 
   QPainter p(&group);
91
 
   p.drawRect(0,0,3*SIZE,SIZE);
92
 
   return group;
93
 
}
94
 
 
95
 
/**** KColorScheme ****/
96
 
 
97
 
KColorScheme::KColorScheme(QWidget *parent, const QVariantList &)
98
 
    : KCModule(KolorFactory::componentData(), parent)
99
 
{
100
 
    nSysSchemes = 2;
101
 
 
102
 
    setQuickHelp( i18n("<p><h1>Colors</h1> This module allows you to choose"
103
 
       " the color scheme used for the KDE desktop. The different"
104
 
       " elements of the desktop, such as title bars, menu text, etc.,"
105
 
       " are called \"widgets\". You can choose the widget whose"
106
 
       " color you want to change by selecting it from a list, or by"
107
 
       " clicking on a graphical representation of the desktop.</p><p>"
108
 
       " You can save color settings as complete color schemes,"
109
 
       " which can also be modified or deleted. KDE comes with several"
110
 
       " predefined color schemes on which you can base your own.</p><p>"
111
 
       " All KDE applications will obey the selected color scheme."
112
 
       " Non-KDE applications may also obey some or all of the color"
113
 
       " settings, if this option is enabled.</p>"));
114
 
 
115
 
    KConfigGroup cfg(KSharedConfig::openConfig("kcmdisplayrc"), "X11");
116
 
    useRM = cfg.readEntry("useResourceManager", true);
117
 
 
118
 
    cs = new WidgetCanvas( this );
119
 
    cs->setCursor( Qt::PointingHandCursor );
120
 
 
121
 
 
122
 
    cs->setFixedHeight(160);
123
 
    cs->setMinimumWidth(440);
124
 
    cs->setWhatsThis( i18n("This is a preview of the color settings which"
125
 
       " will be applied if you click \"Apply\" or \"OK\". You can click on"
126
 
       " different parts of this preview image. The widget name in the"
127
 
       " \"Widget color\" box will change to reflect the part of the preview"
128
 
       " image you clicked.") );
129
 
 
130
 
    connect( cs, SIGNAL( colorDropped( int, const QColor&)),
131
 
         SLOT( slotColorForWidget( int, const QColor&)));
132
 
 
133
 
    QSplitter *splitter = new QSplitter(this);
134
 
 
135
 
    Q3GroupBox *group = new Q3GroupBox( i18n("Color Scheme"), splitter );
136
 
    group->setOrientation( Qt::Horizontal );
137
 
    group->setColumns( 1 );
138
 
 
139
 
 
140
 
    sList = new KListWidget( group );
141
 
    mSchemeList = new KColorSchemeList();
142
 
    connect(sList, SIGNAL(currentRowChanged(int)), SLOT(slotPreviewScheme(int)));
143
 
 
144
 
    sList->setWhatsThis( i18n("<p>This is a list of predefined color schemes,"
145
 
       " including any that you may have created. You can preview an existing"
146
 
       " color scheme by selecting it from the list. The current scheme will"
147
 
       " be replaced by the selected color scheme.</p><p>"
148
 
       " Warning: if you have not yet applied any changes you may have made"
149
 
       " to the current scheme, those changes will be lost if you select"
150
 
       " another color scheme.</p>") );
151
 
 
152
 
    addBt = new QPushButton(i18n("&Save Scheme..."), group);
153
 
    connect(addBt, SIGNAL(clicked()), SLOT(slotAdd()));
154
 
 
155
 
    addBt->setWhatsThis( i18n("Press this button if you want to save"
156
 
       " the current color settings as a color scheme. You will be"
157
 
       " prompted for a name.") );
158
 
 
159
 
    removeBt = new QPushButton(i18n("R&emove Scheme"), group);
160
 
    removeBt->setEnabled(false);
161
 
    connect(removeBt, SIGNAL(clicked()), SLOT(slotRemove()));
162
 
 
163
 
    removeBt->setWhatsThis( i18n("Press this button to remove the selected"
164
 
       " color scheme. Note that this button is disabled if you do not have"
165
 
       " permission to delete the color scheme.") );
166
 
 
167
 
        importBt = new QPushButton(i18n("I&mport Scheme..."), group);
168
 
        connect(importBt, SIGNAL(clicked()),SLOT(slotImport()));
169
 
 
170
 
        importBt->setWhatsThis( i18n("Press this button to import a new color"
171
 
                " scheme. Note that the color scheme will only be available for the"
172
 
                " current user." ));
173
 
 
174
 
 
175
 
 
176
 
    KVBox *vb=new KVBox(splitter);
177
 
 
178
 
        // LAYOUT
179
 
    splitter->addWidget(group);
180
 
    splitter->addWidget(vb);
181
 
    QVBoxLayout *toplayout = new QVBoxLayout(this);
182
 
    toplayout->setMargin(0);
183
 
 
184
 
    toplayout->addWidget(cs);
185
 
    toplayout->addWidget(splitter);
186
 
    setLayout(toplayout);
187
 
 
188
 
    mColorTreeWidget = new KColorTreeWidget(vb);
189
 
    connect(mColorTreeWidget , SIGNAL(colorChanged(int, const QColor& )) ,
190
 
            this , SLOT(slotColorChanged( int, const QColor& ) ));
191
 
 
192
 
    setColorName(i18n("Inactive Title Bar") , CSM_Inactive_title_text , CSM_Inactive_title_bar);
193
 
    setColorName(i18n("Inactive Title Blend"), -1 , CSM_Inactive_title_blend);
194
 
    setColorName(i18n("Active Title Bar"), CSM_Active_title_text, CSM_Active_title_bar);
195
 
    setColorName(i18n("Active Title Blend"), -1, CSM_Active_title_blend);
196
 
    setColorName(i18n("Window"), CSM_Text , CSM_Background);
197
 
    setColorName(i18n("Selected"), CSM_Select_text , CSM_Select_background);
198
 
    setColorName(i18n("Standard"), CSM_Standard_text,  CSM_Standard_background);
199
 
    setColorName(i18n("Button"), CSM_Button_text , CSM_Button_background);
200
 
    setColorName(i18n("Active Title Button"), CSM_Active_title_button , -1 );
201
 
    setColorName(i18n("Inactive Title Button"), CSM_Inactive_title_button , -1);
202
 
    setColorName(i18n("Active Window Frame"), CSM_Active_frame , -1);
203
 
    setColorName(i18n("Active Window Handle"), CSM_Active_handle , -1);
204
 
    setColorName(i18n("Inactive Window Frame"), CSM_Inactive_frame , -1);
205
 
    setColorName(i18n("Inactive Window Handle"), CSM_Inactive_handle , -1);
206
 
    setColorName(i18n("Link"), CSM_Link , -1);
207
 
    setColorName(i18n("Followed Link"), CSM_Followed_Link , -1 );
208
 
    setColorName(i18n("Alternate Background in Lists"), -1 , CSM_Alternate_background);
209
 
 
210
 
 
211
 
    cbShadeList = new QCheckBox(i18n("Shade sorted column in lists"), vb);
212
 
    connect(cbShadeList, SIGNAL(toggled(bool)), this, SLOT(slotShadeSortColumnChanged(bool)));
213
 
 
214
 
    cbShadeList->setWhatsThis(
215
 
       i18n("Check this box to show the sorted column in a list with a shaded background"));
216
 
 
217
 
    group = new Q3GroupBox(  i18n("Con&trast"), vb );
218
 
 
219
 
    QVBoxLayout *groupLayout2 = new QVBoxLayout(group);
220
 
    QHBoxLayout *groupLayout = new QHBoxLayout;
221
 
    groupLayout2->addLayout(groupLayout);
222
 
 
223
 
    sb = new QSlider(Qt::Horizontal, group);
224
 
    sb->setObjectName(QLatin1String("Slider"));
225
 
    sb->setRange( 0, 10 );
226
 
    sb->setFocusPolicy( Qt::StrongFocus );
227
 
    connect(sb, SIGNAL(valueChanged(int)), SLOT(sliderValueChanged(int)));
228
 
 
229
 
    sb->setWhatsThis( i18n("Use this slider to change the contrast level"
230
 
       " of the current color scheme. Contrast does not affect all of the"
231
 
       " colors, only the edges of 3D objects."));
232
 
 
233
 
    QLabel *label = new QLabel(i18nc("Low Contrast", "Low"), group);
234
 
    label->setBuddy( sb );
235
 
    groupLayout->addWidget(label);
236
 
    groupLayout->addWidget(sb, 10);
237
 
    label = new QLabel(group);
238
 
    label->setText(i18nc("High Contrast", "High"));
239
 
    groupLayout->addWidget( label );
240
 
 
241
 
    cbExportColors = new QCheckBox(i18n("Apply colors to &non-KDE applications"), this);
242
 
    toplayout->addWidget( cbExportColors );
243
 
    connect(cbExportColors, SIGNAL(toggled(bool)), this, SLOT(changed()));
244
 
 
245
 
    cbExportColors->setWhatsThis( i18n("Check this box to apply the"
246
 
       " current color scheme to non-KDE applications."));
247
 
 
248
 
    readSchemeNames();
249
 
    sList->setCurrentItem( 0 );
250
 
 
251
 
    load();
252
 
 
253
 
    KAboutData* about = new KAboutData("kcmcolors", 0, ki18n("Colors"), 0, KLocalizedString(),
 
22
 
 
23
#include <QtCore/QFileInfo>
 
24
#include <QtGui/QHeaderView>
 
25
#include <QtGui/QStackedWidget>
 
26
#include <QtDBus/QtDBus>
 
27
 
 
28
#include <KColorButton>
 
29
#include <KColorDialog>
 
30
#include <KGenericFactory>
 
31
#include <KGlobal>
 
32
#include <KGlobalSettings>
 
33
#include <KAboutData>
 
34
#include <KListWidget>
 
35
#include <KStandardDirs>
 
36
 
 
37
K_PLUGIN_FACTORY( KolorFactory, registerPlugin<KColorCm>(); )
 
38
K_EXPORT_PLUGIN( KolorFactory("kcmcolors") )
 
39
 
 
40
KColorCm::KColorCm(QWidget *parent, const QVariantList &)
 
41
    : KCModule( KolorFactory::componentData(), parent )
 
42
{
 
43
    KAboutData* about = new KAboutData(
 
44
        "kcmcolors", 0, ki18n("Colors"), 0, KLocalizedString(),
254
45
        KAboutData::License_GPL,
255
 
        ki18n("(c) 1997-2005 Colors Developers"));
256
 
    about->addAuthor(ki18n("Mark Donohoe"));
257
 
    about->addAuthor(ki18n("Matthias Hoelzer"));
258
 
    about->addAuthor(ki18n("Matthias Ettrich"));
259
 
    about->addAuthor(ki18n("Geert Jansen"));
260
 
    about->addAuthor(ki18n("Waldo Bastian"));
 
46
        ki18n("(c) 2007 Matthew Woehlke")
 
47
    );
 
48
    about->addAuthor( ki18n("Matthew Woehlke"), KLocalizedString(),
 
49
                     "mw_triad@users.sourceforge.net" );
 
50
    about->addAuthor( ki18n("Jeremy Whiting"), KLocalizedString(), "jeremy@scitools.com");
261
51
    setAboutData( about );
262
 
}
263
 
 
264
 
 
265
 
KColorScheme::~KColorScheme()
266
 
{
267
 
    delete mSchemeList;
268
 
}
269
 
 
270
 
 
271
 
void KColorScheme::load()
272
 
{
273
 
    KConfigGroup config(KGlobal::config(), "KDE");
274
 
    sCurrentScheme = config.readEntry("colorScheme");
275
 
 
276
 
    sList->setCurrentRow(findSchemeByName(sCurrentScheme));
277
 
    readScheme(0);
278
 
 
279
 
    cbShadeList->setChecked(cs->shadeSortColumn);
280
 
 
281
 
    cs->drawSampleWidgets();
282
 
    sb->blockSignals(true);
283
 
    sb->setValue(cs->contrast);
284
 
    sb->blockSignals(false);
285
 
 
286
 
    KConfig _cfg( "kcmdisplayrc", KConfig::NoGlobals  );
287
 
    KConfigGroup cfg(&_cfg, "X11");
288
 
    bool exportColors = cfg.readEntry("exportKDEColors", true);
289
 
    cbExportColors->setChecked(exportColors);
 
52
 
 
53
    m_config = KSharedConfig::openConfig("kdeglobals");
 
54
 
 
55
    setupUi(this);
 
56
 
 
57
    connect(colorSet, SIGNAL(currentIndexChanged(int)), this, SLOT(updateColorTable()));
 
58
    connect(schemeList, SIGNAL(currentRowChanged(int)), this, SLOT(loadScheme()));
 
59
 
 
60
    // only needs to be called once
 
61
    setupColorTable();
 
62
 
 
63
    load();
 
64
}
 
65
 
 
66
KColorCm::~KColorCm()
 
67
{
 
68
    m_config->clean();
 
69
}
 
70
 
 
71
void KColorCm::populateSchemeList()
 
72
{
 
73
    QStringList schemeFiles = KGlobal::dirs()->findAllResources("data", "color-schemes/*");
 
74
    for (int i = 0; i < schemeFiles.size(); ++i)
 
75
    {
 
76
        // TODO: add some processing to show some sample of the colorscheme in the icon 
 
77
        // like kde3 colors kcm had
 
78
        QString filename = schemeFiles[i];
 
79
        QFileInfo info(filename);
 
80
        schemeList->addItem(info.fileName());
 
81
    }
 
82
}
 
83
 
 
84
void KColorCm::loadScheme()
 
85
{
 
86
    if (schemeList->currentItem() != NULL)
 
87
    {
 
88
        QString path = KGlobal::dirs()->findResource("data", 
 
89
            "color-schemes/" + schemeList->currentItem()->text());
 
90
        KSharedConfigPtr temp = m_config;
 
91
        m_config = KSharedConfig::openConfig(path);
 
92
        updateColorSchemes();
 
93
        KConfigGroup group(m_config, "General");
 
94
        shadeSortedColumn->setChecked(group.readEntry("shadeSortColumn", true) ? Qt::Checked : Qt::Unchecked);
 
95
        KConfigGroup group2(m_config, "KDE");
 
96
        contrastSlider->setValue(group2.readEntry("contrast").toInt());
 
97
        m_config = temp;
 
98
        updateFromColorSchemes();
 
99
        updateColorTable();
 
100
 
 
101
        schemePreview->setPalette(m_config);
 
102
        inactivePreview->setPalette(m_config, QPalette::Inactive);
 
103
        disabledPreview->setPalette(m_config, QPalette::Disabled);
 
104
 
 
105
        emit changed(true);
 
106
    }
 
107
}
 
108
 
 
109
void KColorCm::createColorEntry(QString text, QString key, QList<KColorButton *> &list, int index)
 
110
{
 
111
    KColorButton *button = new KColorButton(this);
 
112
    button->setObjectName(QString::number(index));
 
113
    connect(button, SIGNAL(changed(const QColor &)), this, SLOT(colorChanged(const QColor &)));
 
114
    list.append(button);
 
115
 
 
116
    m_colorKeys.insert(index, key);
 
117
 
 
118
    QTableWidgetItem *label = new QTableWidgetItem(text);
 
119
    colorTable->setItem(index, 0, label);
 
120
    colorTable->setCellWidget(index, 1, button);
 
121
}
 
122
 
 
123
void KColorCm::variesClicked()
 
124
{
 
125
    // find which button was changed
 
126
    int row = sender()->objectName().toInt();
 
127
 
 
128
    QColor color;
 
129
    if(KColorDialog::getColor(color, this ) != QDialog::Rejected ) 
 
130
    {
 
131
        changeColor(row, color);
 
132
        m_stackedWidgets[row - 9]->setCurrentIndex(0);
 
133
    }
 
134
}
 
135
 
 
136
void KColorCm::updateColorSchemes()
 
137
{
 
138
    m_colorSchemes.clear();
 
139
 
 
140
    m_colorSchemes.append(KColorScheme(QPalette::Active, KColorScheme::View, m_config));
 
141
    m_colorSchemes.append(KColorScheme(QPalette::Active, KColorScheme::Window, m_config));
 
142
    m_colorSchemes.append(KColorScheme(QPalette::Active, KColorScheme::Button, m_config));
 
143
    m_colorSchemes.append(KColorScheme(QPalette::Active, KColorScheme::Selection, m_config));
 
144
    m_colorSchemes.append(KColorScheme(QPalette::Active, KColorScheme::Tooltip, m_config));
 
145
}
 
146
 
 
147
void KColorCm::updateFromColorSchemes()
 
148
{
 
149
    for (int i = KColorScheme::View; i <= KColorScheme::Tooltip; ++i)
 
150
    {
 
151
        KConfigGroup group(m_config, colorSetGroupKey(i));
 
152
        group.writeEntry("BackgroundNormal", m_colorSchemes[i].background(KColorScheme::NormalBackground).color());
 
153
        group.writeEntry("BackgroundAlternate", m_colorSchemes[i].background(KColorScheme::AlternateBackground).color());
 
154
        group.writeEntry("ForegroundNormal", m_colorSchemes[i].foreground(KColorScheme::NormalText).color());
 
155
        group.writeEntry("ForegroundInactive", m_colorSchemes[i].foreground(KColorScheme::InactiveText).color());
 
156
        group.writeEntry("ForegroundActive", m_colorSchemes[i].foreground(KColorScheme::InactiveText).color());
 
157
        group.writeEntry("ForegroundLink", m_colorSchemes[i].foreground(KColorScheme::LinkText).color());
 
158
        group.writeEntry("ForegroundVisited", m_colorSchemes[i].foreground(KColorScheme::VisitedText).color());
 
159
        group.writeEntry("ForegroundNegative", m_colorSchemes[i].foreground(KColorScheme::NegativeText).color());
 
160
        group.writeEntry("ForegroundNeutral", m_colorSchemes[i].foreground(KColorScheme::NeutralText).color());
 
161
        group.writeEntry("ForegroundPositive", m_colorSchemes[i].foreground(KColorScheme::PositiveText).color());
 
162
        group.writeEntry("DecorationFocus", m_colorSchemes[i].decoration(KColorScheme::FocusColor).color());
 
163
        group.writeEntry("DecorationHover", m_colorSchemes[i].decoration(KColorScheme::HoverColor).color());
 
164
    }
 
165
 
 
166
    KConfigGroup KDEgroup(m_config, "KDE");
 
167
    KDEgroup.writeEntry("contrast", contrastSlider->value());
 
168
 
 
169
    KConfigGroup generalGroup(m_config, "General");
 
170
    generalGroup.writeEntry("shadeSortColumn", (bool)shadeSortedColumn->checkState());
 
171
}
 
172
 
 
173
void KColorCm::setupColorTable()
 
174
{
 
175
    // first setup the common colors table
 
176
    commonColorTable->verticalHeader()->hide();
 
177
    commonColorTable->horizontalHeader()->hide();
 
178
    commonColorTable->setShowGrid(false);
 
179
    commonColorTable->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch);
 
180
    int minWidth = QPushButton(i18n("Varies")).minimumSizeHint().width();
 
181
    commonColorTable->horizontalHeader()->setMinimumSectionSize(minWidth);
 
182
    commonColorTable->horizontalHeader()->setResizeMode(1, QHeaderView::ResizeToContents);
 
183
 
 
184
    for (int i = 0; i < 22; ++i)
 
185
    {
 
186
        KColorButton * button = new KColorButton(this);
 
187
        button->setObjectName(QString::number(i));
 
188
        connect(button, SIGNAL(changed(const QColor &)), this, SLOT(colorChanged(const QColor &)));
 
189
        m_commonColorButtons << button;
 
190
 
 
191
        if (i > 8 && i < 16)
 
192
        {
 
193
            // Inactive Text row through Positive Text role all need a varies button
 
194
            KPushButton * variesButton = new KPushButton(NULL);
 
195
            variesButton->setText(i18n("Varies"));
 
196
            variesButton->setObjectName(QString::number(i));
 
197
            connect(variesButton, SIGNAL(clicked()), this, SLOT(variesClicked()));
 
198
 
 
199
            QStackedWidget * widget = new QStackedWidget(this);
 
200
            widget->addWidget(button);
 
201
            widget->addWidget(variesButton);
 
202
            m_stackedWidgets.append(widget);
 
203
 
 
204
            commonColorTable->setCellWidget(i, 1, widget);
 
205
        }
 
206
        else
 
207
        {
 
208
            commonColorTable->setCellWidget(i, 1, button);
 
209
        }
 
210
    }
 
211
 
 
212
    // then the colorTable that the colorSets will use
 
213
    colorTable->verticalHeader()->hide();
 
214
    colorTable->horizontalHeader()->hide();
 
215
    colorTable->setShowGrid(false);
 
216
    colorTable->setRowCount(12);
 
217
    colorTable->horizontalHeader()->setMinimumSectionSize(minWidth);
 
218
    colorTable->horizontalHeader()->setResizeMode(1, QHeaderView::ResizeToContents);
 
219
 
 
220
    createColorEntry(i18n("Normal Background"),    "BackgroundNormal",    m_backgroundButtons, 0);
 
221
    createColorEntry(i18n("Alternate Background"), "BackgroundAlternate", m_backgroundButtons, 1);
 
222
    createColorEntry(i18n("Normal Text"),          "ForegroundNormal",    m_foregroundButtons, 2);
 
223
    createColorEntry(i18n("Inactive Text"),        "ForegroundInactive",  m_foregroundButtons, 3);
 
224
    createColorEntry(i18n("Active Text"),          "ForegroundActive",    m_foregroundButtons, 4);
 
225
    createColorEntry(i18n("Link Text"),            "ForegroundLink",      m_foregroundButtons, 5);
 
226
    createColorEntry(i18n("Visited Text"),         "ForegroundVisited",   m_foregroundButtons, 6);
 
227
    createColorEntry(i18n("Negative Text"),        "ForegroundNegative",  m_foregroundButtons, 7);
 
228
    createColorEntry(i18n("Neutral Text"),         "ForegroundNeutral",   m_foregroundButtons, 8);
 
229
    createColorEntry(i18n("Positive Text"),        "ForegroundPositive",  m_foregroundButtons, 9);
 
230
    createColorEntry(i18n("Focus Decoration"),     "DecorationFocus",     m_decorationButtons, 10);
 
231
    createColorEntry(i18n("Hover Decoration"),     "DecorationHover",     m_decorationButtons, 11);
 
232
 
 
233
    colorTable->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch);
 
234
    colorTable->horizontalHeader()->setResizeMode(1, QHeaderView::ResizeToContents);
 
235
 
 
236
    updateColorSchemes();
 
237
    updateColorTable();
 
238
}
 
239
 
 
240
QColor KColorCm::commonForeground(KColorScheme::ForegroundRole index)
 
241
{
 
242
    QColor temp = m_colorSchemes[KColorScheme::View].foreground(index).color();
 
243
    for (int i = KColorScheme::Window; i < KColorScheme::Tooltip; ++i)
 
244
    {
 
245
        if (m_colorSchemes[i].foreground(index).color() != temp)
 
246
        {
 
247
            temp = QColor(); // make it an invalid color
 
248
            break;
 
249
        }
 
250
    }
 
251
 
 
252
    return temp;
 
253
}
 
254
 
 
255
void KColorCm::updateColorTable()
 
256
{
 
257
    // subtract one here since the 0 item  is "Common Colors"
 
258
    int currentSet = colorSet->currentIndex() - 1;
 
259
 
 
260
    if (currentSet == -1)
 
261
    {
 
262
        // common colors is selected
 
263
        stackedWidget->setCurrentIndex(0);
 
264
 
 
265
        KColorButton * button;
 
266
        foreach (button, m_commonColorButtons)
 
267
        {
 
268
            button->blockSignals(true);
 
269
        }
 
270
 
 
271
        m_commonColorButtons[0]->setColor(m_colorSchemes[KColorScheme::View].background(KColorScheme::NormalBackground).color());
 
272
        m_commonColorButtons[1]->setColor(m_colorSchemes[KColorScheme::View].foreground(KColorScheme::NormalText).color());
 
273
        m_commonColorButtons[2]->setColor(m_colorSchemes[KColorScheme::Window].background(KColorScheme::NormalBackground).color());
 
274
        m_commonColorButtons[3]->setColor(m_colorSchemes[KColorScheme::Window].foreground(KColorScheme::NormalText).color());
 
275
        m_commonColorButtons[4]->setColor(m_colorSchemes[KColorScheme::Button].background(KColorScheme::NormalBackground).color());
 
276
        m_commonColorButtons[5]->setColor(m_colorSchemes[KColorScheme::Button].foreground(KColorScheme::NormalText).color());
 
277
        m_commonColorButtons[6]->setColor(m_colorSchemes[KColorScheme::Selection].background(KColorScheme::NormalBackground).color());
 
278
        m_commonColorButtons[7]->setColor(m_colorSchemes[KColorScheme::Selection].foreground(KColorScheme::NormalText).color());
 
279
        m_commonColorButtons[8]->setColor(m_colorSchemes[KColorScheme::Selection].foreground(KColorScheme::InactiveText).color());
 
280
 
 
281
        QColor color = commonForeground(KColorScheme::InactiveText);
 
282
        m_stackedWidgets[0]->setCurrentIndex(color.isValid() ? 0 : 1);
 
283
        if (color.isValid())
 
284
        {
 
285
            m_commonColorButtons[9]->setColor(color);
 
286
        }
 
287
        color = commonForeground(KColorScheme::ActiveText);
 
288
        m_stackedWidgets[1]->setCurrentIndex(color.isValid() ? 0 : 1);
 
289
        if (color.isValid())
 
290
        {
 
291
            m_commonColorButtons[10]->setColor(color);
 
292
        }
 
293
        color = commonForeground(KColorScheme::LinkText);
 
294
        m_stackedWidgets[2]->setCurrentIndex(color.isValid() ? 0 : 1);
 
295
        if (color.isValid())
 
296
        {
 
297
            m_commonColorButtons[11]->setColor(color);
 
298
        }
 
299
        color = commonForeground(KColorScheme::VisitedText);
 
300
        m_stackedWidgets[3]->setCurrentIndex(color.isValid() ? 0 : 1);
 
301
        if (color.isValid())
 
302
        {
 
303
            m_commonColorButtons[12]->setColor(color);
 
304
        }
 
305
        color = commonForeground(KColorScheme::NegativeText);
 
306
        m_stackedWidgets[4]->setCurrentIndex(color.isValid() ? 0 : 1);
 
307
        if (color.isValid())
 
308
        {
 
309
            m_commonColorButtons[13]->setColor(color);
 
310
        }
 
311
        color = commonForeground(KColorScheme::NeutralText);
 
312
        m_stackedWidgets[5]->setCurrentIndex(color.isValid() ? 0 : 1);
 
313
        if (color.isValid())
 
314
        {
 
315
            m_commonColorButtons[14]->setColor(color);
 
316
        }
 
317
        color = commonForeground(KColorScheme::PositiveText);
 
318
        m_stackedWidgets[6]->setCurrentIndex(color.isValid() ? 0 : 1);
 
319
        if (color.isValid())
 
320
        {
 
321
            m_commonColorButtons[15]->setColor(color);
 
322
        }
 
323
 
 
324
        m_commonColorButtons[16]->setColor(m_colorSchemes[KColorScheme::Tooltip].background(KColorScheme::NormalBackground).color());
 
325
        m_commonColorButtons[17]->setColor(m_colorSchemes[KColorScheme::Tooltip].foreground(KColorScheme::NormalText).color());
 
326
 
 
327
        // use KGS accessors to get the defaults when none have been written to m_config
 
328
        color = KConfigGroup(m_config, "WM").readEntry("activeBackground");
 
329
        if (!color.isValid())
 
330
        {
 
331
            color = KGlobalSettings::activeTitleColor();
 
332
        }
 
333
        m_commonColorButtons[18]->setColor(color);
 
334
        color = KConfigGroup(m_config, "WM").readEntry("activeForeground");
 
335
        if (!color.isValid())
 
336
        {
 
337
            color = KGlobalSettings::activeTextColor();
 
338
        }
 
339
        m_commonColorButtons[19]->setColor(color);
 
340
        color = KConfigGroup(m_config, "WM").readEntry("inactiveBackground");
 
341
        if (!color.isValid())
 
342
        {
 
343
            color = KGlobalSettings::inactiveTitleColor();
 
344
        }
 
345
        m_commonColorButtons[20]->setColor(color);
 
346
        color = KConfigGroup(m_config, "WM").readEntry("inactiveForeground");
 
347
        if (!color.isValid())
 
348
        {
 
349
            color = KGlobalSettings::activeTitleColor();
 
350
        }
 
351
        m_commonColorButtons[21]->setColor(color);
 
352
 
 
353
        foreach (button, m_commonColorButtons)
 
354
        {
 
355
            button->blockSignals(false);
 
356
        }
 
357
    }
 
358
    else
 
359
    {
 
360
        // a real color set is selected
 
361
        stackedWidget->setCurrentIndex(1);
 
362
 
 
363
        for (int i = KColorScheme::NormalBackground; i <= KColorScheme::AlternateBackground; ++i)
 
364
        {
 
365
            m_backgroundButtons[i]->blockSignals(true);
 
366
            m_backgroundButtons[i]->setColor(m_colorSchemes[currentSet].background(KColorScheme::BackgroundRole(i)).color());
 
367
            m_backgroundButtons[i]->blockSignals(false);
 
368
        }
 
369
 
 
370
        for (int i = KColorScheme::NormalText; i <= KColorScheme::PositiveText; ++i)
 
371
        {
 
372
            m_foregroundButtons[i]->blockSignals(true);
 
373
            m_foregroundButtons[i]->setColor(m_colorSchemes[currentSet].foreground(KColorScheme::ForegroundRole(i)).color());
 
374
            m_foregroundButtons[i]->blockSignals(false);
 
375
        }
 
376
 
 
377
        for (int i = KColorScheme::FocusColor; i <= KColorScheme::HoverColor; ++i)
 
378
        {
 
379
            m_decorationButtons[i]->blockSignals(true);
 
380
            m_decorationButtons[i]->setColor(m_colorSchemes[currentSet].decoration(KColorScheme::DecorationRole(i)).color());
 
381
            m_decorationButtons[i]->blockSignals(false);
 
382
        }
 
383
    }
 
384
}
 
385
 
 
386
void KColorCm::colorChanged( const QColor &newColor )
 
387
{
 
388
    // find which button was changed
 
389
    int row = sender()->objectName().toInt();
 
390
    changeColor(row, newColor);
 
391
}
 
392
 
 
393
void KColorCm::changeColor(int row, const QColor &newColor)
 
394
{
 
395
    // update the m_colorSchemes for the selected colorSet
 
396
    int currentSet = colorSet->currentIndex() - 1;
 
397
 
 
398
    if (currentSet == -1)
 
399
    {
 
400
        // common colors is selected
 
401
        switch (row)
 
402
        {
 
403
            case 0:
 
404
                // View Background button
 
405
                KConfigGroup(m_config, "Colors:View").writeEntry("BackgroundNormal", newColor);
 
406
                break;
 
407
            case 1:
 
408
                // View Text button
 
409
                KConfigGroup(m_config, "Colors:View").writeEntry("ForegroundNormal", newColor);
 
410
                break;
 
411
            case 2:
 
412
                // Window Background Button
 
413
                KConfigGroup(m_config, "Colors:Window").writeEntry("BackgroundNormal", newColor);
 
414
                break;
 
415
            case 3:
 
416
                // Window Text Button
 
417
                KConfigGroup(m_config, "Colors:Window").writeEntry("ForegroundNormal", newColor);
 
418
                break;
 
419
            case 4:
 
420
                // Button Background button
 
421
                KConfigGroup(m_config, "Colors:Button").writeEntry("BackgroundNormal", newColor);
 
422
                break;
 
423
            case 5:
 
424
                // Button Text button
 
425
                KConfigGroup(m_config, "Colors:Button").writeEntry("ForegroundNormal", newColor);
 
426
                break;
 
427
            case 6:
 
428
                // Selection Background Button
 
429
                KConfigGroup(m_config, "Colors:Selection").writeEntry("BackgroundNormal", newColor);
 
430
                break;
 
431
            case 7:
 
432
                // Selection Text Button
 
433
                KConfigGroup(m_config, "Colors:Selection").writeEntry("ForegroundNormal", newColor);
 
434
                break;
 
435
            case 8:
 
436
                // Window Text Button
 
437
                KConfigGroup(m_config, "Colors:Selection").writeEntry("ForegroundInactive", newColor);
 
438
                break;
 
439
 
 
440
            // buttons that could have varies in their place
 
441
            case 9:
 
442
                // Inactive Text Button (set all but Selection Inactive Text color)
 
443
                KConfigGroup(m_config, "Colors:View").writeEntry("ForegroundInactive", newColor);
 
444
                KConfigGroup(m_config, "Colors:Window").writeEntry("ForegroundInactive", newColor);
 
445
                KConfigGroup(m_config, "Colors:Button").writeEntry("ForegroundInactive", newColor);
 
446
                KConfigGroup(m_config, "Colors:Tooltip").writeEntry("ForegroundInactive", newColor);
 
447
                break;
 
448
            case 10:
 
449
                // Active Text Button (set all active text colors)
 
450
                KConfigGroup(m_config, "Colors:View").writeEntry("ForegroundActive", newColor);
 
451
                KConfigGroup(m_config, "Colors:Window").writeEntry("ForegroundActive", newColor);
 
452
                KConfigGroup(m_config, "Colors:Selection").writeEntry("ForegroundActive", newColor);
 
453
                KConfigGroup(m_config, "Colors:Button").writeEntry("ForegroundActive", newColor);
 
454
                KConfigGroup(m_config, "Colors:Tooltip").writeEntry("ForegroundActive", newColor);
 
455
                break;
 
456
            case 11:
 
457
                // Link Text Button (set all active text colors)
 
458
                KConfigGroup(m_config, "Colors:View").writeEntry("ForegroundLink", newColor);
 
459
                KConfigGroup(m_config, "Colors:Window").writeEntry("ForegroundLink", newColor);
 
460
                KConfigGroup(m_config, "Colors:Selection").writeEntry("ForegroundLink", newColor);
 
461
                KConfigGroup(m_config, "Colors:Button").writeEntry("ForegroundLink", newColor);
 
462
                KConfigGroup(m_config, "Colors:Tooltip").writeEntry("ForegroundLink", newColor);
 
463
                break;
 
464
            case 12:
 
465
                // Visited Text Button (set all active text colors)
 
466
                KConfigGroup(m_config, "Colors:View").writeEntry("ForegroundVisited", newColor);
 
467
                KConfigGroup(m_config, "Colors:Window").writeEntry("ForegroundVisited", newColor);
 
468
                KConfigGroup(m_config, "Colors:Selection").writeEntry("ForegroundVisited", newColor);
 
469
                KConfigGroup(m_config, "Colors:Button").writeEntry("ForegroundVisited", newColor);
 
470
                KConfigGroup(m_config, "Colors:Tooltip").writeEntry("ForegroundVisited", newColor);
 
471
                break;
 
472
            case 13:
 
473
                // Negative Text Button (set all active text colors)
 
474
                KConfigGroup(m_config, "Colors:View").writeEntry("ForegroundNegavite", newColor);
 
475
                KConfigGroup(m_config, "Colors:Window").writeEntry("ForegroundNegavite", newColor);
 
476
                KConfigGroup(m_config, "Colors:Selection").writeEntry("ForegroundNegavite", newColor);
 
477
                KConfigGroup(m_config, "Colors:Button").writeEntry("ForegroundNegavite", newColor);
 
478
                KConfigGroup(m_config, "Colors:Tooltip").writeEntry("ForegroundNegavite", newColor);
 
479
                break;
 
480
            case 14:
 
481
                // Neutral Text Button (set all active text colors)
 
482
                KConfigGroup(m_config, "Colors:View").writeEntry("ForegroundNeutral", newColor);
 
483
                KConfigGroup(m_config, "Colors:Window").writeEntry("ForegroundNeutral", newColor);
 
484
                KConfigGroup(m_config, "Colors:Selection").writeEntry("ForegroundNeutral", newColor);
 
485
                KConfigGroup(m_config, "Colors:Button").writeEntry("ForegroundNeutral", newColor);
 
486
                KConfigGroup(m_config, "Colors:Tooltip").writeEntry("ForegroundNeutral", newColor);
 
487
                break;
 
488
            case 15:
 
489
                // Positive Text Button (set all active text colors)
 
490
                KConfigGroup(m_config, "Colors:View").writeEntry("ForegroundPositive", newColor);
 
491
                KConfigGroup(m_config, "Colors:Window").writeEntry("ForegroundPositive", newColor);
 
492
                KConfigGroup(m_config, "Colors:Selection").writeEntry("ForegroundPositive", newColor);
 
493
                KConfigGroup(m_config, "Colors:Button").writeEntry("ForegroundPositive", newColor);
 
494
                KConfigGroup(m_config, "Colors:Tooltip").writeEntry("ForegroundPositive", newColor);
 
495
                break;
 
496
 
 
497
            case 16:
 
498
                // Tooltip Background button
 
499
                KConfigGroup(m_config, "Colors:Tooltip").writeEntry("BackgroundNormal", newColor);
 
500
                break;
 
501
            case 17:
 
502
                // Tooltip Text button
 
503
                KConfigGroup(m_config, "Colors:Tooltip").writeEntry("ForegroundNormal", newColor);
 
504
                break;
 
505
            case 18:
 
506
                // Active Window
 
507
                KConfigGroup(m_config, "WM").writeEntry("activeBackground", newColor);
 
508
                break;
 
509
            case 19:
 
510
                // Active Window Text
 
511
                KConfigGroup(m_config, "WM").writeEntry("activeForeground", newColor);
 
512
                break;
 
513
            case 20:
 
514
                // Inactive Window
 
515
                KConfigGroup(m_config, "WM").writeEntry("inactiveBackground", newColor);
 
516
                break;
 
517
            case 21:
 
518
                // Inactive Window Text
 
519
                KConfigGroup(m_config, "WM").writeEntry("inactiveForeground", newColor);
 
520
                break;
 
521
        }
 
522
        m_commonColorButtons[row]->blockSignals(true);
 
523
        m_commonColorButtons[row]->setColor(newColor);
 
524
        m_commonColorButtons[row]->blockSignals(false);
 
525
    }
 
526
    else
 
527
    {
 
528
        QString group = colorSetGroupKey(currentSet);
 
529
        KConfigGroup(m_config, group).writeEntry(m_colorKeys[row], newColor);
 
530
    }
 
531
 
 
532
    updateColorSchemes();
 
533
 
 
534
    schemePreview->setPalette(m_config);
 
535
    inactivePreview->setPalette(m_config, QPalette::Inactive);
 
536
    disabledPreview->setPalette(m_config, QPalette::Disabled);
 
537
 
 
538
    emit changed(true);
 
539
}
 
540
 
 
541
QString KColorCm::colorSetGroupKey(int colorSet)
 
542
{
 
543
    QString group;
 
544
    switch (colorSet) {
 
545
        case KColorScheme::Window:
 
546
            group = "Colors:Window";
 
547
            break;
 
548
        case KColorScheme::Button:
 
549
            group = "Colors:Button";
 
550
            break;
 
551
        case KColorScheme::Selection:
 
552
            group = "Colors:Selection";
 
553
            break;
 
554
        case KColorScheme::Tooltip:
 
555
            group = "Colors:Tooltip";
 
556
            break;
 
557
        default:
 
558
            group = "Colors:View";
 
559
    }
 
560
    return group;
 
561
}
 
562
 
 
563
void KColorCm::on_contrastSlider_valueChanged(int value)
 
564
{
 
565
    KConfigGroup group(m_config, "KDE");
 
566
    group.writeEntry("contrast", value);
 
567
 
 
568
    schemePreview->setPalette(m_config);
 
569
    inactivePreview->setPalette(m_config, QPalette::Inactive);
 
570
    disabledPreview->setPalette(m_config, QPalette::Disabled);
 
571
 
 
572
    emit changed(true);
 
573
}
 
574
 
 
575
void KColorCm::on_shadeSortedColumn_stateChanged(int state)
 
576
{
 
577
    KConfigGroup group(m_config, "General");
 
578
    group.writeEntry("shadeSortColumn", (bool)state);
 
579
 
 
580
    emit changed(true);
 
581
}
 
582
 
 
583
void KColorCm::load()
 
584
{
 
585
    // clean the config, in case we have changed the in-memory kconfig
 
586
    m_config->clean();
 
587
 
 
588
    // update the color table
 
589
    updateColorTable();
 
590
 
 
591
    // fill in the color scheme list
 
592
    populateSchemeList();
 
593
 
 
594
    contrastSlider->setValue(KGlobalSettings::contrast());
 
595
    shadeSortedColumn->setCheckState(KGlobalSettings::shadeSortColumn() ?
 
596
        Qt::Checked : Qt::Unchecked);
 
597
 
 
598
    schemePreview->setPalette(m_config);
 
599
    inactivePreview->setPalette(m_config, QPalette::Inactive);
 
600
    disabledPreview->setPalette(m_config, QPalette::Disabled);
290
601
 
291
602
    emit changed(false);
292
603
}
293
604
 
294
 
 
295
 
void KColorScheme::save()
 
605
void KColorCm::save()
296
606
{
297
 
    KConfigGroup cfg(KGlobal::config(), "General");
298
 
    cfg.writeEntry("background", cs->back, KConfigBase::Normal|KConfigBase::Global);
299
 
    cfg.writeEntry("selectBackground", cs->select, KConfigBase::Normal|KConfigBase::Global);
300
 
    cfg.writeEntry("foreground", cs->txt, KConfigBase::Normal|KConfigBase::Global);
301
 
    cfg.writeEntry("windowForeground", cs->windowTxt, KConfigBase::Normal|KConfigBase::Global);
302
 
    cfg.writeEntry("windowBackground", cs->window, KConfigBase::Normal|KConfigBase::Global);
303
 
    cfg.writeEntry("selectForeground", cs->selectTxt, KConfigBase::Normal|KConfigBase::Global);
304
 
    cfg.writeEntry("buttonBackground", cs->button, KConfigBase::Normal|KConfigBase::Global);
305
 
    cfg.writeEntry("buttonForeground", cs->buttonTxt, KConfigBase::Normal|KConfigBase::Global);
306
 
    cfg.writeEntry("linkColor", cs->link, KConfigBase::Normal|KConfigBase::Global);
307
 
    cfg.writeEntry("visitedLinkColor", cs->visitedLink, KConfigBase::Normal|KConfigBase::Global);
308
 
    cfg.writeEntry("alternateBackground", cs->alternateBackground, KConfigBase::Normal|KConfigBase::Global);
309
 
 
310
 
    cfg.writeEntry("shadeSortColumn", cs->shadeSortColumn, KConfigBase::Normal|KConfigBase::Global);
311
 
 
312
 
    cfg.changeGroup( "WM" );
313
 
    cfg.writeEntry("activeForeground", cs->aTxt, KConfigBase::Normal|KConfigBase::Global);
314
 
    cfg.writeEntry("inactiveBackground", cs->iaTitle, KConfigBase::Normal|KConfigBase::Global);
315
 
    cfg.writeEntry("inactiveBlend", cs->iaBlend, KConfigBase::Normal|KConfigBase::Global);
316
 
    cfg.writeEntry("activeBackground", cs->aTitle, KConfigBase::Normal|KConfigBase::Global);
317
 
    cfg.writeEntry("activeBlend", cs->aBlend, KConfigBase::Normal|KConfigBase::Global);
318
 
    cfg.writeEntry("inactiveForeground", cs->iaTxt, KConfigBase::Normal|KConfigBase::Global);
319
 
    cfg.writeEntry("activeTitleBtnBg", cs->aTitleBtn, KConfigBase::Normal|KConfigBase::Global);
320
 
    cfg.writeEntry("inactiveTitleBtnBg", cs->iTitleBtn, KConfigBase::Normal|KConfigBase::Global);
321
 
    cfg.writeEntry("frame", cs->aFrame, KConfigBase::Normal|KConfigBase::Global);
322
 
    cfg.writeEntry("inactiveFrame", cs->iaFrame, KConfigBase::Normal|KConfigBase::Global);
323
 
    cfg.writeEntry("handle", cs->aHandle, KConfigBase::Normal|KConfigBase::Global);
324
 
    cfg.writeEntry("inactiveHandle", cs->iaHandle, KConfigBase::Normal|KConfigBase::Global);
325
 
 
326
 
    cfg.changeGroup( "KDE" );
327
 
    cfg.writeEntry("contrast", cs->contrast, KConfigBase::Normal|KConfigBase::Global);
328
 
    cfg.writeEntry("colorScheme", sCurrentScheme, KConfigBase::Normal|KConfigBase::Global);
329
 
    cfg.sync();
330
 
 
331
 
    // KDE-1.x support
332
 
    KConfigGroup config(KSharedConfig::openConfig( QDir::homePath() + "/.kderc" ), "General" );
333
 
    config.writeEntry("background", cs->back );
334
 
    config.writeEntry("selectBackground", cs->select );
335
 
    config.writeEntry("foreground", cs->txt, KConfigBase::Normal|KConfigBase::Global);
336
 
    config.writeEntry("windowForeground", cs->windowTxt );
337
 
    config.writeEntry("windowBackground", cs->window );
338
 
    config.writeEntry("selectForeground", cs->selectTxt );
339
 
    config.sync();
340
 
 
341
 
    KConfig _cfg2("kcmdisplayrc", KConfig::NoGlobals);
342
 
    KConfigGroup cfg2(&_cfg2, "X11");
343
 
    bool exportColors = cbExportColors->isChecked();
344
 
    cfg2.writeEntry("exportKDEColors", exportColors);
345
 
    cfg2.sync();
346
 
    QApplication::syncX();
347
 
 
348
 
    // Notify all qt-only apps of the KDE palette changes
349
 
    uint flags = KRdbExportQtColors;
350
 
    if ( exportColors )
351
 
        flags |= KRdbExportColors;
352
 
    else
353
 
    {
354
 
#if defined Q_WS_X11
355
 
        // Undo the property xrdb has placed on the root window (if any),
356
 
        // i.e. remove all entries, including ours
357
 
        XDeleteProperty( QX11Info::display(), QX11Info::appRootWindow(), XA_RESOURCE_MANAGER );
358
 
#endif
359
 
    }
360
 
    runRdb( flags );    // Save the palette to qtrc for KStyles
361
 
 
362
 
    // Notify all KDE applications
 
607
    m_config->sync();
363
608
    KGlobalSettings::self()->emitChange(KGlobalSettings::PaletteChanged);
364
 
 
365
 
    // Update the "Current Scheme"
366
 
    int current = findSchemeByName(sCurrentScheme);
367
 
    sList->setCurrentItem(0);
368
 
    readScheme(0);
369
 
    QPixmap preview = mkColorPreview(cs);
370
 
    sList->item(0)->setIcon(preview);
371
 
    sList->setCurrentRow(current);
372
 
    readScheme(current);
373
 
    preview = mkColorPreview(cs);
374
 
    sList->item(current)->setIcon(preview);
 
609
#ifdef Q_WS_X11
 
610
    // Send signal to all kwin instances
 
611
    QDBusMessage message =
 
612
       QDBusMessage::createSignal("/KWin", "org.kde.KWin", "reloadConfig");
 
613
    QDBusConnection::sessionBus().send(message);
 
614
#endif
375
615
 
376
616
    emit changed(false);
377
617
}
378
618
 
379
 
 
380
 
void KColorScheme::defaults()
381
 
{
382
 
    readScheme(1);
383
 
    sList->setCurrentRow(1);
384
 
 
385
 
    cbShadeList->setChecked(cs->shadeSortColumn);
386
 
 
387
 
    cs->drawSampleWidgets();
388
 
    sb->blockSignals(true);
389
 
    sb->setValue(cs->contrast);
390
 
    sb->blockSignals(false);
391
 
 
392
 
    cbExportColors->setChecked(true);
393
 
 
394
 
    emit changed(true);
395
 
}
396
 
 
397
 
void KColorScheme::sliderValueChanged( int val )
398
 
{
399
 
    cs->contrast = val;
400
 
    cs->drawSampleWidgets();
401
 
 
402
 
    sCurrentScheme.clear();
403
 
 
404
 
    emit changed(true);
405
 
}
406
 
 
407
 
 
408
 
void KColorScheme::slotSave( )
409
 
{
410
 
    KColorSchemeEntry *entry = mSchemeList->at(sList->currentRow()-nSysSchemes);
411
 
    if (!entry) return;
412
 
    sCurrentScheme = entry->path;
413
 
    KConfig *config = new KConfig(sCurrentScheme, KConfig::OnlyLocal);
414
 
    int i = sCurrentScheme.lastIndexOf('/');
415
 
    if (i >= 0)
416
 
      sCurrentScheme = sCurrentScheme.mid(i+1);
417
 
 
418
 
    KConfigGroup group = config->group("Color Scheme" );
419
 
    group.writeEntry("background", cs->back );
420
 
    group.writeEntry("selectBackground", cs->select );
421
 
    group.writeEntry("foreground", cs->txt );
422
 
    group.writeEntry("activeForeground", cs->aTxt );
423
 
    group.writeEntry("inactiveBackground", cs->iaTitle );
424
 
    group.writeEntry("inactiveBlend", cs->iaBlend );
425
 
    group.writeEntry("activeBackground", cs->aTitle );
426
 
    group.writeEntry("activeBlend", cs->aBlend );
427
 
    group.writeEntry("inactiveForeground", cs->iaTxt );
428
 
    group.writeEntry("windowForeground", cs->windowTxt );
429
 
    group.writeEntry("windowBackground", cs->window );
430
 
    group.writeEntry("selectForeground", cs->selectTxt );
431
 
    group.writeEntry("contrast", cs->contrast );
432
 
    group.writeEntry("buttonForeground", cs->buttonTxt );
433
 
    group.writeEntry("buttonBackground", cs->button );
434
 
    group.writeEntry("activeTitleBtnBg", cs->aTitleBtn);
435
 
    group.writeEntry("inactiveTitleBtnBg", cs->iTitleBtn);
436
 
    group.writeEntry("frame", cs->aFrame);
437
 
    group.writeEntry("inactiveFrame", cs->iaFrame);
438
 
    group.writeEntry("handle", cs->aHandle);
439
 
    group.writeEntry("inactiveHandle", cs->iaHandle);
440
 
    group.writeEntry("linkColor", cs->link);
441
 
    group.writeEntry("visitedLinkColor", cs->visitedLink);
442
 
    group.writeEntry("alternateBackground", cs->alternateBackground);
443
 
    group.writeEntry("shadeSortColumn", cs->shadeSortColumn);
444
 
 
445
 
    delete config;
446
 
}
447
 
 
448
 
 
449
 
void KColorScheme::slotRemove()
450
 
{
451
 
    int ind = sList->currentRow();
452
 
    KColorSchemeEntry *entry = mSchemeList->at(ind-nSysSchemes);
453
 
    if (!entry) return;
454
 
 
455
 
    if (unlink(QFile::encodeName(entry->path).data())) {
456
 
        KMessageBox::error( 0,
457
 
          i18n("This color scheme could not be removed.\n"
458
 
           "Perhaps you do not have permission to alter the file"
459
 
           "system where the color scheme is stored." ));
460
 
        return;
461
 
    }
462
 
 
463
 
    delete sList->takeItem(ind);
464
 
    mSchemeList->remove(entry);
465
 
 
466
 
    ind = sList->currentRow();
467
 
    entry = mSchemeList->at(ind-nSysSchemes);
468
 
    if (!entry) return;
469
 
    removeBt->setEnabled(entry ? entry->local : false);
470
 
}
471
 
 
472
 
 
473
 
/*
474
 
 * Add a local color scheme.
475
 
 */
476
 
void KColorScheme::slotAdd()
477
 
{
478
 
    QString sName;
479
 
    if (sList->currentRow() >= nSysSchemes)
480
 
       sName = sList->currentItem()->text();
481
 
 
482
 
    QString sFile;
483
 
 
484
 
    bool valid = false;
485
 
    bool ok;
486
 
    int exists = -1;
487
 
 
488
 
    while (!valid)
489
 
    {
490
 
        sName = KInputDialog::getText( i18n( "Save Color Scheme" ),
491
 
            i18n( "Enter a name for the color scheme:" ), sName, &ok, this );
492
 
        if (!ok)
493
 
            return;
494
 
 
495
 
        sName = sName.simplified();
496
 
        sFile = sName;
497
 
 
498
 
        int i = 0;
499
 
 
500
 
        exists = -1;
501
 
        // Check if it's already there
502
 
        for (i=0; i < (int) sList->count(); i++)
503
 
        {
504
 
            if (sName == sList->item(i)->text())
505
 
            {
506
 
                exists = i;
507
 
                int result = KMessageBox::warningContinueCancel( this,
508
 
                   i18n("A color scheme with the name '%1' already exists.\n"
509
 
                        "Do you want to overwrite it?\n", sName),
510
 
                   i18n("Save Color Scheme"),
511
 
                   KGuiItem(i18n("Overwrite")));
512
 
                if (result == KMessageBox::Cancel)
513
 
                    break;
514
 
            }
515
 
        }
516
 
        if (i == (int) sList->count())
517
 
            valid = true;
518
 
    }
519
 
 
520
 
    disconnect(sList, SIGNAL(currentRowChanged(int)), this,
521
 
               SLOT(slotPreviewScheme(int)));
522
 
 
523
 
    if (exists != -1)
524
 
    {
525
 
       sList->setFocus();
526
 
       sList->setCurrentRow(exists);
527
 
    }
528
 
    else
529
 
    {
530
 
       sFile = KGlobal::dirs()->saveLocation("data", "kdisplay/color-schemes/") + sFile + ".kcsrc";
531
 
       KConfigGroup config(KSharedConfig::openConfig(sFile, KConfig::OnlyLocal), "Color Scheme");
532
 
       config.writeEntry("Name", sName);
533
 
 
534
 
       insertEntry(sFile, sName);
535
 
 
536
 
    }
537
 
    slotSave();
538
 
 
539
 
    QPixmap preview = mkColorPreview(cs);
540
 
    int current = sList->currentRow();
541
 
    sList->item(current)->setIcon(preview);
542
 
    connect(sList, SIGNAL(currentRowChanged(int)), SLOT(slotPreviewScheme(int)));
543
 
    slotPreviewScheme(current);
544
 
}
545
 
 
546
 
void KColorScheme::slotImport()
547
 
{
548
 
        QString location = KStandardDirs::locateLocal( "data", "kdisplay/color-schemes/" );
549
 
 
550
 
        KUrl file ( KFileDialog::getOpenFileName(QString(), "*.kcsrc", this) );
551
 
        if ( file.isEmpty() )
552
 
                return;
553
 
 
554
 
        //kDebug() << "Location: " << location;
555
 
        if (!KIO::NetAccess::file_copy(file, KUrl( location+file.fileName( KUrl::ObeyTrailingSlash ) ) ) )
556
 
        {
557
 
                KMessageBox::error(this, KIO::NetAccess::lastErrorString(),i18n("Import failed."));
558
 
                return;
559
 
        }
560
 
        else
561
 
        {
562
 
                QString sFile = location + file.fileName( false );
563
 
                KConfigGroup config(KSharedConfig::openConfig(sFile, KConfig::OnlyLocal), "Color Scheme");
564
 
                QString sName = config.readEntry("Name", i18n("Untitled Theme"));
565
 
 
566
 
                insertEntry(sFile, sName);
567
 
                QPixmap preview = mkColorPreview(cs);
568
 
                int current = sList->currentRow();
569
 
                sList->item(current)->setIcon(preview);
570
 
                connect(sList, SIGNAL(currentRowChanged(int)), SLOT(slotPreviewScheme(int)));
571
 
                slotPreviewScheme(current);
572
 
        }
573
 
}
574
 
 
575
 
QColor &KColorScheme::color(int index)
576
 
{
577
 
    switch(index) {
578
 
    case CSM_Inactive_title_bar:
579
 
    return cs->iaTitle;
580
 
    case CSM_Inactive_title_text:
581
 
    return cs->iaTxt;
582
 
    case CSM_Inactive_title_blend:
583
 
    return cs->iaBlend;
584
 
    case CSM_Active_title_bar:
585
 
    return cs->aTitle;
586
 
    case CSM_Active_title_text:
587
 
    return cs->aTxt;
588
 
    case CSM_Active_title_blend:
589
 
    return cs->aBlend;
590
 
    case CSM_Background:
591
 
    return cs->back;
592
 
    case CSM_Text:
593
 
    return cs->txt;
594
 
    case CSM_Select_background:
595
 
    return cs->select;
596
 
    case CSM_Select_text:
597
 
    return cs->selectTxt;
598
 
    case CSM_Standard_background:
599
 
    return cs->window;
600
 
    case CSM_Standard_text:
601
 
    return cs->windowTxt;
602
 
    case CSM_Button_background:
603
 
    return cs->button;
604
 
    case CSM_Button_text:
605
 
    return cs->buttonTxt;
606
 
    case CSM_Active_title_button:
607
 
    return cs->aTitleBtn;
608
 
    case CSM_Inactive_title_button:
609
 
    return cs->iTitleBtn;
610
 
    case CSM_Active_frame:
611
 
    return cs->aFrame;
612
 
    case CSM_Active_handle:
613
 
    return cs->aHandle;
614
 
    case CSM_Inactive_frame:
615
 
    return cs->iaFrame;
616
 
    case CSM_Inactive_handle:
617
 
    return cs->iaHandle;
618
 
    case CSM_Link:
619
 
    return cs->link;
620
 
    case CSM_Followed_Link:
621
 
    return cs->visitedLink;
622
 
    case CSM_Alternate_background:
623
 
    return cs->alternateBackground;
624
 
    }
625
 
 
626
 
    assert(0); // Should never be here!
627
 
    return cs->iaTxt; // Silence compiler
628
 
}
629
 
 
630
 
void KColorScheme::slotColorForWidget(int indx, const QColor& col)
631
 
{
632
 
    mColorTreeWidget->setColor( indx , col );
633
 
}
634
 
 
635
 
void KColorScheme::slotShadeSortColumnChanged(bool b)
636
 
{
637
 
    cs->shadeSortColumn = b;
638
 
    sCurrentScheme.clear();
639
 
 
640
 
    emit changed(true);
641
 
}
642
 
 
643
 
/*
644
 
 * Read a color scheme into "cs".
645
 
 *
646
 
 * KEEP IN SYNC with thememgr!
647
 
 */
648
 
void KColorScheme::readScheme( int index )
649
 
{
650
 
    QColor widget(239, 239, 239);
651
 
    QColor kde34Blue(103,141,178);
652
 
    QColor inactiveBackground(157,170,186);
653
 
    QColor activeBackground(65,142,220);
654
 
    QColor inactiveForeground(221,221,221);
655
 
    QColor activeBlend(107,145,184);
656
 
    QColor inactiveBlend(157,170,186);
657
 
    QColor activeTitleBtnBg(220,220,220);
658
 
    QColor inactiveTitleBtnBg(220,220,220);
659
 
    QColor alternateBackground(237,244,249);
660
 
 
661
 
    QColor button;
662
 
    if (QPixmap::defaultDepth() > 8)
663
 
      button.setRgb(221, 223, 228 );
664
 
    else
665
 
      button.setRgb(220, 220, 220);
666
 
 
667
 
    QColor link(0, 0, 238);
668
 
    QColor visitedLink(82, 24,139);
669
 
 
670
 
    // note: keep default color scheme in sync with default Current Scheme
671
 
    if (index == 1) {
672
 
      sCurrentScheme  = "<default>";
673
 
      cs->txt         = Qt::black;
674
 
      cs->back        = widget;
675
 
      cs->select      = kde34Blue;
676
 
      cs->selectTxt   = Qt::white;
677
 
      cs->window      = Qt::white;
678
 
      cs->windowTxt   = Qt::black;
679
 
      cs->iaTitle     = inactiveBackground;
680
 
      cs->iaTxt       = inactiveForeground;
681
 
      cs->iaBlend     = inactiveBlend;
682
 
      cs->aTitle      = activeBackground;
683
 
      cs->aTxt        = Qt::white;
684
 
      cs->aBlend      = activeBlend;
685
 
      cs->button      = button;
686
 
      cs->buttonTxt   = Qt::black;
687
 
      cs->aTitleBtn   = activeTitleBtnBg;
688
 
      cs->iTitleBtn   = inactiveTitleBtnBg;
689
 
      cs->aFrame      = cs->back;
690
 
      cs->aHandle     = cs->back;
691
 
      cs->iaFrame     = cs->back;
692
 
      cs->iaHandle    = cs->back;
693
 
      cs->link        = link;
694
 
      cs->visitedLink = visitedLink;
695
 
      cs->alternateBackground = alternateBackground;
696
 
 
697
 
      cs->contrast    = 7;
698
 
      cs->shadeSortColumn = KDE_DEFAULT_SHADE_SORT_COLUMN;
699
 
 
700
 
      return;
701
 
    }
702
 
 
703
 
    KConfig *config;
704
 
    KConfigGroup group;
705
 
    if (index == 0) {
706
 
      // Current scheme
707
 
      config = KGlobal::config().data();
708
 
      group = config->group("General");
709
 
    } else {
710
 
      // Open scheme file
711
 
      KColorSchemeEntry *entry = mSchemeList->at(sList->currentRow()-nSysSchemes);
712
 
      if (!entry) return;
713
 
      sCurrentScheme = entry->path;
714
 
      config = new KConfig(sCurrentScheme, KConfig::OnlyLocal);
715
 
      group = config->group("Color Scheme");
716
 
      int i = sCurrentScheme.lastIndexOf('/');
717
 
      if (i >= 0)
718
 
        sCurrentScheme = sCurrentScheme.mid(i+1);
719
 
    }
720
 
 
721
 
    cs->shadeSortColumn = group.readEntry( "shadeSortColumn", KDE_DEFAULT_SHADE_SORT_COLUMN );
722
 
 
723
 
    // note: defaults should be the same as the KDE default
724
 
    QColor auxBlack, auxWhite;
725
 
    auxBlack = Qt::black;
726
 
    auxWhite = Qt::white;
727
 
    cs->txt = group.readEntry( "foreground", auxBlack );
728
 
    cs->back = group.readEntry( "background", widget );
729
 
    cs->select = group.readEntry( "selectBackground", kde34Blue );
730
 
    cs->selectTxt = group.readEntry( "selectForeground", auxWhite );
731
 
    cs->window = group.readEntry( "windowBackground", auxWhite );
732
 
    cs->windowTxt = group.readEntry( "windowForeground", auxBlack );
733
 
    cs->button = group.readEntry( "buttonBackground", button );
734
 
    cs->buttonTxt = group.readEntry( "buttonForeground", auxBlack );
735
 
    cs->link = group.readEntry( "linkColor", link );
736
 
    cs->visitedLink = group.readEntry( "visitedLinkColor", visitedLink );
737
 
    QColor alternate = KGlobalSettings::calculateAlternateBackgroundColor(cs->window);
738
 
    cs->alternateBackground = group.readEntry( "alternateBackground", alternate );
739
 
 
740
 
    if (index == 0)
741
 
      group = config->group( "WM" );
742
 
 
743
 
    cs->iaTitle = group.readEntry("inactiveBackground", inactiveBackground);
744
 
    cs->iaTxt = group.readEntry("inactiveForeground", inactiveForeground);
745
 
    cs->iaBlend = group.readEntry("inactiveBlend", inactiveBackground);
746
 
    cs->iaFrame = group.readEntry("inactiveFrame", cs->back);
747
 
    cs->iaHandle = group.readEntry("inactiveHandle", cs->back);
748
 
    cs->aTitle = group.readEntry("activeBackground", activeBackground);
749
 
    cs->aTxt = group.readEntry("activeForeground", auxWhite);
750
 
    cs->aBlend = group.readEntry("activeBlend", activeBlend);
751
 
    cs->aFrame = group.readEntry("frame", cs->back);
752
 
    cs->aHandle = group.readEntry("handle", cs->back);
753
 
    // hack - this is all going away. For now just set all to button bg
754
 
    cs->aTitleBtn = group.readEntry("activeTitleBtnBg", activeTitleBtnBg);
755
 
    cs->iTitleBtn = group.readEntry("inactiveTitleBtnBg", inactiveTitleBtnBg);
756
 
 
757
 
    if (index == 0)
758
 
      group = config->group( "KDE" );
759
 
 
760
 
    cs->contrast = group.readEntry( "contrast", 7 );
761
 
    if (index != 0)
762
 
      delete config;
763
 
 
764
 
    mColorTreeWidget->blockSignals(true);   //block the colorChanged signal
765
 
    for(int f=0; f< CSM_LAST ; f++)
766
 
        mColorTreeWidget->setColor( f , color(f) );
767
 
    mColorTreeWidget->blockSignals(false);
768
 
 
769
 
}
770
 
 
771
 
 
772
 
/*
773
 
 * Get all installed color schemes.
774
 
 */
775
 
void KColorScheme::readSchemeNames()
776
 
{
777
 
    mSchemeList->clear();
778
 
    sList->clear();
779
 
    // Always a current and a default scheme
780
 
    sList->insertItem( 0 , i18n("Current Scheme") );
781
 
    sList->insertItem( 1 , i18n("KDE Default") );
782
 
    nSysSchemes = 2;
783
 
 
784
 
    // Global + local schemes
785
 
    QStringList list = KGlobal::dirs()->findAllResources("data",
786
 
            "kdisplay/color-schemes/*.kcsrc", KStandardDirs::NoDuplicates);
787
 
 
788
 
    // And add them
789
 
    for (QStringList::ConstIterator it = list.begin(); it != list.end(); ++it) {
790
 
       KConfigGroup config(KSharedConfig::openConfig(*it, KConfig::OnlyLocal), "Color Scheme");
791
 
       QString str = config.readEntry("Name");
792
 
       if (str.isEmpty()) {
793
 
          str =  config.readEntry("name");
794
 
          if (str.isEmpty())
795
 
             continue;
796
 
       }
797
 
       mSchemeList->append(new KColorSchemeEntry(*it, str, !config.isImmutable()));
798
 
    }
799
 
 
800
 
    mSchemeList->sort();
801
 
 
802
 
    for(KColorSchemeEntry *entry = mSchemeList->first(); entry; entry = mSchemeList->next())
803
 
    {
804
 
       sList->addItem(entry->name);
805
 
    }
806
 
 
807
 
    for (int i = 0; i < (nSysSchemes + mSchemeList->count()); i++)
808
 
    {
809
 
       sList->setCurrentRow(i);
810
 
       readScheme(i);
811
 
       QPixmap preview = mkColorPreview(cs);
812
 
       sList->item(i)->setIcon(preview);
813
 
    }
814
 
 
815
 
}
816
 
 
817
 
/*
818
 
 * Find scheme based on filename
819
 
 */
820
 
int KColorScheme::findSchemeByName(const QString &scheme)
821
 
{
822
 
   if (scheme.isEmpty())
823
 
      return 0;
824
 
   if (scheme == "<default>")
825
 
      return 1;
826
 
 
827
 
   QString search = scheme;
828
 
   int i = search.lastIndexOf('/');
829
 
   if (i >= 0)
830
 
      search = search.mid(i+1);
831
 
 
832
 
   i = 0;
833
 
 
834
 
   for(KColorSchemeEntry *entry = mSchemeList->first(); entry; entry = mSchemeList->next())
835
 
   {
836
 
      KUrl url;
837
 
      url.setPath(entry->path);
838
 
      if (url.fileName() == search)
839
 
         return i+nSysSchemes;
840
 
      i++;
841
 
   }
842
 
 
843
 
   return 0;
844
 
}
845
 
 
846
 
 
847
 
void KColorScheme::slotPreviewScheme(int indx)
848
 
{
849
 
    readScheme(indx);
850
 
 
851
 
    // Set various appropriate for the scheme
852
 
 
853
 
    cbShadeList->setChecked(cs->shadeSortColumn);
854
 
 
855
 
    cs->drawSampleWidgets();
856
 
    sb->blockSignals(true);
857
 
    sb->setValue(cs->contrast);
858
 
    sb->blockSignals(false);
859
 
    if (indx < nSysSchemes)
860
 
       removeBt->setEnabled(false);
861
 
    else
862
 
    {
863
 
       KColorSchemeEntry *entry = mSchemeList->at(indx-nSysSchemes);
864
 
       removeBt->setEnabled(entry ? entry->local : false);
865
 
    }
866
 
 
867
 
    emit changed((indx != 0));
868
 
}
869
 
 
870
 
 
871
 
/* this function should dissappear: colorscm should work directly on a Qt palette, since
872
 
   this will give us much more cusomization with qt-2.0.
873
 
   */
874
 
QPalette KColorScheme::createPalette()
875
 
{
876
 
    QColorGroup disabledgrp(cs->windowTxt, cs->back, cs->back.light(150),
877
 
                cs->back.dark(), cs->back.dark(120), cs->back.dark(120),
878
 
                cs->window);
879
 
 
880
 
    QColorGroup colgrp(cs->windowTxt, cs->back, cs->back.light(150),
881
 
               cs->back.dark(), cs->back.dark(120), cs->txt, cs->window);
882
 
 
883
 
    colgrp.setColor(QPalette::Highlight, cs->select);
884
 
    colgrp.setColor(QPalette::HighlightedText, cs->selectTxt);
885
 
    colgrp.setColor(QPalette::Button, cs->button);
886
 
    colgrp.setColor(QPalette::ButtonText, cs->buttonTxt);
887
 
    return QPalette( colgrp, disabledgrp, colgrp);
888
 
}
889
 
 
890
 
void KColorScheme::insertEntry(const QString &sFile, const QString &sName)
891
 
{
892
 
       KColorSchemeEntry *newEntry = new KColorSchemeEntry(sFile, sName, true);
893
 
       mSchemeList->inSort(newEntry);
894
 
       int newIndex = mSchemeList->findRef(newEntry)+nSysSchemes;
895
 
       sList->insertItem(newIndex , sName);
896
 
       sList->setCurrentRow(newIndex);
897
 
}
898
 
 
899
 
void KColorScheme::setColorName( const QString & name, int id , int id2 )
900
 
{
901
 
    mColorTreeWidget->addRole( id , id2, name );
902
 
}
903
 
 
904
 
void KColorScheme::slotColorChanged( int selection , const QColor & col)
905
 
{
906
 
    // Adjust the alternate background color if the standard color changes
907
 
    // Only if the previous alternate color was not a user-configured one
908
 
    // of course
909
 
    if ( selection == CSM_Standard_background &&
910
 
         color(CSM_Alternate_background) ==
911
 
         KGlobalSettings::calculateAlternateBackgroundColor(
912
 
             color(CSM_Standard_background) ) )
913
 
    {
914
 
        color(CSM_Alternate_background) =
915
 
            KGlobalSettings::calculateAlternateBackgroundColor( col );
916
 
    }
917
 
 
918
 
    color(selection) = col;
919
 
 
920
 
    cs->drawSampleWidgets();
921
 
 
922
 
    sCurrentScheme.clear();
923
 
 
924
 
    emit changed(true);
925
 
}
926
 
 
927
 
 
928
 
 
929
619
#include "colorscm.moc"