mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 14:00:06 +00:00
Handle hotkeys across multiple map panes
This commit is contained in:
parent
60c8af46bf
commit
589eff9882
5 changed files with 77 additions and 28 deletions
|
|
@ -4,6 +4,7 @@
|
||||||
#include <scwx/qt/main/application.hpp>
|
#include <scwx/qt/main/application.hpp>
|
||||||
#include <scwx/qt/main/versions.hpp>
|
#include <scwx/qt/main/versions.hpp>
|
||||||
#include <scwx/qt/manager/alert_manager.hpp>
|
#include <scwx/qt/manager/alert_manager.hpp>
|
||||||
|
#include <scwx/qt/manager/hotkey_manager.hpp>
|
||||||
#include <scwx/qt/manager/placefile_manager.hpp>
|
#include <scwx/qt/manager/placefile_manager.hpp>
|
||||||
#include <scwx/qt/manager/position_manager.hpp>
|
#include <scwx/qt/manager/position_manager.hpp>
|
||||||
#include <scwx/qt/manager/radar_product_manager.hpp>
|
#include <scwx/qt/manager/radar_product_manager.hpp>
|
||||||
|
|
@ -42,6 +43,7 @@
|
||||||
#include <boost/asio/post.hpp>
|
#include <boost/asio/post.hpp>
|
||||||
#include <boost/asio/thread_pool.hpp>
|
#include <boost/asio/thread_pool.hpp>
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
|
#include <QKeyEvent>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QSplitter>
|
#include <QSplitter>
|
||||||
|
|
@ -197,7 +199,9 @@ public:
|
||||||
|
|
||||||
QTimer clockTimer_ {};
|
QTimer clockTimer_ {};
|
||||||
|
|
||||||
std::shared_ptr<manager::AlertManager> alertManager_;
|
std::shared_ptr<manager::AlertManager> alertManager_;
|
||||||
|
std::shared_ptr<manager::HotkeyManager> hotkeyManager_ {
|
||||||
|
manager::HotkeyManager::Instance()};
|
||||||
std::shared_ptr<manager::PlacefileManager> placefileManager_;
|
std::shared_ptr<manager::PlacefileManager> placefileManager_;
|
||||||
std::shared_ptr<manager::PositionManager> positionManager_;
|
std::shared_ptr<manager::PositionManager> positionManager_;
|
||||||
std::shared_ptr<manager::TextEventManager> textEventManager_;
|
std::shared_ptr<manager::TextEventManager> textEventManager_;
|
||||||
|
|
@ -398,6 +402,24 @@ MainWindow::~MainWindow()
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::keyPressEvent(QKeyEvent* ev)
|
||||||
|
{
|
||||||
|
if (p->hotkeyManager_->HandleKeyPress(ev))
|
||||||
|
{
|
||||||
|
p->activeMap_->update();
|
||||||
|
ev->accept();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::keyReleaseEvent(QKeyEvent* ev)
|
||||||
|
{
|
||||||
|
if (p->hotkeyManager_->HandleKeyRelease(ev))
|
||||||
|
{
|
||||||
|
p->activeMap_->update();
|
||||||
|
ev->accept();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::showEvent(QShowEvent* event)
|
void MainWindow::showEvent(QShowEvent* event)
|
||||||
{
|
{
|
||||||
QMainWindow::showEvent(event);
|
QMainWindow::showEvent(event);
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,8 @@ public:
|
||||||
MainWindow(QWidget* parent = nullptr);
|
MainWindow(QWidget* parent = nullptr);
|
||||||
~MainWindow();
|
~MainWindow();
|
||||||
|
|
||||||
|
void keyPressEvent(QKeyEvent* ev) override final;
|
||||||
|
void keyReleaseEvent(QKeyEvent* ev) override final;
|
||||||
void showEvent(QShowEvent* event) override;
|
void showEvent(QShowEvent* event) override;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
|
||||||
|
|
@ -64,34 +64,44 @@ void HotkeyManager::Impl::UpdateHotkey(types::Hotkey hotkey,
|
||||||
QKeySequence {QString::fromStdString(value)});
|
QKeySequence {QString::fromStdString(value)});
|
||||||
}
|
}
|
||||||
|
|
||||||
void HotkeyManager::HandleKeyPress(QKeyEvent* ev)
|
bool HotkeyManager::HandleKeyPress(QKeyEvent* ev)
|
||||||
{
|
{
|
||||||
logger_->trace("HandleKeyPress: {}, {}",
|
logger_->trace("HandleKeyPress: {}, {}",
|
||||||
ev->keyCombination().toCombined(),
|
ev->keyCombination().toCombined(),
|
||||||
ev->isAutoRepeat());
|
ev->isAutoRepeat());
|
||||||
|
|
||||||
|
bool hotkeyPressed = false;
|
||||||
|
|
||||||
for (auto& hotkey : p->hotkeys_)
|
for (auto& hotkey : p->hotkeys_)
|
||||||
{
|
{
|
||||||
if (hotkey.second.count() == 1 &&
|
if (hotkey.second.count() == 1 &&
|
||||||
hotkey.second[0] == ev->keyCombination())
|
hotkey.second[0] == ev->keyCombination())
|
||||||
{
|
{
|
||||||
|
hotkeyPressed = true;
|
||||||
Q_EMIT HotkeyPressed(hotkey.first, ev->isAutoRepeat());
|
Q_EMIT HotkeyPressed(hotkey.first, ev->isAutoRepeat());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return hotkeyPressed;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HotkeyManager::HandleKeyRelease(QKeyEvent* ev)
|
bool HotkeyManager::HandleKeyRelease(QKeyEvent* ev)
|
||||||
{
|
{
|
||||||
logger_->trace("HandleKeyRelease: {}", ev->keyCombination().toCombined());
|
logger_->trace("HandleKeyRelease: {}", ev->keyCombination().toCombined());
|
||||||
|
|
||||||
|
bool hotkeyReleased = false;
|
||||||
|
|
||||||
for (auto& hotkey : p->hotkeys_)
|
for (auto& hotkey : p->hotkeys_)
|
||||||
{
|
{
|
||||||
if (hotkey.second.count() == 1 &&
|
if (hotkey.second.count() == 1 &&
|
||||||
hotkey.second[0] == ev->keyCombination())
|
hotkey.second[0] == ev->keyCombination())
|
||||||
{
|
{
|
||||||
|
hotkeyReleased = true;
|
||||||
Q_EMIT HotkeyReleased(hotkey.first);
|
Q_EMIT HotkeyReleased(hotkey.first);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return hotkeyReleased;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<HotkeyManager> HotkeyManager::Instance()
|
std::shared_ptr<HotkeyManager> HotkeyManager::Instance()
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,8 @@ public:
|
||||||
explicit HotkeyManager();
|
explicit HotkeyManager();
|
||||||
~HotkeyManager();
|
~HotkeyManager();
|
||||||
|
|
||||||
void HandleKeyPress(QKeyEvent* event);
|
bool HandleKeyPress(QKeyEvent* event);
|
||||||
void HandleKeyRelease(QKeyEvent* event);
|
bool HandleKeyRelease(QKeyEvent* event);
|
||||||
|
|
||||||
static std::shared_ptr<HotkeyManager> Instance();
|
static std::shared_ptr<HotkeyManager> Instance();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -359,28 +359,33 @@ void MapWidgetImpl::HandleHotkeyPressed(types::Hotkey hotkey, bool isAutoRepeat)
|
||||||
switch (hotkey)
|
switch (hotkey)
|
||||||
{
|
{
|
||||||
case types::Hotkey::ChangeMapStyle:
|
case types::Hotkey::ChangeMapStyle:
|
||||||
widget_->changeStyle();
|
if (context_->settings().isActive_)
|
||||||
|
{
|
||||||
|
widget_->changeStyle();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case types::Hotkey::CopyCursorCoordinates:
|
case types::Hotkey::CopyCursorCoordinates:
|
||||||
{
|
if (hasMouse_)
|
||||||
QClipboard* clipboard = QGuiApplication::clipboard();
|
{
|
||||||
auto coordinate = map_->coordinateForPixel(lastPos_);
|
QClipboard* clipboard = QGuiApplication::clipboard();
|
||||||
std::string text =
|
auto coordinate = map_->coordinateForPixel(lastPos_);
|
||||||
fmt::format("{}, {}", coordinate.first, coordinate.second);
|
std::string text =
|
||||||
clipboard->setText(QString::fromStdString(text));
|
fmt::format("{}, {}", coordinate.first, coordinate.second);
|
||||||
|
clipboard->setText(QString::fromStdString(text));
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
case types::Hotkey::CopyMapCoordinates:
|
case types::Hotkey::CopyMapCoordinates:
|
||||||
{
|
if (context_->settings().isActive_)
|
||||||
QClipboard* clipboard = QGuiApplication::clipboard();
|
{
|
||||||
auto coordinate = map_->coordinate();
|
QClipboard* clipboard = QGuiApplication::clipboard();
|
||||||
std::string text =
|
auto coordinate = map_->coordinate();
|
||||||
fmt::format("{}, {}", coordinate.first, coordinate.second);
|
std::string text =
|
||||||
clipboard->setText(QString::fromStdString(text));
|
fmt::format("{}, {}", coordinate.first, coordinate.second);
|
||||||
|
clipboard->setText(QString::fromStdString(text));
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
@ -391,6 +396,8 @@ void MapWidgetImpl::HandleHotkeyPressed(types::Hotkey hotkey, bool isAutoRepeat)
|
||||||
|
|
||||||
void MapWidgetImpl::HandleHotkeyReleased(types::Hotkey hotkey)
|
void MapWidgetImpl::HandleHotkeyReleased(types::Hotkey hotkey)
|
||||||
{
|
{
|
||||||
|
// Erase the hotkey from the active set regardless of whether this is the
|
||||||
|
// active map
|
||||||
activeHotkeys_.erase(hotkey);
|
activeHotkeys_.erase(hotkey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -409,6 +416,14 @@ void MapWidgetImpl::HandleHotkeyUpdates()
|
||||||
hotkeyTime - prevHotkeyTime_),
|
hotkeyTime - prevHotkeyTime_),
|
||||||
100ms);
|
100ms);
|
||||||
|
|
||||||
|
prevHotkeyTime_ = hotkeyTime;
|
||||||
|
|
||||||
|
if (!context_->settings().isActive_)
|
||||||
|
{
|
||||||
|
// Don't attempt to handle a hotkey if this is not the active map
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for (auto& hotkey : activeHotkeys_)
|
for (auto& hotkey : activeHotkeys_)
|
||||||
{
|
{
|
||||||
switch (hotkey)
|
switch (hotkey)
|
||||||
|
|
@ -480,8 +495,6 @@ void MapWidgetImpl::HandleHotkeyUpdates()
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
prevHotkeyTime_ = hotkeyTime;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
common::Level3ProductCategoryMap MapWidget::GetAvailableLevel3Categories()
|
common::Level3ProductCategoryMap MapWidget::GetAvailableLevel3Categories()
|
||||||
|
|
@ -1212,16 +1225,18 @@ void MapWidget::leaveEvent(QEvent* /* ev */)
|
||||||
|
|
||||||
void MapWidget::keyPressEvent(QKeyEvent* ev)
|
void MapWidget::keyPressEvent(QKeyEvent* ev)
|
||||||
{
|
{
|
||||||
p->hotkeyManager_->HandleKeyPress(ev);
|
if (p->hotkeyManager_->HandleKeyPress(ev))
|
||||||
|
{
|
||||||
ev->accept();
|
ev->accept();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapWidget::keyReleaseEvent(QKeyEvent* ev)
|
void MapWidget::keyReleaseEvent(QKeyEvent* ev)
|
||||||
{
|
{
|
||||||
p->hotkeyManager_->HandleKeyRelease(ev);
|
if (p->hotkeyManager_->HandleKeyRelease(ev))
|
||||||
|
{
|
||||||
ev->accept();
|
ev->accept();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapWidget::mousePressEvent(QMouseEvent* ev)
|
void MapWidget::mousePressEvent(QMouseEvent* ev)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue