• Skip to content
  • Skip to link menu
KDE 4.7 API Reference
  • KDE API Reference
  • kdelibs
  • KDE Home
  • 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 <QGraphicsWidget>
00023 #include <QHash>
00024 #include <QTextDocument>
00025 
00026 #include <kiconloader.h>
00027 
00028 namespace Plasma
00029 {
00030 
00031 struct ToolTipResource
00032 {
00033     ToolTipResource()
00034     {
00035     }
00036 
00037     ToolTipResource(ToolTipContent::ResourceType t, const QVariant &v)
00038         : type(t),
00039           data(v)
00040     {
00041     }
00042 
00043     ToolTipContent::ResourceType type;
00044     QVariant data;
00045 };
00046 
00047 const int MAXIMUM_TEXT_LENGTH = 5000;
00048 
00049 class ToolTipContentPrivate
00050 {
00051 public:
00052     ToolTipContentPrivate()
00053       : autohide(true),
00054         instantPopup(false),
00055         clickable(false),
00056         highlightWindows(false)
00057     {
00058     }
00059 
00060     QString mainText;
00061     QString subText;
00062     QPixmap image;
00063     QList<WId> windowsToPreview;
00064     QHash<QString, ToolTipResource> resources;
00065     QWeakPointer<QGraphicsWidget> graphicsWidget;
00066     bool autohide : 1;
00067     bool instantPopup : 1;
00068     bool clickable : 1;
00069     bool highlightWindows : 1;
00070 };
00071 
00072 ToolTipContent::ToolTipContent()
00073     : d(new ToolTipContentPrivate)
00074 {
00075 }
00076 
00077 ToolTipContent::ToolTipContent(const ToolTipContent &other)
00078     : d(new ToolTipContentPrivate(*other.d))
00079 {
00080 }
00081 
00082 ToolTipContent::~ToolTipContent()
00083 {
00084     delete d;
00085 }
00086 
00087 ToolTipContent &ToolTipContent::operator=(const ToolTipContent &other)
00088 {
00089     *d = *other.d;
00090     return *this;
00091 }
00092 
00093 ToolTipContent::ToolTipContent(const QString &mainText,
00094                                const QString &subText,
00095                                const QPixmap &image)
00096     : d(new ToolTipContentPrivate)
00097 {
00098     setMainText(mainText);
00099     setSubText(subText);
00100     setImage(image);
00101 }
00102 
00103 ToolTipContent::ToolTipContent(const QString &mainText,
00104                                const QString &subText,
00105                                const QIcon &icon)
00106     : d(new ToolTipContentPrivate)
00107 {
00108     setMainText(mainText);
00109     setSubText(subText);
00110     setImage(icon);
00111 }
00112 
00113 bool ToolTipContent::isEmpty() const
00114 {
00115     return d->mainText.isEmpty() &&
00116            d->subText.isEmpty() &&
00117            d->image.isNull() &&
00118            (d->windowsToPreview.size() == 0);
00119 }
00120 
00121 void ToolTipContent::setMainText(const QString &text)
00122 {
00123     d->mainText = text.trimmed();
00124 }
00125 
00126 QString ToolTipContent::mainText() const
00127 {
00128     QString text = d->mainText;
00129     text.truncate(MAXIMUM_TEXT_LENGTH);
00130     return text;
00131 }
00132 
00133 void ToolTipContent::setSubText(const QString &text)
00134 {
00135     d->subText = text.trimmed();
00136 }
00137 
00138 QString ToolTipContent::subText() const
00139 {
00140     QString text = d->subText;
00141     text.truncate(MAXIMUM_TEXT_LENGTH);
00142     return text;
00143 }
00144 
00145 void ToolTipContent::setImage(const QPixmap &image)
00146 {
00147     d->image = image;
00148 }
00149 
00150 void ToolTipContent::setImage(const QIcon &icon)
00151 {
00152     d->image = icon.pixmap(IconSize(KIconLoader::Desktop));
00153 }
00154 
00155 QPixmap ToolTipContent::image() const
00156 {
00157     return d->image;
00158 }
00159 
00160 void ToolTipContent::setWindowToPreview(WId id)
00161 {
00162     d->windowsToPreview.clear();
00163     d->windowsToPreview.append(id);
00164 }
00165 
00166 WId ToolTipContent::windowToPreview() const
00167 {
00168     if (d->windowsToPreview.size() == 1) {
00169         return d->windowsToPreview.first();
00170     } else {
00171         return 0;
00172     }
00173 }
00174 
00175 void ToolTipContent::setWindowsToPreview(const QList<WId> & ids)
00176 {
00177     d->windowsToPreview = ids;
00178 }
00179 
00180 QList<WId> ToolTipContent::windowsToPreview() const
00181 {
00182     return d->windowsToPreview;
00183 }
00184 
00185 void ToolTipContent::setHighlightWindows(bool highlight)
00186 {
00187     d->highlightWindows = highlight;
00188 }
00189 
00190 bool ToolTipContent::highlightWindows() const
00191 {
00192     return d->highlightWindows;
00193 }
00194 
00195 void ToolTipContent::setAutohide(bool autohide)
00196 {
00197     d->autohide = autohide;
00198 }
00199 
00200 bool ToolTipContent::autohide() const
00201 {
00202     return d->autohide;
00203 }
00204 
00205 void ToolTipContent::setInstantPopup(bool enabled)
00206 {
00207     d->instantPopup = enabled;
00208 }
00209 
00210 bool ToolTipContent::isInstantPopup() const
00211 {
00212     return d->instantPopup;
00213 }
00214 
00215 void ToolTipContent::addResource(ResourceType type, const QUrl &path, const QVariant &resource)
00216 {
00217     d->resources.insert(path.toString(), ToolTipResource(type, resource));
00218 }
00219 
00220 void ToolTipContent::registerResources(QTextDocument *document) const
00221 {
00222     if (!document) {
00223         return;
00224     }
00225 
00226     QHashIterator<QString, ToolTipResource> it(d->resources);
00227     while (it.hasNext()) {
00228         it.next();
00229         const ToolTipResource &r = it.value();
00230         QTextDocument::ResourceType t = QTextDocument::ImageResource;
00231 
00232         switch (r.type) {
00233             case ImageResource:
00234                 break;
00235             case HtmlResource:
00236                 t = QTextDocument::HtmlResource;
00237                 break;
00238             case CssResource:
00239                 t = QTextDocument::StyleSheetResource;
00240                 break;
00241         }
00242 
00243         document->addResource(t, it.key(), r.data);
00244     }
00245 }
00246 
00247 void ToolTipContent::setClickable(bool clickable)
00248 {
00249     d->clickable = clickable;
00250 }
00251 
00252 bool ToolTipContent::isClickable() const
00253 {
00254     return d->clickable;
00255 }
00256 
00257 void ToolTipContent::setGraphicsWidget(QGraphicsWidget *widget)
00258 {
00259     d->graphicsWidget = widget;
00260 }
00261 
00262 QGraphicsWidget *ToolTipContent::graphicsWidget() const
00263 {
00264     return d->graphicsWidget.data();
00265 }
00266 
00267 } // namespace Plasma
00268 
00269 

Plasma

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.7.5
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