File: MenuItem.h

package info (click to toggle)
kwave 25.04.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 23,272 kB
  • sloc: cpp: 56,173; xml: 817; perl: 688; sh: 57; makefile: 11
file content (145 lines) | stat: -rw-r--r-- 4,600 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/***************************************************************************
                          MenuItem.h  -  selectable and checkable menu item
                             -------------------
    begin                : Mon Jan 10 2000
    copyright            : (C) 2000 by Thomas Eschenbacher
    email                : Thomas.Eschenbacher@gmx.de
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef MENU_ITEM_H
#define MENU_ITEM_H

#include "config.h"

#include <QAction>
#include <QString>

#include "libgui/MenuNode.h"

namespace Kwave
{

    /**
     * Base class for entries in a Menu. It is normally owned by a toplevel
     * menu or a submenu.
     */
    class MenuItem: public Kwave::MenuNode
    {
        Q_OBJECT

    public:

        /**
         * Constructor.
         * @param parent pointer to the node's parent (might be 0)
         * @param name the non-localized name of the node
         * @param command the command to be sent when the node is
         *                selected (optional, default=0)
         * @param shortcut keyboard shortcut (optional, default=0)
         * @param uid unique id string (optional, default=0)
         */
        MenuItem(Kwave::MenuNode *parent,
                 const QString &name,
                 const QString &command,
                 const QKeySequence &shortcut,
                 const QString &uid);

        /** virtual destructor */
        ~MenuItem() override;

        /**
         * Called to notify the item that it has been selected.
         */
        void actionSelected() override;

        /**
         * Handles/interpretes special menu commands.
         * @param command name of a menu node or command
         * @return true if the name was recognized as a command and handled
         */
        bool specialCommand(const QString &command) override;

        /**
         * Shows/hides the current menu node.
         * @param visible true to show the item, false to hide
         */
        void setVisible(bool visible) override;

        /**
         * Returns true if the node is enabled.
         */
        bool isEnabled() override;

        /**
         * Enables/disables the current menu node.
         * @param enable true to enable the item, false to disable
         */
        void setEnabled(bool enable) override;

        /**
         * Enables/disabled checking/selecting the item
         * @param checkable true to enable checking, false for disabling
         */
        virtual void setCheckable(bool checkable);

        /** Returns true if the node is checkable/selectable */
        virtual bool isCheckable();

        /**
         * Sets/removes the checkmark from the current menu item.
         * @param check true to set the mark, false to remove
         */
        void setChecked(bool check) override;

        /**
         * Sets the visible text of an item to a new value. (Only useful
         * for a MenuItem)
         * @param text the new text
         */
        void setText(const QString &text) override;

        /**
         * Returns the menu nodes' icon.
         */
        const QIcon icon() override;

        /**
         * Sets a new icon of a menu node.
         * @param icon QPixmap with the icon
         */
        void setIcon(const QIcon &icon) override;

        /** Returns the corresponding menu action */
        QAction *action() override { return &m_action; }

    private slots:

        virtual void actionTriggered(bool checked);

    private:

        /**
         * name of a group for exclusive selection
         * (optional, set by special command, default=0)
         */
        QString m_exclusive_group;

        /** the QAction behind this menu entry */
        QAction m_action;

    };
}

#endif // _MENU_ITEM_H_

//***************************************************************************
//***************************************************************************