Commit 8643293b authored by Martin Straka's avatar Martin Straka

Added svg graphics

parent 25200c7b
...@@ -88,6 +88,7 @@ SOURCES += \ ...@@ -88,6 +88,7 @@ SOURCES += \
src/accounts.cpp \ src/accounts.cpp \
src/auxiliaries/attachment_helper.cpp \ src/auxiliaries/attachment_helper.cpp \
src/auxiliaries/email_helper.cpp \ src/auxiliaries/email_helper.cpp \
src/datovka_shared/graphics/graphics.cpp \
src/datovka_shared/io/records_management_db.cpp \ src/datovka_shared/io/records_management_db.cpp \
src/datovka_shared/io/sqlite/db.cpp \ src/datovka_shared/io/sqlite/db.cpp \
src/datovka_shared/io/sqlite/db_single.cpp \ src/datovka_shared/io/sqlite/db_single.cpp \
...@@ -168,6 +169,7 @@ HEADERS += \ ...@@ -168,6 +169,7 @@ HEADERS += \
src/auxiliaries/attachment_helper.h \ src/auxiliaries/attachment_helper.h \
src/auxiliaries/email_helper.h \ src/auxiliaries/email_helper.h \
src/common.h \ src/common.h \
src/datovka_shared/graphics/graphics.h \
src/datovka_shared/io/records_management_db.h \ src/datovka_shared/io/records_management_db.h \
src/datovka_shared/io/sqlite/db.h \ src/datovka_shared/io/sqlite/db.h \
src/datovka_shared/io/sqlite/db_single.h \ src/datovka_shared/io/sqlite/db_single.h \
......
...@@ -237,7 +237,6 @@ Item { ...@@ -237,7 +237,6 @@ Item {
serviceLogo.visible = serviceInfo1.visible serviceLogo.visible = serviceInfo1.visible
serviceName.text = srName serviceName.text = srName
tokenName.text = srToken tokenName.text = srToken
//serviceLogo.source = srLogo
} }
} }
} // Item } // Item
/*
* 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 <QImage>
#include <QPainter>
#include <QSvgRenderer>
#include "src/datovka_shared/graphics/graphics.h"
QPixmap Graphics::pixmapFromSvg(const QByteArray &svgData, int edgeLen)
{
if (svgData.isEmpty()) {
return QPixmap();
}
QSvgRenderer renderer;
if (!renderer.load(svgData)) {
return QPixmap();
}
QImage image(edgeLen, edgeLen, QImage::Format_ARGB32);
QPainter painter(&image);
renderer.render(&painter);
QPixmap pixmap;
pixmap.convertFromImage(image);
return pixmap;
}
/*
* 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 <QByteArray>
#include <QPixmap>
/*!
* @brief Encapsulates some graphics-related routines.
*/
class Graphics {
public:
/*!
* @brief Draws a pixmap from supplied SVG data.
*
* @param[in] svgData SVG image data.
* @param[in] edgeLen Edge size of the drawn image square.
* @return Null pixmap on error.
*/
static
QPixmap pixmapFromSvg(const QByteArray &svgData, int edgeLen);
private:
/*!
* @brief Private constructor.
*/
Graphics(void);
};
...@@ -22,9 +22,8 @@ ...@@ -22,9 +22,8 @@
*/ */
#include <QMessageBox> #include <QMessageBox>
#include <QPainter>
#include <QSvgRenderer>
#include "src/datovka_shared/graphics/graphics.h"
#include "src/datovka_shared/io/records_management_db.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/service_info.h"
#include "src/datovka_shared/records_management/json/upload_file.h" #include "src/datovka_shared/records_management/json/upload_file.h"
...@@ -125,11 +124,8 @@ void RecordsManagement::callServiceInfo(const QString &urlStr, ...@@ -125,11 +124,8 @@ void RecordsManagement::callServiceInfo(const QString &urlStr,
} }
m_logoSvg = siRes.logoSvg(); m_logoSvg = siRes.logoSvg();
QPixmap logoPx = fromSvgToPixmap(m_logoSvg); loadRecordsManagementPixmap(m_logoSvg);
emit serviceInfo(siRes.name(), siRes.tokenName());
/* TODO - logoPx to QML */
emit serviceInfo(m_logoSvg, siRes.name(),
siRes.tokenName());
} else { } else {
QMessageBox::critical(Q_NULLPTR, QMessageBox::critical(Q_NULLPTR,
...@@ -235,34 +231,8 @@ void RecordsManagement::loadStoredServiceInfo(void) ...@@ -235,34 +231,8 @@ void RecordsManagement::loadStoredServiceInfo(void)
} }
m_logoSvg = entry.logoSvg; m_logoSvg = entry.logoSvg;
emit serviceInfo(m_logoSvg, entry.name, entry.tokenName); loadRecordsManagementPixmap(entry.logoSvg);
} emit serviceInfo(entry.name, entry.tokenName);
bool RecordsManagement::updateServiceInfo(const QString &urlStr,
const QString &urlStrSettings, const QString &srName, const QString &srToken)
{
if (Q_NULLPTR == globRecordsManagementDbPtr) {
return false;
}
if (!urlStr.trimmed().isEmpty()) {
Q_ASSERT(!urlStr.trimmed().isEmpty());
RecordsManagementDb::ServiceInfoEntry entry;
entry.url = urlStr.trimmed();
entry.name = srName;
entry.tokenName = srToken;
entry.logoSvg = m_logoSvg;
globRecordsManagementDbPtr->updateServiceInfo(entry);
if (urlStrSettings != urlStr) {
globRecordsManagementDbPtr->deleteAllStoredMsg();
}
} else {
globRecordsManagementDbPtr->deleteAllEntries();
}
return true;
} }
bool RecordsManagement::uploadMessage(const QString &urlStr, bool RecordsManagement::uploadMessage(const QString &urlStr,
...@@ -311,19 +281,54 @@ bool RecordsManagement::uploadMessage(const QString &urlStr, ...@@ -311,19 +281,54 @@ bool RecordsManagement::uploadMessage(const QString &urlStr,
} }
} }
QPixmap RecordsManagement::fromSvgToPixmap(const QString &SvgContent) bool RecordsManagement::updateServiceInfo(const QString &urlStr,
const QString &urlStrSettings, const QString &srName, const QString &srToken)
{
if (Q_NULLPTR == globRecordsManagementDbPtr) {
return false;
}
if (!urlStr.trimmed().isEmpty()) {
Q_ASSERT(!urlStr.trimmed().isEmpty());
RecordsManagementDb::ServiceInfoEntry entry;
entry.url = urlStr.trimmed();
entry.name = srName;
entry.tokenName = srToken;
entry.logoSvg = m_logoSvg;
globRecordsManagementDbPtr->updateServiceInfo(entry);
if (urlStrSettings != urlStr) {
globRecordsManagementDbPtr->deleteAllStoredMsg();
}
} else {
globRecordsManagementDbPtr->deleteAllEntries();
}
return true;
}
void RecordsManagement::loadRecordsManagementPixmap(const QByteArray &logoSvg)
{ {
QSize ImageSize(100, 100); if (Q_NULLPTR == globRecordsManagementDbPtr) {
return;
}
QSvgRenderer SvgRenderer(SvgContent); QByteArray logo = logoSvg;
QPixmap Image(ImageSize);
QPainter Painter;
Image.fill(Qt::transparent); if (logo.isNull()) {
Painter.begin(&Image); RecordsManagementDb::ServiceInfoEntry entry(
SvgRenderer.render(&Painter); globRecordsManagementDbPtr->serviceInfo());
Painter.end(); if (!entry.isValid() || entry.logoSvg.isEmpty()) {
return;
}
logo = entry.logoSvg;
}
return Image; QPixmap pixmap(Graphics::pixmapFromSvg(logo, LOGO_EDGE));
if (!pixmap.isNull()) {
/* TODO - set Pixmap into QML */
//m_ui->pixmapLabel->setPixmap(pixmap);
}
} }
...@@ -31,6 +31,8 @@ ...@@ -31,6 +31,8 @@
#include "src/datovka_shared/records_management/io/records_management_connection.h" #include "src/datovka_shared/records_management/io/records_management_connection.h"
#include "src/datovka_shared/settings/records_management.h" #include "src/datovka_shared/settings/records_management.h"
#define LOGO_EDGE 64
class RecordsManagement : public QObject { class RecordsManagement : public QObject {
Q_OBJECT Q_OBJECT
...@@ -80,6 +82,21 @@ public: ...@@ -80,6 +82,21 @@ public:
Q_INVOKABLE Q_INVOKABLE
void loadStoredServiceInfo(void); void loadStoredServiceInfo(void);
/*!
* @brief Upload message into records management service.
*
* @param[in] urlStr Records management url string.
* @param[in] tokenStr Records management token string.
* @param[in] dmId Message identifier.
* @param[in] msgFileName Message file name.
* @param[in] msgData Message data.
* @return True when data have been updated, false else.
*/
Q_INVOKABLE
bool uploadMessage(const QString &urlStr,
const QString &tokenStr, qint64 dmId, const QString &msgFileName,
const QByteArray &msgData);
/*! /*!
* @brief Update record management settings. * @brief Update record management settings.
* *
...@@ -98,35 +115,19 @@ signals: ...@@ -98,35 +115,19 @@ signals:
/*! /*!
* @brief Send service info to QML. * @brief Send service info to QML.
* *
* @param[in] srLogo Service SVG logo.
* @param[in] srName Service name. * @param[in] srName Service name.
* @param[in] srToken Service token. * @param[in] srToken Service token.
*/ */
void serviceInfo(QString srLogo, QString srName, QString srToken); void serviceInfo(QString srName, QString srToken);
private: private:
/*! /*!
* @brief Upload message into records management service. * @brief Loads records management service logo and sets the logo label.
*
* @param[in] urlStr Records management url string.
* @param[in] tokenStr Records management token string.
* @param[in] dmId Message identifier.
* @param[in] msgFileName Message file name.
* @param[in] msgData Message data.
* @return True when data have been updated, false else.
*/
bool uploadMessage(const QString &urlStr,
const QString &tokenStr, qint64 dmId, const QString &msgFileName,
const QByteArray &msgData);
/*!
* @brief Convert svg to QPixmap.
* *
* @param[in] SvgContent Svg content. * @param[in] logoSvg Service SVG logo.
* @return Pixmap.
*/ */
QPixmap fromSvgToPixmap(const QString &SvgContent); void loadRecordsManagementPixmap(const QByteArray &logoSvg);
UploadHierarchyModel m_uploadModel; /*!< Upload hierarchy model. */ UploadHierarchyModel m_uploadModel; /*!< Upload hierarchy model. */
UploadHierarchyProxyModel m_uploadProxyModel; /*!< Used for filtering. */ UploadHierarchyProxyModel m_uploadProxyModel; /*!< Used for filtering. */
......
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