1 | /* |
2 | |
3 | This file is part of the KDE project, module kfile. |
4 | SPDX-FileCopyrightText: 2000 Geert Jansen <jansen@kde.org> |
5 | SPDX-FileCopyrightText: 2000 Kurt Granroth <granroth@kde.org> |
6 | SPDX-FileCopyrightText: 1997 Christoph Neerfeld <chris@kde.org> |
7 | SPDX-FileCopyrightText: 2002 Carsten Pfeiffer <pfeiffer@kde.org> |
8 | |
9 | SPDX-License-Identifier: LGPL-2.0-only |
10 | */ |
11 | |
12 | #ifndef KICONBUTTON_H |
13 | #define KICONBUTTON_H |
14 | |
15 | #include "kiconwidgets_export.h" |
16 | |
17 | #include <QPushButton> |
18 | #include <memory> |
19 | |
20 | #include <kiconloader.h> |
21 | |
22 | /*! |
23 | * \class KIconButton |
24 | * \inmodule KIconWidgets |
25 | * |
26 | * \brief A pushbutton for choosing an icon. |
27 | * |
28 | * Pressing on the button will open a |
29 | * KIconDialog for the user to select an icon. The current icon will be |
30 | * displayed on the button. |
31 | * |
32 | * \sa KIconDialog |
33 | */ |
34 | class KICONWIDGETS_EXPORT KIconButton : public QPushButton |
35 | { |
36 | Q_OBJECT |
37 | |
38 | /*! |
39 | * \property KIconButton::icon |
40 | */ |
41 | Q_PROPERTY(QString icon READ icon WRITE setIcon RESET resetIcon NOTIFY iconChanged USER true) |
42 | |
43 | /*! |
44 | * \property KIconButton::iconSize |
45 | */ |
46 | Q_PROPERTY(int iconSize READ iconSize WRITE setIconSize) |
47 | |
48 | /*! |
49 | * \property KIconButton::strictIconSize |
50 | */ |
51 | Q_PROPERTY(bool strictIconSize READ strictIconSize WRITE setStrictIconSize) |
52 | |
53 | public: |
54 | /*! |
55 | * Constructs a KIconButton using the global icon loader. |
56 | * |
57 | * \a parent The parent widget. |
58 | */ |
59 | explicit KIconButton(QWidget *parent = nullptr); |
60 | |
61 | ~KIconButton() override; |
62 | |
63 | /*! |
64 | * Sets a strict icon size policy for allowed icons. When true, |
65 | * only icons of the specified group's size in setIconType() are allowed, |
66 | * and only icons of that size will be shown in the icon dialog. |
67 | */ |
68 | void setStrictIconSize(bool b); |
69 | |
70 | /*! |
71 | * Returns true if a strict icon size policy is set. |
72 | */ |
73 | bool strictIconSize() const; |
74 | |
75 | /*! |
76 | * Sets the icon group and context. Use KIconLoader::NoGroup if you want to |
77 | * allow icons for any group in the given context. |
78 | */ |
79 | void setIconType(KIconLoader::Group group, KIconLoader::Context context, bool user = false); |
80 | |
81 | /*! |
82 | * Sets the button's initial icon. |
83 | */ |
84 | void setIcon(const QString &icon); |
85 | |
86 | /*! |
87 | * Sets the button's initial icon. |
88 | */ |
89 | void setIcon(const QIcon &icon); |
90 | |
91 | /*! |
92 | * Resets the icon (reverts to an empty button). |
93 | */ |
94 | void resetIcon(); |
95 | |
96 | /*! |
97 | * Returns the name of the selected icon. |
98 | */ |
99 | const QString &icon() const; |
100 | |
101 | /*! |
102 | * Sets the size of the icon to be shown / selected. |
103 | * \sa KIconLoader::StdSizes |
104 | * \sa iconSize |
105 | */ |
106 | void setIconSize(int size); |
107 | /*! |
108 | * Returns the icon size set via setIconSize() or 0, if the default |
109 | * icon size will be used. |
110 | */ |
111 | int iconSize() const; |
112 | |
113 | /*! |
114 | * Sets the size of the icon to be shown on the button. |
115 | * \sa KIconLoader::StdSizes |
116 | * \sa buttonIconSize |
117 | * \since 4.1 |
118 | */ |
119 | void setButtonIconSize(int size); |
120 | /*! |
121 | * Returns the button's icon size. |
122 | * \since 4.1 |
123 | */ |
124 | int buttonIconSize() const; |
125 | |
126 | void paintEvent(QPaintEvent *event) override; |
127 | |
128 | void changeEvent(QEvent *event) override; |
129 | |
130 | Q_SIGNALS: |
131 | /*! |
132 | * Emitted when the icon has changed. |
133 | */ |
134 | void iconChanged(const QString &icon); |
135 | |
136 | private: |
137 | std::unique_ptr<class KIconButtonPrivate> const d; |
138 | |
139 | Q_DISABLE_COPY(KIconButton) |
140 | }; |
141 | |
142 | #endif // KICONBUTTON_H |
143 | |