Browse Source

Improvements to direct printing

Neal Wilson 6 years ago
parent
commit
0978ab8c72
3 changed files with 40 additions and 2 deletions
  1. 30
    1
      src/printerselector.w
  2. 4
    0
      src/typica.w
  3. 6
    1
      src/webview.w

+ 30
- 1
src/printerselector.w View File

@@ -61,11 +61,15 @@ PrinterSelector::PrinterSelector() : QComboBox(NULL)
61 61
 }
62 62
 
63 63
 @ The host environment is informed of this class in the usual way starting with
64
-a constructor function prototype.
64
+a constructor function prototype. Another prototype is also needed for adding
65
+this to a layout from XML.
65 66
 
66 67
 @<Function prototypes for scripting@>=
67 68
 QScriptValue constructPrinterSelector(QScriptContext *context,
68 69
                                       QScriptEngine *engine);
70
+void addPrinterSelectorToLayout(QDomElement element,
71
+                                QStack<QWidget *> *widgetStack,
72
+                                QStack<QLayout *> *layoutStack);
69 73
 
70 74
 @ The engine is informed of this function.
71 75
 
@@ -85,3 +89,28 @@ QScriptValue constructPrinterSelector(QScriptContext *, QScriptEngine *engine)
85 89
 	setQComboBoxProperties(object, engine);
86 90
 	return object;
87 91
 }
92
+
93
+@ It should also be possible to add this to a layout from the XML portion of
94
+the configuration document.
95
+
96
+@<Functions for scripting@>=
97
+void addPrinterSelectorToLayout(QDomElement element, QStack<QWidget *> *,
98
+                                QStack<QLayout *> *layoutStack)
99
+{
100
+	PrinterSelector *selector = new PrinterSelector;
101
+	if(element.hasAttribute("id"))
102
+	{
103
+		selector->setObjectName(element.attribute("id"));
104
+	}
105
+	QBoxLayout *layout = qobject_cast<QBoxLayout *>(layoutStack->top());
106
+	layout->addWidget(selector);
107
+}
108
+
109
+@ This is added in the usual way.
110
+
111
+@<Additional box layout elements@>=
112
+else if(currentElement.tagName() == "printerselector")
113
+{
114
+	addPrinterSelectorToLayout(currentElement, widgetStack, layoutStack);
115
+}
116
+

+ 4
- 0
src/typica.w View File

@@ -6477,6 +6477,10 @@ else if(className == "QTabBar")
6477 6477
 {
6478 6478
 	setQTabBarProperties(value, engine);
6479 6479
 }
6480
+else if(className == "PrinterSelector")
6481
+{
6482
+	setQComboBoxProperties(value, engine);
6483
+}
6480 6484
 
6481 6485
 @ In the list of classes, the SaltTable entry is for a class which does not
6482 6486
 strictly exist on its own. It is, however, useful to provide some custom

+ 6
- 1
src/webview.w View File

@@ -135,7 +135,11 @@ QString TypicaWebView::saveXml()
135 135
 }
136 136
 
137 137
 @ Print functionality has been extended to allow an optional argument. If the
138
-name of a printer is passed in, the print dialog will be bypassed.
138
+name of a printer is passed in, the print dialog will be bypassed. Note that
139
+when bypassing the print dialog, page margins are set to 0. This is intentional
140
+as the use case is for printing to more specialized printers where default page
141
+margins are not appropriate and CSS can be customized to ensure that all
142
+information fits in the printable area with the assumption of no margin.
139 143
 
140 144
 @<TypicaWebView implementation@>=
141 145
 void TypicaWebView::print(const QString &printerName)
@@ -144,6 +148,7 @@ void TypicaWebView::print(const QString &printerName)
144 148
 	if(!printerName.isEmpty())
145 149
 	{
146 150
 		printer->setPrinterName(printerName);
151
+		printer->setFullPage(true);
147 152
 		QWebView::print(printer);
148 153
 		return;
149 154
 	}

Loading…
Cancel
Save