File indexing completed on 2024-09-08 12:18:04
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 SPDX-FileCopyrightText: 2021 Kai Uwe Broulik <kde@broulik.de> 0009 0010 SPDX-License-Identifier: LGPL-2.0-only 0011 */ 0012 0013 #ifndef KICONDIALOG_H 0014 #define KICONDIALOG_H 0015 0016 #include "kiconthemes_export.h" 0017 0018 #include <QDialog> 0019 #include <QPushButton> 0020 #include <memory> 0021 0022 #include <kiconloader.h> 0023 0024 /** 0025 * @class KIconDialog kicondialog.h KIconDialog 0026 * 0027 * Dialog for interactive selection of icons. Use the function 0028 * getIcon() to let the user select an icon. 0029 * 0030 * @short An icon selection dialog. 0031 */ 0032 class KICONTHEMES_EXPORT KIconDialog : public QDialog 0033 { 0034 Q_OBJECT 0035 0036 public: 0037 /** 0038 * Constructs an icon selection dialog using the global icon loader. 0039 * 0040 * @param parent The parent widget. 0041 */ 0042 explicit KIconDialog(QWidget *parent = nullptr); 0043 0044 #if KICONTHEMES_ENABLE_DEPRECATED_SINCE(5, 104) 0045 /** 0046 * Constructs an icon selection dialog using a specific icon loader. 0047 * 0048 * @param loader The icon loader to use. 0049 * @param parent The parent widget. 0050 * 0051 * @deprecated since 5.104, use KIconDialog(QWidget *) instead 0052 */ 0053 KICONTHEMES_DEPRECATED_VERSION(5, 104, "Use KIconDialog(QWidget *) instead") 0054 explicit KIconDialog(KIconLoader *loader, QWidget *parent = nullptr); 0055 #endif 0056 0057 /** 0058 * Destructs the dialog. 0059 */ 0060 ~KIconDialog() override; 0061 0062 /** 0063 * Sets a strict icon size policy for allowed icons. 0064 * 0065 * @param policy When true, only icons of the specified group's 0066 * size in getIcon() are shown. 0067 * When false, icons not available at the desired group's size will 0068 * also be selectable. 0069 */ 0070 void setStrictIconSize(bool policy); 0071 /** 0072 * Returns true if a strict icon size policy is set. 0073 */ 0074 bool strictIconSize() const; 0075 0076 /** 0077 * Sets the location of the custom icon directory. Only local directory 0078 * paths are allowed. 0079 */ 0080 void setCustomLocation(const QString &location); 0081 0082 /** 0083 * Sets the size of the icons to be shown / selected. 0084 * @see KIconLoader::StdSizes 0085 * @see iconSize 0086 */ 0087 void setIconSize(int size); 0088 /** 0089 * Returns the icon size set via setIconSize() or 0, if the default 0090 * icon size will be used. 0091 */ 0092 int iconSize() const; 0093 0094 /** 0095 * Sets the icon that is initially selected in the dialog. 0096 * 0097 * @note Changing this after the dialog has been shown has no effect. 0098 * @note If the given icon cannot be found in the current context, 0099 * no icon will be selected. 0100 * @param iconName The name of the icon to select 0101 * @since 5.89 0102 */ 0103 void setSelectedIcon(const QString &iconName); 0104 0105 /** 0106 * Allows you to set the same parameters as in the class method 0107 * getIcon(), as well as two additional parameters to lock 0108 * the choice between system and user directories and to lock the 0109 * custom icon directory itself. 0110 */ 0111 void setup(KIconLoader::Group group, 0112 KIconLoader::Context context = KIconLoader::Application, 0113 bool strictIconSize = false, 0114 int iconSize = 0, 0115 bool user = false, 0116 bool lockUser = false, 0117 bool lockCustomDir = false); 0118 0119 /** 0120 * exec()utes this modal dialog and returns the name of the selected icon, 0121 * or QString() if the dialog was aborted. 0122 * @returns the name of the icon, suitable for loading with KIconLoader. 0123 * @see getIcon 0124 */ 0125 QString openDialog(); 0126 0127 /** 0128 * show()s this dialog and emits a newIconName(const QString&) signal when 0129 * successful. QString() will be emitted if the dialog was aborted. 0130 */ 0131 void showDialog(); 0132 0133 /** 0134 * Pops up the dialog an lets the user select an icon. 0135 * 0136 * @param group The icon group this icon is intended for. Providing the 0137 * group shows the icons in the dialog with the same appearance as when 0138 * used outside the dialog. 0139 * @param context The initial icon context. Initially, the icons having 0140 * this context are shown in the dialog. The user can change this. 0141 * @param strictIconSize When true, only icons of the specified group's size 0142 * are shown, otherwise icon not available in the desired group's size 0143 * will also be selectable. 0144 * @param iconSize the size of the icons -- the default of the icon group 0145 * if set to 0 0146 * @param user Begin with the "user icons" instead of "system icons". 0147 * @param parent The parent widget of the dialog. 0148 * @param title The title to use for the dialog. 0149 * @return The name of the icon, suitable for loading with KIconLoader. 0150 */ 0151 static QString getIcon(KIconLoader::Group group = KIconLoader::Desktop, 0152 KIconLoader::Context context = KIconLoader::Application, 0153 bool strictIconSize = false, 0154 int iconSize = 0, 0155 bool user = false, 0156 QWidget *parent = nullptr, 0157 const QString &title = QString()); 0158 0159 Q_SIGNALS: 0160 void newIconName(const QString &iconName); 0161 0162 protected Q_SLOTS: 0163 void slotOk(); 0164 0165 private: 0166 std::unique_ptr<class KIconDialogPrivate> const d; 0167 0168 friend class ShowEventFilter; 0169 friend class KIconDialogPrivate; 0170 0171 Q_DISABLE_COPY(KIconDialog) 0172 0173 }; 0174 0175 #endif // KICONDIALOG_H