Eigene Dateien/FlowVis/src/QBackgroundCanvas.cpp

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

Generated on Mon Jan 21 01:15:15 2008 for FlowVis by  doxygen 1.5.4