Commit 23f26c28 authored by David Saxton's avatar David Saxton

Make the precision (i.e. number of decimal places) of the current mouse

position in the statusbar be dependent on the zoom, so that moving the mouse
by one pixel is guaranteed to change the coordinate-string displayed by at
least one digit.

svn path=/trunk/KDE/kdeedu/kmplot/; revision=526402
parent 163562e6
......@@ -115,3 +115,5 @@ kmplot/function.cpp
kmplot/function.h
kmplot/kmplot.cpp
kmplot/kmplot.h
kmplot/kmplotprogress.cpp
kmplot/kmplotprogress.h
......@@ -650,7 +650,7 @@ bool View::root(double *x0, Equation *it)
int k = 0; // iteration count
int max_k = 100; // maximum number of iterations
double max_y = 1e-9; // the largest value of y which is deemed a root found
double max_y = 1e-14; // the largest value of y which is deemed a root found
*x0 = csxpos;
double y = csypos;
......@@ -665,7 +665,10 @@ bool View::root(double *x0, Equation *it)
}
while ( (k++<max_k) && tooBig );
return ! tooBig;
// We continue calculating until |y| < max_y; this may result in k reaching
// max_k. However, if |y| is reasonably small (even if reaching max_k),
// we consider it a root.
return ( qAbs(y) < max_y * 1e4 );
}
void View::paintEvent(QPaintEvent *)
......@@ -1096,6 +1099,25 @@ double View::pixelDistance( double real_x, double real_y, Function * function, d
}
QString View::posToString( double x, double delta ) const
{
assert( delta != 0.0 );
int decimalPlaces = 1-int(log(delta)/log(10.0));
QString number;
if ( decimalPlaces >= 0 )
number = QString::number( x, 'f', decimalPlaces );
else
number = QString::number( x/(pow(10.0,decimalPlaces)), 'f', 0 ) + QString( -decimalPlaces, '0' );
if ( x > 0.0 )
number.prepend('+');
return number;
}
void View::mouseMoveEvent(QMouseEvent *e)
{
if ( isDrawing )
......@@ -1109,17 +1131,8 @@ void View::mouseMoveEvent(QMouseEvent *e)
if ( inBounds )
{
// sx.sprintf( " x= %+.2f", csxpos );
// sy.sprintf( " y= %+.2f", csypos );
if ( qAbs(csxpos) > 1e4 )
sx = QString( "x = %1" ).arg( csxpos, 0, 'f', 0 );
else
sx = QString( "x = %1" ).arg( csxpos, 0, 'g', 3 );
if ( qAbs(csypos) > 1e4 )
sy = QString( "y = %1" ).arg( csypos, 0, 'f', 0 );
else
sy = QString( "y = %1" ).arg( csypos, 0, 'g', 3 );
sx = "x = " + posToString( csxpos, (xmax-xmin)/1e3 );
sy = "y = " + posToString( csypos, (ymax-ymin)/1e3 );
}
else
sx = sy = "";
......
......@@ -214,6 +214,13 @@ private:
* point of the given polar or parametric parametric function at \p x.
*/
double pixelDistance( double real_x, double real_y, Function * function, double x );
/**
* @return a string for displaying the x or y coordinate in the statusbar.
* \param delta is the amount by which the value varies over one pixel in
* the view. This is for choosing an appropriate number of decimals so that
* moving the cursor shows a nice change in the string.
*/
QString posToString( double x, double delta ) const;
/// for areadrawing when printing
......
......@@ -64,7 +64,7 @@ bool Value::operator == ( const Value & other )
//BEGIN class Plot
Plot::Plot( )
{
lineWidth = Settings::gridLineWidth();
lineWidth = 0.2;
color = Qt::black;
visible = false;
}
......
......@@ -456,6 +456,7 @@ void FunctionEditor::createCartesian()
kDebug() << "Created cartesian, so requestion state save.\n";
View::self()->mainDlg()->requestSaveCurrentState();
View::self()->drawPlot();
}
......
......@@ -300,8 +300,8 @@ void KmPlot::setStatusBarText(const QString &text, int id)
void KmPlot::setupStatusBar()
{
statusBar()->insertFixedItem( "123456789012", 1 );
statusBar()->insertFixedItem( "123456789012", 2 );
statusBar()->insertFixedItem( "1234567890123456", 1 );
statusBar()->insertFixedItem( "1234567890123456", 2 );
statusBar()->insertItem( "", 3, 3 );
statusBar()->insertItem( "", 4 );
statusBar()->changeItem( "", 1 );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment