|
@@ -0,0 +1,87 @@
|
|
1
|
+@* Saved Printers.
|
|
2
|
+
|
|
3
|
+\noindent In most cases it's best to handle printing in a way that is common
|
|
4
|
+across many applications. Put a Print menu option in a File menu, bring up the
|
|
5
|
+platform's standard print dialog, and allow people to take full advantage of
|
|
6
|
+the flexibility this provides.
|
|
7
|
+
|
|
8
|
+In more specialized use cases, however, it may make more sense to provide
|
|
9
|
+faster access to a printer that might not be the default printer for that
|
|
10
|
+computer. The first use in Typica where this makes sense is in printing tags
|
|
11
|
+that can follow the coffee and uniquely identify that batch. Using a full sheet
|
|
12
|
+of paper for this might be excessive and time consuming. Instead, it might make
|
|
13
|
+sense to get a small, inexpensive thermal receipt printer to keep at the
|
|
14
|
+roaster. If this were not the default printer, it would quickly become tedious
|
|
15
|
+to bring up the print dialog and change the selected printer after every batch.
|
|
16
|
+
|
|
17
|
+In cases like this, it would be better to provide a combo box in the window
|
|
18
|
+where a printer can be selected and remembered as the default printer just for
|
|
19
|
+that particular use, and allowing people to print directly to that printer
|
|
20
|
+without going through extra steps.
|
|
21
|
+
|
|
22
|
+@(printerselector.h@>=
|
|
23
|
+#include <QPrinterInfo>
|
|
24
|
+#include <QComboBox>
|
|
25
|
+
|
|
26
|
+#ifndef TypicaPrinterSelectorHeader
|
|
27
|
+#define TypicaPrinterSelectorHeader
|
|
28
|
+
|
|
29
|
+class PrinterSelector : public QComboBox@/
|
|
30
|
+{
|
|
31
|
+ @[Q_OBJECT@]@;
|
|
32
|
+ public:
|
|
33
|
+ PrinterSelector();
|
|
34
|
+};
|
|
35
|
+
|
|
36
|
+#endif
|
|
37
|
+
|
|
38
|
+@ The main file also requires this header.
|
|
39
|
+
|
|
40
|
+@<Header files to include@>=
|
|
41
|
+#include "printerselector.h"
|
|
42
|
+
|
|
43
|
+@ Implementation of this class is in a separate file.
|
|
44
|
+
|
|
45
|
+@(printerselector.cpp@>=
|
|
46
|
+#include "printerselector.h"
|
|
47
|
+
|
|
48
|
+@<PrinterSelector implementation@>@;
|
|
49
|
+
|
|
50
|
+@ The constructor looks at the list of available printers and populates itself
|
|
51
|
+with these.
|
|
52
|
+
|
|
53
|
+@<PrinterSelector implementation@>=
|
|
54
|
+PrinterSelector::PrinterSelector() : QComboBox(NULL)
|
|
55
|
+{
|
|
56
|
+ QList<QPrinterInfo> printers = QPrinterInfo::availablePrinters();
|
|
57
|
+ foreach(QPrinterInfo info, printers)
|
|
58
|
+ {
|
|
59
|
+ addItem(info.printerName());
|
|
60
|
+ }
|
|
61
|
+}
|
|
62
|
+
|
|
63
|
+@ The host environment is informed of this class in the usual way starting with
|
|
64
|
+a constructor function prototype.
|
|
65
|
+
|
|
66
|
+@<Function prototypes for scripting@>=
|
|
67
|
+QScriptValue constructPrinterSelector(QScriptContext *context,
|
|
68
|
+ QScriptEngine *engine);
|
|
69
|
+
|
|
70
|
+@ The engine is informed of this function.
|
|
71
|
+
|
|
72
|
+@<Set up the scripting engine@>=
|
|
73
|
+constructor = engine->newFunction(constructPrinterSelector);
|
|
74
|
+engine->globalObject().setProperty("PrinterSelector", constructor);
|
|
75
|
+
|
|
76
|
+@ There is nothing special about the constructor. If there were additional
|
|
77
|
+properties needed beyond those supplied by |setQComboBoxProperties()| it would
|
|
78
|
+make sense to add another function to the chain for setting script value
|
|
79
|
+properties.
|
|
80
|
+
|
|
81
|
+@<Functions for scripting@>=
|
|
82
|
+QScriptValue constructPrinterSelector(QScriptContext *, QScriptEngine *engine)
|
|
83
|
+{
|
|
84
|
+ QScriptValue object = engine->newQObject(new PrinterSelector);
|
|
85
|
+ setQComboBoxProperties(object, engine);
|
|
86
|
+ return object;
|
|
87
|
+}
|