break out Plasma::ToolTipManager::Content to Plasma::ToolTipContent and prep it for BC

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=878923
This commit is contained in:
Aaron J. Seigo 2008-11-02 05:58:42 +00:00
parent 1aa252d612
commit 1c75cca9e2
10 changed files with 260 additions and 57 deletions

View File

@ -62,6 +62,7 @@ set(plasma_LIB_SRCS
servicejob.cpp
svg.cpp
theme.cpp
tooltipcontent.cpp
tooltipmanager.cpp
uiloader.cpp
version.cpp
@ -163,6 +164,7 @@ set(plasma_LIB_INCLUDES
servicejob.h
svg.h
theme.h
tooltipcontent.h
tooltipmanager.h
uiloader.h
tooltipmanager.h

View File

@ -297,10 +297,8 @@ void Applet::setFailedToLaunch(bool failed, const QString &reason)
failureLayout->addItem(failureWidget);
Plasma::ToolTipManager::self()->registerWidget(failureIcon);
Plasma::ToolTipManager::Content data;
data.mainText = i18n("Unable to load the widget");
data.subText = reason;
data.image = KIcon("dialog-error").pixmap(IconSize(KIconLoader::Desktop));
Plasma::ToolTipContent data(i18n("Unable to load the widget"), reason,
KIcon("dialog-error").pixmap(IconSize(KIconLoader::Desktop)));
Plasma::ToolTipManager::self()->setContent(failureIcon, data);
setLayout(failureLayout);

View File

@ -44,7 +44,6 @@ class ToolTipPrivate
: label(0),
imageLabel(0),
preview(0),
windowToPreview(0),
source(s),
autohide(true)
{ }
@ -52,7 +51,6 @@ class ToolTipPrivate
QLabel *label;
QLabel *imageLabel;
WindowPreview *preview;
WId windowToPreview;
FrameSvg *background;
QPointer<QObject> source;
bool autohide;
@ -110,14 +108,13 @@ ToolTip::~ToolTip()
delete d;
}
void ToolTip::setContent(const ToolTipManager::Content &data)
void ToolTip::setContent(const ToolTipContent &data)
{
//reset our size
d->label->setText("<qt><b>" + data.mainText + "</b><br>" + data.subText + "</qt>");
d->imageLabel->setPixmap(data.image);
d->windowToPreview = data.windowToPreview;
d->preview->setWindowId(d->windowToPreview);
d->autohide = data.autohide;
d->label->setText("<qt><b>" + data.mainText() + "</b><br>" + data.subText() + "</qt>");
d->imageLabel->setPixmap(data.image());
d->preview->setWindowId(data.windowToPreview());
d->autohide = data.autohide();
if (isVisible()) {
resize(sizeHint());
@ -130,7 +127,7 @@ void ToolTip::prepareShowing(bool cueUpdate)
QMetaObject::invokeMethod(d->source, "toolTipAboutToShow");
}
if (d->windowToPreview != 0) {
if (d->preview->windowId() != 0) {
// show/hide the preview area
d->preview->show();
} else {

View File

@ -38,7 +38,7 @@ public:
~ToolTip();
void updateTheme();
void setContent(const ToolTipManager::Content &data);
void setContent(const ToolTipContent &data);
void prepareShowing(bool cueUpdate);
void setActivated(bool value);
bool autohide() const;

View File

@ -67,6 +67,11 @@ void WindowPreview::setWindowId(WId w)
readWindowSize();
}
WId WindowPreview::windowId() const
{
return id;
}
QSize WindowPreview::sizeHint() const
{
if (id == 0) {

View File

@ -43,6 +43,7 @@ public:
WindowPreview(QWidget *parent = 0);
void setWindowId(WId w);
WId windowId() const;
void setInfo();
virtual QSize sizeHint() const;

138
tooltipcontent.cpp Normal file
View File

@ -0,0 +1,138 @@
/*
* Copyright 2008 by Aaron Seigo <aseigo@kde.org>
*
* 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.
*
* 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.
*
* 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
*/
#include "tooltipcontent.h"
#include <KIconLoader>
namespace Plasma
{
class ToolTipContentPrivate
{
public:
ToolTipContentPrivate()
: windowToPreview(0),
autohide(true)
{
}
QString mainText;
QString subText;
QPixmap image;
WId windowToPreview;
bool autohide;
};
ToolTipContent::ToolTipContent()
: d(new ToolTipContentPrivate)
{
}
ToolTipContent::ToolTipContent(const ToolTipContent &other)
: d(new ToolTipContentPrivate(*other.d))
{
}
ToolTipContent::ToolTipContent(const QString &mainText,
const QString &subText,
const QPixmap &image)
: d(new ToolTipContentPrivate)
{
d->mainText = mainText;
d->subText = subText;
d->image = image;
}
ToolTipContent::ToolTipContent(const QString &mainText,
const QString &subText,
const QIcon &icon)
: d(new ToolTipContentPrivate)
{
d->mainText = mainText;
d->subText = subText;
d->image = icon.pixmap(IconSize(KIconLoader::Desktop));
}
bool ToolTipContent::isEmpty() const
{
return d->mainText.isEmpty() &&
d->subText.isEmpty() &&
d->image.isNull() &&
d->windowToPreview == 0;
}
void ToolTipContent::setMainText(const QString &text)
{
d->mainText = text;
}
QString ToolTipContent::mainText() const
{
return d->mainText;
}
void ToolTipContent::setSubText(const QString &text)
{
d->subText = text;
}
QString ToolTipContent::subText() const
{
return d->subText;
}
void ToolTipContent::setImage(const QPixmap &image)
{
d->image = image;
}
void ToolTipContent::setImage(const QIcon &icon)
{
d->image = icon.pixmap(IconSize(KIconLoader::Desktop));
}
QPixmap ToolTipContent::image() const
{
return d->image;
}
void ToolTipContent::setWindowToPreview(WId id)
{
d->windowToPreview = id;
}
WId ToolTipContent::windowToPreview() const
{
return d->windowToPreview;
}
void ToolTipContent::setAutohide(bool autohide)
{
d->autohide = autohide;
}
bool ToolTipContent::autohide() const
{
return d->autohide;
}
} // namespace Plasma

99
tooltipcontent.h Normal file
View File

@ -0,0 +1,99 @@
/*
* Copyright 2008 by Aaron Seigo <aseigo@kde.org>
*
* 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.
*
* 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.
*
* 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
*/
#include <QtCore/QString>
#include <QtGui/QPixmap>
#include <QtGui/QIcon>
#include <plasma/plasma_export.h>
/**
* This provides the content for a tooltip.
*
* Normally you will want to set at least the @p mainText and
* @p subText.
*/
namespace Plasma
{
class ToolTipContentPrivate;
class PLASMA_EXPORT ToolTipContent
{
public:
/** Creates an empty Content */
ToolTipContent();
/** Copy constructor */
ToolTipContent(const ToolTipContent &other);
/** Constructor that sets the common fields */
ToolTipContent(const QString &mainText,
const QString &subText,
const QPixmap &image = QPixmap());
/** Constructor that sets the common fields */
ToolTipContent(const QString &mainText,
const QString &subText,
const QIcon &icon);
/** @return true if all the fields are empty */
bool isEmpty() const;
/** Sets the main text which containts important information, e.g. the title */
void setMainText(const QString &text);
/** Important information, e.g. the title */
QString mainText() const;
/** Sets text which elaborates on the @p mainText */
void setSubText(const QString &text) ;
/** Elaborates on the @p mainText */
QString subText() const;
/** Sets the icon to show **/
void setImage(const QPixmap &image);
/** Sets the icon to show **/
void setImage(const QIcon &icon);
/** An icon to display */
QPixmap image() const;
/** Sets the ID of the window to show a preview for */
void setWindowToPreview(WId id);
/** Id of a window if you want to show a preview */
WId windowToPreview() const;
/** Sets whether or not to autohide the tooltip, defaults to true */
void setAutohide(bool autohide);
/** Whether or not to autohide the tooltip, defaults to true */
bool autohide() const;
private:
ToolTipContentPrivate * const d;
};
} // namespace Plasma

View File

@ -109,17 +109,6 @@ ToolTipManager *ToolTipManager::self()
return &privateInstance->self;
}
ToolTipManager::Content::Content()
: windowToPreview(0),
autohide(true)
{
}
bool ToolTipManager::Content::isEmpty() const
{
return mainText.isEmpty() && subText.isEmpty() && image.isNull() && windowToPreview == 0;
}
ToolTipManager::ToolTipManager(QObject *parent)
: QObject(parent),
d(new ToolTipManagerPrivate)
@ -219,7 +208,7 @@ void ToolTipManager::unregisterWidget(QGraphicsWidget *widget)
}
}
void ToolTipManager::setContent(QGraphicsWidget *widget, const Content &data)
void ToolTipManager::setContent(QGraphicsWidget *widget, const ToolTipContent &data)
{
if (d->state == Deactivated) {
return;
@ -248,7 +237,7 @@ void ToolTipManager::setContent(QGraphicsWidget *widget, const Content &data)
void ToolTipManager::clearContent(QGraphicsWidget *widget)
{
setContent(widget, Content());
setContent(widget, ToolTipContent());
}
void ToolTipManager::setState(ToolTipManager::State state)

View File

@ -25,6 +25,7 @@
//plasma
#include <plasma/plasma.h>
#include <plasma/plasma_export.h>
#include <plasma/tooltipcontent.h>
namespace Plasma
{
@ -43,7 +44,7 @@ class Corona;
*
* @code
* // widget is a QGraphicsWidget*
* Plasma::ToolTipManager::Content data;
* Plasma::ToolTipContent data;
* data.mainText = i18n("My Title");
* data.subText = i18n("This is a little tooltip");
* data.image = KIcon("some-icon").pixmap(IconSize(KIconLoader::Desktop));
@ -63,6 +64,7 @@ class Corona;
* 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.
*/
class PLASMA_EXPORT ToolTipManager : public QObject
{
Q_OBJECT
@ -74,34 +76,6 @@ public:
Deactivated /**<< Will discard tooltip data, and not attempt to show them */
};
/**
* @struct Content plasma/tooltipmanager.h <Plasma/ToolTipManager>
*
* This provides the content for a tooltip.
*
* Normally you will want to set at least the @p mainText and
* @p subText.
*/
struct PLASMA_EXPORT Content
{
/** Creates an empty Content */
Content();
/** @return true if all the fields are empty */
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;
/** Whether or not to autohide the tooltip, defaults to true */
bool autohide;
};
/**
* @return The singleton instance of the manager.
*/
@ -170,7 +144,7 @@ public:
* is passed in, the tooltip content will be reset.
*/
void setContent(QGraphicsWidget *widget,
const ToolTipManager::Content &data);
const ToolTipContent &data);
/**
* Clears the tooltip data associated with this widget, but keeps