~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to kwin/effects/cube/cube_config.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/********************************************************************
 
2
 KWin - the KDE window manager
 
3
 This file is part of the KDE project.
 
4
 
 
5
 Copyright (C) 2008 Martin Gräßlin <ubuntu@martin-graesslin.com>
 
6
 
 
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.
 
11
 
 
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.
 
16
 
 
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>
 
22
 
 
23
#include <kconfiggroup.h>
 
24
#include <kcolorscheme.h>
 
25
#include <KActionCollection>
 
26
#include <kaction.h>
 
27
 
 
28
#include <QVBoxLayout>
 
29
#include <QColor>
 
30
 
 
31
namespace KWin
 
32
{
 
33
 
 
34
KWIN_EFFECT_CONFIG_FACTORY
 
35
 
 
36
CubeEffectConfigForm::CubeEffectConfigForm(QWidget* parent) : QWidget(parent)
 
37
{
 
38
    setupUi(this);
 
39
}
 
40
 
 
41
CubeEffectConfig::CubeEffectConfig(QWidget* parent, const QVariantList& args) :
 
42
    KCModule(EffectFactory::componentData(), parent, args)
 
43
{
 
44
    m_ui = new CubeEffectConfigForm(this);
 
45
 
 
46
    QVBoxLayout* layout = new QVBoxLayout(this);
 
47
 
 
48
    layout->addWidget(m_ui);
 
49
 
 
50
    m_ui->tabWidget->setTabText(0, i18nc("@title:tab Basic Settings", "Basic"));
 
51
    m_ui->tabWidget->setTabText(1, i18nc("@title:tab Advanced Settings", "Advanced"));
 
52
 
 
53
    // Shortcut config. The shortcut belongs to the component "kwin"!
 
54
    m_actionCollection = new KActionCollection(this, KComponentData("kwin"));
 
55
 
 
56
    m_actionCollection->setConfigGroup("Cube");
 
57
    m_actionCollection->setConfigGlobal(true);
 
58
 
 
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);
 
71
 
 
72
    m_ui->editor->addCollection(m_actionCollection);
 
73
 
 
74
    m_ui->wallpaperRequester->setFilter("*.png *.jpeg *.jpg ");
 
75
 
 
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()));
 
95
 
 
96
    load();
 
97
}
 
98
 
 
99
void CubeEffectConfig::load()
 
100
{
 
101
    KCModule::load();
 
102
 
 
103
    KConfigGroup conf = EffectsHandler::effectConfig("Cube");
 
104
 
 
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);
 
122
 
 
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);
 
128
    if (desktopName) {
 
129
        m_ui->displayDesktopNameBox->setCheckState(Qt::Checked);
 
130
    } else {
 
131
        m_ui->displayDesktopNameBox->setCheckState(Qt::Unchecked);
 
132
    }
 
133
    if (reflection) {
 
134
        m_ui->reflectionBox->setCheckState(Qt::Checked);
 
135
    } else {
 
136
        m_ui->reflectionBox->setCheckState(Qt::Unchecked);
 
137
    }
 
138
    if (caps) {
 
139
        m_ui->cubeCapsBox->setCheckState(Qt::Checked);
 
140
    } else {
 
141
        m_ui->cubeCapsBox->setCheckState(Qt::Unchecked);
 
142
    }
 
143
    if (texturedCaps) {
 
144
        m_ui->capsImageBox->setCheckState(Qt::Checked);
 
145
    } else {
 
146
        m_ui->capsImageBox->setCheckState(Qt::Unchecked);
 
147
    }
 
148
    if (closeOnMouseRelease) {
 
149
        m_ui->closeOnMouseReleaseBox->setCheckState(Qt::Checked);
 
150
    } else {
 
151
        m_ui->closeOnMouseReleaseBox->setCheckState(Qt::Unchecked);
 
152
    }
 
153
    if (walkThroughDesktop) {
 
154
        m_ui->walkThroughDesktopBox->setCheckState(Qt::Checked);
 
155
    } else {
 
156
        m_ui->walkThroughDesktopBox->setCheckState(Qt::Unchecked);
 
157
    }
 
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();
 
164
 
 
165
    emit changed(false);
 
166
}
 
167
 
 
168
void CubeEffectConfig::save()
 
169
{
 
170
    KConfigGroup conf = EffectsHandler::effectConfig("Cube");
 
171
 
 
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());
 
189
 
 
190
    m_ui->editor->save();
 
191
 
 
192
    conf.sync();
 
193
 
 
194
    emit changed(false);
 
195
    EffectsHandler::sendReloadMessage("cube");
 
196
}
 
197
 
 
198
void CubeEffectConfig::defaults()
 
199
{
 
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();
 
219
    emit changed(true);
 
220
}
 
221
 
 
222
void CubeEffectConfig::capsSelectionChanged()
 
223
{
 
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);
 
229
    } else {
 
230
        // deactivate cap color
 
231
        m_ui->capColorButton->setEnabled(false);
 
232
        m_ui->capColorLabel->setEnabled(false);
 
233
        m_ui->capsImageBox->setEnabled(false);
 
234
    }
 
235
}
 
236
 
 
237
} // namespace
 
238
 
 
239
#include "cube_config.moc"