mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 10:10:05 +00:00 
			
		
		
		
	Hotkey repeat handling update
This commit is contained in:
		
							parent
							
								
									399894f2db
								
							
						
					
					
						commit
						dcaba52db7
					
				
					 3 changed files with 18 additions and 15 deletions
				
			
		|  | @ -71,7 +71,7 @@ void HotkeyManager::HandleKeyPress(QKeyEvent* ev) | ||||||
|       if (hotkey.second.count() == 1 && |       if (hotkey.second.count() == 1 && | ||||||
|           hotkey.second[0] == ev->keyCombination()) |           hotkey.second[0] == ev->keyCombination()) | ||||||
|       { |       { | ||||||
|          Q_EMIT HotkeyPressed(hotkey.first); |          Q_EMIT HotkeyPressed(hotkey.first, ev->isAutoRepeat()); | ||||||
|       } |       } | ||||||
|    } |    } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -30,7 +30,7 @@ public: | ||||||
|    static std::shared_ptr<HotkeyManager> Instance(); |    static std::shared_ptr<HotkeyManager> Instance(); | ||||||
| 
 | 
 | ||||||
| signals: | signals: | ||||||
|    void HotkeyPressed(scwx::qt::types::Hotkey hotkey); |    void HotkeyPressed(scwx::qt::types::Hotkey hotkey, bool isAutoRepeat); | ||||||
|    void HotkeyReleased(scwx::qt::types::Hotkey hotkey); |    void HotkeyReleased(scwx::qt::types::Hotkey hotkey); | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|  |  | ||||||
|  | @ -149,7 +149,7 @@ public: | ||||||
|                           const std::string& before); |                           const std::string& before); | ||||||
|    void ConnectMapSignals(); |    void ConnectMapSignals(); | ||||||
|    void ConnectSignals(); |    void ConnectSignals(); | ||||||
|    void HandleHotkey(types::Hotkey hotkey); |    void HandleHotkey(types::Hotkey hotkey, bool isAutoRepeat); | ||||||
|    void ImGuiCheckFonts(); |    void ImGuiCheckFonts(); | ||||||
|    void InitializeNewRadarProductView(const std::string& colorPalette); |    void InitializeNewRadarProductView(const std::string& colorPalette); | ||||||
|    void RadarProductManagerConnect(); |    void RadarProductManagerConnect(); | ||||||
|  | @ -345,19 +345,18 @@ void MapWidgetImpl::ConnectSignals() | ||||||
|            &MapWidgetImpl::HandleHotkey); |            &MapWidgetImpl::HandleHotkey); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void MapWidgetImpl::HandleHotkey(types::Hotkey hotkey) | void MapWidgetImpl::HandleHotkey(types::Hotkey hotkey, bool isAutoRepeat) | ||||||
| { | { | ||||||
|    static constexpr float  kMapPanFactor    = 0.2f; |    static constexpr float  kMapPanFactor    = 0.2f; | ||||||
|    static constexpr float  kMapRotateFactor = 0.2f; |    static constexpr float  kMapRotateFactor = 0.2f; | ||||||
|    static constexpr long long kMapScaleFactor  = 1000; |    static constexpr double kMapScaleFactor  = 1000.0; | ||||||
| 
 | 
 | ||||||
|    using namespace std::chrono_literals; |    using namespace std::chrono_literals; | ||||||
| 
 | 
 | ||||||
|    std::chrono::system_clock::time_point hotkeyTime = |    std::chrono::system_clock::time_point hotkeyTime = | ||||||
|       std::chrono::system_clock::now(); |       std::chrono::system_clock::now(); | ||||||
|    std::chrono::milliseconds hotkeyElapsed = |    std::chrono::milliseconds hotkeyElapsed = | ||||||
|       prevHotkey_ != types::Hotkey::Unknown ? |       isAutoRepeat ? std::chrono::duration_cast<std::chrono::milliseconds>( | ||||||
|          std::chrono::duration_cast<std::chrono::milliseconds>( |  | ||||||
|                         hotkeyTime - prevHotkeyTime_) : |                         hotkeyTime - prevHotkeyTime_) : | ||||||
|                      100ms; |                      100ms; | ||||||
| 
 | 
 | ||||||
|  | @ -431,16 +430,20 @@ void MapWidgetImpl::HandleHotkey(types::Hotkey hotkey) | ||||||
| 
 | 
 | ||||||
|    case types::Hotkey::MapZoomIn: |    case types::Hotkey::MapZoomIn: | ||||||
|    { |    { | ||||||
|  |       auto    widgetSize = widget_->size(); | ||||||
|  |       QPointF center = {widgetSize.width() * 0.5f, widgetSize.height() * 0.5f}; | ||||||
|       double  scale  = std::pow(2.0, hotkeyElapsed.count() / kMapScaleFactor); |       double  scale  = std::pow(2.0, hotkeyElapsed.count() / kMapScaleFactor); | ||||||
|       map_->scaleBy(scale); |       map_->scaleBy(scale, center); | ||||||
|       break; |       break; | ||||||
|    } |    } | ||||||
| 
 | 
 | ||||||
|    case types::Hotkey::MapZoomOut: |    case types::Hotkey::MapZoomOut: | ||||||
|    { |    { | ||||||
|  |       auto    widgetSize = widget_->size(); | ||||||
|  |       QPointF center = {widgetSize.width() * 0.5f, widgetSize.height() * 0.5f}; | ||||||
|       double  scale = |       double  scale = | ||||||
|          1.0 / std::pow(2.0, hotkeyElapsed.count() / kMapScaleFactor); |          1.0 / std::pow(2.0, hotkeyElapsed.count() / kMapScaleFactor); | ||||||
|       map_->scaleBy(scale); |       map_->scaleBy(scale, center); | ||||||
|       break; |       break; | ||||||
|    } |    } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat