KVIrc  4.9.2
DeveloperAPIs
KviAction.h
Go to the documentation of this file.
1 #ifndef _KVI_ACTION_H_
2 #define _KVI_ACTION_H_
3 //=============================================================================
4 //
5 // File : KviAction.h
6 // Creation date : Sun 21 Nov 2004 03:36:34 by Szymon Stefanek
7 //
8 // This file is part of the KVIrc IRC Client distribution
9 // Copyright (C) 2004-2010 Szymon Stefanek <pragma at kvirc dot net>
10 //
11 // This program is FREE software. You can redistribute it and/or
12 // modify it under the terms of the GNU General Public License
13 // as published by the Free Software Foundation; either version 2
14 // of the License, or (at your option) any later version.
15 //
16 // This program is distributed in the HOPE that it will be USEFUL,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19 // See the GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program. If not, write to the Free Software Foundation,
23 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 //
25 //=============================================================================
26 
33 #include "kvi_settings.h"
34 #include "KviPointerList.h"
35 #include "KviIconManager.h"
36 
37 #include <QObject>
38 #include <QPointer>
39 #include <QShortcut>
40 
41 class QShortcut;
42 class QPixmap;
43 class QMenu;
44 class KviCustomToolBar;
45 
46 #undef None
47 
55 {
56 protected:
57  QString m_szName;
58  QString m_szVisibleName;
59  QString m_szDescription;
60 
61 public:
69  KviActionCategory(const QString & szName, const QString & szVisibleName, const QString & szDescription);
70 
75 
76 public:
81  const QString & name() { return m_szName; };
82 
87  const QString & visibleName() { return m_szVisibleName; };
88 
93  const QString & description() { return m_szDescription; };
94 };
95 
100 class KVIRC_API KviAction : public QObject
101 {
102  friend class KviActionManager;
103  Q_OBJECT
104 public:
110  {
111  Enabled = 1,
112  SetupDone = 2
113  };
114 
119  enum Flags
120  {
121  NeedsContext = 1,
122  NeedsConnection = 2,
123  WindowConsole = 4,
124  WindowChannel = 8,
125  WindowQuery = 16,
126  WindowDccChat = 32,
127  InternalWindowMask = WindowConsole | WindowChannel | WindowQuery | WindowDccChat,
128  EnableAtLogin = 64,
129  WindowOnlyIfUsersSelected = 128
130  };
131 
150  KviAction(
151  QObject * pParent,
152  const QString & szName,
153  const QString & szVisibleName,
154  const QString & szDescription,
155  KviActionCategory * pCategory = NULL,
156  const QString & szBigIconId = QString(),
157  const QString & szSmallIconId = QString(),
158  unsigned int uFlags = 0,
159  const QString & szKeySequence = QString());
160 
179  KviAction(
180  QObject * pParent,
181  const QString & szName,
182  const QString & szVisibleName,
183  const QString & szDescription,
184  KviActionCategory * pCategory = NULL,
185  const QString & szBigIconId = QString(),
187  unsigned int uFlags = 0,
188  const QString & szKeySequence = QString());
189 
193  virtual ~KviAction();
194 
195 protected:
196  QString m_szName;
200  QString m_szBigIconId;
201  QString m_szSmallIconId; // this is alternative to m_eSmallIcon
204  unsigned short int m_uInternalFlags;
205  unsigned int m_uFlags;
207  QPointer<QShortcut> m_pAccel;
208 
209 public:
215  static int validateFlags(int iFlagsToValidate);
216 
221  const QString & name() const { return m_szName; };
222 
227  virtual const QString & visibleName();
228 
233  virtual const QString & description();
234 
239  const QString & keySequence() const { return m_szKeySequence; };
240 
245  const QString & bigIconId() const { return m_szBigIconId; };
246 
251  const QString & smallIconId() const { return m_szSmallIconId; };
252 
257  KviActionCategory * category() const { return m_pCategory; };
258 
263  bool isEnabled() const { return (m_uInternalFlags & KviAction::Enabled); };
264 
269  unsigned int flags() { return m_uFlags; };
270 
276  virtual bool isKviUserActionNeverOverrideThis();
277 
283  virtual void setEnabled(bool bEnabled);
284 
289  QPixmap * smallIcon();
290 
295  QPixmap * bigIcon();
296 
302  virtual bool addToPopupMenu(QMenu * pMenu);
303 
309  virtual QAction * addToCustomToolBar(KviCustomToolBar * pParentToolBar);
310 
315  void suicide() { delete this; };
316 protected:
322  bool setupDone() const { return (m_uInternalFlags & KviAction::SetupDone); };
323 
328  virtual void setup();
329 
334  KviPointerList<QAction> * actionList() { return m_pActionList; };
335 
340  void registerAccelerator();
341 
346  void unregisterAccelerator();
347 
353  void registerAction(QAction * pAction);
354 public slots:
362  virtual void activate();
363 protected slots:
370  virtual void actionDestroyed();
371 
378  virtual void reloadImages();
379 
389  virtual void activeContextChanged();
390 
397  virtual void activeContextStateChanged();
398 
405  virtual void activeWindowChanged();
406 
415  virtual void activeWindowSelectionStateChanged(bool bSelectedNow);
416 signals:
421  void activated();
422 };
423 
424 #endif // _KVI_ACTION_H_
const QString & name() const
Returns the name of the action.
Definition: KviAction.h:221
QString m_szKeySequence
Definition: KviAction.h:206
bool setupDone() const
Returns true if the setup is finished.
Definition: KviAction.h:322
void suicide()
Destroys itself. Maybe the best function in the whole APIs :)
Definition: KviAction.h:315
Flags
Holds the flags of an action.
Definition: KviAction.h:119
const QString & name()
Returns the name of the category.
Definition: KviAction.h:81
Definition: KviCustomToolBar.h:37
#define KVIRC_API
Definition: kvi_settings.h:128
Definition: KviAction.h:111
KviActionCategory * m_pCategory
Definition: KviAction.h:199
char * NULL
Definition: KviIrcNumericCodes.h:391
const QString & smallIconId() const
Returns the id of the small icon associated to the action.
Definition: KviAction.h:251
Holds the categories of an action.
Definition: KviAction.h:54
KviPointerList< QAction > * actionList()
Returns the list of actions associated to the action.
Definition: KviAction.h:334
const QString & description()
Returns the description of the category.
Definition: KviAction.h:93
Defines an action inside KVIrc.
Definition: KviAction.h:100
QString m_szSmallIconId
Definition: KviAction.h:201
QPointer< QShortcut > m_pAccel
Definition: KviAction.h:207
unsigned int flags()
Returns the flag associated to the action.
Definition: KviAction.h:269
void actionDestroyed()
Definition: KviActionManager.cpp:265
InternalFlags
Holds the internal flags of an action.
Definition: KviAction.h:109
Definition: KviActionManager.h:36
Icon manager.
QString m_szDescription
Definition: KviAction.h:198
SmallIcon
Contains all KVIrc's small icons.
Definition: KviIconManager.h:168
QString m_szBigIconId
Definition: KviAction.h:200
const QString & keySequence() const
Returns the shortcut of the action.
Definition: KviAction.h:239
const QString & visibleName()
Returns the visible name of the category.
Definition: KviAction.h:87
KviIconManager::SmallIcon m_eSmallIcon
Definition: KviAction.h:202
Definition: KviIconManager.h:170
KviActionCategory * category() const
Returns the category of the action.
Definition: KviAction.h:257
bool isEnabled() const
Returns true if the action is enabled.
Definition: KviAction.h:263
C++ Template based double linked pointer list class.
bool registerAction(KviAction *a)
Definition: KviActionManager.cpp:254
const QString & bigIconId() const
Returns the id of the big icon associated to the action.
Definition: KviAction.h:245
QString m_szDescription
Definition: KviAction.h:59
QString m_szName
Definition: KviAction.h:57
QString m_szVisibleName
Definition: KviAction.h:58
QString m_szName
Definition: KviAction.h:196
KviPointerList< QAction > * m_pActionList
Definition: KviAction.h:203
This file contains compile time settings.
unsigned int m_uFlags
Definition: KviAction.h:205
unsigned short int m_uInternalFlags
Definition: KviAction.h:204
Definition: KviAction.h:112
QString m_szVisibleName
Definition: KviAction.h:197