DtkWidget
DTK Widget module
载入中...
搜索中...
未找到
dstyle.h
浏览该文件的文档.
1// SPDX-FileCopyrightText: 2019 - 2022 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: LGPL-3.0-or-later
4
5#ifndef DSTYLE_H
6#define DSTYLE_H
7
8#include <dtkwidget_global.h>
9#include <DPalette>
10#include <DDciIcon>
11#include <DGuiApplicationHelper>
12
13#include <QCommonStyle>
14#include <QPainter>
15#include <QIconEngine>
16#include <QStyleOption>
17#include <QApplication>
18
19QT_BEGIN_NAMESPACE
20class QTextLayout;
21QT_END_NAMESPACE
22
23#define ENABLE_ANIMATIONS DGuiApplicationHelper::testAttribute(DGuiApplicationHelper::HasAnimations)
24#define ENABLE_ANIMATION_BUTTONBOX (!qEnvironmentVariableIsSet("DTK_DISABLE_ANIMATION_BUTTONBOX"))
25#define ENABLE_ANIMATION_MESSAGE (!qEnvironmentVariableIsSet("DTK_DISABLE_ANIMATION_MESSAGE"))
26#define ENABLE_ANIMATION_LISTVIEWBOUNCE (!qEnvironmentVariableIsSet("DTK_DISABLE_ANIMATION_LISTVIREBOUNCE"))
27#define ENABLE_ANIMATION_SEARCH (!qEnvironmentVariableIsSet("DTK_DISABLE_ANIMATION_SEARCH"))
28#define ENABLE_ANIMATION_SWITCHBUTTON (!qEnvironmentVariableIsSet("DTK_DISABLE_ANIMATION_SWITCHBUTTON"))
29#define ENABLE_ANIMATION_PROGRESSBAR (!qEnvironmentVariableIsSet("DTK_DISABLE_ANIMATION_PROGRESSBAR"))
30#define ENABLE_ANIMATION_RADIOBUTTON (!qEnvironmentVariableIsSet("DTK_DISABLE_ANIMATION_RADIOBUTTON"))
31#define ENABLE_ANIMATION_CHECKBOX (!qEnvironmentVariableIsSet("DTK_DISABLE_ANIMATION_CHECKBOX"))
32
33DWIDGET_BEGIN_NAMESPACE
34DGUI_USE_NAMESPACE
35
36namespace DDrawUtils
37{
38enum Corner {
39 TopLeftCorner = 0x00001,
40 TopRightCorner = 0x00002,
41 BottomLeftCorner = 0x00004,
42 BottomRightCorner = 0x00008
43};
44Q_DECLARE_FLAGS(Corners, Corner)
45
46void drawShadow(QPainter *pa, const QRect &rect, qreal xRadius, qreal yRadius, const QColor &sc, qreal radius, const QPoint &offset);
47void drawShadow(QPainter *pa, const QRect &rect, const QPainterPath &path, const QColor &sc, int radius, const QPoint &offset);
48void drawRoundedRect(QPainter *pa, const QRect &rect, qreal xRadius, qreal yRadius, Corners corners, Qt::SizeMode mode = Qt::AbsoluteSize);
49void drawFork(QPainter *pa, const QRectF &rect, const QColor &color, int width = 2);
50void drawMark(QPainter *pa, const QRectF &rect, const QColor &boxInside, const QColor &boxOutside, const int penWidth, const int outLineLeng = 2);
51void drawBorder(QPainter *pa, const QRectF &rect, const QBrush &brush, int borderWidth, int radius);
52void drawArrow(QPainter *pa, const QRectF &rect, const QColor &color, Qt::ArrowType arrow, int width = 2);
53void drawPlus(QPainter *painter, const QRectF &rect, const QColor &color , qreal width);
54void drawSubtract(QPainter *painter, const QRectF &rect, const QColor &color, qreal width);
55
56void drawForkElement(QPainter *pa, const QRectF &rect);
57void drawArrowElement(Qt::ArrowType arrow, QPainter *pa, const QRectF &rect);
58void drawDecreaseElement(QPainter *pa, const QRectF &rect);
59void drawIncreaseElement(QPainter *pa, const QRectF &rect);
60void drawMarkElement(QPainter *pa, const QRectF &rect);
61void drawSelectElement(QPainter *pa, const QRectF &rect);
62void drawEditElement(QPainter *pa, const QRectF &rect);
63void drawExpandElement(QPainter *pa, const QRectF &rect);
64void drawReduceElement(QPainter *pa, const QRectF &rect);
65void drawLockElement(QPainter *pa, const QRectF &rect);
66void drawUnlockElement(QPainter *pa, const QRectF &rect);
67void drawMediaVolumeElement(QPainter *pa, const QRectF &rect);
68void drawMediaVolumeFullElement(QPainter *pa, const QRectF &rect);
69void drawMediaVolumeMutedElement(QPainter *pa, const QRectF &rect);
70void drawMediaVolumeLeftElement(QPainter *pa, const QRectF &rect);
71void drawMediaVolumeRightElement(QPainter *pa, const QRectF &rect);
72void drawArrowEnter(QPainter *pa, const QRectF &rect);
73void drawArrowLeave(QPainter *pa, const QRectF &rect);
74void drawArrowNext(QPainter *pa, const QRectF &rect);
75void drawArrowPrev(QPainter *pa, const QRectF &rect);
76void drawShowPassword(QPainter *pa, const QRectF &rect);
77void drawHidePassword(QPainter *pa, const QRectF &rect);
78void drawCloseButton(QPainter *pa, const QRectF &rect);
79void drawIndicatorMajuscule(QPainter *pa, const QRectF &rect);
80void drawIndicatorUnchecked(QPainter *pa, const QRectF &rect);
81void drawIndicatorChecked(QPainter *pa, const QRectF &rect);
82void drawDeleteButton(QPainter *pa, const QRectF &rect);
83void drawAddButton(QPainter *pa, const QRectF &rect);
84
85void drawTitleBarIcon(QPainter *pa, const QRectF &rect, const QString &iconName);
86void drawTitleBarMenuButton(QPainter *pa, const QRectF &rect);
87void drawTitleBarMinButton(QPainter *pa, const QRectF &rect);
88void drawTitleBarMaxButton(QPainter *pa, const QRectF &rect);
89void drawTitleBarCloseButton(QPainter *pa, const QRectF &rect);
90void drawTitleBarNormalButton(QPainter *pa, const QRectF &rect);
91void drawTitleQuitFullButton(QPainter *pa, const QRectF &rect);
92void drawArrowUp(QPainter *pa, const QRectF &rect);
93void drawArrowDown(QPainter *pa, const QRectF &rect);
94void drawArrowLeft(QPainter *pa, const QRectF &rect);
95void drawArrowRight(QPainter *pa, const QRectF &rect);
96void drawArrowBack(QPainter *pa, const QRectF &rect);
97void drawArrowForward(QPainter *pa, const QRectF &rect);
98void drawLineEditClearButton(QPainter *pa, const QRectF &rect);
99
100Q_DECLARE_OPERATORS_FOR_FLAGS(Corners)
101}
102
103class DViewItemAction;
104class DStyle : public QCommonStyle
105{
106 Q_OBJECT
107
108public:
110 PE_ItemBackground = QStyle::PE_CustomBase + 1, //列表项的背景色
111 PE_IconButtonPanel,
112 PE_IconButtonIcon,
113 PE_Icon,
114 PE_SwitchButtonGroove,
115 PE_SwitchButtonHandle,
116 PE_FloatingWidget,
117 PE_CustomBase = QStyle::PE_CustomBase + 0xf00000
118 };
119
120 enum ControlElement {
121 CE_IconButton = QStyle::CE_CustomBase + 1,
122 CE_SwitchButton,
123 CE_FloatingWidget,
124 CE_ButtonBoxButton,
125 CE_ButtonBoxButtonBevel,
126 CE_ButtonBoxButtonLabel,
127 CE_TextButton,
128 CE_CustomBase = QStyle::CE_CustomBase + 0xf00000
129 };
130
132 PM_FocusBorderWidth = QStyle::PM_CustomBase + 1, //控件焦点状态的边框宽度
133 PM_FocusBorderSpacing, //控件内容和border之间的间隔
134 PM_FrameRadius, //控件的圆角大小
135 PM_ShadowRadius, //控件阴影效果的半径
136 PM_ShadowHOffset, //阴影在水平方向的偏移
137 PM_ShadowVOffset, //阴影在竖直方向的偏移
138 PM_FrameMargins, //控件的margins区域,控件内容 = 控件大小 - FrameMargins
139 PM_IconButtonIconSize,
140 PM_TopLevelWindowRadius, //窗口的圆角大小
141 PM_SwitchButtonHandleWidth,
142 PM_SwithcButtonHandleHeight,
143 PM_FloatingWidgetRadius, //(基类)的圆角半径:控件内容-Radius < 控件内容 < 控件显示大小
144 PM_FloatingWidgetShadowRadius, //(基类)的阴影Radius区域:控件内容 < 控件内容+阴影margins < 控件内容+阴影margins+阴影Radius = 控件显示大小
145 PM_FloatingWidgetShadowMargins, //(基类)阴影的宽度 = 控件显示大小 - 阴影Radius - 控件内容
146 PM_FloatingWidgetShadowHOffset, //(基类)的阴影水平偏移
147 PM_FloatingWidgetShadowVOffset, //(基类)的阴影竖直偏移
148 PM_ContentsMargins, //内容的边距(一般只用于左右边距)
149 PM_ContentsSpacing, //内容的间距(可用于列表项中每一项的距离)
150 PM_ButtonMinimizedSize, //按钮控件的最小大小
151 PM_ToolTipLabelWidth, // Maximum width that a ToolTip label can reach
152 PM_FloatingButtonFrameMargin, // Frame margin that a floatingbutton has
153 PM_CustomBase = QStyle::PM_CustomBase + 0xf00000
154 };
155
156 enum SubElement {
157 SE_IconButtonIcon = QStyle::SE_CustomBase + 1,
158 SE_SwitchButtonGroove,
159 SE_SwitchButtonHandle,
160 SE_FloatingWidget,
161 SE_ButtonBoxButtonContents,
162 SE_ButtonBoxButtonFocusRect,
163 SE_CustomBase = QStyle::SE_CustomBase + 0xf00000
164 };
165
166 enum ContentsType {
167 CT_IconButton = QStyle::CT_CustomBase + 1,
168 CT_SwitchButton,
169 CT_FloatingWidget,
170 CT_ButtonBoxButton,
171 CT_CustomBase = QStyle::CT_CustomBase + 0xf00000
172 };
173
175 SS_NormalState = 0x00000000,
176 SS_HoverState = 0x00000001,
177 SS_PressState = 0x00000002,
178 SS_StateCustomBase = 0x000000f0,
179
180 StyleState_Mask = 0x000000ff,
181 SS_CheckedFlag = 0x00000100,
182 SS_SelectedFlag = 0x00000200,
183 SS_FocusFlag = 0x00000400,
184 SS_FlagCustomBase = 0xf00000
185 };
186 Q_DECLARE_FLAGS(StateFlags, StyleState)
187
189 SP_ForkElement = QStyle::SP_CustomBase + 1,
190 SP_DecreaseElement, //减少(-)
191 SP_IncreaseElement, //增加(+)
192 SP_MarkElement, //对勾
193 SP_SelectElement, //选择(...)
194 SP_EditElement, //编辑
195 SP_ExpandElement, //展开
196 SP_ReduceElement, //收缩
197 SP_LockElement, //锁定
198 SP_UnlockElement, //解锁
199 SP_MediaVolumeLowElement, //音量
200 SP_MediaVolumeHighElement, //满音量
201 SP_MediaVolumeMutedElement, //静音
202 SP_MediaVolumeLeftElement, //左声道
203 SP_MediaVolumeRightElement, //右声道
204 SP_ArrowEnter, //进入
205 SP_ArrowLeave, //离开
206 SP_ArrowNext, //下一页
207 SP_ArrowPrev, //上一页
208 SP_ShowPassword, //显示密码
209 SP_HidePassword, //因此密码
210 SP_CloseButton, //关闭按钮(X)
211 SP_IndicatorMajuscule, //大写标识
212 SP_IndicatorSearch, //搜索标识(放大镜)
213 SP_IndicatorUnchecked, //搜索标识(对应对勾的选中状态)
214 SP_IndicatorChecked, //搜索标识(对勾)
215 SP_DeleteButton, //删除按钮
216 SP_AddButton, //新增按钮
217 SP_TitleQuitFullButton, //标题栏(「」)
218 SP_TitleMoreButton, //标题栏 "更多" 按钮
219
220 SP_Title_SS_LeftButton, //标题栏左分屏按钮
221 SP_Title_SS_RightButton, //标题栏右分屏按钮
222 SP_Title_SS_ShowMaximizeButton, //标题栏最大化分屏按钮
223 SP_Title_SS_ShowNormalButton, //标题栏还原分屏按钮
224 SP_CustomBase = QStyle::SP_CustomBase + 0xf00000
225 };
226
227 static QColor adjustColor(const QColor &base,
228 qint8 hueFloat = 0, qint8 saturationFloat = 0, qint8 lightnessFloat = 0,
229 qint8 redFloat = 0, qint8 greenFloat = 0, qint8 blueFloat = 0, qint8 alphaFloat = 0);
230 static QColor blendColor(const QColor &substrate, const QColor &superstratum);
231 static QPair<QIcon::Mode, QIcon::State> toIconModeState(const QStyleOption *option);
232 static DDciIcon::Mode toDciIconMode(const QStyleOption *option);
233#if DTK_VERSION < DTK_VERSION_CHECK(6, 0, 0, 0)
234 D_DECL_DEPRECATED_X("Use DToolTip::setToolTipTextFormat(Qt::TextFormat format)") static void setTooltipTextFormat(Qt::TextFormat format);
235 D_DECL_DEPRECATED_X("Use DToolTip::toolTipTextFormat()") static Qt::TextFormat tooltipTextFormat();
236#endif
237 static DStyle::StyleState getState(const QStyleOption *option);
238 static void setFocusRectVisible(QWidget *widget, bool visible);
239 static void setFrameRadius(QWidget *widget, int radius);
240 static void setUncheckedItemIndicatorVisible(QWidget *widget, bool visible);
241 static void setRedPointVisible(QObject *object, bool visible);
242
243 static void setShortcutUnderlineVisible(bool visible);
244 static bool shortcutUnderlineVisible();
245 static void setMenuKeyboardSearchDisabled(bool disabled);
246 static bool isMenuKeyboardSearchDisabled();
247
248 DStyle();
249
250 static void drawPrimitive(const QStyle *style, DStyle::PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w = nullptr);
251 static void drawControl(const QStyle *style, DStyle::ControlElement ce, const QStyleOption *opt, QPainter *p, const QWidget *w = nullptr);
252 static int pixelMetric(const QStyle *style, DStyle::PixelMetric m, const QStyleOption *opt = nullptr, const QWidget *widget = nullptr);
253 static QRect subElementRect(const QStyle *style, DStyle::SubElement r, const QStyleOption *opt, const QWidget *widget = nullptr);
254 static QSize sizeFromContents(const QStyle *style, DStyle::ContentsType ct, const QStyleOption *opt, const QSize &contentsSize, const QWidget *widget = nullptr);
255 static QIcon standardIcon(const QStyle *style, StandardPixmap st, const QStyleOption *opt = nullptr, const QWidget *widget = 0);
256
257 inline void drawPrimitive(DStyle::PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w = nullptr) const
258 { proxy()->drawPrimitive(static_cast<QStyle::PrimitiveElement>(pe), opt, p, w); }
259 inline void drawControl(DStyle::ControlElement ce, const QStyleOption *opt, QPainter *p, const QWidget *w = nullptr) const
260 { proxy()->drawControl(static_cast<QStyle::ControlElement>(ce), opt, p, w); }
261 inline int pixelMetric(DStyle::PixelMetric m, const QStyleOption *opt = nullptr, const QWidget *widget = nullptr) const
262 { return proxy()->pixelMetric(static_cast<QStyle::PixelMetric>(m), opt, widget); }
263 inline QRect subElementRect(DStyle::SubElement r, const QStyleOption *opt, const QWidget *widget = nullptr) const
264 { return proxy()->subElementRect(static_cast<QStyle::SubElement>(r), opt, widget); }
265 inline QSize sizeFromContents(DStyle::ContentsType ct, const QStyleOption *opt, const QSize &contentsSize, const QWidget *widget = nullptr) const
266 { return proxy()->sizeFromContents(static_cast<QStyle::ContentsType>(ct), opt, contentsSize, widget); }
267 inline QIcon standardIcon(DStyle::StandardPixmap st, const QStyleOption *opt = nullptr, const QWidget *widget = nullptr) const
268 { return proxy()->standardIcon(static_cast<QStyle::StandardPixmap>(st), opt, widget); }
269
270 void drawPrimitive(QStyle::PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w = nullptr) const override;
271 void drawControl(QStyle::ControlElement ce, const QStyleOption *opt, QPainter *p, const QWidget *w = nullptr) const override;
272 int pixelMetric(QStyle::PixelMetric m, const QStyleOption *opt = nullptr, const QWidget *widget = nullptr) const override;
273 int styleHint(StyleHint sh, const QStyleOption *opt, const QWidget *w, QStyleHintReturn *shret) const override;
274 QRect subElementRect(QStyle::SubElement r, const QStyleOption *opt, const QWidget *widget = nullptr) const override;
275 QSize sizeFromContents(QStyle::ContentsType ct, const QStyleOption *opt, const QSize &contentsSize, const QWidget *widget = nullptr) const override;
276 QIcon standardIcon(QStyle::StandardPixmap st, const QStyleOption *opt = nullptr, const QWidget *widget = nullptr) const override;
277
278 QPalette standardPalette() const override;
279 QPixmap generatedIconPixmap(QIcon::Mode iconMode, const QPixmap &pixmap, const QStyleOption *opt) const override;
280
281 // 获取一个加工后的画笔
282 QBrush generatedBrush(const QStyleOption *option, const QBrush &base,
283 QPalette::ColorGroup cg = QPalette::Normal,
284 QPalette::ColorRole role = QPalette::NoRole) const;
285 QBrush generatedBrush(StyleState state, const QStyleOption *option, const QBrush &base,
286 QPalette::ColorGroup cg = QPalette::Normal,
287 QPalette::ColorRole role = QPalette::NoRole) const;
288 virtual QBrush generatedBrush(StateFlags flags, const QBrush &base,
289 QPalette::ColorGroup cg = QPalette::Normal,
290 QPalette::ColorRole role = QPalette::NoRole,
291 const QStyleOption *option = nullptr) const;
292
293 QBrush generatedBrush(const QStyleOption *option, const QBrush &base,
294 DPalette::ColorGroup cg = DPalette::Normal,
295 DPalette::ColorType type = DPalette::ItemBackground) const;
296 QBrush generatedBrush(StyleState state, const QStyleOption *option, const QBrush &base,
297 DPalette::ColorGroup cg = DPalette::Normal,
298 DPalette::ColorType type = DPalette::ItemBackground) const;
299 virtual QBrush generatedBrush(StateFlags flags, const QBrush &base,
300 DPalette::ColorGroup cg = DPalette::Normal,
301 DPalette::ColorType type = DPalette::ItemBackground,
302 const QStyleOption *option = nullptr) const;
303
304 using QCommonStyle::drawPrimitive;
305 using QCommonStyle::drawControl;
306 using QCommonStyle::pixelMetric;
307 using QCommonStyle::subElementRect;
308 using QCommonStyle::sizeFromContents;
309 using QCommonStyle::standardIcon;
310
311#if QT_CONFIG(itemviews)
312 static QSizeF viewItemTextLayout(QTextLayout &textLayout, int lineWidth);
313 static QSize viewItemSize(const QStyle *style, const QStyleOptionViewItem *option, int role);
314 static void viewItemLayout(const QStyle *style, const QStyleOptionViewItem *opt, QRect *pixmapRect,
315 QRect *textRect, QRect *checkRect, bool sizehint);
316 virtual void viewItemLayout(const QStyleOptionViewItem *opt, QRect *pixmapRect,
317 QRect *textRect, QRect *checkRect, bool sizehint) const;
318
319 static QRect viewItemDrawText(const QStyle *style, QPainter *p, const QStyleOptionViewItem *option, const QRect &rect);
320 virtual QRect viewItemDrawText(QPainter *p, const QStyleOptionViewItem *option, const QRect &rect) const;
321#endif
322};
323
325{
326public:
327 inline DStyleHelper(const QStyle *style = QApplication::style()) {
328 setStyle(style);
329 }
330
331 inline void setStyle(const QStyle *style) {
332 m_style = style;
333 m_dstyle = qobject_cast<const DStyle*>(style);
334 }
335
336 inline const QStyle *style() const
337 { return m_style; }
338 inline const DStyle *dstyle() const
339 { return m_dstyle; }
340
341 inline QBrush generatedBrush(const QStyleOption *option, const QBrush &base,
342 QPalette::ColorGroup cg = QPalette::Normal,
343 QPalette::ColorRole role = QPalette::NoRole) const
344 { return m_dstyle ? m_dstyle->generatedBrush(option, base, cg, role) : base; }
345 inline QBrush generatedBrush(const QStyleOption *option, const QBrush &base,
346 QPalette::ColorGroup cg = QPalette::Normal,
347 DPalette::ColorType type = DPalette::NoType) const
348 { return m_dstyle ? m_dstyle->generatedBrush(option, base, cg, type) : base; }
349 inline QColor getColor(const QStyleOption *option, QPalette::ColorRole role) const
350 { return generatedBrush(option, option->palette.brush(role), option->palette.currentColorGroup(), role).color(); }
351 inline QColor getColor(const QStyleOption *option, const DPalette &palette, DPalette::ColorType type) const
352 { return generatedBrush(option, palette.brush(type), palette.currentColorGroup(), type).color(); }
353 template<class T>
354 inline QColor getColor(const T *option, DPalette::ColorType type) const
355 { return getColor(option, option->dpalette, type); }
356
357 inline void drawPrimitive(DStyle::PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w = nullptr) const
358 { m_dstyle ? m_dstyle->drawPrimitive(pe, opt, p, w) : DStyle::drawPrimitive(m_style, pe, opt, p, w); }
359 inline void drawControl(DStyle::ControlElement ce, const QStyleOption *opt, QPainter *p, const QWidget *w = nullptr) const
360 { m_dstyle ? m_dstyle->drawControl(ce, opt, p, w) : DStyle::drawControl(m_style, ce, opt, p, w); }
361 inline int pixelMetric(DStyle::PixelMetric m, const QStyleOption *opt = nullptr, const QWidget *widget = nullptr) const
362 { return m_dstyle ? m_dstyle->pixelMetric(m, opt, widget) : DStyle::pixelMetric(m_style, m, opt, widget); }
363 inline QRect subElementRect(DStyle::SubElement r, const QStyleOption *opt, const QWidget *widget = nullptr) const
364 { return m_dstyle ? m_dstyle->subElementRect(r, opt, widget) : DStyle::subElementRect(m_style, r, opt, widget); }
365 inline QSize sizeFromContents(DStyle::ContentsType ct, const QStyleOption *opt, const QSize &contentsSize, const QWidget *widget = nullptr) const
366 { return m_dstyle ? m_dstyle->sizeFromContents(ct, opt, contentsSize, widget) : DStyle::sizeFromContents(m_style, ct, opt, contentsSize, widget); }
367 inline QIcon standardIcon(DStyle::StandardPixmap standardIcon, const QStyleOption *opt, const QWidget *widget = nullptr) const
368 { return m_dstyle ? m_dstyle->standardIcon(standardIcon, opt, widget) : DStyle::standardIcon(m_style, standardIcon, opt, widget); }
369
370private:
371 const QStyle *m_style;
372 const DStyle *m_dstyle;
373};
374
375class DStylePainter : public QPainter
376{
377public:
378 inline DStylePainter() : QPainter(), widget(nullptr), wstyle(nullptr) {}
379 inline explicit DStylePainter(QWidget *w) { begin(w, w); }
380 inline DStylePainter(QPaintDevice *pd, QWidget *w) { begin(pd, w); }
381 inline bool begin(QWidget *w) { return begin(w, w); }
382 inline bool begin(QPaintDevice *pd, QWidget *w) {
383 Q_ASSERT_X(w, "DStylePainter::DStylePainter", "Widget must be non-zero");
384 widget = w;
385 wstyle = w->style();
386 dstyle.setStyle(wstyle);
387 return QPainter::begin(pd);
388 };
389 inline void drawPrimitive(QStyle::PrimitiveElement pe, const QStyleOption &opt);
390 inline void drawPrimitive(DStyle::PrimitiveElement pe, const QStyleOption &opt);
391 inline void drawControl(QStyle::ControlElement ce, const QStyleOption &opt);
392 inline void drawControl(DStyle::ControlElement ce, const QStyleOption &opt);
393 inline void drawComplexControl(QStyle::ComplexControl cc, const QStyleOptionComplex &opt);
394 inline void drawItemText(const QRect &r, int flags, const QPalette &pal, bool enabled,
395 const QString &text, QPalette::ColorRole textRole = QPalette::NoRole);
396 inline void drawItemPixmap(const QRect &r, int flags, const QPixmap &pixmap);
397 inline QStyle *style() const { return wstyle; }
398
399private:
400 QWidget *widget;
401 QStyle *wstyle;
402 DStyleHelper dstyle;
403 Q_DISABLE_COPY(DStylePainter)
404};
405
406void DStylePainter::drawPrimitive(QStyle::PrimitiveElement pe, const QStyleOption &opt)
407{
408 wstyle->drawPrimitive(pe, &opt, this, widget);
409}
410
411void DStylePainter::drawPrimitive(DStyle::PrimitiveElement pe, const QStyleOption &opt)
412{
413 dstyle.drawPrimitive(pe, &opt, this, widget);
414}
415
416void DStylePainter::drawControl(QStyle::ControlElement ce, const QStyleOption &opt)
417{
418 wstyle->drawControl(ce, &opt, this, widget);
419}
420
421void DStylePainter::drawControl(DStyle::ControlElement ce, const QStyleOption &opt)
422{
423 dstyle.drawControl(ce, &opt, this, widget);
424}
425
426void DStylePainter::drawComplexControl(QStyle::ComplexControl cc, const QStyleOptionComplex &opt)
427{
428 wstyle->drawComplexControl(cc, &opt, this, widget);
429}
430
431void DStylePainter::drawItemText(const QRect &r, int flags, const QPalette &pal, bool enabled,
432 const QString &text, QPalette::ColorRole textRole)
433{
434 wstyle->drawItemText(this, r, flags, pal, enabled, text, textRole);
435}
436
437void DStylePainter::drawItemPixmap(const QRect &r, int flags, const QPixmap &pixmap)
438{
439 wstyle->drawItemPixmap(this, r, flags, pixmap);
440}
441
442class DStyledIconEngine : public QIconEngine
443{
444public:
445 static void drawIcon(const QIcon &icon, QPainter *pa, const QRectF &rect);
446
447 typedef std::function<void(QPainter *, const QRectF &rect)> DrawFun;
448 DStyledIconEngine(DrawFun drawFun, const QString &iconName = QString());
449
450 void bindDrawFun(DrawFun drawFun);
451 void setIconName(const QString &name);
452
453 QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) override;
454 void paint(QPainter *painter, const QPalette &palette, const QRectF &rect);
455 void paint(QPainter *painter, const QRect &rect, QIcon::Mode mode, QIcon::State state) override;
456
457 QIconEngine *clone() const override;
458 void setFrontRole(const QWidget* widget, QPalette::ColorRole role);
459
460protected:
461 void virtual_hook(int id, void *data) override;
462
463 DrawFun m_drawFun = nullptr;
464 QString m_iconName;
465 QPalette::ColorRole m_painterRole;
466 const QWidget *m_widget;
467};
468
469DWIDGET_END_NAMESPACE
470
471#endif // DSTYLE_H
Definition dstyle.h:325
Definition dstyle.h:376
DStyle 提供了一个 Dtk 控件的基础类.
Definition dstyle.h:105
QBrush generatedBrush(const QStyleOption *option, const QBrush &base, QPalette::ColorGroup cg=QPalette::Normal, QPalette::ColorRole role=QPalette::NoRole) const
获取一个加工后的画刷
Definition dstyle.cpp:2362
PixelMetric
Definition dstyle.h:131
PrimitiveElement
Definition dstyle.h:109
StandardPixmap
Definition dstyle.h:188
StyleState
Definition dstyle.h:174
DStyledIconEngine一个修改的 QIconEngine 类.
Definition dstyle.h:443
类似于 QToolTip 功能的类
Definition dtooltip.h:15