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

James Bowlin bowlin at mindspring.com
Sun Aug 12 19:16:34 CEST 2007


SVN commit 699302 by jbowlin:

Fixed the bug where the ecliptic and equator labels were being drawn
on top of the filled horizon.  I did this by going back to drawing
those labels before drawing the horizon.  This gives those labels
a higher priority than the horizon label so I changed their position
priority so they more often draw on the left of the screen since the
horizon label is on the right.

Made changes to Horizon so the horizon label is never clipped by the
edge of the screen.  Made a new SkyLabeler::getMargins() function to
do this.

Fixed a bug I had introduced where the compass point labels would
disappear when their was no room for the horizon label.

Am I cc'ing too many minor htm branch changes?

CCMAIL: kstars-devel at kde.org


 M  +1 -0      ecliptic.cpp  
 M  +6 -0      equator.cpp  
 M  +2 -0      equator.h  
 M  +15 -5     horizoncomponent.cpp  
 M  +3 -14     linelistlabel.cpp  
 M  +13 -0     skylabeler.cpp  
 M  +6 -0      skylabeler.h  
 M  +2 -2      skymapcomposite.cpp  


--- branches/work/kdeedu_kstars_htm/kstars/kstars/skycomponents/ecliptic.cpp #699301:699302
@@ -60,6 +60,7 @@
 		else 
 			drawAllLinesInt( kstars, psky, scale );
 	}
+	m_label.draw( kstars, psky, scale );
 }
 
 
--- branches/work/kdeedu_kstars_htm/kstars/kstars/skycomponents/equator.cpp #699301:699302
@@ -46,6 +46,12 @@
 	m_label.reset( psky );
 }
 
+void Equator::draw( KStars *kstars, QPainter &psky, double scale )
+{
+	NoPrecessIndex::draw( kstars, psky, scale );
+	m_label.draw( kstars, psky, scale );
+}
+
 void Equator::init(KStarsData *data)
 {
 	KSNumbers num( data->ut().djd() );
--- branches/work/kdeedu_kstars_htm/kstars/kstars/skycomponents/equator.h #699301:699302
@@ -42,6 +42,8 @@
 
 		void preDraw( KStars *kstars, QPainter& psky );
 		
+		void draw( KStars *kstars, QPainter &psky, double scale );
+
 		void drawLabel( KStars *kstars, QPainter& psky, double scale );
 
 		void updateLabelCandidates( const QPointF& o, LineList* lineList, int i ) {
--- branches/work/kdeedu_kstars_htm/kstars/kstars/skycomponents/horizoncomponent.cpp #699301:699302
@@ -84,6 +84,13 @@
 	QPolygon groundPoly;
 	SkyPoint *pAnchor(0), *pAnchor2(0);
 
+ 	static const QString horizonLabel = i18n("Horizon");
+	float marginLeft, marginRight, marginTop, marginBot;
+	SkyLabeler::Instance()->getMargins( psky, horizonLabel, &marginLeft, &marginRight,
+			                            &marginTop, &marginBot );
+
+	printf("%.f %.f %.f %.f\n", marginLeft, marginRight, marginTop, marginBot );
+
 	psky.setPen( QPen( QColor( ks->data()->colorScheme()->colorNamed( "HorzColor" ) ), 2, Qt::SolidLine ) );
 
 	if ( Options::showGround() )
@@ -115,7 +122,7 @@
 					groundPoly << QPoint(int(o.x()),int(o.y()));
 
 				//Set the anchor point if this point is onscreen
-				if ( o.x() < Width && o.y() > 0. && o.y() < Height ) 
+				if ( o.x() < marginRight && o.y() > marginTop && o.y() < marginBot ) 
 					pAnchor = p;
 
 				if ( o.y() > 0. ) allGround = false;
@@ -135,7 +142,7 @@
 				groundPoly << QPoint(int(o.x()),int(o.y()));
 
 			//Set the anchor point if this point is onscreen
-			if ( o.x() < Width && o.y() > 0. && o.y() < Height ) 
+			if ( o.x() < marginRight && o.y() > marginTop && o.y() < marginBot ) 
 				pAnchor = p;
 
 			if ( o.y() > 0. ) allGround = false;
@@ -156,7 +163,7 @@
 					groundPoly << QPoint(int(o.x()),int(o.y()));
 
 				//Set the anchor point if this point is onscreen
-				if ( o.x() < Width && o.y() > 0. && o.y() < Height ) 
+				if ( o.x() < marginRight && o.y() > marginTop && o.y() < marginBot ) 
 					pAnchor = p;
 
 				if ( o.y() > 0. ) allGround = false;
@@ -288,7 +295,10 @@
 	//Draw Horizon name label
 	//pAnchor contains the last point of the Horizon before it went offcreen 
 	//on the right/top/bottom edge.  oAnchor2 is the next point after oAnchor.
-	if ( ! pAnchor )  return;
+	if ( ! pAnchor ) {
+		drawCompassLabels( ks, psky, scale );
+		return;
+	}
 
 	int iAnchor = pointList().indexOf( pAnchor );
 	if ( iAnchor == pointList().size()-1 ) iAnchor = 0;
@@ -355,7 +365,7 @@
 	if ( angle < -90.0 ) angle += 180.0;
 	if ( angle >  90.0 ) angle -= 180.0;
 
-	SkyLabeler::Instance()->drawLabel( psky, o1, i18n("Horizon"), angle );
+	SkyLabeler::Instance()->drawLabel( psky, o1, horizonLabel, angle );
 
 	drawCompassLabels( ks, psky, scale );
 }
--- branches/work/kdeedu_kstars_htm/kstars/kstars/skycomponents/linelistlabel.cpp #699301:699302
@@ -55,19 +55,8 @@
 	m_farTop   = 100000.0;
 	m_farBot   = 0.0;
 
-	// We don't draw the label here but we need the proper font in order to set
-	// the margins correctly.  Since psky no contains the zoom dependent font as
-	// its default font, we need to play the little dance below.
-	QFontMetricsF fm = skyLabeler()->fontMetrics();
-	float height     = fm.height();
-	float width      = fm.width( m_text );
-	float sideMargin = fm.width("MM") + width / 2.0;
-
-	// Create the margins within which it is okay to draw the label
-	m_marginRight = psky.window().width() - sideMargin;
-	m_marginLeft  = sideMargin;
-	m_marginTop   = height;
-	m_marginBot   = psky.window().height() - 2.0 * height;
+	skyLabeler()->getMargins( psky, m_text, &m_marginLeft, &m_marginRight,
+			                  &m_marginTop, &m_marginBot );
 }
 
 void LineListLabel::updateLabelCandidates( qreal x, qreal y, LineList* lineList, int i )
@@ -123,7 +112,7 @@
 
 	// We no longer adjust the order but if we were to it would be here
  	static int Order[4]  = 
-		 { RightCandidate, LeftCandidate, BotCandidate, TopCandidate }; 
+		 { LeftCandidate, BotCandidate, TopCandidate, LeftCandidate }; 
 
 	for ( int j = 0; j < 4; j++ ) {
 		idx[j]	= m_labIndex[ Order[ j ] ];
--- branches/work/kdeedu_kstars_htm/kstars/kstars/skycomponents/skylabeler.cpp #699301:699302
@@ -195,7 +195,20 @@
     setFont( psky, m_skyFont );
 }
 
+void SkyLabeler::getMargins( QPainter& psky, const QString& text, float *left,
+		                     float *right, float *top, float *bot )
+{
+	float height     = m_fontMetrics.height();
+	float width      = m_fontMetrics.width( text );
+	float sideMargin = m_fontMetrics.width("MM") + width / 2.0;
 
+	// Create the margins within which it is okay to draw the label
+	*right = psky.window().width() - sideMargin;
+	*left  = sideMargin;
+	*top   = height;
+	*bot   = psky.window().height() - 2.0 * height;
+}
+
 void SkyLabeler::reset( SkyMap* skyMap, QPainter& psky, double scale )
 {
     // ----- Set up Zoom Dependent Font -----
--- branches/work/kdeedu_kstars_htm/kstars/kstars/skycomponents/skylabeler.h #699301:699302
@@ -194,6 +194,12 @@
 
 		//----- Drawing/Adding Labels -----//
 
+		/* @short sets four margins for help in keeping labels entirely on the
+		 * screen.
+		 */
+		void getMargins( QPainter& psky, const QString& text, float *left,
+				         float *right, float *top, float *bot );
+
 		/* @short a convenience routine that draws the label specified
 		 * in the SkyLabel.
 		 */
--- branches/work/kdeedu_kstars_htm/kstars/kstars/skycomponents/skymapcomposite.cpp #699301:699302
@@ -266,8 +266,8 @@
 	m_Horizon->draw( ks, psky, scale );
 //	kDebug() << QString("Horizon     : %1 ms").arg( t.elapsed() ) << endl;
 
-	m_Ecliptic->drawLabel( ks, psky, scale );
-	m_Equator->drawLabel( ks, psky, scale );
+	//m_Ecliptic->drawLabel( ks, psky, scale );
+	//m_Equator->drawLabel( ks, psky, scale );
 
 	m_skyLabeler->resetFont( psky );
     m_skyLabeler->draw( ks, psky );


More information about the Kstars-devel mailing list