summaryrefslogtreecommitdiff
authorsandman <sandman>2002-11-01 16:07:10 (UTC)
committer sandman <sandman>2002-11-01 16:07:10 (UTC)
commit9e4d914ade0af86707531a80e93a870e52738ce6 (patch) (unidiff)
tree13bcdec43e9d1afc7392ce44cd72ff1289f0c8eb
parent28b70b2b7f8fa03ba0991fb73dccf7b46e5c3d1f (diff)
downloadopie-9e4d914ade0af86707531a80e93a870e52738ce6.zip
opie-9e4d914ade0af86707531a80e93a870e52738ce6.tar.gz
opie-9e4d914ade0af86707531a80e93a870e52738ce6.tar.bz2
Some fixes and enhancements:
- don't rely on clipping information from Qt/E -- this doesn't work - theme style has support for all KDE gradient types now
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/styles/theme/ogfxeffect.cpp249
-rw-r--r--noncore/styles/theme/ogfxeffect.h3
-rw-r--r--noncore/styles/theme/othemestyle.cpp7
3 files changed, 223 insertions, 36 deletions
diff --git a/noncore/styles/theme/ogfxeffect.cpp b/noncore/styles/theme/ogfxeffect.cpp
index 55f3c1f..cc5bbcd 100644
--- a/noncore/styles/theme/ogfxeffect.cpp
+++ b/noncore/styles/theme/ogfxeffect.cpp
@@ -1,275 +1,458 @@
1/* This file is part of the KDE libraries 1/* This file is part of the KDE libraries
2 Copyright (C) 1998, 1999 Christian Tibirna <ctibirna@total.net> 2 Copyright (C) 1998, 1999 Christian Tibirna <ctibirna@total.net>
3 (C) 1998, 1999 Daniel M. Duley <mosfet@kde.org> 3 (C) 1998, 1999 Daniel M. Duley <mosfet@kde.org>
4 (C) 1998, 1999 Dirk A. Mueller <mueller@kde.org> 4 (C) 1998, 1999 Dirk A. Mueller <mueller@kde.org>
5 5
6*/ 6*/
7 7
8// $Id$ 8// $Id$
9 9
10#include <qimage.h> 10#include <qimage.h>
11#include <qpainter.h> 11#include <qpainter.h>
12 12
13#include <qpe/qmath.h> 13#include <qpe/qmath.h>
14 14
15#include "ogfxeffect.h" 15#include "ogfxeffect.h"
16 16
17 17
18//====================================================================== 18//======================================================================
19// 19//
20// Gradient effects 20// Gradient effects
21// 21//
22//====================================================================== 22//======================================================================
23 23
24 24
25QPixmap& OGfxEffect::gradient(QPixmap &pixmap, const QColor &ca, 25QPixmap& OGfxEffect::gradient(QPixmap &pixmap, const QColor &ca,
26 const QColor &cb, GradientType eff, int /*ncols*/) 26 const QColor &cb, GradientType eff, int ncols)
27{ 27{
28 if(pixmap.depth() > 8 && 28 QImage image = gradient(pixmap.size(), ca, cb, eff, ncols);
29 (eff == VerticalGradient || eff == HorizontalGradient)) { 29 pixmap.convertFromImage(image);
30 30
31 int rDiff, gDiff, bDiff; 31 return pixmap;
32 int rca, gca, bca /*, rcb, gcb, bcb*/; 32}
33
34QImage OGfxEffect::gradient(const QSize &size, const QColor &ca,
35 const QColor &cb, GradientType eff, int /*ncols*/)
36{
37 int rDiff, gDiff, bDiff;
38 int rca, gca, bca, rcb, gcb, bcb;
39
40 QImage image(size, 32);
41
42 if (size.width() == 0 || size.height() == 0) {
43 qDebug ( "WARNING: OGfxEffect::gradient: invalid image" );
44 return image;
45 }
46
47 register int x, y;
33 48
34 register int x, y; 49 rDiff = (rcb = cb.red()) - (rca = ca.red());
50 gDiff = (gcb = cb.green()) - (gca = ca.green());
51 bDiff = (bcb = cb.blue()) - (bca = ca.blue());
35 52
36 rDiff = (/*rcb = */ cb.red()) - (rca = ca.red()); 53 if( eff == VerticalGradient || eff == HorizontalGradient ){
37 gDiff = (/*gcb = */ cb.green()) - (gca = ca.green()); 54
38 bDiff = (/*bcb = */ cb.blue()) - (bca = ca.blue()); 55 uint *p;
56 uint rgb;
39 57
40 register int rl = rca << 16; 58 register int rl = rca << 16;
41 register int gl = gca << 16; 59 register int gl = gca << 16;
42 register int bl = bca << 16; 60 register int bl = bca << 16;
43 61
44 int rcdelta = ((1<<16) / (eff == VerticalGradient ? pixmap.height() : pixmap.width())) * rDiff; 62 if( eff == VerticalGradient ) {
45 int gcdelta = ((1<<16) / (eff == VerticalGradient ? pixmap.height() : pixmap.width())) * gDiff; 63
46 int bcdelta = ((1<<16) / (eff == VerticalGradient ? pixmap.height() : pixmap.width())) * bDiff; 64 int rcdelta = ((1<<16) / size.height()) * rDiff;
65 int gcdelta = ((1<<16) / size.height()) * gDiff;
66 int bcdelta = ((1<<16) / size.height()) * bDiff;
47 67
48 QPainter p(&pixmap); 68 for ( y = 0; y < size.height(); y++ ) {
69 p = (uint *) image.scanLine(y);
49 70
50 // these for-loops could be merged, but the if's in the inner loop
51 // would make it slow
52 switch(eff) {
53 case VerticalGradient:
54 for ( y = 0; y < pixmap.height(); y++ ) {
55 rl += rcdelta; 71 rl += rcdelta;
56 gl += gcdelta; 72 gl += gcdelta;
57 bl += bcdelta; 73 bl += bcdelta;
58 74
59 p.setPen(QColor(rl>>16, gl>>16, bl>>16)); 75 rgb = qRgb( (rl>>16), (gl>>16), (bl>>16) );
60 p.drawLine(0, y, pixmap.width()-1, y); 76
77 for( x = 0; x < size.width(); x++ ) {
78 *p = rgb;
79 p++;
80 }
61 } 81 }
62 break; 82
63 case HorizontalGradient: 83 }
64 for( x = 0; x < pixmap.width(); x++) { 84 else { // must be HorizontalGradient
85
86 unsigned int *o_src = (unsigned int *)image.scanLine(0);
87 unsigned int *src = o_src;
88
89 int rcdelta = ((1<<16) / size.width()) * rDiff;
90 int gcdelta = ((1<<16) / size.width()) * gDiff;
91 int bcdelta = ((1<<16) / size.width()) * bDiff;
92
93 for( x = 0; x < size.width(); x++) {
94
65 rl += rcdelta; 95 rl += rcdelta;
66 gl += gcdelta; 96 gl += gcdelta;
67 bl += bcdelta; 97 bl += bcdelta;
68 98
69 p.setPen(QColor(rl>>16, gl>>16, bl>>16)); 99 *src++ = qRgb( (rl>>16), (gl>>16), (bl>>16));
70 p.drawLine(x, 0, x, pixmap.height()-1); 100 }
101
102 src = o_src;
103
104 // Believe it or not, manually copying in a for loop is faster
105 // than calling memcpy for each scanline (on the order of ms...).
106 // I think this is due to the function call overhead (mosfet).
107
108 for (y = 1; y < size.height(); ++y) {
109
110 p = (unsigned int *)image.scanLine(y);
111 src = o_src;
112 for(x=0; x < size.width(); ++x)
113 *p++ = *src++;
71 } 114 }
72 break;
73 default:
74 ;
75 } 115 }
76 } 116 }
117
77 else { 118 else {
78// QImage image = OGfxEffect::gradient(pixmap.size(), ca, cb,
79// (OGfxEffect::GradientType) eff, ncols);
80// pixmap.convertFromImage(image);
81 }
82 119
83 return pixmap; 120 float rfd, gfd, bfd;
121 float rd = rca, gd = gca, bd = bca;
122
123 unsigned char *xtable[3];
124 unsigned char *ytable[3];
125
126 unsigned int w = size.width(), h = size.height();
127 xtable[0] = new unsigned char[w];
128 xtable[1] = new unsigned char[w];
129 xtable[2] = new unsigned char[w];
130 ytable[0] = new unsigned char[h];
131 ytable[1] = new unsigned char[h];
132 ytable[2] = new unsigned char[h];
133 w*=2, h*=2;
134
135 if ( eff == DiagonalGradient || eff == CrossDiagonalGradient) {
136 // Diagonal dgradient code inspired by BlackBox (mosfet)
137 // BlackBox dgradient is (C) Brad Hughes, <bhughes@tcac.net> and
138 // Mike Cole <mike@mydot.com>.
139
140 rfd = (float)rDiff/w;
141 gfd = (float)gDiff/w;
142 bfd = (float)bDiff/w;
143
144 int dir;
145 for (x = 0; x < size.width(); x++, rd+=rfd, gd+=gfd, bd+=bfd) {
146 dir = eff == DiagonalGradient? x : size.width() - x - 1;
147 xtable[0][dir] = (unsigned char) rd;
148 xtable[1][dir] = (unsigned char) gd;
149 xtable[2][dir] = (unsigned char) bd;
150 }
151 rfd = (float)rDiff/h;
152 gfd = (float)gDiff/h;
153 bfd = (float)bDiff/h;
154 rd = gd = bd = 0;
155 for (y = 0; y < size.height(); y++, rd+=rfd, gd+=gfd, bd+=bfd) {
156 ytable[0][y] = (unsigned char) rd;
157 ytable[1][y] = (unsigned char) gd;
158 ytable[2][y] = (unsigned char) bd;
159 }
160
161 for (y = 0; y < size.height(); y++) {
162 unsigned int *scanline = (unsigned int *)image.scanLine(y);
163 for (x = 0; x < size.width(); x++) {
164 scanline[x] = qRgb(xtable[0][x] + ytable[0][y],
165 xtable[1][x] + ytable[1][y],
166 xtable[2][x] + ytable[2][y]);
167 }
168 }
169 }
170
171 else if (eff == RectangleGradient ||
172 eff == PyramidGradient ||
173 eff == PipeCrossGradient ||
174 eff == EllipticGradient)
175 {
176 int rSign = rDiff>0? 1: -1;
177 int gSign = gDiff>0? 1: -1;
178 int bSign = bDiff>0? 1: -1;
179
180 rfd = (float)rDiff / size.width();
181 gfd = (float)gDiff / size.width();
182 bfd = (float)bDiff / size.width();
183
184 rd = (float)rDiff/2;
185 gd = (float)gDiff/2;
186 bd = (float)bDiff/2;
187
188 for (x = 0; x < size.width(); x++, rd-=rfd, gd-=gfd, bd-=bfd)
189 {
190 xtable[0][x] = (unsigned char) abs((int)rd);
191 xtable[1][x] = (unsigned char) abs((int)gd);
192 xtable[2][x] = (unsigned char) abs((int)bd);
193 }
194
195 rfd = (float)rDiff/size.height();
196 gfd = (float)gDiff/size.height();
197 bfd = (float)bDiff/size.height();
198
199 rd = (float)rDiff/2;
200 gd = (float)gDiff/2;
201 bd = (float)bDiff/2;
202
203 for (y = 0; y < size.height(); y++, rd-=rfd, gd-=gfd, bd-=bfd)
204 {
205 ytable[0][y] = (unsigned char) abs((int)rd);
206 ytable[1][y] = (unsigned char) abs((int)gd);
207 ytable[2][y] = (unsigned char) abs((int)bd);
208 }
209 unsigned int rgb;
210 int h = (size.height()+1)>>1;
211 for (y = 0; y < h; y++) {
212 unsigned int *sl1 = (unsigned int *)image.scanLine(y);
213 unsigned int *sl2 = (unsigned int *)image.scanLine(QMAX(size.height()-y-1, y));
214
215 int w = (size.width()+1)>>1;
216 int x2 = size.width()-1;
217
218 for (x = 0; x < w; x++, x2--) {
219 rgb = 0;
220 if (eff == PyramidGradient) {
221 rgb = qRgb(rcb-rSign*(xtable[0][x]+ytable[0][y]),
222 gcb-gSign*(xtable[1][x]+ytable[1][y]),
223 bcb-bSign*(xtable[2][x]+ytable[2][y]));
224 }
225 if (eff == RectangleGradient) {
226 rgb = qRgb(rcb - rSign *
227 QMAX(xtable[0][x], ytable[0][y]) * 2,
228 gcb - gSign *
229 QMAX(xtable[1][x], ytable[1][y]) * 2,
230 bcb - bSign *
231 QMAX(xtable[2][x], ytable[2][y]) * 2);
232 }
233 if (eff == PipeCrossGradient) {
234 rgb = qRgb(rcb - rSign *
235 QMIN(xtable[0][x], ytable[0][y]) * 2,
236 gcb - gSign *
237 QMIN(xtable[1][x], ytable[1][y]) * 2,
238 bcb - bSign *
239 QMIN(xtable[2][x], ytable[2][y]) * 2);
240 }
241 if (eff == EllipticGradient) {
242 rgb = qRgb(rcb - rSign *
243 (int)sqrt((xtable[0][x]*xtable[0][x] +
244 ytable[0][y]*ytable[0][y])*2.0),
245 gcb - gSign *
246 (int)sqrt((xtable[1][x]*xtable[1][x] +
247 ytable[1][y]*ytable[1][y])*2.0),
248 bcb - bSign *
249 (int)sqrt((xtable[2][x]*xtable[2][x] +
250 ytable[2][y]*ytable[2][y])*2.0));
251 }
252
253 sl1[x] = sl2[x] = rgb;
254 sl1[x2] = sl2[x2] = rgb;
255 }
256 }
257 }
258
259 delete [] xtable[0];
260 delete [] xtable[1];
261 delete [] xtable[2];
262 delete [] ytable[0];
263 delete [] ytable[1];
264 delete [] ytable[2];
265 }
266 return image;
84} 267}
85 268
86 269
87//====================================================================== 270//======================================================================
88// 271//
89// Blend effects 272// Blend effects
90// 273//
91//====================================================================== 274//======================================================================
92 275
93 276
94QPixmap& OGfxEffect::blend(QPixmap &pixmap, float initial_intensity, 277QPixmap& OGfxEffect::blend(QPixmap &pixmap, float initial_intensity,
95 const QColor &bgnd, GradientType eff, 278 const QColor &bgnd, GradientType eff,
96 bool anti_dir, int /*ncols*/) 279 bool anti_dir, int /*ncols*/)
97{ 280{
98 QImage image = pixmap.convertToImage(); 281 QImage image = pixmap.convertToImage();
99 OGfxEffect::blend(image, initial_intensity, bgnd, eff, anti_dir); 282 OGfxEffect::blend(image, initial_intensity, bgnd, eff, anti_dir);
100 283
101 if ( pixmap. depth ( ) <= 8 ) 284 if ( pixmap. depth ( ) <= 8 )
102 image. convertDepth ( pixmap. depth ( )); 285 image. convertDepth ( pixmap. depth ( ));
103 286
104 pixmap.convertFromImage(image); 287 pixmap.convertFromImage(image);
105 288
106 return pixmap; 289 return pixmap;
107} 290}
108 291
109 292
110QImage& OGfxEffect::blend(QImage &image, float initial_intensity, 293QImage& OGfxEffect::blend(QImage &image, float initial_intensity,
111 const QColor &bgnd, GradientType eff, 294 const QColor &bgnd, GradientType eff,
112 bool anti_dir) 295 bool anti_dir)
113{ 296{
114 if (image.width() == 0 || image.height() == 0) { 297 if (image.width() == 0 || image.height() == 0) {
115 qDebug ( "Invalid image\n" ); 298 qDebug ( "Invalid image\n" );
116 return image; 299 return image;
117 } 300 }
118 301
119 int r_bgnd = bgnd.red(), g_bgnd = bgnd.green(), b_bgnd = bgnd.blue(); 302 int r_bgnd = bgnd.red(), g_bgnd = bgnd.green(), b_bgnd = bgnd.blue();
120 int r, g, b; 303 int r, g, b;
121 int ind; 304 int ind;
122 305
123 unsigned int xi, xf, yi, yf; 306 unsigned int xi, xf, yi, yf;
124 unsigned int a; 307 unsigned int a;
125 308
126 // check the boundaries of the initial intesity param 309 // check the boundaries of the initial intesity param
127 float unaffected = 1; 310 float unaffected = 1;
128 if (initial_intensity > 1) initial_intensity = 1; 311 if (initial_intensity > 1) initial_intensity = 1;
129 if (initial_intensity < -1) initial_intensity = -1; 312 if (initial_intensity < -1) initial_intensity = -1;
130 if (initial_intensity < 0) { 313 if (initial_intensity < 0) {
131 unaffected = 1. + initial_intensity; 314 unaffected = 1. + initial_intensity;
132 initial_intensity = 0; 315 initial_intensity = 0;
133 } 316 }
134 317
135 318
136 float intensity = initial_intensity; 319 float intensity = initial_intensity;
137 float var = 1. - initial_intensity; 320 float var = 1. - initial_intensity;
138 321
139 if (anti_dir) { 322 if (anti_dir) {
140 initial_intensity = intensity = 1.; 323 initial_intensity = intensity = 1.;
141 var = -var; 324 var = -var;
142 } 325 }
143 326
144 register int x, y; 327 register int x, y;
145 328
146 unsigned int *data = (unsigned int *)image.bits(); 329 unsigned int *data = (unsigned int *)image.bits();
147 330
148 if( eff == VerticalGradient || eff == HorizontalGradient ) { 331 if( eff == VerticalGradient || eff == HorizontalGradient ) {
149 332
150 // set the image domain to apply the effect to 333 // set the image domain to apply the effect to
151 xi = 0, xf = image.width(); 334 xi = 0, xf = image.width();
152 yi = 0, yf = image.height(); 335 yi = 0, yf = image.height();
153 if (eff == VerticalGradient) { 336 if (eff == VerticalGradient) {
154 if (anti_dir) yf = (int)(image.height() * unaffected); 337 if (anti_dir) yf = (int)(image.height() * unaffected);
155 else yi = (int)(image.height() * (1 - unaffected)); 338 else yi = (int)(image.height() * (1 - unaffected));
156 } 339 }
157 else { 340 else {
158 if (anti_dir) xf = (int)(image.width() * unaffected); 341 if (anti_dir) xf = (int)(image.width() * unaffected);
159 else xi = (int)(image.height() * (1 - unaffected)); 342 else xi = (int)(image.height() * (1 - unaffected));
160 } 343 }
161 344
162 var /= (eff == VerticalGradient?yf-yi:xf-xi); 345 var /= (eff == VerticalGradient?yf-yi:xf-xi);
163 346
164 for (y = yi; y < (int)yf; y++) { 347 for (y = yi; y < (int)yf; y++) {
165 intensity = eff == VerticalGradient? intensity + var : 348 intensity = eff == VerticalGradient? intensity + var :
166 initial_intensity; 349 initial_intensity;
167 for (x = xi; x < (int)xf ; x++) { 350 for (x = xi; x < (int)xf ; x++) {
168 if (eff == HorizontalGradient) intensity += var; 351 if (eff == HorizontalGradient) intensity += var;
169 ind = x + image.width() * y ; 352 ind = x + image.width() * y ;
170 r = qRed (data[ind]) + (int)(intensity * 353 r = qRed (data[ind]) + (int)(intensity *
171 (r_bgnd - qRed (data[ind]))); 354 (r_bgnd - qRed (data[ind])));
172 g = qGreen(data[ind]) + (int)(intensity * 355 g = qGreen(data[ind]) + (int)(intensity *
173 (g_bgnd - qGreen(data[ind]))); 356 (g_bgnd - qGreen(data[ind])));
174 b = qBlue (data[ind]) + (int)(intensity * 357 b = qBlue (data[ind]) + (int)(intensity *
175 (b_bgnd - qBlue (data[ind]))); 358 (b_bgnd - qBlue (data[ind])));
176 if (r > 255) r = 255; if (r < 0 ) r = 0; 359 if (r > 255) r = 255; if (r < 0 ) r = 0;
177 if (g > 255) g = 255; if (g < 0 ) g = 0; 360 if (g > 255) g = 255; if (g < 0 ) g = 0;
178 if (b > 255) b = 255; if (b < 0 ) b = 0; 361 if (b > 255) b = 255; if (b < 0 ) b = 0;
179 a = qAlpha(data[ind]); 362 a = qAlpha(data[ind]);
180 data[ind] = qRgba(r, g, b, a); 363 data[ind] = qRgba(r, g, b, a);
181 } 364 }
182 } 365 }
183 } 366 }
184 else if (eff == DiagonalGradient || eff == CrossDiagonalGradient) { 367 else if (eff == DiagonalGradient || eff == CrossDiagonalGradient) {
185 float xvar = var / 2 / image.width(); // / unaffected; 368 float xvar = var / 2 / image.width(); // / unaffected;
186 float yvar = var / 2 / image.height(); // / unaffected; 369 float yvar = var / 2 / image.height(); // / unaffected;
187 float tmp; 370 float tmp;
188 371
189 for (x = 0; x < image.width() ; x++) { 372 for (x = 0; x < image.width() ; x++) {
190 tmp = xvar * (eff == DiagonalGradient? x : image.width()-x-1); 373 tmp = xvar * (eff == DiagonalGradient? x : image.width()-x-1);
191 for (y = 0; y < image.height() ; y++) { 374 for (y = 0; y < image.height() ; y++) {
192 intensity = initial_intensity + tmp + yvar * y; 375 intensity = initial_intensity + tmp + yvar * y;
193 ind = x + image.width() * y ; 376 ind = x + image.width() * y ;
194 r = qRed (data[ind]) + (int)(intensity * 377 r = qRed (data[ind]) + (int)(intensity *
195 (r_bgnd - qRed (data[ind]))); 378 (r_bgnd - qRed (data[ind])));
196 g = qGreen(data[ind]) + (int)(intensity * 379 g = qGreen(data[ind]) + (int)(intensity *
197 (g_bgnd - qGreen(data[ind]))); 380 (g_bgnd - qGreen(data[ind])));
198 b = qBlue (data[ind]) + (int)(intensity * 381 b = qBlue (data[ind]) + (int)(intensity *
199 (b_bgnd - qBlue (data[ind]))); 382 (b_bgnd - qBlue (data[ind])));
200 if (r > 255) r = 255; if (r < 0 ) r = 0; 383 if (r > 255) r = 255; if (r < 0 ) r = 0;
201 if (g > 255) g = 255; if (g < 0 ) g = 0; 384 if (g > 255) g = 255; if (g < 0 ) g = 0;
202 if (b > 255) b = 255; if (b < 0 ) b = 0; 385 if (b > 255) b = 255; if (b < 0 ) b = 0;
203 a = qAlpha(data[ind]); 386 a = qAlpha(data[ind]);
204 data[ind] = qRgba(r, g, b, a); 387 data[ind] = qRgba(r, g, b, a);
205 } 388 }
206 } 389 }
207 } 390 }
208 391
209 else if (eff == RectangleGradient || eff == EllipticGradient) { 392 else if (eff == RectangleGradient || eff == EllipticGradient) {
210 float xvar; 393 float xvar;
211 float yvar; 394 float yvar;
212 395
213 for (x = 0; x < image.width() / 2 + image.width() % 2; x++) { 396 for (x = 0; x < image.width() / 2 + image.width() % 2; x++) {
214 xvar = var / image.width() * (image.width() - x*2/unaffected-1); 397 xvar = var / image.width() * (image.width() - x*2/unaffected-1);
215 for (y = 0; y < image.height() / 2 + image.height() % 2; y++) { 398 for (y = 0; y < image.height() / 2 + image.height() % 2; y++) {
216 yvar = var / image.height() * (image.height() - y*2/unaffected -1); 399 yvar = var / image.height() * (image.height() - y*2/unaffected -1);
217 400
218 if (eff == RectangleGradient) 401 if (eff == RectangleGradient)
219 intensity = initial_intensity + QMAX(xvar, yvar); 402 intensity = initial_intensity + QMAX(xvar, yvar);
220 else 403 else
221 intensity = initial_intensity + qSqrt(xvar * xvar + yvar * yvar); 404 intensity = initial_intensity + qSqrt(xvar * xvar + yvar * yvar);
222 if (intensity > 1) intensity = 1; 405 if (intensity > 1) intensity = 1;
223 if (intensity < 0) intensity = 0; 406 if (intensity < 0) intensity = 0;
224 407
225 //NW 408 //NW
226 ind = x + image.width() * y ; 409 ind = x + image.width() * y ;
227 r = qRed (data[ind]) + (int)(intensity * 410 r = qRed (data[ind]) + (int)(intensity *
228 (r_bgnd - qRed (data[ind]))); 411 (r_bgnd - qRed (data[ind])));
229 g = qGreen(data[ind]) + (int)(intensity * 412 g = qGreen(data[ind]) + (int)(intensity *
230 (g_bgnd - qGreen(data[ind]))); 413 (g_bgnd - qGreen(data[ind])));
231 b = qBlue (data[ind]) + (int)(intensity * 414 b = qBlue (data[ind]) + (int)(intensity *
232 (b_bgnd - qBlue (data[ind]))); 415 (b_bgnd - qBlue (data[ind])));
233 if (r > 255) r = 255; if (r < 0 ) r = 0; 416 if (r > 255) r = 255; if (r < 0 ) r = 0;
234 if (g > 255) g = 255; if (g < 0 ) g = 0; 417 if (g > 255) g = 255; if (g < 0 ) g = 0;
235 if (b > 255) b = 255; if (b < 0 ) b = 0; 418 if (b > 255) b = 255; if (b < 0 ) b = 0;
236 a = qAlpha(data[ind]); 419 a = qAlpha(data[ind]);
237 data[ind] = qRgba(r, g, b, a); 420 data[ind] = qRgba(r, g, b, a);
238 421
239 //NE 422 //NE
240 ind = image.width() - x - 1 + image.width() * y ; 423 ind = image.width() - x - 1 + image.width() * y ;
241 r = qRed (data[ind]) + (int)(intensity * 424 r = qRed (data[ind]) + (int)(intensity *
242 (r_bgnd - qRed (data[ind]))); 425 (r_bgnd - qRed (data[ind])));
243 g = qGreen(data[ind]) + (int)(intensity * 426 g = qGreen(data[ind]) + (int)(intensity *
244 (g_bgnd - qGreen(data[ind]))); 427 (g_bgnd - qGreen(data[ind])));
245 b = qBlue (data[ind]) + (int)(intensity * 428 b = qBlue (data[ind]) + (int)(intensity *
246 (b_bgnd - qBlue (data[ind]))); 429 (b_bgnd - qBlue (data[ind])));
247 if (r > 255) r = 255; if (r < 0 ) r = 0; 430 if (r > 255) r = 255; if (r < 0 ) r = 0;
248 if (g > 255) g = 255; if (g < 0 ) g = 0; 431 if (g > 255) g = 255; if (g < 0 ) g = 0;
249 if (b > 255) b = 255; if (b < 0 ) b = 0; 432 if (b > 255) b = 255; if (b < 0 ) b = 0;
250 a = qAlpha(data[ind]); 433 a = qAlpha(data[ind]);
251 data[ind] = qRgba(r, g, b, a); 434 data[ind] = qRgba(r, g, b, a);
252 } 435 }
253 } 436 }
254 437
255 //CT loop is doubled because of stupid central row/column issue. 438 //CT loop is doubled because of stupid central row/column issue.
256 // other solution? 439 // other solution?
257 for (x = 0; x < image.width() / 2; x++) { 440 for (x = 0; x < image.width() / 2; x++) {
258 xvar = var / image.width() * (image.width() - x*2/unaffected-1); 441 xvar = var / image.width() * (image.width() - x*2/unaffected-1);
259 for (y = 0; y < image.height() / 2; y++) { 442 for (y = 0; y < image.height() / 2; y++) {
260 yvar = var / image.height() * (image.height() - y*2/unaffected -1); 443 yvar = var / image.height() * (image.height() - y*2/unaffected -1);
261 444
262 if (eff == RectangleGradient) 445 if (eff == RectangleGradient)
263 intensity = initial_intensity + QMAX(xvar, yvar); 446 intensity = initial_intensity + QMAX(xvar, yvar);
264 else 447 else
265 intensity = initial_intensity + qSqrt(xvar * xvar + yvar * yvar); 448 intensity = initial_intensity + qSqrt(xvar * xvar + yvar * yvar);
266 if (intensity > 1) intensity = 1; 449 if (intensity > 1) intensity = 1;
267 if (intensity < 0) intensity = 0; 450 if (intensity < 0) intensity = 0;
268 451
269 //SW 452 //SW
270 ind = x + image.width() * (image.height() - y -1) ; 453 ind = x + image.width() * (image.height() - y -1) ;
271 r = qRed (data[ind]) + (int)(intensity * 454 r = qRed (data[ind]) + (int)(intensity *
272 (r_bgnd - qRed (data[ind]))); 455 (r_bgnd - qRed (data[ind])));
273 g = qGreen(data[ind]) + (int)(intensity * 456 g = qGreen(data[ind]) + (int)(intensity *
274 (g_bgnd - qGreen(data[ind]))); 457 (g_bgnd - qGreen(data[ind])));
275 b = qBlue (data[ind]) + (int)(intensity * 458 b = qBlue (data[ind]) + (int)(intensity *
diff --git a/noncore/styles/theme/ogfxeffect.h b/noncore/styles/theme/ogfxeffect.h
index 45a8482..755537f 100644
--- a/noncore/styles/theme/ogfxeffect.h
+++ b/noncore/styles/theme/ogfxeffect.h
@@ -1,78 +1,81 @@
1/* This file is part of the KDE libraries 1/* This file is part of the KDE libraries
2 Copyright (C) 1998, 1999 Christian Tibirna <ctibirna@total.net> 2 Copyright (C) 1998, 1999 Christian Tibirna <ctibirna@total.net>
3 (C) 1998, 1999 Daniel M. Duley <mosfet@kde.org> 3 (C) 1998, 1999 Daniel M. Duley <mosfet@kde.org>
4 (C) 1998, 1999 Dirk A. Mueller <mueller@kde.org> 4 (C) 1998, 1999 Dirk A. Mueller <mueller@kde.org>
5 5
6*/ 6*/
7 7
8// $Id$ 8// $Id$
9 9
10#ifndef __OGFX_EFFECT_H 10#ifndef __OGFX_EFFECT_H
11#define __OGFX_EFFECT_H 11#define __OGFX_EFFECT_H
12 12
13#include <qpixmap.h> 13#include <qpixmap.h>
14#include <qimage.h> 14#include <qimage.h>
15 15
16/** 16/**
17 * This class includes various pixmap-based graphical effects. 17 * This class includes various pixmap-based graphical effects.
18 * 18 *
19 * Everything is 19 * Everything is
20 * static, so there is no need to create an instance of this class. You can 20 * static, so there is no need to create an instance of this class. You can
21 * just call the static methods. They are encapsulated here merely to provide 21 * just call the static methods. They are encapsulated here merely to provide
22 * a common namespace. 22 * a common namespace.
23 */ 23 */
24class OGfxEffect 24class OGfxEffect
25{ 25{
26public: 26public:
27 enum GradientType { VerticalGradient, HorizontalGradient, 27 enum GradientType { VerticalGradient, HorizontalGradient,
28 DiagonalGradient, CrossDiagonalGradient, 28 DiagonalGradient, CrossDiagonalGradient,
29 PyramidGradient, RectangleGradient, 29 PyramidGradient, RectangleGradient,
30 PipeCrossGradient, EllipticGradient }; 30 PipeCrossGradient, EllipticGradient };
31 enum RGBComponent { Red, Green, Blue }; 31 enum RGBComponent { Red, Green, Blue };
32 32
33 enum Lighting {NorthLite, NWLite, WestLite, SWLite, 33 enum Lighting {NorthLite, NWLite, WestLite, SWLite,
34 SouthLite, SELite, EastLite, NELite}; 34 SouthLite, SELite, EastLite, NELite};
35 35
36 /** 36 /**
37 * Create a gradient from color a to color b of the specified type. 37 * Create a gradient from color a to color b of the specified type.
38 * 38 *
39 * @param pixmap The pixmap to process. 39 * @param pixmap The pixmap to process.
40 * @param ca Color a. 40 * @param ca Color a.
41 * @param cb Color b. 41 * @param cb Color b.
42 * @param type The type of gradient. 42 * @param type The type of gradient.
43 * @param ncols The number of colors to use when not running on a 43 * @param ncols The number of colors to use when not running on a
44 * truecolor display. The gradient will be dithered to this number of 44 * truecolor display. The gradient will be dithered to this number of
45 * colors. Pass 0 to prevent dithering. 45 * colors. Pass 0 to prevent dithering.
46 * @return Returns the generated pixmap, for convenience. 46 * @return Returns the generated pixmap, for convenience.
47 */ 47 */
48 static QPixmap& gradient(QPixmap& pixmap, const QColor &ca, const QColor &cb, 48 static QPixmap& gradient(QPixmap& pixmap, const QColor &ca, const QColor &cb,
49 GradientType type, int ncols=3); 49 GradientType type, int ncols=3);
50 50
51 static QImage gradient (const QSize &size, const QColor &ca, const QColor &cb,
52 GradientType type, int ncols=3);
53
51 54
52 /** 55 /**
53 * Blend the provided pixmap into a background of the indicated color 56 * Blend the provided pixmap into a background of the indicated color
54 * 57 *
55 * @param pixmap The pixmap to process. 58 * @param pixmap The pixmap to process.
56 * @param initial_intensity this parameter takes values from -1 to 1: 59 * @param initial_intensity this parameter takes values from -1 to 1:
57 * @li If positive, it tells how much to fade the image in its 60 * @li If positive, it tells how much to fade the image in its
58 * less affected spot. 61 * less affected spot.
59 * @li If negative, it tells roughly indicates how much of the image 62 * @li If negative, it tells roughly indicates how much of the image
60 * remains unaffected 63 * remains unaffected
61 * @param bgnd Indicates the color of the background to blend in. 64 * @param bgnd Indicates the color of the background to blend in.
62 * @param eff Lets you choose what kind of blending you like. 65 * @param eff Lets you choose what kind of blending you like.
63 * @param anti_dir Blend in the opposite direction (makes no much sense 66 * @param anti_dir Blend in the opposite direction (makes no much sense
64 * with concentric blending effects). 67 * with concentric blending effects).
65 * @return Returns the @ref pixmap(), provided for convenience. 68 * @return Returns the @ref pixmap(), provided for convenience.
66 */ 69 */
67 static QPixmap& blend(QPixmap& pixmap, float initial_intensity, 70 static QPixmap& blend(QPixmap& pixmap, float initial_intensity,
68 const QColor &bgnd, GradientType eff, 71 const QColor &bgnd, GradientType eff,
69 bool anti_dir=false, int ncols=3); 72 bool anti_dir=false, int ncols=3);
70 73
71 74
72 static QImage& blend(QImage &image, float initial_intensity, 75 static QImage& blend(QImage &image, float initial_intensity,
73 const QColor &bgnd, GradientType eff, 76 const QColor &bgnd, GradientType eff,
74 bool anti_dir); 77 bool anti_dir);
75}; 78};
76 79
77 80
78#endif 81#endif
diff --git a/noncore/styles/theme/othemestyle.cpp b/noncore/styles/theme/othemestyle.cpp
index d97b026..8c7a71b 100644
--- a/noncore/styles/theme/othemestyle.cpp
+++ b/noncore/styles/theme/othemestyle.cpp
@@ -1021,393 +1021,394 @@ void OThemeStyle::drawShade( QPainter *p, int x, int y, int w, int h,
1021 else { 1021 else {
1022 QPointArray highShade( hWidth * 4 ); 1022 QPointArray highShade( hWidth * 4 );
1023 QPointArray lowShade( hWidth * 4 ); 1023 QPointArray lowShade( hWidth * 4 );
1024 1024
1025 p->setPen( g.shadow() ); 1025 p->setPen( g.shadow() );
1026 for ( i = 0; i < bWidth && w > 2 && h > 2; ++i, ++x, ++y, w -= 2, h -= 2 ) 1026 for ( i = 0; i < bWidth && w > 2 && h > 2; ++i, ++x, ++y, w -= 2, h -= 2 )
1027 p->drawRect( x, y , w, h ); 1027 p->drawRect( x, y , w, h );
1028 1028
1029 if ( !hWidth ) 1029 if ( !hWidth )
1030 return ; 1030 return ;
1031 1031
1032 x2 = x + w - 1, y2 = y + h - 1; 1032 x2 = x + w - 1, y2 = y + h - 1;
1033 for ( i = 0; i < hWidth; ++i, ++x, ++y, --x2, --y2 ) { 1033 for ( i = 0; i < hWidth; ++i, ++x, ++y, --x2, --y2 ) {
1034 highShade.putPoints( i * 4, 4, x, y, x2, y, x, y, x, y2 ); 1034 highShade.putPoints( i * 4, 4, x, y, x2, y, x, y, x, y2 );
1035 lowShade.putPoints( i * 4, 4, x, y2, x2, y2, x2, y, x2, y2 ); 1035 lowShade.putPoints( i * 4, 4, x, y2, x2, y2, x2, y, x2, y2 );
1036 } 1036 }
1037 if ( style == Windows && hWidth > 1 ) { 1037 if ( style == Windows && hWidth > 1 ) {
1038 p->setPen( highPen ); 1038 p->setPen( highPen );
1039 p->drawLineSegments( highShade, 0, 2 ); 1039 p->drawLineSegments( highShade, 0, 2 );
1040 p->setPen( lowPen ); 1040 p->setPen( lowPen );
1041 p->drawLineSegments( lowShade, 0, 2 ); 1041 p->drawLineSegments( lowShade, 0, 2 );
1042 1042
1043 p->setPen( ( sunken ) ? g.dark() : g.mid() ); 1043 p->setPen( ( sunken ) ? g.dark() : g.mid() );
1044 p->drawLineSegments( highShade, 4 ); 1044 p->drawLineSegments( highShade, 4 );
1045 p->setPen( ( sunken ) ? g.mid() : g.dark() ); 1045 p->setPen( ( sunken ) ? g.mid() : g.dark() );
1046 p->drawLineSegments( lowShade, 4 ); 1046 p->drawLineSegments( lowShade, 4 );
1047 } 1047 }
1048 else { 1048 else {
1049 p->setPen( ( sunken ) ? g.dark() : g.light() ); 1049 p->setPen( ( sunken ) ? g.dark() : g.light() );
1050 p->drawLineSegments( highShade ); 1050 p->drawLineSegments( highShade );
1051 p->setPen( ( sunken ) ? g.light() : g.dark() ); 1051 p->setPen( ( sunken ) ? g.light() : g.dark() );
1052 p->drawLineSegments( lowShade ); 1052 p->drawLineSegments( lowShade );
1053 } 1053 }
1054 } 1054 }
1055} 1055}
1056 1056
1057void OThemeStyle::drawPushButtonLabel( QPushButton *btn, QPainter *p ) 1057void OThemeStyle::drawPushButtonLabel( QPushButton *btn, QPainter *p )
1058{ 1058{
1059 WidgetType widget = btn->isDown() || btn->isOn() ? PushButtonDown : 1059 WidgetType widget = btn->isDown() || btn->isOn() ? PushButtonDown :
1060 PushButton; 1060 PushButton;
1061 const QColorGroup *cg = colorGroup( btn->colorGroup(), widget ); 1061 const QColorGroup *cg = colorGroup( btn->colorGroup(), widget );
1062 int x, y, w, h; 1062 int x, y, w, h;
1063 1063
1064 QRect r = btn->rect(); 1064 QRect r = btn->rect();
1065 r.rect( &x, &y, &w, &h ); 1065 r.rect( &x, &y, &w, &h );
1066 x += decoWidth( widget ); 1066 x += decoWidth( widget );
1067 y += decoWidth( widget ); 1067 y += decoWidth( widget );
1068 w -= decoWidth( widget ) * 2; 1068 w -= decoWidth( widget ) * 2;
1069 h -= decoWidth( widget ) * 2; 1069 h -= decoWidth( widget ) * 2;
1070 bool act = btn->isOn() || btn->isDown(); 1070 bool act = btn->isOn() || btn->isDown();
1071 1071
1072 // If this is a button with an associated popup menu, draw an arrow first 1072 // If this is a button with an associated popup menu, draw an arrow first
1073 if ( btn->popup() ) { 1073 if ( btn->popup() ) {
1074 int dx = menuButtonIndicatorWidth( btn->height() ); 1074 int dx = menuButtonIndicatorWidth( btn->height() );
1075 1075
1076 QColorGroup g( btn->colorGroup() ); 1076 QColorGroup g( btn->colorGroup() );
1077 int xx = x + w - dx - 4; 1077 int xx = x + w - dx - 4;
1078 int yy = y - 3; 1078 int yy = y - 3;
1079 int hh = h + 6; 1079 int hh = h + 6;
1080 1080
1081 if ( !act ) { 1081 if ( !act ) {
1082 p->setPen( g.light() ); 1082 p->setPen( g.light() );
1083 p->drawLine( xx, yy + 3, xx, yy + hh - 4 ); 1083 p->drawLine( xx, yy + 3, xx, yy + hh - 4 );
1084 } 1084 }
1085 else { 1085 else {
1086 p->setPen( g.button() ); 1086 p->setPen( g.button() );
1087 p->drawLine( xx, yy + 4, xx, yy + hh - 4 ); 1087 p->drawLine( xx, yy + 4, xx, yy + hh - 4 );
1088 } 1088 }
1089 drawArrow( p, DownArrow, FALSE, 1089 drawArrow( p, DownArrow, FALSE,
1090 x + w - dx - 2, y + 2, dx, h - 4, 1090 x + w - dx - 2, y + 2, dx, h - 4,
1091 btn->colorGroup(), 1091 btn->colorGroup(),
1092 btn->isEnabled() ); 1092 btn->isEnabled() );
1093 w -= dx; 1093 w -= dx;
1094 } 1094 }
1095 1095
1096 // Next, draw iconset, if any 1096 // Next, draw iconset, if any
1097 if ( btn->iconSet() && !btn->iconSet() ->isNull() ) { 1097 if ( btn->iconSet() && !btn->iconSet() ->isNull() ) {
1098 QIconSet::Mode mode = btn->isEnabled() 1098 QIconSet::Mode mode = btn->isEnabled()
1099 ? QIconSet::Normal : QIconSet::Disabled; 1099 ? QIconSet::Normal : QIconSet::Disabled;
1100 if ( mode == QIconSet::Normal && btn->hasFocus() ) 1100 if ( mode == QIconSet::Normal && btn->hasFocus() )
1101 mode = QIconSet::Active; 1101 mode = QIconSet::Active;
1102 QPixmap pixmap = btn->iconSet() ->pixmap( QIconSet::Small, mode ); 1102 QPixmap pixmap = btn->iconSet() ->pixmap( QIconSet::Small, mode );
1103 int pixw = pixmap.width(); 1103 int pixw = pixmap.width();
1104 int pixh = pixmap.height(); 1104 int pixh = pixmap.height();
1105 1105
1106 p->drawPixmap( x + 6, y + h / 2 - pixh / 2, pixmap ); 1106 p->drawPixmap( x + 6, y + h / 2 - pixh / 2, pixmap );
1107 x += pixw + 8; 1107 x += pixw + 8;
1108 w -= pixw + 8; 1108 w -= pixw + 8;
1109 } 1109 }
1110 1110
1111 if ( widget == PushButtonDown ) { 1111 if ( widget == PushButtonDown ) {
1112 drawItem( p, x + buttonXShift(), y + buttonYShift(), 1112 drawItem( p, x + buttonXShift(), y + buttonYShift(),
1113 w, h, AlignCenter | ShowPrefix, *cg, btn->isEnabled(), 1113 w, h, AlignCenter | ShowPrefix, *cg, btn->isEnabled(),
1114 btn->pixmap(), btn->text(), -1, &cg->buttonText() ); 1114 btn->pixmap(), btn->text(), -1, &cg->buttonText() );
1115 } 1115 }
1116 else { 1116 else {
1117 drawItem( p, x, y, w, h, AlignCenter | ShowPrefix, *cg, 1117 drawItem( p, x, y, w, h, AlignCenter | ShowPrefix, *cg,
1118 btn->isEnabled(), btn->pixmap(), btn->text(), -1, 1118 btn->isEnabled(), btn->pixmap(), btn->text(), -1,
1119 &cg->buttonText() ); 1119 &cg->buttonText() );
1120 } 1120 }
1121} 1121}
1122 1122
1123int OThemeStyle::splitterWidth() const 1123int OThemeStyle::splitterWidth() const
1124{ 1124{
1125 return ( splitWidth() ); 1125 return ( splitWidth() );
1126} 1126}
1127 1127
1128void OThemeStyle::drawSplitter( QPainter *p, int x, int y, int w, int h, 1128void OThemeStyle::drawSplitter( QPainter *p, int x, int y, int w, int h,
1129 const QColorGroup &g, Orientation ) 1129 const QColorGroup &g, Orientation )
1130{ 1130{
1131 drawBaseButton( p, x, y, w, h, *colorGroup( g, Splitter ), false, false, 1131 drawBaseButton( p, x, y, w, h, *colorGroup( g, Splitter ), false, false,
1132 Splitter ); 1132 Splitter );
1133} 1133}
1134 1134
1135void OThemeStyle::drawCheckMark( QPainter *p, int x, int y, int w, int h, 1135void OThemeStyle::drawCheckMark( QPainter *p, int x, int y, int w, int h,
1136 const QColorGroup &g, bool act, bool dis ) 1136 const QColorGroup &g, bool act, bool dis )
1137{ 1137{
1138 if ( isPixmap( CheckMark ) ) { 1138 if ( isPixmap( CheckMark ) ) {
1139 if ( !dis ) 1139 if ( !dis )
1140 p->drawPixmap( x + ( w - uncached( CheckMark ) ->width() ) / 2, 1140 p->drawPixmap( x + ( w - uncached( CheckMark ) ->width() ) / 2,
1141 y + ( h - uncached( CheckMark ) ->height() ) / 2, 1141 y + ( h - uncached( CheckMark ) ->height() ) / 2,
1142 *uncached( CheckMark ) ); 1142 *uncached( CheckMark ) );
1143 } 1143 }
1144 else 1144 else
1145 QWindowsStyle::drawCheckMark( p, x, y, w, h, *colorGroup( g, CheckMark ), 1145 QWindowsStyle::drawCheckMark( p, x, y, w, h, *colorGroup( g, CheckMark ),
1146 act, dis ); 1146 act, dis );
1147} 1147}
1148 1148
1149int OThemeStyle::popupMenuItemHeight( bool /*checkable*/, QMenuItem *mi, 1149int OThemeStyle::popupMenuItemHeight( bool /*checkable*/, QMenuItem *mi,
1150 const QFontMetrics &fm ) 1150 const QFontMetrics &fm )
1151{ 1151{
1152 int h2, h = 0; 1152 int h2, h = 0;
1153 int offset = QMAX( decoWidth( MenuItemDown ), decoWidth( MenuItem ) ) + 4; 1153 int offset = QMAX( decoWidth( MenuItemDown ), decoWidth( MenuItem ) ) + 4;
1154 1154
1155 if ( mi->isSeparator() ) 1155 if ( mi->isSeparator() )
1156 return ( 2 ); 1156 return ( 2 );
1157 if ( mi->isChecked() ) 1157 if ( mi->isChecked() )
1158 h = isPixmap( CheckMark ) ? uncached( CheckMark ) ->height() + offset : 1158 h = isPixmap( CheckMark ) ? uncached( CheckMark ) ->height() + offset :
1159 offset + 16; 1159 offset + 16;
1160 if ( mi->pixmap() ) { 1160 if ( mi->pixmap() ) {
1161 h2 = mi->pixmap() ->height() + offset; 1161 h2 = mi->pixmap() ->height() + offset;
1162 h = h2 > h ? h2 : h; 1162 h = h2 > h ? h2 : h;
1163 } 1163 }
1164 if ( mi->iconSet() ) { 1164 if ( mi->iconSet() ) {
1165 h2 = mi->iconSet() -> 1165 h2 = mi->iconSet() ->
1166 pixmap( QIconSet::Small, QIconSet::Normal ).height() + offset; 1166 pixmap( QIconSet::Small, QIconSet::Normal ).height() + offset;
1167 h = h2 > h ? h2 : h; 1167 h = h2 > h ? h2 : h;
1168 } 1168 }
1169 h2 = fm.height() + offset; 1169 h2 = fm.height() + offset;
1170 h = h2 > h ? h2 : h; 1170 h = h2 > h ? h2 : h;
1171 return ( h ); 1171 return ( h );
1172} 1172}
1173 1173
1174void OThemeStyle::drawPopupMenuItem( QPainter* p, bool checkable, int maxpmw, 1174void OThemeStyle::drawPopupMenuItem( QPainter* p, bool checkable, int maxpmw,
1175 int tab, QMenuItem* mi, 1175 int tab, QMenuItem* mi,
1176 const QPalette& pal, bool act, 1176 const QPalette& pal, bool act,
1177 bool enabled, int x, int y, int w, int h ) 1177 bool enabled, int x, int y, int w, int h )
1178{ 1178{
1179 // I changed the following method to be based from Qt's instead of my own 1179 // I changed the following method to be based from Qt's instead of my own
1180 // wacky code. Works much better now :P (mosfet) 1180 // wacky code. Works much better now :P (mosfet)
1181 static const int motifItemFrame = 2; // menu item frame width 1181 static const int motifItemFrame = 2; // menu item frame width
1182 static const int motifItemHMargin = 5; // menu item hor text margin 1182 static const int motifItemHMargin = 5; // menu item hor text margin
1183 static const int motifItemVMargin = 4; // menu item ver text margin 1183 static const int motifItemVMargin = 4; // menu item ver text margin
1184 1184
1185 static const int motifArrowHMargin = 6; // arrow horizontal margin 1185 static const int motifArrowHMargin = 6; // arrow horizontal margin
1186 static const int windowsRightBorder = 12; // right border on windowsstatic const int windowsCheckMarkWidth = 12; // checkmarks width on windows 1186 static const int windowsRightBorder = 12; // right border on windowsstatic const int windowsCheckMarkWidth = 12; // checkmarks width on windows
1187 bool dis = !enabled; 1187 bool dis = !enabled;
1188 const QColorGroup &g = dis ? *colorGroup( pal.normal(), MenuItem ) : 1188 const QColorGroup &g = dis ? *colorGroup( pal.normal(), MenuItem ) :
1189 *colorGroup( pal.normal(), MenuItemDown ); 1189 *colorGroup( pal.normal(), MenuItemDown );
1190 1190
1191 QColorGroup itemg = dis ? *colorGroup( pal.disabled(), MenuItem ) 1191 QColorGroup itemg = dis ? *colorGroup( pal.disabled(), MenuItem )
1192 : act ? *colorGroup( pal.active(), MenuItemDown ) 1192 : act ? *colorGroup( pal.active(), MenuItemDown )
1193 : *colorGroup( pal.normal(), MenuItem ); 1193 : *colorGroup( pal.normal(), MenuItem );
1194 1194
1195 maxpmw = QMAX( maxpmw, 20 ); 1195 maxpmw = QMAX( maxpmw, 20 );
1196 int checkcol = maxpmw; 1196 int checkcol = maxpmw;
1197 1197
1198 if ( mi && mi->isSeparator() ) { 1198 if ( mi && mi->isSeparator() ) {
1199 p->setPen( g.dark() ); 1199 p->setPen( g.dark() );
1200 p->drawLine( x, y, x + w, y ); 1200 p->drawLine( x, y, x + w, y );
1201 p->setPen( g.light() ); 1201 p->setPen( g.light() );
1202 p->drawLine( x, y + 1, x + w, y + 1 ); 1202 p->drawLine( x, y + 1, x + w, y + 1 );
1203 return ; 1203 return ;
1204 } 1204 }
1205 if ( act ) { 1205 if ( act ) {
1206 drawBaseButton( p, x, y, w, h, g, true, false, MenuItemDown ); 1206 drawBaseButton( p, x, y, w, h, g, true, false, MenuItemDown );
1207 } 1207 }
1208 else { 1208 else {
1209 drawShade( p, x, y, w, h, *colorGroup( g, MenuItem ), false, false, 1209 drawShade( p, x, y, w, h, *colorGroup( g, MenuItem ), false, false,
1210 highlightWidth( MenuItem ), borderWidth( MenuItem ), 1210 highlightWidth( MenuItem ), borderWidth( MenuItem ),
1211 shade() ); 1211 shade() );
1212 int dw = decoWidth( MenuItem ); 1212 int dw = decoWidth( MenuItem );
1213 if ( !isPixmap( MenuItem ) ) 1213 if ( !isPixmap( MenuItem ) ) {
1214 p->fillRect( x + dw, y + dw, w - dw * 2, h - dw * 2, 1214 p->fillRect( x + dw, y + dw, w - dw * 2, h - dw * 2,
1215 colorGroup( g, MenuItem ) -> 1215 colorGroup( g, MenuItem ) ->
1216 brush( QColorGroup::Background ) ); 1216 brush( QColorGroup::Background ) );
1217 }
1217 else { 1218 else {
1218 // process inactive item pixmaps as one large item 1219 // process inactive item pixmaps as one large item
1219 p->drawTiledPixmap( x + dw, y + dw, w - dw * 2, h - dw * 2, *scalePixmap 1220 p->drawTiledPixmap( x + dw, y + dw, w - dw * 2, h - dw * 2, *scalePixmap
1220 // (w, p->window().height(), MenuItem), 1221 (w, ((QWidget *)p->device())->height(), MenuItem),
1221 ( w, p->clipRegion().boundingRect().height(), MenuItem ), 1222 //( w, p->clipRegion().boundingRect().height(), MenuItem ), // cliping does not work in Qt/E
1222 x, y ); 1223 x, y );
1223 } 1224 }
1224 1225
1225 if ( checkable && mi && mi->isChecked() ) { 1226 if ( checkable && mi && mi->isChecked() ) {
1226 // draw 'pressed' border around checkable items 1227 // draw 'pressed' border around checkable items
1227 // This is extremely important for items that have an iconset 1228 // This is extremely important for items that have an iconset
1228 // because the checkmark isn't drawn in that case 1229 // because the checkmark isn't drawn in that case
1229 // An alternative would be superimposing the checkmark over 1230 // An alternative would be superimposing the checkmark over
1230 // the iconset instead or not drawing the iconset at all. 1231 // the iconset instead or not drawing the iconset at all.
1231 int mw = checkcol + motifItemFrame; 1232 int mw = checkcol + motifItemFrame;
1232 drawShade( p, x, y, mw, h, g, true, false, 1233 drawShade( p, x, y, mw, h, g, true, false,
1233 highlightWidth( MenuItemDown ), 1234 highlightWidth( MenuItemDown ),
1234 borderWidth( MenuItemDown ), shade() ); 1235 borderWidth( MenuItemDown ), shade() );
1235 } 1236 }
1236 } 1237 }
1237 if ( !mi ) 1238 if ( !mi )
1238 return ; 1239 return ;
1239 if ( mi->iconSet() ) { 1240 if ( mi->iconSet() ) {
1240 QIconSet::Mode mode = dis ? QIconSet::Disabled : QIconSet::Normal; 1241 QIconSet::Mode mode = dis ? QIconSet::Disabled : QIconSet::Normal;
1241 if ( act && !dis ) 1242 if ( act && !dis )
1242 mode = QIconSet::Active; 1243 mode = QIconSet::Active;
1243 QPixmap pixmap = mi->iconSet() ->pixmap( QIconSet::Small, mode ); 1244 QPixmap pixmap = mi->iconSet() ->pixmap( QIconSet::Small, mode );
1244 int pixw = pixmap.width(); 1245 int pixw = pixmap.width();
1245 int pixh = pixmap.height(); 1246 int pixh = pixmap.height();
1246 QRect cr( x, y, checkcol, h ); 1247 QRect cr( x, y, checkcol, h );
1247 QRect pmr( 0, 0, pixw, pixh ); 1248 QRect pmr( 0, 0, pixw, pixh );
1248 pmr.moveCenter( cr.center() ); 1249 pmr.moveCenter( cr.center() );
1249 p->setPen( itemg.text() ); 1250 p->setPen( itemg.text() );
1250 p->drawPixmap( pmr.topLeft(), pixmap ); 1251 p->drawPixmap( pmr.topLeft(), pixmap );
1251 1252
1252 } 1253 }
1253 else if ( checkable ) { 1254 else if ( checkable ) {
1254 int mw = checkcol + motifItemFrame; 1255 int mw = checkcol + motifItemFrame;
1255 int mh = h - 2 * motifItemFrame; 1256 int mh = h - 2 * motifItemFrame;
1256 if ( mi->isChecked() ) { 1257 if ( mi->isChecked() ) {
1257 drawCheckMark( p, x + motifItemFrame, 1258 drawCheckMark( p, x + motifItemFrame,
1258 y + motifItemFrame, mw, mh, itemg, act, dis ); 1259 y + motifItemFrame, mw, mh, itemg, act, dis );
1259 } 1260 }
1260 } 1261 }
1261 1262
1262 p->setPen( colorGroup( g, act ? MenuItemDown : MenuItem ) ->text() ); 1263 p->setPen( colorGroup( g, act ? MenuItemDown : MenuItem ) ->text() );
1263 1264
1264 QColor discol; 1265 QColor discol;
1265 if ( dis ) { 1266 if ( dis ) {
1266 discol = itemg.text(); 1267 discol = itemg.text();
1267 p->setPen( discol ); 1268 p->setPen( discol );
1268 } 1269 }
1269 1270
1270 int xm = motifItemFrame + checkcol + motifItemHMargin; 1271 int xm = motifItemFrame + checkcol + motifItemHMargin;
1271 1272
1272 QString s = mi->text(); 1273 QString s = mi->text();
1273 if ( !s.isNull() ) { 1274 if ( !s.isNull() ) {
1274 int t = s.find( '\t' ); 1275 int t = s.find( '\t' );
1275 int m = motifItemVMargin; 1276 int m = motifItemVMargin;
1276 const int text_flags = AlignVCenter | ShowPrefix | DontClip | SingleLine; 1277 const int text_flags = AlignVCenter | ShowPrefix | DontClip | SingleLine;
1277 if ( t >= 0 ) { 1278 if ( t >= 0 ) {
1278 if ( dis && !act ) { 1279 if ( dis && !act ) {
1279 p->setPen( g.light() ); 1280 p->setPen( g.light() );
1280 p->drawText( x + w - tab - windowsRightBorder - motifItemHMargin - motifItemFrame + 1, 1281 p->drawText( x + w - tab - windowsRightBorder - motifItemHMargin - motifItemFrame + 1,
1281 y + m + 1, tab, h - 2 * m, text_flags, s.mid( t + 1 ) ); 1282 y + m + 1, tab, h - 2 * m, text_flags, s.mid( t + 1 ) );
1282 p->setPen( discol ); 1283 p->setPen( discol );
1283 } 1284 }
1284 p->drawText( x + w - tab - windowsRightBorder - motifItemHMargin - motifItemFrame, 1285 p->drawText( x + w - tab - windowsRightBorder - motifItemHMargin - motifItemFrame,
1285 y + m, tab, h - 2 * m, text_flags, s.mid( t + 1 ) ); 1286 y + m, tab, h - 2 * m, text_flags, s.mid( t + 1 ) );
1286 } 1287 }
1287 if ( dis && !act ) { 1288 if ( dis && !act ) {
1288 p->setPen( g.light() ); 1289 p->setPen( g.light() );
1289 p->drawText( x + xm + 1, y + m + 1, w - xm + 1, h - 2 * m, text_flags, s, t ); 1290 p->drawText( x + xm + 1, y + m + 1, w - xm + 1, h - 2 * m, text_flags, s, t );
1290 p->setPen( discol ); 1291 p->setPen( discol );
1291 } 1292 }
1292 p->drawText( x + xm, y + m, w - xm - tab + 1, h - 2 * m, text_flags, s, t ); 1293 p->drawText( x + xm, y + m, w - xm - tab + 1, h - 2 * m, text_flags, s, t );
1293 } 1294 }
1294 else if ( mi->pixmap() ) { 1295 else if ( mi->pixmap() ) {
1295 QPixmap * pixmap = mi->pixmap(); 1296 QPixmap * pixmap = mi->pixmap();
1296 if ( pixmap->depth() == 1 ) 1297 if ( pixmap->depth() == 1 )
1297 p->setBackgroundMode( OpaqueMode ); 1298 p->setBackgroundMode( OpaqueMode );
1298 p->drawPixmap( x + xm, y + motifItemFrame, *pixmap ); 1299 p->drawPixmap( x + xm, y + motifItemFrame, *pixmap );
1299 if ( pixmap->depth() == 1 ) 1300 if ( pixmap->depth() == 1 )
1300 p->setBackgroundMode( TransparentMode ); 1301 p->setBackgroundMode( TransparentMode );
1301 } 1302 }
1302 if ( mi->popup() ) { 1303 if ( mi->popup() ) {
1303 int dim = ( h - 2 * motifItemFrame ) / 2; 1304 int dim = ( h - 2 * motifItemFrame ) / 2;
1304 if ( act ) { 1305 if ( act ) {
1305 if ( !dis ) 1306 if ( !dis )
1306 discol = colorGroup( g, MenuItemDown ) ->text(); 1307 discol = colorGroup( g, MenuItemDown ) ->text();
1307 //discol = white; 1308 //discol = white;
1308 QColorGroup g2( discol, g.highlight(), 1309 QColorGroup g2( discol, g.highlight(),
1309 white, white, 1310 white, white,
1310 dis ? discol : white, 1311 dis ? discol : white,
1311 discol, white ); 1312 discol, white );
1312 drawArrow( p, RightArrow, true, 1313 drawArrow( p, RightArrow, true,
1313 x + w - motifArrowHMargin - motifItemFrame - dim, y + h / 2 - dim / 2, 1314 x + w - motifArrowHMargin - motifItemFrame - dim, y + h / 2 - dim / 2,
1314 dim, dim, g2, TRUE ); 1315 dim, dim, g2, TRUE );
1315 } 1316 }
1316 else { 1317 else {
1317 drawArrow( p, RightArrow, 1318 drawArrow( p, RightArrow,
1318 false, 1319 false,
1319 x + w - motifArrowHMargin - motifItemFrame - dim, y + h / 2 - dim / 2, 1320 x + w - motifArrowHMargin - motifItemFrame - dim, y + h / 2 - dim / 2,
1320 dim, dim, g, mi->isEnabled() ); 1321 dim, dim, g, mi->isEnabled() );
1321 } 1322 }
1322 } 1323 }
1323} 1324}
1324 1325
1325void OThemeStyle::drawFocusRect( QPainter *p, const QRect &r, 1326void OThemeStyle::drawFocusRect( QPainter *p, const QRect &r,
1326 const QColorGroup &g, const QColor *c, 1327 const QColorGroup &g, const QColor *c,
1327 bool atBorder ) 1328 bool atBorder )
1328{ 1329{
1329 p->setPen( g.dark() ); 1330 p->setPen( g.dark() );
1330 if ( !is3DFocus() ) 1331 if ( !is3DFocus() )
1331 QWindowsStyle::drawFocusRect( p, r, g, c, atBorder ); 1332 QWindowsStyle::drawFocusRect( p, r, g, c, atBorder );
1332 else { 1333 else {
1333 int i = focusOffset(); 1334 int i = focusOffset();
1334 p->drawLine( r.x() + i, r.y() + 1 + i, r.x() + i, r.bottom() - 1 - i ); 1335 p->drawLine( r.x() + i, r.y() + 1 + i, r.x() + i, r.bottom() - 1 - i );
1335 p->drawLine( r.x() + 1 + i, r.y() + i, r.right() - 1 - i, r.y() + i ); 1336 p->drawLine( r.x() + 1 + i, r.y() + i, r.right() - 1 - i, r.y() + i );
1336 p->setPen( g.light() ); 1337 p->setPen( g.light() );
1337 p->drawLine( r.right() - i, r.y() + 1 + i, r.right() - i, r.bottom() - 1 - i ); 1338 p->drawLine( r.right() - i, r.y() + 1 + i, r.right() - i, r.bottom() - 1 - i );
1338 p->drawLine( r.x() + 1 + i, r.bottom() - i, r.right() - 1 - i, r.bottom() - i ); 1339 p->drawLine( r.x() + 1 + i, r.bottom() - i, r.right() - 1 - i, r.bottom() - i );
1339 } 1340 }
1340} 1341}
1341 1342
1342#if 0 1343#if 0
1343void OThemeStyle::drawKMenuBar( QPainter *p, int x, int y, int w, int h, 1344void OThemeStyle::drawKMenuBar( QPainter *p, int x, int y, int w, int h,
1344 const QColorGroup &g, bool, QBrush * ) 1345 const QColorGroup &g, bool, QBrush * )
1345{ 1346{
1346 drawBaseButton( p, x, y, w, h, *colorGroup( g, MenuBar ), false, false, 1347 drawBaseButton( p, x, y, w, h, *colorGroup( g, MenuBar ), false, false,
1347 MenuBar ); 1348 MenuBar );
1348} 1349}
1349 1350
1350void OThemeStyle::drawKMenuItem( QPainter *p, int x, int y, int w, int h, 1351void OThemeStyle::drawKMenuItem( QPainter *p, int x, int y, int w, int h,
1351 const QColorGroup &g, bool active, 1352 const QColorGroup &g, bool active,
1352 QMenuItem *mi, QBrush * ) 1353 QMenuItem *mi, QBrush * )
1353{ 1354{
1354 const QColorGroup * cg = colorGroup( g, active ? MenuBarItem : MenuBar ); 1355 const QColorGroup * cg = colorGroup( g, active ? MenuBarItem : MenuBar );
1355 QColor btext = cg->buttonText(); 1356 QColor btext = cg->buttonText();
1356 if ( active ) 1357 if ( active )
1357 drawBaseButton( p, x, y, w, h, *cg, false, false, MenuBarItem ); 1358 drawBaseButton( p, x, y, w, h, *cg, false, false, MenuBarItem );
1358 //qDrawShadePanel(p, x, y, w, h, *cg, false, 1); 1359 //qDrawShadePanel(p, x, y, w, h, *cg, false, 1);
1359 1360
1360 drawItem( p, x, y, w, h, AlignCenter | ShowPrefix | DontClip | SingleLine, 1361 drawItem( p, x, y, w, h, AlignCenter | ShowPrefix | DontClip | SingleLine,
1361 *cg, mi->isEnabled(), mi->pixmap(), mi->text(), 1362 *cg, mi->isEnabled(), mi->pixmap(), mi->text(),
1362 -1, &btext ); 1363 -1, &btext );
1363 ; 1364 ;
1364} 1365}
1365 1366
1366void OThemeStyle::drawKProgressBlock( QPainter *p, int x, int y, int w, int h, 1367void OThemeStyle::drawKProgressBlock( QPainter *p, int x, int y, int w, int h,
1367 const QColorGroup &g, QBrush * ) 1368 const QColorGroup &g, QBrush * )
1368{ 1369{
1369 drawBaseButton( p, x, y, w, h, *colorGroup( g, ProgressBar ), false, false, 1370 drawBaseButton( p, x, y, w, h, *colorGroup( g, ProgressBar ), false, false,
1370 ProgressBar ); 1371 ProgressBar );
1371} 1372}
1372 1373
1373void OThemeStyle::getKProgressBackground( const QColorGroup &g, QBrush &bg ) 1374void OThemeStyle::getKProgressBackground( const QColorGroup &g, QBrush &bg )
1374{ 1375{
1375 const QColorGroup * cg = colorGroup( g, ProgressBg ); 1376 const QColorGroup * cg = colorGroup( g, ProgressBg );
1376 bg.setColor( cg->color( QColorGroup::Background ) ); 1377 bg.setColor( cg->color( QColorGroup::Background ) );
1377 if ( isPixmap( ProgressBg ) ) 1378 if ( isPixmap( ProgressBg ) )
1378 bg.setPixmap( *uncached( ProgressBg ) ); 1379 bg.setPixmap( *uncached( ProgressBg ) );
1379} 1380}
1380#endif 1381#endif
1381 1382
1382void OThemeStyle::tabbarMetrics( const QTabBar* t, int& hframe, int& vframe, int& overlap ) 1383void OThemeStyle::tabbarMetrics( const QTabBar* t, int& hframe, int& vframe, int& overlap )
1383{ 1384{
1384 QCommonStyle::tabbarMetrics( t, hframe, vframe, overlap ); 1385 QCommonStyle::tabbarMetrics( t, hframe, vframe, overlap );
1385} 1386}
1386 1387
1387void OThemeStyle::drawTab( QPainter* p, const QTabBar* tb, QTab* t , 1388void OThemeStyle::drawTab( QPainter* p, const QTabBar* tb, QTab* t ,
1388 bool selected ) 1389 bool selected )
1389{ 1390{
1390 WidgetType widget = selected ? ActiveTab : InactiveTab; 1391 WidgetType widget = selected ? ActiveTab : InactiveTab;
1391 const QColorGroup *cg = colorGroup( tb->colorGroup(), widget ); 1392 const QColorGroup *cg = colorGroup( tb->colorGroup(), widget );
1392 int i; 1393 int i;
1393 int x = t->r.x(), y = t->r.y(); 1394 int x = t->r.x(), y = t->r.y();
1394 int x2 = t->r.right(), y2 = t->r.bottom(); 1395 int x2 = t->r.right(), y2 = t->r.bottom();
1395 int bWidth = borderWidth( widget ); 1396 int bWidth = borderWidth( widget );
1396 int hWidth = highlightWidth( widget ); 1397 int hWidth = highlightWidth( widget );
1397 if ( tb->shape() == QTabBar::RoundedAbove ) { 1398 if ( tb->shape() == QTabBar::RoundedAbove ) {
1398 if ( !selected ) { 1399 if ( !selected ) {
1399 p->fillRect( x, y, x2 - x + 1, 2, 1400 p->fillRect( x, y, x2 - x + 1, 2,
1400 tb->palette().normal().brush( QColorGroup::Background ) ); 1401 tb->palette().normal().brush( QColorGroup::Background ) );
1401 y += 2; 1402 y += 2;
1402 } 1403 }
1403 p->setPen( cg->text() ); 1404 p->setPen( cg->text() );
1404 i = 0; 1405 i = 0;
1405 if ( i < bWidth ) { 1406 if ( i < bWidth ) {
1406 p->drawLine( x, y + 1, x, y2 ); 1407 p->drawLine( x, y + 1, x, y2 );
1407 p->drawLine( x2, y + 1, x2, y2 ); 1408 p->drawLine( x2, y + 1, x2, y2 );
1408 p->drawLine( x + 1, y, x2 - 1, y ); 1409 p->drawLine( x + 1, y, x2 - 1, y );
1409 if ( selected ? activeTabLine() : inactiveTabLine() ) { 1410 if ( selected ? activeTabLine() : inactiveTabLine() ) {
1410 p->drawLine( x, y2, x2, y2 ); 1411 p->drawLine( x, y2, x2, y2 );
1411 --y2; 1412 --y2;
1412 } 1413 }
1413 ++i, ++x, ++y, --x2; 1414 ++i, ++x, ++y, --x2;