That one *kind of* works

This commit is contained in:
Nicolas Mailloux 2021-06-18 20:46:34 -04:00
parent cb65131841
commit f1c18bada5
3 changed files with 426 additions and 410 deletions

View file

@ -28,6 +28,7 @@ reader::reader(QWidget *parent) :
if(global::reader::bookIsEpub == true) {
is_epub = true;
}
mupdf::epubPageNumber = 22;
ui->setupUi(this);
ui->previousBtn->setProperty("type", "borderless");
@ -364,7 +365,7 @@ reader::reader(QWidget *parent) :
// Get text
QDir::setCurrent("/mnt/onboard/.adds/inkbox");
setup_book(book_file, split_total, false);
setup_book(book_file, split_total, true);
// Display text
// Checking saved font size if any
@ -525,7 +526,7 @@ int reader::setup_book(QString book, int i, bool run_parser) {
if(filematch_ran != true) {
if(epub_file_match(book) == true) {
QFile::copy(book, "/inkbox/book/book.epub");
QFile::remove("/mutool_rootfs/run/book.epub");
QFile::copy(book, "/mutool_rootfs/run/book.epub");
// Parsing ePUBs with `mutool'
@ -539,6 +540,7 @@ int reader::setup_book(QString book, int i, bool run_parser) {
filematch_ran = true;
is_epub = true;
qDebug() << "Initial parser ran.";
}
else {
// This is likely not an ePUB.
@ -560,8 +562,8 @@ int reader::setup_book(QString book, int i, bool run_parser) {
}
// Parsing file
if(filematch_ran != true) {
if(is_epub == true) {
if(is_epub == true) {
if(run_parser == true) {
QString epubProg ("sh");
QStringList epubArgs;
convertMuPdfVars();
@ -569,20 +571,25 @@ int reader::setup_book(QString book, int i, bool run_parser) {
QProcess *epubProc = new QProcess();
epubProc->start(epubProg, epubArgs);
epubProc->waitForFinished();
qDebug() << "Standard parser ran.";
}
else {
if(parser_ran != true) {
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;
}
else {
;
}
;
}
}
else {
if(parser_ran != true) {
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;
}
else {
;
}
}
@ -613,6 +620,7 @@ int reader::setup_book(QString book, int i, bool run_parser) {
QTextStream in(&epubPage);
epubPageContent = in.readAll();
epubPage.close();
qDebug() << epubPageContent;
QDir::setCurrent("/mnt/onboard/.adds/inkbox");
}
return 0;
@ -711,7 +719,10 @@ void reader::on_nextBtn_clicked()
}
else {
mupdf::epubPageNumber = mupdf::epubPageNumber + 1;
setup_book(book_file, mupdf::epubPageNumber, false);
qDebug() << mupdf::epubPageNumber;
setup_book(book_file, mupdf::epubPageNumber, true);
ui->text->setText("");
ui->text->setText(epubPageContent);
pagesTurned = pagesTurned + 1;
writeconfig_pagenumber();
@ -746,7 +757,9 @@ void reader::on_previousBtn_clicked()
}
else {
mupdf::epubPageNumber = mupdf::epubPageNumber - 1;
setup_book(book_file, mupdf::epubPageNumber, false);
setup_book(book_file, mupdf::epubPageNumber, true);
ui->text->setText("");
ui->text->setText(epubPageContent);
// We always increment pagesTurned regardless whether we press the Previous or Next button
pagesTurned = pagesTurned + 1;
@ -1151,6 +1164,9 @@ void reader::openCriticalBatteryAlertWindow() {
alertWindow->show();
}
void reader::convertMuPdfVars() {
mupdf::fontSize = 12;
mupdf::width = 400;
mupdf::height = 500;
mupdf::fontSize_qstr = QString::number(mupdf::fontSize);
mupdf::width_qstr = QString::number(mupdf::width);
mupdf::height_qstr = QString::number(mupdf::height);

778
reader.ui
View file

@ -16,6 +16,114 @@
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="10" column="0">
<widget class="QLabel" name="text">
<property name="font">
<font>
<family>Ubuntu</family>
<italic>false</italic>
</font>
</property>
<property name="text">
<string>Text</string>
</property>
<property name="alignment">
<set>Qt::AlignJustify|Qt::AlignVCenter</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</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="17" column="0">
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="4">
<widget class="Line" name="line_3">
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QPushButton" name="previousBtn">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Previous</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="Line" name="line">
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="optionsBtn">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Options</string>
</property>
</widget>
</item>
<item row="0" column="5">
<widget class="QPushButton" name="nextBtn">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Next</string>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QPushButton" name="hideOptionsBtn">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Hide</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="16" column="0">
<widget class="Line" name="line_2">
<property name="frameShadow">
@ -29,6 +137,287 @@
</property>
</widget>
</item>
<item row="12" column="0">
<widget class="QStackedWidget" name="wordWidget">
<widget class="QWidget" name="page_8">
<layout class="QVBoxLayout" name="verticalLayout_4">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="Line" name="line_12">
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="lineWidth">
<number>8</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QGridLayout" name="gridLayout_5">
<property name="bottomMargin">
<number>0</number>
</property>
<property name="spacing">
<number>6</number>
</property>
<item row="1" column="3">
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="0">
<widget class="QPushButton" name="saveWordBtn">
<property name="text">
<string>Save</string>
</property>
</widget>
</item>
<item row="1" column="4">
<widget class="QPushButton" name="infoCloseBtn">
<property name="text">
<string>Close</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLabel" name="wordSearchLabel">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Word search</string>
</property>
</widget>
</item>
<item row="1" column="1">
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QGridLayout" name="gridLayout_12">
<property name="bottomMargin">
<number>0</number>
</property>
<item row="1" column="0">
<layout class="QGridLayout" name="gridLayout_14">
<property name="bottomMargin">
<number>0</number>
</property>
<item row="0" column="2">
<widget class="Line" name="line_14">
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="lineWidth">
<number>2</number>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QLabel" name="definitionLabel">
<property name="font">
<font>
<family>Source Serif Pro</family>
</font>
</property>
<property name="text">
<string>Definition</string>
</property>
<property name="alignment">
<set>Qt::AlignJustify|Qt::AlignVCenter</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="wordLabel">
<property name="font">
<font>
<family>Inter</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Word</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="4">
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="0">
<spacer name="horizontalSpacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="3" column="0">
<spacer name="verticalSpacer_4">
<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="4" column="0">
<layout class="QGridLayout" name="gridLayout_9">
<property name="bottomMargin">
<number>0</number>
</property>
<item row="0" column="0">
<spacer name="horizontalSpacer_7">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="previousDefinitionBtn">
<property name="text">
<string>Previous</string>
</property>
</widget>
</item>
<item row="0" column="4">
<spacer name="horizontalSpacer_8">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="2">
<widget class="QLabel" name="definitionStatusLabel">
<property name="text">
<string>Status</string>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QPushButton" name="nextDefinitionBtn">
<property name="text">
<string>Next</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="0" column="0">
<spacer name="verticalSpacer_3">
<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>
</item>
<item>
<widget class="Line" name="line_13">
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="lineWidth">
<number>8</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="page_9"/>
</widget>
</item>
<item row="8" column="0">
<widget class="QStackedWidget" name="menuWidget">
<widget class="QWidget" name="page_20">
@ -589,395 +978,6 @@
<widget class="QWidget" name="page_21"/>
</widget>
</item>
<item row="12" column="0">
<widget class="QStackedWidget" name="wordWidget">
<widget class="QWidget" name="page_8">
<layout class="QVBoxLayout" name="verticalLayout_4">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="Line" name="line_12">
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="lineWidth">
<number>8</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QGridLayout" name="gridLayout_5">
<property name="bottomMargin">
<number>0</number>
</property>
<property name="spacing">
<number>6</number>
</property>
<item row="1" column="3">
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="0">
<widget class="QPushButton" name="saveWordBtn">
<property name="text">
<string>Save</string>
</property>
</widget>
</item>
<item row="1" column="4">
<widget class="QPushButton" name="infoCloseBtn">
<property name="text">
<string>Close</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLabel" name="wordSearchLabel">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Word search</string>
</property>
</widget>
</item>
<item row="1" column="1">
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QGridLayout" name="gridLayout_12">
<property name="bottomMargin">
<number>0</number>
</property>
<item row="1" column="0">
<layout class="QGridLayout" name="gridLayout_14">
<property name="bottomMargin">
<number>0</number>
</property>
<item row="0" column="2">
<widget class="Line" name="line_14">
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="lineWidth">
<number>2</number>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QLabel" name="definitionLabel">
<property name="font">
<font>
<family>Source Serif Pro</family>
</font>
</property>
<property name="text">
<string>Definition</string>
</property>
<property name="alignment">
<set>Qt::AlignJustify|Qt::AlignVCenter</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="wordLabel">
<property name="font">
<font>
<family>Inter</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Word</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="4">
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="0">
<spacer name="horizontalSpacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="3" column="0">
<spacer name="verticalSpacer_4">
<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="4" column="0">
<layout class="QGridLayout" name="gridLayout_9">
<property name="bottomMargin">
<number>0</number>
</property>
<item row="0" column="0">
<spacer name="horizontalSpacer_7">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="previousDefinitionBtn">
<property name="text">
<string>Previous</string>
</property>
</widget>
</item>
<item row="0" column="4">
<spacer name="horizontalSpacer_8">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="2">
<widget class="QLabel" name="definitionStatusLabel">
<property name="text">
<string>Status</string>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QPushButton" name="nextDefinitionBtn">
<property name="text">
<string>Next</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="0" column="0">
<spacer name="verticalSpacer_3">
<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>
</item>
<item>
<widget class="Line" name="line_13">
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="lineWidth">
<number>8</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="page_9"/>
</widget>
</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="17" column="0">
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="4">
<widget class="Line" name="line_3">
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QPushButton" name="previousBtn">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Previous</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="Line" name="line">
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="optionsBtn">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Options</string>
</property>
</widget>
</item>
<item row="0" column="5">
<widget class="QPushButton" name="nextBtn">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Next</string>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QPushButton" name="hideOptionsBtn">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Hide</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="10" column="0">
<widget class="QLabel" name="text">
<property name="font">
<font>
<family>Ubuntu</family>
<italic>false</italic>
</font>
</property>
<property name="text">
<string>Text</string>
</property>
<property name="alignment">
<set>Qt::AlignJustify|Qt::AlignVCenter</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="9" column="0">
<spacer name="verticalSpacer_2">
<property name="orientation">

View file

@ -193,17 +193,17 @@ QLineEdit:edit-focus, QSpinBox:edit-focus, QDoubleSpinBox:edit-focus
QTextEdit
{
background-color:transparent;
border:1px solid black;
border: none;
padding: 1px;
}
QTextEdit:focus
{
border: 1px solid black;
border: none;
padding: 1px;
}
QTextEdit:edit-focus
{
border: 3px solid black;
border: none;
padding: 0px;
}