#include <cassert>
#include <cmath>
#include <algorithm>
+#include <limits>
#include "signal.hpp"
#include "view.hpp"
using std::max;
using std::min;
using std::none_of;
+using std::numeric_limits;
using std::shared_ptr;
using std::stable_sort;
using std::vector;
Viewport::Viewport(View &parent) :
ViewWidget(parent),
- mouse_down_valid_(false),
+ drag_offset_(numeric_limits<double>::signaling_NaN()),
pinch_zoom_active_(false)
{
setAutoFillBackground(true);
return nullptr;
}
+void Viewport::drag()
+{
+ drag_offset_ = view_.offset();
+}
+
+void Viewport::drag_by(const QPoint &delta)
+{
+ if (isnan(drag_offset_))
+ return;
+
+ view_.set_scale_offset(view_.scale(), drag_offset_ -
+ delta.x() * view_.scale());
+}
+
+void Viewport::drag_release()
+{
+ drag_offset_ = numeric_limits<double>::signaling_NaN();
+}
+
vector< shared_ptr<ViewItem> > Viewport::items()
{
vector< shared_ptr<ViewItem> > items(view_.begin(), view_.end());
if (touchPoint0.state() & Qt::TouchPointReleased) {
// Primary touch released
- mouse_down_valid_ = false;
+ drag_release();
} else {
// Update the mouse down fields so that continued
// dragging with the primary touch will work correctly
mouse_down_point_ = touchPoint0.pos().toPoint();
- mouse_down_offset_ = view_.offset();
- mouse_down_valid_ = true;
+ drag();
}
}
p.end();
}
-void Viewport::mousePressEvent(QMouseEvent *event)
-{
- assert(event);
-
- if (event->button() == Qt::LeftButton) {
- mouse_down_point_ = event->pos();
- mouse_down_offset_ = view_.offset();
- mouse_down_valid_ = true;
- }
-}
-
-void Viewport::mouseReleaseEvent(QMouseEvent *event)
-{
- assert(event);
-
- if (event->button() == Qt::LeftButton)
- mouse_down_valid_ = false;
-}
-
-void Viewport::mouseMoveEvent(QMouseEvent *event)
-{
- assert(event);
-
- if (event->buttons() & Qt::LeftButton) {
- if (!mouse_down_valid_) {
- mouse_down_point_ = event->pos();
- mouse_down_offset_ = view_.offset();
- mouse_down_valid_ = true;
- }
-
- view_.set_scale_offset(view_.scale(),
- mouse_down_offset_ +
- (mouse_down_point_ - event->pos()).x() *
- view_.scale());
- }
-}
-
void Viewport::mouseDoubleClickEvent(QMouseEvent *event)
{
assert(event);
std::shared_ptr<pv::view::ViewItem> get_mouse_over_item(
const QPoint &pt);
+ /**
+ * Sets this item into the dragged state.
+ */
+ void drag();
+
+ /**
+ * Drag the background by the delta offset.
+ * @param delta the drag offset in pixels.
+ */
+ void drag_by(const QPoint &delta);
+
+ /**
+ * Sets this item into the un-dragged state.
+ */
+ void drag_release();
+
/**
* Gets the items in the view widget.
*/
private:
void paintEvent(QPaintEvent *event);
- void mousePressEvent(QMouseEvent *event);
- void mouseReleaseEvent(QMouseEvent *event);
- void mouseMoveEvent(QMouseEvent *event);
void mouseDoubleClickEvent(QMouseEvent * event);
void wheelEvent(QWheelEvent *event);
+
private:
- QPoint mouse_down_point_;
- double mouse_down_offset_;
- bool mouse_down_valid_;
+ double drag_offset_;
double pinch_offset0_;
double pinch_offset1_;
return true;
}
- return false;
+ // A background drag is beginning
+ return true;
}
bool ViewWidget::mouse_down() const
void ViewWidget::drag_items(const QPoint &delta)
{
+ bool item_dragged = false;
+
// Drag the row items
RowItemOwner *item_owner = nullptr;
for (std::shared_ptr<RowItem> r : view_)
}
if (item_owner) {
+ item_dragged = true;
item_owner->restack_items();
for (const auto &r : *item_owner)
r->animate_to_layout_v_offset();
// Drag the time items
const vector< shared_ptr<TimeItem> > items(view_.time_items());
for (auto &i : items)
- if (i->dragging())
+ if (i->dragging()) {
i->drag_by(delta);
+ item_dragged = true;
+ }
+
+ // Do the background drag
+ if (!item_dragged)
+ drag_by(delta);
+}
+
+void ViewWidget::drag()
+{
+}
+
+void ViewWidget::drag_by(const QPoint &delta)
+{
+ (void)delta;
+}
+
+void ViewWidget::drag_release()
+{
}
void ViewWidget::mouse_left_press_event(QMouseEvent *event)
}
// Save the offsets of any signals which will be dragged
+ bool item_dragged = false;
const auto items = this->items();
for (auto &i : items)
- if (i->selected())
+ if (i->selected()) {
+ item_dragged = true;
i->drag();
+ }
+
+ // Do the background drag
+ if (!item_dragged)
+ drag();
selection_changed();
update();
*/
void drag_items(const QPoint &delta);
+ /**
+ * Sets this item into the dragged state.
+ */
+ virtual void drag();
+
+ /**
+ * Drag the background by the delta offset.
+ * @param delta the drag offset in pixels.
+ * @remarks The default implementation does nothing.
+ */
+ virtual void drag_by(const QPoint &delta);
+
+ /**
+ * Sets this item into the un-dragged state.
+ */
+ virtual void drag_release();
+
/**
* Gets the items in the view widget.
*/