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