File indexing completed on 2024-04-28 16:51:18

0001 #ifndef oxygenstyle_h
0002 #define oxygenstyle_h
0003 
0004 //////////////////////////////////////////////////////////////////////////////
0005 // oxygenstyle.h
0006 // Oxygen widget style for KDE 4
0007 // -------------------
0008 //
0009 // SPDX-FileCopyrightText: 2009-2010 Hugo Pereira Da Costa <hugo.pereira@free.fr>
0010 // SPDX-FileCopyrightText: 2008 Long Huynh Huu <long.upcase@googlemail.com>
0011 // SPDX-FileCopyrightText: 2007-2008 Casper Boemann <cbr@boemann.dk>
0012 // SPDX-FileCopyrightText: 2007 Matthew Woehlke <mw_triad@users.sourceforge.net>
0013 // SPDX-FileCopyrightText: 2003-2005 Sandro Giessl <sandro@giessl.com>
0014 //
0015 // based on the KDE style "dotNET":
0016 // SPDX-FileCopyrightText: 2001-2002 Chris Lee <clee@kde.org>
0017 // Carsten Pfeiffer <pfeiffer@kde.org>
0018 // Karol Szwed <gallium@kde.org>
0019 // Drawing routines completely reimplemented from KDE3 HighColor, which was
0020 // originally based on some stuff from the KDE2 HighColor.
0021 //
0022 // based on drawing routines of the style "Keramik":
0023 // SPDX-FileCopyrightText: 2002 Malte Starostik <malte@kde.org>
0024 // SPDX-FileCopyrightText: 2002, 2003 Maksim Orlovich <mo002j@mail.rochester.edu>
0025 // based on the KDE3 HighColor Style
0026 // SPDX-FileCopyrightText: 2001-2002 Karol Szwed <gallium@kde.org>
0027 // SPDX-FileCopyrightText: 2001-2002 Fredrik H �glund  <fredrik@kde.org>
0028 // Drawing routines adapted from the KDE2 HCStyle,
0029 // SPDX-FileCopyrightText: 2000 Daniel M. Duley <mosfet@kde.org>
0030 // SPDX-FileCopyrightText: 2000 Dirk Mueller <mueller@kde.org>
0031 // SPDX-FileCopyrightText: 2001 Martijn Klingens <klingens@kde.org>
0032 // Progressbar code based on KStyle,
0033 // SPDX-FileCopyrightText: 2001-2002 Karol Szwed <gallium@kde.org>
0034 //
0035 // SPDX-License-Identifier: LGPL-2.0-only
0036 //////////////////////////////////////////////////////////////////////////////
0037 
0038 #include "config-liboxygen.h"
0039 #include "oxygen.h"
0040 #include "oxygentileset.h"
0041 
0042 #include <KStyle>
0043 
0044 #include <QAbstractScrollArea>
0045 #include <QCommandLinkButton>
0046 #include <QDockWidget>
0047 #include <QMdiSubWindow>
0048 #include <QStyleOption>
0049 #include <QStyleOptionSlider>
0050 #include <QStylePlugin>
0051 #include <QToolBar>
0052 #include <QToolBox>
0053 #include <QWidget>
0054 
0055 #include <QIcon>
0056 
0057 namespace OxygenPrivate
0058 {
0059 class TabBarData;
0060 }
0061 
0062 namespace Oxygen
0063 {
0064 
0065 class Animations;
0066 class FrameShadowFactory;
0067 class MdiWindowShadowFactory;
0068 class Mnemonics;
0069 class ShadowHelper;
0070 class SplitterFactory;
0071 class StyleHelper;
0072 class Transitions;
0073 class TopLevelManager;
0074 class WindowManager;
0075 class WidgetExplorer;
0076 class BlurHelper;
0077 
0078 //* base class for oxygen style
0079 /** it is responsible to draw all the primitives to be displayed on screen, on request from Qt paint engine */
0080 class Style : public KStyle
0081 {
0082     Q_OBJECT
0083 
0084     /* this tells kde applications that custom style elements are supported, using the kstyle mechanism */
0085     Q_CLASSINFO("X-KDE-CustomElements", "true")
0086 
0087 public:
0088     //* constructor
0089     explicit Style(void);
0090 
0091     //* destructor
0092     ~Style(void) override;
0093 
0094     //* needed to avoid warnings at compilation time
0095     using KStyle::polish;
0096     using KStyle::unpolish;
0097 
0098     //* widget polishing
0099     void polish(QWidget *) override;
0100 
0101     //* widget unpolishing
0102     void unpolish(QWidget *) override;
0103 
0104     //* pixel metrics
0105     int pixelMetric(PixelMetric, const QStyleOption * = nullptr, const QWidget * = nullptr) const override;
0106 
0107     //* style hints
0108     int styleHint(StyleHint, const QStyleOption * = nullptr, const QWidget * = nullptr, QStyleHintReturn * = nullptr) const override;
0109 
0110     //* returns rect corresponding to one widget's subelement
0111     QRect subElementRect(SubElement, const QStyleOption *, const QWidget *) const override;
0112 
0113     //* returns rect corresponding to one widget's subcontrol
0114     QRect subControlRect(ComplexControl, const QStyleOptionComplex *, SubControl, const QWidget *) const override;
0115 
0116     //* returns size matching contents
0117     QSize sizeFromContents(ContentsType, const QStyleOption *, const QSize &, const QWidget *) const override;
0118 
0119     //* returns which subcontrol given QPoint corresponds to
0120     SubControl hitTestComplexControl(ComplexControl, const QStyleOptionComplex *, const QPoint &, const QWidget *) const override;
0121 
0122     //* primitives
0123     void drawPrimitive(PrimitiveElement, const QStyleOption *, QPainter *, const QWidget *) const override;
0124 
0125     //* controls
0126     void drawControl(ControlElement, const QStyleOption *, QPainter *, const QWidget *) const override;
0127 
0128     //* complex controls
0129     void drawComplexControl(ComplexControl, const QStyleOptionComplex *, QPainter *, const QWidget *) const override;
0130 
0131     //* generic text rendering
0132     void drawItemText(QPainter *, const QRect &, int alignment, const QPalette &, bool enabled, const QString &, QPalette::ColorRole = QPalette::NoRole)
0133         const override;
0134 
0135     //*@name event filters
0136     //@{
0137 
0138     bool eventFilter(QObject *, QEvent *) override;
0139     bool eventFilterComboBoxContainer(QWidget *, QEvent *);
0140     bool eventFilterDockWidget(QDockWidget *, QEvent *);
0141     bool eventFilterMdiSubWindow(QMdiSubWindow *, QEvent *);
0142     bool eventFilterCommandLinkButton(QCommandLinkButton *, QEvent *);
0143 
0144     bool eventFilterScrollBar(QWidget *, QEvent *);
0145     bool eventFilterTabBar(QWidget *, QEvent *);
0146     bool eventFilterToolBar(QToolBar *, QEvent *);
0147     bool eventFilterToolBox(QToolBox *, QEvent *);
0148 
0149     //* install event filter to object, in a unique way
0150     void addEventFilter(QObject *object)
0151     {
0152         object->removeEventFilter(this);
0153         object->installEventFilter(this);
0154     }
0155 
0156     //@}
0157 
0158 protected Q_SLOTS:
0159 
0160     //* standard icons
0161     virtual QIcon standardIconImplementation(StandardPixmap, const QStyleOption *, const QWidget *) const;
0162 
0163 protected:
0164     //* standard icons
0165     QIcon standardIcon(StandardPixmap pixmap, const QStyleOption *option = nullptr, const QWidget *widget = nullptr) const override
0166     {
0167         return standardIconImplementation(pixmap, option, widget);
0168     }
0169 
0170 private Q_SLOTS:
0171 
0172     //* update configuration
0173     void configurationChanged(void);
0174 
0175 private:
0176     //* load configuration
0177     void loadConfiguration();
0178 
0179     //*@name enumerations and convenience classes
0180     //@{
0181 
0182     //* used to store slab characteristics
0183     class SlabRect
0184     {
0185     public:
0186         //* constructor
0187         explicit SlabRect(void);
0188 
0189         //* constructor
0190         SlabRect(const QRect &rect, int tiles);
0191 
0192         //* validity
0193         bool isValid(void) const;
0194 
0195         /**
0196         adjust rectangle depending on tiles and tileSize
0197         so that it is rendered properly
0198         **/
0199         void adjust(int);
0200 
0201         /**
0202         adjust rectangle depending on tiles and tileSize
0203         so that it is rendered properly
0204         **/
0205         SlabRect adjusted(int) const;
0206 
0207         QRect rect;
0208         TileSet::Tiles tiles;
0209 
0210         //* list of slabs
0211         using List = QList<SlabRect>;
0212     };
0213 
0214     //@}
0215 
0216     //*@name subelementRect specialized functions
0217     //@{
0218 
0219     //* default implementation. Does not change anything
0220     QRect defaultSubElementRect(const QStyleOption *option, const QWidget *) const
0221     {
0222         return option->rect;
0223     }
0224 
0225     QRect pushButtonContentsRect(const QStyleOption *option, const QWidget *) const;
0226     QRect checkBoxContentsRect(const QStyleOption *option, const QWidget *) const;
0227     QRect lineEditContentsRect(const QStyleOption *, const QWidget *) const;
0228     QRect progressBarGrooveRect(const QStyleOption *option, const QWidget *) const;
0229     QRect progressBarContentsRect(const QStyleOption *option, const QWidget *) const;
0230     QRect headerArrowRect(const QStyleOption *option, const QWidget *) const;
0231     QRect headerLabelRect(const QStyleOption *option, const QWidget *) const;
0232     QRect tabBarTabLeftButtonRect(const QStyleOption *, const QWidget *) const;
0233     QRect tabBarTabRightButtonRect(const QStyleOption *, const QWidget *) const;
0234     QRect tabWidgetTabBarRect(const QStyleOption *, const QWidget *) const;
0235     QRect tabWidgetTabContentsRect(const QStyleOption *, const QWidget *) const;
0236     QRect tabWidgetTabPaneRect(const QStyleOption *, const QWidget *) const;
0237     QRect tabWidgetCornerRect(SubElement, const QStyleOption *option, const QWidget *widget) const;
0238     QRect toolBoxTabContentsRect(const QStyleOption *option, const QWidget *) const;
0239 
0240     //@}
0241 
0242     //*@name subcontrol Rect specialized functions
0243     //@{
0244 
0245     QRect groupBoxSubControlRect(const QStyleOptionComplex *, SubControl, const QWidget *) const;
0246     QRect toolButtonSubControlRect(const QStyleOptionComplex *, SubControl, const QWidget *) const;
0247     QRect comboBoxSubControlRect(const QStyleOptionComplex *, SubControl, const QWidget *) const;
0248     QRect spinBoxSubControlRect(const QStyleOptionComplex *, SubControl, const QWidget *) const;
0249     QRect scrollBarInternalSubControlRect(const QStyleOptionComplex *, SubControl) const;
0250     QRect scrollBarSubControlRect(const QStyleOptionComplex *, SubControl, const QWidget *) const;
0251     QRect sliderSubControlRect(const QStyleOptionComplex *, SubControl, const QWidget *) const;
0252 
0253     //@}
0254 
0255     //*@name sizeFromContents
0256     //@{
0257     QSize defaultSizeFromContents(const QStyleOption *, const QSize &size, const QWidget *) const
0258     {
0259         return size;
0260     }
0261 
0262     QSize checkBoxSizeFromContents(const QStyleOption *, const QSize &, const QWidget *) const;
0263     QSize lineEditSizeFromContents(const QStyleOption *, const QSize &, const QWidget *) const;
0264     QSize comboBoxSizeFromContents(const QStyleOption *, const QSize &, const QWidget *) const;
0265     QSize spinBoxSizeFromContents(const QStyleOption *, const QSize &, const QWidget *) const;
0266     QSize sliderSizeFromContents(const QStyleOption *, const QSize &, const QWidget *) const;
0267     QSize pushButtonSizeFromContents(const QStyleOption *, const QSize &, const QWidget *) const;
0268     QSize toolButtonSizeFromContents(const QStyleOption *, const QSize &, const QWidget *) const;
0269     QSize menuBarItemSizeFromContents(const QStyleOption *, const QSize &, const QWidget *) const;
0270     QSize menuItemSizeFromContents(const QStyleOption *, const QSize &, const QWidget *) const;
0271     QSize tabWidgetSizeFromContents(const QStyleOption *, const QSize &, const QWidget *) const;
0272     QSize tabBarTabSizeFromContents(const QStyleOption *, const QSize &, const QWidget *) const;
0273     QSize headerSectionSizeFromContents(const QStyleOption *, const QSize &, const QWidget *) const;
0274     QSize itemViewItemSizeFromContents(const QStyleOption *, const QSize &, const QWidget *) const;
0275 
0276     //@}
0277 
0278     //*@name primitives specialized functions
0279     //@{
0280 
0281     bool emptyPrimitive(const QStyleOption *, QPainter *, const QWidget *) const
0282     {
0283         return true;
0284     }
0285 
0286     bool drawFramePrimitive(const QStyleOption *, QPainter *, const QWidget *) const;
0287     bool drawFrameLineEditPrimitive(const QStyleOption *, QPainter *, const QWidget *) const;
0288     bool drawFrameFocusRectPrimitive(const QStyleOption *, QPainter *, const QWidget *) const;
0289     bool drawFrameMenuPrimitive(const QStyleOption *, QPainter *, const QWidget *) const;
0290     bool drawFrameGroupBoxPrimitive(const QStyleOption *, QPainter *, const QWidget *) const;
0291     bool drawFrameTabWidgetPrimitive(const QStyleOption *, QPainter *, const QWidget *) const;
0292     bool drawFrameTabBarBasePrimitive(const QStyleOption *, QPainter *, const QWidget *) const;
0293     bool drawFrameWindowPrimitive(const QStyleOption *, QPainter *, const QWidget *) const;
0294 
0295     bool drawIndicatorArrowUpPrimitive(const QStyleOption *option, QPainter *painter, const QWidget *widget) const
0296     {
0297         return drawIndicatorArrowPrimitive(ArrowUp, option, painter, widget);
0298     }
0299 
0300     bool drawIndicatorArrowDownPrimitive(const QStyleOption *option, QPainter *painter, const QWidget *widget) const
0301     {
0302         return drawIndicatorArrowPrimitive(ArrowDown, option, painter, widget);
0303     }
0304 
0305     bool drawIndicatorArrowLeftPrimitive(const QStyleOption *option, QPainter *painter, const QWidget *widget) const
0306     {
0307         return drawIndicatorArrowPrimitive(ArrowLeft, option, painter, widget);
0308     }
0309 
0310     bool drawIndicatorArrowRightPrimitive(const QStyleOption *option, QPainter *painter, const QWidget *widget) const
0311     {
0312         return drawIndicatorArrowPrimitive(ArrowRight, option, painter, widget);
0313     }
0314 
0315     //* dock widget separators
0316     /** it uses the same painting as QSplitter, but due to Qt, the horizontal/vertical convention is inverted */
0317     bool drawIndicatorDockWidgetResizeHandlePrimitive(const QStyleOption *option, QPainter *painter, const QWidget *widget) const
0318     {
0319         renderSplitter(option, painter, widget, !(option->state & State_Horizontal));
0320         return true;
0321     }
0322 
0323     bool drawIndicatorArrowPrimitive(ArrowOrientation, const QStyleOption *, QPainter *, const QWidget *) const;
0324     bool drawIndicatorHeaderArrowPrimitive(const QStyleOption *, QPainter *, const QWidget *) const;
0325     bool drawPanelButtonCommandPrimitive(const QStyleOption *, QPainter *, const QWidget *) const;
0326     bool drawPanelButtonToolPrimitive(const QStyleOption *, QPainter *, const QWidget *) const;
0327     bool drawTabBarPanelButtonToolPrimitive(const QStyleOption *, QPainter *, const QWidget *) const;
0328     bool drawPanelScrollAreaCornerPrimitive(const QStyleOption *, QPainter *, const QWidget *) const;
0329     bool drawPanelMenuPrimitive(const QStyleOption *, QPainter *, const QWidget *) const;
0330     bool drawPanelTipLabelPrimitive(const QStyleOption *, QPainter *, const QWidget *) const;
0331     bool drawPanelItemViewItemPrimitive(const QStyleOption *, QPainter *, const QWidget *) const;
0332     bool drawIndicatorMenuCheckMarkPrimitive(const QStyleOption *, QPainter *, const QWidget *) const;
0333     bool drawIndicatorCheckBoxPrimitive(const QStyleOption *, QPainter *, const QWidget *) const;
0334     bool drawIndicatorRadioButtonPrimitive(const QStyleOption *, QPainter *, const QWidget *) const;
0335     bool drawIndicatorButtonDropDownPrimitive(const QStyleOption *, QPainter *, const QWidget *) const;
0336     bool drawIndicatorTabClosePrimitive(const QStyleOption *option, QPainter *painter, const QWidget *widget) const;
0337     bool drawIndicatorTabTearPrimitive(const QStyleOption *, QPainter *, const QWidget *) const;
0338     bool drawIndicatorToolBarHandlePrimitive(const QStyleOption *, QPainter *, const QWidget *) const;
0339     bool drawIndicatorToolBarSeparatorPrimitive(const QStyleOption *, QPainter *, const QWidget *) const;
0340     bool drawIndicatorBranchPrimitive(const QStyleOption *, QPainter *, const QWidget *) const;
0341     bool drawWidgetPrimitive(const QStyleOption *, QPainter *, const QWidget *) const;
0342 
0343     //@}
0344 
0345     //*@name controls specialized functions
0346     //@{
0347 
0348     bool emptyControl(const QStyleOption *, QPainter *, const QWidget *) const
0349     {
0350         return true;
0351     }
0352 
0353     bool drawPushButtonLabelControl(const QStyleOption *, QPainter *, const QWidget *) const;
0354     bool drawToolButtonLabelControl(const QStyleOption *, QPainter *, const QWidget *) const;
0355     bool drawMenuBarItemControl(const QStyleOption *, QPainter *, const QWidget *) const;
0356     bool drawMenuItemControl(const QStyleOption *, QPainter *, const QWidget *) const;
0357     bool drawProgressBarControl(const QStyleOption *, QPainter *, const QWidget *) const;
0358     bool drawProgressBarContentsControl(const QStyleOption *, QPainter *, const QWidget *) const;
0359     bool drawProgressBarGrooveControl(const QStyleOption *, QPainter *, const QWidget *) const;
0360     bool drawProgressBarLabelControl(const QStyleOption *, QPainter *, const QWidget *) const;
0361     bool drawScrollBarSliderControl(const QStyleOption *, QPainter *, const QWidget *) const;
0362     bool drawScrollBarAddLineControl(const QStyleOption *, QPainter *, const QWidget *) const;
0363     bool drawScrollBarSubLineControl(const QStyleOption *, QPainter *, const QWidget *) const;
0364     bool drawShapedFrameControl(const QStyleOption *, QPainter *, const QWidget *) const;
0365     bool drawRubberBandControl(const QStyleOption *, QPainter *, const QWidget *) const;
0366     bool drawHeaderSectionControl(const QStyleOption *, QPainter *, const QWidget *) const;
0367     bool drawHeaderEmptyAreaControl(const QStyleOption *, QPainter *, const QWidget *) const;
0368     bool drawTabBarTabLabelControl(const QStyleOption *, QPainter *, const QWidget *) const;
0369     bool drawTabBarTabShapeControl(const QStyleOption *, QPainter *, const QWidget *) const;
0370     bool drawTabBarTabShapeControl_selected(const QStyleOption *, QPainter *, const QWidget *) const;
0371     bool drawTabBarTabShapeControl_unselected(const QStyleOption *, QPainter *, const QWidget *) const;
0372     bool drawToolBoxTabLabelControl(const QStyleOption *, QPainter *, const QWidget *) const;
0373     bool drawToolBoxTabShapeControl(const QStyleOption *, QPainter *, const QWidget *) const;
0374     bool drawDockWidgetTitleControl(const QStyleOption *, QPainter *, const QWidget *) const;
0375     bool drawToolBarControl(const QStyleOption *, QPainter *, const QWidget *) const;
0376     bool drawSplitterControl(const QStyleOption *option, QPainter *painter, const QWidget *widget) const
0377     {
0378         renderSplitter(option, painter, widget, option->state & State_Horizontal);
0379         return true;
0380     }
0381 
0382     //*@}
0383 
0384     //*@name complex ontrols specialized functions
0385     //@{
0386     bool drawToolButtonComplexControl(const QStyleOptionComplex *, QPainter *, const QWidget *) const;
0387     bool drawComboBoxComplexControl(const QStyleOptionComplex *, QPainter *, const QWidget *) const;
0388     bool drawSpinBoxComplexControl(const QStyleOptionComplex *, QPainter *, const QWidget *) const;
0389     bool drawSliderComplexControl(const QStyleOptionComplex *, QPainter *, const QWidget *) const;
0390     bool drawDialComplexControl(const QStyleOptionComplex *, QPainter *, const QWidget *) const;
0391     bool drawScrollBarComplexControl(const QStyleOptionComplex *, QPainter *, const QWidget *) const;
0392     bool drawTitleBarComplexControl(const QStyleOptionComplex *, QPainter *, const QWidget *) const;
0393     //@}
0394 
0395     //*@name internal rendering methods
0396     /** here mostly to avoid code duplication */
0397     //@{
0398 
0399     //* qdial slab
0400     void renderDialSlab(QPainter *p, const QRect &r, const QColor &c, const QStyleOption *option, StyleOptions opts = {}) const
0401     {
0402         renderDialSlab(p, r, c, option, opts, -1, AnimationNone);
0403     }
0404 
0405     //* qdial slab
0406     void renderDialSlab(QPainter *, const QRect &, const QColor &, const QStyleOption *, StyleOptions, qreal, AnimationMode) const;
0407 
0408     //* generic button slab
0409     void renderButtonSlab(QPainter *p, QRect r, const QColor &c, StyleOptions opts = {}, TileSet::Tiles tiles = TileSet::Ring) const
0410     {
0411         renderButtonSlab(p, r, c, opts, -1, AnimationNone, tiles);
0412     }
0413 
0414     //* generic button slab
0415     void renderButtonSlab(QPainter *, QRect, const QColor &, StyleOptions, qreal, AnimationMode, TileSet::Tiles) const;
0416 
0417     //* generic slab
0418     void renderSlab(QPainter *painter, const SlabRect &slab, const QColor &color, StyleOptions options = {}) const
0419     {
0420         renderSlab(painter, slab.rect, color, options, slab.tiles);
0421     }
0422 
0423     //* generic slab
0424     void renderSlab(QPainter *painter, QRect rect, const QColor &color, StyleOptions options = {}, TileSet::Tiles tiles = TileSet::Ring) const
0425     {
0426         renderSlab(painter, rect, color, options, -1, AnimationNone, tiles);
0427     }
0428 
0429     //* generic slab
0430     void renderSlab(QPainter *painter, const SlabRect &slab, const QColor &color, StyleOptions options, qreal opacity, AnimationMode mode) const
0431     {
0432         renderSlab(painter, slab.rect, color, options, opacity, mode, slab.tiles);
0433     }
0434 
0435     //* generic slab
0436     void renderSlab(QPainter *, QRect, const QColor &, StyleOptions, qreal, AnimationMode, TileSet::Tiles) const;
0437 
0438     //* tab background
0439     /** this paints window background behind tab when tab is being dragged */
0440     void fillTabBackground(QPainter *, const QRect &, const QColor &, const QWidget *) const;
0441 
0442     //* tab filling
0443     void fillTab(QPainter *, const QRect &, const QColor &, const QTabBar::Shape) const;
0444 
0445     //* spinbox arrows
0446     void renderSpinBoxArrow(QPainter *, const QStyleOptionSpinBox *, const QWidget *, const SubControl &) const;
0447 
0448     //* splitter
0449     void renderSplitter(const QStyleOption *, QPainter *, const QWidget *, bool) const;
0450 
0451     //* mdi subwindow titlebar button
0452     void renderTitleBarButton(QPainter *, const QStyleOptionTitleBar *, const QWidget *, const SubControl &) const;
0453     void renderTitleBarButton(QPainter *, const QRect &r, const QColor &, const QColor &, const SubControl &) const;
0454     void renderTitleBarIcon(QPainter *, const QRect &, const SubControl &) const;
0455 
0456     //* header background
0457     void renderHeaderBackground(const QRect &, const QPalette &, QPainter *, const QWidget *, bool horizontal, bool reverse) const;
0458     void renderHeaderLines(const QRect &, const QPalette &, QPainter *, TileSet::Tiles) const;
0459 
0460     //* menu item background
0461     void renderMenuItemBackground(const QStyleOption *, QPainter *, const QWidget *) const;
0462 
0463     void renderMenuItemRect(const QStyleOption *, const QRect &, const QColor &, const QPalette &, QPainter *p, qreal opacity = -1) const;
0464 
0465     //* checkbox state (used for checkboxes _and_ radio buttons)
0466     enum CheckBoxState { CheckOn, CheckOff, CheckTriState, CheckSunken };
0467 
0468     //* checkbox
0469     void renderCheckBox(QPainter *, const QRect &, const QPalette &, StyleOptions, CheckBoxState, qreal opacity = -1, AnimationMode mode = AnimationNone) const;
0470 
0471     //* radio button
0472     void
0473     renderRadioButton(QPainter *, const QRect &, const QPalette &, StyleOptions, CheckBoxState, qreal opacity = -1, AnimationMode mode = AnimationNone) const;
0474 
0475     //* scrollbar hole
0476     void renderScrollBarHole(QPainter *, const QRect &, const QColor &, const Qt::Orientation &, const TileSet::Tiles & = TileSet::Full) const;
0477 
0478     //* scrollbar handle (non animated)
0479     void renderScrollBarHandle(QPainter *painter, const QRect &r, const QPalette &palette, const Qt::Orientation &orientation, const bool &hover) const
0480     {
0481         renderScrollBarHandle(painter, r, palette, orientation, hover, -1);
0482     }
0483 
0484     //* scrollbar handle (animated)
0485     void renderScrollBarHandle(QPainter *, const QRect &, const QPalette &, const Qt::Orientation &, const bool &, const qreal &) const;
0486 
0487     //* scrollbar arrow
0488     void renderScrollBarArrow(QPainter *, const QRect &, const QColor &, const QColor &, ArrowOrientation) const;
0489 
0490     //* returns true if given scrollbar arrow is animated
0491     QColor scrollBarArrowColor(const QStyleOptionSlider *, const SubControl &, const QWidget *) const;
0492 
0493     //@}
0494 
0495     //**@name various utilty functions
0496     //@{
0497 
0498     //* return dial angle based on option and value
0499     qreal dialAngle(const QStyleOptionSlider *, int) const;
0500 
0501     //* polish scrollarea
0502     void polishScrollArea(QAbstractScrollArea *) const;
0503 
0504     //* toolbar mask
0505     /** this masks out toolbar expander buttons, when visible, from painting */
0506     QRegion tabBarClipRegion(const QTabBar *) const;
0507 
0508     //* returns point position for generic arrows
0509     QPolygonF genericArrow(ArrowOrientation, ArrowSize = ArrowNormal) const;
0510 
0511     //* scrollbar buttons
0512     enum ScrollBarButtonType { NoButton, SingleButton, DoubleButton };
0513 
0514     //* returns height for scrollbar buttons depending of button types
0515     int scrollBarButtonHeight(const ScrollBarButtonType &type) const
0516     {
0517         switch (type) {
0518         case NoButton:
0519             return _noButtonHeight;
0520         case SingleButton:
0521             return _singleButtonHeight;
0522         case DoubleButton:
0523             return _doubleButtonHeight;
0524         default:
0525             return 0;
0526         }
0527     }
0528 
0529     /**
0530     separator can have a title and an icon
0531     in that case they are rendered as sunken flat toolbuttons
0532     return toolbutton option that matches named separator menu items
0533     */
0534     QStyleOptionToolButton separatorMenuItemOption(const QStyleOptionMenuItem *, const QWidget *) const;
0535 
0536     //* return true if option corresponds to QtQuick control
0537     bool isQtQuickControl(const QStyleOption *, const QWidget *) const;
0538 
0539     //@}
0540 
0541     //* adjust rect based on provided margins
0542     QRect insideMargin(const QRect &r, int margin) const
0543     {
0544         return insideMargin(r, margin, margin);
0545     }
0546 
0547     //* adjust rect based on provided margins
0548     QRect insideMargin(const QRect &r, int marginWidth, int marginHeight) const
0549     {
0550         return r.adjusted(marginWidth, marginHeight, -marginWidth, -marginHeight);
0551     }
0552 
0553     //* expand size based on margins
0554     QSize expandSize(const QSize &size, int margin) const
0555     {
0556         return expandSize(size, margin, margin);
0557     }
0558 
0559     //* expand size based on margins
0560     QSize expandSize(const QSize &size, int marginWidth, int marginHeight) const
0561     {
0562         return size + 2 * QSize(marginWidth, marginHeight);
0563     }
0564 
0565     //* returns true for vertical tabs
0566     bool isVerticalTab(const QStyleOptionTab *option) const
0567     {
0568         return isVerticalTab(option->shape);
0569     }
0570 
0571     bool isVerticalTab(const QTabBar::Shape &shape) const
0572     {
0573         return shape == QTabBar::RoundedEast || shape == QTabBar::RoundedWest || shape == QTabBar::TriangularEast || shape == QTabBar::TriangularWest;
0574     }
0575 
0576     //* right to left alignment handling
0577     using KStyle::visualRect;
0578     QRect visualRect(const QStyleOption *opt, const QRect &subRect) const
0579     {
0580         return KStyle::visualRect(opt->direction, opt->rect, subRect);
0581     }
0582 
0583     //* centering
0584     QRect centerRect(const QRect &rect, const QSize &size) const
0585     {
0586         return centerRect(rect, size.width(), size.height());
0587     }
0588 
0589     QRect centerRect(const QRect &rect, int width, int height) const
0590     {
0591         return QRect(rect.left() + (rect.width() - width) / 2, rect.top() + (rect.height() - height) / 2, width, height);
0592     }
0593 
0594     /*
0595     Checks whether the point is before the bound rect for bound of given orientation.
0596     This is needed to implement custom number of buttons in scrollbars,
0597     as well as proper mouse-hover
0598     */
0599     inline bool preceeds(const QPoint &, const QRect &, const QStyleOption *) const;
0600 
0601     //* return which arrow button is hit by point for scrollbar double buttons
0602     inline QStyle::SubControl scrollBarHitTest(const QRect &, const QPoint &, const QStyleOption *) const;
0603 
0604     //* adjusted slabRect
0605     inline void adjustSlabRect(SlabRect &slab, const QRect &, bool documentMode, bool vertical) const;
0606 
0607     //* return true if one of the widget's parent inherits requested type
0608     inline bool hasParent(const QWidget *, const char *) const;
0609 
0610     //* return true if one of the widget's parent inherits requested type
0611     template<typename T>
0612     bool hasParent(const QWidget *) const;
0613 
0614     //*@name scrollbar button types (for addLine and subLine )
0615     //@{
0616     ScrollBarButtonType _addLineButtons = DoubleButton;
0617     ScrollBarButtonType _subLineButtons = SingleButton;
0618     //@}
0619 
0620     //*@name metrics for scrollbar buttons
0621     //@{
0622     int _noButtonHeight = 0;
0623     int _singleButtonHeight = 14;
0624     int _doubleButtonHeight = 28;
0625     //@}
0626 
0627     //* helper
0628     StyleHelper *_helper;
0629 
0630     //* shadow helper
0631     ShadowHelper *_shadowHelper;
0632 
0633     //* animations
0634     Animations *_animations;
0635 
0636     //* transitions
0637     Transitions *_transitions;
0638 
0639     //* window manager
0640     WindowManager *_windowManager;
0641 
0642     //* toplevel manager
0643     TopLevelManager *_topLevelManager;
0644 
0645     //* frame shadows
0646     FrameShadowFactory *_frameShadowFactory;
0647 
0648     //* mdi window shadows
0649     MdiWindowShadowFactory *_mdiWindowShadowFactory;
0650 
0651     //* keyboard accelerators
0652     Mnemonics *_mnemonics;
0653 
0654     //* blur helper
0655     BlurHelper *_blurHelper;
0656 
0657     //* widget explorer
0658     WidgetExplorer *_widgetExplorer;
0659 
0660     //* tabBar data
0661     OxygenPrivate::TabBarData *_tabBarData;
0662 
0663     //* splitter Factory, to extend splitters hit area
0664     SplitterFactory *_splitterFactory;
0665 
0666     //* pointer to primitive specialized function
0667     using StylePrimitive = bool (Style::*)(const QStyleOption *, QPainter *, const QWidget *) const;
0668     StylePrimitive _frameFocusPrimitive = nullptr;
0669 
0670     //* pointer to control specialized function
0671     using StyleControl = bool (Style::*)(const QStyleOption *, QPainter *, const QWidget *) const;
0672 
0673     //* pointer to control specialized function
0674     using StyleComplexControl = bool (Style::*)(const QStyleOptionComplex *, QPainter *, const QWidget *) const;
0675 
0676     //*@name custom elements
0677     //@{
0678 
0679     //* use Argb Drag and Drop Window
0680     QStyle::StyleHint SH_ArgbDndWindow;
0681 
0682     //* styled painting for KCapacityBar
0683     QStyle::ControlElement CE_CapacityBar;
0684 
0685     //@}
0686 
0687     //* tab close button icon (cached)
0688     mutable QIcon _tabCloseIcon;
0689 
0690     friend class OxygenPrivate::TabBarData;
0691 };
0692 
0693 //_________________________________________________________________________
0694 bool Style::preceeds(const QPoint &point, const QRect &bound, const QStyleOption *option) const
0695 {
0696     if (option->state & QStyle::State_Horizontal) {
0697         if (option->direction == Qt::LeftToRight)
0698             return point.x() < bound.right();
0699         else
0700             return point.x() > bound.x();
0701 
0702     } else
0703         return point.y() < bound.y();
0704 }
0705 
0706 //_________________________________________________________________________
0707 QStyle::SubControl Style::scrollBarHitTest(const QRect &rect, const QPoint &point, const QStyleOption *option) const
0708 {
0709     if (option->state & QStyle::State_Horizontal) {
0710         if (option->direction == Qt::LeftToRight)
0711             return point.x() < rect.center().x() ? QStyle::SC_ScrollBarSubLine : QStyle::SC_ScrollBarAddLine;
0712         else
0713             return point.x() > rect.center().x() ? QStyle::SC_ScrollBarSubLine : QStyle::SC_ScrollBarAddLine;
0714     } else
0715         return point.y() < rect.center().y() ? QStyle::SC_ScrollBarSubLine : QStyle::SC_ScrollBarAddLine;
0716 }
0717 
0718 //___________________________________________________________________________________
0719 void Style::adjustSlabRect(SlabRect &slab, const QRect &tabWidgetRect, bool documentMode, bool vertical) const
0720 {
0721     // no tabWidget found, do nothing
0722     if (documentMode || !tabWidgetRect.isValid())
0723         return;
0724     else if (vertical) {
0725         slab.rect.setTop(qMax(slab.rect.top(), tabWidgetRect.top()));
0726         slab.rect.setBottom(qMin(slab.rect.bottom(), tabWidgetRect.bottom()));
0727 
0728     } else {
0729         slab.rect.setLeft(qMax(slab.rect.left(), tabWidgetRect.left()));
0730         slab.rect.setRight(qMin(slab.rect.right(), tabWidgetRect.right()));
0731     }
0732 
0733     return;
0734 }
0735 
0736 //_________________________________________________________________________
0737 bool Style::hasParent(const QWidget *widget, const char *className) const
0738 {
0739     if (!widget)
0740         return false;
0741 
0742     while ((widget = widget->parentWidget())) {
0743         if (widget->inherits(className))
0744             return true;
0745     }
0746 
0747     return false;
0748 }
0749 
0750 //_________________________________________________________________________
0751 template<typename T>
0752 bool Style::hasParent(const QWidget *widget) const
0753 {
0754     if (!widget)
0755         return false;
0756 
0757     while ((widget = widget->parentWidget())) {
0758         if (qobject_cast<const T *>(widget))
0759             return true;
0760     }
0761 
0762     return false;
0763 }
0764 }
0765 
0766 #endif