File indexing completed on 2024-04-28 15:32:15

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 KTOGGLEACTION_H
0017 #define KTOGGLEACTION_H
0018 
0019 #include <QAction>
0020 #include <memory>
0021 
0022 #include <kwidgetsaddons_export.h>
0023 
0024 class KGuiItem;
0025 class KToggleActionPrivate;
0026 
0027 /**
0028  *  @class KToggleAction ktoggleaction.h KToggleAction
0029  *
0030  *  @short Checkbox like action.
0031  *
0032  *  This action provides two states: checked or not.
0033  *
0034  */
0035 class KWIDGETSADDONS_EXPORT KToggleAction : public QAction
0036 {
0037     Q_OBJECT
0038 
0039 public:
0040     /**
0041      * Constructs an action with the specified parent.
0042      *
0043      * @param parent The action's parent object.
0044      */
0045     explicit KToggleAction(QObject *parent);
0046 
0047     /**
0048      * Constructs an action with text; a shortcut may be specified by
0049      * the ampersand character (e.g.\ "&Option" creates a shortcut with key \e O )
0050      *
0051      * This is the most common QAction used when you do not have a
0052      * corresponding icon (note that it won't appear in the current version
0053      * of the "Edit ToolBar" dialog, because an action needs an icon to be
0054      * plugged in a toolbar...).
0055      *
0056      * @param text The text that will be displayed.
0057      * @param parent The action's parent object.
0058      */
0059     KToggleAction(const QString &text, QObject *parent);
0060 
0061     /**
0062      * Constructs an action with text and an icon; a shortcut may be specified by
0063      * the ampersand character (e.g.\ "&Option" creates a shortcut with key \e O )
0064      *
0065      * This is the other common QAction used.  Use it when you
0066      * \e do have a corresponding icon.
0067      *
0068      * @param icon The icon to display.
0069      * @param text The text that will be displayed.
0070      * @param parent The action's parent object.
0071      */
0072     KToggleAction(const QIcon &icon, const QString &text, QObject *parent);
0073 
0074     /**
0075      * Destructor
0076      */
0077     ~KToggleAction() override;
0078 
0079     /**
0080      * Defines the text (and icon, tooltip, whatsthis) that should be displayed
0081      * instead of the normal text, when the action is checked.
0082      * Note that this does <em>not</em> replace the check box in front of the
0083      * menu.  So you should not use it to replace the text "Show <foo>" with
0084      * "Hide <foo>", for example.
0085      *
0086      * If hasIcon(), the icon is kept for the 'checked state', unless
0087      * @p checkedItem defines an icon explicitly. Same thing for tooltip and whatsthis.
0088      */
0089     void setCheckedState(const KGuiItem &checkedItem);
0090 
0091 protected Q_SLOTS:
0092     virtual void slotToggled(bool checked);
0093 
0094 protected:
0095     KWIDGETSADDONS_NO_EXPORT KToggleAction(KToggleActionPrivate &dd, QObject *parent);
0096 
0097 private:
0098     friend class KToggleFullScreenAction;
0099     Q_DECLARE_PRIVATE_D(d, KToggleAction)
0100     std::unique_ptr<class KToggleActionPrivate> const d;
0101     // KF6 TODO: change private d to protected d_ptr, use normal Q_DECLARE_PRIVATE, remove friend
0102 };
0103 
0104 #endif