author | llornkcor <llornkcor> | 2002-06-25 01:46:34 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-06-25 01:46:34 (UTC) |
commit | 4bf0efd9f4c6963b48be4a7b836a3c1c46431814 (patch) (unidiff) | |
tree | c58bff748d51ef18e82c34b310b2b26462223a94 /noncore/styles/metal/metal.cpp | |
parent | 2da629c52c3cbfebff7b314b8668ccd579bb6742 (diff) | |
download | opie-4bf0efd9f4c6963b48be4a7b836a3c1c46431814.zip opie-4bf0efd9f4c6963b48be4a7b836a3c1c46431814.tar.gz opie-4bf0efd9f4c6963b48be4a7b836a3c1c46431814.tar.bz2 |
took about 3 minutes to add, so.. what the heck..
Diffstat (limited to 'noncore/styles/metal/metal.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/styles/metal/metal.cpp | 514 |
1 files changed, 514 insertions, 0 deletions
diff --git a/noncore/styles/metal/metal.cpp b/noncore/styles/metal/metal.cpp new file mode 100644 index 0000000..2380fed --- a/dev/null +++ b/noncore/styles/metal/metal.cpp | |||
@@ -0,0 +1,514 @@ | |||
1 | /**************************************************************************** | ||
2 | ** $Id$ | ||
3 | ** | ||
4 | ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. | ||
5 | ** | ||
6 | ** This file is part of an example program for Qt. This example | ||
7 | ** program may be used, distributed and modified without limitation. | ||
8 | ** | ||
9 | *****************************************************************************/ | ||
10 | |||
11 | #include "metal.h" | ||
12 | #include <qapplication.h> | ||
13 | #include <qpainter.h> | ||
14 | #include <qdrawutil.h> // for now | ||
15 | #include <qpixmap.h> // for now | ||
16 | #include <qpalette.h> // for now | ||
17 | #include <qwidget.h> | ||
18 | #include <qlabel.h> | ||
19 | #include <qimage.h> | ||
20 | #include <qpushbutton.h> | ||
21 | #include <qwidget.h> | ||
22 | #include <qrangecontrol.h> | ||
23 | #include <qscrollbar.h> | ||
24 | #include <limits.h> | ||
25 | |||
26 | |||
27 | ///////////////////////////////////////////////////////// | ||
28 | #include "stonedark.xpm" | ||
29 | #include "stone1.xpm" | ||
30 | #include "marble.xpm" | ||
31 | /////////////////////////////////////////////////////// | ||
32 | |||
33 | |||
34 | |||
35 | MetalStyle::MetalStyle() : QWindowsStyle() { } | ||
36 | |||
37 | /*! | ||
38 | Reimplementation from QStyle | ||
39 | */ | ||
40 | void MetalStyle::polish( QApplication *app) | ||
41 | { | ||
42 | oldPalette = app->palette(); | ||
43 | |||
44 | // we simply create a nice QColorGroup with a couple of fancy | ||
45 | // pixmaps here and apply to it all widgets | ||
46 | |||
47 | QFont f("times", app->font().pointSize() ); | ||
48 | f.setBold( TRUE ); | ||
49 | f.setItalic( TRUE ); | ||
50 | app->setFont( f, TRUE, "QMenuBar"); | ||
51 | app->setFont( f, TRUE, "QPopupMenu"); | ||
52 | |||
53 | |||
54 | //QPixmap button( stone1_xpm ); | ||
55 | QPixmap button( stonedark_xpm ); | ||
56 | QPixmap background(marble_xpm); | ||
57 | #if 0 | ||
58 | |||
59 | int i; | ||
60 | for (i=0; i<img.numColors(); i++) { | ||
61 | QRgb rgb = img.color(i); | ||
62 | QColor c(rgb); | ||
63 | rgb = c.dark().rgb(); | ||
64 | img.setColor(i,rgb); | ||
65 | } | ||
66 | QPixmap mid; | ||
67 | mid.convertFromImage(img); | ||
68 | |||
69 | img = orig; | ||
70 | for (i=0; i<img.numColors(); i++) { | ||
71 | QRgb rgb = img.color(i); | ||
72 | QColor c(rgb); | ||
73 | rgb = c.light().rgb(); | ||
74 | img.setColor(i,rgb); | ||
75 | } | ||
76 | QPixmap light; | ||
77 | light.convertFromImage(img); | ||
78 | |||
79 | img = orig; | ||
80 | for (i=0; i<img.numColors(); i++) { | ||
81 | QRgb rgb = img.color(i); | ||
82 | QColor c(rgb); | ||
83 | rgb = c.dark().rgb(); | ||
84 | img.setColor(i,rgb); | ||
85 | } | ||
86 | QPixmap dark; | ||
87 | dark.convertFromImage(img); | ||
88 | #else | ||
89 | QPixmap dark( 1, 1 ); dark.fill( red.dark() ); | ||
90 | QPixmap mid( stone1_xpm ); | ||
91 | QPixmap light( stone1_xpm );//1, 1 ); light.fill( green ); | ||
92 | #endif | ||
93 | QPalette op = app->palette(); | ||
94 | |||
95 | QColor backCol( 227,227,227 ); | ||
96 | |||
97 | // QPalette op(white); | ||
98 | QColorGroup active (op.normal().foreground(), | ||
99 | QBrush(op.normal().button(),button), | ||
100 | QBrush(op.normal().light(), light), | ||
101 | QBrush(op.normal().dark(), dark), | ||
102 | QBrush(op.normal().mid(), mid), | ||
103 | op.normal().text(), | ||
104 | Qt::white, | ||
105 | op.normal().base(),// QColor(236,182,120), | ||
106 | QBrush(backCol, background) | ||
107 | ); | ||
108 | active.setColor( QColorGroup::ButtonText, Qt::white ); | ||
109 | active.setColor( QColorGroup::Shadow, Qt::black ); | ||
110 | QColorGroup disabled (op.disabled().foreground(), | ||
111 | QBrush(op.disabled().button(),button), | ||
112 | QBrush(op.disabled().light(), light), | ||
113 | op.disabled().dark(), | ||
114 | QBrush(op.disabled().mid(), mid), | ||
115 | op.disabled().text(), | ||
116 | Qt::white, | ||
117 | op.disabled().base(),// QColor(236,182,120), | ||
118 | QBrush(backCol, background) | ||
119 | ); | ||
120 | |||
121 | QPalette newPalette( active, disabled, active ); | ||
122 | app->setPalette( newPalette, TRUE ); | ||
123 | } | ||
124 | |||
125 | /*! | ||
126 | Reimplementation from QStyle | ||
127 | */ | ||
128 | void MetalStyle::unPolish( QApplication *app) | ||
129 | { | ||
130 | app->setPalette(oldPalette, TRUE); | ||
131 | app->setFont( app->font(), TRUE ); | ||
132 | } | ||
133 | |||
134 | /*! | ||
135 | Reimplementation from QStyle | ||
136 | */ | ||
137 | void MetalStyle::polish( QWidget* w) | ||
138 | { | ||
139 | |||
140 | // the polish function sets some widgets to transparent mode and | ||
141 | // some to translate background mode in order to get the full | ||
142 | // benefit from the nice pixmaps in the color group. | ||
143 | |||
144 | if (w->inherits("QPushButton")){ | ||
145 | w->setBackgroundMode( QWidget::NoBackground ); | ||
146 | return; | ||
147 | } | ||
148 | |||
149 | if (w->inherits("QTipLabel") || w->inherits("QLCDNumber") ){ | ||
150 | return; | ||
151 | } | ||
152 | |||
153 | if ( !w->isTopLevel() ) { | ||
154 | if ( w->inherits("QGroupBox") | ||
155 | || w->inherits("QTabWidget") ) { | ||
156 | w->setAutoMask( TRUE ); | ||
157 | return; | ||
158 | } | ||
159 | if (w->inherits("QLabel") | ||
160 | || w->inherits("QSlider") | ||
161 | || w->inherits("QButton") | ||
162 | || w->inherits("QProgressBar") | ||
163 | ){ | ||
164 | w->setBackgroundOrigin( QWidget::ParentOrigin ); | ||
165 | } | ||
166 | } | ||
167 | } | ||
168 | |||
169 | void MetalStyle::unPolish( QWidget* w) | ||
170 | { | ||
171 | |||
172 | // the polish function sets some widgets to transparent mode and | ||
173 | // some to translate background mode in order to get the full | ||
174 | // benefit from the nice pixmaps in the color group. | ||
175 | |||
176 | if (w->inherits("QPushButton")){ | ||
177 | w->setBackgroundMode( QWidget::PaletteButton ); | ||
178 | return; | ||
179 | } | ||
180 | |||
181 | if (w->inherits("QTipLabel") || w->inherits("QLCDNumber") ){ | ||
182 | return; | ||
183 | } | ||
184 | |||
185 | if ( !w->isTopLevel() ) { | ||
186 | if ( w->inherits("QGroupBox") | ||
187 | || w->inherits("QTabWidget") ) { | ||
188 | w->setAutoMask( FALSE ); | ||
189 | return; | ||
190 | } | ||
191 | if (w->inherits("QLabel") | ||
192 | || w->inherits("QSlider") | ||
193 | || w->inherits("QButton") | ||
194 | || w->inherits("QProgressBar") | ||
195 | ){ | ||
196 | w->setBackgroundOrigin( QWidget::WidgetOrigin ); | ||
197 | } | ||
198 | } | ||
199 | |||
200 | } | ||
201 | |||
202 | /*! | ||
203 | Draw a metallic button, sunken if \a sunken is TRUE, horizontal if | ||
204 | /a horz is TRUE. | ||
205 | */ | ||
206 | |||
207 | void MetalStyle::drawMetalButton( QPainter *p, int x, int y, int w, int h, | ||
208 | bool sunken, bool horz ) | ||
209 | { | ||
210 | QColor top1("#878769691515"); | ||
211 | QColor top2("#C6C6B4B44949"); | ||
212 | |||
213 | QColor bot2("#70705B5B1414"); | ||
214 | QColor bot1("56564A4A0E0E"); //first from the bottom | ||
215 | |||
216 | QColor highlight("#E8E8DDDD6565"); | ||
217 | QColor subh1("#CECEBDBD5151"); | ||
218 | QColor subh2("#BFBFACAC4545"); | ||
219 | |||
220 | QColor topgrad("#B9B9A5A54040"); | ||
221 | QColor botgrad("#89896C6C1A1A"); | ||
222 | |||
223 | |||
224 | int x2 = x + w - 1; | ||
225 | int y2 = y + h - 1; | ||
226 | |||
227 | //frame: | ||
228 | |||
229 | p->setPen( top1 ); | ||
230 | p->drawLine( x, y2, x, y ); | ||
231 | p->drawLine( x, y, x2-1, y ); | ||
232 | p->setPen( top2 ); | ||
233 | p->drawLine( x+1, y2 -1, x+1, y+1 ); | ||
234 | p->drawLine( x+1, y+1 , x2-2, y+1 ); | ||
235 | |||
236 | p->setPen( bot1 ); | ||
237 | p->drawLine( x+1, y2, x2, y2 ); | ||
238 | p->drawLine( x2, y2, x2, y ); | ||
239 | p->setPen( bot2 ); | ||
240 | p->drawLine( x+1, y2-1, x2-1, y2-1 ); | ||
241 | p->drawLine( x2-1, y2-1, x2-1, y+1 ); | ||
242 | |||
243 | // highlight: | ||
244 | int i = 0; | ||
245 | int x1 = x + 2; | ||
246 | int y1 = y + 2; | ||
247 | if ( horz ) | ||
248 | x2 = x2 - 2; | ||
249 | else | ||
250 | y2 = y2 - 2; | ||
251 | // Note that x2/y2 mean something else from this point down... | ||
252 | |||
253 | #define DRAWLINE if (horz) \ | ||
254 | p->drawLine( x1, y1+i, x2, y1+i ); \ | ||
255 | else \ | ||
256 | p->drawLine( x1+i, y1, x1+i, y2 ); \ | ||
257 | i++; | ||
258 | |||
259 | if ( !sunken ) { | ||
260 | p->setPen( highlight ); | ||
261 | DRAWLINE; | ||
262 | DRAWLINE; | ||
263 | p->setPen( subh1 ); | ||
264 | DRAWLINE; | ||
265 | p->setPen( subh2 ); | ||
266 | DRAWLINE; | ||
267 | } | ||
268 | // gradient: | ||
269 | int ng = (horz ? h : w) - 8; // how many lines for the gradient? | ||
270 | |||
271 | int h1, h2, s1, s2, v1, v2; | ||
272 | if ( !sunken ) { | ||
273 | topgrad.hsv( &h1, &s1, &v1 ); | ||
274 | botgrad.hsv( &h2, &s2, &v2 ); | ||
275 | } else { | ||
276 | botgrad.hsv( &h1, &s1, &v1 ); | ||
277 | topgrad.hsv( &h2, &s2, &v2 ); | ||
278 | } | ||
279 | |||
280 | if ( ng > 1 ) { | ||
281 | |||
282 | for ( int j =0; j < ng; j++ ) { | ||
283 | p->setPen( QColor( h1 + ((h2-h1)*j)/(ng-1), | ||
284 | s1 + ((s2-s1)*j)/(ng-1), | ||
285 | v1 + ((v2-v1)*j)/(ng-1), QColor::Hsv ) ); | ||
286 | DRAWLINE; | ||
287 | } | ||
288 | } else if ( ng == 1 ) { | ||
289 | p->setPen( QColor( (h1+h2)/2, (s1+s2)/2, (v1+v2)/2, QColor::Hsv ) ); | ||
290 | DRAWLINE; | ||
291 | } | ||
292 | if ( sunken ) { | ||
293 | p->setPen( subh2 ); | ||
294 | DRAWLINE; | ||
295 | |||
296 | p->setPen( subh1 ); | ||
297 | DRAWLINE; | ||
298 | |||
299 | p->setPen( highlight ); | ||
300 | DRAWLINE; | ||
301 | DRAWLINE; | ||
302 | } | ||
303 | |||
304 | } | ||
305 | |||
306 | |||
307 | |||
308 | /*! | ||
309 | Reimplementation from QStyle | ||
310 | */ | ||
311 | void MetalStyle::drawButton( QPainter *p, int x, int y, int w, int h, | ||
312 | const QColorGroup &, bool sunken, const QBrush*) | ||
313 | { | ||
314 | |||
315 | drawMetalButton( p, x, y, w, h, sunken, TRUE ); | ||
316 | } | ||
317 | |||
318 | /*! | ||
319 | Reimplementation from QStyle | ||
320 | */ | ||
321 | void MetalStyle::drawBevelButton( QPainter *p, int x, int y, int w, int h, | ||
322 | const QColorGroup &, bool sunken, const QBrush*) | ||
323 | { | ||
324 | MetalStyle::drawMetalButton(p, x, y, w, h, sunken, TRUE ); | ||
325 | } | ||
326 | |||
327 | /*! | ||
328 | Reimplementation from QStyle | ||
329 | */ | ||
330 | void MetalStyle::drawPushButton( QPushButton* btn, QPainter *p) | ||
331 | { | ||
332 | QColorGroup g = btn->colorGroup(); | ||
333 | int x1, y1, x2, y2; | ||
334 | |||
335 | btn->rect().coords( &x1, &y1, &x2, &y2 ); // get coordinates | ||
336 | |||
337 | p->setPen( g.foreground() ); | ||
338 | p->setBrush( QBrush(g.button(),NoBrush) ); | ||
339 | |||
340 | QBrush fill; | ||
341 | if ( btn->isDown() ) | ||
342 | fill = g.brush( QColorGroup::Mid ); | ||
343 | else if ( btn->isOn() ) | ||
344 | fill = QBrush( g.mid(), Dense4Pattern ); | ||
345 | else | ||
346 | fill = g.brush( QColorGroup::Button ); | ||
347 | |||
348 | if ( btn->isDefault() ) { | ||
349 | QPointArray a; | ||
350 | a.setPoints( 9, | ||
351 | x1, y1, x2, y1, x2, y2, x1, y2, x1, y1+1, | ||
352 | x2-1, y1+1, x2-1, y2-1, x1+1, y2-1, x1+1, y1+1 ); | ||
353 | p->setPen( Qt::black ); | ||
354 | p->drawPolyline( a ); | ||
355 | x1 += 2; | ||
356 | y1 += 2; | ||
357 | x2 -= 2; | ||
358 | y2 -= 2; | ||
359 | } | ||
360 | |||
361 | drawMetalButton( p, x1, y1, x2-x1+1, y2-y1+1, btn->isOn() || btn->isDown(), | ||
362 | TRUE ); // always horizontal | ||
363 | |||
364 | |||
365 | if ( btn->isMenuButton() ) { | ||
366 | int dx = (y1-y2-4)/3; | ||
367 | drawArrow( p, DownArrow, FALSE, | ||
368 | x2 - dx, dx, y1, y2 - y1, | ||
369 | g, btn->isEnabled() ); | ||
370 | } | ||
371 | |||
372 | if ( p->brush().style() != NoBrush ) | ||
373 | p->setBrush( NoBrush ); | ||
374 | |||
375 | } | ||
376 | |||
377 | |||
378 | /*! | ||
379 | Reimplementation from QStyle | ||
380 | */ | ||
381 | void MetalStyle::drawPushButtonLabel( QPushButton* btn, QPainter *p) | ||
382 | { | ||
383 | QRect r = btn->rect(); | ||
384 | int x, y, w, h; | ||
385 | r.rect( &x, &y, &w, &h ); | ||
386 | |||
387 | int x1, y1, x2, y2; | ||
388 | btn->rect().coords( &x1, &y1, &x2, &y2 ); // get coordinates | ||
389 | int dx = 0; | ||
390 | int dy = 0; | ||
391 | if ( btn->isMenuButton() ) | ||
392 | dx = (y2-y1) / 3; | ||
393 | if ( btn->isOn() || btn->isDown() ) { | ||
394 | dx--; | ||
395 | dy--; | ||
396 | } | ||
397 | if ( dx || dy ) | ||
398 | p->translate( dx, dy ); | ||
399 | |||
400 | x += 2; y += 2; w -= 4; h -= 4; | ||
401 | QColorGroup g = btn->colorGroup(); | ||
402 | drawItem( p, x, y, w, h, | ||
403 | AlignCenter|ShowPrefix, | ||
404 | g, btn->isEnabled(), | ||
405 | btn->pixmap(), btn->text(), -1, | ||
406 | (btn->isDown() || btn->isOn())?&btn->colorGroup().brightText():&btn->colorGroup().buttonText()); | ||
407 | |||
408 | if ( dx || dy ) | ||
409 | p->translate( -dx, -dy ); | ||
410 | } | ||
411 | |||
412 | |||
413 | void MetalStyle::drawPanel( QPainter *p, int x, int y, int w, int h, | ||
414 | const QColorGroup &g, bool sunken, | ||
415 | int lineWidth, const QBrush *fill ) | ||
416 | { | ||
417 | |||
418 | QStyle::drawPanel( p, x, y, w, h, | ||
419 | g, sunken, | ||
420 | lineWidth, fill ); | ||
421 | } | ||
422 | |||
423 | |||
424 | /*! | ||
425 | Reimplemented | ||
426 | */ | ||
427 | |||
428 | void MetalStyle::drawSlider( QPainter *p, int x, int y, int w, int h, | ||
429 | const QColorGroup &, Orientation orient, | ||
430 | bool /*tickAbove*/, bool /*tickBelow*/ ) | ||
431 | { | ||
432 | drawMetalButton( p, x, y, w, h, FALSE, orient != Horizontal ); | ||
433 | } | ||
434 | |||
435 | |||
436 | void MetalStyle::drawScrollBarControls( QPainter* p, const QScrollBar* sb, | ||
437 | int sliderStart, uint controls, | ||
438 | uint activeControl ) | ||
439 | { | ||
440 | QWindowsStyle::drawScrollBarControls( p, sb, sliderStart, controls & ~(AddLine|SubLine|Slider), | ||
441 | activeControl & ~(AddLine|SubLine|Slider) ); | ||
442 | bool horz = sb->orientation() == QScrollBar::Horizontal; | ||
443 | int b = 2; | ||
444 | int w = horz ? sb->height() : sb->width(); | ||
445 | |||
446 | QColorGroup g = sb->colorGroup(); | ||
447 | |||
448 | int sliderMin, sliderMax, sliderLength, buttonDim; | ||
449 | scrollBarMetrics( sb, sliderMin, sliderMax, sliderLength, buttonDim ); | ||
450 | |||
451 | if (sliderStart > sliderMax) { // sanity check | ||
452 | sliderStart = sliderMax; | ||
453 | } | ||
454 | bool maxedOut = (sb->maxValue() == sb->minValue()); | ||
455 | |||
456 | |||
457 | if ( controls & AddLine ) { | ||
458 | bool sunken = activeControl & AddLine; | ||
459 | QRect r( b, b, w-2*b, w-2*b ) ; | ||
460 | if ( horz ) | ||
461 | r.moveBy( sb->width() - w, 0 ); | ||
462 | else | ||
463 | r.moveBy( 0, sb->height() - w ); | ||
464 | |||
465 | drawMetalButton( p, r.x(), r.y(), r.width(), r.height(), | ||
466 | sunken, !horz ); | ||
467 | drawArrow( p, horz ? RightArrow : DownArrow, sunken, | ||
468 | r.x(), r.y(), r.width(), r.height(), g, !maxedOut ); | ||
469 | |||
470 | } | ||
471 | if ( controls & SubLine ) { | ||
472 | bool sunken = activeControl & SubLine; | ||
473 | QRect r( b, b, w-2*b, w-2*b ) ; | ||
474 | drawMetalButton( p, r.x(), r.y(), r.width(), r.height(), | ||
475 | sunken, !horz ); | ||
476 | drawArrow( p, horz ? LeftArrow : UpArrow, sunken, | ||
477 | r.x(), r.y(), r.width(), r.height(), g, !maxedOut ); | ||
478 | } | ||
479 | |||
480 | QRect sliderR; | ||
481 | if ( horz ) { | ||
482 | sliderR .setRect( sliderStart, b, sliderLength, w-2*b ); | ||
483 | } else { | ||
484 | sliderR .setRect( b, sliderStart, w-2*b, sliderLength ); | ||
485 | } | ||
486 | if ( controls & Slider ) { | ||
487 | if ( !maxedOut ) { | ||
488 | drawMetalButton( p, sliderR.x(), sliderR.y(), | ||
489 | sliderR.width(), sliderR.height(), | ||
490 | FALSE, horz ); | ||
491 | } | ||
492 | } | ||
493 | |||
494 | } | ||
495 | |||
496 | |||
497 | void MetalStyle::drawComboButton( QPainter *p, int x, int y, int w, int h, | ||
498 | const QColorGroup &g, bool sunken, | ||
499 | bool /*editable*/, | ||
500 | bool enabled, | ||
501 | const QBrush *fill) | ||
502 | { | ||
503 | |||
504 | qDrawWinPanel(p, x, y, w, h, g, TRUE, | ||
505 | fill?fill:(enabled?&g.brush( QColorGroup::Base ): | ||
506 | &g.brush( QColorGroup::Background ))); | ||
507 | |||
508 | |||
509 | drawMetalButton( p, x+w-2-16, y+2, 16, h-4, sunken, TRUE ); | ||
510 | |||
511 | drawArrow( p, QStyle::DownArrow, sunken, | ||
512 | x+w-2-16+ 2, y+2+ 2, 16- 4, h-4- 4, g, enabled ); | ||
513 | |||
514 | } | ||