Move actionsFromMenu from AbstractRunner to plasma.h

svn path=/trunk/KDE/kdelibs/; revision=1002462
This commit is contained in:
Ryan P. Bitanga 2009-07-26 02:51:21 +00:00
parent af839dc89c
commit ef32813846
4 changed files with 51 additions and 45 deletions

View File

@ -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;

View File

@ -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

View File

@ -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

View File

@ -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)