Commit fe8bdbef authored by Martin Straka's avatar Martin Straka

Display service SVG logo in QML

parent 8adba6b0
......@@ -131,6 +131,7 @@ SOURCES += \
src/net/net_layer.cpp \
src/net/xml_layer.cpp \
src/qml_interaction/attachment_data.cpp \
src/qml_interaction/image_provider.cpp \
src/qml_interaction/interaction_filesystem.cpp \
src/qml_interaction/interaction_zfo_file.cpp \
src/qml_interaction/message_envelope.cpp \
......@@ -214,6 +215,7 @@ HEADERS += \
src/net/net_layer.h \
src/net/xml_layer.h \
src/qml_interaction/attachment_data.h \
src/qml_interaction/image_provider.h \
src/qml_interaction/interaction_filesystem.h \
src/qml_interaction/interaction_zfo_file.h \
src/qml_interaction/message_envelope.h \
......
......@@ -231,6 +231,7 @@ Item {
width: imgHeightHeader
height: imgHeightHeader
source: "qrc:/ui/briefcase.svg"
cache: false
accessibleName: qsTr("Records management logo")
}
} // Grid
......@@ -267,6 +268,7 @@ Item {
tokenName.text = srToken
updateRmDataButton.visible = serviceInfo.visible
serviceInfoError.visible = false
serviceLogo.source = "image://images/rmlogo.svg"
} else {
serviceInfo.visible = false
updateRmDataButton.visible = serviceInfo.visible
......
......@@ -51,6 +51,7 @@
#include "src/os_android.h"
#endif /* defined(Q_OS_ANDROID) */
#include "src/qml_interaction/attachment_data.h"
#include "src/qml_interaction/image_provider.h"
#include "src/qml_interaction/interaction_filesystem.h"
#include "src/qml_interaction/interaction_zfo_file.h"
#include "src/qml_interaction/message_envelope.h"
......@@ -317,6 +318,7 @@ int main(int argc, char *argv[])
/* get main handle of appliaction and QML */
QQmlApplicationEngine engine;
QQmlContext *ctx = engine.rootContext();
engine.addImageProvider(QLatin1String("images"), new ImageProvider);
/* Register application pages to QML */
registerQmlTypes(uri, QML_PAGE_LOC, qmlPages);
......
/*
* Copyright (C) 2014-2018 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, 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 General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations including
* the two.
*/
#include "src/datovka_shared/graphics/graphics.h"
#include "src/qml_interaction/image_provider.h"
#include "src/records_management.h"
#define LOGO_EDGE 64
ImageProvider::ImageProvider(void)
: QQuickImageProvider(QQuickImageProvider::Pixmap)
{
}
QPixmap ImageProvider::requestPixmap(const QString& id, QSize* size,
const QSize& requestedSize)
{
Q_UNUSED(id);
QPixmap pixmap(Graphics::pixmapFromSvg(globRmLogoSvg, LOGO_EDGE));
QPixmap result;
if (requestedSize.isValid()) {
result = pixmap.scaled(requestedSize, Qt::KeepAspectRatio);
} else {
result = pixmap;
}
*size = result.size();
return result;
}
/*
* Copyright (C) 2014-2018 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, 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 General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations including
* the two.
*/
#pragma once
#include <QPixmap>
#include <QQuickImageProvider>
/*!
* @brief Class provides an interface for supporting pixmaps
* and threaded image requests in QML.
*/
class ImageProvider : public QQuickImageProvider {
public:
/*!
* @brief Constructor.
*/
ImageProvider(void);
/*!
* @brief Transform image from stored bytearray and show it as QML image.
*
* @param[in] id String that identify image file.
* @param[in,out] size Output image size.
* @param[in] requestedSize Input image size (may be NULL).
* @return Plain pixmap image for QML.
*/
virtual
QPixmap requestPixmap(const QString &id, QSize *size,
const QSize& requestedSize);
};
......@@ -23,7 +23,6 @@
#include <QMessageBox>
#include "src/datovka_shared/graphics/graphics.h"
#include "src/datovka_shared/io/records_management_db.h"
#include "src/datovka_shared/records_management/json/service_info.h"
#include "src/datovka_shared/records_management/json/upload_file.h"
......@@ -92,8 +91,7 @@ bool processUploadFileResponse(const UploadFileResp &ufRes, qint64 dmId,
RecordsManagement::RecordsManagement(QObject *parent)
: QObject(parent),
m_rmc(RecordsManagementConnection::ignoreSslErrorsDflt, this),
m_logoSvg()
m_rmc(RecordsManagementConnection::ignoreSslErrorsDflt, this)
{
globWorkPool.start();
......@@ -128,8 +126,7 @@ bool RecordsManagement::callServiceInfo(const QString &urlStr,
ServiceInfoResp siRes(
ServiceInfoResp::fromJson(response, &ok));
if (ok && siRes.isValid()) {
m_logoSvg = siRes.logoSvg();
loadRecordsManagementPixmap(m_logoSvg);
globRmLogoSvg = siRes.logoSvg();
emit serviceInfo(siRes.name(), siRes.tokenName());
emit statusBarTextChanged(tr("Done"), false, true);
return true;
......@@ -259,8 +256,7 @@ void RecordsManagement::loadStoredServiceInfo(void)
return;
}
m_logoSvg = entry.logoSvg;
loadRecordsManagementPixmap(entry.logoSvg);
globRmLogoSvg = entry.logoSvg;
emit serviceInfo(entry.name, entry.tokenName);
}
......@@ -322,7 +318,7 @@ bool RecordsManagement::updateServiceInfo(const QString &newUrlStr,
entry.url = cUrlStr;
entry.name = srName;
entry.tokenName = srToken;
entry.logoSvg = m_logoSvg;
entry.logoSvg = globRmLogoSvg;
globRecordsManagementDbPtr->updateServiceInfo(entry);
if (oldUrlStr != cUrlStr) {
return globRecordsManagementDbPtr->deleteAllStoredMsg();
......@@ -346,30 +342,6 @@ void RecordsManagement::rmSyncFinished(const QString &userName, int accNumber,
}
}
void RecordsManagement::loadRecordsManagementPixmap(const QByteArray &logoSvg)
{
if (Q_NULLPTR == globRecordsManagementDbPtr) {
return;
}
QByteArray logo = logoSvg;
if (logo.isNull()) {
RecordsManagementDb::ServiceInfoEntry entry(
globRecordsManagementDbPtr->serviceInfo());
if (!entry.isValid() || entry.logoSvg.isEmpty()) {
return;
}
logo = entry.logoSvg;
}
QPixmap pixmap(Graphics::pixmapFromSvg(logo, LOGO_EDGE));
if (!pixmap.isNull()) {
/* TODO - set Pixmap into QML */
}
}
bool RecordsManagement::uploadFile(qint64 dmId, const QString &msgFileName,
const QByteArray &msgData, const QStringList &uploadIds)
{
......@@ -412,3 +384,5 @@ bool RecordsManagement::uploadFile(qint64 dmId, const QString &msgFileName,
emit statusBarTextChanged(tr("Communication error"), false, true);
return false;
}
QByteArray globRmLogoSvg;
......@@ -29,8 +29,6 @@
#include "src/datovka_shared/records_management/io/records_management_connection.h"
#include "src/datovka_shared/settings/records_management.h"
#define LOGO_EDGE 64
class RecordsManagement : public QObject {
Q_OBJECT
......@@ -150,13 +148,6 @@ private slots:
private:
/*!
* @brief Loads records management service logo and sets the logo label.
*
* @param[in] logoSvg Service SVG logo.
*/
void loadRecordsManagementPixmap(const QByteArray &logoSvg);
/*!
* @brief Upload file into records management service.
*
......@@ -171,5 +162,9 @@ private:
const QByteArray &msgData, const QStringList &uploadIds);
RecordsManagementConnection m_rmc; /*!< Connection to records management service. */
QByteArray m_logoSvg; /*!< Raw SVG data. */
};
/*!
* @brief Global SVG data.
*/
extern QByteArray globRmLogoSvg; /*!< Raw SVG data. */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment