#include <pv/session.hpp>
#include <QMouseEvent>
+#include <QScreen>
+#include <QWindow>
#include <QDebug>
{
setAutoFillBackground(true);
setBackgroundRole(QPalette::Base);
+
+ // Set up settings and event handlers
+ GlobalSettings settings;
+ allow_vertical_dragging_ = settings.value(GlobalSettings::Key_View_AllowVerticalDragging).toBool();
+
+ GlobalSettings::add_change_handler(this);
+}
+
+Viewport::~Viewport()
+{
+ GlobalSettings::remove_change_handler(this);
}
shared_ptr<ViewItem> Viewport::get_mouse_over_item(const QPoint &pt)
void Viewport::item_hover(const shared_ptr<ViewItem> &item, QPoint pos)
{
if (item && item->is_draggable(pos))
- setCursor(dynamic_pointer_cast<RowItem>(item) ?
- Qt::SizeVerCursor : Qt::SizeHorCursor);
+ setCursor(dynamic_pointer_cast<ViewItem>(item) ?
+ Qt::SizeHorCursor : Qt::SizeVerCursor);
else
unsetCursor();
}
void Viewport::drag()
{
drag_offset_ = view_.offset();
- drag_v_offset_ = view_.owner_visual_v_offset();
+
+ if (allow_vertical_dragging_)
+ drag_v_offset_ = view_.owner_visual_v_offset();
}
void Viewport::drag_by(const QPoint &delta)
view_.set_scale_offset(view_.scale(),
(*drag_offset_ - delta.x() * view_.scale()));
- view_.set_v_offset(-drag_v_offset_ - delta.y());
+ if (allow_vertical_dragging_)
+ view_.set_v_offset(-drag_v_offset_ - delta.y());
}
void Viewport::drag_release()
bool Viewport::touch_event(QTouchEvent *event)
{
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+ QList<QEventPoint> touchPoints = event->points();
+#else
QList<QTouchEvent::TouchPoint> touchPoints = event->touchPoints();
+#endif
if (touchPoints.count() != 2) {
pinch_zoom_active_ = false;
return false;
}
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+ if (event->device()->type() == QInputDevice::DeviceType::TouchPad) {
+ return false;
+ }
+
+ const QEventPoint &touchPoint0 = touchPoints.first();
+ const QEventPoint &touchPoint1 = touchPoints.last();
+
+ if (!pinch_zoom_active_ ||
+ (event->touchPointStates() & QEventPoint::Pressed)) {
+ pinch_offset0_ = (view_.offset() + view_.scale() * touchPoint0.position().x()).convert_to<double>();
+ pinch_offset1_ = (view_.offset() + view_.scale() * touchPoint1.position().x()).convert_to<double>();
+ pinch_zoom_active_ = true;
+ }
+
+ double w = touchPoint1.position().x() - touchPoint0.position().x();
+ if (abs(w) >= 1.0) {
+ const double scale =
+ fabs((pinch_offset1_ - pinch_offset0_) / w);
+ double offset = pinch_offset0_ - touchPoint0.position().x() * scale;
+ if (scale > 0)
+ view_.set_scale_offset(scale, offset);
+ }
+#else
+ if (event->device()->type() == QTouchDevice::TouchPad) {
+ return false;
+ }
const QTouchEvent::TouchPoint &touchPoint0 = touchPoints.first();
const QTouchEvent::TouchPoint &touchPoint1 = touchPoints.last();
if (scale > 0)
view_.set_scale_offset(scale, offset);
}
+#endif
if (event->touchPointStates() & Qt::TouchPointReleased) {
pinch_zoom_active_ = false;
} else {
// Update the mouse down fields so that continued
// dragging with the primary touch will work correctly
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+ mouse_down_point_ = touchPoint0.position().toPoint();
+#else
mouse_down_point_ = touchPoint0.pos().toPoint();
+#endif
drag();
}
}
&ViewItem::paint_back, &ViewItem::paint_mid,
&ViewItem::paint_fore, nullptr};
- vector< shared_ptr<RowItem> > row_items(view_.list_by_type<RowItem>());
+ vector< shared_ptr<ViewItem> > row_items(view_.list_by_type<ViewItem>());
assert(none_of(row_items.begin(), row_items.end(),
- [](const shared_ptr<RowItem> &r) { return !r; }));
+ [](const shared_ptr<ViewItem> &r) { return !r; }));
stable_sort(row_items.begin(), row_items.end(),
- [](const shared_ptr<RowItem> &a, const shared_ptr<RowItem> &b) {
+ [](const shared_ptr<ViewItem> &a, const shared_ptr<ViewItem> &b) {
return a->drag_point(QRect()).y() < b->drag_point(QRect()).y(); });
const vector< shared_ptr<TimeItem> > time_items(view_.time_items());
[](const shared_ptr<TimeItem> &t) { return !t; }));
QPainter p(this);
- p.setRenderHint(QPainter::Antialiasing);
+
+ // Disable antialiasing for high-DPI displays
+ bool use_antialiasing =
+ window()->windowHandle()->screen()->devicePixelRatio() < 2.0;
+ p.setRenderHint(QPainter::Antialiasing, use_antialiasing);
for (LayerPaintFunc *paint_func = layer_paint_funcs;
*paint_func; paint_func++) {
(t.get()->*(*paint_func))(p, time_pp);
ViewItemPaintParams row_pp(rect(), view_.scale(), view_.offset());
- for (const shared_ptr<RowItem>& r : row_items)
+ for (const shared_ptr<ViewItem>& r : row_items)
(r.get()->*(*paint_func))(p, row_pp);
}
{
assert(event);
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+ if (event->buttons() & Qt::LeftButton)
+ view_.zoom(2.0, event->position().x());
+ else if (event->buttons() & Qt::RightButton)
+ view_.zoom(-2.0, event->position().x());
+#else
if (event->buttons() & Qt::LeftButton)
view_.zoom(2.0, event->x());
else if (event->buttons() & Qt::RightButton)
view_.zoom(-2.0, event->x());
+#endif
}
void Viewport::wheelEvent(QWheelEvent *event)
{
assert(event);
+#if QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)
+ int delta = (event->angleDelta().x() != 0) ? event->angleDelta().x() : event->angleDelta().y();
+#else
+ int delta = event->delta();
+#endif
+
+#if QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)
+ if (event->angleDelta().y() != 0) {
+#else
if (event->orientation() == Qt::Vertical) {
+#endif
if (event->modifiers() & Qt::ControlModifier) {
// Vertical scrolling with the control key pressed
// is intrepretted as vertical scrolling
view_.set_v_offset(-view_.owner_visual_v_offset() -
- (event->delta() * height()) / (8 * 120));
+ (delta * height()) / (8 * 120));
+ } else if (event->modifiers() & Qt::ShiftModifier) {
+ // Vertical scrolling with the shift key pressed
+ // acts as horizontal scrolling like in Gimp
+ // and Inkscape.
+ view_.set_scale_offset(view_.scale(),
+ - delta * view_.scale() + view_.offset());
} else {
// Vertical scrolling is interpreted as zooming in/out
- view_.zoom(event->delta() / 120.0, event->x());
+#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
+ view_.zoom(delta / 120.0, event->position().x());
+#else
+ view_.zoom(delta / 120.0, event->x());
+#endif
}
+#if QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)
+ } else if (event->angleDelta().x() != 0) {
+#else
} else if (event->orientation() == Qt::Horizontal) {
+#endif
// Horizontal scrolling is interpreted as moving left/right
view_.set_scale_offset(view_.scale(),
- event->delta() * view_.scale() + view_.offset());
+ delta * view_.scale() + view_.offset());
}
}
+void Viewport::on_setting_changed(const QString &key, const QVariant &value)
+{
+ if (key == GlobalSettings::Key_View_AllowVerticalDragging)
+ allow_vertical_dragging_ = value.toBool();
+}
+
} // namespace trace
} // namespace views
} // namespace pv