mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 06:40:05 +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(); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat