Use KConfigXT in FlipSwitch effect

REVIEW: 106401
This commit is contained in:
Lilian A. Moraru 2012-09-14 15:35:18 +03:00 committed by Martin Gräßlin
parent 500310b0e8
commit 607817eeef
7 changed files with 68 additions and 76 deletions

View file

@ -6,6 +6,8 @@ set( kwin4_effect_builtins_sources ${kwin4_effect_builtins_sources}
flipswitch/flipswitch.cpp flipswitch/flipswitch.cpp
) )
kde4_add_kcfg_files(kwin4_effect_builtins_sources flipswitch/flipswitchconfig.kcfgc)
# .desktop files # .desktop files
install( FILES install( FILES
flipswitch/flipswitch.desktop flipswitch/flipswitch.desktop
@ -20,6 +22,8 @@ set( kwin4_effect_builtins_config_sources ${kwin4_effect_builtins_config_sources
flipswitch/flipswitch_config.ui flipswitch/flipswitch_config.ui
) )
kde4_add_kcfg_files(kwin4_effect_builtins_config_sources flipswitch/flipswitchconfig.kcfgc)
# .desktop files # .desktop files
install( FILES install( FILES
flipswitch/flipswitch_config.desktop flipswitch/flipswitch_config.desktop

View file

@ -18,12 +18,13 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/ *********************************************************************/
#include "flipswitch.h" #include "flipswitch.h"
// KConfigSkeleton
#include "flipswitchconfig.h"
#include <kwinconfig.h> #include <kwinconfig.h>
#include <QFont> #include <QFont>
#include <QKeyEvent> #include <QKeyEvent>
#include <QMatrix4x4> #include <QMatrix4x4>
#include <kconfiggroup.h>
#include <kdebug.h> #include <kdebug.h>
#include <KAction> #include <KAction>
@ -94,7 +95,7 @@ bool FlipSwitchEffect::supported()
void FlipSwitchEffect::reconfigure(ReconfigureFlags) void FlipSwitchEffect::reconfigure(ReconfigureFlags)
{ {
KConfigGroup conf = effects->effectConfig("FlipSwitch"); FlipSwitchConfig::self()->readConfig();
foreach (ElectricBorder border, m_borderActivate) { foreach (ElectricBorder border, m_borderActivate) {
effects->unreserveElectricBorder(border); effects->unreserveElectricBorder(border);
} }
@ -103,30 +104,24 @@ void FlipSwitchEffect::reconfigure(ReconfigureFlags)
} }
m_borderActivate.clear(); m_borderActivate.clear();
m_borderActivateAll.clear(); m_borderActivateAll.clear();
QList<int> borderList = QList<int>(); foreach (int i, FlipSwitchConfig::borderActivate()) {
borderList.append(int(ElectricNone));
borderList = conf.readEntry("BorderActivate", borderList);
foreach (int i, borderList) {
m_borderActivate.append(ElectricBorder(i)); m_borderActivate.append(ElectricBorder(i));
effects->reserveElectricBorder(ElectricBorder(i)); effects->reserveElectricBorder(ElectricBorder(i));
} }
borderList.clear(); foreach (int i, FlipSwitchConfig::borderActivateAll()) {
borderList.append(int(ElectricNone));
borderList = conf.readEntry("BorderActivateAll", borderList);
foreach (int i, borderList) {
m_borderActivateAll.append(ElectricBorder(i)); m_borderActivateAll.append(ElectricBorder(i));
effects->reserveElectricBorder(ElectricBorder(i)); effects->reserveElectricBorder(ElectricBorder(i));
} }
m_tabbox = conf.readEntry("TabBox", false); m_tabbox = FlipSwitchConfig::tabBox();
m_tabboxAlternative = conf.readEntry("TabBoxAlternative", false); m_tabboxAlternative = FlipSwitchConfig::tabBoxAlternative();
float duration = animationTime(conf, "Duration", 200); const int duration = animationTime(FlipSwitchConfig::duration() != 0 ? FlipSwitchConfig::duration() : 200);
m_timeLine.setDuration(duration); m_timeLine.setDuration(duration);
m_startStopTimeLine.setDuration(duration); m_startStopTimeLine.setDuration(duration);
m_angle = conf.readEntry("Angle", 30); m_angle = FlipSwitchConfig::angle();
m_xPosition = float(conf.readEntry("XPosition", 33)) / 100.0f; m_xPosition = FlipSwitchConfig::xPosition() / 100.0f;
m_yPosition = float(conf.readEntry("YPosition", 100)) / 100.0f; m_yPosition = FlipSwitchConfig::yPosition() / 100.0f;
m_windowTitle = conf.readEntry("WindowTitle", true); m_windowTitle = FlipSwitchConfig::windowTitle();
} }
void FlipSwitchEffect::prePaintScreen(ScreenPrePaintData& data, int time) void FlipSwitchEffect::prePaintScreen(ScreenPrePaintData& data, int time)

View file

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
<kcfgfile name="kwinrc"/>
<group name="Effect-FlipSwitch">
<entry name="BorderActivate" type="IntList" />
<entry name="BorderActivateAll" type="IntList" />
<entry name="TabBox" type="Bool">
<default>false</default>
</entry>
<entry name="TabBoxAlternative" type="Bool">
<default>false</default>
</entry>
<entry name="Duration" type="Int">
<default>0</default>
</entry>
<entry name="Angle" type="Int">
<default>30</default>
</entry>
<entry name="XPosition" type="Int">
<default>33</default>
</entry>
<entry name="YPosition" type="Int">
<default>100</default>
</entry>
<entry name="WindowTitle" type="Bool">
<default>true</default>
</entry>
</group>
</kcfg>

View file

@ -18,6 +18,9 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/ *********************************************************************/
#include "flipswitch_config.h" #include "flipswitch_config.h"
// KConfigSkeleton
#include "flipswitchconfig.h"
#include <kwineffects.h> #include <kwineffects.h>
#include <kconfiggroup.h> #include <kconfiggroup.h>
@ -59,12 +62,7 @@ FlipSwitchEffectConfig::FlipSwitchEffectConfig(QWidget* parent, const QVariantLi
m_ui->shortcutEditor->addCollection(m_actionCollection); m_ui->shortcutEditor->addCollection(m_actionCollection);
connect(m_ui->durationSpin, SIGNAL(valueChanged(int)), SLOT(changed())); addConfig(FlipSwitchConfig::self(), m_ui);
connect(m_ui->angleSpin, SIGNAL(valueChanged(int)), SLOT(changed()));
connect(m_ui->horizontalSlider, SIGNAL(valueChanged(int)), SLOT(changed()));
connect(m_ui->verticalSlider, SIGNAL(valueChanged(int)), SLOT(changed()));
connect(m_ui->windowTitleBox, SIGNAL(stateChanged(int)), SLOT(changed()));
connect(m_ui->shortcutEditor, SIGNAL(keyChange()), this, SLOT(changed()));
load(); load();
} }
@ -73,53 +71,13 @@ FlipSwitchEffectConfig::~FlipSwitchEffectConfig()
{ {
} }
void FlipSwitchEffectConfig::load()
{
KCModule::load();
KConfigGroup conf = EffectsHandler::effectConfig("FlipSwitch");
m_ui->durationSpin->setValue(conf.readEntry("Duration", 0));
m_ui->angleSpin->setValue(conf.readEntry("Angle", 30));
m_ui->horizontalSlider->setValue(conf.readEntry("XPosition", 33));
// slider bottom is 0, effect bottom is 100
m_ui->verticalSlider->setValue(100 - conf.readEntry("YPosition", 100));
m_ui->windowTitleBox->setChecked(conf.readEntry("WindowTitle", true));
emit changed(false);
}
void FlipSwitchEffectConfig::save() void FlipSwitchEffectConfig::save()
{ {
KConfigGroup conf = EffectsHandler::effectConfig("FlipSwitch"); KCModule::save();
conf.writeEntry("Duration", m_ui->durationSpin->value());
conf.writeEntry("Angle", m_ui->angleSpin->value());
conf.writeEntry("XPosition", m_ui->horizontalSlider->value());
// slider bottom is 0, effect bottom is 100
conf.writeEntry("YPosition", 100 - m_ui->verticalSlider->value());
conf.writeEntry("WindowTitle", m_ui->windowTitleBox->isChecked());
m_ui->shortcutEditor->save();
conf.sync();
emit changed(false);
EffectsHandler::sendReloadMessage("flipswitch"); EffectsHandler::sendReloadMessage("flipswitch");
} }
void FlipSwitchEffectConfig::defaults()
{
m_ui->durationSpin->setValue(0);
m_ui->angleSpin->setValue(30);
m_ui->horizontalSlider->setValue(33);
// slider bottom is 0, effect bottom is 100
m_ui->verticalSlider->setValue(0);
m_ui->windowTitleBox->setChecked(true);
m_ui->shortcutEditor->allDefault();
emit changed(true);
}
} // namespace } // namespace

View file

@ -46,8 +46,6 @@ public:
public slots: public slots:
virtual void save(); virtual void save();
virtual void load();
virtual void defaults();
private: private:
FlipSwitchEffectConfigForm* m_ui; FlipSwitchEffectConfigForm* m_ui;

View file

@ -26,12 +26,12 @@
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property> </property>
<property name="buddy"> <property name="buddy">
<cstring>durationSpin</cstring> <cstring>kcfg_Duration</cstring>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="1"> <item row="0" column="1">
<widget class="KIntSpinBox" name="durationSpin"> <widget class="KIntSpinBox" name="kcfg_Duration">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed"> <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch> <horstretch>0</horstretch>
@ -55,12 +55,12 @@
<string>Angle:</string> <string>Angle:</string>
</property> </property>
<property name="buddy"> <property name="buddy">
<cstring>angleSpin</cstring> <cstring>kcfg_Angle</cstring>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="1"> <item row="1" column="1">
<widget class="KIntSpinBox" name="angleSpin"> <widget class="KIntSpinBox" name="kcfg_Angle">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed"> <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch> <horstretch>0</horstretch>
@ -81,14 +81,14 @@
<string>Horizontal position of front:</string> <string>Horizontal position of front:</string>
</property> </property>
<property name="buddy"> <property name="buddy">
<cstring>horizontalSlider</cstring> <cstring>kcfg_XPosition</cstring>
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="1"> <item row="3" column="1">
<layout class="QVBoxLayout" name="verticalLayout_2"> <layout class="QVBoxLayout" name="verticalLayout_2">
<item> <item>
<widget class="QSlider" name="horizontalSlider"> <widget class="QSlider" name="kcfg_XPosition">
<property name="maximum"> <property name="maximum">
<number>100</number> <number>100</number>
</property> </property>
@ -136,14 +136,14 @@
<string>Vertical position of front:</string> <string>Vertical position of front:</string>
</property> </property>
<property name="buddy"> <property name="buddy">
<cstring>verticalSlider</cstring> <cstring>kcfg_YPosition</cstring>
</property> </property>
</widget> </widget>
</item> </item>
<item row="7" column="1"> <item row="7" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_2"> <layout class="QHBoxLayout" name="horizontalLayout_2">
<item> <item>
<widget class="QSlider" name="verticalSlider"> <widget class="QSlider" name="kcfg_YPosition">
<property name="maximum"> <property name="maximum">
<number>100</number> <number>100</number>
</property> </property>
@ -186,7 +186,7 @@
</layout> </layout>
</item> </item>
<item row="2" column="0" colspan="2"> <item row="2" column="0" colspan="2">
<widget class="QCheckBox" name="windowTitleBox"> <widget class="QCheckBox" name="kcfg_WindowTitle">
<property name="text"> <property name="text">
<string>Display window &amp;titles</string> <string>Display window &amp;titles</string>
</property> </property>
@ -233,7 +233,7 @@
</customwidget> </customwidget>
</customwidgets> </customwidgets>
<tabstops> <tabstops>
<tabstop>durationSpin</tabstop> <tabstop>kcfg_Duration</tabstop>
</tabstops> </tabstops>
<resources/> <resources/>
<connections/> <connections/>

View file

@ -0,0 +1,5 @@
File=flipswitch.kcfg
ClassName=FlipSwitchConfig
NameSpace=KWin
Singleton=true
Mutators=true