mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 16: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 <QKeyEvent>
|
||||
#include <QMouseEvent>
|
||||
#include <QPinchGesture>
|
||||
#include <QString>
|
||||
#include <QTextDocument>
|
||||
|
||||
|
|
@ -169,6 +170,7 @@ public:
|
|||
void HandleHotkeyPressed(types::Hotkey hotkey, bool isAutoRepeat);
|
||||
void HandleHotkeyReleased(types::Hotkey hotkey);
|
||||
void HandleHotkeyUpdates();
|
||||
void HandlePinchGesture(QPinchGesture* gesture);
|
||||
void ImGuiCheckFonts();
|
||||
void InitializeCustomStyles();
|
||||
void InitializeNewRadarProductView(const std::string& colorPalette);
|
||||
|
|
@ -293,6 +295,8 @@ MapWidget::MapWidget(std::size_t id, const QMapLibre::Settings& settings) :
|
|||
|
||||
setFocusPolicy(Qt::StrongFocus);
|
||||
|
||||
grabGesture(Qt::GestureType::PinchGesture);
|
||||
|
||||
ImGui_ImplQt_RegisterWidget(this);
|
||||
|
||||
// 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()
|
||||
{
|
||||
if (p->radarProductManager_ != nullptr)
|
||||
|
|
@ -1396,6 +1409,16 @@ bool MapWidget::event(QEvent* e)
|
|||
}
|
||||
pickedEventHandler.reset();
|
||||
|
||||
switch (e->type())
|
||||
{
|
||||
case QEvent::Type::Gesture:
|
||||
gestureEvent(static_cast<QGestureEvent*>(e));
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
p->lastPos_ = ev->position();
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@
|
|||
|
||||
#include <qmaplibre.hpp>
|
||||
|
||||
#include <QGestureEvent>
|
||||
#include <QOpenGLWidget>
|
||||
#include <QPropertyAnimation>
|
||||
#include <QtGlobal>
|
||||
|
|
@ -137,13 +138,14 @@ private:
|
|||
|
||||
// QWidget implementation.
|
||||
bool event(QEvent* e) override;
|
||||
void enterEvent(QEnterEvent* ev) override final;
|
||||
void keyPressEvent(QKeyEvent* ev) override final;
|
||||
void keyReleaseEvent(QKeyEvent* ev) override final;
|
||||
void leaveEvent(QEvent* ev) override final;
|
||||
void mousePressEvent(QMouseEvent* ev) override final;
|
||||
void mouseMoveEvent(QMouseEvent* ev) override final;
|
||||
void wheelEvent(QWheelEvent* ev) override final;
|
||||
void enterEvent(QEnterEvent* ev) final;
|
||||
void keyPressEvent(QKeyEvent* ev) final;
|
||||
void keyReleaseEvent(QKeyEvent* ev) final;
|
||||
void gestureEvent(QGestureEvent* ev);
|
||||
void leaveEvent(QEvent* ev) final;
|
||||
void mousePressEvent(QMouseEvent* ev) final;
|
||||
void mouseMoveEvent(QMouseEvent* ev) final;
|
||||
void wheelEvent(QWheelEvent* ev) final;
|
||||
|
||||
// QOpenGLWidget implementation.
|
||||
void initializeGL() override final;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue