{
}
-void Cursor::paint_label(QPainter &p, const QRect &rect)
+QRectF Cursor::get_label_rect(const QRect &rect) const
{
const float x = (_time - _view.offset()) / _view.scale();
- const QRectF r(x - Size/2, rect.height() - Size - Offset,
+ return QRectF(x - Size/2, rect.height() - Size - Offset,
Size, Size);
+}
+
+void Cursor::paint_label(QPainter &p, const QRect &rect)
+{
+ const QRectF r(get_label_rect(rect));
p.setPen(LineColour);
p.setBrush(QBrush(FillColour));
Cursor(const View &view, double time);
public:
+ /**
+ * Gets the marker label rectangle.
+ * @param rect The rectangle of the ruler client area.
+ * @return Returns the label rectangle.
+ */
+ QRectF get_label_rect(const QRect &rect) const;
+
/**
* Paints the cursor's label to the ruler.
* @param p The painter to draw with.
*/
#include "ruler.h"
+
+#include "cursor.h"
#include "view.h"
#include "viewport.h"
Ruler::Ruler(View &parent) :
QWidget(&parent),
- _view(parent)
+ _view(parent),
+ _grabbed_marker(NULL)
{
setMouseTracking(true);
p.end();
}
+void Ruler::mouseMoveEvent(QMouseEvent *e)
+{
+ if(!_grabbed_marker)
+ return;
+
+ _grabbed_marker->set_time(_view.offset() +
+ ((double)e->x() + 0.5) * _view.scale());
+}
+
+void Ruler::mousePressEvent(QMouseEvent *e)
+{
+ if(e->buttons() & Qt::LeftButton) {
+ _grabbed_marker = NULL;
+
+ if(_view.cursors_shown()) {
+ std::pair<Cursor, Cursor> &cursors =
+ _view.cursors();
+ if(cursors.first.get_label_rect(
+ rect()).contains(e->pos()))
+ _grabbed_marker = &cursors.first;
+ else if(cursors.second.get_label_rect(
+ rect()).contains(e->pos()))
+ _grabbed_marker = &cursors.second;
+ }
+ }
+}
+
+void Ruler::mouseReleaseEvent(QMouseEvent *)
+{
+ _grabbed_marker = NULL;
+}
+
void Ruler::draw_cursors(QPainter &p)
{
if(!_view.cursors_shown())
void Ruler::draw_hover_mark(QPainter &p)
{
const int x = _view.hover_point().x();
- if(x == -1)
+ if(x == -1 || _grabbed_marker)
return;
p.setPen(QPen(Qt::NoPen));
namespace pv {
namespace view {
+class TimeMarker;
class View;
class Ruler : public QWidget
private:
void paintEvent(QPaintEvent *event);
+ void mouseMoveEvent(QMouseEvent *e);
+ void mousePressEvent(QMouseEvent *e);
+ void mouseReleaseEvent(QMouseEvent *);
+
private:
void draw_cursors(QPainter &p);
private:
View &_view;
+
+ TimeMarker *_grabbed_marker;
};
} // namespace view
void TimeMarker::set_time(double time)
{
_time = time;
+ time_changed();
}
void TimeMarker::paint(QPainter &p, const QRect &rect)
#include <QColor>
#include <QObject>
+#include <QRectF>
class QPainter;
class QRect;
*/
virtual void paint(QPainter &p, const QRect &rect);
+ /**
+ * Gets the marker label rectangle.
+ * @param rect The rectangle of the ruler client area.
+ * @return Returns the label rectangle.
+ */
+ virtual QRectF get_label_rect(const QRect &rect) const = 0;
+
/**
* Paints the marker's label to the ruler.
* @param p The painter to draw with.
*/
virtual void paint_label(QPainter &p, const QRect &rect) = 0;
+signals:
+ void time_changed();
+
protected:
const View &_view;
const QColor &_colour;
connect(&_session, SIGNAL(data_updated()),
this, SLOT(data_updated()));
+ connect(&_cursors.first, SIGNAL(time_changed()),
+ this, SLOT(marker_time_changed()));
+ connect(&_cursors.second, SIGNAL(time_changed()),
+ this, SLOT(marker_time_changed()));
+
setViewportMargins(LabelMarginWidth, RulerHeight, 0, 0);
setViewport(_viewport);
_viewport->update();
}
+void View::marker_time_changed()
+{
+ _ruler->update();
+ _viewport->update();
+}
+
} // namespace view
} // namespace pv
void data_updated();
+ void marker_time_changed();
+
private:
SigSession &_session;