diff --git a/eink.qrc b/eink.qrc index 25d1780..0f36504 100644 --- a/eink.qrc +++ b/eink.qrc @@ -60,5 +60,7 @@ resources/wifi-connected.png resources/wifi-off.png resources/wifi-standby.png + resources/zoom-in.png + resources/zoom-out.png diff --git a/mainwindow.cpp b/mainwindow.cpp index 6ccae4d..c5f34b9 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -875,7 +875,9 @@ int MainWindow::testPing() { QProcess *pingProcess = new QProcess(); pingProcess->start(pingProg, pingArgs); pingProcess->waitForFinished(); - return pingProcess->exitCode(); + int exitCode = pingProcess->exitCode(); + pingProcess->deleteLater(); + return exitCode; } void MainWindow::updateWifiIcon(int mode) { diff --git a/reader.cpp b/reader.cpp index 45f2b4d..50c70b2 100644 --- a/reader.cpp +++ b/reader.cpp @@ -56,6 +56,8 @@ reader::reader(QWidget *parent) : ui->nightModeBtn->setProperty("type", "borderless"); ui->searchBtn->setProperty("type", "borderless"); ui->gotoBtn->setProperty("type", "borderless"); + ui->increaseScaleBtn->setProperty("type", "borderless"); + ui->decreaseScaleBtn->setProperty("type", "borderless"); // Icons ui->alignLeftBtn->setText(""); @@ -84,6 +86,10 @@ reader::reader(QWidget *parent) : ui->aboutBtn->setIcon(QIcon(":/resources/info.png")); ui->searchBtn->setText(""); ui->searchBtn->setIcon(QIcon(":/resources/search.png")); + ui->increaseScaleBtn->setText(""); + ui->increaseScaleBtn->setIcon(QIcon(":/resources/zoom-in.png")); + ui->decreaseScaleBtn->setText(""); + ui->decreaseScaleBtn->setIcon(QIcon(":/resources/zoom-out.png")); // Style misc. ui->bookInfoLabel->setStyleSheet("font-style: italic"); @@ -258,6 +264,7 @@ reader::reader(QWidget *parent) : ui->brightnessWidget->setVisible(false); ui->menuBarWidget->setVisible(false); ui->buttonsBarWidget->setVisible(false); + ui->pdfScaleWidget->setVisible(false); ui->wordWidget->setVisible(false); if(checkconfig(".config/11-menubar/sticky") == true) { ui->menuWidget->setVisible(true); @@ -1283,6 +1290,11 @@ void reader::menubar_show() { if(is_pdf == false) { ui->menuBarWidget->setVisible(true); } + else { + ui->pdfScaleWidget->setVisible(true); + ui->graphicsView->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); + ui->graphicsView->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); + } ui->buttonsBarWidget->setVisible(true); ui->statusBarWidget->setVisible(true); ui->pageWidget->setVisible(true); @@ -1312,6 +1324,17 @@ void reader::menubar_hide() { if(is_pdf == false) { ui->menuBarWidget->setVisible(false); } + else { + ui->pdfScaleWidget->setVisible(false); + if(checkconfig(".config/14-reader_scrollbar/config") == true) { + ui->graphicsView->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); + ui->graphicsView->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); + } + else { + ui->graphicsView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + ui->graphicsView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + } + } ui->buttonsBarWidget->setVisible(false); ui->pageWidget->setVisible(false); if(checkconfig(".config/11-menubar/sticky") == true) { @@ -1539,6 +1562,12 @@ void reader::convertMuPdfVars(int fileType) { * 0: ePUB * 1: PDF */ + bool convertRelativeValuesNative; + if(mupdf::convertRelativeValues == true) { + // Safer approach; local bool gets destroyed when getting out of scope + convertRelativeValuesNative = true; + mupdf::convertRelativeValues = false; + } if(fileType == 0) { setPageStyle(0); mupdf::epub::fontSize = 12; @@ -1561,8 +1590,16 @@ void reader::convertMuPdfVars(int fileType) { setPageStyle(1); mupdf::pdf::width = defaultPdfPageWidth; mupdf::pdf::height = defaultPdfPageHeight; - mupdf::pdf::width_qstr = QString::number(mupdf::pdf::width); - mupdf::pdf::height_qstr = QString::number(mupdf::pdf::height); + if(convertRelativeValuesNative == true) { + // For scaling + mupdf::pdf::width_qstr = QString::number(mupdf::pdf::relativeHeight); + mupdf::pdf::height_qstr = QString::number(mupdf::pdf::relativeWidth); + } + else { + // Default + mupdf::pdf::width_qstr = QString::number(mupdf::pdf::width); + mupdf::pdf::height_qstr = QString::number(mupdf::pdf::height); + } if(global::reader::globalReadingSettings == false) { if(goToSavedPageDone == false) { string_checkconfig_ro(".config/A-page_number/config"); @@ -1949,3 +1986,71 @@ void reader::getTotalPdfPagesNumber() { string_checkconfig_ro("/run/pdf_total_pages_number"); totalPagesInt = checkconfig_str_val.toInt(); } + +void reader::on_pdfScaleSlider_valueChanged(int value) +{ + if(value == 1) { + mupdf::pdf::relativeWidth = 1 * mupdf::pdf::width; + mupdf::pdf::relativeHeight = 1 * mupdf::pdf::height; + } + else if(value == 2) { + mupdf::pdf::relativeWidth = 1.50 * mupdf::pdf::width; + mupdf::pdf::relativeHeight = 1.50 * mupdf::pdf::height; + } + else if(value == 3) { + mupdf::pdf::relativeWidth = 2 * mupdf::pdf::width; + mupdf::pdf::relativeHeight = 2 * mupdf::pdf::height; + } + else if(value == 4) { + mupdf::pdf::relativeWidth = 2.50 * mupdf::pdf::width; + mupdf::pdf::relativeHeight = 2.50 * mupdf::pdf::height; + } + + if(value != 1) { + ui->graphicsView->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); + ui->graphicsView->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); + } + else { + if(checkconfig(".config/14-reader_scrollbar/config") == true) { + ui->graphicsView->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); + ui->graphicsView->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); + } + else { + ui->graphicsView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + ui->graphicsView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + } + } + + mupdf::pdf::pdfPageNumber = mupdf::pdf::pdfPageNumber + 1; + setup_book(book_file, mupdf::pdf::pdfPageNumber, true); + setupPng(); +} + +void reader::on_decreaseScaleBtn_clicked() +{ + int sliderCurrentValue; + int sliderWantedValue; + sliderCurrentValue = ui->pdfScaleSlider->value(); + sliderWantedValue = sliderCurrentValue - 1; + if(sliderWantedValue < ui->pdfScaleSlider->QAbstractSlider::minimum()) { + showToast("Minimum scale reached"); + } + else { + ui->pdfScaleSlider->setValue(sliderWantedValue); + } +} + + +void reader::on_increaseScaleBtn_clicked() +{ + int sliderCurrentValue; + int sliderWantedValue; + sliderCurrentValue = ui->pdfScaleSlider->value(); + sliderWantedValue = sliderCurrentValue + 1; + if(sliderWantedValue > ui->pdfScaleSlider->QAbstractSlider::maximum()) { + showToast("Maximum scale reached"); + } + else { + ui->pdfScaleSlider->setValue(sliderWantedValue); + } +} diff --git a/reader.h b/reader.h index 33e039b..82d59f4 100644 --- a/reader.h +++ b/reader.h @@ -13,6 +13,7 @@ using namespace std; // ePUB scaling namespace mupdf { + inline bool convertRelativeValues; namespace epub { inline int fontSize; inline int width; @@ -26,6 +27,8 @@ namespace mupdf { namespace pdf { inline int width; inline int height; + inline int relativeWidth; + inline int relativeHeight; inline int pdfPageNumber; inline QString width_qstr; inline QString height_qstr; @@ -150,6 +153,11 @@ private slots: void saveReadingSettings(); void setupLocalSettingsEnvironment(); void setupPng(); + void on_pdfScaleSlider_valueChanged(int value); + + void on_decreaseScaleBtn_clicked(); + + void on_increaseScaleBtn_clicked(); private: Ui::reader * ui; diff --git a/reader.ui b/reader.ui index 2a4d457..c3fa415 100644 --- a/reader.ui +++ b/reader.ui @@ -674,6 +674,100 @@ + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + 0 + + + + + Increase scale + + + + + + + Decrease scale + + + + + + + + Chivo + true + + + + Scale + + + Qt::AlignCenter + + + + + + + 1 + + + 4 + + + 1 + + + Qt::Horizontal + + + + + + + + + QFrame::Plain + + + Qt::Horizontal + + + + + + + Qt::Horizontal + + + + + + + + diff --git a/resources/zoom-in.png b/resources/zoom-in.png new file mode 100644 index 0000000..25575f8 Binary files /dev/null and b/resources/zoom-in.png differ diff --git a/resources/zoom-out.png b/resources/zoom-out.png new file mode 100644 index 0000000..235bba9 Binary files /dev/null and b/resources/zoom-out.png differ