kwave  18.07.70
Kwave::MenuItem Class Reference

#include <MenuItem.h>

Inheritance diagram for Kwave::MenuItem:
Inheritance graph
Collaboration diagram for Kwave::MenuItem:
Collaboration graph

Public Member Functions

 MenuItem (Kwave::MenuNode *parent, const QString &name, const QString &command, const QKeySequence &shortcut, const QString &uid)
 
virtual ~MenuItem () Q_DECL_OVERRIDE
 
virtual void actionSelected () Q_DECL_OVERRIDE
 
virtual bool specialCommand (const QString &command) Q_DECL_OVERRIDE
 
virtual void setVisible (bool visible) Q_DECL_OVERRIDE
 
virtual bool isEnabled () Q_DECL_OVERRIDE
 
virtual void setEnabled (bool enable) Q_DECL_OVERRIDE
 
virtual void setCheckable (bool checkable)
 
virtual bool isCheckable ()
 
virtual void setChecked (bool check) Q_DECL_OVERRIDE
 
virtual void setText (const QString &text) Q_DECL_OVERRIDE
 
virtual const QIcon icon () Q_DECL_OVERRIDE
 
virtual void setIcon (const QIcon &icon) Q_DECL_OVERRIDE
 
virtual QAction * action () Q_DECL_OVERRIDE
 
- Public Member Functions inherited from Kwave::MenuNode
 MenuNode (Kwave::MenuNode *parent, const QString &name, const QString &command, const QKeySequence &shortcut, const QString &uid)
 
virtual ~MenuNode ()
 
const QString path () const
 
const QString & name () const
 
const QString & command () const
 
const QString & uid () const
 
void setUID (const QString &uid)
 
const QKeySequence & shortcut () const
 
virtual void setShortcut (const QKeySequence &shortcut)
 
virtual bool isBranch () const
 
virtual void clear ()
 
virtual Kwave::MenuNodeparentNode () const
 
Kwave::MenuNodefindUID (const QString &uid)
 
Kwave::MenuNodefindChild (const QString &name)
 
virtual void removeChild (Kwave::MenuNode *child)
 
virtual Kwave::MenuSubinsertBranch (const QString &name, const QString &command, const QKeySequence &shortcut, const QString &uid)
 
virtual Kwave::MenuNodeinsertLeaf (const QString &name, const QString &command, const QKeySequence &shortcut, const QString &uid)
 
virtual void insertChild (Kwave::MenuNode *node, Kwave::MenuNode *before)
 
virtual void insertNode (const QString &name, const QString &position, const QString &command, const QKeySequence &shortcut, const QString &uid)
 
virtual Kwave::MenuNodeleafToBranch (Kwave::MenuNode *node)
 
virtual QHash< QString, Kwave::MenuGroup * > & groupList ()
 
void joinGroup (const QString &group, Kwave::MenuGroup::Mode mode)
 
void leaveGroup (const QString &group)
 

Private Slots

virtual void actionTriggered (bool checked)
 

Private Attributes

QString m_exclusive_group
 
QAction m_action
 

Additional Inherited Members

- Signals inherited from Kwave::MenuNode
void sigCommand (const QString &command)
 
- Protected Member Functions inherited from Kwave::MenuNode
Kwave::MenuNoderootNode ()
 
void emitCommand (const QString &command)
 
- Protected Attributes inherited from Kwave::MenuNode
QList< Kwave::MenuNode * > m_children
 
QStringList m_groups
 

Detailed Description

Base class for entries in a Menu. It is normally owned by a toplevel menu or a submenu.

Definition at line 35 of file MenuItem.h.

Constructor & Destructor Documentation

◆ MenuItem()

Kwave::MenuItem::MenuItem ( Kwave::MenuNode parent,
const QString &  name,
const QString &  command,
const QKeySequence &  shortcut,
const QString &  uid 
)

Constructor.

Parameters
parentpointer to the node's parent (might be 0)
namethe non-localized name of the node
commandthe command to be sent when the node is selected (optional, default=0)
shortcutkeyboard shortcut (optional, default=0)
uidunique id string (optional, default=0)

Definition at line 33 of file MenuItem.cpp.

References _, actionTriggered(), Kwave::connect(), m_action, Kwave::MenuNode::path(), and UTF8.

39  m_exclusive_group(), m_action(Q_NULLPTR)
40 {
41  Q_ASSERT(parent);
42  if (!parent) return;
43 
44  m_action.setText(i18nc(UTF8(_("menu: ") + path()), UTF8(name)));
45  if (!shortcut.isEmpty()) m_action.setShortcut(shortcut);
46 
47  connect(&m_action, SIGNAL(triggered(bool)),
48  this, SLOT(actionTriggered(bool)));
49 }
const QString path() const
Definition: MenuNode.cpp:63
QAction m_action
Definition: MenuItem.h:137
const QKeySequence & shortcut() const
Definition: MenuNode.h:95
bool connect(Kwave::StreamObject &source, const char *output, Kwave::StreamObject &sink, const char *input)
Definition: Connect.cpp:48
const QString & name() const
Definition: MenuNode.h:74
const QString & command() const
Definition: MenuNode.h:77
virtual void actionTriggered(bool checked)
Definition: MenuItem.cpp:57
#define _(m)
Definition: memcpy.c:66
const QString & uid() const
Definition: MenuNode.h:85
QString m_exclusive_group
Definition: MenuItem.h:134
#define UTF8(qs)
Definition: String.h:48
Here is the call graph for this function:

◆ ~MenuItem()

Kwave::MenuItem::~MenuItem ( )
virtual

virtual destructor

Definition at line 52 of file MenuItem.cpp.

53 {
54 }

Member Function Documentation

◆ action()

virtual QAction* Kwave::MenuItem::action ( )
inlinevirtual

Returns the corresponding menu action

Reimplemented from Kwave::MenuNode.

Definition at line 122 of file MenuItem.h.

References actionTriggered(), and m_action.

Referenced by Kwave::MenuSub::insertLeaf(), and Kwave::MenuRoot::insertLeaf().

122 { return &m_action; }
QAction m_action
Definition: MenuItem.h:137
Here is the call graph for this function:
Here is the caller graph for this function:

◆ actionSelected()

void Kwave::MenuItem::actionSelected ( )
virtual

Called to notify the item that it has been selected.

Reimplemented from Kwave::MenuNode.

Definition at line 64 of file MenuItem.cpp.

References Kwave::MenuNode::actionSelected(), isCheckable(), m_exclusive_group, and setChecked().

Referenced by actionTriggered().

65 {
66  if (isCheckable() && !m_exclusive_group.length())
67  setChecked(true);
68 
70 }
virtual void actionSelected()
Definition: MenuNode.cpp:87
virtual bool isCheckable()
Definition: MenuItem.cpp:127
virtual void setChecked(bool check) Q_DECL_OVERRIDE
Definition: MenuItem.cpp:139
QString m_exclusive_group
Definition: MenuItem.h:134
Here is the call graph for this function:
Here is the caller graph for this function:

◆ actionTriggered

void Kwave::MenuItem::actionTriggered ( bool  checked)
privatevirtualslot

Definition at line 57 of file MenuItem.cpp.

References actionSelected().

Referenced by action(), and MenuItem().

58 {
59  Q_UNUSED(checked);
61 }
virtual void actionSelected() Q_DECL_OVERRIDE
Definition: MenuItem.cpp:64
Here is the call graph for this function:
Here is the caller graph for this function:

◆ icon()

const QIcon Kwave::MenuItem::icon ( )
virtual

Returns the menu nodes' icon.

Reimplemented from Kwave::MenuNode.

Definition at line 151 of file MenuItem.cpp.

References m_action.

152 {
153  return m_action.icon();
154 }
QAction m_action
Definition: MenuItem.h:137

◆ isCheckable()

bool Kwave::MenuItem::isCheckable ( )
virtual

Returns true if the node is checkable/selectable

Definition at line 127 of file MenuItem.cpp.

References m_action.

Referenced by actionSelected().

128 {
129  return m_action.isCheckable();
130 }
QAction m_action
Definition: MenuItem.h:137
Here is the caller graph for this function:

◆ isEnabled()

bool Kwave::MenuItem::isEnabled ( )
virtual

Returns true if the node is enabled.

Reimplemented from Kwave::MenuNode.

Definition at line 114 of file MenuItem.cpp.

References Kwave::MenuNode::isEnabled(), and m_action.

115 {
116  if (!m_action.isEnabled()) return false;
118 }
QAction m_action
Definition: MenuItem.h:137
virtual bool isEnabled()
Definition: MenuNode.cpp:130
Here is the call graph for this function:

◆ setCheckable()

void Kwave::MenuItem::setCheckable ( bool  checkable)
virtual

Enables/disabled checking/selecting the item

Parameters
checkabletrue to enable checking, false for disabling

Definition at line 133 of file MenuItem.cpp.

References m_action.

Referenced by specialCommand().

134 {
135  m_action.setCheckable(checkable);
136 }
QAction m_action
Definition: MenuItem.h:137
Here is the caller graph for this function:

◆ setChecked()

void Kwave::MenuItem::setChecked ( bool  check)
virtual

Sets/removes the checkmark from the current menu item.

Parameters
checktrue to set the mark, false to remove

Reimplemented from Kwave::MenuNode.

Definition at line 139 of file MenuItem.cpp.

References m_action.

Referenced by actionSelected().

140 {
141  m_action.setChecked(check);
142 }
QAction m_action
Definition: MenuItem.h:137
Here is the caller graph for this function:

◆ setEnabled()

void Kwave::MenuItem::setEnabled ( bool  enable)
virtual

Enables/disables the current menu node.

Parameters
enabletrue to enable the item, false to disable

Reimplemented from Kwave::MenuNode.

Definition at line 121 of file MenuItem.cpp.

References m_action.

122 {
123  m_action.setEnabled(enable);
124 }
QAction m_action
Definition: MenuItem.h:137

◆ setIcon()

void Kwave::MenuItem::setIcon ( const QIcon &  icon)
virtual

Sets a new icon of a menu node.

Parameters
iconQPixmap with the icon

Reimplemented from Kwave::MenuNode.

Definition at line 157 of file MenuItem.cpp.

References m_action.

158 {
159  m_action.setIcon(icon);
160 }
QAction m_action
Definition: MenuItem.h:137
virtual const QIcon icon() Q_DECL_OVERRIDE
Definition: MenuItem.cpp:151

◆ setText()

void Kwave::MenuItem::setText ( const QString &  text)
virtual

Sets the visible text of an item to a new value. (Only useful for a MenuItem)

Parameters
textthe new text

Reimplemented from Kwave::MenuNode.

Definition at line 145 of file MenuItem.cpp.

References m_action.

146 {
147  m_action.setText(text);
148 }
QAction m_action
Definition: MenuItem.h:137

◆ setVisible()

void Kwave::MenuItem::setVisible ( bool  visible)
virtual

Shows/hides the current menu node.

Parameters
visibletrue to show the item, false to hide

Reimplemented from Kwave::MenuNode.

Definition at line 108 of file MenuItem.cpp.

References m_action.

Referenced by specialCommand().

109 {
110  m_action.setVisible(visible);
111 }
QAction m_action
Definition: MenuItem.h:137
Here is the caller graph for this function:

◆ specialCommand()

bool Kwave::MenuItem::specialCommand ( const QString &  command)
virtual

Handles/interpretes special menu commands.

Parameters
commandname of a menu node or command
Returns
true if the name was recognized as a command and handled

Reimplemented from Kwave::MenuNode.

Definition at line 73 of file MenuItem.cpp.

References _, Kwave::Parser::command(), DBG, Kwave::MenuGroup::EXCLUSIVE, Kwave::Parser::firstParam(), Kwave::MenuNode::joinGroup(), m_exclusive_group, Kwave::MenuNode::name(), Kwave::Parser::nextParam(), setCheckable(), setVisible(), and Kwave::MenuNode::specialCommand().

74 {
75  Kwave::Parser parser(command);
76 
77  if (command == _("#checkable")) {
78  // checking/selecting of the item (non-exclusive)
79  setCheckable(true);
80  }
81  else if (parser.command() == _("#exclusive")) {
82  // join to a list of groups
83  QString group = parser.firstParam();
84  while (group.length()) {
85  if (!m_exclusive_group.length()) {
86  m_exclusive_group = group;
88  } else if (m_exclusive_group != group) {
89  qWarning("menu item '%s' already member of "
90  "exclusive group '%s'",
92  }
93  group = parser.nextParam();
94  }
95 
96  // make the item checkable
97  setCheckable(true);
98  return true;
99  }
100  else if (command == _("#hidden")) {
101  setVisible(false);
102  }
103 
105 }
void joinGroup(const QString &group, Kwave::MenuGroup::Mode mode)
Definition: MenuNode.cpp:378
virtual void setCheckable(bool checkable)
Definition: MenuItem.cpp:133
virtual void setVisible(bool visible) Q_DECL_OVERRIDE
Definition: MenuItem.cpp:108
virtual bool specialCommand(const QString &command)
Definition: MenuNode.cpp:421
const QString & name() const
Definition: MenuNode.h:74
const QString & command() const
Definition: MenuNode.h:77
#define _(m)
Definition: memcpy.c:66
#define DBG(qs)
Definition: String.h:55
QString m_exclusive_group
Definition: MenuItem.h:134
Here is the call graph for this function:

Member Data Documentation

◆ m_action

QAction Kwave::MenuItem::m_action
private

the QAction behind this menu entry

Definition at line 137 of file MenuItem.h.

Referenced by action(), icon(), isCheckable(), isEnabled(), MenuItem(), setCheckable(), setChecked(), setEnabled(), setIcon(), setText(), and setVisible().

◆ m_exclusive_group

QString Kwave::MenuItem::m_exclusive_group
private

name of a group for exclusive selection (optional, set by special command, default=0)

Definition at line 134 of file MenuItem.h.

Referenced by actionSelected(), and specialCommand().


The documentation for this class was generated from the following files: