Commit 61b2ab27 authored by David Saxton's avatar David Saxton

Improved zooming:

- Unified "Zoom Rectangular" and "Zoom in" under one operation "Zoom In".
- Added zoom-out-rectangular equivalent for "Zoom Out".
- Animate zooming operation as a visual aid to how the function is transformed.
- Removed "Center Point" operation and replaced with translating the view via
  dragging (Google maps style).
- Made the zooming operations single shot and added the actions to the toolbar.

svn path=/trunk/KDE/kdeedu/kmplot/; revision=523534
parent dbd2f7ce
......@@ -145,36 +145,15 @@ void MainDlg::setupActions()
//BEGIN zoom menu
QActionGroup * zoomGroup = new QActionGroup( this );
KToggleAction * mnuNoZoom = new KToggleAction( i18n("&No Zoom"), actionCollection(), "no_zoom" );
mnuNoZoom->setShortcut( "CTRL+0" );
connect( mnuNoZoom, SIGNAL(triggered(bool)), view, SLOT( mnuNoZoom_clicked() ) );
zoomGroup->addAction( mnuNoZoom );
mnuNoZoom->setChecked(true);
KToggleAction * mnuRectangular = new KToggleAction( i18n("Zoom &Rectangular"), actionCollection(), "zoom_rectangular" );
mnuRectangular->setShortcut( "CTRL+1" );
mnuRectangular->setIcon( KIcon("viewmagfit") );
connect( mnuRectangular, SIGNAL(triggered(bool)), view, SLOT( mnuRectangular_clicked() ) );
zoomGroup->addAction( mnuRectangular );
KToggleAction * mnuZoomIn = new KToggleAction( i18n("Zoom &In"), actionCollection(), "zoom_in" );
mnuZoomIn->setShortcut( "CTRL+2" );
mnuZoomIn->setIcon( KIcon("viewmag+") );
connect( mnuZoomIn, SIGNAL(triggered(bool)), view, SLOT(mnuZoomIn_clicked()) );
zoomGroup->addAction( mnuZoomIn );
KToggleAction * mnuZoomOut = new KToggleAction( i18n("Zoom &Out"), actionCollection(),"zoom_out" );
mnuZoomOut->setShortcut( "CTRL+3" );
mnuZoomOut->setIcon( KIcon("viewmag-") );
connect( mnuZoomOut, SIGNAL(triggered(bool)), view, SLOT( mnuZoomOut_clicked() ) );
zoomGroup->addAction( mnuZoomOut );
KToggleAction * mnuZoomCenter = new KToggleAction( i18n("&Center Point"), actionCollection(), "zoom_center" );
mnuZoomCenter->setShortcut( "CTRL+4" );
connect( mnuZoomCenter, SIGNAL(triggered(bool)), view, SLOT( mnuCenter_clicked() ) );
zoomGroup->addAction( mnuZoomCenter );
KAction * zoomIn = new KAction( i18n("Zoom &In"), actionCollection(), "zoom_in" );
zoomIn->setShortcut( "CTRL+1" );
zoomIn->setIcon( KIcon("viewmag+") );
connect( zoomIn, SIGNAL(triggered(bool)), view, SLOT(mnuZoomIn_clicked()) );
KAction * zoomOut = new KAction( i18n("Zoom &Out"), actionCollection(),"zoom_out" );
zoomOut->setShortcut( "CTRL+2" );
zoomOut->setIcon( KIcon("viewmag-") );
connect( zoomOut, SIGNAL(triggered(bool)), view, SLOT( mnuZoomOut_clicked() ) );
KAction * zoomTrig = new KAction( i18n("&Fit Widget to Trigonometric Functions"), actionCollection(), "zoom_trig" );
connect( zoomTrig, SIGNAL(triggered(bool)), view, SLOT( mnuTrig_clicked() ) );
......
This diff is collapsed.
......@@ -83,7 +83,7 @@ public:
/// get a y-value from a x-value
void getYValue(Ufkt * , char, double , double &,const QString &);
/// draw and calculate the area between the graph and the x-axis.
void areaUnderGraph(Ufkt *, char const, double &, double &, const QString &, QPainter* );
void areaUnderGraph(Ufkt *, Ufkt::PMode, double &, double &, const QString &, QPainter* );
/// the calculation was cancelled by the user
bool isCalculationStopped();
......@@ -91,21 +91,6 @@ public:
/// @see m_parser
XParser* parser();
/** Current plot range endge. */
static double xmin;
static double xmax;
/// trace mode stuff, must be accessible in KMinMax
int csmode, csparam;
char cstype;
/// for areadrawing when printing
bool areaDraw;
Ufkt * areaUfkt;
char areaPMode;
double areaMin, areaMax;
QString areaParameter;
/// Slider controlling parameter values
QPointer<KSliderWindow> m_sliderWindow;
/// Menu actions for the sliders
......@@ -115,6 +100,14 @@ public:
/// Convert a width in mm to a suitable QPen width for drawing
double mmToPenWidth( double width_mm, bool antialias ) const;
/** Current plot range endge. */
static double xmin;
static double xmax;
/// trace mode stuff, must be accessible in KMinMax
int csmode, csparam;
char cstype;
public slots:
/// Called when the user want to cancel the drawing
void stopDrawing();
......@@ -130,11 +123,8 @@ public slots:
void mnuRemove_clicked();
void mnuEdit_clicked();
///Slots for the zoom menu
void mnuNoZoom_clicked();
void mnuRectangular_clicked();
void mnuZoomIn_clicked();
void mnuZoomOut_clicked();
void mnuCenter_clicked();
void mnuTrig_clicked();
protected slots:
......@@ -152,6 +142,11 @@ protected slots:
bool event( QEvent * e );
/// Restore the mouse cursor when a drawing is finished
void updateCursor();
/**
* Updates csxpos and csypos from the current mouse position.
* @return whether the crosshair is within the bounds of the diagram.
*/
bool updateCrosshairPosition();
signals:
void setStatusBarText(const QString &);
......@@ -169,7 +164,7 @@ private:
/// Draw the function plots.
void plotfkt(Ufkt *ufkt, QPainter*);
/// @return an appropriate pen for drawing the plot
QPen penForPlot( Ufkt * ufkt, int p_mode, bool antialias ) const;
QPen penForPlot( Ufkt * ufkt, Ufkt::PMode, bool antialias ) const;
/// Gets the greek pi symbol.
void setpi(QString *);
/// in trace mode checks, if the function is (near by) zero
......@@ -184,6 +179,26 @@ private:
void increaseProgressBar();
/// @return whether the crosshairs should be shown for the current mouse position
bool shouldShowCrosshairs() const;
/**
* Zooms in by amount \p zoomFactor (which will zooming out if less than 1)
* from clicking at \p mousePos (in widget coordinates).
*/
void zoomIn( const QPoint & mousePos, double zoomFactor );
/// zooms in from having drawn \p zoomRect (which is in widget coordinates)
void zoomIn( const QRect & zoomRect );
/// zooms out from havoutg drawn \p zoomRect (which is out widget coordoutates)
void zoomOut( const QRect & zoomRect );
/// translates the view by \p dx, \p dy (in widget coordinates)
void translateView( int dx, int dy );
/// animates zooming from the current zoom rect to the one given (in real coordinates)
void animateZoom( const QRectF & newCoords );
/// for areadrawing when printing
bool areaDraw;
Ufkt * areaUfkt;
Ufkt::PMode areaPMode;
double areaMin, areaMax;
QString areaParameter;
/// The central parser instance.
/// @see parser()
......@@ -191,15 +206,11 @@ private:
int w, h;
float s;
/// @name Crosshair
/// Crosshair support.
//@{
float fcx; ///< x-position of the crosshais (pixel)
float fcy; ///< y-position of the crosshais (pixel)
QPointF m_crosshairPixelCoords;
float csxpos; ///< y-position of the cross hair (real coordinates)
float csypos; ///< x-position of the cross hair (real coordinates)
//@}
/// trace mode stuff
bool rootflg;
......@@ -271,17 +282,23 @@ private:
enum ZoomMode
{
Normal=0, ///< normal
Rectangular=1, ///< rectangular zoom (in)
ZoomIn=2, ///< zoom in
ZoomOut=3, ///< zoom out
DrawingRectangle=4, ///< drawing a rectangle
Center=5 ///< centering a point
Normal, ///< no zooming
AnimatingZoom, ///< animating a current zooming
ZoomIn, ///< zoom in
ZoomOut, ///< zoom out
ZoomInDrawing, ///< drawing a rectangle for zooming in
ZoomOutDrawing, ///< drawing a rectangle for zooming out
Translating, ///< dragging the view with the mouse
};
ZoomMode zoom_mode;
/// The current editing status
ZoomMode m_zoomMode;
/// for zoom-mode
QPoint rectangle_point;
QPoint m_zoomRectangleStart;
/// for animating zoom; contains the rectangle (in real coordinates) to draw
QRectF m_animateZoomRect;
/// for translating the view via dragging
QPoint m_prevDragMousePos;
DCOPClient *m_dcop_client;
QString m_statusbartext1;
......@@ -290,7 +307,7 @@ private:
QString m_statusbartext4;
KActionCollection *m_ac;
enum Cursor { CursorWait, CursorBlank, CursorArrow, CursorCross, CursorMagnify, CursorLessen, CursorPointing };
enum Cursor { CursorWait, CursorBlank, CursorArrow, CursorCross, CursorMagnify, CursorLessen, CursorMove };
Cursor m_prevCursor;
};
......
......@@ -66,7 +66,7 @@ CDiagr::~CDiagr()
{}
void CDiagr::Create(QPoint Ref, // Bezugspunkt links unten
int lx, int ly, // Achsenl�gen
double lx, double ly, // Achsenl�gen
double xmin, double xmax, // x-Wertebereich
double ymin, double ymax) // y-Wertebereich
{ int x, y, h, w;
......@@ -83,7 +83,7 @@ void CDiagr::Create(QPoint Ref, // Bezugspunkt links unten
sky=ly/(ymax-ymin);
ox=Ref.x()-skx*xmin+0.5; // Ursprungskoordinaten berechnen
oy=Ref.y()+sky*ymax+0.5;
PlotArea.setRect(x=Ref.x(), y=Ref.y(), w=lx, h=ly);
PlotArea.setRect(x=Ref.x(), y=Ref.y(), w=int(lx), h=int(ly));
if( Settings::showExtraFrame() )
{
x-=20;
......
......@@ -64,7 +64,7 @@ public:
/// Sets all members to current values.
void Create( QPoint Ref,
int lx, int ly,
double lx, double ly,
double xmin, double xmax,
double ymin, double ymax );
/// Sets the current values for the scaling factors
......
......@@ -267,22 +267,22 @@ void KMinMax::cmdFind_clicked()
QListWidgetItem * currentItem = m_mainWidget->list->currentItem();
QString function( currentItem ? currentItem->text() : QString::null );
char p_mode = 0;
if ( function.contains('\'') == 1)
Ufkt::PMode p_mode = Ufkt::Function;
if ( function.count('\'') == 1)
{
p_mode = 1;
p_mode = Ufkt::Derivative1;
int pos = function.indexOf('\'');
function.remove(pos,1);
}
else if ( function.contains('\'') == 2)
else if ( function.count('\'') == 2)
{
p_mode = 2;
p_mode = Ufkt::Derivative2;
int pos = function.indexOf('\'');
function.remove(pos,2);
}
else if ( function.at(0).category() == QChar::Letter_Uppercase)
{
p_mode = 3;
p_mode = Ufkt::Integral;
function[0] = function[0].toLower();
}
......@@ -362,22 +362,22 @@ void KMinMax::list_currentChanged(QListWidgetItem* item)
return;
}
QString function( item->text() );
char p_mode = 0;
if ( function.contains('\'') == 1)
Ufkt::PMode p_mode = Ufkt::Function;
if ( function.count('\'') == 1)
{
p_mode = 1;
p_mode = Ufkt::Derivative1;
int pos = function.indexOf('\'');
function.remove(pos,1);
}
else if ( function.contains('\'') == 2)
else if ( function.count('\'') == 2)
{
p_mode = 2;
p_mode = Ufkt::Derivative2;
int pos = function.indexOf('\'');
function.remove(pos,2);
}
else if ( function.at(0).category() == QChar::Letter_Uppercase)
{
p_mode = 3;
p_mode = Ufkt::Integral;
function[0] = function[0].toLower();
}
QString const sec_function = function.section('(',0,0);
......@@ -402,22 +402,22 @@ void KMinMax::cmdParameter_clicked()
QListWidgetItem * currentItem = m_mainWidget->list->currentItem();
QString function( currentItem ? currentItem->text() : QString::null );
char p_mode = 0;
if ( function.contains('\'') == 1)
Ufkt::PMode p_mode = Ufkt::Function;
if ( function.count('\'') == 1)
{
p_mode = 1;
p_mode = Ufkt::Derivative1;
int pos = function.indexOf('\'');
function.remove(pos,1);
}
else if ( function.contains('\'') == 2)
else if ( function.count('\'') == 2)
{
p_mode = 2;
p_mode = Ufkt::Derivative2;
int pos = function.indexOf('\'');
function.remove(pos,2);
}
else if ( function.at(0).category() == QChar::Letter_Uppercase)
{
p_mode = 3;
p_mode = Ufkt::Integral;
function[0] = function[0].toLower();
}
......
<!DOCTYPE kpartgui>
<kpartgui name="kmplot" version="7">
<kpartgui name="kmplot" version="8">
<MenuBar>
<Menu name="file">
<Action name="file_openrecent"/>
......@@ -11,10 +11,8 @@
<Action name="export"/>
</Menu>
<Menu name="edit"><text>&amp;Edit</text>
<Action name="editcolors"/>
<Action name="editaxes"/>
<Action name="editscaling"/>
<Action name="editfonts"/>
<Separator />
<Action name="coord_i"/>
<Action name="coord_ii"/>
......@@ -27,11 +25,8 @@
<Action name="editplots"/>
</Menu>
<Menu name="zoom"><text>&amp;Zoom</text>
<Action name="no_zoom"/>
<Action name="zoom_rectangular"/>
<Action name="zoom_in"/>
<Action name="zoom_out"/>
<Action name="zoom_center"/>
<Separator />
<Action name="zoom_trig"/>
</Menu>
......@@ -59,6 +54,10 @@
<Separator />
<Action name="quickedit"/>
<Action name="newfunction"/>
<Separator />
<Action name="zoom_in"/>
<Action name="zoom_out"/>
<Separator />
<Action name="coord_i"/>
<Action name="coord_ii"/>
<Action name="coord_iii"/>
......
<!DOCTYPE kpartgui>
<kpartgui name="kmplot" version="2">
<kpartgui name="kmplot" version="3">
<MenuBar>
<Menu name="file">
<Action name="file_save_as"/>
......@@ -15,11 +15,8 @@
<Action name="coord_iii"/>
</Menu>
<Menu name="zoom"><text>&amp;Zoom</text>
<Action name="no_zoom"/>
<Action name="zoom_rectangular"/>
<Action name="zoom_in"/>
<Action name="zoom_out"/>
<Action name="zoom_center"/>
<Separator />
<Action name="zoom_trig"/>
</Menu>
......@@ -39,6 +36,9 @@
</Menu>
</MenuBar>
<ToolBar name="mainToolBar">
<Action name="zoom_in"/>
<Action name="zoom_out"/>
<Separator />
<Action name="coord_i"/>
<Action name="coord_ii"/>
<Action name="coord_iii"/>
......
......@@ -119,6 +119,14 @@ class ParameterValueItem
class Ufkt
{
public:
enum PMode
{
Function,
Derivative1,
Derivative2,
Integral,
};
Ufkt();
~Ufkt();
/// Sets the parameter
......
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