mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 20:20: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
|
|
@ -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