1
// KDE Display color scheme setup module
3
// Copyright (c) Mark Donohoe 1997
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
11
#include <config-workspace.h>
23
#include <Qt3Support/Q3GroupBox>
26
#include <kcolorbutton.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>
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>
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.
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.
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.
40
21
#include "colorscm.h"
41
#include "kcolortreewidget.h"
46
#include <X11/Xatom.h>
49
K_PLUGIN_FACTORY(KolorFactory,
50
registerPlugin<KColorScheme>();
52
K_EXPORT_PLUGIN(KolorFactory("kcmcolors"))
54
class KColorSchemeEntry {
56
KColorSchemeEntry(const QString &_path, const QString &_name, bool _local)
57
: path(_path), name(_name), local(_local) { }
64
class KColorSchemeList : public Q3PtrList<KColorSchemeEntry> {
67
{ setAutoDelete(true); }
69
int compareItems(Q3PtrCollection::Item item1, Q3PtrCollection::Item item2)
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);
81
// make a 24 * 8 pixmap with the main colors in a scheme
82
QPixmap mkColorPreview(const WidgetCanvas *cs)
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);
91
p.drawRect(0,0,3*SIZE,SIZE);
95
/**** KColorScheme ****/
97
KColorScheme::KColorScheme(QWidget *parent, const QVariantList &)
98
: KCModule(KolorFactory::componentData(), parent)
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>"));
115
KConfigGroup cfg(KSharedConfig::openConfig("kcmdisplayrc"), "X11");
116
useRM = cfg.readEntry("useResourceManager", true);
118
cs = new WidgetCanvas( this );
119
cs->setCursor( Qt::PointingHandCursor );
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.") );
130
connect( cs, SIGNAL( colorDropped( int, const QColor&)),
131
SLOT( slotColorForWidget( int, const QColor&)));
133
QSplitter *splitter = new QSplitter(this);
135
Q3GroupBox *group = new Q3GroupBox( i18n("Color Scheme"), splitter );
136
group->setOrientation( Qt::Horizontal );
137
group->setColumns( 1 );
140
sList = new KListWidget( group );
141
mSchemeList = new KColorSchemeList();
142
connect(sList, SIGNAL(currentRowChanged(int)), SLOT(slotPreviewScheme(int)));
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>") );
152
addBt = new QPushButton(i18n("&Save Scheme..."), group);
153
connect(addBt, SIGNAL(clicked()), SLOT(slotAdd()));
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.") );
159
removeBt = new QPushButton(i18n("R&emove Scheme"), group);
160
removeBt->setEnabled(false);
161
connect(removeBt, SIGNAL(clicked()), SLOT(slotRemove()));
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.") );
167
importBt = new QPushButton(i18n("I&mport Scheme..."), group);
168
connect(importBt, SIGNAL(clicked()),SLOT(slotImport()));
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"
176
KVBox *vb=new KVBox(splitter);
179
splitter->addWidget(group);
180
splitter->addWidget(vb);
181
QVBoxLayout *toplayout = new QVBoxLayout(this);
182
toplayout->setMargin(0);
184
toplayout->addWidget(cs);
185
toplayout->addWidget(splitter);
186
setLayout(toplayout);
188
mColorTreeWidget = new KColorTreeWidget(vb);
189
connect(mColorTreeWidget , SIGNAL(colorChanged(int, const QColor& )) ,
190
this , SLOT(slotColorChanged( int, const QColor& ) ));
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);
211
cbShadeList = new QCheckBox(i18n("Shade sorted column in lists"), vb);
212
connect(cbShadeList, SIGNAL(toggled(bool)), this, SLOT(slotShadeSortColumnChanged(bool)));
214
cbShadeList->setWhatsThis(
215
i18n("Check this box to show the sorted column in a list with a shaded background"));
217
group = new Q3GroupBox( i18n("Con&trast"), vb );
219
QVBoxLayout *groupLayout2 = new QVBoxLayout(group);
220
QHBoxLayout *groupLayout = new QHBoxLayout;
221
groupLayout2->addLayout(groupLayout);
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)));
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."));
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 );
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()));
245
cbExportColors->setWhatsThis( i18n("Check this box to apply the"
246
" current color scheme to non-KDE applications."));
249
sList->setCurrentItem( 0 );
253
KAboutData* about = new KAboutData("kcmcolors", 0, ki18n("Colors"), 0, KLocalizedString(),
23
#include <QtCore/QFileInfo>
24
#include <QtGui/QHeaderView>
25
#include <QtGui/QStackedWidget>
26
#include <QtDBus/QtDBus>
28
#include <KColorButton>
29
#include <KColorDialog>
30
#include <KGenericFactory>
32
#include <KGlobalSettings>
34
#include <KListWidget>
35
#include <KStandardDirs>
37
K_PLUGIN_FACTORY( KolorFactory, registerPlugin<KColorCm>(); )
38
K_EXPORT_PLUGIN( KolorFactory("kcmcolors") )
40
KColorCm::KColorCm(QWidget *parent, const QVariantList &)
41
: KCModule( KolorFactory::componentData(), parent )
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")
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 );
265
KColorScheme::~KColorScheme()
271
void KColorScheme::load()
273
KConfigGroup config(KGlobal::config(), "KDE");
274
sCurrentScheme = config.readEntry("colorScheme");
276
sList->setCurrentRow(findSchemeByName(sCurrentScheme));
279
cbShadeList->setChecked(cs->shadeSortColumn);
281
cs->drawSampleWidgets();
282
sb->blockSignals(true);
283
sb->setValue(cs->contrast);
284
sb->blockSignals(false);
286
KConfig _cfg( "kcmdisplayrc", KConfig::NoGlobals );
287
KConfigGroup cfg(&_cfg, "X11");
288
bool exportColors = cfg.readEntry("exportKDEColors", true);
289
cbExportColors->setChecked(exportColors);
53
m_config = KSharedConfig::openConfig("kdeglobals");
57
connect(colorSet, SIGNAL(currentIndexChanged(int)), this, SLOT(updateColorTable()));
58
connect(schemeList, SIGNAL(currentRowChanged(int)), this, SLOT(loadScheme()));
60
// only needs to be called once
71
void KColorCm::populateSchemeList()
73
QStringList schemeFiles = KGlobal::dirs()->findAllResources("data", "color-schemes/*");
74
for (int i = 0; i < schemeFiles.size(); ++i)
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());
84
void KColorCm::loadScheme()
86
if (schemeList->currentItem() != NULL)
88
QString path = KGlobal::dirs()->findResource("data",
89
"color-schemes/" + schemeList->currentItem()->text());
90
KSharedConfigPtr temp = m_config;
91
m_config = KSharedConfig::openConfig(path);
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());
98
updateFromColorSchemes();
101
schemePreview->setPalette(m_config);
102
inactivePreview->setPalette(m_config, QPalette::Inactive);
103
disabledPreview->setPalette(m_config, QPalette::Disabled);
109
void KColorCm::createColorEntry(QString text, QString key, QList<KColorButton *> &list, int index)
111
KColorButton *button = new KColorButton(this);
112
button->setObjectName(QString::number(index));
113
connect(button, SIGNAL(changed(const QColor &)), this, SLOT(colorChanged(const QColor &)));
116
m_colorKeys.insert(index, key);
118
QTableWidgetItem *label = new QTableWidgetItem(text);
119
colorTable->setItem(index, 0, label);
120
colorTable->setCellWidget(index, 1, button);
123
void KColorCm::variesClicked()
125
// find which button was changed
126
int row = sender()->objectName().toInt();
129
if(KColorDialog::getColor(color, this ) != QDialog::Rejected )
131
changeColor(row, color);
132
m_stackedWidgets[row - 9]->setCurrentIndex(0);
136
void KColorCm::updateColorSchemes()
138
m_colorSchemes.clear();
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));
147
void KColorCm::updateFromColorSchemes()
149
for (int i = KColorScheme::View; i <= KColorScheme::Tooltip; ++i)
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());
166
KConfigGroup KDEgroup(m_config, "KDE");
167
KDEgroup.writeEntry("contrast", contrastSlider->value());
169
KConfigGroup generalGroup(m_config, "General");
170
generalGroup.writeEntry("shadeSortColumn", (bool)shadeSortedColumn->checkState());
173
void KColorCm::setupColorTable()
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);
184
for (int i = 0; i < 22; ++i)
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;
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()));
199
QStackedWidget * widget = new QStackedWidget(this);
200
widget->addWidget(button);
201
widget->addWidget(variesButton);
202
m_stackedWidgets.append(widget);
204
commonColorTable->setCellWidget(i, 1, widget);
208
commonColorTable->setCellWidget(i, 1, button);
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);
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);
233
colorTable->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch);
234
colorTable->horizontalHeader()->setResizeMode(1, QHeaderView::ResizeToContents);
236
updateColorSchemes();
240
QColor KColorCm::commonForeground(KColorScheme::ForegroundRole index)
242
QColor temp = m_colorSchemes[KColorScheme::View].foreground(index).color();
243
for (int i = KColorScheme::Window; i < KColorScheme::Tooltip; ++i)
245
if (m_colorSchemes[i].foreground(index).color() != temp)
247
temp = QColor(); // make it an invalid color
255
void KColorCm::updateColorTable()
257
// subtract one here since the 0 item is "Common Colors"
258
int currentSet = colorSet->currentIndex() - 1;
260
if (currentSet == -1)
262
// common colors is selected
263
stackedWidget->setCurrentIndex(0);
265
KColorButton * button;
266
foreach (button, m_commonColorButtons)
268
button->blockSignals(true);
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());
281
QColor color = commonForeground(KColorScheme::InactiveText);
282
m_stackedWidgets[0]->setCurrentIndex(color.isValid() ? 0 : 1);
285
m_commonColorButtons[9]->setColor(color);
287
color = commonForeground(KColorScheme::ActiveText);
288
m_stackedWidgets[1]->setCurrentIndex(color.isValid() ? 0 : 1);
291
m_commonColorButtons[10]->setColor(color);
293
color = commonForeground(KColorScheme::LinkText);
294
m_stackedWidgets[2]->setCurrentIndex(color.isValid() ? 0 : 1);
297
m_commonColorButtons[11]->setColor(color);
299
color = commonForeground(KColorScheme::VisitedText);
300
m_stackedWidgets[3]->setCurrentIndex(color.isValid() ? 0 : 1);
303
m_commonColorButtons[12]->setColor(color);
305
color = commonForeground(KColorScheme::NegativeText);
306
m_stackedWidgets[4]->setCurrentIndex(color.isValid() ? 0 : 1);
309
m_commonColorButtons[13]->setColor(color);
311
color = commonForeground(KColorScheme::NeutralText);
312
m_stackedWidgets[5]->setCurrentIndex(color.isValid() ? 0 : 1);
315
m_commonColorButtons[14]->setColor(color);
317
color = commonForeground(KColorScheme::PositiveText);
318
m_stackedWidgets[6]->setCurrentIndex(color.isValid() ? 0 : 1);
321
m_commonColorButtons[15]->setColor(color);
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());
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())
331
color = KGlobalSettings::activeTitleColor();
333
m_commonColorButtons[18]->setColor(color);
334
color = KConfigGroup(m_config, "WM").readEntry("activeForeground");
335
if (!color.isValid())
337
color = KGlobalSettings::activeTextColor();
339
m_commonColorButtons[19]->setColor(color);
340
color = KConfigGroup(m_config, "WM").readEntry("inactiveBackground");
341
if (!color.isValid())
343
color = KGlobalSettings::inactiveTitleColor();
345
m_commonColorButtons[20]->setColor(color);
346
color = KConfigGroup(m_config, "WM").readEntry("inactiveForeground");
347
if (!color.isValid())
349
color = KGlobalSettings::activeTitleColor();
351
m_commonColorButtons[21]->setColor(color);
353
foreach (button, m_commonColorButtons)
355
button->blockSignals(false);
360
// a real color set is selected
361
stackedWidget->setCurrentIndex(1);
363
for (int i = KColorScheme::NormalBackground; i <= KColorScheme::AlternateBackground; ++i)
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);
370
for (int i = KColorScheme::NormalText; i <= KColorScheme::PositiveText; ++i)
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);
377
for (int i = KColorScheme::FocusColor; i <= KColorScheme::HoverColor; ++i)
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);
386
void KColorCm::colorChanged( const QColor &newColor )
388
// find which button was changed
389
int row = sender()->objectName().toInt();
390
changeColor(row, newColor);
393
void KColorCm::changeColor(int row, const QColor &newColor)
395
// update the m_colorSchemes for the selected colorSet
396
int currentSet = colorSet->currentIndex() - 1;
398
if (currentSet == -1)
400
// common colors is selected
404
// View Background button
405
KConfigGroup(m_config, "Colors:View").writeEntry("BackgroundNormal", newColor);
409
KConfigGroup(m_config, "Colors:View").writeEntry("ForegroundNormal", newColor);
412
// Window Background Button
413
KConfigGroup(m_config, "Colors:Window").writeEntry("BackgroundNormal", newColor);
416
// Window Text Button
417
KConfigGroup(m_config, "Colors:Window").writeEntry("ForegroundNormal", newColor);
420
// Button Background button
421
KConfigGroup(m_config, "Colors:Button").writeEntry("BackgroundNormal", newColor);
424
// Button Text button
425
KConfigGroup(m_config, "Colors:Button").writeEntry("ForegroundNormal", newColor);
428
// Selection Background Button
429
KConfigGroup(m_config, "Colors:Selection").writeEntry("BackgroundNormal", newColor);
432
// Selection Text Button
433
KConfigGroup(m_config, "Colors:Selection").writeEntry("ForegroundNormal", newColor);
436
// Window Text Button
437
KConfigGroup(m_config, "Colors:Selection").writeEntry("ForegroundInactive", newColor);
440
// buttons that could have varies in their place
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);
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);
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);
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);
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);
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);
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);
498
// Tooltip Background button
499
KConfigGroup(m_config, "Colors:Tooltip").writeEntry("BackgroundNormal", newColor);
502
// Tooltip Text button
503
KConfigGroup(m_config, "Colors:Tooltip").writeEntry("ForegroundNormal", newColor);
507
KConfigGroup(m_config, "WM").writeEntry("activeBackground", newColor);
510
// Active Window Text
511
KConfigGroup(m_config, "WM").writeEntry("activeForeground", newColor);
515
KConfigGroup(m_config, "WM").writeEntry("inactiveBackground", newColor);
518
// Inactive Window Text
519
KConfigGroup(m_config, "WM").writeEntry("inactiveForeground", newColor);
522
m_commonColorButtons[row]->blockSignals(true);
523
m_commonColorButtons[row]->setColor(newColor);
524
m_commonColorButtons[row]->blockSignals(false);
528
QString group = colorSetGroupKey(currentSet);
529
KConfigGroup(m_config, group).writeEntry(m_colorKeys[row], newColor);
532
updateColorSchemes();
534
schemePreview->setPalette(m_config);
535
inactivePreview->setPalette(m_config, QPalette::Inactive);
536
disabledPreview->setPalette(m_config, QPalette::Disabled);
541
QString KColorCm::colorSetGroupKey(int colorSet)
545
case KColorScheme::Window:
546
group = "Colors:Window";
548
case KColorScheme::Button:
549
group = "Colors:Button";
551
case KColorScheme::Selection:
552
group = "Colors:Selection";
554
case KColorScheme::Tooltip:
555
group = "Colors:Tooltip";
558
group = "Colors:View";
563
void KColorCm::on_contrastSlider_valueChanged(int value)
565
KConfigGroup group(m_config, "KDE");
566
group.writeEntry("contrast", value);
568
schemePreview->setPalette(m_config);
569
inactivePreview->setPalette(m_config, QPalette::Inactive);
570
disabledPreview->setPalette(m_config, QPalette::Disabled);
575
void KColorCm::on_shadeSortedColumn_stateChanged(int state)
577
KConfigGroup group(m_config, "General");
578
group.writeEntry("shadeSortColumn", (bool)state);
583
void KColorCm::load()
585
// clean the config, in case we have changed the in-memory kconfig
588
// update the color table
591
// fill in the color scheme list
592
populateSchemeList();
594
contrastSlider->setValue(KGlobalSettings::contrast());
595
shadeSortedColumn->setCheckState(KGlobalSettings::shadeSortColumn() ?
596
Qt::Checked : Qt::Unchecked);
598
schemePreview->setPalette(m_config);
599
inactivePreview->setPalette(m_config, QPalette::Inactive);
600
disabledPreview->setPalette(m_config, QPalette::Disabled);
291
602
emit changed(false);
295
void KColorScheme::save()
605
void KColorCm::save()
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);
310
cfg.writeEntry("shadeSortColumn", cs->shadeSortColumn, KConfigBase::Normal|KConfigBase::Global);
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);
326
cfg.changeGroup( "KDE" );
327
cfg.writeEntry("contrast", cs->contrast, KConfigBase::Normal|KConfigBase::Global);
328
cfg.writeEntry("colorScheme", sCurrentScheme, KConfigBase::Normal|KConfigBase::Global);
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 );
341
KConfig _cfg2("kcmdisplayrc", KConfig::NoGlobals);
342
KConfigGroup cfg2(&_cfg2, "X11");
343
bool exportColors = cbExportColors->isChecked();
344
cfg2.writeEntry("exportKDEColors", exportColors);
346
QApplication::syncX();
348
// Notify all qt-only apps of the KDE palette changes
349
uint flags = KRdbExportQtColors;
351
flags |= KRdbExportColors;
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 );
360
runRdb( flags ); // Save the palette to qtrc for KStyles
362
// Notify all KDE applications
363
608
KGlobalSettings::self()->emitChange(KGlobalSettings::PaletteChanged);
365
// Update the "Current Scheme"
366
int current = findSchemeByName(sCurrentScheme);
367
sList->setCurrentItem(0);
369
QPixmap preview = mkColorPreview(cs);
370
sList->item(0)->setIcon(preview);
371
sList->setCurrentRow(current);
373
preview = mkColorPreview(cs);
374
sList->item(current)->setIcon(preview);
610
// Send signal to all kwin instances
611
QDBusMessage message =
612
QDBusMessage::createSignal("/KWin", "org.kde.KWin", "reloadConfig");
613
QDBusConnection::sessionBus().send(message);
376
616
emit changed(false);
380
void KColorScheme::defaults()
383
sList->setCurrentRow(1);
385
cbShadeList->setChecked(cs->shadeSortColumn);
387
cs->drawSampleWidgets();
388
sb->blockSignals(true);
389
sb->setValue(cs->contrast);
390
sb->blockSignals(false);
392
cbExportColors->setChecked(true);
397
void KColorScheme::sliderValueChanged( int val )
400
cs->drawSampleWidgets();
402
sCurrentScheme.clear();
408
void KColorScheme::slotSave( )
410
KColorSchemeEntry *entry = mSchemeList->at(sList->currentRow()-nSysSchemes);
412
sCurrentScheme = entry->path;
413
KConfig *config = new KConfig(sCurrentScheme, KConfig::OnlyLocal);
414
int i = sCurrentScheme.lastIndexOf('/');
416
sCurrentScheme = sCurrentScheme.mid(i+1);
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);
449
void KColorScheme::slotRemove()
451
int ind = sList->currentRow();
452
KColorSchemeEntry *entry = mSchemeList->at(ind-nSysSchemes);
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." ));
463
delete sList->takeItem(ind);
464
mSchemeList->remove(entry);
466
ind = sList->currentRow();
467
entry = mSchemeList->at(ind-nSysSchemes);
469
removeBt->setEnabled(entry ? entry->local : false);
474
* Add a local color scheme.
476
void KColorScheme::slotAdd()
479
if (sList->currentRow() >= nSysSchemes)
480
sName = sList->currentItem()->text();
490
sName = KInputDialog::getText( i18n( "Save Color Scheme" ),
491
i18n( "Enter a name for the color scheme:" ), sName, &ok, this );
495
sName = sName.simplified();
501
// Check if it's already there
502
for (i=0; i < (int) sList->count(); i++)
504
if (sName == sList->item(i)->text())
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)
516
if (i == (int) sList->count())
520
disconnect(sList, SIGNAL(currentRowChanged(int)), this,
521
SLOT(slotPreviewScheme(int)));
526
sList->setCurrentRow(exists);
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);
534
insertEntry(sFile, sName);
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);
546
void KColorScheme::slotImport()
548
QString location = KStandardDirs::locateLocal( "data", "kdisplay/color-schemes/" );
550
KUrl file ( KFileDialog::getOpenFileName(QString(), "*.kcsrc", this) );
551
if ( file.isEmpty() )
554
//kDebug() << "Location: " << location;
555
if (!KIO::NetAccess::file_copy(file, KUrl( location+file.fileName( KUrl::ObeyTrailingSlash ) ) ) )
557
KMessageBox::error(this, KIO::NetAccess::lastErrorString(),i18n("Import failed."));
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"));
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);
575
QColor &KColorScheme::color(int index)
578
case CSM_Inactive_title_bar:
580
case CSM_Inactive_title_text:
582
case CSM_Inactive_title_blend:
584
case CSM_Active_title_bar:
586
case CSM_Active_title_text:
588
case CSM_Active_title_blend:
594
case CSM_Select_background:
596
case CSM_Select_text:
597
return cs->selectTxt;
598
case CSM_Standard_background:
600
case CSM_Standard_text:
601
return cs->windowTxt;
602
case CSM_Button_background:
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:
612
case CSM_Active_handle:
614
case CSM_Inactive_frame:
616
case CSM_Inactive_handle:
620
case CSM_Followed_Link:
621
return cs->visitedLink;
622
case CSM_Alternate_background:
623
return cs->alternateBackground;
626
assert(0); // Should never be here!
627
return cs->iaTxt; // Silence compiler
630
void KColorScheme::slotColorForWidget(int indx, const QColor& col)
632
mColorTreeWidget->setColor( indx , col );
635
void KColorScheme::slotShadeSortColumnChanged(bool b)
637
cs->shadeSortColumn = b;
638
sCurrentScheme.clear();
644
* Read a color scheme into "cs".
646
* KEEP IN SYNC with thememgr!
648
void KColorScheme::readScheme( int index )
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);
662
if (QPixmap::defaultDepth() > 8)
663
button.setRgb(221, 223, 228 );
665
button.setRgb(220, 220, 220);
667
QColor link(0, 0, 238);
668
QColor visitedLink(82, 24,139);
670
// note: keep default color scheme in sync with default Current Scheme
672
sCurrentScheme = "<default>";
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;
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;
694
cs->visitedLink = visitedLink;
695
cs->alternateBackground = alternateBackground;
698
cs->shadeSortColumn = KDE_DEFAULT_SHADE_SORT_COLUMN;
707
config = KGlobal::config().data();
708
group = config->group("General");
711
KColorSchemeEntry *entry = mSchemeList->at(sList->currentRow()-nSysSchemes);
713
sCurrentScheme = entry->path;
714
config = new KConfig(sCurrentScheme, KConfig::OnlyLocal);
715
group = config->group("Color Scheme");
716
int i = sCurrentScheme.lastIndexOf('/');
718
sCurrentScheme = sCurrentScheme.mid(i+1);
721
cs->shadeSortColumn = group.readEntry( "shadeSortColumn", KDE_DEFAULT_SHADE_SORT_COLUMN );
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 );
741
group = config->group( "WM" );
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);
758
group = config->group( "KDE" );
760
cs->contrast = group.readEntry( "contrast", 7 );
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);
773
* Get all installed color schemes.
775
void KColorScheme::readSchemeNames()
777
mSchemeList->clear();
779
// Always a current and a default scheme
780
sList->insertItem( 0 , i18n("Current Scheme") );
781
sList->insertItem( 1 , i18n("KDE Default") );
784
// Global + local schemes
785
QStringList list = KGlobal::dirs()->findAllResources("data",
786
"kdisplay/color-schemes/*.kcsrc", KStandardDirs::NoDuplicates);
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");
793
str = config.readEntry("name");
797
mSchemeList->append(new KColorSchemeEntry(*it, str, !config.isImmutable()));
802
for(KColorSchemeEntry *entry = mSchemeList->first(); entry; entry = mSchemeList->next())
804
sList->addItem(entry->name);
807
for (int i = 0; i < (nSysSchemes + mSchemeList->count()); i++)
809
sList->setCurrentRow(i);
811
QPixmap preview = mkColorPreview(cs);
812
sList->item(i)->setIcon(preview);
818
* Find scheme based on filename
820
int KColorScheme::findSchemeByName(const QString &scheme)
822
if (scheme.isEmpty())
824
if (scheme == "<default>")
827
QString search = scheme;
828
int i = search.lastIndexOf('/');
830
search = search.mid(i+1);
834
for(KColorSchemeEntry *entry = mSchemeList->first(); entry; entry = mSchemeList->next())
837
url.setPath(entry->path);
838
if (url.fileName() == search)
839
return i+nSysSchemes;
847
void KColorScheme::slotPreviewScheme(int indx)
851
// Set various appropriate for the scheme
853
cbShadeList->setChecked(cs->shadeSortColumn);
855
cs->drawSampleWidgets();
856
sb->blockSignals(true);
857
sb->setValue(cs->contrast);
858
sb->blockSignals(false);
859
if (indx < nSysSchemes)
860
removeBt->setEnabled(false);
863
KColorSchemeEntry *entry = mSchemeList->at(indx-nSysSchemes);
864
removeBt->setEnabled(entry ? entry->local : false);
867
emit changed((indx != 0));
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.
874
QPalette KColorScheme::createPalette()
876
QColorGroup disabledgrp(cs->windowTxt, cs->back, cs->back.light(150),
877
cs->back.dark(), cs->back.dark(120), cs->back.dark(120),
880
QColorGroup colgrp(cs->windowTxt, cs->back, cs->back.light(150),
881
cs->back.dark(), cs->back.dark(120), cs->txt, cs->window);
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);
890
void KColorScheme::insertEntry(const QString &sFile, const QString &sName)
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);
899
void KColorScheme::setColorName( const QString & name, int id , int id2 )
901
mColorTreeWidget->addRole( id , id2, name );
904
void KColorScheme::slotColorChanged( int selection , const QColor & col)
906
// Adjust the alternate background color if the standard color changes
907
// Only if the previous alternate color was not a user-configured one
909
if ( selection == CSM_Standard_background &&
910
color(CSM_Alternate_background) ==
911
KGlobalSettings::calculateAlternateBackgroundColor(
912
color(CSM_Standard_background) ) )
914
color(CSM_Alternate_background) =
915
KGlobalSettings::calculateAlternateBackgroundColor( col );
918
color(selection) = col;
920
cs->drawSampleWidgets();
922
sCurrentScheme.clear();
929
619
#include "colorscm.moc"