diff --git a/scwx-qt/source/scwx/qt/ui/level2_settings_widget.cpp b/scwx-qt/source/scwx/qt/ui/level2_settings_widget.cpp index 18e9ebf1..85b476c9 100644 --- a/scwx-qt/source/scwx/qt/ui/level2_settings_widget.cpp +++ b/scwx-qt/source/scwx/qt/ui/level2_settings_widget.cpp @@ -1,6 +1,8 @@ #include #include +#include #include +#include #include @@ -16,6 +18,9 @@ namespace qt namespace ui { +static const std::string logPrefix_ = "scwx::qt::ui::level2_settings_widget"; +static const auto logger_ = util::Logger::Create(logPrefix_); + class Level2SettingsWidgetImpl : public QObject { Q_OBJECT @@ -46,9 +51,15 @@ public: settingsLayout->addWidget(declutterCheckBox_); settingsGroupBox_->setVisible(false); + + QObject::connect(hotkeyManager_.get(), + &manager::HotkeyManager::HotkeyPressed, + this, + &Level2SettingsWidgetImpl::HandleHotkeyPressed); } ~Level2SettingsWidgetImpl() = default; + void HandleHotkeyPressed(types::Hotkey hotkey, bool isAutoRepeat); void NormalizeElevationButtons(); void SelectElevation(float elevation); @@ -63,6 +74,12 @@ public: QGroupBox* settingsGroupBox_; QCheckBox* declutterCheckBox_; + + float currentElevation_ {}; + QToolButton* currentElevationButton_ {nullptr}; + + std::shared_ptr hotkeyManager_ { + manager::HotkeyManager::Instance()}; }; Level2SettingsWidget::Level2SettingsWidget(QWidget* parent) : @@ -96,6 +113,71 @@ void Level2SettingsWidget::showEvent(QShowEvent* event) p->NormalizeElevationButtons(); } +void Level2SettingsWidgetImpl::HandleHotkeyPressed(types::Hotkey hotkey, + bool isAutoRepeat) +{ + if (hotkey != types::Hotkey::ProductTiltDecrease && + hotkey != types::Hotkey::ProductTiltIncrease) + { + // Not handling this hotkey + return; + } + + logger_->trace("Handling hotkey: {}, repeat: {}", + types::GetHotkeyShortName(hotkey), + isAutoRepeat); + + if (!self_->isVisible() || currentElevationButton_ == nullptr) + { + // Level 2 product is not selected + return; + } + + // Find the current elevation tilt + auto tiltIt = std::find(elevationButtons_.cbegin(), + elevationButtons_.cend(), + currentElevationButton_); + + if (tiltIt == elevationButtons_.cend()) + { + logger_->error("Could not locate level 2 tilt: {}", currentElevation_); + return; + } + + if (hotkey == types::Hotkey::ProductTiltDecrease) + { + // Validate the current elevation tilt + if (tiltIt != elevationButtons_.cbegin()) + { + // Get the previous elevation tilt + --tiltIt; + + // Select the new elevation tilt + (*tiltIt)->click(); + } + else + { + logger_->info("Level 2 tilt at lower limit"); + } + } + else if (hotkey == types::Hotkey::ProductTiltIncrease) + { + // Get the next elevation tilt + ++tiltIt; + + // Validate the next elevation tilt + if (tiltIt != elevationButtons_.cend()) + { + // Select the new elevation tilt + (*tiltIt)->click(); + } + else + { + logger_->info("Level 2 tilt at upper limit"); + } + } +} + void Level2SettingsWidgetImpl::NormalizeElevationButtons() { // Set each elevation cut's tool button to the same size @@ -135,12 +217,15 @@ void Level2SettingsWidget::UpdateElevationSelection(float elevation) QString buttonText {QString::number(elevation, 'f', 1) + common::Characters::DEGREE}; + QToolButton* newElevationButton = nullptr; + std::for_each(p->elevationButtons_.cbegin(), p->elevationButtons_.cend(), [&](auto& toolButton) { if (toolButton->text() == buttonText) { + newElevationButton = toolButton; toolButton->setCheckable(true); toolButton->setChecked(true); } @@ -150,6 +235,9 @@ void Level2SettingsWidget::UpdateElevationSelection(float elevation) toolButton->setCheckable(false); } }); + + p->currentElevation_ = elevation; + p->currentElevationButton_ = newElevationButton; } void Level2SettingsWidget::UpdateSettings(map::MapWidget* activeMap)