add more spacing
[personal-kdebase.git] / workspace / kwin / effects / wobblywindows_config.cpp
blobc1341c1df4e1dba54bc1a3fc63cd5806aecb5282
1 /********************************************************************
2 KWin - the KDE window manager
3 This file is part of the KDE project.
5 Copyright (C) 2008 Cédric Borgese <cedric.borgese@gmail.com>
6 Copyright (C) 2008 Lucas Murray <lmurray@undefinedfire.com>
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 *********************************************************************/
22 #include "wobblywindows_config.h"
24 #include <kwineffects.h>
26 #include <klocale.h>
27 #include <kdebug.h>
28 #include <kaction.h>
29 #include <kconfiggroup.h>
31 #ifndef KDE_USE_FINAL
32 KWIN_EFFECT_CONFIG_FACTORY
33 #endif
35 namespace KWin
38 //-----------------------------------------------------------------------------
39 // WARNING: This is (kinda) copied from wobblywindows.cpp
41 struct ParameterSet
43 int stiffness;
44 int drag;
45 int move_factor;
48 ParameterSet set_0 =
50 15,
51 80,
55 ParameterSet set_1 =
57 10,
58 85,
62 ParameterSet set_2 =
65 90,
69 ParameterSet set_3 =
72 92,
76 ParameterSet set_4 =
79 97,
83 ParameterSet pset[5] = { set_0, set_1, set_2, set_3, set_4 };
85 //-----------------------------------------------------------------------------
87 WobblyWindowsEffectConfig::WobblyWindowsEffectConfig(QWidget* parent, const QVariantList& args) :
88 KCModule(EffectFactory::componentData(), parent, args)
90 m_ui.setupUi(this);
92 connect(m_ui.wobblinessSlider, SIGNAL(valueChanged(int)), this, SLOT(changed()));
93 connect(m_ui.wobblinessSlider, SIGNAL(valueChanged(int)), this, SLOT(wobblinessChanged()));
94 connect(m_ui.moveBox, SIGNAL(stateChanged(int)), this, SLOT(changed()));
95 connect(m_ui.resizeBox, SIGNAL(stateChanged(int)), this, SLOT(changed()));
96 connect(m_ui.advancedBox, SIGNAL(stateChanged(int)), this, SLOT(changed()));
97 connect(m_ui.advancedBox, SIGNAL(stateChanged(int)), this, SLOT(advancedChanged()));
98 connect(m_ui.stiffnessSpin, SIGNAL(valueChanged(int)), this, SLOT(changed()));
99 connect(m_ui.dragSpin, SIGNAL(valueChanged(int)), this, SLOT(changed()));
100 connect(m_ui.moveFactorSpin, SIGNAL(valueChanged(int)), this, SLOT(changed()));
102 load();
105 WobblyWindowsEffectConfig::~WobblyWindowsEffectConfig()
109 void WobblyWindowsEffectConfig::load()
111 KCModule::load();
113 KConfigGroup conf = EffectsHandler::effectConfig("Wobbly");
114 bool change = true;
116 unsigned int wobblynessLevel = 0;
117 QString settingsMode = conf.readEntry("Settings", "Auto");
118 if (settingsMode != "Custom")
120 wobblynessLevel = conf.readEntry("WobblynessLevel", 0);
121 change = false;
123 if (wobblynessLevel > 4)
125 wobblynessLevel = 4;
126 change = true;
128 m_ui.wobblinessSlider->setSliderPosition(wobblynessLevel);
130 m_ui.moveBox->setChecked(conf.readEntry("MoveWobble", true));
131 m_ui.resizeBox->setChecked(conf.readEntry("ResizeWobble", true));
132 m_ui.advancedBox->setChecked(conf.readEntry("AdvancedMode", false));
134 m_ui.stiffnessSlider->setValue(conf.readEntry("Stiffness", pset[0].stiffness));
135 m_ui.dragSlider->setValue(conf.readEntry("Drag", pset[0].drag));
136 m_ui.moveFactorSlider->setValue(conf.readEntry("MoveFactor", pset[0].move_factor));
138 advancedChanged();
140 emit changed(change);
143 void WobblyWindowsEffectConfig::save()
145 KConfigGroup conf = EffectsHandler::effectConfig("Wobbly");
146 conf.writeEntry("Settings", "Auto");
148 conf.writeEntry("WobblynessLevel", m_ui.wobblinessSlider->value());
150 conf.writeEntry("MoveWobble", m_ui.moveBox->isChecked());
151 conf.writeEntry("ResizeWobble", m_ui.resizeBox->isChecked());
152 conf.writeEntry("AdvancedMode", m_ui.advancedBox->isChecked());
154 conf.writeEntry("Stiffness", m_ui.stiffnessSpin->value());
155 conf.writeEntry("Drag", m_ui.dragSpin->value());
156 conf.writeEntry("MoveFactor", m_ui.moveFactorSpin->value());
158 emit changed(false);
159 EffectsHandler::sendReloadMessage("wobblywindows");
162 void WobblyWindowsEffectConfig::defaults()
164 m_ui.wobblinessSlider->setSliderPosition(0);
166 m_ui.moveBox->setChecked(true);
167 m_ui.resizeBox->setChecked(true);
168 m_ui.advancedBox->setChecked(false);
170 m_ui.stiffnessSlider->setValue(pset[0].stiffness);
171 m_ui.dragSlider->setValue(pset[0].drag);
172 m_ui.moveFactorSlider->setValue(pset[0].move_factor);
174 emit changed(true);
177 void WobblyWindowsEffectConfig::advancedChanged()
179 if(m_ui.advancedBox->isChecked())
180 m_ui.advancedGroup->setEnabled(true);
181 else
182 m_ui.advancedGroup->setEnabled(false);
185 void WobblyWindowsEffectConfig::wobblinessChanged()
187 ParameterSet preset = pset[m_ui.wobblinessSlider->value()];
189 m_ui.stiffnessSlider->setValue(preset.stiffness);
190 m_ui.dragSlider->setValue(preset.drag);
191 m_ui.moveFactorSlider->setValue(preset.move_factor);
194 } // namespace
196 #include "wobblywindows_config.moc"