Hotkey repeat handling update

This commit is contained in:
Dan Paulat 2024-04-11 23:57:12 -05:00
parent 399894f2db
commit dcaba52db7
3 changed files with 18 additions and 15 deletions

View file

@ -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());
}
}
}

View file

@ -30,7 +30,7 @@ public:
static std::shared_ptr<HotkeyManager> 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:

View file

@ -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<std::chrono::milliseconds>(
hotkeyTime - prevHotkeyTime_) :
100ms;
isAutoRepeat ? std::chrono::duration_cast<std::chrono::milliseconds>(
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;
}