summaryrefslogtreecommitdiffstats
path: root/tdestyles/kthemestyle
diff options
context:
space:
mode:
Diffstat (limited to 'tdestyles/kthemestyle')
-rw-r--r--tdestyles/kthemestyle/CMakeLists.txt41
-rw-r--r--tdestyles/kthemestyle/Makefile.am29
-rw-r--r--tdestyles/kthemestyle/kthemebase.cpp1828
-rw-r--r--tdestyles/kthemestyle/kthemebase.h865
-rw-r--r--tdestyles/kthemestyle/kthemestyle.cpp2459
-rw-r--r--tdestyles/kthemestyle/kthemestyle.h242
-rw-r--r--tdestyles/kthemestyle/tdestyledirs.cpp48
-rw-r--r--tdestyles/kthemestyle/tdestyledirs.h82
8 files changed, 5594 insertions, 0 deletions
diff --git a/tdestyles/kthemestyle/CMakeLists.txt b/tdestyles/kthemestyle/CMakeLists.txt
new file mode 100644
index 000000000..63d4cdf6f
--- /dev/null
+++ b/tdestyles/kthemestyle/CMakeLists.txt
@@ -0,0 +1,41 @@
+#################################################
+#
+# (C) 2010 Serghei Amelian
+# serghei (DOT) amelian (AT) gmail.com
+#
+# Improvements and feedback are welcome
+#
+# This file is released under GPL >= 2
+#
+#################################################
+
+add_definitions(
+ -DQT_PLUGIN
+)
+
+include_directories(
+ ${TQT_INCLUDE_DIRS}
+ ${CMAKE_CURRENT_BINARY_DIR}
+ ${CMAKE_BINARY_DIR}/tdecore
+ ${CMAKE_SOURCE_DIR}/tdefx
+ ${CMAKE_SOURCE_DIR}/tdecore
+)
+
+link_directories(
+ ${TQT_LIBRARY_DIRS}
+)
+
+
+##### kthemestyle ###############################
+
+set( target kthemestyle )
+
+set( ${target}_SRCS
+ kthemebase.cpp kthemestyle.cpp tdestyledirs.cpp
+)
+
+tde_add_kpart( ${target} AUTOMOC
+ SOURCES ${${target}_SRCS}
+ LINK tdefx-shared tdecore-shared dl
+ DESTINATION ${PLUGIN_INSTALL_DIR}/plugins/styles
+)
diff --git a/tdestyles/kthemestyle/Makefile.am b/tdestyles/kthemestyle/Makefile.am
new file mode 100644
index 000000000..bc1b13e61
--- /dev/null
+++ b/tdestyles/kthemestyle/Makefile.am
@@ -0,0 +1,29 @@
+
+# This file is part of the KDE libraries
+# Copyright (C) 1997 Matthias Kalle Dalheimer (kalle@kde.org)
+# (C) 1997 Stephan Kulow (coolo@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 as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+
+# 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 General Public License
+# along with this library; see the file COPYING. If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+# Boston, MA 02110-1301, USA.
+
+AM_CPPFLAGS = -DQT_PLUGIN
+
+INCLUDES = -I$(top_srcdir)/tdefx $(all_includes)
+noinst_HEADERS = kthemestyle.h kthemebase.h tdestyledirs.h
+kde_style_LTLIBRARIES = kthemestyle.la
+kthemestyle_la_LDFLAGS = $(all_libraries) $(KDE_PLUGIN) -module
+kthemestyle_la_LIBADD = ../../tdefx/libtdefx.la ../../tdecore/libtdecore.la -ldl $(LIB_QT)
+kthemestyle_la_SOURCES = kthemebase.cpp kthemestyle.cpp tdestyledirs.cpp
+kthemestyle_la_METASOURCES = AUTO
diff --git a/tdestyles/kthemestyle/kthemebase.cpp b/tdestyles/kthemestyle/kthemebase.cpp
new file mode 100644
index 000000000..8e1f5605f
--- /dev/null
+++ b/tdestyles/kthemestyle/kthemebase.cpp
@@ -0,0 +1,1828 @@
+/*
+ $Id$
+
+ This file is part of the KDE libraries
+ Copyright (C) 1999 Daniel M. Duley <mosfet@kde.org>
+
+ KDE3 port (C) 2001-2002 Maksim Orlovich <mo002j@mail.rochester.edu>
+ Port version 0.9.7
+
+ Palette setup code is from TDEApplication,
+ Copyright (C) 1997 Matthias Kalle Dalheimer (kalle@kde.org)
+ Copyright (C) 1998, 1999, 2000 KDE Team
+
+ Includes code portions from the KDE HighColor style.
+
+ KDE3 HighColor Style
+ Copyright (C) 2001 Karol Szwed <gallium@kde.org>
+ (C) 2001 Fredrik H�glund <fredrik@kde.org>
+
+ Drawing routines adapted from the KDE2 HCStyle,
+ Copyright (C) 2000 Daniel M. Duley <mosfet@kde.org>
+ (C) 2000 Dirk Mueller <mueller@kde.org>
+ (C) 2001 Martijn Klingens <klingens@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., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "kthemebase.h"
+#include <kpixmapeffect.h>
+#include <tqimage.h>
+#include <tqpainter.h>
+#include <tqbitmap.h>
+#include <stdlib.h>
+
+#include <tqsettings.h>
+#include <tqapplication.h>
+#include <tqscrollbar.h>
+
+typedef TQMap<TQString, TQString> Prop;
+
+template class TQIntCache<KThemePixmap>
+;
+
+/*
+Bugs:
+Can't delete old slider image when calculating the rotated one for some reason.
+*/
+
+//Shamelessly stolen from TDEConfigBase
+static TQColor readColorEntry( TQSettings* s, const char *pKey,
+ const TQColor* pDefault )
+{
+ TQColor aRetColor;
+ int nRed = 0, nGreen = 0, nBlue = 0;
+
+ TQString aValue = s->readEntry( pKey );
+ if ( !aValue.isEmpty() )
+ {
+ if ( aValue.at( 0 ) == '#' )
+ {
+ aRetColor.setNamedColor( aValue );
+ }
+ else
+ {
+ bool bOK;
+ // find first part (red)
+ int nIndex = aValue.find( ',' );
+ if ( nIndex == -1 )
+ {
+ // return a sensible default -- Bernd
+ if ( pDefault )
+ aRetColor = *pDefault;
+ return aRetColor;
+ }
+
+ nRed = aValue.left( nIndex ).toInt( &bOK );
+
+ // find second part (green)
+ int nOldIndex = nIndex;
+ nIndex = aValue.find( ',', nOldIndex + 1 );
+
+ if ( nIndex == -1 )
+ {
+ // return a sensible default -- Bernd
+ if ( pDefault )
+ aRetColor = *pDefault;
+ return aRetColor;
+ }
+ nGreen = aValue.mid( nOldIndex + 1,
+ nIndex - nOldIndex - 1 ).toInt( &bOK );
+
+ // find third part (blue)
+ nBlue = aValue.right( aValue.length() - nIndex - 1 ).toInt( &bOK );
+
+ aRetColor.setRgb( nRed, nGreen, nBlue );
+ }
+ }
+ else
+ {
+
+ if ( pDefault )
+ aRetColor = *pDefault;
+ }
+
+ return aRetColor;
+}
+
+
+static const char * const widgetEntries[] =
+ { // unsunken widgets (see header)
+ "PushButton", "ComboBox", "HSBarSlider", "VSBarSlider", "Bevel", "ToolButton",
+ "ScrollButton", "HScrollDeco", "VScrollDeco", "ComboDeco", "MenuItem", "Tab",
+ "ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight",
+ // sunken widgets
+ "PushButtonDown", "ComboBoxDown", "HSBarSliderDown", "VSBarSliderDown",
+ "BevelDown", "ToolButtonDown", "ScrollButtonDown", "HScrollDecoDown",
+ "VScrollDecoDown", "ComboDecoDown", "MenuItemDown", "TabDown", "SunkenArrowUp",
+ "SunkenArrowDown", "SunkenArrowLeft", "SunkenArrowRight",
+ // everything else
+ "HScrollGroove", "VScrollGroove", "Slider", "SliderGroove", "CheckBoxDown",
+ "CheckBox", "CheckBoxTri", "RadioDown", "Radio", "HBarHandle", "VBarHandle",
+ "ToolBar", "Splitter", "CheckMark", "MenuBar", "DisableArrowUp",
+ "DisableArrowDown", "DisableArrowLeft", "DisableArrowRight", "ProgressBar",
+ "ProgressBackground", "MenuBarItem", "Background", "RotSlider",
+ "RotInactiveTab", "RotActiveTab",
+ };
+
+#define INHERIT_ITEMS 16
+
+
+class KThemeBasePrivate
+{
+public:
+ /** Color overrides flags..*/
+ bool overrideForeground;
+ bool overrideBackground;
+ bool overrideSelectForeground;
+ bool overrideSelectBackground;
+ bool overrideWindowForeground;
+ bool overrideWindowBackground;
+
+ /**
+ * Colors to override defaults with..
+ */
+ TQColor overrideForegroundCol;
+ TQColor overrideBackgroundCol;
+ TQColor overrideSelectForegroundCol;
+ TQColor overrideSelectBackgroundCol;
+ TQColor overrideWindowForegroundCol;
+ TQColor overrideWindowBackgroundCol;
+
+ int contrast;
+
+
+ TQMap <TQString, TQMap<TQString, TQString> > props;
+
+ TQMap<const TQPixmap*, TQColor> colorCache;
+
+ /*
+ A heuristic routine that tries to determine the avergae color of the image
+ Wouldn't work for things like sliders, etc.
+ */
+ TQColor pixmapAveColor( const TQPixmap* p )
+ {
+ if ( colorCache.contains( p ) )
+ return colorCache[ p ];
+
+ TQImage to_ave = p->convertToImage();
+ double h = 0, s = 0, v = 0;
+ int count = 0;
+ int dh, ds, dv;
+ for ( int x = 0; x < p->width(); x++ )
+ {
+ TQColor pix( to_ave.pixel( x, p->height() / 2 ) );
+ pix.hsv( &dh, &ds, &dv );
+ h += dh;
+ s += ds;
+ v += dv;
+ count++;
+ }
+
+ for ( int y = 0; y < p->height(); y++ )
+ {
+ TQColor pix( to_ave.pixel( p->width() / 2, y ) );
+ pix.hsv( &dh, &ds, &dv );
+ h += dh;
+ s += ds;
+ v += dv;
+ count++;
+ }
+ colorCache[ p ] = TQColor( int( h / count + 0.5 ), int( s / count + 0.5 ), int( v / count + 0.5 ), TQColor::Hsv );
+ return colorCache[ p ];
+ }
+};
+
+
+
+// This is used to encode the keys. I used to use masks but I think this
+// bitfield is nicer :) I don't know why C++ coders don't use these more..
+// (mosfet)
+struct kthemeKeyData
+{
+unsigned int id :
+ 6;
+unsigned int width :
+ 12;
+unsigned int height :
+ 12;
+unsigned int border :
+ 1;
+unsigned int mask :
+ 1;
+};
+
+union kthemeKey{
+ kthemeKeyData data;
+ unsigned int cacheKey;
+};
+
+#define KDE_TQBITMAP_TO_TQPAINTDEVICE(x) TQT_TQPAINTDEVICE_CONST(static_cast<const TQPixmap*>(static_cast<const TQBitmap*>(x)))
+
+void KThemeBase::generateBorderPix( int i )
+{
+ // separate pixmap into separate components
+ if ( pbPixmaps[ i ] )
+ {
+ // evidently I have to do masks manually...
+ const TQBitmap * srcMask = pbPixmaps[ i ] ->mask();
+ TQBitmap destMask( pbWidth[ i ], pbWidth[ i ] );
+ TQPixmap tmp( pbWidth[ i ], pbWidth[ i ] );
+
+ bitBlt( TQT_TQPAINTDEVICE(&tmp), 0, 0, TQT_TQPAINTDEVICE(pbPixmaps[ i ]), 0, 0, pbWidth[ i ], pbWidth[ i ],
+ TQt::CopyROP, false );
+ if ( srcMask )
+ {
+ bitBlt( TQT_TQPAINTDEVICE(&destMask), 0, 0, KDE_TQBITMAP_TO_TQPAINTDEVICE(srcMask), 0, 0, pbWidth[ i ], pbWidth[ i ],
+ TQt::CopyROP, false );
+ tmp.setMask( destMask );
+ }
+ pbPixmaps[ i ] ->setBorder( KThemePixmap::TopLeft, tmp );
+
+ bitBlt( TQT_TQPAINTDEVICE(&tmp), 0, 0, TQT_TQPAINTDEVICE(pbPixmaps[ i ]), pbPixmaps[ i ] ->width() - pbWidth[ i ], 0,
+ pbWidth[ i ], pbWidth[ i ], TQt::CopyROP, false );
+ if ( srcMask )
+ {
+ bitBlt( TQT_TQPAINTDEVICE(&destMask), 0, 0, KDE_TQBITMAP_TO_TQPAINTDEVICE(srcMask), pbPixmaps[ i ] ->width() - pbWidth[ i ],
+ 0, pbWidth[ i ], pbWidth[ i ], TQt::CopyROP, false );
+ tmp.setMask( destMask );
+ }
+ pbPixmaps[ i ] ->setBorder( KThemePixmap::TopRight, tmp );
+
+ bitBlt( TQT_TQPAINTDEVICE(&tmp), 0, 0, TQT_TQPAINTDEVICE(pbPixmaps[ i ]), 0, pbPixmaps[ i ] ->height() - pbWidth[ i ],
+ pbWidth[ i ], pbWidth[ i ], TQt::CopyROP, false );
+ if ( srcMask )
+ {
+ bitBlt( TQT_TQPAINTDEVICE(&destMask), 0, 0, KDE_TQBITMAP_TO_TQPAINTDEVICE(srcMask), 0, pbPixmaps[ i ] ->height() - pbWidth[ i ],
+ pbWidth[ i ], pbWidth[ i ], TQt::CopyROP, false );
+ tmp.setMask( destMask );
+ }
+ pbPixmaps[ i ] ->setBorder( KThemePixmap::BottomLeft, tmp );
+
+ bitBlt( TQT_TQPAINTDEVICE(&tmp), 0, 0, TQT_TQPAINTDEVICE(pbPixmaps[ i ]), pbPixmaps[ i ] ->width() - pbWidth[ i ],
+ pbPixmaps[ i ] ->height() - pbWidth[ i ], pbWidth[ i ], pbWidth[ i ],
+ TQt::CopyROP, false );
+ if ( srcMask )
+ {
+ bitBlt( TQT_TQPAINTDEVICE(&destMask), 0, 0, KDE_TQBITMAP_TO_TQPAINTDEVICE(srcMask), pbPixmaps[ i ] ->width() - pbWidth[ i ],
+ pbPixmaps[ i ] ->height() - pbWidth[ i ], pbWidth[ i ], pbWidth[ i ],
+ TQt::CopyROP, false );
+ tmp.setMask( destMask );
+ }
+ pbPixmaps[ i ] ->setBorder( KThemePixmap::BottomRight, tmp );
+
+ tmp.resize( pbPixmaps[ i ] ->width() - pbWidth[ i ] * 2, pbWidth[ i ] );
+ destMask.resize( pbPixmaps[ i ] ->width() - pbWidth[ i ] * 2, pbWidth[ i ] );
+ bitBlt( TQT_TQPAINTDEVICE(&tmp), 0, 0, TQT_TQPAINTDEVICE(pbPixmaps[ i ]), pbWidth[ i ], 0,
+ pbPixmaps[ i ] ->width() - pbWidth[ i ] * 2, pbWidth[ i ], TQt::CopyROP, false );
+ if ( srcMask )
+ {
+ bitBlt( TQT_TQPAINTDEVICE(&destMask), 0, 0, KDE_TQBITMAP_TO_TQPAINTDEVICE(srcMask), pbWidth[ i ], 0,
+ pbPixmaps[ i ] ->width() - pbWidth[ i ] * 2, pbWidth[ i ],
+ TQt::CopyROP, false );
+ tmp.setMask( destMask );
+ }
+ pbPixmaps[ i ] ->setBorder( KThemePixmap::Top, tmp );
+
+ bitBlt( TQT_TQPAINTDEVICE(&tmp), 0, 0, TQT_TQPAINTDEVICE(pbPixmaps[ i ]), pbWidth[ i ],
+ pbPixmaps[ i ] ->height() - pbWidth[ i ],
+ pbPixmaps[ i ] ->width() - pbWidth[ i ] * 2, pbWidth[ i ], TQt::CopyROP, false );
+ if ( srcMask )
+ {
+ bitBlt( TQT_TQPAINTDEVICE(&destMask), 0, 0, KDE_TQBITMAP_TO_TQPAINTDEVICE(srcMask), pbWidth[ i ],
+ pbPixmaps[ i ] ->height() - pbWidth[ i ],
+ pbPixmaps[ i ] ->width() - pbWidth[ i ] * 2, pbWidth[ i ], TQt::CopyROP, false );
+ tmp.setMask( destMask );
+ }
+ pbPixmaps[ i ] ->setBorder( KThemePixmap::Bottom, tmp );
+
+ tmp.resize( pbWidth[ i ], pbPixmaps[ i ] ->height() - pbWidth[ i ] * 2 );
+ destMask.resize( pbWidth[ i ], pbPixmaps[ i ] ->height() - pbWidth[ i ] * 2 );
+ bitBlt( TQT_TQPAINTDEVICE(&tmp), 0, 0, TQT_TQPAINTDEVICE(pbPixmaps[ i ]), 0, pbWidth[ i ], pbWidth[ i ],
+ pbPixmaps[ i ] ->height() - pbWidth[ i ] * 2, TQt::CopyROP, false );
+ if ( srcMask )
+ {
+ bitBlt( TQT_TQPAINTDEVICE(&destMask), 0, 0, KDE_TQBITMAP_TO_TQPAINTDEVICE(srcMask), 0, pbWidth[ i ], pbWidth[ i ],
+ pbPixmaps[ i ] ->height() - pbWidth[ i ] * 2, TQt::CopyROP, false );
+ tmp.setMask( destMask );
+ }
+
+ pbPixmaps[ i ] ->setBorder( KThemePixmap::Left, tmp );
+
+ bitBlt( TQT_TQPAINTDEVICE(&tmp), 0, 0, TQT_TQPAINTDEVICE(pbPixmaps[ i ]), pbPixmaps[ i ] ->width() - pbWidth[ i ],
+ pbWidth[ i ], pbWidth[ i ], pbPixmaps[ i ] ->height() - pbWidth[ i ] * 2,
+ TQt::CopyROP, false );
+ if ( srcMask )
+ {
+ bitBlt( TQT_TQPAINTDEVICE(&destMask), 0, 0, KDE_TQBITMAP_TO_TQPAINTDEVICE(srcMask), pbPixmaps[ i ] ->width() - pbWidth[ i ],
+ pbWidth[ i ], pbWidth[ i ], pbPixmaps[ i ] ->height() - pbWidth[ i ] * 2,
+ TQt::CopyROP, false );
+ tmp.setMask( destMask );
+ }
+ pbPixmaps[ i ] ->setBorder( KThemePixmap::Right, tmp );
+ }
+ else
+ tqWarning( "KThemeBase: Tried making border from empty pixmap\n" );
+}
+
+
+void KThemeBase::copyWidgetConfig( int sourceID, int destID, TQString *pixnames,
+ TQString *brdnames )
+{
+ scaleHints[ destID ] = scaleHints[ sourceID ];
+ gradients[ destID ] = gradients[ sourceID ];
+ blends[ destID ] = blends[ sourceID ];
+ bContrasts[ destID ] = bContrasts[ sourceID ];
+ borders[ destID ] = borders[ sourceID ];
+ highlights[ destID ] = highlights[ sourceID ];
+
+ if ( grLowColors[ sourceID ] )
+ grLowColors[ destID ] = new TQColor( *grLowColors[ sourceID ] );
+ else
+ grLowColors[ destID ] = NULL;
+
+ if ( grHighColors[ sourceID ] )
+ grHighColors[ destID ] = new TQColor( *grHighColors[ sourceID ] );
+ else
+ grHighColors[ destID ] = NULL;
+
+ if ( colors[ sourceID ] )
+ colors[ destID ] = new TQColorGroup( *colors[ sourceID ] );
+ else
+ colors[ destID ] = NULL;
+
+ // pixmap
+ pixnames[ destID ] = pixnames[ sourceID ];
+ duplicate[ destID ] = false;
+ pixmaps[ destID ] = NULL;
+ images[ destID ] = NULL;
+ if ( !pixnames[ destID ].isEmpty() )
+ {
+ if ( scaleHints[ sourceID ] == TileScale && blends[ sourceID ] == 0.0 )
+ {
+ pixmaps[ destID ] = pixmaps[ sourceID ];
+ duplicate[ destID ] = true;
+ }
+ if ( !duplicate[ destID ] )
+ {
+ pixmaps[ destID ] = loadPixmap( pixnames[ destID ] );
+ if ( scaleHints[ destID ] == TileScale && blends[ destID ] == 0.0 )
+ images[ destID ] = NULL;
+ else
+ images[ destID ] = loadImage( pixnames[ destID ] );
+ }
+ }
+
+ // border pixmap
+ pbDuplicate[ destID ] = false;
+ pbPixmaps[ destID ] = NULL;
+ pbWidth[ destID ] = pbWidth[ sourceID ];
+ brdnames[ destID ] = brdnames[ sourceID ];
+ if ( !brdnames[ destID ].isEmpty() )
+ {
+ pbPixmaps[ destID ] = pbPixmaps[ sourceID ];
+ pbDuplicate[ destID ] = true;
+ }
+
+ if ( sourceID == ActiveTab && destID == InactiveTab )
+ aTabLine = iTabLine;
+ else if ( sourceID == InactiveTab && destID == ActiveTab )
+ iTabLine = aTabLine;
+}
+
+void KThemeBase::readConfig( TQt::GUIStyle /*style*/ )
+{
+#define PREBLEND_ITEMS 12
+ static const WidgetType preBlend[] =
+ {
+ Slider, IndicatorOn, IndicatorOff,
+ ExIndicatorOn, ExIndicatorOff, HScrollDeco, VScrollDeco, HScrollDecoDown,
+ VScrollDecoDown, ComboDeco, ComboDecoDown, CheckMark
+ };
+
+ int i;
+ TQString tmpStr;
+ TQString pixnames[ WIDGETS ]; // used for duplicate check
+ TQString brdnames[ WIDGETS ];
+ bool loaded[ WIDGETS ]; // used for preloading for CopyWidget
+
+ TQSettings config;
+ if (configDirName.isEmpty() || configDirName == ".")
+ {
+ TDEStyleDirs::dirs()->addToSearch( "themerc", config );
+ }
+ else config.insertSearchPath( TQSettings::Unix, configDirName );
+
+ applyConfigFile( config );
+
+ d->contrast = config.readNumEntry( configFileName + "KDE/contrast", 7 );
+
+
+
+ for ( i = 0; i < INHERIT_ITEMS; ++i )
+ applyResourceGroup( &config, i );
+ for ( ; i < INHERIT_ITEMS*2; ++i )
+ {
+ if ( config.entryList( configFileName + widgetEntries[ i ] ).size() )
+ applyResourceGroup( &config, i );
+#ifndef Q_WS_QWS //FIXME
+
+ else
+ {
+ Prop& copyProp = d->props[ widgetEntries[ i ] ];
+ copyProp[ "CopyWidget" ] = TQString( widgetEntries[ i - INHERIT_ITEMS ] );
+ }
+#endif
+
+ }
+ for ( ; i < WIDGETS; ++i )
+ applyResourceGroup( &config, i );
+ applyMiscResourceGroup( &config );
+
+ // initialize defaults that may not be read
+ for ( i = 0; i < WIDGETS; ++i )
+ loaded[ i ] = false;
+ btnXShift = btnYShift = focus3DOffset = 0;
+ aTabLine = iTabLine = true;
+ roundedButton = roundedCombo = roundedSlider = focus3D = false;
+ splitterWidth = 10;
+
+ //Handle the rotated background separately..
+ d->props[ widgetEntries[ RotSliderGroove ] ] = d->props[ widgetEntries[ SliderGroove ] ];
+ d->props[ widgetEntries[ RotInactiveTab ] ] = d->props[ widgetEntries[ InactiveTab ] ];
+ d->props[ widgetEntries[ RotActiveTab ] ] = d->props[ widgetEntries[ ActiveTab ] ];
+
+ // misc items
+ readMiscResourceGroup();
+
+
+ for ( i = 0; i < WIDGETS; ++i )
+ readResourceGroup( i, pixnames, brdnames, loaded );
+
+ if ( pixmaps[ RotSliderGroove ] )
+ {
+ TQWMatrix r270; //TODO: 90 if reverse?
+ r270.rotate( 270 );
+ KThemePixmap* bf = new KThemePixmap( pixmaps[ RotSliderGroove ], pixmaps[ RotSliderGroove ] ->xForm( r270 ) ); //
+ pixmaps[ RotSliderGroove ] = bf;
+ if ( images[ RotSliderGroove ] )
+ {
+ delete images[ RotSliderGroove ];
+ images[ RotSliderGroove ] = new TQImage( bf->convertToImage() );
+ }
+ }
+
+ if ( pixmaps[ RotActiveTab ] )
+ {
+ TQWMatrix r180;
+ r180.rotate( 180 );
+ KThemePixmap* bf = new KThemePixmap( pixmaps[ RotActiveTab ], pixmaps[ RotActiveTab ] ->xForm( r180 ) );
+
+ pixmaps[ RotActiveTab ] = bf;
+ if ( images[ RotActiveTab ] )
+ {
+ delete images[ RotActiveTab ];
+ images[ RotActiveTab ] = new TQImage( bf->convertToImage() );
+ }
+ }
+
+ if ( pixmaps[ RotInactiveTab ] )
+ {
+ TQWMatrix r180;
+ r180.rotate( 180 );
+ KThemePixmap* bf = new KThemePixmap( pixmaps[ RotInactiveTab ], pixmaps[ RotInactiveTab ] ->xForm( r180 ) );
+
+ pixmaps[ RotInactiveTab ] = bf;
+ if ( images[ RotInactiveTab ] )
+ {
+ delete images[ RotInactiveTab ];
+ images[ RotInactiveTab ] = new TQImage( bf->convertToImage() );
+ }
+ }
+
+ // Handle preblend items
+ for ( i = 0; i < PREBLEND_ITEMS; ++i )
+ {
+ if ( pixmaps[ preBlend[ i ] ] != NULL && blends[ preBlend[ i ] ] != 0.0 )
+ blend( preBlend[ i ] );
+ }
+
+ d->props.clear();
+}
+
+KThemeBase::KThemeBase( const TQString& dir, const TQString & configFile )
+ : TDEStyle( FilledFrameWorkaround ), configFileName( configFile )
+{
+ d = new KThemeBasePrivate;
+ if ( configFileName.isEmpty() )
+ configFileName = "tdestylerc";
+
+
+ configDirName = dir;
+ //Strip of rc from the configFileName
+ if ( configFileName.endsWith( "rc" ) )
+ {
+ configFileName.truncate( configFileName.length() - 2 ); //Get rid of rc..
+ }
+ //else SCREAM!!
+
+
+ configFileName = "/" + configFileName + "/";
+
+ readConfig( TQt::WindowsStyle );
+ cache = new KThemeCache( cacheSize );
+
+ switch ( scrollBarLayout() )
+ {
+ case SBBottomLeft:
+ setScrollBarType( NextStyleScrollBar );
+ break;
+ case SBBottomRight:
+ setScrollBarType( PlatinumStyleScrollBar );
+ break;
+ case SBOpposite:
+ break;
+ //Do nothing, this type already set..
+ }
+ ;
+}
+
+void KThemeBase::applyConfigFile( TQSettings& config )
+{
+ TQStringList keys = config.entryList( configFileName );
+
+ if ( keys.contains( "foreground" ) )
+ {
+ d->overrideForeground = true;
+ d->overrideForegroundCol = readColorEntry( &config, ( configFileName + "foreground" ).latin1(), 0 );
+ }
+ else
+ d->overrideForeground = false;
+
+ if ( keys.contains( "background" ) )
+ {
+ d->overrideBackground = true;
+ d->overrideBackgroundCol = readColorEntry( &config, ( configFileName + "background" ).latin1(), 0 );
+ }
+ else
+ d->overrideBackground = false;
+
+
+
+ if ( keys.contains( "selectForeground" ) )
+ {
+ d->overrideSelectForeground = true;
+ d->overrideSelectForegroundCol = readColorEntry( &config, ( configFileName + "selectForeground" ).latin1(), 0 );
+ }
+ else
+ d->overrideSelectForeground = false;
+
+ if ( keys.contains( "selectBackground" ) )
+ {
+ d->overrideSelectBackground = true;
+ d->overrideSelectBackgroundCol = readColorEntry( &config, ( configFileName + "selectBackground" ).latin1(), 0 );
+ }
+ else
+ d->overrideSelectBackground = false;
+
+ if ( keys.contains( "windowBackground" ) )
+ {
+ d->overrideWindowBackground = true;
+ d->overrideWindowBackgroundCol = readColorEntry( &config, ( configFileName + "windowBackground" ).latin1(), 0 );
+ }
+ else
+ d->overrideWindowBackground = false;
+
+
+ if ( keys.contains( "windowForeground" ) )
+ {
+ d->overrideWindowForeground = true;
+ d->overrideWindowForegroundCol = readColorEntry( &config, ( configFileName + "windowForeground" ).latin1(), 0 );
+ }
+ else
+ d->overrideWindowForeground = false;
+
+
+#ifndef Q_WS_QWS //FIXME
+
+ for ( int input = 0; input < WIDGETS; ++input )
+ {
+ d->props.erase( widgetEntries[ input ] );
+ }
+ d->props.erase( "Misc" );
+#endif
+}
+
+KThemeBase::~KThemeBase()
+{
+ int i;
+ for ( i = 0; i < WIDGETS; ++i )
+ {
+ if ( !duplicate[ i ] )
+ {
+ if ( images[ i ] )
+ delete images[ i ];
+ if ( pixmaps[ i ] )
+ delete pixmaps[ i ];
+ }
+ if ( !pbDuplicate[ i ] && pbPixmaps[ i ] )
+ delete pbPixmaps[ i ];
+ if ( colors[ i ] )
+ delete( colors[ i ] );
+ if ( grLowColors[ i ] )
+ delete( grLowColors[ i ] );
+ if ( grHighColors[ i ] )
+ delete( grHighColors[ i ] );
+ }
+ TDEStyleDirs::release();
+ delete cache;
+ delete d;
+}
+
+TQImage* KThemeBase::loadImage( const TQString &name )
+{
+ TQImage * image = new TQImage;
+ TQString path = TDEStyleDirs::dirs()->findResource( "themepixmap",name );
+ image->load( path );
+ if ( !image->isNull() )
+ return ( image );
+ tqWarning( "KThemeBase: Unable to load image %s\n", name.latin1() );
+ delete image;
+ return ( NULL );
+}
+
+KThemePixmap* KThemeBase::loadPixmap( const TQString &name )
+{
+ KThemePixmap * pixmap = new KThemePixmap( false );
+ TQString path = TDEStyleDirs::dirs()->findResource( "themepixmap", name );
+ pixmap->load( path );
+ if ( !pixmap->isNull() )
+ return pixmap;
+ tqWarning( "KThemeBase: Unable to load pixmap %s\n", name.latin1() );
+ delete pixmap;
+ return ( NULL );
+}
+
+
+KThemePixmap* KThemeBase::scale( int w, int h, WidgetType widget ) const
+{
+ if ( scaleHints[ widget ] == FullScale )
+ {
+ if ( !pixmaps[ widget ] || pixmaps[ widget ] ->width() != w ||
+ pixmaps[ widget ] ->height() != h )
+ {
+ KThemePixmap * cachePix = cache->pixmap( w, h, widget );
+ if ( cachePix )
+ {
+ cachePix = new KThemePixmap( *cachePix );
+ if ( pixmaps[ widget ] )
+ cache->insert( pixmaps[ widget ], KThemeCache::FullScale,
+ widget );
+ else
+ tqWarning( "We would have inserted a null pixmap!\n" );
+ pixmaps[ widget ] = cachePix;
+ }
+ else
+ {
+ cache->insert( pixmaps[ widget ], KThemeCache::FullScale, widget );
+ TQImage tmpImg = images[ widget ] ->smoothScale( w, h );
+ pixmaps[ widget ] = new KThemePixmap;
+ pixmaps[ widget ] ->convertFromImage( tmpImg );
+ if ( blends[ widget ] != 0.0 )
+ blend( widget );
+ }
+ }
+ }
+ else if ( scaleHints[ widget ] == HorizontalScale )
+ {
+ if ( pixmaps[ widget ] ->width() != w )
+ {
+ KThemePixmap * cachePix = cache->horizontalPixmap( w, widget );
+ if ( cachePix )
+ {
+ cachePix = new KThemePixmap( *cachePix );
+ if ( pixmaps[ widget ] )
+ cache->insert( pixmaps[ widget ], KThemeCache::HorizontalScale, widget );
+ else
+ tqWarning( "We would have inserted a null pixmap!\n" );
+ pixmaps[ widget ] = cachePix;
+ }
+ else
+ {
+ cache->insert( pixmaps[ widget ], KThemeCache::HorizontalScale, widget );
+ TQImage tmpImg = images[ widget ] ->
+ smoothScale( w, images[ widget ] ->height() );
+ pixmaps[ widget ] = new KThemePixmap;
+ pixmaps[ widget ] ->convertFromImage( tmpImg );
+ if ( blends[ widget ] != 0.0 )
+ blend( widget );
+ }
+ }
+ }
+ else if ( scaleHints[ widget ] == VerticalScale )
+ {
+ if ( pixmaps[ widget ] ->height() != h )
+ {
+ KThemePixmap * cachePix = cache->verticalPixmap( w, widget );
+ if ( cachePix )
+ {
+ cachePix = new KThemePixmap( *cachePix );
+ if ( pixmaps[ widget ] )
+ cache->insert( pixmaps[ widget ], KThemeCache::VerticalScale, widget );
+ else
+ tqWarning( "We would have inserted a null pixmap!\n" );
+ pixmaps[ widget ] = cachePix;
+ }
+ else
+ {
+ cache->insert( pixmaps[ widget ], KThemeCache::VerticalScale, widget );
+ TQImage tmpImg =
+ images[ widget ] ->smoothScale( images[ widget ] ->width(), h );
+ pixmaps[ widget ] = new KThemePixmap;
+ pixmaps[ widget ] ->convertFromImage( tmpImg );
+ if ( blends[ widget ] != 0.0 )
+ blend( widget );
+ }
+ }
+ }
+ // If blended tile here so the blend is scaled properly
+ else if ( scaleHints[ widget ] == TileScale && blends[ widget ] != 0.0 )
+ {
+ if ( !pixmaps[ widget ] || pixmaps[ widget ] ->width() != w ||
+ pixmaps[ widget ] ->height() != h )
+ {
+ KThemePixmap * cachePix = cache->pixmap( w, h, widget );
+ if ( cachePix )
+ {
+ cachePix = new KThemePixmap( *cachePix );
+ cache->insert( pixmaps[ widget ], KThemeCache::FullScale, widget );
+ pixmaps[ widget ] = cachePix;
+ }
+ else
+ {
+ cache->insert( pixmaps[ widget ], KThemeCache::FullScale, widget );
+ TQPixmap tile;
+ tile.convertFromImage( *images[ widget ] );
+ pixmaps[ widget ] = new KThemePixmap;
+ pixmaps[ widget ] ->resize( w, h );
+ TQPainter p( pixmaps[ widget ] );
+ p.drawTiledPixmap( 0, 0, w, h, tile );
+ if ( blends[ widget ] != 0.0 )
+ blend( widget );
+ }
+ }
+ }
+ return ( pixmaps[ widget ] );
+}
+
+KThemePixmap* KThemeBase::scaleBorder( int w, int h, WidgetType widget ) const
+{
+ KThemePixmap * pixmap = NULL;
+ if ( !pbPixmaps[ widget ] && !pbWidth[ widget ] )
+ return ( NULL );
+ pixmap = cache->pixmap( w, h, widget, true );
+ if ( pixmap )
+ {
+ pixmap = new KThemePixmap( *pixmap );
+ }
+ else
+ {
+ pixmap = new KThemePixmap();
+ pixmap->resize( w, h );
+ TQBitmap mask;
+ mask.resize( w, h );
+ mask.fill( color0 );
+ TQPainter mPainter;
+ mPainter.begin( &mask );
+
+ TQPixmap *tmp = borderPixmap( widget ) ->border( KThemePixmap::TopLeft );
+ const TQBitmap *srcMask = tmp->mask();
+ int bdWidth = tmp->width();
+
+ bitBlt( TQT_TQPAINTDEVICE(pixmap), 0, 0, TQT_TQPAINTDEVICE(tmp), 0, 0, bdWidth, bdWidth,
+ TQt::CopyROP, false );
+ if ( srcMask )
+ bitBlt( TQT_TQPAINTDEVICE(&mask), 0, 0, KDE_TQBITMAP_TO_TQPAINTDEVICE(srcMask), 0, 0, bdWidth, bdWidth,
+ TQt::CopyROP, false );
+ else
+ mPainter.fillRect( 0, 0, bdWidth, bdWidth, color1 );
+
+
+ tmp = borderPixmap( widget ) ->border( KThemePixmap::TopRight );
+ srcMask = tmp->mask();
+ bitBlt( TQT_TQPAINTDEVICE(pixmap), w - bdWidth, 0, TQT_TQPAINTDEVICE(tmp), 0, 0, bdWidth,
+ bdWidth, TQt::CopyROP, false );
+ if ( srcMask )
+ bitBlt( TQT_TQPAINTDEVICE(&mask), w - bdWidth, 0, KDE_TQBITMAP_TO_TQPAINTDEVICE(srcMask), 0, 0, bdWidth,
+ bdWidth, TQt::CopyROP, false );
+ else
+ mPainter.fillRect( w - bdWidth, 0, bdWidth, bdWidth, color1 );
+
+ tmp = borderPixmap( widget ) ->border( KThemePixmap::BottomLeft );
+ srcMask = tmp->mask();
+ bitBlt( TQT_TQPAINTDEVICE(pixmap), 0, h - bdWidth, TQT_TQPAINTDEVICE(tmp), 0, 0, bdWidth,
+ bdWidth, TQt::CopyROP, false );
+ if ( srcMask )
+ bitBlt( TQT_TQPAINTDEVICE(&mask), 0, h - bdWidth, KDE_TQBITMAP_TO_TQPAINTDEVICE(srcMask), 0, 0, bdWidth,
+ bdWidth, TQt::CopyROP, false );
+ else
+ mPainter.fillRect( 0, h - bdWidth, bdWidth, bdWidth, color1 );
+
+ tmp = borderPixmap( widget ) ->border( KThemePixmap::BottomRight );
+ srcMask = tmp->mask();
+ bitBlt( TQT_TQPAINTDEVICE(pixmap), w - bdWidth, h - bdWidth, TQT_TQPAINTDEVICE(tmp), 0, 0,
+ bdWidth, bdWidth, TQt::CopyROP, false );
+ if ( srcMask )
+ bitBlt( TQT_TQPAINTDEVICE(&mask), w - bdWidth, h - bdWidth, KDE_TQBITMAP_TO_TQPAINTDEVICE(srcMask), 0, 0,
+ bdWidth, bdWidth, TQt::CopyROP, false );
+ else
+ mPainter.fillRect( w - bdWidth, h - bdWidth, bdWidth, bdWidth, color1 );
+
+ TQPainter p;
+ p.begin( pixmap );
+ if ( w - bdWidth * 2 > 0 )
+ {
+ tmp = borderPixmap( widget ) ->border( KThemePixmap::Top );
+ srcMask = tmp->mask();
+ p.drawTiledPixmap( bdWidth, 0, w - bdWidth * 2, bdWidth, *tmp );
+ if ( srcMask )
+ bitBlt( TQT_TQPAINTDEVICE(&mask), bdWidth, 0, KDE_TQBITMAP_TO_TQPAINTDEVICE(srcMask), 0, 0,
+ w - bdWidth * 2, bdWidth, TQt::CopyROP, false );
+ else
+ mPainter.fillRect( bdWidth, 0, w - bdWidth * 2, bdWidth, color1 );
+
+ tmp = borderPixmap( widget ) ->border( KThemePixmap::Bottom );
+ srcMask = tmp->mask();
+ p.drawTiledPixmap( bdWidth, h - bdWidth, w - bdWidth * 2, bdWidth,
+ *tmp );
+ if ( srcMask )
+ bitBlt( TQT_TQPAINTDEVICE(&mask), bdWidth, h - bdWidth, KDE_TQBITMAP_TO_TQPAINTDEVICE(srcMask), 0, 0,
+ w - bdWidth * 2, bdWidth, TQt::CopyROP, false );
+ else
+ mPainter.fillRect( bdWidth, h - bdWidth, w - bdWidth * 2, bdWidth,
+ color1 );
+ }
+ if ( h - bdWidth * 2 > 0 )
+ {
+ tmp = borderPixmap( widget ) ->border( KThemePixmap::Left );
+ srcMask = tmp->mask();
+ p.drawTiledPixmap( 0, bdWidth, bdWidth, h - bdWidth * 2, *tmp );
+ if ( srcMask )
+ bitBlt( TQT_TQPAINTDEVICE(&mask), 0, bdWidth, KDE_TQBITMAP_TO_TQPAINTDEVICE(srcMask), 0, 0,
+ bdWidth, h - bdWidth * 2, TQt::CopyROP, false );
+ else
+ mPainter.fillRect( 0, bdWidth, bdWidth, h - bdWidth * 2, color1 );
+
+ tmp = borderPixmap( widget ) ->border( KThemePixmap::Right );
+ srcMask = tmp->mask();
+ p.drawTiledPixmap( w - bdWidth, bdWidth, bdWidth, h - bdWidth * 2,
+ *tmp );
+ if ( srcMask )
+ bitBlt( TQT_TQPAINTDEVICE(&mask), w - bdWidth, bdWidth, KDE_TQBITMAP_TO_TQPAINTDEVICE(srcMask), 0, 0,
+ bdWidth, h - bdWidth * 2, TQt::CopyROP, false );
+ else
+ mPainter.fillRect( w - bdWidth, bdWidth, bdWidth, h - bdWidth * 2, color1 );
+ }
+ p.end();
+ mPainter.end();
+ pixmap->setMask( mask );
+ cache->insert( pixmap, KThemeCache::FullScale, widget, true );
+ if ( !pixmap->mask() )
+ tqWarning( "No mask for border pixmap!\n" );
+ }
+ return ( pixmap );
+}
+
+
+KThemePixmap* KThemeBase::blend( WidgetType widget ) const
+{
+ KPixmapEffect::GradientType g;
+ switch ( gradients[ widget ] )
+ {
+ case GrHorizontal:
+ g = KPixmapEffect::HorizontalGradient;
+ break;
+ case GrVertical:
+ g = KPixmapEffect::VerticalGradient;
+ break;
+ case GrPyramid:
+ g = KPixmapEffect::PyramidGradient;
+ break;
+ case GrRectangle:
+ g = KPixmapEffect::RectangleGradient;
+ break;
+ case GrElliptic:
+ g = KPixmapEffect::EllipticGradient;
+ break;
+ default:
+ g = KPixmapEffect::DiagonalGradient;
+ break;
+ }
+ KPixmapEffect::blend( *pixmaps[ widget ], blends[ widget ], *grLowColors[ widget ],
+ g, false );
+ return ( pixmaps[ widget ] );
+}
+
+KThemePixmap* KThemeBase::gradient( int w, int h, WidgetType widget ) const
+{
+ if ( gradients[ widget ] == GrVertical )
+ {
+ if ( !pixmaps[ widget ] || pixmaps[ widget ] ->height() != h )
+ {
+ KThemePixmap * cachePix = cache->verticalPixmap( h, widget );
+ if ( cachePix )
+ {
+ cachePix = new KThemePixmap( *cachePix );
+ if ( pixmaps[ widget ] )
+ cache->insert( pixmaps[ widget ], KThemeCache::VerticalScale,
+ widget );
+ pixmaps[ widget ] = cachePix;
+ }
+ else
+ {
+ if ( pixmaps[ widget ] )
+ cache->insert( pixmaps[ widget ], KThemeCache::VerticalScale,
+ widget );
+ pixmaps[ widget ] = new KThemePixmap;
+ pixmaps[ widget ] ->resize( w, h );
+ KPixmapEffect::gradient( *pixmaps[ widget ], *grHighColors[ widget ],
+ *grLowColors[ widget ],
+ KPixmapEffect::VerticalGradient );
+ }
+ }
+ }
+ else if ( gradients[ widget ] == GrHorizontal )
+ {
+ if ( !pixmaps[ widget ] || pixmaps[ widget ] ->width() != w )
+ {
+ KThemePixmap * cachePix = cache->horizontalPixmap( w, widget );
+ if ( cachePix )
+ {
+ cachePix = new KThemePixmap( *cachePix );
+ if ( pixmaps[ widget ] )
+ cache->insert( pixmaps[ widget ],
+ KThemeCache::HorizontalScale, widget );
+ pixmaps[ widget ] = cachePix;
+ }
+ else
+ {
+ if ( pixmaps[ widget ] )
+ cache->insert( pixmaps[ widget ],
+ KThemeCache::HorizontalScale, widget );
+ pixmaps[ widget ] = new KThemePixmap;
+ pixmaps[ widget ] ->resize( w, h );
+ KPixmapEffect::gradient( *pixmaps[ widget ], *grHighColors[ widget ],
+ *grLowColors[ widget ],
+ KPixmapEffect::HorizontalGradient );
+ }
+ }
+ }
+ else if ( gradients[ widget ] == GrReverseBevel )
+ {
+ if ( !pixmaps[ widget ] || pixmaps[ widget ] ->width() != w ||
+ pixmaps[ widget ] ->height() != h )
+ {
+ KThemePixmap * cachePix = cache->pixmap( w, h, widget );
+ if ( cachePix )
+ {
+ cachePix = new KThemePixmap( *cachePix );
+ if ( pixmaps[ widget ] )
+ cache->insert( pixmaps[ widget ], KThemeCache::FullScale,
+ widget );
+ pixmaps[ widget ] = cachePix;
+ }
+ else
+ {
+ if ( pixmaps[ widget ] )
+ cache->insert( pixmaps[ widget ], KThemeCache::FullScale,
+ widget );
+ pixmaps[ widget ] = new KThemePixmap;
+ pixmaps[ widget ] ->resize( w, h );
+
+ KPixmap s;
+ int offset = decoWidth( widget );
+ s.resize( w - offset * 2, h - offset * 2 );
+ TQColor lc( *grLowColors[ widget ] );
+ TQColor hc( *grHighColors[ widget ] );
+ if ( bevelContrast( widget ) )
+ {
+ int bc = bevelContrast( widget );
+ // want single increments, not factors like light()/dark()
+ lc.setRgb( lc.red() - bc, lc.green() - bc, lc.blue() - bc );
+ hc.setRgb( hc.red() + bc, hc.green() + bc, hc.blue() + bc );
+ }
+ KPixmapEffect::gradient( *pixmaps[ widget ],
+ lc, hc,
+ KPixmapEffect::DiagonalGradient );
+ KPixmapEffect::gradient( s, *grHighColors[ widget ],
+ *grLowColors[ widget ],
+ KPixmapEffect::DiagonalGradient );
+ bitBlt( pixmaps[ widget ], offset, offset, &s, 0, 0, w - offset * 2,
+ h - offset * 2, TQt::CopyROP );
+ }
+ }
+ }
+ else
+ {
+ KPixmapEffect::GradientType g;
+ switch ( gradients[ widget ] )
+ {
+ case GrPyramid:
+ g = KPixmapEffect::PyramidGradient;
+ break;
+ case GrRectangle:
+ g = KPixmapEffect::RectangleGradient;
+ break;
+ case GrElliptic:
+ g = KPixmapEffect::EllipticGradient;
+ break;
+ default:
+ g = KPixmapEffect::DiagonalGradient;
+ break;
+ }
+ if ( !pixmaps[ widget ] || pixmaps[ widget ] ->width() != w ||
+ pixmaps[ widget ] ->height() != h )
+ {
+ KThemePixmap * cachePix = cache->pixmap( w, h, widget );
+ if ( cachePix )
+ {
+ cachePix = new KThemePixmap( *cachePix );
+ if ( pixmaps[ widget ] )
+ cache->insert( pixmaps[ widget ], KThemeCache::FullScale,
+ widget );
+ pixmaps[ widget ] = cachePix;
+ }
+ else
+ {
+ if ( pixmaps[ widget ] )
+ cache->insert( pixmaps[ widget ], KThemeCache::FullScale,
+ widget );
+ pixmaps[ widget ] = new KThemePixmap;
+ pixmaps[ widget ] ->resize( w, h );
+ KPixmapEffect::gradient( *pixmaps[ widget ], *grHighColors[ widget ],
+ *grLowColors[ widget ], g );
+ }
+ }
+ }
+ return ( pixmaps[ widget ] );
+}
+
+KThemePixmap* KThemeBase::scalePixmap( int w, int h, WidgetType widget ) const
+{
+
+ if ( gradients[ widget ] && blends[ widget ] == 0.0 )
+ return ( gradient( w, h, widget ) );
+
+ return ( scale( w, h, widget ) );
+}
+
+TQColorGroup* KThemeBase::makeColorGroup( const TQColor &fg, const TQColor &bg,
+ TQt::GUIStyle )
+{
+ if ( shading == Motif )
+ {
+ int highlightVal, lowlightVal;
+ highlightVal = 100 + ( 2 * d->contrast + 4 ) * 16 / 10;
+ lowlightVal = 100 + ( ( 2 * d->contrast + 4 ) * 10 );
+ return ( new TQColorGroup( fg, bg, bg.light( highlightVal ),
+ bg.dark( lowlightVal ), bg.dark( 120 ),
+ fg, TQApplication::palette().active().base() ) );
+ }
+ else
+ return ( new TQColorGroup( fg, bg, bg.light( 150 ), bg.dark(),
+ bg.dark( 120 ), fg,
+ TQApplication::palette().active().base() ) );
+}
+
+
+void KThemeBase::applyMiscResourceGroup( TQSettings *config )
+{
+#ifndef Q_WS_QWS //FIXME
+ d->props.erase( "Misc" ); // clear the old property
+
+ TQString base = configFileName + "Misc/";
+
+ Prop& prop = d->props[ "Misc" ];
+ TQString tmpStr;
+
+ tmpStr = config->readEntry( base + "SButtonPosition" );
+ if ( tmpStr == "BottomLeft" )
+ prop[ "SButtonPosition" ] = TQString::number( ( int ) SBBottomLeft );
+ else if ( tmpStr == "BottomRight" )
+ prop[ "SButtonPosition" ] = TQString::number( ( int ) SBBottomRight );
+ else
+ {
+ if ( tmpStr != "Opposite" && !tmpStr.isEmpty() )
+ tqWarning( "KThemeBase: Unrecognized sb button option %s, using Opposite.\n", tmpStr.latin1() );
+ ;
+ prop[ "SButtonPosition" ] = TQString::number( ( int ) SBOpposite );
+ }
+ tmpStr = config->readEntry( base + "ArrowType" );
+ if ( tmpStr == "Small" )
+ prop[ "ArrowType" ] = TQString::number( ( int ) SmallArrow );
+ else if ( tmpStr == "3D" )
+ prop[ "ArrowType" ] = TQString::number( ( int ) MotifArrow );
+ else
+ {
+ if ( tmpStr != "Normal" && !tmpStr.isEmpty() )
+ tqWarning( "KThemeBase: Unrecognized arrow option %s, using Normal.\n", tmpStr.latin1() );
+ prop[ "ArrowType" ] = TQString::number( ( int ) LargeArrow );
+ }
+ tmpStr = config->readEntry( base + "ShadeStyle" );
+ if ( tmpStr == "Motif" )
+ prop[ "ShadeStyle" ] = TQString::number( ( int ) Motif );
+ else if ( tmpStr == "Next" )
+ prop[ "ShadeStyle" ] = TQString::number( ( int ) Next );
+ else if ( tmpStr == "KDE" )
+ prop[ "ShadeStyle" ] = TQString::number( ( int ) KDE );
+ else
+ prop[ "ShadeStyle" ] = TQString::number( ( int ) Windows );
+
+ prop[ "FrameWidth" ] = TQString::number( config->readNumEntry( base + "FrameWidth", 2 ) );
+ prop[ "Cache" ] = TQString::number( config->readNumEntry( base + "Cache", 1024 ) );
+ prop[ "ScrollBarExtent" ] = TQString::number( config->readNumEntry( base + "ScrollBarExtent", 16 ) );
+#endif
+}
+
+static int readNumEntry( Prop& prop, TQString setting, int def )
+{
+ bool ok;
+ TQString s_val = prop[ setting ];
+ int val = s_val.toInt( &ok );
+ if ( ok )
+ return val;
+ return def;
+}
+
+static TQColor readColorEntry( Prop& prop, TQString setting, const TQColor& def )
+{
+ TQString s_val = prop[ setting ];
+ if ( !s_val.isEmpty() )
+ {
+ TQColor c( s_val );
+ return c;
+ }
+ return def;
+}
+
+void KThemeBase::readMiscResourceGroup()
+{
+#ifndef Q_WS_QWS //FIXME
+ Prop & prop = d->props[ "Misc" ];
+
+ sbPlacement = ( SButton ) readNumEntry( prop, "SButtonPosition",
+ ( int ) SBOpposite );
+ arrowStyle = ( ArrowStyle ) readNumEntry( prop, "ArrowType",
+ ( int ) LargeArrow );
+ shading = ( ShadeStyle ) readNumEntry( prop, "ShadeStyle", ( int ) Windows );
+ defaultFrame = readNumEntry( prop, "FrameWidth", 2 );
+ cacheSize = readNumEntry( prop, "Cache", 1024 );
+ sbExtent = readNumEntry( prop, "ScrollBarExtent", 16 );
+#endif
+}
+
+
+void KThemeBase::applyResourceGroup( TQSettings *config, int i )
+{
+#ifndef Q_WS_QWS //FIXME
+ TQString tmpStr;
+ int tmpVal;
+
+ // clear the old property
+ d->props.erase( widgetEntries[ i ] );
+
+ TQString base = configFileName + widgetEntries[ i ] + "/";
+
+ Prop& prop = d->props[ widgetEntries[ i ] ];
+
+ tmpStr = config->readEntry( base + "CopyWidget", "" );
+ prop[ "CopyWidget" ] = tmpStr;
+ if ( !tmpStr.isEmpty() )
+ {
+ return ;
+ }
+
+ tmpStr = config->readEntry( base + "Scale" );
+ if ( tmpStr == "Full" )
+ tmpVal = ( int ) FullScale;
+ else if ( tmpStr == "Horizontal" )
+ tmpVal = ( int ) HorizontalScale;
+ else if ( tmpStr == "Vertical" )
+ tmpVal = ( int ) VerticalScale;
+ else
+ {
+ if ( tmpStr != "Tile" && !tmpStr.isEmpty() )
+ tqWarning( "KThemeBase: Unrecognized scale option %s, using Tile.\n", tmpStr.latin1() );
+ tmpVal = ( int ) TileScale;
+ }
+ prop[ "ScaleHint" ] = TQString::number( tmpVal );
+
+ // Gradient type
+ tmpStr = config->readEntry( base + "Gradient" );
+ if ( tmpStr == "Diagonal" )
+ tmpVal = ( int ) GrDiagonal;
+ else if ( tmpStr == "Horizontal" )
+ tmpVal = ( int ) GrHorizontal;
+ else if ( tmpStr == "Vertical" )
+ tmpVal = ( int ) GrVertical;
+ else if ( tmpStr == "Pyramid" )
+ tmpVal = ( int ) GrPyramid;
+ else if ( tmpStr == "Rectangle" )
+ tmpVal = ( int ) GrRectangle;
+ else if ( tmpStr == "Elliptic" )
+ tmpVal = ( int ) GrElliptic;
+ else if ( tmpStr == "ReverseBevel" )
+ tmpVal = ( int ) GrReverseBevel;
+ else
+ {
+ if ( tmpStr != "None" && !tmpStr.isEmpty() )
+ tqWarning( "KThemeBase: Unrecognized gradient option %s, using None.\n", tmpStr.latin1() );
+ tmpVal = ( int ) GrNone;
+ }
+ prop[ "Gradient" ] = TQString::number( tmpVal );
+
+ // Blend intensity
+ tmpStr.setNum( config->readDoubleEntry( base + "BlendIntensity", 0.0 ) );
+ prop[ "Blend" ] = tmpStr;
+
+ // Bevel contrast
+ prop[ "BContrast" ] = TQString::number( config->readNumEntry( base + "BevelContrast", 0 ) );
+
+ // Border width
+ prop[ "Border" ] = TQString::number( config->readNumEntry( base + "Border", 1 ) );
+
+ // Highlight width
+ prop[ "Highlight" ] = TQString::number( config->readNumEntry( base + "Highlight", 1 ) );
+
+ TQStringList keys = config->entryList( base );
+
+ // Gradient low color or blend background
+ if ( keys.contains( "GradientLow" ) )
+ prop[ "GrLow" ] = readColorEntry( config, TQString( base + "GradientLow" ).latin1(),
+ &TQApplication::palette().active().background() ).name();
+
+ // Gradient high color
+ if ( keys.contains( "GradientHigh" ) )
+ prop[ "GrHigh" ] = readColorEntry( config, TQString( base + "GradientHigh" ).latin1(),
+ &TQApplication::palette().active().foreground() ).name();
+
+ // Extended color attributes
+ if ( keys.contains( "Foreground" ) || keys.contains( "Background" ) )
+ {
+ TQColor fg, bg;
+ if ( keys.contains( "Background" ) )
+ bg = readColorEntry( config, TQString( base + "Background" ).latin1(), &bg );
+ if ( keys.contains( "Foreground" ) )
+ fg = readColorEntry( config, TQString( base + "Foreground" ).latin1(), &fg );
+ prop[ "Foreground" ] = fg.name();
+ prop[ "Background" ] = bg.name();
+
+ }
+ else
+ colors[ i ] = NULL;
+
+ // Pixmap
+ tmpStr = config->readEntry( base + "Pixmap", "" );
+ if ( !tmpStr.isEmpty() )
+ prop[ "Pixmap" ] = tmpStr;
+ // Pixmap border
+ tmpStr = config->readEntry( base + "PixmapBorder", "" );
+ if ( !tmpStr.isEmpty() )
+ {
+ prop[ "PixmapBorder" ] = tmpStr;
+ prop[ "PixmapBWidth" ] = TQString::number(
+ config->readNumEntry( base + "PixmapBWidth", 0 ) );
+ }
+
+ // Various widget specific settings. This was more efficient when bunched
+ // together in the misc group, but this makes an easier to read config.
+ if ( i == SliderGroove )
+ prop[ "SmallGroove" ] = TQString::number(
+ config->readBoolEntry( base + "SmallGroove", false ) );
+ else if ( i == ActiveTab || i == InactiveTab )
+ prop[ "BottomLine" ] = TQString::number(
+ config->readBoolEntry( base + "BottomLine", true ) );
+ else if ( i == Splitter )
+ prop[ "Width" ] = TQString::number( config->readNumEntry( base + "Width", 10 ) );
+ else if ( i == ComboBox || i == ComboBoxDown )
+ {
+ if ( keys.contains( "Round" ) )
+ prop[ "Round" ] = TQString::number( config->readBoolEntry( base + "Round", false ) );
+ else
+ prop[ "Round" ] = "5000"; // invalid, used w/multiple groups
+
+ }
+ else if ( i == PushButton || i == PushButtonDown )
+ {
+ if ( keys.contains( "XShift" ) )
+ prop[ "XShift" ] = TQString::number( config->readNumEntry( base + "XShift", 0 ) );
+ else
+ prop[ "XShift" ] = "5000";
+ if ( keys.contains( "YShift" ) )
+ prop[ "YShift" ] = TQString::number( config->readNumEntry( base + "YShift", 0 ) );
+ else
+ prop[ "YShift" ] = "5000";
+ if ( keys.contains( "3DFocusRect" ) )
+ prop[ "3DFRect" ] = TQString::number( config->
+ readBoolEntry( base + "3DFocusRect", false ) );
+ else
+ prop[ "3DFRect" ] = "5000";
+ if ( keys.contains( "3DFocusOffset" ) )
+ prop[ "3DFOffset" ] = TQString::number( config->
+ readBoolEntry( base + "3DFocusOffset", 0 ) );
+ else
+ prop[ "3DFOffset" ] = "5000";
+ if ( keys.contains( "Round" ) )
+ prop[ "Round" ] = TQString::number( config->readBoolEntry( base + "Round", false ) );
+ else
+ prop[ "Round" ] = "5000";
+ }
+#endif
+}
+
+void KThemeBase::readResourceGroup( int i, TQString *pixnames, TQString *brdnames,
+ bool *loadArray )
+{
+#ifndef Q_WS_QWS //FIXME
+ if ( loadArray[ i ] == true )
+ {
+ return ; // already been preloaded.
+ }
+
+ int tmpVal;
+ Prop prop = d->props[ widgetEntries[ i ] ];
+ TQString tmpStr;
+
+ tmpStr = prop[ "CopyWidget" ];
+ if ( !tmpStr.isEmpty() )
+ { // Duplicate another widget's config
+ int sIndex;
+ loadArray[ i ] = true;
+ for ( sIndex = 0; sIndex < WIDGETS; ++sIndex )
+ {
+ if ( tmpStr == widgetEntries[ sIndex ] )
+ {
+ if ( !loadArray[ sIndex ] ) // hasn't been loaded yet
+ readResourceGroup( sIndex, pixnames, brdnames,
+ loadArray );
+ break;
+ }
+ }
+ if ( loadArray[ sIndex ] )
+ {
+ copyWidgetConfig( sIndex, i, pixnames, brdnames );
+ }
+ else
+ tqWarning( "KThemeBase: Unable to identify source widget for %s\n", widgetEntries[ i ] );
+ return ;
+ }
+ // special inheritance for disabled arrows (these are tri-state unlike
+ // the rest of what we handle).
+ for ( tmpVal = DisArrowUp; tmpVal <= DisArrowRight; ++tmpVal )
+ {
+ if ( tmpVal == i )
+ {
+ tmpStr = prop[ "Pixmap" ];
+ if ( tmpStr.isEmpty() )
+ {
+ copyWidgetConfig( ArrowUp + ( tmpVal - DisArrowUp ), i, pixnames,
+ brdnames );
+ return ;
+ }
+ }
+ }
+
+ // Scale hint
+ scaleHints[ i ] = ( ScaleHint ) readNumEntry( prop, "ScaleHint", ( int ) TileScale );
+ gradients[ i ] = ( Gradient ) readNumEntry( prop, "Gradient", ( int ) GrNone );
+
+ // Blend intensity
+ tmpStr = prop[ "Blend" ];
+ if ( tmpStr.isEmpty() )
+ tmpStr = TQString::fromLatin1( "0.0" );
+ blends[ i ] = tmpStr.toFloat();
+
+ // Bevel contrast
+ bContrasts[ i ] = readNumEntry( prop, "BContrast", 0 );
+
+ // Border width
+ borders[ i ] = readNumEntry( prop, "Border", 1 );
+
+ // Highlight width
+ highlights[ i ] = readNumEntry( prop, "Highlight", 1 );
+
+ // Gradient low color or blend background
+ if ( gradients[ i ] != GrNone || blends[ i ] != 0.0 )
+ grLowColors[ i ] =
+ new TQColor( readColorEntry( prop, "GrLow",
+ TQApplication::palette().active().
+ background() ) );
+ else
+ grLowColors[ i ] = NULL;
+
+ // Gradient high color
+ if ( gradients[ i ] != GrNone )
+ grHighColors[ i ] =
+ new TQColor( readColorEntry( prop, "GrHigh",
+ TQApplication::palette().active().
+ background() ) );
+ else
+ grHighColors[ i ] = NULL;
+
+ // Extended color attributes
+ TQColor fg, bg;
+ fg = readColorEntry( prop, "Foreground", fg );
+ bg = readColorEntry( prop, "Background", bg );
+ if ( fg.isValid() || bg.isValid() )
+ {
+ if ( !fg.isValid() )
+ fg = TQApplication::palette().active().foreground();
+ if ( !bg.isValid() )
+ bg = TQApplication::palette().active().background();
+ colors[ i ] = makeColorGroup( fg, bg, TQt::WindowsStyle );
+ }
+ else
+ colors[ i ] = NULL;
+
+ // Pixmap
+ int existing;
+ tmpStr = prop[ "Pixmap" ];
+ pixnames[ i ] = tmpStr;
+ duplicate[ i ] = false;
+ pixmaps[ i ] = NULL;
+ images[ i ] = NULL;
+ // Scan for duplicate pixmaps(two identical pixmaps, tile scale, no blend,
+ // no pixmapped border)
+ if ( !tmpStr.isEmpty() )
+ {
+ for ( existing = 0; existing < i; ++existing )
+ {
+ if ( tmpStr == pixnames[ existing ] && scaleHints[ i ] == TileScale &&
+ scaleHints[ existing ] == TileScale && blends[ existing ] == 0.0 &&
+ blends[ i ] == 0.0 )
+ {
+ pixmaps[ i ] = pixmaps[ existing ];
+ duplicate[ i ] = true;
+ break;
+ }
+ }
+ }
+ // load
+ if ( !duplicate[ i ] && !tmpStr.isEmpty() )
+ {
+ pixmaps[ i ] = loadPixmap( tmpStr );
+ // load and save images for scaled/blended widgets for speed.
+ if ( scaleHints[ i ] == TileScale && blends[ i ] == 0.0 )
+ images[ i ] = NULL;
+ else
+ images[ i ] = loadImage( tmpStr );
+ }
+
+ // Pixmap border
+ tmpStr = prop[ "PixmapBorder" ];
+ brdnames[ i ] = tmpStr;
+ pbDuplicate[ i ] = false;
+ pbPixmaps[ i ] = NULL;
+ pbWidth[ i ] = 0;
+ if ( !tmpStr.isEmpty() )
+ {
+ pbWidth[ i ] = readNumEntry( prop, "PixmapBWidth", 0 );
+ if ( pbWidth[ i ] == 0 )
+ {
+ tqWarning( "KThemeBase: No border width specified for pixmapped border widget %s\n",
+ widgetEntries[ i ] );
+ tqWarning( "KThemeBase: Using default of 2.\n" );
+ pbWidth[ i ] = 2;
+ }
+ // duplicate check
+ for ( existing = 0; existing < i; ++existing )
+ {
+ if ( tmpStr == brdnames[ existing ] )
+ {
+ pbPixmaps[ i ] = pbPixmaps[ existing ];
+ pbDuplicate[ i ] = true;
+ break;
+ }
+ }
+ }
+ // load
+ if ( !pbDuplicate[ i ] && !tmpStr.isEmpty() )
+ pbPixmaps[ i ] = loadPixmap( tmpStr );
+
+ if ( pbPixmaps[ i ] && !pbDuplicate[ i ] )
+ generateBorderPix( i );
+
+ // Various widget specific settings. This was more efficient when bunched
+ // together in the misc group, but this makes an easier to read config.
+ if ( i == SliderGroove )
+ roundedSlider = readNumEntry( prop, "SmallGroove", false );
+ else if ( i == ActiveTab )
+ aTabLine = readNumEntry( prop, "BottomLine", true );
+ else if ( i == InactiveTab )
+ iTabLine = readNumEntry( prop, "BottomLine", true );
+ else if ( i == Splitter )
+ splitterWidth = readNumEntry( prop, "Width", 10 );
+ else if ( i == ComboBox || i == ComboBoxDown )
+ {
+ tmpVal = readNumEntry( prop, "Round", 5000 );
+ if ( tmpVal != 5000 )
+ roundedCombo = tmpVal;
+ }
+ else if ( i == PushButton || i == PushButtonDown )
+ {
+ tmpVal = readNumEntry( prop, "XShift", 0 );
+ if ( tmpVal != 5000 )
+ btnXShift = tmpVal;
+ tmpVal = readNumEntry( prop, "YShift", 0 );
+ if ( tmpVal != 5000 )
+ btnYShift = tmpVal;
+ tmpVal = readNumEntry( prop, "3DFRect", false );
+ if ( tmpVal != 5000 )
+ focus3D = tmpVal;
+ tmpVal = readNumEntry( prop, "3DFOffset", 0 );
+ if ( tmpVal != 5000 )
+ focus3DOffset = tmpVal;
+ tmpVal = readNumEntry( prop, "Round", false );
+ if ( tmpVal != 5000 )
+ roundedButton = tmpVal;
+ }
+ loadArray[ i ] = true;
+#endif
+}
+
+
+TQPalette KThemeBase::overridePalette( const TQPalette& pal )
+{
+
+ //Read current settings for colors..
+ TQColor background = pal.active().background();
+ TQColor foreground = pal.active().foreground();
+ TQColor button = background; //CHECKME
+ TQColor highlight = pal.active().highlight();
+ TQColor highlightedText = pal.active().highlightedText(); //CHECKME
+ TQColor base = pal.active().base(); //config->readColorEntry( "windowBackground", &white );
+ TQColor baseText = pal.active().text(); //CHECKME
+
+ //See whether there are any immediate overrides.
+ if ( d->overrideBackground )
+ background = d->overrideBackgroundCol;
+
+ if ( d->overrideForeground )
+ foreground = d->overrideForegroundCol;
+
+ if ( d->overrideSelectBackground )
+ highlight = d->overrideSelectBackgroundCol;
+ if ( d->overrideSelectForeground )
+ highlightedText = d->overrideSelectForegroundCol;
+
+ if ( d->overrideWindowBackground )
+ base = d->overrideWindowBackgroundCol;
+ if ( d->overrideWindowForeground )
+ baseText = d->overrideWindowForegroundCol;
+
+ //Now, try to get the button color from the pixmap
+ if ( uncached( Bevel ) )
+ button = d->pixmapAveColor( uncached( Bevel ) );
+
+ TQColor buttonText = foreground;
+
+ int highlightVal, lowlightVal;
+ highlightVal = 100 + ( 2 * d->contrast + 4 ) * 16 / 10;
+ lowlightVal = 100 + ( 2 * d->contrast + 4 ) * 10;
+
+
+ if ( isPixmap( Background ) || isColor( Background ) )
+ {
+ if ( isColor( Background ) )
+ {
+ background = colorGroup( pal.active(), Background )
+ ->background();
+ }
+ if ( isPixmap( Background ) )
+ {
+ background = d->pixmapAveColor( uncached( Background ) );
+ }
+
+
+ TQColorGroup pre( foreground, button, background.light( highlightVal ),
+ background.dark( lowlightVal ), background.dark( 120 ),
+ baseText, buttonText /*CHECKME: BrightText*/, base, background );
+
+ buttonText = colorGroup( pre, PushButton ) ->foreground();
+ }
+
+ TQColor disfg = foreground;
+ int h, s, v;
+ disfg.hsv( &h, &s, &v );
+ if ( v > 128 )
+ // dark bg, light fg - need a darker disabled fg
+ disfg = disfg.dark( lowlightVal );
+ else if ( disfg != black )
+ // light bg, dark fg - need a lighter disabled fg - but only if !black
+ disfg = disfg.light( highlightVal );
+ else
+ // black fg - use darkgray disabled fg
+ disfg = Qt::darkGray;
+
+
+ TQColorGroup disabledgrp( disfg, background, //TODO:Convert this to the new ctor.
+ background.light( highlightVal ),
+ background.dark( lowlightVal ),
+ background.dark( 120 ),
+ background.dark( 120 ), base );
+
+
+ TQColorGroup colgrp( foreground, button, background.light( highlightVal ),
+ background.dark( lowlightVal ), background.dark( 120 ),
+ baseText, buttonText /*CHECKME: BrightText*/, base, background );
+
+
+
+ colgrp.setColor( TQColorGroup::Highlight, highlight );
+ colgrp.setColor( TQColorGroup::HighlightedText, highlightedText );
+ colgrp.setColor( TQColorGroup::ButtonText, buttonText );
+ colgrp.setColor( TQColorGroup::Midlight, button.light( 110 ) );
+
+
+ disabledgrp.setColor( TQColorGroup::Base, base );
+ disabledgrp.setColor( TQColorGroup::Button, button );
+ disabledgrp.setColor( TQColorGroup::ButtonText, buttonText );
+ disabledgrp.setColor( TQColorGroup::Midlight, button.light( 110 ) );
+
+ TQPalette newPal( colgrp, disabledgrp, colgrp );
+
+ return newPal;
+
+}
+
+KThemePixmap::KThemePixmap( bool timer )
+ : KPixmap()
+{
+ if ( timer )
+ {
+ t = new TQTime;
+ t->start();
+ }
+ else
+ t = NULL;
+ int i;
+ for ( i = 0; i < 8; ++i )
+ b[ i ] = NULL;
+}
+
+KThemePixmap::KThemePixmap( const KThemePixmap &p )
+ : KPixmap( p )
+{
+ if ( p.t )
+ {
+ t = new TQTime;
+ t->start();
+ }
+ else
+ t = NULL;
+ int i;
+ for ( i = 0; i < 8; ++i )
+ if ( p.b[ i ] )
+ b[ i ] = new TQPixmap( *p.b[ i ] );
+ else
+ b[ i ] = NULL;
+}
+
+KThemePixmap::KThemePixmap( const KThemePixmap &p, const TQPixmap &p2 )
+ : KPixmap( p2 )
+{
+ if ( p.t )
+ {
+ t = new TQTime;
+ t->start();
+ }
+ else
+ t = NULL;
+ int i;
+ for ( i = 0; i < 8; ++i )
+ if ( p.b[ i ] )
+ b[ i ] = new TQPixmap( *p.b[ i ] );
+ else
+ b[ i ] = NULL;
+}
+
+
+
+KThemePixmap::~KThemePixmap()
+{
+ if ( t )
+ delete t;
+ int i;
+ for ( i = 0; i < 8; ++i )
+ if ( b[ i ] )
+ delete b[ i ];
+}
+
+KThemeCache::KThemeCache( int maxSize, TQObject *parent, const char *name )
+ : TQObject( parent, name )
+{
+ cache.setMaxCost( maxSize * 1024 );
+ cache.setAutoDelete( true );
+ flushTimer.start( 300000 ); // 5 minutes
+ connect( &flushTimer, TQT_SIGNAL( timeout() ), TQT_SLOT( flushTimeout() ) );
+}
+
+void KThemeCache::flushTimeout()
+{
+ TQIntCacheIterator<KThemePixmap> it( cache );
+ while ( it.current() )
+ {
+ if ( it.current() ->isOld() )
+ cache.remove( it.currentKey() );
+ else
+ ++it;
+ }
+}
+
+KThemePixmap* KThemeCache::pixmap( int w, int h, int widgetID, bool border,
+ bool mask )
+{
+
+ kthemeKey key;
+ key.cacheKey = 0; // shut up, gcc
+ key.data.id = widgetID;
+ key.data.width = w;
+ key.data.height = h;
+ key.data.border = border;
+ key.data.mask = mask;
+
+ KThemePixmap *pix = cache.find( ( unsigned long ) key.cacheKey );
+ if ( pix )
+ pix->updateAccessed();
+ return ( pix );
+}
+
+KThemePixmap* KThemeCache::horizontalPixmap( int w, int widgetID )
+{
+ kthemeKey key;
+ key.cacheKey = 0; // shut up, gcc
+ key.data.id = widgetID;
+ key.data.width = w;
+ key.data.height = 0;
+ key.data.border = false;
+ key.data.mask = false;
+ KThemePixmap *pix = cache.find( ( unsigned long ) key.cacheKey );
+ if ( pix )
+ pix->updateAccessed();
+ return ( pix );
+}
+
+KThemePixmap* KThemeCache::verticalPixmap( int h, int widgetID )
+{
+ kthemeKey key;
+ key.cacheKey = 0; // shut up, gcc
+ key.data.id = widgetID;
+ key.data.width = 0;
+ key.data.height = h;
+ key.data.border = false;
+ key.data.mask = false;
+ KThemePixmap *pix = cache.find( ( unsigned long ) key.cacheKey );
+ if ( pix )
+ pix->updateAccessed();
+ return ( pix );
+}
+
+bool KThemeCache::insert( KThemePixmap *pixmap, ScaleHint scale, int widgetID,
+ bool border, bool mask )
+{
+ kthemeKey key;
+ key.cacheKey = 0; // shut up, gcc
+ key.data.id = widgetID;
+ key.data.width = ( scale == FullScale || scale == HorizontalScale ) ?
+ pixmap->width() : 0;
+ key.data.height = ( scale == FullScale || scale == VerticalScale ) ?
+ pixmap->height() : 0;
+ key.data.border = border;
+ key.data.mask = mask;
+
+ if ( cache.find( ( unsigned long ) key.cacheKey, true ) != NULL )
+ {
+ return ( true ); // a pixmap of this scale is already in there
+ }
+ return ( cache.insert( ( unsigned long ) key.cacheKey, pixmap,
+ pixmap->width() * pixmap->height() * pixmap->depth() / 8 ) );
+}
+
+
+
+
+#include "kthemebase.moc"
diff --git a/tdestyles/kthemestyle/kthemebase.h b/tdestyles/kthemestyle/kthemebase.h
new file mode 100644
index 000000000..01ecab138
--- /dev/null
+++ b/tdestyles/kthemestyle/kthemebase.h
@@ -0,0 +1,865 @@
+/*
+ $Id$
+
+ This file is part of the KDE libraries
+ Copyright (C) 1999 Daniel M. Duley <mosfet@kde.org>
+
+ KDE3 port (C) 2001 Maksim Orlovich <mo002j@mail.rochester.edu>
+
+ Palette setup code is from TDEApplication,
+Copyright (C) 1997 Matthias Kalle Dalheimer (kalle@kde.org)
+Copyright (C) 1998, 1999, 2000 KDE Team
+
+
+ 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., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef KTHEMEBASE_H
+#define KTHEMEBASE_H
+
+#include <tqtimer.h>
+#include <tqdatetime.h>
+#include <kpixmap.h>
+#include <tqintcache.h>
+#include <tqstring.h>
+#include <tdestyle.h>
+#include <tqsettings.h>
+#include <tqpalette.h> // for QColorGroup
+#include "tdestyledirs.h"
+#include <tqmap.h>
+
+class TQImage;
+
+
+
+/**
+ * This class adds simple time management to KPixmap for use in flushing
+ * KThemeCache.
+ *
+ * @author Daniel M. Duley <mosfet@kde.org>
+ */
+class KThemePixmap : public KPixmap
+{
+public:
+ enum BorderType{Top = 0, Bottom, Left, Right, TopLeft, TopRight, BottomLeft,
+ BottomRight};
+
+ KThemePixmap( bool timer = true );
+ KThemePixmap( const KThemePixmap &p );
+ KThemePixmap( const KThemePixmap &p, const TQPixmap& rp );
+ ~KThemePixmap();
+ TQPixmap* border( BorderType type );
+ void setBorder( BorderType type, const TQPixmap &p );
+ void updateAccessed();
+ bool isOld();
+protected:
+ TQTime *t;
+ TQPixmap *b[ 8 ];
+
+private:
+ class KThemePixmapPrivate;
+ KThemePixmapPrivate *d;
+};
+
+inline TQPixmap* KThemePixmap::border( BorderType type )
+{
+ return ( b[ type ] );
+}
+
+inline void KThemePixmap::setBorder( BorderType type, const TQPixmap &p )
+{
+ if ( b[ type ] )
+ {
+ tqWarning( "KThemePixmap: Overwriting existing border!" );
+ delete( b[ type ] );
+ }
+ b[ type ] = new TQPixmap( p );
+}
+
+inline void KThemePixmap::updateAccessed()
+{
+ if ( t )
+ t->start();
+}
+
+inline bool KThemePixmap::isOld()
+{
+ return ( t ? t->elapsed() >= 300000 : false );
+}
+
+/**
+ * A very simple pixmap cache for theme plugins. TQPixmapCache is not used
+ * since it uses TQString keys which are not needed. All the information we
+ * need can be encoded in a numeric key. Using TQIntCache instead allows us to
+ * skip the string operations.
+ *
+ * This class is mostly just inline methods that do bit operations on a key
+ * composed of the widget ID, width and/or height, and then calls
+ * TQIntCache::find().
+ *
+ * One other thing to note is that full, horizontal, and vertically scaled
+ * pixmaps are not used interchangeably. For example, if you insert a fully
+ * scaled pixmap that is 32x32 then request a horizontally scaled pixmap with
+ * a width of 32, they will not match. This is because a pixmap that has been
+ * inserted into the cache has already been scaled at some point and it is
+ * very likely the vertical height was not originally 32. Thus the pixmap
+ * will be wrong when drawn, even though the horizontal width matches.
+ *
+ * @author Daniel M. Duley <mosfet@kde.org>
+ *
+ */
+class KThemeCache : public TQObject
+{
+ Q_OBJECT
+public:
+ /**
+ * The scale hints supported by the cache. Note that Tiled is not here
+ * since tiled pixmaps are kept only once in KThemeBase.
+ */
+ enum ScaleHint{FullScale, HorizontalScale, VerticalScale};
+ /**
+ * The constructor.
+ *
+ * @param maxSize The maximum size of the cache in kilobytes.
+ * @param parent The parent object.
+ * @param name The name of the object.
+ */
+ KThemeCache( int maxSize, TQObject *parent = 0, const char *name = 0 );
+ /**
+ * Inserts a new pixmap into the cache.
+ *
+ * @param pixmap The pixmap to insert.
+ * @param scale The scaling type of the pixmap.
+ * @param widgetID The widget ID of the pixmap, usually from KThemeBase's
+ * WidgetType enum.
+ * @param border True if the pixmap has a border.
+ * @param mask True if the pixmap has a mask.
+ *
+ * @return True if the insert was successful, false otherwise.
+ */
+ bool insert( KThemePixmap *pixmap, ScaleHint scale, int widgetID,
+ bool border = false, bool mask = false );
+ /**
+ * Returns a fully scaled pixmap.
+ *
+ * @param w The pixmap width to search for.
+ * @param h The pixmap height to search for.
+ * @param widgetID The widget ID to search for.
+ * @param border True if the pixmap has a border.
+ * @param mask True if the pixmap has a mask.
+ *
+ * @return True if a pixmap matching the width, height, and widget ID of
+ * the pixmap exists, NULL otherwise.
+ */
+ KThemePixmap* pixmap( int w, int h, int widgetID, bool border = false,
+ bool mask = false );
+ /**
+ * Returns a horizontally scaled pixmap.
+ *
+ * @param w The pixmap width to search for.
+ * @param widgetID The widget ID to search for.
+ *
+ * @return True if a pixmap matching the width and widget ID of
+ * the pixmap exists, NULL otherwise.
+ */
+ KThemePixmap* horizontalPixmap( int w, int widgetID );
+ /**
+ * Returns a vertically scaled pixmap.
+ *
+ * @param h The pixmap height to search for.
+ * @param widgetID The widget ID to search for.
+ *
+ * @return True if a pixmap matching the height and widget ID of
+ * the pixmap exists, NULL otherwise.
+ */
+ KThemePixmap* verticalPixmap( int h, int widgetID );
+protected slots:
+ void flushTimeout();
+protected:
+ TQIntCache<KThemePixmap> cache;
+ TQTimer flushTimer;
+
+private:
+ class KThemeCachePrivate;
+ KThemeCachePrivate *d;
+};
+
+
+
+class KThemeBasePrivate;
+/**
+ * This is a base class for KDE themed styles. It implements a cache,
+ * configuration file parsing, pixmap scaling, gradients, and a lot
+ * of inline methods for accessing user specified parameters.
+ *
+ * Note that this class *does not* actually implement any themes. It just
+ * provides the groundwork for doing so. The only reason to use this class
+ * directly is if you plan to reimplement all of the widgets. Otherwise,
+ * refer to KThemeStyle for a fully themed style you can derive from.
+ *
+ * @author Daniel M. Duley <mosfet@kde.org>
+ */
+class KThemeBase: public TDEStyle
+{
+ Q_OBJECT
+public:
+ /**
+ * Constructs a new KThemeBase object.
+ */
+ KThemeBase( const TQString &dirs, const TQString &configFile );
+ ~KThemeBase();
+ /**
+ * Describes if a pixmap should be scaled fully, horizontally, vertically,
+ * or not at all and tiled.
+ */
+ enum ScaleHint{FullScale, HorizontalScale, VerticalScale, TileScale};
+ /**
+ * The default arrow types.
+ */
+ enum ArrowStyle{MotifArrow, LargeArrow, SmallArrow};
+ /**
+ * The default frame shading styles.
+ */
+ enum ShadeStyle{Motif, Windows, Next, KDE};
+ /**
+ * The default scrollbar button layout. BottomLeft is like what Next
+ * uses, BottomRight is like Platinum, and Opposite it like Windows and
+ * Motif.
+ */
+ enum SButton{SBBottomLeft, SBBottomRight, SBOpposite};
+ /**
+ * The gradient types. Horizontal is left to right, Vertical is top to
+ * bottom, and diagonal is upper-left to bottom-right.
+ */
+ enum Gradient{GrNone, GrHorizontal, GrVertical, GrDiagonal, GrPyramid,
+ GrRectangle, GrElliptic, GrReverseBevel};
+ /**
+ * This provides a list of widget types that KThemeBase recognizes.
+ */
+ /* Internal note: The order here is important. Some widgets inherit
+ * properties. This is usually for when you have two settings for the
+ * same widget, ie: on(sunken), and off. The on settings will inherit
+ * the properties of the off one when nothing is specified in the config.
+ *
+ * In order to be able to handle this while still having everything in
+ * one group that is easy to loop from we have the following order:
+ * unsunked(off) items, sunken(on)items, and then the ones that don't
+ * matter. INHERIT_ITEMS define the number of widgets that have inheritence
+ * so if 0 == PushButtonOff then INHERIT_ITEMS should == PushButtonOn
+ * and so on. WIDGETS define the total number of widgets.
+ */
+ enum WidgetType{
+ // Off (unsunken widgets)
+ PushButton = 0, ComboBox, HScrollBarSlider, VScrollBarSlider, Bevel,
+ ToolButton, ScrollButton, HScrollDeco, VScrollDeco,
+ ComboDeco, MenuItem, InactiveTab, ArrowUp, ArrowDown, ArrowLeft,
+ ArrowRight,
+ // On (sunken widgets)
+ PushButtonDown, ComboBoxDown, HScrollBarSliderDown,
+ VScrollBarSliderDown, BevelDown, ToolButtonDown, ScrollButtonDown,
+ HScrollDecoDown, VScrollDecoDown, ComboDecoDown, MenuItemDown,
+ ActiveTab, SunkenArrowUp, SunkenArrowDown, SunkenArrowLeft,
+ SunkenArrowRight,
+ // Everything else (indicators must have separate settings)
+ HScrollGroove, VScrollGroove, Slider, SliderGroove, IndicatorOn,
+ IndicatorOff, IndicatorTri, ExIndicatorOn, ExIndicatorOff, HBarHandle, VBarHandle,
+ ToolBar, Splitter, CheckMark, MenuBar, DisArrowUp, DisArrowDown,
+ DisArrowLeft, DisArrowRight, ProgressBar, ProgressBg, MenuBarItem,
+ Background, RotSliderGroove, RotInactiveTab, RotActiveTab, WIDGETS};
+
+ /**
+ * The scaling type specified by the TDEConfig file.
+ *
+ * @param widget A Widgets enum value.
+ *
+ * @return A ScaleHint enum value.
+ */
+ ScaleHint scaleHint( WidgetType widget ) const;
+ /**
+ * The gradient type specified by the TDEConfig file.
+ *
+ * @param widget A Widgets enum value.
+ *
+ * @return A Gradient enum value.
+ */
+ Gradient gradientHint( WidgetType widget ) const;
+ /**
+ * The color group specified for a given widget.
+ * If a color group is set in the theme configuration
+ * that is used, otherwise defaultColor is returned.
+ *
+ * @param defaultGroup The colorGroup to set if one is available.
+ *
+ * @param widget The widget whose color group to retrieve.
+ *
+ */
+ const TQColorGroup* colorGroup( const TQColorGroup &defaultGroup,
+ WidgetType widget ) const;
+
+ TQBrush pixmapBrush( const TQColorGroup &group, TQColorGroup::ColorRole role,
+ int w, int h, WidgetType widget );
+ /**
+ * True if the widget has a pixmap or gradient specified.
+ */
+ bool isPixmap( WidgetType widget ) const;
+ /**
+ * True if the widget has a color group specified.
+ */
+ bool isColor( WidgetType widget ) const;
+ /**
+ * True if the user specified a 3D focus rectangle
+ */
+ bool is3DFocus() const;
+ /**
+ * If the user specified a 3D focus rectangle, they may also specify an
+ * offset from the default rectangle to use when drawing it. This returns
+ * the specified offset.
+ */
+ int focusOffset() const;
+ /**
+ * The border width of the specified widget.
+ */
+ int borderWidth( WidgetType widget ) const;
+ /**
+ * Pixmap border width of the specified widget.
+ */
+ int pixBorderWidth( WidgetType widget ) const;
+ /**
+ * Returns the border pixmap if enabled for the specified widget. This
+ * will contain the originial pixmap, plus the edges separated in
+ * KThemePixmap::border() if valid. If invalid it will return NULL.
+ */
+ KThemePixmap* borderPixmap( WidgetType widget ) const;
+ /**
+ * The highlight width of the specified widget.
+ */
+ int highlightWidth( WidgetType widget ) const;
+ /**
+ * The border plus highlight width of the widget.
+ */
+ int decoWidth( WidgetType widget ) const;
+ /**
+ * The extent (width for vertical, height for horizontal) requested
+ * for the scrollbars.
+ */
+ int getSBExtent() const;
+ /**
+ * The scrollbar button layout.
+ */
+ SButton scrollBarLayout() const;
+ /**
+ * The arrow type.
+ */
+ ArrowStyle arrowType() const;
+ /**
+ * The shading type.
+ */
+ ShadeStyle shade() const;
+ /**
+ * The frame width.
+ */
+ int frameWidth() const;
+ /**
+ * The splitter width.
+ */
+ int splitWidth() const;
+ /**
+ * The contrast for some bevel effects such as reverse gradient.
+ */
+ int bevelContrast( WidgetType widget ) const;
+ /**
+ * The button text X shift.
+ */
+ int buttonXShift() const;
+ /**
+ * The button text Y shift.
+ */
+ int buttonYShift() const;
+ /**
+ * Returns either the slider length of the slider pixmap if available,
+ * otherwise the length specified in the config file.
+ */
+ int sliderButtonLength() const;
+ /**
+ * True if rounded buttons are requested.
+ */
+ bool roundButton() const;
+ /**
+ * True if rounded comboboxes are requested.
+ */
+ bool roundComboBox() const;
+ /**
+ * True if rounded slider grooves are requested.
+ */
+ bool roundSlider() const;
+ /**
+ * True if a line should be drawn on the bottom of active tabs.
+ */
+ bool activeTabLine() const;
+ /**
+ * True if a line should be drawn on the bottom of inactive tabs.
+ */
+ bool inactiveTabLine() const;
+ /**
+ * Returns the current uncached pixmap for the given widget. This will
+ * usually be either the last scaled or gradient pixmap if those have
+ * been specified in the config file, the original pixmap if not, or NULL
+ * if no pixmap has been specified.
+ */
+ KThemePixmap* uncached( WidgetType widget ) const;
+ /**
+ * Returns the pixmap for the given widget at the specified width and
+ * height. This will return NULL if no pixmap or gradient is specified.
+ * It may also return a different sized pixmap if the scaling
+ * is set to Tiled. When using this method, you should call it using
+ * the needed width and height then use TQPainter::drawTiledPixmap to
+ * paint it. Doing this, if the pixmap is scaled it will be the proper
+ * size, otherwise it will be tiled.
+ *
+ * @param w Requested width.
+ * @param h Requested height.
+ * @param widget Widget type.
+ * @return The pixmap or NULL if one is not specified.
+ */
+ virtual KThemePixmap *scalePixmap( int w, int h, WidgetType widget ) const;
+protected:
+ /**
+ * This method reads a configuration file and sets things up so
+ * overrideColorGroup works. Modiying user's config files within
+ * a style is evil, IMHO (SadEagle). On the other hand, this will
+ * make it simply ignore settings.
+ *
+ * @param config The configuration file to apply.
+ */
+ void applyConfigFile( TQSettings & config );
+
+ /*
+ * Generates a new palette based on the values for which have been specified explicitly
+ * in the .themerc file.
+ */
+ TQPalette overridePalette( const TQPalette& pal );
+
+ /**
+ * Returns a TQImage for the given widget if the widget is scaled, NULL
+ * otherwise. QImages of the original pixmap are stored for scaled
+ * widgets in order to facilitate fast and accurate smooth-scaling. This
+ * also saves us a conversion from a pixmap to an image then back again.
+ */
+ TQImage* image( WidgetType widget ) const;
+ /**
+ * Returns the gradient high color if one is specified, NULL otherwise.
+ */
+ TQColor* gradientHigh( WidgetType widget ) const;
+ /**
+ * Returns the gradient low color if one is specified, NULL otherwise.
+ */
+ TQColor* gradientLow( WidgetType widget ) const;
+ /**
+ * Reads in all the configuration file entries supported.
+ *
+ * @param colorStyle The style for the color groups. In KDE, colors were
+ * calculated a little differently for Motif vs Windows styles. This
+ * is obsolete.
+ */
+ void readConfig( TQt::GUIStyle colorStyle = TQt::WindowsStyle );
+ void readWidgetConfig( int i, TQSettings *config, TQString *pixnames,
+ TQString *brdnames, bool *loadArray );
+ void copyWidgetConfig( int sourceID, int destID, TQString *pixnames,
+ TQString *brdnames );
+ /**
+ * Makes a full color group based on the given foreground and background
+ * colors. This is the same code used by KDE (kapp.cpp) in previous
+ * versions.
+ */
+ TQColorGroup* makeColorGroup( const TQColor &fg, const TQColor &bg,
+ TQt::GUIStyle style = TQt::WindowsStyle );
+ KThemePixmap* scale( int w, int h, WidgetType widget ) const;
+ KThemePixmap* scaleBorder( int w, int h, WidgetType type ) const;
+ KThemePixmap* gradient( int w, int h, WidgetType widget ) const ;
+ KThemePixmap* blend( WidgetType widget ) const;
+ void generateBorderPix( int i );
+ void applyResourceGroup( TQSettings *config, int i );
+ void applyMiscResourceGroup( TQSettings *config );
+ void readResourceGroup( int i, TQString *pixnames, TQString *brdnames,
+ bool *loadArray );
+ void readMiscResourceGroup();
+ /**
+ * Attempts to load a pixmap from the default KThemeBase locations.
+ */
+ KThemePixmap* loadPixmap( const TQString &name );
+ /**
+ * Attempts to load a image from the default KThemeBase locations.
+ */
+ TQImage* loadImage( const TQString &name );
+
+
+ /**
+ These are included for fuuture extension purposes..
+ */
+ virtual int pixelMetric ( PixelMetric metric, const TQStyleControlElementData &ceData, ControlElementFlags elementFlags, const TQWidget * widget = 0 ) const
+ {
+ return TDEStyle::pixelMetric( metric, ceData, elementFlags, widget );
+ }
+
+ virtual void drawPrimitive ( PrimitiveElement pe, TQPainter * p, const TQStyleControlElementData &ceData, ControlElementFlags elementFlags, const TQRect & r, const TQColorGroup & cg,
+ SFlags flags = Style_Default,
+ const TQStyleOption& option = TQStyleOption::Default ) const
+ {
+ TDEStyle::tqdrawPrimitive ( pe, p, ceData, elementFlags, r, cg,
+ flags, option );
+ }
+
+
+ virtual void drawControl( TQ_ControlElement element,
+ TQPainter *p,
+ const TQStyleControlElementData &ceData,
+ ControlElementFlags elementFlags,
+ const TQRect &r,
+ const TQColorGroup &cg,
+ SFlags how = Style_Default,
+ const TQStyleOption& opt = TQStyleOption::Default,
+ const TQWidget *widget = 0 ) const
+ {
+ TDEStyle::drawControl( element, p, ceData, elementFlags,
+ r, cg, how, opt, widget );
+ }
+
+ virtual void drawControlMask( TQ_ControlElement element,
+ TQPainter *p,
+ const TQStyleControlElementData &ceData,
+ ControlElementFlags elementFlags,
+ const TQRect &r,
+ const TQStyleOption& opt = TQStyleOption::Default,
+ const TQWidget *widget = 0 ) const
+ {
+ TDEStyle::drawControlMask( element, p, ceData, elementFlags, r, opt, widget );
+ }
+
+
+ virtual void drawComplexControl( TQ_ComplexControl control,
+ TQPainter *p,
+ const TQStyleControlElementData &ceData,
+ ControlElementFlags elementFlags,
+ const TQRect &r,
+ const TQColorGroup &cg,
+ SFlags flags = Style_Default,
+ SCFlags controls = SC_All,
+ SCFlags active = SC_None,
+ const TQStyleOption& opt = TQStyleOption::Default,
+ const TQWidget* widget = 0 ) const
+ {
+ TDEStyle::drawComplexControl( control, p, ceData, elementFlags, r, cg, flags, controls, active, opt, widget );
+ }
+
+
+ virtual void drawTDEStylePrimitive( TDEStylePrimitive kpe,
+ TQPainter* p,
+ const TQStyleControlElementData &ceData,
+ ControlElementFlags elementFlags,
+ const TQRect &r,
+ const TQColorGroup &cg,
+ SFlags flags = Style_Default,
+ const TQStyleOption& opt = TQStyleOption::Default,
+ const TQWidget* widget = 0 ) const
+ {
+ TDEStyle::drawTDEStylePrimitive( kpe,
+ p, ceData, elementFlags, r,
+ cg, flags, opt, widget );
+ }
+
+
+ virtual int styleHint( StyleHint sh, const TQStyleControlElementData &ceData, ControlElementFlags elementFlags,
+ const TQStyleOption& opt = TQStyleOption::Default,
+ TQStyleHintReturn* returnData = 0,
+ const TQWidget *widget = 0 ) const
+ {
+ return TDEStyle::styleHint( sh,
+ ceData,
+ elementFlags,
+ opt,
+ returnData,
+ widget );
+ }
+
+ virtual TQSize sizeFromContents( ContentsType contents,
+ const TQStyleControlElementData &ceData,
+ ControlElementFlags elementFlags,
+ const TQSize &contentsSize,
+ const TQStyleOption& opt = TQStyleOption::Default,
+ const TQWidget *widget = 0 ) const
+ {
+ return TDEStyle::sizeFromContents( contents,
+ ceData, elementFlags, contentsSize, opt, widget );
+ }
+
+private:
+ KThemeBasePrivate *d;
+
+ SButton sbPlacement;
+ ArrowStyle arrowStyle;
+ ShadeStyle shading;
+ int defaultFrame;
+ int btnXShift, btnYShift;
+ int sliderLen;
+ int splitterWidth;
+ int focus3DOffset;
+ int sbExtent;
+ bool smallGroove;
+ bool roundedButton, roundedCombo, roundedSlider;
+ bool aTabLine, iTabLine;
+ bool focus3D;
+ KThemeCache *cache;
+ int cacheSize;
+ TQString configFileName;
+ TQString configDirName;
+
+ /**
+ * The theme pixmaps. Many of these may be NULL if no pixmap is specified.
+ * There may also be duplicate pixmap pointers if more than one widget
+ * uses the same tiled pixmap. If a pixmap is tiled, it is kept here and
+ * this acts as a cache. Otherwise this will hold whatever the last scaled
+ * pixmap was.
+ */
+ mutable KThemePixmap *pixmaps[ WIDGETS ];
+ /**
+ * The theme images. These are for scaled images and are kept in order
+ * to maintain fast smoothscaling.
+ */
+ mutable TQImage *images[ WIDGETS ];
+ /**
+ * The border widths
+ */
+ mutable unsigned char borders[ WIDGETS ];
+ /**
+ * The highlight widths
+ */
+ mutable unsigned char highlights[ WIDGETS ];
+ /**
+ * The scale hints for pixmaps and gradients.
+ */
+ mutable ScaleHint scaleHints[ WIDGETS ];
+ /**
+ * All the color groups.
+ */
+ mutable TQColorGroup *colors[ WIDGETS ];
+ /**
+ * Gradient low colors (or blend background).
+ */
+ mutable TQColor *grLowColors[ WIDGETS ];
+ /**
+ * Gradient high colors.
+ */
+ mutable TQColor *grHighColors[ WIDGETS ];
+ /**
+ * Gradient types.
+ */
+ mutable Gradient gradients[ WIDGETS ];
+ /**
+ * Blend intensity factors
+ */
+ mutable float blends[ WIDGETS ];
+ /**
+ * Bevel contrasts
+ */
+ mutable unsigned char bContrasts[ WIDGETS ];
+ /**
+ * Duplicate pixmap entries (used during destruction).
+ */
+ mutable bool duplicate[ WIDGETS ];
+ /**
+ * Pixmapped border widths
+ */
+ mutable int pbWidth[ WIDGETS ];
+ /**
+ * Pixmapped borders
+ */
+ mutable KThemePixmap *pbPixmaps[ WIDGETS ];
+ /**
+ * Duplicate border pixmapped border entries
+ */
+ mutable bool pbDuplicate[ WIDGETS ];
+
+};
+
+inline bool KThemeBase::isPixmap( WidgetType widget ) const
+{
+ return ( pixmaps[ widget ] != NULL || gradients[ widget ] != GrNone );
+}
+
+inline bool KThemeBase::isColor( WidgetType widget ) const
+{
+ return ( colors[ widget ] != NULL );
+}
+
+inline bool KThemeBase::is3DFocus() const
+{
+ return ( focus3D );
+}
+
+inline int KThemeBase::focusOffset() const
+{
+ return ( focus3DOffset );
+}
+
+inline int KThemeBase::bevelContrast( WidgetType widget ) const
+{
+ return ( bContrasts[ widget ] );
+}
+
+inline KThemeBase::ScaleHint KThemeBase::scaleHint( WidgetType widget ) const
+{
+ return ( ( widget < WIDGETS ) ? scaleHints[ widget ] : TileScale );
+}
+
+inline KThemeBase::Gradient KThemeBase::gradientHint( WidgetType widget ) const
+{
+ return ( ( widget < WIDGETS ) ? gradients[ widget ] : GrNone );
+}
+
+inline KThemePixmap* KThemeBase::uncached( WidgetType widget ) const
+{
+ return ( pixmaps[ widget ] );
+}
+
+inline TQBrush KThemeBase::pixmapBrush( const TQColorGroup &group,
+ TQColorGroup::ColorRole role,
+ int w, int h, WidgetType widget )
+{
+ if ( pixmaps[ widget ] || images[ widget ] )
+ return ( TQBrush( group.color( role ), *scalePixmap( w, h, widget ) ) );
+ else
+ return ( group.color( role ) );
+}
+
+inline const TQColorGroup* KThemeBase::colorGroup( const TQColorGroup &defaultGroup,
+ WidgetType widget ) const
+{
+ return ( ( colors[ widget ] ) ? colors[ widget ] : &defaultGroup );
+}
+
+inline int KThemeBase::borderWidth( WidgetType widget ) const
+{
+ return ( pbWidth[ widget ] ? pbWidth[ widget ] : borders[ widget ] );
+}
+
+inline int KThemeBase::pixBorderWidth( WidgetType widget ) const
+{
+ return ( pbWidth[ widget ] );
+}
+
+inline int KThemeBase::highlightWidth( WidgetType widget ) const
+{
+ return ( pbWidth[ widget ] ? 0 : highlights[ widget ] );
+}
+
+inline int KThemeBase::decoWidth( WidgetType widget ) const
+{
+ return ( pbWidth[ widget ] ? pbWidth[ widget ] : borders[ widget ] + highlights[ widget ] );
+}
+
+inline TQColor* KThemeBase::gradientHigh( WidgetType widget ) const
+{
+ return ( grHighColors[ widget ] );
+}
+
+inline TQColor* KThemeBase::gradientLow( WidgetType widget ) const
+{
+ return ( grLowColors[ widget ] );
+}
+
+inline TQImage* KThemeBase::image( WidgetType widget ) const
+{
+ return ( images[ widget ] );
+}
+
+inline KThemeBase::SButton KThemeBase::scrollBarLayout() const
+{
+ return ( sbPlacement );
+}
+
+inline KThemeBase::ArrowStyle KThemeBase::arrowType() const
+{
+ return ( arrowStyle );
+}
+
+inline KThemeBase::ShadeStyle KThemeBase::shade() const
+{
+ return ( shading );
+}
+
+inline int KThemeBase::frameWidth() const
+{
+ return ( defaultFrame );
+}
+
+inline int KThemeBase::buttonXShift() const
+{
+ return ( btnXShift );
+}
+
+inline int KThemeBase::splitWidth() const
+{
+ return ( splitterWidth );
+}
+
+inline int KThemeBase::buttonYShift() const
+{
+ return ( btnYShift );
+}
+
+inline int KThemeBase::sliderButtonLength() const
+{
+ if ( isPixmap( Slider ) )
+ return ( uncached( Slider ) ->width() );
+ else
+ return ( sliderLen );
+}
+
+inline bool KThemeBase::roundButton() const
+{
+ return ( roundedButton );
+}
+
+inline bool KThemeBase::roundComboBox() const
+{
+ return ( roundedCombo );
+}
+
+inline bool KThemeBase::roundSlider() const
+{
+ return ( roundedSlider );
+}
+
+inline bool KThemeBase::activeTabLine() const
+{
+ return ( aTabLine );
+}
+
+inline bool KThemeBase::inactiveTabLine() const
+{
+ return ( iTabLine );
+}
+
+inline int KThemeBase::getSBExtent() const
+{
+ return ( sbExtent );
+}
+
+inline KThemePixmap* KThemeBase::borderPixmap( WidgetType widget ) const
+{
+ return ( pbPixmaps[ widget ] );
+}
+
+#endif
diff --git a/tdestyles/kthemestyle/kthemestyle.cpp b/tdestyles/kthemestyle/kthemestyle.cpp
new file mode 100644
index 000000000..27f9ca325
--- /dev/null
+++ b/tdestyles/kthemestyle/kthemestyle.cpp
@@ -0,0 +1,2459 @@
+/*
+ $Id$
+
+ This file is part of the KDE libraries
+ Copyright (C) 1999 Daniel M. Duley <mosfet@kde.org>
+
+ KDE3 port (C) 2001-2002 Maksim Orlovich <mo002j@mail.rochester.edu>
+Port version 0.9.7
+
+ Includes code portions from the dotNET style, and the KDE HighColor style.
+
+ dotNET Style
+ Copyright (C) 2001, Chris Lee <lee@azsites.com>
+ Carsten Pfeiffer <pfeiffer@kde.org>
+
+ KDE3 HighColor Style
+ Copyright (C) 2001 Karol Szwed <gallium@kde.org>
+ (C) 2001 Fredrik H�glund <fredrik@kde.org>
+
+ Drawing routines adapted from the KDE2 HCStyle,
+ Copyright (C) 2000 Daniel M. Duley <mosfet@kde.org>
+ (C) 2000 Dirk Mueller <mueller@kde.org>
+ (C) 2001 Martijn Klingens <klingens@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., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "kthemestyle.h"
+#include "kthemebase.h"
+#include <tqstyleplugin.h>
+#include <tqstylefactory.h>
+#include <kimageeffect.h>
+
+#include <tqbitmap.h>
+#include <tqcheckbox.h>
+#include <tqlabel.h>
+#define INCLUDE_MENUITEM_DEF
+#include <tqmenudata.h>
+#include <tqpopupmenu.h>
+#include <tqpalette.h>
+#include <tqtabbar.h>
+#include <tqtoolbutton.h>
+#include <tdeglobalsettings.h>
+#include <kdrawutil.h>
+#include <tqdrawutil.h>
+#include <tqprogressbar.h>
+#include <tqdir.h>
+#include <tqapplication.h>
+#include <tqmenubar.h>
+#include <tqrangecontrol.h>
+#include <tqslider.h>
+#include <tqtooltip.h>
+#include <tqobjectlist.h>
+#include <tqradiobutton.h>
+#include <tqstatusbar.h>
+#include "tdestyledirs.h"
+
+#include <tqimage.h>
+
+#include <limits.h>
+
+#ifdef __GLIBC__
+#include <dlfcn.h>
+#endif
+
+static const TQCOORD u_arrow[] = { -1, -3, 0, -3, -2, -2, 1, -2, -3, -1, 2, -1, -4, 0, 3, 0, -4, 1, 3, 1};
+static const TQCOORD d_arrow[] = { -4, -2, 3, -2, -4, -1, 3, -1, -3, 0, 2, 0, -2, 1, 1, 1, -1, 2, 0, 2};
+static const TQCOORD l_arrow[] = { -3, -1, -3, 0, -2, -2, -2, 1, -1, -3, -1, 2, 0, -4, 0, 3, 1, -4, 1, 3};
+static const TQCOORD r_arrow[] = { -2, -4, -2, 3, -1, -4, -1, 3, 0, -3, 0, 2, 1, -2, 1, 1, 2, -1, 2, 0};
+
+const TQCOORD win_style_u_arrow[] = { 0, -2, 0, -2, -1, -1, 1, -1, -2, 0, 2, 0, -3, 1, 3, 1 };
+const TQCOORD win_style_d_arrow[] = { -3, -2, 3, -2, -2, -1, 2, -1, -1, 0, 1, 0, 0, 1, 0, 1 };
+const TQCOORD win_style_l_arrow[] = { 1, -3, 1, -3, 0, -2, 1, -2, -1, -1, 1, -1, -2, 0, 1, 0, -1, 1, 1, 1, 0, 2, 1, 2, 1, 3, 1, 3 };
+const TQCOORD win_style_r_arrow[] = { -2, -3, -2, -3, -2, -2, -1, -2, -2, -1, 0, -1, -2, 0, 1, 0, -2, 1, 0, 1, -2, 2, -1, 2, -2, 3, -2, 3 };
+
+
+#define TQCOORDARRLEN(x) sizeof(x)/(sizeof(TQCOORD)*2)
+
+
+static const int itemFrame = 2;
+static const int itemHMargin = 3;
+static const int itemVMargin = 1;
+static const int arrowHMargin = 6;
+static const int rightBorder = 12;
+
+
+/*
+BUGS:
+Sliders flash a bit -- anything else?
+
+TODO:
+Nicer disabled buttons.
+Sliders are not disabled properly
+*/
+
+
+class KThemeStylePlugin : public TQStylePlugin
+{
+public:
+
+ KThemeStylePlugin()
+ {
+#ifdef __GLIBC__
+ dlopen("kthemestyle.so",RTLD_LAZY);
+ //####### Keep reference count up so tdecore w. fast-malloc doesn't get unloaded
+ //####### (Fixes exit crashes with qt-only apps that occur on Linux)
+ //####### This should be rethought after 3.0,
+ //####### as it relies on the implementation-specific behavior
+ //####### of the glibc libdl (finding already loaded libraries based on the
+ //####### soname)
+#endif
+ }
+
+ ~KThemeStylePlugin()
+ {}
+
+ TQStringList keys() const
+ {
+ TQSettings cfg;
+ TDEStyleDirs::dirs()->addToSearch( "config", cfg );
+
+ TQStringList keys;
+ bool ok;
+
+ keys = cfg.readListEntry( "/kthemestyle/themes", &ok);
+ if ( !ok )
+ tqWarning( "KThemeStyle cache seems corrupt!\n" ); //Too bad one can't i18n this :-(
+
+ return keys;
+ }
+
+ TQStyle* create( const TQString& key )
+ {
+ TQSettings cfg;
+ TDEStyleDirs::dirs()->addToSearch( "config", cfg );
+
+ TQString file = cfg.readEntry( "/kthemestyle/" + key + "/file" );
+ if ( !key.isEmpty() )
+ {
+ TQFileInfo fi( file );
+ return new KThemeStyle( fi.dirPath(), fi.fileName() );
+ }
+
+ return 0;
+ }
+};
+
+KDE_Q_EXPORT_PLUGIN( KThemeStylePlugin )
+
+
+void kDrawWindowsArrow ( TQPainter *p, const TQStyleControlElementData &ceData, const TQStyle::ControlElementFlags elementFlags, const TQStyle* style, TQStyle::PrimitiveElement pe, bool down,
+ int x, int y, int w, int h,
+ const TQColorGroup &cg, bool enabled )
+{
+ TQPointArray a;
+ switch ( pe )
+ {
+ case TQStyle::PE_ArrowUp:
+ a.setPoints( TQCOORDARRLEN( win_style_u_arrow ), win_style_u_arrow );
+ break;
+
+ case TQStyle::PE_ArrowDown:
+ a.setPoints( TQCOORDARRLEN( win_style_d_arrow ), win_style_d_arrow );
+ break;
+
+ case TQStyle::PE_ArrowLeft:
+ a.setPoints( TQCOORDARRLEN( win_style_l_arrow ), win_style_l_arrow );
+ break;
+ default:
+ a.setPoints( TQCOORDARRLEN( win_style_r_arrow ), win_style_r_arrow );
+ }
+
+ p->save();
+ if ( down )
+ {
+ p->translate( style->pixelMetric( TQStyle::PM_ButtonShiftHorizontal, ceData, elementFlags ),
+ style->pixelMetric( TQStyle::PM_ButtonShiftVertical, ceData, elementFlags ) );
+ }
+
+ if ( enabled )
+ {
+ a.translate( x + w / 2, y + h / 2 );
+ p->setPen( cg.buttonText() );
+ p->drawLineSegments( a );
+ }
+ else
+ {
+ a.translate( x + w / 2 + 1, y + h / 2 + 1 );
+ p->setPen( cg.light() );
+ p->drawLineSegments( a );
+ a.translate( -1, -1 );
+ p->setPen( cg.mid() );
+ p->drawLineSegments( a );
+ }
+
+ p->restore();
+
+}
+
+
+
+TQSize KThemeStyle::sizeFromContents( ContentsType contents,
+ const TQStyleControlElementData &ceData,
+ ControlElementFlags elementFlags,
+ const TQSize &contentSize,
+ const TQStyleOption& opt,
+ const TQWidget* widget ) const
+{
+ switch ( contents )
+ {
+ // PUSHBUTTON SIZE
+ // ------------------------------------------------------------------
+ case CT_PushButton:
+ {
+ const TQPushButton * button = ( const TQPushButton* ) widget;
+ int w = contentSize.width();
+ int h = contentSize.height();
+ int bm = pixelMetric( PM_ButtonMargin, ceData, elementFlags, widget );
+ int fw = pixelMetric( PM_DefaultFrameWidth, ceData, elementFlags, widget ) * 2;
+
+ w += bm + fw + 6; // ### Add 6 to make way for bold font.
+ h += bm + fw;
+
+ // Ensure we stick to standard width and heights.
+ if ( button->isDefault() || button->autoDefault() )
+ {
+ if ( w < 80 && !button->text().isEmpty() )
+ w = 80;
+ }
+
+ if ( h < 22 )
+ h = 22;
+
+ return TQSize( w, h );
+ }
+
+ // POPUPMENU ITEM SIZE
+ // -----------------------------------------------------------------
+ case CT_PopupMenuItem:
+ {
+ if ( ! widget || opt.isDefault() )
+ return contentSize;
+
+ const TQPopupMenu *popup = ( const TQPopupMenu * ) widget;
+ bool checkable = popup->isCheckable();
+ TQMenuItem *mi = opt.menuItem();
+ int maxpmw = opt.maxIconWidth();
+ int w = contentSize.width(), h = contentSize.height();
+
+ if ( mi->custom() )
+ {
+ w = mi->custom() ->sizeHint().width();
+ h = mi->custom() ->sizeHint().height();
+ if ( ! mi->custom() ->fullSpan() )
+ h += 2 * itemVMargin + 2 * itemFrame;
+ }
+ else if ( mi->widget() )
+ {}
+ else if ( mi->isSeparator() )
+ {
+ w = 10; // Arbitrary
+ h = 2;
+ }
+ else
+ {
+ if ( mi->pixmap() )
+ h = QMAX( h, mi->pixmap() ->height() + 2 * itemFrame );
+ else
+ h = QMAX( h, popup->fontMetrics().height()
+ + 2 * itemVMargin + 2 * itemFrame );
+
+ if ( mi->iconSet() )
+ h = QMAX( h, mi->iconSet() ->pixmap(
+ TQIconSet::Small, TQIconSet::Normal ).height() +
+ 2 * itemFrame );
+ }
+
+ if ( ! mi->text().isNull() && mi->text().find( '\t' ) >= 0 )
+ w += 12;
+ else if ( mi->popup() )
+ w += 2 * arrowHMargin;
+
+ if ( maxpmw )
+ w += maxpmw + 6;
+ if ( checkable && maxpmw < 20 )
+ w += 20 - maxpmw;
+ if ( checkable || maxpmw > 0 )
+ w += 12;
+
+ w += rightBorder;
+
+ return TQSize( w, h );
+ }
+
+ default:
+ return KThemeBase::sizeFromContents( contents, ceData, elementFlags, contentSize, opt, widget );
+ }
+}
+
+
+TQRect KThemeStyle::subRect(SubRect sr, const TQStyleControlElementData &ceData, const ControlElementFlags elementFlags, const TQWidget* widget) const
+{
+ if (sr == SR_CheckBoxFocusRect)
+ {
+ const TQCheckBox* cb = static_cast<const TQCheckBox*>(widget);
+
+ //Only checkbox, no label
+ if (cb->text().isEmpty() && (cb->pixmap() == 0) )
+ {
+ TQRect bounding = cb->rect();
+
+ int cw = pixelMetric(PM_IndicatorWidth, ceData, elementFlags, widget);
+ int ch = pixelMetric(PM_IndicatorHeight, ceData, elementFlags, widget);
+
+ TQRect checkbox(bounding.x() + 2, bounding.y() + 2 + (bounding.height() - ch)/2, cw - 4, ch - 4);
+
+ return checkbox;
+ }
+ }
+ return TDEStyle::subRect(sr, ceData, elementFlags, widget);
+}
+
+int KThemeStyle::pixelMetric ( PixelMetric metric, const TQStyleControlElementData &ceData, ControlElementFlags elementFlags, const TQWidget * widget ) const
+{
+ switch ( metric )
+ {
+ case PM_MenuBarFrameWidth:
+ return 1;
+ case PM_DefaultFrameWidth:
+ return ( frameWidth() );
+
+ case PM_ButtonMargin:
+ return decoWidth( PushButton ) > decoWidth( PushButtonDown ) ?
+ 3 + decoWidth( PushButton ) : 3 + decoWidth( PushButtonDown );
+
+ case PM_ScrollBarExtent:
+ case PM_SliderThickness: //Should this be 16 always?
+ return getSBExtent();
+
+ case PM_ButtonDefaultIndicator:
+ return 0;
+
+ case PM_ButtonShiftHorizontal:
+ return buttonXShift();
+
+ case PM_ButtonShiftVertical:
+ return buttonYShift();
+
+ case PM_ExclusiveIndicatorWidth:
+ if ( isPixmap( ExIndicatorOn ) )
+ return ( uncached( ExIndicatorOn ) ->size().width() );
+ else
+ return KThemeBase::pixelMetric ( metric, ceData, elementFlags, widget );
+
+ case PM_ExclusiveIndicatorHeight:
+ if ( isPixmap( ExIndicatorOn ) )
+ return ( uncached( ExIndicatorOn ) ->size().height() );
+ else
+ return KThemeBase::pixelMetric ( metric, ceData, elementFlags, widget );
+
+
+ case PM_IndicatorWidth:
+ if ( isPixmap( IndicatorOn ) )
+ return ( uncached( IndicatorOn ) ->size().width() );
+ else
+ return KThemeBase::pixelMetric ( metric, ceData, elementFlags, widget );
+
+ case PM_IndicatorHeight:
+ if ( isPixmap( IndicatorOn ) )
+ return ( uncached( IndicatorOn ) ->size().height() );
+ else
+ return KThemeBase::pixelMetric ( metric, ceData, elementFlags, widget );
+
+ case PM_SliderLength:
+ return ( sliderButtonLength() );
+
+ case PM_SplitterWidth:
+ return ( splitWidth() );
+
+ case PM_MenuIndicatorFrameHBorder:
+ case PM_MenuIndicatorFrameVBorder:
+ case PM_MenuIconIndicatorFrameHBorder:
+ case PM_MenuIconIndicatorFrameVBorder:
+ return 0;
+
+ default:
+ return KThemeBase::pixelMetric ( metric, ceData, elementFlags, widget );
+ }
+}
+
+
+
+KThemeStyle::KThemeStyle( const TQString& configDir, const TQString &configFile )
+ : KThemeBase( configDir, configFile ), paletteSaved( false ), polishLock( false ), menuCache( 0 ), vsliderCache( 0 ),
+ brushHandle( 0 ), brushHandleSet( false ), kickerMode( false )
+{
+ mtfstyle = TQStyleFactory::create( "Motif" );
+ if ( !mtfstyle )
+ mtfstyle = TQStyleFactory::create( *( TQStyleFactory::keys().begin() ) );
+}
+
+KThemeStyle::~KThemeStyle()
+{
+ delete vsliderCache;
+ delete menuCache;
+
+}
+
+
+void KThemeStyle::applicationPolish( const TQStyleControlElementData &ceData, ControlElementFlags, void *ptr )
+{
+ if (ceData.widgetObjectTypes.contains(TQAPPLICATION_OBJECT_NAME_STRING)) {
+ TQApplication *app = reinterpret_cast<TQApplication*>(ptr);
+ if (!qstrcmp(app->argv()[0], "kicker")) {
+ kickerMode = true;
+ }
+ }
+}
+
+
+void KThemeStyle::polish( TQPalette &p )
+{
+ if ( polishLock )
+ {
+ return ; //Palette polishing disabled ...
+ }
+
+
+
+ if ( !paletteSaved )
+ {
+ oldPalette = p;
+ paletteSaved = true;
+ }
+
+ p = overridePalette( p );
+
+ if ( isPixmap( Background ) )
+ {
+ TQBrush bgBrush( p.color( TQPalette::Normal,
+ TQColorGroup::Background ),
+ *uncached( Background ) );
+ brushHandle = uncached( Background )->handle();
+ brushHandleSet = true;
+ p.setBrush( TQColorGroup::Background, bgBrush );
+ }
+
+}
+
+void KThemeStyle::paletteChanged()
+{
+ TQPalette p = TQApplication::palette();
+ polish( p );
+ TQApplication::setPalette( p );
+}
+
+
+void KThemeStyle::applicationUnPolish( const TQStyleControlElementData &ceData, ControlElementFlags, void *ptr )
+{
+ if (ceData.widgetObjectTypes.contains(TQAPPLICATION_OBJECT_NAME_STRING)) {
+ TQApplication *app = reinterpret_cast<TQApplication*>(ptr);
+ app->setPalette( oldPalette, true );
+ }
+}
+
+bool KThemeStyle::objectEventHandler( const TQStyleControlElementData &ceData, ControlElementFlags elementFlags, void* source, TQEvent *event )
+{
+ if (ceData.widgetObjectTypes.contains(TQOBJECT_OBJECT_NAME_STRING)) {
+ TQObject* object = reinterpret_cast<TQObject*>(source);
+
+ if( object->inherits("KActiveLabel"))
+ {
+ if(event->type() == TQEvent::Move || event->type() == TQEvent::Resize ||
+ event->type() == TQEvent::Show)
+ {
+ TQWidget *w = TQT_TQWIDGET(object);
+ TQPoint pos(0, 0);
+ pos = w->mapTo(w->topLevelWidget(), pos);
+ TQPixmap pix(uncached( Background )->size());
+ TQPainter p;
+ p.begin(&pix);
+ p.drawTiledPixmap(0, 0,
+ uncached( Background )->width(),
+ uncached( Background )->height() ,
+ *uncached( Background ),
+ pos.x(), pos.y());
+ p.end();
+ TQPalette pal(w->palette());
+ TQBrush brush( pal.color( TQPalette::Normal,
+ TQColorGroup::Background),
+ pix );
+ pal.setBrush(TQColorGroup::Base, brush);
+ w->setPalette(pal);
+ }
+ }
+ if (!qstrcmp(object->name(), "kde toolbar widget") && object->inherits(TQLABEL_OBJECT_NAME_STRING))
+ {
+ TQWidget* lb = TQT_TQWIDGET(object);
+ if (lb->backgroundMode() == TQt::PaletteButton)
+ lb->setBackgroundMode(TQt::PaletteBackground);
+ removeObjectEventHandler(ceData, elementFlags, source, this);
+ }
+ }
+
+ return TDEStyle::objectEventHandler(ceData, elementFlags, source, event);
+}
+
+void KThemeStyle::polish( const TQStyleControlElementData &ceData, ControlElementFlags elementFlags, void *ptr )
+{
+ if (ceData.widgetObjectTypes.contains(TQWIDGET_OBJECT_NAME_STRING)) {
+ TQWidget *w = reinterpret_cast<TQWidget*>(ptr);
+
+ if (::tqqt_cast<TQStatusBar*>(w))
+ w->setPaletteBackgroundColor(TQApplication::palette().color(TQPalette::Normal, TQColorGroup::Background));
+
+ if (::tqqt_cast<TQLabel*>(w) && !qstrcmp(w->name(), "kde toolbar widget"))
+ installObjectEventHandler(ceData, elementFlags, ptr, this);
+
+ if (w->backgroundPixmap() && !w->isTopLevel() &&
+ (!kickerMode ||
+ (!w->inherits("TaskBar") && !w->inherits("TaskBarContainer") && !w->inherits("TaskbarApplet") && !w->inherits("ContainerArea") && !w->inherits("AppletHandle"))))
+ {
+ //The brushHandle check verifies that the bg pixmap is actually the brush..
+ if (!brushHandleSet || brushHandle == w->backgroundPixmap()->handle())
+ {
+ w->setBackgroundOrigin( TQWidget::WindowOrigin );
+ }
+ }
+
+ if (w->inherits("KActiveLabel"))
+ {
+ if (uncached( Background ))
+ installObjectEventHandler(ceData, elementFlags, ptr, this);
+ }
+
+ if ( w->inherits( "QTipLabel" ) )
+ {
+ polishLock = true;
+
+ TQColorGroup clrGroup( Qt::black, TQColor( 255, 255, 220 ),
+ TQColor( 96, 96, 96 ), Qt::black, Qt::black,
+ Qt::black, TQColor( 255, 255, 220 ) );
+ TQPalette toolTip ( clrGroup, clrGroup, clrGroup );
+
+ TQToolTip::setPalette( toolTip );
+ polishLock = false;
+ }
+
+ if ( w->inherits( "KonqIconViewWidget" ) ) //Konqueror background hack/workaround
+ {
+ w->setPalette( oldPalette );
+ return ;
+ }
+
+ if ( ::tqqt_cast<TQMenuBar*>(w) )
+ {
+ w->setBackgroundMode( TQWidget::NoBackground );
+ }
+ else if ( w->inherits( "TDEToolBarSeparator" ) || w->inherits( "QToolBarSeparator" ) )
+ {
+ w->setBackgroundMode( TQWidget::PaletteBackground );
+ }
+ else if ( ::tqqt_cast<TQPopupMenu*>(w) )
+ {
+ popupPalette = w->palette();
+ if ( isColor( MenuItem ) || isColor( MenuItemDown ) )
+ {
+ TQPalette newPal( w->palette() );
+ if ( isColor( MenuItem ) )
+ {
+ newPal.setActive( *colorGroup( newPal.active(), MenuItem ) );
+ newPal.setDisabled( *colorGroup( newPal.active(), MenuItem ) );
+ }
+ if ( isColor( MenuItemDown ) )
+ {
+ newPal.setActive( *colorGroup( newPal.active(), MenuItemDown ) );
+ }
+ w->setPalette( newPal );
+ }
+
+ w->setBackgroundMode( TQWidget::NoBackground );
+ }
+ else if ( ::tqqt_cast<TQCheckBox*>(w) )
+ {
+ if ( isColor( IndicatorOff ) || isColor( IndicatorOn ) )
+ {
+ TQPalette newPal( w->palette() );
+ if ( isColor( IndicatorOff ) )
+ {
+ newPal.setActive( *colorGroup( newPal.active(), IndicatorOff ) );
+ newPal.setDisabled( *colorGroup( newPal.active(), IndicatorOff ) );
+ }
+ if ( isColor( IndicatorOn ) )
+ newPal.setActive( *colorGroup( newPal.active(), IndicatorOn ) );
+ w->setPalette( newPal );
+ }
+ }
+ else if ( ::tqqt_cast<TQRadioButton*>(w) )
+ {
+ if ( isColor( ExIndicatorOff ) || isColor( ExIndicatorOn ) )
+ {
+ TQPalette newPal( w->palette() );
+ if ( isColor( ExIndicatorOff ) )
+ {
+ newPal.setActive( *colorGroup( newPal.active(), ExIndicatorOff ) );
+ newPal.setDisabled( *colorGroup( newPal.active(),
+ ExIndicatorOff ) );
+ }
+ if ( isColor( ExIndicatorOn ) )
+ newPal.setActive( *colorGroup( newPal.active(), ExIndicatorOn ) );
+ w->setPalette( newPal );
+ }
+ }
+ }
+
+ TDEStyle::polish( ceData, elementFlags, ptr );
+}
+
+void KThemeStyle::unPolish( const TQStyleControlElementData &ceData, ControlElementFlags elementFlags, void *ptr )
+{
+ if (ceData.widgetObjectTypes.contains(TQWIDGET_OBJECT_NAME_STRING)) {
+ TQWidget *w = reinterpret_cast<TQWidget*>(ptr);
+
+ if (w->backgroundPixmap() && !w->isTopLevel())
+ {
+ //The brushHandle check verifies that the bg pixmap is actually the brush..
+ if (!brushHandleSet || brushHandle ==w->backgroundPixmap()->handle())
+ {
+ w->setBackgroundOrigin( TQWidget::WidgetOrigin );
+ }
+ }
+
+ //Toolbar labels should nornally be PaletteButton
+ if ( ::tqqt_cast<TQLabel*>(w) && !qstrcmp(w->name(), "kde toolbar widget"))
+ w->setBackgroundMode( TQWidget::PaletteButton );
+
+ //The same for menu bars, popup menus
+ else if ( ::tqqt_cast<TQMenuBar*>(w) || ::tqqt_cast<TQPopupMenu*>(w) )
+ w->setBackgroundMode( TQWidget::PaletteButton );
+
+ //For toolbar internal separators, return to button, too (can't use tqqt_cast here since don't have access to the class)
+ else if ( w->inherits( "TDEToolBarSeparator" ) || w->inherits( "QToolBarSeparator" ) )
+ w->setBackgroundMode( TQWidget::PaletteButton );
+
+ //For scrollbars, we don't do much, since the widget queries the style on the switch
+
+ //Drop some custom palettes. ### this really should check the serial number to be 100% correct.
+ if ( ::tqqt_cast<TQPopupMenu*>(w) || ::tqqt_cast<TQCheckBox*>(w) || ::tqqt_cast<TQRadioButton*>(w) || ::tqqt_cast<TQStatusBar*>(w) )
+ w->unsetPalette();
+ }
+
+ TDEStyle::unPolish( ceData, elementFlags, ptr );
+}
+
+
+void KThemeStyle::drawBaseButton( TQPainter *p, int x, int y, int w, int h,
+ const TQColorGroup &g, bool sunken, bool
+ rounded, WidgetType type ) const
+{
+ int offset = borderPixmap( type ) ? 0 : decoWidth( type ) ; //##### This is wrong, but the code relies on it..
+ TQPen oldPen = p->pen();
+
+ // handle reverse bevel here since it uses decowidth differently
+ if ( gradientHint( type ) == GrReverseBevel )
+ {
+ int i;
+ bitBlt( p->device(), x, y, TQT_TQPAINTDEVICE(scalePixmap( w, h, type )), 0, 0, w, h,
+ TQt::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 )
+ {
+ kDrawBeButton( 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( TQColorGroup::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 if ( 1 ) //##### TODO - Get this optimization working... !borderPixmap( type ) || (( w - decoWidth(type) * 2 ) > 0 && ( h - decoWidth(type) * 2 ) > 0) )
+ //Sometimes border covers the whole thing - in that case, avoid drawing the base.
+ {
+ p->fillRect( x + offset, y + offset, w - offset * 2, h - offset * 2,
+ g.brush( TQColorGroup::Button ) );
+ }
+ }
+ if ( borderPixmap( type ) )
+ {
+ bitBlt( p->device(), x, y, TQT_TQPAINTDEVICE(scaleBorder( w, h, type )), 0, 0, w, h,
+ TQt::CopyROP, false );
+ }
+ else
+ drawShade( p, x, y, w, h, g, sunken, rounded,
+ highlightWidth( type ), borderWidth( type ), shade() );
+ }
+ p->setPen( oldPen );
+}
+
+void KThemeStyle::drawPrimitive ( PrimitiveElement pe, TQPainter * p, const TQStyleControlElementData &ceData, ControlElementFlags elementFlags, const TQRect & r, const TQColorGroup & g_base,
+ SFlags flags, const TQStyleOption & opt ) const
+{
+ bool handled = false;
+ int x, y, w, h;
+ r.rect( &x, &y, &w, &h );
+
+ bool sunken = ( flags & Style_Sunken );
+ bool enabled = ( flags & Style_Enabled );
+ bool down = ( flags & Style_Down );
+ bool on = flags & Style_On;
+ bool active = flags & Style_Active;
+ TQColorGroup g = g_base;
+
+ switch ( pe )
+ {
+ case PE_ArrowUp:
+ case PE_ArrowDown:
+ case PE_ArrowRight:
+ case PE_ArrowLeft:
+ {
+ TQRect r( x, y, w, h );
+ if ( r.width() > 12 )
+ {
+ r.setRect( r.x() + ( r.width() - 12 ) / 2, r.y(), 12, r.height() );
+ }
+ if ( r.height() > 12 )
+ {
+ r.setRect( r.x(), r.y() + ( r.height() - 12 ) / 2, r.width(), 12 );
+ }
+ r.rect( &x, &y, &w, &h );
+ // Handles pixmapped arrows. A little inefficient because you can specify
+ // some as pixmaps and some as default types.
+ WidgetType widget;
+ switch ( pe )
+ {
+ case PE_ArrowUp:
+ widget = enabled ? down ? SunkenArrowUp : ArrowUp : DisArrowUp;
+ break;
+ case PE_ArrowDown:
+ widget = enabled ? down ? SunkenArrowDown : ArrowDown : DisArrowDown;
+ break;
+ case PE_ArrowLeft:
+ widget = enabled ? down ? SunkenArrowLeft : ArrowLeft : DisArrowLeft;
+ break;
+ case PE_ArrowRight:
+ default:
+ widget = enabled ? down ? SunkenArrowRight : ArrowRight : DisArrowRight;
+ break;
+ }
+ if ( isPixmap( widget ) )
+ {
+ bitBlt( p->device(), x + ( w - uncached( widget ) ->width() ) / 2,
+ y + ( h - uncached( widget ) ->height() ) / 2,
+ uncached( widget ) );
+
+ return ;
+ }
+ const TQColorGroup *cg = colorGroup( g, widget );
+ // Standard arrow types
+ if ( arrowType() == MotifArrow )
+ {
+ mtfstyle->drawPrimitive( pe, p, ceData, elementFlags, r, g, flags, opt );
+
+ handled = true;
+ }
+ else if ( arrowType() == SmallArrow )
+ {
+ // #### FIXME: This should be like the Platinum style - uses HighColor look for now
+ TQPointArray a;
+
+ switch ( pe )
+ {
+ case PE_ArrowUp:
+ a.setPoints( TQCOORDARRLEN( u_arrow ), u_arrow );
+ break;
+
+ case PE_ArrowDown:
+ a.setPoints( TQCOORDARRLEN( d_arrow ), d_arrow );
+ break;
+
+ case PE_ArrowLeft:
+ a.setPoints( TQCOORDARRLEN( l_arrow ), l_arrow );
+ break;
+
+ default:
+ a.setPoints( TQCOORDARRLEN( r_arrow ), r_arrow );
+ }
+
+ p->save();
+
+ if ( flags & Style_Down )
+ p->translate( pixelMetric( PM_ButtonShiftHorizontal, ceData, elementFlags ),
+ pixelMetric( PM_ButtonShiftVertical, ceData, elementFlags ) );
+
+ if ( flags & Style_Enabled )
+ {
+ a.translate( r.x() + r.width() / 2, r.y() + r.height() / 2 );
+ p->setPen( cg->buttonText() );
+ p->drawLineSegments( a );
+ }
+ else
+ {
+ a.translate( r.x() + r.width() / 2 + 1, r.y() + r.height() / 2 + 1 );
+ p->setPen( cg->mid() );
+ p->drawLineSegments( a );
+ }
+ p->restore();
+ }
+ else
+ {
+ TQPointArray a;
+ int x2 = x + w - 1, y2 = y + h - 1;
+ switch ( pe )
+ {
+ case PE_ArrowUp:
+ a.setPoints( 4, x, y2, x2, y2, x + w / 2, y, x, y2 );
+ break;
+ case PE_ArrowDown:
+ a.setPoints( 4, x, y, x2, y, x + w / 2, y2, x, y );
+ break;
+ case PE_ArrowLeft:
+ a.setPoints( 4, x2, y, x2, y2, x, y + h / 2, x2, y );
+ break;
+ default:
+ a.setPoints( 4, x, y, x, y2, x2, y + h / 2, x, y );
+ break;
+ }
+ TQBrush oldBrush = p->brush();
+ TQPen oldPen = p->pen();
+ p->setBrush( cg->brush( TQColorGroup::Shadow ) );
+ p->setPen( cg->shadow() );
+ p->drawPolygon( a );
+ p->setBrush( oldBrush );
+ p->setPen( oldPen );
+ handled = true;
+ }
+ break;
+
+ }
+ case PE_HeaderSectionMenu:
+ case PE_HeaderSection:
+ {
+ sunken = false; //Never mind this one
+ }
+ case PE_ButtonBevel:
+ {
+ WidgetType type = ( sunken || on || down ) ? BevelDown : Bevel;
+ drawBaseButton( p, x, y, w, h, *colorGroup( g, type ), ( sunken || on || down ), false, type );
+ handled = true;
+ break;
+ }
+ case PE_ButtonCommand:
+ {
+ drawBaseButton( p, x, y, w, h, g, ( sunken || on || down ), roundButton(), ( sunken || on || down ) ?
+ PushButtonDown : PushButton );
+ handled = true;
+ break;
+ }
+ case PE_PanelDockWindow:
+ {
+ drawBaseButton( p, x, y, w, h, *colorGroup( g, ToolBar ), false, false,
+ ToolBar );
+ handled = true;
+ break;
+ }
+ case PE_CheckMark:
+ {
+ if ( isPixmap( CheckMark ) )
+ {
+ if ( flags & Style_Enabled || flags & Style_On )
+ bitBlt( p->device(), x + ( w - uncached( CheckMark ) ->width() ) / 2,
+ y + ( h - uncached( CheckMark ) ->height() ) / 2,
+ uncached( CheckMark ) );
+ handled = true;
+ }
+ else //Small hack to ensure the checkmark gets painter proper color..
+ {
+ g.setColor( TQColorGroup::Text, g.buttonText() );
+ }
+ break;
+ }
+ case PE_ExclusiveIndicator:
+ {
+ if ( isPixmap( ( flags & Style_On || flags & Style_Down ) ? ExIndicatorOn : ExIndicatorOff ) )
+ {
+ p->drawPixmap( x, y, *uncached( ( flags & Style_On || flags & Style_Down ) ? ExIndicatorOn :
+ ExIndicatorOff ) );
+ handled = true;
+ }
+
+ break;
+ }
+ case PE_ExclusiveIndicatorMask:
+ {
+ if ( isPixmap( ( flags & Style_On || flags & Style_Down ) ? ExIndicatorOn : ExIndicatorOff ) )
+ {
+ const TQBitmap * mask = uncached( ( flags & Style_On || flags & Style_Down ) ? ExIndicatorOn : ExIndicatorOff ) ->mask();
+ if ( mask )
+ {
+ p->setPen( Qt::color1 );
+ p->drawPixmap( x, y, *mask );
+ }
+ else
+ p->fillRect( x, y, w, h, TQBrush( color1, SolidPattern ) );
+ handled = true;
+ }
+ break;
+ }
+
+ case PE_IndicatorMask:
+ {
+ if ( isPixmap( ( flags & Style_On ) ? IndicatorOn : IndicatorOff ) )
+ {
+ const TQBitmap * mask = uncached( ( flags & Style_On ) ? IndicatorOn :
+ IndicatorOff ) ->mask();
+ if ( mask )
+ {
+ p->setPen( Qt::color1 );
+ p->drawPixmap( x, y, *mask );
+ }
+ else
+ p->fillRect( x, y, w, h, TQBrush( color1, SolidPattern ) );
+ handled = true;
+ }
+ break;
+ }
+ case PE_Indicator:
+ {
+ if ( isPixmap( ( flags & Style_On || flags & Style_Down ) ?
+ IndicatorOn : IndicatorOff ) )
+ {
+ p->drawPixmap( x, y, *uncached( ( flags & Style_On || flags & Style_Down ) ?
+ IndicatorOn : IndicatorOff ) );
+ handled = true;
+ }
+ break;
+ }
+ case PE_Splitter:
+ {
+ drawBaseButton( p, x, y, w, h, *colorGroup( g, Splitter ), false, false,
+ Splitter );
+ handled = true;
+ break;
+ }
+ case PE_FocusRect:
+ {
+ if ( is3DFocus() )
+ {
+ p->setPen( g.dark() );
+ 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 );
+ handled = true;
+ }
+ else
+ {
+ handled = true;
+ p->drawWinFocusRect(r);
+ }
+ break;
+ }
+ case PE_PanelMenuBar:
+ {
+ TQPixmap* cache = makeMenuBarCache(w, h);
+ p->drawPixmap( x, y, *cache);
+ handled = true;
+ break;
+ }
+ case PE_ScrollBarAddPage:
+ case PE_ScrollBarSubPage:
+ {
+ WidgetType widget = ( flags & Style_Horizontal ) ? HScrollGroove : VScrollGroove;
+
+ if ( !isPixmap( widget ) )
+ {
+ p->fillRect( r, colorGroup( g, widget ) ->brush( TQColorGroup::Background ) );
+ // Do the borders and frame
+ drawShade( p, r.x(), r.y(), r.width(),
+ r.height(), *colorGroup( g, widget ), true, false,
+ highlightWidth( widget ), borderWidth( widget ), shade() );
+ }
+ else
+ {
+ // If the groove is pixmapped we make a full-sized image (it gets
+ // cached) then bitBlt it to the appropriate rect.
+ p->drawTiledPixmap( r.x(), r.y(), r.width(), r.height(),
+ *scalePixmap( r.width(), r.height(),
+ widget ) );
+ drawShade( p, r.x(), r.y(), r.width(),
+ r.height(), *colorGroup( g, widget ), true, false,
+ highlightWidth( widget ), borderWidth( widget ), shade() );
+ }
+
+ handled = true;
+ break;
+ }
+ case PE_ScrollBarAddLine:
+ {
+ bool horizontal = ( flags & Style_Horizontal );
+ drawBaseButton( p, r.x(), r.y(), r.width(), r.height(),
+ *colorGroup( g, down ? ScrollButtonDown : ScrollButton ),
+ down, false, down ? ScrollButtonDown : ScrollButton );
+
+ drawPrimitive( ( horizontal ) ? PE_ArrowRight : PE_ArrowDown, p, ceData, elementFlags ,
+ TQRect( r.x() + 3, r.y() + 3, r.width() - 6, r.height() - 6 ),
+ *colorGroup( g, down ? ScrollButtonDown : ScrollButton ),
+ flags );
+
+ handled = true;
+ break;
+ }
+ case PE_ScrollBarSubLine:
+ {
+ bool horizontal = ( flags & Style_Horizontal );
+ drawBaseButton( p, r.x(), r.y(), r.width(), r.height(),
+ *colorGroup( g, down ? ScrollButtonDown : ScrollButton ),
+ down, false, down ? ScrollButtonDown : ScrollButton );
+
+ drawPrimitive( ( horizontal ) ? PE_ArrowLeft : PE_ArrowUp, p, ceData, elementFlags ,
+ TQRect( r.x() + 3, r.y() + 3, r.width() - 6, r.height() - 6 ),
+ *colorGroup( g, down ? ScrollButtonDown : ScrollButton ),
+ flags );
+ handled = true;
+ break;
+ }
+ case PE_ScrollBarSlider:
+ {
+ bool active = ( flags & Style_Active ) || ( flags & Style_Down ); //activeControl == TQStyle::AddLine;
+ bool horizontal = ( flags & Style_Horizontal );
+ int offsetH = horizontal ? 0: decoWidth(VScrollGroove) ;
+ int offsetV = horizontal ? decoWidth(HScrollGroove):0;
+
+ WidgetType widget = horizontal ?
+ active ? HScrollBarSliderDown : HScrollBarSlider :
+ active ? VScrollBarSliderDown : VScrollBarSlider;
+ drawBaseButton( p, r.x()+offsetH, r.y()+offsetV, r.width()-2*offsetH,
+ r.height()-2*offsetV, *colorGroup( g, widget ), active, false,
+ widget );
+
+ int spaceW = horizontal ? r.width() - decoWidth( widget ) - 4 :
+ r.width();
+ int spaceH = horizontal ? r.height() :
+ r.height() - decoWidth( widget ) - 4;
+
+ widget = active ? horizontal ? HScrollDecoDown : VScrollDecoDown :
+ horizontal ? HScrollDeco : VScrollDeco;
+ if ( isPixmap( widget ) )
+ {
+ if ( spaceW >= uncached( widget ) ->width() &&
+ spaceH >= uncached( widget ) ->height() )
+ {
+ bitBlt( p->device(),
+ r.x() + ( r.width() - uncached( widget ) ->width() ) / 2,
+ r.y() + ( r.height() - uncached( widget ) ->height() ) / 2,
+ uncached( widget ) );
+ }
+ }
+ handled = true;
+ break;
+
+ }
+
+ case PE_MenuItemIndicatorFrame:
+ {
+ // Draw nothing
+ break;
+ }
+ case PE_MenuItemIndicatorIconFrame:
+ {
+ int x, y, w, h;
+ r.rect( &x, &y, &w, &h );
+ int checkcol = styleHint(SH_MenuIndicatorColumnWidth, ceData, elementFlags, opt, NULL, NULL);
+ bool reverse = TQApplication::reverseLayout();
+
+ int cx = reverse ? x + w - checkcol : x;
+ TQRect cr = visualRect( TQRect( x, y, checkcol, h ), r );
+ const TQColorGroup& cg_ours = *colorGroup( g_base, active ? MenuItemDown : MenuItem );
+ drawBaseButton( p, cr.x(), cr.y(), cr.width(), cr.height(), *colorGroup( cg_ours, BevelDown ), true, false, BevelDown );
+ break;
+ }
+ case PE_MenuItemIndicatorCheck:
+ {
+ int x, y, w, h;
+ r.rect( &x, &y, &w, &h );
+ int checkcol = styleHint(SH_MenuIndicatorColumnWidth, ceData, elementFlags, opt, NULL, NULL);
+ bool reverse = TQApplication::reverseLayout();
+
+ int cx = reverse ? x + w - checkcol : x;
+ TQRect cr = visualRect( TQRect( x, y, checkcol, h ), r );
+ const TQColorGroup& cg_ours = *colorGroup( g_base, active ? MenuItemDown : MenuItem );
+
+ SFlags cflags = Style_Default;
+ cflags |= active ? Style_Enabled : Style_On;
+
+ drawPrimitive( PE_CheckMark, p, ceData, elementFlags, TQRect( x + itemFrame, y + itemFrame, checkcol - itemFrame * 2, h - itemFrame * 2 ), cg_ours, cflags );
+ break;
+ }
+ default:
+ handled = false;
+ }
+
+ if ( !handled )
+ KThemeBase::drawPrimitive ( pe, p, ceData, elementFlags, r, g,
+ flags, opt );
+}
+
+
+
+TQPixmap* KThemeStyle::makeMenuBarCache(int w, int h) const
+{
+ if (menuCache)
+ {
+ if (menuCache->width() != w || menuCache->height() != h )
+ {
+ delete menuCache;
+ }
+ else
+ return menuCache;
+ }
+
+ const TQColorGroup *g = colorGroup( TQApplication::palette().active(), MenuBar);
+
+ menuCache = new TQPixmap ( w, h );
+ TQPainter p(menuCache);
+ drawBaseButton( &p, 0, 0, w, h, *g, false, false, MenuBar );
+ p.end();
+ return menuCache;
+}
+
+
+void KThemeStyle::drawControl( ControlElement element,
+ TQPainter *p,
+ const TQStyleControlElementData &ceData,
+ ControlElementFlags elementFlags,
+ const TQRect &r,
+ const TQColorGroup &cg,
+ SFlags how ,
+ const TQStyleOption& opt,
+ const TQWidget *widget ) const
+{
+ bool handled = false;
+ int x, y, w, h;
+ r.rect( &x, &y, &w, &h );
+
+
+ switch ( element )
+ {
+ case CE_PushButton:
+ {
+ const TQPushButton * btn = ( const TQPushButton* ) widget;
+ bool sunken = btn->isOn() || btn->isDown();
+ int diw = pixelMetric( PM_ButtonDefaultIndicator, ceData, elementFlags, btn );
+ drawBaseButton( p, diw, diw, w - 2 * diw, h - 2 * diw,
+ *colorGroup( btn->colorGroup(), sunken ? PushButtonDown :
+ PushButton ), sunken, roundButton(),
+ sunken ? PushButtonDown : PushButton );
+ // TODO if diw, draw fancy default button indicator
+ handled = true;
+ break;
+ }
+ case CE_PushButtonLabel:
+ {
+ const TQPushButton* button = ( const TQPushButton* ) widget;
+ bool active = button->isOn() || button->isDown();
+ int x, y, w, h;
+ r.rect( &x, &y, &w, &h );
+
+ // Shift button contents if pushed.
+ if ( active )
+ {
+ x += pixelMetric( PM_ButtonShiftHorizontal, ceData, elementFlags, widget );
+ y += pixelMetric( PM_ButtonShiftVertical, ceData, elementFlags, widget );
+ how |= Style_Sunken;
+ }
+
+ // Does the button have a popup menu?
+ if ( button->isMenuButton() )
+ {
+ int dx = pixelMetric( PM_MenuButtonIndicator, ceData, elementFlags, widget );
+ drawPrimitive( PE_ArrowDown, p, ceData, elementFlags, TQRect( x + w - dx - 2, y + 2, dx, h - 4 ),
+ cg, how, opt );
+ w -= dx;
+ }
+
+ // Draw the icon if there is one
+ if ( button->iconSet() && !button->iconSet() ->isNull() )
+ {
+ TQIconSet::Mode mode = TQIconSet::Disabled;
+ TQIconSet::State state = TQIconSet::Off;
+
+ if ( button->isEnabled() )
+ mode = button->hasFocus() ? TQIconSet::Active : TQIconSet::Normal;
+ if ( button->isToggleButton() && button->isOn() )
+ state = TQIconSet::On;
+
+ TQPixmap pixmap = button->iconSet() ->pixmap( TQIconSet::Small, mode, state );
+
+ // Center the iconset if there's no text or pixmap
+ if (button->text().isEmpty() && !button->pixmap())
+ p->drawPixmap( x + (w - pixmap.width()) / 2,
+ y + (h - pixmap.height()) / 2, pixmap );
+ else
+ p->drawPixmap( x + 4, y + (h - pixmap.height()) / 2, pixmap );
+
+ int pw = pixmap.width();
+ x += pw + 4;
+ w -= pw + 4;
+ }
+
+ // Make the label indicate if the button is a default button or not
+ if ( active || button->isDefault() && button->isEnabled() )
+ {
+ // Draw "fake" bold text - this enables the font metrics to remain
+ // the same as computed in TQPushButton::sizeHint(), but gives
+ // a reasonable bold effect.
+ int i;
+
+ // Text shadow
+ for ( i = 0; i < 2; i++ )
+ drawItem( p, TQRect( x + i + 1, y + 1, w, h ), AlignCenter | ShowPrefix,
+ button->colorGroup(), button->isEnabled(), NULL,
+ button->text(), -1,
+ active ? &button->colorGroup().dark() : &button->colorGroup().mid() );
+
+ // Normal Text
+ for ( i = 0; i < 2; i++ )
+ drawItem( p, TQRect( x + i, y, w, h ), AlignCenter | ShowPrefix,
+ button->colorGroup(), true, i == 0 ? button->pixmap() : NULL,
+ button->text(), -1,
+ active ? &button->colorGroup().light() : &button->colorGroup().buttonText() );
+ }
+ else
+ {
+ if ( button->isEnabled() )
+ {
+ drawItem( p, TQRect( x, y, w, h ), AlignCenter | ShowPrefix, button->colorGroup(),
+ true, button->pixmap(), button->text(), -1,
+ active ? &button->colorGroup().light() : &button->colorGroup().buttonText() );
+ }
+ else
+ {
+ //TODO: Handle reversed
+ drawItem( p, TQRect( x + 1, y + 1, w, h ), AlignCenter | ShowPrefix, button->colorGroup(),
+ true, button->pixmap(), button->text(), -1,
+ &button->colorGroup().light() );
+
+ drawItem( p, TQRect( x, y, w, h ), AlignCenter | ShowPrefix, button->colorGroup(),
+ true, button->pixmap(), button->text(), -1,
+ &button->colorGroup().buttonText() );
+ }
+ }
+
+ // Draw a focus rect if the button has focus
+ if ( how & Style_HasFocus )
+ drawPrimitive( PE_FocusRect, p, ceData, elementFlags,
+ TQStyle::visualRect( subRect( SR_PushButtonFocusRect, ceData, elementFlags, widget ), ceData, elementFlags ),
+ cg, how );
+ handled = true;
+ break;
+ }
+
+ case CE_MenuBarEmptyArea:
+ {
+ //Expand to cover entire region
+ drawPrimitive(PE_PanelMenuBar, p, ceData, elementFlags,
+ TQRect(0,0,r.width()+r.x()*2, r.height()+r.y()*2),
+ cg, Style_Default);
+ handled = true;
+ break;
+ }
+
+ case CE_TabBarTab:
+ {
+ TQTabBar::Shape tbs = ceData.tabBarData.shape;
+ bool selected = how & Style_Selected;
+ WidgetType widget = selected ? ActiveTab : InactiveTab;
+ const TQColorGroup *cg = colorGroup( ceData.colorGroup, widget );
+ int i;
+ int x2 = x + w - 1, y2 = y + h - 1;
+ int bWidth = borderWidth( widget );
+ int hWidth = highlightWidth( widget );
+ handled = true;
+ if ( tbs == TQTabBar::RoundedAbove || tbs == TQTabBar::TriangularAbove )
+ {
+ if ( !selected )
+ {
+ p->fillRect( x, y, x2 - x + 1, 2,
+ ceData.palette.active().brush( TQColorGroup::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 ( ceData.tabBarData.shape == TQTabBar::RoundedBelow ||
+ ceData.tabBarData.shape == TQTabBar::TriangularBelow )
+ {
+ if ( widget == ActiveTab )
+ widget = RotActiveTab;
+ else
+ widget = RotInactiveTab;
+
+ if ( !selected )
+ {
+ p->fillRect( x, y2 - 2, x2 - x + 1, 2,
+ ceData.palette.active().brush( TQColorGroup::Background ) );
+ y2 -= 2;
+ }
+ p->setPen( cg->text() );
+ i = 0;
+ if ( i < bWidth )
+ {
+ p->drawLine( x, y, x, y2 - 1 );
+ p->drawLine( x2, y, x2, y2 - 1 );
+ p->drawLine( x + 1, y2, x2 - 1, y2 );
+ if ( selected ? activeTabLine() : inactiveTabLine() )
+ {
+ p->drawLine( x, y, x2, y );
+ ++y;
+ }
+ }
+ for ( ; i < bWidth; ++i, ++x, --x2, --y2 )
+ {
+ p->drawLine( x, y, x, y2 );
+ p->drawLine( x2, y, x2, y2 );
+ p->drawLine( x, y2, x2, y2 );
+ if ( selected ? activeTabLine() : inactiveTabLine() )
+ {
+ p->drawLine( x, y, x2, y );
+ ++y;
+ }
+ }
+ i = 0;
+ if ( i < hWidth && bWidth == 0 )
+ {
+ p->setPen( cg->dark() );
+ p->drawLine( x + 1, y2, x2 - 1, y2 );
+ p->drawLine( x2, y, x2, y2 - 1 );
+ p->setPen( cg->light() );
+ p->drawLine( x, y, x, y2 - 1 );
+ if ( selected ? activeTabLine() : inactiveTabLine() )
+ {
+ p->drawLine( x, y, x2, y );
+ ++y;
+ }
+ ++i, ++x, --x2, --y2;
+ }
+ for ( ; i < hWidth; ++i, ++x, --x2, --y2 )
+ {
+ p->setPen( cg->dark() );
+ p->drawLine( x, y2, x2, y2 );
+ p->drawLine( x2, y, x2, y2 );
+ p->setPen( cg->light() );
+ p->drawLine( x, y, x, y2 );
+ if ( selected ? activeTabLine() : inactiveTabLine() )
+ {
+ p->drawLine( x, y, x2, y );
+ ++y;
+ }
+ }
+ 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() );
+ }
+ break;
+ }
+ case CE_MenuBarItem:
+ {
+
+ r.rect( &x, &y, &w, &h );
+ TQMenuItem *mi = opt.menuItem();
+ TQMenuBar *mb = ( TQMenuBar* ) widget;
+ TQRect pr = mb->rect();
+ bool active = how & Style_Active;
+ //bool focused = how & Style_HasFocus;
+ const TQColorGroup *g = colorGroup( cg, active ? MenuBarItem : MenuBar );
+ TQColor btext = g->buttonText();
+
+ TQPixmap* cache = makeMenuBarCache(pr.width(), pr.height());
+
+ TQPixmap buf( w, pr.height() );
+
+ bitBlt(&buf, 0, 0, cache, x, y, w, pr.height());
+ TQPainter p2( &buf );
+
+ if ( active )
+ {
+ drawBaseButton( &p2, 0, 0, w, h, *g, false, false, MenuBarItem );
+ }
+
+ p2.end();
+ p->drawPixmap( x, y, buf, 0, 0, w, h );
+
+ drawItem( p, TQRect(x,y,w,h), AlignCenter | AlignVCenter | ShowPrefix | DontClip | SingleLine,
+ *g, mi->isEnabled(), mi->pixmap(), mi->text(),
+ -1, &btext );
+ handled = true;
+ break;
+ }
+ case CE_PopupMenuItem:
+ {
+ bool separator = false;
+ int x, y, w, h;
+ r.rect( &x, &y, &w, &h );
+
+ TQMenuItem *mi = opt.menuItem();
+ if ( mi )
+ {
+ separator = mi->isSeparator();
+ }
+
+ int tab = opt.tabWidth();
+ int checkcol = opt.maxIconWidth();
+ bool enabled = (mi? mi->isEnabled():true);
+ bool checkable = (elementFlags & CEF_IsCheckable);
+ bool active = how & Style_Active;
+ bool etchtext = styleHint( SH_EtchDisabledText, ceData, elementFlags, TQStyleOption::Default, 0, 0 );
+ bool reverse = TQApplication::reverseLayout();
+
+ const TQColorGroup& cg_ours = *colorGroup( cg, active ? MenuItemDown : MenuItem );
+ //TQColor btext = cg_ours.buttonText();
+
+
+ if ( checkable )
+ checkcol = QMAX( checkcol, 20 );
+
+ // Are we a menu item separator?
+ if ( separator )
+ {
+ p->setPen( cg_ours.dark() );
+ p->drawLine( x, y, x + w, y );
+ p->setPen( cg_ours.light() );
+ p->drawLine( x, y + 1, x + w, y + 1 );
+ break;
+ }
+
+ // Draw the menu item background
+ if ( active )
+ drawBaseButton( p, x, y, w, h, cg_ours, true, false, MenuItemDown );
+ else
+ {
+ drawShade( p, x, y, w, h, *colorGroup( cg_ours, MenuItem ), false, false,
+ highlightWidth( MenuItem ), borderWidth( MenuItem ),
+ shade() );
+ int dw = decoWidth( MenuItem );
+ if ( !isPixmap( MenuItem ) )
+ {
+ p->fillRect(
+ x + dw, y + dw, w - dw * 2, h - dw * 2,
+ cg_ours.brush( TQColorGroup::Background ) );
+ //cg.brush( TQColorGroup::Background ));
+ //colorGroup( cg_ours, MenuItem ) ->brush( TQColorGroup::Background ) );
+ }
+ else
+ {
+ // process inactive item pixmaps as one large item
+ p->drawTiledPixmap( x + dw, y + dw, w - dw * 2, h - dw * 2, *scalePixmap
+ ( w, p->window().height(), MenuItem ),
+ x, y );
+ }
+ }
+
+ if (!mi)
+ break;
+
+ // Do we have an icon?
+ if ( mi->iconSet() )
+ {
+ TQIconSet::Mode mode;
+ TQRect cr = visualRect( TQRect( x, y, checkcol, h ), r );
+
+ // Select the correct icon from the iconset
+ if ( active )
+ mode = enabled ? TQIconSet::Active : TQIconSet::Disabled;
+ else
+ mode = enabled ? TQIconSet::Normal : TQIconSet::Disabled;
+
+ // Do we have an icon and are checked at the same time?
+ // Then draw a "pressed" background behind the icon
+ if ( checkable && mi->isChecked() ) //!active && -- ??
+ drawPrimitive(PE_MenuItemIndicatorIconFrame, p, ceData, elementFlags, r, cg, how, opt);
+
+ // Draw the icon
+ TQPixmap pixmap = mi->iconSet() ->pixmap( TQIconSet::Small, mode );
+ int pixw = pixmap.width();
+ int pixh = pixmap.height();
+ TQRect pmr( 0, 0, pixw, pixh );
+ pmr.moveCenter( cr.center() );
+ p->setPen( cg_ours.highlightedText() );
+ p->drawPixmap( pmr.topLeft(), pixmap );
+ }
+
+ // Are we checked? (This time without an icon)
+ else if ( checkable && mi->isChecked() )
+ {
+ // We only have to draw the background if the menu item is inactive -
+ // if it's active the "pressed" background is already drawn
+ //if ( ! active )
+ // qDrawShadePanel( p, cx, y, checkcol, h, cg_ours, true, 1,
+ // &cg_ours.brush(TQColorGroup::Midlight) );
+
+ // Draw the checkmark
+ drawPrimitive(PE_MenuItemIndicatorCheck, p, ceData, elementFlags, r, cg, how, opt);
+ }
+
+ // Time to draw the menu item label...
+ int xm = itemFrame + checkcol + itemHMargin; // X position margin
+
+ int xp = reverse ? // X position
+ x + tab + rightBorder + itemHMargin + itemFrame - 1 :
+ x + xm;
+
+ int offset = reverse ? -1 : 1; // Shadow offset for etched text
+
+ // Label width (minus the width of the accelerator portion)
+ int tw = w - xm - tab - arrowHMargin - itemHMargin * 3 - itemFrame + 1;
+
+ // Set the color for enabled and disabled text
+ // (used for both active and inactive menu items)
+ p->setPen( enabled ? cg_ours.buttonText() : cg_ours.mid() );
+
+ // This color will be used instead of the above if the menu item
+ // is active and disabled at the same time. (etched text)
+ TQColor discol = cg_ours.mid();
+
+ // Does the menu item draw it's own label?
+ if ( mi->custom() )
+ {
+ int m = itemVMargin;
+ // Save the painter state in case the custom
+ // paint method changes it in some way
+ p->save();
+
+ // Draw etched text if we're inactive and the menu item is disabled
+ if ( etchtext && !enabled && !active )
+ {
+ p->setPen( cg_ours.light() );
+ mi->custom() ->paint( p, cg_ours, active, enabled, xp + offset, y + m + 1, tw, h - 2 * m );
+ p->setPen( discol );
+ }
+ mi->custom() ->paint( p, cg_ours, active, enabled, xp, y + m, tw, h - 2 * m );
+ p->restore();
+ }
+ else
+ {
+ // The menu item doesn't draw it's own label
+ TQString s = mi->text();
+
+ // Does the menu item have a text label?
+ if ( !s.isNull() )
+ {
+ int t = s.find( '\t' );
+ int m = itemVMargin;
+ int text_flags = AlignVCenter | ShowPrefix | DontClip | SingleLine;
+ text_flags |= reverse ? AlignRight : AlignLeft;
+
+ // Does the menu item have a tabstop? (for the accelerator text)
+ if ( t >= 0 )
+ {
+ int tabx = reverse ? x + rightBorder + itemHMargin + itemFrame :
+ x + w - tab - rightBorder - itemHMargin - itemFrame;
+
+
+ // Draw the right part of the label (accelerator text)
+ if ( etchtext && !enabled && !active )
+ {
+ // Draw etched text if we're inactive and the menu item is disabled
+ p->setPen( cg_ours.light() );
+ p->drawText( tabx + offset, y + m + 1, tab, h - 2 * m, text_flags, s.mid( t + 1 ) );
+ p->setPen( discol );
+ }
+ p->drawText( tabx, y + m, tab, h - 2 * m, text_flags, s.mid( t + 1 ) );
+ s = s.left( t );
+ }
+
+
+ // Draw the left part of the label (or the whole label
+ // if there's no accelerator)
+ if ( etchtext && !enabled && !active )
+ {
+ // Etched text again for inactive disabled menu items...
+ p->setPen( cg_ours.light() );
+ p->drawText( xp + offset, y + m + 1, tw, h - 2 * m, text_flags, s, t );
+ p->setPen( discol );
+ }
+
+ p->drawText( xp, y + m, tw, h - 2 * m, text_flags, s, t );
+
+ }
+
+ // The menu item doesn't have a text label
+ // Check if it has a pixmap instead
+ else if ( mi->pixmap() )
+ {
+ TQPixmap * pixmap = mi->pixmap();
+
+ // Draw the pixmap
+ if ( pixmap->depth() == 1 )
+ p->setBackgroundMode( Qt::OpaqueMode );
+
+ int diffw = ( ( w - pixmap->width() ) / 2 )
+ + ( ( w - pixmap->width() ) % 2 );
+ p->drawPixmap( x + diffw, y + itemFrame, *pixmap );
+
+ if ( pixmap->depth() == 1 )
+ p->setBackgroundMode( Qt::TransparentMode );
+ }
+ }
+
+ // Does the menu item have a submenu?
+ if ( mi->popup() )
+ {
+ PrimitiveElement arrow = reverse ? PE_ArrowLeft : PE_ArrowRight;
+ int dim = 10 - itemFrame; //We're not very useful to inherit off, so just hardcode..
+ TQRect vr = visualRect( TQRect( x + w - arrowHMargin - itemFrame - dim,
+ y + h / 2 - dim / 2, dim, dim ), r );
+
+ // Draw an arrow at the far end of the menu item
+ if ( active )
+ {
+ if ( enabled )
+ discol = cg_ours.buttonText();
+
+ TQColorGroup g2( discol, cg_ours.highlight(), white, white,
+ enabled ? white : discol, discol, white );
+
+ drawPrimitive( arrow, p, ceData, elementFlags, vr, g2, Style_Enabled | Style_Down );
+ }
+ else
+ drawPrimitive( arrow, p, ceData, elementFlags, vr, cg_ours,
+ enabled ? Style_Enabled : Style_Default );
+ }
+ handled = true;
+ break;
+ }
+ case CE_ProgressBarGroove:
+ {
+ TQBrush bg;
+ const TQColorGroup * cg2 = colorGroup( cg, ProgressBg );
+ qDrawWinPanel( p, r, *cg2, true );
+ bg.setColor( cg2->color( TQColorGroup::Background ) );
+ if ( isPixmap( ProgressBg ) )
+ bg.setPixmap( *uncached( ProgressBg ) );
+ p->fillRect( x + 2, y + 2, w - 4, h - 4, bg );
+
+ handled = true;
+ break;
+ }
+ case CE_ProgressBarContents:
+ {
+ const TQProgressBar* pb = (const TQProgressBar*)widget;
+ TQRect cr = subRect(SR_ProgressBarContents, ceData, elementFlags, widget);
+ double progress = pb->progress();
+ bool reverse = TQApplication::reverseLayout();
+ int steps = pb->totalSteps();
+
+ int pstep = 0;
+
+ if (!cr.isValid())
+ return;
+
+ // Draw progress bar
+ if (progress > 0 || steps == 0)
+ {
+ double pg = (steps == 0) ? 0.1 : progress / steps;
+ int width = QMIN(cr.width(), (int)(pg * cr.width()));
+ if (steps == 0)
+ { //Busy indicator
+
+ if (width < 1) width = 1; //A busy indicator with width 0 is kind of useless
+
+ int remWidth = cr.width() - width; //Never disappear completely
+ if (remWidth <= 0) remWidth = 1; //Do something non-crashy when too small...
+
+ pstep = int(progress) % ( 2 * remWidth );
+
+ if ( pstep > remWidth )
+ {
+ //Bounce about.. We're remWidth + some delta, we want to be remWidth - delta...
+ // - ( (remWidth + some delta) - 2* remWidth ) = - (some deleta - remWidth) = remWidth - some delta..
+ pstep = - (pstep - 2 * remWidth );
+ }
+ }
+
+ if ( !reverse )
+ drawBaseButton( p, x + pstep, y, width, h, *colorGroup( cg, ProgressBar ), false, false, ProgressBar );
+ else
+ {
+ //TODO:Optimize
+ TQPixmap buf( width, h );
+ TQPainter p2( &buf );
+ drawBaseButton( &p2, 0, 0, width, h, *colorGroup( cg, ProgressBar ), false, false, ProgressBar );
+ p2.end();
+ TQPixmap mirroredPix = TQPixmap( TQImage(buf.convertToImage()).mirror( true, false ) );
+ bitBlt( p->device(), x + w - width - pstep, y, &mirroredPix );
+ }
+ }
+
+ handled = true;
+ break;
+ }
+ default:
+ handled = false;
+ };
+
+ if ( !handled )
+ KThemeBase::drawControl( element,
+ p, ceData, elementFlags, r, cg, how, opt, widget );
+}
+
+
+void KThemeStyle::drawControlMask( ControlElement element,
+ TQPainter *p,
+ const TQStyleControlElementData &ceData,
+ ControlElementFlags elementFlags,
+ const TQRect &r,
+ const TQStyleOption& opt,
+ const TQWidget *widget ) const
+{
+ bool handled = false;
+ int x, y, w, h;
+ r.rect( &x, &y, &w, &h );
+
+ switch ( element )
+ {
+ case CE_PushButton:
+ {
+ //Is this correct?
+ drawBaseMask( p, x, y, w, h, roundButton() );
+ handled = true;
+ break;
+ }
+ default:
+ handled = false;
+ };
+
+ if ( !handled )
+ KThemeBase::drawControlMask( element,
+ p, ceData, elementFlags, r, opt, widget );
+
+}
+
+
+void KThemeStyle::drawTDEStylePrimitive( TDEStylePrimitive kpe,
+ TQPainter* p,
+ const TQStyleControlElementData &ceData,
+ ControlElementFlags elementFlags,
+ const TQRect &r,
+ const TQColorGroup &cg,
+ SFlags flags,
+ const TQStyleOption& opt,
+ const TQWidget* widget ) const
+{
+ bool handled = false;
+ int x, y, w, h;
+ r.rect( &x, &y, &w, &h );
+ switch ( kpe )
+ {
+ case KPE_SliderGroove:
+ {
+ if ( !roundSlider() )
+ {
+ const TQSlider * slider = ( const TQSlider* ) widget;
+ bool horizontal = slider->orientation() == Qt::Horizontal;
+ if ( horizontal )
+ {
+ drawBaseButton( p, x, y, w, h, *colorGroup( cg, SliderGroove ), true,
+ false, SliderGroove );
+ }
+ else
+ {
+ drawBaseButton( p, x, y, w, h, *colorGroup( cg, RotSliderGroove ), true,
+ false, RotSliderGroove );
+ }
+ }
+ else
+ {
+ //This code is from HighColorDefault..
+ const TQSlider* slider = ( const TQSlider* ) widget;
+ bool horizontal = slider->orientation() == Qt::Horizontal;
+ int gcenter = ( horizontal ? r.height() : r.width() ) / 2;
+
+ TQRect gr;
+ if ( horizontal )
+ gr = TQRect( r.x(), r.y() + gcenter - 3, r.width(), 7 );
+ else
+ gr = TQRect( r.x() + gcenter - 3, r.y(), 7, r.height() );
+
+ int x, y, w, h;
+ gr.rect( &x, &y, &w, &h );
+ int x2 = x + w - 1;
+ int y2 = y + h - 1;
+
+ // Draw the slider groove.
+ p->setPen( cg.dark() );
+ p->drawLine( x + 2, y, x2 - 2, y );
+ p->drawLine( x, y + 2, x, y2 - 2 );
+ p->fillRect( x + 2, y + 2, w - 4, h - 4,
+ slider->isEnabled() ? cg.dark() : cg.mid() );
+ p->setPen( cg.shadow() );
+ p->drawRect( x + 1, y + 1, w - 2, h - 2 );
+ p->setPen( cg.light() );
+ p->drawPoint( x + 1, y2 - 1 );
+ p->drawPoint( x2 - 1, y2 - 1 );
+ p->drawLine( x2, y + 2, x2, y2 - 2 );
+ p->drawLine( x + 2, y2, x2 - 2, y2 );
+ }
+ handled = true;
+ break;
+ }
+ case KPE_SliderHandle:
+ {
+ if ( isPixmap( Slider ) )
+ {
+ const TQSlider * slider = ( const TQSlider* ) widget;
+ bool horizontal = slider->orientation() == Qt::Horizontal;
+ if ( horizontal )
+ {
+ bitBlt( p->device(), x, y + ( h - uncached( Slider ) ->height() ) / 2,
+ uncached( Slider ) );
+ }
+ else
+ {
+ if ( !vsliderCache )
+ {
+ TQWMatrix r270;
+ r270.rotate( 270 );
+ vsliderCache = new TQPixmap( uncached( Slider ) ->xForm( r270 ) );
+ if ( uncached( Slider ) ->mask() )
+ vsliderCache->setMask( uncached( Slider ) ->mask() ->xForm( r270 ) );
+ }
+ bitBlt( p->device(), x + ( w - vsliderCache->width() ) / 2, y,
+ vsliderCache );
+ }
+ }
+ else
+ {
+ //This code again from HighColor..
+ //...except sans the gradient..
+ const TQSlider* slider = ( const TQSlider* ) widget;
+ bool horizontal = slider->orientation() == Qt::Horizontal;
+ int x, y, w, h;
+ r.rect( &x, &y, &w, &h );
+ int x2 = x + w - 1;
+ int y2 = y + h - 1;
+
+ p->setPen( cg.mid() );
+ p->drawLine( x + 1, y, x2 - 1, y );
+ p->drawLine( x, y + 1, x, y2 - 1 );
+ p->setPen( cg.shadow() );
+ p->drawLine( x + 1, y2, x2 - 1, y2 );
+ p->drawLine( x2, y + 1, x2, y2 - 1 );
+
+ p->setPen( cg.light() );
+ p->drawLine( x + 1, y + 1, x2 - 1, y + 1 );
+ p->drawLine( x + 1, y + 1, x + 1, y2 - 1 );
+ p->setPen( cg.dark() );
+ p->drawLine( x + 2, y2 - 1, x2 - 1, y2 - 1 );
+ p->drawLine( x2 - 1, y + 2, x2 - 1, y2 - 1 );
+ p->setPen( cg.midlight() );
+ p->drawLine( x + 2, y + 2, x2 - 2, y + 2 );
+ p->drawLine( x + 2, y + 2, x + 2, y2 - 2 );
+ p->setPen( cg.mid() );
+ p->drawLine( x + 3, y2 - 2, x2 - 2, y2 - 2 );
+ p->drawLine( x2 - 2, y + 3, x2 - 2, y2 - 2 );
+ p->fillRect( TQRect( x + 3, y + 3, w - 6, h - 6 ),
+ cg.button() );
+
+ // Paint riffles
+ if ( horizontal )
+ {
+ p->setPen( cg.light() );
+ p->drawLine( x + 5, y + 4, x + 5, y2 - 4 );
+ p->drawLine( x + 8, y + 4, x + 8, y2 - 4 );
+ p->drawLine( x + 11, y + 4, x + 11, y2 - 4 );
+ p->setPen( slider->isEnabled() ? cg.shadow() : cg.mid() );
+ p->drawLine( x + 6, y + 4, x + 6, y2 - 4 );
+ p->drawLine( x + 9, y + 4, x + 9, y2 - 4 );
+ p->drawLine( x + 12, y + 4, x + 12, y2 - 4 );
+ }
+ else
+ {
+ p->setPen( cg.light() );
+ p->drawLine( x + 4, y + 5, x2 - 4, y + 5 );
+ p->drawLine( x + 4, y + 8, x2 - 4, y + 8 );
+ p->drawLine( x + 4, y + 11, x2 - 4, y + 11 );
+ p->setPen( slider->isEnabled() ? cg.shadow() : cg.mid() );
+ p->drawLine( x + 4, y + 6, x2 - 4, y + 6 );
+ p->drawLine( x + 4, y + 9, x2 - 4, y + 9 );
+ p->drawLine( x + 4, y + 12, x2 - 4, y + 12 );
+ }
+ }
+ handled = true;
+ break;
+ }
+ //case KPE_DockWindowHandle:
+ case KPE_ToolBarHandle:
+ case KPE_GeneralHandle:
+ {
+ if ( w > h )
+ drawBaseButton( p, x, y, w, h, *colorGroup( cg, HBarHandle ), false, false,
+ HBarHandle );
+ else
+ drawBaseButton( p, x, y, w, h, *colorGroup( cg, VBarHandle ), false, false,
+ VBarHandle );
+
+ handled = true;
+ break;
+ }
+ default:
+ handled = false;
+
+ }
+
+ if ( !handled )
+ {
+ KThemeBase::drawTDEStylePrimitive( kpe, p, ceData, elementFlags,
+ r, cg, flags, opt, widget );
+ }
+
+}
+
+
+
+
+void KThemeStyle::drawComplexControl ( TQ_ComplexControl control, TQPainter * p, const TQStyleControlElementData &ceData, ControlElementFlags elementFlags,
+ const TQRect & r, const TQColorGroup & g, SFlags how ,
+ SCFlags controls, SCFlags active,
+ const TQStyleOption & opt, const TQWidget * widget ) const
+{
+ bool handled = false;
+ int x, y, w, h;
+ r.rect( &x, &y, &w, &h );
+ bool down = how & Style_Down;
+ bool on = how & Style_On;
+
+ // bool enabled = ( how & Style_Enabled );
+
+ switch ( control )
+ {
+ case CC_ToolButton:
+ {
+ const TQToolButton * toolbutton = ( const TQToolButton * ) widget;
+ TQRect button, menu;
+ button = querySubControlMetrics( control, ceData, elementFlags, SC_ToolButton, opt, widget );
+ menu = querySubControlMetrics( control, ceData, elementFlags, SC_ToolButtonMenu, opt, widget );
+
+
+ if ( controls & SC_ToolButton )
+ {
+ WidgetType widget = ( down || on ) ? ToolButtonDown : ToolButton;
+
+ drawBaseButton( p, button.x(), button.y(), button.width(), button.height(), *colorGroup( g, widget ), down || on, false,
+ widget );
+
+ // int m = decoWidth( widget );
+ }
+
+ if ( controls & SC_ToolButtonMenu )
+ {
+ drawPrimitive( PE_ArrowDown, p, ceData, elementFlags, menu, g, how );
+ /* if ( enabled )
+ kDrawWindowsArrow(p, ceData, elementFlags, this, PE_ArrowDown, false, menu.x(), menu.y(), menu.width(), menu.height(),
+ g, true );
+ else
+ kDrawWindowsArrow(p, ceData, elementFlags, this, PE_ArrowDown, false, menu.x(), menu.y(), menu.width(), menu.height(),
+ g, false );*/
+ }
+
+ if ( toolbutton->hasFocus() && !toolbutton->focusProxy() )
+ {
+ TQRect fr = toolbutton->rect();
+ fr.addCoords( 3, 3, -3, -3 );
+ drawPrimitive( PE_FocusRect, p, ceData, elementFlags, fr, g );
+ }
+
+ handled = true;
+ break;
+ }
+
+ case CC_ComboBox:
+ {
+ if ( controls & SC_ComboBoxFrame )
+ {
+ //TODO: Anyway of detecting when the popup is there -- would look nicer if sunken then too..
+ bool sunken = ( active == SC_ComboBoxArrow );
+ //No frame, edit box and button for now?
+ WidgetType widget = sunken ? ComboBoxDown : ComboBox;
+ drawBaseButton( p, x, y, w, h, *colorGroup( g, widget ), sunken,
+ roundComboBox(), widget );
+
+ controls ^= SC_ComboBoxFrame;
+ }
+
+ if ( controls & SC_ComboBoxArrow )
+ {
+ bool sunken = ( active == SC_ComboBoxArrow );
+ TQRect ar = TQStyle::visualRect(
+ querySubControlMetrics( CC_ComboBox, ceData, elementFlags, SC_ComboBoxArrow, TQStyleOption::Default, widget ),
+ ceData, elementFlags );
+ ar.rect( &x, &y, &w, &h );
+ WidgetType widget = sunken ? ComboBoxDown : ComboBox;
+
+ if ( !sunken && isPixmap( ComboDeco ) )
+ bitBlt( p->device(),
+ x + ( w - uncached( ComboDeco ) ->width() - decoWidth( ComboBox ) / 2 ),
+ y + ( h - uncached( ComboDeco ) ->height() ) / 2,
+ uncached( ComboDeco ) );
+ else if ( sunken && isPixmap( ComboDecoDown ) )
+ bitBlt( p->device(),
+ x + ( w - uncached( ComboDecoDown ) ->width() - decoWidth( ComboBoxDown ) ) / 2,
+ y + ( h - uncached( ComboDecoDown ) ->height() ) / 2,
+ uncached( ComboDecoDown ) );
+ else
+ {
+
+ mtfstyle->drawPrimitive( PE_ArrowDown, p, ceData, elementFlags, TQRect( x, y, w, h ), *colorGroup( g, widget ), sunken ? ( how | Style_Sunken ) : how, opt );
+ qDrawShadeRect( p, x, y, w, h, *colorGroup( g, widget ) ); //w-14, y+7+(h-15), 10, 3,
+ }
+ controls ^= SC_ComboBoxArrow;
+ }
+ break;
+ }
+ case CC_ScrollBar:
+ {
+ const TQScrollBar *sb = ( const TQScrollBar* ) widget;
+ bool maxedOut = ( sb->minValue() == sb->maxValue() );
+ bool horizontal = ( sb->orientation() == Qt::Horizontal );
+ SFlags sflags = ( ( horizontal ? Style_Horizontal : Style_Default ) |
+ ( maxedOut ? Style_Default : Style_Enabled ) );
+
+ //Here, we don't do add page, subpage, etc.,
+ TQRect addline, subline, subline2, groove, slider;
+ subline = querySubControlMetrics( control, ceData, elementFlags, SC_ScrollBarSubLine, opt, widget );
+ addline = querySubControlMetrics( control, ceData, elementFlags, SC_ScrollBarAddLine, opt, widget );
+ groove = querySubControlMetrics( control, ceData, elementFlags, SC_ScrollBarGroove, opt, widget );
+
+ slider = querySubControlMetrics( control, ceData, elementFlags, SC_ScrollBarSlider, opt, widget );
+ subline2 = addline;
+
+ TQPixmap buf( sb->width(), sb->height() );
+ TQPainter p2( &buf );
+
+ if ( groove.isValid() )
+ {
+ p2.fillRect( groove, TQColor( 255, 0, 0 ) );
+ drawPrimitive( PE_ScrollBarSubPage, &p2, ceData, elementFlags, groove, g,
+ sflags | ( ( active == SC_ScrollBarSubPage ) ?
+ Style_Down : Style_Default ) );
+ }
+
+
+ // Draw the up/left button set
+ if ( subline.isValid() )
+ {
+ drawPrimitive( PE_ScrollBarSubLine, &p2, ceData, elementFlags, subline, g,
+ sflags | ( active == SC_ScrollBarSubLine ?
+ Style_Down : Style_Default ) );
+ }
+
+ if ( addline.isValid() )
+ drawPrimitive( PE_ScrollBarAddLine, &p2, ceData, elementFlags, addline, g,
+ sflags | ( ( active == SC_ScrollBarAddLine ) ?
+ Style_Down : Style_Default ) );
+
+ if ( slider.isValid() )
+ { //(controls & SC_ScrollBarSlider) &&
+ drawPrimitive( PE_ScrollBarSlider, &p2, ceData, elementFlags, slider, g,
+ sflags | ( ( active == SC_ScrollBarSlider ) ?
+ Style_Down : Style_Default ) );
+ // Draw focus rect
+ if ( sb->hasFocus() )
+ {
+ TQRect fr( slider.x() + 2, slider.y() + 2,
+ slider.width() - 5, slider.height() - 5 );
+ drawPrimitive( PE_FocusRect, &p2, ceData, elementFlags, fr, g, Style_Default );
+ }
+ p2.end();
+ bitBlt( p->device(), x, y, &buf );
+ handled = true;
+
+ }
+ break;
+ }
+ default:
+ handled = false;
+ }
+
+ if ( !handled )
+ {
+ KThemeBase::drawComplexControl ( control, p, ceData, elementFlags,
+ r, g, how ,
+ controls, active,
+ opt, widget );
+ }
+
+}
+
+
+void KThemeStyle::drawBaseMask( TQPainter *p, int x, int y, int w, int h,
+ bool round ) const
+{
+ // round edge fills
+ static const TQCOORD 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 TQCOORD 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 TQCOORD 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 TQCOORD 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
+ };
+
+ TQBrush fillBrush( color1, SolidPattern );
+ p->setPen( color1 );
+ if ( round && w > 19 && h > 19 )
+ {
+ int x2 = x + w - 1;
+ int y2 = y + h - 1;
+ TQPointArray a( TQCOORDARRLEN( top_left_fill ), top_left_fill );
+ a.translate( 1, 1 );
+ p->drawPoints( a );
+ a.setPoints( TQCOORDARRLEN( btm_left_fill ), btm_left_fill );
+ a.translate( 1, h - 6 );
+ p->drawPoints( a );
+ a.setPoints( TQCOORDARRLEN( top_right_fill ), top_right_fill );
+ a.translate( w - 6, 1 );
+ p->drawPoints( a );
+ a.setPoints( TQCOORDARRLEN( 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 );
+}
+
+int KThemeStyle::styleHint( StyleHint sh, const TQStyleControlElementData &ceData, ControlElementFlags elementFlags, const TQStyleOption &opt, TQStyleHintReturn *shr, const TQWidget *w ) const
+{
+ switch ( sh )
+ {
+ case SH_EtchDisabledText:
+ case SH_Slider_SnapToValue:
+ case SH_PrintDialog_RightAlignButtons:
+ case SH_FontDialog_SelectAssociatedText:
+ case SH_PopupMenu_AllowActiveAndDisabled:
+ case SH_MenuBar_AltKeyNavigation:
+ case SH_MenuBar_MouseTracking:
+ case SH_PopupMenu_MouseTracking:
+ case SH_ComboBox_ListMouseTracking:
+ return 1;
+
+ case SH_GUIStyle:
+ return WindowsStyle;
+
+ case SH_ScrollBar_BackgroundMode:
+ return NoBackground;
+
+ case SH_MenuIndicatorColumnWidth:
+ {
+ int checkcol = opt.maxIconWidth();
+ bool checkable = (elementFlags & CEF_IsCheckable);
+
+ if ( checkable )
+ checkcol = QMAX( checkcol, 20 );
+
+ return checkcol;
+ break;
+ }
+
+ default:
+ return KThemeBase::styleHint( sh, ceData, elementFlags, opt, shr, w );
+ };
+}
+
+
+
+/* This is where we draw the borders and highlights. The new round button
+ * code is a pain in the arse. We don't want to be calculating arcs so
+ * use a whole lotta QPointArray's ;-) The code is made a lot more complex
+ * because you can have variable width border and highlights...
+ * I may want to cache this if round buttons are used, but am concerned
+ * about excessive cache misses. This is a memory/speed tradeoff that I
+ * have to test.
+ */
+void KThemeStyle::drawShade( TQPainter *p, int x, int y, int w, int h,
+ const TQColorGroup &g, bool sunken, bool rounded,
+ int hWidth, int bWidth, ShadeStyle style ) const
+{
+ int i, sc, bc, x2, y2;
+ TQPen highPen, lowPen;
+
+ if ( style == Motif )
+ {
+ highPen.setColor( sunken ? g.dark() : g.light() );
+ lowPen.setColor( sunken ? g.light() : g.dark() );
+ }
+ else
+ {
+ highPen.setColor( sunken ? g.shadow() : g.light() );
+ lowPen.setColor( sunken ? g.light() : g.shadow() );
+ }
+
+ // Advanced round buttons
+ if ( rounded && w > 19 && h > 19 )
+ {
+ x2 = x + w - 1, y2 = y + h - 1;
+ TQPointArray bPntArray, hPntArray, lPntArray;
+ TQPointArray bLineArray, hLineArray, lLineArray;
+ // borders
+ for ( i = 0, bc = 0; i < bWidth; ++i )
+ {
+ bPntArray.putPoints( bc, 24, x + 4, y + 1, x + 5, y + 1, x + 3, y + 2, x + 2, y + 3,
+ x + 1, y + 4, x + 1, y + 5, x + 1, y2 - 5, x + 1, y2 - 4, x + 2, y2 - 3,
+ x2 - 5, y + 1, x2 - 4, y + 1, x2 - 3, y + 2, x2 - 5, y2 - 1,
+ x2 - 4, y2 - 1, x2 - 3, y2 - 2, x2 - 2, y2 - 3, x2 - 1, y2 - 5,
+ x2 - 1, y2 - 4, x + 3, y2 - 2, x + 4, y2 - 1, x + 5, y2 - 1,
+ x2 - 2, y + 3, x2 - 1, y + 4, x2 - 1, y + 5 );
+ bc += 24;
+ // ellispe edges don't match exactly, so fill in blanks
+ if ( i < bWidth - 1 || hWidth != 0 )
+ {
+ bPntArray.putPoints( bc, 20, x + 6, y + 1, x + 4, y + 2, x + 3, y + 3,
+ x + 2, y + 4, x + 1, y + 6, x2 - 6, y + 1, x2 - 4, y + 2,
+ x2 - 3, y + 3, x + 2, y2 - 4, x + 1, y2 - 6, x2 - 6, y2 - 1,
+ x2 - 4, y2 - 2, x2 - 3, y2 - 3, x2 - 2, y2 - 4, x2 - 1, y2 - 6,
+ x + 6, y2 - 1, x + 4, y2 - 2, x + 3, y2 - 3, x2 - 1, y + 6,
+ x2 - 2, y + 4 );
+ bc += 20;
+ }
+ bLineArray.putPoints( i * 8, 8, x + 6, y, x2 - 6, y, x, y + 6, x, y2 - 6,
+ x + 6, y2, x2 - 6, y2, x2, y + 6, x2, y2 - 6 );
+ ++x, ++y;
+ --x2, --y2;
+ }
+ // highlights
+ for ( i = 0, sc = 0; i < hWidth; ++i )
+ {
+ hPntArray.putPoints( sc, 12, x + 4, y + 1, x + 5, y + 1, // top left
+ x + 3, y + 2, x + 2, y + 3, x + 1, y + 4, x + 1, y + 5,
+ x + 1, y2 - 5, x + 1, y2 - 4, x + 2, y2 - 3, // half corners
+ x2 - 5, y + 1, x2 - 4, y + 1, x2 - 3, y + 2 );
+ lPntArray.putPoints( sc, 12, x2 - 5, y2 - 1, x2 - 4, y2 - 1, // btm right
+ x2 - 3, y2 - 2, x2 - 2, y2 - 3, x2 - 1, y2 - 5, x2 - 1, y2 - 4,
+ x + 3, y2 - 2, x + 4, y2 - 1, x + 5, y2 - 1, //half corners
+ x2 - 2, y + 3, x2 - 1, y + 4, x2 - 1, y + 5 );
+ sc += 12;
+ if ( i < hWidth - 1 )
+ {
+ hPntArray.putPoints( sc, 10, x + 6, y + 1, x + 4, y + 2, // top left
+ x + 3, y + 3, x + 2, y + 4, x + 1, y + 6,
+ x2 - 6, y + 1, x2 - 4, y + 2, // half corners
+ x2 - 3, y + 3, x + 2, y2 - 4, x + 1, y2 - 6 );
+ lPntArray.putPoints( sc, 10, x2 - 6, y2 - 1, x2 - 4, y2 - 2, // btm right
+ x2 - 3, y2 - 3, x2 - 2, y2 - 4, x2 - 1, y2 - 6,
+ x + 6, y2 - 1, x + 4, y2 - 2, // half corners
+ x + 3, y2 - 3, x2 - 1, y + 6, x2 - 2, y + 4 );
+ sc += 10;
+ }
+ hLineArray.putPoints( i * 4, 4, x + 6, y, x2 - 6, y, x, y + 6, x, y2 - 6 );
+ lLineArray.putPoints( i * 4, 4, x + 6, y2, x2 - 6, y2, x2, y + 6, x2, y2 - 6 );
+ ++x, ++y;
+ --x2, --y2;
+ }
+ p->setPen( Qt::black );
+ p->drawPoints( bPntArray );
+ p->drawLineSegments( bLineArray );
+ p->setPen( highPen );
+ p->drawPoints( hPntArray );
+ p->drawLineSegments( hLineArray );
+ p->setPen( lowPen );
+ p->drawPoints( lPntArray );
+ p->drawLineSegments( lLineArray );
+ }
+ // Rectangular buttons
+ else
+ {
+ TQPointArray highShade( hWidth * 4 );
+ TQPointArray lowShade( hWidth * 4 );
+
+ p->setPen( g.shadow() );
+ for ( i = 0; i < bWidth && w > 2 && h > 2; ++i, ++x, ++y, w -= 2, h -= 2 )
+ p->drawRect( x, y , w, h );
+
+ if ( !hWidth )
+ return ;
+
+ x2 = x + w - 1, y2 = y + h - 1;
+ for ( i = 0; i < hWidth; ++i, ++x, ++y, --x2, --y2 )
+ {
+ highShade.putPoints( i * 4, 4, x, y, x2, y, x, y, x, y2 );
+ lowShade.putPoints( i * 4, 4, x, y2, x2, y2, x2, y, x2, y2 );
+ }
+ if ( style == Windows && hWidth > 1 )
+ {
+ p->setPen( highPen );
+ p->drawLineSegments( highShade, 0, 2 );
+ p->setPen( lowPen );
+ p->drawLineSegments( lowShade, 0, 2 );
+
+ p->setPen( ( sunken ) ? g.dark() : g.mid() );
+ p->drawLineSegments( highShade, 4 );
+ p->setPen( ( sunken ) ? g.mid() : g.dark() );
+ p->drawLineSegments( lowShade, 4 );
+ }
+ else
+ {
+ p->setPen( ( sunken ) ? g.dark() : g.light() );
+ p->drawLineSegments( highShade );
+ p->setPen( ( sunken ) ? g.light() : g.dark() );
+ p->drawLineSegments( lowShade );
+ }
+ }
+}
+
+
+
+
+int KThemeStyle::popupMenuItemHeight( bool /*checkable*/, TQMenuItem *mi,
+ const TQFontMetrics &fm )
+{
+ int h2, h = 0;
+ int offset = QMAX( decoWidth( MenuItemDown ), decoWidth( MenuItem ) ) + 4;
+
+ if ( mi->isSeparator() )
+ return ( 2 );
+ if ( mi->isChecked() )
+ h = isPixmap( CheckMark ) ? uncached( CheckMark ) ->height() + offset :
+ offset + 16;
+ if ( mi->pixmap() )
+ {
+ h2 = mi->pixmap() ->height() + offset;
+ h = h2 > h ? h2 : h;
+ }
+ if ( mi->iconSet() )
+ {
+ h2 = mi->iconSet() ->
+ pixmap( TQIconSet::Small, TQIconSet::Normal ).height() + offset;
+ h = h2 > h ? h2 : h;
+ }
+ h2 = fm.height() + offset;
+ h = h2 > h ? h2 : h;
+ return ( h );
+}
+
+#include "kthemestyle.moc"
+// kate: indent-width 4; replace-tabs off; tab-width 4; space-indent on;
diff --git a/tdestyles/kthemestyle/kthemestyle.h b/tdestyles/kthemestyle/kthemestyle.h
new file mode 100644
index 000000000..ca112ed14
--- /dev/null
+++ b/tdestyles/kthemestyle/kthemestyle.h
@@ -0,0 +1,242 @@
+/*
+$Id$
+
+This file is part of the KDE libraries
+Copyright (C) 1999 Daniel M. Duley <mosfet@kde.org>
+
+KDE3 port (C) 2001-2002 Maksim Orlovich <mo002j@mail.rochester.edu>
+Port version 0.9.7
+
+Includes code portions from the dotNET style, and the KDE HighColor style.
+
+dotNET Style
+ Copyright (C) 2001, Chris Lee <lee@azsites.com>
+ Carsten Pfeiffer <pfeiffer@kde.org>
+
+KDE3 HighColor Style
+Copyright (C) 2001 Karol Szwed <gallium@kde.org>
+ (C) 2001 Fredrik H�glund <fredrik@kde.org>
+
+Drawing routines adapted from the KDE2 HCStyle,
+Copyright (C) 2000 Daniel M. Duley <mosfet@kde.org>
+ (C) 2000 Dirk Mueller <mueller@kde.org>
+ (C) 2001 Martijn Klingens <klingens@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., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+#ifndef KTHEMESTYLE_H
+#define KTHEMESTYLE_H
+
+#include <tqglobal.h>
+
+#include "kthemebase.h"
+#include <tqwindowdefs.h>
+#include <tqobject.h>
+#include <tqbutton.h>
+#include <tqpushbutton.h>
+#include <tqscrollbar.h>
+#include <tqtabbar.h>
+#include <tqstring.h>
+#include <tqintdict.h>
+#include <tqmap.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 KThemeStyle: public KThemeBase
+{
+ Q_OBJECT
+public:
+ /**
+ * Constructs a new KThemeStyle object.
+ *
+ * @param configDir The directory which has the TDEConfig file.
+ * @param configFile A TDEConfig file to use as the theme configuration.
+ * Defaults to ~/.tderc.
+ */
+ KThemeStyle( const TQString& configDir, const TQString &configFile = TQString::null );
+ ~KThemeStyle();
+
+ virtual int pixelMetric ( PixelMetric metric, const TQStyleControlElementData &ceData, ControlElementFlags elementFlags, const TQWidget * widget = 0 ) const;
+
+ virtual void drawPrimitive ( PrimitiveElement pe, TQPainter * p, const TQStyleControlElementData &ceData, ControlElementFlags elementFlags, const TQRect & r, const TQColorGroup & cg,
+ SFlags flags = Style_Default,
+ const TQStyleOption& = TQStyleOption::Default ) const;
+
+ virtual void drawControl( ControlElement element,
+ TQPainter *p,
+ const TQStyleControlElementData &ceData,
+ ControlElementFlags elementFlags,
+ const TQRect &r,
+ const TQColorGroup &cg,
+ SFlags how = Style_Default,
+ const TQStyleOption& = TQStyleOption::Default,
+ const TQWidget *widget = 0 ) const;
+
+ virtual void drawControlMask( ControlElement element,
+ TQPainter *p,
+ const TQStyleControlElementData &ceData,
+ ControlElementFlags elementFlags,
+ const TQRect &r,
+ const TQStyleOption& = TQStyleOption::Default,
+ const TQWidget *widget = 0 ) const;
+
+
+ virtual void drawComplexControl( TQ_ComplexControl control,
+ TQPainter *p,
+ const TQStyleControlElementData &ceData,
+ ControlElementFlags elementFlags,
+ const TQRect &r,
+ const TQColorGroup &cg,
+ SFlags flags = Style_Default,
+ SCFlags controls = SC_All,
+ SCFlags active = SC_None,
+ const TQStyleOption& = TQStyleOption::Default,
+ const TQWidget* widget = 0 ) const;
+
+ virtual void drawTDEStylePrimitive( TDEStylePrimitive kpe,
+ TQPainter* p,
+ const TQStyleControlElementData &ceData,
+ ControlElementFlags elementFlags,
+ const TQRect &r,
+ const TQColorGroup &cg,
+ SFlags flags = Style_Default,
+ const TQStyleOption& = TQStyleOption::Default,
+ const TQWidget* widget = 0 ) const;
+
+
+ virtual int styleHint( StyleHint sh,
+ const TQStyleControlElementData &ceData,
+ ControlElementFlags elementFlags,
+ const TQStyleOption& = TQStyleOption::Default,
+ TQStyleHintReturn* returnData = 0,
+ const TQWidget *widget = 0 ) const;
+
+ virtual TQSize sizeFromContents( ContentsType contents,
+ const TQStyleControlElementData &ceData,
+ ControlElementFlags elementFlags,
+ const TQSize &contentsSize,
+ const TQStyleOption& = TQStyleOption::Default,
+ const TQWidget *widget = 0 ) const;
+
+ virtual TQRect subRect(SubRect, const TQStyleControlElementData &ceData, const ControlElementFlags elementFlags, const TQWidget *) const;
+
+ virtual void polish( const TQStyleControlElementData &ceData, ControlElementFlags elementFlags, void * );
+ virtual void unPolish( const TQStyleControlElementData &ceData, ControlElementFlags elementFlags, void * );
+ virtual bool objectEventHandler( const TQStyleControlElementData &ceData, ControlElementFlags elementFlags, void* source, TQEvent *e );
+ /**
+ * By default this just sets the background brushes to the pixmapped
+ * background.
+ */
+ virtual void applicationPolish( const TQStyleControlElementData &ceData, ControlElementFlags elementFlags, void * );
+ virtual void applicationUnPolish( const TQStyleControlElementData &ceData, ControlElementFlags elementFlags, void * );
+
+ /** \internal */
+ // to make it possible for derived classes to overload this function
+ virtual void polish( TQPalette& 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 x The x coordinate of the button's upper left hand corner.
+ * @param y The y coordinate of the buttons' upper left hand corner.
+ * @param w The button width.
+ * @param h The button height.
+ * @param p The TQPainter to draw on.
+ * @param g The color group to use.
+ * @param sunken The button is drawn with a sunken style if @p true
+ * @param rounded @p true if the widget is rounded, @p false if rectangular.
+ * @param type The widget type to paint.
+ */
+ virtual void drawBaseButton( TQPainter *p, int x, int y, int w, int h,
+ const TQColorGroup &g, bool sunken = false,
+ bool rounded = false, WidgetType type = Bevel ) const;
+ /**
+ * Draw a mask with for widgets that may be rounded.
+ *
+ *Currently used
+ * by pushbuttons and comboboxes.
+ *
+ * @param p The TQPainter to draw on.
+ * @param x The x coordinate of the widget's upper left hand corner.
+ * @param y The y coordinate of the widget's upper left hand corner.
+ * @param w The widget width.
+ * @param h The widget height.
+ * @param rounded @p true if the widget is rounded, @p false if rectangular.
+ */
+ virtual void drawBaseMask( TQPainter *p, int x, int y, int w, int h,
+ bool rounded ) const;
+
+
+
+ /**
+ * Draw a shaded rectangle using the given style.
+ *
+ * @param p The painter to draw on.
+ * @param g The color group to use.
+ * @param x The x coordinate of the rectangle's upper left hand corner.
+ * @param y The y coordinate of the rectangle's upper left hand corner.
+ * @param w The rectangle width.
+ * @param h The rectangle height.
+ * @param sunken Draws a sunken style if @p true.
+ * @param rounded Draws a rounded shape if @p 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( TQPainter *p, int x, int y, int w, int h,
+ const TQColorGroup &g, bool sunken, bool rounded,
+ int hWidth, int bWidth, ShadeStyle style ) const;
+ int popupMenuItemHeight( bool checkable, TQMenuItem *mi,
+ const TQFontMetrics &fm );
+
+protected:
+ TQPalette oldPalette, popupPalette, indiPalette, exIndiPalette;
+ bool paletteSaved;
+ bool polishLock;
+ TQStyle *mtfstyle;
+
+ TQPixmap* makeMenuBarCache(int w, int h) const;
+
+ mutable TQPixmap* menuCache;
+ mutable TQPixmap* vsliderCache;
+
+ Qt::HANDLE brushHandle;
+ bool brushHandleSet;
+ bool kickerMode;
+
+protected slots:
+ void paletteChanged();
+
+
+
+};
+
+
+#endif
diff --git a/tdestyles/kthemestyle/tdestyledirs.cpp b/tdestyles/kthemestyle/tdestyledirs.cpp
new file mode 100644
index 000000000..9f795e1e2
--- /dev/null
+++ b/tdestyles/kthemestyle/tdestyledirs.cpp
@@ -0,0 +1,48 @@
+/*
+ $Id$
+
+ Simple helper routines for style's use of TDEStandardDirs with TQSettings, etc.
+
+ 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., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+
+
+ This file is part of the KDE libraries
+*/
+
+#include <tqfile.h>
+#include <kstandarddirs.h>
+#include "tdestyledirs.h"
+
+TDEStyleDirs* TDEStyleDirs::instance = 0;
+
+TDEStyleDirs::TDEStyleDirs()
+{
+ addResourceType( "themepixmap", TDEStandardDirs::kde_default( "data" ) + "tdestyle/pixmaps/" );
+ addResourceType( "themerc", TDEStandardDirs::kde_default( "data" ) + "tdestyle/themes/" );
+}
+
+TDEStyleDirs::~TDEStyleDirs()
+{
+}
+
+void TDEStyleDirs::addToSearch( const char* type, TQSettings& s ) const
+{
+ const TQStringList & dirs = resourceDirs(type);
+ for ( int c = dirs.size()-1; c >= 0 ; c-- )
+ {
+ s.insertSearchPath( TQSettings::Unix, dirs[ c ]);
+ }
+}
+
diff --git a/tdestyles/kthemestyle/tdestyledirs.h b/tdestyles/kthemestyle/tdestyledirs.h
new file mode 100644
index 000000000..2a42fd2ba
--- /dev/null
+++ b/tdestyles/kthemestyle/tdestyledirs.h
@@ -0,0 +1,82 @@
+/*
+ $Id$
+
+ This file is part of the KDE libraries
+ (c) 2002 Maksim Orlovich <mo002j@mail.rochester.edu>,
+
+ 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., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef TDESTYLE_DIRS_H
+#define TDESTYLE_DIRS_H
+
+
+#include <tqsettings.h>
+#include <tqstringlist.h>
+#include <kstandarddirs.h>
+
+/**
+* @short Access to the standard KDE directories for the pixmap style
+* @author Maksim Orlovich<mo002j@mail.rochester.edu> is responsible for this file,
+ but all the interesting work is done by TDEStandardDirs
+* @version $Id$
+*
+* This class provides a this wrapper for styles around TDEStandardDirs,
+* permitting integration with TQSettings and easy loading of pixmaps
+*
+* It add share/apps/tdestyle/themes as "themerc",
+* share/apps/tdestyle/pixmaps "themepixmap"
+*/
+class TDEStyleDirs: public TDEStandardDirs
+{
+public:
+ static TDEStyleDirs* dirs()
+ {
+ if ( !instance)
+ instance = new TDEStyleDirs;
+ return instance;
+ }
+
+ static void release()
+ {
+ delete instance;
+ instance = 0;
+ }
+
+ /**
+ Adds all of KDE directories of type type to the seach path of q.
+
+ For example, when one does the following:
+ TQSettings settings;
+ TDEStyleDirs dirs;
+ dirs.addToSearch("config",settings);
+
+ The one can do settings.readEntry("tdestyle/TDE/WidgetStyle") to access a settings in tdestylerc.
+ */
+ void addToSearch( const char* type, TQSettings& q) const; //Better name?
+
+protected:
+ static TDEStyleDirs* instance;
+ /**
+ Creates an instance of the class, and calculates the path information.
+ */
+ TDEStyleDirs();
+ TDEStyleDirs(const TDEStyleDirs&);
+ TDEStyleDirs& operator= (const TDEStyleDirs&);
+
+ virtual ~TDEStyleDirs();
+};
+
+#endif