summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElvis Angelaccio <[email protected]>2017-02-11 13:04:54 +0100
committerElvis Angelaccio <[email protected]>2017-02-11 13:08:13 +0100
commitdfedcd46e2b3c9a10809ac65fab9b8a6fba37a9c (patch)
tree31e9f2f1e6f301ac58a54d01825b6b41952af0dc
parent41680b0b89b7a67c3b0b0bf73d902300f90c57ce (diff)
Port tooltips to KToolTipWidget
Summary: KToolTipWidget (introduced by kwidgetsaddons 5.30) supersedes the tooltip code (originally forked from Dolphin) in systemsettings. Test Plan: Tooltips still work, both in X11 and Wayland. Reviewers: #plasma Subscribers: plasma-devel Tags: #plasma Differential Revision: https://phabricator.kde.org/D4565
-rw-r--r--CMakeLists.txt4
-rw-r--r--app/CMakeLists.txt2
-rw-r--r--app/ToolTips/ktooltip.cpp105
-rw-r--r--app/ToolTips/ktooltip.h47
-rw-r--r--app/ToolTips/ktooltipwindow.cpp62
-rw-r--r--app/ToolTips/ktooltipwindow_p.h40
-rw-r--r--app/ToolTips/tooltipmanager.cpp78
-rw-r--r--app/ToolTips/tooltipmanager.h10
8 files changed, 16 insertions, 332 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 09ef710..1dbda78 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -3,6 +3,7 @@ set(PROJECT_VERSION "5.9.90")
cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
set(QT_MIN_VERSION "5.4.0")
+set(KF5_MIN_VERSION "5.30")
remove_definitions(-DQT_NO_CAST_FROM_ASCII -DQT_STRICT_ITERATORS -DQT_NO_CAST_FROM_BYTEARRAY -DQT_NO_KEYWORDS)
@@ -19,13 +20,14 @@ find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS
Widgets
)
-find_package(KF5 REQUIRED COMPONENTS
+find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS
ItemViews
KCMUtils
I18n
KIO
Service
IconThemes
+ WidgetsAddons
WindowSystem
XmlGui
DBusAddons
diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt
index 3fa8dbb..51f87e0 100644
--- a/app/CMakeLists.txt
+++ b/app/CMakeLists.txt
@@ -4,8 +4,6 @@ include_directories( ToolTips )
set( systemsettings_SRCS
SystemSettingsApp.cpp
SettingsBase.cpp
- ToolTips/ktooltip.cpp
- ToolTips/ktooltipwindow.cpp
ToolTips/tooltipmanager.cpp
main.cpp )
diff --git a/app/ToolTips/ktooltip.cpp b/app/ToolTips/ktooltip.cpp
deleted file mode 100644
index 34561f1..0000000
--- a/app/ToolTips/ktooltip.cpp
+++ /dev/null
@@ -1,105 +0,0 @@
-/***************************************************************************
- * Copyright (C) 2008 by Fredrik Höglund <[email protected]> *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the *
- * Free Software Foundation, Inc., *
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
- ***************************************************************************/
-
-#include "ktooltip.h"
-#include "ktooltipwindow_p.h"
-#include <QLabel>
-#include <QPoint>
-#include <QWindow>
-#include <QWidget>
-
-class KToolTipManager
-{
-public:
- ~KToolTipManager();
-
- static KToolTipManager* instance();
-
- void showTip(const QPoint& pos, QWidget* content, QWindow *transientParent);
- void hideTip();
-
-private:
- KToolTipManager();
-
- KToolTipWindow* m_window;
- static KToolTipManager *s_instance;
-};
-
-KToolTipManager *KToolTipManager::s_instance = 0;
-
-KToolTipManager::KToolTipManager() :
- m_window(0)
-{
-}
-
-KToolTipManager::~KToolTipManager()
-{
- delete m_window;
- m_window = 0;
-}
-
-KToolTipManager* KToolTipManager::instance()
-{
- if (s_instance == 0) {
- s_instance = new KToolTipManager();
- }
-
- return s_instance;
-}
-
-void KToolTipManager::showTip(const QPoint& pos, QWidget* content, QWindow *transientParent)
-{
- hideTip();
- Q_ASSERT(m_window == 0);
- m_window = new KToolTipWindow(content);
- m_window->move(pos);
- m_window->createWinId();
- m_window->windowHandle()->setTransientParent(transientParent);
- m_window->show();
-}
-
-void KToolTipManager::hideTip()
-{
- if (m_window != 0) {
- m_window->hide();
- m_window->deleteLater();
- m_window = 0;
- }
-}
-
-namespace KToolTip
-{
- void showText(const QPoint& pos, const QString& text, QWindow *transientParent)
- {
- QLabel* label = new QLabel(text);
- label->setForegroundRole(QPalette::ToolTipText);
- showTip(pos, label, transientParent);
- }
-
- void showTip(const QPoint& pos, QWidget* content, QWindow *transientParent)
- {
- KToolTipManager::instance()->showTip(pos, content, transientParent);
- }
-
- void hideTip()
- {
- KToolTipManager::instance()->hideTip();
- }
-}
-
diff --git a/app/ToolTips/ktooltip.h b/app/ToolTips/ktooltip.h
deleted file mode 100644
index 82ed45e..0000000
--- a/app/ToolTips/ktooltip.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/***************************************************************************
- * Copyright (C) 2008 by Fredrik Höglund <[email protected]> *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the *
- * Free Software Foundation, Inc., *
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
- ***************************************************************************/
-
-#ifndef KTOOLTIP_H
-#define KTOOLTIP_H
-
-class QPoint;
-class QString;
-class QWidget;
-class QWindow;
-
-/**
- * Allows to show tooltips having a widget as content.
- */
-namespace KToolTip
-{
- void showText(const QPoint& pos, const QString& text, QWindow *transientParent);
-
- /**
- * Shows the tip @p content at the global position indicated by @p pos.
- *
- * Ownership of the content widget is transferred to KToolTip. The widget will be deleted
- * automatically when it is hidden.
- *
- * The tip is shown immediately when this function is called.
- */
- void showTip(const QPoint& pos, QWidget* content, QWindow *transientParent);
- void hideTip();
-}
-
-#endif
diff --git a/app/ToolTips/ktooltipwindow.cpp b/app/ToolTips/ktooltipwindow.cpp
deleted file mode 100644
index 5c972d1..0000000
--- a/app/ToolTips/ktooltipwindow.cpp
+++ /dev/null
@@ -1,62 +0,0 @@
-/*******************************************************************************
- * Copyright (C) 2008 by Fredrik Höglund <[email protected]> *
- * Copyright (C) 2008 by Konstantin Heil <[email protected]> *
- * Copyright (C) 2009 by Peter Penz <[email protected]> *
- * Copyright (C) 2012 by Mark Gaiser <[email protected]> *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the *
- * Free Software Foundation, Inc., *
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
- *******************************************************************************/
-
-#include "ktooltipwindow_p.h"
-
-#include <QVBoxLayout>
-#include <QStylePainter>
-#include <QStyleOptionFrame>
-
-// For the blurred tooltip background
-#include <kwindoweffects.h>
-
-KToolTipWindow::KToolTipWindow(QWidget* content) :
- QWidget(0)
-{
- setAttribute(Qt::WA_TranslucentBackground);
- setWindowFlags(Qt::ToolTip | Qt::FramelessWindowHint);
-
- QVBoxLayout* layout = new QVBoxLayout(this);
- layout->addWidget(content);
-}
-
-KToolTipWindow::~KToolTipWindow()
-{
-}
-
-void KToolTipWindow::paintEvent(QPaintEvent* event)
-{
- QStylePainter painter(this);
- QStyleOptionFrame option;
- option.init(this);
- painter.drawPrimitive(QStyle::PE_PanelTipLabel, option);
- painter.end();
-
- QWidget::paintEvent(event);
-}
-
-void KToolTipWindow::showEvent(QShowEvent *)
-{
- KWindowEffects::enableBlurBehind(winId(), true, mask());
-}
-
-#include "moc_ktooltipwindow_p.cpp"
diff --git a/app/ToolTips/ktooltipwindow_p.h b/app/ToolTips/ktooltipwindow_p.h
deleted file mode 100644
index 4ffe22b..0000000
--- a/app/ToolTips/ktooltipwindow_p.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/***************************************************************************
- * Copyright (C) 2009 by Peter Penz <[email protected]> *
- * Copyright (C) 2012 by Mark Gaiser <[email protected]> *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the *
- * Free Software Foundation, Inc., *
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
- ***************************************************************************/
-
-#ifndef KTOOLTIPWINDOW_H
-#define KTOOLTIPWINDOW_H
-
-#include <QWidget>
-class QPaintEvent;
-
-class KToolTipWindow : public QWidget
-{
- Q_OBJECT
-
-public:
- explicit KToolTipWindow(QWidget* content);
- virtual ~KToolTipWindow();
-
-protected:
- virtual void paintEvent(QPaintEvent* event);
- virtual void showEvent(QShowEvent *);
-};
-
-#endif
diff --git a/app/ToolTips/tooltipmanager.cpp b/app/ToolTips/tooltipmanager.cpp
index f2f9943..31039af 100644
--- a/app/ToolTips/tooltipmanager.cpp
+++ b/app/ToolTips/tooltipmanager.cpp
@@ -21,33 +21,35 @@
#include "MenuItem.h"
-#include "ktooltip.h"
-
#include <QRect>
#include <QLabel>
#include <QTimer>
#include <QScrollBar>
#include <QGridLayout>
#include <QApplication>
-#include <QDesktopWidget>
#include <QAbstractItemView>
#include <KIconLoader>
#include <KColorScheme>
#include <KLocalizedString>
+#include <KToolTipWidget>
class ToolTipManager::Private
{
public:
Private() :
+ tooltip(0),
view(0),
- timer(0)
+ timer(0),
+ delay(300)
{ }
+ KToolTipWidget *tooltip;
QAbstractItemView* view;
QTimer* timer;
QModelIndex item;
QRect itemRect;
+ int delay;
};
ToolTipManager::ToolTipManager(QAbstractItemView* parent)
@@ -55,6 +57,8 @@ ToolTipManager::ToolTipManager(QAbstractItemView* parent)
, d(new ToolTipManager::Private)
{
d->view = parent;
+ d->tooltip = new KToolTipWidget(d->view);
+ d->tooltip->setHideDelay(0);
connect(parent, &QAbstractItemView::viewportEntered, this, &ToolTipManager::hideToolTip);
connect(parent, &QAbstractItemView::entered, this, &ToolTipManager::requestToolTip);
@@ -68,8 +72,6 @@ ToolTipManager::ToolTipManager(QAbstractItemView* parent)
// the scrollbars are observed.
connect(parent->horizontalScrollBar(), &QAbstractSlider::valueChanged, this, &ToolTipManager::hideToolTip);
connect(parent->verticalScrollBar(), &QAbstractSlider::valueChanged, this, &ToolTipManager::hideToolTip);
-
- d->view->viewport()->installEventFilter(this);
}
ToolTipManager::~ToolTipManager()
@@ -77,36 +79,18 @@ ToolTipManager::~ToolTipManager()
delete d;
}
-bool ToolTipManager::eventFilter(QObject* watched, QEvent* event)
-{
- if ( watched == d->view->viewport() ) {
- switch ( event->type() ) {
- case QEvent::Leave:
- case QEvent::MouseButtonPress:
- hideToolTip();
- break;
- case QEvent::ToolTip:
- return true;
- default:
- break;
- }
- }
-
- return QObject::eventFilter(watched, event);
-}
-
void ToolTipManager::requestToolTip(const QModelIndex& index)
{
// only request a tooltip for the name column and when no selection or
// drag & drop operation is done (indicated by the left mouse button)
if ( !(QApplication::mouseButtons() & Qt::LeftButton) ) {
- KToolTip::hideTip();
+ d->tooltip->hide();
d->itemRect = d->view->visualRect(index);
const QPoint pos = d->view->viewport()->mapToGlobal(d->itemRect.topLeft());
d->itemRect.moveTo(pos);
d->item = index;
- d->timer->start(300);
+ d->timer->start(d->delay);
} else {
hideToolTip();
}
@@ -115,7 +99,7 @@ void ToolTipManager::requestToolTip(const QModelIndex& index)
void ToolTipManager::hideToolTip()
{
d->timer->stop();
- KToolTip::hideTip();
+ d->tooltip->hideLater();
}
void ToolTipManager::prepareToolTip()
@@ -131,46 +115,10 @@ void ToolTipManager::showToolTip( QModelIndex menuItem )
QWidget * tip = createTipContent( menuItem );
- // calculate the x- and y-position of the tooltip
- const QSize size = tip->sizeHint();
- const QRect desktop = QApplication::desktop()->screenGeometry( d->itemRect.bottomRight() );
-
- // d->itemRect defines the area of the item, where the tooltip should be
- // shown. Per default the tooltip is shown in the bottom right corner.
- // If the tooltip content exceeds the desktop borders, it must be assured that:
- // - the content is fully visible
- // - the content is not drawn inside d->itemRect
- const int margin = 3;
- const bool hasRoomToLeft = (d->itemRect.left() - size.width() - margin >= desktop.left());
- const bool hasRoomToRight = (d->itemRect.right() + size.width() + margin <= desktop.right());
- const bool hasRoomAbove = (d->itemRect.top() - size.height() - margin >= desktop.top());
- const bool hasRoomBelow = (d->itemRect.bottom() + size.height() + margin <= desktop.bottom());
- if (!hasRoomAbove && !hasRoomBelow && !hasRoomToLeft && !hasRoomToRight) {
- delete tip;
- tip = 0;
- return;
- }
-
- int x = 0;
- int y = 0;
- if (hasRoomBelow || hasRoomAbove) {
- x = qMax(desktop.left(), d->itemRect.center().x() - size.width() / 2);
- if (x + size.width() / 2 >= desktop.right()) {
- x = desktop.right() - size.width();
- }
+ d->tooltip->showBelow(d->itemRect, tip, d->view->nativeParentWidget()->windowHandle());
- y = hasRoomBelow ? d->itemRect.bottom() + margin : d->itemRect.top() - size.height() - margin;
- } else {
- Q_ASSERT(hasRoomToLeft || hasRoomToRight);
- x = hasRoomToRight ? d->itemRect.right() + margin : d->itemRect.left() - size.width() - margin;
-
- // Put the tooltip at the bottom of the screen. The x-coordinate has already
- // been adjusted, so that no overlapping with d->itemRect occurs.
- y = desktop.bottom() - size.height();
- }
+ connect(d->tooltip, &KToolTipWidget::hidden, tip, &QObject::deleteLater);
- // the ownership of tip is transferred to KToolTip
- KToolTip::showTip(QPoint(x, y), tip, d->view->nativeParentWidget()->windowHandle());
}
QWidget * ToolTipManager::createTipContent( QModelIndex item )
diff --git a/app/ToolTips/tooltipmanager.h b/app/ToolTips/tooltipmanager.h
index c2b547f..0e4d032 100644
--- a/app/ToolTips/tooltipmanager.h
+++ b/app/ToolTips/tooltipmanager.h
@@ -56,16 +56,6 @@ public Q_SLOTS:
*/
void hideToolTip();
-protected:
- /**
- * Please see the Qt documentation for more details.
- *
- * @param watched The object that was being watched.
- * @param event The event object.
- * @returns true if the event was handled in this filter, or false if it was not.
- */
- virtual bool eventFilter( QObject* watched, QEvent* event );
-
private Q_SLOTS:
void prepareToolTip();
void requestToolTip(const QModelIndex& index);