void DumpThumbnail(BaseEngine *engine) { RectD rect = engine->Transform(engine->PageMediabox(1), 1, 1.0, 0); if (rect.IsEmpty()) { Out("\t<Thumbnail />\n"); return; } float zoom = min(128 / (float)rect.dx, 128 / (float)rect.dy) - 0.001f; RectI thumb = RectD(0, 0, rect.dx * zoom, rect.dy * zoom).Round(); rect = engine->Transform(thumb.Convert<double>(), 1, zoom, 0, true); RenderedBitmap *bmp = engine->RenderBitmap(1, zoom, 0, &rect); if (!bmp) { Out("\t<Thumbnail />\n"); return; } size_t len; ScopedMem<unsigned char> data(tga::SerializeBitmap(bmp->GetBitmap(), &len)); ScopedMem<char> hexData(data ? str::MemToHex(data, len) : NULL); if (hexData) Out("\t<Thumbnail>\n\t\t%s\n\t</Thumbnail>\n", hexData.Get()); else Out("\t<Thumbnail />\n"); delete bmp; }
ItemData::ItemData(const QModelIndex &index, int maxBytes, QWidget *parent) : QLabel(parent) , ItemWidget(this) { setTextInteractionFlags(Qt::TextSelectableByMouse); setContentsMargins(4, 4, 4, 4); setTextFormat(Qt::RichText); QString text; const QStringList formats = index.data(contentType::formats).toStringList(); for (int i = 0; i < formats.size(); ++i ) { QByteArray data = index.data(contentType::firstFormat + i).toByteArray(); const int size = data.size(); bool trimmed = size > maxBytes; if (trimmed) data = data.left(maxBytes); const QString &format = formats[i]; bool hasText = format.startsWith("text/") || format.startsWith("application/x-copyq-owner-window-title"); const QString content = hasText ? escapeHtml(stringFromBytes(data, format)) : hexData(data); text.append( QString("<p>") ); text.append( QString("<b>%1</b> (%2 bytes)<pre>%3</pre>") .arg(format) .arg(size) .arg(content) ); text.append( QString("</p>") ); if (trimmed) text.append( QString("<p>...</p>") ); } setText(text); }
ItemData::ItemData(const QModelIndex &index, int maxBytes, QWidget *parent) : QLabel(parent) , ItemWidget(this) { setTextInteractionFlags(Qt::TextSelectableByMouse); setContentsMargins(4, 4, 4, 4); setTextFormat(Qt::RichText); QString text; const QVariantMap data = index.data(contentType::data).toMap(); foreach ( const QString &format, data.keys() ) { QByteArray bytes = data[format].toByteArray(); const int size = bytes.size(); bool trimmed = size > maxBytes; if (trimmed) bytes = bytes.left(maxBytes); bool hasText = format.startsWith("text/") || format.startsWith("application/x-copyq-owner-window-title"); const QString content = hasText ? escapeHtml(stringFromBytes(bytes, format)) : hexData(bytes); text.append( QString("<p>") ); text.append( QString("<b>%1</b> (%2 bytes)<pre>%3</pre>") .arg(format) .arg(size) .arg(content) ); text.append( QString("</p>") ); if (trimmed) text.append( QString("<p>...</p>") ); } setText(text); }