[3e4acc]: libgui / MenuSub.cpp History

Parent: [116991] (diff)

Child: [9a27d0] (diff)

Download this file

MenuSub.cpp    144 lines (118 with data), 4.5 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
141
142
143
/***************************************************************************
MenuSub.cpp - submenu
-------------------
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 <QPixmap>
#include <klocale.h>
#include "MenuItem.h"
#include "MenuSub.h"
//***************************************************************************
MenuSub::MenuSub(MenuNode *parent,
QMenu *menu,
const QString &name,
const QString &command,
const QKeySequence &shortcut,
const QString &uid)
:MenuNode(parent, name, command, shortcut, uid), m_menu(menu)
{
QAction *act = action();
Q_ASSERT(act);
if (act) {
act->setText(i18n(name.toUtf8()));
if (shortcut) act->setShortcut(shortcut);
}
}
//***************************************************************************
MenuSub::~MenuSub()
{
}
//*****************************************************************************
bool MenuSub::isEnabled()
{
if (m_menu && !m_menu->isEnabled()) return false;
return MenuNode::isEnabled();
}
//*****************************************************************************
void MenuSub::setEnabled(bool enable)
{
if (m_menu) m_menu->setEnabled(enable);
}
//*****************************************************************************
const QIcon MenuSub::icon()
{
return (m_menu) ? m_menu->icon() : QIcon();
}
//*****************************************************************************
void MenuSub::setIcon(const QIcon &icon)
{
if (m_menu) m_menu->setIcon(icon);
}
//***************************************************************************
MenuSub *MenuSub::insertBranch(const QString &name,
const QString &command,
const QKeySequence &shortcut,
const QString &uid)
{
QMenu *menu = (m_menu) ? m_menu->addMenu(name) : 0;
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 *MenuSub::insertLeaf(const QString &name,
const QString &command,
const QKeySequence &shortcut,
const QString &uid)
{
Q_ASSERT(name.length());
Q_ASSERT(m_menu);
if (!name.length() || !m_menu) return 0;
MenuItem *item = new MenuItem(this, name, command, shortcut, uid);
Q_ASSERT(item);
if (!item) return 0;
registerChild(item);
m_menu->addAction(item->action());
return item;
}
//***************************************************************************
void MenuSub::removeChild(MenuNode *child)
{
QAction *act = action();
if (act && m_menu) m_menu->removeAction(act);
MenuNode::removeChild(child);
}
//***************************************************************************
bool MenuSub::specialCommand(const QString &command)
{
Q_ASSERT(command.length());
if (!command.length()) return false;
if (command.startsWith("#exclusive")) {
return true;
} else if (command.startsWith("#number")) {
return true;
} else if (command.startsWith("#separator")) {
if (m_menu) m_menu->addSeparator();
return true;
}
return MenuNode::specialCommand(command);
}
//***************************************************************************
#include "MenuSub.moc"
//***************************************************************************
//***************************************************************************