[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdeedu/kstars/kstars
From:       Akarsh Simha <akarshsimha () gmail ! com>
Date:       2011-01-01 4:27:24
Message-ID: 20110101042724.28D4BAC8B8 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1210553 by asimha:

Okay, dynamic switching between OpenGL and Native backends!

Bugs: Enable InfoBoxes. Nothing works as expected. You can't pan the
SkyMap, the background is repainted while using OpenGL.

TODO:

+ Get CMake to setup HAVE_OPENGL in the config.

+ Fix those bugs

 M  +37 -55    skymap.cpp  
 M  +16 -5     skymap.h  
 M  +1 -1      skymapevents.cpp  


--- trunk/KDE/kdeedu/kstars/kstars/skymap.cpp #1210552:1210553
@@ -147,7 +147,7 @@
     QGraphicsView( KStars::Instance() ),
     computeSkymap(true), angularDistanceMode(false), scrollCount(0),
     data( KStarsData::Instance() ), pmenu(0),
-    ClickedObject(0), FocusObject(0), TransientObject(0), m_proj(0), \
m_SkyMapDraw(NULL) +    ClickedObject(0), FocusObject(0), TransientObject(0), \
m_proj(0)  {
     m_Scale = 1.0;
 
@@ -173,7 +173,6 @@
     FocusObject = NULL;
 
     m_SkyMapDraw = 0;
-    m_SkyMapDrawWidget = 0;
 
     pmenu = new KSPopupMenu();
 
@@ -225,33 +224,26 @@
     m_iboxes->addInfoBox(m_geoBox);
     m_iboxes->addInfoBox(m_objBox);
 
+#ifdef HAVE_OPENGL
 
-    // TODO: Duplicated code. Please do something better
+    Q_ASSERT( TextureManager::getContext() ); // Should not fail, because \
TextureManager should be already created.  
-    #ifdef HAVE_OPENGL
-    kDebug() << "We have OpenGL! Do you?";
-    // TODO: Can this code be written more elegantly? Or is it a bad idea to cast?
-    if( !Options::useGL() ) {
-        SkyMapQDraw *smqd = new SkyMapQDraw( this );
-        // NOTE: Two different kinds of casts here
-        m_SkyMapDrawWidget = smqd;
-        m_SkyMapDraw = smqd;
+    m_SkyMapQDraw = new SkyMapQDraw( this );
+    m_SkyMapGLDraw = new SkyMapGLDraw( this );
+    m_SkyMapGLDraw->hide();
+    m_SkyMapQDraw->hide();
         
-        smqd->setParent( this->viewport() );
-        smqd->show();
-    }
+    if( Options::useGL() )
+        m_SkyMapDraw = m_SkyMapGLDraw;
     else 
+        m_SkyMapDraw = m_SkyMapQDraw;
+
+#else
+    m_SkyMapDraw = new SkyMapQDraw( this );
     #endif
-    {
-        SkyMapGLDraw *smgld = new SkyMapGLDraw( this );
-        Q_ASSERT( TextureManager::getContext() ); // Should not fail, because \
                TextureManager should be already created.
-        // NOTE: Two different kinds of casts here
-        m_SkyMapDrawWidget = smgld;
-        m_SkyMapDraw = smgld;
 
-        smgld->setParent( this->viewport() );
-        smgld->show();
-    }
+    m_SkyMapDraw->setParent( this->viewport() );
+    m_SkyMapDraw->show();
 
     //The update timer will be destructed when SkyMap is..
     QTimer *update = new QTimer(this);
@@ -306,7 +298,13 @@
         Options::setFocusDec( focus()->dec().Degrees() );
     }
 
-    delete m_SkyMapDrawWidget;
+#ifdef HAVE_OPENGL
+    delete m_SkyMapGLDraw;
+    delete m_SkyMapQDraw;
+    m_SkyMapDraw = 0; // Just a formality
+#else
+    delete m_SkyMapDraw;
+#endif
 
     delete pmenu;
 
@@ -933,18 +931,11 @@
 
     // Ensure that stars are recomputed
     data->incUpdateID();
-    /*
+
     if( now )
-        repaint();
+        m_SkyMapDraw->repaint();
     else
-        update();
-    */
-    m_SkyMapDrawWidget->repaint(); // DEBUG: Testing.
-    /*
-    // DEBUG: For GL, here's something to try
-    QGLWidget *w = dynamic_cast<QGLWidget *>( m_SkyMapDrawWidget );
-    w->updateGL();
-    */
+        m_SkyMapDraw->update();
     
 }
 
@@ -1079,43 +1070,34 @@
 
 #ifdef HAVE_OPENGL
 void SkyMap::slotToggleGL() {
-    kDebug() << "We have OpenGL! Do you?";
 
-    delete m_SkyMapDrawWidget;
+    Q_ASSERT( m_SkyMapGLDraw );
+    Q_ASSERT( m_SkyMapQDraw );
 
-    // TODO: Can this code be written more elegantly? Or is it a bad idea to cast?
+    m_SkyMapDraw->setParent( 0 );
+    m_SkyMapDraw->hide();
+
     if( Options::useGL() ) {
+        // Do NOT use GL
         Options::setUseGL( false );
-
-        SkyMapQDraw *smqd = new SkyMapQDraw( this );
-        // NOTE: Two different kinds of casts here
-        m_SkyMapDrawWidget = smqd;
-        m_SkyMapDraw = smqd;
-        
-        smqd->setParent( this->viewport() );
-        smqd->show();
-        
+        m_SkyMapDraw = m_SkyMapQDraw;
         KStars::Instance()->actionCollection()->action( "opengl" \
)->setText(i18n("Switch to OpenGL backend"));  }
     else {
+        // Use GL
         Options::setUseGL( true );
 
-        SkyMapGLDraw *smgld = new SkyMapGLDraw( this );
         Q_ASSERT( TextureManager::getContext() ); // Should not fail, because \
                TextureManager should be already created.
-        // NOTE: Two different kinds of casts here
-        m_SkyMapDrawWidget = smgld;
-        m_SkyMapDraw = smgld;
 
-        smgld->setParent( this->viewport() );
-        smgld->show();
-
+        m_SkyMapDraw = m_SkyMapGLDraw;
         KStars::Instance()->actionCollection()->action( "opengl" \
)->setText(i18n("Switch to QPainter backend"));  }
+    m_SkyMapDraw->setParent( viewport() );
+    m_SkyMapDraw->show();
+    m_SkyMapDraw->resize( size() );
 }
 #endif
     
-    
-
 #ifdef HAVE_XPLANET
 void SkyMap::startXplanet( const QString & outputFile ) {
     QString year, month, day, hour, minute, seconde, fov;
--- trunk/KDE/kdeedu/kstars/kstars/skymap.h #1210552:1210553
@@ -53,6 +53,11 @@
 
 class QGraphicsScene;
 
+#ifdef HAVE_OPENGL
+class SkyMapGLDraw;
+class SkyMapQDraw;
+#endif
+
 /**@class SkyMap
 	*
 	*This is the canvas on which the sky is painted.  It's the main widget for KStars.
@@ -294,15 +299,16 @@
         @return a pointer to the current projector. */
     const Projector * projector() const;
 
+    // NOTE: These dynamic casts must not segfault. If they do, it's good because we \
know that there is a problem.  /**
      *@short Proxy method for SkyMapDrawAbstract::exportSkyImage()
      */
-    void exportSkyImage( QPaintDevice *pd ) { m_SkyMapDraw->exportSkyImage( pd ); }
+    inline void exportSkyImage( QPaintDevice *pd ) { dynamic_cast<SkyMapDrawAbstract \
*>(m_SkyMapDraw)->exportSkyImage( pd ); }  
     /**
      *@short Proxy method for SkyMapDrawAbstract::drawObjectLabels()
      */
-    void drawObjectLabels( QList< SkyObject* >& labelObjects ) { \
m_SkyMapDraw->drawObjectLabels( labelObjects ); } +    inline void drawObjectLabels( \
QList< SkyObject* >& labelObjects ) { dynamic_cast<SkyMapDrawAbstract \
*>(m_SkyMapDraw)->drawObjectLabels( labelObjects ); }  
 
 
@@ -662,10 +668,15 @@
     InfoBoxWidget* m_objBox;
     InfoBoxes*     m_iboxes;
 
-    // Note: These two point to the same stuff
-    SkyMapDrawAbstract *m_SkyMapDraw;
-    QWidget *m_SkyMapDrawWidget;
 
+    QWidget *m_SkyMapDraw; // Can be dynamic_cast<> to SkyMapDrawAbstract
+
+    // NOTE: These are pointers to the individual widgets
+    #ifdef HAVE_OPENGL
+    SkyMapQDraw *m_SkyMapQDraw;
+    SkyMapGLDraw *m_SkyMapGLDraw;
+    #endif
+
     QGraphicsScene *m_SkyScene;
 
     static SkyMap* pinstance;
--- trunk/KDE/kdeedu/kstars/kstars/skymapevents.cpp #1210552:1210553
@@ -59,7 +59,7 @@
 
     // TODO: Hopefully the child QWidget / QGLWidget will scale automatically...
     // No, it doesn't seem to:
-    m_SkyMapDrawWidget->resize( size() );
+    m_SkyMapDraw->resize( size() );
 
     // Resize infoboxes container.
     // FIXME: this is not really pretty. Maybe there are some better way to this???


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic