Commit 24a859b3 authored by Martin Flöser's avatar Martin Flöser
Browse files

Tooltips

Summary:
BUG: 383040

KWin part of the patch:
https://phabricator.kde.org/D9294

Reviewers: #breeze, #plasma, graesslin

Reviewed By: #plasma, graesslin

Subscribers: cfeck, davidedmundson, jriddell, ngraham, broulik, plasma-devel, #breeze

Tags: #plasma, #breeze

Differential Revision: https://phabricator.kde.org/D7246
parent d676c3c0
......@@ -38,6 +38,7 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
endif()
set(KDECORATION2_INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR}/KDecoration2")
find_package(KF5I18n CONFIG REQUIRED)
# Subdirectories
add_subdirectory(src)
......
......@@ -232,6 +232,16 @@ void MockClient::requestToggleShade()
emit client()->shadedChanged(m_shaded);
}
void MockClient::requestShowToolTip(const QString &text)
{
Q_UNUSED(text);
}
void MockClient::requestHideToolTip()
{
}
int MockClient::width() const
{
return m_width;
......
......@@ -65,6 +65,8 @@ public:
void requestToggleKeepBelow() override;
void requestToggleOnAllDesktops() override;
void requestToggleShade() override;
void requestShowToolTip(const QString &text) override;
void requestHideToolTip() override;
int width() const override;
WId windowId() const override;
......
......@@ -19,6 +19,7 @@ target_link_libraries(kdecorations2
Qt5::Gui
PRIVATE
kdecorations2private
KF5::I18n
)
target_include_directories(kdecorations2 INTERFACE "$<INSTALL_INTERFACE:${KDECORATION2_INCLUDEDIR}>" )
......
......@@ -180,6 +180,16 @@ DELEGATE(requestShowWindowMenu)
#undef DELEGATE
void Decoration::requestShowToolTip(const QString &text)
{
d->client->d->requestShowToolTip(text);
}
void Decoration::requestHideToolTip()
{
d->client->d->requestHideToolTip();
}
void Decoration::requestToggleMaximization(Qt::MouseButtons buttons)
{
d->client->d->requestToggleMaximization(buttons);
......
......@@ -176,6 +176,8 @@ public Q_SLOTS:
void requestToggleKeepAbove();
void requestToggleKeepBelow();
void requestShowWindowMenu();
void requestShowToolTip(const QString &text);
void requestHideToolTip();
void showApplicationMenu(int actionId);
void requestShowApplicationMenu(const QRect &rect, int actionId);
......
......@@ -24,6 +24,9 @@
#include "decoratedclient.h"
#include "decorationsettings.h"
#include <KLocalizedString>
#include <QDebug>
#include <QElapsedTimer>
#include <QHoverEvent>
#include <QGuiApplication>
......@@ -284,6 +287,49 @@ void DecorationButton::Private::stopPressAndHold()
}
}
QString DecorationButton::Private::typeToString(DecorationButtonType type)
{
switch (type) {
case DecorationButtonType::Menu:
return i18n("Menu");
case DecorationButtonType::ApplicationMenu:
return i18n("Application menu");
case DecorationButtonType::OnAllDesktops:
if ( this->q->isChecked() )
return i18n("On one desktop");
else
return i18n("On all desktops");
case DecorationButtonType::Minimize:
return i18n("Minimize");
case DecorationButtonType::Maximize:
if ( this->q->isChecked() )
return i18n("Restore");
else
return i18n("Maximize");
case DecorationButtonType::Close:
return i18n("Close");
case DecorationButtonType::ContextHelp:
return i18n("Context help");
case DecorationButtonType::Shade:
if ( this->q->isChecked() )
return i18n("Unshade");
else
return i18n("Shade");
case DecorationButtonType::KeepBelow:
if ( this->q->isChecked() )
return i18n("Don't keep below");
else
return i18n("Keep below");
case DecorationButtonType::KeepAbove:
if ( this->q->isChecked() )
return i18n("Don't keep above");
else
return i18n("Keep above");
default:
return QString();
}
}
DecorationButton::DecorationButton(DecorationButtonType type, const QPointer<Decoration> &decoration, QObject *parent)
: QObject(parent)
, d(new Private(type, decoration, this))
......@@ -293,6 +339,17 @@ DecorationButton::DecorationButton(DecorationButtonType type, const QPointer<Dec
this, static_cast<void (DecorationButton::*)(const QRectF&)>(&DecorationButton::update));
auto updateSlot = static_cast<void (DecorationButton::*)()>(&DecorationButton::update);
connect(this, &DecorationButton::hoveredChanged, this, updateSlot);
connect(this, &DecorationButton::hoveredChanged, this,
[this](bool hovered) {
if (hovered) {
//TODO: show tooltip if hovered and hide if not
const QString type = this->d->typeToString(this->type());
this->decoration()->requestShowToolTip(type);
} else {
this->decoration()->requestHideToolTip();
}
}
);
connect(this, &DecorationButton::pressedChanged, this, updateSlot);
connect(this, &DecorationButton::checkedChanged, this, updateSlot);
connect(this, &DecorationButton::enabledChanged, this, updateSlot);
......
......@@ -66,6 +66,8 @@ public:
void startPressAndHold();
void stopPressAndHold();
QString typeToString(DecorationButtonType type);
QPointer<Decoration> decoration;
DecorationButtonType type;
QRectF geometry;
......
......@@ -25,7 +25,7 @@ target_link_libraries(kdecorations2private
target_include_directories(kdecorations2private INTERFACE "$<INSTALL_INTERFACE:${KDECORATION2_INCLUDEDIR}>" )
set_target_properties(kdecorations2private PROPERTIES VERSION ${KDECORATION2_VERSION_STRING}
SOVERSION ${KDECORATION2_SOVERSION}
SOVERSION 6
EXPORT_NAME KDecoration2Private
)
......
......@@ -76,6 +76,8 @@ public:
virtual QPalette palette() const = 0;
virtual Qt::Edges adjacentScreenEdges() const = 0;
virtual void requestShowToolTip(const QString &text) = 0;
virtual void requestHideToolTip() = 0;
virtual void requestClose() = 0;
virtual void requestToggleMaximization(Qt::MouseButtons buttons) = 0;
virtual void requestMinimize() = 0;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment