summaryrefslogtreecommitdiffstats
path: root/client/config/config.cpp
blob: 482c1dfd183fb2890d80186b38ad1aa7e827c1f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
/*
	Copyright (C) 2006 Michael Lentner <michaell@gmx.net>
	
	based on KDE2 Default configuration widget:
	Copyright (c) 2001
		Karol Szwed <gallium@kde.org>
		http://gallium.n3.net/
	
	This library is free software; you can redistribute it and/or
	modify it under the terms of the GNU Library General Public
	License version 2 as published by the Free Software Foundation.
	
	This library is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
	Library General Public License for more details.
	
	You should have received a copy of the GNU General Public License
	along with this library; if not, write to the Free Software
	Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 */

#include "config.h"
#include <kglobal.h>
#include <klocale.h>
#include <tqvbox.h>
#include <tqlayout.h>
#include <tqlabel.h>
#include <tqgroupbox.h>
#include <tqsettings.h>

extern "C"
{
	KDE_EXPORT TQObject* allocate_config( KConfig* config, TQWidget* parent )
	{
		return(new DominoConfig(config, parent));
	}
}

// NOTE:
// 'config' is a pointer to the kwindecoration modules open kwin config,
//		  and is by default set to the "Style" group.
// 'parent' is the parent of the TQObject, which is a VBox inside the
//		  Configure tab in kwindecoration

DominoConfig::DominoConfig( KConfig* config, TQWidget* parent )
	: TQObject( parent )
{
	conf = new KConfig("kwindominorc");
	
	KGlobal::locale()->insertCatalogue("kwin_clients");
	
	vBox = new TQVBox( parent );

	customBorderColor = new TQCheckBox( i18n("Custom border color"), vBox );
	TQHBox *hbox1 = new TQHBox(vBox);
	hbox1->layout()->addItem(new TQSpacerItem(20, 0, TQSizePolicy::Fixed, TQSizePolicy::Minimum) );
	borderColor = new KColorButton(hbox1);
	
	customButtonColor = new TQCheckBox( i18n("Custom button color"), vBox );
	TQHBox *hbox2 = new TQHBox(vBox);
	hbox2->layout()->addItem(new TQSpacerItem(20, 0, TQSizePolicy::Fixed, TQSizePolicy::Minimum) );
	buttonColor = new KColorButton(hbox2);
	
	customButtonIconColor = new TQCheckBox( i18n("Custom button icon color"), vBox );
	TQHBox *hbox3 = new TQHBox(vBox);
	hbox3->layout()->addItem(new TQSpacerItem(20, 0, TQSizePolicy::Fixed, TQSizePolicy::Minimum) );
	buttonIconColor = new KColorButton(hbox3);
	
	customGradientColors = new TQCheckBox( i18n("Custom gradient colors"), vBox);
	TQHBox *hbox4 = new TQHBox(vBox);
	hbox4->layout()->addItem(new TQSpacerItem(22, 0, TQSizePolicy::Fixed, TQSizePolicy::Minimum) );
	
	TQVBox *vbox1 = new TQVBox(hbox4);
	new TQLabel( i18n("Top gradient color"), vbox1);
	topGradientColor = new KColorButton(vbox1);
	new TQLabel(i18n("Bottom gradient color"), vbox1);
	bottomGradientColor = new KColorButton(vbox1);
	
	showInactiveButtons = new TQCheckBox( i18n("Show inactive buttons"), vBox );
	showButtonIcons  = new TQCheckBox( i18n("Show button icons"), vBox );
	darkFrame  = new TQCheckBox( i18n("Dark window frame"), vBox );
	
	
	///////////////////////////////////////
	
	
	TQGroupBox* colorGb = new TQGroupBox(vBox);
	colorGb->setTitle(i18n("Button contour colors:"));
	colorGb->setColumnLayout(0, TQt::Vertical );
	colorGb->layout()->setSpacing( 6 );
	colorGb->layout()->setMargin( 11 );
	
	TQGridLayout* gbLayout = new TQGridLayout( colorGb->layout(), 4, 2 );
	gbLayout->setAlignment( TQt::AlignTop );
	
	TQLabel* labelSC = new TQLabel(i18n("Standard color:"), colorGb);
	buttonContourColor = new KColorButton(colorGb);
	buttonContourColor->setSizePolicy(TQSizePolicy::Expanding, TQSizePolicy::Minimum);
	TQLabel* labelMC = new TQLabel(i18n("Mouseover color:"), colorGb);
	buttonMouseOverContourColor = new KColorButton(colorGb);
	TQLabel* labelPC = new TQLabel(i18n("Pressed color:"), colorGb);
	buttonPressedContourColor = new KColorButton(colorGb);
	
	useDominoStyleContourColors = new TQCheckBox( i18n("Use domino style contour colors"), colorGb );
	gbLayout->addMultiCellWidget(useDominoStyleContourColors, 0, 0, 0, 1);
	
	gbLayout->addWidget(labelSC, 1, 0);
	gbLayout->addItem(new TQSpacerItem(20, 0, TQSizePolicy::Minimum, TQSizePolicy::Minimum) );
	gbLayout->addWidget(buttonContourColor, 1, 1);
	
	gbLayout->addWidget(labelMC, 2, 0);
	gbLayout->addItem(new TQSpacerItem(20, 0, TQSizePolicy::Minimum, TQSizePolicy::Minimum) );
	gbLayout->addWidget(buttonMouseOverContourColor, 2, 1);
	
	gbLayout->addWidget(labelPC, 3, 0);
	gbLayout->addItem(new TQSpacerItem(20, 0, TQSizePolicy::Minimum, TQSizePolicy::Minimum) );
	gbLayout->addWidget(buttonPressedContourColor, 3, 1);
	
	
	
	
	
	
	
	
	
	///////////////////////////////////////
	
	// Load configuration options
	load(config);

	// Ensure we track user changes properly
	connect(customGradientColors, SIGNAL(toggled(bool)), topGradientColor, SLOT(setEnabled(bool)));
	connect(customGradientColors, SIGNAL(toggled(bool)), bottomGradientColor, SLOT(setEnabled(bool)));
	
	connect(customBorderColor, SIGNAL(toggled(bool)), borderColor, SLOT(setEnabled(bool)));
	connect(customButtonColor, SIGNAL(toggled(bool)), buttonColor, SLOT(setEnabled(bool)));
	connect(customButtonIconColor, SIGNAL(toggled(bool)), buttonIconColor, SLOT(setEnabled(bool)));
	
	connect(customGradientColors, SIGNAL(clicked()), this, SLOT(slotSelectionChanged()));
	connect(topGradientColor, SIGNAL(changed(const TQColor&)), this, SLOT(slotSelectionChanged()));
	connect(bottomGradientColor, SIGNAL(changed(const TQColor&)), this, SLOT(slotSelectionChanged()));
	
	
	connect(customBorderColor, SIGNAL(clicked()), this, SLOT(slotSelectionChanged()));
	connect(borderColor, SIGNAL(changed(const TQColor&)), this, SLOT(slotSelectionChanged()));
	
	connect(customButtonColor, SIGNAL(clicked()), this, SLOT(slotSelectionChanged()));
	connect(buttonColor, SIGNAL(changed(const TQColor&)), this, SLOT(slotSelectionChanged()));
	connect(customButtonIconColor, SIGNAL(clicked()), this, SLOT(slotSelectionChanged()));
	connect(buttonIconColor, SIGNAL(changed(const TQColor&)), this, SLOT(slotSelectionChanged()));
	
	connect(showInactiveButtons, SIGNAL(clicked()), this, SLOT(slotSelectionChanged()));
	connect(showButtonIcons, SIGNAL(clicked()), this, SLOT(slotSelectionChanged()));
	connect(darkFrame, SIGNAL(clicked()), this, SLOT(slotSelectionChanged()));
	
	connect(useDominoStyleContourColors, SIGNAL(clicked()), this, SLOT(loadButtonContourColors()));
	connect(useDominoStyleContourColors, SIGNAL(clicked()), this, SLOT(slotSelectionChanged()));
	connect(buttonContourColor, SIGNAL(changed(const TQColor&)), this, SLOT(slotSelectionChanged()));
	connect(buttonMouseOverContourColor, SIGNAL(changed(const TQColor&)), this, SLOT(slotSelectionChanged()));
	connect(buttonPressedContourColor, SIGNAL(changed(const TQColor&)), this, SLOT(slotSelectionChanged()));
	
	
	// Make the widgets visible in kwindecoration valueChanged
	vBox->show();
}


DominoConfig::~DominoConfig()
{
	delete vBox;
	delete conf;
}


void DominoConfig::slotSelectionChanged()
{
	emit changed();
}


// Loads the configurable options from the kwinrc config file
// It is passed the open config from kwindecoration to improve efficiency
void DominoConfig::load(KConfig*)
{
	conf->setGroup("General");
	
	customBorderColor->setChecked(conf->readBoolEntry("customBorderColor", true));
	borderColor->setEnabled(customBorderColor->isChecked());
	borderColor->setColor(conf->readEntry("borderColor", "#777B7F"));
	customButtonColor->setChecked(conf->readBoolEntry( "customButtonColor", false));
	buttonColor->setEnabled(customButtonColor->isChecked());
	buttonColor->setColor(conf->readEntry("buttonColor", "#212121"));
	customButtonIconColor->setChecked(conf->readBoolEntry( "customButtonIconColor", false));
	buttonIconColor->setEnabled(customButtonIconColor->isChecked());
	buttonIconColor->setColor(conf->readEntry("buttonIconColor", "#000000"));
	
	customGradientColors->setChecked(conf->readBoolEntry( "customGradientColors", false));
	topGradientColor->setEnabled(customGradientColors->isChecked());
	bottomGradientColor->setEnabled(customGradientColors->isChecked());
	topGradientColor->setColor(conf->readEntry("topGradientColor", "#ffffff"));
	bottomGradientColor->setColor(conf->readEntry("bottomGradientColor", "#000000"));
	
	showInactiveButtons->setChecked(conf->readBoolEntry("showInactiveButtons", false));
	showButtonIcons->setChecked(conf->readBoolEntry("showButtonIcons", false));
	darkFrame->setChecked(conf->readBoolEntry("darkFrame", false));
	
	useDominoStyleContourColors->setChecked(conf->readBoolEntry("useDominoStyleContourColors", true));
	
	loadButtonContourColors();
	
}


// Saves the configurable options to the kwinrc config file
void DominoConfig::save(KConfig*)
{
	conf->setGroup("General");
	
	conf->writeEntry("customBorderColor", customBorderColor->isChecked());
	conf->writeEntry("borderColor", borderColor->color().name());
	conf->writeEntry("customButtonColor", customButtonColor->isChecked());
	conf->writeEntry("buttonColor", buttonColor->color().name());
	conf->writeEntry("customButtonIconColor", customButtonIconColor->isChecked());
	conf->writeEntry("buttonIconColor", buttonIconColor->color().name());
	conf->writeEntry("showInactiveButtons", showInactiveButtons->isChecked());
	conf->writeEntry("showButtonIcons", showButtonIcons->isChecked());
	
	conf->writeEntry("customGradientColors", customGradientColors->isChecked());
	conf->writeEntry("topGradientColor", topGradientColor->color().name());
	conf->writeEntry("bottomGradientColor", bottomGradientColor->color().name());
	conf->writeEntry("darkFrame", darkFrame->isChecked());
	
	conf->writeEntry("useDominoStyleContourColors", useDominoStyleContourColors->isChecked());
	conf->writeEntry("buttonContourColor", buttonContourColor->color().name());
	conf->writeEntry("buttonMouseOverContourColor", buttonMouseOverContourColor->color().name());
	conf->writeEntry("buttonPressedContourColor", buttonPressedContourColor->color().name());
	
	conf->sync();
}


// Sets UI widget defaults which must correspond to style defaults
void DominoConfig::defaults()
{
	
	TQColor background = vBox->paletteBackgroundColor();
	
	customBorderColor->setChecked(true);
	borderColor->setColor("#777B7F");
	customButtonColor->setChecked(false);
	buttonColor->setColor("#212121");
	customButtonIconColor->setChecked(false);
	buttonIconColor->setColor("#000000");
	showInactiveButtons->setChecked(false);
	showButtonIcons->setChecked(false);
	customGradientColors->setChecked(false);
	topGradientColor->setColor("#ffffff");
	bottomGradientColor->setColor("#000000");
	darkFrame->setChecked(false);
	
	useDominoStyleContourColors->setChecked(true);
	buttonContourColor->setColor(background.dark(250).name());
	buttonMouseOverContourColor->setColor(background.dark(250).name());
	buttonPressedContourColor->setColor(background.dark(250).name());
	
}

void DominoConfig::loadButtonContourColors() {
	
	TQColor background = vBox->paletteBackgroundColor();
	if(useDominoStyleContourColors->isChecked()) {
		TQSettings s;
		buttonContourColor->setColor(s.readEntry("/domino/Settings/buttonContourColor", background.dark(250).name()));
		buttonMouseOverContourColor->setColor(s.readEntry("/domino/Settings/buttonMouseOverContourColor", background.dark(250).name()));
		buttonPressedContourColor->setColor(s.readEntry("/domino/Settings/buttonPressedContourColor", background.dark(250).name()));
	}
	else {
		buttonContourColor->setColor(conf->readEntry("buttonContourColor", background.dark(250).name()));
		buttonMouseOverContourColor->setColor(conf->readEntry("buttonMouseOverContourColor", background.dark(250).name()));
		buttonPressedContourColor->setColor(conf->readEntry("buttonPressedContourColor", background.dark(250).name()));
	}
	
}

#include "config.moc"