Use KConfigXT in ShowFps Effect

REVIEW: 106415
This commit is contained in:
Giuseppe Calà 2012-09-12 19:20:43 +02:00 committed by Martin Gräßlin
parent 6ac2014533
commit 65bb42a801
7 changed files with 116 additions and 132 deletions

View file

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

View file

@ -20,11 +20,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "showfps.h"
#include <kwinconfig.h>
// KConfigSkeleton
#include "showfpsconfig.h"
#include <kconfiggroup.h>
#include <kglobal.h>
#include <ksharedconfig.h>
#include <kwinconfig.h>
#include <kwinglutils.h>
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
@ -66,10 +65,10 @@ ShowFpsEffect::ShowFpsEffect()
void ShowFpsEffect::reconfigure(ReconfigureFlags)
{
KConfigGroup config(KGlobal::config(), "EffectShowFps");
alpha = config.readEntry("Alpha", 0.5);
x = config.readEntry("X", -10000);
y = config.readEntry("Y", 0);
ShowFpsConfig::self()->readConfig();
alpha = ShowFpsConfig::alpha();
x = ShowFpsConfig::x();
y = ShowFpsConfig::y();
if (x == -10000) // there's no -0 :(
x = displayWidth() - 2 * NUM_PAINTS - FPS_WIDTH;
else if (x < 0)
@ -80,11 +79,10 @@ void ShowFpsEffect::reconfigure(ReconfigureFlags)
y = displayHeight() - MAX_TIME - y;
fps_rect = QRect(x, y, FPS_WIDTH + 2 * NUM_PAINTS, MAX_TIME);
config = effects->effectConfig("ShowFps");
int textPosition = config.readEntry("TextPosition", int(INSIDE_GRAPH));
textFont = config.readEntry("TextFont", QFont());
textColor = config.readEntry("TextColor", QColor());
double textAlpha = config.readEntry("TextAlpha", 1.0);
int textPosition = ShowFpsConfig::textPosition();
textFont = ShowFpsConfig::textFont();
textColor = ShowFpsConfig::textColor();
double textAlpha = ShowFpsConfig::textAlpha();
if (!textColor.isValid())
textColor = QPalette().color(QPalette::Active, QPalette::WindowText);

View file

@ -0,0 +1,28 @@
<?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-ShowFps">
<entry name="TextPosition" type="Int">
<default>0</default>
</entry>
<entry name="TextFont" type="Font"/>
<entry name="TextColor" type="Color">
<default>invalid</default>
</entry>
<entry name="TextAlpha" type="Double">
<default>1.0</default>
</entry>
<entry name="Alpha" type="Double">
<default>0.5</default>
</entry>
<entry name="X" type="Int">
<default>-10000</default>
</entry>
<entry name="Y" type="Int">
<default>0</default>
</entry>
</group>
</kcfg>

View file

@ -19,6 +19,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#include "showfps_config.h"
// KConfigSkeleton
#include "showfpsconfig.h"
#include "showfps.h"
#include <kwineffects.h>
@ -37,10 +41,7 @@ ShowFpsEffectConfig::ShowFpsEffectConfig(QWidget* parent, const QVariantList& ar
m_ui = new Ui::ShowFpsEffectConfigForm;
m_ui->setupUi(this);
connect(m_ui->textPosition, SIGNAL(currentIndexChanged(int)), this, SLOT(changed()));
connect(m_ui->textFont, SIGNAL(fontSelected(QFont)), this, SLOT(changed()));
connect(m_ui->textColor, SIGNAL(changed(QColor)), this, SLOT(changed()));
connect(m_ui->textAlpha, SIGNAL(valueChanged(double)), this, SLOT(changed()));
addConfig(ShowFpsConfig::self(), this);
load();
}
@ -50,63 +51,12 @@ ShowFpsEffectConfig::~ShowFpsEffectConfig()
delete m_ui;
}
void ShowFpsEffectConfig::load()
{
KCModule::load();
KConfigGroup conf = EffectsHandler::effectConfig("ShowFps");
int position = conf.readEntry("TextPosition", int(ShowFpsEffect::INSIDE_GRAPH));
if (position > -1)
m_ui->textPosition->setCurrentIndex(position);
QFont font = conf.readEntry("TextFont", QFont());
m_ui->textFont->setFont(font);
QColor color = conf.readEntry("TextColor", QColor());
if (color.isValid())
m_ui->textColor->setColor(color);
double alpha = conf.readEntry("TextAlpha", 1.0);
m_ui->textAlpha->setValue(alpha);
emit changed(false);
}
void ShowFpsEffectConfig::save()
{
KCModule::save();
KConfigGroup conf = EffectsHandler::effectConfig("ShowFps");
int position = m_ui->textPosition->currentIndex();
conf.writeEntry("TextPosition", position);
QFont font = m_ui->textFont->font();
conf.writeEntry("TextFont", font);
QColor color = m_ui->textColor->color();
conf.writeEntry("TextColor", color);
double alpha = m_ui->textAlpha->value();
conf.writeEntry("TextAlpha", alpha);
conf.sync();
emit changed(false);
EffectsHandler::sendReloadMessage("showfps");
}
void ShowFpsEffectConfig::defaults()
{
m_ui->textPosition->setCurrentIndex(0);
m_ui->textFont->setFont(QFont());
m_ui->textColor->setColor(QColor());
m_ui->textAlpha->setValue(1.0);
emit changed(true);
}
} // namespace
#include "showfps_config.moc"

View file

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

View file

@ -1,148 +1,149 @@
<ui version="4.0" >
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>KWin::ShowFpsEffectConfigForm</class>
<widget class="QWidget" name="KWin::ShowFpsEffectConfigForm" >
<property name="geometry" >
<widget class="QWidget" name="KWin::ShowFpsEffectConfigForm">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>310</width>
<height>166</height>
<width>356</width>
<height>180</height>
</rect>
</property>
<layout class="QVBoxLayout" >
<layout class="QVBoxLayout">
<item>
<widget class="QGroupBox" name="groupBox" >
<property name="title" >
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Text</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>Text position:</string>
</property>
<property name="alignment" >
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy" >
<cstring>textPosition</cstring>
<property name="buddy">
<cstring>kcfg_TextPosition</cstring>
</property>
</widget>
</item>
<item row="0" column="1" >
<widget class="KComboBox" name="textPosition" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Fixed" hsizetype="Expanding" >
<item row="0" column="1">
<widget class="KComboBox" name="kcfg_TextPosition">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item>
<property name="text" >
<property name="text">
<string>Inside Graph</string>
</property>
</item>
<item>
<property name="text" >
<property name="text">
<string>Nowhere</string>
</property>
</item>
<item>
<property name="text" >
<property name="text">
<string>Top Left</string>
</property>
</item>
<item>
<property name="text" >
<property name="text">
<string>Top Right</string>
</property>
</item>
<item>
<property name="text" >
<property name="text">
<string>Bottom Left</string>
</property>
</item>
<item>
<property name="text" >
<property name="text">
<string>Bottom Right</string>
</property>
</item>
</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>Text font:</string>
</property>
<property name="alignment" >
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="1" >
<widget class="KFontRequester" name="textFont" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Preferred" hsizetype="Expanding" >
<item row="1" column="1">
<widget class="KFontRequester" name="kcfg_TextFont">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="2" column="0" >
<widget class="QLabel" name="label_3" >
<property name="text" >
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Text color:</string>
</property>
<property name="alignment" >
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy" >
<cstring>textColor</cstring>
<property name="buddy">
<cstring>kcfg_TextColor</cstring>
</property>
</widget>
</item>
<item row="2" column="1" >
<widget class="KColorButton" name="textColor" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Fixed" hsizetype="Expanding" >
<item row="2" column="1">
<widget class="KColorButton" name="kcfg_TextColor">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="3" column="0" >
<widget class="QLabel" name="label_4" >
<property name="text" >
<item row="3" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Text alpha:</string>
</property>
<property name="alignment" >
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy" >
<cstring>textAlpha</cstring>
<property name="buddy">
<cstring>kcfg_TextAlpha</cstring>
</property>
</widget>
</item>
<item row="3" column="1" >
<widget class="QDoubleSpinBox" name="textAlpha" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Fixed" hsizetype="Expanding" >
<item row="3" column="1">
<widget class="QDoubleSpinBox" name="kcfg_TextAlpha">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="decimals" >
<property name="decimals">
<number>2</number>
</property>
<property name="maximum" >
<property name="maximum">
<double>1.000000000000000</double>
</property>
<property name="singleStep" >
<property name="singleStep">
<double>0.100000000000000</double>
</property>
<property name="value" >
<property name="value">
<double>1.000000000000000</double>
</property>
</widget>
@ -158,16 +159,16 @@
<extends>QPushButton</extends>
<header>kcolorbutton.h</header>
</customwidget>
<customwidget>
<class>KComboBox</class>
<extends>QComboBox</extends>
<header>kcombobox.h</header>
</customwidget>
<customwidget>
<class>KFontRequester</class>
<extends>QWidget</extends>
<header>kfontrequester.h</header>
</customwidget>
<customwidget>
<class>KComboBox</class>
<extends>QComboBox</extends>
<header>kcombobox.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>

View file

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