KIconThemes

kiconbutton.h
1 /* vi: ts=8 sts=4 sw=4
2 
3  This file is part of the KDE project, module kfile.
4  SPDX-FileCopyrightText: 2000 Geert Jansen <[email protected]>
5  SPDX-FileCopyrightText: 2000 Kurt Granroth <[email protected]>
6  SPDX-FileCopyrightText: 1997 Christoph Neerfeld <[email protected]>
7  SPDX-FileCopyrightText: 2002 Carsten Pfeiffer <[email protected]>
8 
9  SPDX-License-Identifier: LGPL-2.0-only
10 */
11 
12 #ifndef KICONBUTTON_H
13 #define KICONBUTTON_H
14 
15 #include "kiconthemes_export.h"
16 
17 #include <QPushButton>
18 #include <memory>
19 
20 #include <kiconloader.h>
21 
22 /**
23  * @class KIconButton kiconbutton.h KIconButton
24  *
25  * A pushbutton for choosing an icon. Pressing on the button will open a
26  * KIconDialog for the user to select an icon. The current icon will be
27  * displayed on the button.
28  *
29  * @see KIconDialog
30  * @short A push button that allows selection of an icon.
31  */
32 class KICONTHEMES_EXPORT KIconButton : public QPushButton
33 {
34  Q_OBJECT
35  Q_PROPERTY(QString icon READ icon WRITE setIcon RESET resetIcon NOTIFY iconChanged USER true)
36  Q_PROPERTY(int iconSize READ iconSize WRITE setIconSize)
37  Q_PROPERTY(bool strictIconSize READ strictIconSize WRITE setStrictIconSize)
38 
39 public:
40  /**
41  * Constructs a KIconButton using the global icon loader.
42  *
43  * @param parent The parent widget.
44  */
45  explicit KIconButton(QWidget *parent = nullptr);
46 
47  /**
48  * Constructs a KIconButton using a specific icon loader.
49  *
50  * @param loader The icon loader to use.
51  * @param parent The parent widget.
52  */
53  KIconButton(KIconLoader *loader, QWidget *parent);
54 
55  /**
56  * Destructs the button.
57  */
58  ~KIconButton();
59 
60  /**
61  * Sets a strict icon size policy for allowed icons. When true,
62  * only icons of the specified group's size in setIconType() are allowed,
63  * and only icons of that size will be shown in the icon dialog.
64  */
65  void setStrictIconSize(bool b);
66  /**
67  * Returns true if a strict icon size policy is set.
68  */
69  bool strictIconSize() const;
70 
71  /**
72  * Sets the icon group and context. Use KIconLoader::NoGroup if you want to
73  * allow icons for any group in the given context.
74  */
75  void setIconType(KIconLoader::Group group, KIconLoader::Context context, bool user = false);
76 
77  /**
78  * Sets the button's initial icon.
79  */
80  void setIcon(const QString &icon);
81 
82  void setIcon(const QIcon &icon);
83 
84  /**
85  * Resets the icon (reverts to an empty button).
86  */
87  void resetIcon();
88 
89  /**
90  * Returns the name of the selected icon.
91  */
92  const QString &icon() const;
93 
94  /**
95  * Sets the size of the icon to be shown / selected.
96  * @see KIconLoader::StdSizes
97  * @see iconSize
98  */
99  void setIconSize(int size);
100  /**
101  * Returns the icon size set via setIconSize() or 0, if the default
102  * icon size will be used.
103  */
104  int iconSize() const;
105 
106  /**
107  * Sets the size of the icon to be shown on the button.
108  * @see KIconLoader::StdSizes
109  * @see buttonIconSize
110  * @since 4.1
111  */
112  void setButtonIconSize(int size);
113  /**
114  * Returns the button's icon size.
115  * @since 4.1
116  */
117  int buttonIconSize() const;
118 
119 Q_SIGNALS:
120  /**
121  * Emitted when the icon has changed.
122  */
123  void iconChanged(const QString &icon);
124 
125 private:
126  std::unique_ptr<class KIconButtonPrivate> const d;
127 
129 };
130 
131 #endif // KICONBUTTON_H
A pushbutton for choosing an icon.
Definition: kiconbutton.h:32
void setIcon(const QIcon &icon)
void setIconSize(const QSize &size)
Q_PROPERTY(...)
Q_DISABLE_COPY(Class)
Context
Defines the context of the icon.
Definition: kiconloader.h:76
Group
The group of the icon.
Definition: kiconloader.h:120
Iconloader for KDE.
Definition: kiconloader.h:68
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sat May 15 2021 22:41:44 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.