1 | /* |
2 | This file is part of the KDE libraries |
3 | SPDX-FileCopyrightText: 2000 Kurt Granroth <granroth@kde.org> |
4 | SPDX-FileCopyrightText: 2006 Hamish Rodda <rodda@kde.org> |
5 | |
6 | SPDX-License-Identifier: LGPL-2.0-only |
7 | */ |
8 | |
9 | #ifndef KEDITTOOLBARP_H |
10 | #define KEDITTOOLBARP_H |
11 | |
12 | #include "kxmlguiclient.h" |
13 | #include <QDialog> |
14 | #include <QListWidget> |
15 | |
16 | class QDialogButtonBox; |
17 | class QLineEdit; |
18 | class QCheckBox; |
19 | |
20 | namespace KDEPrivate |
21 | { |
22 | class ToolBarItem; |
23 | class KEditToolBarWidgetPrivate; |
24 | |
25 | class ToolBarListWidget : public QListWidget |
26 | { |
27 | Q_OBJECT |
28 | public: |
29 | explicit ToolBarListWidget(QWidget *parent = nullptr); |
30 | |
31 | void makeVisible(QListWidgetItem *item) |
32 | { |
33 | scrollTo(index: indexFromItem(item)); |
34 | } |
35 | |
36 | ToolBarItem *currentItem() const; |
37 | |
38 | void setActiveList(bool isActiveList) |
39 | { |
40 | m_activeList = isActiveList; |
41 | } |
42 | |
43 | Q_SIGNALS: |
44 | void dropped(ToolBarListWidget *list, int index, ToolBarItem *item, bool sourceIsActiveList); |
45 | |
46 | protected: |
47 | Qt::DropActions supportedDropActions() const override |
48 | { |
49 | return Qt::MoveAction; |
50 | } |
51 | QStringList mimeTypes() const override |
52 | { |
53 | return QStringList() << QStringLiteral("application/x-kde-action-list" ); |
54 | } |
55 | |
56 | QMimeData *mimeData(const QList<QListWidgetItem *> &items) const override; |
57 | |
58 | bool dropMimeData(int index, const QMimeData *data, Qt::DropAction action) override; |
59 | |
60 | // Skip internal dnd handling in QListWidget ---- how is one supposed to figure this out |
61 | // without reading the QListWidget code !? |
62 | void dropEvent(QDropEvent *ev) override |
63 | { |
64 | QAbstractItemView::dropEvent(event: ev); |
65 | } |
66 | |
67 | private: |
68 | bool m_activeList; |
69 | }; |
70 | |
71 | class IconTextEditDialog : public QDialog |
72 | { |
73 | Q_OBJECT |
74 | public: |
75 | explicit IconTextEditDialog(QWidget *parent = nullptr); |
76 | |
77 | public: |
78 | void setIconText(const QString &text); |
79 | QString iconText() const; |
80 | |
81 | void setTextAlongsideIconHidden(bool hidden); |
82 | bool textAlongsideIconHidden() const; |
83 | |
84 | private Q_SLOTS: |
85 | void slotTextChanged(const QString &text); |
86 | |
87 | private: |
88 | QLineEdit *m_lineEdit; |
89 | QCheckBox *m_cbHidden; |
90 | QDialogButtonBox *m_buttonBox; |
91 | }; |
92 | |
93 | /** |
94 | * @short A widget used to customize or configure toolbars |
95 | * |
96 | * This is the widget that does all of the work for the |
97 | * KEditToolBar dialog. In most cases, you will want to use the |
98 | * dialog instead of this widget directly. |
99 | * |
100 | * Typically, you would use this widget only if you wanted to embed |
101 | * the toolbar editing directly into your existing configure or |
102 | * preferences dialog. |
103 | * |
104 | * This widget only works if your application uses the XML UI |
105 | * framework for creating menus and toolbars. It depends on the XML |
106 | * files to describe the toolbar layouts and it requires the actions |
107 | * to determine which buttons are active. |
108 | * |
109 | * @author Kurt Granroth <granroth@kde.org> |
110 | * @internal |
111 | */ |
112 | class KEditToolBarWidget : public QWidget, virtual public KXMLGUIClient |
113 | { |
114 | Q_OBJECT |
115 | public: |
116 | /** |
117 | * Old constructor for apps that do not use components. |
118 | * This constructor is somewhat deprecated, since it doesn't work |
119 | * with any KXMLGuiClient being added to the mainwindow. |
120 | * You really want to use the other constructor. |
121 | * |
122 | * You @em must pass along your collection of actions (some of which appear in your toolbars). |
123 | * Then call old-style load. |
124 | * |
125 | * @param collection The collection of actions to work on |
126 | * @param parent This widget's parent |
127 | */ |
128 | explicit KEditToolBarWidget(KActionCollection *collection, QWidget *parent = nullptr); |
129 | |
130 | /** |
131 | * Main constructor. |
132 | * |
133 | * Use this like so: |
134 | * \code |
135 | * KEditToolBarWidget widget(this); |
136 | * widget.load(factory()); |
137 | * ... |
138 | * \endcode |
139 | * |
140 | * @param factory Your application's factory object |
141 | * @param parent This widget's parent |
142 | */ |
143 | explicit KEditToolBarWidget(QWidget *parent = nullptr); |
144 | |
145 | /** |
146 | * Destructor. Note that any changes done in this widget will |
147 | * @em NOT be saved in the destructor. You @em must call save() |
148 | * to do that. |
149 | */ |
150 | ~KEditToolBarWidget() override; |
151 | |
152 | /** |
153 | * Old-style load. |
154 | * |
155 | * Loads the toolbar configuration into the widget. Should be called before being shown. |
156 | * |
157 | * @param resourceFile the name (absolute or relative) of your application's UI |
158 | * resource file. If it is left blank, then the resource file: share/apps/appname/appnameui.rc |
159 | * is used. This is the same resource file that is used by the |
160 | * default createGUI function in KMainWindow so you're usually |
161 | * pretty safe in leaving it blank. |
162 | * |
163 | * @param global controls whether or not the |
164 | * global resource file is used. If this is true, then you may |
165 | * edit all of the actions in your toolbars -- global ones and |
166 | * local one. If it is false, then you may edit only your |
167 | * application's entries. The only time you should set this to |
168 | * false is if your application does not use the global resource |
169 | * file at all (very rare) |
170 | * |
171 | * @param defaultToolBar the default toolbar that will be selected when the dialog is shown. |
172 | * If not set, or QString() is passed in, the global default tool bar name |
173 | * will be used. |
174 | * |
175 | * @see KEditToolBar |
176 | */ |
177 | void load(const QString &resourceFile, bool global = true, const QString &defaultToolBar = QString()); |
178 | |
179 | /** |
180 | * Loads the toolbar configuration into the widget. Should be called before being shown. |
181 | * |
182 | * @param factory pointer to the XML GUI factory object for your application. |
183 | * It contains a list of all of the GUI clients (along with the action |
184 | * collections and xml files) and the toolbar editor uses that. |
185 | * |
186 | * @param defaultToolBar the default toolbar that will be selected when the dialog is shown. |
187 | * If not set, or QString() is passed in, the global default tool bar name |
188 | * will be used. |
189 | * |
190 | * @see KEditToolBar |
191 | */ |
192 | void load(KXMLGUIFactory *factory, const QString &defaultToolBar = QString()); |
193 | |
194 | /** |
195 | * @internal Reimplemented for internal purposes. |
196 | */ |
197 | KActionCollection *actionCollection() const override; |
198 | |
199 | /** |
200 | * Save any changes the user made. The file will be in the user's |
201 | * local directory (usually $HOME/.kde/share/apps/\<appname\>). The |
202 | * filename will be the one specified in the constructor.. or the |
203 | * made up one if the filename was an empty string. |
204 | * |
205 | */ |
206 | void save(); |
207 | |
208 | /** |
209 | * Remove and re-add all KMXLGUIClients to update the GUI |
210 | */ |
211 | void rebuildKXMLGUIClients(); |
212 | |
213 | Q_SIGNALS: |
214 | /** |
215 | * Emitted whenever any modifications are made by the user. |
216 | */ |
217 | void enableOk(bool); |
218 | |
219 | private: |
220 | friend class KEditToolBarWidgetPrivate; |
221 | KEditToolBarWidgetPrivate *const d; |
222 | |
223 | Q_DISABLE_COPY(KEditToolBarWidget) |
224 | }; |
225 | |
226 | } |
227 | |
228 | #endif |
229 | |