1
/********************************************************************
2
KWin - the KDE window manager
3
This file is part of the KDE project.
5
Copyright (C) 2008 Martin Gräßlin <ubuntu@martin-graesslin.com>
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, see <http://www.gnu.org/licenses/>.
19
*********************************************************************/
20
#include "cube_config.h"
21
#include <kwineffects.h>
23
#include <kconfiggroup.h>
24
#include <kcolorscheme.h>
25
#include <KActionCollection>
28
#include <QVBoxLayout>
34
KWIN_EFFECT_CONFIG_FACTORY
36
CubeEffectConfigForm::CubeEffectConfigForm(QWidget* parent) : QWidget(parent)
41
CubeEffectConfig::CubeEffectConfig(QWidget* parent, const QVariantList& args) :
42
KCModule(EffectFactory::componentData(), parent, args)
44
m_ui = new CubeEffectConfigForm(this);
46
QVBoxLayout* layout = new QVBoxLayout(this);
48
layout->addWidget(m_ui);
50
m_ui->tabWidget->setTabText(0, i18nc("@title:tab Basic Settings", "Basic"));
51
m_ui->tabWidget->setTabText(1, i18nc("@title:tab Advanced Settings", "Advanced"));
53
// Shortcut config. The shortcut belongs to the component "kwin"!
54
m_actionCollection = new KActionCollection(this, KComponentData("kwin"));
56
m_actionCollection->setConfigGroup("Cube");
57
m_actionCollection->setConfigGlobal(true);
59
KAction* cubeAction = (KAction*) m_actionCollection->addAction("Cube");
60
cubeAction->setText(i18n("Desktop Cube"));
61
cubeAction->setProperty("isConfigurationAction", true);
62
cubeAction->setGlobalShortcut(KShortcut(Qt::CTRL + Qt::Key_F11));
63
KAction* cylinderAction = (KAction*) m_actionCollection->addAction("Cylinder");
64
cylinderAction->setText(i18n("Desktop Cylinder"));
65
cylinderAction->setProperty("isConfigurationAction", true);
66
cylinderAction->setGlobalShortcut(KShortcut(), KAction::ActiveShortcut);
67
KAction* sphereAction = (KAction*) m_actionCollection->addAction("Sphere");
68
sphereAction->setText(i18n("Desktop Sphere"));
69
sphereAction->setProperty("isConfigurationAction", true);
70
sphereAction->setGlobalShortcut(KShortcut(), KAction::ActiveShortcut);
72
m_ui->editor->addCollection(m_actionCollection);
74
m_ui->wallpaperRequester->setFilter("*.png *.jpeg *.jpg ");
76
connect(m_ui->rotationDurationSpin, SIGNAL(valueChanged(int)), this, SLOT(changed()));
77
connect(m_ui->cubeOpacitySlider, SIGNAL(valueChanged(int)), this, SLOT(changed()));
78
connect(m_ui->cubeOpacitySpin, SIGNAL(valueChanged(int)), this, SLOT(changed()));
79
connect(m_ui->desktopOpacityOnlyBox, SIGNAL(stateChanged(int)), this, SLOT(changed()));
80
connect(m_ui->displayDesktopNameBox, SIGNAL(stateChanged(int)), this, SLOT(changed()));
81
connect(m_ui->reflectionBox, SIGNAL(stateChanged(int)), this, SLOT(changed()));
82
connect(m_ui->backgroundColorButton, SIGNAL(changed(QColor)), this, SLOT(changed()));
83
connect(m_ui->cubeCapsBox, SIGNAL(stateChanged(int)), this, SLOT(changed()));
84
connect(m_ui->cubeCapsBox, SIGNAL(stateChanged(int)), this, SLOT(capsSelectionChanged()));
85
connect(m_ui->capsImageBox, SIGNAL(stateChanged(int)), this, SLOT(changed()));
86
connect(m_ui->capColorButton, SIGNAL(changed(QColor)), this, SLOT(changed()));
87
connect(m_ui->wallpaperRequester, SIGNAL(textChanged(QString)), this, SLOT(changed()));
88
connect(m_ui->closeOnMouseReleaseBox, SIGNAL(stateChanged(int)), this, SLOT(changed()));
89
connect(m_ui->zPositionSlider, SIGNAL(valueChanged(int)), this, SLOT(changed()));
90
connect(m_ui->walkThroughDesktopBox, SIGNAL(stateChanged(int)), this, SLOT(changed()));
91
connect(m_ui->invertKeysBox, SIGNAL(stateChanged(int)), this, SLOT(changed()));
92
connect(m_ui->invertMouseBox, SIGNAL(stateChanged(int)), this, SLOT(changed()));
93
connect(m_ui->capDeformationSlider, SIGNAL(valueChanged(int)), this, SLOT(changed()));
94
connect(m_ui->zOrderingBox, SIGNAL(stateChanged(int)), this, SLOT(changed()));
99
void CubeEffectConfig::load()
103
KConfigGroup conf = EffectsHandler::effectConfig("Cube");
105
int duration = conf.readEntry("RotationDuration", 0);
106
float opacity = conf.readEntry("Opacity", 80);
107
bool desktopOpacityOnly = conf.readEntry("OpacityDesktopOnly", false);
108
bool desktopName = conf.readEntry("DisplayDesktopName", true);
109
bool reflection = conf.readEntry("Reflection", true);
110
QColor background = conf.readEntry("BackgroundColor", QColor(Qt::black));
111
QColor capColor = conf.readEntry("CapColor", KColorScheme(QPalette::Active, KColorScheme::Window).background().color());
112
bool texturedCaps = conf.readEntry("TexturedCaps", true);
113
bool caps = conf.readEntry("Caps", true);
114
bool closeOnMouseRelease = conf.readEntry("CloseOnMouseRelease", false);
115
bool walkThroughDesktop = conf.readEntry("TabBox", false);
116
m_ui->zPositionSlider->setValue(conf.readEntry("ZPosition", 100));
117
m_ui->wallpaperRequester->setUrl(KUrl(conf.readEntry("Wallpaper", "")));
118
bool invertKeys = conf.readEntry("InvertKeys", false);
119
bool invertMouse = conf.readEntry("InvertMouse", false);
120
m_ui->capDeformationSlider->setValue(conf.readEntry("CapDeformation", 0));
121
bool zOrdering = conf.readEntry("ZOrdering", false);
123
m_ui->rotationDurationSpin->setValue(duration);
124
m_ui->rotationDurationSpin->setSuffix(ki18np(" millisecond", " milliseconds"));
125
m_ui->cubeOpacitySlider->setValue(opacity);
126
m_ui->cubeOpacitySpin->setValue(opacity);
127
m_ui->desktopOpacityOnlyBox->setChecked(desktopOpacityOnly);
129
m_ui->displayDesktopNameBox->setCheckState(Qt::Checked);
131
m_ui->displayDesktopNameBox->setCheckState(Qt::Unchecked);
134
m_ui->reflectionBox->setCheckState(Qt::Checked);
136
m_ui->reflectionBox->setCheckState(Qt::Unchecked);
139
m_ui->cubeCapsBox->setCheckState(Qt::Checked);
141
m_ui->cubeCapsBox->setCheckState(Qt::Unchecked);
144
m_ui->capsImageBox->setCheckState(Qt::Checked);
146
m_ui->capsImageBox->setCheckState(Qt::Unchecked);
148
if (closeOnMouseRelease) {
149
m_ui->closeOnMouseReleaseBox->setCheckState(Qt::Checked);
151
m_ui->closeOnMouseReleaseBox->setCheckState(Qt::Unchecked);
153
if (walkThroughDesktop) {
154
m_ui->walkThroughDesktopBox->setCheckState(Qt::Checked);
156
m_ui->walkThroughDesktopBox->setCheckState(Qt::Unchecked);
158
m_ui->backgroundColorButton->setColor(background);
159
m_ui->capColorButton->setColor(capColor);
160
m_ui->invertKeysBox->setChecked(invertKeys);
161
m_ui->invertMouseBox->setChecked(invertMouse);
162
m_ui->zOrderingBox->setChecked(zOrdering);
163
capsSelectionChanged();
168
void CubeEffectConfig::save()
170
KConfigGroup conf = EffectsHandler::effectConfig("Cube");
172
conf.writeEntry("RotationDuration", m_ui->rotationDurationSpin->value());
173
conf.writeEntry("DisplayDesktopName", m_ui->displayDesktopNameBox->checkState() == Qt::Checked ? true : false);
174
conf.writeEntry("Reflection", m_ui->reflectionBox->checkState() == Qt::Checked ? true : false);
175
conf.writeEntry("Opacity", m_ui->cubeOpacitySpin->value());
176
conf.writeEntry("OpacityDesktopOnly", m_ui->desktopOpacityOnlyBox->isChecked());
177
conf.writeEntry("BackgroundColor", m_ui->backgroundColorButton->color());
178
conf.writeEntry("Caps", m_ui->cubeCapsBox->checkState() == Qt::Checked ? true : false);
179
conf.writeEntry("CapColor", m_ui->capColorButton->color());
180
conf.writeEntry("TexturedCaps", m_ui->capsImageBox->checkState() == Qt::Checked ? true : false);
181
conf.writeEntry("CloseOnMouseRelease", m_ui->closeOnMouseReleaseBox->checkState() == Qt::Checked ? true : false);
182
conf.writeEntry("Wallpaper", m_ui->wallpaperRequester->url().path());
183
conf.writeEntry("ZPosition", m_ui->zPositionSlider->value());
184
conf.writeEntry("TabBox", m_ui->walkThroughDesktopBox->checkState() == Qt::Checked ? true : false);
185
conf.writeEntry("InvertKeys", m_ui->invertKeysBox->isChecked());
186
conf.writeEntry("InvertMouse", m_ui->invertMouseBox->isChecked());
187
conf.writeEntry("CapDeformation", m_ui->capDeformationSlider->value());
188
conf.writeEntry("ZOrdering", m_ui->zOrderingBox->isChecked());
190
m_ui->editor->save();
195
EffectsHandler::sendReloadMessage("cube");
198
void CubeEffectConfig::defaults()
200
m_ui->rotationDurationSpin->setValue(0);
201
m_ui->displayDesktopNameBox->setCheckState(Qt::Checked);
202
m_ui->reflectionBox->setCheckState(Qt::Checked);
203
m_ui->cubeOpacitySpin->setValue(80);
204
m_ui->cubeOpacitySlider->setValue(80);
205
m_ui->desktopOpacityOnlyBox->setChecked(false);
206
m_ui->backgroundColorButton->setColor(QColor(Qt::black));
207
m_ui->cubeCapsBox->setCheckState(Qt::Checked);
208
m_ui->capColorButton->setColor(KColorScheme(QPalette::Active, KColorScheme::Window).background().color());
209
m_ui->capsImageBox->setCheckState(Qt::Checked);
210
m_ui->closeOnMouseReleaseBox->setCheckState(Qt::Unchecked);
211
m_ui->wallpaperRequester->setUrl(KUrl(""));
212
m_ui->zPositionSlider->setValue(100);
213
m_ui->walkThroughDesktopBox->setCheckState(Qt::Unchecked);
214
m_ui->invertKeysBox->setChecked(false);
215
m_ui->invertMouseBox->setChecked(false);
216
m_ui->capDeformationSlider->setValue(0);
217
m_ui->zOrderingBox->setChecked(false);
218
m_ui->editor->allDefault();
222
void CubeEffectConfig::capsSelectionChanged()
224
if (m_ui->cubeCapsBox->checkState() == Qt::Checked) {
225
// activate cap color
226
m_ui->capColorButton->setEnabled(true);
227
m_ui->capColorLabel->setEnabled(true);
228
m_ui->capsImageBox->setEnabled(true);
230
// deactivate cap color
231
m_ui->capColorButton->setEnabled(false);
232
m_ui->capColorLabel->setEnabled(false);
233
m_ui->capsImageBox->setEnabled(false);
239
#include "cube_config.moc"