00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "Riostream.h"
00013 #include "qevent.h"
00014 #include "qdialog.h"
00015 #include "qpushbutton.h"
00016 #include "qlabel.h"
00017 #include "qpainter.h"
00018 #if (QT_VERSION > 0x039999) // Added by cholm@nbi.dk - for Qt 4
00019 # include "qnamespace.h"
00020 using namespace Qt;
00021 # include "q3dragobject.h"
00022 typedef Q3TextDrag QTextDrag;
00023 #endif
00024
00025 #include "TQRootCanvas.h"
00026 #include "TROOT.h"
00027 #include "TClass.h"
00028 #include "TCanvas.h"
00029 #include "TQCanvasMenu.h"
00030
00031 ClassImp(TQRootCanvas)
00032
00033
00034 TQRootCanvas::TQRootCanvas( QWidget *parent, const char *name, TCanvas *c )
00035 : QWidget( parent, name ,WRepaintNoErase | WResizeNoErase ),
00036 fNeedResize(kTRUE)
00037 {
00038
00039 setUpdatesEnabled( kTRUE );
00040 setMouseTracking(kTRUE);
00041
00042
00043 setFocusPolicy( TabFocus );
00044 setCursor( Qt::crossCursor );
00045
00046
00047 fWid=gVirtualX->AddWindow((ULong_t)winId(),100,30);
00048 if (c == 0) {
00049 fIsCanvasOwned = kTRUE;
00050
00051 fCanvas=new TCanvas(name,width(),height(),fWid);
00052 }
00053 else {
00054 fIsCanvasOwned= kFALSE;
00055 fCanvas=c;
00056 }
00057
00058 fContextMenu = new TQCanvasMenu( parent, fCanvas );
00059
00060
00061
00062 if ( parent ) {
00063 parent->installEventFilter( this );
00064 fParent = parent;
00065 }
00066 else
00067 fParent=0;
00068
00069
00070 setAcceptDrops(kTRUE);
00071 }
00072
00073
00074 TQRootCanvas::TQRootCanvas( QWidget *parent, QWidget* tabWin, const char *name, TCanvas *c )
00075 : QWidget( tabWin, name ,WRepaintNoErase | WResizeNoErase ),
00076 fNeedResize(kTRUE)
00077 {
00078
00079 setUpdatesEnabled( kTRUE );
00080 setMouseTracking(kTRUE);
00081
00082 setFocusPolicy( TabFocus );
00083 setCursor( Qt::crossCursor );
00084
00085
00086 fWid=gVirtualX->AddWindow((ULong_t)winId(),100,30);
00087 if (c == 0) {
00088 fIsCanvasOwned = kTRUE;
00089 fCanvas=new TCanvas(name,width(),height(),fWid);
00090 }
00091 else {
00092 fIsCanvasOwned= kFALSE;
00093 fCanvas=c;
00094 }
00095
00096 fContextMenu = new TQCanvasMenu( parent, tabWin, fCanvas );
00097
00098
00099
00100 if ( parent ) {
00101 parent->installEventFilter( this );
00102 fParent = parent;
00103 }
00104 else
00105 fParent=0;
00106
00107 if ( tabWin )
00108 fTabWin = tabWin;
00109
00110
00111 setAcceptDrops(TRUE);
00112 }
00113
00114
00115 void TQRootCanvas::mouseMoveEvent(QMouseEvent *e)
00116 {
00117
00118
00119 if (fCanvas) {
00120 if (e->state() & LeftButton) {
00121 fCanvas->HandleInput(kButton1Motion, e->x(), e->y());
00122 }
00123 else {
00124 fCanvas->HandleInput(kMouseMotion, e->x(), e->y());
00125 }
00126 }
00127 }
00128
00129
00130 void TQRootCanvas::mousePressEvent( QMouseEvent *e )
00131 {
00132
00133
00134 TPad *pad=0;
00135 TObjLink *pickobj=0;
00136 TObject *selected=0;
00137 Int_t px=e->x();
00138 Int_t py=e->y();
00139 TString selectedOpt;
00140 switch (e->button()) {
00141 case LeftButton :
00142 fCanvas->HandleInput(kButton1Down, e->x(), e->y());
00143 break;
00144 case RightButton :
00145 selected=fCanvas->GetSelected();
00146 pad = fCanvas->Pick(px, py, pickobj);
00147 if (pad) {
00148 if (!pickobj) {
00149 fCanvas->SetSelected(pad); selected=pad;
00150 selectedOpt = "";
00151 }
00152 else {
00153 if (!selected) {
00154 selected = pickobj->GetObject();
00155 selectedOpt = pickobj->GetOption();
00156 }
00157 }
00158 pad->cd();
00159 fCanvas->SetSelectedPad(pad);
00160 }
00161 gROOT->SetSelectedPrimitive(selected);
00162 fContextMenu->Popup(selected, gPad->AbsPixeltoX(gPad->GetEventX()),
00163 gPad->AbsPixeltoY(gPad->GetEventY()), e);
00164
00165 break;
00166 case MidButton :
00167 pad = fCanvas->Pick(px, py, pickobj);
00168 emit SelectedPadChanged(pad);
00169
00170
00171 fCanvas->HandleInput(kButton2Down, e->x(), e->y());
00172
00173 break;
00174
00175 case NoButton :
00176 break;
00177 default:
00178 break;
00179 }
00180
00181 }
00182
00183
00184 void TQRootCanvas::mouseReleaseEvent( QMouseEvent *e )
00185 {
00186
00187
00188 switch (e->button()) {
00189 case LeftButton :
00190 fCanvas->HandleInput(kButton1Up, e->x(), e->y());
00191 break;
00192 case RightButton :
00193 fCanvas->HandleInput(kButton3Up, e->x(), e->y());
00194 break;
00195 case MidButton :
00196 fCanvas->HandleInput(kButton2Up, e->x(), e->y());
00197 break;
00198 case NoButton :
00199 break;
00200 default:
00201 break;
00202 }
00203
00204 }
00205
00206
00207 void TQRootCanvas::mouseDoubleClickEvent( QMouseEvent *e )
00208 {
00209
00210
00211 switch (e->button()) {
00212 case LeftButton :
00213 fCanvas->HandleInput(kButton1Double, e->x(), e->y());
00214 break;
00215 case RightButton :
00216 fCanvas->HandleInput(kButton3Double, e->x(), e->y());
00217 break;
00218 case MidButton :
00219 fCanvas->HandleInput(kButton2Double, e->x(), e->y());
00220 break;
00221 case NoButton :
00222 break;
00223 default:
00224 break;
00225 }
00226 }
00227
00228
00229 void TQRootCanvas::resizeEvent( QResizeEvent *e )
00230 {
00231
00232
00233 QWidget::resizeEvent( e );
00234 fNeedResize=kTRUE;
00235 }
00236
00237
00238 void TQRootCanvas::paintEvent( QPaintEvent * )
00239 {
00240
00241
00242 if (fCanvas) {
00243 QPainter p;
00244 p.begin( this);
00245 p.end();
00246 if (fNeedResize) {
00247 fCanvas->Resize();
00248 fNeedResize=kFALSE;
00249 }
00250 fCanvas->Update();
00251 }
00252 }
00253
00254
00255 void TQRootCanvas::leaveEvent( QEvent * )
00256 {
00257
00258
00259 if (fCanvas) fCanvas->HandleInput(kMouseLeave, 0, 0);
00260 }
00261
00262
00263 Bool_t TQRootCanvas ::eventFilter( QObject *o, QEvent *e )
00264 {
00265
00266
00267
00268 if ( e->type() == QEvent::Close) {
00269 if (fCanvas && (fIsCanvasOwned== kFALSE) ) {
00270 delete fCanvas;
00271 fCanvas=0;
00272 }
00273 if ( e->type() == QEvent::ChildRemoved ) {
00274 }
00275 return FALSE;
00276 }
00277
00278 if ( e->type() == QEvent::Destroy) {
00279 return FALSE;
00280 }
00281
00282 if ( e->type() == QEvent::Paint) {
00283 return FALSE;
00284 }
00285 if ( e->type() == QEvent::Move) {
00286 return FALSE;
00287 }
00288
00289
00290 return QWidget::eventFilter( o, e );
00291 }
00292
00293
00294
00295
00296 void TQRootCanvas::dragEnterEvent( QDragEnterEvent *e )
00297 {
00298
00299
00300 if ( QTextDrag::canDecode(e))
00301 e->accept();
00302 }
00303
00304
00305 void TQRootCanvas::dropEvent( QDropEvent *Event )
00306 {
00307
00308
00309 QString str;
00310 if ( QTextDrag::decode( Event, str ) ) {
00311 TObject *dragedObject = gROOT->FindObject(str);
00312 QPoint Pos = Event->pos();
00313 TObject *object=0;
00314 TPad *pad = fCanvas->Pick(Pos.x(), Pos.y(), object);
00315 if (dragedObject!=0) {
00316 if (dragedObject->InheritsFrom("TH1")) {
00317 pad->cd();
00318 dragedObject->Draw();
00319 pad->Update();
00320 }
00321 }
00322 else
00323 cout << "object " <<
00324 #if (QT_VERSION > 0x039999) // Added by cholm@nbi.dk - for Qt 4
00325 str.data()
00326 #else
00327 str
00328 #endif
00329 << " not found by ROOT" << endl;
00330 }
00331 }
00332
00333
00334
00335
00336 void TQRootCanvas::cd(Int_t subpadnumber)
00337 {
00338
00339
00340 fCanvas->cd(subpadnumber);
00341 }
00342
00343
00344 void TQRootCanvas::Browse(TBrowser *b)
00345 {
00346
00347
00348 fCanvas->Browse(b);
00349 }
00350
00351
00352 void TQRootCanvas::Clear(Option_t *option)
00353 {
00354
00355
00356 fCanvas->Clear(option);
00357 }
00358
00359
00360 void TQRootCanvas::Close(Option_t *option)
00361 {
00362
00363
00364 fCanvas->Close(option);
00365 }
00366
00367
00368 void TQRootCanvas::Draw(Option_t *option)
00369 {
00370
00371
00372 fCanvas->Draw(option);
00373 }
00374
00375
00376 TObject *TQRootCanvas::DrawClone(Option_t *option)
00377 {
00378
00379
00380 return fCanvas->DrawClone(option);
00381 }
00382
00383
00384 TObject *TQRootCanvas::DrawClonePad()
00385 {
00386
00387
00388 return fCanvas->DrawClonePad();
00389 }
00390
00391
00392 void TQRootCanvas::EditorBar()
00393 {
00394
00395
00396 fCanvas->EditorBar();
00397 }
00398
00399
00400 void TQRootCanvas::EnterLeave(TPad *prevSelPad, TObject *prevSelObj)
00401 {
00402
00403 fCanvas->EnterLeave(prevSelPad, prevSelObj);
00404 }
00405
00406
00407 void TQRootCanvas::FeedbackMode(Bool_t set)
00408 {
00409
00410 fCanvas->FeedbackMode(set);
00411 }
00412
00413
00414 void TQRootCanvas::Flush()
00415 {
00416
00417 fCanvas->Flush();
00418 }
00419
00420
00421 void TQRootCanvas::UseCurrentStyle()
00422 {
00423
00424 fCanvas->UseCurrentStyle();
00425 }
00426
00427
00428 void TQRootCanvas::ForceUpdate()
00429 {
00430
00431 fCanvas->ForceUpdate() ;
00432 }
00433
00434
00435 const char *TQRootCanvas::GetDISPLAY()
00436 {
00437
00438 return fCanvas->GetDISPLAY() ;
00439 }
00440
00441
00442 TContextMenu *TQRootCanvas::GetContextMenu()
00443 {
00444
00445 return fCanvas->GetContextMenu() ;
00446 }
00447
00448
00449 Int_t TQRootCanvas::GetDoubleBuffer()
00450 {
00451
00452 return fCanvas->GetDoubleBuffer();
00453 }
00454
00455
00456 Int_t TQRootCanvas::GetEvent()
00457 {
00458
00459 return fCanvas->GetEvent();
00460 }
00461
00462
00463 Int_t TQRootCanvas::GetEventX()
00464 {
00465
00466 return fCanvas->GetEventX() ;
00467 }
00468
00469
00470 Int_t TQRootCanvas::GetEventY()
00471 {
00472
00473 return fCanvas->GetEventY() ;
00474 }
00475
00476
00477 Color_t TQRootCanvas::GetHighLightColor()
00478 {
00479
00480 return fCanvas->GetHighLightColor() ;
00481 }
00482
00483
00484 TVirtualPad *TQRootCanvas::GetPadSave()
00485 {
00486
00487 return fCanvas->GetPadSave();
00488 }
00489
00490
00491 TObject *TQRootCanvas::GetSelected()
00492 {
00493
00494 return fCanvas->GetSelected() ;
00495 }
00496
00497
00498 Option_t *TQRootCanvas::GetSelectedOpt()
00499 {
00500
00501 return fCanvas->GetSelectedOpt();
00502 }
00503
00504
00505 TVirtualPad *TQRootCanvas::GetSelectedPad()
00506 {
00507
00508 return fCanvas->GetSelectedPad();
00509 }
00510
00511
00512 Bool_t TQRootCanvas::GetShowEventStatus()
00513 {
00514
00515 return fCanvas->GetShowEventStatus() ;
00516 }
00517
00518
00519 Bool_t TQRootCanvas::GetAutoExec()
00520 {
00521
00522 return fCanvas->GetAutoExec();
00523 }
00524
00525
00526 Size_t TQRootCanvas::GetXsizeUser()
00527 {
00528
00529 return fCanvas->GetXsizeUser();
00530 }
00531
00532
00533 Size_t TQRootCanvas::GetYsizeUser()
00534 {
00535
00536 return fCanvas->GetYsizeUser();
00537 }
00538
00539
00540 Size_t TQRootCanvas::GetXsizeReal()
00541 {
00542
00543 return fCanvas->GetXsizeReal();
00544 }
00545
00546
00547 Size_t TQRootCanvas::GetYsizeReal()
00548 {
00549
00550 return fCanvas->GetYsizeReal();
00551 }
00552
00553
00554 Int_t TQRootCanvas::GetCanvasID()
00555 {
00556
00557 return fCanvas->GetCanvasID();
00558 }
00559
00560
00561 Int_t TQRootCanvas::GetWindowTopX()
00562 {
00563
00564 return fCanvas->GetWindowTopX();
00565 }
00566
00567
00568 Int_t TQRootCanvas::GetWindowTopY()
00569 {
00570
00571 return fCanvas->GetWindowTopY();
00572 }
00573
00574
00575 UInt_t TQRootCanvas::GetWindowWidth()
00576 {
00577
00578 return fCanvas->GetWindowWidth() ;
00579 }
00580
00581
00582 UInt_t TQRootCanvas::GetWindowHeight()
00583 {
00584
00585 return fCanvas->GetWindowHeight();
00586 }
00587
00588
00589 UInt_t TQRootCanvas::GetWw()
00590 {
00591
00592 return fCanvas->GetWw();
00593 }
00594
00595
00596 UInt_t TQRootCanvas::GetWh()
00597 {
00598
00599 return fCanvas->GetWh() ;
00600 }
00601
00602
00603 void TQRootCanvas::GetCanvasPar(Int_t &wtopx, Int_t &wtopy, UInt_t &ww, UInt_t &wh)
00604 {
00605
00606 fCanvas->GetCanvasPar(wtopx, wtopy, ww, wh);
00607 }
00608
00609
00610 void TQRootCanvas::HandleInput(EEventType button, Int_t x, Int_t y)
00611 {
00612
00613 fCanvas->HandleInput(button, x, y);
00614 }
00615
00616
00617 Bool_t TQRootCanvas::HasMenuBar()
00618 {
00619
00620 return fCanvas->HasMenuBar() ;
00621 }
00622
00623
00624 void TQRootCanvas::Iconify()
00625 {
00626
00627 fCanvas->Iconify();
00628 }
00629
00630
00631 Bool_t TQRootCanvas::IsBatch()
00632 {
00633
00634 return fCanvas->IsBatch() ;
00635 }
00636
00637
00638 Bool_t TQRootCanvas::IsRetained()
00639 {
00640
00641 return fCanvas->IsRetained();
00642 }
00643
00644
00645 void TQRootCanvas::ls(Option_t *option)
00646 {
00647
00648 fCanvas->ls(option);
00649 }
00650
00651
00652 void TQRootCanvas::MoveOpaque(Int_t set)
00653 {
00654
00655 fCanvas->MoveOpaque(set);
00656 }
00657
00658
00659 Bool_t TQRootCanvas::OpaqueMoving()
00660 {
00661
00662 return fCanvas->OpaqueMoving();
00663 }
00664
00665
00666 Bool_t TQRootCanvas::OpaqueResizing()
00667 {
00668
00669 return fCanvas->OpaqueResizing();
00670 }
00671
00672
00673 void TQRootCanvas::Paint(Option_t *option)
00674 {
00675
00676 fCanvas->Paint(option);
00677 }
00678
00679
00680 TPad *TQRootCanvas::Pick(Int_t px, Int_t py, TObjLink *&pickobj)
00681 {
00682
00683 return fCanvas->Pick(px, py, pickobj);
00684 }
00685
00686
00687 TPad *TQRootCanvas::Pick(Int_t px, Int_t py, TObject *prevSelObj)
00688 {
00689
00690 return fCanvas->Pick(px, py, prevSelObj);
00691 }
00692
00693
00694 void TQRootCanvas::Resize(Option_t *option)
00695 {
00696
00697 fCanvas->Resize(option);
00698 }
00699
00700
00701 void TQRootCanvas::ResizeOpaque(Int_t set)
00702 {
00703
00704 fCanvas->ResizeOpaque(set);
00705 }
00706
00707
00708 void TQRootCanvas::SaveSource(const char *filename, Option_t *option)
00709 {
00710
00711 fCanvas->SaveSource(filename, option);
00712 }
00713
00714
00715 void TQRootCanvas::SetCursor(ECursor cursor)
00716 {
00717
00718 fCanvas->SetCursor(cursor);
00719 }
00720
00721
00722 void TQRootCanvas::SetDoubleBuffer(Int_t mode)
00723 {
00724
00725 fCanvas->SetDoubleBuffer(mode);
00726 }
00727
00728
00729 void TQRootCanvas::SetWindowPosition(Int_t x, Int_t y)
00730 {
00731
00732 fCanvas->SetWindowPosition(x, y) ;
00733 }
00734
00735
00736 void TQRootCanvas::SetWindowSize(UInt_t ww, UInt_t wh)
00737 {
00738
00739 fCanvas->SetWindowSize(ww,wh) ;
00740 }
00741
00742
00743 void TQRootCanvas::SetCanvasSize(UInt_t ww, UInt_t wh)
00744 {
00745
00746 fCanvas->SetCanvasSize(ww, wh);
00747 }
00748
00749
00750 void TQRootCanvas::SetHighLightColor(Color_t col)
00751 {
00752
00753 fCanvas->SetHighLightColor(col);
00754 }
00755
00756
00757 void TQRootCanvas::SetSelected(TObject *obj)
00758 {
00759
00760 fCanvas->SetSelected(obj);
00761 }
00762
00763
00764 void TQRootCanvas::SetSelectedPad(TPad *pad)
00765 {
00766
00767 fCanvas->SetSelectedPad(pad);
00768 }
00769
00770
00771 void TQRootCanvas::Show()
00772 {
00773
00774 fCanvas->Show() ;
00775 }
00776
00777
00778 void TQRootCanvas::Size(Float_t xsizeuser, Float_t ysizeuser)
00779 {
00780
00781 fCanvas->Size(xsizeuser, ysizeuser);
00782 }
00783
00784
00785 void TQRootCanvas::SetBatch(Bool_t batch)
00786 {
00787
00788 fCanvas->SetBatch(batch);
00789 }
00790
00791
00792 void TQRootCanvas::SetRetained(Bool_t retained)
00793 {
00794
00795 fCanvas->SetRetained(retained);
00796 }
00797
00798
00799 void TQRootCanvas::SetTitle(const char *title)
00800 {
00801
00802 fCanvas->SetTitle(title);
00803 }
00804
00805
00806 void TQRootCanvas::ToggleEventStatus()
00807 {
00808
00809 fCanvas->ToggleEventStatus();
00810 }
00811
00812
00813 void TQRootCanvas::ToggleAutoExec()
00814 {
00815
00816 fCanvas->ToggleAutoExec();
00817 }
00818
00819
00820 void TQRootCanvas::Update()
00821 {
00822
00823 fCanvas->Update();
00824 }
00825
00826
00827 void TQRootCanvas::closeEvent( QCloseEvent * e)
00828 {
00829
00830
00831 if ( fIsCanvasOwned ) {
00832 delete fCanvas;
00833 fCanvas = 0;
00834 }
00835 e->accept();
00836 return;
00837 }
00838
00839
00840 TQRootCanvas::~TQRootCanvas()
00841 {
00842
00843
00844 if (fContextMenu) {
00845 delete fContextMenu;
00846 fContextMenu=0;
00847 }
00848 if ( fIsCanvasOwned && fCanvas ) {
00849 delete fCanvas;
00850 fCanvas = 0;
00851 }
00852 }
00853
00854
00855