From 1c75cca9e21e76899e005f36a71687f6d06ae81a Mon Sep 17 00:00:00 2001 From: "Aaron J. Seigo" Date: Sun, 2 Nov 2008 05:58:42 +0000 Subject: [PATCH] break out Plasma::ToolTipManager::Content to Plasma::ToolTipContent and prep it for BC svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=878923 --- CMakeLists.txt | 2 + applet.cpp | 6 +- private/tooltip.cpp | 15 ++--- private/tooltip_p.h | 2 +- private/windowpreview.cpp | 5 ++ private/windowpreview_p.h | 1 + tooltipcontent.cpp | 138 ++++++++++++++++++++++++++++++++++++++ tooltipcontent.h | 99 +++++++++++++++++++++++++++ tooltipmanager.cpp | 15 +---- tooltipmanager.h | 34 ++-------- 10 files changed, 260 insertions(+), 57 deletions(-) create mode 100644 tooltipcontent.cpp create mode 100644 tooltipcontent.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 1e90bf42e..c422269ce 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/applet.cpp b/applet.cpp index 1f7700e1b..8f98d4ad5 100644 --- a/applet.cpp +++ b/applet.cpp @@ -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); diff --git a/private/tooltip.cpp b/private/tooltip.cpp index dab195ca8..36111bed0 100644 --- a/private/tooltip.cpp +++ b/private/tooltip.cpp @@ -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 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("" + data.mainText + "
" + data.subText + "
"); - d->imageLabel->setPixmap(data.image); - d->windowToPreview = data.windowToPreview; - d->preview->setWindowId(d->windowToPreview); - d->autohide = data.autohide; + d->label->setText("" + data.mainText() + "
" + data.subText() + "
"); + 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 { diff --git a/private/tooltip_p.h b/private/tooltip_p.h index 210c575cc..7a3572f64 100644 --- a/private/tooltip_p.h +++ b/private/tooltip_p.h @@ -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; diff --git a/private/windowpreview.cpp b/private/windowpreview.cpp index 7cb0dd01b..b3f930028 100644 --- a/private/windowpreview.cpp +++ b/private/windowpreview.cpp @@ -67,6 +67,11 @@ void WindowPreview::setWindowId(WId w) readWindowSize(); } +WId WindowPreview::windowId() const +{ + return id; +} + QSize WindowPreview::sizeHint() const { if (id == 0) { diff --git a/private/windowpreview_p.h b/private/windowpreview_p.h index 62fea6517..8e541ad2d 100644 --- a/private/windowpreview_p.h +++ b/private/windowpreview_p.h @@ -43,6 +43,7 @@ public: WindowPreview(QWidget *parent = 0); void setWindowId(WId w); + WId windowId() const; void setInfo(); virtual QSize sizeHint() const; diff --git a/tooltipcontent.cpp b/tooltipcontent.cpp new file mode 100644 index 000000000..92d556511 --- /dev/null +++ b/tooltipcontent.cpp @@ -0,0 +1,138 @@ +/* + * Copyright 2008 by Aaron Seigo + * + * 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 + +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 + + diff --git a/tooltipcontent.h b/tooltipcontent.h new file mode 100644 index 000000000..5428e872c --- /dev/null +++ b/tooltipcontent.h @@ -0,0 +1,99 @@ +/* + * Copyright 2008 by Aaron Seigo + * + * 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 +#include +#include + +#include + +/** + * 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 + + diff --git a/tooltipmanager.cpp b/tooltipmanager.cpp index 557fa771d..b4a1e2192 100644 --- a/tooltipmanager.cpp +++ b/tooltipmanager.cpp @@ -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) diff --git a/tooltipmanager.h b/tooltipmanager.h index fed92f4f8..413a10b69 100644 --- a/tooltipmanager.h +++ b/tooltipmanager.h @@ -25,6 +25,7 @@ //plasma #include #include +#include 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 - * - * 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