SARibbon 2.5.2
SARibbon wiki
载入中...
搜索中...
未找到
SARibbonToolButton.h
1#ifndef SARIBBONTOOLBUTTON_H
2#define SARIBBONTOOLBUTTON_H
3#include "SARibbonGlobal.h"
4#include <QToolButton>
5#include <QDebug>
6
7// 前向声明
30class SA_RIBBON_EXPORT SARibbonToolButton : public QToolButton
31{
32 Q_OBJECT
33 SA_RIBBON_DECLARE_PRIVATE(SARibbonToolButton)
34public:
39 {
44
49 SmallButton
50 };
51 Q_ENUM(RibbonButtonType)
52
53
57 {
70 qreal twoLineHeightFactor { 2.05 }; // Note: Kept as literal for header inline initialization compatibility
71
84 qreal oneLineHeightFactor { 1.2 };
85
99 qreal buttonMaximumAspectRatio { 1.4 };
100 };
101
102public:
103 explicit SARibbonToolButton(QWidget* parent = nullptr);
104 explicit SARibbonToolButton(QAction* defaultAction, QWidget* parent = nullptr);
106
107 // Get the current button type (LargeButton or SmallButton)
108 RibbonButtonType buttonType() const;
109 // Set the button type to LargeButton or SmallButton
110 void setButtonType(const RibbonButtonType& buttonType);
111
113 void setEnableIconRightText(bool on);
115 bool isEnableIconRightText() const;
116
117 // Check if the button is a small ribbon button
118 bool isSmallRibbonButton() const;
119 // Check if the button is a large ribbon button
120 bool isLargeRibbonButton() const;
121
122 // Get the current spacing value
123 int spacing() const;
124 // Set the spacing between elements and the border
125 void setSpacing(int v);
126
127 // Force an update of the internal layout rectangles
128 void updateRect();
129
130 // Set the layout factor for fine-tuning the button's appearance
131 void setLayoutFactor(const LayoutFactor& fac);
132 // Get the layout factor for fine-tuning the button's appearance (const version)
133 const LayoutFactor& layoutFactor() const;
134 // Get the layout factor for fine-tuning the button's appearance (non-const version)
135 LayoutFactor& layoutFactor();
136
137 // Enables or disables automatic text wrapping for large buttons / 为大按钮启用或禁用自动文字换行
138 void setEnableWordWrap(bool on);
139 // Checks if automatic text wrapping is enabled / 检查是否启用了自动文字换行
140 bool isEnableWordWrap() const;
141
142 // Sets the button's maximum aspect ratio (width/height) / 设置按钮的最大宽高比
143 void setButtonMaximumAspectRatio(qreal v = 1.4);
144 // Gets the button's maximum aspect ratio (width/height) / 获取按钮的最大宽高比
145 qreal buttonMaximumAspectRatio() const;
146
147 // Invalidates the cached size hint / 使缓存的size hint失效
148 void invalidateSizeHint();
149
150 // 大按钮尺寸
151 void setLargeIconSize(const QSize& largeSize);
152 QSize largeIconSize() const;
153
154 // 小按钮尺寸
155 void setSmallIconSize(const QSize& smallSize);
156 QSize smallIconSize() const;
157
158public:
159 virtual QSize sizeHint() const Q_DECL_OVERRIDE;
160 virtual QSize minimumSizeHint() const Q_DECL_OVERRIDE;
161
162protected:
163 virtual void paintEvent(QPaintEvent* e) Q_DECL_OVERRIDE;
164 virtual void resizeEvent(QResizeEvent* e) Q_DECL_OVERRIDE;
165 virtual void mouseMoveEvent(QMouseEvent* e) Q_DECL_OVERRIDE;
166 virtual void mousePressEvent(QMouseEvent* e) Q_DECL_OVERRIDE;
167 virtual void mouseReleaseEvent(QMouseEvent* e) Q_DECL_OVERRIDE;
168 virtual void focusOutEvent(QFocusEvent* e) Q_DECL_OVERRIDE;
169 virtual void leaveEvent(QEvent* e) Q_DECL_OVERRIDE;
170 virtual bool hitButton(const QPoint& pos) const Q_DECL_OVERRIDE;
171 virtual bool event(QEvent* e) Q_DECL_OVERRIDE;
172 virtual void changeEvent(QEvent* e) Q_DECL_OVERRIDE;
173 virtual void actionEvent(QActionEvent* e) Q_DECL_OVERRIDE;
174
175 // Paints the button's background and frame / 绘制按钮的背景和边框
176 virtual void paintButton(QPainter& p, const QStyleOptionToolButton& opt);
177 // Paints the button's icon / 绘制按钮的图标
178 virtual void paintIcon(QPainter& p, const QStyleOptionToolButton& opt, const QRect& iconDrawRect);
179 // Paints the button's text / 绘制按钮的文字
180 virtual void paintText(QPainter& p, const QStyleOptionToolButton& opt, const QRect& textDrawRect);
181 // Paints the button's indicator (e.g., dropdown arrow) / 绘制按钮的指示器(例如下拉箭头)
182 virtual void paintIndicator(QPainter& p, const QStyleOptionToolButton& opt, const QRect& indicatorDrawRect);
183
191 virtual QPixmap createIconPixmap(const QStyleOptionToolButton& opt, const QSize& iconSize) const;
192
193private:
194 static void drawArrow(const QStyle* style,
195 const QStyleOptionToolButton* toolbutton,
196 const QRect& rect,
197 QPainter* painter,
198 const QWidget* widget = 0);
199};
200
201namespace SA
202{
203QDebug operator<<(QDebug debug, const QStyleOptionToolButton& opt);
204}
205#endif // SARIBBONTOOLBUTTON_H
Ribbon按钮布局策略抽象基类
Definition SARibbonButtonLayoutStrategy.h:76
Definition SARibbonToolButton.h:31
RibbonButtonType
Button type enumeration / 按钮样式枚举
Definition SARibbonToolButton.h:39
@ LargeButton
Large button type, corresponding to the large button in SARibbonBar / 大按钮类型,此类型对应SARibbonBar的大按钮
Definition SARibbonToolButton.h:43
布局上下文
Definition SARibbonButtonLayoutStrategy.h:53
Layout factor structure for fine-tuning button appearance / 用于微调按钮外观的布局系数结构体
Definition SARibbonToolButton.h:57