00001 #include "QBackground_Streamline.h"
00002
00003 QBackground_Streamline::QBackground_Streamline(QWidget* parent ) : QObject(parent), QGLWidget(parent)
00004 {
00005 m_CanvasColor.setX(1.0f);
00006 m_CanvasColor.setY(1.0f);
00007 m_CanvasColor.setZ(1.0f);
00008
00009 glInit ();
00010 }
00011
00012
00013 QBackground_Streamline::~QBackground_Streamline()
00014 {
00015
00016 }
00017
00018 void QBackground_Streamline::setObjectName(const QString &name)
00019 {
00020 }
00021
00022
00023 void QBackground_Streamline::setStreamlinesColorPtr(VVector *v)
00024 {
00025 m_StreamlinesColor = v;
00026
00027 }
00028
00029
00030 void QBackground_Streamline::initializeGL()
00031 {
00032 this->makeCurrent();
00033
00034
00035 glClearColor( m_CanvasColor.getX(), m_CanvasColor.getY(), m_CanvasColor.getZ(), 1.0f );
00036 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00037 glEnable(GL_DEPTH_TEST);
00038
00039 }
00040
00041 void QBackground_Streamline::resizeGL( int w, int h )
00042 {
00043 this->makeCurrent();
00044
00045 glViewport(0, 0, w, h);
00046 gluOrtho2D(0, w, h, 0);
00047
00048 }
00049
00050 void QBackground_Streamline::paintGL()
00051 {
00052
00053 glClearColor( m_CanvasColor.getX(), m_CanvasColor.getY(), m_CanvasColor.getZ(), 1.0f );
00054 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00055 glEnable(GL_DEPTH_TEST);
00056
00057
00058
00059
00060 glPushAttrib(GL_ALL_ATTRIB_BITS);
00061
00062 glMatrixMode(GL_PROJECTION);
00063 glPushMatrix();
00064
00065 glMatrixMode(GL_MODELVIEW);
00066 glPushMatrix();
00067
00068 glLoadIdentity();
00069
00070
00071 glMatrixMode(GL_PROJECTION);
00072 glPopMatrix();
00073
00074 glMatrixMode(GL_MODELVIEW);
00075 glPopMatrix();
00076
00077 glPopAttrib();
00078 }
00079
00080 void QBackground_Streamline::redraw()
00081 {
00082 makeCurrent();
00083 repaint();
00084 swapBuffers();
00085 }
00086 void QBackground_Streamline::paintEvent( QPaintEvent *e )
00087 {
00088 QGLWidget::paintEvent(e);
00089 };
00090
00091 void QBackground_Streamline::mousePressEvent ( QMouseEvent * e )
00092 {
00093
00094 QColor qcolor = QColorDialog::getColor();
00095 VVector color((float)qcolor.red()/255.0f, (float)qcolor.green()/255.0f, (float)qcolor.blue()/255.0f);
00096 m_CanvasColor.setX((float)qcolor.red()/255.0f);
00097 m_CanvasColor.setY((float)qcolor.green()/255.0f);
00098 m_CanvasColor.setZ((float)qcolor.blue()/255.0f);
00099
00100 m_StreamlinesColor->setX(m_CanvasColor.getX());
00101 m_StreamlinesColor->setY(m_CanvasColor.getY());
00102 m_StreamlinesColor->setZ(m_CanvasColor.getZ());
00103
00104 redraw();
00105
00106 };
00107
00108 void QBackground_Streamline::mouseReleaseEvent ( QMouseEvent * e )
00109 {
00110
00111
00112 };
00113
00114 void QBackground_Streamline::mouseMoveEvent ( QMouseEvent * e )
00115 {
00116 const VMouseEvent me(getMouseEvent(e));
00117
00118
00119
00120
00121 const VVector v = me.getPosition();
00122
00123
00124
00125 };
00126
00127 void QBackground_Streamline::mouseDoubleClickEvent ( QMouseEvent * e )
00128 {
00129
00130 };
00131
00132 void QBackground_Streamline::keyPressEvent ( QKeyEvent * e )
00133 {
00134
00135
00136 };
00137
00138 void QBackground_Streamline::keyReleaseEvent ( QKeyEvent * e )
00139 {
00140
00141
00142 };
00143
00144 const VMouseEvent QBackground_Streamline::getMouseEvent (QMouseEvent *e)
00145 {
00146 const VVector vecPosition( (2.0f * float(e->x()) - float(width())) / float(width()),
00147 ( float(height()) - 2.0f * float(e->y())) / float(height()),
00148 0.0f);
00149 const int iButton =
00150 ((e->button() == Qt::LeftButton) ? VMouseEvent::BUTTON_LEFT :
00151 ((e->button() == Qt::MidButton) ? VMouseEvent::BUTTON_MIDDLE :
00152 ((e->button() == Qt::RightButton) ? VMouseEvent::BUTTON_RIGHT : VMouseEvent::BUTTON_NONE)));
00153
00154 const int iStateLeft = (e->buttons () & Qt::LeftButton) ? VMouseEvent::STATE_DOWN : VMouseEvent::STATE_UP;
00155 const int iStateMiddle = (e->buttons () & Qt::MidButton) ? VMouseEvent::STATE_DOWN : VMouseEvent::STATE_UP;
00156 const int iStateRight = (e->buttons () & Qt::RightButton) ? VMouseEvent::STATE_DOWN : VMouseEvent::STATE_UP;
00157
00158 const int iModifiers = ((e->modifiers() & Qt::ShiftModifier) ? VKeyboardEvent::MODIFIER_SHIFT : 0)
00159 | ((e->modifiers() & Qt::ControlModifier) ? VKeyboardEvent::MODIFIER_CTRL : 0)
00160 | ((e->modifiers() & Qt::AltModifier) ? VKeyboardEvent::MODIFIER_ALT : 0);
00161
00162 return VMouseEvent(vecPosition,iButton,iStateLeft,iStateMiddle,iStateRight,iModifiers);
00163
00164 };
00165
00166 const VKeyboardEvent QBackground_Streamline::getKeyboardEvent (QKeyEvent *e)
00167 {
00168 const int iKey = e->key();
00169
00170 const int iModifiers = ((e->modifiers() & Qt::ShiftModifier) ? VKeyboardEvent::MODIFIER_SHIFT : 0)
00171 | ((e->modifiers() & Qt::ControlModifier) ? VKeyboardEvent::MODIFIER_CTRL : 0)
00172 | ((e->modifiers() & Qt::AltModifier) ? VKeyboardEvent::MODIFIER_ALT : 0);
00173
00174 return VKeyboardEvent(iKey,iModifiers);
00175
00176 };