forked from root-project/root
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TQtWidget.h
320 lines (290 loc) · 12.9 KB
/
TQtWidget.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
// @(#)root/qt:$Id$
// Author: Valeri Fine 21/01/2002
/*************************************************************************
* Copyright (C) 1995-2004, Rene Brun and Fons Rademakers. *
* Copyright (C) 2003 by Valeri Fine. *
* All rights reserved. *
* *
* For the licensing terms see $ROOTSYS/LICENSE. *
* For the list of contributors see $ROOTSYS/README/CREDITS. *
*************************************************************************/
#ifndef ROOT_TQtWidget
#define ROOT_TQtWidget
// Definition of TQtWidget class
// "double-buffered" widget
#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
// List of the fake classes to make RootCint happy.
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;
//
// TQtWidget is a custom QWidget to back ROOT TCanvas.
//
// It can be used within Qt-based program and with Qt Designer as a "regular"
// Qt QWidget to create the Qt widget wihe builtin TCanvas'
//
enum EEventTrackingBits {
kMousePressEvent = BIT(0), // emit signal as soon as TCanvas processed mousePressEvent QMouseEvent
kMouseMoveEvent = BIT(1), // emit signal as soon as TCanvas processed mouseMoveEvent QMouseEvent
kMouseReleaseEvent = BIT(2), // emit signal as soon as TCanvas processed mouseReleaseEvent QMouseEvent
kMouseDoubleClickEvent = BIT(3), // emit signal as soon as TCanvas processed mouseDoubleClickEvent QMouseEvent
kKeyPressEvent = BIT(4), // emit signal as soon as TCanvas processed keyPressEvent QKeyEvent
kEnterEvent = BIT(5), // emit signal as soon as TCanvas processed enterEvent QEvent
kLeaveEvent = BIT(6) // emit signal as soon as TCanvas processed leaveEvent QEvent
};
//___________________________________________________________________
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&);
//----- Private bits, clients can only test but not change them
UInt_t fBits; //bit field status word
enum {
kBitMask = 0x00ffffff
};
bool fNeedStretch;
#ifndef __CINT__
QPointer<TQtCanvasPainter> fCanvasDecorator; //< The object to paint onto the TQtWidget on the top of TCanvas image
#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);
// inline TCanvas *GetCanvas() const { return fCanvas;}
TCanvas *GetCanvas() const;
TQtWidgetBuffer &SetBuffer();
const TQtWidgetBuffer *GetBuffer() const;
QPixmap *GetOffScreenBuffer() const;
// overloaded methods
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; // Double buffer of this widget
TQtWidgetBuffer *fPixmapScreen; // Double buffer for no-double buffer operation
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 ignoreLE = 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 *);
// Layout methods:
virtual void SetSizeHint (const QSize &size);
public:
virtual QSize sizeHint () const; // returns the preferred size of the widget.
virtual QSize minimumSizeHint () const; // returns the smallest size the widget can have.
virtual QSizePolicy sizePolicy () const; // returns a QSizePolicy; a value describing the space requirements of the
protected:
// -- A special event handler
virtual void exitSizeEvent ();
virtual void stretchWidget(QResizeEvent *e);
TQtCanvasPainter *CanvasDecorator();
public:
//----- bit manipulation (a'la TObject )
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 method to immitate ROOT as needed
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);
// Proxy methods to access the TCanvas selected TObject
// and last processed ROOT TCanvas event
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;
//----- bit Qt signal emitting the Qt signal to track mouse movement
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:
// emit the Qt signal when the double buffer of the TCamvas has been filled up
void CanvasPainted(); // Signal the TCanvas has been painted onto the screen
void Saved(bool ok); // Signal the TCanvas has been saved into the file
void RootEventProcessed(TObject *selected, unsigned int event, TCanvas *c);
#endif
#ifndef Q_MOC_RUN
ClassDef(TQtWidget,0) // QWidget to back ROOT TCanvas (Can be used with Qt designer)
#endif
};
//______________________________________________________________________________
inline TCanvas *TQtWidget::GetCanvas() const { return fCanvas; }
//______________________________________________________________________________
inline const TQtWidgetBuffer *TQtWidget::GetBuffer() const {
// return the current widget buffer;
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;}
//______________________________________________________________________________
//
// Proxy methods to access the TCanvas selected TObject
// and last processed event
//______________________________________________________________________________
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(); }
//----- bit manipulation
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 ignoreLE) { fIgnoreLeaveEnter = ignoreLE; }
#endif