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
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084 class KDEUI_EXPORT KStyle: public QCommonStyle
00085 {
00086 Q_OBJECT
00087
00088 public:
00089 KStyle();
00090 ~KStyle();
00091
00095 static QString defaultStyle();
00122 static StyleHint customStyleHint(const QString &element, const QWidget *widget);
00123 static ControlElement customControlElement(const QString &element, const QWidget *widget);
00124 static SubElement customSubElement(const QString &element, const QWidget *widget);
00125
00126 protected:
00127
00156 StyleHint newStyleHint(const QString &element);
00157 ControlElement newControlElement(const QString &element);
00158 SubElement newSubElement(const QString &element);
00159
00167 void drawInsideRect(QPainter* p, const QRect& r) const;
00168
00172 QRect centerRect(const QRect &in, int w, int h) const;
00173
00177 QRect centerRect(const QRect &in, const QSize &size) const;
00179
00190 class KDEUI_EXPORT ColorMode
00191 {
00192 public:
00200 enum Mode
00201 {
00202 PaletteEntryMode,
00203 BWAutoContrastMode = 0x8000000
00204 };
00205 private:
00206 Mode mode;
00207 QPalette::ColorRole role;
00208 public:
00209
00212 ColorMode(QPalette::ColorRole _role);
00213
00215 ColorMode(Mode _mode, QPalette::ColorRole _role);
00216
00218 operator int() const;
00219
00221 ColorMode(int encoded);
00222
00225 QColor color(const QPalette& palette);
00226 };
00227
00228
00238 struct KDEUI_EXPORT Option
00239 {
00240 virtual ~Option() {}
00241 };
00242
00252 template<typename EventualSubtype, typename BaseType>
00253 struct KDEUI_EXPORT OptionBase: public BaseType
00254 {
00258 static EventualSubtype* defaultOption()
00259 {
00260 static EventualSubtype* theDefault = 0;
00261
00262
00263 if (!theDefault)
00264 theDefault = new EventualSubtype;
00265
00266 return theDefault;
00267 }
00268 };
00269
00276 template<typename T>
00277 static T extractOption(Option* option);
00278
00283 struct KDEUI_EXPORT ColorOption: public OptionBase<ColorOption, Option>
00284 {
00286 ColorMode color;
00287
00288 ColorOption(): color(QPalette::ButtonText)
00289 {}
00290 };
00291
00296 struct KDEUI_EXPORT IconOption: public OptionBase<IconOption, Option>
00297 {
00298 bool active;
00299 QIcon icon;
00300 QSize size;
00301
00302 IconOption(): active(false)
00303 {}
00304 };
00305
00311 struct KDEUI_EXPORT DoubleButtonOption: public OptionBase<DoubleButtonOption, Option>
00312 {
00316 enum ActiveButton
00317 {
00318 None,
00319 Top,
00320 Left,
00321 Right,
00322 Bottom
00323 };
00324
00329 ActiveButton activeButton;
00330
00331 DoubleButtonOption(): activeButton(None)
00332 {}
00333
00339 DoubleButtonOption(ActiveButton ab): activeButton(ab)
00340 {}
00341 };
00342
00348 struct KDEUI_EXPORT TitleButtonOption: public OptionBase<TitleButtonOption, Option>
00349 {
00350 bool active;
00351 QIcon icon;
00352
00353
00354
00355 TitleButtonOption(): active(false)
00356 {}
00357
00363 TitleButtonOption(bool act): active(act)
00364 {}
00365 };
00366
00368 struct KDEUI_EXPORT TextOption: public OptionBase<TextOption, ColorOption>
00369 {
00370 Qt::Alignment hAlign;
00371 QString text;
00372
00373 TextOption();
00374
00380 TextOption(const QString& _text);
00381
00385 void init();
00386 };
00388
00400 enum WidgetType
00401 {
00402 WT_Generic,
00403 WT_PushButton,
00404 WT_Splitter,
00405 WT_CheckBox,
00406 WT_RadioButton,
00407 WT_DockWidget,
00408 WT_ProgressBar,
00409 WT_MenuBar,
00410 WT_MenuBarItem,
00411 WT_Menu,
00412 WT_MenuItem,
00413 WT_ScrollBar,
00414 WT_TabBar,
00415 WT_TabWidget,
00416 WT_Slider,
00417 WT_Tree,
00418 WT_SpinBox,
00419 WT_ComboBox,
00420 WT_Header,
00421 WT_LineEdit,
00422 WT_GroupBox,
00423 WT_StatusBar,
00424 WT_ToolBar,
00425 WT_ToolButton,
00426 WT_ToolBoxTab,
00427 WT_Window,
00428 WT_Limit = 0xFFFF
00429 };
00430
00431
00439 enum MarginOffsets
00440 {
00441 MainMargin,
00444 Top,
00445 Bot,
00446 Left,
00447 Right,
00448 MarginInc
00450 };
00451
00452
00457 struct Generic
00458 {
00464 enum LayoutProp
00465 {
00466 DefaultFrameWidth,
00467 DefaultLayoutSpacing,
00468 DefaultLayoutMargin
00469 };
00470
00476 enum Primitive
00477 {
00478 Text = 0xFFFF,
00479 Icon,
00480 FocusIndicator,
00481 Frame,
00484 ArrowUp,
00485 ArrowDown,
00486 ArrowRight,
00487 ArrowLeft
00488 };
00489 };
00490
00496 struct PushButton
00497 {
00510 enum LayoutProp
00511 {
00512 ContentsMargin,
00513 FocusMargin = ContentsMargin + MarginInc,
00514 DefaultIndicatorMargin = FocusMargin + MarginInc,
00515 PressedShiftHorizontal = DefaultIndicatorMargin + MarginInc,
00516 PressedShiftVertical,
00517 MenuIndicatorSize,
00518 TextToIconSpace
00519 };
00520
00531 enum Primitive
00532 {
00533 Panel,
00535 DefaultButtonFrame
00538 };
00539 };
00540
00546 struct Splitter
00547 {
00551 enum LayoutProp
00552 {
00553 Width
00554 };
00555
00561 enum Primitive
00562 {
00563 HandleHor,
00564 HandleVert
00565 };
00566 };
00567
00573 struct CheckBox
00574 {
00578 enum LayoutProp
00579 {
00580 Size,
00581 BoxTextSpace,
00582 NoLabelFocusMargin,
00585 FocusMargin = NoLabelFocusMargin + MarginInc
00586 };
00587
00600 enum Primitive
00601 {
00602 CheckOn,
00603 CheckOff,
00604 CheckTriState
00605 };
00606 };
00607
00611 struct RadioButton
00612 {
00616 enum LayoutProp
00617 {
00618 Size,
00621 BoxTextSpace,
00622 FocusMargin
00623 };
00624
00636 enum Primitive
00637 {
00638 RadioOn,
00639 RadioOff
00640 };
00641 };
00642
00643
00649 struct DockWidget
00650 {
00654 enum LayoutProp
00655 {
00656 TitleTextColor,
00657 TitleMargin,
00658 FrameWidth = TitleMargin + MarginInc,
00659 SeparatorExtent
00660 };
00661
00671 enum Primitive
00672 {
00673 TitlePanel,
00674 SeparatorHandle
00675 };
00676 };
00677
00685 struct ProgressBar
00686 {
00690 enum LayoutProp
00691 {
00692 GrooveMargin,
00693 SideText = GrooveMargin + MarginInc,
00694 SideTextSpace,
00695 Precision,
00696 BusyIndicatorSize,
00697 MaxBusyIndicatorSize
00698 };
00699
00706 enum Primitive
00707 {
00708 Groove,
00710 Indicator,
00711 BusyIndicator
00714 };
00715 };
00716
00717
00723 struct MenuBar
00724 {
00728 enum LayoutProp
00729 {
00730 Margin,
00732 ItemSpacing = Margin + MarginInc
00733 };
00734
00738 enum Property
00739 {
00740 EmptyArea
00743 };
00744 };
00745
00746
00753 struct MenuBarItem
00754 {
00758 enum LayoutProp
00759 {
00760 Margin,
00763 Dummy = Margin + MarginInc
00764 };
00765
00769 enum Primitive
00770 {
00771 Panel
00772 };
00773 };
00774
00780 struct Menu
00781 {
00785 enum LayoutProp
00786 {
00787 FrameWidth,
00788 Margin,
00789 ScrollerHeight = Margin + MarginInc,
00790 TearOffHeight
00791 };
00792
00799 enum Primitive
00800 {
00801 Background,
00802 TearOff,
00804 Scroller
00806 };
00807 };
00808
00827 struct MenuItem
00828 {
00832 enum LayoutProp
00833 {
00834 Margin,
00835 CheckAlongsideIcon = Margin + MarginInc,
00838 CheckWidth,
00840 CheckSpace,
00842 IconWidth,
00843 IconSpace,
00844 AccelSpace,
00845 ArrowSpace,
00846 ArrowWidth,
00847 SeparatorHeight,
00848 MinHeight,
00849 ActiveTextColor,
00850 TextColor,
00851 DisabledTextColor,
00852 ActiveDisabledTextColor
00853 };
00854
00862 enum Primitive
00863 {
00864 CheckColumn,
00865 CheckOn,
00866 CheckOff,
00867 RadioOn,
00868 RadioOff,
00869 CheckIcon,
00870 Separator,
00871 ItemIndicator
00872 };
00873 };
00874
00875
00881 struct ScrollBar
00882 {
00889 enum LayoutProp
00890 {
00891 DoubleTopButton,
00892 DoubleBotButton,
00893 SingleButtonHeight,
00894 DoubleButtonHeight,
00895 BarWidth,
00896 MinimumSliderHeight,
00899 ArrowColor,
00901 ActiveArrowColor
00902 };
00903
00913 enum Primitive
00914 {
00915 SingleButtonVert,
00916 SingleButtonHor,
00917 DoubleButtonVert,
00920 DoubleButtonHor,
00921 GrooveAreaVertBottom,
00922 GrooveAreaHorRight,
00923 GrooveAreaVertTop,
00924 GrooveAreaHorLeft,
00925 SliderVert,
00926 SliderHor
00927 };
00928 };
00929
00935 struct TabBar
00936 {
00950 enum LayoutProp
00951 {
00952 TabContentsMargin,
00953 TabFocusMargin = TabContentsMargin + MarginInc,
00956 TabTextToIconSpace = TabFocusMargin + MarginInc,
00958 TabOverlap,
00963 BaseHeight,
00964 BaseOverlap,
00965 ScrollButtonWidth
00966 };
00967
00975 enum Primitive
00976 {
00977 EastText,
00978 WestText,
00979 NorthTab,
00980 EastTab,
00981 WestTab,
00982 SouthTab,
00983 BaseFrame,
00984 IndicatorTear
00988 };
00989 };
00990
00999 struct TabWidget
01000 {
01004 enum LayoutProp
01005 {
01006 ContentsMargin,
01013 DummyProp = ContentsMargin+MarginInc
01014 };
01015 };
01016
01022 struct Slider
01023 {
01024
01030 enum LayoutProp
01031 {
01032 HandleThickness,
01033 HandleLength
01034 };
01035
01042 enum Primitive
01043 {
01044 HandleVert,
01045 HandleHor,
01046 GrooveVert,
01047 GrooveHor
01048 };
01049 };
01050
01051
01055 struct Tree
01056 {
01066 enum LayoutProp
01067 {
01068 MaxExpanderSize
01072 };
01073
01077 enum Primitive
01078 {
01079 ExpanderClosed,
01080 ExpanderOpen,
01081 HorizontalBranch,
01085 VerticalBranch
01086 };
01087 };
01088
01092 struct SpinBox
01093 {
01109 enum LayoutProp
01110 {
01111 FrameWidth,
01113 ButtonWidth,
01114 ButtonMargin,
01118 ButtonSpacing = ButtonMargin + MarginInc,
01119 SymmetricButtons,
01124 SupportFrameless,
01128 ContentsMargin
01131 };
01132
01138 enum Primitive
01139 {
01140 EditField,
01143 UpButton,
01144 DownButton,
01145 ButtonArea,
01148 PlusSymbol,
01150 MinusSymbol
01152 };
01153 };
01154
01158 struct ComboBox
01159 {
01171 enum LayoutProp
01172 {
01173 FrameWidth,
01174 ButtonWidth,
01175 ButtonMargin,
01177 FocusMargin = ButtonMargin + MarginInc,
01180 SupportFrameless = FocusMargin + MarginInc,
01183 ContentsMargin
01186 };
01187
01196 enum Primitive
01197 {
01198 EditField,
01199 Button
01200 };
01201 };
01202
01208 struct Header
01209 {
01213 enum LayoutProp
01214 {
01215 ContentsMargin,
01216 TextToIconSpace = ContentsMargin + MarginInc,
01220 MarkSize
01222 };
01223
01231 enum Primitive
01232 {
01233 SectionHor,
01234 SectionVert
01235 };
01236 };
01237
01243 struct LineEdit
01244 {
01251 enum Primitive
01252 {
01253 Panel
01254 };
01255 };
01256
01269 struct GroupBox
01270 {
01274 enum LayoutProps
01275 {
01276 FrameWidth,
01277 TextAlignTop,
01280 TitleTextColor
01281 };
01285 enum Primitive
01286 {
01287 FlatFrame
01290 };
01291 };
01292
01303 struct StatusBar
01304 {
01308 };
01309
01315 struct ToolBar
01316 {
01320 enum LayoutProps
01321 {
01322 HandleExtent,
01323 SeparatorExtent,
01324 ExtensionExtent,
01325 FrameWidth,
01327 ItemMargin,
01328 ItemSpacing
01329 };
01330
01337 enum Primitive
01338 {
01339 HandleHor,
01340 HandleVert,
01341 Separator,
01342 PanelHor,
01343 PanelVert
01344 };
01345 };
01346
01347
01353 struct ToolBoxTab
01354 {
01358 enum LayoutProps
01359 {
01360 Margin
01363 };
01364
01368 enum Primitive
01369 {
01370 Panel
01373 };
01374 };
01375
01376
01387 struct ToolButton
01388 {
01392 enum LayoutProps
01393 {
01394 ContentsMargin,
01396 FocusMargin = ContentsMargin + MarginInc,
01399 MenuIndicatorSize,
01401 InlineMenuIndicatorSize = FocusMargin + MarginInc,
01404 InlineMenuIndicatorXOff,
01407 InlineMenuIndicatorYOff
01410 };
01411
01422 enum Primitive
01423 {
01424 Panel
01426 };
01427 };
01428
01429
01437 struct Window
01438 {
01442 enum LayoutProps
01443 {
01444 TitleTextColor,
01445 TitleHeight,
01446 NoTitleFrame,
01449 TitleMargin,
01452 ButtonWidth = TitleMargin + MarginInc,
01453 ButtonSpace,
01454 ButtonToTextSpace
01455 };
01456
01466 enum Primitive
01467 {
01468 TitlePanel,
01469 ButtonMenu,
01470 ButtonMin,
01471 ButtonMax,
01472 ButtonRestore,
01473 ButtonClose,
01474 ButtonShade,
01475 ButtonUnshade,
01476 ButtonHelp
01477 };
01478 };
01480
01482 void setWidgetLayoutProp(WidgetType widget, int metric, int value);
01483
01498 virtual int widgetLayoutProp(WidgetType widgetType, int metric,
01499 const QStyleOption* opt = 0, const QWidget* w = 0) const;
01500
01529 virtual void drawKStylePrimitive(WidgetType widgetType, int primitive,
01530 const QStyleOption* opt,
01531 const QRect &r, const QPalette &pal,
01532 State flags, QPainter* p,
01533 const QWidget* widget = 0,
01534 Option* kOpt = 0) const;
01535 private:
01537 bool useSideText(const QStyleOptionProgressBar* opt) const;
01538 int sideTextWidth(const QStyleOptionProgressBar* pbOpt) const;
01539
01541 bool isVerticalTab (const QStyleOptionTab* tbOpt) const;
01542
01544 bool isReflectedTab(const QStyleOptionTab* tbOpt) const;
01545
01546 enum Side
01547 {
01548 North,
01549 East,
01550 West,
01551 South
01552 };
01553
01554 Side tabSide(const QStyleOptionTab* tbOpt) const;
01555
01557 QRect marginAdjustedTab(const QStyleOptionTab* tbOpt, int property) const;
01558
01560 QRect handleRTL(const QStyleOption* opt, const QRect& subRect) const;
01561 QPoint handleRTL(const QStyleOption* opt, const QPoint& pos) const;
01562
01564 QVector<QVector<int> > metrics;
01565
01567 QSize expandDim(const QSize& orig, WidgetType widget, int baseMarginMetric, const QStyleOption* opt, const QWidget* w, bool rotated = false) const;
01568
01571 QRect insideMargin(const QRect &orig, WidgetType widget, int baseMarginMetric, const QStyleOption* opt, const QWidget* w) const;
01572
01575 QRect internalSubControlRect (ComplexControl control, const QStyleOptionComplex* opt,
01576 SubControl subControl, const QWidget* w) const;
01577
01578
01579 const QObject *clickedLabel;
01580
01581 public:
01590 void drawControl (ControlElement elem, const QStyleOption* opt, QPainter* p, const QWidget* w) const;
01591 void drawPrimitive (PrimitiveElement elem, const QStyleOption* opt, QPainter* p, const QWidget* w) const;
01592 int pixelMetric (PixelMetric metric, const QStyleOption* opt = 0, const QWidget* w = 0) const;
01593 QRect subElementRect (SubElement subRect, const QStyleOption* opt, const QWidget* w) const;
01594 QSize sizeFromContents(ContentsType type, const QStyleOption* opt,
01595 const QSize& contentsSize, const QWidget* w) const;
01596 int styleHint (StyleHint hint, const QStyleOption* opt, const QWidget* w,
01597 QStyleHintReturn* returnData) const;
01598 QRect subControlRect (ComplexControl control, const QStyleOptionComplex* opt,
01599 SubControl subControl, const QWidget* w) const;
01600 SubControl hitTestComplexControl(ComplexControl cc, const QStyleOptionComplex* opt,
01601 const QPoint& pt, const QWidget* w) const;
01602 void drawComplexControl (ComplexControl cc, const QStyleOptionComplex* opt,
01603 QPainter *p, const QWidget* w) const;
01604
01605 void polish(QWidget *);
01606 void unpolish(QWidget *);
01607 void polish(QApplication *);
01608 void unpolish(QApplication *);
01609 void polish(QPalette &);
01610 QRect itemTextRect(const QFontMetrics &fm, const QRect &r,
01611 int flags, bool enabled,
01612 const QString &text) const;
01613 QRect itemPixmapRect(const QRect &r, int flags, const QPixmap &pixmap) const;
01614 void drawItemText(QPainter *painter, const QRect &rect,
01615 int flags, const QPalette &pal, bool enabled,
01616 const QString &text, QPalette::ColorRole textRole = QPalette::NoRole) const;
01617 void drawItemPixmap(QPainter *painter, const QRect &rect,
01618 int alignment, const QPixmap &pixmap) const;
01619 QPalette standardPalette() const;
01620 QPixmap standardPixmap(StandardPixmap standardPixmap, const QStyleOption *opt,
01621 const QWidget *widget = 0) const;
01622 QPixmap generatedIconPixmap(QIcon::Mode iconMode, const QPixmap &pixmap,
01623 const QStyleOption *opt) const;
01624 bool eventFilter(QObject *, QEvent *);
01625
01626 protected Q_SLOTS:
01627 int layoutSpacingImplementation(QSizePolicy::ControlType control1,
01628 QSizePolicy::ControlType control2, Qt::Orientation orientation,
01629 const QStyleOption *option, const QWidget *widget) const;
01631 private:
01632 KStylePrivate * const d;
01633 };
01634
01635 template<typename T>
01636 const char* kstyleName()
01637 { return "default"; }
01638
01648 template<typename T>
01649 class KStyleFactory: public QStylePlugin
01650 {
01651 QStringList keys() const
01652 {
01653 QStringList l;
01654 l << kstyleName<T>();
01655 return l;
01656 }
01657
01658 QStyle* create(const QString& id)
01659 {
01660 QStringList names = keys();
01661
01662 if (names.contains(id, Qt::CaseInsensitive))
01663 return new T();
01664
01665 return 0;
01666 }
01667 };
01668
01669
01670 template<typename T>
01671 T KStyle::extractOption(Option* option)
01672 {
01673 if (option && dynamic_cast<T>(option)) {
01674 return static_cast<T>(option);
01675 }
01676
01677
01678
01679
01680 return static_cast<T>(0)->defaultOption();
01681 }
01682
01683 #define K_EXPORT_STYLE(name,type) template<> const char* kstyleName<type>() { return name; } \
01684 Q_EXPORT_PLUGIN(KStyleFactory<type>)
01685
01686 #endif
01687