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

SpeedDial: Fix setting background image

This commit is contained in:
David Rosca 2015-09-05 21:03:08 +02:00
parent 50b9dd9023
commit 328ab40304
4 changed files with 30 additions and 16 deletions

View File

@ -347,9 +347,10 @@ function alignPage() {
}
function bgImageSel() {
external.speedDial.getOpenFileName(function(img) {
if (img) {
document.getElementById('BgImgHold').value = img;
external.speedDial.getOpenFileName(function(arr) {
if (arr.length) {
document.getElementById('BgImgHold').value = arr[0];
document.getElementById('BgImgHoldUrl').value = arr[1];
}
});
}
@ -359,7 +360,7 @@ function saveSettings() {
DIAL_WIDTH = parseInt($('#SdSize').val());
SD_CNTR = ($('#SdCntrToggle').attr('checked') ? 1 : 0 );
external.speedDial.setBackgroundImage($('#BgImgHold').val());
external.speedDial.setBackgroundImage($('#BgImgHoldUrl').val());
external.speedDial.setBackgroundImageSize($('#BgImgSelSiz').val());
external.speedDial.setPagesInRow(MAX_PAGES_ROW);
external.speedDial.setSdSize(DIAL_WIDTH);
@ -371,13 +372,13 @@ function saveSettings() {
function bgImgToggle() {
var check = document.getElementById('BgImgToggle');
var BgImgSel = document.getElementById('BgImgSel');
var BgImgHold = document.getElementById('BgImgHold');
var BgImgHoldUrl = document.getElementById('BgImgHoldUrl');
var BgImgSz = document.getElementById('BgImgSelSiz');
BgImgSel.disabled = (check.checked ? false : true);
BgImgHold.disabled = (check.checked ? false : true);
BgImgHoldUrl.disabled = (check.checked ? false : true);
BgImgSz.disabled = (check.checked ? false : true);
BgImgHold.value = (check.checked ? "%IMG_BACKGROUND%" : '');
BgImgHoldUrl.value = (check.checked ? "%URL_BACKGROUND%" : '');
}
function sdSizeToggle() {
@ -487,6 +488,7 @@ if (window.external) {
<div class="content">
<p>
<input id="BgImgHold" type="hidden" value="%IMG_BACKGROUND%" />
<input id="BgImgHoldUrl" type="hidden" value="%URL_BACKGROUND%" />
</p>
<center><p>
<label for="BgImgSelSiz">%TXT_PLACEMENT%</label>

View File

@ -312,6 +312,7 @@ QString QupZillaSchemeReply::speeddialPage()
page.replace(QLatin1String("%INITIAL-SCRIPT%"), dial->initialScript());
page.replace(QLatin1String("%IMG_BACKGROUND%"), dial->backgroundImage());
page.replace(QLatin1String("%URL_BACKGROUND%"), dial->backgroundImageUrl());
page.replace(QLatin1String("%B_SIZE%"), dial->backgroundImageSize());
page.replace(QLatin1String("%ROW-PAGES%"), QString::number(dial->pagesInRow()));
page.replace(QLatin1String("%SD-SIZE%"), QString::number(dial->sdSize()));

View File

@ -55,7 +55,7 @@ void SpeedDial::loadSettings()
Settings settings;
settings.beginGroup("SpeedDial");
QString allPages = settings.value("pages", QString()).toString();
m_backgroundImage = settings.value("background", QString()).toString();
setBackgroundImage(settings.value("background", QString()).toString());
m_backgroundImageSize = settings.value("backsize", "auto").toString();
m_maxPagesInRow = settings.value("pagesrow", 4).toInt();
m_sizeOfSpeedDials = settings.value("sdsize", 231).toInt();
@ -89,7 +89,7 @@ void SpeedDial::saveSettings()
Settings settings;
settings.beginGroup("SpeedDial");
settings.setValue("pages", generateAllPages());
settings.setValue("background", m_backgroundImage);
settings.setValue("background", m_backgroundImageUrl);
settings.setValue("backsize", m_backgroundImageSize);
settings.setValue("pagesrow", m_maxPagesInRow);
settings.setValue("sdsize", m_sizeOfSpeedDials);
@ -184,6 +184,11 @@ QString SpeedDial::backgroundImage()
return m_backgroundImage;
}
QString SpeedDial::backgroundImageUrl()
{
return m_backgroundImageUrl;
}
QString SpeedDial::backgroundImageSize()
{
ENSURE_LOADED;
@ -276,16 +281,18 @@ void SpeedDial::removeImageForUrl(const QString &url)
}
}
QString SpeedDial::getOpenFileName()
QStringList SpeedDial::getOpenFileName()
{
const QString fileTypes = QString("%3(*.png *.jpg *.jpeg *.bmp *.gif *.svg *.tiff)").arg(tr("Image files"));
const QString image = QzTools::getOpenFileName("SpeedDial-GetOpenFileName", 0, tr("Select image..."), QDir::homePath(), fileTypes);
if (image.isEmpty()) {
return image;
}
if (image.isEmpty())
return QStringList();
return QUrl::fromLocalFile(image).toEncoded();
const QByteArray data = QzTools::pixmapToByteArray(QPixmap(image));
const QByteArray imageData = QByteArrayLiteral("data:image/png;base64,") + data;
return {imageData, QUrl::fromLocalFile(image).toEncoded()};
}
QString SpeedDial::urlFromUserInput(const QString &url)
@ -295,7 +302,9 @@ QString SpeedDial::urlFromUserInput(const QString &url)
void SpeedDial::setBackgroundImage(const QString &image)
{
m_backgroundImage = image;
const QByteArray data = QzTools::pixmapToByteArray(QPixmap(QUrl::fromEncoded(image.toUtf8()).toLocalFile()));
m_backgroundImage = QByteArrayLiteral("data:image/png;base64,") + data;
m_backgroundImageUrl = image;
}
void SpeedDial::setBackgroundImageSize(const QString &size)

View File

@ -60,6 +60,7 @@ public:
int sdCntr();
QString backgroundImage();
QString backgroundImageUrl();
QString backgroundImageSize();
QString initialScript();
@ -73,7 +74,7 @@ public slots:
void loadThumbnail(const QString &url, bool loadTitle);
void removeImageForUrl(const QString &url);
QString getOpenFileName();
QStringList getOpenFileName();
QString urlFromUserInput(const QString &url);
void setBackgroundImage(const QString &image);
void setBackgroundImageSize(const QString &size);
@ -94,6 +95,7 @@ private:
QString m_initialScript;
QString m_thumbnailsDir;
QString m_backgroundImage;
QString m_backgroundImageUrl;
QString m_backgroundImageSize;
int m_maxPagesInRow;
int m_sizeOfSpeedDials;