author | sandman <sandman> | 2002-11-21 19:54:25 (UTC) |
---|---|---|
committer | sandman <sandman> | 2002-11-21 19:54:25 (UTC) |
commit | 6d302b82aab909da59852d99a31bcc7726ba9f34 (patch) (side-by-side diff) | |
tree | e090ba7fcd96afe5fd74e7451f2c59b64f0eb369 | |
parent | 440f1d4d439c83368a855355cdceda43660137f2 (diff) | |
download | opie-6d302b82aab909da59852d99a31bcc7726ba9f34.zip opie-6d302b82aab909da59852d99a31bcc7726ba9f34.tar.gz opie-6d302b82aab909da59852d99a31bcc7726ba9f34.tar.bz2 |
- progress bars are now also themed (same hack/workaround, that is used in
liquid)
- some speed optimizations
-rw-r--r-- | noncore/styles/theme/othemestyle.cpp | 126 | ||||
-rw-r--r-- | noncore/styles/theme/othemestyle.h | 16 |
2 files changed, 124 insertions, 18 deletions
diff --git a/noncore/styles/theme/othemestyle.cpp b/noncore/styles/theme/othemestyle.cpp index 8c7a71b..a820efb 100644 --- a/noncore/styles/theme/othemestyle.cpp +++ b/noncore/styles/theme/othemestyle.cpp @@ -20,34 +20,96 @@ #include "othemebase.h" #include <qpe/qpeapplication.h> #include <qbitmap.h> #define INCLUDE_MENUITEM_DEF #include <qmenudata.h> #include <qpopupmenu.h> #include <qtabbar.h> #include <qglobal.h> +#include <qprogressbar.h> #include <limits.h> #include <stdio.h> +typedef void (QStyle::*QDrawMenuBarItemImpl) (QPainter *, int, int, int, int, QMenuItem *, + QColorGroup &, bool, bool); + +QDrawMenuBarItemImpl qt_set_draw_menu_bar_impl(QDrawMenuBarItemImpl impl); + + +/* !! HACK !! Beware + * + * TT forgot to make the QProgressBar widget styleable in Qt 2.x + * So the only way to customize the drawing, is to intercept the + * paint event - since we have to use protected functions, we need + * to derive a "hack" class from QProgressBar and do the painting + * in there. + * + * - sandman + */ + +class HackProgressBar : public QProgressBar { +public: + HackProgressBar ( ); + + void paint ( QPaintEvent *event, OThemeStyle *style ) + { + QPainter p( this ); + + if ( !contentsRect().contains( event->rect() ) ) { + p.save(); + p.setClipRegion( event->region().intersect(frameRect()) ); + drawFrame( &p); + p.restore(); + } + if ( event->rect().intersects( contentsRect() )) { + p.setClipRegion( event->region().intersect( contentsRect() ) ); + + int x, y, w, h; + contentsRect ( ). rect ( &x, &y, &w, &h ); + + int prog = progress ( ); + int total = totalSteps ( ); + if ( prog < 0 ) + prog = 0; + if ( total <= 0 ) + total = 1; + int perc = prog * 100 / total; + + style-> drawProgressBar ( &p, x, y, w, h, colorGroup ( ), perc ); + + if ( progress ( ) >= 0 && totalSteps ( ) > 0 ) { + QString pstr; + pstr. sprintf ( "%d%%", 100 * progress()/totalSteps ()); + p. setPen ( colorGroup().text());//g.highlightedText ( )); + p. drawText (x,y,w-1,h-1,AlignCenter,pstr); + } + } + } +}; + + #define QCOORDARRLEN(x) sizeof(x)/(sizeof(QCOORD)*2) OThemeStyle::OThemeStyle( const QString &configFile ) : OThemeBase( configFile ) { setScrollBarExtent( getSBExtent(), getSBExtent() ); setButtonDefaultIndicatorWidth( 0 ); // We REALLY should support one, see drawPushButton() below! } OThemeStyle::~OThemeStyle() {} void OThemeStyle::polish( QApplication * /*app*/ ) -{} +{ + qt_set_draw_menu_bar_impl((QDrawMenuBarItemImpl) &OThemeStyle::drawMenuBarItem); +} + void OThemeStyle::polish( QPalette &p ) { oldPalette = p; QColor bg = oldPalette. color ( QPalette::Normal, QColorGroup::Background ); if ( bgcolor. isValid ( )) @@ -74,16 +136,17 @@ void OThemeStyle::polish( QPalette &p ) if ( winbgcolor. isValid ( )) p. setColor ( QColorGroup::Base, winbgcolor ); } void OThemeStyle::unPolish( QApplication *app ) { + qt_set_draw_menu_bar_impl ( 0 ); app->setPalette( oldPalette, true ); } void OThemeStyle::polish( QWidget *w ) { if ( !w->isTopLevel() ) { if ( w->inherits( "QGroupBox" ) || w->inherits( "QTabWidget" ) ) { @@ -107,43 +170,46 @@ void OThemeStyle::polish( QWidget *w ) newPal.setNormal( *colorGroup( newPal.normal(), MenuItem ) ); newPal.setDisabled( *colorGroup( newPal.normal(), MenuItem ) ); } if ( isColor( MenuItemDown ) ) newPal.setActive( *colorGroup( newPal.active(), MenuItemDown ) ); w->setPalette( newPal ); } } - if ( w->inherits( "QCheckBox" ) ) { + else if ( w->inherits( "QCheckBox" ) ) { if ( isColor( IndicatorOff ) || isColor( IndicatorOn ) ) { QPalette newPal( w->palette() ); w->setPalettePropagation( QWidget::SamePalette ); if ( isColor( IndicatorOff ) ) { newPal.setNormal( *colorGroup( newPal.normal(), IndicatorOff ) ); newPal.setDisabled( *colorGroup( newPal.normal(), IndicatorOff ) ); } if ( isColor( IndicatorOn ) ) newPal.setActive( *colorGroup( newPal.active(), IndicatorOn ) ); w->setPalette( newPal ); } } - if ( w->inherits( "QRadioButton" ) ) { + else if ( w->inherits( "QRadioButton" ) ) { if ( isColor( ExIndicatorOff ) || isColor( ExIndicatorOn ) ) { QPalette newPal( w->palette() ); w->setPalettePropagation( QWidget::SamePalette ); if ( isColor( ExIndicatorOff ) ) { newPal.setNormal( *colorGroup( newPal.normal(), ExIndicatorOff ) ); newPal.setDisabled( *colorGroup( newPal.normal(), ExIndicatorOff ) ); } if ( isColor( ExIndicatorOn ) ) newPal.setActive( *colorGroup( newPal.active(), ExIndicatorOn ) ); w->setPalette( newPal ); } } + else if ( w-> inherits ( "QProgressBar" ) ) { + w-> installEventFilter ( this ); + } } void OThemeStyle::unPolish( QWidget* w ) { if ( !w->isTopLevel() ) { if ( w->inherits( "QGroupBox" ) || w->inherits( "QTabWidget" ) ) { w->setAutoMask( FALSE ); @@ -154,20 +220,34 @@ void OThemeStyle::unPolish( QWidget* w ) || w->inherits( "QButton" ) || w->inherits( "QProgressBar" ) ) { w->setBackgroundOrigin( QWidget::WidgetOrigin ); } } if ( w->inherits( "QPopupMenu" ) ) w->unsetPalette(); - if ( w->inherits( "QCheckBox" ) ) + else if ( w->inherits( "QCheckBox" ) ) w->unsetPalette(); - if ( w->inherits( "QRadioButton" ) ) + else if ( w->inherits( "QRadioButton" ) ) w->unsetPalette(); + else if ( w-> inherits ( "QProgressBar" ) ) + w-> removeEventFilter ( this ); +} + +bool OThemeStyle::eventFilter ( QObject *obj, QEvent *ev ) +{ + // only QProgressBar so far + + if ( ev-> type ( ) == QEvent::Paint ) { + HackProgressBar *pb = (HackProgressBar *) obj; + pb-> paint ((QPaintEvent *) ev, this ); + return true; + } + return false; } void OThemeStyle::drawBaseButton( QPainter *p, int x, int y, int w, int h, const QColorGroup &g, bool sunken, bool rounded, WidgetType type, const QBrush * ) { int offset = borderPixmap( type ) ? 0 : decoWidth( type ); QPen oldPen = p->pen(); @@ -1342,33 +1422,59 @@ void OThemeStyle::drawFocusRect( QPainter *p, const QRect &r, #if 0 void OThemeStyle::drawKMenuBar( QPainter *p, int x, int y, int w, int h, const QColorGroup &g, bool, QBrush * ) { drawBaseButton( p, x, y, w, h, *colorGroup( g, MenuBar ), false, false, MenuBar ); } +#endif -void OThemeStyle::drawKMenuItem( QPainter *p, int x, int y, int w, int h, - const QColorGroup &g, bool active, - QMenuItem *mi, QBrush * ) +void OThemeStyle::drawMenuBarItem( QPainter *p, int x, int y, int w, int h, + QMenuItem *mi, const QColorGroup &g, + bool /*enabled*/, bool active ) { + if(active){ + x -= 2; // Bug in Qt/E + y -= 2; + w += 2; + h += 2; + } + const QColorGroup * cg = colorGroup( g, active ? MenuBarItem : MenuBar ); QColor btext = cg->buttonText(); if ( active ) drawBaseButton( p, x, y, w, h, *cg, false, false, MenuBarItem ); //qDrawShadePanel(p, x, y, w, h, *cg, false, 1); drawItem( p, x, y, w, h, AlignCenter | ShowPrefix | DontClip | SingleLine, - *cg, mi->isEnabled(), mi->pixmap(), mi->text(), + *cg, mi-> isEnabled ( ), mi->pixmap(), mi->text(), -1, &btext ); - ; } + + +void OThemeStyle::drawProgressBar ( QPainter *p, int x, int y, int w, int h, const QColorGroup &g, int percent ) +{ + const QColorGroup * cg = colorGroup( g, ProgressBg ); + QBrush bg; + bg.setColor( cg->color( QColorGroup::Background ) ); + if ( isPixmap( ProgressBg ) ) + bg.setPixmap( *uncached( ProgressBg ) ); + + int pw = w * percent / 100; + + p-> fillRect ( x + pw, y, w - pw, h, bg ); // ### TODO + + drawBaseButton( p, x, y, pw, h, *cg, false, false, ProgressBar ); +} + +#if 0 + void OThemeStyle::drawKProgressBlock( QPainter *p, int x, int y, int w, int h, const QColorGroup &g, QBrush * ) { drawBaseButton( p, x, y, w, h, *colorGroup( g, ProgressBar ), false, false, ProgressBar ); } void OThemeStyle::getKProgressBackground( const QColorGroup &g, QBrush &bg ) diff --git a/noncore/styles/theme/othemestyle.h b/noncore/styles/theme/othemestyle.h index 52445c4..406b35b 100644 --- a/noncore/styles/theme/othemestyle.h +++ b/noncore/styles/theme/othemestyle.h @@ -21,16 +21,18 @@ #include "othemebase.h" #include <qwindowdefs.h> #include <qobject.h> #include <qbutton.h> #include <qpushbutton.h> #include <qscrollbar.h> #include <qstring.h> +class QProgressBar; + /** * KDE themed styles. * * It provides methods for * drawing most widgets with user-specified borders, highlights, pixmaps, * etc. It also handles various other settings such as scrollbar types, * rounded buttons, and shading types. For a full list of parameters this @@ -58,16 +60,18 @@ public: */ virtual void polish( QApplication *app ); virtual void unPolish( QApplication* ); /// @internal // to make it possible for derived classes to overload this function virtual void polish( QPalette& pal ); + virtual bool eventFilter ( QObject *obj, QEvent *ev ); + /** * This is a convenience method for drawing widgets with * borders, highlights, pixmaps, colors, etc... * You specify the widget type and it will draw it according to the * config file settings. * * @param p The QPainter to draw on. * @param g The color group to use. @@ -307,22 +311,19 @@ public: void drawKMenuBar( QPainter *p, int x, int y, int w, int h, const QColorGroup &g, bool macMode, QBrush *fill = NULL ); #endif /** * Draw a menubar item. */ -#if 0 - - virtual void drawKMenuItem( QPainter *p, int x, int y, int w, int h, - const QColorGroup &g, bool active, - QMenuItem *item, QBrush *fill = NULL ); -#endif + virtual void drawMenuBarItem( QPainter *p, int x, int y, int w, int h, + QMenuItem *item, const QColorGroup &g, + bool enabled, bool active ); /** * Return the width of the splitter as specified in the config file. */ virtual int splitterWidth() const; /** * Draw a splitter widget. */ virtual void drawSplitter( QPainter *p, int x, int y, int w, int h, @@ -347,18 +348,17 @@ public: /** * Draw the focus rectangle. */ void drawFocusRect( QPainter *p, const QRect &r, const QColorGroup &g, const QColor *c = 0, bool atBorder = false ); /** * Draw a @ref KProgess bar. */ - // virtual void drawKProgressBlock(QPainter *p, int x, int y, int w, int h, - // const QColorGroup &g, QBrush *fill); + virtual void drawProgressBar (QPainter *, int , int , int , int , const QColorGroup &, int ); /** * Return the background for @ref KProgress. */ // virtual void getKProgressBackground(const QColorGroup &g, QBrush &bg); virtual void tabbarMetrics( const QTabBar*, int&, int&, int& ); virtual void drawTab( QPainter*, const QTabBar*, QTab*, bool selected ); virtual void drawTabMask( QPainter*, const QTabBar*, QTab*, bool selected ); protected: |