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
16class QDialogButtonBox;
17class QLineEdit;
18class QCheckBox;
19
20namespace KDEPrivate
21{
22class ToolBarItem;
23class KEditToolBarWidgetPrivate;
24
25class ToolBarListWidget : public QListWidget
26{
27 Q_OBJECT
28public:
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
43Q_SIGNALS:
44 void dropped(ToolBarListWidget *list, int index, ToolBarItem *item, bool sourceIsActiveList);
45
46protected:
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
67private:
68 bool m_activeList;
69};
70
71class IconTextEditDialog : public QDialog
72{
73 Q_OBJECT
74public:
75 explicit IconTextEditDialog(QWidget *parent = nullptr);
76
77public:
78 void setIconText(const QString &text);
79 QString iconText() const;
80
81 void setTextAlongsideIconHidden(bool hidden);
82 bool textAlongsideIconHidden() const;
83
84private Q_SLOTS:
85 void slotTextChanged(const QString &text);
86
87private:
88 QLineEdit *m_lineEdit;
89 QCheckBox *m_cbHidden;
90 QDialogButtonBox *m_buttonBox;
91};
92
93/*!
94 * \brief 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 * \internal
110 */
111class KEditToolBarWidget : public QWidget, virtual public KXMLGUIClient
112{
113 Q_OBJECT
114public:
115 /*!
116 * Old constructor for apps that do not use components.
117 * This constructor is somewhat deprecated, since it doesn't work
118 * with any KXMLGuiClient being added to the mainwindow.
119 * You really want to use the other constructor.
120 *
121 * You @em must pass along your collection of actions (some of which appear in your toolbars).
122 * Then call old-style load.
123 *
124 * @param collection The collection of actions to work on
125 * @param parent This widget's parent
126 */
127 explicit KEditToolBarWidget(KActionCollection *collection, QWidget *parent = nullptr);
128
129 /*!
130 * Main constructor.
131 *
132 * Use this like so:
133 * \code
134 * KEditToolBarWidget widget(this);
135 * widget.load(factory());
136 * ...
137 * \endcode
138 *
139 * @param factory Your application's factory object
140 * @param parent This widget's parent
141 */
142 explicit KEditToolBarWidget(QWidget *parent = nullptr);
143
144 /*!
145 * Destructor. Note that any changes done in this widget will
146 * @em NOT be saved in the destructor. You @em must call save()
147 * to do that.
148 */
149 ~KEditToolBarWidget() override;
150
151 /*!
152 * Old-style load.
153 *
154 * Loads the toolbar configuration into the widget. Should be called before being shown.
155 *
156 * @param resourceFile the name (absolute or relative) of your application's UI
157 * resource file. If it is left blank, then the resource file: share/apps/appname/appnameui.rc
158 * is used. This is the same resource file that is used by the
159 * default createGUI function in KMainWindow so you're usually
160 * pretty safe in leaving it blank.
161 *
162 * @param global controls whether or not the
163 * global resource file is used. If this is true, then you may
164 * edit all of the actions in your toolbars -- global ones and
165 * local one. If it is false, then you may edit only your
166 * application's entries. The only time you should set this to
167 * false is if your application does not use the global resource
168 * file at all (very rare)
169 *
170 * @param defaultToolBar the default toolbar that will be selected when the dialog is shown.
171 * If not set, or QString() is passed in, the global default tool bar name
172 * will be used.
173 *
174 * @see KEditToolBar
175 */
176 void load(const QString &resourceFile, bool global = true, const QString &defaultToolBar = QString());
177
178 /*!
179 * Loads the toolbar configuration into the widget. Should be called before being shown.
180 *
181 * @param factory pointer to the XML GUI factory object for your application.
182 * It contains a list of all of the GUI clients (along with the action
183 * collections and xml files) and the toolbar editor uses that.
184 *
185 * @param defaultToolBar the default toolbar that will be selected when the dialog is shown.
186 * If not set, or QString() is passed in, the global default tool bar name
187 * will be used.
188 *
189 * @see KEditToolBar
190 */
191 void load(KXMLGUIFactory *factory, const QString &defaultToolBar = QString());
192
193 /*!
194 * @internal Reimplemented for internal purposes.
195 */
196 KActionCollection *actionCollection() const override;
197
198 /*!
199 * Save any changes the user made. The file will be in the user's
200 * local directory (usually $HOME/.kde/share/apps/\<appname\>). The
201 * filename will be the one specified in the constructor.. or the
202 * made up one if the filename was an empty string.
203 *
204 */
205 void save();
206
207 /*!
208 * Remove and re-add all KMXLGUIClients to update the GUI
209 */
210 void rebuildKXMLGUIClients();
211
212Q_SIGNALS:
213 /*!
214 * Emitted whenever any modifications are made by the user.
215 */
216 void enableOk(bool);
217
218private:
219 friend class KEditToolBarWidgetPrivate;
220 KEditToolBarWidgetPrivate *const d;
221
222 Q_DISABLE_COPY(KEditToolBarWidget)
223};
224
225}
226
227#endif
228

source code of kxmlgui/src/kedittoolbar_p.h