Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

tqrootcanvas.cpp

Go to the documentation of this file.
00001 //-------------------------------------------------------------
00002 //        Go4 Release Package v3.04-01 (build 30401)
00003 //                      28-November-2008
00004 //---------------------------------------------------------------
00005 //   The GSI Online Offline Object Oriented (Go4) Project
00006 //   Experiment Data Processing at EE department, GSI
00007 //---------------------------------------------------------------
00008 //
00009 //Copyright (C) 2000- Gesellschaft f. Schwerionenforschung, GSI
00010 //                    Planckstr. 1, 64291 Darmstadt, Germany
00011 //Contact:            http://go4.gsi.de
00012 //----------------------------------------------------------------
00013 //This software can be used under the license agreements as stated
00014 //in Go4License.txt file which is part of the distribution.
00015 //----------------------------------------------------------------
00016 /****************************************************************************
00017 ** Copyright ( C ) 2000 denis Bertini.  All rights reserved.
00018 *****************************************************************************/
00019 
00020 #include "tqrootcanvas.h"
00021 
00022 #include "Riostream.h"
00023 
00024 #include "qpainter.h"
00025 #include "qdragobject.h"
00026 
00027 #include "TPad.h"
00028 #include "TCanvas.h"
00029 #include "TROOT.h"
00030 #include "TString.h"
00031 #include "TH1.h"
00032 
00033 #include "tqcanvasmenu.h"
00034 #include "lockguard.h"
00035 
00036 TQRootCanvas::TQRootCanvas( QWidget *parent, const char *name, TCanvas *c ) :
00037    QWidget( parent, name ,WRepaintNoErase | WResizeNoErase ),
00038    fResizeFlag(2),
00039    fMaskDoubleClick(false)
00040 {
00041   Qtrootlockguard threadlock;
00042   // set defaults
00043   setUpdatesEnabled( true );
00044   setMouseTracking(true);
00045 
00046   //  setBackgroundMode( NoBackground );
00047   setFocusPolicy( TabFocus );
00048   setCursor( Qt::crossCursor );
00049 
00050   // add the Qt::WinId to TGX11 interface
00051   wid=gVirtualX->AddWindow(winId(),100,30);
00052   if (c==0){
00053     isCanvasOwned = true;
00054     fCanvas=new TCanvas(name,width(),height(),wid);
00055      }else{
00056     isCanvasOwned= false;
00057     fCanvas=c;
00058   }
00059   // create the context menu
00060   fContextMenu = new TQCanvasMenu( parent, fCanvas );
00061 
00062   // test here all the events sent to the QWidget
00063   // has a parent widget
00064   // then install filter
00065   if ( parent ){
00066     parent->installEventFilter( this );
00067     fParent = parent;
00068   } else fParent=0;
00069 
00070     // drag and drop suppurt  (M. Al-Turany)
00071     setAcceptDrops(TRUE);
00072 
00073 }
00074 
00075 TQRootCanvas::TQRootCanvas( QWidget *parent, QWidget* tabWin, const char *name, TCanvas *c ) :
00076    QWidget( tabWin, name ,WRepaintNoErase | WResizeNoErase ),
00077    fResizeFlag(2),
00078    fMaskDoubleClick(false)
00079 {
00080    Qtrootlockguard threadlock;
00081   // set defaults
00082      setUpdatesEnabled( true );
00083      setMouseTracking(true);
00084 //   QSizePolicy CanvasSizePolicy = new QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
00085 //   setSizePolicy(CanvasSizePolicy);
00086   //  setBackgroundMode( NoBackground );
00087   setFocusPolicy( TabFocus );
00088   setCursor( Qt::crossCursor );
00089 
00090   // add the Qt::WinId to TGX11 interface
00091   wid=gVirtualX->AddWindow(winId(),100,30);
00092   if (c==0){
00093     isCanvasOwned = true;
00094     fCanvas=new TCanvas(name,width(),height(),wid);
00095   }else{
00096     isCanvasOwned= false;
00097     fCanvas=c;
00098   }
00099   // create the context menu
00100   fContextMenu = new TQCanvasMenu( parent, tabWin, fCanvas );
00101 
00102   // test here all the events sent to the QWidget
00103   // has a parent widget
00104   // then install filter
00105   if ( parent ){
00106     parent->installEventFilter( this );
00107     fParent = parent;
00108   } else fParent=0;
00109 
00110   if ( tabWin ) fTabWin = tabWin;
00111 
00112   // drag and drop suppurt  (M. Al-Turany)
00113     setAcceptDrops(TRUE);
00114 }
00115 
00116 TQRootCanvas::~TQRootCanvas()
00117 {
00118    if (fContextMenu){
00119       delete fContextMenu;
00120       fContextMenu = 0;
00121    }
00122    if( isCanvasOwned && fCanvas ) {
00123      delete fCanvas;
00124      fCanvas = 0;
00125    }
00126 }
00127 
00128 void TQRootCanvas::setResizeFlag(int flag)
00129 {
00130    if (flag>=fResizeFlag) fResizeFlag = flag;
00131 }
00132 
00133 bool TQRootCanvas::checkResizeFlag(int level)
00134 {
00135    if (level<=fResizeFlag) {
00136      performResize();
00137      return true;
00138    }
00139    return false;
00140 }
00141 
00142 void TQRootCanvas::performResize()
00143 {
00144    fResizeFlag = 0;
00145    Resize();
00146    Update();
00147 }
00148 
00149 void TQRootCanvas::mouseMoveEvent(QMouseEvent *e)
00150 {
00151   Qtrootlockguard threadlock;
00152   if (fCanvas!=0) {
00153      if (e->state() & LeftButton)
00154        fCanvas->HandleInput(kButton1Motion, e->x(), e->y());
00155      else
00156         fCanvas->HandleInput(kMouseMotion, e->x(), e->y());
00157   }
00158 }
00159 
00160 
00161 void TQRootCanvas::mousePressEvent( QMouseEvent *e )
00162 {
00163    Qtrootlockguard threadlock;
00164 
00165    TObjLink* pickobj = 0;
00166    TPad* pad = fCanvas->Pick(e->x(), e->y(), pickobj);
00167    TObject *selected = fCanvas->GetSelected();
00168 
00169    // fCanvas->cd();
00170 
00171    switch(e->button()) {
00172      case LeftButton :
00173         fCanvas->HandleInput(kButton1Down, e->x(), e->y());
00174         emit PadClicked(pad);
00175         break;
00176      case RightButton : {
00177         TString selectedOpt("");
00178         if (pad!=0) {
00179           if (pickobj==0) {
00180             fCanvas->SetSelected(pad);
00181             selected = pad;
00182           } else
00183           if(selected==0) {
00184             selected    = pickobj->GetObject();
00185             selectedOpt = pickobj->GetOption();
00186           }
00187         }
00188         pad->cd();
00189         fCanvas->SetSelectedPad(pad);
00190         gROOT->SetSelectedPrimitive(selected);
00191         fContextMenu->popup(selected, gPad->AbsPixeltoX(gPad->GetEventX()),  gPad->AbsPixeltoY(gPad->GetEventY()), e);
00192         break;
00193      }
00194      case MidButton :
00195         fCanvas->HandleInput(kButton2Down, e->x(), e->y());
00196         emit SelectedPadChanged(pad);   //   that inform the Qt-world that tha pad is changed
00197                                         // and give the pointer to the new pad as argument
00198                                        // of the signal (M. Al-Turany)
00199         break;
00200      case  NoButton :
00201         break;
00202      default:
00203         break;
00204    }
00205 }
00206 
00207 void TQRootCanvas::mouseReleaseEvent( QMouseEvent *e )
00208 {
00209    Qtrootlockguard threadlock;
00210    switch(e->button()) {
00211       case LeftButton :
00212          fCanvas->HandleInput(kButton1Up, e->x(), e->y());
00213          break;
00214       case RightButton :
00215          fCanvas->HandleInput(kButton3Up, e->x(), e->y());
00216          break;
00217       case MidButton :
00218          fCanvas->HandleInput(kButton2Up, e->x(), e->y());
00219          break;
00220       case  NoButton :
00221          break;
00222       default:
00223          break;
00224   }
00225 }
00226 
00227 void TQRootCanvas::mouseDoubleClickEvent( QMouseEvent *e )
00228 {
00229    Qtrootlockguard threadlock;
00230    switch(e->button()) {
00231       case LeftButton : {
00232          if (!fMaskDoubleClick)
00233             fCanvas->HandleInput(kButton1Double, e->x(), e->y());
00234          TObjLink* pickobj = 0;
00235          TPad* pad = fCanvas->Pick(e->x(), e->y(), pickobj);
00236          emit PadDoubleClicked(pad);
00237          // prevent crash on following release event
00238          // if new canvas will be created in between
00239          // fCanvas->SetSelected(0);
00240          break;
00241       }
00242       case RightButton :
00243          fCanvas->HandleInput(kButton3Double, e->x(), e->y());
00244          break;
00245       case MidButton :
00246          fCanvas->HandleInput(kButton2Double, e->x(), e->y());
00247          break;
00248       case NoButton :
00249          break;
00250       default:
00251          break;
00252    }
00253 }
00254 
00255 void TQRootCanvas::resizeEvent( QResizeEvent *e )
00256 {
00257    QWidget::resizeEvent( e );
00258    setResizeFlag(1);
00259 }
00260 
00261 void TQRootCanvas::paintEvent( QPaintEvent * )
00262 {
00263    if(fCanvas) {
00264       QPainter p;
00265       p.begin( this);
00266       p.end();
00267       if (!checkResizeFlag(2))
00268         fCanvas->Update();
00269   }
00270 }
00271 
00272 void TQRootCanvas::leaveEvent( QEvent *e )
00273 {
00274    Qtrootlockguard threadlock;
00275    if (fCanvas!=0)
00276       fCanvas->HandleInput(kMouseLeave, 0, 0);
00277 }
00278 
00279 bool TQRootCanvas::eventFilter( QObject *o, QEvent *e )
00280 {
00281    if ( e->type() == QEvent::Close) {  // close
00282       if (fCanvas && (isCanvasOwned== false) ) {
00283          delete fCanvas;
00284          #if DEBUG_LEVEL
00285          qDebug("TQRootCanvas ::eventFilter canvas Id:%i deleted \n", fCanvas->GetCanvasID()) ;
00286          #endif
00287          fCanvas=0;
00288        }
00289       return FALSE;
00290    }
00291 
00292    if ( e->type() == QEvent::ChildRemoved ) {  // child is removed
00293       #if DEBUG_LEVEL
00294       qDebug(" TQRootCanvas:QEvent:Child removed called \n" );
00295       #endif
00296       return FALSE;                        // eat event
00297    }
00298 
00299 
00300    if ( e->type() == QEvent::Destroy) {  // destroy
00301       #if DEBUG_LEVEL
00302       qDebug(" QEvent:Destroy called \n" );
00303       #endif
00304       return FALSE;
00305    }
00306 
00307    if( e->type() == QEvent::MouseButtonRelease) {  // Resize on mouse release
00308       checkResizeFlag();
00309       return FALSE;
00310    }
00311 
00312    if( e->type() == QEvent::Enter) { // On enter event check resize flag
00313        checkResizeFlag();
00314        return FALSE;
00315    }
00316 
00317    if( e->type() == QEvent::Leave) {
00318        fCanvas->FeedbackMode(kFALSE);
00319        return FALSE;
00320     }
00321 
00322 
00323    if( e->type() == QEvent::Paint) {  // Paint
00324       return FALSE;
00325    }
00326 
00327    if( e->type() == QEvent::Move) {  // Paint
00328      return FALSE;
00329    }
00330 
00331    if( (e->type() == QEvent::Show) ||
00332        (e->type() == QEvent::ShowNormal) ||
00333        (e->type() == QEvent::ShowFullScreen) ||
00334        (e->type() == QEvent::ShowMaximized) ||
00335        (e->type() == QEvent::ShowMinimized)) {
00336         setResizeFlag(2);
00337         return FALSE;
00338    }
00339 
00340    // standard event processing
00341    return QWidget::eventFilter( o, e );
00342 }
00343 
00345 
00346 void TQRootCanvas::dragEnterEvent( QDragEnterEvent *e )
00347 {
00348 //Qtrootlockguard threadlock;
00349   if ( QTextDrag::canDecode(e ))
00350     e->accept();
00351 }
00352 
00353 void TQRootCanvas::dropEvent( QDropEvent *Event )
00354 {
00355    Qtrootlockguard threadlock;
00356    QString str;
00357 
00358     if ( QTextDrag::decode( Event, str ) ) {
00359       TObject *dragedObject = gROOT->FindObject(str);
00360       QPoint Pos = Event->pos();
00361       TObject *object=0;
00362       TPad *pad = fCanvas->Pick(Pos.x(), Pos.y(), object);
00363       if(dragedObject!=0) {
00364         if(dragedObject->InheritsFrom(TH1::Class())) {
00365           pad->cd();
00366           dragedObject->Draw();
00367           pad->Update();
00368         }
00369       } else
00370         cout << "object " << str <<  " not found by ROOT" << endl;
00371     }
00372 }
00373 
00375 
00376 
00377 void      TQRootCanvas::cd(Int_t subpadnumber)
00378 {
00379    fCanvas->cd(subpadnumber);
00380 }
00381 
00382 void      TQRootCanvas::Browse(TBrowser *b)
00383 {
00384    fCanvas->Browse(b);
00385 }
00386 
00387 void      TQRootCanvas::Clear(Option_t *option)
00388 {
00389    fCanvas->Clear(option);
00390 }
00391 void      TQRootCanvas::Close(Option_t *option)
00392 {
00393    fCanvas->Close(option);
00394 }
00395 void      TQRootCanvas::Draw(Option_t *option)
00396 {
00397    fCanvas->Draw(option);
00398 }
00399 TObject  *TQRootCanvas::DrawClone(Option_t *option)
00400 {
00401    return  fCanvas->DrawClone(option);
00402 }
00403 TObject  *TQRootCanvas::DrawClonePad()
00404 {
00405    return  fCanvas->DrawClonePad();
00406 }
00407 void      TQRootCanvas::EditorBar()
00408 {
00409    fCanvas->EditorBar();
00410 }
00411 void      TQRootCanvas::EnterLeave(TPad *prevSelPad, TObject *prevSelObj)
00412 {
00413    fCanvas->EnterLeave(prevSelPad, prevSelObj);
00414 }
00415 void      TQRootCanvas::FeedbackMode(Bool_t set)
00416 {
00417    fCanvas->FeedbackMode(set);
00418 }
00419 void      TQRootCanvas::Flush()
00420 {
00421    fCanvas->Flush();
00422 }
00423 void      TQRootCanvas::UseCurrentStyle()
00424 {
00425    fCanvas->UseCurrentStyle();
00426 }
00427 void      TQRootCanvas::ForceUpdate()
00428 {
00429    fCanvas->ForceUpdate() ;
00430 }
00431 const char  *TQRootCanvas::GetDISPLAY()
00432 {
00433    return fCanvas->GetDISPLAY() ;
00434 }
00435 TContextMenu  *TQRootCanvas::GetContextMenu()
00436 {
00437    return  fCanvas->GetContextMenu() ;
00438 }
00439 Int_t     TQRootCanvas::GetDoubleBuffer()
00440 {
00441    return fCanvas->GetDoubleBuffer();
00442 }
00443 TControlBar  *TQRootCanvas::GetEditorBar()
00444 {
00445    return 0; // not existing anymore for ROOT>4.00/02 JA
00446    //return fCanvas->GetEditorBar();
00447 }
00448 Int_t     TQRootCanvas::GetEvent()
00449 {
00450    return fCanvas->GetEvent();
00451 }
00452 Int_t     TQRootCanvas::GetEventX()
00453 {
00454    return fCanvas->GetEventX() ;
00455 }
00456 Int_t     TQRootCanvas::GetEventY()
00457 {
00458    return fCanvas->GetEventY() ;
00459 }
00460 Color_t   TQRootCanvas::GetHighLightColor()
00461 {
00462    return fCanvas->GetHighLightColor() ;
00463 }
00464 void     TQRootCanvas::GetPadDivision(Int_t xdivision, Int_t ydivision)
00465 {
00466 //      fCanvas->GetPadDivision(xdivision, ydivision);
00467 //       do nothing this function was taken out in root 3.0.4
00468 
00469 }
00470 TVirtualPad  *TQRootCanvas::GetPadSave()
00471 {
00472    return fCanvas->GetPadSave();
00473 }
00474 TObject   *TQRootCanvas::GetSelected()
00475 {
00476    return fCanvas->GetSelected() ;
00477 }
00478 Option_t  *TQRootCanvas::GetSelectedOpt()
00479 {
00480    return fCanvas->GetSelectedOpt();
00481 }
00482 TVirtualPad *TQRootCanvas::GetSelectedPad()
00483 {
00484    return fCanvas->GetSelectedPad();
00485 }
00486 Bool_t    TQRootCanvas::GetShowEventStatus()
00487 {
00488    return fCanvas->GetShowEventStatus() ;
00489 }
00490 Bool_t    TQRootCanvas::GetAutoExec()
00491 {
00492    return fCanvas->GetAutoExec();
00493 }
00494 Size_t    TQRootCanvas::GetXsizeUser()
00495 {
00496    return fCanvas->GetXsizeUser();
00497 }
00498 Size_t    TQRootCanvas::GetYsizeUser()
00499 {
00500    return fCanvas->GetYsizeUser();
00501 }
00502 Size_t    TQRootCanvas::GetXsizeReal()
00503 {
00504    return fCanvas->GetXsizeReal();
00505 }
00506 Size_t    TQRootCanvas::GetYsizeReal()
00507 {
00508    return fCanvas->GetYsizeReal();
00509 }
00510 Int_t     TQRootCanvas::GetCanvasID()
00511 {
00512    return fCanvas->GetCanvasID();
00513 }
00514 
00515 Int_t     TQRootCanvas::GetWindowTopX()
00516 {
00517    return fCanvas->GetWindowTopX();
00518 }
00519 Int_t     TQRootCanvas::GetWindowTopY()
00520 {
00521    return fCanvas->GetWindowTopY();
00522 }
00523 UInt_t    TQRootCanvas::GetWindowWidth()
00524 {
00525    return fCanvas->GetWindowWidth() ;
00526 }
00527 UInt_t    TQRootCanvas::GetWindowHeight()
00528 {
00529    return fCanvas->GetWindowHeight();
00530 }
00531 UInt_t    TQRootCanvas::GetWw()
00532 {
00533    return fCanvas->GetWw();
00534 }
00535 UInt_t    TQRootCanvas::GetWh()
00536 {
00537    return fCanvas->GetWh() ;
00538 }
00539 void      TQRootCanvas::GetCanvasPar(Int_t &wtopx, Int_t &wtopy, UInt_t &ww, UInt_t &wh)
00540 {
00541    fCanvas->GetCanvasPar(wtopx, wtopy, ww, wh);
00542 }
00543 void      TQRootCanvas::HandleInput(EEventType button, Int_t x, Int_t y)
00544 {
00545    fCanvas->HandleInput(button, x, y);
00546 }
00547 Bool_t    TQRootCanvas::HasMenuBar()
00548 {
00549    return fCanvas->HasMenuBar() ;
00550 }
00551 void      TQRootCanvas::Iconify()
00552 {
00553    fCanvas->Iconify();
00554 }
00555 Bool_t    TQRootCanvas::IsBatch()
00556 {
00557    return fCanvas->IsBatch() ;
00558 }
00559 Bool_t    TQRootCanvas::IsRetained()
00560 {
00561    return fCanvas->IsRetained();
00562 }
00563 void      TQRootCanvas::ls(Option_t *option)
00564 {
00565    fCanvas->ls(option);
00566 }
00567 void      TQRootCanvas::MoveOpaque(Int_t set)
00568 {
00569    fCanvas->MoveOpaque(set);
00570 }
00571 Bool_t    TQRootCanvas::OpaqueMoving()
00572 {
00573    return fCanvas->OpaqueMoving();
00574 }
00575 Bool_t    TQRootCanvas::OpaqueResizing()
00576 {
00577    return fCanvas->OpaqueResizing();
00578 }
00579 void      TQRootCanvas::Paint(Option_t *option)
00580 {
00581    fCanvas->Paint(option);
00582 }
00583 TPad     *TQRootCanvas::Pick(Int_t px, Int_t py, TObjLink *&pickobj)
00584 {
00585    return fCanvas->Pick(px, py, pickobj);
00586 }
00587 TPad     *TQRootCanvas::Pick(Int_t px, Int_t py, TObject *prevSelObj)
00588 {
00589    return fCanvas->Pick(px, py, prevSelObj);
00590 }
00591 void      TQRootCanvas::Resize(Option_t *option)
00592 {
00593    fCanvas->Resize(option);
00594 }
00595 void      TQRootCanvas::ResizeOpaque(Int_t set)
00596 {
00597    fCanvas->ResizeOpaque(set);
00598 }
00599 void      TQRootCanvas::SaveSource(const char *filename, Option_t *option)
00600 {
00601    fCanvas->SaveSource(filename, option);
00602 }
00603 void      TQRootCanvas::SetCursor(ECursor cursor)
00604 {
00605    fCanvas->SetCursor(cursor);
00606 }
00607 void      TQRootCanvas::SetDoubleBuffer(Int_t mode)
00608 {
00609    fCanvas->SetDoubleBuffer(mode);
00610 }
00611 void      TQRootCanvas::SetWindowPosition(Int_t x, Int_t y)
00612 {
00613    fCanvas->SetWindowPosition(x, y) ;
00614 }
00615 void      TQRootCanvas::SetWindowSize(UInt_t ww, UInt_t wh)
00616 {
00617    fCanvas->SetWindowSize(ww,wh) ;
00618 }
00619 void      TQRootCanvas::SetCanvasSize(UInt_t ww, UInt_t wh)
00620 {
00621    fCanvas->SetCanvasSize(ww, wh);
00622 }
00623 void      TQRootCanvas::SetHighLightColor(Color_t col)
00624 {
00625    fCanvas->SetHighLightColor(col);
00626 }
00627 void      TQRootCanvas::SetSelected(TObject *obj)
00628 {
00629    fCanvas->SetSelected(obj);
00630 }
00631 void      TQRootCanvas::SetSelectedPad(TPad *pad)
00632 {
00633    fCanvas->SetSelectedPad(pad);
00634 }
00635 void      TQRootCanvas::Show()
00636 {
00637    fCanvas->Show() ;
00638 }
00639 void      TQRootCanvas::Size(Float_t xsizeuser, Float_t ysizeuser)
00640 {
00641    fCanvas->Size(xsizeuser, ysizeuser);
00642 }
00643 void      TQRootCanvas::SetBatch(Bool_t batch)
00644 {
00645    fCanvas->SetBatch(batch);
00646 }
00647 void      TQRootCanvas::SetRetained(Bool_t retained)
00648 {
00649    fCanvas->SetRetained(retained);
00650 }
00651 void      TQRootCanvas::SetTitle(const char *title)
00652 {
00653    fCanvas->SetTitle(title);
00654 }
00655 void      TQRootCanvas::ToggleEventStatus()
00656 {
00657    fCanvas->ToggleEventStatus();
00658 }
00659 void      TQRootCanvas::ToggleAutoExec()
00660 {
00661    fCanvas->ToggleAutoExec();
00662 }
00663 void      TQRootCanvas::Update()
00664 {
00665    fCanvas->Update();
00666 }
00667 
00668 void  TQRootCanvas::closeEvent( QCloseEvent * e){
00669  //   printf("TQRootCanvas: close event called \n");
00670     if( isCanvasOwned ){
00671       delete fCanvas; fCanvas = 0;
00672     }
00673 
00674     e->accept();
00675     return;
00676 }
00677 
00678 //----------------------------END OF GO4 SOURCE FILE ---------------------

Generated on Fri Nov 28 12:59:33 2008 for Go4-v3.04-1 by  doxygen 1.4.2