2008-07-16 17:17:44 +02:00
|
|
|
/***************************************************************************
|
|
|
|
* Copyright (C) 2007 by Alexis Ménard <darktears31@gmail.com> *
|
|
|
|
* Copyright 2007 by Dan Meltzer <hydrogen@notyetimplemented.com> *
|
|
|
|
* *
|
|
|
|
* 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 PLASMA_TOOLTIP_MANAGER_H
|
|
|
|
#define PLASMA_TOOLTIP_MANAGER_H
|
|
|
|
|
|
|
|
//plasma
|
|
|
|
#include <plasma/plasma.h>
|
|
|
|
#include <plasma/plasma_export.h>
|
|
|
|
|
|
|
|
//KDE
|
|
|
|
#include <KWindowSystem>
|
|
|
|
|
|
|
|
#ifdef Q_WS_X11
|
|
|
|
#include <QX11Info>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//X11
|
|
|
|
#ifdef Q_WS_X11
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <fixx11h.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
class ToolTipManagerPrivate;
|
|
|
|
|
|
|
|
/**
|
2008-07-16 17:18:08 +02:00
|
|
|
* @short The class to manage tooltips on QGraphicsWidget in Plasma
|
2008-07-16 17:17:44 +02:00
|
|
|
*
|
2008-07-16 17:18:08 +02:00
|
|
|
* Manage tooltips on QGraphicsWidget. First you have to register your widget by calling registerWidget on the ToolTipManager singleton. After this you have to set the content of the tooltip by calling setWidgetToolTipContent using the struct ToolTipContent. The tooltip manager unregister automatically the widget when it is destroyed but if you want to do it manually call unregisterWidget. If you use plasma's applets show/hide of tooltip is automatically manage but if you use custom QGraphicsWidget, please call showToolTip on you hoverEnterEvent or hideToolTip on you hoverLeaveEvent.
|
2008-07-16 17:17:44 +02:00
|
|
|
*/
|
|
|
|
class PLASMA_EXPORT ToolTipManager : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2008-07-16 17:18:08 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Content of a tooltip
|
|
|
|
*/
|
2008-07-16 17:18:02 +02:00
|
|
|
struct ToolTipContent
|
2008-07-16 17:17:44 +02:00
|
|
|
{
|
2008-07-16 17:18:02 +02:00
|
|
|
ToolTipContent() : windowToPreview( 0 ) {}
|
2008-07-16 17:18:08 +02:00
|
|
|
QString mainText; /**Important information, e.g. the title*/
|
|
|
|
QString subText; /** Elaborates on the Main Text */
|
|
|
|
QPixmap image; /** Icon to show */
|
|
|
|
WId windowToPreview; /** Id of a window if you want to show a preview */
|
2008-07-16 17:17:44 +02:00
|
|
|
};
|
|
|
|
|
2008-07-16 17:18:02 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @return The singleton instance of the manager.
|
|
|
|
**/
|
2008-07-16 17:17:44 +02:00
|
|
|
static ToolTipManager *self();
|
2008-07-16 17:18:02 +02:00
|
|
|
|
2008-07-16 17:17:44 +02:00
|
|
|
/**
|
|
|
|
* Default constructor. Usually you want to use the singleton instead.
|
|
|
|
*/
|
|
|
|
explicit ToolTipManager(QObject* parent = 0);
|
2008-07-16 17:18:02 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Default destructor.
|
|
|
|
*/
|
2008-07-16 17:17:44 +02:00
|
|
|
~ToolTipManager();
|
2008-07-16 17:18:08 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function to show a tooltip of a widget registered in the tooltip manager
|
|
|
|
* @param widget the widget on which the tooltip will be displayed
|
|
|
|
*/
|
2008-07-16 17:17:44 +02:00
|
|
|
void showToolTip(QGraphicsWidget *widget);
|
2008-07-16 17:18:02 +02:00
|
|
|
|
2008-07-16 17:18:08 +02:00
|
|
|
/**
|
|
|
|
* Function to know if a tooltip of a widget is displayed
|
|
|
|
* @param widget the desired widget
|
|
|
|
* @return true if te tooltip of the widget is currently displayed, otherwhise no
|
|
|
|
*/
|
2008-07-16 17:18:02 +02:00
|
|
|
bool isWidgetToolTipDisplayed(QGraphicsWidget *widget);
|
|
|
|
|
2008-07-16 17:18:08 +02:00
|
|
|
/**
|
|
|
|
* Function to launch a delayed hide of the current displayed tooltip
|
|
|
|
* @param widget the desired widget
|
|
|
|
*/
|
2008-07-16 17:17:44 +02:00
|
|
|
void delayedHideToolTip();
|
2008-07-16 17:18:02 +02:00
|
|
|
|
2008-07-16 17:18:08 +02:00
|
|
|
/**
|
|
|
|
* Function to hide the tooltip of the desired widget
|
|
|
|
* @param widget the desired widget
|
|
|
|
*/
|
2008-07-16 17:17:44 +02:00
|
|
|
void hideToolTip(QGraphicsWidget *widget);
|
2008-07-16 17:18:02 +02:00
|
|
|
|
2008-07-16 17:18:08 +02:00
|
|
|
/**
|
|
|
|
* Function to register a widget to the tooltip manager, after this a setWidgetToolTipContent
|
|
|
|
* must be called
|
|
|
|
* @param widget the desired widget
|
|
|
|
*/
|
2008-07-16 17:18:02 +02:00
|
|
|
void registerWidget(QGraphicsWidget *widget);
|
|
|
|
|
2008-07-16 17:18:08 +02:00
|
|
|
/**
|
|
|
|
* Function to unregister a widget in the tooltip manager, i.e. means that memory will be free
|
|
|
|
* @param widget the desired widget to delete
|
|
|
|
*/
|
2008-07-16 17:18:02 +02:00
|
|
|
void unregisterWidget(QGraphicsWidget *widget);
|
|
|
|
|
2008-07-16 17:18:08 +02:00
|
|
|
/**
|
|
|
|
* Function to set the content of a tooltip on a desired widget
|
|
|
|
* @param widget the desired widget
|
|
|
|
* @param data the content of the tooltip
|
|
|
|
*/
|
2008-07-16 17:18:02 +02:00
|
|
|
void setWidgetToolTipContent(QGraphicsWidget *widget,const ToolTipContent &data);
|
|
|
|
|
2008-07-16 17:52:56 +02:00
|
|
|
/**
|
|
|
|
* Function to know if widget has a tooltip registered in the tooltip manager
|
|
|
|
* @param widget the widget
|
|
|
|
* @return true if this widget has a tooltip
|
|
|
|
*/
|
|
|
|
bool widgetHasToolTip(QGraphicsWidget *widget);
|
|
|
|
|
2008-07-16 17:18:08 +02:00
|
|
|
/**
|
|
|
|
* Reccomended position for a popup window like a menu or a tooltip
|
|
|
|
* given its size
|
|
|
|
* @param s size of the popup
|
|
|
|
* @returns reccomended position
|
|
|
|
*/
|
2008-07-16 17:17:44 +02:00
|
|
|
static QPoint popupPosition(const QGraphicsItem * item, const QSize &s);
|
|
|
|
|
|
|
|
private Q_SLOTS:
|
2008-07-16 17:18:08 +02:00
|
|
|
/**
|
|
|
|
* @internal called when the theme of plasma has change
|
|
|
|
*/
|
2008-07-16 17:17:44 +02:00
|
|
|
void themeUpdated();
|
2008-07-16 17:18:08 +02:00
|
|
|
/**
|
|
|
|
* @internal called when a widget inside the tooltip manager is deleted
|
|
|
|
*/
|
2008-07-16 17:18:02 +02:00
|
|
|
void onWidgetDestroyed(QObject * object);
|
2008-07-16 17:17:44 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
friend class ToolTipManagerSingleton;
|
|
|
|
ToolTipManagerPrivate* const d;
|
|
|
|
Q_PRIVATE_SLOT(d, void showToolTip())
|
|
|
|
Q_PRIVATE_SLOT(d, void resetShownState())
|
|
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|