-
Notifications
You must be signed in to change notification settings - Fork 0
/
textprinterwindow.cpp
executable file
·274 lines (248 loc) · 8.34 KB
/
textprinterwindow.cpp
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
#include "textprinterwindow.h"
#include "ui_textprinterwindow.h"
#include "respeqtsettings.h"
#include <QFileDialog>
#include <QPrintDialog>
#include <QPrinter>
// Includes, Globals and various additional class declarations //
#include <QString>
#include <QFontComboBox>
#include <QMessageBox>
int effAtasciiFont = 0;
int effFontSize = 0;
bool showAscii = true;
bool showAtascii = true;
int fontSize = 9;
QString atasciiFont("Atari Classic Chunky");
TextPrinterWindow::TextPrinterWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::TextPrinterWindow)
{
ui->setupUi(this);
QFont f;
f.setFixedPitch(true);
f.setFamily("monospace");
ui->printerTextEditASCII->setFont(f);
// Set Initial Font for ATASCII text Window //
QFont a;
a.setFixedPitch(true);
a.setFamily(atasciiFont);
a.setPointSize(fontSize);
ui->printerTextEdit->setFont(a);
ui->atasciiFontName->setText(atasciiFont + " - " + QString("%1").arg(fontSize));
effAtasciiFont = 1;
connect(ui->asciiFontName, SIGNAL(currentFontChanged(QFont)), this, SLOT(asciiFontChanged(QFont)));
}
TextPrinterWindow::~TextPrinterWindow()
{
delete ui;
}
void TextPrinterWindow::changeEvent(QEvent *e)
{
QMainWindow::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
void TextPrinterWindow::closeEvent(QCloseEvent *e)
{
// Save Current TexPrinterWindow Position and size //
if (respeqtSettings->saveWindowsPos()) {
respeqtSettings->setLastPrtHorizontalPos(TextPrinterWindow::geometry().x());
respeqtSettings->setLastPrtVerticalPos(TextPrinterWindow::geometry().y());
respeqtSettings->setLastPrtWidth(TextPrinterWindow::geometry().width());
respeqtSettings->setLastPrtHeight(TextPrinterWindow::geometry().height());
}
emit closed();
e->accept();
}
void TextPrinterWindow::print(const QString &text)
{
// DO both ASCII and ATASCII windows //
QTextCursor c = ui->printerTextEdit->textCursor();
c.movePosition(QTextCursor::End, QTextCursor::MoveAnchor);
ui->printerTextEdit->setTextCursor(c);
ui->printerTextEdit->insertPlainText(text);
int n = text.size();
QByteArray textASCII;
textASCII.append(text);
// Disable ATASCII Inverse Video for ASCII window //
for (int x = 0; x <= n-1; ++x){
int byte = textASCII[x];
if (byte < 0){
textASCII[x] = byte ^ 0x80;
}
}
c = ui->printerTextEditASCII->textCursor();
c.movePosition(QTextCursor::End, QTextCursor::MoveAnchor);
ui->printerTextEditASCII->setTextCursor(c);
ui->printerTextEditASCII->insertPlainText(textASCII);
}
void TextPrinterWindow::on_actionWord_wrap_triggered()
{
if (ui->actionWord_wrap->isChecked()) {
ui->printerTextEdit->setLineWrapMode(QPlainTextEdit::WidgetWidth);
//
ui->printerTextEditASCII->setLineWrapMode(QPlainTextEdit::WidgetWidth);
} else {
ui->printerTextEdit->setLineWrapMode(QPlainTextEdit::NoWrap);
//
ui->printerTextEditASCII->setLineWrapMode(QPlainTextEdit::NoWrap);
}
}
void TextPrinterWindow::on_actionClear_triggered()
{
ui->printerTextEdit->clear();
//
ui->printerTextEditASCII->clear();
ui->actionStrip_Line_Numbers->setEnabled(true);
}
// Toggle ATASCII fonts //
void TextPrinterWindow::on_actionAtasciiFont_triggered()
{
++effAtasciiFont;
if (effAtasciiFont == 4){
effAtasciiFont = 1;
}
switch (effAtasciiFont) {
case 1 :
atasciiFont = "Atari Classic Chunky";
break;
case 2 :
atasciiFont = "Atari Classic Smooth";
break;
case 3 :
atasciiFont = "Atari Classic Extrasmooth";
}
QFont(a);
a.setFamily(atasciiFont);
a.setPointSize(fontSize);
ui->printerTextEdit->setFont(a);
ui->atasciiFontName->setText(atasciiFont + " - " + QString("%1").arg(fontSize));
}
// Toggle Atari Output Font Size in both ATASCII and ASCII Windows //
void TextPrinterWindow::on_actionFont_Size_triggered()
{
++effFontSize;
if (effFontSize == 4){
effFontSize = 1;
}
switch (effFontSize) {
case 1 :
fontSize = 6;
break;
case 2 :
fontSize = 9;
break;
case 3 :
fontSize = 12;
}
QFont(a);
a.setFamily(atasciiFont);
a.setPointSize(fontSize);
ui->printerTextEdit->setFont(a);
ui->atasciiFontName->setText(atasciiFont + " - " + QString("%1").arg(fontSize));
QFont (f);
f.setFamily(ui->asciiFontName->currentFont().toString());
f.setPointSize(fontSize);
ui->printerTextEditASCII->setFont(f);
}
// Change ASCII text window font //
void TextPrinterWindow::asciiFontChanged(const QFont &)
{
ui->printerTextEditASCII->setFont(ui->asciiFontName->currentFont());
}
// Hide/Show Ascii text window //
void TextPrinterWindow::on_actionHideShow_Ascii_triggered()
{
if (showAscii) {
ui->printerTextEditASCII->hide();
ui->asciiFontName->hide();
showAscii = false;
}
else {
ui->printerTextEditASCII->show();
ui->asciiFontName->show();
showAscii = true;
}
}
// Hide/Show Atascii text window //
void TextPrinterWindow::on_actionHideShow_Atascii_triggered()
{
if (showAtascii) {
ui->printerTextEdit->hide();
ui->atasciiFontName->hide();
showAtascii = false;
}
else {
ui->printerTextEdit->show();
ui->atasciiFontName->show();
showAtascii = true;
}
}
// Send to Printer Action //
void TextPrinterWindow::on_actionPrint_triggered()
{
QPrinter printer;
QPrintDialog *dialog = new QPrintDialog(&printer, this);
if (dialog->exec() != QDialog::Accepted)
return;
ui->printerTextEdit->print(&printer);
}
void TextPrinterWindow::on_actionSave_triggered()
{
QString fileName = QFileDialog::getSaveFileName(this, tr("Save printer text output"), respeqtSettings->lastPrinterTextDir(),
tr("Text files (*.txt);;All files (*)"), 0);
if (fileName.isEmpty()) {
return;
}
respeqtSettings->setLastPrinterTextDir(QFileInfo(fileName).absolutePath());
QFile file(fileName);
file.open(QFile::WriteOnly | QFile::Truncate | QFile::Text);
file.write(ui->printerTextEdit->toPlainText().toLatin1());
}
void TextPrinterWindow::on_actionStrip_Line_Numbers_triggered()
{
bool number;
bool lineNumberFound = false;
QString plainTextEditContents = ui->printerTextEdit->toPlainText();
QStringList lines = plainTextEditContents.split("\n");
for (int i = 0; i < lines.size(); ++i) {
int x = lines.at(i).indexOf(" ");
if (x > 0) {
lines.at(i).mid(1,x-1).toInt(&number);
if (number) {
lineNumberFound = true;
break;
}
}
}
if (!lineNumberFound) {
QMessageBox::information (this, tr("Stripping Line Numbers.."),tr("The text does not seem to contain any line numbers!"),QMessageBox::Ok);
} else {
ui->printerTextEdit->clear();
ui->printerTextEditASCII->clear();
for (int i = 0; i < lines.size(); ++i) {
int x = lines.at(i).indexOf(" ");
if (x > 0) {
lines.at(i).mid(1,x-1).toInt(&number);
if (!number) {
x = -1;
}
}
QTextCursor c = ui->printerTextEdit->textCursor();
c.movePosition(QTextCursor::End, QTextCursor::MoveAnchor);
ui->printerTextEdit->setTextCursor(c);
ui->printerTextEdit->insertPlainText(lines.at(i).mid(x+1)+"\n");
c = ui->printerTextEditASCII->textCursor();
c.movePosition(QTextCursor::End, QTextCursor::MoveAnchor);
ui->printerTextEditASCII->setTextCursor(c);
ui->printerTextEditASCII->insertPlainText(lines.at(i).mid(x+1)+"\n");
}
// ui->actionStrip_Line_Numbers->setEnabled(false);
}
}