#include <QApplication>
#include <QMouseEvent>
+#include <QTouchEvent>
#include "rowitem.hpp"
#include "view.hpp"
ViewWidget::ViewWidget(View &parent) :
QWidget(&parent),
view_(parent),
- dragging_(false)
+ item_dragging_(false)
{
setFocusPolicy(Qt::ClickFocus);
+ setAttribute(Qt::WA_AcceptTouchEvents, true);
setMouseTracking(true);
}
return false;
}
+bool ViewWidget::mouse_down() const
+{
+ return mouse_down_point_.x() != INT_MIN &&
+ mouse_down_point_.y() != INT_MIN;
+}
+
void ViewWidget::drag_items(const QPoint &delta)
{
// Drag the row items
for (auto &i : items)
i->drag_release();
- if (dragging_)
+ if (item_dragging_)
view_.restack_all_row_items();
else
{
}
}
- dragging_ = false;
+ item_dragging_ = false;
+}
+
+bool ViewWidget::touch_event(QTouchEvent *e)
+{
+ (void)e;
+ return false;
+}
+
+bool ViewWidget::event(QEvent *event)
+{
+ switch (event->type()) {
+ case QEvent::TouchBegin:
+ case QEvent::TouchUpdate:
+ case QEvent::TouchEnd:
+ if (touch_event(static_cast<QTouchEvent *>(event)))
+ return true;
+ break;
+
+ default:
+ break;
+ }
+
+ return QWidget::event(event);
}
void ViewWidget::mousePressEvent(QMouseEvent *event)
if (event->button() & Qt::LeftButton)
mouse_left_release_event(event);
+ mouse_down_point_ = QPoint(INT_MIN, INT_MIN);
mouse_down_item_ = nullptr;
}
return;
// Do the drag
- dragging_ = true;
+ item_dragging_ = true;
drag_items(event->pos() - mouse_down_point_);
update();