libqutim  0.3.1.0
settingslayer.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 SETTINGSLAYER_H
27 #define SETTINGSLAYER_H
28 
29 #include <qglobal.h>
30 #include "localizedstring.h"
31 #include "objectgenerator.h"
32 #include <QPointer>
33 #include <QWidget>
34 #include <QGraphicsObject>
35 #include <QIcon>
36 #include <QComboBox>
37 
38 namespace qutim_sdk_0_3
39 {
40 class SettingsWidget;
41 class SettingsItem;
42 class SettingsItemPrivate;
43 class MenuController;
44 class DataItem;
45 
46 typedef QList<SettingsItem *> SettingsItemList;
47 
48 namespace Settings
49 {
50  enum Type
51  {
52  Invalid = 0,
58  };
59 
60 // struct TypeEntry
61 // {
62 // TypeEntry(const QIcon &icon,const LocalizedString &title,const LocalizedString &description = LocalizedString());
63 // TypeEntry() {}
64 // LocalizedString text;
65 // QIcon icon;
66 // };
67 
68 // typedef QMap<Settings::Type,TypeEntry> TypeEntryMap;
69 
70  // Exmample of usage:
71  // Settings::registerItem(new SettingsWidget<MyCoolPopupSettings>(
72  // Settings::Appearance,
73  // QIcon(":/icons/mycoolicon"),
74  // QT_TRANSLATE_NOOP_UTF8("Settings", "Popup theme")));
75 
81  LIBQUTIM_EXPORT QIcon getTypeIcon(Type type);
85  LIBQUTIM_EXPORT void registerItem(SettingsItem *item, const QMetaObject *meta);
89  template <typename T>
90  Q_INLINE_TEMPLATE void registerItem(SettingsItem *item) { registerItem(item,&T::staticMetaObject); }
91 
95  SettingsItemList items(const QMetaObject *meta);
96  template <typename T>
97  Q_INLINE_TEMPLATE SettingsItemList items() { return items(&T::staticMetaObject); }
98  //TODO,
99 // LIBQUTIM_EXPORT TypeEntryMap *entries();
100 // LIBQUTIM_EXPORT quint16 registerType(const char *id,
101 // const QIcon &icon,
102 // const LocalizedString &text,
103 // const LocalizedString &description = LocalizedString());
104 }
105 
107 {
108  Q_DISABLE_COPY(SettingsItem)
109  Q_DECLARE_PRIVATE(SettingsItem)
110 public:
111  SettingsItem(SettingsItemPrivate &d);
112  SettingsItem(Settings::Type type, const QIcon &icon, const LocalizedString &text);
113  SettingsItem(Settings::Type type, const LocalizedString &text);
114  virtual ~SettingsItem();
115  Settings::Type type() const;
116  QIcon icon() const;
117  LocalizedString text() const;
118  SettingsWidget *widget() const;
119  QGraphicsObject *graphicsObject() const;
120  QObject *object() const;
121  bool isWidget() const;
122  void clearWidget();
123  void connect(const char *signal, QObject *receiver, const char *member);
124  int order() const;
125  void setOrder(int order);
126  int priority() const;
127  void setPriority(int priority);
128 protected:
129  virtual const ObjectGenerator *generator() const = 0;
130  QScopedPointer<SettingsItemPrivate> d_ptr;
131 };
132 
133 template<typename T>
135 {
136 public:
138  : SettingsItem(type, icon, text) {}
140  : SettingsItem(type, text) {}
141  virtual ~GeneralSettingsItem() {}
142 protected:
143  virtual const ObjectGenerator *generator() const
144  {
145  // T must be based on SettingsWidget
146  register SettingsWidget *widget = reinterpret_cast<T *>(0);
147  Q_UNUSED(widget);
148  return new GeneralGenerator<T>();
149  }
150 };
151 
152 class AutoSettingsItemPrivate;
154 {
155  Q_DECLARE_PRIVATE(AutoSettingsItem)
156 public:
157  class EntryPrivate;
159  {
160  public:
161  Entry(const LocalizedString &text, const ObjectGenerator *gen);
162  virtual ~Entry();
163  Entry *setProperty(const char *name, QVariant value);
164  Entry *setName(const QString &name);
165  const LocalizedString &text() const;
166  const ObjectGenerator *generator() const;
167  QWidget *widget(QWidget *parent = 0) const;
168  const QString &name() const;
169  private:
170  QScopedPointer<EntryPrivate> p;
171  };
172  AutoSettingsItem(Settings::Type type, const QIcon &icon, const LocalizedString &text);
174  virtual ~AutoSettingsItem();
175  void setConfig(const QString &config, const QString &group);
176  Entry *addEntry(const LocalizedString &text, const ObjectGenerator *gen);
177  template <typename T>
179  {
180  register QWidget *widget = reinterpret_cast<T *>(0);
181  Q_UNUSED(widget);
182  return addEntry(text, new GeneralGenerator<T>());
183  }
184 private:
185  virtual const ObjectGenerator *generator() const;
186 };
187 
188 class LIBQUTIM_EXPORT AutoSettingsComboBox : public QComboBox
189 {
190  Q_PROPERTY(QStringList items READ items WRITE setItems)
191  Q_OBJECT
192 public:
194  QStringList items() const;
195  void setItems(const QStringList &ls);
196 };
197 
198 class AutoSettingsFileChooserPrivate;
200 {
201  Q_PROPERTY(QString path READ path WRITE setPath NOTIFY pathChanged USER true)
202  Q_OBJECT
203  Q_DECLARE_PRIVATE(AutoSettingsFileChooser)
204 public:
205  AutoSettingsFileChooser(QWidget *parent = 0);
207  QString path() const;
208  void setPath(const QString &p);
209 signals:
210  void pathChanged(const QString &path);
211 private:
212  QScopedPointer<AutoSettingsFileChooserPrivate> d_ptr;
213 };
214 
215 class LIBQUTIM_EXPORT SettingsLayer : public QObject
216 {
217  Q_OBJECT
218  Q_CLASSINFO("Service", "SettingsLayer")
219 public:
220  virtual void show(const SettingsItemList &settings, QObject *controller = 0) = 0;
221  virtual void close(QObject* controller = 0) = 0;
222  virtual void update(const SettingsItemList &settings, QObject *controller = 0) = 0;
223  void show (MenuController *controller);
224 protected:
225  SettingsLayer();
226  virtual ~SettingsLayer();
227  virtual void virtual_hook(int id, void *data);
228 };
229 }
230 
232 
233 #endif // SETTINGSLAYER_H
234 

Generated by Doxygen