mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 03:00:06 +00:00 
			
		
		
		
	Merge pull request #441 from dpaulat/feature/pinch-to-zoom
Pinch to zoom
This commit is contained in:
		
						commit
						4ddff43813
					
				
					 2 changed files with 44 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) | ||||||
|  |    { | ||||||
|  |       map_->scaleBy(gesture->scaleFactor(), | ||||||
|  |                     widget_->mapFromGlobal(gesture->centerPoint())); | ||||||
|  |    } | ||||||
|  | } | ||||||
|  | 
 | ||||||
| common::Level3ProductCategoryMap MapWidget::GetAvailableLevel3Categories() | common::Level3ProductCategoryMap MapWidget::GetAvailableLevel3Categories() | ||||||
| { | { | ||||||
|    if (p->radarProductManager_ != nullptr) |    if (p->radarProductManager_ != nullptr) | ||||||
|  | @ -1396,6 +1409,18 @@ bool MapWidget::event(QEvent* e) | ||||||
|    } |    } | ||||||
|    pickedEventHandler.reset(); |    pickedEventHandler.reset(); | ||||||
| 
 | 
 | ||||||
|  |    switch (e->type()) | ||||||
|  |    { | ||||||
|  |    case QEvent::Type::Gesture: | ||||||
|  |       // QEvent is always a QGestureEvent
 | ||||||
|  |       // NOLINTNEXTLINE(cppcoreguidelines-pro-type-static-cast-downcast)
 | ||||||
|  |       gestureEvent(static_cast<QGestureEvent*>(e)); | ||||||
|  |       break; | ||||||
|  | 
 | ||||||
|  |    default: | ||||||
|  |       break; | ||||||
|  |    } | ||||||
|  | 
 | ||||||
|    return QOpenGLWidget::event(e); |    return QOpenGLWidget::event(e); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -1425,6 +1450,16 @@ void MapWidget::keyReleaseEvent(QKeyEvent* ev) | ||||||
|    } |    } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | void MapWidget::gestureEvent(QGestureEvent* ev) | ||||||
|  | { | ||||||
|  |    if (QGesture* pinch = ev->gesture(Qt::PinchGesture)) | ||||||
|  |    { | ||||||
|  |       // QGesture is always a QPinchGesture
 | ||||||
|  |       // NOLINTNEXTLINE(cppcoreguidelines-pro-type-static-cast-downcast)
 | ||||||
|  |       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
	
	 Dan Paulat
						Dan Paulat