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

« back to all changes in this revision

Viewing changes to kwin/effects/wobblywindows/wobblywindows_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 Cédric Borgese <cedric.borgese@gmail.com>
 
6
 Copyright (C) 2008 Lucas Murray <lmurray@undefinedfire.com>
 
7
 
 
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.
 
12
 
 
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.
 
17
 
 
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
*********************************************************************/
 
21
 
 
22
#include "wobblywindows_config.h"
 
23
 
 
24
#include <kwineffects.h>
 
25
 
 
26
#include <klocale.h>
 
27
#include <kdebug.h>
 
28
#include <kaction.h>
 
29
#include <kconfiggroup.h>
 
30
 
 
31
namespace KWin
 
32
{
 
33
 
 
34
KWIN_EFFECT_CONFIG_FACTORY
 
35
 
 
36
//-----------------------------------------------------------------------------
 
37
// WARNING: This is (kinda) copied from wobblywindows.cpp
 
38
 
 
39
struct ParameterSet {
 
40
    int stiffness;
 
41
    int drag;
 
42
    int move_factor;
 
43
};
 
44
 
 
45
ParameterSet set_0 = {
 
46
    15,
 
47
    80,
 
48
    10
 
49
};
 
50
 
 
51
ParameterSet set_1 = {
 
52
    10,
 
53
    85,
 
54
    10
 
55
};
 
56
 
 
57
ParameterSet set_2 = {
 
58
    6,
 
59
    90,
 
60
    10
 
61
};
 
62
 
 
63
ParameterSet set_3 = {
 
64
    3,
 
65
    92,
 
66
    20
 
67
};
 
68
 
 
69
ParameterSet set_4 = {
 
70
    1,
 
71
    97,
 
72
    25
 
73
};
 
74
 
 
75
ParameterSet pset[5] = { set_0, set_1, set_2, set_3, set_4 };
 
76
 
 
77
//-----------------------------------------------------------------------------
 
78
 
 
79
WobblyWindowsEffectConfig::WobblyWindowsEffectConfig(QWidget* parent, const QVariantList& args) :
 
80
    KCModule(EffectFactory::componentData(), parent, args)
 
81
{
 
82
    m_ui.setupUi(this);
 
83
 
 
84
    connect(m_ui.wobblinessSlider, SIGNAL(valueChanged(int)), this, SLOT(changed()));
 
85
    connect(m_ui.wobblinessSlider, SIGNAL(valueChanged(int)), this, SLOT(wobblinessChanged()));
 
86
    connect(m_ui.moveBox, SIGNAL(stateChanged(int)), this, SLOT(changed()));
 
87
    connect(m_ui.resizeBox, SIGNAL(stateChanged(int)), this, SLOT(changed()));
 
88
    connect(m_ui.advancedBox, SIGNAL(stateChanged(int)), this, SLOT(changed()));
 
89
    connect(m_ui.advancedBox, SIGNAL(stateChanged(int)), this, SLOT(advancedChanged()));
 
90
    connect(m_ui.stiffnessSpin, SIGNAL(valueChanged(int)), this, SLOT(changed()));
 
91
    connect(m_ui.dragSpin, SIGNAL(valueChanged(int)), this, SLOT(changed()));
 
92
    connect(m_ui.moveFactorSpin, SIGNAL(valueChanged(int)), this, SLOT(changed()));
 
93
 
 
94
    load();
 
95
}
 
96
 
 
97
WobblyWindowsEffectConfig::~WobblyWindowsEffectConfig()
 
98
{
 
99
}
 
100
 
 
101
void WobblyWindowsEffectConfig::load()
 
102
{
 
103
    KCModule::load();
 
104
 
 
105
    KConfigGroup conf = EffectsHandler::effectConfig("Wobbly");
 
106
    bool change = true;
 
107
 
 
108
    unsigned int wobblynessLevel = 0;
 
109
    QString settingsMode = conf.readEntry("Settings", "Auto");
 
110
    if (settingsMode != "Custom") {
 
111
        wobblynessLevel = conf.readEntry("WobblynessLevel", 0);
 
112
        change = false;
 
113
    }
 
114
    if (wobblynessLevel > 4) {
 
115
        wobblynessLevel = 4;
 
116
        change = true;
 
117
    }
 
118
    m_ui.wobblinessSlider->setSliderPosition(wobblynessLevel);
 
119
 
 
120
    m_ui.moveBox->setChecked(conf.readEntry("MoveWobble", true));
 
121
    m_ui.resizeBox->setChecked(conf.readEntry("ResizeWobble", true));
 
122
    m_ui.advancedBox->setChecked(conf.readEntry("AdvancedMode", false));
 
123
 
 
124
    m_ui.stiffnessSlider->setValue(conf.readEntry("Stiffness", pset[0].stiffness));
 
125
    m_ui.dragSlider->setValue(conf.readEntry("Drag", pset[0].drag));
 
126
    m_ui.moveFactorSlider->setValue(conf.readEntry("MoveFactor", pset[0].move_factor));
 
127
 
 
128
    advancedChanged();
 
129
 
 
130
    emit changed(change);
 
131
}
 
132
 
 
133
void WobblyWindowsEffectConfig::save()
 
134
{
 
135
    KConfigGroup conf = EffectsHandler::effectConfig("Wobbly");
 
136
    conf.writeEntry("Settings", "Auto");
 
137
 
 
138
    conf.writeEntry("WobblynessLevel", m_ui.wobblinessSlider->value());
 
139
 
 
140
    conf.writeEntry("MoveWobble", m_ui.moveBox->isChecked());
 
141
    conf.writeEntry("ResizeWobble", m_ui.resizeBox->isChecked());
 
142
    conf.writeEntry("AdvancedMode", m_ui.advancedBox->isChecked());
 
143
 
 
144
    conf.writeEntry("Stiffness", m_ui.stiffnessSpin->value());
 
145
    conf.writeEntry("Drag", m_ui.dragSpin->value());
 
146
    conf.writeEntry("MoveFactor", m_ui.moveFactorSpin->value());
 
147
 
 
148
    emit changed(false);
 
149
    EffectsHandler::sendReloadMessage("wobblywindows");
 
150
}
 
151
 
 
152
void WobblyWindowsEffectConfig::defaults()
 
153
{
 
154
    m_ui.wobblinessSlider->setSliderPosition(0);
 
155
 
 
156
    m_ui.moveBox->setChecked(true);
 
157
    m_ui.resizeBox->setChecked(true);
 
158
    m_ui.advancedBox->setChecked(false);
 
159
 
 
160
    m_ui.stiffnessSlider->setValue(pset[0].stiffness);
 
161
    m_ui.dragSlider->setValue(pset[0].drag);
 
162
    m_ui.moveFactorSlider->setValue(pset[0].move_factor);
 
163
 
 
164
    emit changed(true);
 
165
}
 
166
 
 
167
void WobblyWindowsEffectConfig::advancedChanged()
 
168
{
 
169
    if (m_ui.advancedBox->isChecked())
 
170
        m_ui.advancedGroup->setEnabled(true);
 
171
    else
 
172
        m_ui.advancedGroup->setEnabled(false);
 
173
}
 
174
 
 
175
void WobblyWindowsEffectConfig::wobblinessChanged()
 
176
{
 
177
    ParameterSet preset = pset[m_ui.wobblinessSlider->value()];
 
178
 
 
179
    m_ui.stiffnessSlider->setValue(preset.stiffness);
 
180
    m_ui.dragSlider->setValue(preset.drag);
 
181
    m_ui.moveFactorSlider->setValue(preset.move_factor);
 
182
}
 
183
 
 
184
} // namespace
 
185
 
 
186
#include "wobblywindows_config.moc"