Re-implement this to provide the actual tooltip contents. For instance:
QTextDocument *doc = new QTextDocument(this);
doc->addResource(QTextDocument::ImageResource, QUrl("data:thumbnail"), thumb);
QString name =
index.data(Qt::DisplayRole).toString();
const QString image = QString("<img src=\"data:thumbnail\">");
const QString body = QString("<h3 align=\"center\">%1</h3>").arg(name) + image;
const QString html = QString("<html><body>%1</body></html>").arg(body);
doc->setHtml(html);
doc->setTextWidth(qMin(doc->size().width(), 500.0));
return doc;
@ LargeThumbnail
A larger thumbnail for displaying in a tooltip. 200x200 or so.
45{
46 QTextDocument *doc = new QTextDocument(this);
47
48 QImage thumb =
index.data(Qt::DecorationRole).value<QImage>();
49 if (thumb.isNull()) {
51 }
52
54 int pixelSize = 48;
55 if (!thumb.isNull()) {
56
57 Qt::AspectRatioMode aspectRatioMode = thumb.height() == 1 ? Qt::IgnoreAspectRatio : Qt::KeepAspectRatio;
58
59
60
61 Qt::TransformationMode transformationMode = (thumb.width() < pixelSize || thumb.height() < pixelSize) ? Qt::FastTransformation : Qt::SmoothTransformation;
62
65 * devicePixelRatioF(),
66 aspectRatioMode,
67 transformationMode);
68 }
69 }
70
72 QImage image(thumb.size(), QImage::Format_ARGB32);
73
74 {
75 QPainter gc(&image);
77 gc.drawImage(QPoint(), thumb);
78 }
79
80 thumb = image;
81 }
82
83 thumb.setDevicePixelRatio(devicePixelRatioF());
84 doc->addResource(QTextDocument::ImageResource, QUrl("data:thumbnail"), thumb);
85
86 QString
name =
index.data(Qt::DisplayRole).toString();
88
89 if (!presetDisplayName.isEmpty()) {
90 name = presetDisplayName;
91 }
92
94
95 QString tagsRow;
97 if (!tagsData.isEmpty()) {
98 const QString list = QString("<ul style=\"list-style-type: none; margin: 0px;\">%1</ul> ").arg(tagsData);
99 tagsRow = QString("<tr><td>%1:</td><td style=\"text-align: right;\">%2</td></tr>").arg(i18n("Tags"), list);
100 }
101
103 const QString brokenRow =
104 !brokenReason.isEmpty()
105 ? QString("<tr><td colspan=\"2\"><b>%1</b></td></tr>"
106 "<tr><td colspan=\"2\">%2</td></tr>")
107 .arg(i18n("Resource is broken!"), brokenReason)
108 : QString();
109
111 if (location.isEmpty()) {
112 location = i18nc("a placeholder name for the default storage of resources", "resource folder");
113 }
114
115 const QString locationRow = QString("<tr><td>%1:</td><td style=\"text-align: right;\">%2</td></tr>").arg(i18n("Location"), location);
116
117 const QString footerTable = QString("<p><table>%1%2%3</table></p>").arg(brokenRow).arg(tagsRow).arg(locationRow);
118
119 const QString image = QString("<center><img src=\"data:thumbnail\"></center>");
120 QString body = QString("<h3 align=\"center\">%1</h3>%2%3").arg(name, image, footerTable);
121 if (translatedName != name) {
122 body = QString("<h3 align=\"center\">%1</h3><h4 align=\"center\">%2</h4>%3%4").arg(name, translatedName, image, footerTable);
123 }
124 const QString html = QString("<html><body>%1</body></html>").arg(body);
125
126 doc->setHtml(html);
127
128 const int margin = 16;
129 doc->setTextWidth(qMin(doc->size().width() + 2 * margin, qreal(500.0)));
130 doc->setDocumentMargin(margin);
131 doc->setUseDesignMetrics(true);
132
133 return doc;
134}
static KisResourceThumbnailCache * instance()
QImage getImage(const QModelIndex &index, const QSize size=QSize(-1, -1), Qt::AspectRatioMode aspectMode=Qt::IgnoreAspectRatio, Qt::TransformationMode transformMode=Qt::FastTransformation)
const char * name(StandardAction id)