// Do the drag
dragging_ = true;
- const int delta = event->pos().y() - mouse_down_point_.y();
+ const QPoint delta = event->pos() - mouse_down_point_;
for (std::shared_ptr<RowItem> r : view_)
if (r->dragging()) {
- r->force_to_v_offset(r->drag_point().y() + delta);
+ r->drag_by(delta);
// Ensure the trace is selected
r->select();
return visual_v_offset_ + owner_->owner_visual_v_offset();
}
+void RowItem::drag_by(const QPoint &delta)
+{
+ force_to_v_offset(drag_point_.y() + delta.y() -
+ owner_->owner_visual_v_offset());
+}
+
QPoint RowItem::point(const QRect &rect) const
{
return QPoint(rect.right(), get_visual_y());
*/
int get_visual_y() const;
+ /**
+ * Drags the item to a delta relative to the drag point.
+ * @param delta the offset from the drag point.
+ */
+ void drag_by(const QPoint &delta);
+
/**
* Gets the arrow-tip point of the row item marker.
* @param rect the rectangle of the header area.
// Do the drag
dragging_ = true;
- const int delta = e->pos().x() - mouse_down_point_.x();
+ const QPoint delta = e->pos() - mouse_down_point_;
const vector< shared_ptr<TimeItem> > items(view_.time_items());
for (auto &i : items)
if (i->dragging())
- i->set_time(view_.offset() +
- (i->drag_point().x() + delta - 0.5) *
- view_.scale());
+ i->drag_by(delta);
}
void Ruler::mousePressEvent(QMouseEvent *e)
*/
#include "timeitem.hpp"
+#include "view.hpp"
namespace pv {
namespace view {
view_(view) {
}
+void TimeItem::drag_by(const QPoint &delta)
+{
+ set_time(view_.offset() + (drag_point_.x() + delta.x() - 0.5) *
+ view_.scale());
+}
+
} // namespace view
} // namespace pv
virtual float get_x() const = 0;
+ /**
+ * Drags the item to a delta relative to the drag point.
+ * @param delta the offset from the drag point.
+ */
+ void drag_by(const QPoint &delta);
+
protected:
View &view_;
};
ViewItem::ViewItem() :
context_parent_(NULL),
- selected_(false),
- drag_point_(INT_MIN, INT_MIN)
+ drag_point_(INT_MIN, INT_MIN),
+ selected_(false)
{
}
return drag_point_.x() != INT_MIN && drag_point_.y() != INT_MIN;
}
-QPoint ViewItem::drag_point() const
-{
- return drag_point_;
-}
-
void ViewItem::drag()
{
drag_point_ = point(QRect());
*/
bool dragging() const;
- /**
- * Retunrns the current drag point.
- */
- QPoint drag_point() const;
-
/**
* Sets this item into the dragged state.
*/
*/
void drag_release();
+ /**
+ * Drags the item to a delta relative to the drag point.
+ * @param delta the offset from the drag point.
+ */
+ virtual void drag_by(const QPoint &delta) = 0;
+
/**
* Get the drag point.
* @param rect the rectangle of the widget area.
protected:
QWidget *context_parent_;
+ QPoint drag_point_;
private:
bool selected_;
- QPoint drag_point_;
};
} // namespace view