QCodeEdit
2.2
|
00001 /**************************************************************************** 00002 ** 00003 ** Copyright (C) 2006-2009 fullmetalcoder <fullmetalcoder@hotmail.fr> 00004 ** 00005 ** This file is part of the Edyuk project <http://edyuk.org> 00006 ** 00007 ** This file may be used under the terms of the GNU General Public License 00008 ** version 3 as published by the Free Software Foundation and appearing in the 00009 ** file GPL.txt included in the packaging of this file. 00010 ** 00011 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00012 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00013 ** 00014 ****************************************************************************/ 00015 00016 #ifndef _QPANEL_H_ 00017 #define _QPANEL_H_ 00018 00028 #include "qce-config.h" 00029 00030 #include <QHash> 00031 #include <QWidget> 00032 #include <QPointer> 00033 00034 class QPainter; 00035 class QPaintEvent; 00036 00037 class QEditor; 00038 class QPanelCreator; 00039 00040 class QCE_EXPORT QPanel : public QWidget 00041 { 00042 Q_OBJECT 00043 00044 public: 00045 QPanel(QWidget *p = 0); 00046 virtual ~QPanel(); 00047 00048 virtual QString id() const = 0; 00049 virtual QString type() const = 0; 00050 00051 QEditor* editor(); 00052 void attach(QEditor *e); 00053 00054 virtual bool shallShow() const; 00055 00056 bool defaultVisibility() const; 00057 void setDefaultVisibility(bool on); 00058 00059 static QPanel* panel(const QString& id, QWidget *p = 0); 00060 static void registerCreator(QPanelCreator *c); 00061 00062 protected: 00063 virtual bool forward(QMouseEvent *e); 00064 00065 virtual void editorChange(QEditor *e); 00066 00067 virtual void mouseMoveEvent(QMouseEvent *e); 00068 virtual void mousePressEvent(QMouseEvent *e); 00069 virtual void mouseReleaseEvent(QMouseEvent *e); 00070 00071 virtual void showEvent(QShowEvent *e); 00072 virtual void hideEvent(QHideEvent *e); 00073 virtual void paintEvent(QPaintEvent *e); 00074 virtual bool paint(QPainter *p, QEditor *e); 00075 00076 private: 00077 QPointer<QEditor> m_editor; 00078 bool m_defaultVisibility, m_shownOnce; 00079 static QHash<QString, QPanelCreator*>& creators(); 00080 }; 00081 00082 class QPanelCreator 00083 { 00084 public: 00085 virtual ~QPanelCreator() {} 00086 virtual QString id() const = 0; 00087 virtual QPanel* panel(QWidget *p) = 0; 00088 }; 00089 00090 #define Q_PANEL(T, SID) \ 00091 public: \ 00092 class Creator : public QPanelCreator \ 00093 { \ 00094 public: \ 00095 virtual QString id() const \ 00096 { \ 00097 return SID; \ 00098 } \ 00099 \ 00100 virtual QPanel* panel(QWidget *p) \ 00101 { \ 00102 return new T(p); \ 00103 } \ 00104 \ 00105 static QPanelCreator* instance() \ 00106 { \ 00107 static Creator global; \ 00108 return &global; \ 00109 } \ 00110 \ 00111 Creator() {} \ 00112 virtual ~Creator() {} \ 00113 }; \ 00114 \ 00115 QString id() const { return SID; } \ 00116 \ 00117 static void _register() \ 00118 { \ 00119 QPanel::registerCreator(Creator::instance()); \ 00120 } \ 00121 00122 00123 #define Q_PANEL_ID(T) \ 00124 T::Creator::instance()->id() \ 00125 00126 00127 #define Q_CREATE_PANEL(T) \ 00128 QPanel::panel(Q_PANEL_ID(T)) \ 00129 00130 00131 #endif // _QPANEL_H_