libqutim  0.3.1.0
actiongenerator.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** qutIM - instant messenger
4 **
5 ** Copyright © 2011 Ruslan Nigmatullin <euroelessar@yandex.ru>
6 **
7 *****************************************************************************
8 **
9 ** $QUTIM_BEGIN_LICENSE$
10 ** This program is free software: you can redistribute it and/or modify
11 ** it under the terms of the GNU General Public License as published by
12 ** the Free Software Foundation, either version 3 of the License, or
13 ** (at your option) any later version.
14 **
15 ** This program is distributed in the hope that it will be useful,
16 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 ** See the GNU General Public License for more details.
19 **
20 ** You should have received a copy of the GNU General Public License
21 ** along with this program. If not, see http://www.gnu.org/licenses/.
22 ** $QUTIM_END_LICENSE$
23 **
24 ****************************************************************************/
25 
26 #ifndef ACTIONGENERATOR_H
27 #define ACTIONGENERATOR_H
28 
29 #include "objectgenerator.h"
30 #include "localizedstring.h"
31 #include <QtGui/QIcon>
32 #include <QtGui/QAction>
33 #include <QtCore/QEvent>
34 #include <QAction>
35 
36 namespace qutim_sdk_0_3
37 {
38 class ActionGenerator;
39 class ActionGeneratorPrivate;
40 class MenuController;
41 class ActionToolBar;
42 class ActionCollectionPrivate;
43 class ActionValue;
44 
45 //TBD list of all action roles
47 {
48  ActionTypeContactList = 0x01, //Actions in contactlist
49  ActionTypeChatButton = 0x02, //Chat buttons
50  ActionTypeAdditional = 0x04, //Additional modifier
52  ActionTypePreferences = 0x10, //QAction::PreferencesRole
54 };
55 
56 Q_DECLARE_FLAGS(ActionsType,ActionType)
57 
59 {
62 };
63 
64 Q_DECLARE_FLAGS(ActionHandlerTypes,ActionHandlerType)
65 
66 class LIBQUTIM_EXPORT ActionCreatedEvent : public QEvent
67 {
68 public:
69  ActionCreatedEvent(QAction *action, ActionGenerator *gen, QObject *controller);
70  static QEvent::Type eventType();
71  QAction *action() const { return m_action; }
72  ActionGenerator *generator() const { return m_gen; }
73  QObject *controller() const {return m_con;}
74 private:
75  QAction *m_action;
76  ActionGenerator *m_gen;
77  QObject *m_con;
78 };
79 
81 {
82 public:
83  ActionVisibilityChangedEvent(QAction *action,QObject *controller, bool isVisible = true);
84  static QEvent::Type eventType();
85  QAction *action() const { return m_action; }
86  QObject *controller() const { return m_controller; }
87  bool isVisible() const { return m_visible; }
88 private:
89  QAction *m_action;
90  QObject *m_controller;
91  bool m_visible;
92 
93 };
94 
95 // TODO: Resolve problem with action groups, checkable actions and so one
96 // Possible solutions:
97 // * add flag for creating 'unique' actions with different instances for different objects
98 // * add new quint64 property, named 'groupId', which should be unique for every action
99 // and equal for action groups (use algorithm equal to message ids), if core founds
100 // actions with similiar group ids it addes them to QActionGroup
101 //
102 // Also It should be usefull to create some class-listener for unique actions, for such
103 // events as ActionCreated, ActionDestroyed and with ability for changing them during
104 // their lifetime (making disabled/checked and so on)
105 // It should be usefull to create method for getting QAction for MenuController passed
106 // as argument. BTW, unique actions should be created only once for each object, use i.e.
107 // QWeakPointer at cache and QSharedPointer at ActionContainer
108 //
109 // Try to remove any use of legacy ActionGenerator's members everywhere at qutIM
111 {
112  Q_DECLARE_PRIVATE(ActionGenerator)
113  Q_DISABLE_COPY(ActionGenerator)
114  Q_GADGET
115 public:
116  enum Type { StatusType = 0, GeneralType };
117  /*
118  * \code
119 void MyObject::onAction(QObject *obj)
120 {
121  Account *account = qobject_cast<Account*>(obj);
122  Q_ASSERT(account);
123  doStuff();
124 }
125  \endcode
126  */
127  ActionGenerator(const QIcon &icon, const LocalizedString &text, const QObject *receiver, const char *member);
128  // Convience constructor for menus
129  ActionGenerator(const QIcon &icon, const LocalizedString &text, const char *member);
130 #ifndef Q_QDOC
131  ActionGenerator(ActionGeneratorPrivate &priv);
132 #endif
133  virtual ~ActionGenerator();
134  QIcon icon() const;
135  const LocalizedString &text() const;
136  const QObject *receiver() const;
137  const char *member() const;
138  ActionGenerator *addProperty(const QByteArray &name, const QVariant &value);
139  int type() const;
140  ActionGenerator *setType(int type);
141  int priority() const;
142  ActionGenerator *setPriority(int priority);
143  void setMenuController(MenuController *controller);
144  void subscribe(QObject *object, const char *method);
145  //void unsubscribe(QObject *object); //TODO implement me
146  void addHandler(int type, QObject *obj);
147  void removeHandler(int type, QObject *obj);
148  void setCheckable(bool checkable);
149  void setChecked(bool checked);
150  void setToolTip(const LocalizedString &toolTip);
151  void setShortcut(const QKeySequence &shortcut);
152  void setShortcut(const QString &id);
153  QString shortcut() const;
154  void setMenuRole(QAction::MenuRole role);
155  QAction::MenuRole menuRole() const;
156  void setIconVisibleInMenu(bool visible);
157  bool iconVisibleInMenu() const;
158  QList<QAction*> actions(QObject *object) const;
159  QMap<QObject*, QAction*> actions() const;
160  static ActionGenerator *get(QAction *);
161 protected:
162  QAction *prepareAction(QAction *action) const;
163  virtual QObject *generateHelper() const;
164  virtual const QMetaObject *metaObject() const;
165  virtual QList<QByteArray> interfaces() const;
166  void create(QAction *action,QObject *obj) const;
167  virtual void createImpl(QAction *action,QObject *obj) const;
168  virtual void showImpl(QAction *action,QObject *obj); //obj usally is controller, default implementation do nothing
169  virtual void hideImpl(QAction *action,QObject *obj);
170 private:
171  friend class MenuController;
172  friend class ActionToolBar;
173  friend class MenuControllerPrivate;
174  friend class ActionValue;
175  friend class ActionContainerPrivate;
176 };
177 
179 {
180  Q_DECLARE_PRIVATE(ActionGenerator)
181  Q_DISABLE_COPY(MenuActionGenerator)
182 public:
183  MenuActionGenerator(const QIcon &icon, const LocalizedString &text, QMenu *menu);
184  MenuActionGenerator(const QIcon &icon, const LocalizedString &text, MenuController *controller);
185  virtual ~MenuActionGenerator();
186 protected:
187  virtual QObject *generateHelper() const;
188 };
189 }
190 
192 
193 #endif // ACTIONGENERATOR_H
194 

Generated by Doxygen