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

Plasma

  • sources
  • kde-4.12
  • kdelibs
  • plasma
tooltipcontent.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2008 by Aaron Seigo <aseigo@kde.org>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor,
17  * Boston, MA 02110-1301 USA
18  */
19 
20 #include "tooltipcontent.h"
21 
22 #include <QGraphicsWidget>
23 #include <QHash>
24 #include <QTextDocument>
25 
26 #include <kiconloader.h>
27 
28 namespace Plasma
29 {
30 
31 struct ToolTipResource
32 {
33  ToolTipResource()
34  {
35  }
36 
37  ToolTipResource(ToolTipContent::ResourceType t, const QVariant &v)
38  : type(t),
39  data(v)
40  {
41  }
42 
43  ToolTipContent::ResourceType type;
44  QVariant data;
45 };
46 
47 const int MAXIMUM_TEXT_LENGTH = 5000;
48 
49 class ToolTipContentPrivate
50 {
51 public:
52  ToolTipContentPrivate()
53  : autohide(true),
54  instantPopup(false),
55  clickable(false),
56  highlightWindows(false)
57  {
58  }
59 
60  QString mainText;
61  QString subText;
62  QPixmap image;
63  QList<WId> windowsToPreview;
64  QHash<QString, ToolTipResource> resources;
65  QWeakPointer<QGraphicsWidget> graphicsWidget;
66  bool autohide : 1;
67  bool instantPopup : 1;
68  bool clickable : 1;
69  bool highlightWindows : 1;
70 };
71 
72 ToolTipContent::ToolTipContent()
73  : d(new ToolTipContentPrivate)
74 {
75 }
76 
77 ToolTipContent::ToolTipContent(const ToolTipContent &other)
78  : d(new ToolTipContentPrivate(*other.d))
79 {
80 }
81 
82 ToolTipContent::~ToolTipContent()
83 {
84  delete d;
85 }
86 
87 ToolTipContent &ToolTipContent::operator=(const ToolTipContent &other)
88 {
89  *d = *other.d;
90  return *this;
91 }
92 
93 ToolTipContent::ToolTipContent(const QString &mainText,
94  const QString &subText,
95  const QPixmap &image)
96  : d(new ToolTipContentPrivate)
97 {
98  setMainText(mainText);
99  setSubText(subText);
100  setImage(image);
101 }
102 
103 ToolTipContent::ToolTipContent(const QString &mainText,
104  const QString &subText,
105  const QIcon &icon)
106  : d(new ToolTipContentPrivate)
107 {
108  setMainText(mainText);
109  setSubText(subText);
110  setImage(icon);
111 }
112 
113 bool ToolTipContent::isEmpty() const
114 {
115  return d->mainText.isEmpty() &&
116  d->subText.isEmpty() &&
117  d->image.isNull() &&
118  (d->windowsToPreview.size() == 0);
119 }
120 
121 void ToolTipContent::setMainText(const QString &text)
122 {
123  d->mainText = text.trimmed();
124 }
125 
126 QString ToolTipContent::mainText() const
127 {
128  QString text = d->mainText;
129  text.truncate(MAXIMUM_TEXT_LENGTH);
130  return text;
131 }
132 
133 void ToolTipContent::setSubText(const QString &text)
134 {
135  d->subText = text.trimmed();
136 }
137 
138 QString ToolTipContent::subText() const
139 {
140  QString text = d->subText;
141  text.truncate(MAXIMUM_TEXT_LENGTH);
142  return text;
143 }
144 
145 void ToolTipContent::setImage(const QPixmap &image)
146 {
147  d->image = image;
148 }
149 
150 void ToolTipContent::setImage(const QIcon &icon)
151 {
152  d->image = icon.pixmap(IconSize(KIconLoader::Desktop));
153 }
154 
155 QPixmap ToolTipContent::image() const
156 {
157  return d->image;
158 }
159 
160 void ToolTipContent::setWindowToPreview(WId id)
161 {
162  d->windowsToPreview.clear();
163  d->windowsToPreview.append(id);
164 }
165 
166 WId ToolTipContent::windowToPreview() const
167 {
168  if (d->windowsToPreview.size() == 1) {
169  return d->windowsToPreview.first();
170  } else {
171  return 0;
172  }
173 }
174 
175 void ToolTipContent::setWindowsToPreview(const QList<WId> & ids)
176 {
177  d->windowsToPreview = ids;
178 }
179 
180 QList<WId> ToolTipContent::windowsToPreview() const
181 {
182  return d->windowsToPreview;
183 }
184 
185 void ToolTipContent::setHighlightWindows(bool highlight)
186 {
187  d->highlightWindows = highlight;
188 }
189 
190 bool ToolTipContent::highlightWindows() const
191 {
192  return d->highlightWindows;
193 }
194 
195 void ToolTipContent::setAutohide(bool autohide)
196 {
197  d->autohide = autohide;
198 }
199 
200 bool ToolTipContent::autohide() const
201 {
202  return d->autohide;
203 }
204 
205 void ToolTipContent::setInstantPopup(bool enabled)
206 {
207  d->instantPopup = enabled;
208 }
209 
210 bool ToolTipContent::isInstantPopup() const
211 {
212  return d->instantPopup;
213 }
214 
215 void ToolTipContent::addResource(ResourceType type, const QUrl &path, const QVariant &resource)
216 {
217  d->resources.insert(path.toString(), ToolTipResource(type, resource));
218 }
219 
220 void ToolTipContent::registerResources(QTextDocument *document) const
221 {
222  if (!document) {
223  return;
224  }
225 
226  QHashIterator<QString, ToolTipResource> it(d->resources);
227  while (it.hasNext()) {
228  it.next();
229  const ToolTipResource &r = it.value();
230  QTextDocument::ResourceType t = QTextDocument::ImageResource;
231 
232  switch (r.type) {
233  case ImageResource:
234  break;
235  case HtmlResource:
236  t = QTextDocument::HtmlResource;
237  break;
238  case CssResource:
239  t = QTextDocument::StyleSheetResource;
240  break;
241  }
242 
243  document->addResource(t, it.key(), r.data);
244  }
245 }
246 
247 void ToolTipContent::setClickable(bool clickable)
248 {
249  d->clickable = clickable;
250 }
251 
252 bool ToolTipContent::isClickable() const
253 {
254  return d->clickable;
255 }
256 
257 void ToolTipContent::setGraphicsWidget(QGraphicsWidget *widget)
258 {
259  d->graphicsWidget = widget;
260 }
261 
262 QGraphicsWidget *ToolTipContent::graphicsWidget() const
263 {
264  return d->graphicsWidget.data();
265 }
266 
267 } // namespace Plasma
268 
269 
Plasma::ToolTipContent::setInstantPopup
void setInstantPopup(bool enabled)
Sets whether or not the tooltip should popup instantly when the widget is hovered, defaults to false.
Definition: tooltipcontent.cpp:205
Plasma::ToolTipContent::HtmlResource
Definition: tooltipcontent.h:50
Plasma::ToolTipContent::isEmpty
bool isEmpty() const
Definition: tooltipcontent.cpp:113
Plasma::WindowEffects::highlightWindows
void highlightWindows(WId controller, const QList< WId > &ids)
Highlight the selected windows, making all the others translucent.
Definition: windoweffects.cpp:262
Plasma::ToolTipContent::ResourceType
ResourceType
Definition: tooltipcontent.h:50
Plasma::ToolTipContent::setAutohide
void setAutohide(bool autohide)
Sets whether or not to autohide the tooltip, defaults to true.
Definition: tooltipcontent.cpp:195
Plasma::ToolTipContent::setImage
void setImage(const QPixmap &image)
Sets the icon to show.
Definition: tooltipcontent.cpp:145
Plasma::ToolTipContent::ImageResource
Definition: tooltipcontent.h:50
Plasma::Desktop
On the planar desktop layer, extending across the full screen from edge to edge.
Definition: plasma.h:111
Plasma::ToolTipContent::setWindowToPreview
void setWindowToPreview(WId id)
Sets the ID of the window to show a preview for.
Definition: tooltipcontent.cpp:160
Plasma::ToolTipContent::setGraphicsWidget
void setGraphicsWidget(QGraphicsWidget *widget)
Sets an optional graphicsWidget that will be used for positioning the tooltip.
Definition: tooltipcontent.cpp:257
Plasma::ToolTipContent::addResource
void addResource(ResourceType type, const QUrl &path, const QVariant &resource)
Adds a resource that can then be referenced from the text elements using rich text.
Definition: tooltipcontent.cpp:215
Plasma::ToolTipContent::isClickable
bool isClickable() const
Definition: tooltipcontent.cpp:252
Plasma::ToolTipContent
Definition: tooltipcontent.h:47
Plasma::ToolTipContent::CssResource
Definition: tooltipcontent.h:50
Plasma::ToolTipContent::graphicsWidget
QGraphicsWidget * graphicsWidget() const
the graphicsWidget used for positioning the tooltip, if any
Definition: tooltipcontent.cpp:262
Plasma::ToolTipContent::setClickable
void setClickable(bool clickable)
Sets whether or not the tooltip contains clickable content, such as window previews.
Definition: tooltipcontent.cpp:247
Plasma::ToolTipContent::mainText
QString mainText() const
Important information, e.g.
Definition: tooltipcontent.cpp:126
Plasma::ToolTipContent::~ToolTipContent
~ToolTipContent()
Definition: tooltipcontent.cpp:82
Plasma::ToolTipContent::setHighlightWindows
void setHighlightWindows(bool highlight)
sets if when the mouse will be over a thumbnail the corresponding window will be highlighted by reduc...
Definition: tooltipcontent.cpp:185
Plasma::ToolTipContent::windowToPreview
WId windowToPreview() const
Id of a window if you want to show a preview.
Definition: tooltipcontent.cpp:166
Plasma::ToolTipContent::setWindowsToPreview
void setWindowsToPreview(const QList< WId > &ids)
Sets the IDS of the windows to show a preview for.
Definition: tooltipcontent.cpp:175
tooltipcontent.h
Plasma::ToolTipContent::isInstantPopup
bool isInstantPopup() const
Whether or not the tooltip should popup instantly when the widget is hovered, defaults to false...
Definition: tooltipcontent.cpp:210
Plasma::ToolTipContent::image
QPixmap image() const
An icon to display.
Definition: tooltipcontent.cpp:155
Plasma::type
static QScriptValue type(QScriptContext *ctx, QScriptEngine *eng)
Definition: easingcurve.cpp:63
Plasma::ToolTipContent::ToolTipContent
ToolTipContent()
Creates an empty Content.
Definition: tooltipcontent.cpp:72
Plasma::ToolTipContent::windowsToPreview
QList< WId > windowsToPreview() const
Ids of a windows if you want to show a preview.
Definition: tooltipcontent.cpp:180
Plasma::ToolTipContent::setMainText
void setMainText(const QString &text)
Sets the main text which containts important information, e.g.
Definition: tooltipcontent.cpp:121
Plasma::ToolTipContent::setSubText
void setSubText(const QString &text)
Sets text which elaborates on the mainText.
Definition: tooltipcontent.cpp:133
Plasma::ToolTipContent::subText
QString subText() const
Elaborates on the mainText.
Definition: tooltipcontent.cpp:138
Plasma::ToolTipContent::autohide
bool autohide() const
Whether or not to autohide the tooltip, defaults to true.
Definition: tooltipcontent.cpp:200
Plasma::ToolTipContent::highlightWindows
bool highlightWindows() const
true if when the mouse will be over a thumbnail the corresponding window will be highlighted by reduc...
Definition: tooltipcontent.cpp:190
Plasma::ToolTipContent::registerResources
void registerResources(QTextDocument *document) const
Registers all resources with a given document.
Definition: tooltipcontent.cpp:220
Plasma::ToolTipContent::operator=
ToolTipContent & operator=(const ToolTipContent &other)
Definition: tooltipcontent.cpp:87
QGraphicsWidget
Plasma::MAXIMUM_TEXT_LENGTH
const int MAXIMUM_TEXT_LENGTH
Definition: tooltipcontent.cpp:47
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:48:34 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

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 API Reference

Skip menu "kdelibs API Reference"
  • 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
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal