summaryrefslogtreecommitdiff
path: root/noncore/styles/liquid/liquid.cpp
Unidiff
Diffstat (limited to 'noncore/styles/liquid/liquid.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/styles/liquid/liquid.cpp2666
1 files changed, 2666 insertions, 0 deletions
diff --git a/noncore/styles/liquid/liquid.cpp b/noncore/styles/liquid/liquid.cpp
new file mode 100644
index 0000000..5f014ad
--- a/dev/null
+++ b/noncore/styles/liquid/liquid.cpp
@@ -0,0 +1,2666 @@
1/*-
2 * Copyright (C)QPL 2001 Daniel M. Duley. All rights reserved.
3 */
4
5
6
7#ifndef INCLUDE_MENUITEM_DEF
8#define INCLUDE_MENUITEM_DEF
9#endif
10
11#include <qmenudata.h>
12#include "liquid.h"
13#include <qapplication.h>
14#include <qpe/config.h>
15#include "effects.h"
16#include <qpalette.h>
17#include <qbitmap.h>
18#include <qtabbar.h>
19#include <qpopupmenu.h>
20#include <qobjectlist.h>
21#include <qimage.h>
22#include <qtimer.h>
23#include <qpixmapcache.h>
24#include <qradiobutton.h>
25#include <qcombobox.h>
26#include <qdrawutil.h>
27#include <qwidgetlist.h>
28#include <qtoolbutton.h>
29#include <qheader.h>
30#include <unistd.h>
31#include <qmenubar.h>
32
33
34#include <stdio.h>
35
36#include "htmlmasks.h"
37#include "embeddata.h"
38
39typedef void (QStyle::*QDrawMenuBarItemImpl) (QPainter *, int, int, int, int, QMenuItem *,
40 QColorGroup &, bool, bool);
41
42QDrawMenuBarItemImpl qt_set_draw_menu_bar_impl(QDrawMenuBarItemImpl impl);
43
44void TransMenuHandler::stripePixmap(QPixmap &pix, const QColor &color)
45{
46 QImage img(pix.convertToImage());
47 QImageEffect::fade(img, 0.9, color);
48 int x, y;
49 int r, g, b;
50 for(y=0; y < img.height(); y+=3){
51 unsigned int *data = (unsigned int *) img.scanLine(y);
52 for(x=0; x < img.width(); ++x){
53 r = qRed(data[x]);
54 g = qGreen(data[x]);
55 b = qBlue(data[x]);
56 if(r-10)
57 r-=10;
58 if(g-10)
59 g-=10;
60 if(b-10)
61 b-=10;
62 data[x] = qRgb(r, g, b);
63 }
64 }
65 pix.convertFromImage(img);
66}
67
68TransMenuHandler::TransMenuHandler(QObject *parent)
69 : QObject(parent)
70{
71 pixDict.setAutoDelete(true);
72 reloadSettings();
73}
74
75void TransMenuHandler::reloadSettings()
76{
77 pixDict.clear();
78
79 Config config ( "qpe" );
80 config. setGroup ( "MosfetMenus" );
81
82 type = config. readNumEntry("Type", TransStippleBg);
83 color = QColor ( config. readEntry("Color", QApplication::palette().active().button().name()));
84 fgColor = QColor ( config. readEntry("TextColor", QApplication::palette().active().text().name()));
85 opacity = config. readNumEntry("Opacity", 10);
86 shadowText = config. readBoolEntry("ShadowText", true);
87}
88
89bool TransMenuHandler::eventFilter(QObject *obj, QEvent *ev)
90{
91 QPopupMenu *p = (QPopupMenu *)obj;
92
93 if(ev->type() == QEvent::Show){
94 if(type == TransStippleBg || type == TransStippleBtn ||
95 type == Custom){
96 QApplication::syncX();
97 QPixmap *pix = new QPixmap;
98 if(p->testWFlags(Qt::WType_Popup)){
99 QRect r(p->x(), p->y(), p->width(), p->height());
100 QRect deskR = QApplication::desktop()->rect();
101 if(r.right() > deskR.right() || r.bottom() > deskR.bottom()){
102 r.setBottom(deskR.bottom());
103 r.setRight(deskR.right());
104 }
105 *pix = QPixmap::grabWindow(QApplication::desktop()-> winId(), r.x(), r.y(),
106 r.width(), r.height());
107 }
108 else{ // tear off menu
109 pix->resize(p->width(), p->height());
110 pix->fill(Qt::black.rgb());
111 }
112 if(type == TransStippleBg){
113 stripePixmap(*pix, p->colorGroup().background());
114 }
115 else if(type == TransStippleBtn){
116 stripePixmap(*pix, p->colorGroup().button());
117 }
118 else{
119 QPixmapEffect::fade(*pix, (((float)opacity)+80)*0.01, color);
120 }
121 pixDict.insert(p->winId(), pix);
122 }
123 }
124 else if(ev->type() == QEvent::Hide){
125 if(type == TransStippleBg || type == TransStippleBtn ||
126 type == Custom){
127// qWarning("Deleting menu pixmap, width %d", pixDict.find(p->winId())->width());
128 pixDict.remove(p->winId());
129 }
130 }
131 return(false);
132}
133
134
135LiquidStyle::LiquidStyle()
136 :QWindowsStyle()
137{
138 setName ( "LiquidStyle" );
139
140 btnMaskBmp = QBitmap(37, 26, buttonmask_bits, true);
141 btnMaskBmp.setMask(btnMaskBmp);
142 htmlBtnMaskBmp = QBitmap(37, 26, htmlbuttonmask_bits, true);
143 htmlBtnMaskBmp.setMask(htmlBtnMaskBmp);
144 headerHoverID = -1;
145 highlightWidget = NULL;
146 setButtonDefaultIndicatorWidth(0);
147 btnDict.setAutoDelete(true);
148 bevelFillDict.setAutoDelete(true);
149 smallBevelFillDict.setAutoDelete(true);
150 customBtnColorList.setAutoDelete(true);
151 customBtnIconList.setAutoDelete(true);
152 customBtnLabelList.setAutoDelete(true);
153
154 rMatrix.rotate(270.0);
155 highcolor = QPixmap::defaultDepth() > 8;
156 btnBorderPix = new QPixmap;
157 btnBorderPix->convertFromImage(qembed_findImage("buttonfill"));
158 btnBlendPix = new QPixmap;
159 btnBlendPix->convertFromImage(qembed_findImage("buttonborder"));
160 bevelFillPix = new QPixmap;
161 bevelFillPix->convertFromImage(qembed_findImage("clear_fill_large"));
162 smallBevelFillPix = new QPixmap;
163 smallBevelFillPix->convertFromImage(qembed_findImage("clear_fill_small"));
164 // new stuff
165 vsbSliderFillPix = menuPix = NULL;
166 menuHandler = new TransMenuHandler(this);
167 setScrollBarExtent(15, 15);
168 int i;
169 for(i=0; i < BITMAP_ITEMS; ++i){
170 pixmaps[i] = NULL;
171 }
172 oldSliderThickness = sliderThickness();
173 setSliderThickness(11);
174}
175
176LiquidStyle::~LiquidStyle()
177{
178 if(btnBorderPix)
179 delete btnBorderPix;
180 if(btnBlendPix)
181 delete btnBlendPix;
182 if(bevelFillPix)
183 delete bevelFillPix;
184 if(smallBevelFillPix)
185 delete smallBevelFillPix;
186 if(vsbSliderFillPix)
187 delete vsbSliderFillPix;
188 if(menuPix)
189 delete menuPix;
190
191 setScrollBarExtent(16, 16);
192 setSliderThickness(oldSliderThickness);
193 int i;
194 for(i=0; i < BITMAP_ITEMS; ++i){
195 if(pixmaps[i])
196 delete pixmaps[i];
197 }
198}
199
200void LiquidStyle::drawClearBevel(QPainter *p, int x, int y, int w, int h,
201 const QColor &c, const QColor &bg)
202{
203
204 QPen oldPen = p->pen(); // headers need this
205 int x2 = x+w-1;
206 int y2 = y+h-1;
207 // outer dark rect
208 p->setPen(c.dark(130));
209 p->drawLine(x, y+2, x, y2-2); // l
210 p->drawLine(x2, y+2, x2, y2-2); // r
211 p->drawLine(x+2, y, x2-2, y); // t
212 p->drawLine(x+2, y2, x2-2, y2); // b
213 p->drawPoint(x+1, y+1); // tl
214 p->drawPoint(x2-1, y+1); // tr
215 p->drawPoint(x+1, y2-1); // bl
216 p->drawPoint(x2-1, y2-1); // br
217
218 // inner top light lines
219 p->setPen(c.light(105));
220 p->drawLine(x+2, y+1, x2-2, y+1);
221 p->drawLine(x+1, y+2, x2-1, y+2);
222 p->drawLine(x+1, y+3, x+2, y+3);
223 p->drawLine(x2-2, y+3, x2-1, y+3);
224 p->drawPoint(x+1, y+4);
225 p->drawPoint(x2-1, y+4);
226
227 // inner bottom light lines
228 p->setPen(c.light(110));
229 p->drawLine(x+2, y2-1, x2-2, y2-1);
230 p->drawLine(x+1, y2-2, x2-1, y2-2);
231 p->drawLine(x+1, y2-3, x+2, y2-3);
232 p->drawLine(x2-2, y2-3, x2-1, y2-3);
233 p->drawPoint(x+1, y2-4);
234 p->drawPoint(x2-1, y2-4);
235
236 // inner left mid lines
237 //p->setPen(c.light(105));
238 p->setPen(c);
239 p->drawLine(x+1, y+5, x+1, y2-5);
240 p->drawLine(x+2, y+4, x+2, y2-4);
241
242 // inner right mid lines
243 p->drawLine(x2-1, y+5, x2-1, y2-5);
244 p->drawLine(x2-2, y+4, x2-2, y2-4);
245
246 // fill
247 QPixmap *pix;
248 if(h >= 32){
249 pix = bevelFillDict.find(c.rgb());
250 if(!pix){
251 int h, s, v;
252 c.hsv(&h, &s, &v);
253 pix = new QPixmap(*bevelFillPix);
254 adjustHSV(*pix, h, s, v);
255 bevelFillDict.insert(c.rgb(), pix);
256 }
257 }
258 else{
259 pix = smallBevelFillDict.find(c.rgb());
260 if(!pix){
261 int h, s, v;
262 c.hsv(&h, &s, &v);
263 pix = new QPixmap(*smallBevelFillPix);
264 adjustHSV(*pix, h, s, v);
265 smallBevelFillDict.insert(c.rgb(), pix);
266 }
267 }
268 p->drawTiledPixmap(x+3, y+3, w-6, h-6, *pix);
269 // blend
270 int red, green, blue;
271 QColor btnColor(c.dark(130));
272 red = (btnColor.red() >> 1) + (bg.red() >> 1);
273 green = (btnColor.green() >> 1) + (bg.green() >> 1);
274 blue = (btnColor.blue() >> 1) + (bg.blue() >> 1);
275 btnColor.setRgb(red, green, blue);
276
277 p->setPen(btnColor);
278 p->drawPoint(x+1, y);
279 p->drawPoint(x, y+1);
280 p->drawPoint(x+1, y2);
281 p->drawPoint(x, y2-1);
282
283 p->drawPoint(x2-1, y);
284 p->drawPoint(x2, y+1);
285 p->drawPoint(x2-1, y2);
286 p->drawPoint(x2, y2-1);
287
288 p->setPen(oldPen);
289
290}
291
292void LiquidStyle::drawRoundButton(QPainter *painter, const QColor &c,
293 const QColor &back, int x, int y, int w, int h,
294 bool supportPushDown, bool pushedDown,
295 bool autoDefault, bool isMasked)
296{
297 if(w < 21 || h < 21){
298 drawClearBevel(painter, x, y, w, h, c, back);
299 return;
300 }
301 if(supportPushDown){
302 --w, --h;
303 }
304 /* We don't make the round buttons smaller, since they don't look as good
305 if(autoDefault){
306 w = w-buttonDefaultIndicatorWidth()*2;
307 h = h-buttonDefaultIndicatorWidth()*2;
308 }*/
309
310
311 QPixmap *pix = btnDict.find(c.rgb());
312 if(!pix){
313 int h, s, v;
314 c.hsv(&h, &s, &v);
315 pix = new QPixmap(*btnBorderPix);
316 adjustHSV(*pix, h, s, v);
317 btnDict.insert(c.rgb(), pix);
318 }
319 int x2 = x+w-1;
320 int y2 = y+h-1;
321 int bx2 = pix->width()-1;
322 int by2 = pix->height()-1;
323
324 QPixmap tmpPix(w, h);
325 QPixmap tilePix;
326 QPainter p;
327 p.begin(&tmpPix);
328
329 // do the fill
330 p.drawPixmap(0, 0, *pix, 0, 0, 10, 10); // tl
331 p.drawPixmap(x2-9, 0, *pix, bx2-9, 0, 10, 10); // tr
332 p.drawPixmap(0, y2-9, *pix, 0, by2-9, 10, 10); // bl
333 p.drawPixmap(x2-9, y2-9, *pix, bx2-9, by2-9, 10, 10); // br
334
335 // edges
336 tilePix.resize(pix->width()-20, 10);
337 // top
338 bitBlt(&tilePix, 0, 0, pix, 10, 0, pix->width()-20, 10);
339 p.drawTiledPixmap(10, 0, w-20, 10, tilePix);
340 // bottom
341 bitBlt(&tilePix, 0, 0, pix, 10, by2-9, pix->width()-20, 20);
342 p.drawTiledPixmap(10, y2-9, w-20, 10, tilePix);
343 // left
344 tilePix.resize(10, pix->height()-20);
345 bitBlt(&tilePix, 0, 0, pix, 0, 10, 10, pix->height()-20);
346 p.drawTiledPixmap(0, 10, 10, h-20, tilePix);
347 // right
348 bitBlt(&tilePix, 0, 0, pix, bx2-9, 10, 10, pix->height()-20);
349 p.drawTiledPixmap(x2-9, 10, 10, h-20, tilePix);
350
351 // middle
352 tilePix.resize(pix->width()-20, pix->height()-20);
353 bitBlt(&tilePix, 0, 0, pix, 10, 10, pix->width()-20, pix->height()-20);
354 p.drawTiledPixmap(10, 10, w-20, h-20, tilePix);
355
356
357 // do the blend
358 QBitmap blendMask;
359 if(!isMasked){
360 //QRgb bgRgb = back.rgb();
361 //QRgb fgRgb = c.rgb();
362 //int r, g, b;
363
364 //r = (int)(qRed(bgRgb)*0.75 + qRed(fgRgb)*0.25);
365 //g = (int)(qGreen(bgRgb)*0.75 + qGreen(fgRgb)*0.25);
366 //b = (int)(qBlue(bgRgb)*0.75 + qBlue(fgRgb)*0.25);
367 //QColor blendColor(r, g, b);
368 int hue, sat, v1, v2;
369 QColor blendColor(autoDefault ? c : back);
370 back.hsv(&hue, &sat, &v1);
371 blendColor.hsv(&hue, &sat, &v2);
372 if(v2 > v1)
373 blendColor.setHsv(hue, sat, (int)(v1*0.75 + v2*0.25));
374
375 pix = btnBorderDict.find(blendColor.rgb());
376 if(!pix){
377 int h, s, v;
378 blendColor.hsv(&h, &s, &v);
379 pix = new QPixmap(*btnBlendPix);
380 adjustHSV(*pix, h, s, v);
381 btnBorderDict.insert(blendColor.rgb(), pix);
382 }
383 }
384 else{
385 pix = pushedDown ? getPixmap(HTMLBtnBorderDown) :
386 getPixmap(HTMLBtnBorder);
387 }
388 p.drawPixmap(0, 0, *pix, 0, 0, 10, 10); // tl
389 p.drawPixmap(x2-9, 0, *pix, bx2-9, 0, 10, 10); // tr
390 p.drawPixmap(0, y2-9, *pix, 0, by2-9, 10, 10); // bl
391 p.drawPixmap(x2-9, y2-9, *pix, bx2-9, by2-9, 10, 10); // br
392
393 // edges
394 tilePix.resize(pix->width()-20, 10);
395 blendMask.resize(pix->width()-20, 10);
396 // top
397 bitBlt(&tilePix, 0, 0, pix, 10, 0, pix->width()-20, 10);
398 bitBlt(&blendMask, 0, 0, pix->mask(), 10, 0, pix->width()-20, 10);
399 tilePix.setMask(blendMask);
400 p.drawTiledPixmap(10, 0, w-20, 10, tilePix);
401 // bottom
402 bitBlt(&tilePix, 0, 0, pix, 10, by2-9, pix->width()-20, 20);
403 bitBlt(&blendMask, 0, 0, pix->mask(), 10, by2-9, pix->width()-20, 20);
404 tilePix.setMask(blendMask);
405 p.drawTiledPixmap(10, y2-9, w-20, 10, tilePix);
406 // left
407 tilePix.resize(10, pix->height()-20);
408 blendMask.resize(10, pix->height()-20);
409 bitBlt(&tilePix, 0, 0, pix, 0, 10, 10, pix->height()-20);
410 bitBlt(&blendMask, 0, 0, pix->mask(), 0, 10, 10, pix->height()-20);
411 tilePix.setMask(blendMask);
412 p.drawTiledPixmap(0, 10, 10, h-20, tilePix);
413 // right
414 bitBlt(&tilePix, 0, 0, pix, bx2-9, 10, 10, pix->height()-20);
415 bitBlt(&blendMask, 0, 0, pix->mask(), bx2-9, 10, 10, pix->height()-20);
416 tilePix.setMask(blendMask);
417 p.drawTiledPixmap(x2-9, 10, 10, h-20, tilePix);
418
419 p.end();
420
421 // do the button mask - we don't automask buttons
422 QBitmap btnMask(w, h);
423 QBitmap *mask = isMasked ? &htmlBtnMaskBmp : &btnMaskBmp;
424 p.begin(&btnMask);
425 p.fillRect(0, 0, w, h, Qt::color0);
426 p.drawPixmap(0, 0, *mask, 0, 0, 10, 10); // tl
427 p.drawPixmap(x2-9, 0, *mask, bx2-9, 0, 10, 10); // tr
428 p.drawPixmap(0, y2-9, *mask, 0, by2-9, 10, 10); // bl
429 p.drawPixmap(x2-9, y2-9, *mask, bx2-9, by2-9, 10, 10); // br
430 // fills
431 p.fillRect(10, 0, w-20, 10, Qt::color1); // top
432 p.fillRect(10, y2-9, w-20, 10, Qt::color1); // bottom
433 p.fillRect(0, 10, w, h-20, Qt::color1); // middle
434 p.end();
435 tmpPix.setMask(btnMask);
436 /*if(autoDefault){
437 if(supportPushDown && pushedDown){
438 painter->drawPixmap(x+3, y+3, tmpPix);
439 }
440 else{
441 painter->drawPixmap(x+2, y+2, tmpPix);
442 }
443 }
444 else */if(supportPushDown && pushedDown)
445 painter->drawPixmap(x+1, y+1, tmpPix);
446 else
447 painter->drawPixmap(x, y, tmpPix);
448
449
450
451}
452
453
454QPixmap* LiquidStyle::processEmbedded(const char *label, int h, int s, int v,
455 bool blend)
456{
457 QImage img(qembed_findImage(label));
458 img.detach();
459 if(img.isNull()){ // shouldn't happen, been tested
460 qWarning("Invalid embedded label %s", label);
461 return(NULL);
462 }
463 if(img.depth() != 32)
464 img = img.convertDepth(32);
465 unsigned int *data = (unsigned int *)img.bits();
466 int total = img.width()*img.height();
467 int current;
468 QColor c;
469 int oldH, oldS, oldV;
470 int alpha;
471 if(v < 235)
472 v += 20;
473 else
474 v = 255;
475 float intensity = v/255.0;
476
477 for(current=0; current<total; ++current){
478 alpha = qAlpha(data[current]);
479 c.setRgb(data[current]);
480 c.hsv(&oldH, &oldS, &oldV);
481 oldV = (int)(oldV*intensity);
482 c.setHsv(h, s, oldV);
483 if(blend && alpha != 255 && alpha != 0){
484 float srcPercent = ((float)alpha)/255.0;
485 float destPercent = 1.0-srcPercent;
486 oldH = (int)((srcPercent*h) + (destPercent*bH));
487 oldS = (int)((srcPercent*s) + (destPercent*bS));
488 oldV = (int)((srcPercent*oldV) + (destPercent*bV));
489 c.setHsv(oldH, oldS, oldV);
490 alpha = 255;
491 }
492 data[current] = qRgba(c.red(), c.green(), c.blue(), alpha);
493 }
494 QPixmap *pix = new QPixmap;
495 pix->convertFromImage(img);
496 return(pix);
497}
498
499
500
501
502QPixmap* LiquidStyle::getPixmap(BitmapData item)
503{
504
505 if(pixmaps[item])
506 return(pixmaps[item]);
507
508 switch(item){
509 case HTMLBtnBorder:
510 pixmaps[HTMLBtnBorder] = processEmbedded("htmlbtnborder", btnH, btnS, btnV);
511 break;
512 case HTMLBtnBorderDown:
513 pixmaps[HTMLBtnBorderDown] = processEmbedded("htmlbtnborder", btnHoverH, btnHoverS, btnHoverV);
514 break;
515 case HTMLCB:
516 pixmaps[HTMLCB] = processEmbedded("htmlcheckbox", bH, bS, bV);
517 break;
518 case HTMLCBDown:
519 pixmaps[HTMLCBDown] = processEmbedded("htmlcheckboxdown", btnH, btnS, btnV);
520 break;
521 case HTMLCBHover:
522 pixmaps[HTMLCBHover] = processEmbedded("htmlcheckbox", btnH, btnS, btnV);
523 break;
524 case HTMLCBDownHover:
525 pixmaps[HTMLCBDownHover] = processEmbedded("htmlcheckboxdown",
526 btnHoverH, btnHoverS,
527 btnHoverV);
528 break;
529 case HTMLRadio:
530 pixmaps[HTMLRadio] = processEmbedded("htmlradio", bH, bS, bV);
531 case HTMLRadioDown:
532 pixmaps[HTMLRadioDown] = processEmbedded("htmlradiodown", btnH, btnS, btnV);
533 case HTMLRadioHover:
534 pixmaps[HTMLRadioHover] = processEmbedded("htmlradio", btnH, btnS, btnV);
535 case HTMLRadioDownHover:
536 pixmaps[HTMLRadioDownHover] = processEmbedded("htmlradiodown",
537 btnHoverH, btnHoverS,
538 btnHoverV);
539 case RadioOn:
540 pixmaps[RadioOn] = processEmbedded("radio_down", btnH, btnS, btnV, true);
541 break;
542 case RadioOnHover:
543 pixmaps[RadioOnHover] = processEmbedded("radio_down", btnHoverH, btnHoverS,
544 btnHoverV, true);
545 break;
546 case RadioOffHover:
547 pixmaps[RadioOffHover] = processEmbedded("radio", btnH, btnS, btnV, true);
548 break;
549 case TabDown:
550 pixmaps[TabDown] = processEmbedded("tab", btnH, btnS, btnV, true);
551 break;
552 case TabFocus:
553 pixmaps[TabFocus] = processEmbedded("tab", btnHoverH, btnHoverS,
554 btnHoverS, true);
555 break;
556 case CBDown:
557 pixmaps[CBDown] = processEmbedded("checkboxdown", btnH, btnS, btnV, true);
558 break;
559 case CBDownHover:
560 pixmaps[CBDownHover] = processEmbedded("checkboxdown", btnHoverH,
561 btnHoverS, btnHoverV, true);
562 break;
563 case CBHover:
564 pixmaps[CBHover] = processEmbedded("checkbox", btnH, btnS, btnV, true);
565 break;
566 case HSlider:
567 pixmaps[HSlider] = processEmbedded("sliderarrow", btnH, btnS, btnV, true);
568 break;
569 case VSlider:
570 pixmaps[VSlider] = processEmbedded("sliderarrow", btnH, btnS, btnV, true);
571 *pixmaps[VSlider] = pixmaps[VSlider]->xForm(rMatrix);
572 break;
573 case RadioOff:
574 pixmaps[RadioOff] = processEmbedded("radio", bH, bS, bV, true);
575 break;
576 case Tab:
577 pixmaps[Tab] = processEmbedded("tab", bH, bS, bV, true);
578 break;
579 case CB:
580 pixmaps[CB] = processEmbedded("checkbox", bH, bS, bV, true);
581 break;
582 case VSBSliderTop:
583 pixmaps[VSBSliderTop] = processEmbedded("sbslider_top", btnH, btnS, btnV, true);
584 break;
585 case VSBSliderBtm:
586 pixmaps[VSBSliderBtm] = processEmbedded("sbslider_btm", btnH, btnS, btnV, true);
587 break;
588 case VSBSliderMid:
589 pixmaps[VSBSliderMid] = processEmbedded("sbslider_mid", btnH, btnS, btnV);
590 break;
591 case VSBSliderTopHover:
592 pixmaps[VSBSliderTopHover] = processEmbedded("sbslider_top", btnHoverH, btnHoverS, btnHoverV, true);
593 break;
594 case VSBSliderBtmHover:
595 pixmaps[VSBSliderBtmHover] = processEmbedded("sbslider_btm", btnHoverH, btnHoverS, btnHoverV, true);
596 break;
597 case VSBSliderMidHover:
598 pixmaps[VSBSliderMidHover] = processEmbedded("sbslider_mid", btnHoverH, btnHoverS, btnHoverV);
599 break;
600
601 case HSBSliderTop:
602 pixmaps[HSBSliderTop] = processEmbedded("sbslider_top", btnH, btnS, btnV, true);
603 *pixmaps[HSBSliderTop] = pixmaps[HSBSliderTop]->xForm(rMatrix);
604 break;
605 case HSBSliderBtm:
606 pixmaps[HSBSliderBtm] = processEmbedded("sbslider_btm", btnH, btnS, btnV, true);
607 *pixmaps[HSBSliderBtm] = pixmaps[HSBSliderBtm]->xForm(rMatrix);
608 break;
609 case HSBSliderMid:
610 pixmaps[HSBSliderMid] = processEmbedded("sbslider_mid", btnH, btnS, btnV);
611 *pixmaps[HSBSliderMid] = pixmaps[HSBSliderMid]->xForm(rMatrix);
612 break;
613 case HSBSliderTopHover:
614 pixmaps[HSBSliderTopHover] = processEmbedded("sbslider_top", btnHoverH, btnHoverS, btnHoverV, true);
615 *pixmaps[HSBSliderTopHover] = pixmaps[HSBSliderTopHover]->xForm(rMatrix);
616 break;
617 case HSBSliderBtmHover:
618 pixmaps[HSBSliderBtmHover] = processEmbedded("sbslider_btm", btnHoverH, btnHoverS, btnHoverV, true);
619 *pixmaps[HSBSliderBtmHover] = pixmaps[HSBSliderBtmHover]->xForm(rMatrix);
620 break;
621 case HSBSliderMidHover:
622 pixmaps[HSBSliderMidHover] = processEmbedded("sbslider_mid", btnHoverH, btnHoverS, btnHoverV);
623 *pixmaps[HSBSliderMidHover] = pixmaps[HSBSliderMidHover]->xForm(rMatrix);
624 break;
625 case VSBSliderTopBg:
626 pixmaps[VSBSliderTopBg] = processEmbedded("sbslider_top", bH, bS, bV, true);
627 break;
628 case VSBSliderBtmBg:
629 pixmaps[VSBSliderBtmBg] = processEmbedded("sbslider_btm", bH, bS, bV, true);
630 break;
631 case VSBSliderMidBg:
632 pixmaps[VSBSliderMidBg] = processEmbedded("sbslider_mid", bH, bS, bV);
633 break;
634 case HSBSliderTopBg:
635 pixmaps[HSBSliderTopBg] = processEmbedded("sbslider_top", bH, bS, bV, true);
636 *pixmaps[HSBSliderTopBg] = pixmaps[HSBSliderTopBg]->xForm(rMatrix);
637 break;
638 case HSBSliderBtmBg:
639 pixmaps[HSBSliderBtmBg] = processEmbedded("sbslider_btm", bH, bS, bV, true);
640 *pixmaps[HSBSliderBtmBg] = pixmaps[HSBSliderBtmBg]->xForm(rMatrix);
641 break;
642 case HSBSliderMidBg:
643 pixmaps[HSBSliderMidBg] = processEmbedded("sbslider_mid", bH, bS, bV);
644 *pixmaps[HSBSliderMidBg] = pixmaps[HSBSliderMidBg]->xForm(rMatrix);
645 break;
646 default:
647 break;
648 }
649 return(pixmaps[item]);
650}
651
652void LiquidStyle::polish(QPalette &appPal)
653{
654
655 int i;
656 for(i=0; i < BITMAP_ITEMS; ++i){
657 if(pixmaps[i]){
658 delete pixmaps[i];
659 pixmaps[i] = NULL;
660 }
661 }
662 QWidgetList *list = QApplication::allWidgets();
663 QWidgetListIt it( *list );
664 QWidget *w;
665 while ((w=it.current()) != 0 ){
666 ++it;
667 if(w->inherits("QPushButton")){
668 unapplyCustomAttributes((QPushButton *)w);
669 }
670 }
671
672 loadCustomButtons();
673 lowLightVal = 100 + (2* /*KGlobalSettings::contrast()*/ 3 +4)*10;
674 btnDict.clear();
675 btnBorderDict.clear();
676 bevelFillDict.clear();
677 smallBevelFillDict.clear();
678
679 Config config ( "qpe" );
680 QPalette pal = QApplication::palette();
681
682 // button color stuff
683 config. setGroup ( "Appearance" );
684 QColor c = QColor ( config. readEntry("Button", ( Qt::lightGray ). name ( )));
685 if ( c == QColor ( config. readEntry ( "background", ( Qt::lightGray ). name ( )))) {
686 // force button color to be different from background
687 QBrush btnBrush(QColor(200, 202, 228));
688 appPal.setBrush(QColorGroup::Button, btnBrush);
689 }
690 c.hsv(&btnH, &btnS, &btnV);
691 c.light(120).hsv(&btnHoverH, &btnHoverS, &btnHoverV);
692
693 // menu pixmap
694 if(!menuPix){
695 menuPix = new QPixmap;
696 menuPix->resize(64, 64);
697 }
698 QPainter painter;
699 menuPix->fill(c.rgb());
700 painter.begin(menuPix);
701 painter.setPen(c.dark(105));
702 for(i=0; i < 63; i+=4){
703 painter.drawLine(0, i, 63, i);
704 painter.drawLine(0, i+1, 63, i+1);
705 };
706 painter.end();
707 menuBrush.setColor(c);
708 menuBrush.setPixmap(*menuPix);
709
710 // pager brush
711 c = c.dark(120);
712 QPixmap *pix = smallBevelFillDict.find(c.rgb()); // better be NULL ;-)
713 if(!pix){
714 int h, s, v;
715 c.hsv(&h, &s, &v);
716 pix = new QPixmap(*smallBevelFillPix);
717 adjustHSV(*pix, h, s, v);
718 smallBevelFillDict.insert(c.rgb(), pix);
719 }
720 pagerHoverBrush.setColor(c);
721 pagerHoverBrush.setPixmap(*pix);
722
723 c = c.dark(120);
724 pix = smallBevelFillDict.find(c.rgb()); // better be NULL ;-)
725 if(!pix){
726 int h, s, v;
727 c.hsv(&h, &s, &v);
728 pix = new QPixmap(*smallBevelFillPix);
729 adjustHSV(*pix, h, s, v);
730 smallBevelFillDict.insert(c.rgb(), pix);
731 }
732 pagerBrush.setColor(c);
733 pagerBrush.setPixmap(*pix);
734
735 // background color stuff
736 c = QColor ( config. readEntry ( "Background", ( Qt::lightGray ).name ( )));
737 c.hsv(&bH, &bS, &bV);
738 c.light(120).hsv(&bHoverH, &bHoverS, &bHoverV);
739
740 // FIXME?
741 if(vsbSliderFillPix)
742 delete vsbSliderFillPix;
743 vsbSliderFillPix = new QPixmap(bevelFillPix->xForm(rMatrix));
744 adjustHSV(*vsbSliderFillPix, bH, bS, bV);
745
746 // background brush
747 QPixmap wallPaper(32, 32);
748 wallPaper.fill(c.rgb());
749 painter.begin(&wallPaper);
750 for(i=0; i < 32; i+=4){
751 painter.setPen(c.dark(105));
752 painter.drawLine(0, i, 32, i);
753 painter.setPen(c.dark(103));
754 painter.drawLine(0, i+1, 32, i+1);
755 };
756 painter.end();
757 bgBrush.setColor(c);
758 bgBrush.setPixmap(wallPaper);
759 appPal.setBrush(QColorGroup::Background, bgBrush);
760
761 // lineedits
762 c = QColor ( config. readEntry("Base", ( Qt::white). name ( )));
763 QPixmap basePix;
764 basePix.resize(32, 32);
765 basePix.fill(c.rgb());
766 painter.begin(&basePix);
767 painter.setPen(c.dark(105));
768 for(i=0; i < 32; i+=4){
769 painter.drawLine(0, i, 32, i);
770 painter.drawLine(0, i+1, 32, i+1);
771 };
772 painter.end();
773 baseBrush.setColor(c);
774 baseBrush.setPixmap(basePix);
775 it.toFirst();
776 while ((w=it.current()) != 0 ){
777 ++it;
778 if(w->inherits("QLineEdit")){
779 QPalette pal = w->palette();
780 pal.setBrush(QColorGroup::Base, baseBrush);
781 w->setPalette(pal);
782 }
783 else if(w->inherits("QPushButton")){
784 applyCustomAttributes((QPushButton *)w);
785 }
786 }
787
788}
789
790void LiquidStyle::polish(QWidget *w)
791{
792 if(w->inherits("QMenuBar")){
793 //((QFrame*)w)->setLineWidth(0);
794 w->setBackgroundMode(QWidget::PaletteBackground);
795 return;
796 }
797 if(w->inherits("QPopupMenu"))
798 w->setBackgroundMode(QWidget::NoBackground);
799
800 if(w->isTopLevel()){
801 return;
802 }
803
804 w-> setBackgroundOrigin ( QWidget::ParentOrigin );
805
806 if(w->inherits("QComboBox") ||
807 w->inherits("QLineEdit") || w->inherits("QRadioButton") ||
808 w->inherits("QCheckBox") || w->inherits("QScrollBar")) {
809 w->installEventFilter(this);
810 }
811 if(w->inherits("QLineEdit")){
812 QPalette pal = w->palette();
813 pal.setBrush(QColorGroup::Base, baseBrush);
814 w->setPalette(pal);
815 }
816 if(w->inherits("QPushButton")){
817 applyCustomAttributes((QPushButton *)w);
818 w->installEventFilter(this);
819 }
820 if(w->inherits("QButton") || w-> inherits("QComboBox")){
821 w-> setBackgroundMode ( QWidget::PaletteBackground );
822 }
823
824 bool isViewport = qstrcmp(w->name(), "qt_viewport") == 0 ||
825 qstrcmp(w->name(), "qt_clipped_viewport") == 0;
826 bool isViewportChild = w->parent() &&
827 ((qstrcmp(w->parent()->name(), "qt_viewport") == 0) ||
828 (qstrcmp(w->parent()->name(), "qt_clipped_viewport") == 0));
829
830 if(isViewport && w->parent() && qstrcmp(w->parent()->name(), "proxyview") == 0){
831 w->setBackgroundMode(QWidget::X11ParentRelative);
832 return;
833 }
834 if(isViewportChild){
835 if(w->inherits("QButton") || w->inherits("QComboBox")){
836 if(w->parent()){ // heh, only way to test for KHTML children ;-)
837 if(w->parent()->parent()){
838 if(w->parent()->parent()->parent() &&
839 w->parent()->parent()->parent()->inherits("KHTMLView")){
840 w->setAutoMask(true);
841 w->setBackgroundMode(QWidget::NoBackground);
842 }
843 }
844 }
845 return;
846 }
847 }
848 if(w->inherits("QHeader")){
849 w->setMouseTracking(true);
850 w->installEventFilter(this);
851 }
852 if(w-> inherits("QToolButton")) {
853 ((QToolButton*)w)->setAutoRaise (false);
854 }
855 if(w->ownPalette() && !w->inherits("QButton") && !w->inherits("QComboBox")){
856 return;
857 }
858
859 if(w->parent() && w->parent()->isWidgetType() && !((QWidget*)w->parent())->
860 palette().active().brush(QColorGroup::Background).pixmap()){
861 qWarning("No parent pixmap for child widget %s", w->className());
862 return;
863 }
864 if(!isViewport && !isViewportChild && !w->testWFlags(WType_Popup) &&
865 !( !w-> inherits("QLineEdit") && w-> parent() && w-> parent()-> isWidgetType ( ) && w-> parent()-> inherits ( "QMultiLineEdit" ))) {
866 if(w->backgroundMode() == QWidget::PaletteBackground ||
867 w->backgroundMode() == QWidget::PaletteButton){
868 w->setBackgroundMode(QWidget::X11ParentRelative);
869 }
870 }
871 if(w->inherits("QToolBar")){
872 w->installEventFilter(this);
873 w->setBackgroundMode(QWidget::PaletteBackground);
874 return;
875 }
876
877}
878
879void LiquidStyle::unPolish(QWidget *w)
880{
881 if(w->inherits("QMenuBar")){
882 ((QFrame *)w)->setLineWidth(1);
883 w->setBackgroundMode(QWidget::PaletteBackground);
884 return;
885 }
886
887 if(w->inherits("QPopupMenu"))
888 w->setBackgroundMode(QWidget::PaletteButton);
889
890 if(w->isTopLevel())
891 return;
892
893 // for viewport children, don't just check for NoBackground....
894 bool isViewportChild = w->parent() &&
895 ((qstrcmp(w->parent()->name(), "qt_viewport") == 0) ||
896 (qstrcmp(w->parent()->name(), "qt_clipped_viewport") == 0));
897
898 w->setPalette(QApplication::palette());
899 if(w->backgroundMode() == QWidget::X11ParentRelative || isViewportChild){
900 if(w->inherits("QPushButton"))
901 w->setBackgroundMode(QWidget::PaletteButton);
902 else
903 w->setBackgroundMode(QWidget::PaletteBackground);
904 }
905
906 if(isViewportChild)
907 w->setAutoMask(false);
908
909 if(w->inherits("QPushButton")){
910 unapplyCustomAttributes((QPushButton *)w);
911 w->removeEventFilter(this);
912 }
913/*
914 if(w->inherits("QPushButton") || w-> inherits("QComboBox")){
915 w-> setBackgroundMode ( PaletteBackground );
916 }
917*/
918 if(w->inherits("QComboBox") ||
919 w->inherits("QLineEdit") || w->inherits("QRadioButton") ||
920 w->inherits("QCheckBox") || w->inherits("QScrollBar")) {
921 w->removeEventFilter(this);
922 }
923 if(w->inherits("QButton") || w->inherits("QComboBox")){
924 if(w->parent() && w->parent()->inherits("KHTMLPart")){
925 w->setAutoMask(false);
926 }
927 }
928 if(w->inherits("QToolBar")){
929 w->removeEventFilter(this);
930 w->setBackgroundMode(QWidget::PaletteBackground);
931 return;
932 }
933 if(w->inherits("QHeader")){
934 w->setMouseTracking(false);
935 w->removeEventFilter(this);
936 }
937}
938
939void LiquidStyle::polish(QApplication *app)
940{
941
942 QWindowsStyle::polish(app);
943 menuAni = app->isEffectEnabled(UI_AnimateMenu);
944 menuFade = app->isEffectEnabled(UI_FadeMenu);
945 if(menuAni)
946 app->setEffectEnabled(UI_AnimateMenu, false);
947 if(menuFade)
948 app->setEffectEnabled(UI_FadeMenu, false);
949
950 qt_set_draw_menu_bar_impl((QDrawMenuBarItemImpl) &LiquidStyle::drawMenuBarItem);
951}
952
953void LiquidStyle::unPolish(QApplication *app)
954{
955 QWindowsStyle::unPolish(app);
956 app->setEffectEnabled(UI_AnimateMenu, menuAni);
957 app->setEffectEnabled(UI_FadeMenu, menuFade);
958
959 qt_set_draw_menu_bar_impl ( 0 );
960}
961
962/*
963 * This is a fun method ;-) Here's an overview. KToolBar grabs resize to
964 * force everything to erase and repaint on resize. This is going away, I'm
965 * trying to get shaped widgets to work right without masking. QPushButton,
966 * QComboBox, and Panel applet handles capture mouse enter and leaves in order
967 * to set the highlightwidget and repaint for mouse hovers. CheckBoxes and
968 * RadioButtons need to do this differently. Qt buffers these in pixmaps and
969 * caches them in QPixmapCache, which is bad for doing things like hover
970 * because the style methods aren't called in paintEvents if everything
971 * is cached. We use our own Paint event handler instead. Taskbuttons and
972 * pager buttons draw into a pixmap buffer, so we handle those with palette
973 * modifications. For QHeader, different header items are actually one widget
974 * that draws multiple items, so we need to check which ID is hightlighted
975 * and draw it. Finally, we also check enter and leave events for QLineEdit,
976 * since if it's inside a combobox we want to highlight the combobox during
977 * hovering in the edit.
978 */
979bool LiquidStyle::eventFilter(QObject *obj, QEvent *ev)
980{
981 if(obj->inherits("QToolBar")){
982 if(ev->type() == QEvent::Resize){
983 const QObjectList *tbChildList = obj->children();
984 QObjectListIt it(*tbChildList);
985 QObject *child;
986 while((child = it.current()) != NULL){
987 ++it;
988 if(child->isWidgetType())
989 ((QWidget *)child)->repaint(true);
990 }
991
992 }
993 }
994 else if(obj->inherits("QPushButton") || obj->inherits("QComboBox")){
995 QWidget *btn = (QWidget *)obj;
996 if(ev->type() == QEvent::Enter){
997 if(btn->isEnabled()){
998 highlightWidget = btn;
999 btn->repaint(false);
1000 }
1001 }
1002 else if(ev->type() == QEvent::Leave){
1003 if(btn == highlightWidget){
1004 highlightWidget = NULL;
1005 btn->repaint(false);
1006 }
1007 }
1008 }
1009 else if(obj->inherits("QToolButton")){
1010 QToolButton *btn = (QToolButton *)btn;
1011 if(!btn->autoRaise()){
1012 if(btn->isEnabled()){
1013 highlightWidget = btn;
1014 btn->repaint(false);
1015 }
1016 }
1017 else if(ev->type() == QEvent::Leave){
1018 QWidget *btn = (QWidget *)obj;
1019 if(btn == highlightWidget){
1020 highlightWidget = NULL;
1021 btn->repaint(false);
1022 }
1023 }
1024 else
1025 highlightWidget = NULL;
1026 }
1027 else if(obj->inherits("QScrollBar")){
1028 QScrollBar *sb = (QScrollBar *)obj;
1029 if(ev->type() == QEvent::Enter){
1030 if(sb->isEnabled()){
1031 highlightWidget = sb;
1032 sb->repaint(false);
1033 }
1034 }
1035 else if(ev->type() == QEvent::Leave){
1036 if(sb == highlightWidget && !sb->draggingSlider()){
1037 highlightWidget = NULL;
1038 sb->repaint(false);
1039 }
1040 }
1041 else if(ev->type() == QEvent::MouseButtonRelease){
1042 QMouseEvent *me = (QMouseEvent *)ev;
1043 if(sb == highlightWidget && !sb->rect().contains(me->pos())){
1044 highlightWidget = NULL;
1045 sb->repaint(false);
1046 }
1047 }
1048 }
1049 else if(obj->inherits("QLineEdit")){
1050 if(obj->parent() && obj->parent()->inherits("QComboBox")){
1051 QWidget *btn = (QComboBox *)obj->parent();
1052 if(ev->type() == QEvent::Enter){
1053 if (btn->isEnabled()){
1054 highlightWidget = btn;
1055 btn->repaint(false);
1056 }
1057 }
1058 else if(ev->type() == QEvent::Leave){
1059 if (btn == highlightWidget)
1060 highlightWidget = NULL;
1061 btn->repaint(false);
1062 }
1063 }
1064 }
1065 else if(obj->inherits("QRadioButton") || obj->inherits("QCheckBox")){
1066 QButton *btn = (QButton *)obj;
1067 bool isRadio = obj->inherits("QRadioButton");
1068 if(ev->type() == QEvent::Paint){
1069 //if(btn->autoMask())
1070 btn->erase();
1071 QPainter p;
1072 p.begin(btn);
1073 QFontMetrics fm = btn->fontMetrics();
1074 QSize lsz = fm.size(ShowPrefix, btn->text());
1075 QSize sz = isRadio ? exclusiveIndicatorSize()
1076 : indicatorSize();
1077
1078 if(btn->hasFocus()){
1079 QRect r = QRect(0, 0, btn->width(), btn->height());
1080 p.setPen(btn->colorGroup().button().dark(140));
1081 p.drawLine(r.x()+1, r.y(), r.right()-1, r.y());
1082 p.drawLine(r.x(), r.y()+1, r.x(), r.bottom()-1);
1083 p.drawLine(r.right(), r.y()+1, r.right(), r.bottom()-1);
1084 p.drawLine(r.x()+1, r.bottom(), r.right()-1, r.bottom());
1085 }
1086 int x = 0;
1087 int y = (btn->height()-lsz.height()+fm.height()-sz.height())/2;
1088 if(isRadio)
1089 drawExclusiveIndicator(&p, x, y, sz.width(), sz.height(),
1090 btn->colorGroup(), btn->isOn(),
1091 btn->isDown(), btn->isEnabled());
1092 else
1093 drawIndicator(&p, x, y, sz.width(), sz.height(),
1094 btn->colorGroup(), btn->state(), btn->isDown(),
1095 btn->isEnabled());
1096 x = sz.width() + 6;
1097 y = 0;
1098 drawItem(&p, sz.width()+6+1, 0, btn->width()-(sz.width()+6+1),
1099 btn->height(), AlignLeft|AlignVCenter|ShowPrefix,
1100 btn->colorGroup(), btn->isEnabled(),
1101 btn->pixmap(), btn->text());
1102 p.end();
1103 return(true);
1104 }
1105 // for hover, just redraw the indicator (not the text)
1106 else if((ev->type() == QEvent::Enter && btn->isEnabled()) ||
1107 (ev->type() == QEvent::Leave && btn == highlightWidget)){
1108 QButton *btn = (QButton *)obj;
1109 bool isRadio = obj->inherits("QRadioButton");
1110
1111 if(ev->type() == QEvent::Enter)
1112 highlightWidget = btn;
1113 else
1114 highlightWidget = NULL;
1115 QFontMetrics fm = btn->fontMetrics();
1116 QSize lsz = fm.size(ShowPrefix, btn->text());
1117 QSize sz = isRadio ? exclusiveIndicatorSize()
1118 : indicatorSize();
1119 int x = 0;
1120 int y = (btn->height()-lsz.height()+fm.height()-sz.height())/2;
1121 //if(btn->autoMask())
1122 // btn->erase(x+1, y+1, sz.width()-2, sz.height()-2);
1123 QPainter p;
1124 p.begin(btn);
1125 if(isRadio)
1126 drawExclusiveIndicator(&p, x, y, sz.width(), sz.height(),
1127 btn->colorGroup(), btn->isOn(),
1128 btn->isDown(), btn->isEnabled());
1129 else
1130 drawIndicator(&p, x, y, sz.width(), sz.height(),
1131 btn->colorGroup(), btn->state(), btn->isDown(),
1132 btn->isEnabled());
1133 p.end();
1134 }
1135 }
1136 else if(obj->inherits("QHeader")){
1137 QHeader *hw = (QHeader *)obj;
1138 if(ev->type() == QEvent::Enter){
1139 currentHeader = hw;
1140 headerHoverID = -1;
1141 }
1142 else if(ev->type() == QEvent::Leave){
1143 currentHeader = NULL;
1144 if(headerHoverID != -1){
1145 hw->repaint(hw->sectionPos(headerHoverID), 0,
1146 hw->sectionSize(headerHoverID), hw->height());
1147 }
1148 headerHoverID = -1;
1149 }
1150 else if(ev->type() == QEvent::MouseMove){
1151 QMouseEvent *me = (QMouseEvent *)ev;
1152 int oldHeader = headerHoverID;
1153 headerHoverID = hw->sectionAt(me->x());
1154 if(oldHeader != headerHoverID){
1155 // reset old header
1156 if(oldHeader != -1){
1157 hw->repaint(hw->sectionPos(oldHeader), 0,
1158 hw->sectionSize(oldHeader), hw->height());
1159 }
1160 if(headerHoverID != -1){
1161 hw->repaint(hw->sectionPos(headerHoverID), 0,
1162 hw->sectionSize(headerHoverID), hw->height());
1163 }
1164 }
1165 }
1166 }
1167 return(false);
1168}
1169
1170void LiquidStyle::drawButton(QPainter *p, int x, int y, int w, int h,
1171 const QColorGroup &g, bool sunken,
1172 const QBrush *)
1173{
1174 drawRoundButton(p, sunken ? g.background() : g.button(), g.background(),
1175 x, y, w, h);
1176}
1177
1178void LiquidStyle::drawToolButton(QPainter *p, int x, int y, int w, int h,
1179 const QColorGroup &g, bool sunken,
1180 const QBrush *)
1181{
1182 if(p->device()->devType() != QInternal::Widget){
1183 // drawing into a temp pixmap, don't use mask
1184 QColor c = sunken ? g.button() : g.background();
1185 p->setPen(c.dark(130));
1186 p->drawRect(x, y, w, h);
1187 p->setPen(c.light(105));
1188 p->drawRect(x+1, y+1, w-2, h-2);
1189
1190
1191 // fill
1192 QPixmap *pix = bevelFillDict.find(c.rgb());
1193 if(!pix){
1194 int h, s, v;
1195 c.hsv(&h, &s, &v);
1196 pix = new QPixmap(*bevelFillPix);
1197 adjustHSV(*pix, h, s, v);
1198 bevelFillDict.insert(c.rgb(), pix);
1199 }
1200
1201 p->drawTiledPixmap(x+2, y+2, w-4, h-4, *pix);
1202 }
1203 else{
1204 drawClearBevel(p, x, y, w, h, sunken ? g.button() :
1205 highlightWidget == p->device() ? g.button().light(110) :
1206 g.background(), g.background());
1207 }
1208}
1209
1210void LiquidStyle::drawPushButton(QPushButton *btn, QPainter *p)
1211{
1212 QRect r = btn->rect();
1213 bool sunken = btn->isOn() || btn->isDown();
1214 QColorGroup g = btn->colorGroup();
1215
1216
1217 //int dw = buttonDefaultIndicatorWidth();
1218 if(btn->hasFocus() || btn->isDefault()){
1219 QColor c = btn->hasFocus() ? g.button().light(110) : g.background();
1220 QPixmap *pix = bevelFillDict.find(c.rgb());
1221 if(!pix){
1222 int h, s, v;
1223 c.hsv(&h, &s, &v);
1224 pix = new QPixmap(*bevelFillPix);
1225 adjustHSV(*pix, h, s, v);
1226 bevelFillDict.insert(c.rgb(), pix);
1227 }
1228 p->setPen(c.dark(150));
1229 p->drawLine(r.x()+1, r.y(), r.right()-1, r.y());
1230 p->drawLine(r.x(), r.y()+1, r.x(), r.bottom()-1);
1231 p->drawLine(r.right(), r.y()+1, r.right(), r.bottom()-1);
1232 p->drawLine(r.x()+1, r.bottom(), r.right()-1, r.bottom());
1233 p->drawTiledPixmap(r.x()+1, r.y()+1, r.width()-2, r.height()-2, *pix);
1234 }
1235
1236 QColor newColor = btn == highlightWidget || sunken ?
1237 g.button().light(120) : g.button();
1238
1239 drawRoundButton(p, newColor, g.background(),
1240 r.x(), r.y(), r.width(), r.height(), !btn->autoMask(),
1241 sunken, btn->isDefault() || btn->autoDefault() || btn->hasFocus(),
1242 btn->autoMask());
1243}
1244
1245void LiquidStyle::drawPushButtonLabel(QPushButton *btn, QPainter *p)
1246{
1247 int x1, y1, x2, y2, w, h;
1248 btn->rect().coords(&x1, &y1, &x2, &y2);
1249 w = btn->width();
1250 h = btn->height();
1251
1252 bool act = btn->isOn() || btn->isDown();
1253 if(act){
1254 ++x1, ++y1;
1255 }
1256
1257 // Draw iconset first, if any
1258 if ( btn->iconSet() && !btn->iconSet()->isNull() )
1259 {
1260 QIconSet::Mode mode = btn->isEnabled()
1261 ? QIconSet::Normal : QIconSet::Disabled;
1262 if ( mode == QIconSet::Normal && btn->hasFocus() )
1263 mode = QIconSet::Active;
1264 QPixmap pixmap = btn->iconSet()->pixmap( QIconSet::Small, mode );
1265 int pixw = pixmap.width();
1266 int pixh = pixmap.height();
1267
1268 p->drawPixmap( x1+6, y1+h/2-pixh/2, pixmap );
1269 x1 += pixw + 8;
1270 w -= pixw + 8;
1271 }
1272
1273 if(act){
1274 QFont font = btn->font();
1275 font.setBold(true);
1276 p->setFont(font);
1277 QColor shadow(btn->colorGroup().button().dark(130));
1278 drawItem( p, x1+1, y1+1, w, h,
1279 AlignCenter | ShowPrefix, btn->colorGroup(), btn->isEnabled(),
1280 btn->pixmap(), btn->text(), -1,
1281 &shadow);
1282
1283 drawItem( p, x1, y1, w, h,
1284 AlignCenter | ShowPrefix, btn->colorGroup(), btn->isEnabled(),
1285 btn->pixmap(), btn->text(), -1, &btn->colorGroup().light());
1286 }
1287 else{
1288 /* Too blurry
1289 drawItem( p, x1+1, y1+1, w, h,
1290 AlignCenter | ShowPrefix, btn->colorGroup(), btn->isEnabled(),
1291 btn->pixmap(), btn->text(), -1,
1292 &btn->colorGroup().button().dark(115));
1293 */
1294 drawItem( p, x1, y1, w, h,
1295 AlignCenter | ShowPrefix,
1296 btn->colorGroup(), btn->isEnabled(),
1297 btn->pixmap(), btn->text(), -1,
1298 &btn->colorGroup().buttonText());
1299 }
1300}
1301
1302void LiquidStyle::drawButtonMask(QPainter *p, int x, int y, int w, int h)
1303{
1304 int x2 = x+w-1;
1305 int y2 = y+h-1;
1306
1307 p->setPen(Qt::color1);
1308 p->fillRect(x, y, w, h, Qt::color0);
1309 if(w < 21 || h < 21){
1310 // outer rect
1311 p->drawLine(x, y+2, x, y2-2); // l
1312 p->drawLine(x2, y+2, x2, y2-2); // r
1313 p->drawLine(x+2, y, x2-2, y); // t
1314 p->drawLine(x+2, y2, x2-2, y2); // b
1315 p->drawLine(x+1, y+1, x2-1, y+1); // top second line
1316 p->drawLine(x+1, y2-1, x2-1, y2-1); // bottom second line
1317 p->fillRect(x+1, y+2, w-2, h-4, Qt::color1);
1318 }
1319 else{
1320 int x2 = x+w-1;
1321 int y2 = y+h-1;
1322 int bx2 = htmlBtnMaskBmp.width()-1;
1323 int by2 = htmlBtnMaskBmp.height()-1;
1324 p->drawPixmap(0, 0, htmlBtnMaskBmp, 0, 0, 10, 10); // tl
1325 p->drawPixmap(x2-9, 0, htmlBtnMaskBmp, bx2-9, 0, 10, 10); // tr
1326 p->drawPixmap(0, y2-9, htmlBtnMaskBmp, 0, by2-9, 10, 10); // bl
1327 p->drawPixmap(x2-9, y2-9, htmlBtnMaskBmp, bx2-9, by2-9, 10, 10); // br
1328 // fills
1329 p->fillRect(10, 0, w-20, 10, Qt::color1); // top
1330 p->fillRect(10, y2-9, w-20, 10, Qt::color1); // bottom
1331 p->fillRect(0, 10, w, h-20, Qt::color1); // middle
1332 }
1333}
1334
1335void LiquidStyle::drawBevelButton(QPainter *p, int x, int y, int w, int h,
1336 const QColorGroup &g, bool sunken,
1337 const QBrush */*fill*/)
1338{
1339 if(currentHeader && p->device() == currentHeader){
1340 int id = currentHeader->sectionAt(x);
1341 bool isHeaderHover = id != -1 && id == headerHoverID;
1342 drawClearBevel(p, x, y, w, h, sunken ?
1343 g.button() : isHeaderHover ? g.button().light(110) :
1344 g.background(), g.background());
1345 }
1346 else
1347 drawClearBevel(p, x, y, w, h, sunken ? g.button() : g.background(),
1348 g.background());
1349}
1350
1351QRect LiquidStyle::buttonRect(int x, int y, int w, int h)
1352{
1353 return(QRect(x+5, y+5, w-10, h-10));
1354}
1355
1356void LiquidStyle::drawComboButton(QPainter *painter, int x, int y, int w, int h,
1357 const QColorGroup &g, bool sunken,
1358 bool edit, bool, const QBrush *)
1359{
1360 bool isHover = highlightWidget == painter->device();
1361 bool isMasked = false;
1362 if(painter->device()->devType() == QInternal::Widget)
1363 isMasked = ((QWidget*)painter->device())->autoMask();
1364 // TODO: Do custom code, don't just call drawRoundButton into a pixmap
1365 QPixmap tmpPix(w, h);
1366 QPainter p(&tmpPix);
1367
1368 drawRoundButton(&p, g.button(), g.background(), 0, 0, w, h, false,
1369 sunken, false, isMasked);
1370 if(!isHover){
1371 p.setClipRect(0, 0, w-17, h);
1372 drawRoundButton(&p, g.background(), g.background(), 0, 0, w, h, false,
1373 sunken, false, isMasked);
1374 }
1375 p.end();
1376 int x2 = x+w-1;
1377 int y2 = y+h-1;
1378 int bx2 = btnMaskBmp.width()-1;
1379 int by2 = btnMaskBmp.height()-1;
1380 QBitmap btnMask(w, h);
1381 QBitmap *mask = isMasked ? &htmlBtnMaskBmp : &btnMaskBmp;
1382 p.begin(&btnMask);
1383 p.fillRect(0, 0, w, h, Qt::color0);
1384 p.drawPixmap(0, 0, *mask, 0, 0, 10, 10); // tl
1385 p.drawPixmap(x2-9, 0, *mask, bx2-9, 0, 10, 10); // tr
1386 p.drawPixmap(0, y2-9, *mask, 0, by2-9, 10, 10); // bl
1387 p.drawPixmap(x2-9, y2-9, *mask, bx2-9, by2-9, 10, 10); // br
1388 // fills
1389 p.fillRect(10, 0, w-20, 10, Qt::color1); // top
1390 p.fillRect(10, y2-9, w-20, 10, Qt::color1); // bottom
1391 p.fillRect(0, 10, w, h-20, Qt::color1); // middle
1392 p.end();
1393 tmpPix.setMask(btnMask);
1394
1395 painter->drawPixmap(x, y, tmpPix);
1396
1397 painter->setPen(g.button().dark(120));
1398 painter->drawLine(x2-16, y+1, x2-16, y2-1);
1399
1400 if(edit){
1401 painter->setPen(g.mid());
1402 painter->drawRect(x+8, y+2, w-25, h-4);
1403 }
1404 int arrow_h = h / 3;
1405 int arrow_w = arrow_h;
1406 int arrow_x = w - arrow_w - 6;
1407 int arrow_y = (h - arrow_h) / 2;
1408 drawArrow(painter, DownArrow, false, arrow_x, arrow_y, arrow_w, arrow_h, g, true);
1409}
1410
1411void LiquidStyle::drawComboButtonMask(QPainter *p, int x, int y, int w, int h)
1412{
1413 drawButtonMask(p, x, y, w, h);
1414}
1415
1416QRect LiquidStyle::comboButtonRect(int x, int y, int w, int h)
1417{
1418 //return(QRect(x+3, y+3, w - (h / 3) - 13, h-6));
1419 return(QRect(x+9, y+3, w - (h / 3) - 20, h-6));
1420}
1421
1422QRect LiquidStyle::comboButtonFocusRect(int x, int y, int w, int h)
1423{
1424 return(QRect(x+5, y+3, w-(h/3)-13, h-5));
1425}
1426
1427void LiquidStyle::drawScrollBarControls(QPainter *p, const QScrollBar *sb,
1428 int sliderStart, uint controls,
1429 uint activeControl)
1430{
1431 bool isHover = highlightWidget == p->device();
1432 int sliderMin, sliderMax, sliderLength, buttonDim;
1433 scrollBarMetrics( sb, sliderMin, sliderMax, sliderLength, buttonDim );
1434
1435 if (sliderStart > sliderMax)
1436 sliderStart = sliderMax;
1437
1438 bool horiz = sb->orientation() == QScrollBar::Horizontal;
1439 QColorGroup g = sb->colorGroup();
1440 QRect addB, subHC, subB;
1441 QRect addPageR, subPageR, sliderR;
1442 int addX, addY, subX, subY;
1443 int len = horiz ? sb->width() : sb->height();
1444 int extent = horiz ? sb->height() : sb->width();
1445
1446 // a few apps (ie: KSpread), are broken and use a hardcoded scrollbar
1447 // extent of 16. Luckily, most apps (ie: Kate), seem fixed by now.
1448 bool brokenApp;
1449 if(extent == 16)
1450 brokenApp = true;
1451 else
1452 brokenApp = false;
1453
1454 if (horiz) {
1455 subY = addY = ( extent - buttonDim ) / 2;
1456 subX = 0;
1457 addX = len - buttonDim;
1458 if(sbBuffer.size() != sb->size())
1459 sbBuffer.resize(sb->size());
1460 }
1461 else {
1462 subX = addX = ( extent - buttonDim ) / 2;
1463 subY = 0;
1464 addY = len - buttonDim;
1465 if(sbBuffer.size() != sb->size())
1466 sbBuffer.resize(sb->size());
1467 }
1468 subB.setRect( subX,subY,buttonDim,buttonDim );
1469 addB.setRect( addX,addY,buttonDim,buttonDim );
1470 if(horiz)
1471 subHC.setRect(addX-buttonDim,addY,buttonDim,buttonDim );
1472 else
1473 subHC.setRect(addX,addY-buttonDim,buttonDim,buttonDim );
1474
1475 int sliderEnd = sliderStart + sliderLength;
1476 int sliderW = extent;
1477
1478 if (horiz) {
1479 subPageR.setRect( subB.right() + 1, 0,
1480 sliderStart - subB.right() - 1 , sliderW );
1481 addPageR.setRect( sliderEnd, 0, addX - sliderEnd - buttonDim, sliderW );
1482 sliderR .setRect( sliderStart, 0, sliderLength, sliderW );
1483 }
1484 else {
1485 subPageR.setRect( 0, subB.bottom() + 1, sliderW,
1486 sliderStart - subB.bottom() - 1 );
1487 addPageR.setRect( 0, sliderEnd, sliderW, addY - buttonDim - sliderEnd);
1488 sliderR .setRect( 0, sliderStart, sliderW, sliderLength );
1489 }
1490
1491 bool maxed = sb->maxValue() == sb->minValue();
1492
1493 QPainter painter;
1494 if(!horiz){
1495 painter.begin(&sbBuffer);
1496 QRect bgR(0, subB.bottom()+1, sb->width(), (len-(buttonDim*3))+1);
1497 if(sliderR.height() >= 8){
1498 painter.drawPixmap(bgR.x()+1, bgR.y(), *vsbSliderFillPix, 0, 0,
1499 13, 8);
1500 painter.drawPixmap(bgR.x()+1, bgR.y(), *getPixmap(VSBSliderTopBg));
1501 painter.drawTiledPixmap(bgR.x()+1, bgR.y()+8, 13,
1502 bgR.height()-16, *getPixmap(VSBSliderMidBg));
1503 painter.drawPixmap(bgR.x()+1, bgR.bottom()-8, *vsbSliderFillPix,
1504 0, 0, 13, 8);
1505 painter.drawPixmap(bgR.x()+1, bgR.bottom()-8, *getPixmap(VSBSliderBtmBg));
1506 }
1507 else{
1508 painter.drawTiledPixmap(bgR.x()+1, bgR.y(), 13, bgR.height(),
1509 *getPixmap(VSBSliderMidBg));
1510 painter.setPen(g.background().dark(210));
1511 painter.drawRect(bgR.x()+1, bgR.y(), 13, bgR.height()-1);
1512 painter.setPen(g.mid());
1513 painter.drawPoint(bgR.x()+1, bgR.y());
1514 painter.drawPoint(bgR.x()+13, bgR.y());
1515 painter.drawPoint(bgR.x()+1, bgR.bottom()-1);
1516 painter.drawPoint(bgR.x()+13, bgR.bottom()-1);
1517 }
1518 if(controls & Slider){
1519 if(sliderR.height() >= 16){
1520 painter.drawPixmap(sliderR.x()+1, sliderR.y(),
1521 isHover ? *getPixmap(VSBSliderTopHover):
1522 *getPixmap(VSBSliderTop));
1523 painter.drawTiledPixmap(sliderR.x()+1, sliderR.y()+8, 13,
1524 sliderR.height()-16, isHover ?
1525 *getPixmap(VSBSliderMidHover) :
1526 *getPixmap(VSBSliderMid));
1527 painter.drawPixmap(sliderR.x()+1, sliderR.bottom()-8,
1528 isHover ? *getPixmap(VSBSliderBtmHover) :
1529 *getPixmap(VSBSliderBtm));
1530 }
1531 else if(sliderR.height() >= 8){
1532 int m = sliderR.height()/2;
1533 painter.drawPixmap(sliderR.x()+1, sliderR.y(),
1534 isHover ? *getPixmap(VSBSliderTopHover):
1535 *getPixmap(VSBSliderTop), 0, 0, 13, m);
1536 painter.drawPixmap(sliderR.x()+1, sliderR.y()+m,
1537 isHover ? *getPixmap(VSBSliderBtmHover):
1538 *getPixmap(VSBSliderBtm), 0, 8-m, 13, m);
1539 }
1540 else{
1541 painter.setPen(g.button().dark(210));
1542 drawRoundRect(&painter, sliderR.x()+1, sliderR.y(),
1543 13, sliderR.height());
1544 painter.drawTiledPixmap(sliderR.x()+2, sliderR.y()+1,
1545 11, sliderR.height()-2,
1546 isHover ? *getPixmap(VSBSliderMidHover) :
1547 *getPixmap(VSBSliderMid), 1, 0);
1548 }
1549 }
1550 painter.setPen(g.mid());
1551 painter.drawLine(bgR.x(), bgR.y(), bgR.x(), bgR.bottom());
1552 painter.drawLine(bgR.right(), bgR.y(), bgR.right(), bgR.bottom());
1553 if(brokenApp && (controls & Slider)){
1554 painter.setPen(g.background());
1555 painter.drawLine(bgR.right()-1, bgR.y(), bgR.right()-1,
1556 bgR.bottom());
1557 }
1558 painter.end();
1559 }
1560 else{
1561 painter.begin(&sbBuffer);
1562 QRect bgR(subB.right()+1, 0, (len-(buttonDim*3))+1, sb->height());
1563 if(sliderR.width() >= 8){
1564 painter.drawPixmap(bgR.x(), bgR.y()+1, *vsbSliderFillPix, 0, 0,
1565 8, 13);
1566 painter.drawPixmap(bgR.x(), bgR.y()+1, *getPixmap(HSBSliderTopBg));
1567 painter.drawTiledPixmap(bgR.x()+8, bgR.y()+1, bgR.width()-16,
1568 13, *getPixmap(HSBSliderMidBg));
1569 painter.drawPixmap(bgR.right()-8, bgR.y()+1, *vsbSliderFillPix,
1570 0, 0, 8, 13);
1571 painter.drawPixmap(bgR.right()-8, bgR.y()+1, *getPixmap(HSBSliderBtmBg));
1572 }
1573 else{
1574 painter.drawTiledPixmap(bgR.x(), bgR.y()+1, bgR.width(), 13,
1575 *getPixmap(HSBSliderMidBg));
1576 painter.setPen(g.background().dark(210));
1577 painter.drawRect(bgR.x(), bgR.y()+1, bgR.width()-1, 13);
1578 painter.setPen(g.mid());
1579 painter.drawPoint(bgR.x(), bgR.y()+1);
1580 painter.drawPoint(bgR.x(), bgR.bottom()-1);
1581 painter.drawPoint(bgR.right()-1, bgR.y()+1);
1582 painter.drawPoint(bgR.right()-1, bgR.bottom()-1);
1583 }
1584 if(controls & Slider){
1585 if(sliderR.width() >= 16){
1586 painter.drawPixmap(sliderR.x(), sliderR.y()+1,
1587 isHover ? *getPixmap(HSBSliderTopHover) :
1588 *getPixmap(HSBSliderTop));
1589 painter.drawTiledPixmap(sliderR.x()+8, sliderR.y()+1, sliderR.width()-16,
1590 13, isHover ? *getPixmap(HSBSliderMidHover) :
1591 *getPixmap(HSBSliderMid));
1592 painter.drawPixmap(sliderR.right()-8, sliderR.y()+1, isHover ?
1593 *getPixmap(HSBSliderBtmHover) :
1594 *getPixmap(HSBSliderBtm));
1595 }
1596 else if(sliderR.width() >= 8){
1597 int m = sliderR.width()/2;
1598 painter.drawPixmap(sliderR.x(), sliderR.y()+1,
1599 isHover ? *getPixmap(HSBSliderTopHover) :
1600 *getPixmap(HSBSliderTop), 0, 0, m, 13);
1601 painter.drawPixmap(sliderR.right()-8, sliderR.y()+1, isHover ?
1602 *getPixmap(HSBSliderBtmHover) :
1603 *getPixmap(HSBSliderBtm), 8-m, 0, m, 13);
1604 }
1605 else{
1606 painter.setPen(g.button().dark(210));
1607 drawRoundRect(&painter, sliderR.x(), sliderR.y()+1,
1608 sliderR.width(), 13);
1609 painter.drawTiledPixmap(sliderR.x()+1, sliderR.y()+2,
1610 sliderR.width()-2, 11, isHover ?
1611 *getPixmap(HSBSliderMidHover) :
1612 *getPixmap(HSBSliderMid), 0, 1);
1613 }
1614 }
1615 painter.setPen(g.mid());
1616 painter.drawLine(bgR.x(), bgR.y(), bgR.right(), bgR.y());
1617 painter.drawLine(bgR.x(), bgR.bottom(), bgR.right(), bgR.bottom());
1618 if(brokenApp && (controls & Slider)){
1619 painter.setPen(g.background());
1620 painter.drawLine(bgR.x(), bgR.bottom()-1, bgR.right(),
1621 bgR.bottom()-1);
1622 }
1623 painter.end();
1624 }
1625
1626 if ( controls & AddLine ) {
1627 drawSBButton(p, addB, g, activeControl == AddLine);
1628 drawArrow( p, horiz ? RightArrow : DownArrow,
1629 false, addB.x()+4, addB.y()+4,
1630 addB.width()-8, addB.height()-8, g, !maxed);
1631 }
1632 if ( controls & SubLine ) {
1633 drawSBButton(p, subB, g, activeControl == SubLine);
1634 drawArrow( p, horiz ? LeftArrow : UpArrow,
1635 false, subB.x()+4, subB.y()+4,
1636 subB.width()-8, subB.height()-8, g, !maxed);
1637 drawSBButton(p, subHC, g, activeControl == SubLine);
1638 drawArrow( p, horiz ? LeftArrow : UpArrow,
1639 false, subHC.x()+4, subHC.y()+4,
1640 subHC.width()-8, subHC.height()-8, g, !maxed);
1641 }
1642
1643 if(controls & AddPage){
1644 if(addPageR.width()){
1645 p->drawPixmap(addPageR.x(), addPageR.y(), sbBuffer,
1646 addPageR.x(), addPageR.y(), addPageR.width(),
1647 addPageR.height());
1648 }
1649 }
1650 if(controls & SubPage){
1651 if(subPageR.height()){
1652 p->drawPixmap(subPageR.x(), subPageR.y(), sbBuffer,
1653 subPageR.x(), subPageR.y(), subPageR.width(),
1654 subPageR.height());
1655 }
1656 }
1657 if ( controls & Slider ) {
1658 p->drawPixmap(sliderR.x(), sliderR.y(), sbBuffer,
1659 sliderR.x(), sliderR.y(), sliderR.width(),
1660 sliderR.height());
1661 }
1662}
1663
1664void LiquidStyle::drawSBButton(QPainter *p, const QRect &r, const QColorGroup &g,
1665 bool down, bool /*fast*/)
1666{
1667 p->setPen(g.mid());
1668 p->drawRect(r);
1669 QColor c(down ? g.button() : g.background());
1670 QPixmap *pix = bevelFillDict.find(c.rgb());
1671 if(!pix){
1672 int h, s, v;
1673 c.hsv(&h, &s, &v);
1674 pix = new QPixmap(*bevelFillPix);
1675 adjustHSV(*pix, h, s, v);
1676 bevelFillDict.insert(c.rgb(), pix);
1677 }
1678 p->drawTiledPixmap(r.x()+1, r.y()+1, r.width()-2, r.height()-2, *pix);
1679
1680}
1681
1682void LiquidStyle::drawSBDeco(QPainter *p, const QRect &r, const QColorGroup &g,
1683 bool horiz)
1684{
1685 if(horiz){
1686 if(r.width() >= 15){
1687 int y = r.y()+3;
1688 int x = r.x() + (r.width()-7)/2;
1689 int y2 = r.bottom()-3;
1690 p->setPen(g.light());
1691 p->drawLine(x, y, x, y2);
1692 p->drawLine(x+3, y, x+3, y2);
1693 p->drawLine(x+6, y, x+6, y2);
1694
1695 p->setPen(g.mid());
1696 p->drawLine(x+1, y, x+1, y2);
1697 p->drawLine(x+4, y, x+4, y2);
1698 p->drawLine(x+7, y, x+7, y2);
1699 }
1700 }
1701 else{
1702 if(r.height() >= 15){
1703 int x = r.x()+3;
1704 int y = r.y() + (r.height()-7)/2;
1705 int x2 = r.right()-3;
1706 p->setPen(g.light());
1707 p->drawLine(x, y, x2, y);
1708 p->drawLine(x, y+3, x2, y+3);
1709 p->drawLine(x, y+6, x2, y+6);
1710
1711 p->setPen(g.mid());
1712 p->drawLine(x, y+1, x2, y+1);
1713 p->drawLine(x, y+4, x2, y+4);
1714 p->drawLine(x, y+7, x2, y+7);
1715 }
1716 }
1717
1718}
1719
1720
1721void LiquidStyle::scrollBarMetrics(const QScrollBar *sb, int &sliderMin,
1722 int &sliderMax, int &sliderLength,
1723 int &buttonDim)
1724{
1725
1726 int maxLength;
1727 int b = 0;
1728 bool horiz = sb->orientation() == QScrollBar::Horizontal;
1729 int length = horiz ? sb->width() : sb->height();
1730 int extent = horiz ? sb->height() : sb->width();
1731
1732 if ( length > ( extent - b*2 - 1 )*2 + b*2 )
1733 buttonDim = extent - b*2;
1734 else
1735 buttonDim = ( length - b*2 )/2 - 1;
1736
1737 sliderMin = b + buttonDim;
1738 maxLength = length - b*2 - buttonDim*3;
1739
1740 if ( sb->maxValue() == sb->minValue() ) {
1741 sliderLength = maxLength;
1742 } else {
1743 sliderLength = (sb->pageStep()*maxLength)/
1744 (sb->maxValue()-sb->minValue()+sb->pageStep());
1745 uint range = sb->maxValue()-sb->minValue();
1746 if ( sliderLength < 9 || range > INT_MAX/2 )
1747 sliderLength = 9;
1748 if ( sliderLength > maxLength )
1749 sliderLength = maxLength;
1750 }
1751 sliderMax = sliderMin + maxLength - sliderLength;
1752
1753}
1754
1755QStyle::ScrollControl LiquidStyle::scrollBarPointOver(const QScrollBar *sb,
1756 int sliderStart,
1757 const QPoint &p)
1758{
1759 if ( !sb->rect().contains( p ) )
1760 return NoScroll;
1761 int sliderMin, sliderMax, sliderLength, buttonDim, pos;
1762 scrollBarMetrics( sb, sliderMin, sliderMax, sliderLength, buttonDim );
1763 pos = (sb->orientation() == QScrollBar::Horizontal)? p.x() : p.y();
1764 if ( pos < sliderMin )
1765 return SubLine;
1766 if ( pos < sliderStart )
1767 return SubPage;
1768 if ( pos < sliderStart + sliderLength )
1769 return Slider;
1770 if ( pos < sliderMax + sliderLength)
1771 return AddPage;
1772 if(pos > sliderMax + sliderLength + 16)
1773 return AddLine;
1774
1775 return SubLine;
1776}
1777
1778#define QCOORDARRLEN(x) sizeof(x)/(sizeof(QCOORD)*2)
1779
1780
1781QSize LiquidStyle::exclusiveIndicatorSize() const
1782{
1783 return(QSize(16, 16));
1784}
1785
1786void LiquidStyle::drawExclusiveIndicator(QPainter *p, int x, int y, int w,
1787 int h, const QColorGroup &g, bool on,
1788 bool down, bool)
1789{
1790 bool isHover = highlightWidget == p->device();
1791 bool isMasked = p->device() && p->device()->devType() == QInternal::Widget
1792 && ((QWidget*)p->device())->autoMask();
1793
1794 if(isMasked){
1795 if(on || down){
1796 p->drawPixmap(x, y, isHover ? *getPixmap(HTMLRadioDownHover) :
1797 *getPixmap(HTMLRadioDown));
1798 }
1799 else
1800 p->drawPixmap(x, y, isHover ? *getPixmap(HTMLRadioHover) :
1801 *getPixmap(HTMLRadio));
1802
1803 }
1804 else{
1805 if(on || down){
1806 p->drawPixmap(x, y, isHover ? *getPixmap(RadioOnHover) :
1807 *getPixmap(RadioOn));
1808 }
1809 else
1810 p->drawPixmap(x, y, isHover ? *getPixmap(RadioOffHover) :
1811 *getPixmap(RadioOff));
1812 }
1813}
1814
1815void LiquidStyle::drawExclusiveIndicatorMask(QPainter *p, int x, int y, int w,
1816 int h, bool)
1817{
1818 p->fillRect(x, y, w, h, Qt::color0);
1819 p->setPen(Qt::color1);
1820 p->drawPixmap(x, y, *getPixmap(RadioOn)->mask());
1821}
1822
1823
1824QSize LiquidStyle::indicatorSize() const
1825{
1826 return(QSize(20, 22));
1827}
1828
1829void LiquidStyle::drawIndicator(QPainter *p, int x, int y, int w, int h,
1830 const QColorGroup &g, int state, bool down, bool)
1831{
1832 bool isHover = highlightWidget == p->device();
1833 bool isMasked = p->device() && p->device()->devType() == QInternal::Widget
1834 && ((QWidget*)p->device())->autoMask();
1835 if(isMasked){
1836 if(state != QButton::Off){
1837 p->drawPixmap(x, y, isHover ? *getPixmap(HTMLCBDownHover) :
1838 *getPixmap(HTMLCBDown));
1839 }
1840 else
1841 p->drawPixmap(x, y, isHover ? *getPixmap(HTMLCBHover) :
1842 *getPixmap(HTMLCB));
1843
1844 }
1845 else{
1846 if(state != QButton::Off){
1847 p->drawPixmap(x, y, isHover ? *getPixmap(CBDownHover) :
1848 *getPixmap(CBDown));
1849 /* Todo - tristate
1850 if(state == QButton::On){
1851 p->setPen(Qt::black);
1852 p->drawPixmap(3, 3, xBmp);
1853 }
1854 else{
1855 p->setPen(g.dark());
1856 p->drawRect(x+2, y+2, w-4, h-4);
1857 p->setPen(Qt::black);
1858 p->drawLine(x+3, (y+h)/2-2, x+w-4, (y+h)/2-2);
1859 p->drawLine(x+3, (y+h)/2, x+w-4, (y+h)/2);
1860 p->drawLine(x+3, (y+h)/2+2, x+w-4, (y+h)/2+2);
1861 }*/
1862 }
1863 else
1864 p->drawPixmap(x, y, isHover ? *getPixmap(CBHover) : *getPixmap(CB));
1865 }
1866}
1867
1868void LiquidStyle::drawIndicatorMask(QPainter *p, int x, int y, int w, int h,
1869 int state)
1870{
1871 // needed for some reason by KHtml, even tho it's all filled ;P
1872 p->drawPixmap(x, y, *getPixmap(HTMLCB)->mask());
1873
1874}
1875
1876void LiquidStyle::drawSlider(QPainter *p, int x, int y, int w, int h,
1877 const QColorGroup &g, Orientation orient,
1878 bool, bool)
1879{
1880 QWidget *parent = (QWidget *)p->device();
1881 p->setBrushOrigin(parent->pos());
1882 p->fillRect(x, y, w, h,
1883 QApplication::palette().active().brush(QColorGroup::Background));
1884 p->drawPixmap(x, y, orient == Qt::Horizontal ? *getPixmap(HSlider) :
1885 *getPixmap(VSlider));
1886}
1887
1888void LiquidStyle::drawSliderMask(QPainter *p, int x, int y, int w, int h,
1889 Orientation orient, bool, bool)
1890{
1891 p->drawPixmap(x, y, orient == Qt::Horizontal ? *getPixmap(HSlider)->mask() :
1892 *getPixmap(VSlider)->mask());
1893}
1894
1895int LiquidStyle::sliderLength() const
1896{
1897 return(10);
1898}
1899
1900#define QCOORDARRLEN(x) sizeof(x)/(sizeof(QCOORD)*2)
1901
1902void LiquidStyle::drawArrow(QPainter *p, Qt::ArrowType type, bool on, int x,
1903 int y, int w, int h, const QColorGroup &g,
1904 bool enabled, const QBrush *)
1905{
1906 static const QCOORD u_arrow[]={3,1, 4,1, 2,2, 5,2, 1,3, 6,3, 0,4, 7,4, 0,5, 7,5};
1907 static const QCOORD d_arrow[]={0,2, 7,2, 0,3, 7,3, 1,4, 6,4, 2,5, 5,5, 3,6, 4,6};
1908 static const QCOORD l_arrow[]={1,3, 1,4, 2,2, 2,5, 3,1, 3,6, 4,0, 4,7, 5,0, 5,7};
1909 static const QCOORD r_arrow[]={2,0, 2,7, 3,0, 3,7, 4,1, 4,6, 5,2, 5,5, 6,3, 6,4};
1910
1911 p->setPen(enabled ? on ? g.light() : g.buttonText() : g.mid());
1912 if(w > 8){
1913 x = x + (w-8)/2;
1914 y = y + (h-8)/2;
1915 }
1916
1917 QPointArray a;
1918 switch(type){
1919 case Qt::UpArrow:
1920 a.setPoints(QCOORDARRLEN(u_arrow), u_arrow);
1921 break;
1922 case Qt::DownArrow:
1923 a.setPoints(QCOORDARRLEN(d_arrow), d_arrow);
1924 break;
1925 case Qt::LeftArrow:
1926 a.setPoints(QCOORDARRLEN(l_arrow), l_arrow);
1927 break;
1928 default:
1929 a.setPoints(QCOORDARRLEN(r_arrow), r_arrow);
1930 break;
1931 }
1932
1933 a.translate(x, y);
1934 p->drawLineSegments(a);
1935}
1936
1937
1938void LiquidStyle::drawMenuBarItem(QPainter *p, int x, int y, int w, int h,
1939 QMenuItem *mi, QColorGroup &g, bool enabled, bool active )
1940 {
1941 x -= 2; // Bug in Qt/E
1942 y -= 2;
1943 w += 2;
1944 h += 2;
1945
1946 p-> fillRect ( x, y, w, h, g.brush(QColorGroup::Background));
1947
1948 w -= 2;
1949
1950 if(menuHandler->useShadowText()){
1951 QColor shadow;
1952 if(p->device() && p->device()->devType() == QInternal::Widget &&
1953 ((QWidget *)p->device())->inherits("QMenuBar")){
1954 shadow = ((QMenuBar*)p->device())->isTopLevel() ? g.button().dark(130) :
1955 g.background().dark(130);
1956 }
1957 else
1958 shadow = g.background().dark(130);
1959
1960 if(active){
1961 drawClearBevel(p, x+1, y+1, w-1, h-1, g.button(), g.background());
1962 QApplication::style().drawItem(p, x+1, y+1, w, h,
1963 AlignCenter|ShowPrefix|DontClip|SingleLine,
1964 g, mi->isEnabled(), NULL, mi->text(),
1965 -1, &shadow);
1966 QApplication::style().drawItem(p, x, y, w, h,
1967 AlignCenter|ShowPrefix|DontClip|SingleLine,
1968 g, mi->isEnabled(), NULL, mi->text(),
1969 -1, &g.text());
1970 }
1971 else{
1972 QApplication::style().drawItem(p, x+1, y+1, w, h,
1973 AlignCenter|ShowPrefix|DontClip|SingleLine,
1974 g, mi->isEnabled(), NULL, mi->text(),
1975 -1, &shadow);
1976 QApplication::style().drawItem(p, x, y, w, h,
1977 AlignCenter|ShowPrefix|DontClip|SingleLine,
1978 g, mi->isEnabled(), NULL, mi->text(),
1979 -1, &g.text());
1980 }
1981 }
1982 else{
1983 if(active)
1984 drawClearBevel(p, x+1, y+1, w-1, h-1, g.button(), g.background());
1985 QApplication::style().drawItem(p, x, y, w, h,
1986 AlignCenter|ShowPrefix|DontClip|SingleLine,
1987 g, mi->isEnabled(), NULL, mi->text(),
1988 -1, &g.text());
1989 }
1990}
1991
1992void LiquidStyle::drawPopupPanel(QPainter *p, int x, int y, int w, int h,
1993 const QColorGroup &g, int lineWidth,
1994 const QBrush * fill)
1995{
1996 QColor c;
1997 switch(menuHandler->transType()){
1998 case None:
1999 case StippledBg:
2000 case TransStippleBg:
2001 c = g.background();
2002 break;
2003 case StippledBtn:
2004 case TransStippleBtn:
2005 c = g.button();
2006 break;
2007 default:
2008 c = menuHandler->bgColor();
2009 }
2010 p->setPen(c.dark(140));
2011 p->drawRect(x, y, w, h);
2012 p->setPen(c.light(120));
2013 p->drawRect(x+1, y+1, w-2, h-2);
2014}
2015
2016void LiquidStyle::drawPopupMenuItem( QPainter* p, bool checkable, int maxpmw,
2017 int tab, QMenuItem* mi,
2018 const QPalette& pal, bool act,
2019 bool enabled, int x, int y, int w, int h)
2020{
2021static const int motifItemFrame = 2;
2022static const int motifItemHMargin = 3;
2023static const int motifItemVMargin = 2;
2024static const int motifArrowHMargin = 6;
2025static const int windowsRightBorder = 12;
2026
2027 maxpmw = QMAX( maxpmw, 20 );
2028
2029
2030 bool dis = !enabled;
2031 QColorGroup itemg = dis ? pal.disabled() : pal.active();
2032
2033 int checkcol = maxpmw;
2034 if(act){
2035
2036 // FIXME
2037 drawClearBevel(p, x, y, w, h, itemg.button(), itemg.background());
2038 }
2039 //else if(((QWidget*)p->device())->backgroundPixmap()){
2040 // p->drawPixmap(x, y, *((QWidget*)p->device())->backgroundPixmap(),
2041 // x, y, w, h);
2042 //}
2043 else{
2044 if(menuHandler->transType() == None){
2045 p->fillRect(x, y, w, h, pal.active().background());
2046 }
2047 else if(menuHandler->transType() == StippledBg){
2048 p->fillRect(x, y, w, h, bgBrush);
2049 }
2050 else if(menuHandler->transType() == StippledBtn){
2051 p->fillRect(x, y, w, h, menuBrush);
2052 }
2053 else{
2054 QPixmap *pix = menuHandler->pixmap(((QWidget*)p->device())->winId());
2055 if(pix)
2056 p->drawPixmap(x, y, *pix, x, y, w, h);
2057 }
2058 }
2059
2060 if(!mi)
2061 return;
2062
2063 QColor discol;
2064 if (dis) {
2065 discol = itemg.mid();
2066 p->setPen(discol);
2067 }
2068
2069 QColorGroup cg2(itemg);
2070
2071 if(menuHandler->transType() == Custom){
2072 cg2.setColor(QColorGroup::Foreground, menuHandler->textColor());
2073 cg2.setColor(QColorGroup::Text, menuHandler->textColor());
2074 cg2.setColor(QColorGroup::Light, menuHandler->textColor().light(120));
2075 cg2.setColor(QColorGroup::Mid, menuHandler->textColor().dark(120));
2076 }
2077 else{
2078 cg2 = QColorGroup(discol, itemg.highlight(), black, black,
2079 dis ? discol : black, discol, black);
2080 }
2081
2082 if(mi->isSeparator()){
2083 QColor c;
2084 switch(menuHandler->transType()){
2085 case None:
2086 case StippledBg:
2087 case TransStippleBg:
2088 c = QApplication::palette().active().background();
2089 break;
2090 case StippledBtn:
2091 case TransStippleBtn:
2092 c = QApplication::palette().active().button();
2093 break;
2094 default:
2095 c = menuHandler->bgColor();
2096 }
2097 p->setPen(c.dark(140));
2098 p->drawLine(x, y, x+w, y );
2099 p->setPen(c.light(115));
2100 p->drawLine(x, y+1, x+w, y+1 );
2101 return;
2102 }
2103 if(mi->iconSet()) {
2104 QIconSet::Mode mode = dis? QIconSet::Disabled : QIconSet::Normal;
2105 if (!dis)
2106 mode = QIconSet::Active;
2107 QPixmap pixmap = mi->iconSet()->pixmap(QIconSet::Small, mode);
2108 int pixw = pixmap.width();
2109 int pixh = pixmap.height();
2110 QRect cr(x, y, checkcol, h);
2111 QRect pmr(0, 0, pixw, pixh);
2112 pmr.moveCenter( cr.center() );
2113 p->setPen(itemg.highlightedText());
2114 p->drawPixmap(pmr.topLeft(), pixmap );
2115
2116 }
2117 else if(checkable) {
2118 int mw = checkcol + motifItemFrame;
2119 int mh = h - 2*motifItemFrame;
2120 if (mi->isChecked()){
2121 drawCheckMark( p, x + motifItemFrame,
2122 y+motifItemFrame, mw, mh, cg2, act, dis );
2123 }
2124 }
2125 if(menuHandler->transType() == Custom)
2126 p->setPen(menuHandler->textColor());
2127 else
2128 p->setPen(itemg.text());
2129
2130
2131 int xm = motifItemFrame + checkcol + motifItemHMargin;
2132 QString s = mi->text();
2133 if (!s.isNull()) {
2134 int t = s.find( '\t' );
2135 int m = motifItemVMargin;
2136 const int text_flags = AlignVCenter|ShowPrefix | DontClip | SingleLine;
2137 QPen oldPen = p->pen();
2138 if(menuHandler->useShadowText()){
2139 if(menuHandler->transType() == Custom)
2140 p->setPen(menuHandler->bgColor().dark(130));
2141 else if(menuHandler->transType() == StippledBtn ||
2142 menuHandler->transType() == TransStippleBtn)
2143 p->setPen(itemg.button().dark(130));
2144 else
2145 p->setPen(bgBrush.color().dark(130));
2146
2147 if (t >= 0) {
2148 p->drawText(x+w-tab-windowsRightBorder-motifItemHMargin-motifItemFrame+2,
2149 y+m+2, tab-1, h-2*m-1, text_flags, s.mid( t+1 ));
2150 }
2151 p->drawText(x+xm+1, y+m+1, w-xm-tab, h-2*m-1, text_flags, s, t);
2152 }
2153 p->setPen(oldPen);
2154 if (t >= 0) {
2155 p->drawText(x+w-tab-windowsRightBorder-motifItemHMargin-motifItemFrame+1,
2156 y+m+1, tab, h-2*m, text_flags, s.mid( t+1 ));
2157 }
2158 p->drawText(x+xm, y+m, w-xm-tab+1, h-2*m, text_flags, s, t);
2159
2160 }
2161 else if (mi->pixmap()) {
2162 QPixmap *pixmap = mi->pixmap();
2163 if (pixmap->depth() == 1)
2164 p->setBackgroundMode(OpaqueMode);
2165 p->drawPixmap( x+xm, y+motifItemFrame, *pixmap);
2166 if (pixmap->depth() == 1)
2167 p->setBackgroundMode(TransparentMode);
2168 }
2169 if (mi->popup()) {
2170 int dim = (h-2*motifItemFrame) / 2;
2171 drawArrow(p, RightArrow, true,
2172 x+w - motifArrowHMargin - motifItemFrame - dim, y+h/2-dim/2,
2173 dim, dim, cg2, TRUE);
2174 }
2175}
2176
2177int LiquidStyle::popupMenuItemHeight(bool /*checkable*/, QMenuItem *mi,
2178 const QFontMetrics &fm)
2179{
2180 if (mi->isSeparator())
2181 return 2;
2182
2183 int h = 0;
2184 if (mi->pixmap())
2185 h = mi->pixmap()->height();
2186
2187 if (mi->iconSet())
2188 h = QMAX(mi->iconSet()->
2189 pixmap(QIconSet::Small, QIconSet::Normal).height(), h);
2190
2191 h = QMAX(fm.height() + 4, h);
2192
2193 // we want a minimum size of 18
2194 h = QMAX(h, 18);
2195
2196 return h;
2197}
2198
2199
2200void LiquidStyle::drawFocusRect(QPainter *p, const QRect &r,
2201 const QColorGroup &g, const QColor *c,
2202 bool atBorder)
2203{
2204 // are we painting a widget?
2205 if(p->device()->devType() == QInternal::Widget){
2206 // if so does it use a special focus rectangle?
2207 QWidget *w = (QWidget *)p->device();
2208 if(w->inherits("QPushButton") || w->inherits("QSlider")){
2209 return;
2210 }
2211 else{
2212 QWindowsStyle::drawFocusRect(p, r, g, c, atBorder);
2213 }
2214 }
2215 else
2216 QWindowsStyle::drawFocusRect(p, r, g, c, atBorder);
2217
2218}
2219
2220void LiquidStyle::polishPopupMenu(QPopupMenu *mnu)
2221{
2222 mnu->installEventFilter(menuHandler);
2223 QWindowsStyle::polishPopupMenu(mnu);
2224}
2225
2226void LiquidStyle::drawTab(QPainter *p, const QTabBar *tabBar, QTab *tab,
2227 bool selected)
2228{
2229 if(tabBar->shape() != QTabBar::RoundedAbove){
2230 QWindowsStyle::drawTab(p, tabBar, tab, selected);
2231 return;
2232 }
2233 QPixmap tilePix;
2234 QRect r = tab->rect();
2235 //QPixmap *pix = selected ? tabBar->hasFocus() ? pixmaps[TabFocus] :
2236 // pixmaps[TabDown] : pixmaps[Tab];
2237
2238 QPixmap *pix = selected ? getPixmap(TabDown) : getPixmap(Tab);
2239 p->drawPixmap(r.x(), r.y(), *pix, 0, 0, 9, r.height());
2240 p->drawPixmap(r.right()-9, r.y(), *pix, pix->width()-9, 0, 9, r.height());
2241 tilePix.resize(pix->width()-18, r.height());
2242 bitBlt(&tilePix, 0, 0, pix, 9, 0, pix->width()-18, r.height());
2243 p->drawTiledPixmap(r.x()+9, r.y(), r.width()-18, r.height(), tilePix);
2244 QColor c = tabBar->colorGroup().button();
2245 if(!selected){
2246 p->setPen(c.dark(130));
2247 p->drawLine(r.x(), r.bottom(), r.right(), r.bottom());
2248 }
2249
2250 /*
2251 p->setPen(c.light(110));
2252 p->drawLine(r.x(), r.bottom()+1, r.right(), r.bottom()+1);
2253 p->setPen(c);
2254 p->drawLine(r.x(), r.bottom()+2, r.right(), r.bottom()+2);
2255 p->setPen(c.light(110));
2256 p->drawLine(r.x(), r.bottom()+3, r.right(), r.bottom()+3);
2257 p->setPen(c.light(120));
2258 p->drawLine(r.x(), r.bottom()+4, r.right(), r.bottom()+4);
2259 */
2260
2261 /*
2262 QColor c = tabBar->colorGroup().button();
2263 pix = bevelFillDict.find(c.rgb());
2264 if(!pix){
2265 int h, s, v;
2266 c.hsv(&h, &s, &v);
2267 pix = new QPixmap(*bevelFillPix);
2268 adjustHSV(*pix, h, s);
2269 bevelFillDict.insert(c.rgb(), pix);
2270 }*/
2271
2272 /*
2273 QRect r = tab->rect();
2274 QColorGroup g = tabBar->colorGroup();
2275 if(!selected){
2276 r.setY(r.y()+1);
2277 p->setPen(g.dark());
2278 p->drawLine(r.x(), r.y()+4, r.x(), r.bottom()-2);
2279 p->drawLine(r.x(), r.y()+4, r.x()+4, r.y());
2280 p->drawLine(r.x()+4, r.y(), r.right()-1, r.y());
2281 p->drawLine(r.right(), r.y()+1, r.right(), r.bottom()-2);
2282
2283 p->setPen(g.midlight());
2284 p->drawLine(r.x()+1, r.y()+4, r.x()+1, r.bottom());
2285 p->drawLine(r.x()+1, r.y()+4, r.x()+4, r.y()+1);
2286 p->drawLine(r.x()+5, r.y()+1, r.right()-2, r.y()+1);
2287 p->drawLine(r.x(), r.bottom(), r.right(), r.bottom());
2288
2289 p->setPen(g.mid());
2290 p->drawPoint(r.right()-1, r.y()+1);
2291 p->drawLine(r.x()+4, r.y()+2, r.right()-1, r.y()+2);
2292 p->drawLine(r.x()+3, r.y()+3, r.right()-1, r.y()+3);
2293
2294 p->fillRect(r.x()+2, r.y()+4, r.width()-3, r.height()-6,
2295 g.brush(QColorGroup::Mid));
2296
2297 p->setPen(g.light());
2298 p->drawLine(r.x(), r.bottom()-1, r.right(), r.bottom()-1);
2299
2300 }
2301 else{
2302 p->setPen(g.light());
2303 p->drawLine(r.x(), r.y()+4, r.x(), r.bottom());
2304 p->drawLine(r.x(), r.y()+4, r.x()+4, r.y());
2305 p->drawLine(r.x()+4, r.y(), r.right()-1, r.y());
2306 p->setPen(g.dark());
2307 p->drawLine(r.right(), r.y()+1, r.right(), r.bottom());
2308
2309 p->setPen(g.midlight());
2310 p->drawLine(r.x()+1, r.y()+4, r.x()+1, r.bottom());
2311 p->drawLine(r.x()+1, r.y()+4, r.x()+4, r.y()+1);
2312 p->drawLine(r.x()+5, r.y()+1, r.right() - 2, r.y()+1);
2313 p->setPen(g.mid());
2314 p->drawLine(r.right()-1, r.y()+1, r.right()-1, r.bottom());
2315 }*/
2316
2317}
2318
2319
2320
2321void LiquidStyle::drawTabMask(QPainter *p, const QTabBar*, QTab *tab,
2322 bool selected)
2323
2324
2325{
2326 //p->fillRect(tab->rect(), Qt::color1);
2327 QRect r = tab->rect();
2328 QPixmap *pix = selected ? getPixmap(TabDown) : getPixmap(Tab);
2329 p->drawPixmap(r.x(), r.y(), *pix->mask(), 0, 0, 9, r.height());
2330 p->drawPixmap(r.right()-9, r.y(), *pix->mask(), pix->width()-9, 0, 9, r.height());
2331 p->fillRect(r.x()+9, r.y(), r.width()-18, r.height(), Qt::color1);
2332}
2333
2334void LiquidStyle::tabbarMetrics(const QTabBar *t, int &hFrame, int &vFrame,
2335 int &overlap)
2336{
2337 if(t->shape() == QTabBar::RoundedAbove){
2338 overlap = 1;
2339 hFrame = 18; // was 24
2340 vFrame = 8; // was 10
2341 }
2342 else
2343 QWindowsStyle::tabbarMetrics(t, hFrame, vFrame, overlap);
2344}
2345
2346
2347
2348void LiquidStyle::drawSplitter(QPainter *p, int x, int y, int w, int h,
2349 const QColorGroup &g, Orientation)
2350{
2351 drawClearBevel(p, x, y, w, h, highlightWidget == p->device() ?
2352 g.button().light(120) : g.button(), g.background());
2353}
2354
2355
2356void LiquidStyle::drawPanel(QPainter *p, int x, int y, int w, int h,
2357 const QColorGroup &g, bool sunken,
2358 int lineWidth, const QBrush *fill)
2359{
2360 if(p->device()->devType() == QInternal::Widget &&
2361 ((QWidget *)p->device())->inherits("QLineEdit")){
2362 int x2 = x+w-1;
2363 int y2 = y+h-1;
2364 p->setPen(g.dark());
2365 p->drawRect(x, y, w, h);
2366 p->setPen(g.mid());
2367 p->drawLine(x+1, y+1, x2-2, y+1);
2368 p->drawLine(x+1, y+1, x+1, y2-1);
2369 }
2370 else if(lineWidth != 2 || !sunken)
2371 QWindowsStyle::drawPanel(p, x, y, w, h, g, sunken, lineWidth, fill);
2372 else{
2373 QPen oldPen = p->pen();
2374 int x2 = x+w-1;
2375 int y2 = y+h-1;
2376 p->setPen(g.light());
2377 p->drawLine(x, y2, x2, y2);
2378 p->drawLine(x2, y, x2, y2);
2379 p->setPen(g.mid());
2380 p->drawLine(x, y, x2, y);
2381 p->drawLine(x, y, x, y2);
2382
2383 p->setPen(g.midlight());
2384 p->drawLine(x+1, y2-1, x2-1, y2-1);
2385 p->drawLine(x2-1, y+1, x2-1, y2-1);
2386 p->setPen(g.dark());
2387 p->drawLine(x+1, y+1, x2-1, y+1);
2388 p->drawLine(x+1, y+1, x+1, y2-1);
2389 p->setPen(oldPen);
2390 if(fill){
2391 // I believe here we are only supposed to fill if there is a
2392 // specified fill brush...
2393 p->fillRect(x+2, y+2, w-4, h-4, *fill);
2394 }
2395 }
2396}
2397
2398
2399void LiquidStyle::adjustHSV(QPixmap &pix, int h, int s, int v)
2400{
2401 QBitmap *maskBmp = NULL;
2402 if(pix.mask())
2403 maskBmp = new QBitmap(*pix.mask());
2404 QImage img = pix.convertToImage();
2405 if(img.depth() != 32)
2406 img = img.convertDepth(32);
2407 unsigned int *data = (unsigned int *)img.bits();
2408 int total = img.width()*img.height();
2409 int current;
2410 QColor c;
2411 int oldH, oldS, oldV;
2412 if(v < 235)
2413 v += 20;
2414 else
2415 v = 255;
2416 float intensity = v/255.0;
2417
2418 for(current=0; current<total; ++current){
2419 c.setRgb(data[current]);
2420 c.hsv(&oldH, &oldS, &oldV);
2421 oldV = (int)(oldV*intensity);
2422 c.setHsv(h, s, oldV);
2423 data[current] = c.rgb();
2424 }
2425 pix.convertFromImage(img);
2426 if(maskBmp)
2427 pix.setMask(*maskBmp);
2428}
2429
2430void LiquidStyle::intensity(QPixmap &pix, float percent)
2431{
2432 QImage image = pix.convertToImage();
2433 int i, tmp, r, g, b;
2434 int segColors = image.depth() > 8 ? 256 : image.numColors();
2435 unsigned char *segTbl = new unsigned char[segColors];
2436 int pixels = image.depth() > 8 ? image.width()*image.height() :
2437 image.numColors();
2438 unsigned int *data = image.depth() > 8 ? (unsigned int *)image.bits() :
2439 (unsigned int *)image.colorTable();
2440
2441 bool brighten = (percent >= 0);
2442 if(percent < 0)
2443 percent = -percent;
2444
2445 if(brighten){ // keep overflow check out of loops
2446 for(i=0; i < segColors; ++i){
2447 tmp = (int)(i*percent);
2448 if(tmp > 255)
2449 tmp = 255;
2450 segTbl[i] = tmp;
2451 }
2452 }
2453 else{
2454 for(i=0; i < segColors; ++i){
2455 tmp = (int)(i*percent);
2456 if(tmp < 0)
2457 tmp = 0;
2458 segTbl[i] = tmp;
2459 }
2460 }
2461
2462 if(brighten){ // same here
2463 for(i=0; i < pixels; ++i){
2464 r = qRed(data[i]);
2465 g = qGreen(data[i]);
2466 b = qBlue(data[i]);
2467 r = r + segTbl[r] > 255 ? 255 : r + segTbl[r];
2468 g = g + segTbl[g] > 255 ? 255 : g + segTbl[g];
2469 b = b + segTbl[b] > 255 ? 255 : b + segTbl[b];
2470 data[i] = qRgb(r, g, b);
2471 }
2472 }
2473 else{
2474 for(i=0; i < pixels; ++i){
2475 r = qRed(data[i]);
2476 g = qGreen(data[i]);
2477 b = qBlue(data[i]);
2478 r = r - segTbl[r] < 0 ? 0 : r - segTbl[r];
2479 g = g - segTbl[g] < 0 ? 0 : g - segTbl[g];
2480 b = b - segTbl[b] < 0 ? 0 : b - segTbl[b];
2481 data[i] = qRgb(r, g, b);
2482 }
2483 }
2484 delete [] segTbl;
2485 pix.convertFromImage(image);
2486}
2487
2488void LiquidStyle::drawRoundRect(QPainter *p, int x, int y, int w, int h)
2489{
2490 int x2 = x+w-1;
2491 int y2 = y+h-1;
2492 p->drawLine(x+1, y, x2-1, y);
2493 p->drawLine(x, y+1, x, y2-1);
2494 p->drawLine(x+1, y2, x2-1, y2);
2495 p->drawLine(x2, y+1, x2, y2-1);
2496}
2497
2498void LiquidStyle::drawSliderGroove (QPainter * p, int x, int y, int w, int h,
2499 const QColorGroup &g, QCOORD,
2500 Orientation orient)
2501{
2502 bool isFocus = ((QWidget *)p->device())->hasFocus();
2503 QColor c = isFocus ? g.background().dark(120) : g.background();
2504 if(orient == Qt::Horizontal){
2505 int x2 = x+w-1;
2506 y+=2;
2507 p->setPen(c.dark(130));
2508 p->drawLine(x+1, y, x2-1, y);
2509 p->setPen(c.dark(150));
2510 p->drawLine(x, y+1, x2, y+1);
2511 p->setPen(c.dark(125));
2512 p->drawLine(x, y+2, x2, y+2);
2513 p->setPen(c.dark(130));
2514 p->drawLine(x, y+3, x2, y+3);
2515 p->setPen(c.dark(120));
2516 p->drawLine(x, y+4, x2, y+4);
2517 p->setPen(c.light(110));
2518 p->drawLine(x+1, y+5, x2-1, y+5);
2519 }
2520 else{
2521 int y2 = y+h-1;
2522 x+=2;
2523 p->setPen(c.dark(130));
2524 p->drawLine(x, y+1, x, y2-1);
2525 p->setPen(c.dark(150));
2526 p->drawLine(x+1, y, x+1, y2);
2527 p->setPen(c.dark(125));
2528 p->drawLine(x+2, y, x+2, y2);
2529 p->setPen(c.dark(130));
2530 p->drawLine(x+3, y, x+3, y2);
2531 p->setPen(c.dark(120));
2532 p->drawLine(x+4, y, x+4, y2);
2533 p->setPen(c.light(110));
2534 p->drawLine(x+5, y+1, x+5, y2-1);
2535 }
2536 //QWindowsStyle::drawSliderGroove(p, x, y, w, h, g, c, orient);
2537
2538}
2539
2540void LiquidStyle::drawSliderGrooveMask (QPainter * p, int x, int y, int w,
2541 int h, QCOORD, Orientation orient)
2542{
2543 p->fillRect(x, y, w, h, Qt::color0);
2544 p->setPen(Qt::color1);
2545 if(orient == Qt::Horizontal){
2546 int x2 = x+w-1;
2547 y+=2;
2548 p->drawLine(x+1, y, x2-1, y);
2549 p->fillRect(x, y+1, w, 4, Qt::color1);
2550 p->drawLine(x+1, y+5, x2-1, y+5);
2551 }
2552 else{
2553 int y2 = y+h-1;
2554 x+=2;
2555 p->drawLine(x, y+1, x, y2-1);
2556 p->fillRect(x+1, y, 4, h, Qt::color1);
2557 p->drawLine(x+5, y+1, x+5, y2-1);
2558 }
2559}
2560
2561// I'm debating if to use QValueList or QList here. I like QValueList better,
2562// but QList handles pointers which is good for a lot of empty icons...
2563
2564void LiquidStyle::loadCustomButtons()
2565{
2566 return; // TODO
2567 customBtnColorList.clear();
2568 customBtnIconList.clear();
2569 customBtnLabelList.clear();
2570
2571// KConfig *config = KGlobal::config();
2572// QString oldGrp = config->group();
2573// config->setGroup("MosfetButtons");
2574
2575 QStrList iconList, colorList; //temp, we store QPixmaps and QColors
2576 iconList.setAutoDelete(true);
2577 colorList.setAutoDelete(true);
2578// config->readListEntry("Labels", customBtnLabelList);
2579// config->readListEntry("Icons", iconList);
2580// config->readListEntry("Colors", colorList);
2581
2582 const char *labelStr = customBtnLabelList.first();
2583 const char *colorStr = colorList.first();
2584 const char *iconStr = iconList.first();
2585
2586// KIconLoader *ldr = KGlobal::iconLoader();
2587 while(labelStr != NULL){
2588 QColor *c = new QColor;
2589 c->setNamedColor(QString(colorStr));
2590 customBtnColorList.append(c);
2591
2592 QString tmpStr(iconStr);
2593 if(!tmpStr.isEmpty()){
2594 QPixmap *pixmap =
2595 new QPixmap();//ldr->loadIcon(tmpStr, KIcon::Small));
2596 if(pixmap->isNull()){
2597 delete pixmap;
2598 customBtnIconList.append(NULL);
2599 }
2600 else
2601 customBtnIconList.append(pixmap);
2602 }
2603 else
2604 customBtnIconList.append(NULL);
2605
2606 labelStr = customBtnLabelList.next();
2607 colorStr = colorList.next();
2608 iconStr = iconList.next();
2609 }
2610}
2611
2612void LiquidStyle::applyCustomAttributes(QPushButton *btn)
2613{
2614 return; // TODO
2615 QString str = btn->text();
2616 if(str.isEmpty())
2617 return;
2618 while(str.contains('&') != 0)
2619 str = str.remove(str.find('&'), 1);
2620
2621 const char *s;
2622 int idx = 0;
2623 for(s = customBtnLabelList.first(); s != NULL;
2624 ++idx, s = customBtnLabelList.next()){
2625 if(qstricmp(s, str.latin1()) == 0){
2626 QPalette pal = btn->palette();
2627 pal.setColor(QColorGroup::Button,
2628 *customBtnColorList.at(idx));
2629 btn->setPalette(pal);
2630 /*
2631 if(customBtnIconList.at(idx) != NULL){
2632 QPixmap *pix = customBtnIconList.at(idx);
2633 btn->setIconSet(QIconSet(*pix));
2634 }*/
2635 break;
2636 }
2637 }
2638}
2639
2640void LiquidStyle::unapplyCustomAttributes(QPushButton *btn)
2641{
2642 return; // TODO
2643 QString str = btn->text();
2644 if(str.isEmpty())
2645 return;
2646 while(str.contains('&') != 0)
2647 str = str.remove(str.find('&'), 1);
2648
2649 const char *s;
2650 for(s = customBtnLabelList.first(); s != NULL; s = customBtnLabelList.next()){
2651 if(qstricmp(s, str.latin1()) == 0){
2652 btn->setPalette(QApplication::palette());
2653 btn->setIconSet(QIconSet());
2654 break;
2655 }
2656 }
2657}
2658
2659// #include "liquid.moc"
2660
2661
2662
2663
2664
2665
2666/* vim: set noet sw=8 ts=8: */