1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 10:46:35 +01:00

QzTools: Add pixmapToDataUrl()

This commit is contained in:
David Rosca 2015-09-25 16:04:12 +02:00
parent de46aad181
commit f4fb888529
8 changed files with 19 additions and 19 deletions

View File

@ -283,7 +283,7 @@ if (window.external) {
</head>
<body>
<div id="box">
<img class="warning" src="data:image/png;base64,%IMAGE%" >
<img class="warning" src="%IMAGE%" >
<h1>%OOPS%</h1>
<h2>%APOLOGIZE%</h2>

View File

@ -329,7 +329,7 @@ QString QupZillaSchemeReply::restorePage()
rPage.append(QzTools::readAllFileContents(":html/restore.html"));
rPage.replace(QLatin1String("%FAVICON%"), QLatin1String("qrc:icons/qupzilla.png"));
rPage.replace(QLatin1String("%BOX-BORDER%"), QLatin1String("qrc:html/box-border.png"));
rPage.replace(QLatin1String("%IMAGE%"), QzTools::pixmapToByteArray(IconProvider::standardIcon(QStyle::SP_MessageBoxWarning).pixmap(45, 45)));
rPage.replace(QLatin1String("%IMAGE%"), QzTools::pixmapToDataUrl(IconProvider::standardIcon(QStyle::SP_MessageBoxWarning).pixmap(45)).toString());
rPage.replace(QLatin1String("%TITLE%"), tr("Restore Session"));
rPage.replace(QLatin1String("%OOPS%"), tr("Oops, QupZilla crashed."));
rPage.replace(QLatin1String("%APOLOGIZE%"), tr("We apologize for this. Would you like to restore the last saved state?"));

View File

@ -218,8 +218,7 @@ QString SpeedDial::initialScript()
}
}
else {
QByteArray data = QzTools::pixmapToByteArray(QPixmap(imgSource));
imgSource = QByteArrayLiteral("data:image/png;base64,") + data;
imgSource = QzTools::pixmapToDataUrl(QPixmap(imgSource)).toString();
}
m_initialScript.append(QString("addBox('%1', '%2', '%3');\n").arg(page.url, page.title, imgSource));
@ -289,10 +288,7 @@ QStringList SpeedDial::getOpenFileName()
if (image.isEmpty())
return QStringList();
const QByteArray data = QzTools::pixmapToByteArray(QPixmap(image));
const QByteArray imageData = QByteArrayLiteral("data:image/png;base64,") + data;
return {imageData, QUrl::fromLocalFile(image).toEncoded()};
return {QzTools::pixmapToDataUrl(QPixmap(image)).toString(), QUrl::fromLocalFile(image).toEncoded()};
}
QString SpeedDial::urlFromUserInput(const QString &url)
@ -302,8 +298,7 @@ QString SpeedDial::urlFromUserInput(const QString &url)
void SpeedDial::setBackgroundImage(const QString &image)
{
const QByteArray data = QzTools::pixmapToByteArray(QPixmap(QUrl::fromEncoded(image.toUtf8()).toLocalFile()));
m_backgroundImage = QByteArrayLiteral("data:image/png;base64,") + data;
m_backgroundImage = QzTools::pixmapToDataUrl(QPixmap(QUrl(image).toLocalFile())).toString();
m_backgroundImageUrl = image;
}
@ -359,8 +354,7 @@ void SpeedDial::thumbnailCreated(const QPixmap &pixmap)
if (loadTitle)
emit pageTitleLoaded(url, title);
QByteArray data = QzTools::pixmapToByteArray(QPixmap(fileName));
emit thumbnailLoaded(url, QString(QByteArrayLiteral("data:image/png;base64,") + data));
emit thumbnailLoaded(url, QzTools::pixmapToDataUrl(QPixmap(fileName)).toString());
}
QString SpeedDial::escapeTitle(QString title) const

View File

@ -50,7 +50,7 @@ QJsonArray RecoveryJsObject::restoreData() const
Q_FOREACH (const WebTab::SavedTab &t, w.tabsState) {
QJsonObject tab;
tab[QSL("tab")] = j++;
tab[QSL("icon")] = QString(QSL("data:image/png;base64,") + QzTools::pixmapToByteArray(t.icon.pixmap(16)));
tab[QSL("icon")] = QzTools::pixmapToDataUrl(t.icon.pixmap(16)).toString();
tab[QSL("title")] = t.title;
tabs.append(tab);
}

View File

@ -78,6 +78,11 @@ QPixmap QzTools::pixmapFromByteArray(const QByteArray &data)
return image;
}
QUrl QzTools::pixmapToDataUrl(const QPixmap &pix)
{
return QUrl(QSL("data:image/png;base64,") + QString(pixmapToByteArray(pix)));
}
QString QzTools::readAllFileContents(const QString &filename)
{
return QString::fromUtf8(readAllFileByteContents(filename));

View File

@ -34,6 +34,7 @@ class QUPZILLA_EXPORT QzTools
public:
static QByteArray pixmapToByteArray(const QPixmap &pix);
static QPixmap pixmapFromByteArray(const QByteArray &data);
static QUrl pixmapToDataUrl(const QPixmap &pix);
static QString readAllFileContents(const QString &filename);
static QByteArray readAllFileByteContents(const QString &filename);

View File

@ -107,9 +107,9 @@ void AutoScrollPlugin::updateScript()
source.replace(QSL("%MOVE_SPEED%"), settings.value(QSL("Speed"), 5).toString());
source.replace(QSL("%CTRL_CLICK%"), settings.value(QSL("CtrlClick"), true).toString());
source.replace(QSL("%MIDDLE_CLICK%"), settings.value(QSL("MiddleClick"), true).toString());
source.replace(QSL("%IMG_ALL%"), QzTools::pixmapToByteArray(QPixmap(QSL(":/autoscroll/data/scroll_all.png"))));
source.replace(QSL("%IMG_HORIZONTAL%"), QzTools::pixmapToByteArray(QPixmap(QSL(":/autoscroll/data/scroll_horizontal.png"))));
source.replace(QSL("%IMG_VERTICAL%"), QzTools::pixmapToByteArray(QPixmap(QSL(":/autoscroll/data/scroll_vertical.png"))));
source.replace(QSL("%IMG_ALL%"), QzTools::pixmapToDataUrl(QPixmap(QSL(":/autoscroll/data/scroll_all.png"))).toString());
source.replace(QSL("%IMG_HORIZONTAL%"), QzTools::pixmapToDataUrl(QPixmap(QSL(":/autoscroll/data/scroll_horizontal.png"))).toString());
source.replace(QSL("%IMG_VERTICAL%"), QzTools::pixmapToDataUrl(QPixmap(QSL(":/autoscroll/data/scroll_vertical.png"))).toString());
script.setSourceCode(source);

View File

@ -60,11 +60,11 @@
function image(o) {
if (o.width && o.height) {
return "data:image/png;base64,%IMG_ALL%"
return "%IMG_ALL%"
} else if (o.width) {
return "data:image/png;base64,%IMG_HORIZONTAL%"
return "%IMG_HORIZONTAL%"
} else {
return "data:image/png;base64,%IMG_VERTICAL%"
return "%IMG_VERTICAL%"
}
}