#include <QPainter>
#include <QTextStream>
+using namespace std;
+
namespace pv {
namespace view {
division++;
}
+ // Draw the cursors
+ draw_cursors(p);
+
// Draw the hover mark
draw_hover_mark(p);
p.end();
}
+void Ruler::draw_cursors(QPainter &p)
+{
+ if(!_view.cursors_shown())
+ return;
+
+ const QRect r = rect();
+ pair<Cursor, Cursor> &cursors = _view.cursors();
+ cursors.first.paint_label(p, r);
+ cursors.second.paint_label(p, r);
+}
+
void Ruler::draw_hover_mark(QPainter &p)
{
const int x = _view.hover_point().x();
void paintEvent(QPaintEvent *event);
private:
+ void draw_cursors(QPainter &p);
+
/**
* Draw a hover arrow under the cursor position.
*/
const int View::SignalHeight = 50;
+const QColor View::CursorAreaColour(220, 231, 243);
+
View::View(SigSession &session, QWidget *parent) :
QAbstractScrollArea(parent),
_session(session),
_scale(1e-6),
_offset(0),
_v_offset(0),
+ _show_cursors(false),
+ _cursors(pair<Cursor, Cursor>(Cursor(*this, 0.0),
+ Cursor(*this, 1.0))),
_hover_point(-1, -1)
{
connect(horizontalScrollBar(), SIGNAL(valueChanged(int)),
_viewport->update();
}
+bool View::cursors_shown() const
+{
+ return _show_cursors;
+}
+
+void View::show_cursors(bool show)
+{
+ _show_cursors = show;
+ _ruler->update();
+ _viewport->update();
+}
+
+std::pair<Cursor, Cursor>& View::cursors()
+{
+ return _cursors;
+}
+
const QPoint& View::hover_point() const
{
return _hover_point;
#include <stdint.h>
+#include <utility>
+
#include <QAbstractScrollArea>
+#include "cursor.h"
+
namespace pv {
class SigSession;
public:
static const int SignalHeight;
+ static const QColor CursorAreaColour;
+
public:
explicit View(SigSession &session, QWidget *parent = 0);
*/
void set_scale_offset(double scale, double offset);
+ /**
+ * Returns true if cursors are displayed. false otherwise.
+ */
+ bool cursors_shown() const;
+
+ /**
+ * Shows or hides the cursors.
+ */
+ void show_cursors(bool show = true);
+
+ /**
+ * Returns a reference to the pair of cursors.
+ */
+ std::pair<Cursor, Cursor>& cursors();
+
const QPoint& hover_point() const;
signals:
int _v_offset;
+ bool _show_cursors;
+ std::pair<Cursor, Cursor> _cursors;
+
QPoint _hover_point;
};
QPainter p(this);
p.setRenderHint(QPainter::Antialiasing);
+ draw_cursors_background(p);
+
// Plot the signal
int offset = -_view.v_offset();
BOOST_FOREACH(const shared_ptr<Signal> s, sigs)
offset += View::SignalHeight;
}
+ draw_cursors_foreground(p);
+
p.end();
}
_view.zoom(event->delta() / 120, event->x());
}
+void Viewport::draw_cursors_background(QPainter &p)
+{
+ if(!_view.cursors_shown())
+ return;
+
+ p.setPen(Qt::NoPen);
+ p.setBrush(QBrush(View::CursorAreaColour));
+
+ const pair<Cursor, Cursor> &c = _view.cursors();
+ const float x1 = (c.first.time() - _view.offset()) / _view.scale();
+ const float x2 = (c.second.time() - _view.offset()) / _view.scale();
+ const int l = (int)max(min(x1, x2), 0.0f);
+ const int r = (int)min(max(x1, x2), (float)width());
+
+ p.drawRect(l, 0, r - l, height());
+}
+
+void Viewport::draw_cursors_foreground(QPainter &p)
+{
+ if(!_view.cursors_shown())
+ return;
+
+ const QRect r = rect();
+ pair<Cursor, Cursor> &cursors = _view.cursors();
+ cursors.first.paint(p, r);
+ cursors.second.paint(p, r);
+}
+
} // namespace view
} // namespace pv
void mouseReleaseEvent(QMouseEvent *event);
void wheelEvent(QWheelEvent *event);
+private:
+ void draw_cursors_background(QPainter &p);
+
+ void draw_cursors_foreground(QPainter &p);
+
private:
View &_view;