KanoopGuiQt 1.3.0
Qt GUI utility library
Loading...
Searching...
No Matches
playpausebutton.h
1#ifndef PLAYPAUSEBUTTON_H
2#define PLAYPAUSEBUTTON_H
3
4#include <QWidget>
5#include <Kanoop/gui/libkanoopgui.h>
6
7class QLabel;
8class QPushButton;
9
10/**
11 * @brief Compound widget that toggles between "play" and "pause" states.
12 *
13 * PlayPauseButton displays a QPushButton whose icon switches between
14 * iconWhilePlaying and iconWhilePaused according to the current playing state.
15 * An optional text label can be shown alongside the button with configurable
16 * alignment. The playing property is fully bindable and notifies via
17 * playingChanged().
18 */
19class LIBKANOOPGUI_EXPORT PlayPauseButton : public QWidget
20{
21 Q_OBJECT
22 /** @brief Whether the button is in the playing state. */
23 Q_PROPERTY(bool playing READ isPlaying WRITE setPlaying NOTIFY playingChanged)
24 /** @brief Whether the companion text label is visible. */
25 Q_PROPERTY(bool textVisible READ isTextVisible WRITE setTextVisible) // clazy:exclude=qproperty-without-notify
26 /** @brief Text shown in the companion label. */
27 Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
28 /** @brief Icon displayed while the button is in the playing state. */
29 Q_PROPERTY(QIcon iconWhilePlaying READ iconWhilePlaying WRITE setIconWhilePlaying) // clazy:exclude=qproperty-without-notify
30 /** @brief Icon displayed while the button is in the paused state. */
31 Q_PROPERTY(QIcon iconWhilePaused READ iconWhilePaused WRITE setIconWhilePaused) // clazy:exclude=qproperty-without-notify
32 /** @brief Alignment of the companion text label. */
33 Q_PROPERTY(Qt::Alignment textAlignment READ textAlignment WRITE setTextAlignment) // clazy:exclude=qproperty-without-notify
34
35public:
36 /**
37 * @brief Construct with an optional parent.
38 * @param parent Optional QWidget parent
39 */
40 explicit PlayPauseButton(QWidget *parent = nullptr);
41
42 /**
43 * @brief Return whether the widget is in the "playing" state.
44 * @return true if playing
45 */
46 bool isPlaying() const { return _playing; }
47
48 /**
49 * @brief Return the companion text label's text.
50 * @return Label text string
51 */
52 QString text() const { return _text; }
53
54 /**
55 * @brief Return whether the companion text label is visible.
56 * @return true if visible
57 */
58 bool isTextVisible() const;
59
60 /**
61 * @brief Set minimum, maximum, and icon sizes on the button.
62 * @param min Minimum button size
63 * @param max Maximum button size
64 * @param icon Icon size
65 */
66 void setButtonSize(const QSize& min, const QSize& max, const QSize& icon);
67
68 /**
69 * @brief Return the alignment of the companion text label.
70 * @return Qt alignment flags
71 */
72 Qt::Alignment textAlignment() const { return _textAlignment; }
73
74 /**
75 * @brief Return the icon shown while playing.
76 * @return Playing icon
77 */
78 QIcon iconWhilePlaying() const { return _iconWhilePlaying; }
79
80 /**
81 * @brief Return the icon shown while paused.
82 * @return Paused icon
83 */
84 QIcon iconWhilePaused() const { return _iconWhilePaused; }
85
86public slots:
87 /**
88 * @brief Set the playing state and optionally suppress the signal.
89 * @param value true for playing, false for paused
90 * @param blockSignal true to suppress playingChanged()
91 */
92 void setPlaying(bool value, bool blockSignal = false);
93
94 /**
95 * @brief Set the companion text label text.
96 * @param value New text string
97 */
98 void setText(const QString& value);
99
100 /**
101 * @brief Show or hide the companion text label.
102 * @param value true to show, false to hide
103 */
104 void setTextVisible(bool value);
105
106 /**
107 * @brief Set the text label alignment.
108 * @param value Qt alignment flags
109 */
110 void setTextAlignment(Qt::Alignment value);
111
112 /**
113 * @brief Set the icon displayed while in the playing state.
114 * @param value New playing icon
115 */
116 void setIconWhilePlaying(const QIcon& value) { _iconWhilePlaying = value; }
117
118 /**
119 * @brief Set the icon displayed while in the paused state.
120 * @param value New paused icon
121 */
122 void setIconWhilePaused(const QIcon& value) { _iconWhilePaused = value; }
123
124private:
125 QPushButton* _button;
126 QLabel* _textLabel;
127
128 QIcon _iconWhilePlaying;
129 QIcon _iconWhilePaused;
130
131 bool _playing = false;
132 QString _text;
133 Qt::Alignment _textAlignment = Qt::AlignLeft;
134
135signals:
136 /** @brief Emitted when the button is clicked. */
137 void clicked();
138 /**
139 * @brief Emitted when the playing state changes.
140 * @param playing New playing state
141 */
142 void playingChanged(bool playing);
143 /**
144 * @brief Emitted when the text label text changes.
145 * @param playing New playing state at time of text change
146 */
147 void textChanged(bool playing);
148
149private slots:
150 void onPlayPauseClicked();
151};
152
153#endif // PLAYPAUSEBUTTON_H
Compound widget that toggles between "play" and "pause" states.
void textChanged(bool playing)
Emitted when the text label text changes.
void setIconWhilePaused(const QIcon &value)
Set the icon displayed while in the paused state.
QString text() const
Return the companion text label's text.
QIcon iconWhilePaused() const
Return the icon shown while paused.
Qt::Alignment textAlignment() const
Return the alignment of the companion text label.
void setButtonSize(const QSize &min, const QSize &max, const QSize &icon)
Set minimum, maximum, and icon sizes on the button.
QIcon iconWhilePlaying() const
Return the icon shown while playing.
void setTextVisible(bool value)
Show or hide the companion text label.
void setIconWhilePlaying(const QIcon &value)
Set the icon displayed while in the playing state.
void setText(const QString &value)
Set the companion text label text.
void playingChanged(bool playing)
Emitted when the playing state changes.
void clicked()
Emitted when the button is clicked.
bool isTextVisible() const
Return whether the companion text label is visible.
void setPlaying(bool value, bool blockSignal=false)
Set the playing state and optionally suppress the signal.
void setTextAlignment(Qt::Alignment value)
Set the text label alignment.