Use KConfigXT in Magnifier Effect

REVIEW: 106442
This commit is contained in:
Alexander Jones 2012-09-13 15:25:18 -05:00 committed by Martin Gräßlin
parent 85510b91aa
commit 696ea9f4d3
7 changed files with 75 additions and 72 deletions

View file

@ -6,6 +6,8 @@ set( kwin4_effect_builtins_sources ${kwin4_effect_builtins_sources}
magnifier/magnifier.cpp
)
kde4_add_kcfg_files(kwin4_effect_builtins_sources magnifier/magnifierconfig.kcfgc)
# .desktop files
install( FILES
magnifier/magnifier.desktop
@ -19,6 +21,7 @@ set( kwin4_effect_builtins_config_sources ${kwin4_effect_builtins_config_sources
magnifier/magnifier_config.cpp
magnifier/magnifier_config.ui
)
kde4_add_kcfg_files(kwin4_effect_builtins_config_sources magnifier/magnifierconfig.kcfgc)
# .desktop files
install( FILES

View file

@ -21,12 +21,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#include "magnifier.h"
// KConfigSkeleton
#include "magnifierconfig.h"
#include <kwinconfig.h>
#include <kaction.h>
#include <kactioncollection.h>
#include <kconfiggroup.h>
#include <kstandardaction.h>
#include <kwinglutils.h>
@ -82,13 +83,13 @@ bool MagnifierEffect::supported()
void MagnifierEffect::reconfigure(ReconfigureFlags)
{
KConfigGroup conf = EffectsHandler::effectConfig("Magnifier");
MagnifierConfig::self()->readConfig();
int width, height;
width = conf.readEntry("Width", 200);
height = conf.readEntry("Height", 200);
width = MagnifierConfig::width();
height = MagnifierConfig::height();
magnifier_size = QSize(width, height);
// Load the saved zoom value.
target_zoom = conf.readEntry("InitialZoom", target_zoom);
target_zoom = MagnifierConfig::initialZoom();
if (target_zoom != zoom)
toggle();
}

View file

@ -0,0 +1,18 @@
<?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-Magnifier">
<entry name="Width" type="UInt">
<default>200</default>
</entry>
<entry name="Height" type="UInt">
<default>200</default>
</entry>
<entry name="InitialZoom" type="Double">
<default>1.0</default>
</entry>
</group>
</kcfg>

View file

@ -19,6 +19,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#include "magnifier_config.h"
// KConfigSkeleton
#include "magnifierconfig.h"
#include <kwineffects.h>
@ -51,9 +53,9 @@ MagnifierEffectConfig::MagnifierEffectConfig(QWidget* parent, const QVariantList
layout->addWidget(m_ui);
addConfig(MagnifierConfig::self(), m_ui);
connect(m_ui->editor, SIGNAL(keyChange()), this, SLOT(changed()));
connect(m_ui->spinWidth, SIGNAL(valueChanged(int)), this, SLOT(changed()));
connect(m_ui->spinHeight, SIGNAL(valueChanged(int)), this, SLOT(changed()));
// Shortcut config. The shortcut belongs to the component "kwin"!
m_actionCollection = new KActionCollection(this, KComponentData("kwin"));
@ -75,6 +77,7 @@ MagnifierEffectConfig::MagnifierEffectConfig(QWidget* parent, const QVariantList
a->setGlobalShortcut(KShortcut(Qt::META + Qt::Key_0));
m_ui->editor->addCollection(m_actionCollection);
load();
}
MagnifierEffectConfig::~MagnifierEffectConfig()
@ -83,48 +86,21 @@ MagnifierEffectConfig::~MagnifierEffectConfig()
m_ui->editor->undoChanges();
}
void MagnifierEffectConfig::load()
{
KCModule::load();
KConfigGroup conf = EffectsHandler::effectConfig("Magnifier");
int width = conf.readEntry("Width", 200);
int height = conf.readEntry("Height", 200);
m_ui->spinWidth->setValue(width);
m_ui->spinHeight->setValue(height);
emit changed(false);
}
void MagnifierEffectConfig::save()
{
kDebug(1212) << "Saving config of Magnifier" ;
//KCModule::save();
KConfigGroup conf = EffectsHandler::effectConfig("Magnifier");
conf.writeEntry("Width", m_ui->spinWidth->value());
conf.writeEntry("Height", m_ui->spinHeight->value());
m_ui->editor->save(); // undo() will restore to this state from now on
conf.sync();
emit changed(false);
KCModule::save();
EffectsHandler::sendReloadMessage("magnifier");
}
void MagnifierEffectConfig::defaults()
{
m_ui->spinWidth->setValue(200);
m_ui->spinHeight->setValue(200);
m_ui->editor->allDefault();
emit changed(true);
KCModule::defaults();
}
} // namespace
#include "magnifier_config.moc"

View file

@ -45,7 +45,6 @@ public:
virtual ~MagnifierEffectConfig();
virtual void save();
virtual void load();
virtual void defaults();
private:

View file

@ -1,3 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>KWin::MagnifierEffectConfigForm</class>
<widget class="QWidget" name="KWin::MagnifierEffectConfigForm">
@ -25,14 +26,14 @@
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy">
<cstring>spinWidth</cstring>
<cstring>kcfg_Width</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="KIntSpinBox" name="spinWidth" >
<widget class="KIntSpinBox" name="kcfg_Width">
<property name="sizePolicy">
<sizepolicy vsizetype="Fixed" hsizetype="Expanding" >
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -57,14 +58,14 @@
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy">
<cstring>spinHeight</cstring>
<cstring>kcfg_Height</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="KIntSpinBox" name="spinHeight" >
<widget class="KIntSpinBox" name="kcfg_Height">
<property name="sizePolicy">
<sizepolicy vsizetype="Fixed" hsizetype="Expanding" >
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -84,7 +85,7 @@
</widget>
</item>
<item>
<widget class="KWin::GlobalShortcutsEditor" native="1" name="editor" />
<widget class="KWin::GlobalShortcutsEditor" name="editor" native="true"/>
</item>
</layout>
</widget>

View file

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