21 #include <QMouseEvent>
24 #include <QLinearGradient>
28 #include <KPlotObject>
34 setAntialiasing(
true);
40 MousePoint = QPoint( -1, -1 );
48 MousePoint = QPoint(-1, -1);
53 QRect checkRect( leftPadding(), topPadding(), pixRect().width(), pixRect().height() );
57 if ( ! checkRect.contains( e->x(), e->y() ) ) {
58 if ( e->x() < checkRect.left() ) Xcursor = checkRect.left();
59 if ( e->x() > checkRect.right() ) Xcursor = checkRect.right();
60 if ( e->y() < checkRect.top() ) Ycursor = checkRect.top();
61 if ( e->y() > checkRect.bottom() ) Ycursor = checkRect.bottom();
64 Xcursor -= leftPadding();
65 Ycursor -= topPadding();
67 MousePoint = QPoint( Xcursor, Ycursor );
77 p.setRenderHint( QPainter::Antialiasing, antialiasing() );
78 p.fillRect( rect(), backgroundColor() );
79 p.translate( leftPadding(), topPadding() );
82 p.setClipRect( pixRect() );
83 p.setClipping(
true );
85 int pW = pixRect().width();
86 int pH = pixRect().height();
88 QColor SkyColor( 0, 100, 200 );
91 if ( SunMaxAlt > -18.0 ) {
93 int rise = int( pW * ( 0.5 + SunRise ) );
94 int set = int( pW * ( SunSet - 0.5 ) );
95 int da = int( pW * ( 0.5 + Dawn ) );
96 int du = int( pW * ( Dusk - 0.5 ) );
98 if ( SunMinAlt > 0.0 ) {
100 p.fillRect( rect(), SkyColor );
101 }
else if ( SunMaxAlt < 0.0 && SunMinAlt < -18.0 ) {
103 QLinearGradient grad = QLinearGradient( QPointF( 0.0, 0.0 ), QPointF( du, 0.0 ) );
104 grad.setColorAt( 0, SkyColor.darker( SunMaxAlt / -18.0 * 1000 ) );
105 grad.setColorAt( 1, Qt::black );
106 p.fillRect( QRectF( 0.0, 0.0, du+20.0, pH ), grad );
108 grad.setStart( QPointF( pW, 0.0 ) );
109 grad.setFinalStop( QPointF( da-20.0, 0.0 ) );
110 p.fillRect( QRectF( da-20.0, 0.0, pW, pH ), grad );
111 }
else if ( SunMaxAlt < 0.0 && SunMinAlt > -18.0 ) {
113 QLinearGradient grad = QLinearGradient( QPointF( 0.0, 0.0 ), QPointF( pW, 0.0 ) );
114 grad.setColorAt( 0, SkyColor.darker( SunMaxAlt / -18.0 * 1000 ) );
115 grad.setColorAt( 0.5, SkyColor.darker( SunMinAlt / -18.0 * 1000 ) );
116 grad.setColorAt( 1, SkyColor.darker( SunMaxAlt / -18.0 * 1000 ) );
117 p.fillRect( QRectF( 0.0, 0.0, pW, pH ), grad );
118 }
else if ( Dawn < 0.0 ) {
120 p.fillRect( 0, 0, set,
int( 0.5 * pH ), SkyColor );
121 p.fillRect( rise, 0, pW,
int( 0.5 * pH ), SkyColor );
123 QLinearGradient grad = QLinearGradient( QPointF( set-20.0, 0.0 ), QPointF( rise, 0.0 ) );
124 grad.setColorAt( 0, SkyColor );
125 grad.setColorAt( 0.5, SkyColor.darker( SunMinAlt / -18.0 * 1000 ) );
126 grad.setColorAt( 1, SkyColor );
127 p.fillRect( QRectF( set-20.0, 0.0, rise-set+20.0, pH ), grad );
129 p.fillRect( 0, 0, set, pH, SkyColor );
130 p.fillRect( rise, 0, pW, pH, SkyColor );
132 QLinearGradient grad = QLinearGradient( QPointF( set-20.0, 0.0 ), QPointF( du, 0.0 ) );
133 grad.setColorAt( 0, SkyColor );
134 grad.setColorAt( 1, Qt::black );
135 p.fillRect( QRectF( set-20.0, 0.0, du-set+20.0, pH ), grad );
137 grad.setStart( QPointF( rise+20.0, 0.0 ) );
138 grad.setFinalStop( QPointF( da, 0.0 ) );
139 p.fillRect( QRectF( da, 0.0, rise-da+20.0, pH ), grad );
144 p.fillRect( 0,
int(0.5*pH), pW,
int(0.5*pH), QColor(
"#002200" ) );
146 foreach( KPlotObject *po, plotObjects() )
147 po->draw( &p,
this );
149 p.setClipping(
false );
153 QTime t = QTime::currentTime();
154 double x = 12.0 + t.hour() + t.minute()/60.0 + t.second()/3600.0;
155 while ( x > 24.0 ) x -= 24.0;
156 int ix = int(x*pW/24.0);
157 p.setPen( QPen( QBrush(
"white"), 2.0, Qt::DotLine ) );
158 p.drawLine( ix, 0, ix, pH );
162 QFont smallFont = p.font();
163 smallFont.setPointSize( smallFont.pointSize() - 2 );
164 p.setFont( smallFont );
165 p.translate( ix + 10, pH - 20 );
167 p.drawText(0, 0, KGlobal::locale()->formatTime( t ) );
171 if ( MousePoint.x() > 0 ) {
172 p.setPen( QPen( QBrush(
"gold"), 1.0, Qt::SolidLine ) );
173 p.drawLine( QLineF( MousePoint.x()+0.5, 0.5, MousePoint.x()+0.5, pixRect().height()-0.5 ) );
174 p.drawLine( QLineF( 0.5, MousePoint.y()+0.5, pixRect().width()-0.5, MousePoint.y()+0.5 ) );
177 p.setFont( smallFont );
178 double a = (pH - MousePoint.y())*180.0/pH - 90.0;
179 p.drawText( 20, MousePoint.y() + 10, QString::number(a,
'f',2) + QChar(176) );
181 double h = MousePoint.x()*24.0/pW - 12.0;
182 if ( h < 0.0 ) h += 24.0;
183 t = QTime(
int(h),
int(60.*(h -
int(h))) );
185 p.translate( MousePoint.x() + 10, pH - 20 );
187 p.drawText( 0, 0, KGlobal::locale()->formatTime( t ) );
207 #include "avtplotwidget.moc"