summaryrefslogtreecommitdiff
path: root/noncore/styles
authorkergoth <kergoth>2003-08-09 17:14:54 (UTC)
committer kergoth <kergoth>2003-08-09 17:14:54 (UTC)
commita7e015198a8c5ad3b6e144a9032b059086253e00 (patch) (unidiff)
treeb712b6f11310d88744fe393a92b3160b741a7efe /noncore/styles
parentbeba0e73306815337bf04dee39502233595e9739 (diff)
downloadopie-a7e015198a8c5ad3b6e144a9032b059086253e00.zip
opie-a7e015198a8c5ad3b6e144a9032b059086253e00.tar.gz
opie-a7e015198a8c5ad3b6e144a9032b059086253e00.tar.bz2
Merge from BRANCH_1_0
Diffstat (limited to 'noncore/styles') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/styles/flat/flat.cpp128
-rw-r--r--noncore/styles/flat/flat.h6
2 files changed, 104 insertions, 30 deletions
diff --git a/noncore/styles/flat/flat.cpp b/noncore/styles/flat/flat.cpp
index b6635c5..24366f6 100644
--- a/noncore/styles/flat/flat.cpp
+++ b/noncore/styles/flat/flat.cpp
@@ -18,8 +18,7 @@
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include "flat.h" 21#include <qtopia/qpeapplication.h>
22#include <qpe/qpeapplication.h>
23#include <qpushbutton.h> 22#include <qpushbutton.h>
24#include <qtoolbutton.h> 23#include <qtoolbutton.h>
25#include <qpainter.h> 24#include <qpainter.h>
@@ -32,9 +31,13 @@
32#include <qtabbar.h> 31#include <qtabbar.h>
33#include <qspinbox.h> 32#include <qspinbox.h>
34#include <qlineedit.h> 33#include <qlineedit.h>
34#include <qmap.h>
35 35
36#define INCLUDE_MENUITEM_DEF 36#define INCLUDE_MENUITEM_DEF
37#include <qmenudata.h> 37#include <qmenudata.h>
38#include <qpopupmenu.h>
39
40#include "flat.h"
38 41
39#define QCOORDARRLEN(x) sizeof(x)/(sizeof(QCOORD)*2) 42#define QCOORDARRLEN(x) sizeof(x)/(sizeof(QCOORD)*2)
40 43
@@ -54,23 +57,37 @@ public:
54 FlatStylePrivate() : QObject() {} 57 FlatStylePrivate() : QObject() {}
55 58
56 bool eventFilter( QObject *o, QEvent *e ) { 59 bool eventFilter( QObject *o, QEvent *e ) {
57 if ( e->type() == QEvent::ParentPaletteChange && o->inherits( "QMenuBar" ) ) { 60 if ( e->type() == QEvent::ParentPaletteChange ) {
58 QWidget *w = (QWidget *)o; 61 if ( o->inherits( "QMenuBar" ) ) {
59 if ( w->parentWidget() ) { 62 QWidget *w = (QWidget *)o;
60 QPalette p = w->parentWidget()->palette(); 63 if ( w->parentWidget() ) {
61 QColorGroup a = p.active(); 64 QPalette p = w->parentWidget()->palette();
62 a.setColor( QColorGroup::Light, a.foreground() ); 65 QColorGroup a = p.active();
63 a.setColor( QColorGroup::Dark, a.foreground() ); 66 a.setColor( QColorGroup::Light, a.foreground() );
64 p.setActive( a ); 67 a.setColor( QColorGroup::Dark, a.foreground() );
65 p.setInactive( a ); 68 p.setActive( a );
66 w->setPalette( p ); 69 p.setInactive( a );
70 w->setPalette( p );
71 }
72 } else if ( o->inherits( "QHeader" ) ) {
73 QWidget *w = (QWidget *)o;
74 if ( w->parentWidget() ) {
75 QPalette p = w->parentWidget()->palette();
76 QColorGroup a = p.active();
77 a.setColor( QColorGroup::Light, a.button() );
78 p.setActive( a );
79 p.setInactive( a );
80 w->setPalette( p );
81 }
67 } 82 }
68 } 83 }
69 return FALSE; 84 return FALSE;
70 } 85 }
86
87 QMap<QFrame *,int> frameStyles;
71}; 88};
72 89
73FlatStyle::FlatStyle() : revItem(FALSE) 90FlatStyle::FlatStyle() : revItem(FALSE), fillBtnBorder(FALSE)
74{ 91{
75 setButtonMargin(3); 92 setButtonMargin(3);
76 setScrollBarExtent(13,13); 93 setScrollBarExtent(13,13);
@@ -101,7 +118,9 @@ void FlatStyle::polish( QWidget *w )
101{ 118{
102 if ( w->inherits( "QFrame" ) ) { 119 if ( w->inherits( "QFrame" ) ) {
103 QFrame *f = (QFrame *)w; 120 QFrame *f = (QFrame *)w;
104 if ( f->frameShape() != QFrame::NoFrame ) 121 if ( f->frameShape() == QFrame::HLine || f->frameShape() == QFrame::VLine )
122 f->setFrameShadow( QFrame::Plain );
123 else if ( f->frameShape() != QFrame::NoFrame )
105 f->setFrameShape( QFrame::StyledPanel ); 124 f->setFrameShape( QFrame::StyledPanel );
106 f->setLineWidth( 1 ); 125 f->setLineWidth( 1 );
107 } 126 }
@@ -117,20 +136,32 @@ void FlatStyle::polish( QWidget *w )
117 p.setInactive( a ); 136 p.setInactive( a );
118 w->setPalette( p ); 137 w->setPalette( p );
119 w->installEventFilter( d ); 138 w->installEventFilter( d );
139 } else if ( w->inherits( "QHeader" ) ) {
140 // make headers look flat
141 QPalette p = w->palette();
142 QColorGroup a = p.active();
143 a.setColor( QColorGroup::Light, a.button() );
144 p.setActive( a );
145 p.setInactive( a );
146 w->setPalette( p );
147 w->installEventFilter( d );
120 } 148 }
121} 149}
122 150
123void FlatStyle::unPolish( QWidget *w ) 151void FlatStyle::unPolish( QWidget *w )
124{ 152{
125 if ( w->inherits( "QFrame" ) ) { 153 if ( w->inherits("QFrame") ) {
126 QFrame *f = (QFrame *)w; 154 QFrame *f = (QFrame *)w;
127 if ( f->frameShape() != QFrame::NoFrame ) 155 if ( f->frameShape() == QFrame::HLine || f->frameShape() == QFrame::VLine ) {
156 f->setFrameShadow( QFrame::Sunken );
157 } else if ( f->frameShape() != QFrame::NoFrame ) {
128 f->setFrameShape( QFrame::StyledPanel ); 158 f->setFrameShape( QFrame::StyledPanel );
129 f->setLineWidth( 2 ); 159 f->setLineWidth( 2 );
160 }
130 } 161 }
131 if ( w->inherits( "QSpinBox" ) ) 162 if ( w->inherits("QSpinBox") )
132 ((SpinBoxHack*)w)->setFlatButtons( FALSE ); 163 ((SpinBoxHack*)w)->setFlatButtons( FALSE );
133 if ( w->inherits( "QMenuBar" ) ) { 164 if ( w->inherits("QMenuBar") || w->inherits("QHeader") ) {
134 w->unsetPalette(); 165 w->unsetPalette();
135 w->removeEventFilter( d ); 166 w->removeEventFilter( d );
136 } 167 }
@@ -138,7 +169,7 @@ void FlatStyle::unPolish( QWidget *w )
138 169
139int FlatStyle::defaultFrameWidth() const 170int FlatStyle::defaultFrameWidth() const
140{ 171{
141 return 1; 172 return 2;
142} 173}
143 174
144void FlatStyle::drawItem( QPainter *p, int x, int y, int w, int h, 175void FlatStyle::drawItem( QPainter *p, int x, int y, int w, int h,
@@ -171,16 +202,30 @@ void FlatStyle::drawButton( QPainter *p, int x, int y, int w, int h,
171{ 202{
172 QPen oldPen = p->pen(); 203 QPen oldPen = p->pen();
173 204
205 int x2 = x+w-1;
206 int y2 = y+h-1;
207
208 if ( fillBtnBorder && btnBg != cg.color(QColorGroup::Button) ) {
209 p->setPen( btnBg );
210 p->drawLine( x, y, x2, y );
211 p->drawLine( x, y2, x2, y2 );
212 p->drawLine( x, y+1, x, y2-1 );
213 p->drawLine( x2, y+1, x2, y2-1 );
214 p->fillRect( x+1, y+1, 3, 3, btnBg );
215 p->fillRect( x+1, y2-3, 3, 3, btnBg );
216 p->fillRect( x2-3, y2-3, 3, 3, btnBg );
217 p->fillRect( x2-3, y+1, 3, 3, btnBg );
218 p->fillRect( x+2, y+2, w-4, h-4, fill?(*fill):cg.brush(QColorGroup::Button) );
219 } else {
220 p->fillRect( x+1, y+1, w-2, h-2, fill?(*fill):cg.brush(QColorGroup::Button) );
221 }
222
174 if ( h >= 10 ) { 223 if ( h >= 10 ) {
175 x++; y++; 224 x++; y++;
225 x2--; y2--;
176 w -= 2; h -= 2; 226 w -= 2; h -= 2;
177 } 227 }
178 228
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() ); 229 p->setPen( cg.foreground() );
185 230
186 if ( h < 10 ) { 231 if ( h < 10 ) {
@@ -225,12 +270,23 @@ void FlatStyle::drawBevelButton( QPainter *p, int x, int y, int w, int h,
225void FlatStyle::drawToolButton( QPainter *p, int x, int y, int w, int h, 270void FlatStyle::drawToolButton( QPainter *p, int x, int y, int w, int h,
226 const QColorGroup &g, bool sunken, const QBrush* fill ) 271 const QColorGroup &g, bool sunken, const QBrush* fill )
227{ 272{
273 if ( p->device()->devType() == QInternal::Widget ) {
274 QWidget *w = (QWidget *)p->device();
275 if ( w->isA("QToolButton") ) {
276 QToolButton *btn = (QToolButton *)w;
277 if ( btn->parentWidget() ) {
278 btnBg = btn->parentWidget()->backgroundColor();
279 fillBtnBorder = TRUE;
280 }
281 }
282 }
228 QBrush fb( fill ? *fill : g.button() ); 283 QBrush fb( fill ? *fill : g.button() );
229 if ( sunken && fb == g.brush( QColorGroup::Button ) ) { 284 if ( sunken && fb == g.brush( QColorGroup::Button ) ) {
230 fb = g.buttonText(); 285 fb = g.buttonText();
231 revItem = TRUE;// ugh 286 revItem = TRUE;// ugh
232 } 287 }
233 drawButton( p, x, y, w, h, g, sunken, &fb ); 288 drawButton( p, x, y, w, h, g, sunken, &fb );
289 fillBtnBorder = FALSE;
234} 290}
235 291
236void FlatStyle::drawPushButton( QPushButton *btn, QPainter *p ) 292void FlatStyle::drawPushButton( QPushButton *btn, QPainter *p )
@@ -257,6 +313,11 @@ void FlatStyle::drawPushButton( QPushButton *btn, QPainter *p )
257 } 313 }
258 */ 314 */
259 315
316 if ( btn->parentWidget() ) {
317 btnBg = btn->parentWidget()->backgroundColor();
318 fillBtnBorder = TRUE;
319 }
320
260 bool clearButton = TRUE; 321 bool clearButton = TRUE;
261 if ( btn->isDown() ) { 322 if ( btn->isDown() ) {
262 drawButton( p, x1, y1, x2-x1+1, y2-y1+1, g, TRUE, 323 drawButton( p, x1, y1, x2-x1+1, y2-y1+1, g, TRUE,
@@ -283,6 +344,7 @@ void FlatStyle::drawPushButton( QPushButton *btn, QPainter *p )
283 } 344 }
284 */ 345 */
285 346
347 fillBtnBorder = FALSE;
286 if ( p->brush().style() != NoBrush ) 348 if ( p->brush().style() != NoBrush )
287 p->setBrush( NoBrush ); 349 p->setBrush( NoBrush );
288} 350}
@@ -589,7 +651,8 @@ void FlatStyle::drawScrollBarControls( QPainter* p, const QScrollBar* sb, int sl
589 p->setBrush( g.brush( QColorGroup::Mid ) ); 651 p->setBrush( g.brush( QColorGroup::Mid ) );
590 if ( controls & SubPage ) 652 if ( controls & SubPage )
591 p->drawRect( subPageR.x(), subPageR.y(), subPageR.width(), subPageR.height() ); 653 p->drawRect( subPageR.x(), subPageR.y(), subPageR.width(), subPageR.height() );
592 if ( controls & AddPage && addPageR.y() < addPageR.bottom() ) 654 if ( controls & AddPage && addPageR.y() < addPageR.bottom() &&
655 addPageR.x() < addPageR.right() )
593 p->drawRect( addPageR.x(), addPageR.y(), addPageR.width(), addPageR.height() ); 656 p->drawRect( addPageR.x(), addPageR.y(), addPageR.width(), addPageR.height() );
594 if ( controls & Slider ) { 657 if ( controls & Slider ) {
595 QPoint bo = p->brushOrigin(); 658 QPoint bo = p->brushOrigin();
@@ -784,6 +847,12 @@ static const int motifCheckMarkHMargin = 1; // horiz. margins of check mark
784 static const int windowsRightBorder= 8; // right border on windows 847 static const int windowsRightBorder= 8; // right border on windows
785static const int windowsCheckMarkWidth = 2; // checkmarks width on windows 848static const int windowsCheckMarkWidth = 2; // checkmarks width on windows
786 849
850void FlatStyle::polishPopupMenu ( QPopupMenu *m )
851{
852 QWindowsStyle::polishPopupMenu( m );
853 m->setLineWidth( 1 );
854}
855
787/*! \reimp 856/*! \reimp
788*/ 857*/
789int FlatStyle::extraPopupMenuItemWidth( bool checkable, int maxpmw, QMenuItem* mi, const QFontMetrics& /*fm*/ ) 858int FlatStyle::extraPopupMenuItemWidth( bool checkable, int maxpmw, QMenuItem* mi, const QFontMetrics& /*fm*/ )
@@ -1008,7 +1077,7 @@ QStyle *FlatStyleImpl::style()
1008 1077
1009QString FlatStyleImpl::name() const 1078QString FlatStyleImpl::name() const
1010{ 1079{
1011 return QString("Flat"); 1080 return qApp->translate("FlatStyle", "Flat", "Name of the style Flat");
1012} 1081}
1013 1082
1014QRESULT FlatStyleImpl::queryInterface( const QUuid &uuid, QUnknownInterface **iface ) 1083QRESULT FlatStyleImpl::queryInterface( const QUuid &uuid, QUnknownInterface **iface )
@@ -1018,9 +1087,10 @@ QRESULT FlatStyleImpl::queryInterface( const QUuid &uuid, QUnknownInterface **if
1018 *iface = this; 1087 *iface = this;
1019 else if ( uuid == IID_Style ) 1088 else if ( uuid == IID_Style )
1020 *iface = this; 1089 *iface = this;
1090 else
1091 return QS_FALSE;
1021 1092
1022 if ( *iface ) 1093 (*iface)->addRef();
1023 (*iface)->addRef();
1024 return QS_OK; 1094 return QS_OK;
1025} 1095}
1026 1096
diff --git a/noncore/styles/flat/flat.h b/noncore/styles/flat/flat.h
index e446800..ebea95b 100644
--- a/noncore/styles/flat/flat.h
+++ b/noncore/styles/flat/flat.h
@@ -21,12 +21,13 @@
21#ifndef FLATSTYLE_H 21#ifndef FLATSTYLE_H
22#define FLATSTYLE_H 22#define FLATSTYLE_H
23 23
24#include <qcolor.h>
24#include <qwindowsstyle.h> 25#include <qwindowsstyle.h>
25#include <qpe/styleinterface.h> 26#include <qpe/styleinterface.h>
26 27
27class FlatStylePrivate; 28class FlatStylePrivate;
28 29
29class Q_EXPORT FlatStyle : public QWindowsStyle 30class FlatStyle : public QWindowsStyle
30{ 31{
31public: 32public:
32 FlatStyle(); 33 FlatStyle();
@@ -73,6 +74,7 @@ public:
73 const QColorGroup& , QCOORD c, Orientation orient ); 74 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 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 void drawTab( QPainter *, const QTabBar *, QTab *, bool selected );
77 void polishPopupMenu ( QPopupMenu * );
76 int extraPopupMenuItemWidth( bool checkable, int maxpmw, QMenuItem*, const QFontMetrics& ); 78 int extraPopupMenuItemWidth( bool checkable, int maxpmw, QMenuItem*, const QFontMetrics& );
77 int popupMenuItemHeight( bool checkable, QMenuItem*, const QFontMetrics& ); 79 int popupMenuItemHeight( bool checkable, QMenuItem*, const QFontMetrics& );
78 void drawPopupMenuItem( QPainter* p, bool checkable, int maxpmw, int tab, QMenuItem* mi, 80 void drawPopupMenuItem( QPainter* p, bool checkable, int maxpmw, int tab, QMenuItem* mi,
@@ -86,6 +88,8 @@ public:
86private: 88private:
87 FlatStylePrivate *d; 89 FlatStylePrivate *d;
88 bool revItem; 90 bool revItem;
91 bool fillBtnBorder;
92 QColor btnBg;
89 // Disabled copy constructor and operator= 93 // Disabled copy constructor and operator=
90#if defined(Q_DISABLE_COPY) 94#if defined(Q_DISABLE_COPY)
91 FlatStyle( const FlatStyle & ); 95 FlatStyle( const FlatStyle & );