forked from SoftProjector/softprojector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
printpreviewdialog.cpp
275 lines (234 loc) · 8.14 KB
/
printpreviewdialog.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
/***************************************************************************
//
// softProjector - an open source media projection software
// Copyright (C) 2017 Vladislav Kobzar
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation version 3 of the License.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
***************************************************************************/
#include "printpreviewdialog.hpp"
#include "ui_printpreviewdialog.h"
PrintPreviewDialog::PrintPreviewDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::PrintPreviewDialog)
{
ui->setupUi(this);
printer = new QPrinter;
ui->fontComboBox->setFont(ui->textEdit->font());
ui->spinBoxFontSize->setValue(ui->textEdit->font().pointSize());
// set default margins
on_comboBox_currentIndexChanged(0);
ui->doubleSpinBoxLeft->setValue(0.5);
ui->doubleSpinBoxTop->setValue(0.5);
ui->doubleSpinBoxRight->setValue(0.5);
ui->doubleSpinBoxBottom->setValue(0.5);
updateMargins();
// set default font
QFont f;
f.fromString("Arial,12,-1,5,50,0,0,0,0,0");
ui->fontComboBox->setCurrentFont(f);
}
PrintPreviewDialog::~PrintPreviewDialog()
{
delete ui;
}
void PrintPreviewDialog::on_fontComboBox_currentFontChanged(const QFont &f)
{
QFont font = f;
font.setPointSize(ui->spinBoxFontSize->value());
ui->textEdit->setFont(font);
}
void PrintPreviewDialog::on_spinBoxFontSize_valueChanged(int arg1)
{
QFont font = ui->textEdit->font();
font.setPointSize(arg1);
ui->textEdit->setFont(font);
}
void PrintPreviewDialog::setText(Song song)
// This will prepare print text edit for current song
{
QString s;
s = QString("%1 %2\n%3\n").arg(song.songbook_name).arg(song.number).arg(song.title);
// Do not print Tune, WordsBy, and MusicBy if they are empty
if(!song.tune.isEmpty())
s+= tr("Tune: %1\n").arg(song.tune);
if(!song.wordsBy.isEmpty() && !song.musicBy.isEmpty())
s+= tr("Words By: %1\tMusic By: %2\n\n").arg(song.wordsBy).arg(song.musicBy);
else if(!song.wordsBy.isEmpty() && song.musicBy.isEmpty())
s+= tr("Words By: %1\n\n").arg(song.wordsBy);
else if(song.wordsBy.isEmpty() && !song.musicBy.isEmpty())
s+= tr("Music By: %1\n\n").arg(song.musicBy);
else
s+= "\n";
// song.songText=song.songText.split("@$").join("\n\n");
// song.songText=song.songText.split("@%").join("\n");
s += song.songText;
//Check for notes
if(!song.notes.isEmpty())
s += tr("\n\nNotes:\n%1").arg(song.notes);
ui->textEdit->setText(s);
ui->spinBoxFontSize->setValue(14);// default font size for Songs
}
void PrintPreviewDialog::setText(QString bible, QString book, int chapter)
// This will prepare print text edit for Current chapter
{
QString s;
// get proper bible id if operator bible == "same"
QStringList bb = bible.split(",");
if(bb.at(0) == "same")
bible = bb.at(1); // primary bible
else
bible = bb.at(0); // operator bible
Bible b;
b.setBiblesId(bible);
b.loadOperatorBible();
// get bible name instead of id
bible = b.getBibleName();
QStringList clist;
// Get chapter with correct book id
for(int i(0);i<b.books.count();++i)
{
if(b.books.at(i).book == book)
{
clist = b.getChapter(b.books.at(i).bookId.toInt(),chapter);
break;
}
}
s = QString("%1\n%2 %3\n\n").arg(bible).arg(book).arg(chapter);
s += clist.join("\n");
ui->textEdit->setText(s);
ui->spinBoxFontSize->setValue(11);// default font size for Bible chapter
}
void PrintPreviewDialog::setText(Announcement announce)
{
QString s;
s = tr("Announcements: %1\n\n").arg(announce.title);
s += announce.text;
ui->textEdit->setText(s);
ui->spinBoxFontSize->setValue(14);// default font size for Announcements
}
void PrintPreviewDialog::setSchedule(QString scheduleName, const QList<Schedule> &schedule, bool printDetail)
{
QFileInfo fi(scheduleName);
scheduleName = fi.fileName();
scheduleName.remove(".spsc");
QString s;
// start
if(scheduleName.isEmpty())
s = "";
else
s = tr("SoftProject Schedule: ") + scheduleName + "\n\n";
if(printDetail)
{
}
else
{
foreach(const Schedule &si,schedule)
{
s += QString("%1: %2\n").arg(si.stype).arg(si.name);
}
}
ui->textEdit->setText(s);
ui->spinBoxFontSize->setValue(11); // default font size for spftProjector Schedule
}
void PrintPreviewDialog::on_pushButtonPDF_clicked()
{
QString filepath = QFileDialog::getSaveFileName(this,tr("Save PDF as"),".","Portable Document Format(*.pdf)");
if(filepath.isEmpty())
return;
printer->setOutputFormat(QPrinter::PdfFormat);
printer->setOutputFileName(filepath);
ui->textEdit->document()->print(printer);
}
void PrintPreviewDialog::on_pushButtonPrint_clicked()
{
printer->setOutputFormat(QPrinter::NativeFormat);
printer->setOutputFileName("");
QPrintDialog *dlg = new QPrintDialog(printer, this);
if (dlg->exec() != QDialog::Accepted)
return;
ui->textEdit->document()->print(printer);
}
void PrintPreviewDialog::on_comboBox_currentIndexChanged(int index)
{
//}
//void PrintPreviewDialog::on_comboBox_currentIndexChanged(const QString &arg1)
//{
// set margin boxes
double l(0),t(0),r(0),b(0);
if(index == 0)
printer->getPageMargins(&l,&t,&r,&b,QPrinter::Inch);
else if(index == 1)
printer->getPageMargins(&l,&t,&r,&b,QPrinter::Millimeter);
else if(index == 2)
printer->getPageMargins(&l,&t,&r,&b,QPrinter::DevicePixel);
else if(index == 3)
printer->getPageMargins(&l,&t,&r,&b,QPrinter::Point);
if(index == 0)
{
ui->doubleSpinBoxLeft->setDecimals(2);
ui->doubleSpinBoxLeft->setSingleStep(0.01);
ui->doubleSpinBoxTop->setDecimals(2);
ui->doubleSpinBoxTop->setSingleStep(0.01);
ui->doubleSpinBoxRight->setDecimals(2);
ui->doubleSpinBoxRight->setSingleStep(0.01);
ui->doubleSpinBoxBottom->setDecimals(2);
ui->doubleSpinBoxBottom->setSingleStep(0.01);
}
else
{
ui->doubleSpinBoxLeft->setDecimals(0);
ui->doubleSpinBoxLeft->setSingleStep(1.0);
ui->doubleSpinBoxTop->setDecimals(0);
ui->doubleSpinBoxTop->setSingleStep(1.0);
ui->doubleSpinBoxRight->setDecimals(0);
ui->doubleSpinBoxRight->setSingleStep(1.0);
ui->doubleSpinBoxBottom->setDecimals(0);
ui->doubleSpinBoxBottom->setSingleStep(1.0);
}
ui->doubleSpinBoxLeft->setValue(l);
ui->doubleSpinBoxTop->setValue(t);
ui->doubleSpinBoxRight->setValue(r);
ui->doubleSpinBoxBottom->setValue(b);
}
void PrintPreviewDialog::updateMargins()
{
double l = ui->doubleSpinBoxLeft->value();
double t = ui->doubleSpinBoxTop->value();
double r = ui->doubleSpinBoxRight->value();
double b = ui->doubleSpinBoxBottom->value();
if(ui->comboBox->currentIndex() == 0)
printer->setPageMargins(l,t,r,b,QPrinter::Inch);
else if(ui->comboBox->currentIndex() == 1)
printer->setPageMargins(l,t,r,b,QPrinter::Millimeter);
else if(ui->comboBox->currentIndex() == 2)
printer->setPageMargins(l,t,r,b,QPrinter::DevicePixel);
else if(ui->comboBox->currentIndex() == 3)
printer->setPageMargins(l,t,r,b,QPrinter::Point);
}
void PrintPreviewDialog::on_doubleSpinBoxLeft_editingFinished()
{
updateMargins();
}
void PrintPreviewDialog::on_doubleSpinBoxTop_editingFinished()
{
updateMargins();
}
void PrintPreviewDialog::on_doubleSpinBoxRight_editingFinished()
{
updateMargins();
}
void PrintPreviewDialog::on_doubleSpinBoxBottom_editingFinished()
{
updateMargins();
}