20 #include <QtCore/QEvent>
21 #include <QtCore/QSignalMapper>
22 #include <QtCore/QTimer>
25 #include <QDragEnterEvent>
27 #include <QResizeEvent>
28 #include <QMouseEvent>
29 #include <QPaintEvent>
30 #include <QCloseEvent>
31 #include <QInputDialog>
32 #include <QColorDialog>
44 #include "TDataType.h"
45 #include "TDataMember.h"
47 #include "TMethodCall.h"
48 #include "TMethodArg.h"
51 #include "Riostream.h"
54 #include "TGedEditor.h"
59 #include "TGo4LockGuard.h"
70 fMaskDoubleClick(false),
71 fxShowEventStatus(false),
74 setObjectName(
"QRootCanvas");
76 setSizeIncrement( QSize( 100, 100 ) );
80 setUpdatesEnabled(
true );
81 setMouseTracking(
true);
83 setFocusPolicy( Qt::TabFocus );
84 setCursor( Qt::CrossCursor );
89 setAttribute(Qt::WA_PaintOnScreen);
90 setAttribute(Qt::WA_PaintUnclipped);
98 #if QT_VERSION > QT_VERSION_CHECK(5,6,0)
100 fQtScalingfactor=(double) metric(QPaintDevice::PdmDevicePixelRatioScaled)/65536.;
109 setAcceptDrops(
true);
135 #if QT_VERSION > QT_VERSION_CHECK(5,0,0)
137 static ulong lastprocesstime=0;
138 static ulong delta=100;
139 ulong timestamp=e->timestamp();
140 if(timestamp-delta<lastprocesstime)
153 if (e->buttons() & Qt::LeftButton)
160 TObject* selected =
fCanvas->GetSelected();
161 Int_t px =
fCanvas->GetEventX();
162 Int_t py =
fCanvas->GetEventY();
165 buffer = selected->GetName();
167 buffer += selected->GetObjectInfo(px,py);
169 buffer =
"No selected object x = ";
170 buffer += QString::number(px);
172 buffer += QString::number(py);
177 #if QT_VERSION > QT_VERSION_CHECK(5,0,0)
178 lastprocesstime=timestamp;
201 TObjLink* pickobj = 0;
231 TPad* pad =
fCanvas->Pick(scaledX, scaledY, pickobj);
232 TObject *selected =
fCanvas->GetSelected();
234 switch(e->button()) {
235 case Qt::LeftButton :
236 fCanvas->HandleInput(kButton1Down, scaledX, scaledY);
239 case Qt::RightButton : {
240 TString selectedOpt(
"");
247 selected = pickobj->GetObject();
248 selectedOpt = pickobj->GetOption();
253 gROOT->SetSelectedPrimitive(selected);
254 fMousePosX = gPad->AbsPixeltoX(gPad->GetEventX());
255 fMousePosY = gPad->AbsPixeltoY(gPad->GetEventY());
259 connect(&map, SIGNAL(mapped(
int)),
this, SLOT(
executeMenu(
int)));
266 QString buffer = Form(
"%s::%s", cl->GetName(),
fMenuObj->GetName());
272 if(!cl->InheritsFrom(TLatex::Class())) {
277 if(cl->InheritsFrom(TH1::Class())) {
285 while ( (method = dynamic_cast<TMethod*>(iter())) != 0) {
286 buffer = method->GetName();
290 if (menu.exec(e->globalPos())==0) {
299 fCanvas->HandleInput(kButton2Down, scaledX, scaledY);
316 switch(e->button()) {
317 case Qt::LeftButton :
320 case Qt::RightButton :
337 switch(e->button()) {
338 case Qt::LeftButton : {
341 TObjLink* pickobj = 0;
349 case Qt::RightButton :
403 fRootWindowId = gVirtualX->AddWindow((ULong_t)newid, width(), height());
421 QWidget::leaveEvent(e);
425 fCanvas->HandleInput(kMouseLeave, 0, 0);
444 if (e->mimeData()->hasText())
445 e->acceptProposedAction();
451 QPoint pos =
event->pos();
487 return fCanvas->DrawClone(option);
492 return fCanvas->DrawClonePad();
502 fCanvas->EnterLeave(prevSelPad, prevSelObj);
532 return fCanvas->GetContextMenu();
537 return fCanvas->GetDoubleBuffer();
557 return fCanvas->GetHighLightColor() ;
567 return fCanvas->GetSelected() ;
572 return fCanvas->GetSelectedOpt();
577 return fCanvas->GetSelectedPad();
582 return fCanvas->GetShowEventStatus() ;
592 return fCanvas->GetXsizeUser();
597 return fCanvas->GetYsizeUser();
602 return fCanvas->GetXsizeReal();
607 return fCanvas->GetYsizeReal();
617 return fCanvas->GetWindowTopX();
622 return fCanvas->GetWindowTopY();
627 return fCanvas->GetWindowWidth() ;
632 return fCanvas->GetWindowHeight();
647 fCanvas->GetCanvasPar(wtopx, wtopy, ww, wh);
692 return fCanvas->OpaqueMoving();
697 return fCanvas->OpaqueResizing();
707 return fCanvas->Pick(px, py, pickobj);
712 return fCanvas->Pick(px, py, prevSelObj);
727 fCanvas->SaveSource(filename, option);
737 fCanvas->SetDoubleBuffer(mode);
742 fCanvas->SetWindowPosition(x, y) ;
747 fCanvas->SetWindowSize(ww,wh) ;
752 fCanvas->SetCanvasSize(ww, wh);
757 fCanvas->SetHighLightColor(col);
777 fCanvas->Size(xsizeuser, ysizeuser);
787 fCanvas->SetRetained(retained);
823 if ((
object==0) || (method==0))
return;
831 dlg.setWindowTitle(Form(
"%s:%s", object->GetName(), method->GetName()));
835 TMethodArg *argument = 0;
836 TIter next(method->GetListOfMethodArgs());
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);
848 basictype = datatype->GetTypeName();
850 if (type.CompareTo(
"enum") != 0)
851 std::cout <<
"*** Warning in Dialog(): data type is not basic type, assuming (int)\n";
855 if (TString(argument->GetTitle()).Index(
"*")!=kNPOS) {
860 TDataMember *m = argument->GetDataMember();
861 if (m && m->GetterMethod()) {
863 m->GetterMethod()->Init(object->IsA(), m->GetterMethod()->GetMethodName(),
"");
869 if (basictype ==
"char*") {
871 m->GetterMethod()->Execute(
object,
"", &tdefval);
872 if (tdefval) val = tdefval;
874 if ((basictype ==
"float") ||
875 (basictype ==
"double")) {
876 Double_t ddefval(0.);
877 m->GetterMethod()->Execute(
object,
"", ddefval);
878 val = TString::Format(
"%g", ddefval);
880 if ((basictype ==
"char") ||
881 (basictype ==
"int") ||
882 (basictype ==
"long") ||
883 (basictype ==
"short")) {
885 m->GetterMethod()->Execute(
object,
"", ldefval);
886 val = TString::Format(
"%ld", ldefval);
892 if ((opt = m->GetOptions()) != 0) {
896 dlg.
addArg(argTitle.Data(), val.Data(), type.Data());
900 dlg.
addArg(argTitle.Data(), val.Data(), type.Data());
903 if ((argDflt.Length() > 1) &&
904 (argDflt[0]==
'\"') && (argDflt[argDflt.Length()-1]==
'\"')) {
907 argDflt.Remove(argDflt.Length()-1,1);
910 dlg.
addArg(argTitle.Data(), argDflt.Data(), type.Data());
914 if (dlg.exec() != QDialog::Accepted)
return;
916 Bool_t deletion = kFALSE;
918 qDebug(
"DIAL executeMethod: simple version\n");
919 TVirtualPad *psave = gROOT->GetSelectedPad();
921 qDebug(
"DIAL saved pad: %s gPad:%s \n",psave->GetName(),gPad->GetName());
923 qDebug(
"DIAL obj:%s meth:%s \n", object->GetName(), method->GetName());
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())) ;
935 if(strcmp(method->GetName(),
"Delete") == 0) {
937 qDebug(
" DIAL obj name deleted :%s \n", object->GetName());
942 qDebug(
" DIAL deletion done closing ... \n");
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);
952 qDebug(
"TCint::Execute called !\n");
954 object->Execute(method, &tobjlist);
956 if (object->TestBit(TObject::kNotDeleted))
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());
972 gROOT->SetSelectedPad( gPad );
973 gROOT->GetSelectedPad()->Update();
981 QAction* act =
new QAction(text, menu);
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);
993 map->connect (act, SIGNAL(triggered()), map, SLOT(map()));
994 menu->addAction(act);
995 map->setMapping(act,
id);
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);
1019 TH1 *h1 =
dynamic_cast<TH1*
> (
fMenuObj);
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);
1031 TH1 *h1 =
dynamic_cast<TH1*
> (
fMenuObj);
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);
1042 gROOT->GetSelectedPad()->Update();
1043 gROOT->GetSelectedPad()->Modified();
1046 gROOT->SetFromPopUp( kFALSE );
1052 TVirtualPad* psave = gROOT->GetSelectedPad();
1062 if (method->GetListOfMethodArgs()->First()){
1063 if (strstr(method->GetName(),
"Delete")){
1073 gROOT->SetFromPopUp(kTRUE);
1074 fMenuObj->Execute(method->GetName(),
"");
1076 if (
fMenuObj->TestBit(TObject::kNotDeleted)) {
1084 #ifndef __NOGO4GED__
1085 TGedEditor* ed =
dynamic_cast<TGedEditor*
>(TVirtualPadEditor::GetPadEditor(kFALSE));
1089 fCanvas->GetPadSave()->Update();
1090 fCanvas->GetPadSave()->Modified();
1092 gROOT->SetSelectedPad(psave);
1094 gROOT->GetSelectedPad()->Update();
1095 gROOT->GetSelectedPad()->Modified();
1099 gROOT->SetFromPopUp(kFALSE);
void SetBatch(Bool_t batch=kTRUE)
double scaledPosition(int p)
Option_t * GetSelectedOpt()
virtual void mouseDoubleClickEvent(QMouseEvent *e)
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)
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 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
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)
virtual void wheelEvent(QWheelEvent *e)
void PadDoubleClicked(TPad *)
Bool_t GetShowEventStatus()