diff --git a/CMakeLists.txt b/CMakeLists.txt index c90f4bb..7e03e11 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,133 +1,131 @@ project(kinfocenter) set(PROJECT_VERSION "5.9.90") cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR) set(QT_MIN_VERSION "5.4.0") find_package(ECM 1.2.0 REQUIRED NO_MODULE) set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/cmake) include(KDEInstallDirs) include(KDECMakeSettings) include(KDECompilerSettings NO_POLICY_SCOPE) include(FeatureSummary) find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS Core Gui Widgets) -set(KF5_MIN_VERSION "5.9.0") +set(KF5_MIN_VERSION "5.30") find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS Completion Config ConfigWidgets CoreAddons DBusAddons DocTools I18n IconThemes KCMUtils KDELibs4Support KIO Service Solid WidgetsAddons XmlGui Declarative Package Solid ) if(${Qt5Gui_OPENGL_IMPLEMENTATION} STREQUAL "GL") find_package(OpenGL) set_package_properties(OpenGL PROPERTIES DESCRIPTION "The OpenGL libraries" URL "http://www.opengl.org" TYPE OPTIONAL ) else() find_package(OpenGLES) set_package_properties(OpenGLES PROPERTIES DESCRIPTION "The OpenGLES libraries" URL "http://www.khronos.org/opengles" TYPE OPTIONAL ) endif() find_package(EGL) set_package_properties(EGL PROPERTIES TYPE OPTIONAL PURPOSE "Required for OpenGL Information Module" ) find_package(KF5Wayland CONFIG) set_package_properties(KF5Wayland PROPERTIES TYPE OPTIONAL ) add_feature_info("KF5Wayland" KF5Wayland_FOUND "Required for Wayland Compositor Information Module") if(NOT APPLE) find_package(X11) set_package_properties(X11 PROPERTIES DESCRIPTION "X11 libraries" URL "http://www.x.org" TYPE OPTIONAL PURPOSE "Required for building the X11 based workspace" ) if(X11_FOUND) set(HAVE_X11 TRUE) endif() else() set(X11_FOUND False) endif() configure_file(config-workspace.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-workspace.h) configure_file(config-X11.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-X11.h) include_directories(${CMAKE_CURRENT_BINARY_DIR}) add_definitions( -DKDE_DEFAULT_DEBUG_AREA=1208 ) remove_definitions(-DQT_NO_CAST_FROM_ASCII -DQT_STRICT_ITERATORS -DQT_NO_CAST_FROM_BYTEARRAY -DQT_NO_KEYWORDS) add_subdirectory( Categories ) add_subdirectory( kcontrol/menus ) add_subdirectory( Modules ) include(ECMOptionalAddSubdirectory) ecm_optional_add_subdirectory( doc ) include_directories( ToolTips ) set( kinfocenter_SRCS infocenter.cpp main.cpp sidepanel.cpp kcmcontainer.cpp kcmtreeitem.cpp kcmcategoryitem.cpp infokcmmodel.cpp infokcmproxymodel.cpp -ToolTips/ktooltip.cpp -ToolTips/ktooltipwindow.cpp ToolTips/tooltipmanager.cpp ) add_executable( kinfocenter ${kinfocenter_SRCS} ) target_compile_definitions(kinfocenter PRIVATE -DPROJECT_VERSION="${PROJECT_VERSION}") target_link_libraries( kinfocenter KF5::Completion KF5::ConfigWidgets KF5::CoreAddons KF5::DBusAddons KF5::I18n KF5::IconThemes KF5::KCMUtils KF5::KDELibs4Support KF5::Service KF5::Solid KF5::WidgetsAddons KF5::XmlGui ) ##install install( TARGETS kinfocenter ${INSTALL_TARGETS_DEFAULT_ARGS} ) install( PROGRAMS org.kde.kinfocenter.desktop DESTINATION ${XDG_APPS_INSTALL_DIR} ) install( FILES kinfocenterui.rc DESTINATION ${KXMLGUI_INSTALL_DIR}/kinfocenter ) feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/ToolTips/ktooltip.cpp b/ToolTips/ktooltip.cpp deleted file mode 100644 index 34561f1..0000000 --- a/ToolTips/ktooltip.cpp +++ /dev/null @@ -1,105 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Fredrik Höglund * - * * - * 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 -#include -#include -#include - -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/ToolTips/ktooltip.h b/ToolTips/ktooltip.h deleted file mode 100644 index 6b84fe7..0000000 --- a/ToolTips/ktooltip.h +++ /dev/null @@ -1,47 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Fredrik Höglund * - * * - * 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 QWindow; -class QWidget; - -/** - * 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/ToolTips/ktooltipwindow.cpp b/ToolTips/ktooltipwindow.cpp deleted file mode 100644 index 6f3a321..0000000 --- a/ToolTips/ktooltipwindow.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2008 by Fredrik Höglund * - * Copyright (C) 2008 by Konstantin Heil * - * Copyright (C) 2009 by Peter Penz * - * * - * 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 - -#include -#include -#include -#include - -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); - painter.setClipRegion(event->region()); - QStyleOptionFrame option; - option.init(this); - painter.drawPrimitive(QStyle::PE_PanelTipLabel, option); - painter.end(); -} diff --git a/ToolTips/ktooltipwindow_p.h b/ToolTips/ktooltipwindow_p.h deleted file mode 100644 index 0813e6a..0000000 --- a/ToolTips/ktooltipwindow_p.h +++ /dev/null @@ -1,38 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Peter Penz * - * * - * 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 -class QPaintEvent; - -class KToolTipWindow : public QWidget -{ - Q_OBJECT - -public: - explicit KToolTipWindow(QWidget* content); - virtual ~KToolTipWindow(); - -protected: - virtual void paintEvent(QPaintEvent* event); -}; - -#endif diff --git a/ToolTips/tooltipmanager.cpp b/ToolTips/tooltipmanager.cpp index 83fb0b9..6827d27 100644 --- a/ToolTips/tooltipmanager.cpp +++ b/ToolTips/tooltipmanager.cpp @@ -1,227 +1,194 @@ /******************************************************************************* * Copyright (C) 2008 by Konstantin Heil * * * * 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 "tooltipmanager.h" #include "kcmtreeitem.h" #include "sidepanel.h" -#include "ktooltip.h" - #include #include #include #include #include #include -#include #include #include #include +#include class ToolTipManager::Private { public: Private() : view(0), - timer(0) + timer(0), + delay(50) { } + KToolTipWidget *tooltip; QAbstractItemView* view; QTimer* timer; QModelIndex item; QRect itemRect; + int delay; }; ToolTipManager::ToolTipManager(QAbstractItemView* parent) : QObject(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); d->timer = new QTimer(this); d->timer->setSingleShot(true); connect(d->timer, &QTimer::timeout, this, &ToolTipManager::prepareToolTip); // When the mousewheel is used, the items don't get a hovered indication // (Qt-issue #200665). To assure that the tooltip still gets hidden, // 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() { 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(50); + d->timer->start(d->delay); } else { hideToolTip(); } } void ToolTipManager::hideToolTip() { d->timer->stop(); - KToolTip::hideTip(); + d->tooltip->hideLater(); } void ToolTipManager::prepareToolTip() { showToolTip( d->item ); } void ToolTipManager::showToolTip( const QModelIndex& menuItem ) { if (QApplication::mouseButtons() & Qt::LeftButton) { return; } 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 bool hasRoomToLeft = (d->itemRect.left() - size.width() >= desktop.left()); - const bool hasRoomToRight = (d->itemRect.right() + size.width() <= desktop.right()); - const bool hasRoomAbove = (d->itemRect.top() - size.height() >= desktop.top()); - const bool hasRoomBelow = (d->itemRect.bottom() + size.height() <= desktop.bottom()); - if (!hasRoomAbove && !hasRoomBelow && !hasRoomToLeft && !hasRoomToRight) { - delete tip; - tip = 0; - return; - } - - int x = 0; - int y = 0; - if (hasRoomBelow || hasRoomAbove) { - x = QCursor::pos().x() + 16; // TODO: use mouse pointer width instead of the magic value of 16 - if (x + size.width() >= desktop.right()) { - x = desktop.right() - size.width(); - } - y = hasRoomBelow ? d->itemRect.bottom() : d->itemRect.top() - size.height(); - } else { - Q_ASSERT(hasRoomToLeft || hasRoomToRight); - x = hasRoomToRight ? d->itemRect.right() : d->itemRect.left() - size.width(); - - // 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(); - } - - // the ownership of tip is transferred to KToolTip - KToolTip::showTip(QPoint(x, y), tip, d->view->nativeParentWidget()->windowHandle()); + connect(d->tooltip, &KToolTipWidget::hidden, tip, &QObject::deleteLater); + + d->tooltip->showBelow(d->itemRect, tip, d->view->nativeParentWidget()->windowHandle()); } QWidget * ToolTipManager::createTipContent( const QModelIndex& item ) { QWidget * tipContent = new QWidget(); QGridLayout* tipLayout = new QGridLayout(); QLayout * primaryLine = generateToolTipLine( item, tipContent, QSize(32,32), true ); tipLayout->addLayout( primaryLine, 0, 0 ); for ( int done = 0; d->view->model()->rowCount( item ) > done; done = 1 + done ) { QModelIndex childItem = d->view->model()->index( done, 0, item ); QLayout * subLine = generateToolTipLine( childItem, tipContent, QSize(24,24), false ); tipLayout->addLayout( subLine, done + 2, 0 ); } tipLayout->setVerticalSpacing( 0 ); tipContent->setLayout( tipLayout ); if( d->view->model()->rowCount( item ) > 0 ) { QFrame * separatorLine = new QFrame( tipContent ); separatorLine->setFrameStyle( QFrame::HLine ); tipLayout->addWidget( separatorLine, 1, 0 ); } return tipContent; } QLayout * ToolTipManager::generateToolTipLine( const QModelIndex & item, QWidget * toolTip, const QSize& iconSize, bool comment ) { SidePanel *sidePanel = static_cast(d->view); KcmTreeItem *menuItem = static_cast( sidePanel->mapToProxySource(item).internalPointer() ); QString text = menuItem->data(); if ( comment ) { text = QStringLiteral( "%1" ).arg( menuItem->data() ); } QLabel * textLabel = new QLabel( toolTip ); textLabel->setForegroundRole(QPalette::ToolTipText); textLabel->setText( text ); // Get icon QIcon icon( menuItem->icon() ); QLabel * iconLabel = new QLabel( toolTip ); iconLabel->setPixmap( icon.pixmap(iconSize) ); iconLabel->setMaximumSize( iconSize ); // Generate layout QHBoxLayout * layout = new QHBoxLayout(); layout->addWidget( iconLabel ); layout->addWidget( textLabel ); return layout; }