#ifndef ROOT_TQtWidget
#define ROOT_TQtWidget
#include <assert.h>
#include "Rtypes.h"
#include "TCanvas.h"
#ifndef __CINT__
# include <QtGui/QWidget>
# include <QtGui/QMouseEvent>
# include <QtGui/QShowEvent>
# include <QtGui/QFocusEvent>
# include <QtGui/QKeyEvent>
# include <QtGui/QResizeEvent>
# include <QtCore/QEvent>
# include <QtGui/QPaintEvent>
# include <QtGui/QPaintDevice>
# include <QtCore/QSize>
# include <QtCore/QPoint>
# include <QtCore/QPointer>
# include <QtGui/QPixmap>
# include "TQtCanvasPainter.h"
#else
class QWidget;
class QPixmap;
class QMouseEvent;
class QFocusEvent;
class QCustomEvent;
class QKeyEvent;
class QShowEvent;
class QPaintEvent;
class QPaintDevice;
class QResizeEvent;
class QSize;
class QString;
class QEvent;
class QSizePolicy;
class QContextMenuEvent;
class QSize;
class QPoint;
class TQtCanvasPainter;
#endif
class QTimer;
class TApplication;
enum EEventTrackingBits {
kMousePressEvent = BIT(0),
kMouseMoveEvent = BIT(1),
kMouseReleaseEvent = BIT(2),
kMouseDoubleClickEvent = BIT(3),
kKeyPressEvent = BIT(4),
kEnterEvent = BIT(5),
kLeaveEvent = BIT(6)
};
class TQtWidgetBuffer
{
private:
const QWidget *fWidget;
QPaintDevice *fBuffer;
bool fIsImage;
public:
TQtWidgetBuffer(const QWidget *w, bool clear=false);
TQtWidgetBuffer(const TQtWidgetBuffer &b);
const QPaintDevice *Buffer() const { return fBuffer; }
QPaintDevice *Buffer() { return fBuffer; }
~TQtWidgetBuffer();
void Clear();
bool PaintingActive(){ return fBuffer ? fBuffer->paintingActive() : false; }
QRect Rect () const { return fWidget->rect(); }
int Height () const { return fBuffer ? fBuffer->height() : 0;}
int Width () const { return fBuffer ? fBuffer->width() : 0; }
};
class TQtWidget : public QWidget {
#ifndef __CINT__
Q_OBJECT
friend class TQtSynchPainting;
#endif
private:
TQtWidget(const TQtWidget&);
void operator=(const TQtWidget&);
UInt_t fBits;
enum {
kBitMask = 0x00ffffff
};
bool fNeedStretch;
#ifndef __CINT__
QPointer<TQtCanvasPainter> fCanvasDecorator;
#endif
protected:
void Init();
void ResetCanvas() { fCanvas = 0;}
public:
enum {
kEXITSIZEMOVE,
kENTERSIZEMOVE,
kFORCESIZE
};
#ifndef __CINT__
TQtWidget( QWidget* parent, const char* name, Qt::WFlags f=0, bool embedded=TRUE);
TQtWidget( QWidget* parent=0, Qt::WFlags f=0, bool embedded=TRUE);
#else
TQtWidget( QWidget* parent=0);
#endif
virtual ~TQtWidget();
void SetCanvas(TCanvas *c);
TCanvas *GetCanvas() const;
TQtWidgetBuffer &SetBuffer();
const TQtWidgetBuffer *GetBuffer() const;
QPixmap *GetOffScreenBuffer() const;
virtual void Erase ();
bool IsDoubleBuffered() const { return fDoubleBufferOn; }
void SetDoubleBuffer(bool on=TRUE);
virtual void SetSaveFormat(const char *format);
protected:
friend class TGQt;
friend class TQtFeedBackWidget;
TCanvas *fCanvas;
TQtWidgetBuffer *fPixmapID;
TQtWidgetBuffer *fPixmapScreen;
bool fPaint;
bool fSizeChanged;
bool fDoubleBufferOn;
bool fEmbedded;
QSize fSizeHint;
QWidget *fWrapper;
QString fSaveFormat;
bool fInsidePaintEvent;
QPoint fOldMousePos;
int fIgnoreLeaveEnter;
QTimer *fRefreshTimer;
void SetRootID(QWidget *wrapper);
QWidget *GetRootID() const;
virtual void EmitCanvasPainted() { emit CanvasPainted(); }
TCanvas *Canvas();
bool paintFlag(bool mode=TRUE);
void AdjustBufferSize();
bool PaintingActive () const;
void SetIgnoreLeaveEnter(int ignore=1);
virtual void enterEvent ( QEvent * );
virtual void customEvent ( QEvent * );
virtual void contextMenuEvent ( QContextMenuEvent *);
virtual void focusInEvent ( QFocusEvent * );
virtual void focusOutEvent ( QFocusEvent * );
virtual void leaveEvent ( QEvent * );
virtual void mouseDoubleClickEvent(QMouseEvent* );
virtual void mouseMoveEvent ( QMouseEvent * );
virtual void mousePressEvent ( QMouseEvent * );
virtual void mouseReleaseEvent( QMouseEvent * );
virtual void keyPressEvent ( QKeyEvent * );
virtual void keyReleaseEvent ( QKeyEvent * );
virtual void showEvent ( QShowEvent * );
virtual void paintEvent ( QPaintEvent * );
virtual void resizeEvent ( QResizeEvent *);
virtual void SetSizeHint (const QSize &size);
public:
virtual QSize sizeHint () const;
virtual QSize minimumSizeHint () const;
virtual QSizePolicy sizePolicy () const;
protected:
virtual void exitSizeEvent ();
virtual void stretchWidget(QResizeEvent *e);
TQtCanvasPainter *CanvasDecorator();
public:
void SetBit (UInt_t f, Bool_t set);
void SetBit (UInt_t f);
void ResetBit (UInt_t f);
Bool_t TestBit (UInt_t f) const;
Int_t TestBits (UInt_t f) const;
void InvertBit (UInt_t f);
void EmitSignal (UInt_t f);
void EmitTestedSignal();
UInt_t GetAllBits() const;
void SetAllBits(UInt_t f);
void SetCanvasDecorator( TQtCanvasPainter *decorator);
public:
static TApplication *InitRint(Bool_t prompt=kFALSE, const char *appClassName="QtRint", int *argc=0, char **argv=0,
void *options = 0, int numOptions = 0, Bool_t noLogo = kTRUE);
Int_t GetEvent() const;
Int_t GetEventX() const;
Int_t GetEventY() const;
TObject *GetSelected() const;
Int_t GetSelectedX() const;
Int_t GetSelectedY() const;
TVirtualPad *GetSelectedPad() const;
void EnableSignalEvents (UInt_t f);
void DisableSignalEvents (UInt_t f);
Bool_t IsSignalEventEnabled(UInt_t f) const;
static TCanvas *Canvas(TQtWidget *widget);
static TQtWidget *Canvas(const TCanvas *canvas);
static TQtWidget *Canvas(Int_t id);
public slots:
virtual void cd();
virtual void cd(int subpadnumber);
void Disconnect();
void Refresh();
virtual bool Save(const QString &fileName) const;
virtual bool Save(const char *fileName) const;
virtual bool Save(const QString &fileName,const char *format,int quality=60) const;
virtual bool Save(const char *fileName,const char *format,int quality=60) const;
#ifndef __CINT__
protected slots:
void RefreshCB();
signals:
void CanvasPainted();
void Saved(bool ok);
void RootEventProcessed(TObject *selected, unsigned int event, TCanvas *c);
#endif
#ifndef Q_MOC_RUN
ClassDef(TQtWidget,0)
#endif
};
inline TCanvas *TQtWidget::GetCanvas() const { return fCanvas; }
inline const TQtWidgetBuffer *TQtWidget::GetBuffer() const {
return IsDoubleBuffered() ? fPixmapScreen : fPixmapID;
}
inline bool TQtWidget::PaintingActive () const {
return QWidget::paintingActive() || (fPixmapID && fPixmapID->PaintingActive())
|| (fPixmapScreen && fPixmapScreen->PaintingActive());
}
inline void TQtWidget::SetRootID(QWidget *wrapper) { fWrapper = wrapper;}
inline QWidget *TQtWidget::GetRootID() const { return fWrapper;}
inline Int_t TQtWidget::GetEvent() const { return GetCanvas()->GetEvent(); }
inline Int_t TQtWidget::GetEventX() const { return GetCanvas()->GetEventX(); }
inline Int_t TQtWidget::GetEventY() const { return GetCanvas()->GetEventY(); }
inline TObject *TQtWidget::GetSelected() const { return GetCanvas()->GetSelected(); }
inline Int_t TQtWidget::GetSelectedX() const { return GetCanvas()->GetSelectedX(); }
inline Int_t TQtWidget::GetSelectedY() const { return GetCanvas()->GetSelectedY(); }
inline TVirtualPad *TQtWidget::GetSelectedPad() const { return GetCanvas()->GetSelectedPad(); }
inline UInt_t TQtWidget::GetAllBits() const { return fBits; }
inline void TQtWidget::SetAllBits(UInt_t f) { fBits = f; }
inline void TQtWidget::SetBit(UInt_t f) { fBits |= f & kBitMask; }
inline void TQtWidget::ResetBit(UInt_t f) { fBits &= ~(f & kBitMask); }
inline Bool_t TQtWidget::TestBit(UInt_t f) const { return (Bool_t) ((fBits & f) != 0); }
inline Int_t TQtWidget::TestBits(UInt_t f) const { return (Int_t) (fBits & f); }
inline void TQtWidget::InvertBit(UInt_t f) { fBits ^= f & kBitMask; }
inline TQtCanvasPainter *TQtWidget::CanvasDecorator() { return fCanvasDecorator; }
inline void TQtWidget::SetCanvasDecorator( TQtCanvasPainter *decorator) { fCanvasDecorator = decorator;}
inline void TQtWidget::EnableSignalEvents (UInt_t f){ SetBit (f); }
inline void TQtWidget::DisableSignalEvents (UInt_t f){ ResetBit(f); }
inline Bool_t TQtWidget::IsSignalEventEnabled(UInt_t f) const { return TestBit (f); }
inline void TQtWidget::EmitSignal(UInt_t f) {if (IsSignalEventEnabled(f)) EmitTestedSignal();}
inline void TQtWidget::SetIgnoreLeaveEnter(int ignore) { fIgnoreLeaveEnter = ignore; }
#endif