diff --git a/libimageviewer/service/permissionconfig.cpp b/libimageviewer/service/permissionconfig.cpp index 41261852..047a9113 100644 --- a/libimageviewer/service/permissionconfig.cpp +++ b/libimageviewer/service/permissionconfig.cpp @@ -42,6 +42,9 @@ static const qreal g_PrintColumnSpacingLimit = 2.0; // 打印水印默认字体大小,用于计算转换系数 static const qreal g_DefaultPrintFontSize = 65.0; +// 打印计数为-1时,无打印限制 +static const int g_UnlimitPrintCount = -1; + /** @brief 通过dbus接口从任务栏激活窗口 */ @@ -188,7 +191,7 @@ bool PermissionConfig::isUnlimitPrint() const if (checkAuthInvalid()) { return true; } - return -1 == printLimitCount; + return g_UnlimitPrintCount == printLimitCount; } /** @@ -196,6 +199,10 @@ bool PermissionConfig::isUnlimitPrint() const */ void PermissionConfig::reduceOnePrintCount() { + if (g_UnlimitPrintCount == printLimitCount) { + return; + } + if (printLimitCount > 0) { printLimitCount--; Q_EMIT printCountChanged(); @@ -612,6 +619,9 @@ void PermissionConfig::initAuthorise(const QJsonObject ¶m) } printLimitCount = param.value("printCount").toInt(0); + if (printLimitCount < g_UnlimitPrintCount) { + printLimitCount = 0; + } } #ifdef DTKWIDGET_CLASS_DWaterMarkHelper diff --git a/libimageviewer/widgets/printhelper.cpp b/libimageviewer/widgets/printhelper.cpp index 8438d5bf..c2f35c40 100755 --- a/libimageviewer/widgets/printhelper.cpp +++ b/libimageviewer/widgets/printhelper.cpp @@ -50,10 +50,9 @@ void PrintHelper::showPrintDialog(const QStringList &paths, QWidget *parent) return; } - m_re->m_paths.clear(); - m_re->m_imgs.clear(); + m_re->clearPrintState(); + m_re->setPaths(paths); - m_re->m_paths = paths; QStringList tempExsitPaths; // 保存存在的图片路径 for (const QString &path : paths) { QString errMsg; @@ -61,14 +60,14 @@ void PrintHelper::showPrintDialog(const QStringList &paths, QWidget *parent) if (imgReadreder.imageCount() > 1) { for (int imgindex = 0; imgindex < imgReadreder.imageCount(); imgindex++) { imgReadreder.jumpToImage(imgindex); - m_re->m_imgs << imgReadreder.read(); + m_re->appendImage(imgReadreder.read()); } } else { // QImage不应该多次赋值,所以换到这里来,修复style问题 QImage img; LibUnionImage_NameSpace::loadStaticImageFromFile(path, img, errMsg); if (!img.isNull()) { - m_re->m_imgs << img; + m_re->appendImage(img); } } tempExsitPaths << paths; @@ -108,14 +107,19 @@ void PrintHelper::showPrintDialog(const QStringList &paths, QWidget *parent) int ret = QDialog::Accepted; #endif + // DTKWidget 在 5.6.9 版本前,无论是否打印,只会返回相同值 0 ,区分版本判断 (DTKWIDGET_CLASS_DWaterMarkHelper在 5.6.9 提供) + // 没有直接以 DTKCore(DTK_VERSION_CHECK) 版本判断,DTKCore 和 DTKWidget 版本可能不同 +#ifndef DTKWIDGET_CLASS_DWaterMarkHelper + if (m_re->isPrinted()) { +#else if (QDialog::Accepted == ret) { +#endif if (!tempExsitPaths.isEmpty()) { PermissionConfig::instance()->triggerPrint(tempExsitPaths.first()); } } - m_re->m_paths.clear(); - m_re->m_imgs.clear(); + m_re->clearPrintState(); } RequestedSlot::RequestedSlot(QObject *parent) @@ -125,6 +129,32 @@ RequestedSlot::RequestedSlot(QObject *parent) RequestedSlot::~RequestedSlot() {} +void RequestedSlot::clearPrintState() +{ + m_paths.clear(); + m_imgs.clear(); + m_printed = false; +} + +/** + @brief 设置打印文件路径 `paths` + */ +void RequestedSlot::setPaths(const QStringList &paths) +{ + m_paths = paths; +} + +/** + @brief 追加打印图片数据 `img` + */ +void RequestedSlot::appendImage(const QImage &img) +{ + m_imgs << img; +} + +/** + @brief dtk打印组件请求绘制页面,将打印信息绘制到 `_printer` 中 + */ void RequestedSlot::paintRequestSync(DPrinter *_printer) { // 由于之前再度修改了打印的逻辑,导致了相同图片不在被显示,多余多页tiff来说不合理 @@ -154,4 +184,8 @@ void RequestedSlot::paintRequestSync(DPrinter *_printer) } } painter.end(); + + if (!m_printed && 0 != indexNum) { + m_printed = true; + } } diff --git a/libimageviewer/widgets/printhelper.h b/libimageviewer/widgets/printhelper.h index caa56ec8..62e5e0d1 100755 --- a/libimageviewer/widgets/printhelper.h +++ b/libimageviewer/widgets/printhelper.h @@ -21,12 +21,20 @@ class RequestedSlot : public QObject explicit RequestedSlot(QObject *parent = nullptr); ~RequestedSlot(); -private slots: - void paintRequestSync(DPrinter *_printer); + // 清理打印状态,当前是否触发打印 + void clearPrintState(); + inline bool isPrinted() { return m_printed; } -public: + void setPaths(const QStringList &paths); + void appendImage(const QImage &img); + +private: + Q_SLOT void paintRequestSync(DPrinter *_printer); + +private: QStringList m_paths; QList m_imgs; + bool m_printed = false; }; class PrintHelper : public QObject