tUpdate the cover page - sailfish-safe - Sailfish frontend for safe(1)
 (HTM) git clone git://git.z3bra.org/sailfish-safe.git
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 1193e8ca390e4f236b9915c33baa6aabb2e313ee
 (DIR) parent 28c9776bda3ca635a02edcb38fb84ff2a10a2594
 (HTM) Author: Daniel Vrátil <dvratil@kde.org>
       Date:   Sun,  3 Feb 2019 18:15:51 +0100
       
       Update the cover page
       
       Diffstat:
         M harbour-passilic.pro                |       6 ++++--
         M qml/cover/CoverPage.qml             |      19 +++++--------------
         A qml/images/cover.png                |       0 
         A src/imageprovider.cpp               |      80 +++++++++++++++++++++++++++++++
         A src/imageprovider.h                 |      38 +++++++++++++++++++++++++++++++
         M src/main.cpp                        |      10 +++++++++-
       
       6 files changed, 136 insertions(+), 17 deletions(-)
       ---
 (DIR) diff --git a/harbour-passilic.pro b/harbour-passilic.pro
       t@@ -7,6 +7,7 @@ INCLUDEPATH += 3rdparty/kitemmodels/
        SOURCES += \
            src/main.cpp \
            src/abbreviations.cpp \
       +    src/imageprovider.cpp \
            src/passwordfiltermodel.cpp \
            src/passwordprovider.cpp \
            src/passwordsmodel.cpp \
       t@@ -16,6 +17,7 @@ SOURCES += \
        
        HEADERS += \
            src/abbreviations.h \
       +    src/imageprovider.h \
            src/passwordfiltermodel.h \
            src/passwordprovider.h \
            src/passwordsmodel.h \
       t@@ -26,13 +28,13 @@ DISTFILES += \
            qml/harbour-passilic.qml \
            qml/cover/CoverPage.qml \
            qml/pages/PasswordListPage.qml \
       +    qml/pages/PassphraseRequester.qml \
            rpm/harbour-passilic.changes.in \
            rpm/harbour-passilic.changes.run.in \
            rpm/harbour-passilic.spec \
            rpm/harbour-passilic.yaml \
            translations/*.ts \
       -    harbour-passilic.desktop \
       -    qml/pages/PassphraseRequester.qml
       +    harbour-passilic.desktop
        
        SAILFISHAPP_ICONS = 86x86 108x108 128x128 172x172
        
 (DIR) diff --git a/qml/cover/CoverPage.qml b/qml/cover/CoverPage.qml
       t@@ -2,21 +2,12 @@ import QtQuick 2.0
        import Sailfish.Silica 1.0
        
        CoverBackground {
       -    Label {
       -        id: label
       -        anchors.centerIn: parent
       -        text: qsTr("My Cover")
       -    }
        
       -    CoverActionList {
       -        id: coverAction
       -
       -        CoverAction {
       -            iconSource: "image://theme/icon-cover-next"
       -        }
       +    Image {
       +        source: "image://passImage/cover.png?" + Theme.primaryColor
       +        anchors.centerIn: parent
        
       -        CoverAction {
       -            iconSource: "image://theme/icon-cover-pause"
       -        }
       +        width: parent.width - 2 * Theme.paddingLarge
       +        height: sourceSize.height * width / sourceSize.width
            }
        }
 (DIR) diff --git a/qml/images/cover.png b/qml/images/cover.png
       Binary files differ.
 (DIR) diff --git a/src/imageprovider.cpp b/src/imageprovider.cpp
       t@@ -0,0 +1,80 @@
       +/*
       + *   Copyright (C) 2019  Daniel Vrátil <dvratil@kde.org>
       + *
       + *   This program is free software; you can redistribute it and/or modify
       + *   it under the terms of the GNU Library General Public License as
       + *   published by the Free Software Foundation; either version 2, or
       + *   (at your option) any later version.
       + *
       + *   This program is distributed in the hope that it will be useful,
       + *   but WITHOUT ANY WARRANTY; without even the implied warranty of
       + *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       + *   GNU General Public License for more details
       + *
       + *   You should have received a copy of the GNU Library General Public
       + *   License along with this program; if not, write to the
       + *   Free Software Foundation, Inc.,
       + *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
       + */
       +
       +#include "imageprovider.h"
       +
       +#include <QPainter>
       +#include <QColor>
       +#include <QMap>
       +
       +#include <sailfishapp.h>
       +
       +namespace {
       +
       +static const auto schemaMap = QMap<QString, QString>{
       +    {{QStringLiteral("passIcon"), QStringLiteral("icons")},
       +     {QStringLiteral("passImage"), QStringLiteral("images")}}
       +};
       +
       +static QString pathForSchema(const QString &schema)
       +{
       +    return schemaMap.value(schema);
       +}
       +
       +}
       +
       +ImageProvider::ImageProvider(const QString &schema)
       +    : QQuickImageProvider(QQuickImageProvider::Pixmap)
       +    , mSchema(schema)
       +{
       +    Q_ASSERT(schemaMap.contains(schema));
       +}
       +
       +// Based on https://together.jolla.com/question/44325/iconbutton-how-to-use-own-icons-with-highlight/
       +QPixmap ImageProvider::requestPixmap(const QString &id, QSize *size, const QSize &requestedSize)
       +{
       +    const auto parts = id.splitRef(QLatin1Char('?'));
       +
       +    auto source = findSource(parts.at(0));
       +    if (size) {
       +        *size = source.size();
       +    }
       +
       +    if (parts.size() > 1) {
       +        const auto color = parts.at(1).toString();
       +        if (QColor::isValidColor(color)) {
       +            QPainter painter(&source);
       +            painter.setCompositionMode(QPainter::CompositionMode_SourceIn);
       +            painter.fillRect(source.rect(), color);
       +            painter.end();
       +        }
       +    }
       +
       +    if (requestedSize.width() > 0 && requestedSize.height() > 0) {
       +        return source.scaled(requestedSize, Qt::IgnoreAspectRatio);
       +    } else {
       +        return source;
       +    }
       +}
       +
       +QPixmap ImageProvider::findSource(const QStringRef &name)
       +{
       +    const QString imgPath = QStringLiteral("qml/") % pathForSchema(mSchema) % QStringLiteral("/") % name;
       +    return QPixmap(SailfishApp::pathTo(imgPath).toString(QUrl::RemoveScheme));
       +}
 (DIR) diff --git a/src/imageprovider.h b/src/imageprovider.h
       t@@ -0,0 +1,38 @@
       +/*
       + *   Copyright (C) 2019  Daniel Vrátil <dvratil@kde.org>
       + *
       + *   This program is free software; you can redistribute it and/or modify
       + *   it under the terms of the GNU Library General Public License as
       + *   published by the Free Software Foundation; either version 2, or
       + *   (at your option) any later version.
       + *
       + *   This program is distributed in the hope that it will be useful,
       + *   but WITHOUT ANY WARRANTY; without even the implied warranty of
       + *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       + *   GNU General Public License for more details
       + *
       + *   You should have received a copy of the GNU Library General Public
       + *   License along with this program; if not, write to the
       + *   Free Software Foundation, Inc.,
       + *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
       + */
       +
       +#ifndef IMAGEPROVIDER_H
       +#define IMAGEROVIDER_H
       +
       +#include <QQuickImageProvider>
       +
       +class ImageProvider : public QQuickImageProvider
       +{
       +public:
       +    explicit ImageProvider(const QString &schema);
       +
       +    QPixmap requestPixmap(const QString &id, QSize *size, const QSize &requestedSize) override;
       +
       +private:
       +    QPixmap findSource(const QStringRef &name);
       +
       +    QString mSchema;
       +};
       +
       +#endif // IMAGEPROVIDER
 (DIR) diff --git a/src/main.cpp b/src/main.cpp
       t@@ -1,5 +1,5 @@
        /*
       - *   Copyright (C) 2018  Daniel Vrátil <dvratil@kde.org>
       + *   Copyright (C) 2019  Daniel Vrátil <dvratil@kde.org>
         *
         *   This program is free software; you can redistribute it and/or modify
         *   it under the terms of the GNU Library General Public License as
       t@@ -20,6 +20,7 @@
        #include "passwordsmodel.h"
        #include "passwordfiltermodel.h"
        #include "passwordsortproxymodel.h"
       +#include "imageprovider.h"
        
        #ifdef QT_QML_DEBUG
        #include <QtQuick>
       t@@ -28,6 +29,11 @@
        
        #include <sailfishapp.h>
        
       +void addImageProvider(QQmlEngine *engine, const QString &id)
       +{
       +    engine->addImageProvider(id, new ImageProvider(id));
       +}
       +
        int main(int argc, char *argv[])
        {
            QScopedPointer<QGuiApplication> app(SailfishApp::application(argc, argv));
       t@@ -37,6 +43,8 @@ int main(int argc, char *argv[])
            qmlRegisterType<PasswordFilterModel>("harbour.passilic", 1, 0, "PasswordFilterModel");
            qmlRegisterType<PasswordSortProxyModel>("harbour.passilic", 1, 0, "PasswordSortProxyModel");
        
       +    addImageProvider(view->engine(), QStringLiteral("passIcon"));
       +    addImageProvider(view->engine(), QStringLiteral("passImage"));
            view->setSource(SailfishApp::pathToMainQml());
            view->show();