#include <extdef.h>
+using namespace boost;
+
namespace pv {
namespace view {
const int Cursor::ArrowSize = 4;
-Cursor::Cursor(const View &view, double time, Cursor &other) :
- TimeMarker(view, LineColour, time),
- _other(other)
+Cursor::Cursor(const View &view, double time) :
+ TimeMarker(view, LineColour, time)
{
}
QRectF Cursor::get_label_rect(const QRect &rect) const
{
+ const shared_ptr<Cursor> other(get_other_cursor());
+ assert(other);
+
const float x = (_time - _view.offset()) / _view.scale();
const QSizeF label_size(
Cursor::Offset - Cursor::ArrowSize - 0.5f;
const float height = label_size.height();
- if (_time > _other.time())
+ if (_time > other->time())
return QRectF(x, top, label_size.width(), height);
else
return QRectF(x - label_size.width(), top,
void Cursor::paint_label(QPainter &p, const QRect &rect,
unsigned int prefix)
{
+ const shared_ptr<Cursor> other(get_other_cursor());
+ assert(other);
+
compute_text_size(p, prefix);
const QRectF r(get_label_rect(rect));
QPointF(r.right() - 1, rect.bottom() - 1),
};
- const QPointF *const points = (_time > _other.time()) ?
+ const QPointF *const points = (_time > other->time()) ?
left_points : right_points;
- const QPointF *const highlight_points = (_time > _other.time()) ?
+ const QPointF *const highlight_points = (_time > other->time()) ?
left_highlight_points : right_highlight_points;
if (selected()) {
Ruler::format_time(_time, prefix, 2)).size();
}
+shared_ptr<Cursor> Cursor::get_other_cursor() const
+{
+ const CursorPair &cursors = _view.cursors();
+ return (cursors.first().get() == this) ?
+ cursors.second() : cursors.first();
+}
+
} // namespace view
} // namespace pv
#include "timemarker.h"
+#include <boost/shared_ptr.hpp>
+
#include <QSizeF>
class QPainter;
* Constructor.
* @param view A reference to the view that owns this cursor pair.
* @param time The time to set the flag to.
- * @param other A reference to the other cursor.
*/
- Cursor(const View &view, double time, Cursor &other);
+ Cursor(const View &view, double time);
public:
/**
private:
void compute_text_size(QPainter &p, unsigned int prefix);
-private:
- const Cursor &_other;
+ boost::shared_ptr<Cursor> get_other_cursor() const;
+private:
QSizeF _text_size;
};
#include <algorithm>
+using namespace boost;
using namespace std;
namespace pv {
const int CursorPair::DeltaPadding = 8;
CursorPair::CursorPair(const View &view) :
- _first(view, 0.0, _second),
- _second(view, 1.0, _first),
+ _first(new Cursor(view, 0.0)),
+ _second(new Cursor(view, 1.0)),
_view(view)
{
}
-const Cursor& CursorPair::first() const
+shared_ptr<Cursor> CursorPair::first() const
{
return _first;
}
-Cursor& CursorPair::first()
-{
- return _first;
-}
-
-const Cursor& CursorPair::second() const
-{
- return _second;
-}
-
-Cursor& CursorPair::second()
+shared_ptr<Cursor> CursorPair::second() const
{
return _second;
}
void CursorPair::draw_markers(QPainter &p,
const QRect &rect, unsigned int prefix)
{
+ assert(_first);
+ assert(_second);
+
compute_text_size(p, prefix);
QRectF delta_rect(get_label_rect(rect));
p.setPen(Cursor::TextColour);
p.drawText(text_rect, Qt::AlignCenter | Qt::AlignVCenter,
- Ruler::format_time(_second.time() - _first.time(), prefix, 2));
+ Ruler::format_time(_second->time() - _first->time(), prefix, 2));
}
// Paint the cursor markers
- _first.paint_label(p, rect, prefix);
- _second.paint_label(p, rect, prefix);
+ _first->paint_label(p, rect, prefix);
+ _second->paint_label(p, rect, prefix);
}
void CursorPair::draw_viewport_background(QPainter &p,
void CursorPair::draw_viewport_foreground(QPainter &p,
const QRect &rect)
{
- _first.paint(p, rect);
- _second.paint(p, rect);
+ assert(_first);
+ assert(_second);
+
+ _first->paint(p, rect);
+ _second->paint(p, rect);
}
void CursorPair::compute_text_size(QPainter &p, unsigned int prefix)
{
+ assert(_first);
+ assert(_second);
+
_text_size = p.boundingRect(QRectF(), 0, Ruler::format_time(
- _second.time() - _first.time(), prefix, 2)).size();
+ _second->time() - _first->time(), prefix, 2)).size();
}
pair<float, float> CursorPair::get_cursor_offsets() const
{
+ assert(_first);
+ assert(_second);
+
return pair<float, float>(
- (_first.time() - _view.offset()) / _view.scale(),
- (_second.time() - _view.offset()) / _view.scale());
+ (_first->time() - _view.offset()) / _view.scale(),
+ (_second->time() - _view.offset()) / _view.scale());
}
} // namespace view
#include "cursor.h"
+#include <boost/shared_ptr.hpp>
+
#include <QPainter>
class QPainter;
CursorPair(const View &view);
/**
- * Returns a reference to the first cursor.
- */
- Cursor& first();
-
- /**
- * Returns a reference to the first cursor.
- */
- const Cursor& first() const;
-
- /**
- * Returns a reference to the second cursor.
+ * Returns a pointer to the first cursor.
*/
- Cursor& second();
+ boost::shared_ptr<Cursor> first() const;
/**
- * Returns a reference to the second cursor.
+ * Returns a pointer to the second cursor.
*/
- const Cursor& second() const;
+ boost::shared_ptr<Cursor> second() const;
public:
QRectF get_label_rect(const QRect &rect) const;
std::pair<float, float> get_cursor_offsets() const;
private:
- Cursor _first, _second;
+ boost::shared_ptr<Cursor> _first, _second;
const View &_view;
QSizeF _text_size;
#include <QPainter>
#include <QTextStream>
+using namespace boost;
using namespace std;
namespace pv {
const int Ruler::HoverArrowSize = 5;
Ruler::Ruler(View &parent) :
- MarginWidget(parent),
- _grabbed_marker(NULL)
+ MarginWidget(parent)
{
setMouseTracking(true);
void Ruler::clear_selection()
{
CursorPair &cursors = _view.cursors();
- cursors.first().select(false);
- cursors.second().select(false);
+ cursors.first()->select(false);
+ cursors.second()->select(false);
update();
}
void Ruler::mouseMoveEvent(QMouseEvent *e)
{
- if (!_grabbed_marker)
- return;
-
- _grabbed_marker->set_time(_view.offset() +
- ((double)e->x() + 0.5) * _view.scale());
+ if (shared_ptr<TimeMarker> m = _grabbed_marker.lock())
+ m->set_time(_view.offset() +
+ ((double)e->x() + 0.5) * _view.scale());
}
void Ruler::mousePressEvent(QMouseEvent *e)
{
if (e->buttons() & Qt::LeftButton) {
- _grabbed_marker = NULL;
+ _grabbed_marker.reset();
clear_selection();
if (_view.cursors_shown()) {
CursorPair &cursors = _view.cursors();
- if (cursors.first().get_label_rect(
+ if (cursors.first()->get_label_rect(
rect()).contains(e->pos()))
- _grabbed_marker = &cursors.first();
- else if (cursors.second().get_label_rect(
+ _grabbed_marker = cursors.first();
+ else if (cursors.second()->get_label_rect(
rect()).contains(e->pos()))
- _grabbed_marker = &cursors.second();
+ _grabbed_marker = cursors.second();
}
- if(_grabbed_marker)
- _grabbed_marker->select();
+ if (shared_ptr<TimeMarker> m = _grabbed_marker.lock())
+ m->select();
selection_changed();
}
void Ruler::mouseReleaseEvent(QMouseEvent *)
{
- _grabbed_marker = NULL;
+ _grabbed_marker.reset();
}
void Ruler::draw_hover_mark(QPainter &p)
{
const int x = _view.hover_point().x();
- if (x == -1 || _grabbed_marker)
+ if (x == -1 || !_grabbed_marker.expired())
return;
p.setPen(QPen(Qt::NoPen));
#ifndef PULSEVIEW_PV_VIEW_RULER_H
#define PULSEVIEW_PV_VIEW_RULER_H
+#include <boost/weak_ptr.hpp>
+
#include "marginwidget.h"
namespace pv {
void hover_point_changed();
private:
- TimeMarker *_grabbed_marker;
+ boost::weak_ptr<TimeMarker> _grabbed_marker;
};
} // namespace view
connect(&_session, SIGNAL(data_updated()),
this, SLOT(data_updated()));
- connect(&_cursors.first(), SIGNAL(time_changed()),
+ connect(_cursors.first().get(), SIGNAL(time_changed()),
this, SLOT(marker_time_changed()));
- connect(&_cursors.second(), SIGNAL(time_changed()),
+ connect(_cursors.second().get(), SIGNAL(time_changed()),
this, SLOT(marker_time_changed()));
connect(_header, SIGNAL(signals_moved()),
void View::centre_cursors()
{
const double time_width = _scale * _viewport->width();
- _cursors.first().set_time(_offset + time_width * 0.4);
- _cursors.second().set_time(_offset + time_width * 0.6);
+ _cursors.first()->set_time(_offset + time_width * 0.4);
+ _cursors.second()->set_time(_offset + time_width * 0.6);
_ruler->update();
_viewport->update();
}
return _cursors;
}
+const CursorPair& View::cursors() const
+{
+ return _cursors;
+}
+
const QPoint& View::hover_point() const
{
return _hover_point;
*/
CursorPair& cursors();
+ /**
+ * Returns a reference to the pair of cursors.
+ */
+ const CursorPair& cursors() const;
+
const QPoint& hover_point() const;
void normalize_layout();