summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/styles/flat/flat.cpp1032
-rw-r--r--noncore/styles/flat/flat.h114
-rw-r--r--noncore/styles/flat/flat.pro11
-rw-r--r--noncore/styles/flat/opie-style-flat.control9
-rw-r--r--noncore/styles/fresh/fresh.cpp846
-rw-r--r--noncore/styles/fresh/fresh.h100
-rw-r--r--noncore/styles/fresh/fresh.pro11
-rw-r--r--noncore/styles/fresh/opie-style-fresh.control9
8 files changed, 2132 insertions, 0 deletions
diff --git a/noncore/styles/flat/flat.cpp b/noncore/styles/flat/flat.cpp
new file mode 100644
index 0000000..b6635c5
--- a/dev/null
+++ b/noncore/styles/flat/flat.cpp
@@ -0,0 +1,1032 @@
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 "flat.h"
22#include <qpe/qpeapplication.h>
23#include <qpushbutton.h>
24#include <qtoolbutton.h>
25#include <qpainter.h>
26#include <qfontmetrics.h>
27#include <qpalette.h>
28#include <qdrawutil.h>
29#include <qscrollbar.h>
30#include <qbutton.h>
31#include <qframe.h>
32#include <qtabbar.h>
33#include <qspinbox.h>
34#include <qlineedit.h>
35
36#define INCLUDE_MENUITEM_DEF
37#include <qmenudata.h>
38
39#define QCOORDARRLEN(x) sizeof(x)/(sizeof(QCOORD)*2)
40
41class SpinBoxHack : public QSpinBox
42{
43public:
44 void setFlatButtons( bool f ) {
45 upButton()->setFlat( f );
46 downButton()->setFlat( f );
47 }
48};
49
50class FlatStylePrivate : public QObject
51{
52 Q_OBJECT
53public:
54 FlatStylePrivate() : QObject() {}
55
56 bool eventFilter( QObject *o, QEvent *e ) {
57 if ( e->type() == QEvent::ParentPaletteChange && o->inherits( "QMenuBar" ) ) {
58 QWidget *w = (QWidget *)o;
59 if ( w->parentWidget() ) {
60 QPalette p = w->parentWidget()->palette();
61 QColorGroup a = p.active();
62 a.setColor( QColorGroup::Light, a.foreground() );
63 a.setColor( QColorGroup::Dark, a.foreground() );
64 p.setActive( a );
65 p.setInactive( a );
66 w->setPalette( p );
67 }
68 }
69 return FALSE;
70 }
71};
72
73FlatStyle::FlatStyle() : revItem(FALSE)
74{
75 setButtonMargin(3);
76 setScrollBarExtent(13,13);
77 setButtonDefaultIndicatorWidth(0);
78 d = new FlatStylePrivate;
79}
80
81FlatStyle::~FlatStyle()
82{
83 delete d;
84}
85
86int FlatStyle::buttonMargin() const
87{
88 return 3;
89}
90
91QSize FlatStyle::scrollBarExtent() const
92{
93 return QSize(13,13);
94}
95
96void FlatStyle::polish ( QPalette & )
97{
98}
99
100void FlatStyle::polish( QWidget *w )
101{
102 if ( w->inherits( "QFrame" ) ) {
103 QFrame *f = (QFrame *)w;
104 if ( f->frameShape() != QFrame::NoFrame )
105 f->setFrameShape( QFrame::StyledPanel );
106 f->setLineWidth( 1 );
107 }
108 if ( w->inherits( "QSpinBox" ) )
109 ((SpinBoxHack*)w)->setFlatButtons( TRUE );
110 if ( w->inherits( "QMenuBar" ) ) {
111 // make selected item look flat
112 QPalette p = w->palette();
113 QColorGroup a = p.active();
114 a.setColor( QColorGroup::Light, a.foreground() );
115 a.setColor( QColorGroup::Dark, a.foreground() );
116 p.setActive( a );
117 p.setInactive( a );
118 w->setPalette( p );
119 w->installEventFilter( d );
120 }
121}
122
123void FlatStyle::unPolish( QWidget *w )
124{
125 if ( w->inherits( "QFrame" ) ) {
126 QFrame *f = (QFrame *)w;
127 if ( f->frameShape() != QFrame::NoFrame )
128 f->setFrameShape( QFrame::StyledPanel );
129 f->setLineWidth( 2 );
130 }
131 if ( w->inherits( "QSpinBox" ) )
132 ((SpinBoxHack*)w)->setFlatButtons( FALSE );
133 if ( w->inherits( "QMenuBar" ) ) {
134 w->unsetPalette();
135 w->removeEventFilter( d );
136 }
137}
138
139int FlatStyle::defaultFrameWidth() const
140{
141 return 1;
142}
143
144void FlatStyle::drawItem( QPainter *p, int x, int y, int w, int h,
145 int flags, const QColorGroup &g, bool enabled,
146 const QPixmap *pixmap, const QString& text, int len,
147 const QColor* penColor )
148{
149 QColor pc( penColor ? *penColor : g.foreground() );
150 QColorGroup cg( g );
151 if ( !enabled )
152 cg.setColor( QColorGroup::Light, cg.background() );
153 if ( revItem ) {
154 pc = cg.button();
155 revItem = FALSE;
156 }
157 QWindowsStyle::drawItem( p, x, y, w, h, flags, cg, enabled, pixmap, text, len, &pc );
158}
159
160void FlatStyle::drawPanel ( QPainter * p, int x, int y, int w, int h,
161 const QColorGroup &g, bool /*sunken*/, int lineWidth, const QBrush * fill )
162{
163 if ( fill )
164 p->setBrush( *fill );
165 p->setPen( QPen(g.foreground(), lineWidth) );
166 p->drawRect( x, y, w, h );
167}
168
169void FlatStyle::drawButton( QPainter *p, int x, int y, int w, int h,
170 const QColorGroup &cg, bool /*sunken*/, const QBrush* fill )
171{
172 QPen oldPen = p->pen();
173
174 if ( h >= 10 ) {
175 x++; y++;
176 w -= 2; h -= 2;
177 }
178
179 p->fillRect( x+1, y+1, w-2, h-2, fill?(*fill):cg.brush(QColorGroup::Button) );
180
181 int x2 = x+w-1;
182 int y2 = y+h-1;
183
184 p->setPen( cg.foreground() );
185
186 if ( h < 10 ) {
187 p->setBrush( NoBrush );
188 p->drawRect( x, y, w, h );
189 } else {
190 p->drawLine( x+3, y, x2-3, y );
191 p->drawLine( x+3, y2, x2-3, y2 );
192 p->drawLine( x, y+3, x, y2-3 );
193 p->drawLine( x2, y+3, x2, y2-3 );
194
195 p->drawLine( x+1, y+1, x+2, y+1 );
196 p->drawPoint( x+1, y+2 );
197 p->drawLine( x2-2, y+1, x2-1, y+1 );
198 p->drawPoint( x2-1, y+2 );
199
200 p->drawLine( x+1, y2-1, x+2, y2-1 );
201 p->drawPoint( x+1, y2-2 );
202 p->drawLine( x2-2, y2-1, x2-1, y2-1 );
203 p->drawPoint( x2-1, y2-2 );
204 }
205
206 p->setPen( oldPen );
207}
208
209void FlatStyle::drawButtonMask ( QPainter * p, int x, int y, int w, int h )
210{
211 x++; y++;
212 x-=2; y-=2;
213 p->fillRect( x, y, w, h, color1 );
214}
215
216void FlatStyle::drawBevelButton( QPainter *p, int x, int y, int w, int h,
217 const QColorGroup &g, bool /*sunken*/, const QBrush* fill )
218{
219 p->fillRect( x+1, y+1, w-2, h-2, fill?(*fill):g.brush(QColorGroup::Button) );
220 p->setPen( g.foreground() );
221 p->setBrush( NoBrush );
222 p->drawRect( x, y, w, h );
223}
224
225void FlatStyle::drawToolButton( QPainter *p, int x, int y, int w, int h,
226 const QColorGroup &g, bool sunken, const QBrush* fill )
227{
228 QBrush fb( fill ? *fill : g.button() );
229 if ( sunken && fb == g.brush( QColorGroup::Button ) ) {
230 fb = g.buttonText();
231 revItem = TRUE;// ugh
232 }
233 drawButton( p, x, y, w, h, g, sunken, &fb );
234}
235
236void FlatStyle::drawPushButton( QPushButton *btn, QPainter *p )
237{
238 QColorGroup g = btn->colorGroup();
239 int x1, y1, x2, y2;
240
241 btn->rect().coords( &x1, &y1, &x2, &y2 );// get coordinates
242
243 p->setPen( g.foreground() );
244 p->setBrush( QBrush(g.button(),NoBrush) );
245
246// int diw = buttonDefaultIndicatorWidth();
247 /*
248 if ( btn->isDefault() || btn->autoDefault() ) {
249 if ( btn->isDefault() ) {
250 p->setPen( g.shadow() );
251 p->drawRect( x1, y1, x2-x1+1, y2-y1+1 );
252 }
253 x1 += diw;
254 y1 += diw;
255 x2 -= diw;
256 y2 -= diw;
257 }
258 */
259
260 bool clearButton = TRUE;
261 if ( btn->isDown() ) {
262 drawButton( p, x1, y1, x2-x1+1, y2-y1+1, g, TRUE,
263 &g.brush( QColorGroup::Text ) );
264 } else {
265 if ( btn->isToggleButton() && btn->isOn() && btn->isEnabled() ) {
266 QBrush fill(g.light(), Dense4Pattern );
267 drawButton( p, x1, y1, x2-x1+1, y2-y1+1, g, TRUE, &fill );
268 clearButton = FALSE;
269 } else {
270 if ( !btn->isFlat() )
271 drawButton( p, x1, y1, x2-x1+1, y2-y1+1, g, btn->isOn(),
272 &g.brush( QColorGroup::Button ) );
273 }
274 }
275 /*
276 if ( clearButton ) {
277 if (btn->isDown())
278 p->setBrushOrigin(p->brushOrigin() + QPoint(1,1));
279 p->fillRect( x1+2, y1+2, x2-x1-3, y2-y1-3,
280 g.brush( QColorGroup::Button ) );
281 if (btn->isDown())
282 p->setBrushOrigin(p->brushOrigin() - QPoint(1,1));
283 }
284 */
285
286 if ( p->brush().style() != NoBrush )
287 p->setBrush( NoBrush );
288}
289
290void FlatStyle::drawPushButtonLabel( QPushButton *btn, QPainter *p )
291{
292 QRect r = pushButtonContentsRect( btn );
293 int x, y, w, h;
294 r.rect( &x, &y, &w, &h );
295 QColorGroup cg = btn->colorGroup();
296 if ( btn->isToggleButton() && btn->isOn() && btn->isEnabled() && !btn->isDown() )
297 cg.setColor( QColorGroup::ButtonText, btn->colorGroup().text() );
298 else if ( btn->isDown() || btn->isOn() )
299 cg.setColor( QColorGroup::ButtonText, btn->colorGroup().button() );
300 if ( btn->isMenuButton() ) {
301 int dx = menuButtonIndicatorWidth( btn->height() );
302 drawArrow( p, DownArrow, FALSE,
303 x+w-dx, y+2, dx-4, h-4,
304 cg,
305 btn->isEnabled() );
306 w -= dx;
307 }
308
309 if ( btn->iconSet() && !btn->iconSet()->isNull() ) {
310 QIconSet::Mode mode = btn->isEnabled()
311 ? QIconSet::Normal : QIconSet::Disabled;
312 if ( mode == QIconSet::Normal && btn->hasFocus() )
313 mode = QIconSet::Active;
314 QPixmap pixmap = btn->iconSet()->pixmap( QIconSet::Small, mode );
315 int pixw = pixmap.width();
316 int pixh = pixmap.height();
317 p->drawPixmap( x+2, y+h/2-pixh/2, pixmap );
318 x += pixw + 4;
319 w -= pixw + 4;
320 }
321 drawItem( p, x, y, w, h,
322 AlignCenter | ShowPrefix,
323 cg, btn->isEnabled(),
324 btn->pixmap(), btn->text(), -1, &cg.buttonText() );
325
326}
327
328QRect FlatStyle::comboButtonRect( int x, int y, int w, int h)
329{
330 return QRect(x+2, y+2, w-4-13, h-4);
331}
332
333
334QRect FlatStyle::comboButtonFocusRect( int x, int y, int w, int h)
335{
336 return QRect(x+2, y+2, w-4-14, h-4);
337}
338
339void FlatStyle::drawComboButton( QPainter *p, int x, int y, int w, int h,
340 const QColorGroup &g, bool sunken,
341 bool /*editable*/,
342 bool enabled,
343 const QBrush * /*fill*/ )
344{
345 x++; y++;
346 w-=2; h-=2;
347 p->setPen( g.foreground() );
348 p->setBrush( QBrush(NoBrush) );
349 p->drawRect( x, y, w, h );
350 p->setPen( g.background() );
351 p->drawRect( x+1, y+1, w-14, h-2 );
352 p->fillRect( x+2, y+2, w-16, h-4, g.brush( QColorGroup::Base ) );
353 QColorGroup cg( g );
354 if ( sunken ) {
355 cg.setColor( QColorGroup::ButtonText, g.button() );
356 cg.setColor( QColorGroup::Button, g.buttonText() );
357 }
358 drawArrow( p, QStyle::DownArrow, FALSE,
359 x+w-13, y+1, 12, h-2, cg, enabled,
360 &cg.brush( QColorGroup::Button ) );
361
362}
363
364
365void FlatStyle::drawExclusiveIndicator ( QPainter * p, int x, int y, int w,
366 int h, const QColorGroup &cg, bool on, bool down, bool enabled )
367{
368 static const QCOORD pts1[] = { // dark lines
369 1,9, 1,8, 0,7, 0,4, 1,3, 1,2, 2,1, 3,1, 4,0, 7,0, 8,1, 9,1 };
370 static const QCOORD pts4[] = { // white lines
371 2,10, 3,10, 4,11, 7,11, 8,10, 9,10, 10,9, 10,8, 11,7,
372 11,4, 10,3, 10,2 };
373 static const QCOORD pts5[] = { // inner fill
374 4,2, 7,2, 9,4, 9,7, 7,9, 4,9, 2,7, 2,4 };
375
376 p->eraseRect( x, y, w, h );
377 QPointArray a( QCOORDARRLEN(pts1), pts4 );
378 a.translate( x, y );
379 p->setPen( cg.foreground() );
380 p->drawPolyline( a );
381 a.setPoints( QCOORDARRLEN(pts4), pts1 );
382 a.translate( x, y );
383 p->setPen( cg.foreground() );
384 p->drawPolyline( a );
385 a.setPoints( QCOORDARRLEN(pts5), pts5 );
386 a.translate( x, y );
387 QColor fillColor = ( down || !enabled ) ? cg.button() : cg.base();
388 p->setPen( fillColor );
389 p->setBrush( fillColor ) ;
390 p->drawPolygon( a );
391 if ( on ) {
392 p->setPen( NoPen );
393 p->setBrush( cg.text() );
394 p->drawRect( x+5, y+4, 2, 4 );
395 p->drawRect( x+4, y+5, 4, 2 );
396 }
397}
398
399void FlatStyle::drawIndicator ( QPainter * p, int x, int y, int w, int h,
400 const QColorGroup &cg, int state, bool down, bool enabled )
401{
402 QColorGroup mycg( cg );
403 mycg.setBrush( QColorGroup::Button, QBrush() );
404 QBrush fill;
405 drawButton( p, x, y, w, h, mycg, TRUE, 0 );
406 if ( down )
407 fill = cg.brush( QColorGroup::Button );
408 else
409 fill = cg.brush( enabled ? QColorGroup::Base : QColorGroup::Background );
410 mycg.setBrush( QColorGroup::Button, fill );
411 p->fillRect( x+1, y+1, w-2, h-2, fill );
412 if ( state != QButton::Off ) {
413 QPointArray a( 7*2 );
414 int i, xx, yy;
415 xx = x+3;
416 yy = y+5;
417 for ( i=0; i<3; i++ ) {
418 a.setPoint( 2*i, xx, yy );
419 a.setPoint( 2*i+1, xx, yy+2 );
420 xx++; yy++;
421 }
422 yy -= 2;
423 for ( i=3; i<7; i++ ) {
424 a.setPoint( 2*i, xx, yy );
425 a.setPoint( 2*i+1, xx, yy+2 );
426 xx++; yy--;
427 }
428 if ( state == QButton::NoChange ) {
429 p->setPen( mycg.dark() );
430 } else {
431 p->setPen( mycg.text() );
432 }
433 p->drawLineSegments( a );
434 }
435}
436
437 #define HORIZONTAL(sb->orientation() == QScrollBar::Horizontal)
438 #define VERTICAL!HORIZONTAL
439 #define MOTIF_BORDER2
440 #define SLIDER_MIN9 // ### motif says 6 but that's too small
441
442/*! \reimp */
443
444void FlatStyle::scrollBarMetrics( const QScrollBar* sb, int &sliderMin, int &sliderMax, int &sliderLength, int& buttonDim )
445{
446 int maxLength;
447 int length = HORIZONTAL ? sb->width() : sb->height();
448 int extent = HORIZONTAL ? sb->height() : sb->width();
449
450 if ( length > (extent - 1)*2 )
451 buttonDim = extent;
452 else
453 buttonDim = length/2 - 1;
454
455 sliderMin = 0;
456 maxLength = length - buttonDim*2 + 2;
457
458 if ( sb->maxValue() == sb->minValue() ) {
459 sliderLength = maxLength;
460 } else {
461 sliderLength = (sb->pageStep()*maxLength)/
462 (sb->maxValue()-sb->minValue()+sb->pageStep());
463 uint range = sb->maxValue()-sb->minValue();
464 if ( sliderLength < SLIDER_MIN || range > INT_MAX/2 )
465 sliderLength = SLIDER_MIN;
466 if ( sliderLength > maxLength )
467 sliderLength = maxLength;
468 }
469
470 sliderMax = sliderMin + maxLength - sliderLength;
471}
472
473/*!\reimp
474 */
475QStyle::ScrollControl FlatStyle::scrollBarPointOver( const QScrollBar* sb, int sliderStart, const QPoint& p )
476{
477 if ( !sb->rect().contains( p ) )
478 return NoScroll;
479 int sliderMin, sliderMax, sliderLength, buttonDim, pos;
480 scrollBarMetrics( sb, sliderMin, sliderMax, sliderLength, buttonDim );
481
482 if (sb->orientation() == QScrollBar::Horizontal)
483 pos = p.x();
484 else
485 pos = p.y();
486
487 if (pos < sliderStart)
488 return SubPage;
489 if (pos < sliderStart + sliderLength)
490 return Slider;
491 if (pos < sliderMax + sliderLength)
492 return AddPage;
493 if (pos < sliderMax + sliderLength + buttonDim)
494 return SubLine;
495 return AddLine;
496}
497
498/*! \reimp */
499
500void FlatStyle::drawScrollBarControls( QPainter* p, const QScrollBar* sb, int sliderStart, uint controls, uint activeControl )
501{
502#define ADD_LINE_ACTIVE ( activeControl == AddLine )
503#define SUB_LINE_ACTIVE ( activeControl == SubLine )
504 QColorGroup g = sb->colorGroup();
505
506 int sliderMin, sliderMax, sliderLength, buttonDim;
507 scrollBarMetrics( sb, sliderMin, sliderMax, sliderLength, buttonDim );
508
509 if ( controls == (AddLine | SubLine | AddPage | SubPage | Slider | First | Last ) ) {
510 p->setPen( g.foreground() );
511 p->setBrush( g.brush( QColorGroup::Mid ) );
512 p->drawRect( 0, 0, sb->width(), sb->height() );
513 }
514
515 if (sliderStart > sliderMax) { // sanity check
516 sliderStart = sliderMax;
517 }
518
519 int dimB = buttonDim;
520 QRect addB;
521 QRect subB;
522 QRect addPageR;
523 QRect subPageR;
524 QRect sliderR;
525 int addX, addY, subX, subY;
526 int length = HORIZONTAL ? sb->width() : sb->height();
527 int extent = HORIZONTAL ? sb->height() : sb->width();
528
529 if ( HORIZONTAL ) {
530 subY = addY = ( extent - dimB ) / 2;
531 subX = length - dimB - dimB + 1;
532 addX = length - dimB;
533 } else {
534 subX = addX = ( extent - dimB ) / 2;
535 subY = length - dimB - dimB + 1;
536 addY = length - dimB;
537 }
538
539 int sliderEnd = sliderStart + sliderLength;
540 int sliderW = extent;
541 if ( HORIZONTAL ) {
542 subB.setRect( subX,subY,dimB,dimB );
543 addB.setRect( addX,addY,dimB,dimB );
544 subPageR.setRect( 0, 0, sliderStart+1, sliderW );
545 addPageR.setRect( sliderEnd-1, 0, subX - sliderEnd+2, sliderW );
546 sliderR .setRect( sliderStart, 0, sliderLength, sliderW );
547
548 } else {
549 subB.setRect( subX,subY,dimB,dimB );
550 addB.setRect( addX,addY,dimB,dimB );
551 subPageR.setRect( 0, 0, sliderW, sliderStart+1 );
552 addPageR.setRect( 0, sliderEnd-1, sliderW, subY - sliderEnd+2 );
553 sliderR .setRect( 0, sliderStart, sliderW, sliderLength );
554 }
555
556 bool maxedOut = (sb->maxValue() == sb->minValue());
557 p->setPen( g.foreground() );
558 if ( controls & AddLine ) {
559 p->setBrush( ADD_LINE_ACTIVE ? g.foreground() : g.button() );
560 p->drawRect( addB.x(), addB.y(), addB.width(), addB.height() );
561 p->setPen( ADD_LINE_ACTIVE ? g.button() : g.foreground() );
562 QColorGroup cg( g );
563 if ( maxedOut )
564 cg.setColor( QColorGroup::ButtonText, g.mid() );
565 else if ( ADD_LINE_ACTIVE )
566 cg.setColor( QColorGroup::ButtonText, g.button() );
567 int xo = VERTICAL ? 1 : 0;
568 drawArrow( p, VERTICAL ? DownArrow : RightArrow, FALSE,
569 addB.x()+2+xo, addB.y()+2, addB.width()-4-xo, addB.height()-4,
570 cg, TRUE, &p->brush() );
571 }
572 if ( controls & SubLine ) {
573 p->setBrush( SUB_LINE_ACTIVE ? g.foreground() : g.button() );
574 p->drawRect( subB.x(), subB.y(), subB.width(), subB.height() );
575 p->setPen( SUB_LINE_ACTIVE ? g.button() : g.foreground() );
576 QColorGroup cg( g );
577 if ( maxedOut )
578 cg.setColor( QColorGroup::ButtonText, g.mid() );
579 else if ( SUB_LINE_ACTIVE )
580 cg.setColor( QColorGroup::ButtonText, g.button() );
581 int xo = VERTICAL ? 1 : 0;
582 drawArrow( p, VERTICAL ? UpArrow : LeftArrow, FALSE,
583 subB.x()+2+xo, subB.y()+2, subB.width()-4-xo, subB.height()-4,
584 cg, TRUE, &p->brush() );
585 }
586
587
588 p->setPen( g.foreground() );
589 p->setBrush( g.brush( QColorGroup::Mid ) );
590 if ( controls & SubPage )
591 p->drawRect( subPageR.x(), subPageR.y(), subPageR.width(), subPageR.height() );
592 if ( controls & AddPage && addPageR.y() < addPageR.bottom() )
593 p->drawRect( addPageR.x(), addPageR.y(), addPageR.width(), addPageR.height() );
594 if ( controls & Slider ) {
595 QPoint bo = p->brushOrigin();
596 p->setBrushOrigin(sliderR.topLeft());
597 p->setPen( g.foreground() );
598 p->setBrush( g.button() );
599 p->drawRect( sliderR.x(), sliderR.y(), sliderR.width(), sliderR.height() );
600 p->setBrushOrigin(bo);
601 QColorGroup cg( g );
602 if ( maxedOut )
603 cg.setColor( QColorGroup::ButtonText, g.mid() );
604 drawRiffles( p, sliderR.x(), sliderR.y(),
605 sliderR.width(), sliderR.height(), cg, HORIZONTAL );
606 }
607
608 // ### perhaps this should not be able to accept focus if maxedOut?
609 if ( sb->hasFocus() && (controls & Slider) )
610 p->drawWinFocusRect( sliderR.x()+2, sliderR.y()+2,
611 sliderR.width()-5, sliderR.height()-5,
612 sb->backgroundColor() );
613
614}
615
616void FlatStyle::drawRiffles( QPainter* p, int x, int y, int w, int h,
617 const QColorGroup &g, bool horizontal )
618{
619 if (!horizontal) {
620 if (h > 20) {
621 y += (h-20)/2 ;
622 h = 20;
623 }
624 if (h > 12) {
625 int n = 3;
626 int my = y+h/2-2;
627 int i ;
628 p->setPen(g.buttonText());
629 for (i=0; i<n; i++) {
630 p->drawLine(x+4, my+3*i, x+w-5, my+3*i);
631 }
632 }
633 } else {
634 if (w > 20) {
635 x += (w-20)/2 ;
636 w = 20;
637 }
638 if (w > 12) {
639 int n = 3;
640 int mx = x+w/2-4;
641 int i ;
642 p->setPen(g.buttonText());
643 for (i=0; i<n; i++) {
644 p->drawLine(mx+3*i, y+4, mx + 3*i, y+h-5);
645 }
646 }
647 }
648}
649
650int FlatStyle::sliderLength() const
651{
652 return 12;
653}
654
655void FlatStyle::drawSlider( QPainter *p, int x, int y, int w, int h,
656 const QColorGroup &g, Orientation o, bool tickAbove, bool tickBelow )
657{
658 int a = tickAbove ? 3 : 0;
659 int b = tickBelow ? 3 : 0;
660
661 p->setPen( g.foreground() );
662 p->setBrush( g.button() );
663 if ( o == Horizontal ) {
664 p->drawRect( x, y+a, w, h-a-b );
665 int xp = x + w/2;
666 p->drawLine( xp-1, y+a+3, xp-1, y+h-b-4 );
667 p->drawLine( xp, y+a+3, xp, y+h-b-4 );
668 } else {
669 p->drawRect( x+a, y, w-a-b, h );
670 int yp = y + h/2;
671 p->drawLine( x+a+3, yp-1, x+w-b-4, yp-1 );
672 p->drawLine( x+a+3, yp, x+w-b-4, yp );
673 }
674}
675
676void FlatStyle::drawSliderMask ( QPainter * p, int x, int y, int w, int h,
677 Orientation o, bool tickAbove, bool tickBelow )
678{
679 int a = tickAbove ? 3 : 0;
680 int b = tickBelow ? 3 : 0;
681 if ( o == Horizontal )
682 p->fillRect( x, y+a, w, h-a-b, color1 );
683 else
684 p->fillRect( x+a, y, w-a-b, h, color1 );
685}
686
687/*!\reimp
688 */
689void FlatStyle::drawSliderGrooveMask( QPainter *p,
690 int x, int y, int w, int h,
691 const QColorGroup& , QCOORD c,
692 Orientation orient )
693{
694 if ( orient == Horizontal )
695 p->fillRect( x, y + c - 2, w, 4, color1 );
696 else
697 p->fillRect( x + c - 2, y, 4, h, color1 );
698}
699
700void FlatStyle::drawSliderGroove( QPainter *p, int x, int y, int w, int h, const QColorGroup &g, QCOORD c, Orientation orient )
701{
702 if ( orient == Horizontal )
703 p->fillRect( x, y + c - 2, w, 4, g.foreground() );
704 else
705 p->fillRect( x + c - 2, y, 4, h, g.foreground() );
706}
707
708void FlatStyle::drawTab( QPainter *p, const QTabBar *tb, QTab *t, bool selected )
709{
710 QRect r( t->rect() );
711 if ( tb->shape() == QTabBar::RoundedAbove ) {
712 p->setPen( tb->colorGroup().foreground() );
713 p->drawLine( r.left(), r.bottom(), r.right(), r.bottom() );
714 if ( r.left() == 0 )
715 p->drawPoint( tb->rect().bottomLeft() );
716 else
717 p->drawLine( r.left(), r.bottom(), r.right(), r.bottom() );
718
719 if ( selected ) {
720 p->setPen( tb->colorGroup().background() );
721 p->drawLine( r.left()+2, r.top()+1, r.right()-2, r.top()+1 );
722 p->fillRect( QRect( r.left()+1, r.top()+2, r.width()-2, r.height()-2),
723 tb->colorGroup().brush( QColorGroup::Background ));
724 } else {
725 r.setRect( r.left() + 2, r.top() + 2,
726 r.width() - 4, r.height() - 2 );
727 p->setPen( tb->colorGroup().button() );
728 p->drawLine( r.left()+2, r.top()+1, r.right()-2, r.top()+1 );
729 p->fillRect( QRect( r.left()+1, r.top()+2, r.width()-2, r.height()-3),
730 tb->colorGroup().brush( QColorGroup::Button ));
731 }
732
733 p->setPen( tb->colorGroup().foreground() );
734 p->drawLine( r.left(), r.bottom()-1, r.left(), r.top() + 2 );
735 p->drawPoint( r.left()+1, r.top() + 1 );
736 p->drawLine( r.left()+2, r.top(),
737 r.right() - 2, r.top() );
738
739 p->drawPoint( r.right() - 1, r.top() + 1 );
740 p->drawLine( r.right(), r.top() + 2, r.right(), r.bottom() - 1);
741 } else if ( tb->shape() == QTabBar::RoundedBelow ) {
742 if ( selected ) {
743 p->setPen( tb->colorGroup().background() );
744 p->drawLine( r.left()+2, r.bottom()-1, r.right()-2, r.bottom()-1 );
745 p->fillRect( QRect( r.left()+1, r.top(), r.width()-2, r.height()-2),
746 tb->palette().normal().brush( QColorGroup::Background ));
747 } else {
748 p->setPen( tb->colorGroup().foreground() );
749 p->drawLine( r.left(), r.top(),
750 r.right(), r.top() );
751 r.setRect( r.left() + 2, r.top(),
752 r.width() - 4, r.height() - 2 );
753 p->setPen( tb->colorGroup().button() );
754 p->drawLine( r.left()+2, r.bottom()-1, r.right()-2, r.bottom()-1 );
755 p->fillRect( QRect( r.left()+1, r.top()+1, r.width()-2, r.height()-3),
756 tb->palette().normal().brush( QColorGroup::Button ));
757 }
758
759 p->setPen( tb->colorGroup().foreground() );
760 p->drawLine( r.right(), r.top(),
761 r.right(), r.bottom() - 2 );
762 p->drawPoint( r.right() - 1, r.bottom() - 1 );
763 p->drawLine( r.right() - 2, r.bottom(),
764 r.left() + 2, r.bottom() );
765
766 p->drawLine( r.left(), r.top()+1,
767 r.left(), r.bottom() - 2 );
768 p->drawPoint( r.left() + 1, r.bottom() - 1 );
769 if ( r.left() == 0 )
770 p->drawPoint( tb->rect().topLeft() );
771
772 } else {
773 QCommonStyle::drawTab( p, tb, t, selected );
774 }
775}
776
777 static const int motifItemFrame = 0;// menu item frame width
778 static const int motifSepHeight = 2;// separator item height
779 static const int motifItemHMargin = 1;// menu item hor text margin
780 static const int motifItemVMargin = 2;// menu item ver text margin
781 static const int motifArrowHMargin = 0;// arrow horizontal margin
782 static const int motifTabSpacing = 12;// space between text and tab
783 static const int motifCheckMarkHMargin = 1;// horiz. margins of check mark
784 static const int windowsRightBorder= 8; // right border on windows
785static const int windowsCheckMarkWidth = 2; // checkmarks width on windows
786
787/*! \reimp
788*/
789int FlatStyle::extraPopupMenuItemWidth( bool checkable, int maxpmw, QMenuItem* mi, const QFontMetrics& /*fm*/ )
790{
791#ifndef QT_NO_MENUDATA
792 int w = 2*motifItemHMargin + 2*motifItemFrame; // a little bit of border can never harm
793
794 if ( mi->isSeparator() )
795 return 10; // arbitrary
796 else if ( mi->pixmap() )
797 w += mi->pixmap()->width();// pixmap only
798
799 if ( !mi->text().isNull() ) {
800 if ( mi->text().find('\t') >= 0 )// string contains tab
801 w += motifTabSpacing;
802 }
803
804 if ( maxpmw ) { // we have iconsets
805 w += maxpmw;
806 w += 6; // add a little extra border around the iconset
807 }
808
809 if ( checkable && maxpmw < windowsCheckMarkWidth ) {
810 w += windowsCheckMarkWidth - maxpmw; // space for the checkmarks
811 }
812
813 if ( maxpmw > 0 || checkable ) // we have a check-column ( iconsets or checkmarks)
814 w += motifCheckMarkHMargin; // add space to separate the columns
815
816 w += windowsRightBorder; // windows has a strange wide border on the right side
817
818 return w;
819#endif
820}
821
822/*! \reimp
823*/
824int FlatStyle::popupMenuItemHeight( bool /*checkable*/, QMenuItem* mi, const QFontMetrics& fm )
825{
826#ifndef QT_NO_MENUDATA
827 int h = 0;
828 if ( mi->isSeparator() ) // separator height
829 h = motifSepHeight;
830 else if ( mi->pixmap() ) // pixmap height
831 h = mi->pixmap()->height() + 2*motifItemFrame;
832 else // text height
833 h = fm.height() + 2*motifItemVMargin + 2*motifItemFrame - 1;
834
835 if ( !mi->isSeparator() && mi->iconSet() != 0 ) {
836 h = QMAX( h, mi->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).height() + 2*motifItemFrame );
837 }
838 if ( mi->custom() )
839 h = QMAX( h, mi->custom()->sizeHint().height() + 2*motifItemVMargin + 2*motifItemFrame ) - 1;
840 return h;
841#endif
842}
843
844void FlatStyle::drawPopupMenuItem( QPainter* p, bool checkable, int maxpmw, int tab, QMenuItem* mi,
845 const QPalette& pal,
846 bool act, bool enabled, int x, int y, int w, int h)
847{
848#ifndef QT_NO_MENUDATA
849 const QColorGroup & g = pal.active();
850 bool dis = !enabled;
851 QColorGroup itemg = dis ? pal.disabled() : pal.active();
852
853 if ( checkable )
854 maxpmw = QMAX( maxpmw, 8 ); // space for the checkmarks
855
856 int checkcol = maxpmw;
857
858 if ( mi && mi->isSeparator() ) { // draw separator
859 p->setPen( g.dark() );
860 p->drawLine( x, y, x+w, y );
861 return;
862 }
863
864 QBrush fill = act? g.brush( QColorGroup::Highlight ) :
865 g.brush( QColorGroup::Button );
866 p->fillRect( x, y, w, h, fill);
867
868 if ( !mi )
869 return;
870
871 if ( mi->isChecked() ) {
872 if ( act && !dis ) {
873 qDrawShadePanel( p, x, y, checkcol, h,
874 g, TRUE, 1, &g.brush( QColorGroup::Button ) );
875 } else {
876 qDrawShadePanel( p, x, y, checkcol, h,
877 g, TRUE, 1, &g.brush( QColorGroup::Midlight ) );
878 }
879 } else if ( !act ) {
880 p->fillRect(x, y, checkcol , h,
881 g.brush( QColorGroup::Button ));
882 }
883
884 if ( mi->iconSet() ) { // draw iconset
885 QIconSet::Mode mode = dis ? QIconSet::Disabled : QIconSet::Normal;
886 if (act && !dis )
887 mode = QIconSet::Active;
888 QPixmap pixmap = mi->iconSet()->pixmap( QIconSet::Small, mode );
889 int pixw = pixmap.width();
890 int pixh = pixmap.height();
891 if ( act && !dis ) {
892 if ( !mi->isChecked() )
893 qDrawShadePanel( p, x, y, checkcol, h, g, FALSE, 1, &g.brush( QColorGroup::Button ) );
894 }
895 QRect cr( x, y, checkcol, h );
896 QRect pmr( 0, 0, pixw, pixh );
897 pmr.moveCenter( cr.center() );
898 p->setPen( itemg.text() );
899 p->drawPixmap( pmr.topLeft(), pixmap );
900
901 QBrush fill = act? g.brush( QColorGroup::Highlight ) :
902 g.brush( QColorGroup::Button );
903 p->fillRect( x+checkcol + 1, y, w - checkcol - 1, h, fill);
904 } else if ( checkable ) {// just "checking"...
905 int mw = checkcol + motifItemFrame;
906 int mh = h - 2*motifItemFrame;
907 if ( mi->isChecked() ) {
908 drawCheckMark( p, x + motifItemFrame + 2,
909 y+motifItemFrame, mw, mh, itemg, act, dis );
910 }
911 }
912
913 p->setPen( act ? g.highlightedText() : g.buttonText() );
914
915 QColor discol;
916 if ( dis ) {
917 discol = itemg.text();
918 p->setPen( discol );
919 }
920
921 int xm = motifItemFrame + checkcol + motifItemHMargin;
922
923 if ( mi->custom() ) {
924 int m = motifItemVMargin;
925 p->save();
926 if ( dis && !act ) {
927 p->setPen( g.light() );
928 mi->custom()->paint( p, itemg, act, enabled,
929 x+xm+1, y+m+1, w-xm-tab+1, h-2*m );
930 p->setPen( discol );
931 }
932 mi->custom()->paint( p, itemg, act, enabled,
933 x+xm, y+m, w-xm-tab+1, h-2*m );
934 p->restore();
935 }
936 QString s = mi->text();
937 if ( !s.isNull() ) { // draw text
938 int t = s.find( '\t' );
939 int m = motifItemVMargin;
940 const int text_flags = AlignVCenter|ShowPrefix | DontClip | SingleLine;
941 if ( t >= 0 ) { // draw tab text
942 if ( dis && !act ) {
943 p->setPen( g.light() );
944 p->drawText( x+w-tab-windowsRightBorder-motifItemHMargin-motifItemFrame+1,
945 y+m+1, tab, h-2*m, text_flags, s.mid( t+1 ));
946 p->setPen( discol );
947 }
948 p->drawText( x+w-tab-windowsRightBorder-motifItemHMargin-motifItemFrame,
949 y+m, tab, h-2*m, text_flags, s.mid( t+1 ) );
950 }
951 if ( dis && !act )
952 p->setPen( discol );
953 p->drawText( x+xm, y+m, w-xm-tab+1, h-2*m, text_flags, s, t );
954 } else if ( mi->pixmap() ) { // draw pixmap
955 QPixmap *pixmap = mi->pixmap();
956 if ( pixmap->depth() == 1 )
957 p->setBackgroundMode( OpaqueMode );
958 p->drawPixmap( x+xm, y+motifItemFrame, *pixmap );
959 if ( pixmap->depth() == 1 )
960 p->setBackgroundMode( TransparentMode );
961 }
962 if ( mi->popup() ) { // draw sub menu arrow
963 int dim = (h-2*motifItemFrame) / 2;
964 if ( act ) {
965 if ( !dis )
966 discol = white;
967 QColorGroup g2( discol, g.highlight(),
968 white, white,
969 dis ? discol : white,
970 discol, white );
971 drawArrow( p, RightArrow, FALSE,
972 x+w - motifArrowHMargin - motifItemFrame - dim, y+h/2-dim/2,
973 dim, dim, g2, TRUE );
974 } else {
975 drawArrow( p, RightArrow,
976 FALSE,
977 x+w - motifArrowHMargin - motifItemFrame - dim, y+h/2-dim/2,
978 dim, dim, g, mi->isEnabled() );
979 }
980 }
981#endif
982}
983
984void FlatStyle::getButtonShift( int &x, int &y )
985{
986 x = 0; y = 0;
987}
988
989//===========================================================================
990
991FlatStyleImpl::FlatStyleImpl()
992 : flat(0), ref(0)
993{
994}
995
996FlatStyleImpl::~FlatStyleImpl()
997{
998 // We do not delete the style because Qt does that when a new style
999 // is set.
1000}
1001
1002QStyle *FlatStyleImpl::style()
1003{
1004 if ( !flat )
1005 flat = new FlatStyle();
1006 return flat;
1007}
1008
1009QString FlatStyleImpl::name() const
1010{
1011 return QString("Flat");
1012}
1013
1014QRESULT FlatStyleImpl::queryInterface( const QUuid &uuid, QUnknownInterface **iface )
1015{
1016 *iface = 0;
1017 if ( uuid == IID_QUnknown )
1018 *iface = this;
1019 else if ( uuid == IID_Style )
1020 *iface = this;
1021
1022 if ( *iface )
1023 (*iface)->addRef();
1024 return QS_OK;
1025}
1026
1027Q_EXPORT_INTERFACE()
1028{
1029 Q_CREATE_INSTANCE( FlatStyleImpl )
1030}
1031
1032#include "flat.moc"
diff --git a/noncore/styles/flat/flat.h b/noncore/styles/flat/flat.h
new file mode 100644
index 0000000..e446800
--- a/dev/null
+++ b/noncore/styles/flat/flat.h
@@ -0,0 +1,114 @@
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#ifndef FLATSTYLE_H
22#define FLATSTYLE_H
23
24#include <qwindowsstyle.h>
25#include <qpe/styleinterface.h>
26
27class FlatStylePrivate;
28
29class Q_EXPORT FlatStyle : public QWindowsStyle
30{
31public:
32 FlatStyle();
33 virtual ~FlatStyle();
34 virtual void polish( QPalette &p );
35 virtual void polish( QWidget *w );
36 virtual void unPolish( QWidget *w );
37
38 int defaultFrameWidth () const;
39 void drawItem( QPainter *p, int x, int y, int w, int h,
40 int flags, const QColorGroup &g, bool enabled,
41 const QPixmap *pixmap, const QString& text, int len, const QColor* penColor );
42 void drawPanel ( QPainter * p, int x, int y, int w, int h,
43 const QColorGroup &, bool sunken=FALSE, int lineWidth = 1, const QBrush * fill = 0 );
44 void drawButton( QPainter *p, int x, int y, int w, int h,
45 const QColorGroup &g, bool sunken, const QBrush* fill );
46 void drawButtonMask ( QPainter * p, int x, int y, int w, int h );
47 void drawBevelButton( QPainter *p, int x, int y, int w, int h,
48 const QColorGroup &g, bool sunken=FALSE, const QBrush* fill=0 );
49 void drawToolButton( QPainter *p, int x, int y, int w, int h,
50 const QColorGroup &g, bool sunken=FALSE, const QBrush* fill=0 );
51 void drawPushButton( QPushButton *btn, QPainter *p );
52 void drawPushButtonLabel( QPushButton *btn, QPainter *p );
53 QRect comboButtonRect( int x, int y, int w, int h);
54 QRect comboButtonFocusRect( int x, int y, int w, int h);
55 void drawComboButton( QPainter *p, int x, int y, int w, int h,
56 const QColorGroup &g, bool sunken, bool, bool enabled,
57 const QBrush *fill );
58 void drawExclusiveIndicator ( QPainter * p, int x, int y, int w, int h,
59 const QColorGroup & g, bool on, bool down = FALSE, bool enabled = TRUE );
60 void drawIndicator ( QPainter * p, int x, int y, int w, int h,
61 const QColorGroup & g, int state, bool down = FALSE, bool enabled = TRUE );
62 void scrollBarMetrics( const QScrollBar*, int&, int&, int&, int&);
63 void drawScrollBarControls( QPainter*, const QScrollBar*, int sliderStart, uint controls, uint activeControl );
64 ScrollControl scrollBarPointOver( const QScrollBar* sb, int sliderStart, const QPoint& p );
65 void drawRiffles( QPainter* p, int x, int y, int w, int h,
66 const QColorGroup &g, bool horizontal );
67 int sliderLength() const;
68 void drawSlider( QPainter *p, int x, int y, int w, int h,
69 const QColorGroup &g, Orientation, bool tickAbove, bool tickBelow );
70 void drawSliderMask( QPainter *p, int x, int y, int w, int h,
71 Orientation, bool tickAbove, bool tickBelow );
72 void drawSliderGrooveMask( QPainter *p, int x, int y, int w, int h,
73 const QColorGroup& , QCOORD c, Orientation orient );
74 void drawSliderGroove ( QPainter * p, int x, int y, int w, int h, const QColorGroup & g, QCOORD c, Orientation );
75 void drawTab( QPainter *, const QTabBar *, QTab *, bool selected );
76 int extraPopupMenuItemWidth( bool checkable, int maxpmw, QMenuItem*, const QFontMetrics& );
77 int popupMenuItemHeight( bool checkable, QMenuItem*, const QFontMetrics& );
78 void drawPopupMenuItem( QPainter* p, bool checkable, int maxpmw, int tab, QMenuItem* mi,
79 const QPalette& pal,
80 bool act, bool enabled, int x, int y, int w, int h);
81
82 int buttonMargin() const;
83 QSize scrollBarExtent() const;
84 void getButtonShift( int &x, int &y );
85
86private:
87 FlatStylePrivate *d;
88 bool revItem;
89 // Disabled copy constructor and operator=
90#if defined(Q_DISABLE_COPY)
91 FlatStyle( const FlatStyle & );
92 FlatStyle& operator=( const FlatStyle & );
93#endif
94};
95
96
97class FlatStyleImpl : public StyleInterface
98{
99public:
100 FlatStyleImpl();
101 virtual ~FlatStyleImpl();
102
103 QRESULT queryInterface( const QUuid&, QUnknownInterface** );
104 Q_REFCOUNT
105
106 virtual QStyle *style();
107 virtual QString name() const;
108
109private:
110 FlatStyle *flat;
111 ulong ref;
112};
113
114#endif // FLATSTYLE_H
diff --git a/noncore/styles/flat/flat.pro b/noncore/styles/flat/flat.pro
new file mode 100644
index 0000000..8e2512f
--- a/dev/null
+++ b/noncore/styles/flat/flat.pro
@@ -0,0 +1,11 @@
1 TEMPLATE= lib
2 CONFIG += qt warn_on release
3 HEADERS = flat.h
4 SOURCES = flat.cpp
5 TARGET = flatstyle
6 DESTDIR = $(OPIEDIR)/plugins/styles
7 INCLUDEPATH+= $(OPIEDIR)/include
8DEPENDPATH += $(OPIEDIR)/include
9LIBS += -lqpe
10 VERSION = 1.0.0
11
diff --git a/noncore/styles/flat/opie-style-flat.control b/noncore/styles/flat/opie-style-flat.control
new file mode 100644
index 0000000..f02b9b1
--- a/dev/null
+++ b/noncore/styles/flat/opie-style-flat.control
@@ -0,0 +1,9 @@
1Files: plugins/styles/libflatstyle.so*
2Priority: optional
3Section: opie/styles
4Maintainer: Robert Griebl <sandman@handhelds.org>
5Architecture: arm
6Version: $QPE_VERSION-$SUB_VERSION
7Depends: opie-base ($QPE_VERSION)
8Description: OPIE widget style
9 Simple, flat widget style for OPIE.
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
diff --git a/noncore/styles/fresh/fresh.h b/noncore/styles/fresh/fresh.h
new file mode 100644
index 0000000..b4be7f3
--- a/dev/null
+++ b/noncore/styles/fresh/fresh.h
@@ -0,0 +1,100 @@
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#ifndef FRESHSTYLE_H
22#define FRESHSTYLE_H
23
24#include <qwindowsstyle.h>
25#include <qpe/styleinterface.h>
26
27class Q_EXPORT FreshStyle : public QWindowsStyle
28{
29public:
30 FreshStyle();
31 virtual ~FreshStyle();
32 virtual void polish( QPalette &p );
33 virtual void polish( QWidget *w );
34 virtual void unPolish( QWidget *w );
35
36 int defaultFrameWidth () const;
37 void drawPanel ( QPainter * p, int x, int y, int w, int h,
38 const QColorGroup &, bool sunken=FALSE, int lineWidth = 1, const QBrush * fill = 0 );
39 void drawButton( QPainter *p, int x, int y, int w, int h,
40 const QColorGroup &g, bool sunken, const QBrush* fill );
41 void drawButtonMask ( QPainter * p, int x, int y, int w, int h );
42 void drawBevelButton( QPainter *p, int x, int y, int w, int h,
43 const QColorGroup &g, bool sunken=FALSE, const QBrush* fill=0 );
44 QRect comboButtonRect( int x, int y, int w, int h);
45 QRect comboButtonFocusRect( int x, int y, int w, int h);
46 void drawComboButton( QPainter *p, int x, int y, int w, int h,
47 const QColorGroup &g, bool sunken, bool, bool enabled,
48 const QBrush *fill );
49 void drawExclusiveIndicator ( QPainter * p, int x, int y, int w, int h,
50 const QColorGroup & g, bool on, bool down = FALSE, bool enabled = TRUE );
51 void drawIndicator ( QPainter * p, int x, int y, int w, int h,
52 const QColorGroup & g, int state, bool down = FALSE, bool enabled = TRUE );
53 void scrollBarMetrics( const QScrollBar*, int&, int&, int&, int&);
54 void drawScrollBarControls( QPainter*, const QScrollBar*, int sliderStart, uint controls, uint activeControl );
55 ScrollControl scrollBarPointOver( const QScrollBar* sb, int sliderStart, const QPoint& p );
56 void drawRiffles( QPainter* p, int x, int y, int w, int h,
57 const QColorGroup &g, bool horizontal );
58 int sliderLength() const;
59 void drawSlider( QPainter *p, int x, int y, int w, int h,
60 const QColorGroup &g, Orientation, bool tickAbove, bool tickBelow );
61 void drawSliderMask( QPainter *p, int x, int y, int w, int h,
62 Orientation, bool tickAbove, bool tickBelow );
63 void drawSliderGrooveMask( QPainter *p, int x, int y, int w, int h,
64 const QColorGroup& , QCOORD c, Orientation orient );
65 void drawTab( QPainter *, const QTabBar *, QTab *, bool selected );
66 int extraPopupMenuItemWidth( bool checkable, int maxpmw, QMenuItem*, const QFontMetrics& );
67 int popupMenuItemHeight( bool checkable, QMenuItem*, const QFontMetrics& );
68 void drawPopupMenuItem( QPainter* p, bool checkable, int maxpmw, int tab, QMenuItem* mi,
69 const QPalette& pal,
70 bool act, bool enabled, int x, int y, int w, int h);
71
72 int buttonMargin() const;
73 QSize scrollBarExtent() const;
74
75 private:// Disabled copy constructor and operator=
76#if defined(Q_DISABLE_COPY)
77 FreshStyle( const FreshStyle & );
78 FreshStyle& operator=( const FreshStyle & );
79#endif
80};
81
82
83class FreshStyleImpl : public StyleInterface
84{
85public:
86 FreshStyleImpl();
87 virtual ~FreshStyleImpl();
88
89 QRESULT queryInterface( const QUuid&, QUnknownInterface** );
90 Q_REFCOUNT
91
92 virtual QStyle *style();
93 virtual QString name() const;
94
95private:
96 FreshStyle *fresh;
97 ulong ref;
98};
99
100#endif // FRESHSTYLE_H
diff --git a/noncore/styles/fresh/fresh.pro b/noncore/styles/fresh/fresh.pro
new file mode 100644
index 0000000..e2780e0
--- a/dev/null
+++ b/noncore/styles/fresh/fresh.pro
@@ -0,0 +1,11 @@
1 TEMPLATE= lib
2 CONFIG += qt warn_on release
3 HEADERS = fresh.h
4 SOURCES = fresh.cpp
5 TARGET = freshstyle
6 DESTDIR = $(OPIEDIR)/plugins/styles
7 INCLUDEPATH+= $(OPIEDIR)/include
8DEPENDPATH += $(OPIEDIR)/include
9LIBS += -lqpe
10 VERSION = 1.0.0
11
diff --git a/noncore/styles/fresh/opie-style-fresh.control b/noncore/styles/fresh/opie-style-fresh.control
new file mode 100644
index 0000000..161bc11
--- a/dev/null
+++ b/noncore/styles/fresh/opie-style-fresh.control
@@ -0,0 +1,9 @@
1Files: plugins/styles/libfreshstyle.so*
2Priority: optional
3Section: opie/styles
4Maintainer: Robert Griebl <sandman@handhelds.org>
5Architecture: arm
6Version: $QPE_VERSION-$SUB_VERSION
7Depends: opie-base ($QPE_VERSION)
8Description: OPIE widget style
9 Simple widget style for OPIE.