summaryrefslogtreecommitdiff
authorsandman <sandman>2002-11-21 19:54:25 (UTC)
committer sandman <sandman>2002-11-21 19:54:25 (UTC)
commit6d302b82aab909da59852d99a31bcc7726ba9f34 (patch) (side-by-side diff)
treee090ba7fcd96afe5fd74e7451f2c59b64f0eb369
parent440f1d4d439c83368a855355cdceda43660137f2 (diff)
downloadopie-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
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/styles/theme/othemestyle.cpp124
-rw-r--r--noncore/styles/theme/othemestyle.h16
2 files changed, 123 insertions, 17 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
@@ -1,261 +1,341 @@
/* This file is part of the KDE libraries
Copyright (C) 1999 Daniel M. Duley <mosfet@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2 as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include "othemestyle.h"
#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 ( ))
bg = bgcolor;
if ( isColor ( Background ))
bg = colorGroup ( oldPalette. active ( ), Background )-> background ( );
p = QPalette ( bg, bg );
if ( isPixmap( Background ) )
p. setBrush ( QColorGroup::Background, QBrush ( bg, *uncached ( Background )));
if ( fgcolor. isValid ( )) {
p. setColor ( QColorGroup::Foreground, fgcolor );
p. setColor ( QColorGroup::ButtonText, fgcolor );
}
if ( selfgcolor. isValid ( ))
p. setColor ( QColorGroup::HighlightedText, selfgcolor );
if ( selbgcolor. isValid ( ))
p. setColor ( QColorGroup::Highlight, selbgcolor );
if ( winfgcolor. isValid ( ))
p. setColor ( QColorGroup::Text, winfgcolor );
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" ) ) {
w->setAutoMask( TRUE );
return ;
}
if ( w->inherits( "QLabel" )
|| w->inherits( "QSlider" )
|| w->inherits( "QButton" )
|| w->inherits( "QProgressBar" )
) {
w->setBackgroundOrigin( QWidget::ParentOrigin );
}
}
if ( w->inherits( "QPopupMenu" ) ) {
popupPalette = w->palette();
if ( isColor( MenuItem ) || isColor( MenuItemDown ) ) {
QPalette newPal( w->palette() );
w->setPalettePropagation( QWidget::SamePalette );
if ( isColor( MenuItem ) ) {
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 );
return ;
}
if ( w->inherits( "QLabel" )
|| w->inherits( "QSlider" )
|| 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();
// handle reverse bevel here since it uses decowidth differently
if ( gradientHint( type ) == GrReverseBevel ) {
int i;
bitBlt( p->device(), x, y, scalePixmap( w, h, type ), 0, 0, w, h,
Qt::CopyROP, true );
p->setPen( g.text() );
for ( i = 0; i < borderWidth( type ); ++i, ++x, ++y, w -= 2, h -= 2 )
p->drawRect( x, y, w, h );
}
// same with KDE style borders
else if ( !borderPixmap( type ) && shade() == KDE ) {
qDrawWinButton( p, x, y, w, h, g, sunken );
if ( isPixmap( type ) )
p->drawTiledPixmap( x + 4, y + 4, w - 6, h - 6,
*scalePixmap( w - 6, h - 6,
type ) );
else
p->fillRect( x + 4, y + 4, w - 6, h - offset * 6,
g.brush( QColorGroup::Button ) );
}
else {
if ( ( w - offset * 2 ) > 0 && ( h - offset * 2 ) > 0 ) {
if ( isPixmap( type ) )
if ( rounded )
p->drawTiledPixmap( x, y, w, h, *scalePixmap( w, h, type ) );
else
p->drawTiledPixmap( x + offset, y + offset, w - offset * 2,
h - offset * 2,
*scalePixmap( w - offset * 2, h - offset * 2,
type ) );
else
p->fillRect( x + offset, y + offset, w - offset * 2, h - offset * 2,
g.brush( QColorGroup::Button ) );
}
if ( borderPixmap( type ) )
bitBlt( p->device(), x, y, scaleBorder( w, h, type ), 0, 0, w, h,
Qt::CopyROP, false );
else
drawShade( p, x, y, w, h, g, sunken, rounded,
highlightWidth( type ), borderWidth( type ), shade() );
}
p->setPen( oldPen );
}
void OThemeStyle::drawButton( QPainter *p, int x, int y, int w, int h,
const QColorGroup &g, bool sunken,
const QBrush *fill )
{
drawBaseButton( p, x, y, w, h, g, sunken, roundButton(), sunken ?
PushButtonDown : PushButton, fill );
}
void OThemeStyle::drawPushButton( QPushButton* btn, QPainter *p )
{
bool sunken = btn->isOn() || btn->isDown();
int diw = buttonDefaultIndicatorWidth();
drawBaseButton( p, diw, diw, btn->width() - 2 * diw, btn->height() - 2 * diw,
*colorGroup( btn->colorGroup(), sunken ? PushButtonDown :
PushButton ), sunken, roundButton(),
sunken ? PushButtonDown : PushButton, NULL );
// TODO if diw, draw fancy default button indicator
}
void OThemeStyle::drawBaseMask( QPainter *p, int x, int y, int w, int h,
bool round )
{
// round edge fills
static const QCOORD btm_left_fill[] = {
0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 0, 1, 1, 1, 2, 1, 3, 1, 4, 1,
1, 2, 2, 2, 3, 2, 4, 2, 2, 3, 3, 3, 4, 3, 3, 4, 4, 4
};
static const QCOORD btm_right_fill[] = {
0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 0, 1, 1, 1, 2, 1, 3, 1, 4,
1, 0, 2, 1, 2, 2, 2, 3, 2, 0, 3, 1, 3, 2, 3, 0, 4, 1, 4
};
static const QCOORD top_left_fill[] = {
3, 0, 4, 0, 2, 1, 3, 1, 4, 1, 1, 2, 2, 2, 3, 2, 4, 2, 0, 3,
1, 3, 2, 3, 3, 3, 4, 3, 0, 4, 1, 4, 2, 4, 3, 4, 4, 4
};
static const QCOORD top_right_fill[] = {
0, 0, 1, 0, 0, 1, 1, 1, 2, 1, 0, 2, 1, 2, 2, 2, 3, 2, 0,
3, 1, 3, 2, 3, 3, 3, 4, 3, 0, 4, 1, 4, 2, 4, 3, 4, 4, 4
};
@@ -1254,209 +1334,235 @@ void OThemeStyle::drawPopupMenuItem( QPainter* p, bool checkable, int maxpmw,
else if ( checkable ) {
int mw = checkcol + motifItemFrame;
int mh = h - 2 * motifItemFrame;
if ( mi->isChecked() ) {
drawCheckMark( p, x + motifItemFrame,
y + motifItemFrame, mw, mh, itemg, act, dis );
}
}
p->setPen( colorGroup( g, act ? MenuItemDown : MenuItem ) ->text() );
QColor discol;
if ( dis ) {
discol = itemg.text();
p->setPen( discol );
}
int xm = motifItemFrame + checkcol + motifItemHMargin;
QString s = mi->text();
if ( !s.isNull() ) {
int t = s.find( '\t' );
int m = motifItemVMargin;
const int text_flags = AlignVCenter | ShowPrefix | DontClip | SingleLine;
if ( t >= 0 ) {
if ( dis && !act ) {
p->setPen( g.light() );
p->drawText( x + w - tab - windowsRightBorder - motifItemHMargin - motifItemFrame + 1,
y + m + 1, tab, h - 2 * m, text_flags, s.mid( t + 1 ) );
p->setPen( discol );
}
p->drawText( x + w - tab - windowsRightBorder - motifItemHMargin - motifItemFrame,
y + m, tab, h - 2 * m, text_flags, s.mid( t + 1 ) );
}
if ( dis && !act ) {
p->setPen( g.light() );
p->drawText( x + xm + 1, y + m + 1, w - xm + 1, h - 2 * m, text_flags, s, t );
p->setPen( discol );
}
p->drawText( x + xm, y + m, w - xm - tab + 1, h - 2 * m, text_flags, s, t );
}
else if ( mi->pixmap() ) {
QPixmap * pixmap = mi->pixmap();
if ( pixmap->depth() == 1 )
p->setBackgroundMode( OpaqueMode );
p->drawPixmap( x + xm, y + motifItemFrame, *pixmap );
if ( pixmap->depth() == 1 )
p->setBackgroundMode( TransparentMode );
}
if ( mi->popup() ) {
int dim = ( h - 2 * motifItemFrame ) / 2;
if ( act ) {
if ( !dis )
discol = colorGroup( g, MenuItemDown ) ->text();
//discol = white;
QColorGroup g2( discol, g.highlight(),
white, white,
dis ? discol : white,
discol, white );
drawArrow( p, RightArrow, true,
x + w - motifArrowHMargin - motifItemFrame - dim, y + h / 2 - dim / 2,
dim, dim, g2, TRUE );
}
else {
drawArrow( p, RightArrow,
false,
x + w - motifArrowHMargin - motifItemFrame - dim, y + h / 2 - dim / 2,
dim, dim, g, mi->isEnabled() );
}
}
}
void OThemeStyle::drawFocusRect( QPainter *p, const QRect &r,
const QColorGroup &g, const QColor *c,
bool atBorder )
{
p->setPen( g.dark() );
if ( !is3DFocus() )
QWindowsStyle::drawFocusRect( p, r, g, c, atBorder );
else {
int i = focusOffset();
p->drawLine( r.x() + i, r.y() + 1 + i, r.x() + i, r.bottom() - 1 - i );
p->drawLine( r.x() + 1 + i, r.y() + i, r.right() - 1 - i, r.y() + i );
p->setPen( g.light() );
p->drawLine( r.right() - i, r.y() + 1 + i, r.right() - i, r.bottom() - 1 - i );
p->drawLine( r.x() + 1 + i, r.bottom() - i, r.right() - 1 - i, r.bottom() - i );
}
}
#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(),
-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 )
{
const QColorGroup * cg = colorGroup( g, ProgressBg );
bg.setColor( cg->color( QColorGroup::Background ) );
if ( isPixmap( ProgressBg ) )
bg.setPixmap( *uncached( ProgressBg ) );
}
#endif
void OThemeStyle::tabbarMetrics( const QTabBar* t, int& hframe, int& vframe, int& overlap )
{
QCommonStyle::tabbarMetrics( t, hframe, vframe, overlap );
}
void OThemeStyle::drawTab( QPainter* p, const QTabBar* tb, QTab* t ,
bool selected )
{
WidgetType widget = selected ? ActiveTab : InactiveTab;
const QColorGroup *cg = colorGroup( tb->colorGroup(), widget );
int i;
int x = t->r.x(), y = t->r.y();
int x2 = t->r.right(), y2 = t->r.bottom();
int bWidth = borderWidth( widget );
int hWidth = highlightWidth( widget );
if ( tb->shape() == QTabBar::RoundedAbove ) {
if ( !selected ) {
p->fillRect( x, y, x2 - x + 1, 2,
tb->palette().normal().brush( QColorGroup::Background ) );
y += 2;
}
p->setPen( cg->text() );
i = 0;
if ( i < bWidth ) {
p->drawLine( x, y + 1, x, y2 );
p->drawLine( x2, y + 1, x2, y2 );
p->drawLine( x + 1, y, x2 - 1, y );
if ( selected ? activeTabLine() : inactiveTabLine() ) {
p->drawLine( x, y2, x2, y2 );
--y2;
}
++i, ++x, ++y, --x2;
}
for ( ; i < bWidth; ++i, ++x, ++y, --x2 ) {
p->drawLine( x, y, x, y2 );
p->drawLine( x2, y, x2, y2 );
p->drawLine( x, y, x2, y );
if ( selected ? activeTabLine() : inactiveTabLine() ) {
p->drawLine( x, y2, x2, y2 );
--y2;
}
}
i = 0;
if ( i < hWidth && bWidth == 0 ) {
p->setPen( cg->light() );
p->drawLine( x, y + 1, x, y2 );
p->drawLine( x + 1, y, x2 - 1, y );
p->setPen( cg->dark() );
p->drawLine( x2, y + 1, x2, y2 );
if ( selected ? activeTabLine() : inactiveTabLine() ) {
p->drawLine( x, y2, x2, y2 );
--y2;
}
++i, ++x, ++y, --x2;
}
for ( ; i < hWidth; ++i, ++x, ++y, --x2 ) {
p->setPen( cg->light() );
p->drawLine( x, y, x, y2 );
p->drawLine( x, y, x2, y );
p->setPen( cg->dark() );
p->drawLine( x2, y + 1, x2, y2 );
if ( selected ? activeTabLine() : inactiveTabLine() ) {
p->drawLine( x, y2, x2, y2 );
--y2;
}
}
if ( isPixmap( widget ) )
p->drawTiledPixmap( x, y, x2 - x + 1, y2 - y + 1,
*scalePixmap( x2 - x + 1, y2 - y + 1, widget ) );
else
p->fillRect( x, y, x2 - x + 1, y2 - y + 1, cg->background() );
}
else if ( tb->shape() == QTabBar::RoundedBelow ) {
if ( !selected ) {
p->fillRect( x, y2 - 2, x2 - x + 1, 2,
tb->palette().normal().brush( QColorGroup::Background ) );
y2 -= 2;
}
p->setPen( cg->text() );
i = 0;
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
@@ -1,161 +1,165 @@
/* This file is part of the KDE libraries
Copyright (C) 1999 Daniel M. Duley <mosfet@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2 as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#ifndef __KTHEMESTYLE_H
#define __KTHEMESTYLE_H
#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
* class handles refer to the KDE theme configuration documentation.
*
*/
class OThemeStyle: public OThemeBase
{
Q_OBJECT
public:
/**
* Construct a new @ref OThemeStyle object.
*
* @param configFile A KConfig file to use as the theme configuration.
* Defaults to ~/.kderc.
*/
OThemeStyle( const QString &configFile = QString::null );
~OThemeStyle();
virtual void polish( QWidget* );
virtual void unPolish( QWidget* );
/**
* By default this just sets the background brushes to the pixmapped
* background.
*/
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.
* @param rounded @p true if the widget is rounded, @p false if rectangular.
* @param type The widget type to paint.
* @param fill An optional fill brush. Currently ignored (the config file
* is used instead).
*/
virtual void drawBaseButton( QPainter *p, int x, int y, int w, int h,
const QColorGroup &g, bool sunken = FALSE,
bool rounded = FALSE, WidgetType type = Bevel,
const QBrush *fill = 0 );
/**
* Draw a mask with for widgets that may be rounded.
*
*Currently used
* by pushbuttons and comboboxes.
*
* @param p The QPainter to draw on.
* @param rounded @p true if the widget is rounded, @p false if rectangular.
*/
virtual void drawBaseMask( QPainter *p, int x, int y, int w, int h,
bool rounded );
/**
* Draw a pushbutton.
*
* This calls @ref drawBaseButton() with @p PushButton as the
* widget type.
*/
virtual void drawButton( QPainter *p, int x, int y, int w, int h,
const QColorGroup &g, bool sunken = FALSE,
const QBrush *fill = 0 );
/**
* Draw a bevel button.
*
* This calls @ref drawBaseButton() with Bevel as the
* widget type.
*/
virtual void drawBevelButton( QPainter *p, int x, int y, int w, int h,
const QColorGroup &g, bool sunken = FALSE,
const QBrush *fill = 0 );
/**
* Draw a toolbar button.
*/
virtual void drawToolButton ( QPainter *p, int x, int y, int w, int h,
const QColorGroup &g, bool sunken = FALSE,
const QBrush *fill = 0 );
#if 0
/**
* Draw a toolbar button.
*/
virtual void drawKToolBarButton( QPainter *p, int x, int y, int w, int h,
const QColorGroup &g, bool sunken = false,
bool raised = true, bool enabled = true,
bool popup = false, KToolButtonType type = Icon,
const QString &btext = QString::null,
const QPixmap *icon = NULL,
QFont *font = NULL, QWidget *btn = NULL );
/**
* Draw the handle used in toolbars.
*/
void drawKBarHandle( QPainter *p, int x, int y, int w, int h,
const QColorGroup &g,
KToolBarPos type, QBrush *fill = NULL );
/**
* Draw a toolbar.
*/
void drawKToolBar( QPainter *p, int x, int y, int w, int h,
const QColorGroup &g, KToolBarPos type,
QBrush *fill = NULL );
#endif
/**
* Return the space available in a pushbutton, taking configurable
* borders and highlights into account.
*/
virtual QRect buttonRect( int x, int y, int w, int h );
/**
* Draw an arrow in the style specified by the config file.
*/
virtual void drawArrow( QPainter *p, Qt::ArrowType type, bool down,
int x, int y, int w, int h, const QColorGroup &g,
bool enabled = true, const QBrush *fill = 0 );
/**
* Return the size of the exclusive indicator pixmap if one is specified
* in the config file, otherwise it uses the base style's size.
*/
virtual QSize exclusiveIndicatorSize() const;
/**
* Draw an exclusive indicator widget.
*
@@ -219,153 +223,149 @@ public:
virtual void drawPushButton( QPushButton* btn, QPainter *p );
/**
* Return the amount of button content displacement specified by the
* config file.
*/
virtual void getButtonShift( int &x, int &y );
/**
* Return the frame width.
*/
virtual int defaultFrameWidth() const;
/**
* Calculate the metrics of the scrollbar controls according to the
* layout specified by the config file.
*/
virtual void scrollBarMetrics( const QScrollBar*, int&, int&, int&, int& );
/**
* Draw a themed scrollbar.
*/
virtual void drawScrollBarControls( QPainter*, const QScrollBar*,
int sliderStart, uint controls,
uint activeControl );
/**
* Return the control that the given point is over according to the
* layout in the config file.
*/
virtual ScrollControl scrollBarPointOver( const QScrollBar*,
int sliderStart, const QPoint& );
/**
* Return the configurable default slider length.
*/
virtual int sliderLength() const;
/**
* Draw a slider control.
*/
virtual void drawSlider( QPainter *p, int x, int y, int w, int h,
const QColorGroup &g, Orientation, bool tickAbove,
bool tickBelow );
/**
* Draw a slider groove.
*/
void drawSliderGroove( QPainter *p, int x, int y, int w, int h,
const QColorGroup& g, QCOORD c,
Orientation );
/**
* Draw the mask for a slider (both the control and groove.
*/
virtual 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,
// QCOORD c, Orientation );
/**
* Convience method for drawing themed scrollbar grooves.
*
* Since the
* grooves may be a scaled pixmap you cannot just bitblt the pixmap at
* any offset. This generates a cached pixmap at full size if needed and
* then copies the requested area.
*
* @param p The painter to draw on.
* @param sb The scrollbar (usually given by drawScrollBarControls).
* @param horizontal Is the scrollBar horizontal?
* @param r The rectangle to fill.
* @param g The color group to use.
*/
virtual void drawScrollBarGroove( QPainter *p, const QScrollBar *sb,
bool horizontal, QRect r, QColorGroup g );
/**
* Draw a shaded rectangle using the given style.
*
* @param p The painter to draw on.
* @param g The color group to use.
* @param rounded Draws a rounded shape if true. Requires bWidth to be
* at least 1.
* @param hWidth The highlight width.
* @param bWidth The border width.
* @param style The shading style to use.
*/
virtual void drawShade( QPainter *p, int x, int y, int w, int h,
const QColorGroup &g, bool sunken, bool rounded,
int hWidth, int bWidth, ShadeStyle style );
/**
* Draw the text for a pushbutton.
*/
virtual void drawPushButtonLabel( QPushButton *btn, QPainter *p );
/**
* Draw a menubar.
*/
#if 0
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,
const QColorGroup &g, Orientation );
/**
* Draw a checkmark.
*/
virtual void drawCheckMark( QPainter *p, int x, int y, int w, int h,
const QColorGroup &g, bool act, bool dis );
/**
* Draw a menu item.
*
* Note: This method manually handles applying
* inactive menu backgrounds to the entire widget.
*/
virtual 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 );
int popupMenuItemHeight( bool checkable, QMenuItem *mi,
const QFontMetrics &fm );
/**
* 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:
QPalette oldPalette, popupPalette, indiPalette, exIndiPalette;
class OThemeStylePrivate;
OThemeStylePrivate *d;
};
#endif