diff --git a/scwx-qt/source/scwx/qt/manager/hotkey_manager.cpp b/scwx-qt/source/scwx/qt/manager/hotkey_manager.cpp index e47f7b24..afcb9124 100644 --- a/scwx-qt/source/scwx/qt/manager/hotkey_manager.cpp +++ b/scwx-qt/source/scwx/qt/manager/hotkey_manager.cpp @@ -71,7 +71,7 @@ void HotkeyManager::HandleKeyPress(QKeyEvent* ev) if (hotkey.second.count() == 1 && hotkey.second[0] == ev->keyCombination()) { - Q_EMIT HotkeyPressed(hotkey.first); + Q_EMIT HotkeyPressed(hotkey.first, ev->isAutoRepeat()); } } } diff --git a/scwx-qt/source/scwx/qt/manager/hotkey_manager.hpp b/scwx-qt/source/scwx/qt/manager/hotkey_manager.hpp index 49f7576d..0a38709d 100644 --- a/scwx-qt/source/scwx/qt/manager/hotkey_manager.hpp +++ b/scwx-qt/source/scwx/qt/manager/hotkey_manager.hpp @@ -30,7 +30,7 @@ public: static std::shared_ptr Instance(); signals: - void HotkeyPressed(scwx::qt::types::Hotkey hotkey); + void HotkeyPressed(scwx::qt::types::Hotkey hotkey, bool isAutoRepeat); void HotkeyReleased(scwx::qt::types::Hotkey hotkey); private: diff --git a/scwx-qt/source/scwx/qt/map/map_widget.cpp b/scwx-qt/source/scwx/qt/map/map_widget.cpp index b065bd82..7ba843c1 100644 --- a/scwx-qt/source/scwx/qt/map/map_widget.cpp +++ b/scwx-qt/source/scwx/qt/map/map_widget.cpp @@ -149,7 +149,7 @@ public: const std::string& before); void ConnectMapSignals(); void ConnectSignals(); - void HandleHotkey(types::Hotkey hotkey); + void HandleHotkey(types::Hotkey hotkey, bool isAutoRepeat); void ImGuiCheckFonts(); void InitializeNewRadarProductView(const std::string& colorPalette); void RadarProductManagerConnect(); @@ -345,21 +345,20 @@ void MapWidgetImpl::ConnectSignals() &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 kMapRotateFactor = 0.2f; - static constexpr long long kMapScaleFactor = 1000; + static constexpr float kMapPanFactor = 0.2f; + static constexpr float kMapRotateFactor = 0.2f; + static constexpr double kMapScaleFactor = 1000.0; using namespace std::chrono_literals; std::chrono::system_clock::time_point hotkeyTime = std::chrono::system_clock::now(); std::chrono::milliseconds hotkeyElapsed = - prevHotkey_ != types::Hotkey::Unknown ? - std::chrono::duration_cast( - hotkeyTime - prevHotkeyTime_) : - 100ms; + isAutoRepeat ? std::chrono::duration_cast( + hotkeyTime - prevHotkeyTime_) : + 100ms; switch (hotkey) { @@ -431,16 +430,20 @@ void MapWidgetImpl::HandleHotkey(types::Hotkey hotkey) case types::Hotkey::MapZoomIn: { - double scale = std::pow(2.0, hotkeyElapsed.count() / kMapScaleFactor); - map_->scaleBy(scale); + auto widgetSize = widget_->size(); + QPointF center = {widgetSize.width() * 0.5f, widgetSize.height() * 0.5f}; + double scale = std::pow(2.0, hotkeyElapsed.count() / kMapScaleFactor); + map_->scaleBy(scale, center); break; } case types::Hotkey::MapZoomOut: { - double scale = + auto widgetSize = widget_->size(); + QPointF center = {widgetSize.width() * 0.5f, widgetSize.height() * 0.5f}; + double scale = 1.0 / std::pow(2.0, hotkeyElapsed.count() / kMapScaleFactor); - map_->scaleBy(scale); + map_->scaleBy(scale, center); break; }