Add advanced page ranges (list of ranges)

This commit is contained in:
Anton Thomasson 2022-08-13 16:30:13 +02:00
parent 3abd1e103f
commit 53ca370f92
15 changed files with 166 additions and 14 deletions

View file

@ -34,6 +34,7 @@ DEFINES += PDF_CREATOR='\\"SeaPrint\ $$VERSION\\"'
DEFINES += SEAPRINT_VERSION='\\"$$VERSION\\"' DEFINES += SEAPRINT_VERSION='\\"$$VERSION\\"'
SOURCES += src/harbour-seaprint.cpp \ SOURCES += src/harbour-seaprint.cpp \
src/rangelistchecker.cpp \
src/convertchecker.cpp \ src/convertchecker.cpp \
src/curlrequester.cpp \ src/curlrequester.cpp \
src/imageitem.cpp \ src/imageitem.cpp \
@ -51,6 +52,7 @@ SOURCES += src/harbour-seaprint.cpp \
DISTFILES += qml/harbour-seaprint.qml \ DISTFILES += qml/harbour-seaprint.qml \
qml/components/DependentOn.qml \ qml/components/DependentOn.qml \
qml/components/RangeListInputDialog.qml \
qml/cover/CoverPage.qml \ qml/cover/CoverPage.qml \
qml/components/*qml \ qml/components/*qml \
qml/pages/*.qml \ qml/pages/*.qml \
@ -81,6 +83,7 @@ TRANSLATIONS += translations/harbour-seaprint-de.ts \
translations/harbour-seaprint-pl.ts translations/harbour-seaprint-pl.ts
HEADERS += \ HEADERS += \
src/rangelistchecker.h \
src/convertchecker.h \ src/convertchecker.h \
src/curlrequester.h \ src/curlrequester.h \
src/imageitem.h \ src/imageitem.h \

@ -1 +1 @@
Subproject commit 89cfaa0b424310f54355ee2415d3bee9ed786255 Subproject commit fafcd9d21d646ee633cae38265a7f899902c8e33

View file

@ -5,6 +5,7 @@ Setting {
property int high property int high
property int choice_low: 1 property int choice_low: 1
property int choice_high: 0 property int choice_high: 0
property bool acceptRangeList: false
property bool suppressChange: false property bool suppressChange: false
@ -41,7 +42,7 @@ Setting {
} }
onChoiceChanged: { onChoiceChanged: {
if(choice == undefined) if(choice == undefined || choice.constructor.name !== "Object")
{ {
suppressChange = true; suppressChange = true;
low_slider.value = low_slider.minimumValue; low_slider.value = low_slider.minimumValue;
@ -50,7 +51,39 @@ Setting {
} }
} }
displayValue: choice == undefined ? qsTr("all") : ""+choice.low+" - "+choice.high displayValue: prettify(choice)
function prettify(choice)
{
if(choice == undefined)
{
return qsTr("all");
}
else if(choice.constructor.name === "Object")
{
return (""+choice.low+" - "+choice.high)
}
else
{
var ret = "";
for(var i = 0; i < choice.length; i++)
{
if(i!=0)
{
ret = ret+","
}
if(choice[i].low == choice[i].high)
{
ret=ret+choice[i].low
}
else
{
ret=ret+choice[i].low+"-"+choice[i].high
}
}
return ret
}
}
menu: ContextMenu { menu: ContextMenu {
MenuItem { MenuItem {
@ -109,6 +142,17 @@ Setting {
} }
MenuItem {
visible: acceptRangeList
text: qsTr("Advanced")
onClicked: {var dialog = pageStack.push(Qt.resolvedUrl("RangeListInputDialog.qml"),
{value: choice, title: prettyName});
dialog.accepted.connect(function() {
choice = dialog.value;
})
}
}
} }

View file

@ -120,6 +120,7 @@ Page {
property var pdfpages: ConvertChecker.pdfPages(selectedFile) property var pdfpages: ConvertChecker.pdfPages(selectedFile)
high: pdfpages == 0 ? 65535 : pdfpages high: pdfpages == 0 ? 65535 : pdfpages
acceptRangeList: true
} }
ChoiceSetting { ChoiceSetting {
tag: IppMsg.Integer tag: IppMsg.Integer

View file

@ -7,6 +7,7 @@
#include <src/mimer.h> #include <src/mimer.h>
#include <src/convertchecker.h> #include <src/convertchecker.h>
#include <src/settings.h> #include <src/settings.h>
#include <src/rangelistchecker.h>
Q_DECLARE_METATYPE(CURLcode) Q_DECLARE_METATYPE(CURLcode)
Q_DECLARE_METATYPE(Bytestream) Q_DECLARE_METATYPE(Bytestream)
@ -41,7 +42,9 @@ int main(int argc, char *argv[])
qmlRegisterSingletonType<IppDiscovery>("seaprint.ippdiscovery", 1, 0, "IppDiscovery", singletontype_provider<IppDiscovery>); qmlRegisterSingletonType<IppDiscovery>("seaprint.ippdiscovery", 1, 0, "IppDiscovery", singletontype_provider<IppDiscovery>);
qmlRegisterSingletonType<Mimer>("seaprint.mimer", 1, 0, "Mimer", singletontype_provider<Mimer>); qmlRegisterSingletonType<Mimer>("seaprint.mimer", 1, 0, "Mimer", singletontype_provider<Mimer>);
qmlRegisterSingletonType<ConvertChecker>("seaprint.convertchecker", 1, 0, "ConvertChecker", singletontype_provider<ConvertChecker>); qmlRegisterSingletonType<ConvertChecker>("seaprint.convertchecker", 1, 0, "ConvertChecker", singletontype_provider<ConvertChecker>);
qmlRegisterSingletonType<ConvertChecker>("seaprint.settings", 1, 0, "SeaPrintSettings", singletontype_provider<Settings>); qmlRegisterSingletonType<Settings>("seaprint.settings", 1, 0, "SeaPrintSettings", singletontype_provider<Settings>);
qmlRegisterSingletonType<RangeListChecker>("seaprint.rangelistchecker", 1, 0, "RangeListChecker", singletontype_provider<RangeListChecker>);
qmlRegisterType<IppPrinter>("seaprint.ippprinter", 1, 0, "IppPrinter"); qmlRegisterType<IppPrinter>("seaprint.ippprinter", 1, 0, "IppPrinter");
qmlRegisterType<ImageItem>("seaprint.imageitem", 1, 0, "ImageItem"); qmlRegisterType<ImageItem>("seaprint.imageitem", 1, 0, "ImageItem");
qmlRegisterUncreatableType<IppMsg>("seaprint.ippmsg", 1, 0, "IppMsg", "Only used to supply an enum type"); qmlRegisterUncreatableType<IppMsg>("seaprint.ippmsg", 1, 0, "IppMsg", "Only used to supply an enum type");

View file

@ -721,21 +721,24 @@ void IppPrinter::print(QJsonObject jobAttrs, QString filename)
Params.hwResW = PrinterResolutionRef.toObject()["x"].toInt(Params.hwResW); Params.hwResW = PrinterResolutionRef.toObject()["x"].toInt(Params.hwResW);
Params.hwResH = PrinterResolutionRef.toObject()["y"].toInt(Params.hwResH); Params.hwResH = PrinterResolutionRef.toObject()["y"].toInt(Params.hwResH);
if(jobAttrs.contains("page-ranges")) // Effected locally, unless it is Postscript which we cant't render
if(jobAttrs.contains("page-ranges") && mimeType != Mimer::Postscript)
{ {
QJsonObject PageRanges = getAttrOrDefault(jobAttrs, "page-ranges").toObject(); QJsonArray tmp;
size_t fromPage = PageRanges["low"].toInt(); QJsonValue pageRanges = getAttrOrDefault(jobAttrs, "page-ranges");
size_t toPage = PageRanges["high"].toInt(); if(pageRanges.isArray())
if(fromPage != 0 || toPage != 0)
{ {
Params.pageRangeList = {{fromPage, toPage}}; tmp = pageRanges.toArray();
} }
else if(pageRanges.isObject())
// Effected locally, unless it is Postscript which we cant't render
if(targetFormat != Mimer::Postscript)
{ {
jobAttrs.remove("page-ranges"); tmp = {pageRanges.toObject()};
} }
for(QJsonValueRef ref : tmp)
{
Params.pageRangeList.push_back({ref.toObject()["low"].toInt(), ref.toObject()["high"].toInt()});
}
jobAttrs.remove("page-ranges");
} }
adjustRasterSettings(filename, mimeType, jobAttrs, Params); adjustRasterSettings(filename, mimeType, jobAttrs, Params);

41
src/rangelistchecker.cpp Normal file
View file

@ -0,0 +1,41 @@
#include "rangelistchecker.h"
RangeListChecker::RangeListChecker()
{
}
RangeListChecker::~RangeListChecker()
{
}
RangeListChecker* RangeListChecker::m_Instance = 0;
RangeListChecker* RangeListChecker::instance()
{
static QMutex mutex;
if (!m_Instance)
{
mutex.lock();
if (!m_Instance)
m_Instance = new RangeListChecker;
mutex.unlock();
}
return m_Instance;
}
QJsonArray RangeListChecker::parse(QString str) const
{
PrintParameters params;
params.setPageRange(str.toStdString());
QJsonArray ret;
for(const std::pair<size_t, size_t>& p : params.pageRangeList)
{
ret.append(QJsonObject {{"low", int(p.first)}, {"high", int(p.second)}});
}
return ret;
}

29
src/rangelistchecker.h Normal file
View file

@ -0,0 +1,29 @@
#ifndef RANGELISTCHECKER_H
#define RANGELISTCHECKER_H
#include <QValidator>
#include <QMutex>
#include <QJsonArray>
#include <QJsonObject>
#include "printparameters.h"
class RangeListChecker : public QObject
{
Q_OBJECT
public:
static RangeListChecker* instance();
Q_INVOKABLE QJsonArray parse(QString str) const;
private:
static RangeListChecker* m_Instance;
RangeListChecker();
~RangeListChecker();
RangeListChecker(const RangeListChecker &);
RangeListChecker& operator=(const RangeListChecker &);
};
#endif // RANGELISTCHECKER_H

View file

@ -531,6 +531,10 @@ auf diesem Drucker</translation>
<source>all</source> <source>all</source>
<translation>Alle</translation> <translation>Alle</translation>
</message> </message>
<message>
<source>Advanced</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>Setting</name> <name>Setting</name>

View file

@ -530,6 +530,10 @@
<source>all</source> <source>all</source>
<translation>todos</translation> <translation>todos</translation>
</message> </message>
<message>
<source>Advanced</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>Setting</name> <name>Setting</name>

View file

@ -531,6 +531,10 @@ sur cette imprimante</translation>
<source>all</source> <source>all</source>
<translation>tout</translation> <translation>tout</translation>
</message> </message>
<message>
<source>Advanced</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>Setting</name> <name>Setting</name>

View file

@ -530,6 +530,10 @@
<source>all</source> <source>all</source>
<translation>alles</translation> <translation>alles</translation>
</message> </message>
<message>
<source>Advanced</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>Setting</name> <name>Setting</name>

View file

@ -530,6 +530,10 @@
<source>all</source> <source>all</source>
<translation>wszystkie</translation> <translation>wszystkie</translation>
</message> </message>
<message>
<source>Advanced</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>Setting</name> <name>Setting</name>

View file

@ -530,6 +530,10 @@
<source>all</source> <source>all</source>
<translation></translation> <translation></translation>
</message> </message>
<message>
<source>Advanced</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>Setting</name> <name>Setting</name>

View file

@ -530,6 +530,10 @@
<source>all</source> <source>all</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Advanced</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>Setting</name> <name>Setting</name>