Start to fix some error
[kdeartwork.git] / kwin-styles / glow / config / glowconfigdialog.cpp
blobb3a233283c65e8d6dbd0f6b44d4d977fdaaed978
1 /***************************************************************************
2 glowconfigdialog.cpp - description
3 -------------------
4 begin : Thu Sep 12 2001
5 copyright : (C) 2001 by Henning Burchardt
6 email : h_burchardt@gmx.net
7 ***************************************************************************/
9 /***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
18 #include <qbitmap.h>
19 #include <q3buttongroup.h>
20 #include <qcheckbox.h>
21 #include <qcombobox.h>
22 #include <qdir.h>
23 #include <qfileinfo.h>
24 #include <q3groupbox.h>
25 #include <qlabel.h>
26 #include <qlayout.h>
27 #include <q3listview.h>
28 #include <qpushbutton.h>
29 #include <qsignalmapper.h>
30 #include <qstringlist.h>
31 //Added by qt3to4:
32 #include <QPixmap>
33 #include <QHBoxLayout>
34 #include <QVBoxLayout>
35 #include <kconfig.h>
36 #include <kcolorbutton.h>
37 #include <kdebug.h>
38 #include <kglobal.h>
39 #include <kglobalsettings.h>
40 #include <klocale.h>
41 #include <kpixmap.h>
42 #include <kpixmapeffect.h>
43 #include <kstandarddirs.h>
44 #include "bitmaps.h"
45 #include "glowconfigdialog.h"
46 #include "../resources.h"
48 #define NUMBER_OF_BUTTONS 5
50 extern "C"
52 KDE_EXPORT QObject* allocate_config( KConfig* conf, QWidget* parent )
54 return(new GlowConfigDialog(conf, parent));
58 GlowConfigDialog::GlowConfigDialog( KConfig * conf, QWidget * parent )
59 : QObject(parent)
61 _glowConfig = new KConfig("kwinglowrc");
62 KGlobal::locale()->insertCatalog("kwin_glow_config");
64 _main_group_box = new QWidget(parent);
65 QVBoxLayout *main_group_boxLayout = new QVBoxLayout(_main_group_box);
66 main_group_boxLayout->setAlignment(Qt::AlignTop | Qt::AlignLeft);
67 main_group_boxLayout->setSpacing(6);
69 //-------------------------------------------------------------------------
70 // themes
72 _theme_list_view = new Q3ListView (_main_group_box, "theme_list_view");
73 _theme_list_view->addColumn (i18n("Theme"));
74 _theme_list_view->addColumn (i18n("Button Size"));
75 _theme_list_view->setAllColumnsShowFocus(true);
76 _theme_list_view->setResizeMode(Q3ListView::AllColumns);
78 main_group_boxLayout->addWidget (_theme_list_view);
79 QObject::connect (_theme_list_view, SIGNAL(selectionChanged()),
80 this, SLOT(slotThemeListViewSelectionChanged()));
81 slotLoadThemeList();
83 _button_glow_color_group_box = new Q3GroupBox(
84 0, Qt::Horizontal, i18n("Button Glow Colors"), _main_group_box);
85 QHBoxLayout *colorHBoxLayout =
86 new QHBoxLayout(_button_glow_color_group_box->layout());
88 // create buttons
89 QSize buttonSize(BITMAP_SIZE, BITMAP_SIZE);
90 QPixmap pm(buttonSize);
91 pm.fill(Qt::black);
93 _stickyButton = new QPushButton(_button_glow_color_group_box);
94 pm.setMask(QBitmap(buttonSize, stickyoff_bits, true));
95 _stickyButton->setPixmap(pm);
96 colorHBoxLayout->addWidget(_stickyButton);
97 _titleButtonList.push_back(_stickyButton);
99 _helpButton = new QPushButton(_button_glow_color_group_box);
100 pm.setMask(QBitmap(buttonSize, help_bits, true));
101 _helpButton->setPixmap(pm);
102 colorHBoxLayout->addWidget(_helpButton);
103 _titleButtonList.push_back(_helpButton);
105 _iconifyButton = new QPushButton(_button_glow_color_group_box);
106 pm.setMask(QBitmap(buttonSize, minimize_bits, true));
107 _iconifyButton->setPixmap(pm);
108 colorHBoxLayout->addWidget(_iconifyButton);
109 _titleButtonList.push_back(_iconifyButton);
111 _maximizeButton = new QPushButton(_button_glow_color_group_box);
112 pm.setMask(QBitmap(buttonSize, maximizeoff_bits, true));
113 _maximizeButton->setPixmap(pm);
114 colorHBoxLayout->addWidget(_maximizeButton);
115 _titleButtonList.push_back(_maximizeButton);
117 _closeButton = new QPushButton(_button_glow_color_group_box);
118 pm.setMask(QBitmap(buttonSize, close_bits, true));
119 _closeButton->setPixmap(pm);
120 colorHBoxLayout->addWidget(_closeButton);
121 _titleButtonList.push_back(_closeButton);
123 // create signal mapper
124 _titleButtonMapper = new QSignalMapper(this);
125 for( uint i=0; i<_titleButtonList.size(); i++ ) {
126 _titleButtonMapper->setMapping(_titleButtonList[i], i);
127 connect(_titleButtonList[i], SIGNAL(clicked()),_titleButtonMapper, SLOT(map()));
129 connect(_titleButtonMapper, SIGNAL(mapped(int)),this, SLOT(slotTitleButtonClicked(int)));
131 _colorButton = new KColorButton(_button_glow_color_group_box);
132 _colorButton->setEnabled(false);
133 connect(_colorButton, SIGNAL(changed(const QColor&)),
134 this, SLOT(slotColorButtonChanged(const QColor&)));
136 colorHBoxLayout->addItem(new QSpacerItem(
137 200, 20, QSizePolicy::Expanding, QSizePolicy::Minimum));
138 colorHBoxLayout->addWidget(_colorButton);
140 main_group_boxLayout->addWidget(_button_glow_color_group_box);
142 QHBoxLayout *titlebarGradientTypeLayout = new QHBoxLayout();
143 _titlebarGradientTypeComboBox = new QComboBox(_main_group_box);
145 KConfig *c = KGlobal::config();
146 KConfigGroupSaver cgs( c, QString::fromLatin1("WM") );
147 QColor activeBackground = c->readColorEntry("activeBackground");
148 QColor activeBlend = c->readColorEntry("activeBlend");
150 // If the colors are equal, change one to get a gradient effect
151 if (activeBackground==activeBlend) {
152 activeBackground = activeBackground.dark();
154 for (int i=0; i< KPixmapEffect::EllipticGradient; i++ ) {
155 KPixmap gradPixmap(QSize(196,20));
156 KPixmapEffect::gradient(gradPixmap, activeBackground,
157 activeBlend, (KPixmapEffect::GradientType) i);
159 _titlebarGradientTypeComboBox->insertItem(gradPixmap, i);
162 connect(_titlebarGradientTypeComboBox, SIGNAL(activated(int)),
163 this, SLOT(slotTitlebarGradientTypeChanged(int)));
164 titlebarGradientTypeLayout->addWidget(
165 new QLabel(i18n("Titlebar gradient:"), _main_group_box));
166 titlebarGradientTypeLayout->addWidget(_titlebarGradientTypeComboBox, 0, Qt::AlignLeft);
167 titlebarGradientTypeLayout->addStretch(10);
168 main_group_boxLayout->addLayout(titlebarGradientTypeLayout);
171 _showResizeHandleCheckBox = new QCheckBox(
172 i18n("Show resize handle"), _main_group_box);
173 connect(_showResizeHandleCheckBox, SIGNAL(clicked()),
174 this, SLOT(slotResizeHandleCheckBoxChanged()));
175 main_group_boxLayout->addWidget(_showResizeHandleCheckBox);
177 // load config and update user interface
178 load(conf);
180 _main_group_box->show();
183 GlowConfigDialog::~GlowConfigDialog()
185 delete _main_group_box;
186 delete _glowConfig;
187 delete[] _buttonConfigMap;
190 void GlowConfigDialog::load( KConfig* /* conf */ )
192 QColor color;
193 const QColor defaultCloseButtonColor(DEFAULT_CLOSE_BUTTON_COLOR);
194 const QColor defaultMaximizeButtonColor(DEFAULT_MAXIMIZE_BUTTON_COLOR);
195 const QColor defaultIconifyButtonColor(DEFAULT_ICONIFY_BUTTON_COLOR);
196 const QColor defaultHelpButtonColor(DEFAULT_HELP_BUTTON_COLOR);
197 const QColor defaultStickyButtonColor(DEFAULT_STICKY_BUTTON_COLOR);
199 _glowConfig->setGroup("General");
201 _buttonConfigMap = new QColor[NUMBER_OF_BUTTONS];
202 color = _glowConfig->readColorEntry("stickyButtonGlowColor",
203 &defaultStickyButtonColor);
204 _buttonConfigMap[stickyButton] = color;
206 color = _glowConfig->readColorEntry("helpButtonGlowColor",
207 &defaultHelpButtonColor);
208 _buttonConfigMap[helpButton] = color;
210 color = _glowConfig->readColorEntry("iconifyButtonGlowColor",
211 &defaultIconifyButtonColor);
212 _buttonConfigMap[iconifyButton] = color;
214 color = _glowConfig->readColorEntry("maximizeButtonGlowColor",
215 &defaultMaximizeButtonColor);
216 _buttonConfigMap[maximizeButton] = color;
218 color = _glowConfig->readColorEntry("closeButtonGlowColor",
219 &defaultCloseButtonColor);
220 _buttonConfigMap[closeButton] = color;
222 _showResizeHandle = _glowConfig->readBoolEntry("showResizeHandle", true);
223 _titlebarGradientType = static_cast<KPixmapEffect::GradientType>
224 (_glowConfig->readNumEntry("titlebarGradientType",
225 KPixmapEffect::DiagonalGradient));
227 _showResizeHandleCheckBox->setChecked(_showResizeHandle);
228 _titlebarGradientTypeComboBox->setCurrentItem(_titlebarGradientType);
230 _theme_name = _glowConfig->readEntry ("themeName", "default");
231 _theme_list_view->setSelected (
232 _theme_list_view->findItem (_theme_name, 0), true);
233 slotTitleButtonClicked(0);
236 void GlowConfigDialog::save( KConfig* /* conf */ )
238 _glowConfig->setGroup("General");
240 _glowConfig->writeEntry("stickyButtonGlowColor", _buttonConfigMap[stickyButton]);
241 _glowConfig->writeEntry("helpButtonGlowColor", _buttonConfigMap[helpButton]);
242 _glowConfig->writeEntry("iconifyButtonGlowColor", _buttonConfigMap[iconifyButton]);
243 _glowConfig->writeEntry("maximizeButtonGlowColor", _buttonConfigMap[maximizeButton]);
244 _glowConfig->writeEntry("closeButtonGlowColor", _buttonConfigMap[closeButton]);
246 _glowConfig->writeEntry("showResizeHandle", _showResizeHandle);
247 _glowConfig->writeEntry("titlebarGradientType", _titlebarGradientType);
249 _glowConfig->writeEntry ("themeName", _theme_name);
251 _glowConfig->sync();
254 void GlowConfigDialog::defaults()
256 const QColor defaultCloseButtonColor = DEFAULT_CLOSE_BUTTON_COLOR;
257 const QColor defaultMaximizeButtonColor(DEFAULT_MAXIMIZE_BUTTON_COLOR);
258 const QColor defaultIconifyButtonColor(DEFAULT_ICONIFY_BUTTON_COLOR);
259 const QColor defaultHelpButtonColor(DEFAULT_HELP_BUTTON_COLOR);
260 const QColor defaultStickyButtonColor(DEFAULT_STICKY_BUTTON_COLOR);
262 _buttonConfigMap[stickyButton] = defaultStickyButtonColor;
263 _buttonConfigMap[helpButton] = defaultHelpButtonColor;
264 _buttonConfigMap[iconifyButton] = defaultIconifyButtonColor;
265 _buttonConfigMap[maximizeButton] = defaultMaximizeButtonColor;
266 _buttonConfigMap[closeButton] = defaultCloseButtonColor;
268 _showResizeHandle = true;
269 _titlebarGradientType = KPixmapEffect::DiagonalGradient;
271 _showResizeHandleCheckBox->setChecked(_showResizeHandle);
272 _titlebarGradientTypeComboBox->setCurrentItem(_titlebarGradientType);
274 _theme_list_view->setSelected (
275 _theme_list_view->findItem("default", 0), true);
278 void GlowConfigDialog::slotLoadThemeList ()
280 QStringList dir_list=KGlobal::dirs()->findDirs("data", "kwin/glow-themes");
282 QStringList::ConstIterator it;
284 _theme_list_view->clear();
285 new Q3ListViewItem (_theme_list_view, "default", "17x17");
287 for (it=dir_list.begin(); it!=dir_list.end(); ++it)
289 QDir dir (*it, QString("*"), QDir::Unsorted,
290 QDir::Dirs | QDir::Readable);
291 if (dir.exists())
293 QFileInfoListIterator it2(*dir.entryInfoList());
294 QFileInfo * finfo;
296 while ((finfo=it2.current()))
298 if (finfo->fileName() == "." || finfo->fileName() == "..") {
299 ++it2;
300 continue;
303 if (! _theme_list_view->findItem (finfo->fileName(), 0))
305 KConfig conf (dir.path() + "/" + finfo->fileName() + "/" +
306 finfo->fileName() + ".theme");
307 QSize button_size = conf.readSizeEntry (
308 "buttonSize", new QSize (-1, -1));
309 if (button_size.width() == -1)
311 ++it2;
312 continue;
314 QString size_string = QString("") +
315 QString::number(button_size.width()) +
316 "x" + QString::number(button_size.height());
317 new Q3ListViewItem (_theme_list_view,
318 finfo->fileName(), size_string);
321 ++it2;
327 void GlowConfigDialog::slotTitlebarGradientTypeChanged(int index)
329 _titlebarGradientType = static_cast<KPixmapEffect::GradientType>(index);
330 emit changed();
333 void GlowConfigDialog::slotResizeHandleCheckBoxChanged()
335 _showResizeHandle = _showResizeHandleCheckBox->isChecked();
336 emit changed();
339 void GlowConfigDialog::slotTitleButtonClicked(int index)
341 for( int i=0; i< ((int) _titleButtonList.size()); i++ ) {
342 _titleButtonList[i]->setDown(i==index);
344 _colorButton->setEnabled(true);
345 _colorButton->setColor(_buttonConfigMap[index]);
348 void GlowConfigDialog::slotColorButtonChanged(const QColor& glowColor)
350 if( _stickyButton->isDown() ) {
351 _buttonConfigMap[stickyButton] = glowColor;
352 } else if( _helpButton->isDown() ) {
353 _buttonConfigMap[helpButton] = glowColor;
354 } else if( _iconifyButton->isDown() ) {
355 _buttonConfigMap[iconifyButton] = glowColor;
356 } else if( _maximizeButton->isDown() ) {
357 _buttonConfigMap[maximizeButton] = glowColor;
358 } else {
359 _buttonConfigMap[closeButton] = glowColor;
361 emit changed();
364 void GlowConfigDialog::slotThemeListViewSelectionChanged ()
366 if( _theme_list_view->selectedItem() != 0 ) {
367 _theme_name = _theme_list_view->selectedItem()->text (0);
369 emit changed();
373 #include "glowconfigdialog.moc"