kdelibs/kdeui/actions/kactioncategory.cpp

139 lines
3.6 KiB
C++
Raw Permalink Normal View History

2014-11-13 01:04:59 +02:00
/* Copyright (C) 2008 Michael Jansen <kde@michael-jansen.biz>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "kactioncategory.h"
#include <QtGui/QAction>
#include "kaction.h"
struct KActionCategoryPrivate
{
2014-11-13 01:04:59 +02:00
//! The text for this category
QString text;
//! List of actions
QList<QAction*> actions;
}; // class KActionCategoryPrivate
2014-11-13 01:04:59 +02:00
KActionCategory::KActionCategory(const QString &text, KActionCollection *parent)
: QObject(parent),
d(new KActionCategoryPrivate())
{
2014-11-13 01:04:59 +02:00
d->text = text;
}
2014-11-13 01:04:59 +02:00
KActionCategory::~KActionCategory()
{
2014-11-13 01:04:59 +02:00
delete d;
}
2014-11-13 01:04:59 +02:00
const QList<QAction*> KActionCategory::actions() const
{
2014-11-13 01:04:59 +02:00
return d->actions;
}
2014-11-13 01:04:59 +02:00
QAction* KActionCategory::addAction(const QString &name, QAction *action)
{
2014-11-13 01:04:59 +02:00
collection()->addAction(name, action);
addAction(action);
return action;
}
2014-11-13 01:04:59 +02:00
KAction* KActionCategory::addAction(const QString &name, KAction *action)
{
2014-11-13 01:04:59 +02:00
collection()->addAction(name, action);
addAction(action);
return action;
}
2014-11-13 01:04:59 +02:00
KAction* KActionCategory::addAction(KStandardAction::StandardAction actionType,
const QObject *receiver,
const char *member)
{
2014-11-13 01:04:59 +02:00
KAction *action = collection()->addAction(actionType, receiver, member);
addAction(action);
return action;
}
2014-11-13 01:04:59 +02:00
KAction* KActionCategory::addAction(KStandardAction::StandardAction actionType,
const QString &name,
const QObject *receiver,
const char *member)
{
2014-11-13 01:04:59 +02:00
KAction *action = collection()->addAction(actionType, name, receiver, member);
addAction(action);
return action;
}
2014-11-13 01:04:59 +02:00
KAction *KActionCategory::addAction(const QString &name,
const QObject *receiver,
const char *member)
{
2014-11-13 01:04:59 +02:00
KAction *action = collection()->addAction(name, receiver, member);
addAction(action);
return action;
}
2014-11-13 01:04:59 +02:00
void KActionCategory::addAction(QAction *action)
{
2014-11-13 01:04:59 +02:00
// Only add the action if wasn't added earlier.
if (!d->actions.contains(action)) {
2014-11-13 01:04:59 +02:00
d->actions.append(action);
}
}
2014-11-13 01:04:59 +02:00
KActionCollection * KActionCategory::collection() const
{
2014-11-13 01:04:59 +02:00
return qobject_cast<KActionCollection*>(parent());
}
2014-11-13 01:04:59 +02:00
QString KActionCategory::text() const
{
2014-11-13 01:04:59 +02:00
return d->text;
}
2014-11-13 01:04:59 +02:00
void KActionCategory::setText(const QString &text)
{
2014-11-13 01:04:59 +02:00
d->text = text;
}
2014-11-13 01:04:59 +02:00
void KActionCategory::unlistAction(QAction *action)
{
2014-11-13 01:04:59 +02:00
// ATTENTION:
// This method is called from KActionCollection with an QObject formerly
// known as a QAction during _k_actionDestroyed(). So don't do fancy stuff
// here that needs a real QAction!
// Get the index for the action
int index = d->actions.indexOf(action);
// Action not found.
if (index==-1) {
return;
}
2014-11-13 01:04:59 +02:00
// Remove the action
d->actions.takeAt(index);
}
2014-11-13 01:04:59 +02:00
#include "moc_kactioncategory.cpp"