summaryrefslogtreecommitdiff
path: root/noncore/styles/fresh/fresh.cpp
authorsandman <sandman>2002-10-04 01:54:04 (UTC)
committer sandman <sandman>2002-10-04 01:54:04 (UTC)
commit3ba387cb218f45f72c00d8b64ea46d75e19fb3de (patch) (unidiff)
treeef166da4a0e837f5424ba2990a5f2225a3f0dd10 /noncore/styles/fresh/fresh.cpp
parent4a6ccb87f45065bc37f801adb61c3462f870cb92 (diff)
downloadopie-3ba387cb218f45f72c00d8b64ea46d75e19fb3de.zip
opie-3ba387cb218f45f72c00d8b64ea46d75e19fb3de.tar.gz
opie-3ba387cb218f45f72c00d8b64ea46d75e19fb3de.tar.bz2
Added two styles from Qtopia 1.6
Diffstat (limited to 'noncore/styles/fresh/fresh.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/styles/fresh/fresh.cpp846
1 files changed, 846 insertions, 0 deletions
diff --git a/noncore/styles/fresh/fresh.cpp b/noncore/styles/fresh/fresh.cpp
new file mode 100644
index 0000000..0730329
--- a/dev/null
+++ b/noncore/styles/fresh/fresh.cpp
@@ -0,0 +1,846 @@
1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3**
4** This file is part of the 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 "fresh.h"
22#include <qpe/qpeapplication.h>
23#include <qpushbutton.h>
24#include <qpainter.h>
25#include <qfontmetrics.h>
26#include <qpalette.h>
27#include <qdrawutil.h>
28#include <qscrollbar.h>
29#include <qbutton.h>
30#include <qframe.h>
31#include <qtabbar.h>
32
33#define INCLUDE_MENUITEM_DEF
34#include <qmenudata.h>
35
36#define QCOORDARRLEN(x) sizeof(x)/(sizeof(QCOORD)*2)
37
38FreshStyle::FreshStyle()
39{
40 setButtonMargin(2);
41 setScrollBarExtent(13,13);
42}
43
44FreshStyle::~FreshStyle()
45{
46}
47
48int FreshStyle::buttonMargin() const
49{
50 return 2;
51}
52
53QSize FreshStyle::scrollBarExtent() const
54{
55 return QSize(13,13);
56}
57
58void FreshStyle::polish ( QPalette & )
59{
60}
61
62void FreshStyle::polish( QWidget *w )
63{
64 if ( w->inherits( "QListBox" ) ||
65 w->inherits( "QListView" ) ||
66 w->inherits( "QPopupMenu" ) ||
67 w->inherits( "QSpinBox" ) ) {
68 QFrame *f = (QFrame *)w;
69 f->setFrameShape( QFrame::StyledPanel );
70 f->setLineWidth( 1 );
71 }
72}
73
74void FreshStyle::unPolish( QWidget *w )
75{
76 if ( w->inherits( "QListBox" ) ||
77 w->inherits( "QListView" ) ||
78 w->inherits( "QPopupMenu" ) ||
79 w->inherits( "QSpinBox" ) ) {
80 QFrame *f = (QFrame *)w;
81 f->setFrameShape( QFrame::StyledPanel );
82 f->setLineWidth( 2 );
83 }
84}
85
86int FreshStyle::defaultFrameWidth() const
87{
88 return 1;
89}
90
91void FreshStyle::drawPanel ( QPainter * p, int x, int y, int w, int h,
92 const QColorGroup &g, bool sunken, int lineWidth, const QBrush * fill )
93{
94 qDrawShadePanel( p, QRect(x, y, w, h), g, sunken, lineWidth, fill );
95}
96
97void FreshStyle::drawButton( QPainter *p, int x, int y, int w, int h,
98 const QColorGroup &cg, bool sunken, const QBrush* fill )
99{
100 QPen oldPen = p->pen();
101 int off = sunken ? 1 : 0;
102 p->fillRect( x+1+off, y+1+off, w-3, h-3, fill?(*fill):cg.brush(QColorGroup::Button) );
103
104 int x2 = x+w-1;
105 int y2 = y+h-1;
106
107 if ( sunken )
108 p->setPen( cg.dark() );
109 else
110 p->setPen( cg.light() );
111 p->drawLine( x, y, x, y2-1 );
112 p->drawLine( x, y, x2, y );
113
114 if ( sunken ) {
115 p->setPen( white );
116 p->drawLine( x+1, y+1, x+1, y2-2 );
117 p->drawLine( x+1, y+1, x2-2, y+1 );
118 }
119
120 if ( sunken )
121 p->setPen( cg.light() );
122 else
123 p->setPen( cg.dark() );
124 p->drawLine( x2, y+1, x2, y2 );
125 p->drawLine( x, y2, x2, y2 );
126
127 if ( !sunken ) {
128 p->setPen( white );
129 p->drawLine( x2-1, y+1, x2-1, y2-1 );
130 p->drawLine( x+1, y2-1, x2-1, y2-1 );
131 }
132 p->setPen( oldPen );
133}
134
135void FreshStyle::drawButtonMask ( QPainter * p, int x, int y, int w, int h )
136{
137 p->fillRect( x, y, w, h, color1 );
138}
139
140void FreshStyle::drawBevelButton( QPainter *p, int x, int y, int w, int h,
141 const QColorGroup &g, bool sunken, const QBrush* fill )
142{
143 drawButton( p, x, y, w, h, g, sunken, fill );
144}
145
146QRect FreshStyle::comboButtonRect( int x, int y, int w, int h)
147{
148 return QRect(x+1, y+1, w-2-14, h-2);
149}
150
151
152QRect FreshStyle::comboButtonFocusRect( int x, int y, int w, int h)
153{
154 return QRect(x+2, y+2, w-4-14, h-4);
155}
156
157void FreshStyle::drawComboButton( QPainter *p, int x, int y, int w, int h,
158 const QColorGroup &g, bool sunken,
159 bool /*editable*/,
160 bool enabled,
161 const QBrush *fill )
162{
163 drawBevelButton( p, x, y, w, h, g, FALSE, fill );
164 drawBevelButton( p, x+w-14, y, 14, h, g, sunken, fill );
165 drawArrow( p, QStyle::DownArrow, sunken,
166 x+w-14+ 2, y+ 2, 14- 4, h- 4, g, enabled,
167 &g.brush( QColorGroup::Button ) );
168
169}
170
171
172void FreshStyle::drawExclusiveIndicator ( QPainter * p, int x, int y, int w,
173 int h, const QColorGroup &cg, bool on, bool down, bool enabled )
174{
175 static const QCOORD pts1[] = { // dark lines
176 1,9, 1,8, 0,7, 0,4, 1,3, 1,2, 2,1, 3,1, 4,0, 7,0, 8,1, 9,1 };
177 static const QCOORD pts4[] = { // white lines
178 2,10, 3,10, 4,11, 7,11, 8,10, 9,10, 10,9, 10,8, 11,7,
179 11,4, 10,3, 10,2 };
180 static const QCOORD pts5[] = { // inner fill
181 4,2, 7,2, 9,4, 9,7, 7,9, 4,9, 2,7, 2,4 };
182
183 p->eraseRect( x, y, w, h );
184 QPointArray a( QCOORDARRLEN(pts1), pts4 );
185 a.translate( x, y );
186 p->setPen( cg.dark() );
187 p->drawPolyline( a );
188 a.setPoints( QCOORDARRLEN(pts4), pts1 );
189 a.translate( x, y );
190 p->setPen( cg.light() );
191 p->drawPolyline( a );
192 a.setPoints( QCOORDARRLEN(pts5), pts5 );
193 a.translate( x, y );
194 QColor fillColor = ( down || !enabled ) ? cg.button() : cg.base();
195 p->setPen( fillColor );
196 p->setBrush( fillColor ) ;
197 p->drawPolygon( a );
198 if ( on ) {
199 p->setPen( NoPen );
200 p->setBrush( cg.text() );
201 p->drawRect( x+5, y+4, 2, 4 );
202 p->drawRect( x+4, y+5, 4, 2 );
203 }
204}
205
206void FreshStyle::drawIndicator ( QPainter * p, int x, int y, int w, int h,
207 const QColorGroup &cg, int state, bool down, bool enabled )
208{
209 QColorGroup mycg( cg );
210 mycg.setBrush( QColorGroup::Button, QBrush() );
211 QBrush fill;
212 drawButton( p, x, y, w, h, mycg, TRUE, 0 );
213 if ( down )
214 fill = cg.brush( QColorGroup::Button );
215 else
216 fill = cg.brush( enabled ? QColorGroup::Base : QColorGroup::Background );
217 mycg.setBrush( QColorGroup::Button, fill );
218 p->fillRect( x+1, y+1, w-2, h-2, fill );
219 if ( state != QButton::Off ) {
220 QPointArray a( 7*2 );
221 int i, xx, yy;
222 xx = x+3;
223 yy = y+5;
224 for ( i=0; i<3; i++ ) {
225 a.setPoint( 2*i, xx, yy );
226 a.setPoint( 2*i+1, xx, yy+2 );
227 xx++; yy++;
228 }
229 yy -= 2;
230 for ( i=3; i<7; i++ ) {
231 a.setPoint( 2*i, xx, yy );
232 a.setPoint( 2*i+1, xx, yy+2 );
233 xx++; yy--;
234 }
235 if ( state == QButton::NoChange ) {
236 p->setPen( mycg.dark() );
237 } else {
238 p->setPen( mycg.text() );
239 }
240 p->drawLineSegments( a );
241 }
242}
243
244 #define HORIZONTAL(sb->orientation() == QScrollBar::Horizontal)
245 #define VERTICAL!HORIZONTAL
246 #define MOTIF_BORDER2
247 #define SLIDER_MIN9 // ### motif says 6 but that's too small
248
249/*! \reimp */
250
251void FreshStyle::scrollBarMetrics( const QScrollBar* sb, int &sliderMin, int &sliderMax, int &sliderLength, int& buttonDim )
252{
253 int maxLength;
254 int length = HORIZONTAL ? sb->width() : sb->height();
255 int extent = HORIZONTAL ? sb->height() : sb->width();
256
257 if ( length > (extent - 1)*2 )
258 buttonDim = extent;
259 else
260 buttonDim = length/2 - 1;
261
262 sliderMin = 0;
263 maxLength = length - buttonDim*2;
264
265 if ( sb->maxValue() == sb->minValue() ) {
266 sliderLength = maxLength;
267 } else {
268 sliderLength = (sb->pageStep()*maxLength)/
269 (sb->maxValue()-sb->minValue()+sb->pageStep());
270 uint range = sb->maxValue()-sb->minValue();
271 if ( sliderLength < SLIDER_MIN || range > INT_MAX/2 )
272 sliderLength = SLIDER_MIN;
273 if ( sliderLength > maxLength )
274 sliderLength = maxLength;
275 }
276
277 sliderMax = sliderMin + maxLength - sliderLength;
278}
279
280/*!\reimp
281 */
282QStyle::ScrollControl FreshStyle::scrollBarPointOver( const QScrollBar* sb, int sliderStart, const QPoint& p )
283{
284 if ( !sb->rect().contains( p ) )
285 return NoScroll;
286 int sliderMin, sliderMax, sliderLength, buttonDim, pos;
287 scrollBarMetrics( sb, sliderMin, sliderMax, sliderLength, buttonDim );
288
289 if (sb->orientation() == QScrollBar::Horizontal)
290 pos = p.x();
291 else
292 pos = p.y();
293
294 if (pos < sliderStart)
295 return SubPage;
296 if (pos < sliderStart + sliderLength)
297 return Slider;
298 if (pos < sliderMax + sliderLength)
299 return AddPage;
300 if (pos < sliderMax + sliderLength + buttonDim)
301 return SubLine;
302 return AddLine;
303}
304
305/*! \reimp */
306
307void FreshStyle::drawScrollBarControls( QPainter* p, const QScrollBar* sb, int sliderStart, uint controls, uint activeControl )
308{
309#define ADD_LINE_ACTIVE ( activeControl == AddLine )
310#define SUB_LINE_ACTIVE ( activeControl == SubLine )
311 QColorGroup g = sb->colorGroup();
312
313 int sliderMin, sliderMax, sliderLength, buttonDim;
314 scrollBarMetrics( sb, sliderMin, sliderMax, sliderLength, buttonDim );
315
316 if ( controls == (AddLine | SubLine | AddPage | SubPage | Slider | First | Last ) )
317 p->fillRect( 0, 0, sb->width(), sb->height(), g.brush( QColorGroup::Mid ));
318
319 if (sliderStart > sliderMax) { // sanity check
320 sliderStart = sliderMax;
321 }
322
323 int dimB = buttonDim;
324 QRect addB;
325 QRect subB;
326 QRect addPageR;
327 QRect subPageR;
328 QRect sliderR;
329 int addX, addY, subX, subY;
330 int length = HORIZONTAL ? sb->width() : sb->height();
331 int extent = HORIZONTAL ? sb->height() : sb->width();
332
333 if ( HORIZONTAL ) {
334 subY = addY = ( extent - dimB ) / 2;
335 subX = length - dimB - dimB;
336 addX = length - dimB;
337 } else {
338 subX = addX = ( extent - dimB ) / 2;
339 subY = length - dimB - dimB;
340 addY = length - dimB;
341 }
342
343 int sliderEnd = sliderStart + sliderLength;
344 int sliderW = extent;
345 if ( HORIZONTAL ) {
346 subB.setRect( subX,subY+1,dimB,dimB-1 );
347 addB.setRect( addX,addY+1,dimB,dimB-1 );
348
349 subPageR.setRect( 0, 0,
350 sliderStart+1, sliderW );
351 addPageR.setRect( sliderEnd-1, 0, subX - sliderEnd+1, sliderW );
352 sliderR .setRect( sliderStart, 1, sliderLength, sliderW-1 );
353
354 } else {
355 subB.setRect( subX+1,subY,dimB-1,dimB );
356 addB.setRect( addX+1,addY,dimB-1,dimB );
357
358 subPageR.setRect( 0, 0, sliderW,
359 sliderStart+1 );
360 addPageR.setRect( 0, sliderEnd-1, sliderW, subY - sliderEnd+1 );
361 sliderR .setRect( 1, sliderStart, sliderW-1, sliderLength );
362 }
363
364 bool maxedOut = (sb->maxValue() == sb->minValue());
365 if ( controls & AddLine ) {
366 drawBevelButton( p, addB.x(), addB.y(),
367 addB.width(), addB.height(), g,
368 ADD_LINE_ACTIVE);
369 p->setPen(g.shadow());
370 drawArrow( p, VERTICAL ? DownArrow : RightArrow,
371 FALSE, addB.x()+2, addB.y()+2,
372 addB.width()-4, addB.height()-4, g, !maxedOut,
373 &g.brush( QColorGroup::Button ));
374 }
375 if ( controls & SubLine ) {
376 drawBevelButton( p, subB.x(), subB.y(),
377 subB.width(), subB.height(), g,
378 SUB_LINE_ACTIVE );
379 p->setPen(g.shadow());
380 drawArrow( p, VERTICAL ? UpArrow : LeftArrow,
381 FALSE, subB.x()+2, subB.y()+2,
382 subB.width()-4, subB.height()-4, g, !maxedOut,
383 &g.brush( QColorGroup::Button ));
384 }
385
386
387 if ( controls & SubPage )
388 p->fillRect( subPageR.x(), subPageR.y(), subPageR.width(),
389 subPageR.height(), g.brush( QColorGroup::Mid ));
390 if ( controls & AddPage )
391 p->fillRect( addPageR.x(), addPageR.y(), addPageR.width(),
392 addPageR.height(), g.brush( QColorGroup::Mid ));
393 if ( controls & Slider ) {
394 QPoint bo = p->brushOrigin();
395 p->setBrushOrigin(sliderR.topLeft());
396 drawBevelButton( p, sliderR.x(), sliderR.y(),
397 sliderR.width(), sliderR.height(), g,
398 FALSE, &g.brush( QColorGroup::Button ) );
399 p->setBrushOrigin(bo);
400 drawRiffles( p, sliderR.x(), sliderR.y(),
401 sliderR.width(), sliderR.height(), g, HORIZONTAL );
402 }
403
404 // ### perhaps this should not be able to accept focus if maxedOut?
405 if ( sb->hasFocus() && (controls & Slider) )
406 p->drawWinFocusRect( sliderR.x()+2, sliderR.y()+2,
407 sliderR.width()-5, sliderR.height()-5,
408 sb->backgroundColor() );
409
410}
411
412void FreshStyle::drawRiffles( QPainter* p, int x, int y, int w, int h,
413 const QColorGroup &g, bool horizontal )
414{
415 return;
416 if (!horizontal) {
417 if (h > 20) {
418 y += (h-20)/2 ;
419 h = 20;
420 }
421 if (h > 12) {
422 int n = 3;
423 int my = y+h/2-4;
424 int i ;
425 p->setPen(g.light());
426 for (i=0; i<n; i++) {
427 p->drawLine(x+2, my+3*i, x+w-4, my+3*i);
428 }
429 p->setPen(g.dark());
430 my++;
431 for (i=0; i<n; i++) {
432 p->drawLine(x+2, my+3*i, x+w-4, my+3*i);
433 }
434 }
435 }
436 else {
437 if (w > 20) {
438 x += (w-20)/2 ;
439 w = 20;
440 }
441 if (w > 12) {
442 int n = 3;
443 int mx = x+w/2-4;
444 int i ;
445 p->setPen(g.light());
446 for (i=0; i<n; i++) {
447 p->drawLine(mx+3*i, y+2, mx + 3*i, y+h-4);
448 }
449 p->setPen(g.dark());
450 mx++;
451 for (i=0; i<n; i++) {
452 p->drawLine(mx+3*i, y+2, mx + 3*i, y+h-4);
453 }
454 }
455 }
456}
457
458int FreshStyle::sliderLength() const
459{
460 return 12;
461}
462
463void FreshStyle::drawSlider( QPainter *p, int x, int y, int w, int h,
464 const QColorGroup &g, Orientation o, bool tickAbove, bool tickBelow )
465{
466 int a = tickAbove ? 3 : 0;
467 int b = tickBelow ? 3 : 0;
468
469 if ( o == Horizontal ) {
470 drawBevelButton( p, x, y+a, w, h-a-b, g, FALSE, &g.brush( QColorGroup::Button ) );
471 int xp = x + w/2;
472 qDrawShadeLine( p, xp, y+a+2, xp, y+h-b-3, g );
473 } else {
474 drawBevelButton( p, x+a, y, w-a-b, h, g, FALSE, &g.brush( QColorGroup::Button ) );
475 int yp = y + h/2;
476 qDrawShadeLine( p, x+a+2, yp, x+w-b-3, yp, g );
477 }
478}
479
480void FreshStyle::drawSliderMask ( QPainter * p, int x, int y, int w, int h,
481 Orientation o, bool tickAbove, bool tickBelow )
482{
483 int a = tickAbove ? 3 : 0;
484 int b = tickBelow ? 3 : 0;
485 if ( o == Horizontal )
486 p->fillRect( x, y+a, w, h-a-b, color1 );
487 else
488 p->fillRect( x+a, y, w-a-b, h, color1 );
489}
490
491/*!\reimp
492 */
493void FreshStyle::drawSliderGrooveMask( QPainter *p,
494 int x, int y, int w, int h,
495 const QColorGroup& , QCOORD c,
496 Orientation orient )
497{
498 if ( orient == Horizontal )
499 p->fillRect( x, y + c - 2, w, 4, color1 );
500 else
501 p->fillRect( x + c - 2, y, 4, h, color1 );
502}
503
504void FreshStyle::drawTab( QPainter *p, const QTabBar *tb, QTab *t, bool selected )
505{
506 QRect r( t->rect() );
507 if ( tb->shape() == QTabBar::RoundedAbove ) {
508 p->setPen( tb->colorGroup().light() );
509 p->drawLine( r.left(), r.bottom(), r.right(), r.bottom() );
510 if ( r.left() == 0 )
511 p->drawPoint( tb->rect().bottomLeft() );
512 else {
513 p->setPen( tb->colorGroup().light() );
514 p->drawLine( r.left(), r.bottom(), r.right(), r.bottom() );
515 }
516
517 if ( selected ) {
518 p->setPen( tb->colorGroup().background() );
519 p->drawLine( r.left()+2, r.top()+1, r.right()-2, r.top()+1 );
520 p->fillRect( QRect( r.left()+1, r.top()+2, r.width()-2, r.height()-2),
521 tb->colorGroup().brush( QColorGroup::Background ));
522 } else {
523 r.setRect( r.left() + 2, r.top() + 2,
524 r.width() - 4, r.height() - 2 );
525 p->setPen( tb->colorGroup().button() );
526 p->drawLine( r.left()+2, r.top()+1, r.right()-2, r.top()+1 );
527 p->fillRect( QRect( r.left()+1, r.top()+2, r.width()-2, r.height()-3),
528 tb->colorGroup().brush( QColorGroup::Button ));
529
530 //do shading; will not work for pixmap brushes
531 QColor bg = tb->colorGroup().button();
532 // int h,s,v;
533 // bg.hsv( &h, &s, &v );
534 int n = r.height()/2;
535 int dark = 100;
536 for ( int i = 1; i < n; i++ ) {
537 dark = (dark * (100+(i*15)/n) )/100;
538 p->setPen( bg.dark( dark ) );
539 int y = r.bottom()-n+i;
540 int x1 = r.left()+1;
541 int x2 = r.right()-1;
542 p->drawLine( x1, y, x2, y );
543 }
544 }
545
546 p->setPen( tb->colorGroup().light() );
547 p->drawLine( r.left(), r.bottom()-1, r.left(), r.top() + 2 );
548 p->drawPoint( r.left()+1, r.top() + 1 );
549 p->drawLine( r.left()+2, r.top(),
550 r.right() - 2, r.top() );
551
552 p->setPen( tb->colorGroup().dark() );
553 p->drawPoint( r.right() - 1, r.top() + 1 );
554 p->drawLine( r.right(), r.top() + 2, r.right(), r.bottom() - 1);
555 } else if ( tb->shape() == QTabBar::RoundedBelow ) {
556 if ( selected ) {
557 p->setPen( tb->colorGroup().background() );
558 p->drawLine( r.left()+2, r.bottom()-1, r.right()-2, r.bottom()-1 );
559 p->fillRect( QRect( r.left()+1, r.top(), r.width()-2, r.height()-2),
560 tb->palette().normal().brush( QColorGroup::Background ));
561 } else {
562 p->setPen( tb->colorGroup().dark() );
563 p->drawLine( r.left(), r.top(),
564 r.right(), r.top() );
565 r.setRect( r.left() + 2, r.top(),
566 r.width() - 4, r.height() - 2 );
567 p->setPen( tb->colorGroup().button() );
568 p->drawLine( r.left()+2, r.bottom()-1, r.right()-2, r.bottom()-1 );
569 p->fillRect( QRect( r.left()+1, r.top()+1, r.width()-2, r.height()-3),
570 tb->palette().normal().brush( QColorGroup::Button ));
571 }
572
573 p->setPen( tb->colorGroup().dark() );
574 p->drawLine( r.right(), r.top(),
575 r.right(), r.bottom() - 2 );
576 p->drawPoint( r.right() - 1, r.bottom() - 1 );
577 p->drawLine( r.right() - 2, r.bottom(),
578 r.left() + 2, r.bottom() );
579
580 p->setPen( tb->colorGroup().light() );
581 p->drawLine( r.left(), r.top()+1,
582 r.left(), r.bottom() - 2 );
583 p->drawPoint( r.left() + 1, r.bottom() - 1 );
584 if ( r.left() == 0 )
585 p->drawPoint( tb->rect().topLeft() );
586
587 } else {
588 QCommonStyle::drawTab( p, tb, t, selected );
589 }
590}
591
592 static const int motifItemFrame = 0;// menu item frame width
593 static const int motifSepHeight = 2;// separator item height
594 static const int motifItemHMargin = 1;// menu item hor text margin
595 static const int motifItemVMargin = 2;// menu item ver text margin
596 static const int motifArrowHMargin = 0;// arrow horizontal margin
597 static const int motifTabSpacing = 12;// space between text and tab
598 static const int motifCheckMarkHMargin = 1;// horiz. margins of check mark
599 static const int windowsRightBorder= 8; // right border on windows
600static const int windowsCheckMarkWidth = 2; // checkmarks width on windows
601
602/*! \reimp
603*/
604int FreshStyle::extraPopupMenuItemWidth( bool checkable, int maxpmw, QMenuItem* mi, const QFontMetrics& /*fm*/ )
605{
606#ifndef QT_NO_MENUDATA
607 int w = 2*motifItemHMargin + 2*motifItemFrame; // a little bit of border can never harm
608
609 if ( mi->isSeparator() )
610 return 10; // arbitrary
611 else if ( mi->pixmap() )
612 w += mi->pixmap()->width();// pixmap only
613
614 if ( !mi->text().isNull() ) {
615 if ( mi->text().find('\t') >= 0 )// string contains tab
616 w += motifTabSpacing;
617 }
618
619 if ( maxpmw ) { // we have iconsets
620 w += maxpmw;
621 w += 6; // add a little extra border around the iconset
622 }
623
624 if ( checkable && maxpmw < windowsCheckMarkWidth ) {
625 w += windowsCheckMarkWidth - maxpmw; // space for the checkmarks
626 }
627
628 if ( maxpmw > 0 || checkable ) // we have a check-column ( iconsets or checkmarks)
629 w += motifCheckMarkHMargin; // add space to separate the columns
630
631 w += windowsRightBorder; // windows has a strange wide border on the right side
632
633 return w;
634#endif
635}
636
637/*! \reimp
638*/
639int FreshStyle::popupMenuItemHeight( bool /*checkable*/, QMenuItem* mi, const QFontMetrics& fm )
640{
641#ifndef QT_NO_MENUDATA
642 int h = 0;
643 if ( mi->isSeparator() ) // separator height
644 h = motifSepHeight;
645 else if ( mi->pixmap() ) // pixmap height
646 h = mi->pixmap()->height() + 2*motifItemFrame;
647 else // text height
648 h = fm.height() + 2*motifItemVMargin + 2*motifItemFrame - 1;
649
650 if ( !mi->isSeparator() && mi->iconSet() != 0 ) {
651 h = QMAX( h, mi->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).height() + 2*motifItemFrame );
652 }
653 if ( mi->custom() )
654 h = QMAX( h, mi->custom()->sizeHint().height() + 2*motifItemVMargin + 2*motifItemFrame ) - 1;
655 return h;
656#endif
657}
658
659void FreshStyle::drawPopupMenuItem( QPainter* p, bool checkable, int maxpmw, int tab, QMenuItem* mi,
660 const QPalette& pal,
661 bool act, bool enabled, int x, int y, int w, int h)
662{
663#ifndef QT_NO_MENUDATA
664 const QColorGroup & g = pal.active();
665 bool dis = !enabled;
666 QColorGroup itemg = dis ? pal.disabled() : pal.active();
667
668 if ( checkable )
669 maxpmw = QMAX( maxpmw, 8 ); // space for the checkmarks
670
671 int checkcol = maxpmw;
672
673 if ( mi && mi->isSeparator() ) { // draw separator
674 p->setPen( g.dark() );
675 p->drawLine( x, y, x+w, y );
676 p->setPen( g.light() );
677 p->drawLine( x, y+1, x+w, y+1 );
678 return;
679 }
680
681 QBrush fill = act? g.brush( QColorGroup::Highlight ) :
682 g.brush( QColorGroup::Button );
683 p->fillRect( x, y, w, h, fill);
684
685 if ( !mi )
686 return;
687
688 if ( mi->isChecked() ) {
689 if ( act && !dis ) {
690 qDrawShadePanel( p, x, y, checkcol, h,
691 g, TRUE, 1, &g.brush( QColorGroup::Button ) );
692 } else {
693 qDrawShadePanel( p, x, y, checkcol, h,
694 g, TRUE, 1, &g.brush( QColorGroup::Midlight ) );
695 }
696 } else if ( !act ) {
697 p->fillRect(x, y, checkcol , h,
698 g.brush( QColorGroup::Button ));
699 }
700
701 if ( mi->iconSet() ) { // draw iconset
702 QIconSet::Mode mode = dis ? QIconSet::Disabled : QIconSet::Normal;
703 if (act && !dis )
704 mode = QIconSet::Active;
705 QPixmap pixmap = mi->iconSet()->pixmap( QIconSet::Small, mode );
706 int pixw = pixmap.width();
707 int pixh = pixmap.height();
708 if ( act && !dis ) {
709 if ( !mi->isChecked() )
710 qDrawShadePanel( p, x, y, checkcol, h, g, FALSE, 1, &g.brush( QColorGroup::Button ) );
711 }
712 QRect cr( x, y, checkcol, h );
713 QRect pmr( 0, 0, pixw, pixh );
714 pmr.moveCenter( cr.center() );
715 p->setPen( itemg.text() );
716 p->drawPixmap( pmr.topLeft(), pixmap );
717
718 QBrush fill = act? g.brush( QColorGroup::Highlight ) :
719 g.brush( QColorGroup::Button );
720 p->fillRect( x+checkcol + 1, y, w - checkcol - 1, h, fill);
721 } else if ( checkable ) {// just "checking"...
722 int mw = checkcol + motifItemFrame;
723 int mh = h - 2*motifItemFrame;
724 if ( mi->isChecked() ) {
725 drawCheckMark( p, x + motifItemFrame + 2,
726 y+motifItemFrame, mw, mh, itemg, act, dis );
727 }
728 }
729
730 p->setPen( act ? g.highlightedText() : g.buttonText() );
731
732 QColor discol;
733 if ( dis ) {
734 discol = itemg.text();
735 p->setPen( discol );
736 }
737
738 int xm = motifItemFrame + checkcol + motifItemHMargin;
739
740 if ( mi->custom() ) {
741 int m = motifItemVMargin;
742 p->save();
743 if ( dis && !act ) {
744 p->setPen( g.light() );
745 mi->custom()->paint( p, itemg, act, enabled,
746 x+xm+1, y+m+1, w-xm-tab+1, h-2*m );
747 p->setPen( discol );
748 }
749 mi->custom()->paint( p, itemg, act, enabled,
750 x+xm, y+m, w-xm-tab+1, h-2*m );
751 p->restore();
752 }
753 QString s = mi->text();
754 if ( !s.isNull() ) { // draw text
755 int t = s.find( '\t' );
756 int m = motifItemVMargin;
757 const int text_flags = AlignVCenter|ShowPrefix | DontClip | SingleLine;
758 if ( t >= 0 ) { // draw tab text
759 if ( dis && !act ) {
760 p->setPen( g.light() );
761 p->drawText( x+w-tab-windowsRightBorder-motifItemHMargin-motifItemFrame+1,
762 y+m+1, tab, h-2*m, text_flags, s.mid( t+1 ));
763 p->setPen( discol );
764 }
765 p->drawText( x+w-tab-windowsRightBorder-motifItemHMargin-motifItemFrame,
766 y+m, tab, h-2*m, text_flags, s.mid( t+1 ) );
767 }
768 if ( dis && !act ) {
769 p->setPen( g.light() );
770 p->drawText( x+xm+1, y+m+1, w-xm+1, h-2*m, text_flags, s, t );
771 p->setPen( discol );
772 }
773 p->drawText( x+xm, y+m, w-xm-tab+1, h-2*m, text_flags, s, t );
774 } else if ( mi->pixmap() ) { // draw pixmap
775 QPixmap *pixmap = mi->pixmap();
776 if ( pixmap->depth() == 1 )
777 p->setBackgroundMode( OpaqueMode );
778 p->drawPixmap( x+xm, y+motifItemFrame, *pixmap );
779 if ( pixmap->depth() == 1 )
780 p->setBackgroundMode( TransparentMode );
781 }
782 if ( mi->popup() ) { // draw sub menu arrow
783 int dim = (h-2*motifItemFrame) / 2;
784 if ( act ) {
785 if ( !dis )
786 discol = white;
787 QColorGroup g2( discol, g.highlight(),
788 white, white,
789 dis ? discol : white,
790 discol, white );
791 drawArrow( p, RightArrow, FALSE,
792 x+w - motifArrowHMargin - motifItemFrame - dim, y+h/2-dim/2,
793 dim, dim, g2, TRUE );
794 } else {
795 drawArrow( p, RightArrow,
796 FALSE,
797 x+w - motifArrowHMargin - motifItemFrame - dim, y+h/2-dim/2,
798 dim, dim, g, mi->isEnabled() );
799 }
800 }
801#endif
802}
803
804//===========================================================================
805
806FreshStyleImpl::FreshStyleImpl()
807 : fresh(0), ref(0)
808{
809}
810
811FreshStyleImpl::~FreshStyleImpl()
812{
813 // We do not delete the style because Qt does that when a new style
814 // is set.
815}
816
817QStyle *FreshStyleImpl::style()
818{
819 if ( !fresh )
820 fresh = new FreshStyle();
821 return fresh;
822}
823
824QString FreshStyleImpl::name() const
825{
826 return QString("Fresh");
827}
828
829QRESULT FreshStyleImpl::queryInterface( const QUuid &uuid, QUnknownInterface **iface )
830{
831 *iface = 0;
832 if ( uuid == IID_QUnknown )
833 *iface = this;
834 else if ( uuid == IID_Style )
835 *iface = this;
836
837 if ( *iface )
838 (*iface)->addRef();
839 return QS_OK;
840}
841
842Q_EXPORT_INTERFACE()
843{
844 Q_CREATE_INSTANCE( FreshStyleImpl )
845}
846