Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion libimageviewer/service/permissionconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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接口从任务栏激活窗口
*/
Expand Down Expand Up @@ -188,14 +191,18 @@ bool PermissionConfig::isUnlimitPrint() const
if (checkAuthInvalid()) {
return true;
}
return -1 == printLimitCount;
return g_UnlimitPrintCount == printLimitCount;
}

/**
@brief 减少一次打印计数并发送打印计数变更信号 `printCountChanged`
*/
void PermissionConfig::reduceOnePrintCount()
{
if (g_UnlimitPrintCount == printLimitCount) {
return;
}

if (printLimitCount > 0) {
printLimitCount--;
Q_EMIT printCountChanged();
Expand Down Expand Up @@ -612,6 +619,9 @@ void PermissionConfig::initAuthorise(const QJsonObject &param)
}

printLimitCount = param.value("printCount").toInt(0);
if (printLimitCount < g_UnlimitPrintCount) {
printLimitCount = 0;
}
}

#ifdef DTKWIDGET_CLASS_DWaterMarkHelper
Expand Down
48 changes: 41 additions & 7 deletions libimageviewer/widgets/printhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,25 +50,24 @@ 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;
QImageReader imgReadreder(path);
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;
Expand Down Expand Up @@ -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)
Expand All @@ -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来说不合理
Expand Down Expand Up @@ -154,4 +184,8 @@ void RequestedSlot::paintRequestSync(DPrinter *_printer)
}
}
painter.end();

if (!m_printed && 0 != indexNum) {
m_printed = true;
}
}
14 changes: 11 additions & 3 deletions libimageviewer/widgets/printhelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<QImage> m_imgs;
bool m_printed = false;
};

class PrintHelper : public QObject
Expand Down