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:
parent
de46aad181
commit
f4fb888529
@ -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>
|
||||
|
||||
|
@ -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?"));
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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));
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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%"
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user