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

« back to all changes in this revision

Viewing changes to kwin/clients/b2/config/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
        This file contains the B2 configuration widget
 
3
 
 
4
        Copyright (c) 2001
 
5
                Karol Szwed <gallium@kde.org>
 
6
                http://gallium.n3.net/
 
7
        Copyright (c) 2007
 
8
                Luciano Montanaro <mikelima@cirulla.net>
 
9
        Automove titlebar bits Copyright (c) 2009 Jussi Kekkonen <tmt@ubuntu.com>
 
10
 
 
11
This program is free software; you can redistribute it and/or modify
 
12
it under the terms of the GNU General Public License as published by
 
13
the Free Software Foundation; either version 2 of the License, or
 
14
(at your option) any later version.
 
15
 
 
16
This program is distributed in the hope that it will be useful,
 
17
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
18
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
19
GNU General Public License for more details.
 
20
 
 
21
You should have received a copy of the GNU General Public License
 
22
along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
23
*********************************************************************/
 
24
 
 
25
#include "config.h" 
 
26
#include <kglobal.h>
 
27
#include <kconfiggroup.h>
 
28
 
 
29
//Added by qt3to4:
 
30
#include <QLabel>
 
31
#include <QGridLayout>
 
32
#include <QSpacerItem>
 
33
#include <klocale.h>
 
34
#include <kvbox.h>
 
35
 
 
36
 
 
37
extern "C" KDE_EXPORT QObject *allocate_config(KConfig *conf, QWidget *parent)
 
38
{
 
39
    return(new B2Config(conf, parent));
 
40
}
 
41
 
 
42
/* NOTE:
 
43
 * 'conf'       is a pointer to the kwindecoration modules open kwin config,
 
44
 *                      and is by default set to the "Style" group.
 
45
 *
 
46
 * 'parent'     is the parent of the QObject, which is a VBox inside the
 
47
 *                      Configure tab in kwindecoration
 
48
 */
 
49
 
 
50
B2Config::B2Config(KConfig *conf, QWidget *parent)
 
51
        : QObject(parent)
 
52
{
 
53
    Q_UNUSED( conf );
 
54
    KGlobal::locale()->insertCatalog("kwin_b2_config");
 
55
    b2Config = new KConfig("kwinb2rc");
 
56
    gb = new KVBox(parent);
 
57
 
 
58
    cbColorBorder = new QCheckBox(
 
59
            i18n("Draw window frames using &titlebar colors"), gb);
 
60
    cbColorBorder->setWhatsThis(
 
61
            i18n("When selected, the window borders "
 
62
                "are drawn using the titlebar colors; otherwise, they are "
 
63
                "drawn using normal border colors."));
 
64
 
 
65
    // Grab Handle
 
66
    showGrabHandleCb = new QCheckBox(
 
67
            i18n("Draw &resize handle"), gb);
 
68
    showGrabHandleCb->setWhatsThis(
 
69
            i18n("When selected, decorations are drawn with a \"grab handle\" "
 
70
                "in the bottom right corner of the windows; "
 
71
                "otherwise, no grab handle is drawn."));
 
72
                
 
73
        // Automove Titlebar
 
74
        autoMoveTitlebarCb = new QCheckBox(
 
75
                i18n("Auto-move titlebar"), gb);
 
76
        autoMoveTitlebarCb->setWhatsThis(
 
77
                i18n("When selected, titlebars are automatically relocated "
 
78
                 "to visible positions; "
 
79
                 "otherwise, they are only moved manually using shift+drag."));
 
80
 
 
81
    // Double click menu option support
 
82
    actionsGB = new QGroupBox(i18n("Actions Settings"), gb);
 
83
    //actionsGB->setOrientation(Qt::Horizontal);
 
84
    QLabel *menuDblClickLabel = new QLabel(actionsGB);
 
85
    menuDblClickLabel->setText(i18n("Double click on menu button:"));
 
86
    menuDblClickOp = new KComboBox(actionsGB);
 
87
    menuDblClickOp->addItem(i18n("Do Nothing"));
 
88
    menuDblClickOp->addItem(i18n("Minimize Window"));
 
89
    menuDblClickOp->addItem(i18n("Shade Window"));
 
90
    menuDblClickOp->addItem(i18n("Close Window"));
 
91
 
 
92
    menuDblClickOp->setWhatsThis(
 
93
            i18n("An action can be associated to a double click "
 
94
                "of the menu button. Leave it to none if in doubt."));
 
95
 
 
96
    QGridLayout *actionsLayout = new QGridLayout();
 
97
    QSpacerItem *actionsSpacer = new QSpacerItem(8, 8, 
 
98
            QSizePolicy::Expanding, QSizePolicy::Fixed);
 
99
    actionsLayout->addWidget(menuDblClickLabel, 0, 0, Qt::AlignRight);
 
100
    actionsLayout->addWidget(menuDblClickOp, 0, 1);
 
101
    actionsLayout->addItem(actionsSpacer, 0, 2);
 
102
    actionsGB->setLayout(actionsLayout);
 
103
    // Load configuration options
 
104
    KConfigGroup cg(b2Config, "General");
 
105
    load(cg);
 
106
 
 
107
    // Ensure we track user changes properly
 
108
    connect(cbColorBorder, SIGNAL(clicked()),
 
109
            this, SLOT(slotSelectionChanged()));
 
110
    connect(showGrabHandleCb, SIGNAL(clicked()),
 
111
            this, SLOT(slotSelectionChanged()));
 
112
        connect(autoMoveTitlebarCb, SIGNAL(clicked()),
 
113
                this, SLOT(slotSelectionChanged()));
 
114
    connect(menuDblClickOp, SIGNAL(activated(int)),
 
115
            this, SLOT(slotSelectionChanged()));
 
116
    // Make the widgets visible in kwindecoration
 
117
    gb->show();
 
118
}
 
119
 
 
120
B2Config::~B2Config()
 
121
{
 
122
    delete b2Config;
 
123
    delete gb;
 
124
}
 
125
 
 
126
void B2Config::slotSelectionChanged()
 
127
{
 
128
    emit changed();
 
129
}
 
130
 
 
131
// Loads the configurable options from the kwinrc config file
 
132
// It is passed the open config from kwindecoration to improve efficiency
 
133
void B2Config::load(const KConfigGroup & /*conf*/)
 
134
{
 
135
    KConfigGroup cg(b2Config, "General");
 
136
 
 
137
    bool override = cg.readEntry("UseTitleBarBorderColors", false);
 
138
    cbColorBorder->setChecked(override);
 
139
 
 
140
    override = cg.readEntry("DrawGrabHandle", true);
 
141
    showGrabHandleCb->setChecked(override);
 
142
 
 
143
        override = cg.readEntry( "AutoMoveTitleBar", true );
 
144
        autoMoveTitlebarCb->setChecked(override);
 
145
 
 
146
    QString returnString = cg.readEntry(
 
147
            "MenuButtonDoubleClickOperation", "NoOp");
 
148
 
 
149
    int op;
 
150
    if (returnString == "Close") {
 
151
        op = 3;
 
152
    } else if (returnString == "Shade") {
 
153
        op = 2;
 
154
    } else if (returnString == "Minimize") {
 
155
        op = 1;
 
156
    } else {
 
157
        op = 0;
 
158
    }
 
159
 
 
160
    menuDblClickOp->setCurrentIndex(op);
 
161
}
 
162
 
 
163
static QString opToString(int op)
 
164
{
 
165
    switch (op) {
 
166
    case 1:
 
167
        return "Minimize";
 
168
    case 2:
 
169
        return "Shade";
 
170
    case 3:
 
171
        return "Close";
 
172
    case 0:
 
173
    default:
 
174
        return "NoOp";
 
175
    }
 
176
}
 
177
 
 
178
// Saves the configurable options to the kwinrc config file
 
179
void B2Config::save(KConfigGroup & /*conf*/)
 
180
{
 
181
    KConfigGroup cg(b2Config, "General");
 
182
    cg.writeEntry("UseTitleBarBorderColors", cbColorBorder->isChecked());
 
183
    cg.writeEntry("DrawGrabHandle", showGrabHandleCb->isChecked());
 
184
    cg.writeEntry("AutoMoveTitleBar", autoMoveTitlebarCb->isChecked());
 
185
    cg.writeEntry("MenuButtonDoubleClickOperation", 
 
186
            opToString(menuDblClickOp->currentIndex()));
 
187
    // Ensure others trying to read this config get updated
 
188
    b2Config->sync();
 
189
}
 
190
 
 
191
// Sets UI widget defaults which must correspond to style defaults
 
192
void B2Config::defaults()
 
193
{
 
194
    cbColorBorder->setChecked(false);
 
195
    showGrabHandleCb->setChecked(true);
 
196
    autoMoveTitlebarCb->setChecked(true);
 
197
    menuDblClickOp->setCurrentIndex(0);
 
198
}
 
199
 
 
200
#include "config.moc"
 
201
// vi: sw=4 ts=8