-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmainwindow.cpp
334 lines (289 loc) · 10.5 KB
/
mainwindow.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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "tools.h"
#include <QFileDialog>
#include <QDebug>
#include <QKeyEvent>
#include <QDateTime>
#include <QDialog>
#include <QtWidgets>
#include <QPushButton>
#include <stdio.h>
#include <string.h>
//#include <iostream>
#include <fstream>
//#include <sstream>
/*
QString::fromStdString(string) <- from string to Qstring
QString::number(int) <- from int to QString
string = QString.toUtf8().constData() from QString to string
QString::fromStdString(formattext(QString::number(d1).toUtf8().constData(),1,1))
std::to_string(42) int to string
*/
using namespace std;
QString greek_lexicon,hebrew_lexicon;
QString hmem[10];
int hmempos = -1;
QString source,pwd;
bool nightmode=true;
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
char csettings[13]="settings.txt";
pwd = QDir::currentPath();
pwd += "/tmp.htm";
//qDebug() << pwd;
createSettings(pwd.toUtf8().constData(),"");
source = "file:///"+pwd;
ui->setupUi(this);
ui->lineEdit->installEventFilter(this);
ui->textBrowser->installEventFilter(this);
setCentralWidget(ui->frame_3);
ui->lineEdit->focusWidget();
ui->textBrowser->setOpenExternalLinks(true);
QString font = readSettings("settings.txt","font");
greek_lexicon = readSettings("settings.txt","greek");
hebrew_lexicon = readSettings("settings.txt","hebrew");
QString nightm = readSettings("settings.txt","nightmode");
//qDebug() << font;
if (font != "none") {
QFont f1;
f1.fromString(font);
ui->textBrowser->setFont(f1);
}
if (greek_lexicon == "none") {
greek_lexicon = QFileDialog::getExistingDirectory(this,"Select Greek lexicon's directory",".");
writeSettings(csettings,"greek",greek_lexicon.toUtf8().constData());
}
if (hebrew_lexicon == "none") {
hebrew_lexicon = QFileDialog::getExistingDirectory(this,"Select Hebrew lexicon's directory",".");
writeSettings(csettings,"hebrew",hebrew_lexicon.toUtf8().constData());
}
if (nightm == "true") {
nightmode = true;
ui->action_Nightmode->setChecked(true);
} else {
nightmode = false;
ui->action_Nightmode->setChecked(false);
}
if (nightmode) ui->textBrowser->setStyleSheet("background-color: #1f1414; color: white");
if (nightmode) ui->lineEdit->setStyleSheet("background-color: #1f1414; color: white");
ui->textBrowser->setSource(source);
}
MainWindow::~MainWindow()
{
QString location = pwd;
QFile *File = new QFile(location);
File->remove();
delete ui;
}
bool MainWindow::eventFilter(QObject* obj, QEvent *event)
{
if (obj == ui->lineEdit)
{
if (event->type() == QEvent::KeyPress)
{
QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
if (keyEvent->key() == Qt::Key_Up)
{
//ui->lineEdit->setText("Up Key");
if (hmempos > 0) {
hmempos --;
ui->lineEdit->setText(hmem[hmempos]);
//qDebug() << hmem[hmempos] << hmempos;
}
return true;
}
else if(keyEvent->key() == Qt::Key_Down)
{
//ui->lineEdit->setText("Down Key");
if (hmempos > -1) {
if (hmempos < 10 && hmem[hmempos] != "") {
if (hmem[hmempos] != "") hmempos ++;
//qDebug() << hmem[hmempos] << hmempos;
if(hmempos <= 9 ) ui->lineEdit->setText(hmem[hmempos]);
else ui->lineEdit->setText("");
//if (hmem[hmempos+2] == "") ui->lineEdit->setText("");
}
}
//if (hmempos == 10) ui->lineEdit->setText("");
return true;
}
}
return false;
} else if (obj == ui->textBrowser)
{
//qDebug() << event->type();
if (event->type() == QEvent::InputMethodQuery)
{
// QString html = ui->textBrowser->toHtml();
// while (replacestring(pwd,"../greek/",""));
// while (replacestring(pwd,"/greek/",""));
// ui->textBrowser->setHtml(html);
//qDebug() << html;
}
}
return false;
}
void MainWindow::keymem(QString memstr)
{
if (hmem[9] != "") {
for (int i=0;i<9;i++){
hmem[i] = hmem[i+1];
}
}
hmem[9] = "";
for (hmempos=1;hmempos<10;hmempos++){
if (hmem[hmempos-1] == "") break;
}
hmem[hmempos-1] = memstr;
}
void MainWindow::on_lineEdit_returnPressed()
{
QString backbutton = "<a href=\"javascript:history.back()\">Go Back</a>";
QString html="";
std::string line = ui->lineEdit->text().toUtf8().constData();
QString anumber=QString::fromStdString(line);
int nr=anumber.toInt();
int ns1 = getwordnumericvalue(line,0,0,0);
int ns2 = getwordnumericvalue(line,0,0,4);
int ns3 = getwordnumericvalue(line,0,0,5);
QString tphrase = ui->lineEdit->text();
html = "<left><h2>Phrase: "+tphrase+"</h2></left>";
if (nr==0) {
html += readbib(ns1,"EO",hebrew_lexicon,greek_lexicon);
html += readbib(ns2,"Jew",hebrew_lexicon,greek_lexicon);
html += readbib(ns3,"Sum",hebrew_lexicon,greek_lexicon);
} else {
html += readbib(nr,"EO",hebrew_lexicon,greek_lexicon);
html += readbib(nr,"Jew",hebrew_lexicon,greek_lexicon);
html += readbib(nr,"Sum",hebrew_lexicon,greek_lexicon);
}
ui->textBrowser->append("<html>"+html+"</html>");
savelog(html,pwd);
//qDebug() << html+" qstring";
keymem(tphrase);
ui->lineEdit->clear();
}
void MainWindow::on_actionSelect_Greek_lexicon_triggered()
{
char csettings[13]="settings.txt";
greek_lexicon = QFileDialog::getExistingDirectory(this,"Select Greek lexicon's directory",".");
writeSettings(csettings,"greek",greek_lexicon.toUtf8().constData());
}
void MainWindow::on_actionSelect_Hebrew_lexicon_triggered()
{
char csettings[13]="settings.txt";
hebrew_lexicon = QFileDialog::getExistingDirectory(this,"Select Hebrew lexicon's directory",".");
writeSettings(csettings,"hebrew",hebrew_lexicon.toUtf8().constData());
}
void MainWindow::doPrint(QPrinter * printer)
{
QTime ct = QTime::currentTime();
//ui->textBrowser->print(printer);
printer->newPage();
printer->setDocName("Bible Lexicon - "+ct.currentTime().toString());
ui->textBrowser->print(printer);
}
void MainWindow::on_action_Print_triggered()
{
QPrintPreviewDialog * printPreview = new QPrintPreviewDialog(this);
connect(printPreview, SIGNAL(paintRequested(QPrinter *)), this, SLOT(doPrint(QPrinter *)));
printPreview->exec();
}
void MainWindow::on_action_Save_output_triggered()
{
//QFileDialog saveAsdialog(this);
//QString filename = saveAsdialog.getSaveFileName(this, tr("Save file"), ".", tr("Files (*.htm)"));
const QString format = "htm";
QString initialPath = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
if (initialPath.isEmpty())
initialPath = QDir::currentPath();
initialPath += tr("/untitled.") + format;
QFileDialog fileDialog(this, tr("Save Output As"), initialPath);
fileDialog.setAcceptMode(QFileDialog::AcceptSave);
fileDialog.setFileMode(QFileDialog::AnyFile);
fileDialog.setDirectory(initialPath);
if (fileDialog.exec() != QDialog::Accepted)
return;
const QString fileName = fileDialog.selectedFiles().first();
savelog(ui->textBrowser->toHtml(),fileName);
//}
}
void MainWindow::savelog(QString line, QString filename)
{
std::ofstream fout; // Create Object of Ofstream
std::ifstream fin;
fout.open (filename.toUtf8().constData(),ios::app); // Append mode
fin.open(filename.toUtf8().constData());
if(fin.is_open())
fout<< line.toUtf8().constData(); // Writing data to file
fin.close();
fout.close(); // Closing the file
line = "";
}
void MainWindow::on_action_Clear_output_triggered()
{
ui->textBrowser->clear();
}
void MainWindow::saveScreenshot()
{
QScreen *screen = QGuiApplication::primaryScreen();
if (const QWindow *window = windowHandle())
screen = window->screen();
if (!screen)
return;
originalPixmap = screen->grabWindow(QWidget::hasFocus(),MainWindow::x(),MainWindow::y(),MainWindow::width(),MainWindow::height());
const QString format = "png";
QString initialPath = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation);
if (initialPath.isEmpty())
initialPath = QDir::currentPath();
initialPath += tr("/untitled.") + format;
QFileDialog fileDialog(this, tr("Save As"), initialPath);
fileDialog.setAcceptMode(QFileDialog::AcceptSave);
fileDialog.setFileMode(QFileDialog::AnyFile);
fileDialog.setDirectory(initialPath);
QStringList mimeTypes;
const QList<QByteArray> baMimeTypes = QImageWriter::supportedMimeTypes();
for (const QByteArray &bf : baMimeTypes)
mimeTypes.append(QLatin1String(bf));
fileDialog.setMimeTypeFilters(mimeTypes);
fileDialog.selectMimeTypeFilter("image/" + format);
fileDialog.setDefaultSuffix(format);
if (fileDialog.exec() != QDialog::Accepted)
return;
const QString fileName = fileDialog.selectedFiles().first();
if (!originalPixmap.save(fileName)) {
QMessageBox::warning(this, tr("Save Error"), tr("The image could not be saved to \"%1\".")
.arg(QDir::toNativeSeparators(fileName)));
}
}
void MainWindow::on_actionScreenShot_triggered()
{
saveScreenshot();
}
void MainWindow::on_actionSelect_Font_triggered()
{
//const QFontDialog::FontDialogOptions options = QFlag(fontDialogOptionsWidget->value());
bool ok;
QFont font = QFontDialog::getFont(&ok,QFont(ui->textBrowser->font()),this,"Select Font");
if (ok) {
writeSettings("settings.txt","font",font.toString().toUtf8().constData());
ui->textBrowser->setFont(font);
}
}
void MainWindow::on_action_Nightmode_toggled(bool arg1)
{
if (arg1) nightmode = true;
else nightmode = false;
if (nightmode) {
writeSettings("settings.txt","nightmode","true");
ui->textBrowser->setStyleSheet("background-color: #1f1414; color: white");
ui->lineEdit->setStyleSheet("background-color: #1f1414; color: white");
} else {
writeSettings("settings.txt","nightmode","false");
ui->textBrowser->setStyleSheet("");
ui->lineEdit->setStyleSheet("");
}
}