Toolbox Qt
Loading...
Searching...
No Matches
button.h
1#ifndef TBQ_WIDGETS_BUTTON_H
2#define TBQ_WIDGETS_BUTTON_H
3
4#include <QPainter>
5#include <QPushButton>
6#include <QToolButton>
7#include <QWidget>
8
9#include "toolboxqt/toolboxqt_global.h"
10
11/*****************************/
12/* Start namespace */
13/*****************************/
14
15namespace tbq
16{
17
18/*****************************/
19/* Class definitions */
20/* BtnAbstractWordWrap */
21/*****************************/
22
23class TOOLBOXQT_EXPORT BtnAbstractWordWrap
24{
25
26public:
27 explicit BtnAbstractWordWrap();
28
29public:
30 void setPadding(int padding);
31
32public:
33 const QString& getText() const;
34 int getPadding() const;
35
36protected:
37 void setTextWordWrap(const QString &text);
38
39 void paintTextWordWrap(QPainter *painter, const QRect &rect);
40 QSize calcSizeHintWordWrap(const QFontMetrics &fm, int width) const;
41
42protected:
43 virtual void updateGeometryBtn() = 0;
44 virtual void updateBtn() = 0;
45
46private:
47 void performRefresh();
48
49private:
50 QString m_text;
51 int m_padding;
52};
53
54/*****************************/
55/* Class definitions */
56/* BtnTool */
57/*****************************/
58
59class TOOLBOXQT_EXPORT BtnTool : public QToolButton, public BtnAbstractWordWrap
60{
61 Q_OBJECT
62
63public:
64 explicit BtnTool(QWidget *parent = nullptr);
65 explicit BtnTool(const QString &text, int padding = 5, QWidget *parent = nullptr);
66
67public:
68 void setText(const QString &text);
69
70protected: // Virtual methods from QToolButton
71 void paintEvent(QPaintEvent *event) override;
72
73 QSize sizeHint() const override;
74 QSize minimumSizeHint() const override;
75
76protected: // Virtual methods from BtnAbstractWordWrap
77 void updateGeometryBtn() override;
78 void updateBtn() override;
79
80private: // Disable inherited public methods that can confuse users
81 using QToolButton::text;
82};
83
84/*****************************/
85/* Class definitions */
86/* BtnPush */
87/*****************************/
88
89class TOOLBOXQT_EXPORT BtnPush : public QPushButton, public BtnAbstractWordWrap
90{
91 Q_OBJECT
92
93public:
94 explicit BtnPush(QWidget *parent = nullptr);
95 explicit BtnPush(const QString &text, int padding = 5, QWidget *parent = nullptr);
96
97public:
98 void setText(const QString &text);
99 void setTimeDoubleClick(int interval = 250);
100
101signals:
104
105protected: // Virtual methods from QToolButton
106 void paintEvent(QPaintEvent *event) override;
107
108 QSize sizeHint() const override;
109 QSize minimumSizeHint() const override;
110
111protected: // Virtual methods from BtnAbstractWordWrap
112 void updateGeometryBtn() override;
113 void updateBtn() override;
114
115private: // Disable inherited public methods that can confuse users
116 using QPushButton::text;
117
118private:
119 void eventIsClicked();
120 void eventTimeoutDblClk();
121
122private:
123 QTimer *m_timerDblClk = nullptr;
124};
125
126/*****************************/
127/* End namespace */
128/*****************************/
129
130} // namespace tbq
131
132/*****************************/
133/* End file */
134/*****************************/
135
136#endif // TBQ_WIDGETS_BUTTON_H
Virtual class implementing wordwrap for buttons.
Definition: button.h:24
Custom QPushButton implementing wordwrap and double-click event support.
Definition: button.h:90
void sClickedSimple()
Signal emitted when sure that double-click has not been performed.
void sClickedDouble()
Signal emitted when double-click event is detected.
Custom QToolButton implementing wordwrap.
Definition: button.h:60