00001
00002
00003
00004
00005
00006
00007 #include "QScreen.h"
00008
00009
00010 #include <iostream>
00011 using namespace std;
00012
00013
00014
00015
00016
00017 void QScreen::draw( QEvent* e )
00018 {
00019 glColor3f(0.3,0.3,0.5);
00020 glBegin(GL_POLYGON);
00021 LookAndFeel->drawRect(0,0,Width,Height);
00022 glEnd();
00023 }
00024
00025
00026 void QScreen::layout()
00027 {
00028 }
00029
00030
00031 bool QScreen::canDrag( QEvent* e )
00032 {
00033 return false;
00034 }
00035
00036
00037 bool QScreen::processEvent( QEvent* e )
00038 {
00039 return false;
00040 }
00041
00042
00043 bool QScreen::processMouseOwner( QEvent* e )
00044 {
00045 return false;
00046 }
00047
00048
00049 void QScreen::childrenChanged()
00050 {
00051 }
00052
00053
00054 bool QScreen::canFocus( QEvent* e )
00055 {
00056 return false;
00057 }
00058
00059
00060 void QScreen::Init()
00061 {
00062 LookAndFeel = new QLookAndFeel();
00063 }
00064
00065
00066 void QScreen::CleanUp()
00067 {
00068 delete LookAndFeel;
00069 }
00070
00071
00072 void QScreen::freeWidget( QWidget* widget )
00073 {
00074
00075 WidgetsToRemove.remove(widget);
00076
00077
00078 WidgetsToRemove.push_front(widget);
00079
00080 }
00081
00082
00083 void QScreen::remove( QWidget* widget )
00084 {
00085 if (FocusPath == widget) this->ScreenFocusedWidget = 0;
00086 QWidget::remove(widget);
00087 }
00088
00089
00090 void QScreen::sendEvent()
00091 {
00092 QWidget* w;
00093
00094 while (WidgetsToRemove.size() > 0)
00095 {
00096 w = WidgetsToRemove.front();
00097 if (w->getOwner()) w->getOwner()->remove(w);
00098 delete w;
00099 WidgetsToRemove.pop_front();
00100 }
00101 event(LastEvent);
00102 }
00103
00104
00105 void QScreen::redraw()
00106 {
00107 glutPostRedisplay();
00108 }
00109
00110
00111 void QScreen::glutResize( int width , int height )
00112 {
00113 }
00114
00115
00116 void QScreen::glutKeyboard( unsigned char key , int x , int y )
00117 {
00118 LastEvent->setType(etKeyboard);
00119 LastEvent->setKey(key);
00120 LastEvent->setX(x);
00121 LastEvent->setY(y);
00122 sendEvent();
00123 redraw();
00124 }
00125
00126
00127 void QScreen::glutKeyboardUp( unsigned char key , int x , int y )
00128 {
00129 LastEvent->setType(etKeyboardUp);
00130 LastEvent->setKey(key);
00131 LastEvent->setX(x);
00132 LastEvent->setY(y);
00133 sendEvent();
00134 redraw();
00135 }
00136
00137
00138 void QScreen::glutSpecialFunc( int key , int x , int y )
00139 {
00140 LastEvent->setType(etSpecialKey);
00141 LastEvent->setKey(key);
00142 LastEvent->setX(x);
00143 LastEvent->setY(y);
00144 sendEvent();
00145 redraw();
00146 }
00147
00148
00149 void QScreen::glutMotion( int x , int y )
00150 {
00151 LastEvent->setType(etMouseMotion);
00152 LastEvent->setX(x);
00153 LastEvent->setY(y);
00154 sendEvent();
00155 redraw();
00156 }
00157
00158
00159 void QScreen::glutMouse( int button , int state , int x , int y )
00160 {
00161 LastEvent->setX(x);
00162 LastEvent->setY(y);
00163
00164 switch (button)
00165 {
00166 case GLUT_LEFT_BUTTON: LastEvent->setButton(mbLeft);
00167 break;
00168 case GLUT_RIGHT_BUTTON: LastEvent->setButton(mbRight);
00169 break;
00170 case GLUT_MIDDLE_BUTTON: LastEvent->setButton(mbCenter);
00171 break;
00172 }
00173
00174 if (state == GLUT_DOWN)
00175 {
00176 LastEvent->setType(etMouseDown);
00177 sendEvent();
00178 }
00179 else if (state == GLUT_UP)
00180 {
00181 LastEvent->setType(etMouseUp);
00182 sendEvent();
00183 LastEvent->setType(etMouseClick);
00184 sendEvent();
00185 }
00186 redraw();
00187 }
00188
00189
00190 void QScreen::glutDisplay()
00191 {
00192 LastEvent->setType(etDraw);
00193 sendEvent();
00194 }
00195
00196
00197 void QScreen::requestFocus( QWidget* Sender , QWidget* FocusedWidget )
00198 {
00199 if ((FocusPath != 0) && (FocusPath != Sender))
00200 {
00201 FocusPath->clearFocusPath();
00202 }
00203
00204
00205 FocusPath = Sender;
00206 ScreenFocusedWidget = FocusedWidget;
00207
00208 redraw();
00209 }
00210
00211
00212 QWidget* QScreen::getScreenFocusedWidget()
00213 {
00214 return ScreenFocusedWidget;
00215 }
00216
00217
00218 void QScreen::setScreenFocusedWidget( QWidget* newValue )
00219 {
00220 ScreenFocusedWidget = newValue;
00221 }
00222
00223
00224 QEvent* QScreen::getLastEvent()
00225 {
00226 return LastEvent;
00227 }
00228
00229
00230
00231
00232 void QScreen::print()
00233 {
00234
00235 cout << "Class : QScreen" << endl;
00236
00237 cout << "ScreenFocusedWidget = " << ScreenFocusedWidget << endl;
00238 }
00239
00240
00241
00242
00243 QScreen::QScreen( QWidget* aOwner ):QWidget(aOwner)
00244 {
00245 ScreenFocusedWidget = 0;
00246 LastEvent = new QEvent;
00247 Init();
00248 layout();
00249 }
00250
00251
00252
00253
00254 QScreen::~QScreen()
00255 {
00256 delete LastEvent;
00257 CleanUp();
00258 }
00259
00260
00261
00262