File indexing completed on 2024-09-08 12:18:03
0001 /* vi: ts=8 sts=4 sw=4 0002 0003 This file is part of the KDE project, module kfile. 0004 SPDX-FileCopyrightText: 2000 Geert Jansen <jansen@kde.org> 0005 SPDX-FileCopyrightText: 2000 Kurt Granroth <granroth@kde.org> 0006 SPDX-FileCopyrightText: 1997 Christoph Neerfeld <chris@kde.org> 0007 SPDX-FileCopyrightText: 2002 Carsten Pfeiffer <pfeiffer@kde.org> 0008 0009 SPDX-License-Identifier: LGPL-2.0-only 0010 */ 0011 0012 #ifndef KICONBUTTON_H 0013 #define KICONBUTTON_H 0014 0015 #include "kiconthemes_export.h" 0016 0017 #include <QPushButton> 0018 #include <memory> 0019 0020 #include <kiconloader.h> 0021 0022 /** 0023 * @class KIconButton kiconbutton.h KIconButton 0024 * 0025 * A pushbutton for choosing an icon. Pressing on the button will open a 0026 * KIconDialog for the user to select an icon. The current icon will be 0027 * displayed on the button. 0028 * 0029 * @see KIconDialog 0030 * @short A push button that allows selection of an icon. 0031 */ 0032 class KICONTHEMES_EXPORT KIconButton : public QPushButton 0033 { 0034 Q_OBJECT 0035 Q_PROPERTY(QString icon READ icon WRITE setIcon RESET resetIcon NOTIFY iconChanged USER true) 0036 Q_PROPERTY(int iconSize READ iconSize WRITE setIconSize) 0037 Q_PROPERTY(bool strictIconSize READ strictIconSize WRITE setStrictIconSize) 0038 0039 public: 0040 /** 0041 * Constructs a KIconButton using the global icon loader. 0042 * 0043 * @param parent The parent widget. 0044 */ 0045 explicit KIconButton(QWidget *parent = nullptr); 0046 0047 #if KICONTHEMES_ENABLE_DEPRECATED_SINCE(5, 104) 0048 /** 0049 * Constructs a KIconButton using a specific icon loader. 0050 * @deprecated since 5.104, use KIconButton(QWidget *). 0051 * 0052 * @param loader The icon loader to use. 0053 * @param parent The parent widget. 0054 */ 0055 KICONTHEMES_DEPRECATED_VERSION(5, 104, "Use KIconButton(QWidget *) instead") 0056 KIconButton(KIconLoader *loader, QWidget *parent); 0057 #endif 0058 0059 /** 0060 * Destructs the button. 0061 */ 0062 ~KIconButton() override; 0063 0064 /** 0065 * Sets a strict icon size policy for allowed icons. When true, 0066 * only icons of the specified group's size in setIconType() are allowed, 0067 * and only icons of that size will be shown in the icon dialog. 0068 */ 0069 void setStrictIconSize(bool b); 0070 /** 0071 * Returns true if a strict icon size policy is set. 0072 */ 0073 bool strictIconSize() const; 0074 0075 /** 0076 * Sets the icon group and context. Use KIconLoader::NoGroup if you want to 0077 * allow icons for any group in the given context. 0078 */ 0079 void setIconType(KIconLoader::Group group, KIconLoader::Context context, bool user = false); 0080 0081 /** 0082 * Sets the button's initial icon. 0083 */ 0084 void setIcon(const QString &icon); 0085 0086 void setIcon(const QIcon &icon); 0087 0088 /** 0089 * Resets the icon (reverts to an empty button). 0090 */ 0091 void resetIcon(); 0092 0093 /** 0094 * Returns the name of the selected icon. 0095 */ 0096 const QString &icon() const; 0097 0098 /** 0099 * Sets the size of the icon to be shown / selected. 0100 * @see KIconLoader::StdSizes 0101 * @see iconSize 0102 */ 0103 void setIconSize(int size); 0104 /** 0105 * Returns the icon size set via setIconSize() or 0, if the default 0106 * icon size will be used. 0107 */ 0108 int iconSize() const; 0109 0110 /** 0111 * Sets the size of the icon to be shown on the button. 0112 * @see KIconLoader::StdSizes 0113 * @see buttonIconSize 0114 * @since 4.1 0115 */ 0116 void setButtonIconSize(int size); 0117 /** 0118 * Returns the button's icon size. 0119 * @since 4.1 0120 */ 0121 int buttonIconSize() const; 0122 0123 Q_SIGNALS: 0124 /** 0125 * Emitted when the icon has changed. 0126 */ 0127 void iconChanged(const QString &icon); 0128 0129 private: 0130 std::unique_ptr<class KIconButtonPrivate> const d; 0131 0132 Q_DISABLE_COPY(KIconButton) 0133 }; 0134 0135 #endif // KICONBUTTON_H