SARibbon 2.5.1
SARibbon wiki
载入中...
搜索中...
未找到
SARibbonToolButton.h
1#ifndef SARIBBONTOOLBUTTON_H
2#define SARIBBONTOOLBUTTON_H
3#include "SARibbonGlobal.h"
4#include <QToolButton>
5#include <QDebug>
19class SA_RIBBON_EXPORT SARibbonToolButton : public QToolButton
20{
21 Q_OBJECT
22 SA_RIBBON_DECLARE_PRIVATE(SARibbonToolButton)
23public:
28 {
33
38 SmallButton
39 };
40 Q_ENUM(RibbonButtonType)
41
42
46 {
59 qreal twoLineHeightFactor { 2.05 };
60
73 qreal oneLineHeightFactor { 1.2 };
74
88 qreal buttonMaximumAspectRatio { 1.4 };
89 };
90
91public:
92 explicit SARibbonToolButton(QWidget* parent = nullptr);
93 explicit SARibbonToolButton(QAction* defaultAction, QWidget* parent = nullptr);
95
96 // Gets the current button type (LargeButton or SmallButton) / 获取当前按钮的类型(大按钮或小按钮)
97 RibbonButtonType buttonType() const;
98 // Sets the button type to LargeButton or SmallButton / 设置按钮类型为大按钮或小按钮
99 void setButtonType(const RibbonButtonType& buttonType);
100
101 // Checks if the button is a small ribbon button / 判断按钮是否为小Ribbon按钮
102 bool isSmallRibbonButton() const;
103 // Checks if the button is a large ribbon button / 判断按钮是否为大Ribbon按钮
104 bool isLargeRibbonButton() const;
105
106 // Gets the current spacing value / 获取当前的间距值
107 int spacing() const;
108 // Sets the spacing between elements and the border / 设置元素与边框之间的间距
109 void setSpacing(int v);
110
111 // Forces an update of the internal layout rectangles / 强制更新内部布局矩形
112 void updateRect();
113
114 // Sets the layout factor for fine-tuning the button's appearance / 设置布局系数以微调按钮外观
115 void setLayoutFactor(const LayoutFactor& fac);
116 // layout factor for fine-tuning the button's appearance / 布局系数以微调按钮外观
117 const LayoutFactor& layoutFactor() const;
118 LayoutFactor& layoutFactor();
119
120 // Enables or disables automatic text wrapping for large buttons / 为大按钮启用或禁用自动文字换行
121 void setEnableWordWrap(bool on);
122 // Checks if automatic text wrapping is enabled / 检查是否启用了自动文字换行
123 bool isEnableWordWrap();
124
125 // Sets the button's maximum aspect ratio (width/height) / 设置按钮的最大宽高比
126 void setButtonMaximumAspectRatio(qreal v = 1.4);
127 // Gets the button's maximum aspect ratio (width/height) / 获取按钮的最大宽高比
128 qreal buttonMaximumAspectRatio() const;
129
130 // Invalidates the cached size hint / 使缓存的size hint失效
131 void invalidateSizeHint();
132
133public:
134 virtual QSize sizeHint() const Q_DECL_OVERRIDE;
135 virtual QSize minimumSizeHint() const Q_DECL_OVERRIDE;
136
137protected:
138 virtual void paintEvent(QPaintEvent* e) Q_DECL_OVERRIDE;
139 virtual void resizeEvent(QResizeEvent* e) Q_DECL_OVERRIDE;
140 virtual void mouseMoveEvent(QMouseEvent* e) Q_DECL_OVERRIDE;
141 virtual void mousePressEvent(QMouseEvent* e) Q_DECL_OVERRIDE;
142 virtual void mouseReleaseEvent(QMouseEvent* e) Q_DECL_OVERRIDE;
143 virtual void focusOutEvent(QFocusEvent* e) Q_DECL_OVERRIDE;
144 virtual void leaveEvent(QEvent* e) Q_DECL_OVERRIDE;
145 virtual bool hitButton(const QPoint& pos) const Q_DECL_OVERRIDE;
146 virtual bool event(QEvent* e) Q_DECL_OVERRIDE;
147 virtual void changeEvent(QEvent* e) Q_DECL_OVERRIDE;
148 virtual void actionEvent(QActionEvent* e) Q_DECL_OVERRIDE;
149
150 // Paints the button's background and frame / 绘制按钮的背景和边框
151 virtual void paintButton(QPainter& p, const QStyleOptionToolButton& opt);
152 // Paints the button's icon / 绘制按钮的图标
153 virtual void paintIcon(QPainter& p, const QStyleOptionToolButton& opt, const QRect& iconDrawRect);
154 // Paints the button's text / 绘制按钮的文字
155 virtual void paintText(QPainter& p, const QStyleOptionToolButton& opt, const QRect& textDrawRect);
156 // Paints the button's indicator (e.g., dropdown arrow) / 绘制按钮的指示器(例如下拉箭头)
157 virtual void paintIndicator(QPainter& p, const QStyleOptionToolButton& opt, const QRect& indicatorDrawRect);
158
159private:
160 static void drawArrow(const QStyle* style,
161 const QStyleOptionToolButton* toolbutton,
162 const QRect& rect,
163 QPainter* painter,
164 const QWidget* widget = 0);
165};
166
167namespace SA
168{
169QDebug operator<<(QDebug debug, const QStyleOptionToolButton& opt);
170}
171#endif // SARIBBONTOOLBUTTON_H
Ribbon interface adapted tool button / Ribbon界面适用的toolButton
Definition SARibbonToolButton.h:20
RibbonButtonType
Button type enumeration / 按钮样式枚举
Definition SARibbonToolButton.h:28
@ LargeButton
Large button type, corresponding to the large button in SARibbonBar / 大按钮类型,此类型对应SARibbonBar的大按钮
Definition SARibbonToolButton.h:32
Layout factor structure for fine-tuning button appearance / 用于微调按钮外观的布局系数结构体
Definition SARibbonToolButton.h:46