From 351a375dfcf302680dab6ef81623c6af942232c0 Mon Sep 17 00:00:00 2001 From: Nicolas Mailloux Date: Sun, 20 Jun 2021 22:57:10 -0400 Subject: [PATCH] Things are going well! (and I'm strongly hoping that it will continue like that too ;p) --- functions.h | 13 +++ reader.cpp | 63 ++++++------ settings.cpp | 43 ++++++++ settings.h | 3 +- settings.ui | 277 ++++++++++++++++++++++++++++++++------------------- 5 files changed, 262 insertions(+), 137 deletions(-) diff --git a/functions.h b/functions.h index 8065d4b..38342fa 100644 --- a/functions.h +++ b/functions.h @@ -63,6 +63,8 @@ namespace { QString batt_level; QString kernelVersion; int batt_level_int; + int defaultEpubPageWidth; + int defaultEpubPageHeight; bool checked_box = false; bool checkconfig(QString file) { QFile config(file); @@ -318,5 +320,16 @@ namespace { QString returnedMetadata = proc->readAllStandardOutput(); return returnedMetadata; } + void defineDefaultPageSize() { + string_checkconfig_ro("/opt/inkbox_device"); + if(checkconfig_str_val == "n705\n") { + defaultEpubPageWidth = 425; + defaultEpubPageHeight = 425; + } + if(checkconfig_str_val == "n905\n") { + defaultEpubPageHeight = 425; + defaultEpubPageWidth = 425; + } + } } #endif // FUNCTIONS_H diff --git a/reader.cpp b/reader.cpp index d696f92..f8619b8 100644 --- a/reader.cpp +++ b/reader.cpp @@ -89,7 +89,7 @@ reader::reader(QWidget *parent) : string_checkconfig(".config/04-book/font"); if(checkconfig_str_val == "") { ui->fontChooser->setCurrentText(checkconfig_str_val); - ui->text->setFont(QFont("Inter")); + ui->text->setFont(QFont("Source Serif Pro")); } else { if(checkconfig_str_val == "Crimson Pro") { @@ -1225,9 +1225,8 @@ void reader::openCriticalBatteryAlertWindow() { } void reader::convertMuPdfVars() { + setPageStyle(); mupdf::fontSize = 12; - mupdf::width = 400; - mupdf::height = 460; mupdf::fontSize_qstr = QString::number(mupdf::fontSize); mupdf::width_qstr = QString::number(mupdf::width); mupdf::height_qstr = QString::number(mupdf::height); @@ -1236,29 +1235,38 @@ void reader::convertMuPdfVars() { void reader::setPageStyle() { // General page size - string_checkconfig_ro("/opt/inkbox_device"); - if(checkconfig_str_val == "n705\n") { - string_checkconfig_ro(".config/04-book/font"); - if(checkconfig_str_val == "Crimson Pro") { - mupdf::width = 415; - mupdf::height = 490; - } - else { - mupdf::width = 400; - mupdf::height = 460; - } + defineDefaultPageSize(); + + string_checkconfig_ro(".config/13-epub_page_size/width"); + if(checkconfig_str_val != "") { + ; } - else if(checkconfig_str_val == "n905\n") { - string_checkconfig_ro(".config/04-book/font"); - if(checkconfig_str_val == "Crimson Pro") { - mupdf::width = 415; - mupdf::height = 490; - } - else { - mupdf::width = 400; - mupdf::height = 460; - } + else { + std::string pageWidth = std::to_string(defaultEpubPageWidth); + string_writeconfig(".config/13-epub_page_size/width", pageWidth); + string_writeconfig(".config/13-epub_page_size/set", "true"); + string_checkconfig_ro(".config/13-epub_page_size/width"); } + mupdf::width = checkconfig_str_val.toInt(); + + string_checkconfig_ro(".config/13-epub_page_size/height"); + if(checkconfig_str_val != "") { + ; + } + else { + std::string pageHeight = std::to_string(defaultEpubPageHeight); + string_writeconfig(".config/13-epub_page_size/height", pageHeight); + string_writeconfig(".config/13-epub_page_size/set", "true"); + string_checkconfig_ro(".config/13-epub_page_size/height"); + } + mupdf::height = checkconfig_str_val.toInt(); +} + +void reader::delay(int seconds) { + // https://stackoverflow.com/questions/3752742/how-do-i-create-a-pause-wait-function-using-qt + QTime dieTime= QTime::currentTime().addSecs(seconds); + while (QTime::currentTime() < dieTime) + QCoreApplication::processEvents(QEventLoop::AllEvents, 100); } void reader::on_text_selectionChanged() { @@ -1296,10 +1304,3 @@ void reader::on_text_selectionChanged() { } } } - -void reader::delay(int seconds) { - // https://stackoverflow.com/questions/3752742/how-do-i-create-a-pause-wait-function-using-qt - QTime dieTime= QTime::currentTime().addSecs(seconds); - while (QTime::currentTime() < dieTime) - QCoreApplication::processEvents(QEventLoop::AllEvents, 100); -} diff --git a/settings.cpp b/settings.cpp index a49ad98..f3824c5 100644 --- a/settings.cpp +++ b/settings.cpp @@ -66,6 +66,9 @@ settings::settings(QWidget *parent) : ui->uiScalingSlider->hide(); ui->uiScalingLabel->hide(); + // Variables + defineDefaultPageSize(); + // Settings tweaking + enabling specific features whether it's running on the provided integrated OS or Kobo firmware if(checkconfig(".config/01-demo/config") == true) { ui->demoCheckBox->click(); @@ -90,6 +93,32 @@ settings::settings(QWidget *parent) : ui->wordsNumber->setValue(words_number); } + // ePUB page size + if(checkconfig(".config/13-epub_page_size/set") == true) { + string_checkconfig_ro(".config/13-epub_page_size/width"); + if(checkconfig_str_val != "") { + int pageWidth = checkconfig_str_val.toInt(); + ui->pageSizeWidthSpinBox->setValue(pageWidth); + } + else { + // Failsafe: setting default + ui->pageSizeWidthSpinBox->setValue(defaultEpubPageWidth); + } + string_checkconfig_ro(".config/13-epub_page_size/height"); + if(checkconfig_str_val != "") { + int pageHeight = checkconfig_str_val.toInt(); + ui->pageSizeHeightSpinBox->setValue(pageHeight); + } + else { + // Failsafe: setting default + ui->pageSizeHeightSpinBox->setValue(defaultEpubPageHeight); + } + } + else { + ui->pageSizeWidthSpinBox->setValue(defaultEpubPageWidth); + ui->pageSizeHeightSpinBox->setValue(defaultEpubPageHeight); + } + // Sticky menubar if(checkconfig(".config/11-menubar/sticky") == true) { ui->menuBarCheckBox->click(); @@ -660,3 +689,17 @@ void settings::on_showSystemInfoBtn_clicked() generalDialogWindow->setAttribute(Qt::WA_DeleteOnClose); generalDialogWindow->show(); } + +void settings::on_pageSizeWidthSpinBox_valueChanged(int arg1) +{ + std::string value = std::to_string(arg1); + string_writeconfig(".config/13-epub_page_size/width", value); + string_writeconfig(".config/13-epub_page_size/set", "true"); +} + +void settings::on_pageSizeHeightSpinBox_valueChanged(int arg1) +{ + std::string value = std::to_string(arg1); + string_writeconfig(".config/13-epub_page_size/height", value); + string_writeconfig(".config/13-epub_page_size/set", "true"); +} diff --git a/settings.h b/settings.h index 0c4ad64..5eee262 100644 --- a/settings.h +++ b/settings.h @@ -46,8 +46,9 @@ private slots: void on_setPasscodeBtn_clicked(); void on_enableLockscreenCheckBox_toggled(bool checked); void on_enableUiScalingCheckBox_toggled(bool checked); - void on_showSystemInfoBtn_clicked(); + void on_pageSizeWidthSpinBox_valueChanged(int arg1); + void on_pageSizeHeightSpinBox_valueChanged(int arg1); private: Ui::settings *ui; diff --git a/settings.ui b/settings.ui index 5eb220a..c67918c 100644 --- a/settings.ui +++ b/settings.ui @@ -191,14 +191,7 @@ OK 0 - - - Clock: Show seconds - - - - - + QFrame::Plain @@ -208,6 +201,26 @@ OK + + + QFrame::Plain + + + Qt::Horizontal + + + + + + + QFrame::Plain + + + Qt::Horizontal + + + + 0 @@ -247,27 +260,114 @@ OK - - - - QFrame::Plain + + + + + Chivo + true + - - Qt::Horizontal + + Networking - - - - QFrame::Plain - - - Qt::Horizontal + + + + Disable authors quotes - + + + + Disable "Welcome to InkBox" message + + + + + + + 0 + + + + + Request DHCP lease + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 75 + true + + + + Request + + + + + + + + + Always show status bar + + + + + + + + Chivo + true + + + + Reading + + + + + + + Clock: Show seconds + + + + + + + + Chivo + true + + + + Storage + + + + 0 @@ -338,43 +438,6 @@ OK - - - - QFrame::Plain - - - Qt::Horizontal - - - - - - - Disable authors quotes - - - - - - - Always show status bar - - - - - - - - Chivo - true - - - - Reading - - - @@ -396,7 +459,7 @@ OK - Words number per page (plain text files) + Words number/page (plain text files) @@ -418,7 +481,7 @@ OK - + @@ -431,53 +494,57 @@ OK - - - - - Chivo - true - + + + + QFrame::Plain - - Storage + + Qt::Horizontal - - - - - Chivo - true - - - - Networking - - - - - - - Disable "Welcome to InkBox" message - - - - - + + 0 - - + + - Request DHCP lease + Height: + + + + + + + Width: + + + + + + + 300 + + + 700 + + + 25 + + + + + + + ePUB page size - + Qt::Horizontal @@ -489,16 +556,16 @@ OK - - - - - 75 - true - + + + + 300 - - Request + + 700 + + + 25