[Kstars-devel] branches/work/kdeedu_kstars_htm/kstars/kstars

James Bowlin bowlin at mindspring.com
Mon Aug 13 01:35:19 CEST 2007


SVN commit 699409 by jbowlin:

As per Jason's suggestion, am now using the Skylabeler to draw the
custom labels and the central focus label so other labels won't over
overlap with them.  I've never seen the central focus label so maybe
it's not working.  If it starts working again then we will need to fix
the star names like the fix I implemented below for the custom labels.  

These labels used to use SkyObject::drawNameLabel() which has NOT been
re-implemented with SkyLabeler.  This routine is what draws the labels
that magically appear near the cursor.  If I had used SkyLabeler here
then those labels would never appear when the normal label was already
drawn.  But since the custom labels are "attached to the skymap" they
do need to use SkyLabeler, hence the change.

I also fixed two bugs (I think) in SkyMap::drawObjectLabels().  We
were returning from the routine whenever the list contained an object
of a type that was not currently being displayed so I changed all the
return's to continue's.  Second, we weren't displaying the names of
stars properly.  For example stars with genitive names were being
labeled as "star".  I fixed this too.  Since the code to create the
label name for a star was now in three places, StarObject,
StarComponent, and SkyMap, I made StarObject::labelName so the code is
now only in one spot. I probably should have done something similar
with the offset for the star labels but I didn't.

Despite the minor bug fixes, SkyMap::drawObjectLabels() should
probably be refactored someday especially if users might make a large
number of custom labels.

CCMAIL: kstars-devel at kde.org


 M  +2 -19     skycomponents/starcomponent.cpp  
 M  +42 -25    skymapdraw.cpp  
 M  +6 -1      starobject.cpp  
 M  +2 -0      starobject.h  


--- branches/work/kdeedu_kstars_htm/kstars/kstars/skycomponents/starcomponent.cpp #699408:699409
@@ -175,6 +175,7 @@
     double zoom = Options::zoomFactor();
 
     bool drawMag = Options::showStarMagnitudes();
+	bool drawName = Options::showStarNames();
 
 	//Loop for drawing star images
     MeshIterator region(m_skyMesh, DRAW_BUF);
@@ -207,26 +208,8 @@
             if ( mag > labelMagLim ) continue;
             //if ( checkSlewing || ! (Options::showStarMagnitudes() || Options::showStarNames()) ) continue;
 
-            // NOTE: the code below was copied here from StarObject.  Perhaps
-            // there is a cleaner way. -jbb
             float offset = scale * (6. + 0.5*( 5.0 - mag ) + 0.01*( zoom/500. ) );
-
-            //bool drawName = ( Options::showStarNames() && curStar->name() != i18n("star") );
-            bool drawName = ( Options::showStarNames() );
-
-            QString sName( i18n("star") + ' ' );
-            if ( drawName ) {
-                if ( curStar->translatedName() != i18n("star") && ! curStar->translatedName().isEmpty() )
-                    sName = curStar->translatedName() + ' ';
-                else if ( ! curStar->gname().trimmed().isEmpty() ) sName = curStar->gname( true ) + ' ';
-            }
-            if ( drawMag ) {
-                if ( drawName )
-                    sName += QString().sprintf("%.1f", curStar->mag() );
-                else
-                    sName.sprintf("%.1f", curStar->mag() );
-            }
-    
+			QString sName = curStar->nameLabel( drawName, drawMag );
 			SkyLabeler::Instance()->addLabel( QPointF( o.x() + offset, o.y() + offset), sName, STAR_LABEL );
 	    }
     }
--- branches/work/kdeedu_kstars_htm/kstars/kstars/skymapdraw.cpp #699408:699409
@@ -46,6 +46,7 @@
 #include "indidevice.h"
 #include "observinglist.h"
 #include "skycomponents/constellationboundary.h"
+#include "skycomponents/skylabeler.h"
 
 void toXYZ(SkyPoint* p, double *x, double *y, double *z) {
     double sinRa, sinDec, cosRa, cosDec;
@@ -280,6 +281,9 @@
 	float Width = scale * width();
 	float Height = scale * height();
 
+	SkyLabeler* skyLabeler = SkyLabeler::Instance();
+	skyLabeler->resetFont( psky );      // use the zoom dependent font
+
 	psky.setPen( data->colorScheme()->colorNamed( "UserLabelColor" ) );
 
 	bool checkSlewing = ( slewing || ( clockSlewing && data->clock()->isActive() ) ) && Options::hideOnSlew();
@@ -297,45 +301,58 @@
 		//Only draw an attached label if the object is being drawn to the map
 		//reproducing logic from other draw funcs here...not an optimal solution
 		if ( obj->type() == SkyObject::STAR ) {
-			if ( ! drawStars ) return;
-			if ( obj->mag() > Options::magLimitDrawStar() ) return;
-			if ( hideFaintStars && obj->mag() > Options::magLimitHideStar() ) return;
+			if ( ! drawStars ) continue;
+			if ( obj->mag() > Options::magLimitDrawStar() ) continue;
+			if ( hideFaintStars && obj->mag() > Options::magLimitHideStar() ) continue;
 		}
 		if ( obj->type() == SkyObject::PLANET ) {
-			if ( ! drawPlanets ) return;
-			if ( obj->name() == "Sun" && ! Options::showSun() ) return;
-			if ( obj->name() == "Mercury" && ! Options::showMercury() ) return;
-			if ( obj->name() == "Venus" && ! Options::showVenus() ) return;
-			if ( obj->name() == "Moon" && ! Options::showMoon() ) return;
-			if ( obj->name() == "Mars" && ! Options::showMars() ) return;
-			if ( obj->name() == "Jupiter" && ! Options::showJupiter() ) return;
-			if ( obj->name() == "Saturn" && ! Options::showSaturn() ) return;
-			if ( obj->name() == "Uranus" && ! Options::showUranus() ) return;
-			if ( obj->name() == "Neptune" && ! Options::showNeptune() ) return;
-			if ( obj->name() == "Pluto" && ! Options::showPluto() ) return;
+			if ( ! drawPlanets ) continue;
+			if ( obj->name() == "Sun" && ! Options::showSun() ) continue;
+			if ( obj->name() == "Mercury" && ! Options::showMercury() ) continue;
+			if ( obj->name() == "Venus" && ! Options::showVenus() ) continue;
+			if ( obj->name() == "Moon" && ! Options::showMoon() ) continue;
+			if ( obj->name() == "Mars" && ! Options::showMars() ) continue;
+			if ( obj->name() == "Jupiter" && ! Options::showJupiter() ) continue;
+			if ( obj->name() == "Saturn" && ! Options::showSaturn() ) continue;
+			if ( obj->name() == "Uranus" && ! Options::showUranus() ) continue;
+			if ( obj->name() == "Neptune" && ! Options::showNeptune() ) continue;
+			if ( obj->name() == "Pluto" && ! Options::showPluto() ) continue;
 		}
 		if ( obj->type() >= SkyObject::OPEN_CLUSTER && obj->type() <= SkyObject::GALAXY ) {
-			if ( ((DeepSkyObject*)obj)->isCatalogM() && ! drawMessier ) return;
-			if ( ((DeepSkyObject*)obj)->isCatalogNGC() && ! drawNGC ) return;
-			if ( ((DeepSkyObject*)obj)->isCatalogIC() && ! drawIC ) return;
-			if ( ((DeepSkyObject*)obj)->isCatalogNone() && ! drawOther ) return;
+			if ( ((DeepSkyObject*)obj)->isCatalogM() && ! drawMessier ) continue;
+			if ( ((DeepSkyObject*)obj)->isCatalogNGC() && ! drawNGC ) continue;
+			if ( ((DeepSkyObject*)obj)->isCatalogIC() && ! drawIC ) continue;
+			if ( ((DeepSkyObject*)obj)->isCatalogNone() && ! drawOther ) continue;
 		}
-		if ( obj->type() == SkyObject::COMET && ! drawComets ) return;
-		if ( obj->type() == SkyObject::ASTEROID && ! drawAsteroids ) return;
+		if ( obj->type() == SkyObject::COMET && ! drawComets ) continue;
+		if ( obj->type() == SkyObject::ASTEROID && ! drawAsteroids ) continue;
 
-		if ( checkVisibility( obj ) ) {
-			QPointF o = toScreen( obj, scale );
-			if ( o.x() >= 0. && o.x() <= Width && o.y() >= 0. && o.y() <= Height )
-				obj->drawNameLabel( psky, o.x(), o.y(), scale );
+		if ( ! checkVisibility( obj ) ) continue;
+		QPointF o = toScreen( obj, scale );
+		if ( ! (o.x() >= 0. && o.x() <= Width && o.y() >= 0. && o.y() <= Height ) ) continue;
+
+		if ( obj->type() == SkyObject::STAR ) {
+			StarObject* star = (StarObject*) obj;
+			float offset = scale * (6. + 0.5*( 5.0 - star->mag() ) 
+					+ 0.01 * ( Options::zoomFactor() /500. ) );
+			QString sName = star->nameLabel( Options::showStarNames(), Options::showStarMagnitudes() );
+			//kDebug() << QString("Star: %1\n").arg(sName);
+			skyLabeler->drawLabel( psky, QPointF( o.x() + offset, o.y() + offset), sName );
 		}
+		else {
+			skyLabeler->drawOffsetLabel( psky, o, obj->translatedName() );
+		}
 	}
 
 	//Attach a label to the centered object
 	if ( focusObject() != NULL && Options::useAutoLabel() ) {
 		QPointF o = toScreen( focusObject(), scale );
 		if ( o.x() >= 0. && o.x() <= Width && o.y() >= 0. && o.y() <= Height )
-			focusObject()->drawNameLabel( psky, o.x(), o.y(), scale );
+			skyLabeler->drawOffsetLabel( psky, o, focusObject()->translatedName() );
+			//focusObject()->drawNameLabel( psky, o.x(), o.y(), scale );
 	}
+
+	skyLabeler->useStdFont( psky );   // For the guides that all use the StdFont.
 }
 
 void SkyMap::drawTransientLabel( QPainter &p ) {
--- branches/work/kdeedu_kstars_htm/kstars/kstars/starobject.cpp #699408:699409
@@ -343,7 +343,8 @@
 		psky.drawEllipse( QRect( int(x - 0.5*size), int(y - 0.5*size), int(size), int(size) ) );
 }
 
-void StarObject::drawLabel( QPainter &psky, float x, float y, double zoom, bool drawName, bool drawMag, double scale ) {
+QString StarObject::nameLabel( bool drawName, bool drawMag )
+{
 	QString sName( i18n("star") + ' ' );
 	if ( drawName ) {
 		if ( translatedName() != i18n("star") && ! translatedName().isEmpty() )
@@ -356,7 +357,11 @@
 		else
 			sName.sprintf("%.1f", mag() );
 	}
+	return sName;
+}
 
+void StarObject::drawLabel( QPainter &psky, float x, float y, double zoom, bool drawName, bool drawMag, double scale ) {
+	QString sName = nameLabel( drawName, drawMag );
 	float offset = scale * (6. + 0.5*( 5.0 - mag() ) + 0.01*( zoom/500. ) );
 
 	if ( Options::useAntialias() )
--- branches/work/kdeedu_kstars_htm/kstars/kstars/starobject.h #699408:699409
@@ -224,6 +224,8 @@
 			bool useRealColors, int scIntensity, bool drawMultiple=true, 
 			double scale=1.0 );
 
+	QString nameLabel( bool drawName, bool drawMag );
+
 	void drawLabel( QPainter &psky, float x, float y, double zoom, bool drawName, bool drawMag, double scale );
 
 /**


More information about the Kstars-devel mailing list