forked from root-project/root
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TGQt.cxx
2947 lines (2642 loc) · 97.4 KB
/
TGQt.cxx
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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// @(#)root/qt:$Id$
// Author: Valeri Fine 21/01/2002
/*************************************************************************
* Copyright (C) 1995-2004, Rene Brun and Fons Rademakers. *
* Copyright (C) 2002 by Valeri Fine. *
* All rights reserved. *
* *
* For the licensing terms see $ROOTSYS/LICENSE. *
* For the list of contributors see $ROOTSYS/README/CREDITS. *
*************************************************************************/
//////////////////////////////////////////////////////////////////////////
// //
// TGQt //
// //
// This class is the basic interface to the Qt graphics system. It is //
// an implementation of the abstract TVirtualX class. //
// //
//////////////////////////////////////////////////////////////////////////
#if defined(HAVE_CONFIG) || defined (R__HAVE_CONFIG)
# include "RConfigure.h"
#endif
#ifdef R__QTWIN32
#include <process.h>
#endif
#include <assert.h>
// Qt include files
#include <QApplication>
#include <QWidget>
#include <QPolygon>
#include <QEvent>
#include <QImageWriter>
#include <QVector>
#include <QStack>
#include <QFrame>
#include <QPicture>
#include <QDebug>
#include <qpixmap.h>
#include <qcursor.h>
#include <qdesktopwidget.h>
#include <qimage.h>
#include <qfontmetrics.h>
#include <qdialog.h>
#include <qlineedit.h>
#include <qfileinfo.h>
#include <qtextcodec.h>
#include <qdir.h>
#include "TROOT.h"
#include "TMath.h"
#include "TColor.h"
#include "TEnv.h"
#include "TQtPen.h"
#include "TQtApplication.h"
#include "TQtWidget.h"
#include "TGQt.h"
#include "TQtBrush.h"
#include "TQtClientFilter.h"
#include "TQtEventQueue.h"
#include "TQtSymbolCodec.h"
#include "TQtLock.h"
#include "TQtPadFont.h"
#include "TStyle.h"
#include "TObjString.h"
#include "TObjArray.h"
#include "TSystem.h"
#ifdef R__QTWIN32
# include "TWinNTSystem.h"
# include "Win32Constants.h"
# include <Winuser.h>
#else
# ifdef R__QTX11
# include <X11/Xlib.h>
# endif
#endif
#include "TSysEvtHandler.h"
#include "TQtMarker.h"
#include "TImage.h"
#include "TError.h"
////////////////////////////////////////////////////////////////////////////////
/// PluginManager creation function
TVirtualX* ROOT_Plugin_TGQt(const char* name, const char* title) {
return new TGQt(name, title);
}
TGQt *gQt=0;
TVirtualX *TGQt::fgTQt = 0; // to remember the pointer foolishing ROOT PluginManager later.
TQtTextProxy *TGQt::fgTextProxy = 0; // The pointer to the custom text proxy;
class TQtTextCloneProxy {
private:
TQtTextProxy *fProxy;
void *operator new(size_t);
TQtTextCloneProxy(const TQtTextCloneProxy&);
void operator=(const TQtTextCloneProxy&);
public:
TQtTextCloneProxy() : fProxy(0)
{
if ( TGQt::TextProxy())
fProxy = TGQt::TextProxy()->Clone();
}
inline ~TQtTextCloneProxy() { delete fProxy; }
inline TQtTextProxy *operator->() { return fProxy;}
};
#define NoOperation (QPaintDevice *)(-1)
// static const int kDefault=2;
////////////////////////////////////////////////////////////////////////////////
static QWidget *IsWidget(QPaintDevice *d)
{ return dynamic_cast<QWidget *>(d); }
////////////////////////////////////////////////////////////////////////////////
static QPixmap *IsPixmap(QPaintDevice *d)
{ return dynamic_cast<QPixmap *>(d); }
////////////////////////////////////////////////////////////////////////////////
/// Set the file pattern
QString TGQt::SetFileName(const QString &fileName)
{
QFileInfo fi(fileName);
QString saveFileMoviePattern =
fi.path()+"/" + fi.completeBaseName()+ "_%04d" + "." + fi.suffix();
return saveFileMoviePattern;
}
////////////////////////////////////////////////////////////////////////////////
/// Find the filename for the given "fileNamePrototype"
QString TGQt::GetNewFileName(const QString &fileNamePrototype)
{
TString flN = fileNamePrototype.toStdString().c_str();
gSystem->ExpandPathName(flN);
QString fileName = (const char *)flN;
Int_t counter = 0;
QString formatPattern = SetFileName(fileName);
while (gSystem->AccessPathName(fileName.toStdString().c_str())==0) {
fileName = QString().sprintf(formatPattern.toStdString().c_str(),counter++);
}
return fileName;
}
//______________________________________________________________________________
//
// custom TQtPainter
////////////////////////////////////////////////////////////////////////////////
class TQtPainter : public QPainter {
private:
TGQt *fVirtualX;
protected:
inline void UpdateBrush() { setBrush(*fVirtualX->fQBrush); }
inline void UpdatePen() { setPen(*fVirtualX->fQPen); }
inline void UpdateFont() { setFont(*fVirtualX->fQFont);
fVirtualX->fTextFontModified = 0;
}
public:
enum { kNone = 0,
kUseFeedBack = 1,
kUpdateFont = 2,
kUpdateBrush = 4,
kUpdatePen = 8
};
TQtPainter() : QPainter (), fVirtualX(0) {}
TQtPainter(QPaintDevice * dev) : QPainter ( dev ), fVirtualX(0) {}
TQtPainter( TGQt *dev, unsigned int useFeedBack=kUpdateBrush | kUpdatePen ) : fVirtualX(0)
{ begin(dev,useFeedBack); }
~TQtPainter () { fVirtualX->fQPainter = 0; }
bool begin ( TGQt *dev, unsigned int useFeedBack);
};
//______________________________________________________________________________
//
// class TQtFeedBackWidget to back the TCanvas FeedBack mode
////////////////////////////////////////////////////////////////////////////////
class TQtFeedBackWidget : public QFrame {
QPixmap *fPixBuffer;
QPixmap *fGrabBuffer;
TQtWidget *fParentWidget;
protected:
virtual void hideEvent (QHideEvent *ev) {
// hide the feedback widget and remove the buffer
delete fPixBuffer; fPixBuffer = 0;
delete fGrabBuffer; fGrabBuffer = 0;
QFrame::hideEvent(ev);
if (fParentWidget) {
fParentWidget->SetIgnoreLeaveEnter(0);
SetParent(0); // reparent // it is dangerous thing to do inside of the event processing
}
}
virtual void paintEvent(QPaintEvent *ev) {
if (fPixBuffer) {
QRect rc = ev->rect();
{
QPainter p(this);
p.setClipRect(rc);
p.drawPixmap(0,0,*fPixBuffer);
}
ClearBuffer();
} else if (fGrabBuffer) {
QRect rc = ev->rect();
QPainter p(this);
p.setClipRect(rc);
p.drawPixmap(rc,*fGrabBuffer);
}
QFrame::paintEvent(ev);
}
public:
TQtFeedBackWidget(QWidget *mother=0, Qt::WindowFlags f=0) : QFrame(mother,f)
,fPixBuffer(0),fGrabBuffer(0),fParentWidget(0)
{
// Create the feedback widget
setAttribute(Qt::WA_NoSystemBackground);
setEnabled(false);
setBackgroundRole(QPalette::Window);
setAutoFillBackground(false);
QPalette p = palette();
p.setBrush(QPalette::Window, Qt::transparent);
setPalette(p);
setMouseTracking(true);
}
virtual ~TQtFeedBackWidget()
{
fParentWidget = 0;
delete fPixBuffer; fPixBuffer = 0;
delete fGrabBuffer; fGrabBuffer = 0;
}
void SetParent(TQtWidget *w) {
setParent(fParentWidget = w);
}
void Hide() {
if (fParentWidget) {
fParentWidget->SetIgnoreLeaveEnter(0);
SetParent(0); // reparent
}
}
void Show() {
// Protect (Qt >= 4.5.x) TCanvas against of
// the confusing mouseMoveEvent
if (fParentWidget) fParentWidget->SetIgnoreLeaveEnter(2);
QFrame::show();
if (fParentWidget) fParentWidget->SetIgnoreLeaveEnter();
}
QPaintDevice *PixBuffer() {
// Create the feedback buffer if needed
if (fParentWidget ) {
// resize the feedback
QSize canvasSize = fParentWidget->size();
setGeometry(QRect(QPoint(0,0),canvasSize));
if ( !fPixBuffer || (fPixBuffer->size() != canvasSize) ) {
delete fPixBuffer;
fPixBuffer = new QPixmap(canvasSize);
ClearBuffer();
}
}
return fPixBuffer;
}
QPaintDevice *GrabBuffer(QSize &s) {
// Create the feedback buffer to grab the parent TPad image
if (fParentWidget ) {
// resize the feedback
if ( !fPixBuffer || (fPixBuffer->size() != s) ) {
delete fPixBuffer;
fPixBuffer = new QPixmap(s);
ClearBuffer();
}
}
return fPixBuffer;
}
void ClearBuffer() {
// Fill the feedback buffer with the transparent background
fPixBuffer->fill(Qt::transparent);
}
void SetGeometry(int xp,int yp, int w, int h, TQtWidget *src=0)
{
// Set the feedback widget position and geometry
if (isHidden() && src ) {
// grab the parent window and move the feedback
delete fGrabBuffer; fGrabBuffer = 0;
QPixmap *canvas = src->GetOffScreenBuffer();
if (canvas && w > 4 && h > 4 ) {
fGrabBuffer = new QPixmap(canvas->copy(xp,yp,w,h));
}
}
setGeometry(xp,yp,w,h);
}
};
//______________________________________________________________________________
//
// class TQtFeedBackWidget to back the TCanvas FeedBack mode
//______________________________________________________________________________
class TQtToggleFeedBack {
TGQt *fGQt;
TQtPainter fFeedBackPainter;
public:
TQtToggleFeedBack(TGQt *gqt) : fGQt(gqt)
{
// activate temporary TQtFeedBackWidget widget buffer
if (fGQt->fFeedBackMode && fGQt->fFeedBackWidget->isHidden()) {
fGQt->fFeedBackWidget->Show();
}
}
~TQtToggleFeedBack()
{
// Update the "feedback" widget
if (fFeedBackPainter.isActive() ) fFeedBackPainter.end();
if (fGQt->fFeedBackMode && fGQt->fFeedBackWidget)
{ fGQt->fFeedBackWidget->update(); }
}
TQtPainter &painter() {
// activate return the "feedback" painter
if (!fFeedBackPainter.isActive()) {
fFeedBackPainter.begin(fGQt, TQtPainter::kUseFeedBack
| TQtPainter::kUpdatePen
| TQtPainter::kUpdateBrush);
if (fGQt->fFeedBackMode) {
fFeedBackPainter.setPen(QColor(128,128,128,128));// Qt::white);// darkGray);
}
}
return fFeedBackPainter;
}
};
//______________________________________________________________________________
//
// custom TQtPainter
////////////////////////////////////////////////////////////////////////////////
/// Activate return the "feedback" painter
inline bool TQtPainter::begin ( TGQt *dev, unsigned int useFeedBack)
{
bool res = false;
if (dev && (dev->fSelectedWindow != NoOperation)) {
fVirtualX = dev;
QPaintDevice *src= 0;
if ( (useFeedBack & kUseFeedBack) && dev->fFeedBackMode
&& dev->fFeedBackWidget
&& dev->fFeedBackWidget)
{ src = dev->fFeedBackWidget->PixBuffer(); }
else {
src = dev->fSelectedWindow;
if ( src->devType() == QInternal::Widget)
{
TQtWidget *theWidget = (TQtWidget *)src;
// Substitute the widget with its internal buffer
src = theWidget->SetBuffer().Buffer();
}
}
if (!(res= QPainter::begin(src)) ) {
Error("TGQt::Begin()","Can not create Qt painter for win=0x%lx dev=0x%lx\n",(Long_t)src,(Long_t)dev);
assert(0);
} else {
dev->fQPainter = (TQtPainter*)-1;
UpdatePen();
UpdateBrush();
UpdateFont();
TGQt::TQTCLIPMAP::iterator it= (dev->fClipMap).find(src);
QRect clipRect;
if (it != (dev->fClipMap).end()) {
clipRect = it.value();
setClipRect(clipRect);
setClipping(TRUE);
}
if (src->devType() == QInternal::Image )
setCompositionMode(dev->fDrawMode);
}
}
return res;
}
//----- Terminal Input file handler --------------------------------------------
////////////////////////////////////////////////////////////////////////////////
class TQtEventInputHandler : public TTimer {
protected: // singleton
TQtEventInputHandler() : TTimer(340) { }
static TQtEventInputHandler *gfQtEventInputHandler;
public:
static TQtEventInputHandler *Instance() {
if (!gfQtEventInputHandler)
gfQtEventInputHandler = new TQtEventInputHandler();
gfQtEventInputHandler->Start(240);
return gfQtEventInputHandler;
}
Bool_t Notify() {
Timeout(); // emit Timeout() signal
Bool_t ret = gQt->processQtEvents();
Start(240);
Reset();
return ret;
}
Bool_t ReadNotify() { return Notify(); }
};
TQtEventInputHandler *TQtEventInputHandler::gfQtEventInputHandler = 0;
//______________________________________________________________________________
// static methods:
//______________________________________________________________________________
//______________________________________________________________________________
// static methods:
// kNone = no window
// kDefault = means default desktopwindow
// else the pointer to the QPaintDevice
class TQWidgetCollection {
private:
QStack<int> fFreeWindowsIdStack;
QVector<QPaintDevice *> fWidgetCollection;
Int_t fIDMax; // current max id
Int_t fIDTotalMax; // life-time max id
protected:
/////////////////////////////////////////////////////////////////////////////
inline Int_t SetMaxId(Int_t newId)
{
fIDMax = newId;
if (newId>fIDTotalMax) {
fIDTotalMax = newId;
fWidgetCollection.resize(fIDTotalMax+1);
}
return fIDMax;
}
public:
/////////////////////////////////////////////////////////////////////////////
/// mark the position before kNone and between kNone and kDefault
/// as "free position" if any
TQWidgetCollection () : fIDMax(-1), fIDTotalMax(-1)
{
int kDefault = 1;
assert(!kNone);
SetMaxId (kDefault);
fWidgetCollection[kNone] = (QPaintDevice*)0;
fWidgetCollection[kDefault] = (QPaintDevice *)QApplication::desktop();
}
/////////////////////////////////////////////////////////////////////////////
inline Int_t GetFreeId(QPaintDevice *device) {
Int_t Id = 0;
if (!fFreeWindowsIdStack.isEmpty() ) {
Id = fFreeWindowsIdStack.pop();
if (Id > fIDMax ) SetMaxId ( Id );
} else {
Id = fWidgetCollection.count();
assert(fIDMax <= Id );
SetMaxId ( Id );
}
fWidgetCollection[Id] = device;
// fprintf(stderr," add %p as %d max Id = %d \n", device, Id,fIDMax);
return Id;
}
/////////////////////////////////////////////////////////////////////////////
/// method to provide the ROOT "cast" from (QPaintDevice*) to ROOT windows "id"
inline Int_t RemoveByPointer(QPaintDevice *device)
{
Int_t intWid = kNone; // TGQt::iwid(device);
if ((ULong_t) device != (ULong_t) -1) {
intWid = find( device);
if ( intWid != -1 &&
fWidgetCollection[intWid]) {
fWidgetCollection[intWid] = (QPaintDevice *)(-1);
fFreeWindowsIdStack.push(intWid);
if (fIDMax == intWid) SetMaxId(--fIDMax);
} else {
intWid = kNone;
}
}
return intWid;
}
/////////////////////////////////////////////////////////////////////////////
inline const QPaintDevice *DeleteById(Int_t Id)
{
QPaintDevice *device = fWidgetCollection[Id];
if (device) {
delete device;
fWidgetCollection[Id] = (QPaintDevice *)(-1);
fFreeWindowsIdStack.push(Id);
if (fIDMax == Id) SetMaxId(--fIDMax);
}
//return device; this was a huge bug
return 0;
}
/////////////////////////////////////////////////////////////////////////////
inline const QPaintDevice *ReplaceById(Int_t Id, QPaintDevice *newDev)
{
if (newDev) {
// delete the old definition
delete fWidgetCollection[Id];
// add the new one instead
fWidgetCollection[Id] = newDev;
} else {
DeleteById(Id);
}
return newDev;
}
//______________________________________________________________________________
inline uint count() const { return fWidgetCollection.count();}
//______________________________________________________________________________
inline uint MaxId() const { return fIDMax;}
//______________________________________________________________________________
inline uint MaxTotalId() const { return fIDTotalMax;}
/////////////////////////////////////////////////////////////////////////////
inline int find(const QPaintDevice *device, uint i=0) const
{
return fWidgetCollection.indexOf((QPaintDevice*)device,i);
}
//______________________________________________________________________________
inline QPaintDevice *operator[](int i) const {return fWidgetCollection[i];}
};
TQWidgetCollection *fWidgetArray = 0;
////////////////////////////////////////////////////////////////////////////////
/// Convert ROOT Widget Id to the Qt QPaintDevice pointer
QPaintDevice *TGQt::iwid(Window_t wd)
{
QPaintDevice *topDevice = 0;
if ( wd != kNone ) {
topDevice = (wd == kDefault) ?
(QPaintDevice *)QApplication::desktop()
:
(QPaintDevice*)wd;
}
return topDevice;
}
////////////////////////////////////////////////////////////////////////////////
/// method to provide the ROOT "cast" from (QPaintDevice*) to ROOT windows "id"
Int_t TGQt::iwid(QPaintDevice *wd)
{
Int_t intWid = kNone;
// look up the widget
if ((ULong_t) wd == (ULong_t) -1) intWid = -1;
else {
intWid = fWidgetArray->find(wd);
assert(intWid != -1);
// if (intWid == -1) intWid = Int_t(wd);
}
return intWid;
}
////////////////////////////////////////////////////////////////////////////////
/// method to restore (cast) the QPaintDevice object pointer from ROOT windows "id"
QPaintDevice *TGQt::iwid(Int_t wd)
{
QPaintDevice *topDevice = 0;
if (0 <= wd && wd <= int(fWidgetArray->MaxId()) )
topDevice = (*fWidgetArray)[wd];
if (topDevice == (QPaintDevice *)(-1) ) topDevice = 0;
else {
assert(wd <= Int_t(fWidgetArray->MaxTotalId()));
// this is allowed from the embedded TCanvas dtor only.
// at this point "wd" may have been destroyed
//-- vf topDevice = (QPaintDevice *)wd;
}
return topDevice;
}
////////////////////////////////////////////////////////////////////////////////
/// returns the top level QWidget for the ROOT widget
QWidget *TGQt::winid(Window_t id)
{
return (id != kNone)? TGQt::wid(id)->topLevelWidget():0;
}
////////////////////////////////////////////////////////////////////////////////
Window_t TGQt::wid(TQtClientWidget *widget)
{
return rootwid(widget);
}
////////////////////////////////////////////////////////////////////////////////
Window_t TGQt::rootwid(QPaintDevice *dev)
{
return Window_t(dev);
}
////////////////////////////////////////////////////////////////////////////////
/// method to restore (dynamic cast) the QWidget object pointer (if any) from ROOT windows "id"
QWidget *TGQt::wid(Window_t id)
{
QPaintDevice *dev = 0;
if (id == (Window_t)kNone || id == (Window_t)(-1) ) return (QWidget *)dev;
if ( id <= fWidgetArray->MaxId() )
dev = (*fWidgetArray)[id];
else
dev = (QPaintDevice *)id;
#if 0
if ( dev->devType() != QInternal::Widget) {
fprintf(stderr," %s %i type=%d QInternal::Widget = %d id =%x id = %d\n", "TGQt::wid", __LINE__
, dev->devType()
, QInternal::Widget, id, id );
// , (const char *)dev->name(), (const char *)dev->className(), QInternal::Widget);
}
#endif
assert(dev->devType() == QInternal::Widget);
return (QWidget *)dev;
}
////////////////////////////////////////////////////////////////////////////////
/// Dump trhe ROOT Event_t structure to debug the code
void TGQt::PrintEvent(Event_t &ev)
{
//EGEventType fType; // of event (see EGEventTypes)
//Window_t fWindow; // window reported event is relative to
//Time_t fTime; // time event event occured in ms
//Int_t fX, fY; // pointer x, y coordinates in event window
//Int_t fXRoot, fYRoot; // coordinates relative to root
//UInt_t fCode; // key or button code
//UInt_t fState; // key or button mask
//UInt_t fWidth, fHeight; // width and height of exposed area
//Int_t fCount; // if non-zero, at least this many more exposes
//Bool_t fSendEvent; // true if event came from SendEvent
//Handle_t fHandle; // general resource handle (used for atoms or windows)
//Int_t fFormat; // Next fields only used by kClientMessageEvent
//Long_t fUser[5]; // 5 longs can be used by client message events
// // NOTE: only [0], [1] and [2] may be used.
// // [1] and [2] may contain >32 bit quantities
// // (i.e. pointers on 64 bit machines)
qDebug() << "----- Window "<< TGQt::wid(ev.fWindow) << TGQt::wid(ev.fWindow) << " " << TGQt::wid(ev.fWindow)-> objectName();
fprintf(stderr,"event type = %x, key or button code %d \n", ev.fType, ev.fCode);
fprintf(stderr,"fX, fY, fXRoot, fYRoot = %d %d :: %d %d\n", ev.fX, ev.fY,ev.fXRoot, ev.fYRoot);
}
int TGQt::fgCoinFlag = 0; // no current coin viewer;
int TGQt::fgCoinLoaded = 0; // coint viewer DLL has not been loaded
////////////////////////////////////////////////////////////////////////////////
/// return the Coin/QGL viewer flag safely
int TGQt::CoinFlag()
{
TQtLock lock;
int ret = fgCoinFlag;
return ret;
}
////////////////////////////////////////////////////////////////////////////////
/// Set the Coin/QGL viewer flag safely
void TGQt::SetCoinFlag(int flag)
{
TQtLock lock;
fgCoinFlag=flag;
}
//______________________________________________________________________________
void TGQt::SetCoinLoaded() { fgCoinLoaded = 1; }
//______________________________________________________________________________
Int_t TGQt::IsCoinLoaded(){ return fgCoinLoaded;}
#if ROOT_VERSION_CODE < ROOT_VERSION(5,13,0)
////////////////////////////////////////////////////////////////////////////////
/// Create the Qt QPixamp from the WIN32 system icon (for WIN32 only)
QPixmap *TGQt::MakeIcon(Int_t i)
{
QPixmap *tempIcon = NULL;
if (i) { /* just to suspend the warning under UNIX */ }
#ifdef R__QTWIN32
HICON largeIcon[1];
HICON smallIcon[1];
HICON icon = ((TWinNTSystem *)gSystem)->GetNormalIcon(i);
#if 0
int numIcons = ::ExtractIconEx(
"c:\winnt\explorer.exe",
0,
largeIcon,
smallIcon,
1);
if (numIcons > 0)
{
#endif
tempIcon =new QPixmap (GetSystemMetrics(SM_CXSMICON),
GetSystemMetrics(SM_CYSMICON));
HDC dc = tempIcon->handle();
DrawIcon (dc, 0, 0, icon);
#else
# ifdef ROOTICONPATH
gSystem->ExpandPathName(ROOTICONPATH);
# else
gSystem->ExpandPathName("$ROOTSYS/icons/");
// tempIcon =new QPixmap (16,16),
# endif
#endif
return tempIcon;
}
#endif
ClassImp(TGQt)
//____________________________________________________
//
// Some static methods
////////////////////////////////////////////////////////////////////////////////
QString TGQt::RootFileFormat(const char *selector)
{ return RootFileFormat(QString(selector)); }
////////////////////////////////////////////////////////////////////////////////
/// Define whether the input string contains any pattern
/// that matches the ROOT image formats
/// those Qt library can not provide
QString TGQt::RootFileFormat(const QString &selector)
{
QString saveType;
QString defExtension[] = {"cpp","cxx","eps","svg","root","pdf","ps","xml"
#if ROOT_VERSION_CODE >= ROOT_VERSION(5,13,0)
,"gif"
#endif
,"C"};
UInt_t nExt = sizeof(defExtension)/sizeof(const char *);
UInt_t i = 0;
for (i=0; i < nExt; i++) {
if (selector.contains(defExtension[i], Qt::CaseSensitive)) {
saveType = defExtension[i];
break;
}
}
if (saveType.contains("C",Qt::CaseInsensitive)) saveType= "cxx";
return saveType;
}
////////////////////////////////////////////////////////////////////////////////
QString TGQt::QtFileFormat(const char *selector)
{ return QtFileFormat(QString(selector)); }
////////////////////////////////////////////////////////////////////////////////
/// returns Qt file format
///
/// if no suitable format found and the selector is empty
/// the default PNG format is returned
///
/// a special treatment of the "gif" format.
/// If "gif" is not provided with the local Qt installation
/// replace "gif" format with "png" one
///
QString TGQt::QtFileFormat(const QString &selector)
{
QString saveType="PNG"; // it is the default format
if (!selector.isEmpty()) {
QList<QByteArray> formats = QImageWriter::supportedImageFormats();
QList<QByteArray>::const_iterator j;
for (j = formats.constBegin(); j != formats.constEnd(); ++j)
{
QString nextFormat = *j;
// Trick to count both "jpeg" and "jpg" extenstion
QString checkString = selector.contains("jpg",Qt::CaseInsensitive) ? "JPEG" : selector;
if (checkString.contains(nextFormat,Qt::CaseInsensitive) ) {
saveType = nextFormat;
break;
}
}
// a special treatment of the "gif" format.
// If "gif" is not provided with the local Qt installation
// replace "gif" format with "png" one
// -- if (saveType.isEmpty() && selector.contains("gif",FALSE)) saveType="PNG";
}
return saveType;
}
////////////////////////////////////////////////////////////////////////////////
/// The method to instantiate the QApplication if needed
TQtApplication *TGQt::CreateQtApplicationImp()
{
static TQtApplication *app = 0;
if (!app) {
// app = new TQtApplication(gApplication->ApplicationName(),gApplication->Argc(),gApplication->Argv());
static TString argvString (
#ifdef ROOTBINDIR
ROOTBINDIR "/root.exe"
#else
"$ROOTSYS/bin/root.exe"
#endif
);
gSystem->ExpandPathName(argvString);
static char *argv[] = {(char *)argvString.Data()};
static int nArg = 1;
app = new TQtApplication("Qt",nArg,argv);
}
return app;
}
////////////////////////////////////////////////////////////////////////////////
/// Qt announced that QThread::postEvent to become obsolete and
/// we have to switch to the QAppication instead.
void TGQt::PostQtEvent(QObject *receiver, QEvent *event)
{
QApplication::postEvent(receiver,event);
}
////////////////////////////////////////////////////////////////////////////////
///*-*-*-*-*-*-*-*-*-*-*-*Default Constructor *-*-*-*-*-*-*-*-*-*-*-*-*-*-*
///*-* ===================
TGQt::TGQt() : TVirtualX(),fDisplayOpened(kFALSE),fQPainter(0),fhEvent ()
,fQBrush(),fQPen(),fQtMarker(),fQFont(),fQClientFilter(),fQClientFilterBuffer(0)
,fPointerGrabber(),fCodec(0),fSymbolFontFamily("Symbol"),fQtEventHasBeenProcessed(0)
,fFeedBackMode(kFALSE),fFeedBackWidget(0),fBlockRGB(kFALSE),fUseTTF(kTRUE)
{
assert(!fgTQt);
fgTQt = this;
gQt = this;
fSelectedWindow = fPrevWindow = NoOperation;
}
////////////////////////////////////////////////////////////////////////////////
///*-*-*-*-*-*-*-*-*-*-*-*-*-*Normal Constructor*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
///*-* ================== *-*
TGQt::TGQt(const char *name, const char *title) : TVirtualX(name,title),fDisplayOpened(kFALSE)
,fQPainter(0),fhEvent(),fCursors(kNumCursors),fQClientFilter(0),fQClientFilterBuffer(0),fPointerGrabber(0)
,fCodec(0),fSymbolFontFamily("Symbol"),fQtEventHasBeenProcessed(0)
,fFeedBackMode(kFALSE),fFeedBackWidget(0),fBlockRGB(kFALSE),fUseTTF(kTRUE)
{
assert(!fgTQt);
fgTQt = this;
gQt = this;
fSelectedWindow = fPrevWindow = NoOperation;
CreateQtApplicationImp();
Init();
}
////////////////////////////////////////////////////////////////////////////////
///*-*-*-*-*-*-*-*-*-*-*-*Default Destructor*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
///*-* ==================
TGQt::~TGQt()
{
{ // critical section
TQtLock lock;
gVirtualX = gGXBatch;
gROOT->SetBatch();
// clear the color map
QMap<Color_t,QColor*>::const_iterator it;
for (it = fPallete.begin();it !=fPallete.end();++it) {
QColor *c = *it; delete c;
}
qDeleteAll(fCursors.begin(), fCursors.end());
delete fQClientFilter; fQClientFilter = 0;
delete fQClientFilterBuffer; fQClientFilterBuffer = 0;
delete fgTextProxy; fgTextProxy = 0;
// --- delete fQPainter; fQPainter = 0;
}
// Stop GUI thread
TQtApplication::Terminate();
// fprintf(stderr, "TGQt::~TGQt()<------\n");
}
////////////////////////////////////////////////////////////////////////////////
///*-*-*-*-*-*-*-*-*-*-*-*-*-*Qt GUI initialization-*-*-*-*-*-*-*-*-*-*-*-*-*-*
///*-* ======================== *-*
Bool_t TGQt::Init(void* /*display*/)
{
fprintf(stderr,"** $Id$ this=%p\n",this);
#ifndef R__QTWIN32
extern void qt_x11_set_global_double_buffer(bool);
// qt_x11_set_global_double_buffer(false);
#endif
if(fDisplayOpened) return fDisplayOpened;
fSelectedWindow = fPrevWindow = NoOperation;
fTextAlignH = 1;
fTextAlignV = 1;
fTextMagnitude = 1;
fCharacterUpX = 1;
fCharacterUpY = 1;
fDrawMode = QPainter::CompositionMode_Source; // Qt::CopyROP;
fTextFontModified = 0;
fTextAlign = 0;
fTextSize = -1;
fTextFont = -1;
fLineWidth = -1;
fFillColor = -1;
fLineColor = -1;
fLineStyle = -1;
fMarkerSize = -1;
fMarkerStyle = -1;
//
// Retrieve the application instance
//
// -- fHInstance = GetModuleHandle(NULL);
//
// Create cursors
//
// Qt::BlankCursor - blank/invisible cursor
// Qt::BitmapCursor
fCursors[kBottomLeft] = new QCursor(Qt::SizeBDiagCursor); // diagonal resize (/) LoadCursor(NULL, IDC_SIZENESW);// (display, XC_bottom_left_corner);
fCursors[kBottomRight] = new QCursor(Qt::SizeFDiagCursor); // diagonal resize (\) LoadCursor(NULL, IDC_SIZENWSE);// (display, XC_bottom_right_corner);
fCursors[kTopLeft] = new QCursor(Qt::SizeFDiagCursor); // diagonal resize (\) (display, XC_top_left_corner);
fCursors[kTopRight] = new QCursor(Qt::SizeBDiagCursor); // diagonal resize (/) LoadCursor(NULL, IDC_SIZENESW);// (display, XC_top_right_corner);
//fCursors[kBottomSide] = new QCursor(Qt::SplitHCursor); // - horziontal splitting LoadCursor(NULL, IDC_SIZENS); // (display, XC_bottom_side);
//fCursors[kLeftSide] = new QCursor(Qt::SplitVCursor); // - vertical splitting LoadCursor(NULL, IDC_SIZEWE); // (display, XC_left_side);
//fCursors[kTopSide] = new QCursor(Qt::SplitHCursor); // - horziontal splitting LoadCursor(NULL, IDC_SIZENS); // (display, XC_top_side);
//fCursors[kRightSide] = new QCursor(Qt::SplitVCursor); // - vertical splitting LoadCursor(NULL, IDC_SIZEWE); // (display, XC_right_side);
fCursors[kBottomSide] = new QCursor(Qt::SizeVerCursor); // - horziontal splitting LoadCursor(NULL, IDC_SIZENS); // (display, XC_bottom_side);
fCursors[kLeftSide] = new QCursor(Qt::SizeHorCursor); // - vertical splitting LoadCursor(NULL, IDC_SIZEWE); // (display, XC_left_side);
fCursors[kTopSide] = new QCursor(Qt::SizeVerCursor); // - horziontal splitting LoadCursor(NULL, IDC_SIZENS); // (display, XC_top_side);
fCursors[kRightSide] = new QCursor(Qt::SizeHorCursor); // - vertical splitting LoadCursor(NULL, IDC_SIZEWE); // (display, XC_right_side);
fCursors[kMove] = new QCursor(Qt::SizeAllCursor); // all directions resize LoadCursor(NULL, IDC_SIZEALL); // (display, XC_fleur);
fCursors[kCross] = new QCursor(Qt::CrossCursor); // - crosshair LoadCursor(NULL, IDC_CROSS); // (display, XC_tcross);
fCursors[kArrowHor] = new QCursor(Qt::SizeHorCursor); // horizontal resize LoadCursor(NULL, IDC_SIZEWE); // (display, XC_sb_h_double_arrow);
fCursors[kArrowVer] = new QCursor(Qt::SizeVerCursor); // vertical resize LoadCursor(NULL, IDC_SIZENS) (display, XC_sb_v_double_arrow);
fCursors[kHand] = new QCursor(Qt::PointingHandCursor); // a pointing hand LoadCursor(NULL, IDC_NO); // (display, XC_hand2);
fCursors[kRotate] = new QCursor(Qt::ForbiddenCursor); // - a slashed circle LoadCursor(NULL, IDC_ARROW); // (display, XC_exchange);
fCursors[kPointer] = new QCursor(Qt::ArrowCursor); // standard arrow cursor / (display, XC_left_ptr);
fCursors[kArrowRight] = new QCursor(Qt::UpArrowCursor); // - upwards arrow LoadCursor(NULL, IDC_ARROW); // XC_arrow
fCursors[kCaret] = new QCursor(Qt::IBeamCursor); // ibeam/text entry LoadCursor(NULL, IDC_IBEAM); // XC_xterm
fCursors[kWatch] = new QCursor(Qt::WaitCursor); //
// The default cursor
fCursor = kCross;
// Qt object used to paint the canvas
fQPen = new TQtPen;
fQBrush = new TQtBrush;
fQtMarker = new TQtMarker;
fQFont = new TQtPadFont();
// ((TGQt *)TGQt::GetVirtualX())->SetQClientFilter(
fQClientFilter = new TQtClientFilter();
// Query the default font for Widget decoration.
fFontTextCode = "ISO8859-1";
const char *default_font =
gEnv->GetValue("Gui.DefaultFont", "-adobe-helvetica-medium-r-*-*-12-*-*-*-*-*-iso8859-1");
QFont *dfFont = (QFont *)LoadQueryFont(default_font);
QApplication::setFont(*dfFont);
delete dfFont;
// define the font code page
QString fontName(default_font);
fFontTextCode = fontName.section('-',13). toUpper();
if ( fFontTextCode.isEmpty() ) fFontTextCode = "ISO8859-5";
#ifndef R__QTWIN32
// Check whether "Symbol" font is available
QFontDatabase fdb;
QString fontFamily;
QStringList families = fdb.families();
Bool_t symbolFontFound = kFALSE;
Bool_t isXdfSupport = !gSystem->Getenv("QT_X11_NO_FONTCONFIG");
for ( QStringList::Iterator f = families.begin(); f != families.end(); ++f ) {
// qDebug() << "Next Symbol font family found:" << *f << fdb.writingSystems(*f);
if ( (isXdfSupport && (*f).contains(fSymbolFontFamily)
&& fdb.writingSystems(*f).contains(QFontDatabase::Symbol)
) || (!isXdfSupport && ((*f) == fSymbolFontFamily)) )
{
symbolFontFound = kTRUE;
qDebug() << "Symbol font family found: " << *f;
if (*f == "Standard Symbols L") { fontFamily = *f; break; }
}
}
if (isXdfSupport && !symbolFontFound) {
// Load the local ROOT font