• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

Plasma

tooltipcontent.cpp

Go to the documentation of this file.
00001 /*
00002  * Copyright 2008 by Aaron Seigo <aseigo@kde.org>
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2.1 of the License, or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Lesser General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Lesser General Public
00015  * License along with this library; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin St, Fifth Floor,
00017  * Boston, MA  02110-1301  USA
00018  */
00019 
00020 #include "tooltipcontent.h"
00021 
00022 #include <QHash>
00023 #include <QTextDocument>
00024 
00025 #include <kiconloader.h>
00026 
00027 namespace Plasma
00028 {
00029 
00030 struct ToolTipResource
00031 {
00032     ToolTipResource()
00033     {
00034     }
00035 
00036     ToolTipResource(ToolTipContent::ResourceType t, const QVariant &v)
00037         : type(t),
00038           data(v)
00039     {
00040     }
00041 
00042     ToolTipContent::ResourceType type;
00043     QVariant data;
00044 };
00045 class ToolTipContentPrivate
00046 {
00047 public:
00048     ToolTipContentPrivate()
00049       : windowToPreview(0),
00050         autohide(true)
00051     {
00052     }
00053 
00054     QString mainText;
00055     QString subText;
00056     QPixmap image;
00057     WId windowToPreview;
00058     QHash<QString, ToolTipResource> resources;
00059     bool autohide;
00060 };
00061 
00062 ToolTipContent::ToolTipContent()
00063     : d(new ToolTipContentPrivate)
00064 {
00065 }
00066 
00067 ToolTipContent::ToolTipContent(const ToolTipContent &other)
00068     : d(new ToolTipContentPrivate(*other.d))
00069 {
00070 }
00071 
00072 ToolTipContent::~ToolTipContent()
00073 {
00074     delete d;
00075 }
00076 
00077 ToolTipContent &ToolTipContent::operator=(const ToolTipContent &other)
00078 {
00079     *d = *other.d;
00080     return *this;
00081 }
00082 
00083 ToolTipContent::ToolTipContent(const QString &mainText,
00084                                const QString &subText,
00085                                const QPixmap &image)
00086     : d(new ToolTipContentPrivate)
00087 {
00088     d->mainText = mainText;
00089     d->subText = subText;
00090     d->image = image;
00091 }
00092 
00093 ToolTipContent::ToolTipContent(const QString &mainText,
00094                                const QString &subText,
00095                                const QIcon &icon)
00096     : d(new ToolTipContentPrivate)
00097 {
00098     d->mainText = mainText;
00099     d->subText = subText;
00100     d->image = icon.pixmap(IconSize(KIconLoader::Desktop));
00101 }
00102 
00103 bool ToolTipContent::isEmpty() const
00104 {
00105     return d->mainText.isEmpty() &&
00106            d->subText.isEmpty() &&
00107            d->image.isNull() &&
00108            d->windowToPreview == 0;
00109 }
00110 
00111 void ToolTipContent::setMainText(const QString &text)
00112 {
00113     d->mainText = text;
00114 }
00115 
00116 QString ToolTipContent::mainText() const
00117 {
00118     return d->mainText;
00119 }
00120 
00121 void ToolTipContent::setSubText(const QString &text)
00122 {
00123     d->subText = text;
00124 }
00125 
00126 QString ToolTipContent::subText() const
00127 {
00128     return d->subText;
00129 }
00130 
00131 void ToolTipContent::setImage(const QPixmap &image)
00132 {
00133     d->image = image;
00134 }
00135 
00136 void ToolTipContent::setImage(const QIcon &icon)
00137 {
00138     d->image = icon.pixmap(IconSize(KIconLoader::Desktop));
00139 }
00140 
00141 QPixmap ToolTipContent::image() const
00142 {
00143     return d->image;
00144 }
00145 
00146 void ToolTipContent::setWindowToPreview(WId id)
00147 {
00148     d->windowToPreview = id;
00149 }
00150 
00151 WId ToolTipContent::windowToPreview() const
00152 {
00153     return d->windowToPreview;
00154 }
00155 
00156 void ToolTipContent::setAutohide(bool autohide)
00157 {
00158     d->autohide = autohide;
00159 }
00160 
00161 bool ToolTipContent::autohide() const
00162 {
00163     return d->autohide;
00164 }
00165 
00166 void ToolTipContent::addResource(ResourceType type, const QUrl &path, const QVariant &resource)
00167 {
00168     d->resources.insert(path.toString(), ToolTipResource(type, resource));
00169 }
00170 
00171 void ToolTipContent::registerResources(QTextDocument *document) const
00172 {
00173     if (!document) {
00174         return;
00175     }
00176 
00177     QHashIterator<QString, ToolTipResource> it(d->resources);
00178     while (it.hasNext()) {
00179         it.next();
00180         const ToolTipResource &r = it.value();
00181         QTextDocument::ResourceType t;
00182 
00183         switch (r.type) {
00184             case ImageResource:
00185                 t = QTextDocument::ImageResource;
00186                 break;
00187             case HtmlResource:
00188                 t = QTextDocument::HtmlResource;
00189                 break;
00190             case CssResource:
00191                 t = QTextDocument::StyleSheetResource;
00192                 break;
00193         }
00194 
00195         document->addResource(t, it.key(), r.data);
00196     }
00197 }
00198 
00199 } // namespace Plasma
00200 
00201 

Plasma

Skip menu "Plasma"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal