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,62 +1,71 @@
<ui version="4.0" >
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>KWin::MouseMarkEffectConfigForm</class>
<widget class="QWidget" name="KWin::MouseMarkEffectConfigForm" >
<layout class="QVBoxLayout" >
<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" >
<property name="title" >
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Appearance</string>
</property>
<layout class="QGridLayout" name="gridLayout" >
<item row="0" column="0" >
<widget class="QLabel" name="label" >
<property name="text" >
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>&amp;Width:</string>
</property>
<property name="alignment" >
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy" >
<cstring>spinWidth</cstring>
<property name="buddy">
<cstring>kcfg_LineWidth</cstring>
</property>
</widget>
</item>
<item row="0" column="1" >
<widget class="KIntSpinBox" name="spinWidth" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Fixed" hsizetype="Expanding" >
<item row="0" column="1">
<widget class="KIntSpinBox" name="kcfg_LineWidth">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimum" >
<property name="minimum">
<number>1</number>
</property>
<property name="maximum" >
<property name="maximum">
<number>10</number>
</property>
<property name="value" >
<property name="value">
<number>3</number>
</property>
</widget>
</item>
<item row="1" column="0" >
<widget class="QLabel" name="label_2" >
<property name="text" >
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>&amp;Color:</string>
</property>
<property name="alignment" >
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy" >
<cstring>comboColors</cstring>
<property name="buddy">
<cstring>kcfg_Color</cstring>
</property>
</widget>
</item>
<item row="1" column="1" >
<widget class="KColorCombo" name="comboColors" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Fixed" hsizetype="Expanding" >
<item row="1" column="1">
<widget class="KColorCombo" name="kcfg_Color">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -67,17 +76,17 @@
</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" >
<property name="text" >
<widget class="QLabel" name="label_3">
<property name="text">
<string>Draw with the mouse by holding Shift+Meta keys and moving the mouse.</string>
</property>
<property name="alignment" >
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="wordWrap" >
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
@ -98,7 +107,7 @@
<customwidget>
<class>KWin::GlobalShortcutsEditor</class>
<extends>QWidget</extends>
<header location="global" >kwineffects.h</header>
<header location="global">kwineffects.h</header>
<container>1</container>
</customwidget>
</customwidgets>

View file

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