File indexing completed on 2024-04-28 15:31:56

0001 /*
0002     This file is part of the KDE libraries
0003     SPDX-FileCopyrightText: 1999 Reginald Stadlbauer <reggie@kde.org>
0004     SPDX-FileCopyrightText: 1999 Simon Hausmann <hausmann@kde.org>
0005     SPDX-FileCopyrightText: 2000 Nicolas Hadacek <haadcek@kde.org>
0006     SPDX-FileCopyrightText: 2000 Kurt Granroth <granroth@kde.org>
0007     SPDX-FileCopyrightText: 2000 Michael Koch <koch@kde.org>
0008     SPDX-FileCopyrightText: 2001 Holger Freyther <freyther@kde.org>
0009     SPDX-FileCopyrightText: 2002 Ellis Whitehead <ellis@kde.org>
0010     SPDX-FileCopyrightText: 2003 Andras Mantia <amantia@kde.org>
0011     SPDX-FileCopyrightText: 2005-2006 Hamish Rodda <rodda@kde.org>
0012 
0013     SPDX-License-Identifier: LGPL-2.0-only
0014 */
0015 
0016 #ifndef KACTIONMENU_H
0017 #define KACTIONMENU_H
0018 
0019 #include <QToolButton>
0020 #include <QWidgetAction>
0021 #include <memory>
0022 
0023 #include <kwidgetsaddons_export.h>
0024 
0025 class QMenu;
0026 
0027 /**
0028  * @class KActionMenu kactionmenu.h KActionMenu
0029  *
0030  * A KActionMenu is an action that provides a sub-menu of other actions.
0031  *
0032  * Plugged in a popupmenu, it will create a submenu.
0033  * Plugged in a toolbar, it will create a button with a popup menu.
0034  *
0035  * This is the action used by the XMLGUI since it holds other actions.
0036  * If you want a submenu for selecting one tool among many (without icons), see KSelectAction.
0037  */
0038 class KWIDGETSADDONS_EXPORT KActionMenu : public QWidgetAction
0039 {
0040     Q_OBJECT
0041 #if KWIDGETSADDONS_ENABLE_DEPRECATED_SINCE(5, 77)
0042     Q_PROPERTY(bool delayed READ delayed WRITE setDelayed)
0043     Q_PROPERTY(bool stickyMenu READ stickyMenu WRITE setStickyMenu)
0044 #endif
0045     Q_PROPERTY(QToolButton::ToolButtonPopupMode popupMode READ popupMode WRITE setPopupMode)
0046 
0047 public:
0048     explicit KActionMenu(QObject *parent);
0049     KActionMenu(const QString &text, QObject *parent);
0050     KActionMenu(const QIcon &icon, const QString &text, QObject *parent);
0051     ~KActionMenu() override;
0052 
0053 #if KWIDGETSADDONS_ENABLE_DEPRECATED_SINCE(5, 0)
0054     /**
0055      * @deprecated Since 5.0.
0056      */
0057     KWIDGETSADDONS_DEPRECATED_VERSION(5, 0, "Use KActionMenu::removeAction(QAction*)")
0058     void remove(QAction *);
0059 #endif
0060 
0061     /**
0062      * Adds @p action to this KActionMenu.
0063      * The KActionMenu does not take ownership of @p action.
0064      */
0065     void addAction(QAction *action);
0066     QAction *addSeparator();
0067     void insertAction(QAction *before, QAction *action);
0068     QAction *insertSeparator(QAction *before);
0069     void removeAction(QAction *action);
0070 
0071 #if KWIDGETSADDONS_ENABLE_DEPRECATED_SINCE(5, 0)
0072     /**
0073      * Returns this action's menu as a KMenu, if it is one.
0074      * If none exists, one will be created.
0075      * @deprecated Since 5.0, use menu() instead.
0076      */
0077     KWIDGETSADDONS_DEPRECATED_VERSION(5, 0, "Use KActionMenu::menu()")
0078     inline QMenu *popupMenu()
0079     {
0080         return menu();
0081     }
0082 #endif
0083 
0084 #if KWIDGETSADDONS_ENABLE_DEPRECATED_SINCE(5, 77)
0085     /**
0086      * Returns true if this action creates a delayed popup menu
0087      * when plugged in a KToolBar.
0088      *
0089      * @deprecated Since 5.77, use popupMode() instead.
0090      */
0091     KWIDGETSADDONS_DEPRECATED_VERSION(5, 77, "Use KActionMenu::popupMode()")
0092     bool delayed() const;
0093 #endif
0094 
0095 #if KWIDGETSADDONS_ENABLE_DEPRECATED_SINCE(5, 77)
0096     /**
0097      * If set to true, this action will create a delayed popup menu
0098      * when plugged in a KToolBar. Otherwise it creates a normal popup.
0099      * Default: true
0100      *
0101      * Remember that if the "main" action (the toolbar button itself)
0102      * cannot be clicked, then you should call setDelayed(false).
0103      *
0104      * In the other case, if the main action can be clicked, it can only happen
0105      * in a toolbar: in a menu, the parent of a submenu can't be activated.
0106      * To get a "normal" menu item when plugged a menu (and no submenu)
0107      * use KToolBarPopupAction.
0108      *
0109      * @deprecated Since 5.77, use setPopupMode() instead.
0110      */
0111     KWIDGETSADDONS_DEPRECATED_VERSION(5, 77, "Use KActionMenu::setPopupMode()")
0112     void setDelayed(bool delayed);
0113 #endif
0114 
0115 #if KWIDGETSADDONS_ENABLE_DEPRECATED_SINCE(5, 77)
0116     /**
0117      * Returns true if this action creates a sticky popup menu.
0118      * @see setStickyMenu().
0119      * @deprecated Since 5.77, use popupMode() instead.
0120      */
0121     KWIDGETSADDONS_DEPRECATED_VERSION(5, 77, "Use KActionMenu::popupMode()")
0122     bool stickyMenu() const;
0123 #endif
0124 
0125 #if KWIDGETSADDONS_ENABLE_DEPRECATED_SINCE(5, 77)
0126     /**
0127      * If set to true, this action will create a sticky popup menu
0128      * when plugged in a KToolBar.
0129      * "Sticky", means it's visible until a selection is made or the mouse is
0130      * clicked elsewhere. This feature allows you to make a selection without
0131      * having to press and hold down the mouse while making a selection.
0132      * Default: sticky.
0133      *
0134      * @deprecated Since 5.77, use setPopupMode() instead.
0135      */
0136     KWIDGETSADDONS_DEPRECATED_VERSION(5, 77, "Use KActionMenu::setPopupMode()")
0137     void setStickyMenu(bool sticky);
0138 #endif
0139 
0140     /**
0141      * The currently used popup mode when plugged in a KToolBar.
0142      *
0143      * @see setPopupMode()
0144      *
0145      * @since 5.77
0146      */
0147     QToolButton::ToolButtonPopupMode popupMode() const;
0148 
0149     /**
0150      * Determines the popup mode when plugged in a KToolBar.
0151      *
0152      * Options are:
0153      *  - QToolButton::InstantPopup
0154      *    Clicking anywhere on the toolbar button opens the popup menu.
0155      *  - QToolButton::DelayedPopup (Default)
0156      *    Clicking anywhere on the toolbar button triggers the default action.
0157      *    Clicking and holding the toolbar button opens the popup menu instead.
0158      *  - QToolButton::MenuButtonPopup
0159      *    The toolbar button is split in a main button (triggers default action)
0160      *    and an arrow button (opens the popup menu).
0161      *
0162      * @see QToolButton
0163      *
0164      * @since 5.77
0165      */
0166     void setPopupMode(QToolButton::ToolButtonPopupMode popupMode);
0167 
0168     QWidget *createWidget(QWidget *parent) override;
0169 
0170 private:
0171     std::unique_ptr<class KActionMenuPrivate> const d;
0172 };
0173 
0174 #endif