-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
92 lines (79 loc) · 3.09 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
/*
* Copyright 2019 Green Radio Software Solutions (GRSS)
* Released under GPL3 License
* Test app - An app written to test spell check library
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, either version 3 of the License, or
any later version.
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 "mainwindow.h"
#include "ui_mainwindow.h"
#include "globals.h"
QString highlightedText;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
dictionaryFile = new QFile(qApp->applicationDirPath()+"/../spellchecker/dictionary.txt",this);
if(dictionaryFile->exists()){
ui->plainTextEditEditor->appendPlainText("Found dictionary... OK");
spellChecker = new ClassSpellChecker(true, dictionaryFile, ui->plainTextEditEditor);
//threading not used until signal/slots are incoporated
//seems to run fine in main thread
// spellCheckerThread = new QThread(this);
// spellChecker->moveToThread(spellCheckerThread);
}
else {
spellChecker = nullptr;
ui->plainTextEditEditor->appendPlainText("ERROR: Dictionary not found!");
ui->plainTextEditEditor->appendPlainText(qApp->applicationDirPath()+"/../spellchecker/dictionary.txt");
}
}//MainWindow
MainWindow::~MainWindow()
{
delete ui;
if(spellChecker != nullptr){
delete spellChecker;
delete dictionaryFile;
// delete spellCheckerThread;
}
}//MainWindow
void MainWindow::on_plainTextEditEditor_textChanged()
{
static bool isBusy = false;
if(isBusy){
if(spellChecker != nullptr){
if(spellChecker->getIsRehighlighting()){
spellChecker->setIsRehighlighting(false);
QApplication::processEvents();
}
}
return;
}
isBusy = true;
if(spellChecker != nullptr){
if(ui->plainTextEditEditor->toPlainText().size() > (editorDocument.size()+10)){
spellChecker->spellCheck(ui->plainTextEditEditor->toPlainText(), true);
}
else {
QTextCursor textCursor(ui->plainTextEditEditor->textCursor());
textCursor.select(QTextCursor::LineUnderCursor);
QString selectedWord = textCursor.selectedText();
spellChecker->spellCheck(selectedWord, false);
}
editorDocument = ui->plainTextEditEditor->toPlainText();
}
isBusy = false;
}//on_plainTextEditEditor_textChanged
void MainWindow::on_plainTextEditEditor_customContextMenuRequested(const QPoint &pos)
{
spellChecker->createContextMenu(pos);
}//on_plainTextEditEditor_customContextMenuRequested