]> Git trees. - libqmvoc.git/commitdiff
Adding autorotation and the slots for zoomin/out. Benoit, I added the code but have...
authorCarsten Niehaus <cniehaus@gmx.de>
Wed, 28 Jun 2006 20:50:14 +0000 (20:50 +0000)
committerCarsten Niehaus <cniehaus@gmx.de>
Wed, 28 Jun 2006 20:50:14 +0000 (20:50 +0000)
CCMAIL:jacob@math.jussieu.fr

svn path=/trunk/KDE/kdeedu/kalzium/src/kalziumglwidget.h; revision=555971

kalzium/kalziumglwidget.cpp
kalzium/kalziumglwidget.h

index 1ca9145d113e23c77acbf8f24e55e0afc7380a91..3c3a4de87e6562454e428407b7eeaece6e3030c3 100644 (file)
@@ -21,6 +21,7 @@
 
 #include <QMouseEvent>
 #include <QListWidget>
+#include <QTimer>
 
 
 #ifdef USE_FPS_COUNTER
@@ -46,6 +47,10 @@ KalziumGLWidget::KalziumGLWidget( QWidget * parent )
        ChooseStylePreset( PRESET_SPHERES_AND_BICOLOR_BONDS );
        
        setMinimumSize( 100,100 );
+
+       QTimer *timer = new QTimer( this );
+       connect( timer, SIGNAL( timeout() ), this, SLOT( rotate() ) );
+       timer->start( 50 );
 }
 
 KalziumGLWidget::~KalziumGLWidget()
@@ -337,6 +342,29 @@ void KalziumGLWidget::mouseMoveEvent( QMouseEvent * event )
        }
 }
 
+void KalziumGLWidget::rotate( )
+{
+       kDebug() << "KalziumGLWidget::rotate()" << endl;
+       //TODO at this place we need a nice way to rotate
+       //based on certain values. For example, we could use two
+       //bool variables for x and y rotation. If x is true the 
+       //molecule will rotate in the x-axis, if false not. Same
+       //for y. 
+       //As I have no idea what this code is doing I just copy&pasted
+       //everything from the mousewheel method...
+       glPushMatrix();
+       glLoadIdentity();
+
+       //Benoit, I took those values pretty much at random,
+       //no idea what value is for what... :)
+       glRotated( 10.0, 0.0, 1.0, 0.0 );
+       glRotated( 10.0, 1.0, 0.0, 0.0 );
+       glMultMatrixd( m_RotationMatrix );
+       glGetDoublev( GL_MODELVIEW_MATRIX, m_RotationMatrix );
+       glPopMatrix();
+       updateGL();
+}
+
 void KalziumGLWidget::setupObjects()
 {
        int sphere_detail, cylinder_faces;
@@ -429,6 +457,24 @@ inline GLFLOAT KalziumGLWidget::atomRadius()
        return m_atomRadiusCoeff * m_molMinBondLength;
 }
 
+void KalziumGLWidget::slotZoomIn()
+{
+       //TODO
+       //This slot can be very easily accessed by simply calling it from
+       //the GUI. I guess we need a second pair of zoomin/out slots for 
+       //a more finegrained zooming. For example, if we use the mousewheel
+       //for zooming, we might want to use the delta()-value of the mouse-
+       //wheel as a factor.
+       //But as I have no idea how zooming works in OpenGL I cannot do the
+       //coding...
+}
+
+void KalziumGLWidget::slotZoomOut()
+{
+       //TODO
+       //Comment so slotZoomIn()
+}
+
 void KalziumGLWidget::slotSetMolecule( OpenBabel::OBMol* molecule )
 {
        if ( !molecule ) return;
index dd3ee429a8fe2cce837d2ed4693d9e87a17561ca..29e58c9ada75ccc768b5fe85502be7c64f786b7d 100644 (file)
@@ -152,10 +152,11 @@ class KalziumGLWidget : public QGLWidget
                virtual ~KalziumGLWidget();
 
                /**
-                * returns a pointer to the molecule being worked on
+                * @return Returns a pointer to the molecule being worked on
                 */
-               inline OpenBabel::OBMol* molecule () const
-                       { return m_molecule; }
+               OpenBabel::OBMol* molecule () const { 
+                       return m_molecule; 
+               }
        
        signals:
                /**
@@ -164,11 +165,28 @@ class KalziumGLWidget : public QGLWidget
                void atomsSelected( QList<OpenBabel::OBAtom*> atoms );
 
        public slots:
+               /**
+                * The autorotation timer ended so we have to move the molecule a bit more
+                * not needed I guess
+                */
+               void rotate();
+               
                /**
                 * sets the molecule which will be displayed
                 * @param molecule the molecule to render
                 */
                void slotSetMolecule( OpenBabel::OBMol* molecule );
+
+               /**
+                * zoom in by 10%
+                */
+               void slotZoomIn();
+               
+               /**
+                * zoom out by 10%
+                */
+               void slotZoomOut();
+
                
                /**
                 * Sets the detail-grade in a range from 0 to 2