diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,6 +24,7 @@ Core Gui Test + Widgets ) include(KDEInstallDirs) @@ -38,6 +39,7 @@ endif() set(KDECORATION2_INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR}/KDecoration2") +find_package(KF5I18n CONFIG REQUIRED) # Subdirectories add_subdirectory(src) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,3 +1,5 @@ +add_definitions(-DTRANSLATION_DOMAIN="kcmkwindecoration") + add_subdirectory(private) set(libkdecoration2_SRCS @@ -17,8 +19,10 @@ PUBLIC Qt5::Core Qt5::Gui + Qt5::Widgets PRIVATE kdecorations2private + KF5::I18n ) target_include_directories(kdecorations2 INTERFACE "$" ) diff --git a/src/decorationbutton.h b/src/decorationbutton.h --- a/src/decorationbutton.h +++ b/src/decorationbutton.h @@ -152,6 +152,11 @@ **/ void update(); + //* show tooltip + void showTooltip(bool); + + QString typeToString( DecorationButtonType type ); + Q_SIGNALS: void clicked(Qt::MouseButton); void pressed(); diff --git a/src/decorationbutton.cpp b/src/decorationbutton.cpp --- a/src/decorationbutton.cpp +++ b/src/decorationbutton.cpp @@ -24,11 +24,15 @@ #include "decoratedclient.h" #include "decorationsettings.h" +#include + +#include #include #include #include #include #include +#include namespace KDecoration2 { @@ -293,6 +297,7 @@ this, static_cast(&DecorationButton::update)); auto updateSlot = static_cast(&DecorationButton::update); connect(this, &DecorationButton::hoveredChanged, this, updateSlot); + connect(this, &DecorationButton::hoveredChanged, this, &DecorationButton::showTooltip); connect(this, &DecorationButton::pressedChanged, this, updateSlot); connect(this, &DecorationButton::checkedChanged, this, updateSlot); connect(this, &DecorationButton::enabledChanged, this, updateSlot); @@ -496,4 +501,65 @@ Q_UNUSED(event) } +void DecorationButton::showTooltip( bool hovered ) +{ + + //TODO: show tooltip if hovered and hide if not + if ( hovered ){ + const QString& type = typeToString(this->type()); + const QPoint& position = QCursor::pos(); + + //TODO: change offset to something valuable + QToolTip::showText(position, type); + } else { + QToolTip::hideText(); + } + +} + +QString DecorationButton::typeToString( DecorationButtonType type ) +{ + + switch (type) { + case DecorationButtonType::Menu: + return i18n("Menu"); + case DecorationButtonType::ApplicationMenu: + return i18n("Application menu"); + case DecorationButtonType::OnAllDesktops: + if ( isChecked() ) + return i18n("On one desktop"); + else + return i18n("On all desktops"); + case DecorationButtonType::Minimize: + return i18n("Minimize"); + case DecorationButtonType::Maximize: + if ( 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 ( isChecked() ) + return i18n("Unshade"); + else + return i18n("Shade"); + case DecorationButtonType::KeepBelow: + if ( isChecked() ) + return i18n("Don't keep below"); + else + return i18n("Keep below"); + case DecorationButtonType::KeepAbove: + if ( isChecked() ) + return i18n("Don't keep above"); + else + return i18n("Keep above"); + default: + return QString(); + } + +} + }