Changeset - f3a38044a4bb
[Not reviewed]
default
0 2 0
Hasan Yavuz Ă–ZDERYA - 9 years ago 2016-08-13 05:06:06
hy@ozderya.net
fix jagged snapping behavior
2 files changed with 7 insertions and 6 deletions:
0 comments (0 inline, 0 general)
src/scalepicker.cpp
Show inline comments
 
@@ -97,18 +97,18 @@ bool ScalePicker::eventFilter(QObject* o
 
        event->type() == QEvent::MouseButtonRelease ||
 
        event->type() == QEvent::MouseMove)
 
    {
 
        updateSnapPoints();
 

	
 
        QMouseEvent* mouseEvent = (QMouseEvent*) event;
 
        double posPx = this->positionPx(mouseEvent);
 
        int posPx = this->positionPx(mouseEvent);
 

	
 
        // do snapping unless Shift is pressed
 
        if (! (mouseEvent->modifiers() & Qt::ShiftModifier))
 
        {
 
            for (double sp : snapPoints)
 
            for (auto sp : snapPoints)
 
            {
 
                if (fabs(posPx-sp) <= SNAP_DISTANCE)
 
                {
 
                    posPx = sp;
 
                    break;
 
                }
 
@@ -224,13 +224,13 @@ void ScalePicker::setPen(QPen pen)
 
// convert the position of the click to the plot coordinates
 
double ScalePicker::position(double posPx)
 
{
 
    return _scaleWidget->scaleDraw()->scaleMap().invTransform(posPx);
 
}
 

	
 
double ScalePicker::positionPx(QMouseEvent* mouseEvent)
 
int ScalePicker::positionPx(QMouseEvent* mouseEvent)
 
{
 
    double pos;
 
    if (_scaleWidget->alignment() == QwtScaleDraw::BottomScale ||
 
        _scaleWidget->alignment() == QwtScaleDraw::TopScale)
 
    {
 
        pos = mouseEvent->pos().x();
 
@@ -269,9 +269,10 @@ void ScalePicker::updateSnapPoints()
 
        _scaleWidget->scaleDraw()->scaleDiv().ticks(QwtScaleDiv::MediumTick) +
 
        _scaleWidget->scaleDraw()->scaleDiv().ticks(QwtScaleDiv::MinorTick);
 

	
 
    snapPoints.clear();
 
    for(auto t : allTicks)
 
    {
 
        snapPoints << _scaleWidget->scaleDraw()->scaleMap().transform(t);
 
        // `round` is used because `allTicks` is double but `snapPoints` is int
 
        snapPoints << round(_scaleWidget->scaleDraw()->scaleMap().transform(t));
 
    }
 
}
src/scalepicker.h
Show inline comments
 
@@ -54,16 +54,16 @@ private:
 

	
 
    bool pressed;
 
    bool started;
 
    double firstPos; // converted to plot coordinates
 
    double firstPosPx; // pixel coordinates
 
    double currentPosPx; // current position in pixel coordinates
 
    QList<double> snapPoints;
 
    QList<int> snapPoints;
 

	
 
    double position(double); // returns the axis mouse position relative to plot coordinates
 
    double positionPx(QMouseEvent*); // returns the axis mouse position in pixels
 
    int positionPx(QMouseEvent*); // returns the axis mouse position in pixels
 
    double posCanvasPx(double pos); // returns the given position in canvas coordinates
 

	
 
private slots:
 
    void updateSnapPoints();
 
};
 

	
0 comments (0 inline, 0 general)