File indexing completed on 2024-04-21 15:05:48

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 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
0057     QMimeData *mimeData(const QList<QListWidgetItem *> items) const override;
0058 #else
0059     QMimeData *mimeData(const QList<QListWidgetItem *> &items) const override;
0060 #endif
0061 
0062     bool dropMimeData(int index, const QMimeData *data, Qt::DropAction action) override;
0063 
0064     // Skip internal dnd handling in QListWidget ---- how is one supposed to figure this out
0065     // without reading the QListWidget code !?
0066     void dropEvent(QDropEvent *ev) override
0067     {
0068         QAbstractItemView::dropEvent(ev);
0069     }
0070 
0071 private:
0072     bool m_activeList;
0073 };
0074 
0075 class IconTextEditDialog : public QDialog
0076 {
0077     Q_OBJECT
0078 public:
0079     explicit IconTextEditDialog(QWidget *parent = nullptr);
0080 
0081 public:
0082     void setIconText(const QString &text);
0083     QString iconText() const;
0084 
0085     void setTextAlongsideIconHidden(bool hidden);
0086     bool textAlongsideIconHidden() const;
0087 
0088 private Q_SLOTS:
0089     void slotTextChanged(const QString &text);
0090 
0091 private:
0092     QLineEdit *m_lineEdit;
0093     QCheckBox *m_cbHidden;
0094     QDialogButtonBox *m_buttonBox;
0095 };
0096 
0097 /**
0098  * @short A widget used to customize or configure toolbars
0099  *
0100  * This is the widget that does all of the work for the
0101  * KEditToolBar dialog.  In most cases, you will want to use the
0102  * dialog instead of this widget directly.
0103  *
0104  * Typically, you would use this widget only if you wanted to embed
0105  * the toolbar editing directly into your existing configure or
0106  * preferences dialog.
0107  *
0108  * This widget only works if your application uses the XML UI
0109  * framework for creating menus and toolbars.  It depends on the XML
0110  * files to describe the toolbar layouts and it requires the actions
0111  * to determine which buttons are active.
0112  *
0113  * @author Kurt Granroth <granroth@kde.org>
0114  * @internal
0115  */
0116 class KEditToolBarWidget : public QWidget, virtual public KXMLGUIClient
0117 {
0118     Q_OBJECT
0119 public:
0120     /**
0121      * Old constructor for apps that do not use components.
0122      * This constructor is somewhat deprecated, since it doesn't work
0123      * with any KXMLGuiClient being added to the mainwindow.
0124      * You really want to use the other constructor.
0125      *
0126      * You @em must pass along your collection of actions (some of which appear in your toolbars).
0127      * Then call old-style load.
0128      *
0129      * @param collection The collection of actions to work on
0130      * @param parent This widget's parent
0131      */
0132     explicit KEditToolBarWidget(KActionCollection *collection, QWidget *parent = nullptr);
0133 
0134     /**
0135      * Main constructor.
0136      *
0137      * Use this like so:
0138      * \code
0139      * KEditToolBarWidget widget(this);
0140      * widget.load(factory());
0141      * ...
0142      * \endcode
0143      *
0144      * @param factory Your application's factory object
0145      * @param parent This widget's parent
0146      */
0147     explicit KEditToolBarWidget(QWidget *parent = nullptr);
0148 
0149     /**
0150      * Destructor.  Note that any changes done in this widget will
0151      * @em NOT be saved in the destructor.  You @em must call save()
0152      * to do that.
0153      */
0154     ~KEditToolBarWidget() override;
0155 
0156     /**
0157      * Old-style load.
0158      *
0159      * Loads the toolbar configuration into the widget. Should be called before being shown.
0160      *
0161      * @param resourceFile the name (absolute or relative) of your application's UI
0162      * resource file.  If it is left blank, then the resource file: share/apps/appname/appnameui.rc
0163      * is used.  This is the same resource file that is used by the
0164      * default createGUI function in KMainWindow so you're usually
0165      * pretty safe in leaving it blank.
0166      *
0167      * @param global controls whether or not the
0168      * global resource file is used.  If this is true, then you may
0169      * edit all of the actions in your toolbars -- global ones and
0170      * local one.  If it is false, then you may edit only your
0171      * application's entries.  The only time you should set this to
0172      * false is if your application does not use the global resource
0173      * file at all (very rare)
0174      *
0175      * @param defaultToolBar the default toolbar that will be selected when the dialog is shown.
0176      * If not set, or QString() is passed in, the global default tool bar name
0177      * will be used.
0178      *
0179      * @see KEditToolBar
0180      */
0181     void load(const QString &resourceFile, bool global = true, const QString &defaultToolBar = QString());
0182 
0183     /**
0184      * Loads the toolbar configuration into the widget. Should be called before being shown.
0185      *
0186      * @param factory pointer to the XML GUI factory object for your application.
0187      * It contains a list of all of the GUI clients (along with the action
0188      * collections and xml files) and the toolbar editor uses that.
0189      *
0190      * @param defaultToolBar the default toolbar that will be selected when the dialog is shown.
0191      * If not set, or QString() is passed in, the global default tool bar name
0192      * will be used.
0193      *
0194      * @see KEditToolBar
0195      */
0196     void load(KXMLGUIFactory *factory, const QString &defaultToolBar = QString());
0197 
0198     /**
0199      * @internal Reimplemented for internal purposes.
0200      */
0201     KActionCollection *actionCollection() const override;
0202 
0203     /**
0204      * Save any changes the user made.  The file will be in the user's
0205      * local directory (usually $HOME/.kde/share/apps/\<appname\>).  The
0206      * filename will be the one specified in the constructor.. or the
0207      * made up one if the filename was an empty string.
0208      *
0209      */
0210     void save();
0211 
0212     /**
0213      * Remove and re-add all KMXLGUIClients to update the GUI
0214      */
0215     void rebuildKXMLGUIClients();
0216 
0217 Q_SIGNALS:
0218     /**
0219      * Emitted whenever any modifications are made by the user.
0220      */
0221     void enableOk(bool);
0222 
0223 private:
0224     friend class KEditToolBarWidgetPrivate;
0225     KEditToolBarWidgetPrivate *const d;
0226 
0227     Q_DISABLE_COPY(KEditToolBarWidget)
0228 };
0229 
0230 }
0231 
0232 #endif