00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef ROOT_TQtWidget
00014 #define ROOT_TQtWidget
00015
00016
00017
00018
00019 #include <assert.h>
00020 #include "Rtypes.h"
00021 #include "TCanvas.h"
00022
00023 #ifndef __CINT__
00024 # include <QtGui/QWidget>
00025 # include <QtGui/QMouseEvent>
00026 # include <QtGui/QShowEvent>
00027 # include <QtGui/QFocusEvent>
00028 # include <QtGui/QKeyEvent>
00029 # include <QtGui/QResizeEvent>
00030 # include <QtCore/QEvent>
00031 # include <QtGui/QPaintEvent>
00032 # include <QtGui/QPaintDevice>
00033 # include <QtCore/QSize>
00034 # include <QtCore/QPoint>
00035 # include <QtCore/QPointer>
00036 # include <QtGui/QPixmap>
00037 # include "TQtCanvasPainter.h"
00038 #else
00039
00040 class QWidget;
00041 class QPixmap;
00042 class QMouseEvent;
00043 class QFocusEvent;
00044 class QCustomEvent;
00045 class QKeyEvent;
00046 class QShowEvent;
00047 class QPaintEvent;
00048 class QPaintDevice;
00049 class QResizeEvent;
00050 class QSize;
00051 class QString;
00052 class QEvent;
00053 class QSizePolicy;
00054 class QContextMenuEvent;
00055 class QSize;
00056 class QPoint;
00057 class TQtCanvasPainter;
00058 #endif
00059 class QTimer;
00060 class TApplication;
00061
00062
00063
00064
00065
00066
00067 enum EEventTrackingBits {
00068 kMousePressEvent = BIT(0),
00069 kMouseMoveEvent = BIT(1),
00070 kMouseReleaseEvent = BIT(2),
00071 kMouseDoubleClickEvent = BIT(3),
00072 kKeyPressEvent = BIT(4),
00073 kEnterEvent = BIT(5),
00074 kLeaveEvent = BIT(6)
00075 };
00076
00077
00078 class TQtWidgetBuffer
00079 {
00080 private:
00081 const QWidget *fWidget;
00082 QPaintDevice *fBuffer;
00083 bool fIsImage;
00084 public:
00085 TQtWidgetBuffer(const QWidget *w, bool clear=false);
00086 TQtWidgetBuffer(const TQtWidgetBuffer &b);
00087 const QPaintDevice *Buffer() const { return fBuffer; }
00088 QPaintDevice *Buffer() { return fBuffer; }
00089 ~TQtWidgetBuffer();
00090 void Clear();
00091 bool PaintingActive(){ return fBuffer ? fBuffer->paintingActive() : false; }
00092 QRect Rect () const { return fWidget->rect(); }
00093 int Height () const { return fBuffer ? fBuffer->height() : 0;}
00094 int Width () const { return fBuffer ? fBuffer->width() : 0; }
00095 };
00096
00097
00098 class TQtWidget : public QWidget {
00099 #ifndef __CINT__
00100 Q_OBJECT
00101 friend class TQtSynchPainting;
00102 #endif
00103 private:
00104
00105 TQtWidget(const TQtWidget&);
00106 void operator=(const TQtWidget&);
00107
00108 UInt_t fBits;
00109 enum {
00110 kBitMask = 0x00ffffff
00111 };
00112 bool fNeedStretch;
00113 #ifndef __CINT__
00114 QPointer<TQtCanvasPainter> fCanvasDecorator;
00115 #endif
00116 protected:
00117 void Init();
00118 void ResetCanvas() { fCanvas = 0;}
00119
00120 public:
00121 enum {
00122 kEXITSIZEMOVE,
00123 kENTERSIZEMOVE,
00124 kFORCESIZE
00125 };
00126 #ifndef __CINT__
00127 TQtWidget( QWidget* parent, const char* name, Qt::WFlags f=0, bool embedded=TRUE);
00128 TQtWidget( QWidget* parent=0, Qt::WFlags f=0, bool embedded=TRUE);
00129 #else
00130 TQtWidget( QWidget* parent=0);
00131 #endif
00132 virtual ~TQtWidget();
00133 void SetCanvas(TCanvas *c);
00134
00135 TCanvas *GetCanvas() const;
00136 TQtWidgetBuffer &SetBuffer();
00137 const TQtWidgetBuffer *GetBuffer() const;
00138 QPixmap *GetOffScreenBuffer() const;
00139
00140
00141 virtual void Erase ();
00142 bool IsDoubleBuffered() const { return fDoubleBufferOn; }
00143 void SetDoubleBuffer(bool on=TRUE);
00144 virtual void SetSaveFormat(const char *format);
00145
00146 protected:
00147 friend class TGQt;
00148 friend class TQtFeedBackWidget;
00149 TCanvas *fCanvas;
00150 TQtWidgetBuffer *fPixmapID;
00151 TQtWidgetBuffer *fPixmapScreen;
00152 bool fPaint;
00153 bool fSizeChanged;
00154 bool fDoubleBufferOn;
00155 bool fEmbedded;
00156 QSize fSizeHint;
00157 QWidget *fWrapper;
00158 QString fSaveFormat;
00159 bool fInsidePaintEvent;
00160 QPoint fOldMousePos;
00161 int fIgnoreLeaveEnter;
00162 QTimer *fRefreshTimer;
00163
00164
00165 void SetRootID(QWidget *wrapper);
00166 QWidget *GetRootID() const;
00167 virtual void EmitCanvasPainted() { emit CanvasPainted(); }
00168 TCanvas *Canvas();
00169 bool paintFlag(bool mode=TRUE);
00170 void AdjustBufferSize();
00171
00172 bool PaintingActive () const;
00173 void SetIgnoreLeaveEnter(int ignore=1);
00174
00175
00176 virtual void enterEvent ( QEvent * );
00177 virtual void customEvent ( QEvent * );
00178 virtual void contextMenuEvent ( QContextMenuEvent *);
00179 virtual void focusInEvent ( QFocusEvent * );
00180 virtual void focusOutEvent ( QFocusEvent * );
00181 virtual void leaveEvent ( QEvent * );
00182 virtual void mouseDoubleClickEvent(QMouseEvent* );
00183 virtual void mouseMoveEvent ( QMouseEvent * );
00184 virtual void mousePressEvent ( QMouseEvent * );
00185 virtual void mouseReleaseEvent( QMouseEvent * );
00186 virtual void keyPressEvent ( QKeyEvent * );
00187 virtual void keyReleaseEvent ( QKeyEvent * );
00188 virtual void showEvent ( QShowEvent * );
00189 virtual void paintEvent ( QPaintEvent * );
00190 virtual void resizeEvent ( QResizeEvent *);
00191
00192 virtual void SetSizeHint (const QSize &size);
00193 public:
00194 virtual QSize sizeHint () const;
00195 virtual QSize minimumSizeHint () const;
00196 virtual QSizePolicy sizePolicy () const;
00197 protected:
00198
00199 virtual void exitSizeEvent ();
00200 virtual void stretchWidget(QResizeEvent *e);
00201 TQtCanvasPainter *CanvasDecorator();
00202 public:
00203
00204 void SetBit (UInt_t f, Bool_t set);
00205 void SetBit (UInt_t f);
00206 void ResetBit (UInt_t f);
00207 Bool_t TestBit (UInt_t f) const;
00208 Int_t TestBits (UInt_t f) const;
00209 void InvertBit (UInt_t f);
00210 void EmitSignal (UInt_t f);
00211 void EmitTestedSignal();
00212 UInt_t GetAllBits() const;
00213 void SetAllBits(UInt_t f);
00214 void SetCanvasDecorator( TQtCanvasPainter *decorator);
00215
00216 public:
00217
00218 static TApplication *InitRint(Bool_t prompt=kFALSE, const char *appClassName="QtRint", int *argc=0, char **argv=0,
00219 void *options = 0, int numOptions = 0, Bool_t noLogo = kTRUE);
00220
00221
00222 Int_t GetEvent() const;
00223 Int_t GetEventX() const;
00224 Int_t GetEventY() const;
00225 TObject *GetSelected() const;
00226 Int_t GetSelectedX() const;
00227 Int_t GetSelectedY() const;
00228 TVirtualPad *GetSelectedPad() const;
00229
00230
00231 void EnableSignalEvents (UInt_t f);
00232 void DisableSignalEvents (UInt_t f);
00233 Bool_t IsSignalEventEnabled(UInt_t f) const;
00234
00235 static TCanvas *Canvas(TQtWidget *widget);
00236 static TQtWidget *Canvas(const TCanvas *canvas);
00237 static TQtWidget *Canvas(Int_t id);
00238
00239 public slots:
00240 virtual void cd();
00241 virtual void cd(int subpadnumber);
00242 void Disconnect();
00243 void Refresh();
00244 virtual bool Save(const QString &fileName) const;
00245 virtual bool Save(const char *fileName) const;
00246 virtual bool Save(const QString &fileName,const char *format,int quality=60) const;
00247 virtual bool Save(const char *fileName,const char *format,int quality=60) const;
00248 #ifndef __CINT__
00249 protected slots:
00250 void RefreshCB();
00251
00252 signals:
00253
00254 void CanvasPainted();
00255 void Saved(bool ok);
00256 void RootEventProcessed(TObject *selected, unsigned int event, TCanvas *c);
00257 #endif
00258
00259 #ifndef Q_MOC_RUN
00260 ClassDef(TQtWidget,0)
00261 #endif
00262 };
00263
00264
00265 inline TCanvas *TQtWidget::GetCanvas() const { return fCanvas; }
00266
00267
00268 inline const TQtWidgetBuffer *TQtWidget::GetBuffer() const {
00269
00270 return IsDoubleBuffered() ? fPixmapScreen : fPixmapID;
00271 }
00272
00273
00274 inline bool TQtWidget::PaintingActive () const {
00275 return QWidget::paintingActive() || (fPixmapID && fPixmapID->PaintingActive())
00276 || (fPixmapScreen && fPixmapScreen->PaintingActive());
00277 }
00278
00279 inline void TQtWidget::SetRootID(QWidget *wrapper) { fWrapper = wrapper;}
00280
00281 inline QWidget *TQtWidget::GetRootID() const { return fWrapper;}
00282
00283
00284
00285
00286
00287
00288 inline Int_t TQtWidget::GetEvent() const { return GetCanvas()->GetEvent(); }
00289
00290 inline Int_t TQtWidget::GetEventX() const { return GetCanvas()->GetEventX(); }
00291
00292 inline Int_t TQtWidget::GetEventY() const { return GetCanvas()->GetEventY(); }
00293
00294 inline TObject *TQtWidget::GetSelected() const { return GetCanvas()->GetSelected(); }
00295
00296 inline Int_t TQtWidget::GetSelectedX() const { return GetCanvas()->GetSelectedX(); }
00297
00298 inline Int_t TQtWidget::GetSelectedY() const { return GetCanvas()->GetSelectedY(); }
00299
00300 inline TVirtualPad *TQtWidget::GetSelectedPad() const { return GetCanvas()->GetSelectedPad(); }
00301
00302
00303 inline UInt_t TQtWidget::GetAllBits() const { return fBits; }
00304 inline void TQtWidget::SetAllBits(UInt_t f) { fBits = f; }
00305 inline void TQtWidget::SetBit(UInt_t f) { fBits |= f & kBitMask; }
00306 inline void TQtWidget::ResetBit(UInt_t f) { fBits &= ~(f & kBitMask); }
00307 inline Bool_t TQtWidget::TestBit(UInt_t f) const { return (Bool_t) ((fBits & f) != 0); }
00308 inline Int_t TQtWidget::TestBits(UInt_t f) const { return (Int_t) (fBits & f); }
00309 inline void TQtWidget::InvertBit(UInt_t f) { fBits ^= f & kBitMask; }
00310
00311 inline TQtCanvasPainter *TQtWidget::CanvasDecorator() { return fCanvasDecorator; }
00312 inline void TQtWidget::SetCanvasDecorator( TQtCanvasPainter *decorator) { fCanvasDecorator = decorator;}
00313
00314 inline void TQtWidget::EnableSignalEvents (UInt_t f){ SetBit (f); }
00315 inline void TQtWidget::DisableSignalEvents (UInt_t f){ ResetBit(f); }
00316 inline Bool_t TQtWidget::IsSignalEventEnabled(UInt_t f) const { return TestBit (f); }
00317 inline void TQtWidget::EmitSignal(UInt_t f) {if (IsSignalEventEnabled(f)) EmitTestedSignal();}
00318 inline void TQtWidget::SetIgnoreLeaveEnter(int ignore) { fIgnoreLeaveEnter = ignore; }
00319
00320 #endif