Use KConfigXT in MouseMark Effect

REVIEW: 106414
This commit is contained in:
Giuseppe Calà 2012-09-12 19:14:30 +02:00 committed by Martin Gräßlin
parent 65bb42a801
commit ab305a1aba
7 changed files with 81 additions and 79 deletions

View file

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

View file

@ -21,15 +21,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "mousemark.h"
// KConfigSkeleton
#include "mousemarkconfig.h"
#include <kwinconfig.h>
#include <kwinglutils.h>
#include <kaction.h>
#include <kactioncollection.h>
#include <kglobal.h>
#include <klocale.h>
#include <kstandarddirs.h>
#include <kconfiggroup.h>
#include <math.h>
@ -68,10 +68,10 @@ MouseMarkEffect::~MouseMarkEffect()
static int width_2 = 1;
void MouseMarkEffect::reconfigure(ReconfigureFlags)
{
KConfigGroup conf = EffectsHandler::effectConfig("MouseMark");
width = conf.readEntry("LineWidth", 3);
MouseMarkConfig::self()->readConfig();
width = MouseMarkConfig::lineWidth();
width_2 = width / 2;
color = conf.readEntry("Color", QColor(Qt::red));
color = MouseMarkConfig::color();
color.setAlphaF(1.0);
}

View file

@ -0,0 +1,15 @@
<?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-MouseMark">
<entry name="LineWidth" type="UInt">
<default>3</default>
</entry>
<entry name="Color" type="Color">
<default>255,0,0</default>
</entry>
</group>
</kcfg>

View file

@ -20,11 +20,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "mousemark_config.h"
// KConfigSkeleton
#include "mousemarkconfig.h"
#include <kwineffects.h>
#include <klocale.h>
#include <kdebug.h>
#include <kconfiggroup.h>
#include <KActionCollection>
#include <kaction.h>
#include <KShortcutsEditor>
@ -46,13 +48,13 @@ MouseMarkEffectConfig::MouseMarkEffectConfig(QWidget* parent, const QVariantList
{
m_ui = new MouseMarkEffectConfigForm(this);
m_ui->kcfg_LineWidth->setSuffix(ki18np(" pixel", " pixels"));
QVBoxLayout* layout = new QVBoxLayout(this);
layout->addWidget(m_ui);
connect(m_ui->editor, SIGNAL(keyChange()), this, SLOT(changed()));
connect(m_ui->spinWidth, SIGNAL(valueChanged(int)), this, SLOT(changed()));
connect(m_ui->comboColors, SIGNAL(currentIndexChanged(int)), this, SLOT(changed()));
addConfig(MouseMarkConfig::self(), m_ui);
// Shortcut config. The shortcut belongs to the component "kwin"!
m_actionCollection = new KActionCollection(this, KComponentData("kwin"));
@ -78,48 +80,17 @@ MouseMarkEffectConfig::~MouseMarkEffectConfig()
m_ui->editor->undoChanges();
}
void MouseMarkEffectConfig::load()
{
KCModule::load();
KConfigGroup conf = EffectsHandler::effectConfig("MouseMark");
int width = conf.readEntry("LineWidth", 3);
QColor color = conf.readEntry("Color", QColor(Qt::red));
m_ui->spinWidth->setValue(width);
m_ui->spinWidth->setSuffix(ki18np(" pixel", " pixels"));
m_ui->comboColors->setColor(color);
emit changed(false);
}
void MouseMarkEffectConfig::save()
{
kDebug(1212) << "Saving config of MouseMark" ;
//KCModule::save();
KConfigGroup conf = EffectsHandler::effectConfig("MouseMark");
conf.writeEntry("LineWidth", m_ui->spinWidth->value());
conf.writeEntry("Color", m_ui->comboColors->color());
KCModule::save();
m_actionCollection->writeSettings();
m_ui->editor->save(); // undo() will restore to this state from now on
conf.sync();
emit changed(false);
EffectsHandler::sendReloadMessage("mousemark");
}
void MouseMarkEffectConfig::defaults()
{
m_ui->spinWidth->setValue(3);
m_ui->comboColors->setColor(Qt::red);
emit changed(true);
}
} // namespace
#include "mousemark_config.moc"

View file

@ -45,8 +45,6 @@ public:
virtual ~MouseMarkEffectConfig();
virtual void save();
virtual void load();
virtual void defaults();
private:
MouseMarkEffectConfigForm* m_ui;

View file

@ -1,6 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>KWin::MouseMarkEffectConfigForm</class>
<widget class="QWidget" name="KWin::MouseMarkEffectConfigForm">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>279</width>
<height>178</height>
</rect>
</property>
<layout class="QVBoxLayout">
<item>
<widget class="QGroupBox" name="groupBox">
@ -17,14 +26,14 @@
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy">
<cstring>spinWidth</cstring>
<cstring>kcfg_LineWidth</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="KIntSpinBox" name="spinWidth" >
<widget class="KIntSpinBox" name="kcfg_LineWidth">
<property name="sizePolicy">
<sizepolicy vsizetype="Fixed" hsizetype="Expanding" >
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -49,14 +58,14 @@
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy">
<cstring>comboColors</cstring>
<cstring>kcfg_Color</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="KColorCombo" name="comboColors" >
<widget class="KColorCombo" name="kcfg_Color">
<property name="sizePolicy">
<sizepolicy vsizetype="Fixed" hsizetype="Expanding" >
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -67,7 +76,7 @@
</widget>
</item>
<item>
<widget class="KWin::GlobalShortcutsEditor" native="1" name="editor" />
<widget class="KWin::GlobalShortcutsEditor" name="editor" native="true"/>
</item>
<item>
<widget class="QLabel" name="label_3">

View file

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