summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/styles/theme/othemestyle.cpp8
-rw-r--r--noncore/styles/theme/othemestyle.h6
2 files changed, 14 insertions, 0 deletions
diff --git a/noncore/styles/theme/othemestyle.cpp b/noncore/styles/theme/othemestyle.cpp
index 61127b8..d97b026 100644
--- a/noncore/styles/theme/othemestyle.cpp
+++ b/noncore/styles/theme/othemestyle.cpp
@@ -1,695 +1,703 @@
/* 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 <limits.h>
#include <stdio.h>
#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*/ )
{}
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 )
{
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" ) ) {
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" ) ) {
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 );
}
}
}
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" ) )
w->unsetPalette();
if ( w->inherits( "QRadioButton" ) )
w->unsetPalette();
}
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
};
QBrush fillBrush( color1, SolidPattern );
p->setPen( color1 );
if ( round && w > 19 && h > 19 ) {
int x2 = x + w - 1;
int y2 = y + h - 1;
QPointArray a( QCOORDARRLEN( top_left_fill ), top_left_fill );
a.translate( 1, 1 );
p->drawPoints( a );
a.setPoints( QCOORDARRLEN( btm_left_fill ), btm_left_fill );
a.translate( 1, h - 6 );
p->drawPoints( a );
a.setPoints( QCOORDARRLEN( top_right_fill ), top_right_fill );
a.translate( w - 6, 1 );
p->drawPoints( a );
a.setPoints( QCOORDARRLEN( btm_right_fill ), btm_right_fill );
a.translate( w - 6, h - 6 );
p->drawPoints( a );
p->fillRect( x + 6, y, w - 12, h, fillBrush );
p->fillRect( x, y + 6, x + 6, h - 12, fillBrush );
p->fillRect( x2 - 6, y + 6, x2, h - 12, fillBrush );
p->drawLine( x + 6, y, x2 - 6, y );
p->drawLine( x + 6, y2, x2 - 6, y2 );
p->drawLine( x, y + 6, x, y2 - 6 );
p->drawLine( x2, y + 6, x2, y2 - 6 );
}
else
p->fillRect( x, y, w, h, fillBrush );
}
void OThemeStyle::drawButtonMask( QPainter *p, int x, int y, int w, int h )
{
drawBaseMask( p, x, y, w, h, roundButton() );
}
void OThemeStyle::drawComboButtonMask( QPainter *p, int x, int y, int w, int h )
{
drawBaseMask( p, x, y, w, h, roundComboBox() );
}
void OThemeStyle::drawBevelButton( QPainter *p, int x, int y, int w, int h,
const QColorGroup &g, bool sunken,
const QBrush * )
{
WidgetType type = sunken ? BevelDown : Bevel;
drawBaseButton( p, x, y, w, h, *colorGroup( g, type ), sunken, false, type );
}
+void OThemeStyle::drawToolButton( QPainter *p, int x, int y, int w, int h,
+ const QColorGroup &g, bool sunken,
+ const QBrush * )
+{
+ WidgetType type = sunken ? ToolButtonDown : ToolButton;
+ drawBaseButton( p, x, y, w, h, *colorGroup( g, type ), sunken, false, type );
+}
+
#if 0
void OThemeStyle::drawKToolBarButton( QPainter *p, int x, int y, int w, int h,
const QColorGroup &g, bool sunken,
bool raised, bool enabled, bool popup,
KToolButtonType type, const QString &btext,
const QPixmap *pixmap, QFont *font,
QWidget * )
{
QFont tmp_font( QString::fromLatin1( "Helvetica" ), 10 );
if ( font )
tmp_font = *font;
QFontMetrics fm( tmp_font );
WidgetType widget = sunken ? ToolButtonDown : ToolButton;
drawBaseButton( p, x, y, w, h, *colorGroup( g, widget ), sunken, false,
widget );
int dx, dy;
if ( type == Icon ) { // icon only
if ( pixmap ) {
dx = ( w - pixmap->width() ) / 2;
dy = ( h - pixmap->height() ) / 2;
if ( sunken ) {
++dx;
++dy;
}
p->drawPixmap( x + dx, y + dy, *pixmap );
}
}
else if ( type == IconTextRight ) { // icon and text (if any)
if ( pixmap ) {
dx = 4;
dy = ( h - pixmap->height() ) / 2;
if ( sunken ) {
++dx;
++dy;
}
p->drawPixmap( x + dx, y + dy, *pixmap );
}
if ( !btext.isNull() ) {
int tf = AlignVCenter | AlignLeft;
if ( pixmap )
dx = 4 + pixmap->width() + 2;
else
dx = 4;
dy = 0;
if ( sunken ) {
++dx;
++dy;
}
if ( font )
p->setFont( *font );
if ( raised )
p->setPen( KGlobalSettings::toolBarHighlightColor() );
p->drawText( x + dx, y + dy, w - dx, h, tf, btext );
}
}
else if ( type == Text ) { // only text, even if there is a icon
if ( !btext.isNull() ) {
int tf = AlignTop | AlignLeft;
if ( !enabled )
p->setPen( g.dark() );
dx = ( w - fm.width( btext ) ) / 2;
dy = ( h - fm.lineSpacing() ) / 2;
if ( sunken ) {
++dx;
++dy;
}
if ( font )
p->setFont( *font );
if ( raised )
p->setPen( KGlobalSettings::toolBarHighlightColor() );
p->drawText( x + dx, y + dy, fm.width( btext ), fm.lineSpacing(), tf, btext );
}
}
else if ( type == IconTextBottom ) {
if ( pixmap ) {
dx = ( w - pixmap->width() ) / 2;
dy = ( h - fm.lineSpacing() - pixmap->height() ) / 2;
if ( sunken ) {
++dx;
++dy;
}
p->drawPixmap( x + dx, y + dy, *pixmap );
}
if ( !btext.isNull() ) {
int tf = AlignBottom | AlignHCenter;
dx = ( w - fm.width( btext ) ) / 2;
dy = h - fm.lineSpacing() - 4;
if ( sunken ) {
++dx;
++dy;
}
if ( font )
p->setFont( *font );
if ( raised )
p->setPen( KGlobalSettings::toolBarHighlightColor() );
p->drawText( x + dx, y + dy, fm.width( btext ), fm.lineSpacing(), tf, btext );
}
}
if ( popup ) {
if ( enabled )
qDrawArrow ( p, DownArrow, WindowsStyle, false, w - 5, h - 5, 0, 0,
g, true );
else
qDrawArrow ( p, DownArrow, WindowsStyle, false, w - 5, h - 5,
0, 0, g, false );
}
}
void OThemeStyle::drawKBarHandle( QPainter *p, int x, int y, int w, int h,
const QColorGroup &g, KToolBarPos, QBrush * )
{
if ( w > h )
drawBaseButton( p, x, y, w, h, *colorGroup( g, HBarHandle ), false, false,
HBarHandle );
else
drawBaseButton( p, x, y, w, h, *colorGroup( g, VBarHandle ), false, false,
VBarHandle );
}
void OThemeStyle::drawKToolBar( QPainter *p, int x, int y, int w, int h,
const QColorGroup &g, KToolBarPos, QBrush * )
{
drawBaseButton( p, x, y, w, h, *colorGroup( g, ToolBar ), false, false,
ToolBar );
}
#endif
QRect OThemeStyle::buttonRect( int x, int y, int w, int h )
{
int spacing = decoWidth( PushButton ) > decoWidth( PushButtonDown ) ?
decoWidth( PushButton ) : decoWidth( PushButtonDown );
return ( QRect( x + spacing, y + spacing, w - ( spacing * 2 ), h - ( spacing * 2 ) ) );
}
void OThemeStyle::drawComboButton( QPainter *p, int x, int y, int w, int h,
const QColorGroup &g, bool sunken, bool,
bool, const QBrush * )
{
WidgetType widget = sunken ? ComboBoxDown : ComboBox;
drawBaseButton( p, x, y, w, h, *colorGroup( g, widget ), sunken,
roundComboBox(), widget );
if ( !sunken && isPixmap( ComboDeco ) )
p->drawPixmap( w - uncached( ComboDeco ) ->width() -
decoWidth( ComboBox ) - 2,
y + ( h - uncached( ComboDeco ) ->
height() ) / 2, *uncached( ComboDeco ) );
else if ( sunken && isPixmap( ComboDecoDown ) )
p->drawPixmap( w - uncached( ComboDecoDown ) ->width() -
decoWidth( ComboBoxDown ) - 2,
y + ( h - uncached( ComboDecoDown ) ->
height() ) / 2, *uncached( ComboDecoDown ) );
else {
qDrawArrow( p, Qt::DownArrow, Qt::MotifStyle, false, w - 15, y + 6, 10,
h - 15, *colorGroup( g, widget ), true );
qDrawShadeRect( p, w - 14, y + 7 + ( h - 15 ), 10, 3, *colorGroup( g, widget ) );
}
}
void OThemeStyle::drawScrollBarControls( QPainter *p, const QScrollBar *sb,
int sliderStart, uint controls,
uint activeControl )
{
int sliderMin, sliderMax, sliderLength, buttonDim;
QRect add
, sub, addPage, subPage, slider;
int addX, addY, subX, subY;
bool horizontal = sb->orientation() == QScrollBar::Horizontal;
int len = ( horizontal ) ? sb->width() : sb->height();
int extent = ( horizontal ) ? sb->height() : sb->width();
int offset = decoWidth( horizontal ? HScrollGroove : VScrollGroove );
QColorGroup g = sb->colorGroup();
scrollBarMetrics( sb, sliderMin, sliderMax, sliderLength, buttonDim );
if ( sliderStart > sliderMax )
sliderStart = sliderMax;
int sliderEnd = sliderStart + sliderLength;
int sliderWidth = extent - offset * 2;
// Scary button placement code >:-P Feel free to improve this if you
// want. I get a headache just looking at it... (mosfet)
if ( scrollBarLayout() == SBOpposite ) {
if ( horizontal ) {
subY = addY = ( extent - buttonDim ) / 2;
subX = offset;
addX = len - buttonDim - offset;
}
else {
subX = addX = ( extent - buttonDim ) / 2;
subY = offset;
addY = len - buttonDim - offset;
}
sub.setRect( subX, subY, buttonDim, buttonDim );
add.setRect( addX, addY, buttonDim, buttonDim );
if ( horizontal ) {
subPage.setRect( sub.right() + 1, offset,
sliderStart - sub.right() - 1 , sliderWidth );
addPage.setRect( sliderEnd, offset, addX - sliderEnd, sliderWidth );
slider.setRect( sliderStart, offset, sliderLength, sliderWidth );
}
else {
subPage.setRect( offset, sub.bottom() + 1, sliderWidth,
sliderStart - sub.bottom() - 1 );
addPage.setRect( offset, sliderEnd, sliderWidth, addY - sliderEnd );
slider.setRect( offset, sliderStart, sliderWidth, sliderLength );
}
}
else if ( horizontal ) {
subY = addY = ( extent - buttonDim ) / 2;
if ( scrollBarLayout() == SBBottomLeft ) {
subX = offset;
addX = buttonDim + offset;
subPage.setRect( buttonDim * 2, 0, sliderStart - 1, extent );
addPage.setRect( sliderEnd, 0, len - sliderEnd, extent );
slider.setRect( sliderStart, 0, sliderLength, extent );
}
else {
subX = len - buttonDim - buttonDim - offset;
addX = len - buttonDim - offset;
subPage.setRect( offset + 1, offset, sliderStart - 1 , sliderWidth );
addPage.setRect( sliderEnd, offset, subX - sliderEnd, sliderWidth );
slider.setRect( sliderStart, offset, sliderLength, sliderWidth );
}
sub.setRect( subX, subY, buttonDim, buttonDim );
add.setRect( addX, addY, buttonDim, buttonDim );
}
else { // BottomLeft and BottomRight vertical bars are the same.
subX = addX = ( extent - buttonDim ) / 2;
subY = len - buttonDim - buttonDim - offset;
addY = len - buttonDim - offset;
subPage.setRect( offset, offset + 1, sliderWidth,
sliderStart - offset - 1 );
addPage.setRect( offset, sliderEnd, sliderWidth, subY - sliderEnd );
slider.setRect( offset, sliderStart, sliderWidth, sliderLength );
sub.setRect( subX, subY, buttonDim, buttonDim );
add.setRect( addX, addY, buttonDim, buttonDim );
}
// End of the button placement code
bool active;
if ( ( controls & QStyle::SubPage ) ) {
drawScrollBarGroove( p, sb, horizontal, subPage, g );
}
if ( ( controls & QStyle::AddPage ) ) {
drawScrollBarGroove( p, sb, horizontal, addPage, g );
}
if ( controls & QStyle::AddLine ) {
active = activeControl == QStyle::AddLine;
drawBaseButton( p, add.x(), add.y(), add.width(), add.height(),
*colorGroup( g, active ? ScrollButtonDown : ScrollButton ),
active, false, active ? ScrollButtonDown : ScrollButton );
drawArrow( p, ( horizontal ) ? RightArrow : DownArrow, active, add.x() + 3,
add.y() + 3, add.width() - 6, add.height() - 6,
*colorGroup( g, active ? ScrollButtonDown : ScrollButton ) );
}
if ( controls & QStyle::SubLine ) {
active = activeControl == QStyle::SubLine;
p->setPen( g.dark() );
p->drawRect( sub );
drawBaseButton( p, sub.x(), sub.y(), sub.width(), sub.height(),
*colorGroup( g, active ? ScrollButtonDown : ScrollButton ),
active, false, active ? ScrollButtonDown : ScrollButton );
drawArrow( p, ( horizontal ) ? LeftArrow : UpArrow, active, sub.x() + 3,
sub.y() + 3, sub.width() - 6, sub.height() - 6,
*colorGroup( g, active ? ScrollButtonDown : ScrollButton ) );
}
if ( controls & QStyle::Slider ) {
active = activeControl == QStyle::Slider;
WidgetType widget = horizontal ?
active ? HScrollBarSliderDown : HScrollBarSlider :
active ? VScrollBarSliderDown : VScrollBarSlider;
drawBaseButton( p, slider.x(), slider.y(), slider.width(),
slider.height(), *colorGroup( g, widget ), active, false,
widget );
int spaceW = horizontal ? slider.width() - decoWidth( widget ) - 4 :
slider.width();
int spaceH = horizontal ? slider.height() :
slider.height() - decoWidth( widget ) - 4;
widget = active ? horizontal ? HScrollDecoDown : VScrollDecoDown :
horizontal ? HScrollDeco : VScrollDeco;
if ( isPixmap( widget ) ) {
if ( spaceW >= uncached( widget ) ->width() &&
spaceH >= uncached( widget ) ->height() ) {
p->drawPixmap( slider.x() + ( slider.width() -
uncached( widget ) ->width() ) / 2,
slider.y() + ( slider.height() -
uncached( widget ) ->height() ) / 2,
*uncached( widget ) );
}
}
}
}
void OThemeStyle::drawScrollBarGroove( QPainter *p, const QScrollBar *sb,
bool horizontal, QRect r, QColorGroup g )
{
WidgetType widget = ( horizontal ) ? HScrollGroove : VScrollGroove;
if ( !isPixmap( widget ) ) {
p->fillRect( r, colorGroup( g, widget ) ->brush( QColorGroup::Background ) );
}
else {
// If the groove is pixmapped we make a full-sized image (it gets
// cached) then bitBlt it to the appropriate rect.
QPixmap buffer( sb->size() );
QPainter bPainter( &buffer );
bPainter.drawTiledPixmap( 0, 0, buffer.width(), buffer.height(),
*scalePixmap( buffer.width(), buffer.height(),
widget ) );
bitBlt( p->device(), r.x(), r.y(), &buffer, r.x(), r.y(), r.width(),
r.height(), Qt::CopyROP );
}
// Do the borders and frame
drawShade( p, sb->rect().x(), sb->rect().y(), sb->rect().width(),
sb->rect().height(), *colorGroup( g, widget ), true, false,
highlightWidth( widget ), borderWidth( widget ), shade() );
}
void OThemeStyle::scrollBarMetrics( const QScrollBar *sb, int &sliderMin,
int &sliderMax, int &sliderLength,
int &buttonDim )
{
bool horizontal = sb->orientation() == QScrollBar::Horizontal;
int offset = decoWidth( horizontal ? HScrollGroove : VScrollGroove );
int maxlen;
int len = horizontal ? sb->width() : sb->height();
int extent = horizontal ? sb->height() : sb->width();
if ( len > ( extent - offset * 2 - 1 ) * 2 + offset * 2 )
buttonDim = extent - offset * 2;
else
buttonDim = ( len - offset * 2 ) / 2 - 1;
maxlen = len - offset * 2 - buttonDim * 2 - 1;
switch ( scrollBarLayout() ) {
case SBBottomLeft:
sliderMin = ( horizontal ) ? buttonDim * 2 + offset + 1 : offset + 1;
break;
case SBBottomRight:
sliderMin = offset + 1;
break;
case SBOpposite:
default:
sliderMin = offset + buttonDim;
break;
}
if ( sb->maxValue() == sb->minValue() )
sliderLength = maxlen;
else
sliderLength = ( sb->pageStep() * maxlen ) / ( sb->maxValue() -
sb->minValue() + sb->pageStep() );
if ( sliderLength < 12 || ( sb->maxValue() - sb->minValue() ) > INT_MAX / 2 )
sliderLength = 12;
if ( sliderLength > maxlen )
sliderLength = maxlen;
sliderMax = sliderMin + maxlen - sliderLength;
}
QStyle::ScrollControl OThemeStyle::scrollBarPointOver( const QScrollBar *sb,
int sliderStart,
const QPoint &p )
{
if ( !sb->rect().contains( p ) )
return ( QStyle::NoScroll );
int sliderMin, sliderMax, sliderLength, buttonDim;
int pos = ( sb->orientation() == QScrollBar::Horizontal ) ? p.x() : p.y();
scrollBarMetrics( sb, sliderMin, sliderMax, sliderLength, buttonDim );
if ( scrollBarLayout() == SBOpposite ) {
if ( pos < sliderMin )
return QStyle::SubLine;
if ( pos < sliderStart )
return SubPage;
if ( pos < sliderStart + sliderLength )
return QStyle::Slider;
if ( pos < sliderMax + sliderLength )
return QStyle::AddPage;
return QStyle::AddLine;
}
if ( scrollBarLayout() == SBBottomLeft && sb->orientation() ==
QScrollBar::Horizontal ) {
if ( pos <= buttonDim )
diff --git a/noncore/styles/theme/othemestyle.h b/noncore/styles/theme/othemestyle.h
index 02bec78..52445c4 100644
--- a/noncore/styles/theme/othemestyle.h
+++ b/noncore/styles/theme/othemestyle.h
@@ -1,365 +1,371 @@
/* 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>
/**
* 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 );
/**
* 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.
*
* If a pixmap is specified in the
* config file that is used, otherwise the base style's widget is drawn.
*/
virtual void drawExclusiveIndicator( QPainter* p, int x, int y, int w,
int h, const QColorGroup &g, bool on,
bool down = FALSE,
bool enabled = TRUE );
/**
* Set the mask of an exclusive indicator widget.
*
* If a pixmap is specified
* it is masked according to it's transparent pixels, otherwise the
* base style's mask is used.
*/
virtual void drawExclusiveIndicatorMask( QPainter *p, int x, int y, int w,
int h, bool on );
/**
* Set the mask of an indicator widget.
*
* If a pixmap is specified
* it is masked according to it's transparent pixels, otherwise the
* base style's mask is used.
*/
virtual void drawIndicatorMask( QPainter *p, int x, int y, int w, int h,
int state );
/**
* Set the mask for pushbuttons.
*/
virtual void drawButtonMask( QPainter *p, int x, int y, int w, int h );
/**
* Set the mask for combo boxes.
*/
virtual void drawComboButtonMask( QPainter *p, int x, int y, int w, int h );
/**
* Return the size of the indicator pixmap if one is specified
* in the config file, otherwise it uses the base style's size.
*/
virtual QSize indicatorSize() const;
/**
* Draw an indicator widget.
*
* If a pixmap is specified in the
* config file that is used, otherwise the base style's widget is drawn.
*/
virtual void drawIndicator( QPainter* p, int x, int y, int w, int h,
const QColorGroup &g, int state,
bool down = FALSE, bool enabled = TRUE );
/**
* Draw a combobox.
*/
virtual void drawComboButton( QPainter *p, int x, int y, int w, int h,
const QColorGroup &g, bool sunken = FALSE,
bool editable = FALSE, bool enabled = TRUE,
const QBrush *fill = 0 );
/**
* Draw a pushbutton.
*/
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
/**
* 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);
/**
* 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