Use KConfigXT in CoverSwitch Effect

REVIEW: 106396
This commit is contained in:
Dario Cambié 2012-09-19 17:59:11 +02:00 committed by Martin Gräßlin
parent bf8e7c4fc8
commit b26108121d
7 changed files with 119 additions and 125 deletions

View file

@ -6,6 +6,8 @@ set( kwin4_effect_builtins_sources ${kwin4_effect_builtins_sources}
coverswitch/coverswitch.cpp
)
kde4_add_kcfg_files(kwin4_effect_builtins_sources coverswitch/coverswitchconfig.kcfgc)
# .desktop files
install( FILES
coverswitch/coverswitch.desktop
@ -24,6 +26,7 @@ set( kwin4_effect_builtins_config_sources ${kwin4_effect_builtins_config_sources
coverswitch/coverswitch_config.cpp
coverswitch/coverswitch_config.ui
)
kde4_add_kcfg_files(kwin4_effect_builtins_config_sources coverswitch/coverswitchconfig.kcfgc)
# .desktop files
install( FILES

View file

@ -18,6 +18,8 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#include "coverswitch.h"
// KConfigSkeleton
#include "coverswitchconfig.h"
#include <kwinconfig.h>
#include <QFont>
@ -26,7 +28,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <klocale.h>
#include <kapplication.h>
#include <kcolorscheme.h>
#include <kconfiggroup.h>
#include <kglobal.h>
#include <kstandarddirs.h>
#include <KDE/KIcon>
@ -89,27 +90,30 @@ bool CoverSwitchEffect::supported()
void CoverSwitchEffect::reconfigure(ReconfigureFlags)
{
KConfigGroup conf = effects->effectConfig("CoverSwitch");
animationDuration = animationTime(conf, "Duration", 200);
animateSwitch = conf.readEntry("AnimateSwitch", true);
animateStart = conf.readEntry("AnimateStart", true);
animateStop = conf.readEntry("AnimateStop", true);
reflection = conf.readEntry("Reflection", true);
windowTitle = conf.readEntry("WindowTitle", true);
zPosition = conf.readEntry("ZPosition", 900.0);
thumbnails = conf.readEntry("Thumbnails", true);
dynamicThumbnails = conf.readEntry("DynamicThumbnails", true);
thumbnailWindows = conf.readEntry("ThumbnailWindows", 8);
CoverSwitchConfig::self()->readConfig();
animationDuration = animationTime(CoverSwitchConfig::duration());
animateSwitch = CoverSwitchConfig::animateSwitch();
animateStart = CoverSwitchConfig::animateStart();
animateStop = CoverSwitchConfig::animateStop();
reflection = CoverSwitchConfig::reflection();
windowTitle = CoverSwitchConfig::windowTitle();
zPosition = CoverSwitchConfig::zPosition();
thumbnails = CoverSwitchConfig::thumbnails();
dynamicThumbnails = CoverSwitchConfig::dynamicThumbnails();
thumbnailWindows = CoverSwitchConfig::thumbnailWindows();
timeLine.setCurveShape(QTimeLine::EaseInOutCurve);
timeLine.setDuration(animationDuration);
primaryTabBox = conf.readEntry("TabBox", false);
secondaryTabBox = conf.readEntry("TabBoxAlternative", false);
QColor tmp = conf.readEntry("MirrorFrontColor", QColor(0, 0, 0));
// Defined outside the ui
primaryTabBox = CoverSwitchConfig::tabBox();
secondaryTabBox = CoverSwitchConfig::tabBoxAlternative();
QColor tmp = CoverSwitchConfig::mirrorFrontColor();
mirrorColor[0][0] = tmp.redF();
mirrorColor[0][1] = tmp.greenF();
mirrorColor[0][2] = tmp.blueF();
mirrorColor[0][3] = 1.0;
tmp = conf.readEntry("MirrorRearColor", QColor(0, 0, 0));
tmp = CoverSwitchConfig::mirrorRearColor();
mirrorColor[1][0] = tmp.redF();
mirrorColor[1][1] = tmp.greenF();
mirrorColor[1][2] = tmp.blueF();

View file

@ -0,0 +1,51 @@
<?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-CoverSwitch">
<entry name="Duration" type="UInt">
<default>0</default>
</entry>
<entry name="AnimateSwitch" type="Bool">
<default>true</default>
</entry>
<entry name="AnimateStart" type="Bool">
<default>true</default>
</entry>
<entry name="AnimateStop" type="Bool">
<default>true</default>
</entry>
<entry name="Reflection" type="Bool">
<default>true</default>
</entry>
<entry name="MirrorFrontColor" type="Color">
<default code="true">QColor(0, 0, 0)</default>
</entry>
<entry name="MirrorRearColor" type="Color">
<default code="true">QColor(0, 0, 0)</default>
</entry>
<entry name="WindowTitle" type="Bool">
<default>true</default>
</entry>
<entry name="Thumbnails" type="Bool">
<default>true</default>
</entry>
<entry name="DynamicThumbnails" type="Bool">
<default>true</default>
</entry>
<entry name="ThumbnailWindows" type="UInt">
<default>8</default>
</entry>
<entry name="zPosition" type="UInt">
<default>900</default>
</entry>
<entry name="TabBox" type="Bool">
<default>false</default>
</entry>
<entry name="TabBoxAlternative" type="Bool">
<default>false</default>
</entry>
</group>
</kcfg>

View file

@ -18,9 +18,10 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#include "coverswitch_config.h"
#include <kwineffects.h>
// KConfigSkeleton
#include "coverswitchconfig.h"
#include <kconfiggroup.h>
#include <kwineffects.h>
#include <QVBoxLayout>
@ -43,98 +44,27 @@ CoverSwitchEffectConfig::CoverSwitchEffectConfig(QWidget* parent, const QVariant
layout->addWidget(m_ui);
connect(m_ui->checkAnimateSwitch, SIGNAL(stateChanged(int)), this, SLOT(changed()));
connect(m_ui->checkAnimateStart, SIGNAL(stateChanged(int)), this, SLOT(changed()));
connect(m_ui->checkAnimateStop, SIGNAL(stateChanged(int)), this, SLOT(changed()));
connect(m_ui->checkReflection, SIGNAL(stateChanged(int)), this, SLOT(changed()));
connect(m_ui->colorFront, SIGNAL(changed(QColor)), this, SLOT(changed()));
connect(m_ui->colorRear, SIGNAL(changed(QColor)), this, SLOT(changed()));
connect(m_ui->checkWindowTitle, SIGNAL(stateChanged(int)), this, SLOT(changed()));
connect(m_ui->checkThumbnails, SIGNAL(stateChanged(int)), this, SLOT(changed()));
connect(m_ui->checkDynamicThumbnails, SIGNAL(stateChanged(int)), this, SLOT(changed()));
connect(m_ui->spinThumbnailWindows, SIGNAL(valueChanged(int)), this, SLOT(changed()));
connect(m_ui->spinDuration, SIGNAL(valueChanged(int)), this, SLOT(changed()));
connect(m_ui->zPositionSlider, SIGNAL(valueChanged(int)), this, SLOT(changed()));
connect(m_ui->kcfg_Thumbnails, SIGNAL(stateChanged(int)), this, SLOT(thumbnailsChanged()));
connect(m_ui->kcfg_DynamicThumbnails, SIGNAL(stateChanged(int)), this, SLOT(thumbnailsChanged()));
connect(m_ui->checkThumbnails, SIGNAL(stateChanged(int)), this, SLOT(thumbnailsChanged()));
connect(m_ui->checkDynamicThumbnails, SIGNAL(stateChanged(int)), this, SLOT(thumbnailsChanged()));
load();
}
void CoverSwitchEffectConfig::load()
{
KCModule::load();
KConfigGroup conf = EffectsHandler::effectConfig("CoverSwitch");
m_ui->spinDuration->setValue(conf.readEntry("Duration", 0));
m_ui->spinDuration->setSuffix(ki18np(" millisecond", " milliseconds"));
m_ui->checkAnimateSwitch->setChecked(conf.readEntry("AnimateSwitch", true));
m_ui->checkAnimateStart->setChecked(conf.readEntry("AnimateStart", true));
m_ui->checkAnimateStop->setChecked(conf.readEntry("AnimateStop", true));
m_ui->checkReflection->setChecked(conf.readEntry("Reflection", true));
m_ui->colorFront->setColor(conf.readEntry("MirrorFrontColor", QColor(0, 0, 0)));
m_ui->colorRear->setColor(conf.readEntry("MirrorRearColor", QColor(0, 0, 0)));
m_ui->checkWindowTitle->setChecked(conf.readEntry("WindowTitle", true));
m_ui->checkThumbnails->setChecked(conf.readEntry("Thumbnails", true));
m_ui->checkDynamicThumbnails->setChecked(conf.readEntry("DynamicThumbnails", true));
m_ui->spinThumbnailWindows->setValue(conf.readEntry("ThumbnailWindows", 8));
m_ui->zPositionSlider->setValue(conf.readEntry("ZPosition", 900));
thumbnailsChanged();
emit changed(false);
addConfig(CoverSwitchConfig::self(), m_ui);
}
void CoverSwitchEffectConfig::save()
{
KConfigGroup conf = EffectsHandler::effectConfig("CoverSwitch");
conf.writeEntry("Duration", m_ui->spinDuration->value());
conf.writeEntry("AnimateSwitch", m_ui->checkAnimateSwitch->isChecked());
conf.writeEntry("AnimateStart", m_ui->checkAnimateStart->isChecked());
conf.writeEntry("AnimateStop", m_ui->checkAnimateStop->isChecked());
conf.writeEntry("Reflection", m_ui->checkReflection->isChecked());
conf.writeEntry("MirrorFrontColor", m_ui->colorFront->color());
conf.writeEntry("MirrorRearColor", m_ui->colorRear->color());
conf.writeEntry("WindowTitle", m_ui->checkWindowTitle->isChecked());
conf.writeEntry("Thumbnails", m_ui->checkThumbnails->isChecked());
conf.writeEntry("DynamicThumbnails", m_ui->checkDynamicThumbnails->isChecked());
conf.writeEntry("ThumbnailWindows", m_ui->spinThumbnailWindows->value());
conf.writeEntry("ZPosition", m_ui->zPositionSlider->value());
conf.sync();
emit changed(false);
KCModule::save();
EffectsHandler::sendReloadMessage("coverswitch");
}
void CoverSwitchEffectConfig::defaults()
{
m_ui->spinDuration->setValue(0);
m_ui->checkAnimateSwitch->setCheckState(Qt::Checked);
m_ui->checkAnimateStart->setCheckState(Qt::Checked);
m_ui->checkAnimateStop->setCheckState(Qt::Checked);
m_ui->checkReflection->setCheckState(Qt::Checked);
m_ui->colorFront->setColor(QColor(0, 0, 0));
m_ui->colorRear->setColor(QColor(0, 0, 0));
m_ui->checkWindowTitle->setCheckState(Qt::Checked);
m_ui->checkThumbnails->setCheckState(Qt::Checked);
m_ui->checkDynamicThumbnails->setCheckState(Qt::Checked);
m_ui->spinThumbnailWindows->setValue(8);
m_ui->zPositionSlider->setValue(900);
emit changed(true);
}
void CoverSwitchEffectConfig::thumbnailsChanged()
{
bool enabled = m_ui->checkThumbnails->isChecked() && m_ui->checkDynamicThumbnails->isChecked();
m_ui->checkDynamicThumbnails->setEnabled(m_ui->checkThumbnails->isChecked());
m_ui->spinThumbnailWindows->setEnabled(enabled);
bool enabled = m_ui->kcfg_Thumbnails->isChecked() && m_ui->kcfg_DynamicThumbnails->isChecked();
m_ui->kcfg_DynamicThumbnails->setEnabled(m_ui->kcfg_Thumbnails->isChecked());
m_ui->kcfg_ThumbnailWindows->setEnabled(enabled);
m_ui->labelThumbnailWindows->setEnabled(enabled);
}
} // namespace
#include "coverswitch_config.moc"

View file

@ -44,8 +44,6 @@ public:
public slots:
virtual void save();
virtual void load();
virtual void defaults();
private slots:
void thumbnailsChanged();

View file

@ -7,12 +7,12 @@
<x>0</x>
<y>0</y>
<width>453</width>
<height>264</height>
<height>270</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<widget class="QCheckBox" name="checkWindowTitle">
<widget class="QCheckBox" name="kcfg_WindowTitle">
<property name="text">
<string>Display window &amp;titles</string>
</property>
@ -34,7 +34,7 @@
</widget>
</item>
<item>
<widget class="QSlider" name="zPositionSlider">
<widget class="QSlider" name="kcfg_zPosition">
<property name="toolTip">
<string>Define how far away the windows should appear</string>
</property>
@ -111,21 +111,21 @@
</attribute>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QCheckBox" name="checkAnimateSwitch">
<widget class="QCheckBox" name="kcfg_AnimateSwitch">
<property name="text">
<string>Animate switch</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkAnimateStart">
<widget class="QCheckBox" name="kcfg_AnimateStart">
<property name="text">
<string>Animation on tab box open</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkAnimateStop">
<widget class="QCheckBox" name="kcfg_AnimateStop">
<property name="text">
<string>Animation on tab box close</string>
</property>
@ -142,12 +142,12 @@
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy">
<cstring>spinDuration</cstring>
<cstring>kcfg_Duration</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="KIntSpinBox" name="spinDuration">
<widget class="KIntSpinBox" name="kcfg_Duration">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -157,6 +157,9 @@
<property name="specialValueText">
<string comment="Duration of rotation">Default</string>
</property>
<property name="suffix">
<string> milliseconds</string>
</property>
<property name="maximum">
<number>9999</number>
</property>
@ -175,14 +178,14 @@
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QCheckBox" name="checkThumbnails">
<widget class="QCheckBox" name="kcfg_Thumbnails">
<property name="text">
<string>Use additional thumbnail bar</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkDynamicThumbnails">
<widget class="QCheckBox" name="kcfg_DynamicThumbnails">
<property name="toolTip">
<string>Only show thumbnail bar if there are at least specified number of windows</string>
</property>
@ -202,12 +205,12 @@
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy">
<cstring>spinThumbnailWindows</cstring>
<cstring>kcfg_ThumbnailWindows</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="KIntSpinBox" name="spinThumbnailWindows"/>
<widget class="KIntSpinBox" name="kcfg_ThumbnailWindows"/>
</item>
</layout>
</item>
@ -219,7 +222,7 @@
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QCheckBox" name="checkReflection">
<widget class="QCheckBox" name="kcfg_Reflection">
<property name="text">
<string>Reflections</string>
</property>
@ -238,7 +241,7 @@
</widget>
</item>
<item row="0" column="1">
<widget class="KColorButton" name="colorRear"/>
<widget class="KColorButton" name="kcfg_MirrorRearColor"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label">
@ -248,7 +251,7 @@
</widget>
</item>
<item row="1" column="1">
<widget class="KColorButton" name="colorFront"/>
<widget class="KColorButton" name="kcfg_MirrorFrontColor"/>
</item>
</layout>
</item>
@ -286,9 +289,9 @@
<resources/>
<connections>
<connection>
<sender>checkReflection</sender>
<sender>kcfg_Reflection</sender>
<signal>toggled(bool)</signal>
<receiver>colorFront</receiver>
<receiver>kcfg_MirrorFrontColor</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
@ -302,9 +305,9 @@
</hints>
</connection>
<connection>
<sender>checkReflection</sender>
<sender>kcfg_Reflection</sender>
<signal>toggled(bool)</signal>
<receiver>colorRear</receiver>
<receiver>kcfg_MirrorRearColor</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
@ -318,7 +321,7 @@
</hints>
</connection>
<connection>
<sender>checkReflection</sender>
<sender>kcfg_Reflection</sender>
<signal>toggled(bool)</signal>
<receiver>label_2</receiver>
<slot>setEnabled(bool)</slot>
@ -334,7 +337,7 @@
</hints>
</connection>
<connection>
<sender>checkReflection</sender>
<sender>kcfg_Reflection</sender>
<signal>toggled(bool)</signal>
<receiver>label</receiver>
<slot>setEnabled(bool)</slot>
@ -350,9 +353,9 @@
</hints>
</connection>
<connection>
<sender>checkThumbnails</sender>
<sender>kcfg_Thumbnails</sender>
<signal>toggled(bool)</signal>
<receiver>checkDynamicThumbnails</receiver>
<receiver>kcfg_DynamicThumbnails</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
@ -366,7 +369,7 @@
</hints>
</connection>
<connection>
<sender>checkThumbnails</sender>
<sender>kcfg_Thumbnails</sender>
<signal>toggled(bool)</signal>
<receiver>labelThumbnailWindows</receiver>
<slot>setEnabled(bool)</slot>
@ -382,9 +385,9 @@
</hints>
</connection>
<connection>
<sender>checkThumbnails</sender>
<sender>kcfg_Thumbnails</sender>
<signal>toggled(bool)</signal>
<receiver>spinThumbnailWindows</receiver>
<receiver>kcfg_ThumbnailWindows</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">

View file

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