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 ) );
79 setUpdatesEnabled(
true );
80 setMouseTracking(
true);
82 setFocusPolicy( Qt::TabFocus );
83 setCursor( Qt::CrossCursor );
88 setAttribute(Qt::WA_PaintOnScreen);
89 setAttribute(Qt::WA_PaintUnclipped);
97 #if QT_VERSION > QT_VERSION_CHECK(5,6,0)
99 fQtScalingfactor=(double) metric(QPaintDevice::PdmDevicePixelRatioScaled)/65536.;
108 setAcceptDrops(
true);
160 #if QT_VERSION < QT_VERSION_CHECK(6,0,0)
167 return QPoint(scaledX, scaledY);
174 #if QT_VERSION > QT_VERSION_CHECK(5,0,0)
176 static ulong lastprocesstime=0;
177 static ulong delta=100;
178 ulong timestamp=e->timestamp();
179 if(timestamp-delta<lastprocesstime)
194 if (e->buttons() & Qt::LeftButton)
195 fCanvas->HandleInput(kButton1Motion, pnt.x(), pnt.y());
197 fCanvas->HandleInput(kMouseMotion, pnt.x(), pnt.y());
201 TObject* selected =
fCanvas->GetSelected();
202 Int_t px =
fCanvas->GetEventX();
203 Int_t py =
fCanvas->GetEventY();
206 buffer = selected->GetName();
208 buffer += selected->GetObjectInfo(px, py);
210 buffer =
"No selected object x = ";
211 buffer += QString::number(px);
213 buffer += QString::number(py);
221 #if QT_VERSION > QT_VERSION_CHECK(5,0,0)
222 lastprocesstime=timestamp;
234 #if QT_VERSION < QT_VERSION_CHECK(5,15,0)
235 bool positive = (e->delta() > 0);
236 int ex = e->x(), ey = e->y();
238 QPoint delta = e->pixelDelta();
239 if (delta.isNull()) delta = e->angleDelta() / 8;
240 bool positive = delta.x() > 0 || delta.y() > 0;
241 int ex = e->position().x(), ey = e->position().y();
253 TObjLink* pickobj = 0;
258 #if QT_VERSION < QT_VERSION_CHECK(6,0,0)
259 QPoint mouse_pnt = e->globalPos();
261 QPoint mouse_pnt = e->globalPosition().toPoint();
289 TPad* pad =
fCanvas->Pick(scaled.x(), scaled.y(), pickobj);
290 TObject *selected =
fCanvas->GetSelected();
292 switch(e->button()) {
293 case Qt::LeftButton :
294 fCanvas->HandleInput(kButton1Down, scaled.x(), scaled.y());
297 case Qt::RightButton : {
298 TString selectedOpt(
"");
305 selected = pickobj->GetObject();
306 selectedOpt = pickobj->GetOption();
311 gROOT->SetSelectedPrimitive(selected);
312 fMousePosX = gPad->AbsPixeltoX(gPad->GetEventX());
313 fMousePosY = gPad->AbsPixeltoY(gPad->GetEventY());
317 connect(&map, SIGNAL(mapped(
int)),
this, SLOT(
executeMenu(
int)));
324 QString buffer = Form(
"%s::%s", cl->GetName(),
fMenuObj->GetName());
330 if(!cl->InheritsFrom(TLatex::Class())) {
335 if(cl->InheritsFrom(TH1::Class())) {
343 while ( (method = dynamic_cast<TMethod*>(iter())) != 0) {
344 buffer = method->GetName();
348 if (menu.exec(mouse_pnt)==0) {
356 case Qt::MiddleButton :
357 fCanvas->HandleInput(kButton2Down, scaled.x(), scaled.y());
377 switch(e->button()) {
378 case Qt::LeftButton :
379 fCanvas->HandleInput(kButton1Up, scaled.x(), scaled.y());
381 case Qt::RightButton :
382 fCanvas->HandleInput(kButton3Up, scaled.x(), scaled.y());
384 case Qt::MiddleButton :
385 fCanvas->HandleInput(kButton2Up, scaled.x(), scaled.y());
402 switch(e->button()) {
403 case Qt::LeftButton : {
405 fCanvas->HandleInput(kButton1Double, scaled.x(), scaled.y());
406 TObjLink* pickobj = 0;
407 TPad* pad =
fCanvas->Pick(scaled.x(), scaled.y(), pickobj);
414 case Qt::RightButton :
415 fCanvas->HandleInput(kButton3Double, scaled.x(), scaled.y());
417 case Qt::MiddleButton :
418 fCanvas->HandleInput(kButton2Double, scaled.x(), scaled.y());
469 fRootWindowId = gVirtualX->AddWindow((ULong_t)newid, width(), height());
487 QWidget::leaveEvent(e);
493 fCanvas->HandleInput(kMouseLeave, 0, 0);
512 if (e->mimeData()->hasText())
513 e->acceptProposedAction();
520 #if QT_VERSION < QT_VERSION_CHECK(6,0,0)
521 QPoint pos =
event->pos();
523 QPoint pos =
event->position().toPoint();
561 return fCanvas->DrawClone(option);
566 return fCanvas->DrawClonePad();
576 fCanvas->EnterLeave(prevSelPad, prevSelObj);
606 return fCanvas->GetContextMenu();
611 return fCanvas->GetDoubleBuffer();
631 return fCanvas->GetHighLightColor() ;
641 return fCanvas->GetSelected() ;
646 return fCanvas->GetSelectedOpt();
651 return fCanvas->GetSelectedPad();
656 return fCanvas->GetShowEventStatus() ;
666 return fCanvas->GetXsizeUser();
671 return fCanvas->GetYsizeUser();
676 return fCanvas->GetXsizeReal();
681 return fCanvas->GetYsizeReal();
691 return fCanvas->GetWindowTopX();
696 return fCanvas->GetWindowTopY();
701 return fCanvas->GetWindowWidth() ;
706 return fCanvas->GetWindowHeight();
721 fCanvas->GetCanvasPar(wtopx, wtopy, ww, wh);
766 return fCanvas->OpaqueMoving();
771 return fCanvas->OpaqueResizing();
781 return fCanvas->Pick(px, py, pickobj);
786 return fCanvas->Pick(px, py, prevSelObj);
801 fCanvas->SaveSource(filename, option);
811 fCanvas->SetDoubleBuffer(mode);
816 fCanvas->SetWindowPosition(x, y) ;
821 fCanvas->SetWindowSize(ww,wh) ;
826 fCanvas->SetCanvasSize(ww, wh);
831 fCanvas->SetHighLightColor(col);
851 fCanvas->Size(xsizeuser, ysizeuser);
861 fCanvas->SetRetained(retained);
897 if ((
object==0) || (method==0))
return;
907 dlg.setWindowTitle(Form(
"%s:%s", object->GetName(), method->GetName()));
911 TMethodArg *argument = 0;
912 TIter next(method->GetListOfMethodArgs());
914 while ((argument = (TMethodArg *) next())) {
915 TString argTitle = TString::Format(
"(%s) %s", argument->GetTitle(), argument->GetName());
916 TString argDflt = argument->GetDefault() ? argument->GetDefault() :
"";
917 if (argDflt.Length()>0)
918 argTitle += TString::Format(
" [default: %s]", argDflt.Data());
919 TString type = argument->GetTypeName();
920 TDataType *datatype = gROOT->GetType(type);
924 basictype = datatype->GetTypeName();
926 if (type.CompareTo(
"enum") != 0)
927 std::cout <<
"*** Warning in Dialog(): data type is not basic type, assuming (int)\n";
931 if (TString(argument->GetTitle()).Index(
"*")!=kNPOS) {
936 TDataMember *m = argument->GetDataMember();
937 if (m && m->GetterMethod()) {
939 m->GetterMethod()->Init(object->IsA(), m->GetterMethod()->GetMethodName(),
"");
945 if (basictype ==
"char*") {
947 m->GetterMethod()->Execute(
object,
"", &tdefval);
948 if (tdefval) val = tdefval;
950 if ((basictype ==
"float") ||
951 (basictype ==
"double")) {
952 Double_t ddefval(0.);
953 m->GetterMethod()->Execute(
object,
"", ddefval);
954 val = TString::Format(
"%g", ddefval);
956 if ((basictype ==
"char") ||
957 (basictype ==
"int") ||
958 (basictype ==
"long") ||
959 (basictype ==
"short")) {
961 m->GetterMethod()->Execute(
object,
"", ldefval);
962 val = TString::Format(
"%ld", ldefval);
968 if ((opt = m->GetOptions()) != 0) {
972 dlg.
addArg(argTitle.Data(), val.Data(), type.Data());
976 dlg.
addArg(argTitle.Data(), val.Data(), type.Data());
979 if ((argDflt.Length() > 1) &&
980 (argDflt[0]==
'\"') && (argDflt[argDflt.Length()-1]==
'\"')) {
983 argDflt.Remove(argDflt.Length()-1,1);
986 dlg.
addArg(argTitle.Data(), argDflt.Data(), type.Data());
990 if (dlg.exec() != QDialog::Accepted)
return;
992 Bool_t deletion = kFALSE;
994 qDebug(
"DIAL executeMethod: simple version\n");
995 TVirtualPad *psave = gROOT->GetSelectedPad();
997 qDebug(
"DIAL saved pad: %s gPad:%s \n",psave->GetName(),gPad->GetName());
999 qDebug(
"DIAL obj:%s meth:%s \n", object->GetName(), method->GetName());
1003 TObjArray tobjlist(method->GetListOfMethodArgs()->LastIndex() + 1);
1004 for (
int n=0; n<=method->GetListOfMethodArgs()->LastIndex(); n++) {
1005 QString s = dlg.
getArg(n);
1006 qDebug(
"** QString values (first ) :%s \n", s.toLatin1().constData() );
1007 tobjlist.AddLast(
new TObjString(s.toLatin1().constData())) ;
1011 if(strcmp(method->GetName(),
"Delete") == 0) {
1013 qDebug(
" DIAL obj name deleted :%s \n", object->GetName());
1018 qDebug(
" DIAL deletion done closing ... \n");
1020 if (strcmp(method->GetName(),
"SetCanvasSize") == 0) {
1021 int width = dlg.
getArg(0).toInt();
1022 int height = dlg.
getArg(1).toInt();
1023 qDebug(
" do resize with %i %i \n", width, height);
1024 resize(width, height);
1028 qDebug(
"TCint::Execute called !\n");
1030 object->Execute(method, &tobjlist);
1032 if (object->TestBit(TObject::kNotDeleted))
1041 qDebug(
"DIAL set saved pad: %s herit:%s gPad:%s\n",
1042 psave->GetName(), psave->ClassName(), gPad->GetName());
1043 gROOT->SetSelectedPad(psave);
1044 gROOT->GetSelectedPad()->Modified();
1045 gROOT->GetSelectedPad()->Update();
1046 qDebug(
"DIAL update done on %s \n", gROOT->GetSelectedPad()->GetName());
1048 gROOT->SetSelectedPad( gPad );
1049 gROOT->GetSelectedPad()->Update();
1057 QAction* act =
new QAction(text, menu);
1060 if ((text.compare(
"DrawClone")==0) ||
1061 (text.compare(
"DrawClass")==0) ||
1062 (text.compare(
"Inspect")==0) ||
1063 (text.compare(
"SetShowProjectionX")==0) ||
1064 (text.compare(
"SetShowProjectionY")==0) ||
1065 (text.compare(
"DrawPanel")==0) ||
1066 (text.compare(
"FitPanel")==0))
1067 act->setEnabled(
false);
1069 map->connect (act, SIGNAL(triggered()), map, SLOT(map()));
1070 menu->addAction(act);
1071 map->setMapping(act,
id);
1087 TLatex *fxLatex =
new TLatex();
1088 text = QInputDialog::getText(
this, tr(
"Qt Root" ),
1089 tr(
"Please enter your text" ),
1090 QLineEdit::Normal, QString(), &ok);
1097 TH1 *h1 =
dynamic_cast<TH1*
> (
fMenuObj);
1099 QColor col = QColorDialog::getColor();
1100 if (col.isValid()) {
1101 short int C_new = TColor::GetColor(col.red(), col.green(), col.blue());
1102 h1->SetLineColor(C_new);
1109 TH1 *h1 =
dynamic_cast<TH1*
> (
fMenuObj);
1111 QColor col = QColorDialog::getColor();
1112 if (col.isValid()) {
1113 short int C_new = TColor::GetColor(col.red(), col.green(), col.blue());
1114 h1->SetFillColor(C_new);
1120 gROOT->GetSelectedPad()->Update();
1121 gROOT->GetSelectedPad()->Modified();
1124 gROOT->SetFromPopUp( kFALSE );
1130 TVirtualPad* psave = gROOT->GetSelectedPad();
1140 if (method->GetListOfMethodArgs()->First()){
1141 if (strstr(method->GetName(),
"Delete")){
1151 gROOT->SetFromPopUp(kTRUE);
1152 fMenuObj->Execute(method->GetName(),
"");
1154 if (
fMenuObj->TestBit(TObject::kNotDeleted)) {
1162 #ifndef __NOGO4GED__
1163 TGedEditor* ed =
dynamic_cast<TGedEditor*
>(TVirtualPadEditor::GetPadEditor(kFALSE));
1167 fCanvas->GetPadSave()->Update();
1168 fCanvas->GetPadSave()->Modified();
1170 gROOT->SetSelectedPad(psave);
1172 gROOT->GetSelectedPad()->Update();
1173 gROOT->GetSelectedPad()->Modified();
1177 gROOT->SetFromPopUp(kFALSE);
1204 #ifndef __NOGO4GED__
1209 #if QT_VERSION > QT_VERSION_CHECK(5,6,0)
1211 double scalefactor=(double) metric(QPaintDevice::PdmDevicePixelRatioScaled)/65536.;
1228 fxPeditor = TVirtualPadEditor::LoadEditor();
1237 #ifndef __NOGO4GED__
1238 TGedEditor* ed =
dynamic_cast<TGedEditor*
>(
fxPeditor);
1247 #ifndef __NOGO4GED__
1248 TGedEditor* ed =
dynamic_cast<TGedEditor*
>(
fxPeditor);
1251 ed->SetModel(pad, obj, kButton1Down);
1258 #ifndef __NOGO4GED__
1260 TGedEditor* ed =
dynamic_cast<TGedEditor*
>(
fxPeditor);
1263 fDummyHisto =
new TH1I(
"dummyhisto",
"dummyhisto", 100, -10., 10.);
1270 ed->SetModel(0,
getCanvas(), kButton1Down);
1299 QVBoxLayout* gedlayout =
new QVBoxLayout(
fEditorFrame);
1300 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()