Add SvgProvider for even better scaling
This commit is contained in:
parent
7db4f21f4e
commit
8aef95b143
7 changed files with 87 additions and 10 deletions
|
@ -26,6 +26,7 @@ INSTALLS += i18n
|
||||||
system(lrelease $$PWD/translations/*.ts)
|
system(lrelease $$PWD/translations/*.ts)
|
||||||
|
|
||||||
CONFIG += sailfishapp
|
CONFIG += sailfishapp
|
||||||
|
QT += svg
|
||||||
|
|
||||||
# Write version file
|
# Write version file
|
||||||
VERSION_H = \
|
VERSION_H = \
|
||||||
|
@ -42,7 +43,8 @@ SOURCES += src/harbour-seaprint.cpp \
|
||||||
src/ippprinter.cpp \
|
src/ippprinter.cpp \
|
||||||
src/mimer.cpp \
|
src/mimer.cpp \
|
||||||
ppm2pwg/ppm2pwg.cpp \
|
ppm2pwg/ppm2pwg.cpp \
|
||||||
ppm2pwg/bytestream/bytestream.cpp
|
ppm2pwg/bytestream/bytestream.cpp \
|
||||||
|
src/svgprovider.cpp
|
||||||
|
|
||||||
DISTFILES += qml/harbour-seaprint.qml \
|
DISTFILES += qml/harbour-seaprint.qml \
|
||||||
qml/cover/CoverPage.qml \
|
qml/cover/CoverPage.qml \
|
||||||
|
@ -88,7 +90,8 @@ HEADERS += \
|
||||||
ppm2pwg/UrfPgHdr.codable \
|
ppm2pwg/UrfPgHdr.codable \
|
||||||
ppm2pwg/bytestream/bytestream.h \
|
ppm2pwg/bytestream/bytestream.h \
|
||||||
ppm2pwg/bytestream/codable.h \
|
ppm2pwg/bytestream/codable.h \
|
||||||
src/papersizes.h
|
src/papersizes.h \
|
||||||
|
src/svgprovider.h
|
||||||
|
|
||||||
INCLUDEPATH += ppm2pwg \
|
INCLUDEPATH += ppm2pwg \
|
||||||
ppm2pwg/bytestream
|
ppm2pwg/bytestream
|
||||||
|
|
|
@ -6,7 +6,9 @@ CoverBackground {
|
||||||
anchors.centerIn: parent
|
anchors.centerIn: parent
|
||||||
height: parent.width
|
height: parent.width
|
||||||
width: parent.width
|
width: parent.width
|
||||||
opacity: 0.33
|
sourceSize.height: height
|
||||||
|
sourceSize.width: width
|
||||||
|
opacity: 0.4
|
||||||
source: "../pages/icon-seaprint-nobg-bw.png"
|
source: "../pages/icon-seaprint-nobg-bw.png"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -227,10 +227,12 @@ Page {
|
||||||
|
|
||||||
height: Theme.itemSizeLarge
|
height: Theme.itemSizeLarge
|
||||||
width: Theme.itemSizeLarge
|
width: Theme.itemSizeLarge
|
||||||
|
sourceSize.height: height
|
||||||
|
sourceSize.width: width
|
||||||
source: printer.attrs["printer-icons"] ? "image://ippdiscovery/"+Utils.selectIcon(printer.attrs["printer-icons"].value)
|
source: printer.attrs["printer-icons"] ? "image://ippdiscovery/"+Utils.selectIcon(printer.attrs["printer-icons"].value)
|
||||||
: "icon-seaprint-nobg.svg"
|
: "image://svg/qml/pages/icon-seaprint-nobg.svg"
|
||||||
// Some printers serve their icons over https with invalid certs...
|
// Some printers serve their icons over https with invalid certs...
|
||||||
onStatusChanged: if (status == Image.Error) source = "icon-seaprint-nobg.svg"
|
onStatusChanged: if (status == Image.Error) source = "image://svg/qml/pages/icon-seaprint-nobg.svg"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,8 +12,8 @@
|
||||||
version="1.1"
|
version="1.1"
|
||||||
x="0px"
|
x="0px"
|
||||||
y="0px"
|
y="0px"
|
||||||
viewBox="0 0 172 172"
|
viewBox="0 0 86 86"
|
||||||
style="enable-background:new 0 0 172 172;"
|
style="enable-background:new 0 0 86 86;"
|
||||||
xml:space="preserve"
|
xml:space="preserve"
|
||||||
id="svg82"
|
id="svg82"
|
||||||
sodipodi:docname="icon-seaprint-nobg.svg"
|
sodipodi:docname="icon-seaprint-nobg.svg"
|
||||||
|
@ -39,8 +39,6 @@
|
||||||
.st11{fill:url(#SVGID_10_);}
|
.st11{fill:url(#SVGID_10_);}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<g transform="scale(2)">
|
|
||||||
|
|
||||||
<g
|
<g
|
||||||
id="Слой_3"
|
id="Слой_3"
|
||||||
class="st1">
|
class="st1">
|
||||||
|
@ -249,5 +247,4 @@
|
||||||
d="M65,59.2H21c-1.1,0-2-0.9-2-2V-2.6c0-1.1,0.9-2,2-2h44c1.1,0,2,0.9,2,2v59.9C67,58.3,66.1,59.2,65,59.2z"
|
d="M65,59.2H21c-1.1,0-2-0.9-2-2V-2.6c0-1.1,0.9-2,2-2h44c1.1,0,2,0.9,2,2v59.9C67,58.3,66.1,59.2,65,59.2z"
|
||||||
id="path79" />
|
id="path79" />
|
||||||
</g>
|
</g>
|
||||||
</g>
|
|
||||||
</svg>
|
</svg>
|
||||||
|
|
Before Width: | Height: | Size: 5.4 KiB After Width: | Height: | Size: 5.4 KiB |
|
@ -6,6 +6,7 @@
|
||||||
#include <src/ippprinter.h>
|
#include <src/ippprinter.h>
|
||||||
#include <src/mimer.h>
|
#include <src/mimer.h>
|
||||||
#include <src/convertchecker.h>
|
#include <src/convertchecker.h>
|
||||||
|
#include <src/svgprovider.h>
|
||||||
|
|
||||||
#define PPM2PWG_MAIN ppm2pwg_main
|
#define PPM2PWG_MAIN ppm2pwg_main
|
||||||
#include <ppm2pwg/ppm2pwg.cpp>
|
#include <ppm2pwg/ppm2pwg.cpp>
|
||||||
|
@ -45,6 +46,7 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
view->engine()->addImportPath(SailfishApp::pathTo("qml/pages").toString());
|
view->engine()->addImportPath(SailfishApp::pathTo("qml/pages").toString());
|
||||||
view->engine()->addImageProvider(QLatin1String("ippdiscovery"), IppDiscovery::instance());
|
view->engine()->addImageProvider(QLatin1String("ippdiscovery"), IppDiscovery::instance());
|
||||||
|
view->engine()->addImageProvider(QLatin1String("svg"), SvgProvider::instance());
|
||||||
|
|
||||||
view->setSource(SailfishApp::pathToMainQml());
|
view->setSource(SailfishApp::pathToMainQml());
|
||||||
view->show();
|
view->show();
|
||||||
|
|
43
src/svgprovider.cpp
Normal file
43
src/svgprovider.cpp
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
#include "svgprovider.h"
|
||||||
|
|
||||||
|
|
||||||
|
SvgProvider::SvgProvider() : QQuickImageProvider(QQuickImageProvider::Image, ForceAsynchronousImageLoading)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
SvgProvider::~SvgProvider() {
|
||||||
|
}
|
||||||
|
|
||||||
|
SvgProvider* SvgProvider::m_Instance = nullptr;
|
||||||
|
|
||||||
|
SvgProvider* SvgProvider::instance()
|
||||||
|
{
|
||||||
|
static QMutex mutex;
|
||||||
|
if (!m_Instance)
|
||||||
|
{
|
||||||
|
mutex.lock();
|
||||||
|
|
||||||
|
if (!m_Instance)
|
||||||
|
m_Instance = new SvgProvider;
|
||||||
|
|
||||||
|
mutex.unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
return m_Instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
QImage SvgProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize)
|
||||||
|
{
|
||||||
|
QSvgRenderer renderer(SailfishApp::pathTo(id).toLocalFile());
|
||||||
|
*size = requestedSize.isValid() ? requestedSize : renderer.defaultSize();
|
||||||
|
|
||||||
|
QImage img(*size, QImage::Format_ARGB32);
|
||||||
|
img.fill(QColor("transparent"));
|
||||||
|
QPainter painter(&img);
|
||||||
|
qDebug() << img << painter.isActive();
|
||||||
|
|
||||||
|
renderer.render(&painter);
|
||||||
|
|
||||||
|
return img;
|
||||||
|
}
|
28
src/svgprovider.h
Normal file
28
src/svgprovider.h
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
#ifndef SVGPROVIDER_H
|
||||||
|
#define SVGPROVIDER_H
|
||||||
|
|
||||||
|
#include <QQuickImageProvider>
|
||||||
|
#include <QPainter>
|
||||||
|
#include <QtSvg/QSvgRenderer>
|
||||||
|
#include <QMutex>
|
||||||
|
#include <QtDebug>
|
||||||
|
#include <sailfishapp.h>
|
||||||
|
|
||||||
|
class SvgProvider : public QQuickImageProvider
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static SvgProvider* instance();
|
||||||
|
|
||||||
|
QImage requestImage(const QString &id, QSize *size, const QSize &requestedSize) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
SvgProvider();
|
||||||
|
~SvgProvider();
|
||||||
|
SvgProvider(const SvgProvider &);
|
||||||
|
SvgProvider& operator=(const SvgProvider &);
|
||||||
|
|
||||||
|
static SvgProvider* m_Instance;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // SVGPROVIDER_H
|
Loading…
Reference in a new issue