gqtbuttonswidget
Loading...
Searching...
No Matches
gQtButtonsWidget.h
Go to the documentation of this file.
1#pragma once
2
3#include <QString>
4
6namespace gemc {
8QString translateSvgLabels(QString svg);
9}
10
11// C++
12#include <string>
13#include <vector>
14
15// qt
16#include <QWidget>
17#include <QListWidget>
18#include <QPushButton>
19#include <QVector>
20#include <QIcon>
21#include <QPalette>
22#include <QSize>
23#include <QEvent>
24#include <QShowEvent>
25
45{
52 explicit ButtonInfo(const std::string& icon);
53
63 QListWidgetItem* thisButton;
64
85 QIcon iconForState(int state, const QSize& iconSize, const QPalette& palette) const;
86
87private:
88 std::string buttonName;
89};
90
108class GQTButtonsWidget : public QWidget
109{
110 Q_OBJECT
111
112public:
129 explicit GQTButtonsWidget(double h, double v,
130 const std::vector<std::string>& bicons,
131 bool vertical = true,
132 QWidget* parent = nullptr);
133
134 ~GQTButtonsWidget() override = default;
135
146 QListWidget* buttonsWidget;
147
157 int button_pressed() const { return buttonsWidget->currentRow(); }
158
168 void press_button(int i);
169
177 void reset_buttons();
178
179private:
187 void refresh_icons();
188
189protected:
190 void changeEvent(QEvent* event) override;
191 void showEvent(QShowEvent* event) override;
192
193private:
200 std::vector<ButtonInfo*> buttons;
201
202private slots:
213 void buttonWasPressed(QListWidgetItem* item);
214};
215
229class GQTToggleButtonWidget : public QWidget
230{
231 Q_OBJECT
232
233public:
244 explicit GQTToggleButtonWidget(int buttonWidth, int buttonHeight, int borderRadius,
245 const std::vector<std::string>& titles,
246 bool vertical = true,
247 QWidget* parent = nullptr);
248
257 int buttonPressed() const { return buttonPressedIndex; }
258
267 bool lastButtonState() const;
268
274 void toggleButton(int index);
275
282 bool buttonStatus(int index) const;
283
291 void reset_buttons();
292
304 void setSvgButtonIcon(int index, const QString& svgResourcePath, const QSize& iconSize = QSize());
305
306signals:
313
314protected:
315 void changeEvent(QEvent* event) override;
316 void showEvent(QShowEvent* event) override;
317
318private:
319 struct SvgIcon { QString path; QSize size; };
320
321 int buttonPressedIndex;
322 QVector<QPushButton*> buttons;
323 QVector<SvgIcon> svgIcons;
324
325 void refresh_svg_icons();
326
327private slots:
333 void setButtonPressed(int index);
334};
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
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.
event
GEMC helpers for translating and rendering Qt toolbar artwork.
QString translateSvgLabels(QString svg)
Translate SVG toolbar captions and fit their font size without changing stored artwork.
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.