gqtbuttonswidget
Loading...
Searching...
No Matches
gQtButtonsWidget.h
Go to the documentation of this file.
1#pragma once
2
3// C++
4#include <string>
5#include <vector>
6
7// qt
8#include <QWidget>
9#include <QListWidget>
10#include <QPushButton>
11#include <QVector>
12#include <QIcon>
13#include <QPalette>
14#include <QSize>
15#include <QEvent>
16#include <QShowEvent>
17
37{
44 explicit ButtonInfo(const std::string& icon);
45
55 QListWidgetItem* thisButton;
56
74 QIcon iconForState(int state, const QSize& iconSize, const QPalette& palette) const;
75
76private:
77 std::string buttonName;
78};
79
97class GQTButtonsWidget : public QWidget
98{
99 Q_OBJECT
100
101public:
118 explicit GQTButtonsWidget(double h, double v,
119 const std::vector<std::string>& bicons,
120 bool vertical = true,
121 QWidget* parent = nullptr);
122
123 ~GQTButtonsWidget() override = default;
124
135 QListWidget* buttonsWidget;
136
146 int button_pressed() const { return buttonsWidget->currentRow(); }
147
157 void press_button(int i);
158
166 void reset_buttons();
167
168private:
176 void refresh_icons();
177
178protected:
179 void changeEvent(QEvent* event) override;
180 void showEvent(QShowEvent* event) override;
181
182private:
189 std::vector<ButtonInfo*> buttons;
190
191private slots:
202 void buttonWasPressed(QListWidgetItem* item);
203};
204
218class GQTToggleButtonWidget : public QWidget
219{
220 Q_OBJECT
221
222public:
233 explicit GQTToggleButtonWidget(int buttonWidth, int buttonHeight, int borderRadius,
234 const std::vector<std::string>& titles,
235 bool vertical = true,
236 QWidget* parent = nullptr);
237
246 int buttonPressed() const { return buttonPressedIndex; }
247
256 bool lastButtonState() const;
257
263 void toggleButton(int index);
264
271 bool buttonStatus(int index) const;
272
280 void reset_buttons();
281
293 void setSvgButtonIcon(int index, const QString& svgResourcePath, const QSize& iconSize = QSize());
294
295signals:
302
303protected:
304 void changeEvent(QEvent* event) override;
305 void showEvent(QShowEvent* event) override;
306
307private:
308 struct SvgIcon { QString path; QSize size; };
309
310 int buttonPressedIndex;
311 QVector<QPushButton*> buttons;
312 QVector<SvgIcon> svgIcons;
313
314 void refresh_svg_icons();
315
316private slots:
322 void setButtonPressed(int index);
323};
Icon-based button strip widget implemented using a QListWidget.
void changeEvent(QEvent *event) override
void reset_buttons()
Reset all buttons to the "normal" icon state.
void showEvent(QShowEvent *event) override
QListWidget * buttonsWidget
Underlying QListWidget used to render the icons.
void press_button(int i)
Programmatically press a button.
GQTButtonsWidget(double h, double v, const std::vector< std::string > &bicons, bool vertical=true, QWidget *parent=nullptr)
Constructs a GQTButtonsWidget.
int button_pressed() const
Returns the index of the currently selected (pressed) button.
~GQTButtonsWidget() override=default
Group of toggleable push buttons with a tracked "last pressed" index.
void toggleButton(int index)
Toggle the checked state of a button.
void setSvgButtonIcon(int index, const QString &svgResourcePath, const QSize &iconSize=QSize())
Assign an SVG resource to a button so it re-renders on every palette/theme change.
void showEvent(QShowEvent *event) override
GQTToggleButtonWidget(int buttonWidth, int buttonHeight, int borderRadius, const std::vector< std::string > &titles, bool vertical=true, QWidget *parent=nullptr)
Constructs a GQTToggleButtonWidget.
void changeEvent(QEvent *event) override
void reset_buttons()
Uncheck all buttons.
int buttonPressed() const
Returns the last pressed button index.
void buttonPressedIndexChanged(int index)
Emitted whenever the last pressed button index changes.
bool buttonStatus(int index) const
Returns the checked state for a specific button.
bool lastButtonState() const
Returns the checked state of the last pressed button.
Logical description of one icon-button entry used by GQTButtonsWidget.
QIcon iconForState(int state, const QSize &iconSize, const QPalette &palette) const
Returns the icon for a given interaction state.
QListWidgetItem * thisButton
The UI item representing this logical button.
ButtonInfo(const std::string &icon)
Constructs a ButtonInfo for a given base icon name.