mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 08:20:05 +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/versions.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/position_manager.hpp>
|
||||
#include <scwx/qt/manager/radar_product_manager.hpp>
|
||||
|
|
@ -42,6 +43,7 @@
|
|||
#include <boost/asio/post.hpp>
|
||||
#include <boost/asio/thread_pool.hpp>
|
||||
#include <QDesktopServices>
|
||||
#include <QKeyEvent>
|
||||
#include <QFileDialog>
|
||||
#include <QMessageBox>
|
||||
#include <QSplitter>
|
||||
|
|
@ -197,7 +199,9 @@ public:
|
|||
|
||||
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::PositionManager> positionManager_;
|
||||
std::shared_ptr<manager::TextEventManager> textEventManager_;
|
||||
|
|
@ -398,6 +402,24 @@ MainWindow::~MainWindow()
|
|||
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)
|
||||
{
|
||||
QMainWindow::showEvent(event);
|
||||
|
|
|
|||
|
|
@ -26,6 +26,8 @@ public:
|
|||
MainWindow(QWidget* parent = nullptr);
|
||||
~MainWindow();
|
||||
|
||||
void keyPressEvent(QKeyEvent* ev) override final;
|
||||
void keyReleaseEvent(QKeyEvent* ev) override final;
|
||||
void showEvent(QShowEvent* event) override;
|
||||
|
||||
signals:
|
||||
|
|
|
|||
|
|
@ -64,34 +64,44 @@ void HotkeyManager::Impl::UpdateHotkey(types::Hotkey hotkey,
|
|||
QKeySequence {QString::fromStdString(value)});
|
||||
}
|
||||
|
||||
void HotkeyManager::HandleKeyPress(QKeyEvent* ev)
|
||||
bool HotkeyManager::HandleKeyPress(QKeyEvent* ev)
|
||||
{
|
||||
logger_->trace("HandleKeyPress: {}, {}",
|
||||
ev->keyCombination().toCombined(),
|
||||
ev->isAutoRepeat());
|
||||
|
||||
bool hotkeyPressed = false;
|
||||
|
||||
for (auto& hotkey : p->hotkeys_)
|
||||
{
|
||||
if (hotkey.second.count() == 1 &&
|
||||
hotkey.second[0] == ev->keyCombination())
|
||||
{
|
||||
hotkeyPressed = true;
|
||||
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());
|
||||
|
||||
bool hotkeyReleased = false;
|
||||
|
||||
for (auto& hotkey : p->hotkeys_)
|
||||
{
|
||||
if (hotkey.second.count() == 1 &&
|
||||
hotkey.second[0] == ev->keyCombination())
|
||||
{
|
||||
hotkeyReleased = true;
|
||||
Q_EMIT HotkeyReleased(hotkey.first);
|
||||
}
|
||||
}
|
||||
|
||||
return hotkeyReleased;
|
||||
}
|
||||
|
||||
std::shared_ptr<HotkeyManager> HotkeyManager::Instance()
|
||||
|
|
|
|||
|
|
@ -24,8 +24,8 @@ public:
|
|||
explicit HotkeyManager();
|
||||
~HotkeyManager();
|
||||
|
||||
void HandleKeyPress(QKeyEvent* event);
|
||||
void HandleKeyRelease(QKeyEvent* event);
|
||||
bool HandleKeyPress(QKeyEvent* event);
|
||||
bool HandleKeyRelease(QKeyEvent* event);
|
||||
|
||||
static std::shared_ptr<HotkeyManager> Instance();
|
||||
|
||||
|
|
|
|||
|
|
@ -359,28 +359,33 @@ void MapWidgetImpl::HandleHotkeyPressed(types::Hotkey hotkey, bool isAutoRepeat)
|
|||
switch (hotkey)
|
||||
{
|
||||
case types::Hotkey::ChangeMapStyle:
|
||||
widget_->changeStyle();
|
||||
if (context_->settings().isActive_)
|
||||
{
|
||||
widget_->changeStyle();
|
||||
}
|
||||
break;
|
||||
|
||||
case types::Hotkey::CopyCursorCoordinates:
|
||||
{
|
||||
QClipboard* clipboard = QGuiApplication::clipboard();
|
||||
auto coordinate = map_->coordinateForPixel(lastPos_);
|
||||
std::string text =
|
||||
fmt::format("{}, {}", coordinate.first, coordinate.second);
|
||||
clipboard->setText(QString::fromStdString(text));
|
||||
if (hasMouse_)
|
||||
{
|
||||
QClipboard* clipboard = QGuiApplication::clipboard();
|
||||
auto coordinate = map_->coordinateForPixel(lastPos_);
|
||||
std::string text =
|
||||
fmt::format("{}, {}", coordinate.first, coordinate.second);
|
||||
clipboard->setText(QString::fromStdString(text));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case types::Hotkey::CopyMapCoordinates:
|
||||
{
|
||||
QClipboard* clipboard = QGuiApplication::clipboard();
|
||||
auto coordinate = map_->coordinate();
|
||||
std::string text =
|
||||
fmt::format("{}, {}", coordinate.first, coordinate.second);
|
||||
clipboard->setText(QString::fromStdString(text));
|
||||
if (context_->settings().isActive_)
|
||||
{
|
||||
QClipboard* clipboard = QGuiApplication::clipboard();
|
||||
auto coordinate = map_->coordinate();
|
||||
std::string text =
|
||||
fmt::format("{}, {}", coordinate.first, coordinate.second);
|
||||
clipboard->setText(QString::fromStdString(text));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
|
|
@ -391,6 +396,8 @@ void MapWidgetImpl::HandleHotkeyPressed(types::Hotkey hotkey, bool isAutoRepeat)
|
|||
|
||||
void MapWidgetImpl::HandleHotkeyReleased(types::Hotkey hotkey)
|
||||
{
|
||||
// Erase the hotkey from the active set regardless of whether this is the
|
||||
// active map
|
||||
activeHotkeys_.erase(hotkey);
|
||||
}
|
||||
|
||||
|
|
@ -409,6 +416,14 @@ void MapWidgetImpl::HandleHotkeyUpdates()
|
|||
hotkeyTime - prevHotkeyTime_),
|
||||
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_)
|
||||
{
|
||||
switch (hotkey)
|
||||
|
|
@ -480,8 +495,6 @@ void MapWidgetImpl::HandleHotkeyUpdates()
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
prevHotkeyTime_ = hotkeyTime;
|
||||
}
|
||||
|
||||
common::Level3ProductCategoryMap MapWidget::GetAvailableLevel3Categories()
|
||||
|
|
@ -1212,16 +1225,18 @@ void MapWidget::leaveEvent(QEvent* /* ev */)
|
|||
|
||||
void MapWidget::keyPressEvent(QKeyEvent* ev)
|
||||
{
|
||||
p->hotkeyManager_->HandleKeyPress(ev);
|
||||
|
||||
ev->accept();
|
||||
if (p->hotkeyManager_->HandleKeyPress(ev))
|
||||
{
|
||||
ev->accept();
|
||||
}
|
||||
}
|
||||
|
||||
void MapWidget::keyReleaseEvent(QKeyEvent* ev)
|
||||
{
|
||||
p->hotkeyManager_->HandleKeyRelease(ev);
|
||||
|
||||
ev->accept();
|
||||
if (p->hotkeyManager_->HandleKeyRelease(ev))
|
||||
{
|
||||
ev->accept();
|
||||
}
|
||||
}
|
||||
|
||||
void MapWidget::mousePressEvent(QMouseEvent* ev)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue