Move actionsFromMenu from AbstractRunner to plasma.h
svn path=/trunk/KDE/kdelibs/; revision=1002462
This commit is contained in:
parent
af839dc89c
commit
ef32813846
@ -225,39 +225,6 @@ void AbstractRunner::clearActions()
|
||||
d->actions.clear();
|
||||
}
|
||||
|
||||
QList<QAction*> AbstractRunner::actionsFromMenu(QMenu *menu, const QString &prefix)
|
||||
{
|
||||
Q_ASSERT(menu);
|
||||
|
||||
QList<QAction*> ret;
|
||||
foreach (QAction *action, menu->actions()) {
|
||||
if (QMenu *submenu = action->menu()) {
|
||||
//Flatten hierarchy and prefix submenu text to all actions in submenu
|
||||
ret << actionsFromMenu(submenu, action->text());
|
||||
} else if (!action->isSeparator() && action->isEnabled()) {
|
||||
QString text = action->text();
|
||||
if (action->isCheckable()) {
|
||||
if (action->isChecked()) {
|
||||
text = QString("(%1) %2").arg(QChar(0x2613)).arg(text);
|
||||
} else {
|
||||
text = QString("( ) %1").arg(text);
|
||||
}
|
||||
}
|
||||
|
||||
if (!prefix.isEmpty()) {
|
||||
text = QString("%1: %2").arg(prefix).arg(text);
|
||||
}
|
||||
text = text.replace(QRegExp("&([\\S])"), "\\1");
|
||||
|
||||
QAction *a = new QAction(action->icon(), text, this);
|
||||
|
||||
connect(a, SIGNAL(triggered(bool)), action, SIGNAL(triggered(bool)));
|
||||
ret << a;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool AbstractRunner::hasRunOptions()
|
||||
{
|
||||
return d->hasRunOptions;
|
||||
|
@ -352,18 +352,6 @@ class PLASMA_EXPORT AbstractRunner : public QObject
|
||||
*/
|
||||
void clearActions();
|
||||
|
||||
/**
|
||||
* Returns a list of all actions in the given QMenu
|
||||
* This method flattens the hierarchy of the menu by prefixing the
|
||||
* text of all actions in a submenu with the submenu title.
|
||||
*
|
||||
* @param menu the QMenu storing the actions
|
||||
* @param prefix text to display before the text of all actions in the menu
|
||||
*
|
||||
* @since 4.4
|
||||
*/
|
||||
QList<QAction*> actionsFromMenu(QMenu *menu, const QString &prefix = QString());
|
||||
|
||||
/**
|
||||
* Adds a registed syntax that this runner understands. This is used to
|
||||
* display to the user what this runner can understand and how it can be
|
||||
|
35
plasma.cpp
35
plasma.cpp
@ -19,8 +19,10 @@
|
||||
|
||||
#include <plasma/plasma.h>
|
||||
|
||||
#include <QAction>
|
||||
#include <QGraphicsScene>
|
||||
#include <QGraphicsView>
|
||||
#include <QMenu>
|
||||
|
||||
#include <plasma/containment.h>
|
||||
#include <plasma/view.h>
|
||||
@ -107,4 +109,37 @@ QGraphicsView *viewFor(const QGraphicsItem *item)
|
||||
return found;
|
||||
}
|
||||
|
||||
QList<QAction*> actionsFromMenu(QMenu *menu, const QString &prefix, QObject *parent)
|
||||
{
|
||||
Q_ASSERT(menu);
|
||||
|
||||
QList<QAction*> ret;
|
||||
foreach (QAction *action, menu->actions()) {
|
||||
if (QMenu *submenu = action->menu()) {
|
||||
//Flatten hierarchy and prefix submenu text to all actions in submenu
|
||||
ret << actionsFromMenu(submenu, action->text(), parent);
|
||||
} else if (!action->isSeparator() && action->isEnabled()) {
|
||||
QString text = action->text();
|
||||
if (action->isCheckable()) {
|
||||
if (action->isChecked()) {
|
||||
text = QString("(%1) %2").arg(QChar(0x2613)).arg(text);
|
||||
} else {
|
||||
text = QString("( ) %1").arg(text);
|
||||
}
|
||||
}
|
||||
|
||||
if (!prefix.isEmpty()) {
|
||||
text = QString("%1: %2").arg(prefix).arg(text);
|
||||
}
|
||||
text = text.replace(QRegExp("&([\\S])"), "\\1");
|
||||
|
||||
QAction *a = new QAction(action->icon(), text, parent);
|
||||
|
||||
QObject::connect(a, SIGNAL(triggered(bool)), action, SIGNAL(triggered(bool)));
|
||||
ret << a;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
} // Plasma namespace
|
||||
|
16
plasma.h
16
plasma.h
@ -27,6 +27,7 @@
|
||||
|
||||
#include <plasma/plasma_export.h>
|
||||
|
||||
class QAction;
|
||||
class QGraphicsView;
|
||||
|
||||
/**
|
||||
@ -294,6 +295,21 @@ PLASMA_EXPORT Direction locationToInverseDirection(Location location);
|
||||
*/
|
||||
PLASMA_EXPORT QGraphicsView *viewFor(const QGraphicsItem *item);
|
||||
|
||||
/**
|
||||
* Returns a list of all actions in the given QMenu
|
||||
* This method flattens the hierarchy of the menu by prefixing the
|
||||
* text of all actions in a submenu with the submenu title.
|
||||
*
|
||||
* @param menu the QMenu storing the actions
|
||||
* @param prefix text to display before the text of all actions in the menu
|
||||
* @param parent QObject to be passed as parent of all the actions in the list
|
||||
*
|
||||
* @since 4.4
|
||||
*/
|
||||
PLASMA_EXPORT QList<QAction*> actionsFromMenu(QMenu *menu,
|
||||
const QString &prefix = QString(),
|
||||
QObject *parent = 0);
|
||||
|
||||
} // Plasma namespace
|
||||
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(Plasma::Constraints)
|
||||
|
Loading…
Reference in New Issue
Block a user