From: David Llewellyn-Jones Date: Sun, 15 Jul 2018 16:31:15 +0000 (+0100) Subject: Add icons and images dependent on device resolution X-Git-Url: https://www.flypig.org.uk/git/?p=harbour-pedalo.git;a=commitdiff_plain;h=7d6ca1150d70c17469e48d71920dfe6083e1a719 Add icons and images dependent on device resolution --- diff --git a/generate.sh b/generate.sh new file mode 100755 index 0000000..170bbf4 --- /dev/null +++ b/generate.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +# Generate graphics at different resolutions for different devices +# 1.0 (jolla phone), 1.25 (jolla c), 1.5 (tablet), 1.75 (xperia) +ratios="1.0 1.25 1.5 1.75 2.0" + +# Generate app icons +sizes="86 108 128 172 256" +for size in ${sizes}; do + mkdir -p "./icons/${size}x${size}" + inkscape -z -e "./icons/${size}x${size}/harbour-pedalo.png" -w $size -h $size "inputs/harbour-pedalo.svg" +done + +# Create the ratio directories +for ratio in ${ratios}; do + mkdir -p "./qml/images/z${ratio}" +done + +# Function for generating PNG images +function generate { + basex=$1 + basey=$2 + names=$3 + for ratio in ${ratios}; do + sizex=`echo "${ratio} * ${basex}" | bc` + sizey=`echo "${ratio} * ${basey}" | bc` + for name in ${names}; do + inkscape -z -e "./qml/images/z${ratio}/${name}.png" -w ${sizex} -h ${sizey} "inputs/${name}.svg" + done + done +} + +# Generate titles +generate 303 86 "pedalo-title" + diff --git a/harbour-pedalo.pro b/harbour-pedalo.pro index e50d930..9033b75 100644 --- a/harbour-pedalo.pro +++ b/harbour-pedalo.pro @@ -25,12 +25,14 @@ DEFINES += "VERSION_MAJOR=$$VERSION_MAJOR" \ "VERSION=\\\"$$VERSION\\\"" CONFIG += sailfishapp - +PKGCONFIG += mlite5 +B SOURCES += src/harbour-pedalo.cpp \ src/journey.cpp \ src/journeymodel.cpp \ src/status.cpp \ - src/settings.cpp + src/settings.cpp \ + src/imageprovider.cpp DISTFILES += qml/harbour-pedalo.qml \ qml/cover/CoverPage.qml \ @@ -66,4 +68,5 @@ HEADERS += \ src/journeymodel.h \ src/status.h \ src/settings.h \ - src/harbour-pedalo.h + src/harbour-pedalo.h \ + src/imageprovider.h diff --git a/icons/108x108/harbour-pedalo.png b/icons/108x108/harbour-pedalo.png index ab10628..079936c 100644 Binary files a/icons/108x108/harbour-pedalo.png and b/icons/108x108/harbour-pedalo.png differ diff --git a/icons/128x128/harbour-pedalo.png b/icons/128x128/harbour-pedalo.png index 54375c5..f3f691a 100644 Binary files a/icons/128x128/harbour-pedalo.png and b/icons/128x128/harbour-pedalo.png differ diff --git a/icons/172x172/harbour-pedalo.png b/icons/172x172/harbour-pedalo.png index 36eee58..bb2136e 100644 Binary files a/icons/172x172/harbour-pedalo.png and b/icons/172x172/harbour-pedalo.png differ diff --git a/icons/256x256/harbour-pedalo.png b/icons/256x256/harbour-pedalo.png new file mode 100644 index 0000000..0671eb9 Binary files /dev/null and b/icons/256x256/harbour-pedalo.png differ diff --git a/icons/86x86/harbour-pedalo.png b/icons/86x86/harbour-pedalo.png index ad316d6..a893845 100644 Binary files a/icons/86x86/harbour-pedalo.png and b/icons/86x86/harbour-pedalo.png differ diff --git a/inputs/harbour-pedalo.svg b/inputs/harbour-pedalo.svg new file mode 100644 index 0000000..9473e77 --- /dev/null +++ b/inputs/harbour-pedalo.svg @@ -0,0 +1,134 @@ + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + diff --git a/inputs/pedalo-title.svg b/inputs/pedalo-title.svg new file mode 100644 index 0000000..0a08a3f --- /dev/null +++ b/inputs/pedalo-title.svg @@ -0,0 +1,210 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + diff --git a/qml/pages/About.qml b/qml/pages/About.qml index df656ee..f732dd2 100644 --- a/qml/pages/About.qml +++ b/qml/pages/About.qml @@ -30,7 +30,7 @@ Page { Image { anchors.topMargin: Theme.paddingLarge anchors.horizontalCenter: parent.horizontalCenter - source : Qt.resolvedUrl("image://theme/icon-m-cloud-download") + source : Qt.resolvedUrl("image://pedalo/pedalo-title") } Label { diff --git a/src/harbour-pedalo.cpp b/src/harbour-pedalo.cpp index a4218cd..216240d 100644 --- a/src/harbour-pedalo.cpp +++ b/src/harbour-pedalo.cpp @@ -9,6 +9,7 @@ #include "journeymodel.h" #include "status.h" #include "settings.h" +#include "imageprovider.h" #include "harbour-pedalo.h" @@ -44,6 +45,7 @@ int main(int argc, char *argv[]) journeys.importFromFile(file); QScopedPointer view(SailfishApp::createView()); + view->engine()->addImageProvider(QLatin1String("pedalo"), new ImageProvider(Settings::getInstance())); view->setSource(SailfishApp::pathTo("qml/harbour-pedalo.qml")); QQmlContext *ctxt = view->rootContext(); diff --git a/src/imageprovider.cpp b/src/imageprovider.cpp new file mode 100644 index 0000000..431fd23 --- /dev/null +++ b/src/imageprovider.cpp @@ -0,0 +1,38 @@ +#include +#include +#include +#include +#include +#include "settings.h" + +#include "imageprovider.h" + +ImageProvider::ImageProvider(Settings const & settings) : QQuickImageProvider(QQuickImageProvider::Pixmap) { + imageDir = settings.getImageDir(); +} + +QPixmap ImageProvider::requestPixmap(const QString &id, QSize *size, const QSize &requestedSize) { + QPixmap image; + QStringList parts = id.split('?'); + QPixmap sourcePixmap(imageDir + parts.at(0) + ".png"); + + if (size) { + *size = sourcePixmap.size(); + } + if (parts.length() > 1) { + if (QColor::isValidColor(parts.at(1))) { + QPainter painter(&sourcePixmap); + painter.setCompositionMode(QPainter::CompositionMode_SourceIn); + painter.fillRect(sourcePixmap.rect(), parts.at(1)); + painter.end(); + } + } + if (requestedSize.width() > 0 && requestedSize.height() > 0) { + image = sourcePixmap.scaled(requestedSize.width(), requestedSize.height(), Qt::IgnoreAspectRatio); + } + else { + image = sourcePixmap; + } + + return image; +} diff --git a/src/imageprovider.h b/src/imageprovider.h new file mode 100644 index 0000000..bc62fbf --- /dev/null +++ b/src/imageprovider.h @@ -0,0 +1,17 @@ +#ifndef IMAGEPROVIDER_H +#define IMAGEPROVIDER_H + +#include +#include +#include "settings.h" + +class ImageProvider : public QQuickImageProvider { +public: + explicit ImageProvider(Settings const & settings); + + QPixmap requestPixmap(const QString &id, QSize *size, const QSize &requestedSize); +private: + QString imageDir; +}; + +#endif // IMAGEPROVIDER_H diff --git a/src/settings.cpp b/src/settings.cpp index 0998d37..b1755a7 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -1,6 +1,8 @@ #include #include #include +#include +#include #include "settings.h" @@ -10,6 +12,27 @@ Settings::Settings(QObject *parent) : QObject(parent), settings(this), mainStatus(nullptr) { + QScopedPointer ratioItem(new MGConfItem("/desktop/sailfish/silica/theme_pixel_ratio")); + pixelRatio = ratioItem->value(1.0).toDouble(); + QString dir; + if (pixelRatio > 1.75) { + dir = "2.0"; + } + else if (pixelRatio > 1.5) { + dir = "1.75"; + } + else if (pixelRatio > 1.25) { + dir = "1.5"; + } + else if (pixelRatio > 1.0) { + dir = "1.25"; + } + else { + dir = "1.0"; + } + + imageDir = SailfishApp::pathTo("qml/images/z" + dir).toString(QUrl::RemoveScheme) + "/"; + qDebug() << "Image folder: " << imageDir; } Settings::~Settings() { @@ -36,6 +59,13 @@ QString Settings::getConfigDir() { return QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation); } +QString Settings::getImageDir() const { + return imageDir; +} +QString Settings::getImageUrl(const QString &id) const { + return imageDir + id + ".png"; +} + void Settings::setMainStatus(Status &value) { mainStatus = &value; } diff --git a/src/settings.h b/src/settings.h index 2390d89..5dc4fa9 100644 --- a/src/settings.h +++ b/src/settings.h @@ -19,6 +19,8 @@ public: static QObject * provider(QQmlEngine *engine, QJSEngine *scriptEngine); Q_INVOKABLE static QString getConfigDir(); + Q_INVOKABLE QString getImageDir() const; + Q_INVOKABLE QString getImageUrl(const QString &id) const; void loadSettings(); void saveSettings(); @@ -31,6 +33,8 @@ public slots: private: static Settings * instance; QSettings settings; + double pixelRatio; + QString imageDir; // Configurable values Status * mainStatus;