5 Rik Hemsley <rik@kde.org>
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA.
31 #include <q3ptrlist.h>
32 #include <kcommondecoration.h>
33 #include <kdecoration.h>
35 // #include <ksimpleconfig.h>
43 static const char * const texture_xpm
[] = {
48 " b b b b b b b a b ",
49 " b aa b aaa aaa b a b aab bb a ",
50 " b b a b b b b aa b b aa ",
51 " b b b a a b b b b aa ab ab ",
53 " aaa aaa aa b b b b b b ",
54 " b b bb a b aa b a a aaa a b ",
55 " b b b b b a b b b b b",
56 " b b b b a a b b aa b baa ",
57 " a b a bb aa bb aa aaa b aa a ",
58 " a a aab b b aa aab a b ",
59 " b a b b aaa a b bb b b b b"};
61 Static
* Static::instance_
= NULL
;
74 const QPixmap
& Static::titleTextLeft(bool active
) const
76 return active
? aTitleTextLeft_
: iTitleTextLeft_
;
79 const QPixmap
& Static::titleTextRight(bool active
) const
81 return active
? aTitleTextRight_
: iTitleTextRight_
;
84 const QPixmap
& Static::resizeMidLeft(bool active
) const
86 return active
? aResizeMidLeft_
: iResizeMidLeft_
;
89 const QPixmap
& Static::resizeMidRight(bool active
) const
91 return active
? aResizeMidRight_
: iResizeMidRight_
;
94 const QPixmap
& Static::titleTextMid(bool active
) const
96 return active
? aTitleTextMid_
: iTitleTextMid_
;
99 const QPixmap
& Static::resizeMidMid(bool active
) const
101 return active
? aResizeMid_
: iResizeMid_
;
104 const QPixmap
& Static::resize(bool active
) const
106 return active
? aResize_
: iResize_
;
109 int Static::animationStyle() const
111 return animationStyle_
;
114 int Static::titleHeight() const
119 int Static::resizeHeight() const
121 return resizeHeight_
;
124 void Static::_drawBorder(QPixmap
&pix
, int w
, int h
)
134 painter_
.begin(&pix
);
135 painter_
.translate(transx
, transy
);
137 QColor c0
= down_
? palette_
[7] : palette_
[0];
138 QColor c1
= down_
? palette_
[6] : palette_
[1];
139 QColor c2
= down_
? palette_
[5] : palette_
[2];
140 QColor c3
= down_
? palette_
[4] : palette_
[3];
141 QColor c4
= down_
? palette_
[3] : palette_
[4];
142 QColor c5
= down_
? palette_
[2] : palette_
[5];
143 QColor c6
= down_
? palette_
[2] : palette_
[6];
144 QColor c7
= down_
? palette_
[1] : palette_
[7];
147 painter_
.drawPoint(0, 0);
150 painter_
.drawPoint(1, 1);
151 painter_
.drawLine(1, 0, w
- 1, 0);
152 painter_
.drawLine(0, 1, 0, h
- 1);
155 painter_
.drawLine(2, 1, w
- 2, 1);
156 painter_
.drawLine(1, 2, 1, h
- 2);
159 painter_
.drawPoint(0, h
);
160 painter_
.drawPoint(1, h
- 1);
161 painter_
.drawPoint(w
, 0);
162 painter_
.drawPoint(w
- 1, 1);
163 painter_
.fillRect(2, 2, w
- 2, h
- 2, c3
);
166 painter_
.drawLine(2, h
- 1, w
- 2, h
- 1);
167 painter_
.drawLine(w
- 1, 2, w
- 1, h
- 2);
170 painter_
.drawPoint(w
, 1);
171 painter_
.drawPoint(1, h
);
174 painter_
.drawLine(w
, 2, w
, h
- 1);
175 painter_
.drawLine(2, h
, w
- 1, h
);
178 painter_
.drawPoint(w
- 1, h
- 1);
179 painter_
.drawPoint(w
, h
);
183 painter_
.resetXForm();
186 void setPalette(Palette
&pal
, QColor c
)
196 pal
[0] = c
.light(200).rgb();
197 pal
[1] = c
.light(166).rgb();
198 pal
[2] = c
.light(125).rgb();
199 pal
[4] = c
.dark(133).rgb();
200 pal
[5] = c
.dark(166).rgb();
201 pal
[6] = c
.dark(200).rgb();
202 pal
[7] = c
.dark(300).rgb();
207 hicolour_
= QPixmap::defaultDepth() > 8;
215 // Workspace::self()->slotResetAllClientsDelayed();
218 void Static::updatePixmaps()
232 _drawTitleTextAreaSides();
234 _drawResizeCentralAreaSides();
236 _drawTitleTextAreaBackground();
238 _drawResizeCentralAreaBackground();
240 _drawResizeHandles();
242 _drawButtonBackgrounds();
245 void Static::_createTexture(QPixmap
&px
, int t
, bool active
)
247 const QImage
texture(QPixmap((const char **)texture_xpm
).convertToImage());
248 const QRgb
w(qRgb(255, 255, 255));
249 const QRgb
b(qRgb(0, 0, 0));
251 QColor
c(KDecoration::options()->color(KDecoration::ColorType(t
), active
));
254 QRgb
light (c
.light(110).rgb());
255 QRgb
dark (c
.dark(110).rgb());
257 QRgb
* data(reinterpret_cast<QRgb
*>(texture
.bits()));
259 for (int x
= 0; x
< 64*12; x
++)
262 else if (data
[x
] == b
)
267 px
.convertFromImage(texture
);
270 const QPixmap
& Static::buttonBase(bool active
, bool down
) const
273 return down
? aButtonDown_
: aButtonUp_
;
275 return down
? iButtonDown_
: iButtonUp_
;
278 void Static::_initSizes()
280 QFont
f(KDecoration::options()->font(true)); // XXX false doesn't work right at the moment
286 titleHeight_
= h
+ 6;
288 if (titleHeight_
< 20)
291 buttonSize_
= titleHeight_
- 1;
296 void Static::_resizeAllPixmaps()
298 aResize_
.resize(30, resizeHeight_
);
299 iResize_
.resize(30, resizeHeight_
);
300 aTitleTextLeft_
.resize( 3, titleHeight_
);
301 aTitleTextRight_
.resize( 3, titleHeight_
);
302 iTitleTextLeft_
.resize( 3, titleHeight_
);
303 iTitleTextRight_
.resize( 3, titleHeight_
);
304 aTitleTextMid_
.resize(64, titleHeight_
);
305 iTitleTextMid_
.resize(64, titleHeight_
);
306 aResizeMidLeft_
.resize( 3, resizeHeight_
);
307 aResizeMidRight_
.resize( 3, resizeHeight_
);
308 iResizeMidLeft_
.resize( 3, resizeHeight_
);
309 iResizeMidRight_
.resize( 3, resizeHeight_
);
310 aResizeMid_
.resize(64, resizeHeight_
);
311 iResizeMid_
.resize(64, resizeHeight_
);
313 aButtonUp_
.resize(buttonSize_
, buttonSize_
);
314 iButtonUp_
.resize(buttonSize_
, buttonSize_
);
315 aButtonDown_
.resize(buttonSize_
, buttonSize_
);
316 iButtonDown_
.resize(buttonSize_
, buttonSize_
);
319 void Static::_blankAllPixmaps()
321 aResize_
.fill(Qt::black
);
322 iResize_
.fill(Qt::black
);
323 aTitleTextLeft_
.fill(Qt::black
);
324 aTitleTextRight_
.fill(Qt::black
);
325 iTitleTextLeft_
.fill(Qt::black
);
326 iTitleTextRight_
.fill(Qt::black
);
327 aTitleTextMid_
.fill(Qt::black
);
328 iTitleTextMid_
.fill(Qt::black
);
329 aResizeMidLeft_
.fill(Qt::black
);
330 aResizeMidRight_
.fill(Qt::black
);
331 iResizeMidLeft_
.fill(Qt::black
);
332 iResizeMidRight_
.fill(Qt::black
);
333 aResizeMid_
.fill(Qt::black
);
334 iResizeMid_
.fill(Qt::black
);
335 aButtonUp_
.fill(Qt::black
);
336 iButtonUp_
.fill(Qt::black
);
337 aButtonDown_
.fill(Qt::black
);
338 iButtonDown_
.fill(Qt::black
);
341 void Static::_initPalettes()
343 const KDecorationOptions
* options
= KDecoration::options();
344 setPalette(aButPal_
, options
->color(KDecoration::ColorButtonBg
, true));
345 setPalette(iButPal_
, options
->color(KDecoration::ColorButtonBg
, false));
347 setPalette(aTitlePal_
, options
->color(KDecoration::ColorTitleBar
, true));
348 setPalette(iTitlePal_
, options
->color(KDecoration::ColorTitleBar
, false));
350 setPalette(aResizePal_
, options
->color(KDecoration::ColorTitleBar
, true));
351 setPalette(iResizePal_
, options
->color(KDecoration::ColorTitleBar
, false));
354 void Static::_initTextures()
356 _createTexture(aTexture_
, KDecoration::ColorTitleBar
, true);
357 _createTexture(iTexture_
, KDecoration::ColorTitleBar
, false);
358 _createTexture(abTexture_
, KDecoration::ColorButtonBg
, true);
359 _createTexture(ibTexture_
, KDecoration::ColorButtonBg
, false);
362 void Static::_drawTitleTextAreaSides()
364 QPixmap
temp(4, titleHeight_
);
365 temp
.fill(Qt::black
);
367 transx
= transy
= 0.0;
369 palette_
= aTitlePal_
;
372 _drawBorder(temp
, 4, titleHeight_
- 2);
374 painter_
.begin(&aTitleTextLeft_
);
375 painter_
.drawPixmap(1, 1, temp
, 0, 1);
378 painter_
.begin(&aTitleTextRight_
);
379 painter_
.drawPixmap(0, 1, temp
, 2, 1);
382 palette_
= iTitlePal_
;
383 _drawBorder(temp
, 4, titleHeight_
- 2);
385 painter_
.begin(&iTitleTextLeft_
);
386 painter_
.drawPixmap(1, 1, temp
, 0, 1);
389 painter_
.begin(&iTitleTextRight_
);
390 painter_
.drawPixmap(0, 1, temp
, 2, 1);
394 void Static::_drawResizeCentralAreaSides()
396 QPixmap
temp(4, resizeHeight_
);
397 temp
.fill(Qt::black
);
401 palette_
= aResizePal_
;
403 _drawBorder(temp
, 4, resizeHeight_
- 3);
405 painter_
.begin(&aResizeMidLeft_
);
406 painter_
.drawPixmap(0, 1, temp
, 0, 1);
409 painter_
.begin(&aResizeMidRight_
);
410 painter_
.drawPixmap(0, 1, temp
, 2, 1);
413 palette_
= iResizePal_
;
414 _drawBorder(temp
, 4, resizeHeight_
- 3);
416 painter_
.begin(&iResizeMidLeft_
);
417 painter_
.drawPixmap(0, 1, temp
, 0, 1);
420 painter_
.begin(&iResizeMidRight_
);
421 painter_
.drawPixmap(0, 1, temp
, 2, 1);
425 void Static::_drawTitleTextAreaBackground()
427 QPixmap
temp(70, titleHeight_
);
428 temp
.fill(Qt::black
);
430 transx
= transy
= 0.0;
432 palette_
= aTitlePal_
;
433 _drawBorder(temp
, 70, titleHeight_
- 3);
435 painter_
.begin(&aTitleTextMid_
);
436 painter_
.drawPixmap(0, 1, temp
, 2, 0);
438 painter_
.drawTiledPixmap(0, 4, 64, titleHeight_
- 8, aTexture_
);
441 palette_
= iTitlePal_
;
442 _drawBorder(temp
, 70, titleHeight_
- 3);
444 painter_
.begin(&iTitleTextMid_
);
445 painter_
.drawPixmap(0, 1, temp
, 2, 0);
447 painter_
.drawTiledPixmap(0, 4, 64, titleHeight_
- 8, iTexture_
);
451 void Static::_drawResizeCentralAreaBackground()
453 QPixmap
temp(70, titleHeight_
);
454 temp
.fill(Qt::black
);
458 palette_
= aResizePal_
;
459 _drawBorder(temp
, 70, resizeHeight_
- 3);
461 painter_
.begin(&aResizeMid_
);
462 painter_
.drawPixmap(0, 0, temp
, 2, 0);
464 painter_
.drawTiledPixmap(0, 4, 64, resizeHeight_
- 8, aTexture_
);
467 palette_
= iResizePal_
;
468 _drawBorder(temp
, 70, 7);
470 painter_
.begin(&iResizeMid_
);
471 painter_
.drawPixmap(0, 0, temp
, 2, 0);
473 painter_
.drawTiledPixmap(0, 4, 64, resizeHeight_
- 8, iTexture_
);
477 void Static::_drawResizeHandles()
479 transx
= transy
= 1.0;
483 palette_
= aResizePal_
;
484 _drawBorder(aResize_
, 28, resizeHeight_
- 3);
488 painter_
.begin(&aResize_
);
489 painter_
.drawTiledPixmap(4, 4, 20, resizeHeight_
- 8, aTexture_
);
493 palette_
= iResizePal_
;
494 _drawBorder(iResize_
, 28, resizeHeight_
- 3);
498 painter_
.begin(&iResize_
);
499 painter_
.drawTiledPixmap(4, 4, 20, resizeHeight_
- 8, iTexture_
);
504 void Static::_drawButtonBackgrounds()
512 _drawBorder(aButtonUp_
, buttonSize_
, buttonSize_
);
514 _drawBorder(aButtonDown_
, buttonSize_
, buttonSize_
);
517 _drawBorder(iButtonDown_
, buttonSize_
, buttonSize_
);
519 _drawBorder(iButtonUp_
, buttonSize_
, buttonSize_
);
521 painter_
.begin(&aButtonUp_
);
524 painter_
.drawTiledPixmap(2, 4, buttonSize_
- 4, buttonSize_
- 5,
529 painter_
.begin(&iButtonUp_
);
531 painter_
.drawTiledPixmap(2, 4, buttonSize_
- 4, buttonSize_
- 5,
539 // vim:ts=2:sw=2:tw=78