Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

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

Download this file

MenuItem.cpp    177 lines (146 with data), 5.1 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/***************************************************************************
MenuItem.h - description
-------------------
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 <QMenu>
#include <kapplication.h>
#include <kiconloader.h>
#include <klocale.h>
#include "libkwave/Parser.h"
#include "MenuNode.h"
#include "MenuSub.h"
#include "MenuGroup.h"
#include "MenuItem.h"
//*****************************************************************************
MenuItem::MenuItem(MenuNode *parent,
const QString &name,
const QString &command,
const QKeySequence &shortcut,
const QString &uid)
:MenuNode(parent, name, command, shortcut, uid),
m_exclusive_group(), m_action(0)
{
Q_ASSERT(parent);
if (!parent) return;
m_action.setText(i18n(name.toUtf8()));
if (shortcut) m_action.setShortcut(shortcut);
connect(&m_action, SIGNAL(triggered(bool)),
this, SLOT(actionTriggered(bool)));
}
//*****************************************************************************
MenuItem::~MenuItem()
{
}
//*****************************************************************************
void MenuItem::actionTriggered(bool checked)
{
Q_UNUSED(checked);
actionSelected();
}
//*****************************************************************************
void MenuItem::actionSelected()
{
MenuGroup *group = 0;
if (isCheckable()) {
if (m_exclusive_group.length()) {
MenuNode *root = getRootNode();
if (root) group =
static_cast<MenuGroup *>(root->findUID(m_exclusive_group));
}
if (group && (static_cast<MenuNode *>(group))->inherits("MenuGroup")) {
// exclusive check == selection
group->selectItem(uid());
} else {
// normal check, maybe multiple
setChecked(true);
}
}
MenuNode::actionSelected();
}
//*****************************************************************************
bool MenuItem::specialCommand(const QString &command)
{
if (command.startsWith("#checkable")) {
// checking/selecting of the item (non-exclusive)
setCheckable(true);
}
if (command.startsWith("#exclusive(")) {
Parser parser(command);
// join to a list of groups
QString group = parser.firstParam();
while (group.length()) {
if (!m_exclusive_group.length()) {
m_exclusive_group = group;
joinGroup(group);
} else if (m_exclusive_group != group) {
qWarning("menu item '%s' already member of "\
"exclusive group '%s'",
name().toLocal8Bit().data(),
m_exclusive_group.toLocal8Bit().data());
}
group = parser.nextParam();
}
// make the item checkable
setCheckable(true);
return true;
}
return (MenuNode::specialCommand(command));
}
//*****************************************************************************
bool MenuItem::isEnabled()
{
if (!m_action.isEnabled()) return false;
return MenuNode::isEnabled();
}
//*****************************************************************************
void MenuItem::setEnabled(bool enable)
{
m_action.setEnabled(enable);
}
//*****************************************************************************
bool MenuItem::isCheckable()
{
return m_action.isCheckable();
}
//*****************************************************************************
void MenuItem::setCheckable(bool checkable)
{
m_action.setCheckable(checkable);
}
//*****************************************************************************
void MenuItem::setChecked(bool check)
{
m_action.setChecked(check);
}
//*****************************************************************************
void MenuItem::setText(const QString &text)
{
m_action.setText(text);
}
//*****************************************************************************
const QIcon MenuItem::icon()
{
return m_action.icon();
}
//*****************************************************************************
void MenuItem::setIcon(const QIcon &icon)
{
m_action.setIcon(icon);
}
//***************************************************************************
#include "MenuItem.moc"
//*****************************************************************************
//*****************************************************************************