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

Jason Harris kstars at 30doradus.org
Mon Jul 24 02:50:31 CEST 2006


SVN commit 565654 by harris:

Improvements to AltVsTime tool.  I restored the crosshairs that appear 
when clicking or dragging the mouse to aid in measuring altitudes and 
times in the plot.  In addition, the altitude and time of the crosshairs 
are now labeled on the plot.  The time of the "Now" line is also 
labeled.

CCMAIL: kstars-devel at kde.org



 M  +41 -12    tools/altvstime.cpp  
 M  +8 -1      tools/altvstime.h  
 M  +1 -1      widgets/kstarsplotwidget.cpp  


--- trunk/KDE/kdeedu/kstars/kstars/tools/altvstime.cpp #565653:565654
@@ -426,7 +426,7 @@
                                 delete oldNum;
 				oldNum = 0;
 			}
-                        o->EquatorialToHorizontal( ks->LST(), ks->geo()->lat() );
+			o->EquatorialToHorizontal( ks->LST(), ks->geo()->lat() );
 		} else {  //assume unfound object is a custom object
 			pList.at(i)->updateCoords( num ); //precess to desired epoch
 
@@ -507,12 +507,19 @@
 	//Default SunRise/SunSet values
 	SunRise = 0.25;
 	SunSet = 0.75;
+
+	MousePoint = QPoint( -1.0, -1.0 );
 }
 
 void AVTPlotWidget::mousePressEvent( QMouseEvent *e ) {
 	mouseMoveEvent( e );
 }
 
+void AVTPlotWidget::mouseDoubleClickEvent( QMouseEvent * ) {
+	MousePoint = QPoint(-1, -1);
+	update();
+}
+
 void AVTPlotWidget::mouseMoveEvent( QMouseEvent *e ) {
 	QRect checkRect( leftPadding(), topPadding(), PixRect.width(), PixRect.height() );
 	int Xcursor = e->x();
@@ -528,15 +535,8 @@
 	Xcursor -= leftPadding();
 	Ycursor -= topPadding();
 
-//	QPixmap buffer2( *buffer );
-	QPainter p;
-	p.begin( this );
-	p.translate( leftPadding(), topPadding() );
-	p.setPen( QPen( QBrush("grey"), 1.0, Qt::SolidLine ) );
-	p.drawLine( Xcursor, 0, Xcursor, PixRect.height() );
-	p.drawLine( 0, Ycursor, PixRect.width(), Ycursor );
-	p.end();
-//	bitBlt( this, 0, 0, &buffer2 );
+	MousePoint = QPoint( Xcursor, Ycursor );
+	update();
 }
 
 void AVTPlotWidget::paintEvent( QPaintEvent */*e*/ ) {
@@ -587,9 +587,38 @@
 	p.setPen( QPen( QBrush("white"), 2.0, Qt::DotLine ) );
 	p.drawLine( ix, 0, ix, pH );
 
+	//Label this vertical line with the current time
+	p.save();
+	QFont smallFont = p.font();
+	smallFont.setPointSize( smallFont.pointSize() - 3 );
+	p.setFont( smallFont );
+	p.translate( ix + 10, pH - 20 );
+	p.rotate(-90);
+	p.drawText(0, 0, t.toString( "hh:mm" ) );
+	p.restore();
+
+	//Draw crosshairs at clicked position
+	if ( MousePoint.x() > 0 ) {
+		p.setPen( QPen( QBrush("gold"), 1.0, Qt::SolidLine ) );
+		p.drawLine( MousePoint.x(), 0, MousePoint.x(), PixRect.height() );
+		p.drawLine( 0, MousePoint.y(), PixRect.width(), MousePoint.y() );
+		
+		//Label each crosshair line (time and altitude)
+		p.setFont( smallFont );
+		double a = (pH - MousePoint.y())*180.0/pH - 90.0;
+		p.drawText( 20, MousePoint.y() + 10, QString::number(a,'f',2) + QChar(176) );
+	
+		double h = MousePoint.x()*24.0/pW - 12.0;
+		if ( h < 0.0 ) h += 24.0;
+		t = QTime( int(h), int(60.*(h - int(h))) );
+		p.save();
+		p.translate( MousePoint.x() + 10, pH - 20 );
+		p.rotate(-90);
+		p.drawText( 0, 0, t.toString("hh:mm") );
+		p.restore();
+	}
+
 	p.end();
-
-//	bitBlt( this, 0, 0, buffer );
 }
 
 #include "altvstime.moc"
--- trunk/KDE/kdeedu/kstars/kstars/tools/altvstime.h #565653:565654
@@ -82,16 +82,23 @@
 	*/
 	void mouseMoveEvent( QMouseEvent *e );
 	
-/**Simply calls mouseMoveEvent().
+/**
+	*Simply calls mouseMoveEvent().
 	*/
 	void mousePressEvent( QMouseEvent *e );
 	
+/**
+	*Reset the MousePoint to a null value, to erase the crosshairs
+	*/
+	void mouseDoubleClickEvent( QMouseEvent *e );
+
 /**Redraw the plot.
 	*/
 	void paintEvent( QPaintEvent *e );
 
 private: 
 	double SunRise, SunSet;
+	QPoint MousePoint;
 };
 
 /**@class AltVsTime
--- trunk/KDE/kdeedu/kstars/kstars/widgets/kstarsplotwidget.cpp #565653:565654
@@ -386,7 +386,7 @@
 					}
 					case ANGLE :
 					{
-						QString str = QString().sprintf( "%d%c", int(lab), 176 );
+						QString str = QString::number( int(lab) ) + QChar(176);
 						if ( px > 0 && px < pW ) {
 							QRect r( px - BIGTICKSIZE, pH+BIGTICKSIZE, 2*BIGTICKSIZE, BIGTICKSIZE );
 							p->drawText( r, Qt::AlignCenter | Qt::TextDontClip, str );


More information about the Kstars-devel mailing list