GSI Object Oriented Online Offline (Go4)  GO4-5.3.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
QRootCanvas.cpp
Go to the documentation of this file.
1 // $Id: QRootCanvas.cpp 1959 2016-11-24 08:47:28Z adamczew $
2 //-----------------------------------------------------------------------
3 // The GSI Online Offline Object Oriented (Go4) Project
4 // Experiment Data Processing at EE department, GSI
5 //-----------------------------------------------------------------------
6 // Copyright (C) 2000- GSI Helmholtzzentrum für Schwerionenforschung GmbH
7 // Planckstr. 1, 64291 Darmstadt, Germany
8 // Contact: http://go4.gsi.de
9 //-----------------------------------------------------------------------
10 // This software can be used under the license agreements as stated
11 // in Go4License.txt file which is part of the distribution.
12 //-----------------------------------------------------------------------
13 
14 /****************************************************************************
15 ** Copyright ( C ) 2000 denis Bertini. All rights reserved.
16 *****************************************************************************/
17 
18 #include "QRootCanvas.h"
19 
20 #include <QtCore/QEvent>
21 #include <QtCore/QSignalMapper>
22 #include <QtCore/QTimer>
23 
24 #include <QPainter>
25 #include <QDragEnterEvent>
26 #include <QDropEvent>
27 #include <QResizeEvent>
28 #include <QMouseEvent>
29 #include <QPaintEvent>
30 #include <QCloseEvent>
31 #include <QInputDialog>
32 #include <QColorDialog>
33 #include <QMenu>
34 #include <QAction>
35 #include <QMimeData>
36 #include <QDateTime>
37 
38 #include "TPad.h"
39 #include "TCanvas.h"
40 #include "TROOT.h"
41 #include "TString.h"
42 #include "TH1.h"
43 #include "TClass.h"
44 #include "TDataType.h"
45 #include "TDataMember.h"
46 #include "TMethod.h"
47 #include "TMethodCall.h"
48 #include "TMethodArg.h"
49 #include "TColor.h"
50 #include "TLatex.h"
51 #include "Riostream.h"
52 #include "TMath.h"
53 #ifndef __NOGO4GED__
54 #include "TGedEditor.h"
55 #endif
56 
57 #include "TGX11.h"
58 
59 #include "TGo4LockGuard.h"
60 //#define TGo4LockGuard int JAMDEBUG
61 
62 #include "QRootDialog.h"
63 #include "QRootApplication.h"
64 
65 #include <cstring>
66 
67 
68 QRootCanvas::QRootCanvas(QWidget *parent) :
69  QWidget(parent),
70  fMaskDoubleClick(false),
71  fxShowEventStatus(false),
72  fQtScalingfactor(1.0)
73 {
74  setObjectName( "QRootCanvas");
75 
76  setSizeIncrement( QSize( 100, 100 ) );
77 
78  TGo4LockGuard threadlock;
79  // set defaults
80  setUpdatesEnabled( true );
81  setMouseTracking(true);
82 
83  setFocusPolicy( Qt::TabFocus );
84  setCursor( Qt::CrossCursor );
85 
86  // disable option that at least background is redrawn immediately
87  // and canvas content after 100 ms timeout
88  //setAttribute(Qt::WA_NoSystemBackground);
89  setAttribute(Qt::WA_PaintOnScreen);
90  setAttribute(Qt::WA_PaintUnclipped);
91 
92  // add the Qt::WinId to TGX11 interface
93  fQtWindowId = winId();
94  fRootWindowId = gVirtualX->AddWindow((ULong_t)fQtWindowId, 100, 30);
95 
96  fCanvas = new TCanvas("Canvas", width(), height(), fRootWindowId);
97 
98 #if QT_VERSION > QT_VERSION_CHECK(5,6,0)
99  // JAM the following is pure empiric. hopefully default denominator won't change in future qt?
100  fQtScalingfactor=(double) metric(QPaintDevice::PdmDevicePixelRatioScaled)/65536.;
101 #endif
102  //std::cout <<"Found Qt scaling factor:"<<fQtScalingfactor << std::endl;
103  // create the context menu
104  fMousePosX = 0;
105  fMousePosY = 0;
106  fMenuMethods = 0;
107  fMenuObj = 0;
108 
109  setAcceptDrops(true);
110 
111  fRepaintMode = 0;
112  fRepaintTimer = new QTimer;
113  fRepaintTimer->setSingleShot(true);
114  connect(fRepaintTimer, SIGNAL(timeout()), this, SLOT(processRepaintTimer()));
115 }
116 
118 {
119  if(fCanvas) {
120  delete fCanvas;
121  fCanvas = 0;
122  }
123 
124  if (fMenuMethods) {
125  delete fMenuMethods;
126  fMenuMethods = 0;
127  }
128 
129  delete fRepaintTimer;
130 }
131 
132 void QRootCanvas::mouseMoveEvent(QMouseEvent *e)
133 {
134  TGo4LockGuard threadlock;
135 #if QT_VERSION > QT_VERSION_CHECK(5,0,0)
136  // JAM use event timestamp for reduction of events (qt5 bug):
137  static ulong lastprocesstime=0;
138  static ulong delta=100; // maybe ms units?
139  ulong timestamp=e->timestamp();
140  if(timestamp-delta<lastprocesstime)
141  {
142  // just eat too old events
143  e->accept();
144  // std::cout <<"----- EATING timestamp:"<<timestamp<< std::endl;
145  return;
146  }
147 
148  //std::cout <<"----- QRootCanvas::mouseMoveEvent with timestamp:"<<timestamp<<", oldstamp:"<<lastprocesstime << std::endl;
149 #endif
150 
151 
152  if (fCanvas!=0) {
153  if (e->buttons() & Qt::LeftButton)
154  fCanvas->HandleInput(kButton1Motion, scaledPosition(e->x()), scaledPosition(e->y()));
155  else
156  fCanvas->HandleInput(kMouseMotion, scaledPosition(e->x()), scaledPosition(e->y()));
157  }
158 
159  if(fxShowEventStatus) {
160  TObject* selected = fCanvas->GetSelected();
161  Int_t px = fCanvas->GetEventX();
162  Int_t py = fCanvas->GetEventY();
163  QString buffer = "";
164  if (selected!=0) {
165  buffer = selected->GetName();
166  buffer += " ";
167  buffer += selected->GetObjectInfo(px,py);
168  } else {
169  buffer = "No selected object x = ";
170  buffer += QString::number(px);
171  buffer += " y = ";
172  buffer += QString::number(py);
173  }
174  emit CanvasStatusEvent(buffer.toLatin1().constData());
175  }
176  e->accept();
177 #if QT_VERSION > QT_VERSION_CHECK(5,0,0)
178  lastprocesstime=timestamp;
179 #endif
180 }
181 
182 void QRootCanvas::wheelEvent( QWheelEvent* e)
183 {
184  TGo4LockGuard threadlock;
185  /*int scaledmetric= metric(QPaintDevice::PdmDevicePixelRatioScaled);
186  int scaledX=e->x() * scaledmetric/65536; // empiric
187  int scaledY=e->y() * scaledmetric/65536; // empiric
188  */
189  if (fCanvas==0) return;
190  e->accept();
191  if (e->delta() > 0)
192  fCanvas->HandleInput(kWheelUp, scaledPosition(e->x()), scaledPosition(e->y()));
193  else
194  fCanvas->HandleInput(kWheelDown, scaledPosition(e->x()), scaledPosition(e->y()));
195 }
196 
197 
198 void QRootCanvas::mousePressEvent( QMouseEvent *e )
199 {
200  TGo4LockGuard threadlock;
201  TObjLink* pickobj = 0;
202  // JAM2016-9 test
203 // std::cout <<"QRootCanvas::mousePressEvent at ("<<e->x()<<", "<< e->y()<<")"<< std::endl;
204  int scaledX=scaledPosition(e->x());
205  int scaledY=scaledPosition(e->y());
206  // std::cout <<" scaledX,scaledY: ("<<scaledX<<", "<<scaledY <<") "<< std::endl;
207 // std::cout <<"global from event: ("<<e->globalX()<<", "<< e->globalY()<< std::endl;
208 // QPoint globalp=QWidget::mapToGlobal(e->pos());
209 // std::cout <<"global from map: ("<<globalp.x()<<", "<<globalp.y() <<") "<< std::endl;
210 // QPoint parentp=QWidget::mapToParent(e->pos());
211 // std::cout <<"parent: ("<<parentp.x()<<", "<<parentp.y()<<") " << std::endl;
212 // QPoint backfromglobalp=QWidget::mapFromGlobal(globalp);
213 // std::cout <<"backglobal: ("<<backfromglobalp.x()<<", "<<backfromglobalp.y()<<") " << std::endl;
214 // Int_t destx=0, desty=0;
215 // Window_t child;
216 // Window_t rootwindow=gVirtualX->GetDefaultRootWindow();
217 // gVirtualX->TranslateCoordinates(rootwindow, fQtWindowId, globalp.x(), globalp.y(), destx, desty, child);
218 // std::cout <<"TGX11 global translated: ("<<destx<<", "<<desty<<") " << std::endl;
219 // std::cout <<"TGX11 winids - default root:"<<rootwindow<<", Qt:"<<fQtWindowId<<", child:" <<child<< std::endl;
220 
221 
222  /* int themetric= metric(QPaintDevice::PdmDevicePixelRatio);
223  int scaledmetric= metric(QPaintDevice::PdmDevicePixelRatioScaled);
224  std::cout <<"metric="<<themetric<<", scaled="<<scaledmetric << std::endl;
225  int scaledX=e->x() * scaledmetric/65536; // empiric
226  int scaledY=e->y() * scaledmetric/65536; // empiric
227  std::cout <<"scaledX,scaledY: ("<<scaledX<<", "<<scaledY <<") "<< std::endl;
228  */
229 
230 
231  TPad* pad = fCanvas->Pick(scaledX, scaledY, pickobj);
232  TObject *selected = fCanvas->GetSelected();
233 
234  switch(e->button()) {
235  case Qt::LeftButton :
236  fCanvas->HandleInput(kButton1Down, scaledX, scaledY);
237  emit PadClicked(pad);
238  break;
239  case Qt::RightButton : {
240  TString selectedOpt("");
241  if (pad!=0) {
242  if (pickobj==0) {
243  fCanvas->SetSelected(pad);
244  selected = pad;
245  } else
246  if(selected==0) {
247  selected = pickobj->GetObject();
248  selectedOpt = pickobj->GetOption();
249  }
250  pad->cd();
251  }
252  fCanvas->SetSelectedPad(pad);
253  gROOT->SetSelectedPrimitive(selected);
254  fMousePosX = gPad->AbsPixeltoX(gPad->GetEventX());
255  fMousePosY = gPad->AbsPixeltoY(gPad->GetEventY());
256 
257  QMenu menu(this);
258  QSignalMapper map;
259  connect(&map, SIGNAL(mapped(int)), this, SLOT(executeMenu(int)));
260 
261  fMenuObj = selected;
262  fMenuMethods = new TList;
263  TClass *cl = fMenuObj->IsA();
264  int curId = -1;
265 
266  QString buffer = Form("%s::%s", cl->GetName(), fMenuObj->GetName());
267  addMenuAction(&menu, &map, buffer, curId++);
268 
269  cl->GetMenuItems(fMenuMethods);
270  menu.addSeparator();
271 
272  if(!cl->InheritsFrom(TLatex::Class())) {
273  addMenuAction(&menu, &map, "Insert Latex", 100 );
274  menu.addSeparator();
275  }
276 
277  if(cl->InheritsFrom(TH1::Class())) {
278  addMenuAction(&menu, &map, "Qt Hist Line Color ", 101 );
279  addMenuAction(&menu, &map, "Qt Hist Fill Color ", 102 );
280  menu.addSeparator();
281  }
282 
283  TIter iter(fMenuMethods);
284  TMethod *method=0;
285  while ( (method = dynamic_cast<TMethod*>(iter())) != 0) {
286  buffer = method->GetName();
287  addMenuAction(&menu, &map, buffer, curId++);
288  }
289 
290  if (menu.exec(e->globalPos())==0) {
291  fMenuObj = 0;
292  delete fMenuMethods;
293  fMenuMethods = 0;
294  }
295 
296  break;
297  }
298  case Qt::MidButton :
299  fCanvas->HandleInput(kButton2Down, scaledX, scaledY);
300  emit SelectedPadChanged(pad); // that inform the Qt-world that tha pad is changed
301  // and give the pointer to the new pad as argument
302  // of the signal (M. Al-Turany)
303  break;
304  case Qt::NoButton :
305  break;
306  default:
307  break;
308  }
309  e->accept();
310 }
311 
312 void QRootCanvas::mouseReleaseEvent( QMouseEvent *e )
313 {
314  TGo4LockGuard threadlock;
315 
316  switch(e->button()) {
317  case Qt::LeftButton :
318  fCanvas->HandleInput(kButton1Up, scaledPosition(e->x()), scaledPosition(e->y()));
319  break;
320  case Qt::RightButton :
321  fCanvas->HandleInput(kButton3Up, scaledPosition(e->x()), scaledPosition(e->y()));
322  break;
323  case Qt::MidButton :
324  fCanvas->HandleInput(kButton2Up, scaledPosition(e->x()),scaledPosition( e->y()));
325  break;
326  case Qt::NoButton :
327  break;
328  default:
329  break;
330  }
331  e->accept();
332 }
333 
335 {
336  TGo4LockGuard threadlock;
337  switch(e->button()) {
338  case Qt::LeftButton : {
339  if (!fMaskDoubleClick)
340  fCanvas->HandleInput(kButton1Double, scaledPosition(e->x()), scaledPosition(e->y()));
341  TObjLink* pickobj = 0;
342  TPad* pad = fCanvas->Pick(scaledPosition(e->x()), scaledPosition(e->y()), pickobj);
343  emit PadDoubleClicked(pad);
344  // prevent crash on following release event
345  // if new canvas will be created in between
346  // fCanvas->SetSelected(0);
347  break;
348  }
349  case Qt::RightButton :
350  fCanvas->HandleInput(kButton3Double, scaledPosition(e->x()), scaledPosition(e->y()));
351  break;
352  case Qt::MidButton :
353  fCanvas->HandleInput(kButton2Double, scaledPosition(e->x()), scaledPosition(e->y()));
354  break;
355  case Qt::NoButton :
356  break;
357  default:
358  break;
359  }
360  e->accept();
361 }
362 
364 {
365  fRepaintMode |= mode;
366 // if (fRepaintMode > 0) setUpdatesEnabled( false ); // JAM avoid flicker on Qt5 ?
367  fRepaintTimer->setSingleShot(true);
368  fRepaintTimer->start(100);
369 }
370 
371 void QRootCanvas::resizeEvent( QResizeEvent *)
372 {
373  //std::cout<< "QRootCanvas::resizeEvent"<<std::endl;
375 }
376 
377 void QRootCanvas::paintEvent( QPaintEvent *)
378 {
379  // this is workaround a problem, that after drawing canvas in
380  // viewpanel there is always 1 event after that
381  // therefore fRepaintMode set to -1 to ignore such first event
382  // In future behavior may change
383 
384  if (fRepaintMode<0)
385  fRepaintMode = 0;
386  else
388 }
389 
391 {
392  if (fRepaintMode == 0) return;
393  //std::cout<< " QRootCanvas::processRepaintTimer()"<<std::endl;
394  //printf("processRepaintTimer with fRepaintMode %d\n",fRepaintMode);
395  TGo4LockGuard threadlock;
396 
397  WId newid = winId();
398  if(newid != fQtWindowId) {
399  //printf("processRepaintTimer - sees changed window id %d \n",newid);
400  // Qt has changed id for this widget (e.g. at QWorkspace::addWindow())
401  // need to adjust the ROOT X access:
402  delete fCanvas; // should also remove old x windows!
403  fRootWindowId = gVirtualX->AddWindow((ULong_t)newid, width(), height());
404  fCanvas = new TCanvas(objectName().toLatin1().constData(), width(), height(), fRootWindowId);
405  fQtWindowId = newid;
406  }
407 
408  if (fRepaintMode && act_Resize) fCanvas->Resize();
409  else fCanvas->Modified(kTRUE);
410 
411  fCanvas->Update();
412 
413  fRepaintMode = 0;
414  //std::cout<< std::endl;
415  emit CanvasUpdated();
416  //setUpdatesEnabled( true ); // JAM avoid flicker on Qt5 ?
417 }
418 
419 void QRootCanvas::leaveEvent( QEvent *e )
420 {
421  QWidget::leaveEvent(e);
422 
423  TGo4LockGuard threadlock;
424  if (fCanvas!=0)
425  fCanvas->HandleInput(kMouseLeave, 0, 0);
426 
427  emit CanvasLeaveEvent();
428 }
429 
431 {
432  fxShowEventStatus = s;
433 }
434 
436 {
437  return fxShowEventStatus;
438 }
439 
441 
442 void QRootCanvas::dragEnterEvent( QDragEnterEvent *e )
443 {
444  if (e->mimeData()->hasText())
445  e->acceptProposedAction();
446 }
447 
448 void QRootCanvas::dropEvent( QDropEvent *event )
449 {
450  TObject* obj(0);
451  QPoint pos = event->pos();
452  TPad* pad = Pick(scaledPosition(pos.x()), scaledPosition(pos.y()), obj);
453 
454  if (pad!=0)
455  emit CanvasDropEvent(event, pad);
456 }
457 
459 
460 void QRootCanvas::cd(Int_t subpadnumber)
461 {
462  fCanvas->cd(subpadnumber);
463 }
464 
465 void QRootCanvas::Browse(TBrowser *b)
466 {
467  fCanvas->Browse(b);
468 }
469 
470 void QRootCanvas::Clear(Option_t *option)
471 {
472  fCanvas->Clear(option);
473 }
474 
475 void QRootCanvas::Close(Option_t *option)
476 {
477  fCanvas->Close(option);
478 }
479 
480 void QRootCanvas::Draw(Option_t *option)
481 {
482  fCanvas->Draw(option);
483 }
484 
485 TObject* QRootCanvas::DrawClone(Option_t *option)
486 {
487  return fCanvas->DrawClone(option);
488 }
489 
491 {
492  return fCanvas->DrawClonePad();
493 }
494 
496 {
497  fCanvas->EditorBar();
498 }
499 
500 void QRootCanvas::EnterLeave(TPad *prevSelPad, TObject *prevSelObj)
501 {
502  fCanvas->EnterLeave(prevSelPad, prevSelObj);
503 }
504 
506 {
507  fCanvas->FeedbackMode(set);
508 }
509 
511 {
512  fCanvas->Flush();
513 }
514 
516 {
517  fCanvas->UseCurrentStyle();
518 }
519 
521 {
522  fCanvas->ForceUpdate() ;
523 }
524 
526 {
527  return fCanvas->GetDISPLAY() ;
528 }
529 
531 {
532  return fCanvas->GetContextMenu();
533 }
534 
536 {
537  return fCanvas->GetDoubleBuffer();
538 }
539 
541 {
542  return fCanvas->GetEvent();
543 }
544 
546 {
547  return fCanvas->GetEventX();
548 }
549 
551 {
552  return fCanvas->GetEventY();
553 }
554 
556 {
557  return fCanvas->GetHighLightColor() ;
558 }
559 
561 {
562  return fCanvas->GetPadSave();
563 }
564 
566 {
567  return fCanvas->GetSelected() ;
568 }
569 
571 {
572  return fCanvas->GetSelectedOpt();
573 }
574 
576 {
577  return fCanvas->GetSelectedPad();
578 }
579 
581 {
582  return fCanvas->GetShowEventStatus() ;
583 }
584 
586 {
587  return fCanvas->GetAutoExec();
588 }
589 
591 {
592  return fCanvas->GetXsizeUser();
593 }
594 
596 {
597  return fCanvas->GetYsizeUser();
598 }
599 
601 {
602  return fCanvas->GetXsizeReal();
603 }
604 
606 {
607  return fCanvas->GetYsizeReal();
608 }
609 
611 {
612  return fCanvas->GetCanvasID();
613 }
614 
616 {
617  return fCanvas->GetWindowTopX();
618 }
619 
621 {
622  return fCanvas->GetWindowTopY();
623 }
624 
626 {
627  return fCanvas->GetWindowWidth() ;
628 }
629 
631 {
632  return fCanvas->GetWindowHeight();
633 }
634 
636 {
637  return fCanvas->GetWw();
638 }
639 
641 {
642  return fCanvas->GetWh() ;
643 }
644 
645 void QRootCanvas::GetCanvasPar(Int_t &wtopx, Int_t &wtopy, UInt_t &ww, UInt_t &wh)
646 {
647  fCanvas->GetCanvasPar(wtopx, wtopy, ww, wh);
648 }
649 
650 void QRootCanvas::HandleInput(EEventType button, Int_t x, Int_t y)
651 {
652  fCanvas->HandleInput(button, scaledPosition(x), scaledPosition(y));
653 }
654 
656 {
657  return fCanvas->HasMenuBar() ;
658 }
659 
661 {
662  fCanvas->Iconify();
663 }
664 
666 {
667  return fCanvas->IsBatch() ;
668 }
669 
671 {
672  return fCanvas->IsRetained();
673 }
674 
675 void QRootCanvas::ls(Option_t *option)
676 {
677  fCanvas->ls(option);
678 }
679 
680 void QRootCanvas::Modified(Bool_t mod)
681 {
682  fCanvas->Modified(mod);
683 }
684 
685 void QRootCanvas::MoveOpaque(Int_t set)
686 {
687  fCanvas->MoveOpaque(set);
688 }
689 
691 {
692  return fCanvas->OpaqueMoving();
693 }
694 
696 {
697  return fCanvas->OpaqueResizing();
698 }
699 
700 void QRootCanvas::Paint(Option_t *option)
701 {
702  fCanvas->Paint(option);
703 }
704 
705 TPad* QRootCanvas::Pick(Int_t px, Int_t py, TObjLink *&pickobj)
706 {
707  return fCanvas->Pick(px, py, pickobj);
708 }
709 
710 TPad* QRootCanvas::Pick(Int_t px, Int_t py, TObject *prevSelObj)
711 {
712  return fCanvas->Pick(px, py, prevSelObj);
713 }
714 
715 void QRootCanvas::Resize(Option_t *option)
716 {
717  fCanvas->Resize(option);
718 }
719 
721 {
722  fCanvas->ResizeOpaque(set);
723 }
724 
725 void QRootCanvas::SaveSource(const char *filename, Option_t *option)
726 {
727  fCanvas->SaveSource(filename, option);
728 }
729 
730 void QRootCanvas::SetCursor(ECursor cursor)
731 {
732  fCanvas->SetCursor(cursor);
733 }
734 
736 {
737  fCanvas->SetDoubleBuffer(mode);
738 }
739 
740 void QRootCanvas::SetWindowPosition(Int_t x, Int_t y)
741 {
742  fCanvas->SetWindowPosition(x, y) ;
743 }
744 
745 void QRootCanvas::SetWindowSize(UInt_t ww, UInt_t wh)
746 {
747  fCanvas->SetWindowSize(ww,wh) ;
748 }
749 
750 void QRootCanvas::SetCanvasSize(UInt_t ww, UInt_t wh)
751 {
752  fCanvas->SetCanvasSize(ww, wh);
753 }
754 
756 {
757  fCanvas->SetHighLightColor(col);
758 }
759 
760 void QRootCanvas::SetSelected(TObject *obj)
761 {
762  fCanvas->SetSelected(obj);
763 }
764 
766 {
767  fCanvas->SetSelectedPad(pad);
768 }
769 
771 {
772  fCanvas->Show();
773 }
774 
775 void QRootCanvas::Size(Float_t xsizeuser, Float_t ysizeuser)
776 {
777  fCanvas->Size(xsizeuser, ysizeuser);
778 }
779 
780 void QRootCanvas::SetBatch(Bool_t batch)
781 {
782  fCanvas->SetBatch(batch);
783 }
784 
785 void QRootCanvas::SetRetained(Bool_t retained)
786 {
787  fCanvas->SetRetained(retained);
788 }
789 
790 void QRootCanvas::SetTitle(const char *title)
791 {
792  fCanvas->SetTitle(title);
793 }
794 
796 {
797  fCanvas->ToggleEventStatus();
798 }
799 
801 {
802  fCanvas->ToggleAutoExec();
803 }
804 
806 {
807  // do not call update directly, use timer instead
809 }
810 
811 void QRootCanvas::closeEvent( QCloseEvent * e)
812 {
813  if (fCanvas) {
814  delete fCanvas;
815  fCanvas = 0;
816  }
817 
818  e->accept();
819 }
820 
821 void QRootCanvas::methodDialog(TObject* object, TMethod* method)
822 {
823  if ((object==0) || (method==0)) return;
824 
825  TGo4LockGuard threadlock;
826  // Create dialog object with OK and Cancel buttons. This dialog
827  // prompts for the arguments of "method".
828 
829  QRootDialog dlg;
830 
831  dlg.setWindowTitle(Form("%s:%s", object->GetName(), method->GetName()));
832 
833  // iterate through all arguments and create apropriate input-data objects:
834  // inputlines, option menus...
835  TMethodArg *argument = 0;
836  TIter next(method->GetListOfMethodArgs());
837 
838  while ((argument = (TMethodArg *) next())) {
839  TString argTitle = TString::Format("(%s) %s", argument->GetTitle(), argument->GetName());
840  TString argDflt = argument->GetDefault() ? argument->GetDefault() : "";
841  if (argDflt.Length()>0)
842  argTitle += TString::Format(" [default: %s]", argDflt.Data());
843  TString type = argument->GetTypeName();
844  TDataType *datatype = gROOT->GetType(type);
845  TString basictype;
846 
847  if (datatype) {
848  basictype = datatype->GetTypeName();
849  } else {
850  if (type.CompareTo("enum") != 0)
851  std::cout << "*** Warning in Dialog(): data type is not basic type, assuming (int)\n";
852  basictype = "int";
853  }
854 
855  if (TString(argument->GetTitle()).Index("*")!=kNPOS) {
856  basictype += "*";
857  type = "char*";
858  }
859 
860  TDataMember *m = argument->GetDataMember();
861  if (m && m->GetterMethod()) {
862 
863  m->GetterMethod()->Init(object->IsA(), m->GetterMethod()->GetMethodName(), "");
864 
865  // Get the current value and form it as a text:
866 
867  TString val;
868 
869  if (basictype == "char*") {
870  char *tdefval(0);
871  m->GetterMethod()->Execute(object, "", &tdefval);
872  if (tdefval) val = tdefval;
873  } else
874  if ((basictype == "float") ||
875  (basictype == "double")) {
876  Double_t ddefval(0.);
877  m->GetterMethod()->Execute(object, "", ddefval);
878  val = TString::Format("%g", ddefval);
879  } else
880  if ((basictype == "char") ||
881  (basictype == "int") ||
882  (basictype == "long") ||
883  (basictype == "short")) {
884  Long_t ldefval(0);
885  m->GetterMethod()->Execute(object, "", ldefval);
886  val = TString::Format("%ld", ldefval);
887  }
888 
889  // Find out whether we have options ...
890 
891  TList *opt;
892  if ((opt = m->GetOptions()) != 0) {
893  //std::cout << "*** Warning in Dialog(): option menu not yet implemented " << opt << std::endl;
894  // should stop dialog
895  // workaround JAM: do not stop dialog, use textfield (for time display toggle)
896  dlg.addArg(argTitle.Data(), val.Data(), type.Data());
897  //return;
898  } else {
899  // we haven't got options - textfield ...
900  dlg.addArg(argTitle.Data(), val.Data(), type.Data());
901  }
902  } else { // if m not found ...
903  if ((argDflt.Length() > 1) &&
904  (argDflt[0]=='\"') && (argDflt[argDflt.Length()-1]=='\"')) {
905  // cut "" from the string argument
906  argDflt.Remove(0,1);
907  argDflt.Remove(argDflt.Length()-1,1);
908  }
909 
910  dlg.addArg(argTitle.Data(), argDflt.Data(), type.Data());
911  }
912  }
913 
914  if (dlg.exec() != QDialog::Accepted) return;
915 
916  Bool_t deletion = kFALSE;
917 
918  qDebug("DIAL executeMethod: simple version\n");
919  TVirtualPad *psave = gROOT->GetSelectedPad();
920 
921  qDebug("DIAL saved pad: %s gPad:%s \n",psave->GetName(),gPad->GetName());
922 
923  qDebug("DIAL obj:%s meth:%s \n", object->GetName(), method->GetName());
924 
925  //std::cout<< "executeMethod" << fCurMethod->GetName() << std::endl;
926 
927  TObjArray tobjlist(method->GetListOfMethodArgs()->LastIndex() + 1);
928  for (int n=0; n<=method->GetListOfMethodArgs()->LastIndex(); n++) {
929  QString s = dlg.getArg(n);
930  qDebug( "** QString values (first ) :%s \n", s.toLatin1().constData() );
931  tobjlist.AddLast(new TObjString(s.toLatin1().constData())) ;
932  }
933 
934  // handle command if existing object
935  if(strcmp(method->GetName(),"Delete") == 0) {
936  // here call explicitly the dtor
937  qDebug(" DIAL obj name deleted :%s \n", object->GetName());
938  emit MenuCommandExecuted(object, "Delete");
939  delete object;
940  object = 0;
941  deletion = kTRUE;
942  qDebug(" DIAL deletion done closing ... \n");
943  } else
944  if (strcmp(method->GetName(), "SetCanvasSize") == 0) {
945  int width = dlg.getArg(0).toInt();
946  int height = dlg.getArg(1).toInt();
947  qDebug( " do resize with %i %i \n", width, height);
948  resize(width, height);
949  emit MenuCommandExecuted(fCanvas, "SetCanvasSize");
950  } else {
951  // here call cint call
952  qDebug("TCint::Execute called !\n");
953 
954  object->Execute(method, &tobjlist);
955 
956  if (object->TestBit(TObject::kNotDeleted))
957  emit MenuCommandExecuted(object, method->GetName());
958  else {
959  deletion = true;
960  object = 0;
961  }
962  }
963 
964  if(!deletion ) {
965  qDebug("DIAL set saved pad: %s herit:%s gPad:%s\n",
966  psave->GetName(), psave->ClassName(), gPad->GetName());
967  gROOT->SetSelectedPad(psave);
968  gROOT->GetSelectedPad()->Modified();
969  gROOT->GetSelectedPad()->Update();
970  qDebug("DIAL update done on %s \n", gROOT->GetSelectedPad()->GetName());
971  } else {
972  gROOT->SetSelectedPad( gPad );
973  gROOT->GetSelectedPad()->Update();
974  }
975 }
976 
977 QAction* QRootCanvas::addMenuAction(QMenu* menu, QSignalMapper* map, const QString& text, int id)
978 {
980 
981  QAction* act = new QAction(text, menu);
982 
983  if (!enabled)
984  if ((text.compare("DrawClone")==0) ||
985  (text.compare("DrawClass")==0) ||
986  (text.compare("Inspect")==0) ||
987  (text.compare("SetShowProjectionX")==0) ||
988  (text.compare("SetShowProjectionY")==0) ||
989  (text.compare("DrawPanel")==0) ||
990  (text.compare("FitPanel")==0))
991  act->setEnabled(false);
992 
993  map->connect (act, SIGNAL(triggered()), map, SLOT(map()));
994  menu->addAction(act);
995  map->setMapping(act, id);
996 
997 
998  return act;
999 }
1000 
1002 {
1003  TGo4LockGuard threadlock;
1004  QString text("");
1005  bool ok = false;
1006  if (id >=100) {
1007  switch (id){
1008  case 100: {
1009  TLatex *fxLatex = new TLatex();
1010  text = QInputDialog::getText(this, tr( "Qt Root" ),
1011  tr( "Please enter your text" ),
1012  QLineEdit::Normal, QString::null, &ok);
1013  //if (ok && !text.isEmpty())
1014  fxLatex->DrawLatex(fMousePosX, fMousePosY, text.toLatin1().constData());
1015  emit MenuCommandExecuted(fxLatex, "DrawLatex");
1016  break;
1017  }
1018  case 101: {
1019  TH1 *h1 = dynamic_cast<TH1*> (fMenuObj);
1020  if (h1!=0) {
1021  QColor col = QColorDialog::getColor();
1022  if (col.isValid()) {
1023  short int C_new = TColor::GetColor(col.red(), col.green(), col.blue());
1024  h1->SetLineColor(C_new);
1025  emit MenuCommandExecuted(h1, "SetLineColor");
1026  }
1027  }
1028  break;
1029  }
1030  case 102 : {
1031  TH1 *h1 = dynamic_cast<TH1*> (fMenuObj);
1032  if (h1!=0) {
1033  QColor col = QColorDialog::getColor();
1034  if (col.isValid()) {
1035  short int C_new = TColor::GetColor(col.red(), col.green(), col.blue());
1036  h1->SetFillColor(C_new);
1037  emit MenuCommandExecuted(h1,"SetFillColor");
1038  }
1039  }
1040  }
1041  }
1042  gROOT->GetSelectedPad()->Update();
1043  gROOT->GetSelectedPad()->Modified();
1044  fCanvas->Modified();
1045  fCanvas->ForceUpdate();
1046  gROOT->SetFromPopUp( kFALSE );
1047  } else
1048  if (id >=0) {
1049 
1050  // save global to Pad before calling TObject::Execute()
1051 
1052  TVirtualPad* psave = gROOT->GetSelectedPad();
1053  TMethod *method = (TMethod *) fMenuMethods->At(id);
1054 
1056  fCanvas->HandleInput(kButton3Up, gPad->XtoAbsPixel(fMousePosX), gPad->YtoAbsPixel(fMousePosY));
1057 
1058  // change current dir that all new histograms appear here
1059  gROOT->cd();
1060 
1061 
1062  if (method->GetListOfMethodArgs()->First()){
1063  if (strstr(method->GetName(), "Delete")){
1064  // JAM2016: do not allow mouse menu delete in Go4
1065  //std::cout << "Supressing Delete in menu!" << std::endl;
1066  }
1067  else {
1068  methodDialog(fMenuObj, method);
1069  }
1070  }
1071  else
1072  {
1073  gROOT->SetFromPopUp(kTRUE);
1074  fMenuObj->Execute(method->GetName(), "");
1075 
1076  if (fMenuObj->TestBit(TObject::kNotDeleted)) {
1077  emit MenuCommandExecuted(fMenuObj, method->GetName());
1078  } else {
1079  fMenuObj = 0;
1080  }
1081 
1082  }
1083 
1084  #ifndef __NOGO4GED__
1085  TGedEditor* ed = dynamic_cast<TGedEditor*>(TVirtualPadEditor::GetPadEditor(kFALSE));
1086  if (fMenuObj && ed) ed->SetModel(psave, fMenuObj, kButton1Down);
1087  #endif
1088 
1089  fCanvas->GetPadSave()->Update();
1090  fCanvas->GetPadSave()->Modified();
1091 
1092  gROOT->SetSelectedPad(psave);
1093 
1094  gROOT->GetSelectedPad()->Update();
1095  gROOT->GetSelectedPad()->Modified();
1096 
1097  fCanvas->Modified();
1098  fCanvas->ForceUpdate();
1099  gROOT->SetFromPopUp(kFALSE);
1100  }
1101 
1102  fMenuObj = 0;
1103  delete fMenuMethods;
1104  fMenuMethods = 0;
1105 }
void SetBatch(Bool_t batch=kTRUE)
Bool_t IsRetained()
double scaledPosition(int p)
Definition: QRootCanvas.h:198
Option_t * GetSelectedOpt()
Size_t GetYsizeUser()
void Iconify()
virtual void mouseDoubleClickEvent(QMouseEvent *e)
void Modified(Bool_t=1)
Int_t GetWindowTopX()
virtual void Draw(Option_t *option="")
virtual void Size(Float_t xsizeuser=0, Float_t ysizeuser=0)
void SetRetained(Bool_t retained=kTRUE)
TVirtualPad * GetSelectedPad()
virtual void paintEvent(QPaintEvent *e)
void activateRepaint(int act)
virtual void dropEvent(QDropEvent *Event)
TObject * fMenuObj
Definition: QRootCanvas.h:221
Bool_t IsBatch()
TList * fMenuMethods
Definition: QRootCanvas.h:222
void MenuCommandExecuted(TObject *, const char *)
void CanvasLeaveEvent()
virtual void HandleInput(EEventType button, Int_t x, Int_t y)
void SelectedPadChanged(TPad *)
Int_t GetEventY()
virtual void ToggleEventStatus()
Bool_t OpaqueResizing()
virtual void ToggleAutoExec()
void FeedbackMode(Bool_t set)
void SetCanvasSize(UInt_t ww, UInt_t wh)
void EnterLeave(TPad *prevSelPad, TObject *prevSelObj)
void SetTitle(const char *title="")
void PadClicked(TPad *)
Int_t GetWindowTopY()
Int_t GetEventX()
void CanvasUpdated()
Int_t GetEvent()
virtual void Browse(TBrowser *b)
UInt_t GetWh()
int fRepaintMode
Definition: QRootCanvas.h:214
virtual TObject * DrawClone(Option_t *option="")
QRootCanvas(QWidget *parent=0)
Definition: QRootCanvas.cpp:68
Bool_t GetAutoExec()
virtual void SetDoubleBuffer(Int_t mode=1)
void SaveSource(const char *filename="", Option_t *option="")
bool fMaskDoubleClick
Definition: QRootCanvas.h:217
double fMousePosX
Definition: QRootCanvas.h:218
TObject * GetSelected()
void methodDialog(TObject *object, TMethod *method)
Int_t GetCanvasID()
QAction * addMenuAction(QMenu *menu, QSignalMapper *map, const QString &text, int id)
Bool_t OpaqueMoving()
virtual void SetCursor(ECursor cursor)
double fMousePosY
Definition: QRootCanvas.h:219
Color_t GetHighLightColor()
void ResizeOpaque(Int_t set=1)
void cd(Int_t subpadnumber=0)
void ForceUpdate()
void setShowEventStatus(bool s)
TContextMenu * GetContextMenu()
virtual void mouseReleaseEvent(QMouseEvent *e)
void SetHighLightColor(Color_t col)
void SetSelected(TObject *obj)
virtual void mousePressEvent(QMouseEvent *e)
bool fxShowEventStatus
Definition: QRootCanvas.h:223
void Clear(Option_t *option="")
virtual void leaveEvent(QEvent *e)
virtual TObject * DrawClonePad()
virtual void resizeEvent(QResizeEvent *e)
void Close(Option_t *option="")
Int_t GetDoubleBuffer()
void CanvasDropEvent(QDropEvent *, TPad *)
static bool IsRootCanvasMenuEnabled()
QString getArg(int n)
Definition: QRootDialog.cpp:77
QTimer * fRepaintTimer
Definition: QRootCanvas.h:213
void addArg(const char *argname, const char *value, const char *type)
Definition: QRootDialog.cpp:63
virtual void GetCanvasPar(Int_t &wtopx, Int_t &wtopy, UInt_t &ww, UInt_t &wh)
virtual void Paint(Option_t *option="")
virtual TPad * Pick(Int_t px, Int_t py, TObjLink *&pickobj)
virtual void Resize(Option_t *option="")
TVirtualPad * GetPadSave()
virtual void dragEnterEvent(QDragEnterEvent *e)
void SetWindowSize(UInt_t ww, UInt_t wh)
const char * GetDISPLAY()
bool showEventStatus() const
Bool_t HasMenuBar()
Size_t GetXsizeUser()
virtual void EditorBar()
TCanvas * fCanvas
Definition: QRootCanvas.h:210
void processRepaintTimer()
void UseCurrentStyle()
virtual void closeEvent(QCloseEvent *e)
double fQtScalingfactor
Definition: QRootCanvas.h:225
UInt_t GetWindowHeight()
virtual void mouseMoveEvent(QMouseEvent *e)
void MoveOpaque(Int_t set=1)
UInt_t GetWw()
Size_t GetYsizeReal()
virtual void ls(Option_t *option="")
void CanvasStatusEvent(const char *)
Size_t GetXsizeReal()
void SetWindowPosition(Int_t x, Int_t y)
void SetSelectedPad(TPad *pad)
void executeMenu(int id)
virtual void wheelEvent(QWheelEvent *e)
void PadDoubleClicked(TPad *)
virtual ~QRootCanvas()
Bool_t GetShowEventStatus()
UInt_t GetWindowWidth()
Int_t fRootWindowId
Definition: QRootCanvas.h:211
virtual void Update()