~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to kwin/effects/zoom/zoom_config.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/********************************************************************
 
2
 KWin - the KDE window manager
 
3
 This file is part of the KDE project.
 
4
 
 
5
Copyright (C) 2007 Rivo Laks <rivolaks@hot.ee>
 
6
Copyright (C) 2010 Sebastian Sauer <sebsauer@kdab.com>
 
7
 
 
8
This program is free software; you can redistribute it and/or modify
 
9
it under the terms of the GNU General Public License as published by
 
10
the Free Software Foundation; either version 2 of the License, or
 
11
(at your option) any later version.
 
12
 
 
13
This program is distributed in the hope that it will be useful,
 
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
GNU General Public License for more details.
 
17
 
 
18
You should have received a copy of the GNU General Public License
 
19
along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
20
*********************************************************************/
 
21
 
 
22
#include "zoom_config.h"
 
23
 
 
24
#include <kwineffects.h>
 
25
 
 
26
#include <klocale.h>
 
27
#include <kdebug.h>
 
28
#include <KActionCollection>
 
29
#include <kaction.h>
 
30
#include <KShortcutsEditor>
 
31
 
 
32
#include <QVBoxLayout>
 
33
 
 
34
namespace KWin
 
35
{
 
36
 
 
37
KWIN_EFFECT_CONFIG_FACTORY
 
38
 
 
39
ZoomEffectConfigForm::ZoomEffectConfigForm(QWidget* parent) : QWidget(parent)
 
40
{
 
41
    setupUi(this);
 
42
}
 
43
 
 
44
ZoomEffectConfig::ZoomEffectConfig(QWidget* parent, const QVariantList& args) :
 
45
    KCModule(EffectFactory::componentData(), parent, args)
 
46
{
 
47
    m_ui = new ZoomEffectConfigForm(this);
 
48
 
 
49
    QVBoxLayout* layout = new QVBoxLayout(this);
 
50
    layout->addWidget(m_ui);
 
51
 
 
52
    connect(m_ui->zoomStepsSpinBox, SIGNAL(valueChanged(double)), this, SLOT(changed()));
 
53
    connect(m_ui->mousePointerComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(changed()));
 
54
    connect(m_ui->mouseTrackingComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(changed()));
 
55
    connect(m_ui->focusTrackingCheckBox, SIGNAL(toggled(bool)), this, SLOT(changed()));
 
56
    connect(m_ui->followFocusCheckBox, SIGNAL(toggled(bool)), this, SLOT(changed()));
 
57
    connect(m_ui->editor, SIGNAL(keyChange()), this, SLOT(changed()));
 
58
 
 
59
    // Shortcut config. The shortcut belongs to the component "kwin"!
 
60
    KActionCollection *actionCollection = new KActionCollection(this, KComponentData("kwin"));
 
61
    actionCollection->setConfigGroup("Zoom");
 
62
    actionCollection->setConfigGlobal(true);
 
63
 
 
64
    KAction* a;
 
65
    a = static_cast< KAction* >(actionCollection->addAction(KStandardAction::ZoomIn));
 
66
    a->setProperty("isConfigurationAction", true);
 
67
    a->setGlobalShortcut(KShortcut(Qt::META + Qt::Key_Equal));
 
68
 
 
69
    a = static_cast< KAction* >(actionCollection->addAction(KStandardAction::ZoomOut));
 
70
    a->setProperty("isConfigurationAction", true);
 
71
    a->setGlobalShortcut(KShortcut(Qt::META + Qt::Key_Minus));
 
72
 
 
73
    a = static_cast< KAction* >(actionCollection->addAction(KStandardAction::ActualSize));
 
74
    a->setProperty("isConfigurationAction", true);
 
75
    a->setGlobalShortcut(KShortcut(Qt::META + Qt::Key_0));
 
76
 
 
77
    a = static_cast< KAction* >(actionCollection->addAction("MoveZoomLeft"));
 
78
    a->setIcon(KIcon("go-previous"));
 
79
    a->setText(i18n("Move Left"));
 
80
    a->setProperty("isConfigurationAction", true);
 
81
    a->setGlobalShortcut(KShortcut(Qt::META + Qt::Key_Left));
 
82
 
 
83
    a = static_cast< KAction* >(actionCollection->addAction("MoveZoomRight"));
 
84
    a->setIcon(KIcon("go-next"));
 
85
    a->setText(i18n("Move Right"));
 
86
    a->setProperty("isConfigurationAction", true);
 
87
    a->setGlobalShortcut(KShortcut(Qt::META + Qt::Key_Right));
 
88
 
 
89
    a = static_cast< KAction* >(actionCollection->addAction("MoveZoomUp"));
 
90
    a->setIcon(KIcon("go-up"));
 
91
    a->setText(i18n("Move Up"));
 
92
    a->setProperty("isConfigurationAction", true);
 
93
    a->setGlobalShortcut(KShortcut(Qt::META + Qt::Key_Up));
 
94
 
 
95
    a = static_cast< KAction* >(actionCollection->addAction("MoveZoomDown"));
 
96
    a->setIcon(KIcon("go-down"));
 
97
    a->setText(i18n("Move Down"));
 
98
    a->setProperty("isConfigurationAction", true);
 
99
    a->setGlobalShortcut(KShortcut(Qt::META + Qt::Key_Down));
 
100
 
 
101
    a = static_cast< KAction* >(actionCollection->addAction("MoveMouseToFocus"));
 
102
    a->setIcon(KIcon("view-restore"));
 
103
    a->setText(i18n("Move Mouse to Focus"));
 
104
    a->setProperty("isConfigurationAction", true);
 
105
    a->setGlobalShortcut(KShortcut(Qt::META + Qt::Key_F5));
 
106
 
 
107
    a = static_cast< KAction* >(actionCollection->addAction("MoveMouseToCenter"));
 
108
    a->setIcon(KIcon("view-restore"));
 
109
    a->setText(i18n("Move Mouse to Center"));
 
110
    a->setProperty("isConfigurationAction", true);
 
111
    a->setGlobalShortcut(KShortcut(Qt::META + Qt::Key_F6));
 
112
 
 
113
    m_ui->editor->addCollection(actionCollection);
 
114
    load();
 
115
}
 
116
 
 
117
ZoomEffectConfig::~ZoomEffectConfig()
 
118
{
 
119
    // Undo (only) unsaved changes to global key shortcuts
 
120
    m_ui->editor->undoChanges();
 
121
}
 
122
 
 
123
void ZoomEffectConfig::load()
 
124
{
 
125
    KCModule::load();
 
126
    KConfigGroup conf = EffectsHandler::effectConfig("Zoom");
 
127
    m_ui->zoomStepsSpinBox->setValue(conf.readEntry("ZoomFactor", 1.2));
 
128
    m_ui->mousePointerComboBox->setCurrentIndex(conf.readEntry("MousePointer", 0));
 
129
    m_ui->mouseTrackingComboBox->setCurrentIndex(conf.readEntry("MouseTracking", 0));
 
130
    m_ui->focusTrackingCheckBox->setChecked(conf.readEntry("EnableFocusTracking", false));
 
131
    m_ui->followFocusCheckBox->setChecked(conf.readEntry("EnableFollowFocus", true));
 
132
    emit changed(false);
 
133
}
 
134
 
 
135
void ZoomEffectConfig::save()
 
136
{
 
137
    //KCModule::save();
 
138
    KConfigGroup conf = EffectsHandler::effectConfig("Zoom");
 
139
    conf.writeEntry("ZoomFactor", m_ui->zoomStepsSpinBox->value());
 
140
    conf.writeEntry("MousePointer", m_ui->mousePointerComboBox->currentIndex());
 
141
    conf.writeEntry("MouseTracking", m_ui->mouseTrackingComboBox->currentIndex());
 
142
    conf.writeEntry("EnableFocusTracking", m_ui->focusTrackingCheckBox->isChecked());
 
143
    conf.writeEntry("EnableFollowFocus", m_ui->followFocusCheckBox->isChecked());
 
144
    m_ui->editor->save(); // undo() will restore to this state from now on
 
145
    conf.sync();
 
146
    emit changed(false);
 
147
    EffectsHandler::sendReloadMessage("zoom");
 
148
}
 
149
 
 
150
void ZoomEffectConfig::defaults()
 
151
{
 
152
    m_ui->zoomStepsSpinBox->setValue(1.25);
 
153
    m_ui->mousePointerComboBox->setCurrentIndex(0);
 
154
    m_ui->mouseTrackingComboBox->setCurrentIndex(0);
 
155
    m_ui->focusTrackingCheckBox->setChecked(false);
 
156
    m_ui->followFocusCheckBox->setChecked(true);
 
157
    m_ui->editor->allDefault();
 
158
    emit changed(true);
 
159
}
 
160
 
 
161
} // namespace
 
162
 
 
163
#include "zoom_config.moc"