Line 0
Link Here
|
|
|
1 |
# Origin: https://github.com/gottcode/focuswriter/commit/e7311fb017782a0bbf017d0055f6f01b36233b89 |
2 |
# Subject: FIXED: Possible delay on start when creating non-native printer. |
3 |
# Origin: https://github.com/gottcode/focuswriter/commit/1423754c4eae874857ce34613bddead8224ee887 |
4 |
# Subject: FIXED: Memory leak from creating multiple printers. |
5 |
# |
6 |
# Patch with some addition. |
7 |
|
8 |
--- src/stack.cpp.orig 2016-10-13 09:37:59 UTC |
9 |
+++ src/stack.cpp |
10 |
@@ -55,6 +55,7 @@ |
11 |
Stack::Stack(QWidget* parent) : |
12 |
QWidget(parent), |
13 |
m_symbols_dialog(0), |
14 |
+ m_printer(0), |
15 |
m_current_document(0), |
16 |
m_footer_margin(0), |
17 |
m_header_margin(0), |
18 |
@@ -78,17 +79,6 @@ Stack::Stack(QWidget* parent) : |
19 |
m_find_dialog = new FindDialog(this); |
20 |
connect(m_find_dialog, SIGNAL(findNextAvailable(bool)), this, SIGNAL(findNextAvailable(bool))); |
21 |
|
22 |
- m_printer = new QPrinter(QPrinter::HighResolution); |
23 |
-#if (QT_VERSION >= QT_VERSION_CHECK(5,3,0)) |
24 |
- m_printer->setPageSize(QPageSize(QPageSize::Letter)); |
25 |
- m_printer->setPageOrientation(QPageLayout::Portrait); |
26 |
- m_printer->setPageMargins(QMarginsF(1.0, 1.0, 1.0, 1.0), QPageLayout::Inch); |
27 |
-#else |
28 |
- m_printer->setPageSize(QPrinter::Letter); |
29 |
- m_printer->setOrientation(QPrinter::Portrait); |
30 |
- m_printer->setPageMargins(1.0, 1.0, 1.0, 1.0, QPrinter::Inch); |
31 |
-#endif |
32 |
- |
33 |
connect(ActionManager::instance(), SIGNAL(insertText(QString)), this, SLOT(insertSymbol(QString))); |
34 |
|
35 |
m_layout = new QGridLayout(this); |
36 |
@@ -129,7 +119,8 @@ Stack::~Stack() |
37 |
{ |
38 |
m_theme_renderer->wait(); |
39 |
|
40 |
- delete m_printer; |
41 |
+ if (m_printer) |
42 |
+ delete m_printer; |
43 |
} |
44 |
|
45 |
//----------------------------------------------------------------------------- |
46 |
@@ -397,6 +388,7 @@ void Stack::pasteUnformatted() |
47 |
|
48 |
void Stack::pageSetup() |
49 |
{ |
50 |
+ initPrinter(); |
51 |
QPageSetupDialog dialog(m_printer, this); |
52 |
dialog.exec(); |
53 |
} |
54 |
@@ -405,6 +397,7 @@ void Stack::pageSetup() |
55 |
|
56 |
void Stack::print() |
57 |
{ |
58 |
+ initPrinter(); |
59 |
m_current_document->print(m_printer); |
60 |
} |
61 |
|
62 |
@@ -835,3 +828,23 @@ void Stack::updateMenuIndexes() |
63 |
} |
64 |
|
65 |
//----------------------------------------------------------------------------- |
66 |
+ |
67 |
+void Stack::initPrinter() |
68 |
+{ |
69 |
+ if (m_printer) { |
70 |
+ return; |
71 |
+ } |
72 |
+ |
73 |
+ m_printer = new QPrinter(QPrinter::HighResolution); |
74 |
+#if (QT_VERSION >= QT_VERSION_CHECK(5,3,0)) |
75 |
+ m_printer->setPageSize(QPageSize(QPageSize::Letter)); |
76 |
+ m_printer->setPageOrientation(QPageLayout::Portrait); |
77 |
+ m_printer->setPageMargins(QMarginsF(1.0, 1.0, 1.0, 1.0), QPageLayout::Inch); |
78 |
+#else |
79 |
+ m_printer->setPageSize(QPrinter::Letter); |
80 |
+ m_printer->setOrientation(QPrinter::Portrait); |
81 |
+ m_printer->setPageMargins(1.0, 1.0, 1.0, 1.0, QPrinter::Inch); |
82 |
+#endif |
83 |
+} |
84 |
+ |
85 |
+//----------------------------------------------------------------------------- |
86 |
--- src/stack.h.orig 2016-10-13 09:37:59 UTC |
87 |
+++ src/stack.h |
88 |
@@ -140,6 +140,7 @@ private: |
89 |
#if (QT_VERSION < QT_VERSION_CHECK(5,6,0)) |
90 |
qreal devicePixelRatioF() const { return devicePixelRatio(); } |
91 |
#endif |
92 |
+ void initPrinter(); |
93 |
|
94 |
private: |
95 |
AlertLayer* m_alerts; |