22 #include <QtCore/QSignalMapper>
23 #include <QtCore/QTimer>
25 #include <QDragEnterEvent>
27 #include <QMouseEvent>
28 #include <QCloseEvent>
29 #include <QInputDialog>
30 #include <QColorDialog>
34 #include <QVBoxLayout>
39 #include "TObjString.h"
40 #include "TObjArray.h"
43 #include "TDataType.h"
44 #include "TDataMember.h"
46 #include "TMethodCall.h"
47 #include "TMethodArg.h"
52 #include "TGedEditor.h"
53 #include "TVirtualPadEditor.h"
57 #include "TGo4LockGuard.h"
59 #define TGo4LockGuard int
68 fMaskDoubleClick(false),
69 fxShowEventStatus(false),
72 setObjectName(
"QRootCanvas");
74 setSizeIncrement( QSize( 100, 100 ) );
78 setUpdatesEnabled(
true );
79 setMouseTracking(
true);
81 setFocusPolicy( Qt::TabFocus );
82 setCursor( Qt::CrossCursor );
87 setAttribute(Qt::WA_PaintOnScreen);
88 setAttribute(Qt::WA_PaintUnclipped);
96 #if QT_VERSION > QT_VERSION_CHECK(5,6,0)
98 fQtScalingfactor=(double) metric(QPaintDevice::PdmDevicePixelRatioScaled)/65536.;
107 setAcceptDrops(
true);
159 #if QT_VERSION < QT_VERSION_CHECK(6,0,0)
166 return QPoint(scaledX, scaledY);
172 #if QT_VERSION > QT_VERSION_CHECK(5,0,0)
174 static ulong lastprocesstime=0;
175 static ulong delta=100;
176 ulong timestamp=e->timestamp();
177 if(timestamp-delta<lastprocesstime)
192 if (e->buttons() & Qt::LeftButton)
193 fCanvas->HandleInput(kButton1Motion, pnt.x(), pnt.y());
195 fCanvas->HandleInput(kMouseMotion, pnt.x(), pnt.y());
199 TObject* selected =
fCanvas->GetSelected();
200 Int_t px =
fCanvas->GetEventX();
201 Int_t py =
fCanvas->GetEventY();
204 buffer = selected->GetName();
206 buffer += selected->GetObjectInfo(px, py);
208 buffer =
"No selected object x = ";
209 buffer += QString::number(px);
211 buffer += QString::number(py);
219 #if QT_VERSION > QT_VERSION_CHECK(5,0,0)
220 lastprocesstime=timestamp;
230 #if QT_VERSION < QT_VERSION_CHECK(5,15,0)
231 bool positive = (e->delta() > 0);
232 int ex = e->x(), ey = e->y();
234 QPoint delta = e->pixelDelta();
235 if (delta.isNull()) delta = e->angleDelta() / 8;
236 bool positive = delta.x() > 0 || delta.y() > 0;
237 int ex = e->position().x(), ey = e->position().y();
247 TObjLink* pickobj = 0;
252 #if QT_VERSION < QT_VERSION_CHECK(6,0,0)
253 QPoint mouse_pnt = e->globalPos();
255 QPoint mouse_pnt = e->globalPosition().toPoint();
283 TPad* pad =
fCanvas->Pick(scaled.x(), scaled.y(), pickobj);
284 TObject *selected =
fCanvas->GetSelected();
286 switch(e->button()) {
287 case Qt::LeftButton :
288 fCanvas->HandleInput(kButton1Down, scaled.x(), scaled.y());
291 case Qt::RightButton : {
292 TString selectedOpt(
"");
299 selected = pickobj->GetObject();
300 selectedOpt = pickobj->GetOption();
305 gROOT->SetSelectedPrimitive(selected);
306 fMousePosX = gPad->AbsPixeltoX(gPad->GetEventX());
307 fMousePosY = gPad->AbsPixeltoY(gPad->GetEventY());
311 connect(&map, SIGNAL(mapped(
int)),
this, SLOT(
executeMenu(
int)));
318 QString buffer = Form(
"%s::%s", cl->GetName(),
fMenuObj->GetName());
324 if(!cl->InheritsFrom(TLatex::Class())) {
329 if(cl->InheritsFrom(TH1::Class())) {
337 while ( (method = dynamic_cast<TMethod*>(iter())) != 0) {
338 buffer = method->GetName();
342 if (menu.exec(mouse_pnt)==0) {
350 case Qt::MiddleButton :
351 fCanvas->HandleInput(kButton2Down, scaled.x(), scaled.y());
370 switch(e->button()) {
371 case Qt::LeftButton :
372 fCanvas->HandleInput(kButton1Up, scaled.x(), scaled.y());
374 case Qt::RightButton :
375 fCanvas->HandleInput(kButton3Up, scaled.x(), scaled.y());
377 case Qt::MiddleButton :
378 fCanvas->HandleInput(kButton2Up, scaled.x(), scaled.y());
393 switch(e->button()) {
394 case Qt::LeftButton : {
396 fCanvas->HandleInput(kButton1Double, scaled.x(), scaled.y());
397 TObjLink* pickobj = 0;
398 TPad* pad =
fCanvas->Pick(scaled.x(), scaled.y(), pickobj);
405 case Qt::RightButton :
406 fCanvas->HandleInput(kButton3Double, scaled.x(), scaled.y());
408 case Qt::MiddleButton :
409 fCanvas->HandleInput(kButton2Double, scaled.x(), scaled.y());
459 fRootWindowId = gVirtualX->AddWindow((ULong_t)newid, width(), height());
477 QWidget::leaveEvent(e);
481 fCanvas->HandleInput(kMouseLeave, 0, 0);
500 if (e->mimeData()->hasText())
501 e->acceptProposedAction();
508 #if QT_VERSION < QT_VERSION_CHECK(6,0,0)
509 QPoint pos =
event->pos();
511 QPoint pos =
event->position().toPoint();
549 return fCanvas->DrawClone(option);
554 return fCanvas->DrawClonePad();
564 fCanvas->EnterLeave(prevSelPad, prevSelObj);
594 return fCanvas->GetContextMenu();
599 return fCanvas->GetDoubleBuffer();
619 return fCanvas->GetHighLightColor() ;
629 return fCanvas->GetSelected() ;
634 return fCanvas->GetSelectedOpt();
639 return fCanvas->GetSelectedPad();
644 return fCanvas->GetShowEventStatus() ;
654 return fCanvas->GetXsizeUser();
659 return fCanvas->GetYsizeUser();
664 return fCanvas->GetXsizeReal();
669 return fCanvas->GetYsizeReal();
679 return fCanvas->GetWindowTopX();
684 return fCanvas->GetWindowTopY();
689 return fCanvas->GetWindowWidth() ;
694 return fCanvas->GetWindowHeight();
709 fCanvas->GetCanvasPar(wtopx, wtopy, ww, wh);
754 return fCanvas->OpaqueMoving();
759 return fCanvas->OpaqueResizing();
769 return fCanvas->Pick(px, py, pickobj);
774 return fCanvas->Pick(px, py, prevSelObj);
789 fCanvas->SaveSource(filename, option);
799 fCanvas->SetDoubleBuffer(mode);
804 fCanvas->SetWindowPosition(x, y) ;
809 fCanvas->SetWindowSize(ww,wh) ;
814 fCanvas->SetCanvasSize(ww, wh);
819 fCanvas->SetHighLightColor(col);
839 fCanvas->Size(xsizeuser, ysizeuser);
849 fCanvas->SetRetained(retained);
885 if ((
object==0) || (method==0))
return;
893 dlg.setWindowTitle(Form(
"%s:%s", object->GetName(), method->GetName()));
897 TMethodArg *argument = 0;
898 TIter next(method->GetListOfMethodArgs());
900 while ((argument = (TMethodArg *) next())) {
901 TString argTitle = TString::Format(
"(%s) %s", argument->GetTitle(), argument->GetName());
902 TString argDflt = argument->GetDefault() ? argument->GetDefault() :
"";
903 if (argDflt.Length()>0)
904 argTitle += TString::Format(
" [default: %s]", argDflt.Data());
905 TString type = argument->GetTypeName();
906 TDataType *datatype = gROOT->GetType(type);
910 basictype = datatype->GetTypeName();
912 if (type.CompareTo(
"enum") != 0)
913 std::cout <<
"*** Warning in Dialog(): data type is not basic type, assuming (int)\n";
917 if (TString(argument->GetTitle()).Index(
"*")!=kNPOS) {
922 TDataMember *m = argument->GetDataMember();
923 if (m && m->GetterMethod()) {
925 m->GetterMethod()->Init(object->IsA(), m->GetterMethod()->GetMethodName(),
"");
931 if (basictype ==
"char*") {
933 m->GetterMethod()->Execute(
object,
"", &tdefval);
934 if (tdefval) val = tdefval;
936 if ((basictype ==
"float") ||
937 (basictype ==
"double")) {
938 Double_t ddefval(0.);
939 m->GetterMethod()->Execute(
object,
"", ddefval);
940 val = TString::Format(
"%g", ddefval);
942 if ((basictype ==
"char") ||
943 (basictype ==
"int") ||
944 (basictype ==
"long") ||
945 (basictype ==
"short")) {
947 m->GetterMethod()->Execute(
object,
"", ldefval);
948 val = TString::Format(
"%ld", ldefval);
954 if ((opt = m->GetOptions()) != 0) {
958 dlg.
addArg(argTitle.Data(), val.Data(), type.Data());
962 dlg.
addArg(argTitle.Data(), val.Data(), type.Data());
965 if ((argDflt.Length() > 1) &&
966 (argDflt[0]==
'\"') && (argDflt[argDflt.Length()-1]==
'\"')) {
969 argDflt.Remove(argDflt.Length()-1,1);
972 dlg.
addArg(argTitle.Data(), argDflt.Data(), type.Data());
976 if (dlg.exec() != QDialog::Accepted)
return;
978 Bool_t deletion = kFALSE;
980 qDebug(
"DIAL executeMethod: simple version\n");
981 TVirtualPad *psave = gROOT->GetSelectedPad();
983 qDebug(
"DIAL saved pad: %s gPad:%s \n",psave->GetName(),gPad->GetName());
985 qDebug(
"DIAL obj:%s meth:%s \n", object->GetName(), method->GetName());
989 TObjArray tobjlist(method->GetListOfMethodArgs()->LastIndex() + 1);
990 for (
int n=0; n<=method->GetListOfMethodArgs()->LastIndex(); n++) {
991 QString s = dlg.
getArg(n);
992 qDebug(
"** QString values (first ) :%s \n", s.toLatin1().constData() );
993 tobjlist.AddLast(
new TObjString(s.toLatin1().constData())) ;
997 if(strcmp(method->GetName(),
"Delete") == 0) {
999 qDebug(
" DIAL obj name deleted :%s \n", object->GetName());
1004 qDebug(
" DIAL deletion done closing ... \n");
1006 if (strcmp(method->GetName(),
"SetCanvasSize") == 0) {
1007 int width = dlg.
getArg(0).toInt();
1008 int height = dlg.
getArg(1).toInt();
1009 qDebug(
" do resize with %i %i \n", width, height);
1010 resize(width, height);
1014 qDebug(
"TCint::Execute called !\n");
1016 object->Execute(method, &tobjlist);
1018 if (object->TestBit(TObject::kNotDeleted))
1027 qDebug(
"DIAL set saved pad: %s herit:%s gPad:%s\n",
1028 psave->GetName(), psave->ClassName(), gPad->GetName());
1029 gROOT->SetSelectedPad(psave);
1030 gROOT->GetSelectedPad()->Modified();
1031 gROOT->GetSelectedPad()->Update();
1032 qDebug(
"DIAL update done on %s \n", gROOT->GetSelectedPad()->GetName());
1034 gROOT->SetSelectedPad( gPad );
1035 gROOT->GetSelectedPad()->Update();
1043 QAction* act =
new QAction(text, menu);
1046 if ((text.compare(
"DrawClone")==0) ||
1047 (text.compare(
"DrawClass")==0) ||
1048 (text.compare(
"Inspect")==0) ||
1049 (text.compare(
"SetShowProjectionX")==0) ||
1050 (text.compare(
"SetShowProjectionY")==0) ||
1051 (text.compare(
"DrawPanel")==0) ||
1052 (text.compare(
"FitPanel")==0))
1053 act->setEnabled(
false);
1055 map->connect (act, SIGNAL(triggered()), map, SLOT(map()));
1056 menu->addAction(act);
1057 map->setMapping(act,
id);
1071 TLatex *fxLatex =
new TLatex();
1072 text = QInputDialog::getText(
this, tr(
"Qt Root" ),
1073 tr(
"Please enter your text" ),
1074 QLineEdit::Normal, QString(), &ok);
1081 TH1 *h1 =
dynamic_cast<TH1*
> (
fMenuObj);
1083 QColor col = QColorDialog::getColor();
1084 if (col.isValid()) {
1085 short int C_new = TColor::GetColor(col.red(), col.green(), col.blue());
1086 h1->SetLineColor(C_new);
1093 TH1 *h1 =
dynamic_cast<TH1*
> (
fMenuObj);
1095 QColor col = QColorDialog::getColor();
1096 if (col.isValid()) {
1097 short int C_new = TColor::GetColor(col.red(), col.green(), col.blue());
1098 h1->SetFillColor(C_new);
1104 gROOT->GetSelectedPad()->Update();
1105 gROOT->GetSelectedPad()->Modified();
1108 gROOT->SetFromPopUp( kFALSE );
1114 TVirtualPad* psave = gROOT->GetSelectedPad();
1124 if (method->GetListOfMethodArgs()->First()){
1125 if (strstr(method->GetName(),
"Delete")){
1135 gROOT->SetFromPopUp(kTRUE);
1136 fMenuObj->Execute(method->GetName(),
"");
1138 if (
fMenuObj->TestBit(TObject::kNotDeleted)) {
1146 #ifndef __NOGO4GED__
1147 TGedEditor* ed =
dynamic_cast<TGedEditor*
>(TVirtualPadEditor::GetPadEditor(kFALSE));
1151 fCanvas->GetPadSave()->Update();
1152 fCanvas->GetPadSave()->Modified();
1154 gROOT->SetSelectedPad(psave);
1156 gROOT->GetSelectedPad()->Update();
1157 gROOT->GetSelectedPad()->Modified();
1161 gROOT->SetFromPopUp(kFALSE);
1188 #ifndef __NOGO4GED__
1193 #if QT_VERSION > QT_VERSION_CHECK(5,6,0)
1195 double scalefactor=(double) metric(QPaintDevice::PdmDevicePixelRatioScaled)/65536.;
1210 fxPeditor = TVirtualPadEditor::LoadEditor();
1219 #ifndef __NOGO4GED__
1220 TGedEditor* ed =
dynamic_cast<TGedEditor*
>(
fxPeditor);
1229 #ifndef __NOGO4GED__
1230 TGedEditor* ed =
dynamic_cast<TGedEditor*
>(
fxPeditor);
1233 ed->SetModel(pad, obj, kButton1Down);
1240 #ifndef __NOGO4GED__
1242 TGedEditor* ed =
dynamic_cast<TGedEditor*
>(
fxPeditor);
1245 fDummyHisto =
new TH1I(
"dummyhisto",
"dummyhisto", 100, -10., 10.);
1252 ed->SetModel(0,
getCanvas(), kButton1Down);
1281 QVBoxLayout* gedlayout =
new QVBoxLayout(
fEditorFrame);
1282 gedlayout->setContentsMargins(0, 0, 0, 0);
void SetBatch(Bool_t batch=kTRUE)
double scaledPosition(int p)
QRootWindow * fxRooteditor
void showStatusMessage(const char *msg)
Option_t * GetSelectedOpt()
virtual void mouseDoubleClickEvent(QMouseEvent *e)
bool isStatusBarVisible()
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)
void MenuCommandExecuted(TObject *, const char *)
virtual void HandleInput(EEventType button, Int_t x, Int_t y)
void SelectedPadChanged(TPad *)
virtual void ToggleEventStatus()
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="")
virtual void Browse(TBrowser *b)
void SetEditable(bool on=true)
virtual TObject * DrawClone(Option_t *option="")
QRootCanvas(QWidget *parent=0)
virtual void SetDoubleBuffer(Int_t mode=1)
void SaveSource(const char *filename="", Option_t *option="")
void methodDialog(TObject *object, TMethod *method)
QAction * addMenuAction(QMenu *menu, QSignalMapper *map, const QString &text, int id)
virtual void SetCursor(ECursor cursor)
Color_t GetHighLightColor()
void ResizeOpaque(Int_t set=1)
void cd(Int_t subpadnumber=0)
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)
void SetResizeOnPaint(bool on=true)
void Clear(Option_t *option="")
virtual void leaveEvent(QEvent *e)
virtual TObject * DrawClonePad()
virtual void resizeEvent(QResizeEvent *e)
void Close(Option_t *option="")
void CanvasDropEvent(QDropEvent *, TPad *)
static bool IsRootCanvasMenuEnabled()
void addArg(const char *argname, const char *value, const char *type)
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
QPoint scaledMousePoint(QMouseEvent *ev)
void processRepaintTimer()
virtual void closeEvent(QCloseEvent *e)
virtual void mouseMoveEvent(QMouseEvent *e)
void MoveOpaque(Int_t set=1)
virtual void ls(Option_t *option="")
void CanvasStatusEvent(const char *)
void SetWindowPosition(Int_t x, Int_t y)
void SetSelectedPad(TPad *pad)
TVirtualPadEditor * fxPeditor
void activateEditor(TPad *pad, TObject *obj)
void setStatusBarVisible(bool flag)
virtual void wheelEvent(QWheelEvent *e)
void PadDoubleClicked(TPad *)
Bool_t GetShowEventStatus()