not quite so much needs to be delayed to the init() function
[personal-kdebase.git] / workspace / kwin / clients / b2 / config / config.cpp
blobadd63d6375bffe5ac8a4d1e17787a4642831f1d8
1 /********************************************************************
2 This file contains the B2 configuration widget
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>
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 *********************************************************************/
24 #include "config.h"
25 #include <kglobal.h>
26 #include <kconfiggroup.h>
28 //Added by qt3to4:
29 #include <QLabel>
30 #include <QGridLayout>
31 #include <QSpacerItem>
32 #include <klocale.h>
33 #include <kvbox.h>
36 extern "C" KDE_EXPORT QObject *allocate_config(KConfig *conf, QWidget *parent)
38 return(new B2Config(conf, parent));
41 /* NOTE:
42 * 'conf' is a pointer to the kwindecoration modules open kwin config,
43 * and is by default set to the "Style" group.
45 * 'parent' is the parent of the QObject, which is a VBox inside the
46 * Configure tab in kwindecoration
49 B2Config::B2Config(KConfig *conf, QWidget *parent)
50 : QObject(parent)
52 KGlobal::locale()->insertCatalog("kwin_b2_config");
53 b2Config = new KConfig("kwinb2rc");
54 gb = new KVBox(parent);
56 cbColorBorder = new QCheckBox(
57 i18n("Draw window frames using &titlebar colors"), gb);
58 cbColorBorder->setWhatsThis(
59 i18n("When selected, the window borders "
60 "are drawn using the titlebar colors; otherwise, they are "
61 "drawn using normal border colors."));
63 // Grab Handle
64 showGrabHandleCb = new QCheckBox(
65 i18n("Draw &resize handle"), gb);
66 showGrabHandleCb->setWhatsThis(
67 i18n("When selected, decorations are drawn with a \"grab handle\" "
68 "in the bottom right corner of the windows; "
69 "otherwise, no grab handle is drawn."));
71 // Double click menu option support
72 actionsGB = new QGroupBox(i18n("Actions Settings"), gb);
73 //actionsGB->setOrientation(Qt::Horizontal);
74 QLabel *menuDblClickLabel = new QLabel(actionsGB);
75 menuDblClickLabel->setText(i18n("Double click on menu button:"));
76 menuDblClickOp = new QComboBox(actionsGB);
77 menuDblClickOp->addItem(i18n("Do Nothing"));
78 menuDblClickOp->addItem(i18n("Minimize Window"));
79 menuDblClickOp->addItem(i18n("Shade Window"));
80 menuDblClickOp->addItem(i18n("Close Window"));
82 menuDblClickOp->setWhatsThis(
83 i18n("An action can be associated to a double click "
84 "of the menu button. Leave it to none if in doubt."));
86 QGridLayout *actionsLayout = new QGridLayout();
87 QSpacerItem *actionsSpacer = new QSpacerItem(8, 8,
88 QSizePolicy::Expanding, QSizePolicy::Fixed);
89 actionsLayout->addWidget(menuDblClickLabel, 0, 0, Qt::AlignRight);
90 actionsLayout->addWidget(menuDblClickOp, 0, 1);
91 actionsLayout->addItem(actionsSpacer, 0, 2);
92 actionsGB->setLayout(actionsLayout);
93 // Load configuration options
94 KConfigGroup cg(b2Config, "General");
95 load(cg);
97 // Ensure we track user changes properly
98 connect(cbColorBorder, SIGNAL(clicked()),
99 this, SLOT(slotSelectionChanged()));
100 connect(showGrabHandleCb, SIGNAL(clicked()),
101 this, SLOT(slotSelectionChanged()));
102 connect(menuDblClickOp, SIGNAL(activated(int)),
103 this, SLOT(slotSelectionChanged()));
104 // Make the widgets visible in kwindecoration
105 gb->show();
108 B2Config::~B2Config()
110 delete b2Config;
111 delete gb;
114 void B2Config::slotSelectionChanged()
116 emit changed();
119 // Loads the configurable options from the kwinrc config file
120 // It is passed the open config from kwindecoration to improve efficiency
121 void B2Config::load(const KConfigGroup & /*conf*/)
123 KConfigGroup cg(b2Config, "General");
125 bool override = cg.readEntry("UseTitleBarBorderColors", false);
126 cbColorBorder->setChecked(override);
128 override = cg.readEntry("DrawGrabHandle", true);
129 showGrabHandleCb->setChecked(override);
131 QString returnString = cg.readEntry(
132 "MenuButtonDoubleClickOperation", "NoOp");
134 int op;
135 if (returnString == "Close") {
136 op = 3;
137 } else if (returnString == "Shade") {
138 op = 2;
139 } else if (returnString == "Minimize") {
140 op = 1;
141 } else {
142 op = 0;
145 menuDblClickOp->setCurrentIndex(op);
148 static QString opToString(int op)
150 switch (op) {
151 case 1:
152 return "Minimize";
153 case 2:
154 return "Shade";
155 case 3:
156 return "Close";
157 case 0:
158 default:
159 return "NoOp";
163 // Saves the configurable options to the kwinrc config file
164 void B2Config::save(KConfigGroup & /*conf*/)
166 KConfigGroup cg(b2Config, "General");
167 cg.writeEntry("UseTitleBarBorderColors", cbColorBorder->isChecked());
168 cg.writeEntry("DrawGrabHandle", showGrabHandleCb->isChecked());
169 cg.writeEntry("MenuButtonDoubleClickOperation",
170 opToString(menuDblClickOp->currentIndex()));
171 // Ensure others trying to read this config get updated
172 b2Config->sync();
175 // Sets UI widget defaults which must correspond to style defaults
176 void B2Config::defaults()
178 cbColorBorder->setChecked(false);
179 showGrabHandleCb->setChecked(true);
180 menuDblClickOp->setCurrentIndex(0);
183 #include "config.moc"
184 // vi: sw=4 ts=8