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

Close

[r11318]: trunk / rosegarden / src / gui / general / ActionFileParser.h Maximize Restore History

Download this file

ActionFileParser.h    186 lines (141 with data), 5.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
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
177
178
179
180
181
182
183
184
185
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
/*
Rosegarden
A MIDI and audio sequencer and musical notation editor.
Copyright 2000-2009 the Rosegarden development team.
Other copyrights also apply to some parts of this work. Please
see the AUTHORS file and individual file headers for details.
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. See the file
COPYING included with this distribution for more information.
*/
#ifndef _RG_ACTIONFILEPARSER_H_
#define _RG_ACTIONFILEPARSER_H_
#include <QXmlDefaultHandler>
#include <QMap>
#include <QObject>
#include <set>
class QAction;
class QActionGroup;
class QMenu;
class QToolBar;
namespace Rosegarden
{
class ActionFileParser : public QObject, public QXmlDefaultHandler
{
Q_OBJECT
public:
ActionFileParser(QObject *actionOwner);
virtual ~ActionFileParser();
bool load(QString actionRcFile);
// XML handler methods
virtual bool startDocument();
virtual bool startElement(const QString& namespaceURI,
const QString& localName,
const QString& qName,
const QXmlAttributes& atts);
virtual bool endElement(const QString& namespaceURI,
const QString& localName,
const QString& qName);
virtual bool characters(const QString& ch);
virtual bool endDocument();
bool error(const QXmlParseException &exception);
bool fatalError(const QXmlParseException &exception);
void enterActionState(QString stateName);
void leaveActionState(QString stateName);
protected slots:
void slotObjectDestroyed();
protected:
enum Position { Top, Bottom, Left, Right, Default };
bool setActionText(QString actionName, QString text);
bool setActionIcon(QString actionName, QString icon);
bool setActionShortcut(QString actionName, QString shortcut, bool isApplicationContext);
bool setActionToolTip(QString actionName, QString tooltip);
bool setActionGroup(QString actionName, QString group);
bool setActionChecked(QString actionName, bool);
bool setMenuText(QString name, QString text);
bool addMenuToMenu(QString parent, QString child);
bool addMenuToMenubar(QString menuName);
bool addActionToMenu(QString menuName, QString actionName);
bool addSeparatorToMenu(QString menuName);
bool setToolbarText(QString name, QString text);
bool addActionToToolbar(QString toolbarName, QString actionName);
bool addSeparatorToToolbar(QString toolbarName);
void addToolbarBreak(Position);
bool enableActionInState(QString stateName, QString actionName);
bool disableActionInState(QString stateName, QString actionName);
/**
* Set the action as visible for state.
*/
bool toVisibleActionInState(QString stateName, QString actionName);
/**
* Set the action as invisible for state.
*/
bool toInvisibleActionInState(QString stateName, QString actionName);
bool enableMenuInState(QString stateName, QString menuName);
bool disableMenuInState(QString stateName, QString menuName);
/** Translate a string with QObject::tr() and an optional disambiguation
* \param text The text to translate
* \param disambiguation Context disambiguation, if required
* \return A translated QString
*/
QString translate(QString text, QString disambiguation = "");
QString findRcFile(QString name);
QAction *findAction(QString name);
QAction *findStandardAction(QString name);
QActionGroup *findGroup(QString name);
QMenu *findMenu(QString name);
QToolBar *findToolbar(QString name, Position position);
typedef std::set<QAction *> ActionSet;
typedef QMap<QString, ActionSet> StateMap;
// Map of enable(d) items when entering action state.
StateMap m_stateEnableMap;
// Map of disable(d) items when entering action state.
StateMap m_stateDisableMap;
// Map of visible items when entering action state.
StateMap m_stateVisibleMap;
// Map of invisible items when entering action state.
StateMap m_stateInvisibleMap;
/**
* Null safe settter for QAction->enable(bool).
*/
void setEnabled(QAction *, bool);
/**
* Null safe settter for QAction->setVisibe(bool).
*/
void setVisible(QAction *, bool);
ActionSet m_tooltipSet;
QObject *m_actionOwner;
bool m_inMenuBar;
bool m_inText;
bool m_inEnable;
bool m_inDisable;
bool m_inVisible; // Are we inside a State/visible tag?
bool m_inInvisible; // Are we inside a State/invisible tag?
QStringList m_currentMenus;
QString m_currentToolbar;
QString m_currentState;
QString m_currentText;
QString m_currentFile;
Position m_lastToolbarPosition;
};
// A QMenu needs a QWidget as its parent, but the action file client
// will not necessarily be a QWidget -- for example, it might be a
// tool object. In this case, we need to make a menu that has no
// parent, but we need to wrap it in something that is parented by the
// action file client so that we can find it later and it shares the
// scope of the client. This is that wrapper.
class ActionFileMenuWrapper : public QObject
{
Q_OBJECT
public:
ActionFileMenuWrapper(QMenu *menu, QObject *parent);
virtual ~ActionFileMenuWrapper();
QMenu *getMenu();
private:
QMenu *m_menu;
};
}
#endif