2008-09-07 23:33:02 +02:00
|
|
|
/*
|
2008-09-08 19:32:25 +02:00
|
|
|
* Copyright 2007 by Dan Meltzer <hydrogen@notyetimplemented.com>
|
|
|
|
* Copyright 2008 by Aaron Seigo <aseigo@kde.org>
|
|
|
|
* Copyright 2008 by Alexis Ménard <darktears31@gmail.com>
|
2008-09-07 23:33:02 +02:00
|
|
|
*
|
2008-09-08 19:32:25 +02:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2008-09-07 23:33:02 +02:00
|
|
|
*
|
2008-09-08 19:32:25 +02:00
|
|
|
* This library 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
|
|
|
|
* Lesser General Public License for more details.
|
2008-09-07 23:33:02 +02:00
|
|
|
*
|
2008-09-08 19:32:25 +02:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301 USA
|
2008-09-07 23:33:02 +02:00
|
|
|
*/
|
2008-07-16 17:17:44 +02:00
|
|
|
|
2008-10-12 12:48:53 +02:00
|
|
|
#ifndef PLASMA_TOOLTIP_MANAGER_H
|
|
|
|
#define PLASMA_TOOLTIP_MANAGER_H
|
2008-07-16 17:17:44 +02:00
|
|
|
|
|
|
|
//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-08-23 17:35:10 +02:00
|
|
|
/**
|
|
|
|
* @class ToolTipManager plasma/tooltipmanager.h <Plasma/ToolTipManager>
|
|
|
|
*
|
|
|
|
* @short Manages tooltips for QGraphicsWidgets in Plasma
|
|
|
|
*
|
|
|
|
* If you want a widget to have a tooltip displayed when the mouse is hovered over
|
|
|
|
* it, you should do something like:
|
|
|
|
*
|
|
|
|
* @code
|
|
|
|
* // widget is a QGraphicsWidget*
|
2008-10-21 04:31:43 +02:00
|
|
|
* Plasma::ToolTipManager::Content data;
|
2008-08-23 17:35:10 +02:00
|
|
|
* data.mainText = i18n("My Title");
|
|
|
|
* data.subText = i18n("This is a little tooltip");
|
|
|
|
* data.image = KIcon("some-icon").pixmap(IconSize(KIconLoader::Desktop));
|
2008-10-21 03:33:32 +02:00
|
|
|
* Plasma::ToolTipManager::self()->setContent(widget, data);
|
2008-08-23 17:35:10 +02:00
|
|
|
* @endcode
|
|
|
|
*
|
|
|
|
* Note that, since a Plasma::Applet is a QGraphicsWidget, you can use
|
2008-10-21 03:33:32 +02:00
|
|
|
* Plasma::ToolTipManager::self()->setContent(this, data); in the
|
2008-08-23 17:35:10 +02:00
|
|
|
* applet's init() method to set a tooltip for the whole applet.
|
|
|
|
*
|
2008-10-21 03:33:32 +02:00
|
|
|
* The tooltip will be registered automatically by setContent(). It will be
|
2008-08-23 17:35:10 +02:00
|
|
|
* automatically unregistered when the associated widget is deleted, freeing the
|
|
|
|
* memory used by the tooltip, but you can manually unregister it at any time by
|
|
|
|
* calling 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() slot
|
|
|
|
* will be invoked if it exists. This allows widgets to provide on-demand tooltip data.
|
|
|
|
*/
|
2008-07-17 09:53:31 +02:00
|
|
|
class PLASMA_EXPORT ToolTipManager : public QObject
|
|
|
|
{
|
2008-08-23 17:35:10 +02:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
|
2008-10-21 03:58:01 +02:00
|
|
|
enum State {
|
|
|
|
Activated = 0 /**<< Will accept tooltip data and show tooltips */,
|
|
|
|
Inhibited /**<< Will accept tooltip data, but not show tooltips */,
|
|
|
|
Deactivated /**<< Will discard tooltip data, and not attempt to show them */
|
|
|
|
};
|
|
|
|
|
2008-08-23 17:35:10 +02:00
|
|
|
/**
|
2008-10-21 04:31:43 +02:00
|
|
|
* @struct Content plasma/tooltipmanager.h <Plasma/ToolTipManager>
|
2008-08-25 19:47:48 +02:00
|
|
|
*
|
2008-08-23 17:35:10 +02:00
|
|
|
* This provides the content for a tooltip.
|
|
|
|
*
|
|
|
|
* Normally you will want to set at least the @p mainText and
|
|
|
|
* @p subText.
|
|
|
|
*/
|
2008-10-21 04:31:43 +02:00
|
|
|
struct PLASMA_EXPORT Content
|
2008-08-23 17:35:10 +02:00
|
|
|
{
|
2008-10-21 04:31:43 +02:00
|
|
|
/** Creates an empty Content */
|
|
|
|
Content();
|
2008-08-25 19:47:48 +02:00
|
|
|
|
|
|
|
/** @return true if all the fields are empty */
|
2008-08-23 17:35:10 +02:00
|
|
|
bool isEmpty() const;
|
|
|
|
|
|
|
|
/** Important information, e.g. the title */
|
|
|
|
QString mainText;
|
|
|
|
/** Elaborates on the @p mainText */
|
|
|
|
QString subText;
|
|
|
|
/** An icon to display */
|
|
|
|
QPixmap image;
|
|
|
|
/** Id of a window if you want to show a preview */
|
|
|
|
WId windowToPreview;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return The singleton instance of the manager.
|
|
|
|
*/
|
|
|
|
static ToolTipManager *self();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the tooltip for a widget registered in the tooltip manager
|
|
|
|
*
|
|
|
|
* @param widget the widget for which the tooltip will be displayed
|
|
|
|
*/
|
2008-10-21 03:33:32 +02:00
|
|
|
void show(QGraphicsWidget *widget);
|
2008-08-23 17:35:10 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Find out whether the tooltip for a given widget is currently being displayed.
|
|
|
|
*
|
|
|
|
* @param widget the widget to check the tooltip for
|
|
|
|
* @return true if the tooltip of the widget is currently displayed,
|
|
|
|
* false if not
|
|
|
|
*/
|
2008-10-21 03:33:32 +02:00
|
|
|
bool isVisible(QGraphicsWidget *widget) const;
|
2008-08-23 17:35:10 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Hides the tooltip for a widget immediately.
|
|
|
|
*
|
|
|
|
* @param widget the widget to hide the tooltip for
|
|
|
|
*/
|
2008-10-21 03:33:32 +02:00
|
|
|
void hide(QGraphicsWidget *widget);
|
2008-08-23 17:35:10 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Registers a widget with the tooltip manager.
|
|
|
|
*
|
2008-10-21 03:33:32 +02:00
|
|
|
* Note that setContent() will register the widget if it
|
2008-08-23 17:35:10 +02:00
|
|
|
* has not already been registered, and so you do not normally
|
|
|
|
* need to use the method.
|
|
|
|
*
|
|
|
|
* This is useful for creating tooltip content on demand. You can
|
|
|
|
* register your widget with registerWidget(), then implement
|
|
|
|
* a slot named toolTipAboutToShow for the widget. This will be
|
|
|
|
* called before the tooltip is shown, allowing you to set the
|
2008-10-21 03:33:32 +02:00
|
|
|
* data with setContent().
|
2008-08-23 17:35:10 +02:00
|
|
|
*
|
|
|
|
* If the widget also has a toolTipHidden slot, this will be called
|
|
|
|
* after the tooltip is hidden.
|
|
|
|
*
|
|
|
|
* @param widget the desired widget
|
|
|
|
*/
|
|
|
|
void registerWidget(QGraphicsWidget *widget);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unregisters a widget from the tooltip manager.
|
|
|
|
*
|
|
|
|
* This will free the memory used by the tooltip associated with the widget.
|
|
|
|
*
|
|
|
|
* @param widget the desired widget to delete
|
|
|
|
*/
|
|
|
|
void unregisterWidget(QGraphicsWidget *widget);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the content for the tooltip associated with a widget.
|
|
|
|
*
|
|
|
|
* Note that this will register the widget with the ToolTipManager if
|
|
|
|
* necessary, so there is usually no need to call registerWidget().
|
|
|
|
*
|
|
|
|
* @param widget the widget the tooltip should be associated with
|
2008-10-21 04:31:43 +02:00
|
|
|
* @param data the content of the tooltip. If an empty Content
|
2008-08-23 17:35:10 +02:00
|
|
|
* is passed in, the tooltip content will be reset.
|
|
|
|
*/
|
2008-10-21 03:33:32 +02:00
|
|
|
void setContent(QGraphicsWidget *widget,
|
2008-10-24 00:14:07 +02:00
|
|
|
const ToolTipManager::Content &data);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clears the tooltip data associated with this widget, but keeps
|
|
|
|
* the widget registered.
|
|
|
|
*/
|
|
|
|
void clearContent(QGraphicsWidget *widget);
|
2008-08-23 17:35:10 +02:00
|
|
|
|
2008-10-21 03:58:01 +02:00
|
|
|
/**
|
|
|
|
* Sets the current state of the manager.
|
|
|
|
* @see State
|
|
|
|
* @arg state the state to put the manager in
|
|
|
|
*/
|
|
|
|
void setState(ToolTipManager::State state);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the current state of the manager; @see State
|
|
|
|
*/
|
|
|
|
ToolTipManager::State state() const;
|
|
|
|
|
2008-10-21 03:01:12 +02:00
|
|
|
private:
|
2008-09-30 20:26:50 +02:00
|
|
|
/**
|
2008-10-21 03:01:12 +02:00
|
|
|
* Default constructor.
|
2008-08-23 17:35:10 +02:00
|
|
|
*
|
2008-10-21 03:01:12 +02:00
|
|
|
* You should normall use self() instead.
|
2008-08-28 22:23:39 +02:00
|
|
|
*/
|
2008-10-21 03:01:12 +02:00
|
|
|
explicit ToolTipManager(QObject *parent = 0);
|
2008-08-28 22:23:39 +02:00
|
|
|
|
|
|
|
/**
|
2008-10-21 03:01:12 +02:00
|
|
|
* Default destructor.
|
2008-08-28 22:23:39 +02:00
|
|
|
*/
|
2008-10-21 03:01:12 +02:00
|
|
|
~ToolTipManager();
|
2008-08-28 22:23:39 +02:00
|
|
|
|
2008-08-23 17:35:10 +02:00
|
|
|
friend class ToolTipManagerSingleton;
|
|
|
|
bool eventFilter(QObject *watched, QEvent *event);
|
|
|
|
|
2008-10-11 18:19:04 +02:00
|
|
|
ToolTipManagerPrivate *const d;
|
2008-08-23 17:35:10 +02:00
|
|
|
Q_PRIVATE_SLOT(d, void showToolTip())
|
|
|
|
Q_PRIVATE_SLOT(d, void resetShownState())
|
|
|
|
Q_PRIVATE_SLOT(d, void onWidgetDestroyed(QObject*))
|
|
|
|
Q_PRIVATE_SLOT(d, void themeUpdated())
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Plasma
|
|
|
|
|
|
|
|
#endif // PLASMA_TOOL_TIP_MANAGER_H
|