mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 21:10:04 +00:00
Pinch to zoom functionality
This commit is contained in:
parent
ef480f6d10
commit
b169f46f5f
2 changed files with 40 additions and 7 deletions
|
|
@ -53,6 +53,7 @@
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
#include <QKeyEvent>
|
#include <QKeyEvent>
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
|
#include <QPinchGesture>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QTextDocument>
|
#include <QTextDocument>
|
||||||
|
|
||||||
|
|
@ -169,6 +170,7 @@ public:
|
||||||
void HandleHotkeyPressed(types::Hotkey hotkey, bool isAutoRepeat);
|
void HandleHotkeyPressed(types::Hotkey hotkey, bool isAutoRepeat);
|
||||||
void HandleHotkeyReleased(types::Hotkey hotkey);
|
void HandleHotkeyReleased(types::Hotkey hotkey);
|
||||||
void HandleHotkeyUpdates();
|
void HandleHotkeyUpdates();
|
||||||
|
void HandlePinchGesture(QPinchGesture* gesture);
|
||||||
void ImGuiCheckFonts();
|
void ImGuiCheckFonts();
|
||||||
void InitializeCustomStyles();
|
void InitializeCustomStyles();
|
||||||
void InitializeNewRadarProductView(const std::string& colorPalette);
|
void InitializeNewRadarProductView(const std::string& colorPalette);
|
||||||
|
|
@ -293,6 +295,8 @@ MapWidget::MapWidget(std::size_t id, const QMapLibre::Settings& settings) :
|
||||||
|
|
||||||
setFocusPolicy(Qt::StrongFocus);
|
setFocusPolicy(Qt::StrongFocus);
|
||||||
|
|
||||||
|
grabGesture(Qt::GestureType::PinchGesture);
|
||||||
|
|
||||||
ImGui_ImplQt_RegisterWidget(this);
|
ImGui_ImplQt_RegisterWidget(this);
|
||||||
|
|
||||||
// Qt parent deals with memory management
|
// Qt parent deals with memory management
|
||||||
|
|
@ -603,6 +607,15 @@ void MapWidgetImpl::HandleHotkeyUpdates()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MapWidgetImpl::HandlePinchGesture(QPinchGesture* gesture)
|
||||||
|
{
|
||||||
|
if (gesture->changeFlags() & QPinchGesture::ChangeFlag::ScaleFactorChanged)
|
||||||
|
{
|
||||||
|
double scale = gesture->scaleFactor();
|
||||||
|
map_->scaleBy(scale, widget_->mapFromGlobal(gesture->centerPoint()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
common::Level3ProductCategoryMap MapWidget::GetAvailableLevel3Categories()
|
common::Level3ProductCategoryMap MapWidget::GetAvailableLevel3Categories()
|
||||||
{
|
{
|
||||||
if (p->radarProductManager_ != nullptr)
|
if (p->radarProductManager_ != nullptr)
|
||||||
|
|
@ -1396,6 +1409,16 @@ bool MapWidget::event(QEvent* e)
|
||||||
}
|
}
|
||||||
pickedEventHandler.reset();
|
pickedEventHandler.reset();
|
||||||
|
|
||||||
|
switch (e->type())
|
||||||
|
{
|
||||||
|
case QEvent::Type::Gesture:
|
||||||
|
gestureEvent(static_cast<QGestureEvent*>(e));
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
return QOpenGLWidget::event(e);
|
return QOpenGLWidget::event(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1425,6 +1448,14 @@ void MapWidget::keyReleaseEvent(QKeyEvent* ev)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MapWidget::gestureEvent(QGestureEvent* ev)
|
||||||
|
{
|
||||||
|
if (QGesture* pinch = ev->gesture(Qt::PinchGesture))
|
||||||
|
{
|
||||||
|
p->HandlePinchGesture(static_cast<QPinchGesture*>(pinch));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MapWidget::mousePressEvent(QMouseEvent* ev)
|
void MapWidget::mousePressEvent(QMouseEvent* ev)
|
||||||
{
|
{
|
||||||
p->lastPos_ = ev->position();
|
p->lastPos_ = ev->position();
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@
|
||||||
|
|
||||||
#include <qmaplibre.hpp>
|
#include <qmaplibre.hpp>
|
||||||
|
|
||||||
|
#include <QGestureEvent>
|
||||||
#include <QOpenGLWidget>
|
#include <QOpenGLWidget>
|
||||||
#include <QPropertyAnimation>
|
#include <QPropertyAnimation>
|
||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
|
|
@ -137,13 +138,14 @@ private:
|
||||||
|
|
||||||
// QWidget implementation.
|
// QWidget implementation.
|
||||||
bool event(QEvent* e) override;
|
bool event(QEvent* e) override;
|
||||||
void enterEvent(QEnterEvent* ev) override final;
|
void enterEvent(QEnterEvent* ev) final;
|
||||||
void keyPressEvent(QKeyEvent* ev) override final;
|
void keyPressEvent(QKeyEvent* ev) final;
|
||||||
void keyReleaseEvent(QKeyEvent* ev) override final;
|
void keyReleaseEvent(QKeyEvent* ev) final;
|
||||||
void leaveEvent(QEvent* ev) override final;
|
void gestureEvent(QGestureEvent* ev);
|
||||||
void mousePressEvent(QMouseEvent* ev) override final;
|
void leaveEvent(QEvent* ev) final;
|
||||||
void mouseMoveEvent(QMouseEvent* ev) override final;
|
void mousePressEvent(QMouseEvent* ev) final;
|
||||||
void wheelEvent(QWheelEvent* ev) override final;
|
void mouseMoveEvent(QMouseEvent* ev) final;
|
||||||
|
void wheelEvent(QWheelEvent* ev) final;
|
||||||
|
|
||||||
// QOpenGLWidget implementation.
|
// QOpenGLWidget implementation.
|
||||||
void initializeGL() override final;
|
void initializeGL() override final;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue