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.
46{
47 QTextDocument *doc = new QTextDocument(this);
48
49 QImage thumb =
index.data(Qt::DecorationRole).value<QImage>();
50 if (thumb.isNull()) {
52 }
53
55 int pixelSize = 48;
56 if (!thumb.isNull()) {
57
58 Qt::AspectRatioMode aspectRatioMode = thumb.height() == 1 ? Qt::IgnoreAspectRatio : Qt::KeepAspectRatio;
59
60
61
62 Qt::TransformationMode transformationMode = (thumb.width() < pixelSize || thumb.height() < pixelSize) ? Qt::FastTransformation : Qt::SmoothTransformation;
63
66 * devicePixelRatioF(),
67 aspectRatioMode,
68 transformationMode);
69 }
70 }
71
73 QImage image(thumb.size(), QImage::Format_ARGB32);
74
75 {
76 QPainter gc(&image);
78 gc.drawImage(QPoint(), thumb);
79 }
80
81 thumb = image;
82 }
83
84 thumb.setDevicePixelRatio(devicePixelRatioF());
85 doc->addResource(QTextDocument::ImageResource, QUrl("data:thumbnail"), thumb);
86
87 QString
name =
index.data(Qt::DisplayRole).toString();
89
90 if (!presetDisplayName.isEmpty()) {
91 name = presetDisplayName;
92 }
93
95
96 QString tagsRow;
98 if (!tagsData.isEmpty()) {
99 const QString list = QString("<ul style=\"list-style-type: none; margin: 0px;\">%1</ul> ").arg(tagsData);
100 tagsRow = QString("<tr><td>%1:</td><td style=\"text-align: right;\">%2</td></tr>").arg(i18n("Tags"), list);
101 }
102
104 const QString brokenRow =
105 !brokenReason.isEmpty()
106 ? QString("<tr><td colspan=\"2\"><b>%1</b></td></tr>"
107 "<tr><td colspan=\"2\">%2</td></tr>")
108 .arg(i18n("Resource is broken!"), brokenReason)
109 : QString();
110
112 if (location.isEmpty()) {
113 location = i18nc("a placeholder name for the default storage of resources", "resource folder");
114 }
115
116 const QString locationRow = QString("<tr><td>%1:</td><td style=\"text-align: right;\">%2</td></tr>").arg(i18n("Location"), location);
117
118 const QString footerTable = QString("<p><table>%1%2%3</table></p>").arg(brokenRow).arg(tagsRow).arg(locationRow);
119
120 const QString image = QString("<center><img src=\"data:thumbnail\"></center>");
121 QString body = QString("<h3 align=\"center\">%1</h3>%2%3").arg(name, image, footerTable);
122 if (translatedName != name) {
123 body = QString("<h3 align=\"center\">%1</h3><h4 align=\"center\">%2</h4>%3%4").arg(name, translatedName, image, footerTable);
124 }
125 const QString html = QString("<html><body>%1</body></html>").arg(body);
126
127 doc->setHtml(html);
128
129 const int margin = 16;
130 doc->setTextWidth(qMin(doc->size().width() + 2 * margin, qreal(500.0)));
131 doc->setDocumentMargin(margin);
132 doc->setUseDesignMetrics(true);
133
134 return doc;
135}
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)