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 <QIcon>
32 #include <QEvent>
33 #include <QAction>
34 
35 namespace qutim_sdk_0_3
36 {
37 class ActionGenerator;
38 class ActionGeneratorPrivate;
39 class MenuController;
40 class ActionToolBar;
41 class ActionCollectionPrivate;
42 class ActionValue;
43 
44 //TBD list of all action roles
46 {
47  ActionTypeContactList = 0x01, //Actions in contactlist
48  ActionTypeChatButton = 0x02, //Chat buttons
49  ActionTypeAdditional = 0x04, //Additional modifier
51  ActionTypePreferences = 0x10, //QAction::PreferencesRole
53 };
54 
55 Q_DECLARE_FLAGS(ActionsType,ActionType)
56 
58 {
61 };
62 
63 Q_DECLARE_FLAGS(ActionHandlerTypes,ActionHandlerType)
64 
65 class LIBQUTIM_EXPORT ActionCreatedEvent : public QEvent
66 {
67 public:
68  ActionCreatedEvent(QAction *action, ActionGenerator *gen, QObject *controller);
69  static QEvent::Type eventType();
70  QAction *action() const { return m_action; }
71  ActionGenerator *generator() const { return m_gen; }
72  QObject *controller() const {return m_con;}
73 private:
74  QAction *m_action;
75  ActionGenerator *m_gen;
76  QObject *m_con;
77 };
78 
80 {
81 public:
82  ActionVisibilityChangedEvent(QAction *action,QObject *controller, bool isVisible = true);
83  static QEvent::Type eventType();
84  QAction *action() const { return m_action; }
85  QObject *controller() const { return m_controller; }
86  bool isVisible() const { return m_visible; }
87 private:
88  QAction *m_action;
89  QObject *m_controller;
90  bool m_visible;
91 
92 };
93 
94 // TODO: Resolve problem with action groups, checkable actions and so one
95 // Possible solutions:
96 // * add flag for creating 'unique' actions with different instances for different objects
97 // * add new quint64 property, named 'groupId', which should be unique for every action
98 // and equal for action groups (use algorithm equal to message ids), if core founds
99 // actions with similiar group ids it addes them to QActionGroup
100 //
101 // Also It should be usefull to create some class-listener for unique actions, for such
102 // events as ActionCreated, ActionDestroyed and with ability for changing them during
103 // their lifetime (making disabled/checked and so on)
104 // It should be usefull to create method for getting QAction for MenuController passed
105 // as argument. BTW, unique actions should be created only once for each object, use i.e.
106 // QPointer at cache and QSharedPointer at ActionContainer
107 //
108 // Try to remove any use of legacy ActionGenerator's members everywhere at qutIM
110 {
111  Q_DECLARE_PRIVATE(ActionGenerator)
112  Q_DISABLE_COPY(ActionGenerator)
113  Q_GADGET
114 public:
115  enum Type { StatusType = 0, GeneralType };
116  /*
117  * \code
118 void MyObject::onAction(QObject *obj)
119 {
120  Account *account = qobject_cast<Account*>(obj);
121  Q_ASSERT(account);
122  doStuff();
123 }
124  \endcode
125  */
126  ActionGenerator(const QIcon &icon, const LocalizedString &text, const QObject *receiver, const char *member);
127  // Convience constructor for menus
128  ActionGenerator(const QIcon &icon, const LocalizedString &text, const char *member);
129 #ifndef Q_QDOC
130  ActionGenerator(ActionGeneratorPrivate &priv);
131 #endif
132  virtual ~ActionGenerator();
133  QIcon icon() const;
134  const LocalizedString &text() const;
135  const QObject *receiver() const;
136  const char *member() const;
137  ActionGenerator *addProperty(const QByteArray &name, const QVariant &value);
138  int type() const;
139  ActionGenerator *setType(int type);
140  int priority() const;
141  ActionGenerator *setPriority(int priority);
142  void setMenuController(MenuController *controller);
143  void subscribe(QObject *object, const char *method);
144  //void unsubscribe(QObject *object); //TODO implement me
145  void addHandler(int type, QObject *obj);
146  void removeHandler(int type, QObject *obj);
147  void setCheckable(bool checkable);
148  void setChecked(bool checked);
149  void setToolTip(const LocalizedString &toolTip);
150  void setShortcut(const QKeySequence &shortcut);
151  void setShortcut(const QString &id);
152  QString shortcut() const;
153  void setMenuRole(QAction::MenuRole role);
154  QAction::MenuRole menuRole() const;
155  void setIconVisibleInMenu(bool visible);
156  bool iconVisibleInMenu() const;
157  QList<QAction*> actions(QObject *object) const;
158  QMap<QObject*, QAction*> actions() const;
159  static ActionGenerator *get(QAction *);
160 protected:
161  QAction *prepareAction(QAction *action) const;
162  virtual QObject *generateHelper() const;
163  virtual const QMetaObject *metaObject() const;
164  virtual QList<QByteArray> interfaces() const;
165  void create(QAction *action,QObject *obj) const;
166  virtual void createImpl(QAction *action,QObject *obj) const;
167  virtual void showImpl(QAction *action,QObject *obj); //obj usally is controller, default implementation do nothing
168  virtual void hideImpl(QAction *action,QObject *obj);
169 private:
170  friend class MenuController;
171  friend class ActionToolBar;
172  friend class MenuControllerPrivate;
173  friend class ActionValue;
174  friend class ActionContainerPrivate;
175 };
176 
178 {
179  Q_DECLARE_PRIVATE(ActionGenerator)
180  Q_DISABLE_COPY(MenuActionGenerator)
181 public:
182  MenuActionGenerator(const QIcon &icon, const LocalizedString &text, QMenu *menu);
183  MenuActionGenerator(const QIcon &icon, const LocalizedString &text, MenuController *controller);
184  virtual ~MenuActionGenerator();
185 protected:
186  virtual QObject *generateHelper() const;
187 };
188 }
189 
191 
192 #endif // ACTIONGENERATOR_H
193 

Generated by Doxygen