• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KDEUI

kstyle.h

Go to the documentation of this file.
00001 
00035 #ifndef KDE_KSTYLE_H
00036 #define KDE_KSTYLE_H
00037 
00038 #include <kdeui_export.h>
00039 
00040 #include <QtGui/QCommonStyle>
00041 #include <QtGui/QPalette>
00042 #include <QtGui/QStylePlugin>
00043 
00044 class QStyleOptionProgressBar;
00045 class QStyleOptionTab;
00046 
00047 class KStylePrivate;
00073 // TODO: From 'Qt4 Themes' discussion on kde-devel
00074 // - Remi Villatel: extend QStyle enums for KColorButton, KColorCombo, KKeyButton, split PE_HeaderSection into KPopupTitle, PopupMenuTitle, TaskContainer)
00075 // - RV: KLineEdit "plays with its colors" - related to KStyle?
00076 // - RV: KMulitTabBarTab ... does it need support from KStyle (instead of manual button rotation etc.)? Or is it dumped already?
00077 // - RV: KTabCtl draws itself mimicking QDrawShadeThingies
00078 // - RV: fixed colors (e.g. Konqueror, KToolbarButton label text ->KPE_ToolbarButton?): To prevent hacks like "preventing any PaletteChange()"... mor related to KDE4 color schemes... I guess
00079 // - LM: User interface guidelines... related to KStyle?
00080 // - e.g. drawFancyPE() in kdeui for KDE widgets: check "qobject_cast<KStyle*>(style())", or fallback drawing...
00081 // TODO: implement standardIcon().. and what about standardPalette()?
00082 // TODO: maybe the arrow in CE_PushButtonLabel should be painted in CE_PushButtonBevel like QCommonStyle
00083 
00084 class KDEUI_EXPORT KStyle: public QCommonStyle
00085 {
00086     Q_OBJECT
00087 
00088 public:
00089     KStyle();
00090     ~KStyle();
00091 
00095     static QString defaultStyle();
00096 
00097 protected:
00105     void drawInsideRect(QPainter* p, const QRect& r) const;
00106     
00110     QRect centerRect(const QRect &in, int w, int h) const;
00111 
00115     QRect centerRect(const QRect &in, const QSize &size) const;
00117 
00128     class KDEUI_EXPORT ColorMode //krazy:exclude=dpointer (lightweight helper)
00129     {
00130     public:
00138         enum Mode
00139         {
00140             PaletteEntryMode,
00141             BWAutoContrastMode = 0x8000000
00142         };
00143     private:
00144         Mode                mode;
00145         QPalette::ColorRole role;
00146     public:
00147 
00150         ColorMode(QPalette::ColorRole _role);
00151 
00153         ColorMode(Mode _mode, QPalette::ColorRole _role);
00154 
00156         operator int() const;
00157 
00159         ColorMode(int encoded);
00160 
00163         QColor color(const QPalette& palette);
00164     };
00165 
00166     
00176     struct KDEUI_EXPORT Option
00177     {
00178         virtual ~Option() {} //So dynamic_cast works, and g++ shuts up
00179     };
00180 
00190     template<typename EventualSubtype, typename BaseType>
00191     struct KDEUI_EXPORT OptionBase: public BaseType
00192     {
00196         static EventualSubtype* defaultOption()
00197         {
00198             static EventualSubtype* theDefault = 0; //### function static, not very nice,
00199             //but avoids need for explicit instantiation.
00200 
00201             if (!theDefault)
00202                 theDefault = new EventualSubtype;
00203                 
00204             return theDefault;
00205         }
00206     };
00207     
00214     template<typename T>
00215     static T extractOption(Option* option);
00216 
00221     struct KDEUI_EXPORT ColorOption: public OptionBase<ColorOption, Option>
00222     {
00224         ColorMode color;
00225 
00226         ColorOption(): color(QPalette::ButtonText)
00227         {}
00228     };
00229 
00234     struct KDEUI_EXPORT IconOption: public OptionBase<IconOption, Option>
00235     {
00236         bool  active; 
00237         QIcon icon;   
00238         QSize size;
00239 
00240         IconOption(): active(false)
00241         {}
00242     };
00243 
00249     struct KDEUI_EXPORT DoubleButtonOption: public OptionBase<DoubleButtonOption, Option>
00250     {
00254         enum ActiveButton
00255         {
00256             None,   
00257             Top,    
00258             Left,   
00259             Right,  
00260             Bottom  
00261         };
00262 
00267         ActiveButton activeButton; 
00268 
00269         DoubleButtonOption(): activeButton(None)
00270         {}
00271 
00277         DoubleButtonOption(ActiveButton ab): activeButton(ab)
00278         {}
00279     };
00280 
00286     struct KDEUI_EXPORT TitleButtonOption: public OptionBase<TitleButtonOption, Option>
00287     {
00288         bool active;  
00289         QIcon icon;   
00290 //         /// whether the button is hovered, this doesn't work at the moment (not even in any Qt style)...
00291 //         bool hover;
00292 
00293         TitleButtonOption(): active(false)/*, hover(false)*/
00294         {}
00295 
00301         TitleButtonOption(bool act): active(act)
00302         {}
00303     };
00304     
00306     struct KDEUI_EXPORT TextOption: public OptionBase<TextOption, ColorOption>
00307     {
00308         Qt::Alignment        hAlign; 
00309         QString              text;   
00310         
00311         TextOption();
00312 
00318         TextOption(const QString& _text);
00319 
00323         void init();
00324     };
00326 
00338     enum WidgetType
00339     {
00340         WT_Generic,         
00341         WT_PushButton,      
00342         WT_Splitter,        
00343         WT_CheckBox,        
00344         WT_RadioButton,     
00345         WT_DockWidget,      
00346         WT_ProgressBar,     
00347         WT_MenuBar,         
00348         WT_MenuBarItem,     
00349         WT_Menu,            
00350         WT_MenuItem,        
00351         WT_ScrollBar,       
00352         WT_TabBar,          
00353         WT_TabWidget,       
00354         WT_Slider,          
00355         WT_Tree,            
00356         WT_SpinBox,         
00357         WT_ComboBox,        
00358         WT_Header,          
00359         WT_LineEdit,        
00360         WT_GroupBox,        
00361         WT_StatusBar,       
00362         WT_ToolBar,         
00363         WT_ToolButton,      
00364         WT_ToolBoxTab,      
00365         WT_Window,          
00366         WT_Limit = 0xFFFF 
00367     };
00368 
00369                 
00377     enum MarginOffsets
00378     {
00379         MainMargin, 
00382         Top,        
00383         Bot,        
00384         Left,       
00385         Right,      
00386         MarginInc   
00388     };
00389 
00390 
00395     struct Generic
00396     {
00402         enum LayoutProp
00403         {
00404             DefaultFrameWidth   
00405         };
00406 
00412         enum Primitive
00413         {
00414             Text = 0xFFFF,  
00415             Icon,           
00416             FocusIndicator, 
00417             Frame,          
00420             ArrowUp,        
00421             ArrowDown,      
00422             ArrowRight,     
00423             ArrowLeft       
00424         };
00425     };
00426 
00432     struct PushButton
00433     {
00446         enum LayoutProp
00447         {
00448             ContentsMargin, 
00449             FocusMargin            = ContentsMargin + MarginInc, 
00450             DefaultIndicatorMargin = FocusMargin    + MarginInc, 
00451             PressedShiftHorizontal = DefaultIndicatorMargin + MarginInc, 
00452             PressedShiftVertical, 
00453             MenuIndicatorSize, 
00454             TextToIconSpace 
00455         };
00456 
00467         enum Primitive
00468         {
00469             Panel,              
00471             DefaultButtonFrame  
00474         };
00475     };
00476 
00482     struct Splitter
00483     {
00487         enum LayoutProp
00488         {
00489             Width 
00490         };
00491 
00497         enum Primitive
00498         {
00499             HandleHor,      
00500             HandleVert      
00501         };
00502     };
00503 
00509     struct CheckBox
00510     {
00514         enum LayoutProp
00515         {
00516             Size,               
00517             BoxTextSpace,       
00518             NoLabelFocusMargin, 
00521             FocusMargin = NoLabelFocusMargin + MarginInc 
00522         };
00523 
00536         enum Primitive
00537         {
00538             CheckOn,        
00539             CheckOff,       
00540             CheckTriState   
00541         };
00542     };
00543 
00547     struct RadioButton
00548     {
00552         enum LayoutProp
00553         {
00554             Size, 
00557             BoxTextSpace, 
00558             FocusMargin   
00559         };
00560 
00572         enum Primitive
00573         {
00574             RadioOn,        
00575             RadioOff        
00576         };
00577     };
00578     
00579 
00585     struct DockWidget
00586     {
00590         enum LayoutProp
00591         {
00592             TitleTextColor, 
00593             TitleMargin, 
00594             FrameWidth = TitleMargin + MarginInc,  
00595             SeparatorExtent 
00596         };
00597 
00607         enum Primitive
00608         {
00609             TitlePanel, 
00610             SeparatorHandle 
00611         };
00612     };
00613 
00621     struct ProgressBar
00622     {
00626         enum LayoutProp
00627         {
00628             GrooveMargin,        
00629             SideText = GrooveMargin + MarginInc, 
00630             SideTextSpace,       
00631             Precision,           
00632             BusyIndicatorSize,   
00633             MaxBusyIndicatorSize 
00634         };
00635 
00642         enum Primitive
00643         {
00644             Groove,         
00646             Indicator,      
00647             BusyIndicator   
00650         };
00651     };
00652 
00653 
00659     struct MenuBar
00660     {
00664         enum LayoutProp
00665         {
00666             Margin,           
00668             ItemSpacing = Margin + MarginInc 
00669         };
00670 
00674         enum Property
00675         {
00676             EmptyArea 
00679         };
00680     };
00681 
00682 
00689     struct MenuBarItem
00690     {
00694         enum LayoutProp
00695         {
00696             Margin,                    
00699             Dummy = Margin + MarginInc //Paranoia about underlying type
00700         };
00701 
00705         enum Primitive
00706         {
00707             Panel       
00708         };
00709     };
00710 
00716     struct Menu
00717     {
00721         enum LayoutProp
00722         {
00723             FrameWidth, 
00724             Margin,     
00725             ScrollerHeight = Margin + MarginInc, 
00726             TearOffHeight 
00727         };
00728 
00735         enum Primitive
00736         {
00737             Background, 
00738             TearOff,    
00740             Scroller    
00742         };
00743     };
00744 
00763     struct MenuItem
00764     {
00768         enum LayoutProp
00769         {
00770             Margin,         
00771             CheckAlongsideIcon = Margin + MarginInc,
00774             CheckWidth,     
00776             CheckSpace,     
00778             IconWidth,      
00779             IconSpace,      
00780             AccelSpace,     
00781             ArrowSpace,     
00782             ArrowWidth,     
00783             SeparatorHeight,
00784             MinHeight,      
00785             ActiveTextColor,
00786             TextColor,      
00787             DisabledTextColor, 
00788             ActiveDisabledTextColor 
00789         };
00790 
00798         enum Primitive
00799         {
00800             CheckColumn, 
00801             CheckOn,     
00802             CheckOff,    
00803             RadioOn,     
00804             RadioOff,    
00805             CheckIcon,   
00806             Separator,   //A separator item.
00807             ItemIndicator //Shows the active item
00808         };
00809     };
00810 
00811 
00817     struct ScrollBar
00818     {
00825         enum LayoutProp
00826         {
00827             DoubleTopButton,    
00828             DoubleBotButton,    
00829             SingleButtonHeight, 
00830             DoubleButtonHeight, 
00831             BarWidth,           
00832             MinimumSliderHeight,
00835             ArrowColor,         
00837             ActiveArrowColor    
00838         };
00839 
00849         enum Primitive
00850         {
00851             SingleButtonVert,   
00852             SingleButtonHor,    
00853             DoubleButtonVert,           
00856             DoubleButtonHor,            
00857             GrooveAreaVertBottom,   
00858             GrooveAreaHorRight,    
00859             GrooveAreaVertTop,   
00860             GrooveAreaHorLeft,    
00861             SliderVert,       
00862             SliderHor         
00863         };
00864     };
00865 
00871     struct TabBar
00872     {
00886         enum LayoutProp
00887         {
00888             TabContentsMargin,  
00889             TabFocusMargin     = TabContentsMargin + MarginInc,
00892             TabTextToIconSpace = TabFocusMargin    + MarginInc,
00894             TabOverlap,         
00899             BaseHeight,        
00900             BaseOverlap,       
00901             ScrollButtonWidth  
00902         };
00903 
00911         enum Primitive
00912         {
00913             EastText,       
00914             WestText,       
00915             NorthTab,       
00916             EastTab,
00917             WestTab,
00918             SouthTab,
00919             BaseFrame,      
00920             IndicatorTear   
00924         };
00925     };
00926 
00935     struct TabWidget
00936     {
00940         enum LayoutProp
00941         {
00942             ContentsMargin,      
00949             DummyProp = ContentsMargin+MarginInc
00950         };
00951     };
00952 
00958     struct Slider
00959     {
00960 
00966         enum LayoutProp
00967         {
00968             HandleThickness, 
00969             HandleLength     
00970         };
00971 
00978         enum Primitive
00979         {
00980             HandleVert,   
00981             HandleHor,    
00982             GrooveVert,   
00983             GrooveHor     
00984         };
00985     };
00986 
00987 
00991     struct Tree
00992     {
01002         enum LayoutProp
01003         {
01004             MaxExpanderSize      
01008         };
01009 
01013         enum Primitive
01014         {
01015             ExpanderClosed, 
01016             ExpanderOpen,   
01017             HorizontalBranch, 
01021             VerticalBranch    
01022         };
01023     };
01024 
01028     struct SpinBox
01029     {
01045         enum LayoutProp
01046         {
01047             FrameWidth,        
01049             ButtonWidth,       
01050             ButtonMargin,      
01054             ButtonSpacing = ButtonMargin + MarginInc, 
01055             SymmetricButtons,  
01060             SupportFrameless,   
01064             ContentsMargin
01067         };
01068 
01074         enum Primitive
01075         {
01076             EditField,          
01079             UpButton,           
01080             DownButton,         
01081             ButtonArea,         
01084             PlusSymbol,         
01086             MinusSymbol         
01088         };
01089     };
01090 
01094     struct ComboBox
01095     {
01107         enum LayoutProp
01108         {
01109             FrameWidth,         
01110             ButtonWidth,        
01111             ButtonMargin,       
01113             FocusMargin = ButtonMargin + MarginInc,
01116             SupportFrameless = FocusMargin + MarginInc,
01119             ContentsMargin
01122         };
01123 
01132         enum Primitive
01133         {
01134             EditField,          
01135             Button              
01136         };
01137     };
01138 
01144     struct Header
01145     {
01149         enum LayoutProp
01150         {
01151             ContentsMargin,      
01152             TextToIconSpace = ContentsMargin + MarginInc,
01156             MarkSize             
01158         };
01159 
01167         enum Primitive
01168         {
01169             SectionHor, 
01170             SectionVert 
01171         };
01172     };
01173 
01179     struct LineEdit
01180     {
01187         enum Primitive
01188         {
01189             Panel     
01190         };
01191     };
01192 
01205     struct GroupBox
01206     {
01210         enum LayoutProps
01211         {
01212             FrameWidth, 
01213             TextAlignTop, 
01216             TitleTextColor 
01217         };
01221         enum Primitive
01222         {
01223             FlatFrame  
01226         };
01227     };
01228 
01239     struct StatusBar
01240     {
01244     };
01245 
01251     struct ToolBar
01252     {
01256         enum LayoutProps
01257         {
01258             HandleExtent,       
01259             SeparatorExtent,    
01260             ExtensionExtent,    
01261             FrameWidth,    
01263             ItemMargin,         
01264             ItemSpacing         
01265         };
01266 
01273         enum Primitive
01274         {
01275             HandleHor, 
01276             HandleVert, 
01277             Separator, 
01278             PanelHor,  
01279             PanelVert  
01280         };
01281     };
01282 
01283 
01289     struct ToolBoxTab
01290     {
01294         enum LayoutProps
01295         {
01296             Margin  
01299         };
01300 
01304         enum Primitive
01305         {
01306             Panel   
01309         };
01310     };
01311 
01312 
01323     struct ToolButton
01324     {
01328         enum LayoutProps
01329         {
01330             ContentsMargin,  
01332             FocusMargin            = ContentsMargin + MarginInc,
01335             MenuIndicatorSize, 
01337             InlineMenuIndicatorSize = FocusMargin + MarginInc, 
01340             InlineMenuIndicatorXOff,  
01343             InlineMenuIndicatorYOff   
01346         };
01347 
01358         enum Primitive
01359         {
01360             Panel           
01362         };
01363     };
01364 
01365 
01373     struct Window
01374     {
01378         enum LayoutProps
01379         {
01380             TitleTextColor, 
01381             TitleHeight, 
01382             NoTitleFrame, 
01385             TitleMargin,  
01388             ButtonWidth = TitleMargin + MarginInc, 
01389             ButtonSpace,      
01390             ButtonToTextSpace 
01391         };
01392 
01402         enum Primitive
01403         {
01404             TitlePanel,  
01405             ButtonMenu,     
01406             ButtonMin,      
01407             ButtonMax,      
01408             ButtonRestore,  
01409             ButtonClose,    
01410             ButtonShade,    
01411             ButtonUnshade,  
01412             ButtonHelp      
01413         };
01414     };
01416 
01418     void setWidgetLayoutProp(WidgetType widget, int metric, int value);
01419 
01434     virtual int widgetLayoutProp(WidgetType widgetType, int metric,
01435                                  const QStyleOption* opt = 0, const QWidget* w = 0) const;
01436 
01465     virtual void drawKStylePrimitive(WidgetType widgetType, int primitive, 
01466                                      const QStyleOption* opt,
01467                                      const QRect &r, const QPalette &pal,
01468                                      State flags, QPainter* p,
01469                                      const QWidget* widget = 0,
01470                                      Option* kOpt    = 0) const;
01471 private:
01473     bool useSideText(const QStyleOptionProgressBar* opt)     const;
01474     int  sideTextWidth(const QStyleOptionProgressBar* pbOpt) const;
01475 
01477     bool isVerticalTab (const QStyleOptionTab* tbOpt) const;
01478 
01480     bool isReflectedTab(const QStyleOptionTab* tbOpt) const;
01481 
01482     enum Side
01483     {
01484         North,
01485         East,
01486         West,
01487         South
01488     };
01489 
01490     Side tabSide(const QStyleOptionTab* tbOpt) const;
01491 
01493     QRect marginAdjustedTab(const QStyleOptionTab* tbOpt, int property) const;
01494 
01496     QRect  handleRTL(const QStyleOption* opt, const QRect& subRect) const;
01497     QPoint handleRTL(const QStyleOption* opt, const QPoint& pos)    const;
01498 
01500     QVector<QVector<int> > metrics;
01501     
01503     QSize expandDim(const QSize& orig, WidgetType widget, int baseMarginMetric, const QStyleOption* opt, const QWidget* w) const;
01504     
01507     QRect insideMargin(const QRect &orig, WidgetType widget, int baseMarginMetric, const QStyleOption* opt, const QWidget* w) const;
01508 
01511     QRect internalSubControlRect (ComplexControl control, const QStyleOptionComplex* opt,
01512                                                     SubControl subControl, const QWidget* w) const;
01513 
01514     // fitt's law label support: QLabel focusing its buddy widget
01515     const QObject *clickedLabel;
01516 
01517 public:
01526     void drawControl      (ControlElement   elem, const QStyleOption* opt, QPainter* p, const QWidget* w) const;
01527     void drawPrimitive    (PrimitiveElement elem, const QStyleOption* opt, QPainter* p, const QWidget* w) const;
01528     int  pixelMetric      (PixelMetric    metric, const QStyleOption* opt = 0, const QWidget* w = 0) const;
01529     QRect subElementRect  (SubElement    subRect, const QStyleOption* opt, const QWidget* w) const;
01530     QSize sizeFromContents(ContentsType     type, const QStyleOption* opt,
01531                                                 const QSize& contentsSize, const QWidget* w) const;
01532     int   styleHint       (StyleHint        hint, const QStyleOption* opt, const QWidget* w,
01533                                                                QStyleHintReturn* returnData) const;
01534     QRect subControlRect (ComplexControl control, const QStyleOptionComplex* opt,
01535                                                     SubControl subControl, const QWidget* w) const;
01536     SubControl hitTestComplexControl(ComplexControl cc, const QStyleOptionComplex* opt,
01537                                              const QPoint& pt, const QWidget* w) const;
01538     void       drawComplexControl   (ComplexControl cc, const QStyleOptionComplex* opt,
01539                                              QPainter *p,      const QWidget* w) const;
01540 
01541     void polish(QWidget *);
01542     void unpolish(QWidget *);
01543     void polish(QApplication *);
01544     void unpolish(QApplication *);
01545     void polish(QPalette &);
01546     QRect itemTextRect(const QFontMetrics &fm, const QRect &r,
01547                            int flags, bool enabled,
01548                            const QString &text) const;
01549     QRect itemPixmapRect(const QRect &r, int flags, const QPixmap &pixmap) const;
01550     void drawItemText(QPainter *painter, const QRect &rect,
01551                               int flags, const QPalette &pal, bool enabled,
01552                               const QString &text, QPalette::ColorRole textRole = QPalette::NoRole) const;
01553     void drawItemPixmap(QPainter *painter, const QRect &rect,
01554                                 int alignment, const QPixmap &pixmap) const;
01555     QPalette standardPalette() const;
01556     QPixmap standardPixmap(StandardPixmap standardPixmap, const QStyleOption *opt,
01557                                    const QWidget *widget = 0) const;
01558     QPixmap generatedIconPixmap(QIcon::Mode iconMode, const QPixmap &pixmap,
01559                                    const QStyleOption *opt) const;
01560     bool eventFilter(QObject *, QEvent *);
01562 private:
01563     KStylePrivate * const d;
01564 };
01565 
01566 template<typename T>
01567 const char* kstyleName()
01568 { return "default"; }
01569 
01579 template<typename T>
01580 class KStyleFactory: public QStylePlugin
01581 {
01582     QStringList keys() const
01583     {
01584         QStringList l;
01585         l << kstyleName<T>();
01586         return l;
01587     }
01588     
01589     QStyle* create(const QString& id)
01590     {
01591         QStringList names = keys();
01592         //check whether included in the keys
01593         if (names.contains(id, Qt::CaseInsensitive))
01594             return new T();
01595 
01596         return 0;
01597     }
01598 };
01599 
01600 
01601 template<typename T>
01602 T KStyle::extractOption(Option* option)
01603 {
01604     if (option && dynamic_cast<T>(option)) {
01605         return static_cast<T>(option);
01606     }
01607 
01608     //### warn if cast failed?
01609 
01610     //since T is a pointer type, need this to get to the static.
01611     return static_cast<T>(0)->defaultOption();
01612 }
01613 
01614 #define K_EXPORT_STYLE(name,type) template<> const char* kstyleName<type>() { return name; } \
01615     Q_EXPORT_PLUGIN(KStyleFactory<type>)
01616 
01617 #endif
01618 // kate: indent-width 4; replace-tabs on; tab-width 4; space-indent on;

KDEUI

Skip menu "KDEUI"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • KIO
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal