File: dbuttonbox.h

package info (click to toggle)
dtkwidget 5.7.12-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 36,540 kB
  • sloc: cpp: 63,257; ansic: 132; python: 88; sh: 42; makefile: 13
file content (94 lines) | stat: -rw-r--r-- 2,788 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// SPDX-FileCopyrightText: 2019 - 2024 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later

#ifndef DBUTTONBOX_H
#define DBUTTONBOX_H

#include <dtkwidget_global.h>
#include <DObject>
#include <DStyle>
#include <DDciIcon>

#include <QAbstractButton>

DWIDGET_BEGIN_NAMESPACE

class DStyleOptionButtonBoxButton;
class DButtonBoxButtonPrivate;
class DButtonBoxButton : public QAbstractButton, public DCORE_NAMESPACE::DObject
{
    Q_OBJECT
    D_DECLARE_PRIVATE(DButtonBoxButton)

public:
    explicit DButtonBoxButton(const QString &text, QWidget *parent = nullptr);
    DButtonBoxButton(const QIcon& icon, const QString &text = QString(), QWidget *parent = nullptr);
    DButtonBoxButton(QStyle::StandardPixmap iconType = static_cast<QStyle::StandardPixmap>(-1),
                     const QString &text = QString(), QWidget *parent = nullptr);
    DButtonBoxButton(DStyle::StandardPixmap iconType = static_cast<DStyle::StandardPixmap>(-1),
                     const QString &text = QString(), QWidget *parent = nullptr);
    DButtonBoxButton(const DDciIcon &dciIcon, const QString &text = QString(), QWidget *parent = nullptr);

    void setIcon(const QIcon &icon);
    void setIcon(QStyle::StandardPixmap iconType);
    void setIcon(DStyle::StandardPixmap iconType);

    void setIcon(const DDciIcon &icon);
    DDciIcon dciIcon() const;

    QSize iconSize() const;
    QSize sizeHint() const;
    QSize minimumSizeHint() const override;

private:
    void initStyleOption(DStyleOptionButtonBoxButton *option) const;

    void paintEvent(QPaintEvent *e) override;
    void keyPressEvent(QKeyEvent *event) override;
    bool event(QEvent *e) override;

    friend class DButtonBox;
};

class DButtonBoxPrivate;
class DButtonBox : public QWidget, public DCORE_NAMESPACE::DObject
{
    Q_OBJECT
    D_DECLARE_PRIVATE(DButtonBox)

public:
    explicit DButtonBox(QWidget *parent = nullptr);

    Qt::Orientation orientation() const;
    void setOrientation(Qt::Orientation orientation);

    void setButtonList(const QList<DButtonBoxButton*> &list, bool checkable);
    QList<QAbstractButton*> buttonList() const;

    QAbstractButton * checkedButton() const;
    // no setter on purpose!

    QAbstractButton *button(int id) const;
    void setId(QAbstractButton *button, int id);
    int id(QAbstractButton *button) const;
    int checkedId() const;

Q_SIGNALS:
    void buttonClicked(QAbstractButton *);
    void buttonPressed(QAbstractButton *);
    void buttonReleased(QAbstractButton *);
    void buttonToggled(QAbstractButton *, bool);

protected:
    bool eventFilter(QObject *o, QEvent *e) override;

private:
    void paintEvent(QPaintEvent *e) override;

    friend class DButtonBoxButton;
};

DWIDGET_END_NAMESPACE

#endif // DBUTTONBOX_H