[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-core-devel
Subject: Re: Adding KUndoGroup
From: Albert Astals Cid <aacid () kde ! org>
Date: 2008-05-01 16:43:28
Message-ID: 200805011843.30021.aacid () kde ! org
[Download RAW message or body]
A Dijous 01 Maig 2008, Albert Astals Cid va escriure:
> Might i add KUndoGroup that inherits QUndoGroup and adds proper
> QAction *createRedoAction(KActionCollection* actionCollection, const
> QString& actionName)
> and
> QAction *createUndoAction(KActionCollection* actionCollection, const
> QString& actionName)
> like KUndoStack does?
>
> That is, set the KDE proper icon, icon text, shortcut and add it to the
> actioncollection.
>
> Albert
Well, i did some copy&paste, here is the patch i'm proposing.
Albert
["kundogroup.patch" (text/x-diff)]
Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt (revision 801396)
+++ CMakeLists.txt (working copy)
@@ -164,6 +164,8 @@
util/kxmessages.cpp
util/kxutils.cpp
util/kundostack.cpp
+ util/kundogroup.cpp
+ util/kundo_p.cpp
widgets/kactionselector.cpp
widgets/kanimatedbutton.cpp
widgets/karrowbutton.cpp
@@ -432,6 +434,7 @@
util/kxutils.h
util/kxmessages.h
util/kundostack.h
+ util/kundogroup.h
widgets/kactionselector.h
widgets/kanimatedbutton.h
widgets/karrowbutton.h
Index: util/kundogroup.h
===================================================================
--- util/kundogroup.h (revision 0)
+++ util/kundogroup.h (revision 0)
@@ -0,0 +1,59 @@
+/* This file is part of the KDE project
+ Copyright (C) 2006 Peter Simonsson <peter.simonsson@gmail.com>
+
+ 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.
+*/
+
+#ifndef KUNDOGROUP_H
+#define KUNDOGROUP_H
+
+#include <kdeui_export.h>
+
+#include <QtGui/QUndoGroup>
+
+class KActionCollection;
+
+/**
+ * Extends QUndoGroup with functions that creates actions with KDE's default icons \
and shortcuts. + * See QUndoGroup for more information.
+ */
+class KDEUI_EXPORT KUndoGroup : public QUndoGroup
+{
+ Q_OBJECT
+ public:
+ /**
+ * Constructs a KUndoGroup with @p parent as parent
+ * @param parent parent of the object
+ */
+ KUndoGroup(QObject* parent = 0);
+
+ /**
+ * Creates an redo action with the default shortcut and icon and adds it to \
@p actionCollection + * @param actionCollection the KActionCollection that \
should be the parent of the action + * @param actionName the created action's \
object name, empty string will set it to the KDE default + * @return the \
created action. + */
+ QAction* createRedoAction(KActionCollection* actionCollection, const \
QString& actionName = QString()); + /**
+ * Creates an undo action with the default KDE shortcut and icon and adds it \
to @p actionCollection + * @param actionCollection the KActionCollection that \
should be the parent of the action + * @param actionName the created action's \
object name, empty string will set it to the KDE default + * @return the \
created action. + */
+ QAction* createUndoAction(KActionCollection* actionCollection, const \
QString& actionName = QString()); +};
+
+#endif
Index: util/kundo_p.h
===================================================================
--- util/kundo_p.h (revision 0)
+++ util/kundo_p.h (revision 0)
@@ -0,0 +1,47 @@
+/* This file is part of the KDE project
+ Copyright (C) 2006 Peter Simonsson <peter.simonsson@gmail.com>
+
+ 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.
+*/
+
+#ifndef KUNDO_PRIVATE_H
+#define KUNDO_PRIVATE_H
+
+class QAction;
+class QString;
+
+class KActionCollection;
+
+namespace KUndoPrivate
+{
+ /**
+ * Fills an action with the default redo shortcut and icon and adds it to @p \
actionCollection + * @param actionCollection the KActionCollection that should be \
the parent of the action + * @param actionName the created action's object name, \
empty string will set it to the KDE default + * @return the created action.
+ */
+ void fillRedoAction(QAction* action, KActionCollection* actionCollection, const \
QString& actionName); +
+ /**
+ * Fills an an action with the default undo KDE shortcut and icon and adds it \
to @p actionCollection + * @param actionCollection the KActionCollection that \
should be the parent of the action + * @param actionName the created action's \
object name, empty string will set it to the KDE default + * @return the created \
action. + */
+ void fillUndoAction(QAction* action, KActionCollection* actionCollection, \
const QString& actionName); +}
+
+#endif
Index: util/kundostack.cpp
===================================================================
--- util/kundostack.cpp (revision 801396)
+++ util/kundostack.cpp (working copy)
@@ -18,16 +18,9 @@
*/
#include "kundostack.h"
+#include "kundo_p.h"
-#include <QAction>
-#include <QKeySequence>
-#include <QList>
-
-#include <kstandardaction.h>
-#include <kstandardshortcut.h>
-#include <kicon.h>
#include <kactioncollection.h>
-#include <klocale.h>
KUndoStack::KUndoStack(QObject* parent)
: QUndoStack(parent)
@@ -37,38 +30,16 @@
QAction* KUndoStack::createRedoAction(KActionCollection* actionCollection, const \
QString& actionName) {
QAction* action = QUndoStack::createRedoAction(actionCollection);
+ KUndoPrivate::fillRedoAction(action, actionCollection, actionName);
- if(actionName.isEmpty()) {
- action->setObjectName(KStandardAction::name(KStandardAction::Redo));
- } else {
- action->setObjectName(actionName);
- }
-
- action->setIcon(KIcon("edit-redo"));
- action->setIconText(i18n("Redo"));
- action->setShortcuts(KStandardShortcut::redo());
-
- actionCollection->addAction(action->objectName(), action);
-
return action;
}
QAction* KUndoStack::createUndoAction(KActionCollection* actionCollection, const \
QString& actionName) {
QAction* action = QUndoStack::createUndoAction(actionCollection);
+ KUndoPrivate::fillUndoAction(action, actionCollection, actionName);
- if(actionName.isEmpty()) {
- action->setObjectName(KStandardAction::name(KStandardAction::Undo));
- } else {
- action->setObjectName(actionName);
- }
-
- action->setIcon(KIcon("edit-undo"));
- action->setIconText(i18n("Undo"));
- action->setShortcuts(KStandardShortcut::undo());
-
- actionCollection->addAction(action->objectName(), action);
-
return action;
}
Index: util/kundogroup.cpp
===================================================================
--- util/kundogroup.cpp (revision 0)
+++ util/kundogroup.cpp (revision 0)
@@ -0,0 +1,46 @@
+/* This file is part of the KDE project
+ Copyright (C) 2006 Peter Simonsson <peter.simonsson@gmail.com>
+
+ 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 "kundogroup.h"
+#include "kundo_p.h"
+
+#include <kactioncollection.h>
+
+KUndoGroup::KUndoGroup(QObject* parent)
+: QUndoGroup(parent)
+{
+}
+
+QAction* KUndoGroup::createRedoAction(KActionCollection* actionCollection, const \
QString& actionName) +{
+ QAction* action = QUndoGroup::createRedoAction(actionCollection);
+ KUndoPrivate::fillRedoAction(action, actionCollection, actionName);
+
+ return action;
+}
+
+QAction* KUndoGroup::createUndoAction(KActionCollection* actionCollection, const \
QString& actionName) +{
+ QAction* action = QUndoGroup::createUndoAction(actionCollection);
+ KUndoPrivate::fillUndoAction(action, actionCollection, actionName);
+
+ return action;
+}
+
+#include "kundogroup.moc"
Index: util/kundo_p.cpp
===================================================================
--- util/kundo_p.cpp (revision 0)
+++ util/kundo_p.cpp (revision 0)
@@ -0,0 +1,47 @@
+
+#include "kundo_p.h"
+
+#include <kstandardaction.h>
+#include <kstandardshortcut.h>
+#include <kicon.h>
+#include <kactioncollection.h>
+#include <klocale.h>
+
+#include <QAction>
+#include <QKeySequence>
+#include <QList>
+
+namespace KUndoPrivate
+{
+
+void fillRedoAction(QAction* action, KActionCollection* actionCollection, const \
QString& actionName) +{
+ if(actionName.isEmpty()) {
+ action->setObjectName(KStandardAction::name(KStandardAction::Redo));
+ } else {
+ action->setObjectName(actionName);
+ }
+
+ action->setIcon(KIcon("edit-redo"));
+ action->setIconText(i18n("Redo"));
+ action->setShortcuts(KStandardShortcut::redo());
+
+ actionCollection->addAction(action->objectName(), action);
+}
+
+void fillUndoAction(QAction* action, KActionCollection* actionCollection, const \
QString& actionName) +{
+ if(actionName.isEmpty()) {
+ action->setObjectName(KStandardAction::name(KStandardAction::Undo));
+ } else {
+ action->setObjectName(actionName);
+ }
+
+ action->setIcon(KIcon("edit-undo"));
+ action->setIconText(i18n("Undo"));
+ action->setShortcuts(KStandardShortcut::undo());
+
+ actionCollection->addAction(action->objectName(), action);
+}
+
+}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic