1 /***************************************************************************
2 glowconfigdialog.cpp - description
4 begin : Thu Sep 12 2001
5 copyright : (C) 2001 by Henning Burchardt
6 email : h_burchardt@gmx.net
7 ***************************************************************************/
9 /***************************************************************************
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. *
16 ***************************************************************************/
19 #include <q3buttongroup.h>
20 #include <qcheckbox.h>
21 #include <qcombobox.h>
23 #include <qfileinfo.h>
24 #include <q3groupbox.h>
27 #include <q3listview.h>
28 #include <qpushbutton.h>
29 #include <qsignalmapper.h>
30 #include <qstringlist.h>
33 #include <QHBoxLayout>
34 #include <QVBoxLayout>
36 #include <kcolorbutton.h>
39 #include <kglobalsettings.h>
42 #include <kpixmapeffect.h>
43 #include <kstandarddirs.h>
45 #include "glowconfigdialog.h"
46 #include "../resources.h"
48 #define NUMBER_OF_BUTTONS 5
52 KDE_EXPORT QObject
* allocate_config( KConfig
* conf
, QWidget
* parent
)
54 return(new GlowConfigDialog(conf
, parent
));
58 GlowConfigDialog::GlowConfigDialog( KConfig
* conf
, QWidget
* 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 //-------------------------------------------------------------------------
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()));
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());
89 QSize
buttonSize(BITMAP_SIZE
, BITMAP_SIZE
);
90 QPixmap
pm(buttonSize
);
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
180 _main_group_box
->show();
183 GlowConfigDialog::~GlowConfigDialog()
185 delete _main_group_box
;
187 delete[] _buttonConfigMap
;
190 void GlowConfigDialog::load( KConfig
* /* conf */ )
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
);
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
);
293 QFileInfoListIterator
it2(*dir
.entryInfoList());
296 while ((finfo
=it2
.current()))
298 if (finfo
->fileName() == "." || finfo
->fileName() == "..") {
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)
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
);
327 void GlowConfigDialog::slotTitlebarGradientTypeChanged(int index
)
329 _titlebarGradientType
= static_cast<KPixmapEffect::GradientType
>(index
);
333 void GlowConfigDialog::slotResizeHandleCheckBoxChanged()
335 _showResizeHandle
= _showResizeHandleCheckBox
->isChecked();
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
;
359 _buttonConfigMap
[closeButton
] = glowColor
;
364 void GlowConfigDialog::slotThemeListViewSelectionChanged ()
366 if( _theme_list_view
->selectedItem() != 0 ) {
367 _theme_name
= _theme_list_view
->selectedItem()->text (0);
373 #include "glowconfigdialog.moc"