diff --git a/doc/index.docbook b/doc/index.docbook --- a/doc/index.docbook +++ b/doc/index.docbook @@ -43,8 +43,8 @@ &FDLNotice; -2018-11-09 -1.2.2 (Applications 18.12) +2018-11-23 +1.3.0 (Applications 19.04) @@ -469,7 +469,7 @@ - Here you can set global settings which automatic will be saved when you exit &kmplot;. you can set angle-mode (radians and degrees), zoom in and zoom out factors, and whether to show advanced plot tracing. + Here you can set global settings which automatic will be saved when you exit &kmplot;. You can set angle-mode (radians and degrees), zoom in and zoom out factors for zooming using &Ctrl; with mouse wheel or the corresponding menu items, and whether to show advanced plot tracing. @@ -1214,6 +1214,11 @@ The View Menu The first three items in the menu are related to zooming. + + + The mouse wheel can also be used as a zoom control. To zoom in or out using the mouse, hold down the &Ctrl; key while you turn the mouse wheel. Each tick increases or decreases the zoom factor by the value defined in the &kmplot; General settings. + + diff --git a/kmplot/view.h b/kmplot/view.h --- a/kmplot/view.h +++ b/kmplot/view.h @@ -250,6 +250,8 @@ void keyPressEvent(QKeyEvent * ) Q_DECL_OVERRIDE; /// called when a mouse key is released void mouseReleaseEvent ( QMouseEvent * e ) Q_DECL_OVERRIDE; + /// called for zooming with Ctrl+mouse wheel + void wheelEvent(QWheelEvent *event); /// Is needed to be reimplement so that the user can stop a preview-drawing bool event( QEvent * e ) Q_DECL_OVERRIDE; /** @@ -628,6 +630,18 @@ KTextEdit * m_textEdit; ///< Contains m_textDocument QTextDocument * m_textDocument; ///< Used for layout of axis labels + + /// Various things for the animation + struct AnimInfo + { + QPointF beginTopLeft; + QPointF beginBottomRight; + QPointF endTopLeft; + QPointF endBottomRight; + int step; + } m_animInfo; + private slots: + void updateAnim(); }; #endif // View_included diff --git a/kmplot/view.cpp b/kmplot/view.cpp --- a/kmplot/view.cpp +++ b/kmplot/view.cpp @@ -3392,6 +3392,26 @@ } +void View::wheelEvent(QWheelEvent *e) +{ + if (e->modifiers() & Qt::ControlModifier) + { + // Disable animation? + if (e->delta() > 0) + { + zoomIn( e->pos(), double(Settings::zoomInStep())/100.0 ); + } + else + { + zoomIn( e->pos(), (double(Settings::zoomOutStep())/100.0) + 1.0 ); + } + e->accept(); + return; + } + QWidget::wheelEvent(e); +} + + bool View::updateCrosshairPosition() { QPointF mousePos = mapFromGlobal( QCursor::pos() ); @@ -3619,58 +3639,38 @@ newCoords.bottom() == m_ymax ) return; - m_zoomMode = AnimatingZoom; - - double oldCoordsArea = (m_xmax-m_xmin) * (m_ymax-m_ymin); - double newCoordsArea = newCoords.width() * newCoords.height(); - - QPointF beginTL, beginBR, endTL, endBR; - - if ( oldCoordsArea > newCoordsArea ) - { - // zooming in - beginTL = newCoords.topLeft(); - beginBR = newCoords.bottomRight(); - endTL = QPointF( m_xmin, m_ymin ); - endBR = QPointF( m_xmax, m_ymax ); - } - else - { - // zooming out - beginTL = QPointF( m_xmin, m_ymin ); - beginBR = QPointF( m_xmax, m_ymax ); - - double kx = ( m_xmin - m_xmax ) / ( newCoords.left() - newCoords.right() ); - double ky = ( m_ymin - m_ymax ) / ( newCoords.top() - newCoords.bottom() ); - - double lx = m_xmin - (kx * newCoords.left()); - double ly = m_ymin - (ky * newCoords.top()); - - endTL = QPointF( (kx * m_xmin) + lx, (ky * m_ymin) + ly ); - endBR = QPointF( (kx * m_xmax) + lx, (ky * m_ymax) + ly ); - } - - double MAX = 10; - double ms = MAX*16; // milliseconds to animate for - - for ( int i = 0; i <= MAX; ++i ) + if ( style()->styleHint(QStyle::SH_Widget_Animate) ) { - QTime t; - t.start(); + double oldCoordsArea = (m_xmax-m_xmin) * (m_ymax-m_ymin); + double newCoordsArea = newCoords.width() * newCoords.height(); - QPointF tl = (( i*endTL) + ((MAX-i)*beginTL)) / MAX; - QPointF br = (( i*endBR) + ((MAX-i)*beginBR)) / MAX; + if ( oldCoordsArea > newCoordsArea ) + { + // zooming in + double kx = ( newCoords.left() - newCoords.right() ) / ( m_xmin - m_xmax ); + double ky = ( newCoords.top() - newCoords.bottom() ) / ( m_ymin - m_ymax ); - m_animateZoomRect = QRectF( tl, QSizeF( br.x()-tl.x(), br.y()-tl.y() ) ); + double lx = newCoords.left() - (kx * m_xmin); + double ly = newCoords.top() - (ky * m_ymin); - repaint(); + m_animInfo.beginTopLeft = QPointF( (kx * newCoords.left()) + lx, (ky * newCoords.top()) + ly ); + m_animInfo.beginBottomRight = QPointF( (kx * newCoords.right()) + lx, (ky * newCoords.bottom()) + ly ); + m_animInfo.endTopLeft = newCoords.topLeft(); + m_animInfo.endBottomRight = newCoords.bottomRight(); + } + else + { + // zooming out + m_animInfo.beginTopLeft = newCoords.topLeft(); + m_animInfo.beginBottomRight = newCoords.bottomRight(); + m_animInfo.endTopLeft = QPointF( m_xmin, m_ymin ); + m_animInfo.endBottomRight = QPointF( m_xmax, m_ymax ); + } + m_animInfo.step = 0; - if ( i == MAX ) - break; - else while ( t.elapsed() < (ms/MAX) ) - ; // do nothing + QTimer::singleShot( 0, this, &View::updateAnim ); } - + m_xmin = newCoords.left(); m_xmax = newCoords.right(); m_ymin = newCoords.top(); @@ -3686,7 +3686,30 @@ drawPlot(); //update all graphs - m_zoomMode = Normal; +} + +void View::updateAnim() +{ + const int MAX = 11; + const int ANIM_MS = MAX*16; + + if (m_animInfo.step >= MAX) + { + m_zoomMode = Normal; + } + else + { + int i = m_animInfo.step; + m_zoomMode = AnimatingZoom; + QPointF tl = (( i*m_animInfo.endTopLeft) + ((MAX-1-i)*m_animInfo.beginTopLeft)) / (MAX-1); + QPointF br = (( i*m_animInfo.endBottomRight) + ((MAX-1-i)*m_animInfo.beginBottomRight)) / (MAX-1); + + m_animateZoomRect = QRectF( tl, QSizeF( br.x()-tl.x(), br.y()-tl.y() ) ); + + QTimer::singleShot( ANIM_MS/MAX, this, &View::updateAnim ); + m_animInfo.step++; + } + repaint(); }