00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef __OTHEMEBASE_H
00019 #define __OTHEMEBASE_H
00020
00021
00022 #include <opie2/odebug.h>
00023 using namespace Opie::Core;
00024
00025
00026 #include <qdatetime.h>
00027 #include <qtimer.h>
00028 #include <qwindowsstyle.h>
00029 #include <qpixmap.h>
00030 #include <qpe/config.h>
00031 #include <qimage.h>
00032 #include <qintcache.h>
00033 #include <qstring.h>
00034 #include <qpalette.h>
00035
00036 #define WIDGETS 54
00037
00044 class OThemePixmap : public QPixmap
00045 {
00046 public:
00047 enum BorderType{Top = 0, Bottom, Left, Right, TopLeft, TopRight, BottomLeft,
00048 BottomRight};
00049
00050 OThemePixmap( bool timer = true );
00051 OThemePixmap( const OThemePixmap &p );
00052 ~OThemePixmap();
00053 QPixmap* border( BorderType type );
00054 void setBorder( BorderType type, const QPixmap &p );
00055 void updateAccessed();
00056 bool isOld();
00057 protected:
00058 QTime *t;
00059 QPixmap *b[ 8 ];
00060
00061 private:
00062 class OThemePixmapPrivate;
00063 OThemePixmapPrivate *d;
00064 };
00065
00066 inline QPixmap* OThemePixmap::border( BorderType type )
00067 {
00068 return ( b[ type ] );
00069 }
00070
00071 inline void OThemePixmap::setBorder( BorderType type, const QPixmap &p )
00072 {
00073 if ( b[ type ] ) {
00074 owarn << "OThemePixmap: Overwriting existing border!" << oendl;
00075 delete( b[ type ] );
00076 }
00077 b[ type ] = new QPixmap( p );
00078 }
00079
00080 inline void OThemePixmap::updateAccessed()
00081 {
00082 if (t)
00083 t->start();
00084 }
00085
00086 inline bool OThemePixmap::isOld()
00087 {
00088 return ( t ? t->elapsed() >= 300000 : false );
00089 }
00090
00112 class OThemeCache : public QObject
00113 {
00114 Q_OBJECT
00115 public:
00120 enum ScaleHint{FullScale, HorizontalScale, VerticalScale};
00126 OThemeCache( int maxSize, QObject *parent = 0, const char *name = 0 );
00137 bool insert( OThemePixmap *pixmap, ScaleHint scale, int widgetID,
00138 bool border = false, bool mask = false );
00149 OThemePixmap* pixmap( int w, int h, int widgetID, bool border = false,
00150 bool mask = false );
00160 OThemePixmap* horizontalPixmap( int w, int widgetID );
00170 OThemePixmap* verticalPixmap( int h, int widgetID );
00171 protected slots:
00172 void flushTimeout();
00173 protected:
00174 QIntCache<OThemePixmap> cache;
00175 QTimer flushTimer;
00176
00177 private:
00178 class OThemeCachePrivate;
00179 OThemeCachePrivate *d;
00180 };
00181
00182
00195 class OThemeBase: public QWindowsStyle
00196 {
00197 Q_OBJECT
00198 public:
00202 OThemeBase( const QString &configFile );
00203 ~OThemeBase();
00208 enum ScaleHint{FullScale, HorizontalScale, VerticalScale, TileScale};
00212 enum ArrowStyle{MotifArrow, LargeArrow, SmallArrow};
00216 enum ShadeStyle{Motif, Windows, Next, KDE};
00222 enum SButton{SBBottomLeft, SBBottomRight, SBOpposite};
00227 enum Gradient{GrNone, GrHorizontal, GrVertical, GrDiagonal, GrPyramid,
00228 GrRectangle, GrElliptic, GrReverseBevel};
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244 enum WidgetType{
00245
00246 PushButton = 0, ComboBox, HScrollBarSlider, VScrollBarSlider, Bevel,
00247 ToolButton, ScrollButton, HScrollDeco, VScrollDeco,
00248 ComboDeco, MenuItem, InactiveTab, ArrowUp, ArrowDown, ArrowLeft,
00249 ArrowRight,
00250
00251 PushButtonDown, ComboBoxDown, HScrollBarSliderDown,
00252 VScrollBarSliderDown, BevelDown, ToolButtonDown, ScrollButtonDown,
00253 HScrollDecoDown, VScrollDecoDown, ComboDecoDown, MenuItemDown,
00254 ActiveTab, SunkenArrowUp, SunkenArrowDown, SunkenArrowLeft,
00255 SunkenArrowRight,
00256
00257 HScrollGroove, VScrollGroove, Slider, SliderGroove, IndicatorOn,
00258 IndicatorOff, ExIndicatorOn, ExIndicatorOff, HBarHandle, VBarHandle,
00259 ToolBar, Splitter, CheckMark, MenuBar, DisArrowUp, DisArrowDown,
00260 DisArrowLeft, DisArrowRight, ProgressBar, ProgressBg, MenuBarItem,
00261 Background};
00262
00270 ScaleHint scaleHint( WidgetType widget ) const;
00278 Gradient gradientHint( WidgetType widget ) const;
00289 const QColorGroup* colorGroup( const QColorGroup &defaultGroup,
00290 WidgetType widget ) const;
00291
00292 QBrush pixmapBrush( const QColorGroup &group, QColorGroup::ColorRole role,
00293 int w, int h, WidgetType widget );
00297 bool isPixmap( WidgetType widget ) const;
00301 bool isColor( WidgetType widget ) const;
00305 bool is3DFocus() const;
00311 int focusOffset() const;
00315 int borderWidth( WidgetType widget ) const;
00319 int pixBorderWidth( WidgetType widget ) const;
00325 OThemePixmap* borderPixmap( WidgetType widget );
00329 int highlightWidth( WidgetType widget ) const;
00333 int decoWidth( WidgetType widget ) const;
00338 int getSBExtent() const;
00342 SButton scrollBarLayout() const;
00346 ArrowStyle arrowType() const;
00350 ShadeStyle shade() const;
00354 int frameWidth() const;
00358 int splitWidth() const;
00362 int bevelContrast( WidgetType widget ) const;
00366 int buttonXShift() const;
00370 int buttonYShift() const;
00375 int sliderButtonLength() const;
00379 bool roundButton() const;
00383 bool roundComboBox() const;
00387 bool roundSlider() const;
00391 bool activeTabLine() const;
00395 bool inactiveTabLine() const;
00402 OThemePixmap* uncached( WidgetType widget ) const;
00417 virtual OThemePixmap *scalePixmap( int w, int h, WidgetType widget );
00426 static void applyConfigFile( const QString &file );
00427 protected:
00434 QImage* image( WidgetType widget ) const;
00438 QColor* gradientHigh( WidgetType widget ) const;
00442 QColor* gradientLow( WidgetType widget ) const;
00450 void readConfig( Qt::GUIStyle colorStyle = Qt::WindowsStyle );
00451 void readWidgetConfig( int i, Config *config, QString *pixnames,
00452 QString *brdnames, bool *loadArray );
00453 void copyWidgetConfig( int sourceID, int destID, QString *pixnames,
00454 QString *brdnames );
00460 QColorGroup* makeColorGroup( QColor &fg, QColor &bg,
00461 Qt::GUIStyle style = Qt::WindowsStyle );
00462 OThemePixmap* scale( int w, int h, WidgetType widget );
00463 OThemePixmap* scaleBorder( int w, int h, WidgetType type );
00464 OThemePixmap* gradient( int w, int h, WidgetType widget );
00465 OThemePixmap* blend( WidgetType widget );
00466 void generateBorderPix( int i );
00467 void applyResourceGroup( Config *config, int i, QString *copyfrom, QString *pixnames, QString *brdnames );
00468 void applyMiscResourceGroup( Config *config );
00469 void readResourceGroup( int i, QString *copyfrom, QString *pixnames, QString *brdnames,
00470 bool *loadArray );
00471 void readMiscResourceGroup();
00475 OThemePixmap* loadPixmap( QString &name );
00479 QImage* loadImage( QString &name );
00480 private:
00481 SButton sbPlacement;
00482 ArrowStyle arrowStyle;
00483 ShadeStyle shading;
00484 int defaultFrame;
00485 int btnXShift, btnYShift;
00486 int sliderLen;
00487 int splitterWidth;
00488 int focus3DOffset;
00489 int sbExtent;
00490 bool smallGroove;
00491 bool roundedButton, roundedCombo, roundedSlider;
00492 bool aTabLine, iTabLine;
00493 bool focus3D;
00494 OThemeCache *cache;
00495 int cacheSize;
00496 QString configFileName;
00497 QString configFilePath;
00498
00499 protected:
00500 QColor fgcolor, bgcolor, selfgcolor, selbgcolor, winfgcolor, winbgcolor;
00501
00502 private:
00510 OThemePixmap *pixmaps[ WIDGETS ];
00515 QImage *images[ WIDGETS ];
00519 unsigned char borders[ WIDGETS ];
00523 unsigned char highlights[ WIDGETS ];
00527 ScaleHint scaleHints[ WIDGETS ];
00531 QColorGroup *colors[ WIDGETS ];
00535 QColor *grLowColors[ WIDGETS ];
00539 QColor *grHighColors[ WIDGETS ];
00543 Gradient gradients[ WIDGETS ];
00547 float blends[ WIDGETS ];
00551 unsigned char bContrasts[ WIDGETS ];
00555 bool duplicate[ WIDGETS ];
00559 int pbWidth[ WIDGETS ];
00563 OThemePixmap *pbPixmaps[ WIDGETS ];
00567 bool pbDuplicate[ WIDGETS ];
00568
00569 private:
00570 class OThemeBasePrivate;
00571 OThemeBasePrivate *d;
00572
00573 };
00574
00575 inline bool OThemeBase::isPixmap( WidgetType widget ) const
00576 {
00577 return ( pixmaps[ widget ] != NULL || gradients[ widget ] != GrNone );
00578 }
00579
00580 inline bool OThemeBase::isColor( WidgetType widget ) const
00581 {
00582 return ( colors[ widget ] != NULL );
00583 }
00584
00585 inline bool OThemeBase::is3DFocus() const
00586 {
00587 return ( focus3D );
00588 }
00589
00590 inline int OThemeBase::focusOffset() const
00591 {
00592 return ( focus3DOffset );
00593 }
00594
00595 inline int OThemeBase::bevelContrast( WidgetType widget ) const
00596 {
00597 return ( bContrasts[ widget ] );
00598 }
00599
00600 inline OThemeBase::ScaleHint OThemeBase::scaleHint( WidgetType widget ) const
00601 {
00602 return ( ( widget < WIDGETS ) ? scaleHints[ widget ] : TileScale );
00603 }
00604
00605 inline OThemeBase::Gradient OThemeBase::gradientHint( WidgetType widget ) const
00606 {
00607 return ( ( widget < WIDGETS ) ? gradients[ widget ] : GrNone );
00608 }
00609
00610 inline OThemePixmap* OThemeBase::uncached( WidgetType widget ) const
00611 {
00612 return ( pixmaps[ widget ] );
00613 }
00614
00615 inline QBrush OThemeBase::pixmapBrush( const QColorGroup &group,
00616 QColorGroup::ColorRole role,
00617 int w, int h, WidgetType widget )
00618 {
00619 if ( pixmaps[ widget ] || images[ widget ] )
00620 return ( QBrush( group.color( role ), *scalePixmap( w, h, widget ) ) );
00621 else
00622 return ( group.color( role ) );
00623 }
00624
00625 inline const QColorGroup* OThemeBase::colorGroup( const QColorGroup &defaultGroup,
00626 WidgetType widget ) const
00627 {
00628 return ( ( colors[ widget ] ) ? colors[ widget ] : &defaultGroup );
00629 }
00630
00631 inline int OThemeBase::borderWidth( WidgetType widget ) const
00632 {
00633 return ( pbWidth[ widget ] ? pbWidth[ widget ] : borders[ widget ] );
00634 }
00635
00636 inline int OThemeBase::pixBorderWidth( WidgetType widget ) const
00637 {
00638 return ( pbWidth[ widget ] );
00639 }
00640
00641 inline int OThemeBase::highlightWidth( WidgetType widget ) const
00642 {
00643 return ( pbWidth[ widget ] ? 0 : highlights[ widget ] );
00644 }
00645
00646 inline int OThemeBase::decoWidth( WidgetType widget ) const
00647 {
00648 return ( pbWidth[ widget ] ? pbWidth[ widget ] : borders[ widget ] + highlights[ widget ] );
00649 }
00650
00651 inline QColor* OThemeBase::gradientHigh( WidgetType widget ) const
00652 {
00653 return ( grHighColors[ widget ] );
00654 }
00655
00656 inline QColor* OThemeBase::gradientLow( WidgetType widget ) const
00657 {
00658 return ( grLowColors[ widget ] );
00659 }
00660
00661 inline QImage* OThemeBase::image( WidgetType widget ) const
00662 {
00663 return ( images[ widget ] );
00664 }
00665
00666 inline OThemeBase::SButton OThemeBase::scrollBarLayout() const
00667 {
00668 return ( sbPlacement );
00669 }
00670
00671 inline OThemeBase::ArrowStyle OThemeBase::arrowType() const
00672 {
00673 return ( arrowStyle );
00674 }
00675
00676 inline OThemeBase::ShadeStyle OThemeBase::shade() const
00677 {
00678 return ( shading );
00679 }
00680
00681 inline int OThemeBase::frameWidth() const
00682 {
00683 return ( defaultFrame );
00684 }
00685
00686 inline int OThemeBase::buttonXShift() const
00687 {
00688 return ( btnXShift );
00689 }
00690
00691 inline int OThemeBase::splitWidth() const
00692 {
00693 return ( splitterWidth );
00694 }
00695
00696 inline int OThemeBase::buttonYShift() const
00697 {
00698 return ( btnYShift );
00699 }
00700
00701 inline int OThemeBase::sliderButtonLength() const
00702 {
00703 if ( isPixmap( Slider ) )
00704 return ( uncached( Slider ) ->width() );
00705 else
00706 return ( sliderLen );
00707 }
00708
00709 inline bool OThemeBase::roundButton() const
00710 {
00711 return ( roundedButton );
00712 }
00713
00714 inline bool OThemeBase::roundComboBox() const
00715 {
00716 return ( roundedCombo );
00717 }
00718
00719 inline bool OThemeBase::roundSlider() const
00720 {
00721 return ( roundedSlider );
00722 }
00723
00724 inline bool OThemeBase::activeTabLine() const
00725 {
00726 return ( aTabLine );
00727 }
00728
00729 inline bool OThemeBase::inactiveTabLine() const
00730 {
00731 return ( iTabLine );
00732 }
00733
00734 inline int OThemeBase::getSBExtent() const
00735 {
00736 return ( sbExtent );
00737 }
00738
00739 inline OThemePixmap* OThemeBase::borderPixmap( WidgetType widget )
00740 {
00741 return ( pbPixmaps[ widget ] );
00742 }
00743
00744 #endif