summaryrefslogtreecommitdiff
path: root/library/qpestyle.cpp
authorkergoth <kergoth>2002-01-25 22:14:26 (UTC)
committer kergoth <kergoth>2002-01-25 22:14:26 (UTC)
commit15318cad33835e4e2dc620d033e43cd930676cdd (patch) (unidiff)
treec2fa0399a2c47fda8e2cd0092c73a809d17f68eb /library/qpestyle.cpp
downloadopie-15318cad33835e4e2dc620d033e43cd930676cdd.zip
opie-15318cad33835e4e2dc620d033e43cd930676cdd.tar.gz
opie-15318cad33835e4e2dc620d033e43cd930676cdd.tar.bz2
Initial revision
Diffstat (limited to 'library/qpestyle.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--library/qpestyle.cpp1194
1 files changed, 1194 insertions, 0 deletions
diff --git a/library/qpestyle.cpp b/library/qpestyle.cpp
new file mode 100644
index 0000000..dfd300f
--- a/dev/null
+++ b/library/qpestyle.cpp
@@ -0,0 +1,1194 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include "qpestyle.h"
22#include "qpeapplication.h"
23#include <qpushbutton.h>
24
25#include <qpainter.h>
26
27#define QCOORDARRLEN(x) sizeof(x)/(sizeof(QCOORD)*2)
28
29#if QT_VERSION >= 300
30
31#include <qdrawutil.h>
32#include <qcombobox.h>
33#include <qtabbar.h>
34
35QPEStyle::QPEStyle()
36{
37}
38
39QPEStyle::~QPEStyle()
40{
41}
42
43void QPEStyle::drawPrimitive( PrimitiveElement pe, QPainter *p, const QRect &r,
44 const QColorGroup &cg, SFlags flags, const QStyleOption &data) const
45{
46 switch ( pe ) {
47 case PE_ButtonTool:
48 {
49 QColorGroup mycg = cg;
50 if ( flags & Style_On ) {
51 QBrush fill( cg.mid(), Dense4Pattern );
52 mycg.setBrush( QColorGroup::Button, fill );
53 }
54 drawPrimitive( PE_ButtonBevel, p, r, mycg, flags, data );
55 break;
56 }
57 case PE_ButtonCommand:
58 case PE_ButtonDefault:
59 case PE_ButtonBevel:
60 case PE_HeaderSection:
61 {
62 QPen oldPen = p->pen();
63 p->fillRect( r.x()+1, r.y()+1, r.width()-2, r.height()-2, cg.brush(QColorGroup::Button) );
64
65 int x2 = r.right();
66 int y2 = r.bottom();
67
68 if ( flags & (Style_Sunken | Style_Down | Style_On) )
69 p->setPen( cg.dark() );
70 else
71 p->setPen( cg.light() );
72 p->drawLine( r.x(), r.y()+1, r.x(), y2-1 );
73 p->drawLine( r.x()+1, r.y(), x2-1, r.y() );
74
75 if ( flags & (Style_Sunken | Style_Down | Style_On) )
76 p->setPen( cg.light() );
77 else
78 p->setPen( cg.dark() );
79 p->drawLine( x2, r.y()+1, x2, y2-1 );
80 p->drawLine( r.x()+1, y2, x2-1, y2 );
81 p->setPen( oldPen );
82 break;
83 }
84 case PE_FocusRect:
85 break;
86 case PE_Indicator:
87 {
88 QColorGroup mycg( cg );
89 QBrush fill;
90 if ( flags & Style_Down )
91 fill = cg.brush( QColorGroup::Button );
92 else
93 fill = cg.brush( (flags&Style_Enabled) ? QColorGroup::Base : QColorGroup::Background );
94 mycg.setBrush( QColorGroup::Button, fill );
95 if ( flags&Style_Enabled )
96 flags |= Style_Sunken;
97 drawPrimitive( PE_ButtonBevel, p, r, mycg, flags );
98 if ( flags & Style_On ) {
99 QPointArray a( 7*2 );
100 int i, xx, yy;
101 xx = r.x()+3;
102 yy = r.y()+5;
103 for ( i=0; i<3; i++ ) {
104 a.setPoint( 2*i, xx, yy );
105 a.setPoint( 2*i+1, xx, yy+2 );
106 xx++; yy++;
107 }
108 yy -= 2;
109 for ( i=3; i<7; i++ ) {
110 a.setPoint( 2*i, xx, yy );
111 a.setPoint( 2*i+1, xx, yy+2 );
112 xx++; yy--;
113 }
114 if ( flags & Style_NoChange ) {
115 p->setPen( mycg.dark() );
116 } else {
117 p->setPen( mycg.text() );
118 }
119 p->drawLineSegments( a );
120 }
121 break;
122 }
123 case PE_ExclusiveIndicator:
124 {
125 static const QCOORD pts1[] = { // dark lines
126 1,9, 1,8, 0,7, 0,4, 1,3, 1,2, 2,1, 3,1, 4,0, 7,0, 8,1, 9,1 };
127 static const QCOORD pts4[] = { // white lines
128 2,10, 3,10, 4,11, 7,11, 8,10, 9,10, 10,9, 10,8, 11,7,
129 11,4, 10,3, 10,2 };
130 static const QCOORD pts5[] = { // inner fill
131 4,2, 7,2, 9,4, 9,7, 7,9, 4,9, 2,7, 2,4 };
132
133 int x, y, w, h;
134 r.rect( &x, &y, &w, &h );
135 p->eraseRect( x, y, w, h );
136 QPointArray a( QCOORDARRLEN(pts1), pts1 );
137 a.translate( x, y );
138 p->setPen( cg.dark() );
139 p->drawPolyline( a );
140 a.setPoints( QCOORDARRLEN(pts4), pts4 );
141 a.translate( x, y );
142 p->setPen( cg.light() );
143 p->drawPolyline( a );
144 a.setPoints( QCOORDARRLEN(pts5), pts5 );
145 a.translate( x, y );
146 QColor fillColor = ( flags&Style_Down || !(flags&Style_Enabled) ) ? cg.button() : cg.base();
147 p->setPen( fillColor );
148 p->setBrush( fillColor ) ;
149 p->drawPolygon( a );
150 if ( flags&Style_On ) {
151 p->setPen( NoPen );
152 p->setBrush( cg.text() );
153 p->drawRect( x+5, y+4, 2, 4 );
154 p->drawRect( x+4, y+5, 4, 2 );
155 }
156 break;
157 }
158 default:
159 QWindowsStyle::drawPrimitive( pe, p, r, cg, flags, data );
160 break;
161 }
162}
163
164void QPEStyle::drawControl( ControlElement ce, QPainter *p,
165 const QWidget *widget, const QRect &r,
166 const QColorGroup &cg, SFlags how, const QStyleOption &data) const
167{
168 switch ( ce ) {
169 case CE_PushButton:
170 {
171 const QPushButton *btn = (QPushButton*)widget;
172 SFlags flags;
173 flags = Style_Default;
174 if ( btn->isDown() )
175 flags |= Style_Down;
176 if ( btn->isOn() )
177 flags |= Style_On;
178 if ( btn->isEnabled() )
179 flags |= Style_Enabled;
180 if ( btn->isDefault() )
181 flags |= Style_Default;
182 if (! btn->isFlat() && !(flags & Style_Down))
183 flags |= Style_Raised;
184 p->setPen( cg.foreground() );
185 p->setBrush( QBrush(cg.button(), NoBrush) );
186 QColorGroup mycg( cg );
187 if ( flags & Style_On ) {
188 QBrush fill = QBrush( cg.mid(), Dense4Pattern );
189 mycg.setBrush( QColorGroup::Button, fill );
190 }
191 drawPrimitive( PE_ButtonBevel, p, r, mycg, flags, data );
192 break;
193 }
194 case CE_TabBarTab:
195 {
196 if ( !widget || !widget->parentWidget() )
197 break;
198
199 const QTabBar *tb = (const QTabBar *) widget;
200 bool selected = how & Style_Selected;
201
202 QRect r2(r);
203 if ( tb->shape() == QTabBar::RoundedAbove ) {
204 p->setPen( cg.light() );
205 p->drawLine( r2.left(), r2.bottom(), r2.right(), r2.bottom() );
206 if ( r2.left() == 0 )
207 p->drawPoint( tb->rect().bottomLeft() );
208 else {
209 p->setPen( cg.light() );
210 p->drawLine( r2.left(), r2.bottom(), r2.right(), r2.bottom() );
211 }
212
213 if ( selected ) {
214 p->setPen( cg.background() );
215 p->drawLine( r2.left()+2, r2.top()+1, r2.right()-2, r2.top()+1 );
216 p->fillRect( QRect( r2.left()+1, r2.top()+2, r2.width()-2, r2.height()-2),
217 cg.brush( QColorGroup::Background ));
218 } else {
219 r2.setRect( r2.left() + 2, r2.top() + 2,
220 r2.width() - 4, r2.height() - 2 );
221 p->setPen( cg.button() );
222 p->drawLine( r2.left()+2, r2.top()+1, r2.right()-2, r2.top()+1 );
223 p->fillRect( QRect( r2.left()+1, r2.top()+2, r2.width()-2, r2.height()-3),
224 cg.brush( QColorGroup::Button ));
225
226 //do shading; will not work for pixmap brushes
227 QColor bg = cg.button();
228 // int h,s,v;
229 // bg.hsv( &h, &s, &v );
230 int n = r2.height()/2;
231 int dark = 100;
232 for ( int i = 1; i < n; i++ ) {
233 dark = (dark * (100+(i*15)/n) )/100;
234 p->setPen( bg.dark( dark ) );
235 int y = r2.bottom()-n+i;
236 int x1 = r2.left()+1;
237 int x2 = r2.right()-1;
238 p->drawLine( x1, y, x2, y );
239 }
240 }
241
242 p->setPen( cg.light() );
243 p->drawLine( r2.left(), r2.bottom()-1, r2.left(), r2.top() + 2 );
244 p->drawPoint( r2.left()+1, r2.top() + 1 );
245 p->drawLine( r2.left()+2, r2.top(),
246 r2.right() - 2, r2.top() );
247
248 p->setPen( cg.dark() );
249 p->drawPoint( r2.right() - 1, r2.top() + 1 );
250 p->drawLine( r2.right(), r2.top() + 2, r2.right(), r2.bottom() - 1);
251 } else if ( tb->shape() == QTabBar::RoundedBelow ) {
252 if ( selected ) {
253 p->setPen( cg.background() );
254 p->drawLine( r2.left()+2, r2.bottom()-1, r2.right()-2, r2.bottom()-1 );
255 p->fillRect( QRect( r2.left()+1, r2.top(), r2.width()-2, r2.height()-2),
256 tb->palette().normal().brush( QColorGroup::Background ));
257 } else {
258 p->setPen( cg.dark() );
259 p->drawLine( r2.left(), r2.top(),
260 r2.right(), r2.top() );
261 r2.setRect( r2.left() + 2, r2.top(),
262 r2.width() - 4, r2.height() - 2 );
263 p->setPen( cg.button() );
264 p->drawLine( r2.left()+2, r2.bottom()-1, r2.right()-2, r2.bottom()-1 );
265 p->fillRect( QRect( r2.left()+1, r2.top()+1, r2.width()-2, r2.height()-3),
266 tb->palette().normal().brush( QColorGroup::Button ));
267 }
268
269 p->setPen( cg.dark() );
270 p->drawLine( r2.right(), r2.top(),
271 r2.right(), r2.bottom() - 2 );
272 p->drawPoint( r2.right() - 1, r2.bottom() - 1 );
273 p->drawLine( r2.right() - 2, r2.bottom(),
274 r2.left() + 2, r2.bottom() );
275
276 p->setPen( cg.light() );
277 p->drawLine( r2.left(), r2.top()+1,
278 r2.left(), r2.bottom() - 2 );
279 p->drawPoint( r2.left() + 1, r2.bottom() - 1 );
280 if ( r2.left() == 0 )
281 p->drawPoint( tb->rect().topLeft() );
282
283 } else {
284 QCommonStyle::drawControl( ce, p, widget, r, cg, how, data );
285 }
286 break;
287 }
288 default:
289 QWindowsStyle::drawControl( ce, p, widget, r, cg, how, data );
290 break;
291 }
292}
293
294void QPEStyle::drawComplexControl( ComplexControl control, QPainter *p,
295 const QWidget *widget, const QRect &r,
296 const QColorGroup &cg, SFlags how,
297 SCFlags sub, SCFlags subActive, const QStyleOption &data) const
298{
299 switch ( control ) {
300 case CC_ComboBox:
301 if ( sub & SC_ComboBoxArrow ) {
302 SFlags flags = Style_Default;
303
304 drawPrimitive( PE_ButtonBevel, p, r, cg, flags, data );
305
306 QRect ar =
307 QStyle::visualRect( querySubControlMetrics( CC_ComboBox, widget,
308 SC_ComboBoxArrow ), widget );
309
310 if ( subActive == SC_ComboBoxArrow ) {
311 p->setPen( cg.dark() );
312 p->setBrush( cg.brush( QColorGroup::Button ) );
313 p->drawRect( ar );
314 }
315
316 ar.addCoords( 2, 2, -2, -2 );
317 if ( widget->isEnabled() )
318 flags |= Style_Enabled;
319
320 if ( subActive & Style_Sunken ) {
321 flags |= Style_Sunken;
322 }
323 drawPrimitive( PE_ArrowDown, p, ar, cg, flags );
324 }
325
326 if ( sub & SC_ComboBoxEditField ) {
327 const QComboBox * cb = (const QComboBox *) widget;
328 QRect re =
329 QStyle::visualRect( querySubControlMetrics( CC_ComboBox, widget,
330 SC_ComboBoxEditField ), widget );
331 if ( cb->hasFocus() && !cb->editable() )
332 p->fillRect( re.x(), re.y(), re.width(), re.height(),
333 cg.brush( QColorGroup::Highlight ) );
334
335 if ( cb->hasFocus() ) {
336 p->setPen( cg.highlightedText() );
337 p->setBackgroundColor( cg.highlight() );
338
339 } else {
340 p->setPen( cg.text() );
341 p->setBackgroundColor( cg.background() );
342 }
343
344 if ( cb->hasFocus() && !cb->editable() ) {
345 QRect re =
346 QStyle::visualRect( subRect( SR_ComboBoxFocusRect, cb ), widget );
347 drawPrimitive( PE_FocusRect, p, re, cg, Style_FocusAtBorder, QStyleOption(cg.highlight()));
348 }
349 }
350 break;
351 default:
352 QWindowsStyle::drawComplexControl( control, p, widget, r, cg, how,
353 sub, subActive, data );
354 break;
355 }
356}
357
358int QPEStyle::pixelMetric( PixelMetric metric, const QWidget *widget ) const
359{
360 int ret;
361 switch( metric ) {
362 case PM_ButtonMargin:
363 ret = 2;
364 break;
365 case PM_DefaultFrameWidth:
366 ret = 1;
367 break;
368 case PM_ButtonDefaultIndicator:
369 ret = 2;
370 break;
371 case PM_ButtonShiftHorizontal:
372 case PM_ButtonShiftVertical:
373 ret = -1;
374 break;
375 case PM_IndicatorWidth:
376 ret = 15;
377 break;
378 case PM_IndicatorHeight:
379 ret = 13;
380 break;
381 case PM_ExclusiveIndicatorHeight:
382 case PM_ExclusiveIndicatorWidth:
383 ret = 15;
384 break;
385 case PM_ScrollBarExtent:
386 ret = 13;
387 break;
388 case PM_SliderLength:
389 ret = 12;
390 break;
391 default:
392 ret = QWindowsStyle::pixelMetric( metric, widget );
393 break;
394 }
395 return ret;
396}
397
398QSize QPEStyle::sizeFromContents( ContentsType contents, const QWidget *widget,
399 const QSize &contentsSize, const QStyleOption &data) const
400{
401 QSize sz(contentsSize);
402
403 switch ( contents ) {
404 case CT_PopupMenuItem:
405 {
406 if ( !widget || data.isDefault() )
407 break;
408 sz = QWindowsStyle::sizeFromContents( contents, widget, contentsSize, data );
409 sz = QSize( sz.width(), sz.height()-2 );
410 break;
411 }
412 default:
413 sz = QWindowsStyle::sizeFromContents( contents, widget, contentsSize, data );
414 break;
415 }
416
417 return sz;
418}
419
420#else
421
422#include <qfontmetrics.h>
423#include <qpalette.h>
424#include <qdrawutil.h>
425#include <qscrollbar.h>
426#include <qbutton.h>
427#include <qframe.h>
428#include <qtabbar.h>
429
430#define INCLUDE_MENUITEM_DEF
431#include <qmenudata.h>
432
433QPEStyle::QPEStyle()
434{
435#if QT_VERSION < 300
436 setButtonMargin(buttonMargin());
437 setScrollBarExtent(scrollBarExtent().width(),scrollBarExtent().height());
438#endif
439}
440
441QPEStyle::~QPEStyle()
442{
443}
444
445int QPEStyle::buttonMargin() const
446{
447 return 2;
448}
449
450QSize QPEStyle::scrollBarExtent() const
451{
452 return QSize(13,13);
453}
454
455void QPEStyle::polish ( QPalette & )
456{
457}
458
459void QPEStyle::polish( QWidget *w )
460{
461 if ( w->inherits( "QListBox" ) ||
462 w->inherits( "QListView" ) ||
463 w->inherits( "QPopupMenu" ) ||
464 w->inherits( "QSpinBox" ) ) {
465 QFrame *f = (QFrame *)w;
466 f->setFrameShape( QFrame::StyledPanel );
467 f->setLineWidth( 1 );
468 }
469}
470
471void QPEStyle::unPolish( QWidget *w )
472{
473 if ( w->inherits( "QListBox" ) ||
474 w->inherits( "QListView" ) ||
475 w->inherits( "QPopupMenu" ) ||
476 w->inherits( "QSpinBox" ) ) {
477 QFrame *f = (QFrame *)w;
478 f->setFrameShape( QFrame::StyledPanel );
479 f->setLineWidth( 2 );
480 }
481}
482
483int QPEStyle::defaultFrameWidth() const
484{
485 return 1;
486}
487
488void QPEStyle::drawPanel ( QPainter * p, int x, int y, int w, int h,
489 const QColorGroup &g, bool sunken, int lineWidth, const QBrush * fill )
490{
491 qDrawShadePanel( p, QRect(x, y, w, h), g, sunken, lineWidth, fill );
492}
493
494void QPEStyle::drawButton( QPainter *p, int x, int y, int w, int h,
495 const QColorGroup &g, bool sunken, const QBrush* fill )
496{
497 QPen oldPen = p->pen();
498 if ( sunken )
499 p->setPen( g.dark() );
500 else
501 p->setPen( g.light() );
502
503 int x2 = x+w-1;
504 int y2 = y+h-1;
505
506 p->drawLine( x, y, x, y2 );
507 p->drawLine( x, y, x2, y );
508
509 if ( sunken )
510 p->setPen( g.light() );
511 else
512 p->setPen( g.dark() );
513
514 p->drawLine( x2, y, x2, y2 );
515 p->drawLine( x, y2, x2, y2 );
516 p->setPen( oldPen );
517
518 p->fillRect( x+1, y+1, w-2, h-2, fill?(*fill):g.brush(QColorGroup::Button) );
519}
520
521void QPEStyle::drawButtonMask ( QPainter * p, int x, int y, int w, int h )
522{
523 p->fillRect( x, y, w, h, color1 );
524}
525
526void QPEStyle::drawBevelButton( QPainter *p, int x, int y, int w, int h,
527 const QColorGroup &g, bool sunken, const QBrush* fill )
528{
529 drawButton( p, x, y, w, h, g, sunken, fill );
530}
531
532QRect QPEStyle::comboButtonRect( int x, int y, int w, int h)
533{
534 return QRect(x+1, y+1, w-2-14, h-2);
535}
536
537
538QRect QPEStyle::comboButtonFocusRect( int x, int y, int w, int h)
539{
540 return QRect(x+2, y+2, w-4-14, h-4);
541}
542
543void QPEStyle::drawComboButton( QPainter *p, int x, int y, int w, int h,
544 const QColorGroup &g, bool sunken,
545 bool /*editable*/,
546 bool enabled,
547 const QBrush *fill )
548{
549 drawBevelButton( p, x, y, w, h, g, FALSE, fill );
550 drawBevelButton( p, x+w-14, y, 14, h, g, sunken, fill );
551 drawArrow( p, QStyle::DownArrow, sunken,
552 x+w-14+ 2, y+ 2, 14- 4, h- 4, g, enabled,
553 &g.brush( QColorGroup::Button ) );
554
555}
556
557
558void QPEStyle::drawExclusiveIndicator ( QPainter * p, int x, int y, int w,
559 int h, const QColorGroup & g, bool on, bool down, bool enabled )
560{
561 static const QCOORD pts1[] = { // dark lines
562 1,9, 1,8, 0,7, 0,4, 1,3, 1,2, 2,1, 3,1, 4,0, 7,0, 8,1, 9,1 };
563 static const QCOORD pts4[] = { // white lines
564 2,10, 3,10, 4,11, 7,11, 8,10, 9,10, 10,9, 10,8, 11,7,
565 11,4, 10,3, 10,2 };
566 static const QCOORD pts5[] = { // inner fill
567 4,2, 7,2, 9,4, 9,7, 7,9, 4,9, 2,7, 2,4 };
568
569 p->eraseRect( x, y, w, h );
570 QPointArray a( QCOORDARRLEN(pts1), pts1 );
571 a.translate( x, y );
572 p->setPen( g.dark() );
573 p->drawPolyline( a );
574 a.setPoints( QCOORDARRLEN(pts4), pts4 );
575 a.translate( x, y );
576 p->setPen( g.light() );
577 p->drawPolyline( a );
578 a.setPoints( QCOORDARRLEN(pts5), pts5 );
579 a.translate( x, y );
580 QColor fillColor = ( down || !enabled ) ? g.button() : g.base();
581 p->setPen( fillColor );
582 p->setBrush( fillColor ) ;
583 p->drawPolygon( a );
584 if ( on ) {
585 p->setPen( NoPen );
586 p->setBrush( g.text() );
587 p->drawRect( x+5, y+4, 2, 4 );
588 p->drawRect( x+4, y+5, 4, 2 );
589 }
590}
591
592void QPEStyle::drawIndicator ( QPainter * p, int x, int y, int w, int h,
593 const QColorGroup & g, int state, bool down, bool enabled )
594{
595
596 QBrush fill;
597 if ( state == QButton::NoChange ) {
598 QBrush b = p->brush();
599 QColor c = p->backgroundColor();
600 p->setBackgroundMode( TransparentMode );
601 p->setBackgroundColor( green );
602 fill = QBrush(g.base(), Dense4Pattern);
603 p->setBackgroundColor( c );
604 p->setBrush( b );
605 } else if ( down )
606 fill = g.brush( QColorGroup::Button );
607 else
608 fill = g.brush( enabled ? QColorGroup::Base : QColorGroup::Background );
609 drawPanel( p, x, y, w, h, g, TRUE, 1, &fill );
610 if ( state != QButton::Off ) {
611 QPointArray a( 7*2 );
612 int i, xx, yy;
613 xx = x+3;
614 yy = y+5;
615 for ( i=0; i<3; i++ ) {
616 a.setPoint( 2*i, xx, yy );
617 a.setPoint( 2*i+1, xx, yy+2 );
618 xx++; yy++;
619 }
620 yy -= 2;
621 for ( i=3; i<7; i++ ) {
622 a.setPoint( 2*i, xx, yy );
623 a.setPoint( 2*i+1, xx, yy+2 );
624 xx++; yy--;
625 }
626 if ( state == QButton::NoChange ) {
627 p->setPen( g.dark() );
628 } else {
629 p->setPen( g.text() );
630 }
631 p->drawLineSegments( a );
632 }
633}
634
635 #define HORIZONTAL(sb->orientation() == QScrollBar::Horizontal)
636 #define VERTICAL!HORIZONTAL
637 #define MOTIF_BORDER2
638 #define SLIDER_MIN9 // ### motif says 6 but that's too small
639
640/*! \reimp */
641
642void QPEStyle::scrollBarMetrics( const QScrollBar* sb, int &sliderMin, int &sliderMax, int &sliderLength, int& buttonDim )
643{
644 int maxLength;
645 int length = HORIZONTAL ? sb->width() : sb->height();
646 int extent = HORIZONTAL ? sb->height() : sb->width();
647
648 if ( length > (extent - 1)*2 )
649 buttonDim = extent;
650 else
651 buttonDim = length/2 - 1;
652
653 sliderMin = 0;
654 maxLength = length - buttonDim*2;
655
656 if ( sb->maxValue() == sb->minValue() ) {
657 sliderLength = maxLength;
658 } else {
659 sliderLength = (sb->pageStep()*maxLength)/
660 (sb->maxValue()-sb->minValue()+sb->pageStep());
661 uint range = sb->maxValue()-sb->minValue();
662 if ( sliderLength < SLIDER_MIN || range > INT_MAX/2 )
663 sliderLength = SLIDER_MIN;
664 if ( sliderLength > maxLength )
665 sliderLength = maxLength;
666 }
667
668 sliderMax = sliderMin + maxLength - sliderLength;
669}
670
671/*!\reimp
672 */
673QStyle::ScrollControl QPEStyle::scrollBarPointOver( const QScrollBar* sb, int sliderStart, const QPoint& p )
674{
675 if ( !sb->rect().contains( p ) )
676 return NoScroll;
677 int sliderMin, sliderMax, sliderLength, buttonDim, pos;
678 scrollBarMetrics( sb, sliderMin, sliderMax, sliderLength, buttonDim );
679
680 if (sb->orientation() == QScrollBar::Horizontal)
681 pos = p.x();
682 else
683 pos = p.y();
684
685 if (pos < sliderStart)
686 return SubPage;
687 if (pos < sliderStart + sliderLength)
688 return Slider;
689 if (pos < sliderMax + sliderLength)
690 return AddPage;
691 if (pos < sliderMax + sliderLength + buttonDim)
692 return SubLine;
693 return AddLine;
694}
695
696/*! \reimp */
697
698void QPEStyle::drawScrollBarControls( QPainter* p, const QScrollBar* sb, int sliderStart, uint controls, uint activeControl )
699{
700#define ADD_LINE_ACTIVE ( activeControl == AddLine )
701#define SUB_LINE_ACTIVE ( activeControl == SubLine )
702 QColorGroup g = sb->colorGroup();
703
704 int sliderMin, sliderMax, sliderLength, buttonDim;
705 scrollBarMetrics( sb, sliderMin, sliderMax, sliderLength, buttonDim );
706
707 if ( controls == (AddLine | SubLine | AddPage | SubPage | Slider | First | Last ) )
708 p->fillRect( 0, 0, sb->width(), sb->height(), g.brush( QColorGroup::Mid ));
709
710 if (sliderStart > sliderMax) { // sanity check
711 sliderStart = sliderMax;
712 }
713
714 int dimB = buttonDim;
715 QRect addB;
716 QRect subB;
717 QRect addPageR;
718 QRect subPageR;
719 QRect sliderR;
720 int addX, addY, subX, subY;
721 int length = HORIZONTAL ? sb->width() : sb->height();
722 int extent = HORIZONTAL ? sb->height() : sb->width();
723
724 if ( HORIZONTAL ) {
725 subY = addY = ( extent - dimB ) / 2;
726 subX = length - dimB - dimB;
727 addX = length - dimB;
728 } else {
729 subX = addX = ( extent - dimB ) / 2;
730 subY = length - dimB - dimB;
731 addY = length - dimB;
732 }
733
734 int sliderEnd = sliderStart + sliderLength;
735 int sliderW = extent;
736 if ( HORIZONTAL ) {
737 subB.setRect( subX,subY+1,dimB,dimB-1 );
738 addB.setRect( addX,addY+1,dimB,dimB-1 );
739
740 subPageR.setRect( 0, 0,
741 sliderStart+1, sliderW );
742 addPageR.setRect( sliderEnd-1, 0, subX - sliderEnd+1, sliderW );
743 sliderR .setRect( sliderStart, 1, sliderLength, sliderW-1 );
744
745 } else {
746 subB.setRect( subX+1,subY,dimB-1,dimB );
747 addB.setRect( addX+1,addY,dimB-1,dimB );
748
749 subPageR.setRect( 0, 0, sliderW,
750 sliderStart+1 );
751 addPageR.setRect( 0, sliderEnd-1, sliderW, subY - sliderEnd+1 );
752 sliderR .setRect( 1, sliderStart, sliderW-1, sliderLength );
753 }
754
755 bool maxedOut = (sb->maxValue() == sb->minValue());
756 if ( controls & AddLine ) {
757 drawBevelButton( p, addB.x(), addB.y(),
758 addB.width(), addB.height(), g,
759 ADD_LINE_ACTIVE);
760 p->setPen(g.shadow());
761 drawArrow( p, VERTICAL ? DownArrow : RightArrow,
762 FALSE, addB.x()+2, addB.y()+2,
763 addB.width()-4, addB.height()-4, g, !maxedOut,
764 &g.brush( QColorGroup::Button ));
765 }
766 if ( controls & SubLine ) {
767 drawBevelButton( p, subB.x(), subB.y(),
768 subB.width(), subB.height(), g,
769 SUB_LINE_ACTIVE );
770 p->setPen(g.shadow());
771 drawArrow( p, VERTICAL ? UpArrow : LeftArrow,
772 FALSE, subB.x()+2, subB.y()+2,
773 subB.width()-4, subB.height()-4, g, !maxedOut,
774 &g.brush( QColorGroup::Button ));
775 }
776
777
778 if ( controls & SubPage )
779 p->fillRect( subPageR.x(), subPageR.y(), subPageR.width(),
780 subPageR.height(), g.brush( QColorGroup::Mid ));
781 if ( controls & AddPage )
782 p->fillRect( addPageR.x(), addPageR.y(), addPageR.width(),
783 addPageR.height(), g.brush( QColorGroup::Mid ));
784 if ( controls & Slider ) {
785 QPoint bo = p->brushOrigin();
786 p->setBrushOrigin(sliderR.topLeft());
787 drawBevelButton( p, sliderR.x(), sliderR.y(),
788 sliderR.width(), sliderR.height(), g,
789 FALSE, &g.brush( QColorGroup::Button ) );
790 p->setBrushOrigin(bo);
791 drawRiffles( p, sliderR.x(), sliderR.y(),
792 sliderR.width(), sliderR.height(), g, HORIZONTAL );
793 }
794
795 // ### perhaps this should not be able to accept focus if maxedOut?
796 if ( sb->hasFocus() && (controls & Slider) )
797 p->drawWinFocusRect( sliderR.x()+2, sliderR.y()+2,
798 sliderR.width()-5, sliderR.height()-5,
799 sb->backgroundColor() );
800
801}
802
803void QPEStyle::drawRiffles( QPainter* p, int x, int y, int w, int h,
804 const QColorGroup &g, bool horizontal )
805{
806 if (!horizontal) {
807 if (h > 20) {
808 y += (h-20)/2 ;
809 h = 20;
810 }
811 if (h > 12) {
812 int n = 3;
813 int my = y+h/2-4;
814 int i ;
815 p->setPen(g.light());
816 for (i=0; i<n; i++) {
817 p->drawLine(x+2, my+3*i, x+w-4, my+3*i);
818 }
819 p->setPen(g.dark());
820 my++;
821 for (i=0; i<n; i++) {
822 p->drawLine(x+2, my+3*i, x+w-4, my+3*i);
823 }
824 }
825 }
826 else {
827 if (w > 20) {
828 x += (w-20)/2 ;
829 w = 20;
830 }
831 if (w > 12) {
832 int n = 3;
833 int mx = x+w/2-4;
834 int i ;
835 p->setPen(g.light());
836 for (i=0; i<n; i++) {
837 p->drawLine(mx+3*i, y+2, mx + 3*i, y+h-4);
838 }
839 p->setPen(g.dark());
840 mx++;
841 for (i=0; i<n; i++) {
842 p->drawLine(mx+3*i, y+2, mx + 3*i, y+h-4);
843 }
844 }
845 }
846}
847
848int QPEStyle::sliderLength() const
849{
850 return 12;
851}
852
853void QPEStyle::drawSlider( QPainter *p, int x, int y, int w, int h,
854 const QColorGroup &g, Orientation o, bool tickAbove, bool tickBelow )
855{
856 int a = tickAbove ? 3 : 0;
857 int b = tickBelow ? 3 : 0;
858
859 if ( o == Horizontal ) {
860 drawBevelButton( p, x, y+a, w, h-a-b, g, FALSE, &g.brush( QColorGroup::Button ) );
861 int xp = x + w/2;
862 qDrawShadeLine( p, xp, y+a+2, xp, y+h-b-3, g );
863 } else {
864 drawBevelButton( p, x+a, y, w-a-b, h, g, FALSE, &g.brush( QColorGroup::Button ) );
865 int yp = y + h/2;
866 qDrawShadeLine( p, x+a+2, yp, x+w-b-3, yp, g );
867 }
868}
869
870void QPEStyle::drawSliderMask ( QPainter * p, int x, int y, int w, int h,
871 Orientation o, bool tickAbove, bool tickBelow )
872{
873 int a = tickAbove ? 3 : 0;
874 int b = tickBelow ? 3 : 0;
875 if ( o == Horizontal )
876 p->fillRect( x, y+a, w, h-a-b, color1 );
877 else
878 p->fillRect( x+a, y, w-a-b, h, color1 );
879}
880
881/*!\reimp
882 */
883void QPEStyle::drawSliderGrooveMask( QPainter *p,
884 int x, int y, int w, int h,
885 const QColorGroup& , QCOORD c,
886 Orientation orient )
887{
888 if ( orient == Horizontal )
889 p->fillRect( x, y + c - 2, w, 4, color1 );
890 else
891 p->fillRect( x + c - 2, y, 4, h, color1 );
892}
893
894void QPEStyle::drawTab( QPainter *p, const QTabBar *tb, QTab *t, bool selected )
895{
896 QRect r( t->rect() );
897 if ( tb->shape() == QTabBar::RoundedAbove ) {
898 p->setPen( tb->colorGroup().light() );
899 p->drawLine( r.left(), r.bottom(), r.right(), r.bottom() );
900 if ( r.left() == 0 )
901 p->drawPoint( tb->rect().bottomLeft() );
902 else {
903 p->setPen( tb->colorGroup().light() );
904 p->drawLine( r.left(), r.bottom(), r.right(), r.bottom() );
905 }
906
907 if ( selected ) {
908 p->setPen( tb->colorGroup().background() );
909 p->drawLine( r.left()+2, r.top()+1, r.right()-2, r.top()+1 );
910 p->fillRect( QRect( r.left()+1, r.top()+2, r.width()-2, r.height()-2),
911 tb->colorGroup().brush( QColorGroup::Background ));
912 } else {
913 r.setRect( r.left() + 2, r.top() + 2,
914 r.width() - 4, r.height() - 2 );
915 p->setPen( tb->colorGroup().button() );
916 p->drawLine( r.left()+2, r.top()+1, r.right()-2, r.top()+1 );
917 p->fillRect( QRect( r.left()+1, r.top()+2, r.width()-2, r.height()-3),
918 tb->colorGroup().brush( QColorGroup::Button ));
919
920 //do shading; will not work for pixmap brushes
921 QColor bg = tb->colorGroup().button();
922 // int h,s,v;
923 // bg.hsv( &h, &s, &v );
924 int n = r.height()/2;
925 int dark = 100;
926 for ( int i = 1; i < n; i++ ) {
927 dark = (dark * (100+(i*15)/n) )/100;
928 p->setPen( bg.dark( dark ) );
929 int y = r.bottom()-n+i;
930 int x1 = r.left()+1;
931 int x2 = r.right()-1;
932 p->drawLine( x1, y, x2, y );
933 }
934 }
935
936 p->setPen( tb->colorGroup().light() );
937 p->drawLine( r.left(), r.bottom()-1, r.left(), r.top() + 2 );
938 p->drawPoint( r.left()+1, r.top() + 1 );
939 p->drawLine( r.left()+2, r.top(),
940 r.right() - 2, r.top() );
941
942 p->setPen( tb->colorGroup().dark() );
943 p->drawPoint( r.right() - 1, r.top() + 1 );
944 p->drawLine( r.right(), r.top() + 2, r.right(), r.bottom() - 1);
945 } else if ( tb->shape() == QTabBar::RoundedBelow ) {
946 if ( selected ) {
947 p->setPen( tb->colorGroup().background() );
948 p->drawLine( r.left()+2, r.bottom()-1, r.right()-2, r.bottom()-1 );
949 p->fillRect( QRect( r.left()+1, r.top(), r.width()-2, r.height()-2),
950 tb->palette().normal().brush( QColorGroup::Background ));
951 } else {
952 p->setPen( tb->colorGroup().dark() );
953 p->drawLine( r.left(), r.top(),
954 r.right(), r.top() );
955 r.setRect( r.left() + 2, r.top(),
956 r.width() - 4, r.height() - 2 );
957 p->setPen( tb->colorGroup().button() );
958 p->drawLine( r.left()+2, r.bottom()-1, r.right()-2, r.bottom()-1 );
959 p->fillRect( QRect( r.left()+1, r.top()+1, r.width()-2, r.height()-3),
960 tb->palette().normal().brush( QColorGroup::Button ));
961 }
962
963 p->setPen( tb->colorGroup().dark() );
964 p->drawLine( r.right(), r.top(),
965 r.right(), r.bottom() - 2 );
966 p->drawPoint( r.right() - 1, r.bottom() - 1 );
967 p->drawLine( r.right() - 2, r.bottom(),
968 r.left() + 2, r.bottom() );
969
970 p->setPen( tb->colorGroup().light() );
971 p->drawLine( r.left(), r.top()+1,
972 r.left(), r.bottom() - 2 );
973 p->drawPoint( r.left() + 1, r.bottom() - 1 );
974 if ( r.left() == 0 )
975 p->drawPoint( tb->rect().topLeft() );
976
977 } else {
978 QCommonStyle::drawTab( p, tb, t, selected );
979 }
980}
981
982 static const int motifItemFrame = 0;// menu item frame width
983 static const int motifSepHeight = 2;// separator item height
984 static const int motifItemHMargin = 1;// menu item hor text margin
985 static const int motifItemVMargin = 2;// menu item ver text margin
986 static const int motifArrowHMargin = 0;// arrow horizontal margin
987 static const int motifTabSpacing = 12;// space between text and tab
988 static const int motifCheckMarkHMargin = 1;// horiz. margins of check mark
989 static const int windowsRightBorder= 8; // right border on windows
990static const int windowsCheckMarkWidth = 2; // checkmarks width on windows
991
992/*! \reimp
993*/
994int QPEStyle::extraPopupMenuItemWidth( bool checkable, int maxpmw, QMenuItem* mi, const QFontMetrics& /*fm*/ )
995{
996#ifndef QT_NO_MENUDATA
997 int w = 2*motifItemHMargin + 2*motifItemFrame; // a little bit of border can never harm
998
999 if ( mi->isSeparator() )
1000 return 10; // arbitrary
1001 else if ( mi->pixmap() )
1002 w += mi->pixmap()->width();// pixmap only
1003
1004 if ( !mi->text().isNull() ) {
1005 if ( mi->text().find('\t') >= 0 )// string contains tab
1006 w += motifTabSpacing;
1007 }
1008
1009 if ( maxpmw ) { // we have iconsets
1010 w += maxpmw;
1011 w += 6; // add a little extra border around the iconset
1012 }
1013
1014 if ( checkable && maxpmw < windowsCheckMarkWidth ) {
1015 w += windowsCheckMarkWidth - maxpmw; // space for the checkmarks
1016 }
1017
1018 if ( maxpmw > 0 || checkable ) // we have a check-column ( iconsets or checkmarks)
1019 w += motifCheckMarkHMargin; // add space to separate the columns
1020
1021 w += windowsRightBorder; // windows has a strange wide border on the right side
1022
1023 return w;
1024#endif
1025}
1026
1027/*! \reimp
1028*/
1029int QPEStyle::popupMenuItemHeight( bool /*checkable*/, QMenuItem* mi, const QFontMetrics& fm )
1030{
1031#ifndef QT_NO_MENUDATA
1032 int h = 0;
1033 if ( mi->isSeparator() ) // separator height
1034 h = motifSepHeight;
1035 else if ( mi->pixmap() ) // pixmap height
1036 h = mi->pixmap()->height() + 2*motifItemFrame;
1037 else // text height
1038 h = fm.height() + 2*motifItemVMargin + 2*motifItemFrame - 1;
1039
1040 if ( !mi->isSeparator() && mi->iconSet() != 0 ) {
1041 h = QMAX( h, mi->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).height() + 2*motifItemFrame );
1042 }
1043 if ( mi->custom() )
1044 h = QMAX( h, mi->custom()->sizeHint().height() + 2*motifItemVMargin + 2*motifItemFrame ) - 1;
1045 return h;
1046#endif
1047}
1048
1049void QPEStyle::drawPopupMenuItem( QPainter* p, bool checkable, int maxpmw, int tab, QMenuItem* mi,
1050 const QPalette& pal,
1051 bool act, bool enabled, int x, int y, int w, int h)
1052{
1053#ifndef QT_NO_MENUDATA
1054 const QColorGroup & g = pal.active();
1055 bool dis = !enabled;
1056 QColorGroup itemg = dis ? pal.disabled() : pal.active();
1057
1058 if ( checkable )
1059 maxpmw = QMAX( maxpmw, 8 ); // space for the checkmarks
1060
1061 int checkcol = maxpmw;
1062
1063 if ( mi && mi->isSeparator() ) { // draw separator
1064 p->setPen( g.dark() );
1065 p->drawLine( x, y, x+w, y );
1066 p->setPen( g.light() );
1067 p->drawLine( x, y+1, x+w, y+1 );
1068 return;
1069 }
1070
1071 QBrush fill = act? g.brush( QColorGroup::Highlight ) :
1072 g.brush( QColorGroup::Button );
1073 p->fillRect( x, y, w, h, fill);
1074
1075 if ( !mi )
1076 return;
1077
1078 if ( mi->isChecked() ) {
1079 if ( act && !dis ) {
1080 qDrawShadePanel( p, x, y, checkcol, h,
1081 g, TRUE, 1, &g.brush( QColorGroup::Button ) );
1082 } else {
1083 qDrawShadePanel( p, x, y, checkcol, h,
1084 g, TRUE, 1, &g.brush( QColorGroup::Midlight ) );
1085 }
1086 } else if ( !act ) {
1087 p->fillRect(x, y, checkcol , h,
1088 g.brush( QColorGroup::Button ));
1089 }
1090
1091 if ( mi->iconSet() ) { // draw iconset
1092 QIconSet::Mode mode = dis ? QIconSet::Disabled : QIconSet::Normal;
1093 if (act && !dis )
1094 mode = QIconSet::Active;
1095 QPixmap pixmap = mi->iconSet()->pixmap( QIconSet::Small, mode );
1096 int pixw = pixmap.width();
1097 int pixh = pixmap.height();
1098 if ( act && !dis ) {
1099 if ( !mi->isChecked() )
1100 qDrawShadePanel( p, x, y, checkcol, h, g, FALSE, 1, &g.brush( QColorGroup::Button ) );
1101 }
1102 QRect cr( x, y, checkcol, h );
1103 QRect pmr( 0, 0, pixw, pixh );
1104 pmr.moveCenter( cr.center() );
1105 p->setPen( itemg.text() );
1106 p->drawPixmap( pmr.topLeft(), pixmap );
1107
1108 QBrush fill = act? g.brush( QColorGroup::Highlight ) :
1109 g.brush( QColorGroup::Button );
1110 p->fillRect( x+checkcol + 1, y, w - checkcol - 1, h, fill);
1111 } else if ( checkable ) {// just "checking"...
1112 int mw = checkcol + motifItemFrame;
1113 int mh = h - 2*motifItemFrame;
1114 if ( mi->isChecked() ) {
1115 drawCheckMark( p, x + motifItemFrame + 2,
1116 y+motifItemFrame, mw, mh, itemg, act, dis );
1117 }
1118 }
1119
1120 p->setPen( act ? g.highlightedText() : g.buttonText() );
1121
1122 QColor discol;
1123 if ( dis ) {
1124 discol = itemg.text();
1125 p->setPen( discol );
1126 }
1127
1128 int xm = motifItemFrame + checkcol + motifItemHMargin;
1129
1130 if ( mi->custom() ) {
1131 int m = motifItemVMargin;
1132 p->save();
1133 if ( dis && !act ) {
1134 p->setPen( g.light() );
1135 mi->custom()->paint( p, itemg, act, enabled,
1136 x+xm+1, y+m+1, w-xm-tab+1, h-2*m );
1137 p->setPen( discol );
1138 }
1139 mi->custom()->paint( p, itemg, act, enabled,
1140 x+xm, y+m, w-xm-tab+1, h-2*m );
1141 p->restore();
1142 }
1143 QString s = mi->text();
1144 if ( !s.isNull() ) { // draw text
1145 int t = s.find( '\t' );
1146 int m = motifItemVMargin;
1147 const int text_flags = AlignVCenter|ShowPrefix | DontClip | SingleLine;
1148 if ( t >= 0 ) { // draw tab text
1149 if ( dis && !act ) {
1150 p->setPen( g.light() );
1151 p->drawText( x+w-tab-windowsRightBorder-motifItemHMargin-motifItemFrame+1,
1152 y+m+1, tab, h-2*m, text_flags, s.mid( t+1 ));
1153 p->setPen( discol );
1154 }
1155 p->drawText( x+w-tab-windowsRightBorder-motifItemHMargin-motifItemFrame,
1156 y+m, tab, h-2*m, text_flags, s.mid( t+1 ) );
1157 }
1158 if ( dis && !act ) {
1159 p->setPen( g.light() );
1160 p->drawText( x+xm+1, y+m+1, w-xm+1, h-2*m, text_flags, s, t );
1161 p->setPen( discol );
1162 }
1163 p->drawText( x+xm, y+m, w-xm-tab+1, h-2*m, text_flags, s, t );
1164 } else if ( mi->pixmap() ) { // draw pixmap
1165 QPixmap *pixmap = mi->pixmap();
1166 if ( pixmap->depth() == 1 )
1167 p->setBackgroundMode( OpaqueMode );
1168 p->drawPixmap( x+xm, y+motifItemFrame, *pixmap );
1169 if ( pixmap->depth() == 1 )
1170 p->setBackgroundMode( TransparentMode );
1171 }
1172 if ( mi->popup() ) { // draw sub menu arrow
1173 int dim = (h-2*motifItemFrame) / 2;
1174 if ( act ) {
1175 if ( !dis )
1176 discol = white;
1177 QColorGroup g2( discol, g.highlight(),
1178 white, white,
1179 dis ? discol : white,
1180 discol, white );
1181 drawArrow( p, RightArrow, FALSE,
1182 x+w - motifArrowHMargin - motifItemFrame - dim, y+h/2-dim/2,
1183 dim, dim, g2, TRUE );
1184 } else {
1185 drawArrow( p, RightArrow,
1186 FALSE,
1187 x+w - motifArrowHMargin - motifItemFrame - dim, y+h/2-dim/2,
1188 dim, dim, g, mi->isEnabled() );
1189 }
1190 }
1191#endif
1192}
1193
1194#endif