DtkWidget
DTK Widget module
载入中...
搜索中...
未找到
dimagebutton.h
1// SPDX-FileCopyrightText: 2015 - 2022 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: LGPL-3.0-or-later
4
5#ifndef DIMAGEBUTTON_H
6#define DIMAGEBUTTON_H
7
8#include <QObject>
9#include <QWidget>
10#include <QLabel>
11#include <QPixmap>
12
13#include <dtkwidget_global.h>
14#include <DObject>
15
16#if DTK_VERSION < DTK_VERSION_CHECK(6, 0, 0, 0)
17
18DWIDGET_BEGIN_NAMESPACE
19class DImageButtonPrivate;
20class LIBDTKWIDGETSHARED_EXPORT D_DECL_DEPRECATED_X("Use DIconButton") DImageButton : public QLabel, public DTK_CORE_NAMESPACE::DObject
21{
22 Q_OBJECT
23 Q_PROPERTY(QString normalPic READ getNormalPic WRITE setNormalPic DESIGNABLE true)
24 Q_PROPERTY(QString hoverPic READ getHoverPic WRITE setHoverPic DESIGNABLE true)
25 Q_PROPERTY(QString pressPic READ getPressPic WRITE setPressPic DESIGNABLE true)
26 Q_PROPERTY(QString checkedPic READ getCheckedPic WRITE setCheckedPic DESIGNABLE true)
27 Q_PROPERTY(QString disabledPic READ getDisabledPic WRITE setDisabledPic DESIGNABLE true)
28 Q_PROPERTY(bool checked READ isChecked WRITE setChecked NOTIFY checkedChanged)
29 Q_PROPERTY(bool checkable READ isCheckable WRITE setCheckable)
30
31public:
32 DImageButton(QWidget *parent = 0);
33
34 DImageButton(const QString &normalPic, const QString &hoverPic,
35 const QString &pressPic, QWidget *parent = 0);
36
37 DImageButton(const QString &normalPic, const QString &hoverPic,
38 const QString &pressPic, const QString &checkedPic, QWidget *parent = 0);
39
40 ~DImageButton();
41
42 void setEnabled(bool enabled);
43 void setDisabled(bool disabled);
44
45 void setChecked(bool flag);
46 void setCheckable(bool flag);
47 bool isChecked() const;
48 bool isCheckable() const;
49
50 void setNormalPic(const QString &normalPic);
51 void setHoverPic(const QString &hoverPic);
52 void setPressPic(const QString &pressPic);
53 void setCheckedPic(const QString &checkedPic);
54 void setDisabledPic(const QString &disabledPic);
55
56 const QString getNormalPic() const;
57 const QString getHoverPic() const;
58 const QString getPressPic() const;
59 const QString getCheckedPic() const;
60 const QString getDisabledPic() const;
61
62 enum State {
63 Normal,
64 Hover,
65 Press,
66 Checked,
67 Disabled
68 };
69
70 void setState(State state);
71 State getState() const;
72
73Q_SIGNALS:
74 void clicked();
75 void checkedChanged(bool checked);
76 void stateChanged();
77
78protected:
79 DImageButton(DImageButtonPrivate &q, QWidget *parent);
80#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
81 void enterEvent(QEvent *event) Q_DECL_OVERRIDE;
82#else
83 void enterEvent(QEnterEvent *event) Q_DECL_OVERRIDE;
84#endif
85 void leaveEvent(QEvent *event) Q_DECL_OVERRIDE;
86 void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
87 void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
88 void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
89
90private:
91 Q_DISABLE_COPY(DImageButton)
92 D_DECLARE_PRIVATE(DImageButton)
93};
94
95DWIDGET_END_NAMESPACE
96
97#endif // DIMAGEBUTTON_H
98
99#endif