1 /********************************************************************
2 KWin - the KDE window manager
3 This file is part of the KDE project.
5 Copyright (C) 2007 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 *********************************************************************/
21 #include "snow_config.h"
22 #include <kwineffects.h>
26 #include <KActionCollection>
28 #include <kconfiggroup.h>
30 #include <QVBoxLayout>
32 KWIN_EFFECT_CONFIG_FACTORY
37 SnowEffectConfigForm::SnowEffectConfigForm(QWidget
* parent
) : QWidget(parent
)
42 SnowEffectConfig::SnowEffectConfig(QWidget
* parent
, const QVariantList
& args
) :
43 KCModule(EffectFactory::componentData(), parent
, args
)
45 m_ui
= new SnowEffectConfigForm(this);
47 QVBoxLayout
* layout
= new QVBoxLayout(this);
49 layout
->addWidget(m_ui
);
51 connect(m_ui
->editor
, SIGNAL(keyChange()), this, SLOT(changed()));
52 connect(m_ui
->numberFlakes
, SIGNAL(valueChanged(int)), this, SLOT(changed()));
53 connect(m_ui
->minSizeFlake
, SIGNAL(valueChanged(int)), this, SLOT(changed()));
54 connect(m_ui
->maxSizeFlake
, SIGNAL(valueChanged(int)), this, SLOT(changed()));
55 connect(m_ui
->maxVSpeed
, SIGNAL(valueChanged(int)), this, SLOT(changed()));
56 connect(m_ui
->maxHSpeed
, SIGNAL(valueChanged(int)), this, SLOT(changed()));
57 connect(m_ui
->snowBehindWindows
, SIGNAL(stateChanged(int)), this, SLOT(changed()));
59 m_actionCollection
= new KActionCollection( this, componentData() );
60 m_actionCollection
->setConfigGroup("Snow");
61 m_actionCollection
->setConfigGlobal(true);
63 KAction
* a
= (KAction
*)m_actionCollection
->addAction( "Snow" );
64 a
->setText( i18n("Toggle Snow on Desktop" ));
65 a
->setProperty("isConfigurationAction", true);
66 a
->setGlobalShortcut( KShortcut( Qt::CTRL
+ Qt::META
+ Qt::Key_F12
));
68 m_ui
->editor
->addCollection(m_actionCollection
);
71 SnowEffectConfig::~SnowEffectConfig()
73 // Undo (only) unsaved changes to global key shortcuts
74 m_ui
->editor
->undoChanges();
77 void SnowEffectConfig::load()
81 KConfigGroup conf
= EffectsHandler::effectConfig("Snow");
83 int number
= conf
.readEntry("Number", 200);
84 int minFlake
= conf
.readEntry("MinFlakes", 10);
85 int maxFlake
= conf
.readEntry("MaxFlakes", 50);
86 int maxVSpeed
= conf
.readEntry("MaxVSpeed", 2);
87 int maxHSpeed
= conf
.readEntry("MaxHSpeed", 1);
88 m_ui
->snowBehindWindows
->setChecked( conf
.readEntry("BehindWindows", true));
89 m_ui
->numberFlakes
->setValue( number
);
90 m_ui
->minSizeFlake
->setValue( minFlake
);
91 m_ui
->maxSizeFlake
->setValue( maxFlake
);
92 m_ui
->maxVSpeed
->setValue( maxVSpeed
);
93 m_ui
->maxHSpeed
->setValue( maxHSpeed
);
99 void SnowEffectConfig::save()
101 KConfigGroup conf
= EffectsHandler::effectConfig("Snow");
102 conf
.writeEntry("Number", m_ui
->numberFlakes
->value());
103 conf
.writeEntry("MinFlakes", m_ui
->minSizeFlake
->value());
104 conf
.writeEntry("MaxFlakes", m_ui
->maxSizeFlake
->value());
105 conf
.writeEntry("MaxVSpeed", m_ui
->maxVSpeed
->value());
106 conf
.writeEntry("MaxHSpeed", m_ui
->maxHSpeed
->value());
107 conf
.writeEntry("BehindWindows", m_ui
->snowBehindWindows
->isChecked());
109 m_ui
->editor
->save(); // undo() will restore to this state from now on
114 EffectsHandler::sendReloadMessage( "snow" );
117 void SnowEffectConfig::defaults()
119 m_ui
->numberFlakes
->setValue( 200 );
120 m_ui
->minSizeFlake
->setValue( 10 );
121 m_ui
->maxSizeFlake
->setValue( 50 );
122 m_ui
->maxVSpeed
->setValue( 2 );
123 m_ui
->maxHSpeed
->setValue( 1 );
124 m_ui
->snowBehindWindows
->setChecked( true );
125 m_ui
->editor
->allDefault();
132 #include "snow_config.moc"