File: qprintdialog_duplex.diff

package info (click to toggle)
qtbase-opensource-src 5.11.3%2Bdfsg1-1%2Bdeb10u5
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 313,804 kB
  • sloc: cpp: 1,831,962; ansic: 318,856; xml: 113,585; python: 9,691; java: 7,209; asm: 4,023; perl: 2,151; sh: 1,790; yacc: 1,733; lex: 1,197; javascript: 469; makefile: 301; objc: 70
file content (76 lines) | stat: -rw-r--r-- 3,080 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
Description: Unix print dialog: Properly initialize duplex
Origin: upstream, https://code.qt.io/cgit/qt/qtbase.git/commit/?id=fa854f214a3c812e
Last-Update: 2019-02-07

--- a/src/printsupport/dialogs/qprintdialog_unix.cpp
+++ b/src/printsupport/dialogs/qprintdialog_unix.cpp
@@ -240,6 +240,10 @@ public:
     QDialogButtonBox *buttons;
     QPushButton *collapseButton;
     QPrinter::OutputFormat printerOutputFormat;
+private:
+    void setExplicitDuplexMode(QPrint::DuplexMode duplexMode);
+    // duplex mode explicitly set by user, QPrint::DuplexAuto otherwise
+    QPrint::DuplexMode explicitDuplexMode;
 };
 
 #if QT_CONFIG(cups)
@@ -479,7 +483,8 @@ void QPrintPropertiesDialog::accept()
 
 */
 QPrintDialogPrivate::QPrintDialogPrivate()
-    : top(nullptr), bottom(nullptr), buttons(nullptr), collapseButton(nullptr)
+    : top(nullptr), bottom(nullptr), buttons(nullptr), collapseButton(nullptr),
+      explicitDuplexMode(QPrint::DuplexAuto)
 {
     initResources();
 }
@@ -540,6 +545,10 @@ void QPrintDialogPrivate::init()
                      q, SLOT(_q_togglePageSetCombo(bool)));
 
     QObject::connect(collapseButton, SIGNAL(released()), q, SLOT(_q_collapseOrExpandDialog()));
+
+    QObject::connect(options.noDuplex, &QAbstractButton::clicked, q, [this] { setExplicitDuplexMode(QPrint::DuplexNone); });
+    QObject::connect(options.duplexLong, &QAbstractButton::clicked, q, [this] { setExplicitDuplexMode(QPrint::DuplexLongSide); });
+    QObject::connect(options.duplexShort, &QAbstractButton::clicked, q, [this] { setExplicitDuplexMode(QPrint::DuplexShortSide); });
 }
 
 // initialize printer options
@@ -559,13 +568,20 @@ void QPrintDialogPrivate::selectPrinter(
         else
             options.grayscale->setChecked(true);
 
-        switch (p->duplex()) {
-        case QPrinter::DuplexNone:
+        // keep duplex value explicitly set by user, if any, and selected printer supports it;
+        // use device default otherwise
+        QPrint::DuplexMode duplex;
+        if (explicitDuplexMode != QPrint::DuplexAuto && supportedDuplexMode.contains(explicitDuplexMode))
+            duplex = explicitDuplexMode;
+        else
+            duplex = top->d->m_currentPrintDevice.defaultDuplexMode();
+        switch (duplex) {
+        case QPrint::DuplexNone:
             options.noDuplex->setChecked(true); break;
-        case QPrinter::DuplexLongSide:
-        case QPrinter::DuplexAuto:
+        case QPrint::DuplexLongSide:
+        case QPrint::DuplexAuto:
             options.duplexLong->setChecked(true); break;
-        case QPrinter::DuplexShortSide:
+        case QPrint::DuplexShortSide:
             options.duplexShort->setChecked(true); break;
         }
         options.copies->setValue(p->copyCount());
@@ -667,6 +683,11 @@ static bool isValidPagesString(const QSt
 }
 #endif
 
+void QPrintDialogPrivate::setExplicitDuplexMode(const QPrint::DuplexMode duplexMode)
+{
+    explicitDuplexMode = duplexMode;
+}
+
 void QPrintDialogPrivate::setupPrinter()
 {
     // First setup the requested OutputFormat, Printer and Page Size first