[Kstars-devel] KDE/kdeedu/kstars/kstars/tools
Jason Harris
kstars at 30doradus.org
Tue Nov 27 02:12:30 CET 2007
SVN commit 742061 by harris:
Enable antialiasing in the plot widgets of the Alt vs Time and Solar
System tools.
Also improved the twilight gradients, using QLinearGradient instead of
repeated calls to drawLine while stepping in color :)
I noticed that with antialiasing active, a horizontal or vertical line
drawn with integer pixel values is drawn "fuzzy" and half-transparent.
I offset the coordinates of the yellow lines drawn at mouse click
positions by 0.5 pixels to sharpen them up. This works really well.
I should apply the same sharpness fix to KPlotWidget's axis lines.
CCMAIL: kstars-devel at kde.org
M +21 -13 avtplotwidget.cpp
M +1 -0 pvplotwidget.cpp
--- trunk/KDE/kdeedu/kstars/kstars/tools/avtplotwidget.cpp #742060:742061
@@ -19,14 +19,18 @@
#include <QMouseEvent>
#include <QPainter>
#include <QTime>
+#include <QLinearGradient>
#include <KPlotObject>
+#include <kdebug.h>
#include "avtplotwidget.h"
AVTPlotWidget::AVTPlotWidget( QWidget *parent )
: KPlotWidget( parent )
{
+ setAntialiasing(true);
+
//Default SunRise/SunSet values
SunRise = 0.25;
SunSet = 0.75;
@@ -79,29 +83,33 @@
int pW = pixRect().width();
int pH = pixRect().height();
+ QColor SkyColor( 0, 100, 200 );
+
//draw daytime sky if the Sun rises for the current date/location
//(when Sun does not rise, SunSet = -1.0)
if ( SunSet != -1.0 ) {
//If Sun does not set, then just fill the daytime sky color
if ( SunSet == 1.0 ) {
- p.fillRect( 0, 0, pW, int(0.5*pH), QColor( 0, 100, 200 ) );
+ p.fillRect( 0, 0, pW, int(0.5*pH), SkyColor );
} else {
//Display centered on midnight, so need to modulate dawn/dusk by 0.5
int dawn = int(pW*(0.5 + SunRise));
int dusk = int(pW*(SunSet - 0.5));
- p.fillRect( 0, 0, dusk, int(0.5*pH), QColor( 0, 100, 200 ) );
- p.fillRect( dawn, 0, pW - dawn, int(0.5*pH), QColor( 0, 100, 200 ) );
+ p.fillRect( 0, 0, dusk, int(0.5*pH), SkyColor );
+ p.fillRect( dawn, 0, pW - dawn, int(0.5*pH), SkyColor );
//draw twilight gradients
- unsigned short int W = 40;
- for ( unsigned short int i=0; i<W; ++i ) {
- p.setPen( QColor( 0, int(100*i/W), 200*i/W ) );
- p.drawLine( dusk - (i-20), 0, dusk - (i-20), pH );
- p.drawLine( dawn + (i-20), 0, dawn + (i-20), pH );
- }
- }
+ QLinearGradient grad = QLinearGradient( QPointF(dusk-20.0, 0.0), QPointF(dusk+20.0, 0.0) );
+ grad.setColorAt(0, SkyColor );
+ grad.setColorAt(1, Qt::black );
+ p.fillRect( QRectF( dusk-20.0, 0.0, 40.0, pH ), grad );
+
+ grad.setStart( QPointF(dawn+20.0, 0.0) );
+ grad.setFinalStop( QPointF(dawn-20.0, 0.0) );
+ p.fillRect( QRectF( dawn-20.0, 0.0, 40.0, pH ), grad );
+ }
}
-
+
//draw ground
p.fillRect( 0, int(0.5*pH), pW, int(0.5*pH), QColor( "#002200" ) );
@@ -132,8 +140,8 @@
//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() );
+ p.drawLine( QLineF( MousePoint.x()+0.5, 0.5, MousePoint.x()+0.5, pixRect().height()-0.5 ) );
+ p.drawLine( QLineF( 0.5, MousePoint.y()+0.5, pixRect().width()-0.5, MousePoint.y()+0.5 ) );
//Label each crosshair line (time and altitude)
p.setFont( smallFont );
--- trunk/KDE/kdeedu/kstars/kstars/tools/pvplotwidget.cpp #742060:742061
@@ -30,6 +30,7 @@
{
setFocusPolicy( Qt::StrongFocus );
setMouseTracking (true);
+ setAntialiasing(true);
pv = (PlanetViewer*)topLevelWidget();
}
More information about the Kstars-devel
mailing list