return shared_ptr<RowItem>();
}
+bool Header::accept_drag() const
+{
+ // Check all the drag items share a common owner
+ RowItemOwner *item_owner = nullptr;
+ for (shared_ptr<RowItem> r : view_)
+ if (r->dragging()) {
+ if (!item_owner)
+ item_owner = r->owner();
+ else if(item_owner != r->owner())
+ return false;
+ }
+
+ return item_owner;
+}
+
+void Header::drag_items(const QPoint &delta)
+{
+ RowItemOwner *item_owner = nullptr;
+ for (std::shared_ptr<RowItem> r : view_)
+ if (r->dragging()) {
+ item_owner = r->owner();
+ r->drag_by(delta);
+
+ // Ensure the trace is selected
+ r->select();
+ }
+
+ item_owner->restack_items();
+ for (const auto &r : *item_owner)
+ r->animate_to_layout_v_offset();
+ signals_moved();
+}
+
void Header::paintEvent(QPaintEvent*)
{
// The trace labels are not drawn with the arrows exactly on the
painter.end();
}
-void Header::mouseMoveEvent(QMouseEvent *event)
-{
- assert(event);
- mouse_point_ = event->pos();
-
- if (!(event->buttons() & Qt::LeftButton))
- return;
-
- if ((event->pos() - mouse_down_point_).manhattanLength() <
- QApplication::startDragDistance())
- return;
-
- // Check all the drag items share a common owner
- RowItemOwner *item_owner = nullptr;
- for (shared_ptr<RowItem> r : view_)
- if (r->dragging()) {
- if (!item_owner)
- item_owner = r->owner();
- else if(item_owner != r->owner())
- return;
- }
-
- if (!item_owner)
- return;
-
- // Do the drag
- dragging_ = true;
-
- const QPoint delta = event->pos() - mouse_down_point_;
-
- for (std::shared_ptr<RowItem> r : view_)
- if (r->dragging()) {
- r->drag_by(delta);
-
- // Ensure the trace is selected
- r->select();
- }
-
- item_owner->restack_items();
- for (const auto &r : *item_owner)
- r->animate_to_layout_v_offset();
- signals_moved();
-
- update();
-}
-
void Header::contextMenuEvent(QContextMenuEvent *event)
{
const shared_ptr<ViewItem> r = get_mouse_over_item(mouse_point_);
std::shared_ptr<pv::view::ViewItem> get_mouse_over_item(
const QPoint &pt);
+ /**
+ * Returns true if the selection of row items allows dragging.
+ * @return Returns true if the drag is acceptable.
+ */
+ bool accept_drag() const;
+
+ /**
+ * Drag the dragging items by the delta offset.
+ * @param delta the drag offset in pixels.
+ */
+ void drag_items(const QPoint &delta);
+
private:
void paintEvent(QPaintEvent *event);
private:
- void mouseMoveEvent(QMouseEvent *event);
-
void contextMenuEvent(QContextMenuEvent *event);
void keyPressEvent(QKeyEvent *e);
mouse_down_item_ = nullptr;
}
+void MarginWidget::mouseMoveEvent(QMouseEvent *event)
+{
+ assert(event);
+ mouse_point_ = event->pos();
+
+ if (!(event->buttons() & Qt::LeftButton))
+ return;
+
+ if ((event->pos() - mouse_down_point_).manhattanLength() <
+ QApplication::startDragDistance())
+ return;
+
+ if (!accept_drag())
+ return;
+
+ // Do the drag
+ dragging_ = true;
+ drag_items(event->pos() - mouse_down_point_);
+
+ update();
+}
+
void MarginWidget::leaveEvent(QEvent*)
{
mouse_point_ = QPoint(-1, -1);
*/
void show_popup(const std::shared_ptr<ViewItem> &item);
+ /**
+ * Returns true if the selection of row items allows dragging.
+ * @return Returns true if the drag is acceptable.
+ */
+ virtual bool accept_drag() const = 0;
+
+ /**
+ * Drag the dragging items by the delta offset.
+ * @param delta the drag offset in pixels.
+ */
+ virtual void drag_items(const QPoint &delta) = 0;
+
/**
* Handles left mouse button press events.
* @param event the mouse event that triggered this handler.
protected:
void mousePressEvent(QMouseEvent * event);
void mouseReleaseEvent(QMouseEvent *event);
+ void mouseMoveEvent(QMouseEvent *event);
void leaveEvent(QEvent *event);
return nullptr;
}
+bool Ruler::accept_drag() const
+{
+ return true;
+}
+
+void Ruler::drag_items(const QPoint &delta)
+{
+ const vector< shared_ptr<TimeItem> > items(view_.time_items());
+ for (auto &i : items)
+ if (i->dragging())
+ i->drag_by(delta);
+}
+
void Ruler::paintEvent(QPaintEvent*)
{
const int ValueMargin = 3;
}
}
-void Ruler::mouseMoveEvent(QMouseEvent *e)
-{
- mouse_point_ = e->pos();
-
- if (!(e->buttons() & Qt::LeftButton))
- return;
-
- if ((e->pos() - mouse_down_point_).manhattanLength() <
- QApplication::startDragDistance())
- return;
-
- // Do the drag
- dragging_ = true;
-
- 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->drag_by(delta);
-}
-
void Ruler::mouseDoubleClickEvent(QMouseEvent *e)
{
view_.add_flag(view_.offset() + ((double)e->x() + 0.5) * view_.scale());
std::shared_ptr<pv::view::ViewItem> get_mouse_over_item(
const QPoint &pt);
+ /**
+ * Returns true if the selection of time items allows dragging.
+ * @return Returns true if the drag is acceptable.
+ */
+ bool accept_drag() const;
+
+ /**
+ * Drag the dragging items by the delta offset.
+ * @param delta the drag offset in pixels.
+ */
+ void drag_items(const QPoint &delta);
+
private:
void paintEvent(QPaintEvent *event);
- void mouseMoveEvent(QMouseEvent *e);
-
void mouseDoubleClickEvent(QMouseEvent *e);
private: