Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

[3e4acc]: libgui / MenuRoot.cpp Maximize Restore History

Download this file

MenuRoot.cpp    141 lines (116 with data), 4.7 kB

  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
/***************************************************************************
MenuRoot.cpp - root node of a menu structure
-------------------
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. *
* *
***************************************************************************/
#include "config.h"
#include <klocale.h>
#include <kmenubar.h>
#include "MenuItem.h"
#include "MenuSub.h"
#include "MenuRoot.h"
//***************************************************************************
/** garbage collector for menu nodes */
QList<MenuNode *> MenuRoot::m_garbage;
//***************************************************************************
MenuRoot::MenuRoot(KMenuBar &bar)
:MenuNode(0, "(root)", 0, 0, 0), m_menu_bar(bar), m_group_list()
{
}
//***************************************************************************
MenuRoot::~MenuRoot()
{
clear();
}
//***************************************************************************
QHash<QString, MenuGroup *> &MenuRoot::getGroupList()
{
return m_group_list;
}
//*****************************************************************************
void MenuRoot::insertNode(const QString &name,
const QString &position,
const QString &command,
const QKeySequence &shortcut,
const QString &uid)
{
MenuNode::insertNode(name, position, command, shortcut, uid);
// now delete all leafes that have been converted to branches
while (!m_garbage.isEmpty()) {
MenuNode *node = m_garbage.takeFirst();
if (node) delete node;
}
}
//***************************************************************************
MenuSub *MenuRoot::insertBranch(const QString &name,
const QString &command,
const QKeySequence &shortcut,
const QString &uid)
{
QMenu *menu = m_menu_bar.addMenu(name);
Q_ASSERT(menu);
if (!menu) return 0;
MenuSub *sub = new MenuSub(this, menu, name, command, shortcut, uid);
Q_ASSERT(sub);
if (!sub) return 0;
registerChild(sub);
return sub;
}
//***************************************************************************
MenuNode *MenuRoot::insertLeaf(const QString &name,
const QString &command,
const QKeySequence &shortcut,
const QString &uid)
{
MenuItem *item = new MenuItem(this, name, command, shortcut, uid);
Q_ASSERT(item);
if (!item) return 0;
registerChild(item);
m_menu_bar.addAction(item->action());
return item;
}
//***************************************************************************
void MenuRoot::removeChild(MenuNode *child)
{
Q_ASSERT(child);
if (!child) return ;
if (!m_children.contains(child)) return ;
QHash<QString, MenuGroup *> &group_list = getGroupList();
if (!group_list.contains(child->name())) {
// only remove what has been added to the menu bar,
// but not menu groups
QAction *action = child->action();
if (action) m_menu_bar.removeAction(action);
}
MenuNode::removeChild(child);
}
//***************************************************************************
bool MenuRoot::specialCommand(const QString &command)
{
Q_ASSERT(command.length());
if (!command.length()) return false;
if (command == "#separator") {
m_menu_bar.addSeparator();
return true;
}
return MenuNode::specialCommand(command);
}
//***************************************************************************
void MenuRoot::deleteLater(MenuNode *node)
{
if (node) m_garbage.append(node);
}
//***************************************************************************
#include "MenuRoot.moc"
//***************************************************************************
//***************************************************************************