File indexing completed on 2025-02-09 04:30:13
0001 /* 0002 This file is part of the KDE libraries 0003 SPDX-FileCopyrightText: 2000 Kurt Granroth <granroth@kde.org> 0004 SPDX-FileCopyrightText: 2006 Hamish Rodda <rodda@kde.org> 0005 0006 SPDX-License-Identifier: LGPL-2.0-only 0007 */ 0008 0009 #ifndef KEDITTOOLBARP_H 0010 #define KEDITTOOLBARP_H 0011 0012 #include "kxmlguiclient.h" 0013 #include <QDialog> 0014 #include <QListWidget> 0015 0016 class QDialogButtonBox; 0017 class QLineEdit; 0018 class QCheckBox; 0019 0020 namespace KDEPrivate 0021 { 0022 class ToolBarItem; 0023 class KEditToolBarWidgetPrivate; 0024 0025 class ToolBarListWidget : public QListWidget 0026 { 0027 Q_OBJECT 0028 public: 0029 explicit ToolBarListWidget(QWidget *parent = nullptr); 0030 0031 void makeVisible(QListWidgetItem *item) 0032 { 0033 scrollTo(indexFromItem(item)); 0034 } 0035 0036 ToolBarItem *currentItem() const; 0037 0038 void setActiveList(bool isActiveList) 0039 { 0040 m_activeList = isActiveList; 0041 } 0042 0043 Q_SIGNALS: 0044 void dropped(ToolBarListWidget *list, int index, ToolBarItem *item, bool sourceIsActiveList); 0045 0046 protected: 0047 Qt::DropActions supportedDropActions() const override 0048 { 0049 return Qt::MoveAction; 0050 } 0051 QStringList mimeTypes() const override 0052 { 0053 return QStringList() << QStringLiteral("application/x-kde-action-list"); 0054 } 0055 0056 QMimeData *mimeData(const QList<QListWidgetItem *> &items) const override; 0057 0058 bool dropMimeData(int index, const QMimeData *data, Qt::DropAction action) override; 0059 0060 // Skip internal dnd handling in QListWidget ---- how is one supposed to figure this out 0061 // without reading the QListWidget code !? 0062 void dropEvent(QDropEvent *ev) override 0063 { 0064 QAbstractItemView::dropEvent(ev); 0065 } 0066 0067 private: 0068 bool m_activeList; 0069 }; 0070 0071 class IconTextEditDialog : public QDialog 0072 { 0073 Q_OBJECT 0074 public: 0075 explicit IconTextEditDialog(QWidget *parent = nullptr); 0076 0077 public: 0078 void setIconText(const QString &text); 0079 QString iconText() const; 0080 0081 void setTextAlongsideIconHidden(bool hidden); 0082 bool textAlongsideIconHidden() const; 0083 0084 private Q_SLOTS: 0085 void slotTextChanged(const QString &text); 0086 0087 private: 0088 QLineEdit *m_lineEdit; 0089 QCheckBox *m_cbHidden; 0090 QDialogButtonBox *m_buttonBox; 0091 }; 0092 0093 /** 0094 * @short A widget used to customize or configure toolbars 0095 * 0096 * This is the widget that does all of the work for the 0097 * KEditToolBar dialog. In most cases, you will want to use the 0098 * dialog instead of this widget directly. 0099 * 0100 * Typically, you would use this widget only if you wanted to embed 0101 * the toolbar editing directly into your existing configure or 0102 * preferences dialog. 0103 * 0104 * This widget only works if your application uses the XML UI 0105 * framework for creating menus and toolbars. It depends on the XML 0106 * files to describe the toolbar layouts and it requires the actions 0107 * to determine which buttons are active. 0108 * 0109 * @author Kurt Granroth <granroth@kde.org> 0110 * @internal 0111 */ 0112 class KEditToolBarWidget : public QWidget, virtual public KXMLGUIClient 0113 { 0114 Q_OBJECT 0115 public: 0116 /** 0117 * Old constructor for apps that do not use components. 0118 * This constructor is somewhat deprecated, since it doesn't work 0119 * with any KXMLGuiClient being added to the mainwindow. 0120 * You really want to use the other constructor. 0121 * 0122 * You @em must pass along your collection of actions (some of which appear in your toolbars). 0123 * Then call old-style load. 0124 * 0125 * @param collection The collection of actions to work on 0126 * @param parent This widget's parent 0127 */ 0128 explicit KEditToolBarWidget(KActionCollection *collection, QWidget *parent = nullptr); 0129 0130 /** 0131 * Main constructor. 0132 * 0133 * Use this like so: 0134 * \code 0135 * KEditToolBarWidget widget(this); 0136 * widget.load(factory()); 0137 * ... 0138 * \endcode 0139 * 0140 * @param factory Your application's factory object 0141 * @param parent This widget's parent 0142 */ 0143 explicit KEditToolBarWidget(QWidget *parent = nullptr); 0144 0145 /** 0146 * Destructor. Note that any changes done in this widget will 0147 * @em NOT be saved in the destructor. You @em must call save() 0148 * to do that. 0149 */ 0150 ~KEditToolBarWidget() override; 0151 0152 /** 0153 * Old-style load. 0154 * 0155 * Loads the toolbar configuration into the widget. Should be called before being shown. 0156 * 0157 * @param resourceFile the name (absolute or relative) of your application's UI 0158 * resource file. If it is left blank, then the resource file: share/apps/appname/appnameui.rc 0159 * is used. This is the same resource file that is used by the 0160 * default createGUI function in KMainWindow so you're usually 0161 * pretty safe in leaving it blank. 0162 * 0163 * @param global controls whether or not the 0164 * global resource file is used. If this is true, then you may 0165 * edit all of the actions in your toolbars -- global ones and 0166 * local one. If it is false, then you may edit only your 0167 * application's entries. The only time you should set this to 0168 * false is if your application does not use the global resource 0169 * file at all (very rare) 0170 * 0171 * @param defaultToolBar the default toolbar that will be selected when the dialog is shown. 0172 * If not set, or QString() is passed in, the global default tool bar name 0173 * will be used. 0174 * 0175 * @see KEditToolBar 0176 */ 0177 void load(const QString &resourceFile, bool global = true, const QString &defaultToolBar = QString()); 0178 0179 /** 0180 * Loads the toolbar configuration into the widget. Should be called before being shown. 0181 * 0182 * @param factory pointer to the XML GUI factory object for your application. 0183 * It contains a list of all of the GUI clients (along with the action 0184 * collections and xml files) and the toolbar editor uses that. 0185 * 0186 * @param defaultToolBar the default toolbar that will be selected when the dialog is shown. 0187 * If not set, or QString() is passed in, the global default tool bar name 0188 * will be used. 0189 * 0190 * @see KEditToolBar 0191 */ 0192 void load(KXMLGUIFactory *factory, const QString &defaultToolBar = QString()); 0193 0194 /** 0195 * @internal Reimplemented for internal purposes. 0196 */ 0197 KActionCollection *actionCollection() const override; 0198 0199 /** 0200 * Save any changes the user made. The file will be in the user's 0201 * local directory (usually $HOME/.kde/share/apps/\<appname\>). The 0202 * filename will be the one specified in the constructor.. or the 0203 * made up one if the filename was an empty string. 0204 * 0205 */ 0206 void save(); 0207 0208 /** 0209 * Remove and re-add all KMXLGUIClients to update the GUI 0210 */ 0211 void rebuildKXMLGUIClients(); 0212 0213 Q_SIGNALS: 0214 /** 0215 * Emitted whenever any modifications are made by the user. 0216 */ 0217 void enableOk(bool); 0218 0219 private: 0220 friend class KEditToolBarWidgetPrivate; 0221 KEditToolBarWidgetPrivate *const d; 0222 0223 Q_DISABLE_COPY(KEditToolBarWidget) 0224 }; 0225 0226 } 0227 0228 #endif