Changeset - e6427508f520
[Not reviewed]
Hasan Yavuz Ă–ZDERYA - 7 years ago 2018-10-01 15:39:39
hy@ozderya.net
calculate smaller trackerrect for value tracker
2 files changed with 19 insertions and 3 deletions:
0 comments (0 inline, 0 general)
src/zoomer.cpp
Show inline comments
 
@@ -21,6 +21,9 @@
 
#include <qwt_plot.h>
 
#include <QPen>
 
#include <QMouseEvent>
 
#include <QtMath>
 

	
 
static const int VALUE_POINT_DIAM = 4;
 

	
 
Zoomer::Zoomer(QWidget* widget, const Stream* stream, bool doReplot) :
 
    ScrollZoomer(widget)
 
@@ -139,7 +142,7 @@ void Zoomer::drawValues(QPainter* painte
 

	
 
            painter->setBrush(_stream->channel(ci)->color());
 
            painter->setPen(Qt::NoPen);
 
            painter->drawEllipse(p, 4, 4);
 
            painter->drawEllipse(p, VALUE_POINT_DIAM, VALUE_POINT_DIAM);
 

	
 
            painter->setPen(Qt::white);
 
            painter->drawText(p, QString("%1").arg(val));
 
@@ -171,11 +174,21 @@ QRect Zoomer::trackerRect(const QFont& f
 
    }
 
    else
 
    {
 
        // TODO: optimize tracker area for masking instead of returning whole plot size
 
        return pickArea().boundingRect().toRect();
 
        return valueTrackerRect(font);
 
    }
 
}
 

	
 
QRect Zoomer::valueTrackerRect(const QFont& font) const
 
{
 
    // TODO: consider using actual tracker values for width calculation
 
    const int textWidth = qCeil(QwtText("-8.8888888").textSize(font).width());
 
    const int width = textWidth + VALUE_POINT_DIAM;
 
    const int x = trackerPosition().x() - VALUE_POINT_DIAM;
 
    const auto pickRect = pickArea().boundingRect();
 

	
 
    return QRect(x, pickRect.y(), width, pickRect.height());
 
}
 

	
 
void Zoomer::widgetMousePressEvent(QMouseEvent* mouseEvent)
 
{
 
    if (mouseEvent->modifiers() & Qt::ControlModifier)
src/zoomer.h
Show inline comments
 
@@ -21,6 +21,7 @@
 
#define ZOOMER_H
 

	
 
#include <QVector>
 
#include <QRect>
 

	
 
#include "scrollzoomer.h"
 
#include "stream.h"
 
@@ -64,6 +65,8 @@ private:
 
    void drawValues(QPainter* painter) const;
 
    /// Find sample values for given X value
 
    QVector<double> findValues(double x) const;
 
    /// Returns trackerRect for value tracker
 
    QRect valueTrackerRect(const QFont& font) const;
 
};
 

	
 
#endif // ZOOMER_H
0 comments (0 inline, 0 general)