File indexing completed on 2024-04-28 03:59:16

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     SPDX-FileCopyrightText: 2023 Kai Uwe Broulik <kde@broulik.de>
0013 
0014     SPDX-License-Identifier: LGPL-2.0-only
0015 */
0016 
0017 #ifndef KTOOLBARPOPUPACTION_H
0018 #define KTOOLBARPOPUPACTION_H
0019 
0020 #include <QToolButton>
0021 #include <QWidgetAction>
0022 #include <memory>
0023 
0024 #include <kwidgetsaddons_export.h>
0025 
0026 class QMenu;
0027 
0028 /**
0029  * @class KToolBarPopupAction ktoolbarpopupaction.h KToolBarPopupAction
0030  *
0031  * This action is a normal action everywhere, except in a toolbar
0032  * where it also has a popupmenu (optionally delayed). This action is designed
0033  * for history actions (back/forward, undo/redo) and for any other action
0034  * that has more detail in a toolbar than in a menu (e.g. tool chooser
0035  * with "Other" leading to a dialog...).
0036  *
0037  * In contrast to KActionMenu, this action is a \e simple menuitem when plugged
0038  * into a menu, and has a popup only in a toolbar.
0039  *
0040  * Use cases include Back/Forward, and Undo/Redo. Simple click is what's most commonly
0041  * used, and enough for menus, but in toolbars there is \e also an optional popup
0042  * to go back N steps or undo N steps.
0043  *
0044  * @note Add actions to the popupMenu(), don't use setMenu().
0045  */
0046 class KWIDGETSADDONS_EXPORT KToolBarPopupAction : public QWidgetAction
0047 {
0048     Q_OBJECT
0049     Q_PROPERTY(PopupMode popupMode READ popupMode WRITE setPopupMode)
0050 
0051 public:
0052     /**
0053      * The menu popup mode.
0054      *
0055      * Default is MenuButtonPopup.
0056      *
0057      * @sa QToolButton::ToolButtonPopupMode
0058      *
0059      * @since 6.0
0060      */
0061     enum PopupMode {
0062         NoPopup = -1, ///< Behave as if the button had no menu.
0063         DelayedPopup = QToolButton::DelayedPopup, ///< Clicking anywhere on the toolbar button triggers the default action.
0064                                                   ///< Clicking and holding the toolbar button opens the popup menu instead.
0065         MenuButtonPopup = QToolButton::MenuButtonPopup, ///< The toolbar button is split in a main button (triggers default action)
0066                                                         ///< and an arrow button (opens the popup menu).
0067         InstantPopup = QToolButton::InstantPopup, ///< Clicking anywhere on the toolbar button opens the popup menu.
0068     };
0069     Q_ENUM(PopupMode)
0070 
0071     // Not all constructors - because we need an icon, since this action only makes
0072     // sense when being plugged at least in a toolbar.
0073     /**
0074      * Create a KToolBarPopupAction, with a text, an icon, a
0075      * parent and a name.
0076      *
0077      * @param icon The icon to display.
0078      * @param text The text that will be displayed.
0079      * @param parent This action's parent.
0080      */
0081     KToolBarPopupAction(const QIcon &icon, const QString &text, QObject *parent);
0082 
0083     /**
0084      * Destroys the toolbar popup action.
0085      */
0086     ~KToolBarPopupAction() override;
0087 
0088     /**
0089      * The popup menu that is shown when clicking (some time) on the toolbar
0090      * button. You may want to plug items into it on creation, or connect to
0091      * aboutToShow for a more dynamic menu.
0092      *
0093      * @note menu() is null on this action by default and using setMenu()
0094      * will effectively turn this action into a regular action with a submenu.
0095      *
0096      * @since 6.0
0097      */
0098     QMenu *popupMenu() const;
0099 
0100     /**
0101      * The popup mode of the toolbar button.
0102      *
0103      * @see setPopupMode()
0104      *
0105      * @since 6.0
0106      */
0107     PopupMode popupMode() const;
0108 
0109     /**
0110      * Determines the popup mode of the toolbar button.
0111      * @see PopupMode
0112      *
0113      * @since 6.0
0114      */
0115     void setPopupMode(PopupMode popupMode);
0116 
0117     /**
0118      * Reimplemented from QWidgetAction.
0119      */
0120     QWidget *createWidget(QWidget *parent) override;
0121 
0122 private:
0123     std::unique_ptr<class KToolBarPopupActionPrivate> const d;
0124 };
0125 
0126 #endif