author | kergoth <kergoth> | 2003-08-09 17:14:54 (UTC) |
---|---|---|
committer | kergoth <kergoth> | 2003-08-09 17:14:54 (UTC) |
commit | a7e015198a8c5ad3b6e144a9032b059086253e00 (patch) (side-by-side diff) | |
tree | b712b6f11310d88744fe393a92b3160b741a7efe /noncore/styles/flat | |
parent | beba0e73306815337bf04dee39502233595e9739 (diff) | |
download | opie-a7e015198a8c5ad3b6e144a9032b059086253e00.zip opie-a7e015198a8c5ad3b6e144a9032b059086253e00.tar.gz opie-a7e015198a8c5ad3b6e144a9032b059086253e00.tar.bz2 |
Merge from BRANCH_1_0
-rw-r--r-- | noncore/styles/flat/flat.cpp | 102 | ||||
-rw-r--r-- | noncore/styles/flat/flat.h | 6 |
2 files changed, 91 insertions, 17 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 @@ -15,29 +15,32 @@ ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ -#include "flat.h" -#include <qpe/qpeapplication.h> +#include <qtopia/qpeapplication.h> #include <qpushbutton.h> #include <qtoolbutton.h> #include <qpainter.h> #include <qfontmetrics.h> #include <qpalette.h> #include <qdrawutil.h> #include <qscrollbar.h> #include <qbutton.h> #include <qframe.h> #include <qtabbar.h> #include <qspinbox.h> #include <qlineedit.h> +#include <qmap.h> #define INCLUDE_MENUITEM_DEF #include <qmenudata.h> +#include <qpopupmenu.h> + +#include "flat.h" #define QCOORDARRLEN(x) sizeof(x)/(sizeof(QCOORD)*2) class SpinBoxHack : public QSpinBox { public: @@ -51,29 +54,43 @@ class FlatStylePrivate : public QObject { Q_OBJECT public: FlatStylePrivate() : QObject() {} bool eventFilter( QObject *o, QEvent *e ) { - if ( e->type() == QEvent::ParentPaletteChange && o->inherits( "QMenuBar" ) ) { + if ( e->type() == QEvent::ParentPaletteChange ) { + if ( o->inherits( "QMenuBar" ) ) { QWidget *w = (QWidget *)o; if ( w->parentWidget() ) { QPalette p = w->parentWidget()->palette(); QColorGroup a = p.active(); a.setColor( QColorGroup::Light, a.foreground() ); a.setColor( QColorGroup::Dark, a.foreground() ); p.setActive( a ); p.setInactive( a ); w->setPalette( p ); } + } else if ( o->inherits( "QHeader" ) ) { + QWidget *w = (QWidget *)o; + if ( w->parentWidget() ) { + QPalette p = w->parentWidget()->palette(); + QColorGroup a = p.active(); + a.setColor( QColorGroup::Light, a.button() ); + p.setActive( a ); + p.setInactive( a ); + w->setPalette( p ); + } + } } return FALSE; } + + QMap<QFrame *,int> frameStyles; }; -FlatStyle::FlatStyle() : revItem(FALSE) +FlatStyle::FlatStyle() : revItem(FALSE), fillBtnBorder(FALSE) { setButtonMargin(3); setScrollBarExtent(13,13); setButtonDefaultIndicatorWidth(0); d = new FlatStylePrivate; } @@ -98,13 +115,15 @@ void FlatStyle::polish ( QPalette & ) } void FlatStyle::polish( QWidget *w ) { if ( w->inherits( "QFrame" ) ) { QFrame *f = (QFrame *)w; - if ( f->frameShape() != QFrame::NoFrame ) + if ( f->frameShape() == QFrame::HLine || f->frameShape() == QFrame::VLine ) + f->setFrameShadow( QFrame::Plain ); + else if ( f->frameShape() != QFrame::NoFrame ) f->setFrameShape( QFrame::StyledPanel ); f->setLineWidth( 1 ); } if ( w->inherits( "QSpinBox" ) ) ((SpinBoxHack*)w)->setFlatButtons( TRUE ); if ( w->inherits( "QMenuBar" ) ) { @@ -114,34 +133,46 @@ void FlatStyle::polish( QWidget *w ) a.setColor( QColorGroup::Light, a.foreground() ); a.setColor( QColorGroup::Dark, a.foreground() ); p.setActive( a ); p.setInactive( a ); w->setPalette( p ); w->installEventFilter( d ); + } else if ( w->inherits( "QHeader" ) ) { + // make headers look flat + QPalette p = w->palette(); + QColorGroup a = p.active(); + a.setColor( QColorGroup::Light, a.button() ); + p.setActive( a ); + p.setInactive( a ); + w->setPalette( p ); + w->installEventFilter( d ); } } void FlatStyle::unPolish( QWidget *w ) { if ( w->inherits( "QFrame" ) ) { QFrame *f = (QFrame *)w; - if ( f->frameShape() != QFrame::NoFrame ) + if ( f->frameShape() == QFrame::HLine || f->frameShape() == QFrame::VLine ) { + f->setFrameShadow( QFrame::Sunken ); + } else if ( f->frameShape() != QFrame::NoFrame ) { f->setFrameShape( QFrame::StyledPanel ); f->setLineWidth( 2 ); } + } if ( w->inherits( "QSpinBox" ) ) ((SpinBoxHack*)w)->setFlatButtons( FALSE ); - if ( w->inherits( "QMenuBar" ) ) { + if ( w->inherits("QMenuBar") || w->inherits("QHeader") ) { w->unsetPalette(); w->removeEventFilter( d ); } } int FlatStyle::defaultFrameWidth() const { - return 1; + return 2; } void FlatStyle::drawItem( QPainter *p, int x, int y, int w, int h, int flags, const QColorGroup &g, bool enabled, const QPixmap *pixmap, const QString& text, int len, const QColor* penColor ) @@ -168,22 +199,36 @@ void FlatStyle::drawPanel ( QPainter * p, int x, int y, int w, int h, void FlatStyle::drawButton( QPainter *p, int x, int y, int w, int h, const QColorGroup &cg, bool /*sunken*/, const QBrush* fill ) { QPen oldPen = p->pen(); + int x2 = x+w-1; + int y2 = y+h-1; + + if ( fillBtnBorder && btnBg != cg.color(QColorGroup::Button) ) { + p->setPen( btnBg ); + p->drawLine( x, y, x2, y ); + p->drawLine( x, y2, x2, y2 ); + p->drawLine( x, y+1, x, y2-1 ); + p->drawLine( x2, y+1, x2, y2-1 ); + p->fillRect( x+1, y+1, 3, 3, btnBg ); + p->fillRect( x+1, y2-3, 3, 3, btnBg ); + p->fillRect( x2-3, y2-3, 3, 3, btnBg ); + p->fillRect( x2-3, y+1, 3, 3, btnBg ); + p->fillRect( x+2, y+2, w-4, h-4, fill?(*fill):cg.brush(QColorGroup::Button) ); + } else { + p->fillRect( x+1, y+1, w-2, h-2, fill?(*fill):cg.brush(QColorGroup::Button) ); + } + if ( h >= 10 ) { x++; y++; + x2--; y2--; w -= 2; h -= 2; } - p->fillRect( x+1, y+1, w-2, h-2, fill?(*fill):cg.brush(QColorGroup::Button) ); - - int x2 = x+w-1; - int y2 = y+h-1; - p->setPen( cg.foreground() ); if ( h < 10 ) { p->setBrush( NoBrush ); p->drawRect( x, y, w, h ); } else { @@ -222,18 +267,29 @@ void FlatStyle::drawBevelButton( QPainter *p, int x, int y, int w, int h, p->drawRect( x, y, w, h ); } void FlatStyle::drawToolButton( QPainter *p, int x, int y, int w, int h, const QColorGroup &g, bool sunken, const QBrush* fill ) { + if ( p->device()->devType() == QInternal::Widget ) { + QWidget *w = (QWidget *)p->device(); + if ( w->isA("QToolButton") ) { + QToolButton *btn = (QToolButton *)w; + if ( btn->parentWidget() ) { + btnBg = btn->parentWidget()->backgroundColor(); + fillBtnBorder = TRUE; + } + } + } QBrush fb( fill ? *fill : g.button() ); if ( sunken && fb == g.brush( QColorGroup::Button ) ) { fb = g.buttonText(); revItem = TRUE; // ugh } drawButton( p, x, y, w, h, g, sunken, &fb ); + fillBtnBorder = FALSE; } void FlatStyle::drawPushButton( QPushButton *btn, QPainter *p ) { QColorGroup g = btn->colorGroup(); int x1, y1, x2, y2; @@ -254,12 +310,17 @@ void FlatStyle::drawPushButton( QPushButton *btn, QPainter *p ) y1 += diw; x2 -= diw; y2 -= diw; } */ + if ( btn->parentWidget() ) { + btnBg = btn->parentWidget()->backgroundColor(); + fillBtnBorder = TRUE; + } + bool clearButton = TRUE; if ( btn->isDown() ) { drawButton( p, x1, y1, x2-x1+1, y2-y1+1, g, TRUE, &g.brush( QColorGroup::Text ) ); } else { if ( btn->isToggleButton() && btn->isOn() && btn->isEnabled() ) { @@ -280,12 +341,13 @@ void FlatStyle::drawPushButton( QPushButton *btn, QPainter *p ) g.brush( QColorGroup::Button ) ); if (btn->isDown()) p->setBrushOrigin(p->brushOrigin() - QPoint(1,1)); } */ + fillBtnBorder = FALSE; if ( p->brush().style() != NoBrush ) p->setBrush( NoBrush ); } void FlatStyle::drawPushButtonLabel( QPushButton *btn, QPainter *p ) { @@ -586,13 +648,14 @@ void FlatStyle::drawScrollBarControls( QPainter* p, const QScrollBar* sb, int sl p->setPen( g.foreground() ); p->setBrush( g.brush( QColorGroup::Mid ) ); if ( controls & SubPage ) p->drawRect( subPageR.x(), subPageR.y(), subPageR.width(), subPageR.height() ); - if ( controls & AddPage && addPageR.y() < addPageR.bottom() ) + if ( controls & AddPage && addPageR.y() < addPageR.bottom() && + addPageR.x() < addPageR.right() ) p->drawRect( addPageR.x(), addPageR.y(), addPageR.width(), addPageR.height() ); if ( controls & Slider ) { QPoint bo = p->brushOrigin(); p->setBrushOrigin(sliderR.topLeft()); p->setPen( g.foreground() ); p->setBrush( g.button() ); @@ -781,12 +844,18 @@ static const int motifItemVMargin = 2; // menu item ver text margin static const int motifArrowHMargin = 0; // arrow horizontal margin static const int motifTabSpacing = 12; // space between text and tab static const int motifCheckMarkHMargin = 1; // horiz. margins of check mark static const int windowsRightBorder = 8; // right border on windows static const int windowsCheckMarkWidth = 2; // checkmarks width on windows +void FlatStyle::polishPopupMenu ( QPopupMenu *m ) +{ + QWindowsStyle::polishPopupMenu( m ); + m->setLineWidth( 1 ); +} + /*! \reimp */ int FlatStyle::extraPopupMenuItemWidth( bool checkable, int maxpmw, QMenuItem* mi, const QFontMetrics& /*fm*/ ) { #ifndef QT_NO_MENUDATA int w = 2*motifItemHMargin + 2*motifItemFrame; // a little bit of border can never harm @@ -1005,24 +1074,25 @@ QStyle *FlatStyleImpl::style() flat = new FlatStyle(); return flat; } QString FlatStyleImpl::name() const { - return QString("Flat"); + return qApp->translate("FlatStyle", "Flat", "Name of the style Flat"); } QRESULT FlatStyleImpl::queryInterface( const QUuid &uuid, QUnknownInterface **iface ) { *iface = 0; if ( uuid == IID_QUnknown ) *iface = this; else if ( uuid == IID_Style ) *iface = this; + else + return QS_FALSE; - if ( *iface ) (*iface)->addRef(); return QS_OK; } Q_EXPORT_INTERFACE() { 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 @@ -18,18 +18,19 @@ ** **********************************************************************/ #ifndef FLATSTYLE_H #define FLATSTYLE_H +#include <qcolor.h> #include <qwindowsstyle.h> #include <qpe/styleinterface.h> class FlatStylePrivate; -class Q_EXPORT FlatStyle : public QWindowsStyle +class FlatStyle : public QWindowsStyle { public: FlatStyle(); virtual ~FlatStyle(); virtual void polish( QPalette &p ); virtual void polish( QWidget *w ); @@ -70,12 +71,13 @@ public: void drawSliderMask( QPainter *p, int x, int y, int w, int h, Orientation, bool tickAbove, bool tickBelow ); void drawSliderGrooveMask( QPainter *p, int x, int y, int w, int h, const QColorGroup& , QCOORD c, Orientation orient ); void drawSliderGroove ( QPainter * p, int x, int y, int w, int h, const QColorGroup & g, QCOORD c, Orientation ); void drawTab( QPainter *, const QTabBar *, QTab *, bool selected ); + void polishPopupMenu ( QPopupMenu * ); int extraPopupMenuItemWidth( bool checkable, int maxpmw, QMenuItem*, const QFontMetrics& ); int popupMenuItemHeight( bool checkable, QMenuItem*, const QFontMetrics& ); void drawPopupMenuItem( QPainter* p, bool checkable, int maxpmw, int tab, QMenuItem* mi, const QPalette& pal, bool act, bool enabled, int x, int y, int w, int h); @@ -83,12 +85,14 @@ public: QSize scrollBarExtent() const; void getButtonShift( int &x, int &y ); private: FlatStylePrivate *d; bool revItem; + bool fillBtnBorder; + QColor btnBg; // Disabled copy constructor and operator= #if defined(Q_DISABLE_COPY) FlatStyle( const FlatStyle & ); FlatStyle& operator=( const FlatStyle & ); #endif }; |