QCodeEdit  2.2
qpanel.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2006-2009 fullmetalcoder <fullmetalcoder@hotmail.fr>
4 **
5 ** This file is part of the Edyuk project <http://edyuk.org>
6 **
7 ** This file may be used under the terms of the GNU General Public License
8 ** version 3 as published by the Free Software Foundation and appearing in the
9 ** file GPL.txt included in the packaging of this file.
10 **
11 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13 **
14 ****************************************************************************/
15 
16 #ifndef _QPANEL_H_
17 #define _QPANEL_H_
18 
28 #include "qce-config.h"
29 
30 #include <QHash>
31 #include <QWidget>
32 #include <QPointer>
33 
34 class QPainter;
35 class QPaintEvent;
36 
37 class QEditor;
38 class QPanelCreator;
39 
40 class QCE_EXPORT QPanel : public QWidget
41 {
42  Q_OBJECT
43 
44  public:
45  QPanel(QWidget *p = 0);
46  virtual ~QPanel();
47 
48  virtual QString id() const = 0;
49  virtual QString type() const = 0;
50 
51  QEditor* editor();
52  void attach(QEditor *e);
53 
54  virtual bool shallShow() const;
55 
56  bool defaultVisibility() const;
57  void setDefaultVisibility(bool on);
58 
59  static QPanel* panel(const QString& id, QWidget *p = 0);
60  static void registerCreator(QPanelCreator *c);
61 
62  protected:
63  virtual bool forward(QMouseEvent *e);
64 
65  virtual void editorChange(QEditor *e);
66 
67  virtual void mouseMoveEvent(QMouseEvent *e);
68  virtual void mousePressEvent(QMouseEvent *e);
69  virtual void mouseReleaseEvent(QMouseEvent *e);
70 
71  virtual void showEvent(QShowEvent *e);
72  virtual void hideEvent(QHideEvent *e);
73  virtual void paintEvent(QPaintEvent *e);
74  virtual bool paint(QPainter *p, QEditor *e);
75 
76  private:
77  QPointer<QEditor> m_editor;
78  bool m_defaultVisibility, m_shownOnce;
79  static QHash<QString, QPanelCreator*>& creators();
80 };
81 
83 {
84  public:
85  virtual ~QPanelCreator() {}
86  virtual QString id() const = 0;
87  virtual QPanel* panel(QWidget *p) = 0;
88 };
89 
90 #define Q_PANEL(T, SID) \
91  public: \
92  class Creator : public QPanelCreator \
93  { \
94  public: \
95  virtual QString id() const \
96  { \
97  return SID; \
98  } \
99  \
100  virtual QPanel* panel(QWidget *p) \
101  { \
102  return new T(p); \
103  } \
104  \
105  static QPanelCreator* instance() \
106  { \
107  static Creator global; \
108  return &global; \
109  } \
110  \
111  Creator() {} \
112  virtual ~Creator() {} \
113  }; \
114  \
115  QString id() const { return SID; } \
116  \
117  static void _register() \
118  { \
119  QPanel::registerCreator(Creator::instance()); \
120  } \
121 
122 
123 #define Q_PANEL_ID(T) \
124  T::Creator::instance()->id() \
125 
126 
127 #define Q_CREATE_PANEL(T) \
128  QPanel::panel(Q_PANEL_ID(T)) \
129 
130 
131 #endif // _QPANEL_H_