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

Jason Harris kstars at 30doradus.org
Thu Jul 24 00:46:05 CEST 2008


SVN commit 837151 by harris:

Add custom CalendarWidget::drawAxes() function which labels the top
and bottom axes with time strings and places horizontal lines which
separate the months on the y-axis.

CCMAIL: kstars-devel at kde.org



 M  +50 -0     calendarwidget.cpp  
 M  +1 -1      calendarwidget.h  


--- trunk/KDE/kdeedu/kstars/kstars/tools/calendarwidget.cpp #837150:837151
@@ -25,6 +25,13 @@
 #include "kssun.h"
 #include "skycalendar.h"
 
+#define XPADDING 20
+#define YPADDING 20
+#define BIGTICKSIZE 10
+#define SMALLTICKSIZE 4
+#define TICKOFFSET 0
+
+
 CalendarWidget::CalendarWidget( QWidget *parent ) 
     : KPlotWidget( parent ) 
 {
@@ -92,4 +99,47 @@
     delete sun;
 }
 
+void CalendarWidget::drawAxes( QPainter *p ) {
+    p->setPen( foregroundColor() );
+    p->setBrush( Qt::NoBrush );
+
+    //Draw bounding box for the plot
+    p->drawRect( pixRect() );
+
+    //set small font for axis labels
+    QFont f = p->font();
+    int s = f.pointSize();
+    f.setPointSize( s - 2 );
+    p->setFont( f );
+
+    //Top/Bottom axis tickmarks and time labels
+    for ( float xx=-8.0; xx<= 8.0; xx += 2.0 ) {
+				int h = int(xx);
+				if ( h < 0 ) h += 24;
+				QString sTime = KGlobal::locale()->formatTime( QTime( h, 0, 0 ) );
+
+        QPointF pTick = mapToWidget( QPointF( xx, dataRect().y() ) );
+        p->drawLine( pTick, QPointF( pTick.x(), pTick.y() - BIGTICKSIZE ) );
+				QRectF r( pTick.x() - BIGTICKSIZE, pTick.y() + 0.5*BIGTICKSIZE, 2*BIGTICKSIZE, BIGTICKSIZE );
+				p->drawText( r, Qt::AlignCenter | Qt::TextDontClip, sTime );
+
+        pTick = QPointF( pTick.x(), 0.0 );
+        p->drawLine( pTick, QPointF( pTick.x(), pTick.y() + BIGTICKSIZE ) );
+				r.moveTop( -2.0*BIGTICKSIZE );
+				p->drawText( r, Qt::AlignCenter | Qt::TextDontClip, sTime );
+    }
+
+		
+    //Month dividers
+    SkyCalendar *skycal = (SkyCalendar*)topLevelWidget();
+    int y = skycal->year();
+    for ( int imonth=2; imonth <= 12; ++imonth ) {
+        QDate dt( y, imonth, 1 );
+        float doy = float( dt.daysInYear() - dt.dayOfYear() );
+        QPointF pdoy = mapToWidget( QPointF( dataRect().x(), doy ) );
+        p->drawLine( pdoy, QPointF( pixRect().right(), pdoy.y() ) );
+    }
+  
+}
+
 #include "calendarwidget.moc"
--- trunk/KDE/kdeedu/kstars/kstars/tools/calendarwidget.h #837150:837151
@@ -34,7 +34,7 @@
         
     private:
         void drawHorizon( QPainter *p );
-        
+				void drawAxes( QPainter *p );
 };
 
 #endif


More information about the Kstars-devel mailing list