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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
|
/* SuSE KWin window decoration
Copyright (C) 2005 Gerd Fleischer <[email protected]>
Copyright (C) 2005 Adrian Schroeter <[email protected]>
based on the window decoration "Plastik" and "Web":
Copyright (C) 2003 Sandro Giessl <[email protected]>
Copyright (C) 2001 Rik Hemsley (rikkus) <[email protected]>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This program 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
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
Boston, MA 02110-1301 USA.
*/
//#include <kdebug.h>
#include <qpainter.h>
#include <qbitmap.h>
#include <kconfig.h>
#include <klocale.h>
#include <kglobal.h>
#include <kstandarddirs.h>
#include <kpixmap.h>
#include "misc.h"
#include "shadow.h"
#include "SUSE2.h"
#include "SUSE2.moc"
#include "SUSE2client.h"
#include "SUSE2button.h"
namespace KWinSUSE2
{
SUSE2Handler::SUSE2Handler()
{
memset(m_pixmaps, 0, sizeof(QPixmap *) * NumButtonStatus * NumButtonIcons); // set elements to 0
KGlobal::locale()->insertCatalogue("kwin_clients");
KGlobal::locale()->insertCatalogue("kwin_SUSE2");
reset(0);
}
SUSE2Handler::~SUSE2Handler()
{
for (int t = 0; t < NumButtonStatus; ++t)
for (int i = 0; i < NumButtonIcons; ++i)
delete m_pixmaps[t][i];
}
bool SUSE2Handler::reset(unsigned long /*changed*/)
{
// we assume the active font to be the same as the inactive font since the control
// center doesn't offer different settings anyways.
m_titleFont = KDecoration::options()->font(true, false); // not small
m_titleFontTool = KDecoration::options()->font(true, true); // small
switch(KDecoration::options()->preferredBorderSize( this )) {
case BorderTiny:
m_borderSize = 3;
break;
case BorderLarge:
m_borderSize = 8;
break;
case BorderVeryLarge:
m_borderSize = 12;
break;
case BorderHuge:
m_borderSize = 18;
break;
case BorderVeryHuge:
m_borderSize = 27;
break;
case BorderOversized:
m_borderSize = 40;
break;
case BorderNormal:
default:
m_borderSize = 4;
}
// check if we are in reverse layout mode
m_reverse = QApplication::reverseLayout();
// read in the configuration
readConfig();
for (int t = 0; t < NumButtonStatus; ++t) {
for (int i = 0; i < NumButtonIcons; ++i) {
if (m_pixmaps[t][i]) {
delete m_pixmaps[t][i];
m_pixmaps[t][i] = 0;
}
}
}
/// I dont want to do smart things here
/// just for cases that do not happen very often.
return true;
}
KDecoration* SUSE2Handler::createDecoration( KDecorationBridge* bridge )
{
return new SUSE2Client( bridge, this );
}
bool SUSE2Handler::supports( Ability ability ) const
{
switch( ability )
{
case AbilityAnnounceButtons:
case AbilityButtonMenu:
case AbilityButtonOnAllDesktops:
case AbilityButtonSpacer:
case AbilityButtonHelp:
case AbilityButtonMinimize:
case AbilityButtonMaximize:
case AbilityButtonClose:
case AbilityButtonAboveOthers:
case AbilityButtonBelowOthers:
case AbilityButtonShade:
return true;
default:
return false;
};
}
void SUSE2Handler::readConfig()
{
// create a config object
KConfig config("kwinSUSE2rc");
config.setGroup("General");
// grab settings
QString alignValue = config.readEntry("TitleAlignment", "AlignLeft");
if (alignValue == "AlignLeft") m_titleAlign = Qt::AlignLeft;
else if (alignValue == "AlignHCenter") m_titleAlign = Qt::AlignHCenter;
else if (alignValue == "AlignRight") m_titleAlign = Qt::AlignRight;
QString roundValue = config.readEntry("RoundCorners", "NotMaximized");
if (roundValue == "RoundAlways") m_roundCorners = 1;
else if (roundValue == "NotMaximized") m_roundCorners = 2;
else if (roundValue == "RoundNever") m_roundCorners = 3;
m_menuClose = config.readBoolEntry("CloseOnMenuDoubleClick", true);
m_titleShadow = config.readBoolEntry("TitleShadow", true);
QFontMetrics fm(m_titleFont); // active font = inactive font
int addSpace = config.readNumEntry("AddSpace", 4);
// The title should stretch with bigger font sizes!
m_titleHeight = QMAX(16, fm.height() + addSpace);
fm = QFontMetrics(m_titleFontTool); // active font = inactive font
m_titleHeightTool = QMAX(13, fm.height() ); // don't care about the shadow etc.
m_titlebarStyle = config.readNumEntry("TitleBarStyle", 0);
m_buttonType = config.readNumEntry("TitleBarButtonType", 0);
m_customColors = config.readBoolEntry("CustomColors", false);
m_useTitleProps = config.readBoolEntry("UseTitleProps", false);
m_animateButtons = config.readBoolEntry("AnimateButtons", true);
m_redCloseButton = config.readBoolEntry("RedCloseButton", false);
m_iconSize = (config.readNumEntry("IconSize", 45))/100.0;
m_customIconColors = config.readBoolEntry("CustomIconColors", false);
QColor afgcolor = QColor(10, 20, 40);
m_aFgColor = config.readColorEntry("AFgColor", &afgcolor);
QColor abgcolor = QColor(210, 220, 240);
m_aBgColor = config.readColorEntry("ABgColor", &abgcolor);
QColor ifgcolor = QColor(40, 40, 40);
m_iFgColor = config.readColorEntry("IFgColor", &ifgcolor);
QColor ibgcolor = QColor(240, 240, 240);
m_iBgColor = config.readColorEntry("IBgColor", &ibgcolor);
m_iconShadow = config.readBoolEntry("IconShadow", false);
m_titleLogo = config.readBoolEntry("TitleBarLogo", true);
m_titleLogoOffset = config.readNumEntry("TitleBarLogoOffset", 3);
m_titleLogoURL = config.readEntry("TitleBarLogoURL", locate("data", "kwin/pics/titlebar_decor.png"));
}
QColor SUSE2Handler::getColor(KWinSUSE2::ColorType type, const bool active) const
{
switch (type) {
case TitleGradientFrom:
return KDecoration::options()->color(ColorTitleBar, active);
break;
case TitleGradientTo:
return KDecoration::options()->color(ColorTitleBlend, active);
break;
case WindowContour:
case Border:
return KDecoration::options()->color(ColorFrame, active);
break;
case TitleFont:
return KDecoration::options()->color(ColorFont, active);
break;
case BtnBg:
return KDecoration::options()->color(ColorButtonBg, active);
break;
default:
return Qt::black;
}
}
const KPixmap &SUSE2Handler::buttonPixmap(ButtonIcon type, int size, ButtonStatus status)
{
if (m_pixmaps[status][type]) {
if (status != Shadow && m_pixmaps[status][type]->size() == QSize(size, size))
return *m_pixmaps[status][type];
else if (status == Shadow && m_pixmaps[status][type]->size() == QSize(size+4, size+4))
return *m_pixmaps[status][type];
}
// no matching pixmap found, create a new one...
delete m_pixmaps[status][type];
m_pixmaps[status][type] = 0;
QColor aDecoFgDark = alphaBlendColors(getColor(TitleGradientTo, true), Qt::black, 50);
QColor aDecoFgLight = alphaBlendColors(getColor(TitleGradientTo, true), Qt::white, 50);
QColor iDecoFgDark = alphaBlendColors(getColor(TitleGradientTo, false), Qt::black, 50);
QColor iDecoFgLight = alphaBlendColors(getColor(TitleGradientTo, false), Qt::white, 50);
if (m_customIconColors && !m_useTitleProps) {
aDecoFgDark = m_aFgColor;
aDecoFgLight = m_aBgColor;
iDecoFgDark = m_iFgColor;
iDecoFgLight = m_iBgColor;
}
KPixmap icon = IconEngine::icon(type, size);
QImage img = icon.convertToImage();
KPixmap *pixmap;
QImage tmpImage;
ShadowEngine se;
QPainter painter;
KPixmap tmpShadow;
switch (status) {
case ActiveUp:
if (m_useTitleProps)
tmpImage = recolorImage(&img, getColor(TitleFont, true));
else
tmpImage = recolorImage(&img, aDecoFgDark);
pixmap = new KPixmap(tmpImage);
break;
case ActiveDown:
if (m_useTitleProps)
tmpImage = recolorImage(&img, getColor(TitleFont, true));
else
tmpImage = recolorImage(&img, aDecoFgLight);
pixmap = new KPixmap(tmpImage);
break;
case InactiveUp:
if (m_useTitleProps)
tmpImage = recolorImage(&img, getColor(TitleFont, false));
else
tmpImage = recolorImage(&img, iDecoFgDark);
pixmap = new KPixmap(tmpImage);
break;
case InactiveDown:
if (m_useTitleProps)
tmpImage = recolorImage(&img, getColor(TitleFont, false));
else
tmpImage = recolorImage(&img, iDecoFgLight);
pixmap = new KPixmap(tmpImage);
break;
case Shadow:
// prepare shadow
tmpShadow = QPixmap(icon.width()+4, icon.height()+4);
tmpShadow.fill(QColor(0,0,0));
tmpShadow.setMask(tmpShadow.createHeuristicMask(true));
painter.begin(&tmpShadow);
painter.setPen(white);
painter.drawPixmap(0,0, icon);
painter.end();
tmpImage = se.makeShadow(tmpShadow, QColor(0, 0, 0));
pixmap = new KPixmap(tmpImage);
break;
default:
pixmap = new KPixmap();
}
m_pixmaps[status][type] = pixmap;
return *pixmap;
}
QValueList< SUSE2Handler::BorderSize >
SUSE2Handler::borderSizes() const
{
// the list must be sorted
return QValueList< BorderSize >() << BorderTiny << BorderNormal <<
BorderLarge << BorderVeryLarge << BorderHuge <<
BorderVeryHuge << BorderOversized;
}
static SUSE2Handler *handler = 0;
SUSE2Handler *Handler()
{
return handler;
}
} // KWinSUSE2
//////////////////////////////////////////////////////////////////////////////
// Plugin Stuff //
//////////////////////////////////////////////////////////////////////////////
extern "C"
{
KDE_EXPORT KDecorationFactory *create_factory()
{
KWinSUSE2::handler = new KWinSUSE2::SUSE2Handler();
return KWinSUSE2::handler;
}
}
// kate: space-indent on; indent-width 4; replace-tabs on;
|