KDEUI
kactioncategory.cpp
Go to the documentation of this file.
00001 /* Copyright (C) 2008 Michael Jansen <kde@michael-jansen.biz> 00002 00003 This library is free software; you can redistribute it and/or 00004 modify it under the terms of the GNU Library General Public 00005 License as published by the Free Software Foundation; either 00006 version 2 of the License, or (at your option) any later version. 00007 00008 This library is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00011 Library General Public License for more details. 00012 00013 You should have received a copy of the GNU Library General Public License 00014 along with this library; see the file COPYING.LIB. If not, write to 00015 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00016 Boston, MA 02110-1301, USA. 00017 */ 00018 00019 #include "kactioncategory.h" 00020 00021 #include <QtGui/QAction> 00022 00023 #include "kaction.h" 00024 00025 00026 struct KActionCategoryPrivate 00027 { 00028 00029 KActionCategoryPrivate( KActionCategory *host ); 00030 00032 KActionCategory *q; 00033 00035 QString text; 00036 00038 QList<QAction*> actions; 00039 00040 }; // class KActionCategoryPrivate 00041 00042 00043 KActionCategory::KActionCategory(const QString &text, KActionCollection *parent) 00044 : QObject(parent) 00045 ,d( new KActionCategoryPrivate(this) ) 00046 { 00047 d->text = text; 00048 } 00049 00050 00051 KActionCategory::~KActionCategory() 00052 { 00053 delete d; 00054 } 00055 00056 00057 const QList<QAction*> KActionCategory::actions() const 00058 { 00059 return d->actions; 00060 } 00061 00062 00063 QAction * KActionCategory::addAction(const QString &name, QAction *action) 00064 { 00065 collection()->addAction(name, action); 00066 addAction(action); 00067 return action; 00068 } 00069 00070 00071 KAction * KActionCategory::addAction(const QString &name, KAction *action) 00072 { 00073 collection()->addAction(name, action); 00074 addAction(action); 00075 return action; 00076 } 00077 00078 00079 KAction * KActionCategory::addAction( 00080 KStandardAction::StandardAction actionType, 00081 const QObject *receiver, 00082 const char *member) 00083 { 00084 KAction *action = collection()->addAction(actionType, receiver, member); 00085 addAction(action); 00086 return action; 00087 } 00088 00089 00090 KAction * KActionCategory::addAction( 00091 KStandardAction::StandardAction actionType, 00092 const QString &name, 00093 const QObject *receiver, 00094 const char *member) 00095 { 00096 KAction *action = collection()->addAction(actionType, name, receiver, member); 00097 addAction(action); 00098 return action; 00099 } 00100 00101 00102 KAction *KActionCategory::addAction( 00103 const QString &name, 00104 const QObject *receiver, 00105 const char *member) 00106 { 00107 KAction *action = collection()->addAction(name, receiver, member); 00108 addAction(action); 00109 return action; 00110 } 00111 00112 00113 void KActionCategory::addAction(QAction *action) 00114 { 00115 // Only add the action if wasn't added earlier. 00116 if (!d->actions.contains(action)) 00117 { 00118 d->actions.append(action); 00119 } 00120 } 00121 00122 00123 KActionCollection * KActionCategory::collection() const 00124 { 00125 return qobject_cast<KActionCollection*>(parent()); 00126 } 00127 00128 00129 QString KActionCategory::text() const 00130 { 00131 return d->text; 00132 } 00133 00134 00135 void KActionCategory::setText(const QString &text) 00136 { 00137 d->text = text; 00138 } 00139 00140 00141 void KActionCategory::unlistAction(QAction *action) 00142 { 00143 // ATTENTION: 00144 // This method is called from KActionCollection with an QObject formerly 00145 // known as a QAction during _k_actionDestroyed(). So don't do fancy stuff 00146 // here that needs a real QAction! 00147 00148 // Get the index for the action 00149 int index = d->actions.indexOf(action); 00150 00151 // Action not found. 00152 if (index==-1) return; 00153 00154 // Remove the action 00155 d->actions.takeAt(index); 00156 } 00157 00158 00159 KActionCategoryPrivate::KActionCategoryPrivate( KActionCategory *host ) 00160 : q(host) 00161 {} 00162 00163 00164 #include "moc_kactioncategory.cpp"
KDE 4.6 API Reference