[Kstars-devel] KDE/kdeedu/kstars/kstars

Alexey Khudyakov alexey.skladnoy at gmail.com
Fri Mar 11 17:55:58 CET 2011


SVN commit 1224503 by khudyakov:

Use QToolTip for showing some info for object under cursor.
Much simpler than previous version also prettier and more informative

CCMAIL: kstars-devel at kde.org

 M  +8 -33     skymap.cpp  
 M  +3 -29     skymap.h  
 M  +2 -6      skymapevents.cpp  


--- trunk/KDE/kdeedu/kstars/kstars/skymap.cpp #1224502:1224503
@@ -21,6 +21,7 @@
 #include <QBitmap>
 #include <QPainter>
 #include <QPixmap>
+#include <QToolTip>
 #include <QTextStream>
 #include <QFile>
 #include <QPointF>
@@ -169,11 +170,10 @@
     setupProjector();
 
     //Initialize Transient label stuff
-    TransientTimeout = 100; //fade label color every 0.1 sec
+    HoverTimer.setInterval( 500 );
     HoverTimer.setSingleShot( true ); // using this timer as a single shot timer
 
     connect( &HoverTimer,     SIGNAL( timeout() ), this, SLOT( slotTransientLabel() ) );
-    connect( &TransientTimer, SIGNAL( timeout() ), this, SLOT( slotTransientTimeout() ) );
     connect( this, SIGNAL( destinationChanged() ), this, SLOT( slewFocus() ) );
 
     // Time infobox
@@ -356,11 +356,13 @@
         SkyObject *so = data->skyComposite()->objectNearest( &m_MousePoint, maxrad );
 
         if ( so && ! isObjectLabeled( so ) ) {
+            QToolTip::showText(
+                QCursor::pos(),
+                i18n("%1: %2<sup>m</sup>",
+                     so->translatedLongName(),
+                     QString::number(so->mag(), 'f', 1)),
+                this);
             setTransientObject( so );
-
-            TransientColor = data->colorScheme()->colorNamed( "UserLabelColor" );
-            if ( TransientTimer.isActive() ) TransientTimer.stop();
-            update();
         }
     }
 }
@@ -368,30 +370,6 @@
 
 //Slots
 
-void SkyMap::slotTransientTimeout() {
-    //Don't fade label if the transientObject is now the focusObject!
-    if ( transientObject() == focusObject() && Options::useAutoLabel() ) {
-        setTransientObject( NULL );
-        TransientTimer.stop();
-        return;
-    }
-
-    //to fade the labels, we will need to smoothly transition the alpha
-    //channel from opaque (255) to transparent (0) by step of stepAlpha
-    static const int stepAlpha = 12;
-
-    //Check to see if next step produces a transparent label
-    //If so, point TransientObject to NULL.
-    if ( TransientColor.alpha() <= stepAlpha ) {
-        setTransientObject( NULL );
-        TransientTimer.stop();
-    } else {
-        TransientColor.setAlpha(TransientColor.alpha()-stepAlpha);
-    }
-
-    update();
-}
-
 void SkyMap::setClickedObject( SkyObject *o ) {
 	  ClickedObject = o;
 }
@@ -878,9 +856,6 @@
                 }
 
                 slewing = true;
-                //since we are slewing, fade out the transient label
-                if ( transientObject() && ! TransientTimer.isActive() )
-                    fadeTransientLabel();
 
                 forceUpdate();
                 qApp->processEvents(); //keep up with other stuff
--- trunk/KDE/kdeedu/kstars/kstars/skymap.h #1224502:1224503
@@ -527,13 +527,6 @@
     virtual void resizeEvent( QResizeEvent * );
 
 private slots:
-    /**Gradually fade the Transient Hover Label into the background sky color, and
-    	*redraw the screen after each color change.  Once it has faded fully, set the 
-    	*TransientObject pointer to NULL to remove the label.
-    	*/
-    void slotTransientTimeout();
-
-    // NOTE: Akarsh believes that this method is backend-independent, and is pretty confident about that, but he thinks that it really requires a second inspection.
     /**@short attach transient label to object nearest the mouse cursor.
     	*This slot is connected to the timeout() signal of the HoverTimer, which is restarted
     	*in every mouseMoveEvent().  So this slot is executed only if the mouse does not move for 
@@ -550,35 +543,18 @@
 
 private:
 
-    /**@short Begin fading out the name label attached to TransientObject.
-    	*
-    	*mouseMoveEvent() will call fadeTransientLabel() when TransientObject is not a 
-    	*NULL pointer, and the TransientTimer is not already active.  These conditions 
-    	*are met when the mouse did not move for HOVER_INTERVAL msec (triggering a 
-    	*TransientLabel), but the mouse has since been moved, thus ending the Hover event.  
-    	*This function merely starts the TransientTimer, whose timeout SIGNAL is 
-    	*connected to the slotTransientTimeout() SLOT, which handles the actual fading 
-    	*of the transient label, and eventually resets TransientObject to NULL.
-    	*@sa SkyMap::slotTransientLabel(), SkyMap::slotTransientTimeout()
-    	*/
-    void fadeTransientLabel() { TransientTimer.start( TransientTimeout ); }
-
-    /**@short Sets the shape of the default mouse cursor to a cross.
-    	*/
+    /**@short Sets the shape of the default mouse cursor to a cross. */
     void setDefaultMouseCursor();
 
-    /**@short Sets the shape of the mouse cursor to a magnifying glass.
-    	*/
+    /**@short Sets the shape of the mouse cursor to a magnifying glass. */
     void setZoomMouseCursor();
 
     /** Calculate the zoom factor for the given keyboard modifier
-     * @param modifier
      */
     double zoomFactor( const int modifier );
 
     /** calculate the magnitude factor (1, .5, .2, or .1) for the given
      * keyboard modifier.
-     * @param modifier
      */
     double magFactor( const int modifier );
 
@@ -654,9 +630,7 @@
     QRect ZoomRect; //The manual-focus circle.
 
     //data for transient object labels
-    QTimer TransientTimer, HoverTimer;
-    QColor TransientColor;
-    unsigned int TransientTimeout;
+    QTimer HoverTimer;
 
     // InfoBoxes. Used in desctructor to save state
     InfoBoxWidget* m_timeBox;
--- trunk/KDE/kdeedu/kstars/kstars/skymapevents.cpp #1224502:1224503
@@ -25,6 +25,7 @@
 #include <QKeyEvent>
 #include <QKeySequence>
 #include <QPaintEvent>
+#include <QToolTip>
 
 #include <kstatusbar.h>
 #include <kio/job.h>
@@ -410,16 +411,11 @@
 
 void SkyMap::mouseMoveEvent( QMouseEvent *e ) {
     if ( Options::useHoverLabel() ) {
-        //First of all, if the transientObject() pointer is not NULL, then
-        //we just moved off of a hovered object.  Begin fading the label.
-        if ( transientObject() && ! TransientTimer.isActive() ) {
-            fadeTransientLabel();
-        }
-
         //Start a single-shot timer to monitor whether we are currently hovering.
         //The idea is that whenever a moveEvent occurs, the timer is reset.  It
         //will only timeout if there are no move events for HOVER_INTERVAL ms
         HoverTimer.start( HOVER_INTERVAL );
+        QToolTip::hideText();
     }
 
     //Are we defining a ZoomRect?


More information about the Kstars-devel mailing list