Kind-of working QTextEdit display

This commit is contained in:
Nicolas Mailloux 2021-06-11 18:58:23 -04:00
parent 7c03591c94
commit 6ad18aaba7
3 changed files with 76 additions and 151 deletions

View file

@ -15,6 +15,8 @@
#include <QFontDatabase> #include <QFontDatabase>
#include <QDirIterator> #include <QDirIterator>
#include <QDebug> #include <QDebug>
#include <QTextDocument>
#include <QTextCodec>
using namespace std; using namespace std;
@ -26,6 +28,10 @@ reader::reader(QWidget *parent) :
global::battery::showLowBatteryDialog = true; global::battery::showLowBatteryDialog = true;
global::battery::showCriticalBatteryAlert = true; global::battery::showCriticalBatteryAlert = true;
// QTextDocument
QTextDocument *text = new QTextDocument();
ui->setupUi(this); ui->setupUi(this);
ui->previousBtn->setProperty("type", "borderless"); ui->previousBtn->setProperty("type", "borderless");
ui->nextBtn->setProperty("type", "borderless"); ui->nextBtn->setProperty("type", "borderless");
@ -346,7 +352,7 @@ reader::reader(QWidget *parent) :
// Checking if we're waking from sleep; if so, do nothing there because the book should have already been parsed // Checking if we're waking from sleep; if so, do nothing there because the book should have already been parsed
if(wakeFromSleep != true) { if(wakeFromSleep != true) {
// Counting number of parsed files // Counting number of parsed files
split_total = setup_book(book_file, 0, true); split_total = setup_book(book_file);
split_files_number = split_total; split_files_number = split_total;
split_total = split_total - 1; split_total = split_total - 1;
@ -356,12 +362,12 @@ reader::reader(QWidget *parent) :
// Retrieve split_total from tmpfs // Retrieve split_total from tmpfs
string_checkconfig("/tmp/inkboxPageNumber"); string_checkconfig("/tmp/inkboxPageNumber");
split_total = checkconfig_str_val.toInt(); split_total = checkconfig_str_val.toInt();
setup_book(book_file, 0, true); setup_book(book_file);
} }
// Get text // Get text
QDir::setCurrent("/mnt/onboard/.adds/inkbox"); QDir::setCurrent("/mnt/onboard/.adds/inkbox");
setup_book(book_file, split_total, false); setup_book(book_file);
// Display text // Display text
// Checking saved font size if any // Checking saved font size if any
@ -494,100 +500,13 @@ reader::~reader()
delete ui; delete ui;
} }
int reader::setup_book(QString book, int i, bool run_parser) { int reader::setup_book(QString book) {
// Parse ebook QFile bookFile = book;
if(remount != false) { bookFile.open(QIODevice::ReadOnly);
QString mount_prog ("sh"); content = bookFile.readAll();
QStringList mount_args; bookFile.close();
mount_args << "split.sh";
QProcess *mount_proc = new QProcess();
mount_proc->start(mount_prog, mount_args);
mount_proc->waitForFinished();
remount = false;
}
else {
string_writeconfig("/inkbox/remount", "false");
QString mount_prog ("sh");
QStringList mount_args;
mount_args << "split.sh";
QProcess *mount_proc = new QProcess();
mount_proc->start(mount_prog, mount_args);
mount_proc->waitForFinished();
}
if(booktostr_ran != true) { ittext = content;
if(epub_file_match(book) == true) {
// Parsing ePUBs with epub2txt, thanks to GitHub:kevinboone
QString epubProg ("sh");
QStringList epubArgs;
epubArgs << "/mnt/onboard/.adds/inkbox/epub.sh" << book;
QProcess *epubProc = new QProcess();
epubProc->start(epubProg, epubArgs);
epubProc->waitForFinished();
is_epub = true;
booktostr_ran = true;
}
else {
// This is likely not an ePUB.
// Copying book specified in the function call
QFile::copy(book, "/inkbox/book/book.txt");
is_epub = false;
booktostr_ran = true;
}
}
// Checking if the user has defined an option for the number of words per page; if not, then setting the default.
QDir::setCurrent("/mnt/onboard/.adds/inkbox");
string_checkconfig(".config/07-words_number/config");
if(checkconfig_str_val == "") {
string_writeconfig(".config/07-words_number/config", "100");
string_checkconfig(".config/07-words_number/config");
}
// Parsing file
if(parser_ran != true) {
if(is_epub == true) {
QString parse_prog ("python3");
QStringList parse_args;
parse_args << "split.py" << checkconfig_str_val;
QProcess *parse_proc = new QProcess();
parse_proc->start(parse_prog, parse_args);
parse_proc->waitForFinished();
parser_ran = true;
}
else {
QString parse_prog ("python3");
QStringList parse_args;
parse_args << "split-txt.py" << checkconfig_str_val;
QProcess *parse_proc = new QProcess();
parse_proc->start(parse_prog, parse_args);
parse_proc->waitForFinished();
parser_ran = true;
}
}
// Changing current working directory
QDir::setCurrent("/inkbox/book");
// Reading file
if(run_parser == true) {
QDirIterator it("/inkbox/book/split");
while (it.hasNext()) {
QFile f(it.next());
f.open(QIODevice::ReadOnly);
content << f.readAll();
f.close();
}
return content.size();
QDir::setCurrent("/mnt/onboard/.adds/inkbox");
}
else {
ittext = content[i];
QDir::setCurrent("/mnt/onboard/.adds/inkbox");
}
return 0;
} }
void reader::checkwords() { void reader::checkwords() {
@ -672,7 +591,7 @@ void reader::on_nextBtn_clicked()
parser_ran = true; parser_ran = true;
split_total = split_total - 1; split_total = split_total - 1;
setup_book(book_file, split_total, false); setup_book(book_file);
ui->text->setText(""); ui->text->setText("");
ui->text->setText(ittext); ui->text->setText(ittext);
@ -702,7 +621,7 @@ void reader::on_previousBtn_clicked()
else { else {
parser_ran = true; parser_ran = true;
split_total = split_total + 1; split_total = split_total + 1;
setup_book(book_file, split_total, false); setup_book(book_file);
ui->text->setText(""); ui->text->setText("");
ui->text->setText(ittext); ui->text->setText(ittext);

View file

@ -57,8 +57,8 @@ public:
QPixmap scaledHalfPixmap; QPixmap scaledHalfPixmap;
QPixmap scaledFullPixmap; QPixmap scaledFullPixmap;
QPixmap scaledEmptyPixmap; QPixmap scaledEmptyPixmap;
QList<QString> content; QString content;
int setup_book(QString book, int i, bool run_parser); int setup_book(QString book);
void checkwords(); void checkwords();
bool epub_file_match(QString file); bool epub_file_match(QString file);
void dictionary_lookup(string word, QString first_letter, int position); void dictionary_lookup(string word, QString first_letter, int position);

108
reader.ui
View file

@ -16,22 +16,16 @@
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<item row="10" column="0"> <item row="16" column="0">
<widget class="QTextEdit" name="text"> <widget class="Line" name="line_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>100</horstretch>
<verstretch>100</verstretch>
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow"> <property name="frameShadow">
<enum>QFrame::Plain</enum> <enum>QFrame::Plain</enum>
</property> </property>
<property name="lineWidth"> <property name="lineWidth">
<number>0</number> <number>2</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property> </property>
</widget> </widget>
</item> </item>
@ -111,32 +105,6 @@
</item> </item>
</layout> </layout>
</item> </item>
<item row="9" column="0">
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="16" column="0">
<widget class="Line" name="line_2">
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="lineWidth">
<number>2</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="12" column="0"> <item row="12" column="0">
<widget class="QStackedWidget" name="wordWidget"> <widget class="QStackedWidget" name="wordWidget">
<widget class="QWidget" name="page_8"> <widget class="QWidget" name="page_8">
@ -418,6 +386,57 @@
<widget class="QWidget" name="page_9"/> <widget class="QWidget" name="page_9"/>
</widget> </widget>
</item> </item>
<item row="10" column="0">
<widget class="QTextEdit" name="text">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>100</horstretch>
<verstretch>100</verstretch>
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="lineWidth">
<number>0</number>
</property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
</widget>
</item>
<item row="9" column="0">
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="11" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="8" column="0"> <item row="8" column="0">
<widget class="QStackedWidget" name="menuWidget"> <widget class="QStackedWidget" name="menuWidget">
<widget class="QWidget" name="page_20"> <widget class="QWidget" name="page_20">
@ -978,19 +997,6 @@
<widget class="QWidget" name="page_21"/> <widget class="QWidget" name="page_21"/>
</widget> </widget>
</item> </item>
<item row="11" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout> </layout>
</item> </item>
</layout> </layout>