Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "QRootWindow.h"
00015
00016 #include "TSystem.h"
00017 #include "GuiTypes.h"
00018 #include "TGFrame.h"
00019 #include "Riostream.h"
00020
00021 #include <QPainter>
00022 #include <QMouseEvent>
00023 #include <QCloseEvent>
00024 #include <QPaintEvent>
00025
00026 #include "TGo4LockGuard.h"
00027
00029 class TQRootFrame: public TGCompositeFrame {
00030 public:
00032 TQRootFrame(Window_t id) :
00033 TGCompositeFrame(gClient, id, new TGMainFrame(gClient->GetDefaultRoot(),100,100))
00034 {
00035
00036
00037 }
00038
00039 virtual ~TQRootFrame()
00040 {
00041 delete fParent;
00042 }
00043
00044 virtual void CloseWindow()
00045 {
00046 UnmapWindow();
00047 }
00048
00049
00050
00051
00052
00053
00054
00055 };
00056
00057
00058
00060
00061
00062 QRootWindow::QRootWindow( QWidget *parent, const char *name, bool designermode) :
00063 QWidget(parent),
00064 fxRootwindow(0),
00065 fbResizeOnPaint(kTRUE)
00066 {
00067 setObjectName( name ? name : "QRootWindow");
00068
00069
00070 setUpdatesEnabled( true );
00071 setMouseTracking(true);
00072
00073 setFocusPolicy( Qt::TabFocus );
00074 setCursor( Qt::CrossCursor );
00075
00076 if(!designermode) {
00077
00078 fQtWinId = winId();
00079 fiWinid = gVirtualX->AddWindow((ULong_t)fQtWinId,145,400);
00080
00081 fxRootwindow = new TQRootFrame(gVirtualX->GetWindowID(fiWinid));
00082 fxRootwindow->Resize();
00083 if ( parent ) parent->installEventFilter( this );
00084 }
00085 }
00086
00087 void QRootWindow::AddSubFrame(TGFrame* f, TGLayoutHints* l)
00088 {
00089 fxRootwindow->AddFrame(f,l);
00090 fxRootwindow->MapWindow();
00091 fxRootwindow->MapSubwindows();
00092 fxRootwindow->Resize();
00093 ensurePolished();
00094 update();
00095 show();
00096 }
00097
00098 void QRootWindow::SetEditable(bool on)
00099 {
00100 fxRootwindow->SetEditable(on);
00101 }
00102
00103 Bool_t QRootWindow::MapQMouseEvent(QMouseEvent *e, Event_t* rev)
00104 {
00105 if((e==0) || (rev==0)) return kFALSE;
00106
00107 rev->fX=e->x();
00108 rev->fY=e->y();
00109 rev->fXRoot= e->globalX();
00110 rev->fYRoot= e->globalY();
00111
00112
00113 if(e->type() == QEvent::MouseButtonPress) rev->fType = kButtonPress;
00114 else if(e->type() == QEvent::MouseButtonRelease) rev->fType = kButtonRelease;
00115 else if(e->type() == QEvent::MouseButtonDblClick) rev->fType = kButtonDoubleClick;
00116 else if(e->type() == QEvent::MouseMove) rev->fType = kMotionNotify;
00117 else if(e->type() == QEvent::KeyPress) rev->fType = kGKeyPress;
00118 else if(e->type() == QEvent::KeyRelease) rev->fType = kKeyRelease;
00119 else rev->fType = kOtherEvent;
00120
00121
00122 rev->fState=0;
00123 if(e->buttons() & Qt::LeftButton)
00124 rev->fState |= kButton1Mask;
00125 if(e->buttons() & Qt::RightButton)
00126 rev->fState |= kButton3Mask;
00127 if(e->buttons() & Qt::MidButton)
00128 rev->fState |= kButton2Mask;
00129 if(e->buttons() & Qt::MouseButtonMask)
00130 rev->fState |= kButton1Mask;
00131
00132 if(e->modifiers() & Qt::ShiftModifier)
00133 rev->fState |= kKeyShiftMask;
00134 if(e->modifiers() & Qt::ControlModifier)
00135 rev->fState |= kKeyControlMask;
00136 if(e->modifiers() & Qt::AltModifier)
00137 rev->fState |= kKeyMod1Mask;
00138 if(e->modifiers() & Qt::MetaModifier)
00139 rev->fState |= kKeyMod1Mask;
00140
00141
00142
00143
00144
00145 rev->fCode = Qt::NoButton;
00146 if(e->button() == Qt::LeftButton)
00147 rev->fCode |= kButton1Mask;
00148 if(e->button() == Qt::RightButton)
00149 rev->fCode |= kButton3Mask;
00150 if(e->button() == Qt::MidButton)
00151 rev->fCode |= kButton2Mask;
00152
00153 rev->fUser[0]=0;
00154 rev->fWindow = gVirtualX->GetWindowID(fiWinid);
00155 rev->fSendEvent = 0;
00156 rev->fTime = 0;
00157
00158 return kTRUE;
00159 }
00160
00161
00162
00163 void QRootWindow::paintEvent( QPaintEvent * e)
00164 {
00165
00166
00167 if(fxRootwindow) {
00168 WId nxid = winId();
00169 if(fQtWinId!=nxid) {
00170 TGo4LockGuard threadlock(0,true);
00171
00172 std::cout <<"Warning: QRootWindow::paintEvent finds changed X window id: "<< (ULong_t) winId()<<", previous:"<<fQtWinId << std::endl;
00173 delete fxRootwindow;
00174 fQtWinId = nxid;
00175 fiWinid = gVirtualX->AddWindow((ULong_t) fQtWinId, width(), height());
00176 fxRootwindow = new TQRootFrame(gVirtualX->GetWindowID(fiWinid));
00177 }
00178 if(fbResizeOnPaint) {
00179 TGo4LockGuard threadlock(0,true);
00180
00181 fxRootwindow->Resize(width(),height());
00182 gVirtualX->Update(1);
00183 }
00184 }
00185 QWidget::paintEvent(e);
00186 }
00187
00188 bool QRootWindow ::eventFilter( QObject *o, QEvent *e )
00189 {
00190 TGo4LockGuard threadlock(0,true);
00191 QMouseEvent* me = dynamic_cast<QMouseEvent*>(e);
00192
00193 Event_t root_evnt;
00194
00195 if (MapQMouseEvent(me, &root_evnt)) {
00196 if(fxRootwindow) fxRootwindow->HandleEvent(&root_evnt);
00197 return false;
00198 }
00199
00200 if ( e->type() == QEvent::Close) {
00201 delete fxRootwindow;
00202 fxRootwindow = 0;
00203 return false;
00204 }
00205
00206
00207 return QWidget::eventFilter( o, e );
00208 }
00209
00210 void QRootWindow::closeEvent( QCloseEvent * e)
00211 {
00212 if (fxRootwindow) {
00213 delete fxRootwindow;
00214 fxRootwindow = 0;
00215 }
00216 e->accept();
00217 }
00218
00219 QRootWindow::~QRootWindow()
00220 {
00221 if (fxRootwindow) {
00222 delete fxRootwindow;
00223 fxRootwindow = 0;
00224 }
00225 }
00226
00227 TGCompositeFrame* QRootWindow::GetRootFrame()
00228 {
00229 return fxRootwindow;
00230 }