| 1 | // SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. |
|---|---|
| 2 | // |
| 3 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 4 | |
| 5 | #ifndef SINGLECHOICEBOX_H |
| 6 | #define SINGLECHOICEBOX_H |
| 7 | |
| 8 | #include <QGroupBox> |
| 9 | #include <QIcon> |
| 10 | |
| 11 | class SingleChoiceBoxPrivate; |
| 12 | class SingleChoiceBox : public QWidget |
| 13 | { |
| 14 | Q_OBJECT |
| 15 | SingleChoiceBoxPrivate *const d; |
| 16 | public: |
| 17 | struct Info { |
| 18 | QString text; |
| 19 | QString tooltip; |
| 20 | QIcon icon; |
| 21 | inline bool operator == (const Info& info) const { |
| 22 | return text == info.text |
| 23 | && tooltip == info.tooltip; |
| 24 | } |
| 25 | |
| 26 | inline Info& operator=(const Info& info) { |
| 27 | text = info.text; |
| 28 | tooltip = info.tooltip; |
| 29 | icon = info.icon; |
| 30 | return *this; |
| 31 | } |
| 32 | }; |
| 33 | |
| 34 | explicit SingleChoiceBox(QWidget *parent = nullptr); |
| 35 | virtual ~SingleChoiceBox(); |
| 36 | void setInfos(QSet<Info> infos); |
| 37 | void setChoiceTitle(const QString &title); |
| 38 | |
| 39 | signals: |
| 40 | void selected(const Info &info); |
| 41 | |
| 42 | private slots: |
| 43 | void toggled(bool checked); |
| 44 | }; |
| 45 | |
| 46 | uint qHash(const SingleChoiceBox::Info &info, uint seed = 0); |
| 47 | |
| 48 | #endif // SINGLECHOICEBOX_H |
| 49 |