Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

/qtroot/interface/tqrootwindow.cpp

Go to the documentation of this file.
00001 //---------------------------------------------------------------
00002 //        Go4 Release Package v2.10-5 (build 21005) 
00003 //                      03-Nov-2005
00004 //---------------------------------------------------------------
00005 //       The GSI Online Offline Object Oriented (Go4) Project
00006 //       Experiment Data Processing at DVEE 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 #include "tqrootwindow.h"
00017 
00018 #include <iostream.h>
00019 
00020 #include "TVirtualX.h"
00021 #include "TSystem.h"
00022 #include "GuiTypes.h"
00023 
00024 #include "qevent.h"
00025 #include "qpainter.h"
00026 
00027 using namespace std;
00028 
00029 #include "lockguard.h"
00030 
00032 TQRootFrame::TQRootFrame(Window_t wid)
00033    :TGCompositeFrame(gClient,wid,new TGMainFrame(gClient->GetDefaultRoot(),100,100)) 
00034 {
00035 // we have to offer a real mainframe as top parent for root internal lists:
00036  // fParent=new TGMainFrame(gClient->GetDefaultRoot(),100,100);
00037 }
00038 
00039 TQRootFrame::~TQRootFrame()
00040 {
00041    delete fParent;   
00042 }
00043 
00044 Bool_t TQRootFrame::HandleEvent(Event_t *event)
00045 {
00046 //   cout <<"TQRootFrame event handler"<< endl;
00047    //cout <<"   event: "<<event->fType << endl;
00048    return TGCompositeFrame::HandleEvent(event);   
00049 }
00050 
00051 
00052 void TQRootFrame::CloseWindow()
00053 {
00054     UnmapWindow();  // capture the close window   
00055 }
00056 
00057 
00059 // This is the widget to be embedded in qt:
00060 
00061 TQRootWindow::TQRootWindow( QWidget *parent, const char *name)
00062   : QWidget( parent, name)//, WMouseNoMask | WPaintUnclipped | WPaintClever)//|WRepaintNoErase | WResizeNoErase)
00063 {
00064   // set defaults
00065   setUpdatesEnabled( true );
00066   setMouseTracking(true);
00067 
00068   //setBackgroundMode( NoBackground );
00069   setFocusPolicy( TabFocus );
00070   setCursor( Qt::crossCursor );
00071 
00072   // add the Qt::WinId to TGX11 interface
00073   fiWinid=gVirtualX->AddWindow(winId(),145,600);
00074 //  cout <<"Qt winId is "<<winId() << endl;
00075 //  cout <<"VirtualX Id is "<<fiWinid << endl;
00076   gSystem->Sleep(60);  // avoid "empty editor" for first viewpanel
00077                       // timing problem? to be investigated...  
00078   Window_t handle=gVirtualX->GetWindowID(fiWinid); 
00079 //  cout <<"window handle is "<< handle << endl;
00080   fxRootwindow=new TQRootFrame(handle);
00081   fxRootwindow->Resize();
00082   if ( parent ) parent->installEventFilter( this );
00083 
00084 //  cout <<"visible rect is: "<<visibleRect().width()<<", "<<visibleRect().height() << endl;  
00085 }
00086 
00087 
00088 void TQRootWindow::AddSubFrame(TGFrame* f, TGLayoutHints* l)
00089 {
00090    //cout <<"TQRootWindow::AddSubFrame" << endl;
00091    fxRootwindow->AddFrame(f,l);   
00092    fxRootwindow->MapWindow();
00093    fxRootwindow->MapSubwindows();
00094    fxRootwindow->Resize();
00095    polish();
00096    update();
00097    show();
00098 }
00099 
00100 void TQRootWindow::SetEditable(bool on)
00101 {
00102    fxRootwindow->SetEditable(on);    
00103 }
00104 
00105 Event_t* TQRootWindow::MapQMouseEvent(QMouseEvent *e)
00106 {
00107 if(e==0) return 0;
00108 Event_t* rev= new Event_t;
00109 
00110 rev->fX=e->x();
00111 rev->fY=e->y();
00112 rev->fXRoot= e->globalX();
00113 rev->fYRoot= e->globalY();
00114 
00115 // translate Qt event type: 
00116 if(e->type() == QEvent::MouseButtonPress)   rev->fType = kButtonPress;
00117 else if(e->type() == QEvent::MouseButtonRelease) rev->fType = kButtonRelease;
00118 else if(e->type() == QEvent::MouseButtonDblClick) rev->fType = kButtonDoubleClick; 
00119 else if(e->type() == QEvent::MouseMove) rev->fType = kMotionNotify;
00120 else if(e->type() == QEvent::KeyPress) rev->fType = kGKeyPress;
00121 else if(e->type() == QEvent::KeyRelease) rev->fType = kKeyRelease;
00122 else rev->fType = kOtherEvent; 
00123 
00124 // translate Qt state bits: 
00125 rev->fState=0;
00126 if(e->state() & LeftButton)
00127          rev->fState |= kButton1Mask;
00128 if(e->state() & RightButton)
00129          rev->fState |= kButton3Mask;
00130 if(e->state() & MidButton)
00131          rev->fState |= kButton2Mask;         
00132 if(e->state() & MouseButtonMask)
00133          rev->fState |= kButton1Mask;
00134 if(e->state() & ShiftButton)
00135          rev->fState |= kKeyShiftMask;           
00136 if(e->state() & ControlButton)
00137          rev->fState |= kKeyControlMask;
00138 if(e->state() & AltButton)
00139          rev->fState |= kKeyMod1Mask;
00140 if(e->state() & MetaButton)
00141          rev->fState |= kKeyMod1Mask;                  
00142 //if(e->state() & KeyButtonMask)
00143 //         rev->fState |= ShiftMask;
00144 //if(e->state() & Keypad)
00145 //         rev->fState |= ShiftMask;              
00146 
00147 rev->fCode      = NoButton;    // button code
00148 if(e->button() & LeftButton)
00149          rev->fCode |= kButton1Mask;
00150 if(e->button() & RightButton)
00151          rev->fCode |= kButton3Mask;
00152 if(e->button() & MidButton)
00153          rev->fCode |= kButton2Mask;  
00154 
00155 rev->fUser[0]=0;
00156 rev->fWindow    = gVirtualX->GetWindowID(fiWinid); // we refer signals to this window
00157 rev->fSendEvent = 0;
00158 rev->fTime = 0; // this might cause problems with root doubleclick treatment?
00159 
00160  
00161 
00162 return rev;    
00163 }
00164 
00165 
00166 
00167 void TQRootWindow::paintEvent( QPaintEvent * )
00168 {
00169 
00170 //Qtrootlockguard threadlock;
00171  if(fxRootwindow){
00172 //     QPainter p;
00173 //     p.begin( this);
00174 //     p.end();
00175 //     cout <<"TQRootWindow::paintEvent" << endl;
00176 //     cout <<"visible rect is: "<<visibleRect().width()<<", "<<visibleRect().height() << endl;  
00177      fxRootwindow->Resize(width(),height()); 
00178   }
00179 }
00180 
00181 
00182 bool TQRootWindow ::eventFilter( QObject *o, QEvent *e )
00183 {
00184 //Qtrootlockguard threadlock;
00185   // Filtering of QWidget Events
00186   //cout <<"TQRootWindow ::eventFilter" << endl;
00187   QMouseEvent* me=dynamic_cast<QMouseEvent*>(e);
00188   if(me)
00189    {
00190     //cout <<"TQRootWindow ::eventFilter has mouse event" << endl;
00191     Event_t* roote=MapQMouseEvent(me);
00192     if(fxRootwindow) fxRootwindow->HandleEvent(roote);
00193     delete roote;  
00194     return FALSE;
00195    }
00196   
00197   
00198   if ( e->type() == QEvent::Close) {  // close
00199         delete fxRootwindow;
00200         fxRootwindow=0;
00201         return FALSE;
00202        }
00203 
00204   // standard event processing
00205   return QWidget::eventFilter( o, e );
00206 }
00207 
00208 
00209 
00210 void  TQRootWindow::closeEvent( QCloseEvent * e){
00211    
00212     delete fxRootwindow;
00213     fxRootwindow=0;
00214     e->accept();
00215     return;
00216 }
00217 
00218 
00219 
00220 TQRootWindow::~TQRootWindow()
00221 {
00222     delete fxRootwindow;
00223     fxRootwindow=0;
00224 }
00225 
00226 TGCompositeFrame* TQRootWindow::GetRootFrame()
00227 { 
00228    return fxRootwindow;
00229 }
00230 
00231 
00232 //----------------------------END OF GO4 SOURCE FILE ---------------------

Generated on Tue Nov 8 10:56:09 2005 for Go4-v2.10-5 by doxygen1.2.15