4
* Copyright (c) 2000 Matthias Elter <elter@kde.org>
5
* Copyright (c) 2000 Aaron J. Seigo <aseigo@olympusproject.org>
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2 of the License, or
10
* (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
21
#include <qcheckbox.h>
23
#include <qradiobutton.h>
26
#include <kcolorbutton.h>
28
#include <kfiledialog.h>
29
#include <kiconeffect.h>
31
#include <klineedit.h>
33
#include <kmessagebox.h>
34
#include <kstandarddirs.h>
36
#include <kickerSettings.h>
37
#include "advancedDialog.h"
41
#include "lookandfeeltab_impl.h"
42
#include "lookandfeeltab_impl.moc"
47
LookAndFeelTab::LookAndFeelTab( QWidget *parent, const char* name )
48
: LookAndFeelTabBase(parent, name),
51
connect(m_kmenuTile, SIGNAL(activated(int)), SIGNAL(changed()));
52
connect(m_desktopTile, SIGNAL(activated(int)), SIGNAL(changed()));
53
connect(m_browserTile, SIGNAL(activated(int)), SIGNAL(changed()));
54
connect(m_urlTile, SIGNAL(activated(int)), SIGNAL(changed()));
55
connect(m_windowListTile, SIGNAL(activated(int)), SIGNAL(changed()));
57
connect(m_kmenuTile, SIGNAL(activated(int)), SLOT(kmenuTileChanged(int)));
58
connect(m_desktopTile, SIGNAL(activated(int)), SLOT(desktopTileChanged(int)));
59
connect(m_browserTile, SIGNAL(activated(int)), SLOT(browserTileChanged(int)));
60
connect(m_urlTile, SIGNAL(activated(int)), SLOT(urlTileChanged(int)));
61
connect(m_windowListTile, SIGNAL(activated(int)), SLOT(wlTileChanged(int)));
63
connect(kcfg_ColorizeBackground, SIGNAL(toggled(bool)), SLOT(browseTheme()));
65
connect(kcfg_BackgroundTheme->lineEdit(), SIGNAL(lostFocus()), SLOT(browseTheme()));
66
kcfg_BackgroundTheme->setFilter(KImageIO::pattern(KImageIO::Reading));
67
kcfg_BackgroundTheme->setCaption(i18n("Select Image File"));
72
void LookAndFeelTab::browseTheme()
74
browseTheme(kcfg_BackgroundTheme->url());
77
void LookAndFeelTab::browseTheme(const QString& newtheme)
79
if (newtheme.isEmpty())
81
kcfg_BackgroundTheme->clear();
82
m_backgroundLabel->setPixmap(QPixmap());
87
previewBackground(newtheme, true);
90
void LookAndFeelTab::launchAdvancedDialog()
94
m_advDialog = new advancedDialog(this, "advancedDialog");
95
connect(m_advDialog, SIGNAL(finished()), this, SLOT(finishAdvancedDialog()));
98
m_advDialog->setActiveWindow();
101
void LookAndFeelTab::finishAdvancedDialog()
103
m_advDialog->delayedDestruct();
107
void LookAndFeelTab::enableTransparency(bool useTransparency)
109
bool useBgTheme = kcfg_UseBackgroundTheme->isChecked();
111
kcfg_UseBackgroundTheme->setDisabled(useTransparency);
112
kcfg_BackgroundTheme->setDisabled(useTransparency || !useBgTheme);
113
m_backgroundLabel->setDisabled(useTransparency || !useBgTheme);
114
kcfg_ColorizeBackground->setDisabled(useTransparency || !useBgTheme);
117
void LookAndFeelTab::previewBackground(const QString& themepath, bool isNew)
119
QString theme = themepath;
121
theme = locate("data", "kicker/" + theme);
123
QImage tmpImg(theme);
126
tmpImg = tmpImg.smoothScale(m_backgroundLabel->contentsRect().width(),
127
m_backgroundLabel->contentsRect().height());
128
if (kcfg_ColorizeBackground->isChecked())
129
KickerLib::colorize(tmpImg);
130
theme_preview.convertFromImage(tmpImg);
131
if(!theme_preview.isNull()) {
132
// avoid getting changed(true) from KConfigDialogManager for the default value
133
if( KickerSettings::backgroundTheme() == themepath )
134
KickerSettings::setBackgroundTheme( theme );
135
kcfg_BackgroundTheme->lineEdit()->setText(theme);
136
m_backgroundLabel->setPixmap(theme_preview);
143
KMessageBox::error(this,
144
i18n("Error loading theme image file.\n\n%1\n%2")
145
.arg(theme, themepath));
146
kcfg_BackgroundTheme->clear();
147
m_backgroundLabel->setPixmap(QPixmap());
150
void LookAndFeelTab::load()
155
void LookAndFeelTab::load(bool useDefaults)
157
KConfig config(KickerConfig::the()->configName(), false, false);
159
config.setReadDefaults( useDefaults );
161
config.setGroup("General");
163
bool use_theme = kcfg_UseBackgroundTheme->isChecked();
164
QString theme = kcfg_BackgroundTheme->lineEdit()->text().stripWhiteSpace();
166
bool transparent = kcfg_Transparent->isChecked();
168
kcfg_BackgroundTheme->setEnabled(use_theme);
169
m_backgroundLabel->setEnabled(use_theme);
170
kcfg_ColorizeBackground->setEnabled(use_theme);
171
m_backgroundLabel->clear();
172
if (theme.length() > 0)
174
previewBackground(theme, false);
178
config.setGroup("buttons");
180
kmenuTileChanged(m_kmenuTile->currentItem());
181
desktopTileChanged(m_desktopTile->currentItem());
182
urlTileChanged(m_urlTile->currentItem());
183
browserTileChanged(m_browserTile->currentItem());
184
wlTileChanged(m_windowListTile->currentItem());
186
if (config.readBoolEntry("EnableTileBackground", false))
188
config.setGroup("button_tiles");
190
if (config.readBoolEntry("EnableKMenuTiles", false))
192
tile = config.readEntry("KMenuTile", "solid_blue");
193
m_kmenuTile->setCurrentItem(m_tilename.findIndex(tile));
194
kcfg_KMenuTileColor->setEnabled(tile == "Colorize");
197
if (config.readBoolEntry("EnableDesktopButtonTiles", false))
199
tile = config.readEntry("DesktopButtonTile", "solid_orange");
200
m_desktopTile->setCurrentItem(m_tilename.findIndex(tile));
201
kcfg_DesktopButtonTileColor->setEnabled(tile == "Colorize");
204
if (config.readBoolEntry("EnableURLTiles", false))
206
tile = config.readEntry("URLTile", "solid_gray");
207
m_urlTile->setCurrentItem(m_tilename.findIndex(tile));
208
kcfg_URLTileColor->setEnabled(tile == "Colorize");
211
if (config.readBoolEntry("EnableBrowserTiles", false))
213
tile = config.readEntry("BrowserTile", "solid_green");
214
m_browserTile->setCurrentItem(m_tilename.findIndex(tile));
215
kcfg_BrowserTileColor->setEnabled(tile == "Colorize");
218
if (config.readBoolEntry("EnableWindowListTiles", false))
220
tile = config.readEntry("WindowListTile", "solid_green");
221
m_windowListTile->setCurrentItem(m_tilename.findIndex(tile));
222
kcfg_WindowListTileColor->setEnabled(tile == "Colorize");
225
enableTransparency( transparent );
228
void LookAndFeelTab::save()
230
KConfig config(KickerConfig::the()->configName(), false, false);
232
config.setGroup("General");
234
config.setGroup("button_tiles");
235
bool enableTiles = false;
236
int tile = m_kmenuTile->currentItem();
240
config.writeEntry("EnableKMenuTiles", true);
241
config.writeEntry("KMenuTile", m_tilename[m_kmenuTile->currentItem()]);
245
config.writeEntry("EnableKMenuTiles", false);
248
tile = m_desktopTile->currentItem();
252
config.writeEntry("EnableDesktopButtonTiles", true);
253
config.writeEntry("DesktopButtonTile", m_tilename[m_desktopTile->currentItem()]);
257
config.writeEntry("EnableDesktopButtonTiles", false);
260
tile = m_urlTile->currentItem();
264
config.writeEntry("EnableURLTiles", tile > 0);
265
config.writeEntry("URLTile", m_tilename[m_urlTile->currentItem()]);
269
config.writeEntry("EnableURLTiles", false);
272
tile = m_browserTile->currentItem();
276
config.writeEntry("EnableBrowserTiles", tile > 0);
277
config.writeEntry("BrowserTile", m_tilename[m_browserTile->currentItem()]);
281
config.writeEntry("EnableBrowserTiles", false);
284
tile = m_windowListTile->currentItem();
288
config.writeEntry("EnableWindowListTiles", tile > 0);
289
config.writeEntry("WindowListTile", m_tilename[m_windowListTile->currentItem()]);
293
config.writeEntry("EnableWindowListTiles", false);
296
config.setGroup("buttons");
297
config.writeEntry("EnableTileBackground", enableTiles);
302
void LookAndFeelTab::defaults()
307
void LookAndFeelTab::fillTileCombos()
309
/* m_kmenuTile->clear();
310
m_kmenuTile->insertItem(i18n("Default"));
311
m_desktopTile->clear();
312
m_desktopTile->insertItem(i18n("Default"));
314
m_urlTile->insertItem(i18n("Default"));
315
m_browserTile->clear();
316
m_browserTile->insertItem(i18n("Default"));
317
m_windowListTile->clear();
318
m_windowListTile->insertItem(i18n("Default"));*/
320
m_tilename << "" << "Colorize";
322
QStringList list = KGlobal::dirs()->findAllResources("tiles","*_tiny_up.png");
325
for (QStringList::Iterator it = list.begin(); it != list.end(); ++it)
327
QString tile = (*it);
330
tile = fi.fileName();
331
tile.truncate(tile.find("_tiny_up.png"));
334
// Transform tile to words with title case
335
// The same is done when generating messages for translation
336
QStringList words = QStringList::split(QRegExp("[_ ]"), tile);
337
for (QStringList::iterator w = words.begin(); w != words.end(); ++w)
338
(*w)[0] = (*w)[0].upper();
339
tile = i18n(words.join(" ").utf8());
341
m_kmenuTile->insertItem(pix, tile);
342
m_desktopTile->insertItem(pix, tile);
343
m_urlTile->insertItem(pix, tile);
344
m_browserTile->insertItem(pix, tile);
345
m_windowListTile->insertItem(pix, tile);
347
if (pix.height() > minHeight)
349
minHeight = pix.height();
354
m_kmenuTile->setMinimumHeight(minHeight);
355
m_desktopTile->setMinimumHeight(minHeight);
356
m_urlTile->setMinimumHeight(minHeight);
357
m_browserTile->setMinimumHeight(minHeight);
358
m_windowListTile->setMinimumHeight(minHeight);
361
void LookAndFeelTab::kmenuTileChanged(int i)
363
kcfg_KMenuTileColor->setEnabled(i == 1);
366
void LookAndFeelTab::desktopTileChanged(int i)
368
kcfg_DesktopButtonTileColor->setEnabled(i == 1);
371
void LookAndFeelTab::browserTileChanged(int i)
373
kcfg_BrowserTileColor->setEnabled(i == 1);
376
void LookAndFeelTab::urlTileChanged(int i)
378
kcfg_URLTileColor->setEnabled(i == 1);
381
void LookAndFeelTab::wlTileChanged(int i)
383
kcfg_WindowListTileColor->setEnabled(i == 1);