#include "ruler.h"
#include "view.h"
+#include "viewport.h"
#include <extdef.h>
#include <assert.h>
#include <math.h>
+#include <QMouseEvent>
#include <QPainter>
#include <QTextStream>
{"f", "p", "n", QChar(0x03BC), "m", "", "k", "M", "G"};
const int Ruler::FirstSIPrefixPower = -15;
+const int Ruler::HoverArrowSize = 5;
+
Ruler::Ruler(View &parent) :
QWidget(&parent),
_view(parent)
{
+ setMouseTracking(true);
+
+ connect(&_view, SIGNAL(hover_point_changed()),
+ this, SLOT(hover_point_changed()));
}
void Ruler::paintEvent(QPaintEvent *event)
division++;
}
+ // Draw the hover mark
+ draw_hover_mark(p);
+
p.end();
}
+void Ruler::draw_hover_mark(QPainter &p)
+{
+ const int x = _view.hover_point().x();
+ if(x == -1)
+ return;
+
+ p.setPen(QPen(Qt::NoPen));
+ p.setBrush(QBrush(QColor(Qt::black)));
+
+ const int b = height() - 1;
+ const QPointF points[] = {
+ QPointF(x, b),
+ QPointF(x - HoverArrowSize, b - HoverArrowSize),
+ QPointF(x + HoverArrowSize, b - HoverArrowSize)
+ };
+ p.drawPolygon(points, countof(points));
+}
+
+void Ruler::hover_point_changed()
+{
+ update();
+}
+
} // namespace view
} // namespace pv
static const QString SIPrefixes[9];
static const int FirstSIPrefixPower;
+ static const int HoverArrowSize;
+
public:
Ruler(View &parent);
private:
void paintEvent(QPaintEvent *event);
+private:
+ /**
+ * Draw a hover arrow under the cursor position.
+ */
+ void draw_hover_mark(QPainter &p);
+
+private slots:
+ void hover_point_changed();
+
private:
View &_view;
};