From ab456596777a65a45b01b27bfd57c6384a2b5cd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Fri, 23 Dec 2016 17:39:12 +0100 Subject: [PATCH] Add support for on-screen-message to kwineffects Summary: This adds support for the new on-screen-message support to the kwineffects API and makes use of it in the colorpicker effect. Not yet added to screenshot effect as for that we need support for skip close animation on the on-screen-message window. Reviewers: #plasma, #kwin Subscribers: plasma-devel, kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D3803 --- autotests/mock_effectshandler.h | 5 +++++ effects.cpp | 11 +++++++++++ effects.h | 3 +++ effects/colorpicker/colorpicker.cpp | 21 +++------------------ effects/colorpicker/colorpicker.h | 1 - libkwineffects/kwineffects.h | 17 +++++++++++++++++ 6 files changed, 39 insertions(+), 19 deletions(-) diff --git a/autotests/mock_effectshandler.h b/autotests/mock_effectshandler.h index 1a1e057332..00e7c56a5d 100644 --- a/autotests/mock_effectshandler.h +++ b/autotests/mock_effectshandler.h @@ -251,6 +251,11 @@ public: void startInteractivePositionSelection(std::function callback) override { callback(QPoint(-1, -1)); } + void showOnScreenMessage(const QString &message, const QString &iconName = QString()) override { + Q_UNUSED(message) + Q_UNUSED(iconName) + } + void hideOnScreenMessage() override {} private: bool m_animationsSuported = true; diff --git a/effects.cpp b/effects.cpp index 7c51236a63..f228fc4318 100644 --- a/effects.cpp +++ b/effects.cpp @@ -30,6 +30,7 @@ along with this program. If not, see . #include "client.h" #include "cursor.h" #include "group.h" +#include "osd.h" #include "pointer_input.h" #include "scene_xrender.h" #include "scene_qpainter.h" @@ -1590,6 +1591,16 @@ void EffectsHandlerImpl::startInteractivePositionSelection(std::functionplatform()->startInteractivePositionSelection(callback); } +void EffectsHandlerImpl::showOnScreenMessage(const QString &message, const QString &iconName) +{ + OSD::show(message, iconName); +} + +void EffectsHandlerImpl::hideOnScreenMessage() +{ + OSD::hide(); +} + //**************************************** // EffectWindowImpl //**************************************** diff --git a/effects.h b/effects.h index 58e4f7ce36..c44a167d10 100644 --- a/effects.h +++ b/effects.h @@ -234,6 +234,9 @@ public: void startInteractiveWindowSelection(std::function callback) override; void startInteractivePositionSelection(std::function callback) override; + void showOnScreenMessage(const QString &message, const QString &iconName = QString()) override; + void hideOnScreenMessage() override; + Scene *scene() const { return m_scene; } diff --git a/effects/colorpicker/colorpicker.cpp b/effects/colorpicker/colorpicker.cpp index 200bfc8a60..707e73e163 100644 --- a/effects/colorpicker/colorpicker.cpp +++ b/effects/colorpicker/colorpicker.cpp @@ -65,10 +65,6 @@ void ColorPickerEffect::paintScreen(int mask, QRegion region, ScreenPaintData &d { m_cachedOutputGeometry = data.outputGeometry(); effects->paintScreen(mask, region, data); - - if (m_infoFrame) { - m_infoFrame->render(region); - } } void ColorPickerEffect::postPaintScreen() @@ -116,28 +112,17 @@ QColor ColorPickerEffect::pick() void ColorPickerEffect::showInfoMessage() { - if (!m_infoFrame.isNull()) { - return; - } - // TODO: turn the info message into a system wide service which performs hiding on mouse over - m_infoFrame.reset(effects->effectFrame(EffectFrameStyled, false)); - QFont font; - font.setBold(true); - m_infoFrame->setFont(font); - QRect area = effects->clientArea(ScreenArea, effects->activeScreen(), effects->currentDesktop()); - m_infoFrame->setPosition(QPoint(area.x() + area.width() / 2, area.y() + area.height() / 3)); - m_infoFrame->setText(i18n("Select a position for color picking with left click or enter.\nEscape or right click to cancel.")); - effects->addRepaintFull(); + effects->showOnScreenMessage(i18n("Select a position for color picking with left click or enter.\nEscape or right click to cancel."), QStringLiteral("color-picker")); } void ColorPickerEffect::hideInfoMessage() { - m_infoFrame.reset(); + effects->hideOnScreenMessage(); } bool ColorPickerEffect::isActive() const { - return m_picking && ((m_scheduledPosition != QPoint(-1, -1)) || !m_infoFrame.isNull()) && !effects->isScreenLocked(); + return m_picking && ((m_scheduledPosition != QPoint(-1, -1))) && !effects->isScreenLocked(); } } // namespace diff --git a/effects/colorpicker/colorpicker.h b/effects/colorpicker/colorpicker.h index eab9410d8a..f3856cea8d 100644 --- a/effects/colorpicker/colorpicker.h +++ b/effects/colorpicker/colorpicker.h @@ -58,7 +58,6 @@ private: QRect m_cachedOutputGeometry; QPoint m_scheduledPosition; bool m_picking = false; - QScopedPointer m_infoFrame; }; } // namespace diff --git a/libkwineffects/kwineffects.h b/libkwineffects/kwineffects.h index 5ff36ac8f0..9b50d4e27a 100644 --- a/libkwineffects/kwineffects.h +++ b/libkwineffects/kwineffects.h @@ -1229,6 +1229,23 @@ public: **/ virtual void startInteractivePositionSelection(std::function callback) = 0; + /** + * Shows an on-screen-message. To hide it again use @link{hideOnScreenMessage}. + * + * @param message The message to show + * @param iconName The optional themed icon name + * @see hideOnScreenMessage + * @since 5.9 + **/ + virtual void showOnScreenMessage(const QString &message, const QString &iconName = QString()) = 0; + + /** + * Hides a previously shown on-screen-message again. + * @see showOnScreenMessage + * @since 5.9 + **/ + virtual void hideOnScreenMessage() = 0; + Q_SIGNALS: /** * Signal emitted when the current desktop changed.