File indexing completed on 2024-04-14 05:26:09

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