File indexing completed on 2025-01-26 03:40:56
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 "kiconwidgets_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 KICONWIDGETS_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 /** 0048 * Destructs the button. 0049 */ 0050 ~KIconButton() override; 0051 0052 /** 0053 * Sets a strict icon size policy for allowed icons. When true, 0054 * only icons of the specified group's size in setIconType() are allowed, 0055 * and only icons of that size will be shown in the icon dialog. 0056 */ 0057 void setStrictIconSize(bool b); 0058 /** 0059 * Returns true if a strict icon size policy is set. 0060 */ 0061 bool strictIconSize() const; 0062 0063 /** 0064 * Sets the icon group and context. Use KIconLoader::NoGroup if you want to 0065 * allow icons for any group in the given context. 0066 */ 0067 void setIconType(KIconLoader::Group group, KIconLoader::Context context, bool user = false); 0068 0069 /** 0070 * Sets the button's initial icon. 0071 */ 0072 void setIcon(const QString &icon); 0073 0074 void setIcon(const QIcon &icon); 0075 0076 /** 0077 * Resets the icon (reverts to an empty button). 0078 */ 0079 void resetIcon(); 0080 0081 /** 0082 * Returns the name of the selected icon. 0083 */ 0084 const QString &icon() const; 0085 0086 /** 0087 * Sets the size of the icon to be shown / selected. 0088 * @see KIconLoader::StdSizes 0089 * @see iconSize 0090 */ 0091 void setIconSize(int size); 0092 /** 0093 * Returns the icon size set via setIconSize() or 0, if the default 0094 * icon size will be used. 0095 */ 0096 int iconSize() const; 0097 0098 /** 0099 * Sets the size of the icon to be shown on the button. 0100 * @see KIconLoader::StdSizes 0101 * @see buttonIconSize 0102 * @since 4.1 0103 */ 0104 void setButtonIconSize(int size); 0105 /** 0106 * Returns the button's icon size. 0107 * @since 4.1 0108 */ 0109 int buttonIconSize() const; 0110 0111 Q_SIGNALS: 0112 /** 0113 * Emitted when the icon has changed. 0114 */ 0115 void iconChanged(const QString &icon); 0116 0117 private: 0118 std::unique_ptr<class KIconButtonPrivate> const d; 0119 0120 Q_DISABLE_COPY(KIconButton) 0121 }; 0122 0123 #endif // KICONBUTTON_H