File indexing completed on 2024-05-12 13:30:25
0001 /* 0002 * SPDX-FileCopyrightText: 2014 Hugo Pereira Da Costa <hugo.pereira@free.fr> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef breezestyle_h 0008 #define breezestyle_h 0009 0010 #include "breeze.h" 0011 #include "breezehelper.h" 0012 #include "breezemetrics.h" 0013 #include "config-breeze.h" 0014 0015 #if BREEZE_HAVE_KSTYLE 0016 #include <KStyle> 0017 #endif 0018 0019 #include <QAbstractItemView> 0020 #include <QAbstractScrollArea> 0021 0022 #include <QCommandLinkButton> 0023 #include <QCommonStyle> 0024 #include <QDockWidget> 0025 #include <QFocusFrame> 0026 #include <QHash> 0027 #include <QIcon> 0028 #include <QMdiSubWindow> 0029 #include <QStyleOption> 0030 #include <QWidget> 0031 0032 #include <functional> 0033 0034 namespace BreezePrivate 0035 { 0036 class TabBarData; 0037 } 0038 0039 namespace Breeze 0040 { 0041 class Animations; 0042 class FrameShadowFactory; 0043 class Helper; 0044 class MdiWindowShadowFactory; 0045 class Mnemonics; 0046 class ShadowHelper; 0047 class SplitterFactory; 0048 class WidgetExplorer; 0049 class WindowManager; 0050 class BlurHelper; 0051 class ToolsAreaManager; 0052 0053 //* convenience typedef for base class 0054 #if !BREEZE_HAVE_KSTYLE 0055 using ParentStyleClass = QCommonStyle; 0056 #else 0057 using ParentStyleClass = KStyle; 0058 #endif 0059 0060 //* base class for breeze style 0061 /** it is responsible to draw all the primitives to be displayed on screen, on request from Qt paint engine */ 0062 class Style : public ParentStyleClass 0063 { 0064 Q_OBJECT 0065 0066 /* this tells kde applications that custom style elements are supported, using the kstyle mechanism */ 0067 Q_CLASSINFO("X-KDE-CustomElements", "true") 0068 0069 public: 0070 //* constructor 0071 explicit Style(); 0072 0073 //* destructor 0074 ~Style() override; 0075 0076 //* needed to avoid warnings at compilation time 0077 using ParentStyleClass::polish; 0078 using ParentStyleClass::unpolish; 0079 0080 //* widget polishing 0081 void polish(QWidget *) override; 0082 0083 //* widget unpolishing 0084 void unpolish(QWidget *) override; 0085 0086 //* application polishing 0087 void polish(QApplication *) override; 0088 0089 //* polish scrollarea 0090 void polishScrollArea(QAbstractScrollArea *); 0091 0092 //* pixel metrics 0093 int pixelMetric(PixelMetric, const QStyleOption * = nullptr, const QWidget * = nullptr) const override; 0094 0095 //* style hints 0096 int styleHint(StyleHint, const QStyleOption * = nullptr, const QWidget * = nullptr, QStyleHintReturn * = nullptr) const override; 0097 0098 //* returns rect corresponding to one widget's subelement 0099 QRect subElementRect(SubElement, const QStyleOption *, const QWidget *) const override; 0100 0101 //* returns rect corresponding to one widget's subcontrol 0102 QRect subControlRect(ComplexControl, const QStyleOptionComplex *, SubControl, const QWidget *) const override; 0103 0104 //* returns size matching contents 0105 QSize sizeFromContents(ContentsType, const QStyleOption *, const QSize &, const QWidget *) const override; 0106 0107 //* returns which subcontrol given QPoint corresponds to 0108 SubControl hitTestComplexControl(ComplexControl, const QStyleOptionComplex *, const QPoint &, const QWidget *) const override; 0109 0110 //* primitives 0111 void drawPrimitive(PrimitiveElement, const QStyleOption *, QPainter *, const QWidget *) const override; 0112 0113 //* controls 0114 void drawControl(ControlElement, const QStyleOption *, QPainter *, const QWidget *) const override; 0115 0116 //* complex controls 0117 void drawComplexControl(ComplexControl, const QStyleOptionComplex *, QPainter *, const QWidget *) const override; 0118 0119 //* generic text rendering 0120 void drawItemText(QPainter *, const QRect &, int alignment, const QPalette &, bool enabled, const QString &, QPalette::ColorRole = QPalette::NoRole) 0121 const override; 0122 0123 bool event(QEvent *) override; 0124 0125 //*@name event filters 0126 //@{ 0127 0128 bool eventFilter(QObject *, QEvent *) override; 0129 bool eventFilterScrollArea(QWidget *, QEvent *); 0130 bool eventFilterComboBoxContainer(QWidget *, QEvent *); 0131 bool eventFilterDockWidget(QDockWidget *, QEvent *); 0132 bool eventFilterMdiSubWindow(QMdiSubWindow *, QEvent *); 0133 bool eventFilterCommandLinkButton(QCommandLinkButton *, QEvent *); 0134 0135 //* install event filter to object, in a unique way 0136 void addEventFilter(QObject *object) 0137 { 0138 object->removeEventFilter(this); 0139 object->installEventFilter(this); 0140 } 0141 0142 //@} 0143 0144 protected Q_SLOTS: 0145 0146 //* update configuration 0147 void configurationChanged(); 0148 0149 //* global configuration changed 0150 void globalConfigurationChanged(int type, int arg); 0151 void loadGlobalAnimationSettings(); 0152 0153 //* standard icons 0154 QIcon standardIconImplementation(StandardPixmap, const QStyleOption *, const QWidget *) const; 0155 0156 protected: 0157 //* standard icons 0158 QIcon standardIcon(StandardPixmap pixmap, const QStyleOption *option = nullptr, const QWidget *widget = nullptr) const override 0159 { 0160 return standardIconImplementation(pixmap, option, widget); 0161 } 0162 0163 private: 0164 //* load configuration 0165 void loadConfiguration(); 0166 0167 bool isTabletMode() const; 0168 0169 //*@name subelementRect specialized functions 0170 //@{ 0171 0172 QRect pushButtonContentsRect(const QStyleOption *, const QWidget *) const; 0173 QRect checkBoxContentsRect(const QStyleOption *, const QWidget *) const; 0174 QRect lineEditContentsRect(const QStyleOption *, const QWidget *) const; 0175 QRect progressBarGrooveRect(const QStyleOption *, const QWidget *) const; 0176 QRect progressBarContentsRect(const QStyleOption *, const QWidget *) const; 0177 QRect progressBarLabelRect(const QStyleOption *, const QWidget *) const; 0178 QRect frameContentsRect(const QStyleOption *, const QWidget *) const; 0179 QRect headerArrowRect(const QStyleOption *, const QWidget *) const; 0180 QRect headerLabelRect(const QStyleOption *, const QWidget *) const; 0181 QRect tabBarTabLeftButtonRect(const QStyleOption *, const QWidget *) const; 0182 QRect tabBarTabRightButtonRect(const QStyleOption *, const QWidget *) const; 0183 QRect tabWidgetTabBarRect(const QStyleOption *, const QWidget *) const; 0184 QRect tabWidgetTabContentsRect(const QStyleOption *, const QWidget *) const; 0185 QRect tabWidgetTabPaneRect(const QStyleOption *, const QWidget *) const; 0186 QRect tabWidgetCornerRect(SubElement, const QStyleOption *, const QWidget *widget) const; 0187 QRect toolBoxTabContentsRect(const QStyleOption *, const QWidget *) const; 0188 QRect genericLayoutItemRect(const QStyleOption *, const QWidget *) const; 0189 0190 //@} 0191 0192 //*@name subcontrol Rect specialized functions 0193 //@{ 0194 0195 QRect groupBoxSubControlRect(const QStyleOptionComplex *, SubControl, const QWidget *) const; 0196 QRect toolButtonSubControlRect(const QStyleOptionComplex *, SubControl, const QWidget *) const; 0197 QRect comboBoxSubControlRect(const QStyleOptionComplex *, SubControl, const QWidget *) const; 0198 QRect spinBoxSubControlRect(const QStyleOptionComplex *, SubControl, const QWidget *) const; 0199 QRect scrollBarInternalSubControlRect(const QStyleOptionComplex *, SubControl) const; 0200 QRect scrollBarSubControlRect(const QStyleOptionComplex *, SubControl, const QWidget *) const; 0201 QRect dialSubControlRect(const QStyleOptionComplex *, SubControl, const QWidget *) const; 0202 QRect sliderSubControlRect(const QStyleOptionComplex *, SubControl, const QWidget *) const; 0203 0204 //@} 0205 0206 //*@name sizeFromContents 0207 //@{ 0208 QSize defaultSizeFromContents(const QStyleOption *, const QSize &size, const QWidget *) const 0209 { 0210 return size; 0211 } 0212 0213 QSize checkBoxSizeFromContents(const QStyleOption *, const QSize &, const QWidget *) const; 0214 QSize lineEditSizeFromContents(const QStyleOption *, const QSize &, const QWidget *) const; 0215 QSize comboBoxSizeFromContents(const QStyleOption *, const QSize &, const QWidget *) const; 0216 QSize spinBoxSizeFromContents(const QStyleOption *, const QSize &, const QWidget *) const; 0217 QSize sliderSizeFromContents(const QStyleOption *, const QSize &, const QWidget *) const; 0218 QSize pushButtonSizeFromContents(const QStyleOption *, const QSize &, const QWidget *) const; 0219 QSize toolButtonSizeFromContents(const QStyleOption *, const QSize &, const QWidget *) const; 0220 QSize menuBarItemSizeFromContents(const QStyleOption *, const QSize &, const QWidget *) const; 0221 QSize menuItemSizeFromContents(const QStyleOption *, const QSize &, const QWidget *) const; 0222 QSize progressBarSizeFromContents(const QStyleOption *, const QSize &, const QWidget *) const; 0223 QSize tabWidgetSizeFromContents(const QStyleOption *, const QSize &, const QWidget *) const; 0224 QSize tabBarTabSizeFromContents(const QStyleOption *, const QSize &, const QWidget *) const; 0225 QSize headerSectionSizeFromContents(const QStyleOption *, const QSize &, const QWidget *) const; 0226 QSize itemViewItemSizeFromContents(const QStyleOption *, const QSize &, const QWidget *) const; 0227 0228 //@} 0229 0230 //*@name primitives specialized functions 0231 //@{ 0232 0233 bool emptyPrimitive(const QStyleOption *, QPainter *, const QWidget *) const 0234 { 0235 return true; 0236 } 0237 0238 bool drawFramePrimitive(const QStyleOption *, QPainter *, const QWidget *) const; 0239 bool drawFrameLineEditPrimitive(const QStyleOption *, QPainter *, const QWidget *) const; 0240 bool drawFrameFocusRectPrimitive(const QStyleOption *, QPainter *, const QWidget *) const; 0241 bool drawFrameMenuPrimitive(const QStyleOption *, QPainter *, const QWidget *) const; 0242 bool drawFrameGroupBoxPrimitive(const QStyleOption *, QPainter *, const QWidget *) const; 0243 bool drawFrameTabWidgetPrimitive(const QStyleOption *, QPainter *, const QWidget *) const; 0244 bool drawFrameTabBarBasePrimitive(const QStyleOption *, QPainter *, const QWidget *) const; 0245 bool drawFrameWindowPrimitive(const QStyleOption *, QPainter *, const QWidget *) const; 0246 0247 bool drawIndicatorArrowUpPrimitive(const QStyleOption *option, QPainter *painter, const QWidget *widget) const 0248 { 0249 return drawIndicatorArrowPrimitive(ArrowUp, option, painter, widget); 0250 } 0251 0252 bool drawIndicatorArrowDownPrimitive(const QStyleOption *option, QPainter *painter, const QWidget *widget) const 0253 { 0254 return drawIndicatorArrowPrimitive(ArrowDown, option, painter, widget); 0255 } 0256 0257 bool drawIndicatorArrowLeftPrimitive(const QStyleOption *option, QPainter *painter, const QWidget *widget) const 0258 { 0259 return drawIndicatorArrowPrimitive(ArrowLeft, option, painter, widget); 0260 } 0261 0262 bool drawIndicatorArrowRightPrimitive(const QStyleOption *option, QPainter *painter, const QWidget *widget) const 0263 { 0264 return drawIndicatorArrowPrimitive(ArrowRight, option, painter, widget); 0265 } 0266 0267 bool drawIndicatorArrowPrimitive(ArrowOrientation, const QStyleOption *, QPainter *, const QWidget *) const; 0268 bool drawIndicatorHeaderArrowPrimitive(const QStyleOption *, QPainter *, const QWidget *) const; 0269 bool drawPanelButtonCommandPrimitive(const QStyleOption *, QPainter *, const QWidget *) const; 0270 bool drawPanelButtonToolPrimitive(const QStyleOption *, QPainter *, const QWidget *) const; 0271 bool drawTabBarPanelButtonToolPrimitive(const QStyleOption *, QPainter *, const QWidget *) const; 0272 bool drawPanelScrollAreaCornerPrimitive(const QStyleOption *, QPainter *, const QWidget *) const; 0273 bool drawPanelMenuPrimitive(const QStyleOption *, QPainter *, const QWidget *) const; 0274 bool drawPanelTipLabelPrimitive(const QStyleOption *, QPainter *, const QWidget *) const; 0275 bool drawPanelItemViewItemPrimitive(const QStyleOption *, QPainter *, const QWidget *) const; 0276 bool drawIndicatorCheckBoxPrimitive(const QStyleOption *, QPainter *, const QWidget *) const; 0277 bool drawIndicatorRadioButtonPrimitive(const QStyleOption *, QPainter *, const QWidget *) const; 0278 bool drawIndicatorButtonDropDownPrimitive(const QStyleOption *, QPainter *, const QWidget *) const; 0279 bool drawIndicatorTabClosePrimitive(const QStyleOption *, QPainter *painter, const QWidget *widget) const; 0280 bool drawIndicatorTabTearPrimitive(const QStyleOption *, QPainter *, const QWidget *) const; 0281 bool drawIndicatorToolBarHandlePrimitive(const QStyleOption *, QPainter *, const QWidget *) const; 0282 bool drawIndicatorToolBarSeparatorPrimitive(const QStyleOption *, QPainter *, const QWidget *) const; 0283 bool drawIndicatorBranchPrimitive(const QStyleOption *, QPainter *, const QWidget *) const; 0284 bool drawWidgetPrimitive(const QStyleOption *, QPainter *, const QWidget *) const; 0285 0286 //@} 0287 0288 //*@name controls specialized functions 0289 //@{ 0290 0291 bool emptyControl(const QStyleOption *, QPainter *, const QWidget *) const 0292 { 0293 return true; 0294 } 0295 0296 bool drawPushButtonLabelControl(const QStyleOption *, QPainter *, const QWidget *) const; 0297 bool drawToolButtonLabelControl(const QStyleOption *, QPainter *, const QWidget *) const; 0298 bool drawCheckBoxLabelControl(const QStyleOption *, QPainter *, const QWidget *) const; 0299 bool drawComboBoxLabelControl(const QStyleOption *, QPainter *, const QWidget *) const; 0300 bool drawMenuBarItemControl(const QStyleOption *, QPainter *, const QWidget *) const; 0301 bool drawMenuItemControl(const QStyleOption *, QPainter *, const QWidget *) const; 0302 bool drawProgressBarControl(const QStyleOption *, QPainter *, const QWidget *) const; 0303 bool drawProgressBarContentsControl(const QStyleOption *, QPainter *, const QWidget *) const; 0304 bool drawProgressBarGrooveControl(const QStyleOption *, QPainter *, const QWidget *) const; 0305 bool drawProgressBarLabelControl(const QStyleOption *, QPainter *, const QWidget *) const; 0306 bool drawScrollBarSliderControl(const QStyleOption *, QPainter *, const QWidget *) const; 0307 bool drawScrollBarAddLineControl(const QStyleOption *, QPainter *, const QWidget *) const; 0308 bool drawScrollBarSubLineControl(const QStyleOption *, QPainter *, const QWidget *) const; 0309 bool drawShapedFrameControl(const QStyleOption *, QPainter *, const QWidget *) const; 0310 bool drawFocusFrame(const QStyleOption *, QPainter *, const QWidget *) const; 0311 bool drawRubberBandControl(const QStyleOption *, QPainter *, const QWidget *) const; 0312 bool drawHeaderSectionControl(const QStyleOption *, QPainter *, const QWidget *) const; 0313 bool drawHeaderEmptyAreaControl(const QStyleOption *, QPainter *, const QWidget *) const; 0314 bool drawTabBarTabLabelControl(const QStyleOption *, QPainter *, const QWidget *) const; 0315 bool drawTabBarTabShapeControl(const QStyleOption *, QPainter *, const QWidget *) const; 0316 bool drawToolBoxTabLabelControl(const QStyleOption *, QPainter *, const QWidget *) const; 0317 bool drawToolBoxTabShapeControl(const QStyleOption *, QPainter *, const QWidget *) const; 0318 bool drawDockWidgetTitleControl(const QStyleOption *, QPainter *, const QWidget *) const; 0319 0320 //*@} 0321 0322 //*@name complex ontrols specialized functions 0323 //@{ 0324 bool drawGroupBoxComplexControl(const QStyleOptionComplex *, QPainter *, const QWidget *) const; 0325 bool drawToolButtonComplexControl(const QStyleOptionComplex *, QPainter *, const QWidget *) const; 0326 bool drawComboBoxComplexControl(const QStyleOptionComplex *, QPainter *, const QWidget *) const; 0327 bool drawSpinBoxComplexControl(const QStyleOptionComplex *, QPainter *, const QWidget *) const; 0328 bool drawSliderComplexControl(const QStyleOptionComplex *, QPainter *, const QWidget *) const; 0329 bool drawDialComplexControl(const QStyleOptionComplex *, QPainter *, const QWidget *) const; 0330 bool drawScrollBarComplexControl(const QStyleOptionComplex *, QPainter *, const QWidget *) const; 0331 bool drawTitleBarComplexControl(const QStyleOptionComplex *, QPainter *, const QWidget *) const; 0332 //@} 0333 0334 //!*@name various utility functions 0335 //@{ 0336 0337 //* spinbox arrows 0338 void renderSpinBoxArrow(const SubControl &, const QStyleOptionSpinBox *, QPainter *, const QWidget *) const; 0339 0340 //* return dial angle based on option and value 0341 qreal dialAngle(const QStyleOptionSlider *, int) const; 0342 0343 //* returns relevant scrollbar parent 0344 /** needed to detect parent focus */ 0345 const QWidget *scrollBarParent(const QWidget *) const; 0346 0347 //* returns true if given scrollbar arrow is animated 0348 QColor scrollBarArrowColor(const QStyleOptionSlider *, const SubControl &, const QWidget *) const; 0349 0350 //* scrollbar buttons 0351 enum ScrollBarButtonType { 0352 NoButton, 0353 SingleButton, 0354 DoubleButton, 0355 }; 0356 0357 //* returns height for scrollbar buttons depending of button types 0358 int scrollBarButtonHeight(const ScrollBarButtonType &type) const 0359 { 0360 switch (type) { 0361 case NoButton: 0362 return Metrics::ScrollBar_NoButtonHeight; 0363 case SingleButton: 0364 return Metrics::ScrollBar_SingleButtonHeight; 0365 case DoubleButton: 0366 return Metrics::ScrollBar_DoubleButtonHeight; 0367 default: 0368 return 0; 0369 } 0370 } 0371 0372 //@} 0373 0374 //* translucent background 0375 void setTranslucentBackground(QWidget *) const; 0376 0377 //* create toolbar extension icon 0378 QIcon toolBarExtensionIcon(StandardPixmap, const QStyleOption *, const QWidget *) const; 0379 0380 //* create title bar button icon 0381 QIcon titleBarButtonIcon(StandardPixmap, const QStyleOption *, const QWidget *) const; 0382 0383 //* return true if option corresponds to QtQuick control 0384 bool isQtQuickControl(const QStyleOption *, const QWidget *) const; 0385 0386 //@} 0387 0388 //* adjust rect based on provided margins 0389 QRect insideMargin(const QRect &r, int margin) const 0390 { 0391 return insideMargin(r, margin, margin); 0392 } 0393 0394 //* adjust rect based on provided margins 0395 QRect insideMargin(const QRect &r, int marginWidth, int marginHeight) const 0396 { 0397 return r.adjusted(marginWidth, marginHeight, -marginWidth, -marginHeight); 0398 } 0399 0400 //* expand size based on margins 0401 QSize expandSize(const QSize &size, int margin) const 0402 { 0403 return expandSize(size, margin, margin); 0404 } 0405 0406 //* expand size based on margins 0407 QSize expandSize(const QSize &size, int marginWidth, int marginHeight) const 0408 { 0409 return size + 2 * QSize(marginWidth, marginHeight); 0410 } 0411 0412 //* returns true for vertical tabs 0413 bool isVerticalTab(const QStyleOptionTab *option) const 0414 { 0415 return isVerticalTab(option->shape); 0416 } 0417 0418 bool isVerticalTab(const QTabBar::Shape &shape) const 0419 { 0420 return shape == QTabBar::RoundedEast || shape == QTabBar::RoundedWest || shape == QTabBar::TriangularEast || shape == QTabBar::TriangularWest; 0421 } 0422 0423 //* right to left alignment handling 0424 using ParentStyleClass::visualRect; 0425 QRect visualRect(const QStyleOption *opt, const QRect &subRect) const 0426 { 0427 return ParentStyleClass::visualRect(opt->direction, opt->rect, subRect); 0428 } 0429 0430 //* centering 0431 QRect centerRect(const QRect &rect, const QSize &size) const 0432 { 0433 return centerRect(rect, size.width(), size.height()); 0434 } 0435 0436 QRect centerRect(const QRect &rect, int width, int height) const 0437 { 0438 return QRect(rect.left() + (rect.width() - width) / 2, rect.top() + (rect.height() - height) / 2, width, height); 0439 } 0440 0441 /* 0442 Checks whether the point is before the bound rect for bound of given orientation. 0443 This is needed to implement custom number of buttons in scrollbars, 0444 as well as proper mouse-hover 0445 */ 0446 inline bool preceeds(const QPoint &, const QRect &, const QStyleOption *) const; 0447 0448 //* return which arrow button is hit by point for scrollbar double buttons 0449 inline QStyle::SubControl scrollBarHitTest(const QRect &, const QPoint &, const QStyleOption *) const; 0450 0451 //! return true if one of the widget's parent inherits requested type 0452 inline bool hasParent(const QWidget *, const char *) const; 0453 0454 //* return true if icons should be shown in menus 0455 bool showIconsInMenuItems() const; 0456 0457 //* return true if icons should be shown on buttons 0458 bool showIconsOnPushButtons() const; 0459 0460 //* return true if passed widget is a menu title (KMenu::addTitle) 0461 bool hasAlteredBackground(const QWidget *) const; 0462 0463 /* 0464 * return true if the widget should be highlighted with neutral color 0465 * if widget is null, check for the styleObject in option 0466 * return false if the widget has the mouse hover or is focused. 0467 */ 0468 bool hasHighlightNeutral(const QObject *widget, const QStyleOption *option, bool mouseOver = false, bool focus = false) const; 0469 0470 //*@name scrollbar button types (for addLine and subLine ) 0471 //@{ 0472 ScrollBarButtonType _addLineButtons = SingleButton; 0473 ScrollBarButtonType _subLineButtons = SingleButton; 0474 //@} 0475 0476 //* focus frame 0477 QPointer<QFocusFrame> _focusFrame = nullptr; 0478 0479 //* helper 0480 Helper *_helper = nullptr; 0481 0482 //* shadow helper 0483 ShadowHelper *_shadowHelper = nullptr; 0484 0485 //* animations 0486 Animations *_animations = nullptr; 0487 0488 //* keyboard accelerators 0489 Mnemonics *_mnemonics = nullptr; 0490 0491 //* blur helper 0492 BlurHelper *_blurHelper = nullptr; 0493 0494 //* window manager 0495 WindowManager *_windowManager = nullptr; 0496 0497 //* frame shadows 0498 FrameShadowFactory *_frameShadowFactory = nullptr; 0499 0500 //* mdi window shadows 0501 MdiWindowShadowFactory *_mdiWindowShadowFactory = nullptr; 0502 0503 //* splitter Factory, to extend splitters hit area 0504 SplitterFactory *_splitterFactory = nullptr; 0505 0506 //* signal manager for the tools area 0507 ToolsAreaManager *_toolsAreaManager = nullptr; 0508 0509 //* widget explorer 0510 WidgetExplorer *_widgetExplorer = nullptr; 0511 0512 //* tabbar data 0513 BreezePrivate::TabBarData *_tabBarData = nullptr; 0514 0515 //* icon hash 0516 using IconCache = QHash<StandardPixmap, QIcon>; 0517 IconCache _iconCache; 0518 0519 //* pointer to primitive specialized function 0520 using StylePrimitive = std::function<bool(const Style &, const QStyleOption *, QPainter *, const QWidget *)>; 0521 StylePrimitive _frameFocusPrimitive; 0522 0523 //* pointer to control specialized function 0524 using StyleControl = std::function<bool(const Style &, const QStyleOption *, QPainter *, const QWidget *)>; 0525 0526 //* pointer to control specialized function 0527 using StyleComplexControl = std::function<bool(const Style &, const QStyleOptionComplex *, QPainter *, const QWidget *)>; 0528 0529 //*@name custom elements 0530 //@{ 0531 0532 //* use Argb Drag and Drop Window 0533 QStyle::StyleHint SH_ArgbDndWindow; 0534 0535 //! styled painting for KCapacityBar 0536 QStyle::ControlElement CE_CapacityBar; 0537 0538 //@} 0539 }; 0540 0541 //_________________________________________________________________________ 0542 bool Style::preceeds(const QPoint &point, const QRect &bound, const QStyleOption *option) const 0543 { 0544 if (option->state & QStyle::State_Horizontal) { 0545 if (option->direction == Qt::LeftToRight) { 0546 return point.x() < bound.right(); 0547 } else { 0548 return point.x() > bound.x(); 0549 } 0550 0551 } else { 0552 return point.y() < bound.y(); 0553 } 0554 } 0555 0556 //_________________________________________________________________________ 0557 QStyle::SubControl Style::scrollBarHitTest(const QRect &rect, const QPoint &point, const QStyleOption *option) const 0558 { 0559 if (option->state & QStyle::State_Horizontal) { 0560 if (option->direction == Qt::LeftToRight) { 0561 return point.x() < rect.center().x() ? QStyle::SC_ScrollBarSubLine : QStyle::SC_ScrollBarAddLine; 0562 } else { 0563 return point.x() > rect.center().x() ? QStyle::SC_ScrollBarSubLine : QStyle::SC_ScrollBarAddLine; 0564 } 0565 0566 } else { 0567 return point.y() < rect.center().y() ? QStyle::SC_ScrollBarSubLine : QStyle::SC_ScrollBarAddLine; 0568 } 0569 } 0570 0571 //_________________________________________________________________________ 0572 bool Style::hasParent(const QWidget *widget, const char *className) const 0573 { 0574 if (!widget) { 0575 return false; 0576 } 0577 0578 while ((widget = widget->parentWidget())) { 0579 if (widget->inherits(className)) { 0580 return true; 0581 } 0582 } 0583 0584 return false; 0585 } 0586 } 0587 0588 #endif