00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "QRootCanvas.h"
00019
00020 #include <QtCore/QEvent>
00021 #include <QtCore/QSignalMapper>
00022 #include <QtCore/QTimer>
00023
00024 #include <QPainter>
00025 #include <QDragEnterEvent>
00026 #include <QDropEvent>
00027 #include <QResizeEvent>
00028 #include <QMouseEvent>
00029 #include <QPaintEvent>
00030 #include <QCloseEvent>
00031 #include <QInputDialog>
00032 #include <QColorDialog>
00033 #include <QMenu>
00034 #include <QAction>
00035 #include <QMimeData>
00036
00037 #include "TPad.h"
00038 #include "TCanvas.h"
00039 #include "TROOT.h"
00040 #include "TString.h"
00041 #include "TH1.h"
00042 #include "TClass.h"
00043 #include "TDataType.h"
00044 #include "TDataMember.h"
00045 #include "TMethod.h"
00046 #include "TMethodCall.h"
00047 #include "TMethodArg.h"
00048 #include "TColor.h"
00049 #include "TLatex.h"
00050 #include "Riostream.h"
00051 #ifndef __NOGO4GED__
00052 #include "TGedEditor.h"
00053 #endif
00054
00055 #include "TGo4LockGuard.h"
00056
00057 #include "QRootDialog.h"
00058 #include "QRootApplication.h"
00059
00060 #include <cstring>
00061
00062
00063 QRootCanvas::QRootCanvas(QWidget *parent) :
00064 QWidget(parent),
00065 fMaskDoubleClick(false),
00066 fxShowEventStatus(false)
00067 {
00068 setObjectName( "QRootCanvas");
00069
00070 setSizeIncrement( QSize( 100, 100 ) );
00071
00072 TGo4LockGuard threadlock(0,true);
00073
00074 setUpdatesEnabled( true );
00075 setMouseTracking(true);
00076
00077 setFocusPolicy( Qt::TabFocus );
00078 setCursor( Qt::CrossCursor );
00079
00080
00081
00082
00083 setAttribute(Qt::WA_PaintOnScreen);
00084 setAttribute(Qt::WA_PaintUnclipped);
00085
00086
00087 fQtWindowId = winId();
00088 fRootWindowId = gVirtualX->AddWindow((ULong_t)fQtWindowId, 100, 30);
00089
00090 fCanvas = new TCanvas("Canvas", width(), height(), fRootWindowId);
00091
00092
00093 fMousePosX = 0;
00094 fMousePosY = 0;
00095 fMenuMethods = 0;
00096 fMenuObj = 0;
00097
00098 setAcceptDrops(true);
00099
00100 fRepaintMode = 0;
00101 fRepaintTimer = new QTimer;
00102 fRepaintTimer->setSingleShot(true);
00103 connect(fRepaintTimer, SIGNAL(timeout()), this, SLOT(processRepaintTimer()));
00104 }
00105
00106 QRootCanvas::~QRootCanvas()
00107 {
00108 if(fCanvas) {
00109 delete fCanvas;
00110 fCanvas = 0;
00111 }
00112
00113 if (fMenuMethods) {
00114 delete fMenuMethods;
00115 fMenuMethods = 0;
00116 }
00117
00118 delete fRepaintTimer;
00119 }
00120
00121 void QRootCanvas::mouseMoveEvent(QMouseEvent *e)
00122 {
00123 TGo4LockGuard threadlock(0,true);
00124 if (fCanvas!=0) {
00125 if (e->buttons() & Qt::LeftButton)
00126 fCanvas->HandleInput(kButton1Motion, e->x(), e->y());
00127 else
00128 fCanvas->HandleInput(kMouseMotion, e->x(), e->y());
00129 }
00130
00131 if(fxShowEventStatus) {
00132 TObject* selected = fCanvas->GetSelected();
00133 Int_t px = fCanvas->GetEventX();
00134 Int_t py = fCanvas->GetEventY();
00135 QString buffer = "";
00136 if (selected!=0) {
00137 buffer = selected->GetName();
00138 buffer += " ";
00139 buffer += selected->GetObjectInfo(px,py);
00140 } else {
00141 buffer = "No selected object x = ";
00142 buffer += QString::number(px);
00143 buffer += " y = ";
00144 buffer += QString::number(py);
00145 }
00146 emit CanvasStatusEvent(buffer.toLatin1().constData());
00147 }
00148 }
00149
00150
00151 void QRootCanvas::mousePressEvent( QMouseEvent *e )
00152 {
00153 TGo4LockGuard threadlock(0,true);
00154
00155 TObjLink* pickobj = 0;
00156 TPad* pad = fCanvas->Pick(e->x(), e->y(), pickobj);
00157 TObject *selected = fCanvas->GetSelected();
00158
00159
00160
00161 switch(e->button()) {
00162 case Qt::LeftButton :
00163 fCanvas->HandleInput(kButton1Down, e->x(), e->y());
00164 emit PadClicked(pad);
00165 break;
00166 case Qt::RightButton : {
00167 TString selectedOpt("");
00168 if (pad!=0) {
00169 if (pickobj==0) {
00170 fCanvas->SetSelected(pad);
00171 selected = pad;
00172 } else
00173 if(selected==0) {
00174 selected = pickobj->GetObject();
00175 selectedOpt = pickobj->GetOption();
00176 }
00177 pad->cd();
00178 }
00179 fCanvas->SetSelectedPad(pad);
00180 gROOT->SetSelectedPrimitive(selected);
00181 fMousePosX = gPad->AbsPixeltoX(gPad->GetEventX());
00182 fMousePosY = gPad->AbsPixeltoY(gPad->GetEventY());
00183
00184 QMenu menu(this);
00185 QSignalMapper map;
00186 connect(&map, SIGNAL(mapped(int)), this, SLOT(executeMenu(int)));
00187
00188 fMenuObj = selected;
00189 fMenuMethods = new TList;
00190 TClass *cl = fMenuObj->IsA();
00191 int curId = -1;
00192
00193 QString buffer = Form("%s::%s", cl->GetName(), fMenuObj->GetName());
00194 addMenuAction(&menu, &map, buffer, curId++);
00195
00196 cl->GetMenuItems(fMenuMethods);
00197 menu.addSeparator();
00198
00199 if(!cl->InheritsFrom(TLatex::Class())) {
00200 addMenuAction(&menu, &map, "Insert Latex", 100 );
00201 menu.addSeparator();
00202 }
00203
00204 if(cl->InheritsFrom(TH1::Class())) {
00205 addMenuAction(&menu, &map, "Qt Hist Line Color ", 101 );
00206 addMenuAction(&menu, &map, "Qt Hist Fill Color ", 102 );
00207 menu.addSeparator();
00208 }
00209
00210 TIter iter(fMenuMethods);
00211 TMethod *method=0;
00212 while ( (method = dynamic_cast<TMethod*>(iter())) != 0) {
00213 buffer = method->GetName();
00214 addMenuAction(&menu, &map, buffer, curId++);
00215 }
00216
00217 if (menu.exec(e->globalPos())==0) {
00218 fMenuObj = 0;
00219 delete fMenuMethods;
00220 fMenuMethods = 0;
00221 }
00222
00223 break;
00224 }
00225 case Qt::MidButton :
00226 fCanvas->HandleInput(kButton2Down, e->x(), e->y());
00227 emit SelectedPadChanged(pad);
00228
00229
00230 break;
00231 case Qt::NoButton :
00232 break;
00233 default:
00234 break;
00235 }
00236 }
00237
00238 void QRootCanvas::mouseReleaseEvent( QMouseEvent *e )
00239 {
00240 TGo4LockGuard threadlock(0,true);
00241 switch(e->button()) {
00242 case Qt::LeftButton :
00243 fCanvas->HandleInput(kButton1Up, e->x(), e->y());
00244 break;
00245 case Qt::RightButton :
00246 fCanvas->HandleInput(kButton3Up, e->x(), e->y());
00247 break;
00248 case Qt::MidButton :
00249 fCanvas->HandleInput(kButton2Up, e->x(), e->y());
00250 break;
00251 case Qt::NoButton :
00252 break;
00253 default:
00254 break;
00255 }
00256 }
00257
00258 void QRootCanvas::mouseDoubleClickEvent( QMouseEvent *e )
00259 {
00260 TGo4LockGuard threadlock(0,true);
00261 switch(e->button()) {
00262 case Qt::LeftButton : {
00263 if (!fMaskDoubleClick)
00264 fCanvas->HandleInput(kButton1Double, e->x(), e->y());
00265 TObjLink* pickobj = 0;
00266 TPad* pad = fCanvas->Pick(e->x(), e->y(), pickobj);
00267 emit PadDoubleClicked(pad);
00268
00269
00270
00271 break;
00272 }
00273 case Qt::RightButton :
00274 fCanvas->HandleInput(kButton3Double, e->x(), e->y());
00275 break;
00276 case Qt::MidButton :
00277 fCanvas->HandleInput(kButton2Double, e->x(), e->y());
00278 break;
00279 case Qt::NoButton :
00280 break;
00281 default:
00282 break;
00283 }
00284 }
00285
00286 void QRootCanvas::actiavteRepaint(int mode)
00287 {
00288 fRepaintMode |= mode;
00289 fRepaintTimer->setSingleShot(true);
00290 fRepaintTimer->start(100);
00291 }
00292
00293 void QRootCanvas::resizeEvent( QResizeEvent *)
00294 {
00295 actiavteRepaint(act_Resize);
00296 }
00297
00298 void QRootCanvas::paintEvent( QPaintEvent *)
00299 {
00300
00301
00302
00303
00304
00305 if (fRepaintMode<0)
00306 fRepaintMode = 0;
00307 else
00308 actiavteRepaint(act_Update);
00309 }
00310
00311 void QRootCanvas::processRepaintTimer()
00312 {
00313 if (fRepaintMode == 0) return;
00314
00315 TGo4LockGuard threadlock(0,true);
00316
00317 WId newid = winId();
00318 if(newid != fQtWindowId) {
00319
00320
00321 delete fCanvas;
00322 fRootWindowId = gVirtualX->AddWindow((ULong_t)newid, width(), height());
00323 fCanvas = new TCanvas(objectName().toLatin1().constData(), width(), height(), fRootWindowId);
00324 fQtWindowId = newid;
00325 }
00326
00327 if (fRepaintMode && act_Resize) fCanvas->Resize();
00328 else fCanvas->Modified(kTRUE);
00329
00330 fCanvas->Update();
00331
00332 fRepaintMode = 0;
00333
00334 emit CanvasUpdated();
00335 }
00336
00337 void QRootCanvas::leaveEvent( QEvent *e )
00338 {
00339 QWidget::leaveEvent(e);
00340
00341 TGo4LockGuard threadlock(0,true);
00342 if (fCanvas!=0)
00343 fCanvas->HandleInput(kMouseLeave, 0, 0);
00344
00345 emit CanvasLeaveEvent();
00346 }
00347
00348 void QRootCanvas::setShowEventStatus(bool s)
00349 {
00350 fxShowEventStatus = s;
00351 }
00352
00353 bool QRootCanvas::showEventStatus() const
00354 {
00355 return fxShowEventStatus;
00356 }
00357
00358
00360
00361 void QRootCanvas::dragEnterEvent( QDragEnterEvent *e )
00362 {
00363 if (e->mimeData()->hasText())
00364 e->acceptProposedAction();
00365 }
00366
00367 void QRootCanvas::dropEvent( QDropEvent *event )
00368 {
00369 TObject* obj(0);
00370 QPoint pos = event->pos();
00371 TPad* pad = Pick(pos.x(), pos.y(), obj);
00372
00373 if (pad!=0)
00374 emit CanvasDropEvent(event, pad);
00375 }
00376
00378
00379
00380 void QRootCanvas::cd(Int_t subpadnumber)
00381 {
00382 fCanvas->cd(subpadnumber);
00383 }
00384
00385 void QRootCanvas::Browse(TBrowser *b)
00386 {
00387 fCanvas->Browse(b);
00388 }
00389
00390 void QRootCanvas::Clear(Option_t *option)
00391 {
00392 fCanvas->Clear(option);
00393 }
00394 void QRootCanvas::Close(Option_t *option)
00395 {
00396 fCanvas->Close(option);
00397 }
00398 void QRootCanvas::Draw(Option_t *option)
00399 {
00400 fCanvas->Draw(option);
00401 }
00402 TObject *QRootCanvas::DrawClone(Option_t *option)
00403 {
00404 return fCanvas->DrawClone(option);
00405 }
00406 TObject *QRootCanvas::DrawClonePad()
00407 {
00408 return fCanvas->DrawClonePad();
00409 }
00410 void QRootCanvas::EditorBar()
00411 {
00412 fCanvas->EditorBar();
00413 }
00414 void QRootCanvas::EnterLeave(TPad *prevSelPad, TObject *prevSelObj)
00415 {
00416 fCanvas->EnterLeave(prevSelPad, prevSelObj);
00417 }
00418 void QRootCanvas::FeedbackMode(Bool_t set)
00419 {
00420 fCanvas->FeedbackMode(set);
00421 }
00422 void QRootCanvas::Flush()
00423 {
00424 fCanvas->Flush();
00425 }
00426 void QRootCanvas::UseCurrentStyle()
00427 {
00428 fCanvas->UseCurrentStyle();
00429 }
00430 void QRootCanvas::ForceUpdate()
00431 {
00432 fCanvas->ForceUpdate() ;
00433 }
00434 const char *QRootCanvas::GetDISPLAY()
00435 {
00436 return fCanvas->GetDISPLAY() ;
00437 }
00438 TContextMenu *QRootCanvas::GetContextMenu()
00439 {
00440 return fCanvas->GetContextMenu() ;
00441 }
00442 Int_t QRootCanvas::GetDoubleBuffer()
00443 {
00444 return fCanvas->GetDoubleBuffer();
00445 }
00446 TControlBar *QRootCanvas::GetEditorBar()
00447 {
00448 return 0;
00449
00450 }
00451 Int_t QRootCanvas::GetEvent()
00452 {
00453 return fCanvas->GetEvent();
00454 }
00455 Int_t QRootCanvas::GetEventX()
00456 {
00457 return fCanvas->GetEventX() ;
00458 }
00459 Int_t QRootCanvas::GetEventY()
00460 {
00461 return fCanvas->GetEventY() ;
00462 }
00463 Color_t QRootCanvas::GetHighLightColor()
00464 {
00465 return fCanvas->GetHighLightColor() ;
00466 }
00467
00468 TVirtualPad *QRootCanvas::GetPadSave()
00469 {
00470 return fCanvas->GetPadSave();
00471 }
00472 TObject *QRootCanvas::GetSelected()
00473 {
00474 return fCanvas->GetSelected() ;
00475 }
00476 Option_t *QRootCanvas::GetSelectedOpt()
00477 {
00478 return fCanvas->GetSelectedOpt();
00479 }
00480 TVirtualPad *QRootCanvas::GetSelectedPad()
00481 {
00482 return fCanvas->GetSelectedPad();
00483 }
00484 Bool_t QRootCanvas::GetShowEventStatus()
00485 {
00486 return fCanvas->GetShowEventStatus() ;
00487 }
00488 Bool_t QRootCanvas::GetAutoExec()
00489 {
00490 return fCanvas->GetAutoExec();
00491 }
00492 Size_t QRootCanvas::GetXsizeUser()
00493 {
00494 return fCanvas->GetXsizeUser();
00495 }
00496 Size_t QRootCanvas::GetYsizeUser()
00497 {
00498 return fCanvas->GetYsizeUser();
00499 }
00500 Size_t QRootCanvas::GetXsizeReal()
00501 {
00502 return fCanvas->GetXsizeReal();
00503 }
00504 Size_t QRootCanvas::GetYsizeReal()
00505 {
00506 return fCanvas->GetYsizeReal();
00507 }
00508 Int_t QRootCanvas::GetCanvasID()
00509 {
00510 return fCanvas->GetCanvasID();
00511 }
00512
00513 Int_t QRootCanvas::GetWindowTopX()
00514 {
00515 return fCanvas->GetWindowTopX();
00516 }
00517 Int_t QRootCanvas::GetWindowTopY()
00518 {
00519 return fCanvas->GetWindowTopY();
00520 }
00521 UInt_t QRootCanvas::GetWindowWidth()
00522 {
00523 return fCanvas->GetWindowWidth() ;
00524 }
00525 UInt_t QRootCanvas::GetWindowHeight()
00526 {
00527 return fCanvas->GetWindowHeight();
00528 }
00529 UInt_t QRootCanvas::GetWw()
00530 {
00531 return fCanvas->GetWw();
00532 }
00533 UInt_t QRootCanvas::GetWh()
00534 {
00535 return fCanvas->GetWh() ;
00536 }
00537 void QRootCanvas::GetCanvasPar(Int_t &wtopx, Int_t &wtopy, UInt_t &ww, UInt_t &wh)
00538 {
00539 fCanvas->GetCanvasPar(wtopx, wtopy, ww, wh);
00540 }
00541 void QRootCanvas::HandleInput(EEventType button, Int_t x, Int_t y)
00542 {
00543 fCanvas->HandleInput(button, x, y);
00544 }
00545 Bool_t QRootCanvas::HasMenuBar()
00546 {
00547 return fCanvas->HasMenuBar() ;
00548 }
00549 void QRootCanvas::Iconify()
00550 {
00551 fCanvas->Iconify();
00552 }
00553 Bool_t QRootCanvas::IsBatch()
00554 {
00555 return fCanvas->IsBatch() ;
00556 }
00557 Bool_t QRootCanvas::IsRetained()
00558 {
00559 return fCanvas->IsRetained();
00560 }
00561 void QRootCanvas::ls(Option_t *option)
00562 {
00563 fCanvas->ls(option);
00564 }
00565
00566 void QRootCanvas::Modified(Bool_t mod)
00567 {
00568 fCanvas->Modified(mod);
00569 }
00570
00571 void QRootCanvas::MoveOpaque(Int_t set)
00572 {
00573 fCanvas->MoveOpaque(set);
00574 }
00575
00576 Bool_t QRootCanvas::OpaqueMoving()
00577 {
00578 return fCanvas->OpaqueMoving();
00579 }
00580 Bool_t QRootCanvas::OpaqueResizing()
00581 {
00582 return fCanvas->OpaqueResizing();
00583 }
00584 void QRootCanvas::Paint(Option_t *option)
00585 {
00586 fCanvas->Paint(option);
00587 }
00588 TPad *QRootCanvas::Pick(Int_t px, Int_t py, TObjLink *&pickobj)
00589 {
00590 return fCanvas->Pick(px, py, pickobj);
00591 }
00592 TPad *QRootCanvas::Pick(Int_t px, Int_t py, TObject *prevSelObj)
00593 {
00594 return fCanvas->Pick(px, py, prevSelObj);
00595 }
00596 void QRootCanvas::Resize(Option_t *option)
00597 {
00598 fCanvas->Resize(option);
00599 }
00600 void QRootCanvas::ResizeOpaque(Int_t set)
00601 {
00602 fCanvas->ResizeOpaque(set);
00603 }
00604 void QRootCanvas::SaveSource(const char *filename, Option_t *option)
00605 {
00606 fCanvas->SaveSource(filename, option);
00607 }
00608 void QRootCanvas::SetCursor(ECursor cursor)
00609 {
00610 fCanvas->SetCursor(cursor);
00611 }
00612 void QRootCanvas::SetDoubleBuffer(Int_t mode)
00613 {
00614 fCanvas->SetDoubleBuffer(mode);
00615 }
00616 void QRootCanvas::SetWindowPosition(Int_t x, Int_t y)
00617 {
00618 fCanvas->SetWindowPosition(x, y) ;
00619 }
00620 void QRootCanvas::SetWindowSize(UInt_t ww, UInt_t wh)
00621 {
00622 fCanvas->SetWindowSize(ww,wh) ;
00623 }
00624 void QRootCanvas::SetCanvasSize(UInt_t ww, UInt_t wh)
00625 {
00626 fCanvas->SetCanvasSize(ww, wh);
00627 }
00628 void QRootCanvas::SetHighLightColor(Color_t col)
00629 {
00630 fCanvas->SetHighLightColor(col);
00631 }
00632 void QRootCanvas::SetSelected(TObject *obj)
00633 {
00634 fCanvas->SetSelected(obj);
00635 }
00636 void QRootCanvas::SetSelectedPad(TPad *pad)
00637 {
00638 fCanvas->SetSelectedPad(pad);
00639 }
00640 void QRootCanvas::Show()
00641 {
00642 fCanvas->Show() ;
00643 }
00644 void QRootCanvas::Size(Float_t xsizeuser, Float_t ysizeuser)
00645 {
00646 fCanvas->Size(xsizeuser, ysizeuser);
00647 }
00648 void QRootCanvas::SetBatch(Bool_t batch)
00649 {
00650 fCanvas->SetBatch(batch);
00651 }
00652 void QRootCanvas::SetRetained(Bool_t retained)
00653 {
00654 fCanvas->SetRetained(retained);
00655 }
00656 void QRootCanvas::SetTitle(const char *title)
00657 {
00658 fCanvas->SetTitle(title);
00659 }
00660 void QRootCanvas::ToggleEventStatus()
00661 {
00662 fCanvas->ToggleEventStatus();
00663 }
00664 void QRootCanvas::ToggleAutoExec()
00665 {
00666 fCanvas->ToggleAutoExec();
00667 }
00668 void QRootCanvas::Update()
00669 {
00670
00671 actiavteRepaint(act_Update);
00672
00673 }
00674
00675 void QRootCanvas::closeEvent( QCloseEvent * e)
00676 {
00677 if (fCanvas) {
00678 delete fCanvas;
00679 fCanvas = 0;
00680 }
00681
00682 e->accept();
00683 }
00684
00685
00686 void QRootCanvas::methodDialog(TObject* object, TMethod* method)
00687 {
00688 if ((object==0) || (method==0)) return;
00689
00690 TGo4LockGuard threadlock(0,true);
00691
00692
00693
00694 QRootDialog dlg;
00695
00696 dlg.setWindowTitle(Form("%s:%s", object->GetName(), method->GetName()));
00697
00698
00699
00700 TMethodArg *argument = 0;
00701 TIter next(method->GetListOfMethodArgs());
00702
00703 while ((argument = (TMethodArg *) next())) {
00704 TString argTitle = TString::Format("(%s) %s", argument->GetTitle(), argument->GetName());
00705 TString argDflt = argument->GetDefault() ? argument->GetDefault() : "";
00706 if (argDflt.Length()>0)
00707 argTitle += TString::Format(" [default: %s]", argDflt.Data());
00708 TString type = argument->GetTypeName();
00709 TDataType *datatype = gROOT->GetType(type);
00710 TString basictype;
00711
00712 if (datatype) {
00713 basictype = datatype->GetTypeName();
00714 } else {
00715 if (type.CompareTo("enum") != 0)
00716 std::cout << "*** Warning in Dialog(): data type is not basic type, assuming (int)\n";
00717 basictype = "int";
00718 }
00719
00720 if (TString(argument->GetTitle()).Index("*")!=kNPOS) {
00721 basictype += "*";
00722 type = "char*";
00723 }
00724
00725 TDataMember *m = argument->GetDataMember();
00726 if (m && m->GetterMethod()) {
00727
00728 m->GetterMethod()->Init(object->IsA(), m->GetterMethod()->GetMethodName(), "");
00729
00730
00731
00732 TString val;
00733
00734 if (basictype == "char*") {
00735 char *tdefval(0);
00736 m->GetterMethod()->Execute(object, "", &tdefval);
00737 if (tdefval) val = tdefval;
00738 } else
00739 if ((basictype == "float") ||
00740 (basictype == "double")) {
00741 Double_t ddefval(0.);
00742 m->GetterMethod()->Execute(object, "", ddefval);
00743 val = TString::Format("%g", ddefval);
00744 } else
00745 if ((basictype == "char") ||
00746 (basictype == "int") ||
00747 (basictype == "long") ||
00748 (basictype == "short")) {
00749 Long_t ldefval(0);
00750 m->GetterMethod()->Execute(object, "", ldefval);
00751 val = TString::Format("%ld", ldefval);
00752 }
00753
00754
00755
00756 TList *opt;
00757 if ((opt = m->GetOptions()) != 0) {
00758
00759
00760
00761 dlg.addArg(argTitle.Data(), val.Data(), type.Data());
00762
00763 } else {
00764
00765 dlg.addArg(argTitle.Data(), val.Data(), type.Data());
00766 }
00767 } else {
00768 if ((argDflt.Length() > 1) &&
00769 (argDflt[0]=='\"') && (argDflt[argDflt.Length()-1]=='\"')) {
00770
00771 argDflt.Remove(0,1);
00772 argDflt.Remove(argDflt.Length()-1,1);
00773 }
00774
00775 dlg.addArg(argTitle.Data(), argDflt.Data(), type.Data());
00776 }
00777 }
00778
00779 if (dlg.exec() != QDialog::Accepted) return;
00780
00781 Bool_t deletion = kFALSE;
00782
00783 qDebug("DIAL executeMethod: simple version\n");
00784 TVirtualPad *psave = gROOT->GetSelectedPad();
00785
00786 qDebug("DIAL saved pad: %s gPad:%s \n",psave->GetName(),gPad->GetName());
00787
00788 qDebug("DIAL obj:%s meth:%s \n", object->GetName(), method->GetName());
00789
00790
00791
00792 TObjArray tobjlist(method->GetListOfMethodArgs()->LastIndex() + 1);
00793 for (int n=0; n<=method->GetListOfMethodArgs()->LastIndex(); n++) {
00794 QString s = dlg.getArg(n);
00795 qDebug( "** QString values (first ) :%s \n", s.toLatin1().constData() );
00796 tobjlist.AddLast(new TObjString(s.toLatin1().constData())) ;
00797 }
00798
00799
00800 if(strcmp(method->GetName(),"Delete") == 0) {
00801
00802 qDebug(" DIAL obj name deleted :%s \n", object->GetName());
00803 emit MenuCommandExecuted(object, "Delete");
00804 delete object;
00805 object = 0;
00806 deletion = kTRUE;
00807 qDebug(" DIAL deletion done closing ... \n");
00808 } else
00809 if (strcmp(method->GetName(), "SetCanvasSize") == 0) {
00810 int width = dlg.getArg(0).toInt();
00811 int height = dlg.getArg(1).toInt();
00812 qDebug( " do resize with %i %i \n", width, height);
00813 resize(width, height);
00814 emit MenuCommandExecuted(fCanvas, "SetCanvasSize");
00815 } else {
00816
00817 qDebug("TCint::Execute called !\n");
00818
00819 object->Execute(method, &tobjlist);
00820
00821 if (object->TestBit(TObject::kNotDeleted))
00822 emit MenuCommandExecuted(object, method->GetName());
00823 else {
00824 deletion = true;
00825 object = 0;
00826 }
00827 }
00828
00829 if(!deletion ) {
00830 qDebug("DIAL set saved pad: %s herit:%s gPad:%s\n",
00831 psave->GetName(), psave->ClassName(), gPad->GetName());
00832 gROOT->SetSelectedPad(psave);
00833 gROOT->GetSelectedPad()->Modified();
00834 gROOT->GetSelectedPad()->Update();
00835 qDebug("DIAL update done on %s \n", gROOT->GetSelectedPad()->GetName());
00836 } else {
00837 gROOT->SetSelectedPad( gPad );
00838 gROOT->GetSelectedPad()->Update();
00839 }
00840 }
00841
00842 QAction* QRootCanvas::addMenuAction(QMenu* menu, QSignalMapper* map, const QString& text, int id)
00843 {
00844 bool enabled = QRootApplication::IsRootCanvasMenuEnabled();
00845
00846 QAction* act = new QAction(text, menu);
00847
00848 if (!enabled)
00849 if ((text.compare("DrawClone")==0) ||
00850 (text.compare("DrawClass")==0) ||
00851 (text.compare("Inspect")==0) ||
00852 (text.compare("SetShowProjectionX")==0) ||
00853 (text.compare("SetShowProjectionY")==0) ||
00854 (text.compare("DrawPanel")==0) ||
00855 (text.compare("FitPanel")==0))
00856 act->setEnabled(false);
00857
00858 map->connect (act, SIGNAL(triggered()), map, SLOT(map()));
00859 menu->addAction(act);
00860 map->setMapping(act, id);
00861
00862
00863 return act;
00864 }
00865
00866 void QRootCanvas::executeMenu(int id)
00867 {
00868 TGo4LockGuard threadlock(0,true);
00869 QString text("");
00870 bool ok = false;
00871 if (id >=100) {
00872 switch (id){
00873 case 100: {
00874 TLatex *fxLatex = new TLatex();
00875 text = QInputDialog::getText(this, tr( "Qt Root" ),
00876 tr( "Please enter your text" ),
00877 QLineEdit::Normal, QString::null, &ok);
00878
00879 fxLatex->DrawLatex(fMousePosX, fMousePosY, text.toLatin1().constData());
00880 emit MenuCommandExecuted(fxLatex, "DrawLatex");
00881 break;
00882 }
00883 case 101: {
00884 TH1 *h1 = dynamic_cast<TH1*> (fMenuObj);
00885 if (h1!=0) {
00886 QColor col = QColorDialog::getColor();
00887 if (col.isValid()) {
00888 short int C_new = TColor::GetColor(col.red(), col.green(), col.blue());
00889 h1->SetLineColor(C_new);
00890 emit MenuCommandExecuted(h1, "SetLineColor");
00891 }
00892 }
00893 break;
00894 }
00895 case 102 : {
00896 TH1 *h1 = dynamic_cast<TH1*> (fMenuObj);
00897 if (h1!=0) {
00898 QColor col = QColorDialog::getColor();
00899 if (col.isValid()) {
00900 short int C_new = TColor::GetColor(col.red(), col.green(), col.blue());
00901 h1->SetFillColor(C_new);
00902 emit MenuCommandExecuted(h1,"SetFillColor");
00903 }
00904 }
00905 }
00906 }
00907 gROOT->GetSelectedPad()->Update();
00908 gROOT->GetSelectedPad()->Modified();
00909 fCanvas->Modified();
00910 fCanvas->ForceUpdate();
00911 gROOT->SetFromPopUp( kFALSE );
00912 } else
00913 if (id >=0) {
00914
00915
00916
00917 TVirtualPad* psave = gROOT->GetSelectedPad();
00918 TMethod *method = (TMethod *) fMenuMethods->At(id);
00919
00921 fCanvas->HandleInput(kButton3Up, gPad->XtoAbsPixel(fMousePosX), gPad->YtoAbsPixel(fMousePosY));
00922
00923
00924 gROOT->cd();
00925
00926
00927 if (method->GetListOfMethodArgs()->First()) {
00928 methodDialog(fMenuObj, method);
00929 } else {
00930
00931 gROOT->SetFromPopUp(kTRUE);
00932
00933 fMenuObj->Execute(method->GetName(), "");
00934
00935 if (fMenuObj->TestBit(TObject::kNotDeleted)) {
00936 emit MenuCommandExecuted(fMenuObj, method->GetName());
00937 } else {
00938 fMenuObj = 0;
00939 }
00940
00941 }
00942
00943 #ifndef __NOGO4GED__
00944 TGedEditor* ed = dynamic_cast<TGedEditor*>(TVirtualPadEditor::GetPadEditor(kFALSE));
00945 if (fMenuObj && ed) ed->SetModel(psave, fMenuObj, kButton1Down);
00946 #endif
00947
00948 fCanvas->GetPadSave()->Update();
00949 fCanvas->GetPadSave()->Modified();
00950
00951 gROOT->SetSelectedPad(psave);
00952
00953 gROOT->GetSelectedPad()->Update();
00954 gROOT->GetSelectedPad()->Modified();
00955
00956 fCanvas->Modified();
00957 fCanvas->ForceUpdate();
00958 gROOT->SetFromPopUp(kFALSE);
00959 }
00960
00961 fMenuObj = 0;
00962 delete fMenuMethods;
00963 fMenuMethods = 0;
00964 }