File indexing completed on 2024-04-28 03:58:58

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     Q_PROPERTY(QToolButton::ToolButtonPopupMode popupMode READ popupMode WRITE setPopupMode)
0042 
0043 public:
0044     explicit KActionMenu(QObject *parent);
0045     KActionMenu(const QString &text, QObject *parent);
0046     KActionMenu(const QIcon &icon, const QString &text, QObject *parent);
0047     ~KActionMenu() override;
0048 
0049     /**
0050      * Adds @p action to this KActionMenu.
0051      * The KActionMenu does not take ownership of @p action.
0052      */
0053     void addAction(QAction *action);
0054     QAction *addSeparator();
0055     void insertAction(QAction *before, QAction *action);
0056     QAction *insertSeparator(QAction *before);
0057     void removeAction(QAction *action);
0058 
0059     /**
0060      * The currently used popup mode when plugged in a KToolBar.
0061      *
0062      * @see setPopupMode()
0063      *
0064      * @since 5.77
0065      */
0066     QToolButton::ToolButtonPopupMode popupMode() const;
0067 
0068     /**
0069      * Determines the popup mode when plugged in a KToolBar.
0070      *
0071      * Options are:
0072      *  - QToolButton::InstantPopup
0073      *    Clicking anywhere on the toolbar button opens the popup menu.
0074      *  - QToolButton::DelayedPopup (Default)
0075      *    Clicking anywhere on the toolbar button triggers the default action.
0076      *    Clicking and holding the toolbar button opens the popup menu instead.
0077      *  - QToolButton::MenuButtonPopup
0078      *    The toolbar button is split in a main button (triggers default action)
0079      *    and an arrow button (opens the popup menu).
0080      *
0081      * @see QToolButton
0082      *
0083      * @since 5.77
0084      */
0085     void setPopupMode(QToolButton::ToolButtonPopupMode popupMode);
0086 
0087     QWidget *createWidget(QWidget *parent) override;
0088 
0089 private:
0090     std::unique_ptr<class KActionMenuPrivate> const d;
0091 };
0092 
0093 #endif