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
|
2023-06-29 18:20:49 +03:00
|
|
|
{
|
2014-11-13 01:04:59 +02:00
|
|
|
//! The text for this category
|
|
|
|
QString text;
|
|
|
|
//! List of actions
|
|
|
|
QList<QAction*> actions;
|
|
|
|
|
2023-06-29 18:20:49 +03:00
|
|
|
}; // class KActionCategoryPrivate
|
2014-11-13 01:04:59 +02:00
|
|
|
|
|
|
|
|
|
|
|
KActionCategory::KActionCategory(const QString &text, KActionCollection *parent)
|
2023-06-29 18:20:49 +03:00
|
|
|
: QObject(parent),
|
2023-08-28 01:27:27 +03:00
|
|
|
d(new KActionCategoryPrivate())
|
2023-06-29 18:20:49 +03:00
|
|
|
{
|
2014-11-13 01:04:59 +02:00
|
|
|
d->text = text;
|
2023-06-29 18:20:49 +03:00
|
|
|
}
|
2014-11-13 01:04:59 +02:00
|
|
|
|
|
|
|
|
|
|
|
KActionCategory::~KActionCategory()
|
2023-06-29 18:20:49 +03:00
|
|
|
{
|
2014-11-13 01:04:59 +02:00
|
|
|
delete d;
|
2023-06-29 18:20:49 +03:00
|
|
|
}
|
2014-11-13 01:04:59 +02:00
|
|
|
|
|
|
|
const QList<QAction*> KActionCategory::actions() const
|
2023-06-29 18:20:49 +03:00
|
|
|
{
|
2014-11-13 01:04:59 +02:00
|
|
|
return d->actions;
|
2023-06-29 18:20:49 +03:00
|
|
|
}
|
2014-11-13 01:04:59 +02:00
|
|
|
|
2023-06-29 18:20:49 +03: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;
|
2023-06-29 18:20:49 +03:00
|
|
|
}
|
2014-11-13 01:04:59 +02:00
|
|
|
|
2023-06-29 18:20:49 +03: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;
|
2023-06-29 18:20:49 +03:00
|
|
|
}
|
2014-11-13 01:04:59 +02:00
|
|
|
|
2023-06-29 18:20:49 +03: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;
|
2023-06-29 18:20:49 +03:00
|
|
|
}
|
2014-11-13 01:04:59 +02:00
|
|
|
|
2023-06-29 18:20:49 +03: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;
|
2023-06-29 18:20:49 +03:00
|
|
|
}
|
2014-11-13 01:04:59 +02:00
|
|
|
|
2023-06-29 18:20:49 +03: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;
|
2023-06-29 18:20:49 +03:00
|
|
|
}
|
2014-11-13 01:04:59 +02:00
|
|
|
|
|
|
|
void KActionCategory::addAction(QAction *action)
|
2023-06-29 18:20:49 +03:00
|
|
|
{
|
2014-11-13 01:04:59 +02:00
|
|
|
// Only add the action if wasn't added earlier.
|
2023-06-29 18:20:49 +03:00
|
|
|
if (!d->actions.contains(action)) {
|
2014-11-13 01:04:59 +02:00
|
|
|
d->actions.append(action);
|
|
|
|
}
|
2023-06-29 18:20:49 +03:00
|
|
|
}
|
2014-11-13 01:04:59 +02:00
|
|
|
|
|
|
|
|
|
|
|
KActionCollection * KActionCategory::collection() const
|
2023-06-29 18:20:49 +03:00
|
|
|
{
|
2014-11-13 01:04:59 +02:00
|
|
|
return qobject_cast<KActionCollection*>(parent());
|
2023-06-29 18:20:49 +03:00
|
|
|
}
|
2014-11-13 01:04:59 +02:00
|
|
|
|
|
|
|
QString KActionCategory::text() const
|
2023-06-29 18:20:49 +03:00
|
|
|
{
|
2014-11-13 01:04:59 +02:00
|
|
|
return d->text;
|
2023-06-29 18:20:49 +03:00
|
|
|
}
|
2014-11-13 01:04:59 +02:00
|
|
|
|
|
|
|
void KActionCategory::setText(const QString &text)
|
2023-06-29 18:20:49 +03:00
|
|
|
{
|
2014-11-13 01:04:59 +02:00
|
|
|
d->text = text;
|
2023-06-29 18:20:49 +03:00
|
|
|
}
|
2014-11-13 01:04:59 +02:00
|
|
|
|
|
|
|
void KActionCategory::unlistAction(QAction *action)
|
2023-06-29 18:20:49 +03:00
|
|
|
{
|
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.
|
2023-06-29 18:20:49 +03:00
|
|
|
if (index==-1) {
|
|
|
|
return;
|
|
|
|
}
|
2014-11-13 01:04:59 +02:00
|
|
|
|
|
|
|
// Remove the action
|
|
|
|
d->actions.takeAt(index);
|
2023-06-29 18:20:49 +03:00
|
|
|
}
|
2014-11-13 01:04:59 +02:00
|
|
|
|
|
|
|
#include "moc_kactioncategory.cpp"
|