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

James Bowlin bowlin at mindspring.com
Sun Aug 12 09:37:33 CEST 2007


SVN commit 699181 by jbowlin:

dded code to stop drawing labels over the 3 infoBoxes.  It usually
works but sometimes it doesn't especially when skewing.  I'm using
the same coordinates in the InfoBoxes class that are used to draw
the text strings.  It appears that those coordinates are jumping
around even though the info boxes stay at fixed positions.

Fixed a couple of bugs caused by moving drawLabel() outside the draw()
routine in Ecliptic and Equator.  In general, the order we draw the
labels is the opposite of the order we draw the objects/guides
because the priority in SkyLabeler is first-come first-served which
is the opposite of the z-buffer technique we use for objects/guides.
This is why I had to move the drawLabel() routines.

Fixed a bug in SkyLabeler that would occasionally cause an index
out of bounds crash.

Fixed a bug in LineListLabeler that would cause a crash if drawLabel()
was called before reset() was ever called.

CCMAIL:kstars-devel at kde.org



 M  +19 -0     infoboxes.cpp  
 M  +5 -0      infoboxes.h  
 M  +4 -0      skycomponents/ecliptic.cpp  
 M  +2 -0      skycomponents/equator.cpp  
 M  +6 -0      skycomponents/linelistlabel.cpp  
 M  +18 -2     skycomponents/skylabeler.cpp  
 M  +3 -1      skycomponents/skylabeler.h  
 M  +2 -1      skycomponents/skymapcomposite.cpp  


--- branches/work/kdeedu_kstars_htm/kstars/kstars/infoboxes.cpp #699180:699181
@@ -27,6 +27,7 @@
 #include "dms.h"
 #include "geolocation.h"
 #include "skypoint.h"
+#include "skycomponents/skylabeler.h"
 
 InfoBoxes::InfoBoxes( int w, int h, const QPoint &tp, bool tshade,
 		const QPoint &gp, bool gshade, const QPoint &fp, bool fshade,
@@ -127,6 +128,24 @@
 	}
 }
 
+void InfoBoxes::reserveBoxes( QPainter& psky )
+{
+	if ( ! isVisible() ) return;
+	SkyLabeler* skyLabeler = SkyLabeler::Instance();
+
+	if ( GeoBox->isVisible() ) {
+		skyLabeler->markRect( GeoBox->x(), GeoBox->y(), GeoBox->width(), GeoBox->height(), psky );
+	}
+
+	if ( TimeBox->isVisible() ) {
+		skyLabeler->markRect( TimeBox->x(), TimeBox->y(), TimeBox->width(), TimeBox->height(), psky );
+	}
+
+	if ( FocusBox->isVisible() ) {
+		skyLabeler->markRect( FocusBox->x(), FocusBox->y(), FocusBox->width(), FocusBox->height(), psky );
+	}
+}
+
 bool InfoBoxes::grabBox( QMouseEvent *e ) {
 	if ( GeoBox->rect().contains( e->pos() ) ) {
 		GrabbedBox = 1;
--- branches/work/kdeedu_kstars_htm/kstars/kstars/infoboxes.h #699180:699181
@@ -144,6 +144,11 @@
 			const QColor &grabColor=QColor("red"), const QColor &BGColor=QColor("black"),
 			unsigned int BGMode=0 );
 	
+	/* Use the SkyLabeler to reserve the space under to boxes to prevent labels
+ 	 * from overlapping the boxes.
+ 	 */
+	void reserveBoxes( QPainter& psky );
+
 /**Determine whether a mouse click occurred inside one of the infoboxes.
 	*Also, set the internal variable GrabBox to indicate which box was grabbed.
 	*Finally, set the internal variable GrabPos to record the relative position of the
--- branches/work/kdeedu_kstars_htm/kstars/kstars/skycomponents/ecliptic.cpp #699180:699181
@@ -41,6 +41,8 @@
 
 void Ecliptic::draw( KStars *kstars, QPainter &psky, double scale )
 {
+	if ( ! selected() ) return;
+
 	QColor color( kstars->data()->colorScheme()->colorNamed( "EclColor" ) );
 	psky.setPen( QPen( QBrush( color ), 1, Qt::SolidLine ) );
 
@@ -63,6 +65,8 @@
 
 void Ecliptic::drawLabel( KStars *kstars, QPainter& psky, double scale )
 {
+	if ( ! selected() ) return;
+
     QColor color( kstars->data()->colorScheme()->colorNamed( "EclColor" ) );
 	psky.setPen( QPen( QBrush( color ), 1, Qt::SolidLine ) );	
 
--- branches/work/kdeedu_kstars_htm/kstars/kstars/skycomponents/equator.cpp #699180:699181
@@ -72,6 +72,8 @@
 void Equator::drawLabel( KStars *kstars, QPainter& psky, double scale )
 {
 
+	if ( ! selected() ) return;
+
 	QColor color( kstars->data()->colorScheme()->colorNamed( "EqColor" ) );
 	psky.setPen( QPen( QBrush( color ), 1, Qt::SolidLine ) );
 
--- branches/work/kdeedu_kstars_htm/kstars/kstars/skycomponents/linelistlabel.cpp #699180:699181
@@ -29,6 +29,12 @@
 	: m_text( text )
 {
 	m_skyLabeler = SkyLabeler::Instance();
+
+	// prevent a crash if drawLabel() is called before reset()
+	for ( int i = 0; i < 4; i++ ) {
+		m_labList[i] = 0;
+		m_labIndex[i] = 0;
+	}
 }
 
 void LineListLabel::reset( QPainter &psky )
--- branches/work/kdeedu_kstars_htm/kstars/kstars/skycomponents/skylabeler.cpp #699180:699181
@@ -268,6 +268,22 @@
 	return markRegion( p.x(), maxX, p.y(), minY );
 }
 
+bool SkyLabeler::markRect( qreal x, qreal y, qreal width, qreal height, QPainter& psky )
+{
+	/***
+	QColor color( "red" );
+	psky.setPen( QPen( QBrush( color ), 1, Qt::SolidLine ) );	
+
+	qreal x2 = x + width;
+	qreal y2 = y + height;
+	psky.drawLine( QPointF( x, y ),  QPointF( x2, y ));
+	psky.drawLine( QPointF( x2, y ), QPointF( x2, y2 ));
+	psky.drawLine( QPointF( x2, y2 ),QPointF( x, y2 ));
+	psky.drawLine( QPointF( x, y2 ), QPointF( x,y ));
+	***/
+
+	return markRegion( x, x + width, y + height, y );
+}
 bool SkyLabeler::markRegion( qreal left, qreal right, qreal top, qreal bot )
 {
     if ( m_maxY < 1 ) {
@@ -294,13 +310,13 @@
     if ( minY > m_maxY ) minY = m_maxY;
 
 	if ( maxY < minY ) {
+		int temp = maxY;
 		maxY = minY;
-		minY = int( bot / m_yScale );
+		minY = temp;
 	}
 
     // check to see if we overlap any existing label
     // We must check all rows before we start marking
-
     for (int y = minY; y <= maxY; y++ ) {
         LabelRow* row = screenRows[ y ];
         int i;
--- branches/work/kdeedu_kstars_htm/kstars/kstars/skycomponents/skylabeler.h #699180:699181
@@ -28,7 +28,7 @@
 
 class QString;
 class QPointF;
-
+class KStars;
 class SkyMap;
 class QPainter;
 class LabelRun;
@@ -258,7 +258,9 @@
 		 */
 		bool markRegion( qreal left, qreal right, qreal top, qreal bot );
 
+		bool markRect( qreal x, qreal y, qreal width, qreal height, QPainter& psky );
 
+
 		//----- Diagnostics and Information -----//
 
 		/* @short diagnostic. the *percentage* of pixels that have been filled.
--- branches/work/kdeedu_kstars_htm/kstars/kstars/skycomponents/skymapcomposite.cpp #699180:699181
@@ -43,9 +43,9 @@
 #include "starcomponent.h"
 #include "satellitecomposite.h"
 
-//#include "ksfilereader.h"
 #include "skymesh.h"
 #include "skylabeler.h"
+#include "infoboxes.h"
 
 SkyMapComposite::SkyMapComposite(SkyComponent *parent, KStarsData *data) : 
     SkyComposite(parent), m_reindexNum( J2000 )
@@ -190,6 +190,7 @@
 
     m_skyLabeler->reset( m_map, psky, scale ); 
 	m_skyLabeler->useStdFont( psky );
+	ks->infoBoxes()->reserveBoxes( psky );
 
 	//TIMING
 	//QTime t;


More information about the Kstars-devel mailing list