2008-07-16 17:17:44 +02:00
|
|
|
/***************************************************************************
|
2008-07-17 01:27:34 +02:00
|
|
|
* Copyright 2008 by Alexis Ménard <darktears31@gmail.com> *
|
|
|
|
* Copyright 2008 by Aaron Seigo <aseigo@kde.org> *
|
|
|
|
* 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 . *
|
|
|
|
***************************************************************************/
|
2008-07-16 17:17:44 +02:00
|
|
|
|
|
|
|
#ifndef PLASMA_TOOLTIP_MANAGER_H
|
|
|
|
#define PLASMA_TOOLTIP_MANAGER_H
|
|
|
|
|
|
|
|
//plasma
|
|
|
|
#include <plasma/plasma.h>
|
|
|
|
#include <plasma/plasma_export.h>
|
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
2008-07-17 09:53:31 +02:00
|
|
|
|
|
|
|
class ToolTipManagerPrivate;
|
|
|
|
class Applet;
|
2008-07-16 17:17:44 +02:00
|
|
|
|
|
|
|
/**
|
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-17 01:27:34 +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 setToolTipContent using the struct ToolTipContent. Calling
|
|
|
|
* setToolTipContent on a widget that is not registered will cause it to be registered.
|
|
|
|
*
|
|
|
|
* The tooltip manager unregister automatically the widget when it is destroyed but if
|
|
|
|
* you want to do it manually call unregisterWidget.
|
|
|
|
*
|
|
|
|
* When a tooltip for a widget is about to be shown, the widget's toolTipAboutToShow slot will be
|
|
|
|
* invoked if it exists. Similarly, when a tooltip is hidden, the widget's toolTipHidden() slow
|
|
|
|
* will be invoked if it exists. This allows widgets to provide on-demand tooltip data.
|
2008-07-16 17:17:44 +02:00
|
|
|
*/
|
2008-07-17 01:27:34 +02:00
|
|
|
|
2008-07-17 09:53:31 +02:00
|
|
|
class PLASMA_EXPORT ToolTipManager : public QObject
|
|
|
|
{
|
2008-07-16 17:17:44 +02:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2008-07-16 17:18:08 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Content of a tooltip
|
|
|
|
*/
|
2008-07-17 08:34:59 +02:00
|
|
|
struct PLASMA_EXPORT ToolTipContent
|
2008-07-16 17:17:44 +02:00
|
|
|
{
|
2008-07-17 01:27:34 +02:00
|
|
|
ToolTipContent();
|
|
|
|
bool isEmpty() const;
|
|
|
|
|
|
|
|
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-17 01:27:34 +02:00
|
|
|
|
2008-07-16 17:18:02 +02:00
|
|
|
/**
|
|
|
|
* Default destructor.
|
|
|
|
*/
|
2008-07-16 17:17:44 +02:00
|
|
|
~ToolTipManager();
|
2008-07-17 01:27:34 +02:00
|
|
|
|
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
|
|
|
/**
|
2008-07-17 01:27:34 +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. If an empty ToolTipContent is passed in,
|
|
|
|
* the tooltip content will be reset.
|
|
|
|
*/
|
|
|
|
void setToolTipContent(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
|
|
|
|
*/
|
2008-07-16 23:58:36 +02:00
|
|
|
bool widgetHasToolTip(QGraphicsWidget *widget) const;
|
2008-07-17 01:27:34 +02:00
|
|
|
|
2008-07-16 17:17:44 +02:00
|
|
|
private:
|
|
|
|
friend class ToolTipManagerSingleton;
|
2008-07-17 01:11:51 +02:00
|
|
|
bool eventFilter(QObject * watched, QEvent * event);
|
|
|
|
|
2008-07-16 17:17:44 +02:00
|
|
|
ToolTipManagerPrivate* const d;
|
|
|
|
Q_PRIVATE_SLOT(d, void showToolTip())
|
|
|
|
Q_PRIVATE_SLOT(d, void resetShownState())
|
2008-07-16 23:44:19 +02:00
|
|
|
Q_PRIVATE_SLOT(d, void onWidgetDestroyed(QObject*))
|
|
|
|
Q_PRIVATE_SLOT(d, void themeUpdated())
|
2008-07-16 17:17:44 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|