• Skip to content
  • Skip to link menu
KDE 4.3 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 
00046 class ToolTipContentPrivate
00047 {
00048 public:
00049     ToolTipContentPrivate()
00050       : autohide(true)
00051     {
00052     }
00053 
00054     QString mainText;
00055     QString subText;
00056     QPixmap image;
00057     QList<WId> windowsToPreview;
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->windowsToPreview.size() == 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->windowsToPreview.clear();
00149     d->windowsToPreview.append(id);
00150 }
00151 
00152 WId ToolTipContent::windowToPreview() const
00153 {
00154     if (d->windowsToPreview.size() == 1) {
00155         return d->windowsToPreview.first();
00156     } else {
00157         return 0;
00158     }
00159 }
00160 
00161 void ToolTipContent::setWindowsToPreview(const QList<WId> & ids)
00162 {
00163     d->windowsToPreview = ids;
00164 }
00165 
00166 QList<WId> ToolTipContent::windowsToPreview() const
00167 {
00168     return d->windowsToPreview;
00169 }
00170 
00171 void ToolTipContent::setAutohide(bool autohide)
00172 {
00173     d->autohide = autohide;
00174 }
00175 
00176 bool ToolTipContent::autohide() const
00177 {
00178     return d->autohide;
00179 }
00180 
00181 void ToolTipContent::addResource(ResourceType type, const QUrl &path, const QVariant &resource)
00182 {
00183     d->resources.insert(path.toString(), ToolTipResource(type, resource));
00184 }
00185 
00186 void ToolTipContent::registerResources(QTextDocument *document) const
00187 {
00188     if (!document) {
00189         return;
00190     }
00191 
00192     QHashIterator<QString, ToolTipResource> it(d->resources);
00193     while (it.hasNext()) {
00194         it.next();
00195         const ToolTipResource &r = it.value();
00196         QTextDocument::ResourceType t;
00197 
00198         switch (r.type) {
00199             case ImageResource:
00200                 t = QTextDocument::ImageResource;
00201                 break;
00202             case HtmlResource:
00203                 t = QTextDocument::HtmlResource;
00204                 break;
00205             case CssResource:
00206                 t = QTextDocument::StyleSheetResource;
00207                 break;
00208         }
00209 
00210         document->addResource(t, it.key(), r.data);
00211     }
00212 }
00213 
00214 } // namespace Plasma
00215 
00216 

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
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.6.1
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