kwave  18.07.70
Kwave::MenuSub Class Reference

#include <MenuSub.h>

Inheritance diagram for Kwave::MenuSub:
Inheritance graph
Collaboration diagram for Kwave::MenuSub:
Collaboration graph

Public Member Functions

 MenuSub (Kwave::MenuNode *parent, QMenu *menu, const QString &name, const QString &command, const QKeySequence &shortcut, const QString &uid)
 
virtual ~MenuSub () Q_DECL_OVERRIDE
 
virtual bool isBranch () const Q_DECL_OVERRIDE
 
virtual Kwave::MenuSubinsertBranch (const QString &name, const QString &command, const QKeySequence &shortcut, const QString &uid) Q_DECL_OVERRIDE
 
virtual Kwave::MenuNodeinsertLeaf (const QString &name, const QString &command, const QKeySequence &shortcut, const QString &uid) Q_DECL_OVERRIDE
 
virtual QAction * action () Q_DECL_OVERRIDE
 
virtual void removeChild (Kwave::MenuNode *child) 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 const QIcon icon () Q_DECL_OVERRIDE
 
virtual void setIcon (const QIcon &icon) 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 void clear ()
 
virtual Kwave::MenuNodeparentNode () const
 
virtual void setChecked (bool check)
 
virtual void setText (const QString &text)
 
Kwave::MenuNodefindUID (const QString &uid)
 
Kwave::MenuNodefindChild (const QString &name)
 
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 void actionSelected ()
 
virtual QHash< QString, Kwave::MenuGroup * > & groupList ()
 
void joinGroup (const QString &group, Kwave::MenuGroup::Mode mode)
 
void leaveGroup (const QString &group)
 

Protected Member Functions

virtual QMenu * menu ()
 
- Protected Member Functions inherited from Kwave::MenuNode
Kwave::MenuNoderootNode ()
 
void emitCommand (const QString &command)
 

Private Attributes

QMenu * m_menu
 

Friends

class MenuRoot
 

Additional Inherited Members

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

Detailed Description

This is the class for submenu entries in a Menu. It is normally owned by a root menu node, a toplevel menu or another submenu.

Definition at line 36 of file MenuSub.h.

Constructor & Destructor Documentation

◆ MenuSub()

Kwave::MenuSub::MenuSub ( Kwave::MenuNode parent,
QMenu *  menu,
const QString &  name,
const QString &  command,
const QKeySequence &  shortcut,
const QString &  uid 
)

Constructor.

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

Definition at line 33 of file MenuSub.cpp.

References _, action(), Kwave::MenuNode::path(), and UTF8.

40 {
41  QAction *act = action();
42  Q_ASSERT(act);
43  if (act) act->setText(i18nc(UTF8(_("menu: ") + path()), UTF8(name)));
44 }
const QString path() const
Definition: MenuNode.cpp:63
QMenu * m_menu
Definition: MenuSub.h:155
const QKeySequence & shortcut() const
Definition: MenuNode.h:95
const QString & name() const
Definition: MenuNode.h:74
const QString & command() const
Definition: MenuNode.h:77
virtual QMenu * menu()
Definition: MenuSub.h:150
virtual QAction * action() Q_DECL_OVERRIDE
Definition: MenuSub.h:102
#define _(m)
Definition: memcpy.c:66
const QString & uid() const
Definition: MenuNode.h:85
#define UTF8(qs)
Definition: String.h:48
Here is the call graph for this function:

◆ ~MenuSub()

Kwave::MenuSub::~MenuSub ( )
virtual

Destructor

Definition at line 47 of file MenuSub.cpp.

48 {
49 }

Member Function Documentation

◆ action()

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

Returns the corresponding menu action

Reimplemented from Kwave::MenuNode.

Definition at line 102 of file MenuSub.h.

References icon(), isEnabled(), m_menu, removeChild(), setEnabled(), setIcon(), setVisible(), and specialCommand().

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

102  {
103  return (m_menu) ? m_menu->menuAction() : Q_NULLPTR;
104  }
QMenu * m_menu
Definition: MenuSub.h:155
Here is the call graph for this function:
Here is the caller graph for this function:

◆ icon()

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

Returns the menu nodes' icon.

Reimplemented from Kwave::MenuNode.

Definition at line 86 of file MenuSub.cpp.

References m_menu.

Referenced by action().

87 {
88  return (m_menu) ? m_menu->icon() : QIcon();
89 }
QMenu * m_menu
Definition: MenuSub.h:155
Here is the caller graph for this function:

◆ insertBranch()

Kwave::MenuSub * Kwave::MenuSub::insertBranch ( const QString &  name,
const QString &  command,
const QKeySequence &  shortcut,
const QString &  uid 
)
virtual

Inserts a new branch node under the submenu. The new node normally is (derived from) MenuSub.

Parameters
namenon-localized name of the node
commandthe command template used for creating commands of submenus (leafes) that don't have an own command but contain data for their parent's command. Should contain a s that will be replaced by some data from a child entry. (this is used for menus with data selection lists like "recent files) If not used, pass 0.
shortcutkeyboard shortcut, 0 if unused
uidunique id string (might be 0)
Returns
pointer to the new branch node

Reimplemented from Kwave::MenuNode.

Definition at line 98 of file MenuSub.cpp.

References Kwave::MenuNode::insertChild(), m_menu, and menu().

Referenced by isBranch().

102 {
103  QMenu *menu = (m_menu) ? m_menu->addMenu(name) : Q_NULLPTR;
104  Q_ASSERT(menu);
105  if (!menu) return Q_NULLPTR;
106 
107  Kwave::MenuSub *sub = new(std::nothrow)
108  Kwave::MenuSub(this, menu, name, command, shortcut, uid);
109  Q_ASSERT(sub);
110  if (!sub) return Q_NULLPTR;
111 
112  insertChild(sub, Q_NULLPTR);
113 
114  return sub;
115 }
QMenu * m_menu
Definition: MenuSub.h:155
const QKeySequence & shortcut() const
Definition: MenuNode.h:95
virtual void insertChild(Kwave::MenuNode *node, Kwave::MenuNode *before)
Definition: MenuNode.cpp:181
const QString & name() const
Definition: MenuNode.h:74
const QString & command() const
Definition: MenuNode.h:77
virtual QMenu * menu()
Definition: MenuSub.h:150
const QString & uid() const
Definition: MenuNode.h:85
Here is the call graph for this function:
Here is the caller graph for this function:

◆ insertLeaf()

Kwave::MenuNode * Kwave::MenuSub::insertLeaf ( const QString &  name,
const QString &  command,
const QKeySequence &  shortcut,
const QString &  uid 
)
virtual

Inserts a new leaf node under the submenu. The new node normally is (derived from) MenuItem.

Parameters
namenon-localized name of the node
commandthe command to be sent when the node is selected (might be 0)
shortcutkeyboard shortcut, 0 if unused
uidunique id string (might be 0)
Returns
pointer to the new leaf node

Reimplemented from Kwave::MenuNode.

Definition at line 118 of file MenuSub.cpp.

References Kwave::MenuNode::action(), Kwave::MenuItem::action(), Kwave::MenuNode::insertChild(), Kwave::MenuNode::m_children, m_menu, Kwave::MenuNode::name(), and Kwave::MenuNode::uid().

Referenced by isBranch().

122 {
123  Q_ASSERT(name.length());
124  Q_ASSERT(m_menu);
125  if (!name.length() || !m_menu) return Q_NULLPTR;
126 
127  Kwave::MenuItem *item = new(std::nothrow)
129  Q_ASSERT(item);
130  if (!item) return Q_NULLPTR;
131 
132  /*
133  * find out where to insert the leaf: if there is a placeholder
134  * with the matching uid, insert after that one, otherwise append
135  * to the end
136  */
137  bool found = false;
138  Kwave::MenuNode *child_after = Q_NULLPTR;
139  QListIterator<Kwave::MenuNode *> it(m_children);
140  it.toBack();
141  while (!found && it.hasPrevious()) {
142  Kwave::MenuNode *child = it.previous();
143  if (!child) continue;
144  if (uid.length() && ((uid == child->uid()) || (uid == child->name())))
145  found = true;
146  else if (child->action())
147  child_after = child;
148  }
149 
150  insertChild(item, (found) ? child_after : Q_NULLPTR);
151 
152  QAction *action_after = (found && child_after) ?
153  child_after->action() : Q_NULLPTR;
154  if (action_after)
155  m_menu->insertAction(action_after, item->action());
156  else
157  m_menu->addAction(item->action());
158 
159  return item;
160 }
QMenu * m_menu
Definition: MenuSub.h:155
const QKeySequence & shortcut() const
Definition: MenuNode.h:95
virtual void insertChild(Kwave::MenuNode *node, Kwave::MenuNode *before)
Definition: MenuNode.cpp:181
const QString & name() const
Definition: MenuNode.h:74
const QString & command() const
Definition: MenuNode.h:77
QList< Kwave::MenuNode * > m_children
Definition: MenuNode.h:317
const QString & uid() const
Definition: MenuNode.h:85
virtual QAction * action() Q_DECL_OVERRIDE
Definition: MenuItem.h:122
virtual QAction * action()
Definition: MenuNode.h:80
Here is the call graph for this function:
Here is the caller graph for this function:

◆ isBranch()

virtual bool Kwave::MenuSub::isBranch ( ) const
inlinevirtual

Always returns true, as the nodes of this type are branches.

Reimplemented from Kwave::MenuNode.

Definition at line 64 of file MenuSub.h.

References insertBranch(), and insertLeaf().

64 { return true; }
Here is the call graph for this function:

◆ isEnabled()

bool Kwave::MenuSub::isEnabled ( )
virtual

Returns true if the node is enabled.

Reimplemented from Kwave::MenuNode.

Definition at line 73 of file MenuSub.cpp.

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

Referenced by action().

74 {
75  if (m_menu && !m_menu->isEnabled()) return false;
77 }
QMenu * m_menu
Definition: MenuSub.h:155
virtual bool isEnabled()
Definition: MenuNode.cpp:130
Here is the call graph for this function:
Here is the caller graph for this function:

◆ menu()

virtual QMenu* Kwave::MenuSub::menu ( )
inlineprotectedvirtual

return the pointer to our QMenu

Definition at line 150 of file MenuSub.h.

References m_menu.

Referenced by insertBranch(), and Kwave::MenuRoot::showChild().

150 { return m_menu; }
QMenu * m_menu
Definition: MenuSub.h:155
Here is the caller graph for this function:

◆ removeChild()

void Kwave::MenuSub::removeChild ( Kwave::MenuNode child)
virtual

Removes a child node of the current node. If the child was not found or is already removed this does nothing.

Parameters
childpointer to the child node

Reimplemented from Kwave::MenuNode.

Definition at line 163 of file MenuSub.cpp.

References Kwave::MenuNode::action(), m_menu, and Kwave::MenuNode::removeChild().

Referenced by action().

164 {
165  QAction *act = (child) ? child->action() : Q_NULLPTR;
166  if (act && m_menu) m_menu->removeAction(act);
167 
169 }
QMenu * m_menu
Definition: MenuSub.h:155
virtual void removeChild(Kwave::MenuNode *child)
Definition: MenuNode.cpp:223
virtual QAction * action()
Definition: MenuNode.h:80
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setEnabled()

void Kwave::MenuSub::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 80 of file MenuSub.cpp.

References m_menu.

Referenced by action(), and Kwave::MenuNode::leafToBranch().

81 {
82  if (m_menu) m_menu->setEnabled(enable);
83 }
QMenu * m_menu
Definition: MenuSub.h:155
Here is the caller graph for this function:

◆ setIcon()

void Kwave::MenuSub::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 92 of file MenuSub.cpp.

References m_menu.

Referenced by action(), and Kwave::MenuNode::leafToBranch().

93 {
94  if (m_menu) m_menu->setIcon(icon);
95 }
virtual const QIcon icon() Q_DECL_OVERRIDE
Definition: MenuSub.cpp:86
QMenu * m_menu
Definition: MenuSub.h:155
Here is the caller graph for this function:

◆ setVisible()

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

Shows/hides the current sub menu.

Parameters
visibletrue to show the sub menu, false to hide

Reimplemented from Kwave::MenuNode.

Definition at line 52 of file MenuSub.cpp.

References Kwave::MenuRoot::hideChild(), m_menu, Kwave::MenuNode::parentNode(), Kwave::MenuNode::rootNode(), and Kwave::MenuRoot::showChild().

Referenced by action().

53 {
54  if (!m_menu) return;
55 
56  Kwave::MenuRoot *root = qobject_cast<Kwave::MenuRoot *>(rootNode());
57  Q_ASSERT(root);
58  if (root && (parentNode() == root)) {
59  // special case: entries of the main menu can only be made
60  // visible/invisible by adding to/removing from the main menu
61  if (visible) {
62  root->showChild(this);
63  }
64  else
65  root->hideChild(this);
66  } else {
67  // normal menu entry
68  m_menu->setVisible(visible);
69  }
70 }
virtual Kwave::MenuNode * parentNode() const
Definition: MenuNode.cpp:103
QMenu * m_menu
Definition: MenuSub.h:155
void hideChild(Kwave::MenuSub *child)
Definition: MenuRoot.cpp:110
Kwave::MenuNode * rootNode()
Definition: MenuNode.cpp:109
void showChild(Kwave::MenuSub *child)
Definition: MenuRoot.cpp:122
Here is the call graph for this function:
Here is the caller graph for this function:

◆ specialCommand()

bool Kwave::MenuSub::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 172 of file MenuSub.cpp.

References _, m_menu, and Kwave::MenuNode::specialCommand().

Referenced by action().

173 {
174  Q_ASSERT(command.length());
175  if (!command.length()) return false;
176 
177  if (command.startsWith(_("#exclusive"))) {
178  return true;
179  } else if (command.startsWith(_("#separator"))) {
180  if (m_menu) m_menu->addSeparator();
181  return true;
182  }
183 
185 }
QMenu * m_menu
Definition: MenuSub.h:155
virtual bool specialCommand(const QString &command)
Definition: MenuNode.cpp:421
const QString & command() const
Definition: MenuNode.h:77
#define _(m)
Definition: memcpy.c:66
Here is the call graph for this function:
Here is the caller graph for this function:

Friends And Related Function Documentation

◆ MenuRoot

friend class MenuRoot
friend

Definition at line 147 of file MenuSub.h.

Member Data Documentation

◆ m_menu

QMenu* Kwave::MenuSub::m_menu
private

the QMenu that is controlled

Definition at line 155 of file MenuSub.h.

Referenced by action(), icon(), insertBranch(), insertLeaf(), isEnabled(), menu(), removeChild(), setEnabled(), setIcon(), setVisible(), and specialCommand().


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