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

James Bowlin bowlin at mindspring.com
Tue Aug 14 07:03:46 CEST 2007


SVN commit 699772 by jbowlin:

I fixed a problem with the star labels that caused ugly overlaps
when a star label got highlighted in the overlay.  This was more
complicated than I expected.  I think it is working now.  I'm
no longer filling the screen with labels that just say "star".
but the overlay highlight and the custom labels will still say
"star" if a star has no name and they will do so in a way that
will only overlap an existing label for the same star with the
exact same text.  The overlay can still overlap exiting labels
for other stars.

I'm also polluting the data directory with little Perl scripts
for manipulating the data files.

CCMAIL: kstars-devel at kde.org


 M  +8 -5      data/read-hippo.pl  
 A             data/sort-hip-by-pm.pl   data/read-hippo.pl#699589
 M  +1 -2      skymapdraw.cpp  
 M  +43 -12    starobject.cpp  
 M  +8 -1      starobject.h  


--- trunk/KDE/kdeedu/kstars/kstars/data/read-hippo.pl #699771:699772
@@ -9,6 +9,7 @@
 #    [90, 50], [50, 20], [20, -20], 
     [-20, -50], [-50, -90]);
 
+my $cnt;
 
 while(<>) {
     m/^\s*#/ and do {  next};
@@ -19,14 +20,16 @@
         next;
     };
     $star->{line} = $.;
+    $star->{name} or next;
     push @STARS, $star;
-    #$star->{name} or next;
     #print_star_line($star);
+
 }
 
- at STARS = sort { $b->{pm} <=> $a->{pm} } @STARS;
+ at STARS = sort { $b->{mag} <=> $a->{mag} } @STARS;
 for my $star ( @STARS ) {
-    print_star_line($star);
+	printf "%4.1f %s\n", $star->{mag}, $star->{name};
+	#print_star_line($star);
 }
 
 exit;
@@ -36,7 +39,7 @@
 
 sub print_star_line {
 	my $star = shift;
-    printf "%8.2f ", $star->{pm};
+	#printf "%8.2f ", $star->{pm};
 	printf "%s %s %s%s%s %s%s%s %s%s",
 	@$star{qw/ra_str dec_str dra ddec parallax mag bv_index spec_type mult/};
 	my $s2;
@@ -59,7 +62,7 @@
 
 
 sub print_stars {
-    my @stars = sort {$a->{ra} <=> $b->{ra}} @_;
+    my @stars = sort {$a->{mag} <=> $b->{mag}} @_;
     for my $dec_region (@DEC_REGIONS) {
         my ($top, $bot) = @$dec_region;
         print "\nFrom $top to $bot:\n";
--- trunk/KDE/kdeedu/kstars/kstars/skymapdraw.cpp #699771:699772
@@ -337,8 +337,7 @@
 			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);
+			QString sName = star->customLabel( Options::showStarNames(), Options::showStarMagnitudes() );
 			skyLabeler->drawLabel( psky, QPointF( o.x() + offset, o.y() + offset), sName );
 		}
 		else {
--- trunk/KDE/kdeedu/kstars/kstars/starobject.cpp #699771:699772
@@ -343,25 +343,56 @@
 		psky.drawEllipse( QRect( int(x - 0.5*size), int(y - 0.5*size), int(size), int(size) ) );
 }
 
+// The two routines below seem overly complicated but at least they are doing
+// the right thing now.  Please resist the temptation to simplify them unless
+// you are prepared to ensure there is no ugly label overlap for all 8 cases
+// they deal with ( drawName x DrawMag x star-has-name).  -jbb
+
 QString StarObject::nameLabel( bool drawName, bool drawMag )
 {
-	QString sName( i18n("star") + ' ' );
+	QString sName;
 	if ( drawName ) {
-		if ( translatedName() != i18n("star") && ! translatedName().isEmpty() )
-			sName = translatedName() + ' ';
-		else if ( ! gname().trimmed().isEmpty() ) sName = gname( true ) + ' ';
+	    if ( translatedName() != i18n("star") && ! translatedName().isEmpty() )
+			sName = translatedName();
+		else if ( ! gname().trimmed().isEmpty() ) 
+			sName = gname( true );
+		else {
+			if ( drawMag ) 
+				return QString().sprintf("%.1f", mag() );
+		}	
+		if ( ! drawMag )
+			return sName;
+		else
+			return sName + QString().sprintf(" %.1f", mag() );
 	}
-	if ( drawMag ) {
-		if ( drawName )
-			sName += QString().sprintf("%.1f", mag() );
+	return QString().sprintf("%.1f", mag() );
+}
+
+QString StarObject::customLabel( bool drawName, bool drawMag )
+{
+	QString sName;
+	if ( translatedName() != i18n("star") && ! translatedName().isEmpty() )
+		sName = translatedName();
+	else if ( ! gname().trimmed().isEmpty() ) 
+		sName = gname( true );
+	else
+		sName = i18n("star");
+
+	if ( drawMag  && drawName ) {
+		if ( sName == i18n("star") ) 
+			return QString().sprintf("%.1f, ", mag() ) + sName;
 		else
-			sName.sprintf("%.1f", mag() );
-	}
+			return sName + QString().sprintf(" %.1f", mag() );
+	}	
+	else if ( drawMag && ! drawName ) 
+		return QString().sprintf("%.1f, ", mag() ) + sName;
+
 	return sName;
 }
 
-void StarObject::drawLabel( QPainter &psky, float x, float y, double zoom, bool drawName, bool drawMag, double scale ) {
-	QString sName = nameLabel( drawName, drawMag );
+void StarObject::drawLabel( QPainter &psky, float x, float y, double zoom, double scale )
+{
+	QString sName = customLabel( Options::showStarNames(), Options::showStarMagnitudes() );
 	float offset = scale * (6. + 0.5*( 5.0 - mag() ) + 0.01*( zoom/500. ) );
 
 	if ( Options::useAntialias() )
@@ -374,6 +405,6 @@
 	//set the zoom-dependent font
 	QFont stdFont( psky.font() );
     SkyLabeler::setZoomFont( psky );
-	drawLabel( psky, x, y, Options::zoomFactor(), true, false, scale );
+	drawLabel( psky, x, y, Options::zoomFactor(), scale );
 	psky.setFont( stdFont );
 }
--- trunk/KDE/kdeedu/kstars/kstars/starobject.h #699771:699772
@@ -224,10 +224,17 @@
 			bool useRealColors, int scIntensity, bool drawMultiple=true, 
 			double scale=1.0 );
 
+	/* @short returns the name, the magnitude or both.
+	 */
 	QString nameLabel( bool drawName, bool drawMag );
 
-	void drawLabel( QPainter &psky, float x, float y, double zoom, bool drawName, bool drawMag, double scale );
+	/* @short does the same as above except when only the magnitude is selected
+	 * in which case it returns "$mag, name".  This prevents label overlap.
+	 */
+	QString customLabel( bool drawName, bool drawMag );
 
+	void drawLabel( QPainter &psky, float x, float y, double zoom, double scale );
+
 /**
 	*@short draw the star's name label on the map
 	*@param psky reference to the QPainter on which to draw (either the sky pixmap or printer device)


More information about the Kstars-devel mailing list