From 5b815e83d3d8279cde19fb3d924cf21d81512c1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Haris=20Gu=C5=A1i=C4=87?= Date: Tue, 12 Oct 2021 13:35:57 +0200 Subject: [PATCH] Reappear help message when selection hidden MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Haris Gušić --- src/widgets/capture/capturewidget.cpp | 46 +++++++++++++++---------- src/widgets/capture/capturewidget.h | 2 +- src/widgets/capture/overlaymessage.cpp | 5 +-- src/widgets/capture/overlaymessage.h | 2 +- src/widgets/capture/selectionwidget.cpp | 10 ++++++ src/widgets/capture/selectionwidget.h | 4 +++ 6 files changed, 46 insertions(+), 23 deletions(-) diff --git a/src/widgets/capture/capturewidget.cpp b/src/widgets/capture/capturewidget.cpp index f769d384..49e57084 100644 --- a/src/widgets/capture/capturewidget.cpp +++ b/src/widgets/capture/capturewidget.cpp @@ -219,7 +219,7 @@ CaptureWidget::CaptureWidget(uint id, QGuiAppCurrentScreen().currentScreen()->geometry()); if (m_config.showHelp()) { - initHelpMessage(); + pushHelpMessage(); } updateCursor(); @@ -317,27 +317,30 @@ void CaptureWidget::initButtons() m_buttonHandler->setButtons(vectorButtons); } -void CaptureWidget::initHelpMessage() +void CaptureWidget::pushHelpMessage() { - QList> keyMap; - keyMap << QPair(tr("Mouse"), tr("Select screenshot area")); - using CT = CaptureTool; - for (auto toolType : { CT::TYPE_ACCEPT, CT::TYPE_SAVE, CT::TYPE_COPY }) { - if (!m_tools.contains(toolType)) { - continue; - } - auto* tool = m_tools[toolType]; - QString shortcut = - ConfigHandler().shortcut(QVariant::fromValue(toolType).toString()); - shortcut.replace("Return", "Enter"); - if (!shortcut.isEmpty()) { - keyMap << QPair(shortcut, tool->description()); + static QList> keyMap; + if (keyMap.isEmpty()) { + keyMap << QPair(tr("Mouse"), tr("Select screenshot area")); + using CT = CaptureTool; + for (auto toolType : + { CT::TYPE_ACCEPT, CT::TYPE_SAVE, CT::TYPE_COPY }) { + if (!m_tools.contains(toolType)) { + continue; + } + auto* tool = m_tools[toolType]; + QString shortcut = ConfigHandler().shortcut( + QVariant::fromValue(toolType).toString()); + shortcut.replace("Return", "Enter"); + if (!shortcut.isEmpty()) { + keyMap << QPair(shortcut, tool->description()); + } } + keyMap << QPair(tr("Mouse Wheel"), tr("Change tool size")); + keyMap << QPair(tr("Right Click"), tr("Show color picker")); + keyMap << QPair(tr("Space"), tr("Open side panel")); + keyMap << QPair(tr("Esc"), tr("Exit")); } - keyMap << QPair(tr("Mouse Wheel"), tr("Change tool size")); - keyMap << QPair(tr("Right Click"), tr("Show color picker")); - keyMap << QPair(tr("Space"), tr("Open side panel")); - keyMap << QPair(tr("Esc"), tr("Exit")); OverlayMessage::pushKeyMap(keyMap); } @@ -1017,6 +1020,11 @@ void CaptureWidget::initSelection() m_buttonHandler->hide(); } }); + connect(m_selection, &SelectionWidget::visibilityChanged, this, [this]() { + if (!m_selection->isVisible() && ConfigHandler().showHelp()) { + pushHelpMessage(); + } + }); } void CaptureWidget::setState(CaptureToolButton* b) diff --git a/src/widgets/capture/capturewidget.h b/src/widgets/capture/capturewidget.h index f54f435d..29194839 100644 --- a/src/widgets/capture/capturewidget.h +++ b/src/widgets/capture/capturewidget.h @@ -107,7 +107,7 @@ private: void initSelection(); void initShortcuts(); void initButtons(); - void initHelpMessage(); + void pushHelpMessage(); void updateSizeIndicator(); void updateCursor(); void updateSelectionState(); diff --git a/src/widgets/capture/overlaymessage.cpp b/src/widgets/capture/overlaymessage.cpp index 767d4137..d6f8039e 100644 --- a/src/widgets/capture/overlaymessage.cpp +++ b/src/widgets/capture/overlaymessage.cpp @@ -74,14 +74,15 @@ OverlayMessage* OverlayMessage::instance() void OverlayMessage::pushKeyMap(const QList>& map) { - push(compileKeyMap(map)); + push(compileFromKeyMap(map)); } /** * @brief Compile a message from a set of shortcuts and descriptions. * @param map List of (shortcut, description) pairs */ -QString OverlayMessage::compileKeyMap(const QList>& map) +QString OverlayMessage::compileFromKeyMap( + const QList>& map) { QString str = QStringLiteral(""); for (const auto& pair : map) { diff --git a/src/widgets/capture/overlaymessage.h b/src/widgets/capture/overlaymessage.h index 0fbbbc4a..bfea1d6f 100644 --- a/src/widgets/capture/overlaymessage.h +++ b/src/widgets/capture/overlaymessage.h @@ -29,7 +29,7 @@ public: static OverlayMessage* instance(); static void pushKeyMap(const QList>& map); - static QString compileKeyMap(const QList>& map); + static QString compileFromKeyMap(const QList>& map); private: QStack m_messageStack; diff --git a/src/widgets/capture/selectionwidget.cpp b/src/widgets/capture/selectionwidget.cpp index e2e9e33c..a3b17a6b 100644 --- a/src/widgets/capture/selectionwidget.cpp +++ b/src/widgets/capture/selectionwidget.cpp @@ -304,6 +304,16 @@ void SelectionWidget::moveEvent(QMoveEvent*) } } +void SelectionWidget::showEvent(QShowEvent*) +{ + emit visibilityChanged(); +} + +void SelectionWidget::hideEvent(QHideEvent*) +{ + emit visibilityChanged(); +} + void SelectionWidget::updateColor(const QColor& c) { m_color = c; diff --git a/src/widgets/capture/selectionwidget.h b/src/widgets/capture/selectionwidget.h index 3100bc58..8f5a24d7 100644 --- a/src/widgets/capture/selectionwidget.h +++ b/src/widgets/capture/selectionwidget.h @@ -50,10 +50,14 @@ protected: void resizeEvent(QResizeEvent*); void moveEvent(QMoveEvent*); + void showEvent(QShowEvent*) override; + void hideEvent(QHideEvent*) override; + signals: void animationEnded(); void geometryChanged(); void geometrySettled(); + void visibilityChanged(); public slots: void updateColor(const QColor& c);