mirror of
https://github.com/Quill-OS/quill.git
synced 2024-12-28 08:37:22 -08:00
Picture display support!
This commit is contained in:
parent
bbc5c3b927
commit
b97b3c5f82
2 changed files with 99 additions and 17 deletions
112
reader.cpp
112
reader.cpp
|
@ -425,7 +425,7 @@ reader::reader(QWidget *parent) :
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get text; no need to do it multiple times for ePUB books
|
// Get text; no need to do it multiple times for ePUB books
|
||||||
if(is_epub == false or is_pdf == false) {
|
if(is_epub == false && is_pdf == false && is_image == false) {
|
||||||
setDefaultWorkDir();
|
setDefaultWorkDir();
|
||||||
if(global::reader::globalReadingSettings == false) {
|
if(global::reader::globalReadingSettings == false) {
|
||||||
string_checkconfig_ro(".config/A-page_number/config");
|
string_checkconfig_ro(".config/A-page_number/config");
|
||||||
|
@ -495,6 +495,11 @@ reader::reader(QWidget *parent) :
|
||||||
ui->text->deleteLater();
|
ui->text->deleteLater();
|
||||||
setupPng();
|
setupPng();
|
||||||
}
|
}
|
||||||
|
else if(is_image == true) {
|
||||||
|
ui->text->hide();
|
||||||
|
ui->text->deleteLater();
|
||||||
|
setupPng();
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
ui->text->setText(ittext);
|
ui->text->setText(ittext);
|
||||||
}
|
}
|
||||||
|
@ -758,8 +763,39 @@ int reader::setup_book(QString book, int i, bool run_parser) {
|
||||||
filematch_ran = true;
|
filematch_ran = true;
|
||||||
is_pdf = true;
|
is_pdf = true;
|
||||||
}
|
}
|
||||||
|
else if(image_file_match(book) == true) {
|
||||||
|
ui->previousBtn->hide();
|
||||||
|
ui->nextBtn->hide();
|
||||||
|
ui->line->hide();
|
||||||
|
ui->line_3->hide();
|
||||||
|
ui->previousBtn->deleteLater();
|
||||||
|
ui->nextBtn->deleteLater();
|
||||||
|
ui->line->deleteLater();
|
||||||
|
ui->line_3->deleteLater();
|
||||||
|
|
||||||
|
string_writeconfig("/tmp/inkboxImagePath", book.toStdString());
|
||||||
|
string_writeconfig("/opt/ibxd", "inkbox_convert_image\n");
|
||||||
|
|
||||||
|
while(true) {
|
||||||
|
if(QFile::exists("/inkbox/convertImageDone")) {
|
||||||
|
if(checkconfig("/inkbox/convertImageDone") == true) {
|
||||||
|
filematch_ran = true;
|
||||||
|
is_image = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
showToast("Failed to display image");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
QFile::remove("/inkbox/convertImageDone");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
filematch_ran = true;
|
||||||
|
is_image = true;
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
// This is likely not an ePUB.
|
// This is likely not an ePUB, a PDF or a picture.
|
||||||
// Copying book specified in the function call
|
// Copying book specified in the function call
|
||||||
QFile::copy(book, "/inkbox/book/book.txt");
|
QFile::copy(book, "/inkbox/book/book.txt");
|
||||||
|
|
||||||
|
@ -818,6 +854,10 @@ int reader::setup_book(QString book, int i, bool run_parser) {
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if(is_image == true) {
|
||||||
|
// Do nothing, since images won't have pages
|
||||||
|
;
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
QString parse_prog ("python3");
|
QString parse_prog ("python3");
|
||||||
QStringList parse_args;
|
QStringList parse_args;
|
||||||
|
@ -1309,17 +1349,24 @@ void reader::menubar_show() {
|
||||||
}
|
}
|
||||||
|
|
||||||
ui->menuWidget->setVisible(true);
|
ui->menuWidget->setVisible(true);
|
||||||
if(is_pdf == false) {
|
if(is_pdf == false && is_image == false) {
|
||||||
ui->menuBarWidget->setVisible(true);
|
ui->menuBarWidget->setVisible(true);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ui->pdfScaleWidget->setVisible(true);
|
if(is_pdf == true) {
|
||||||
|
ui->pdfScaleWidget->setVisible(true);
|
||||||
|
}
|
||||||
ui->graphicsView->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
ui->graphicsView->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
||||||
ui->graphicsView->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
ui->graphicsView->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
||||||
|
if(is_image == false) {
|
||||||
|
ui->pageWidget->setVisible(true);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ui->pageWidget->setVisible(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ui->buttonsBarWidget->setVisible(true);
|
ui->buttonsBarWidget->setVisible(true);
|
||||||
ui->statusBarWidget->setVisible(true);
|
ui->statusBarWidget->setVisible(true);
|
||||||
ui->pageWidget->setVisible(true);
|
|
||||||
|
|
||||||
string_checkconfig_ro("/opt/inkbox_device");
|
string_checkconfig_ro("/opt/inkbox_device");
|
||||||
if(checkconfig_str_val == "n705\n" or checkconfig_str_val == "n905\n") {
|
if(checkconfig_str_val == "n705\n" or checkconfig_str_val == "n905\n") {
|
||||||
|
@ -1342,7 +1389,7 @@ void reader::menubar_hide() {
|
||||||
ui->brightnessWidget->setVisible(false);
|
ui->brightnessWidget->setVisible(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(is_pdf == false) {
|
if(is_pdf == false && is_image == false) {
|
||||||
ui->menuBarWidget->setVisible(false);
|
ui->menuBarWidget->setVisible(false);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -1587,6 +1634,7 @@ void reader::convertMuPdfVars(int fileType) {
|
||||||
/* fileType can be:
|
/* fileType can be:
|
||||||
* 0: ePUB
|
* 0: ePUB
|
||||||
* 1: PDF
|
* 1: PDF
|
||||||
|
* 2: Image
|
||||||
*/
|
*/
|
||||||
if(fileType == 0) {
|
if(fileType == 0) {
|
||||||
setPageStyle(0);
|
setPageStyle(0);
|
||||||
|
@ -1632,6 +1680,9 @@ void reader::convertMuPdfVars(int fileType) {
|
||||||
}
|
}
|
||||||
mupdf::pdf::pdfPageNumber_qstr = QString::number(mupdf::pdf::pdfPageNumber);
|
mupdf::pdf::pdfPageNumber_qstr = QString::number(mupdf::pdf::pdfPageNumber);
|
||||||
}
|
}
|
||||||
|
else if(fileType == 2) {
|
||||||
|
;
|
||||||
|
}
|
||||||
if(mupdf::convertRelativeValues == true) {
|
if(mupdf::convertRelativeValues == true) {
|
||||||
mupdf::convertRelativeValues = false;
|
mupdf::convertRelativeValues = false;
|
||||||
}
|
}
|
||||||
|
@ -1641,6 +1692,7 @@ void reader::setPageStyle(int fileType) {
|
||||||
/* fileType can be:
|
/* fileType can be:
|
||||||
* 0: ePUB
|
* 0: ePUB
|
||||||
* 1: PDF
|
* 1: PDF
|
||||||
|
* 2: Image
|
||||||
*/
|
*/
|
||||||
if(fileType == 0) {
|
if(fileType == 0) {
|
||||||
// General page size
|
// General page size
|
||||||
|
@ -1977,16 +2029,29 @@ void reader::setupLocalSettingsEnvironment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void reader::setupPng() {
|
void reader::setupPng() {
|
||||||
// Note: Output file is supposed to be '/run/page.png', but somehow mutool puts it in '/run/page1.png'
|
if(is_pdf == true) {
|
||||||
QPixmap pixmap("/run/page1.png");
|
// Note: Output file is supposed to be '/run/page.png', but somehow mutool puts it in '/run/page1.png'
|
||||||
// Initialized above
|
QPixmap pixmap("/run/page1.png");
|
||||||
graphicsScene->clear();
|
// Initialized above
|
||||||
graphicsScene->addPixmap(pixmap);
|
graphicsScene->clear();
|
||||||
// Shrinking scene if item is smaller than previous one
|
graphicsScene->addPixmap(pixmap);
|
||||||
QRectF rect = graphicsScene->itemsBoundingRect();
|
// Shrinking scene if item is smaller than previous one
|
||||||
graphicsScene->setSceneRect(rect);
|
QRectF rect = graphicsScene->itemsBoundingRect();
|
||||||
ui->graphicsView->items().clear();
|
graphicsScene->setSceneRect(rect);
|
||||||
ui->graphicsView->setScene(graphicsScene);
|
ui->graphicsView->items().clear();
|
||||||
|
ui->graphicsView->setScene(graphicsScene);
|
||||||
|
}
|
||||||
|
else if(is_image == true) {
|
||||||
|
QPixmap pixmap("/run/image.png");
|
||||||
|
// Initialized above
|
||||||
|
graphicsScene->clear();
|
||||||
|
graphicsScene->addPixmap(pixmap);
|
||||||
|
// Shrinking scene if item is smaller than previous one
|
||||||
|
QRectF rect = graphicsScene->itemsBoundingRect();
|
||||||
|
graphicsScene->setSceneRect(rect);
|
||||||
|
ui->graphicsView->items().clear();
|
||||||
|
ui->graphicsView->setScene(graphicsScene);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool reader::pdf_file_match(QString file) {
|
bool reader::pdf_file_match(QString file) {
|
||||||
|
@ -2002,6 +2067,21 @@ bool reader::pdf_file_match(QString file) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool reader::image_file_match(QString file) {
|
||||||
|
if(file.right(3) == "png" or file.right(3) == "jpg" or file.right(3) == "bmp" or file.right(3) == "tif") {
|
||||||
|
string_writeconfig("/inkbox/bookIsImage", "true");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if(file.right(4) == "jpeg" or file.right(4) == "tiff") {
|
||||||
|
string_writeconfig("/inkbox/bookIsImage", "true");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
string_writeconfig("/inkbox/bookIsImage", "false");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void reader::getTotalPdfPagesNumber() {
|
void reader::getTotalPdfPagesNumber() {
|
||||||
QString epubProg ("sh");
|
QString epubProg ("sh");
|
||||||
QStringList epubArgs;
|
QStringList epubArgs;
|
||||||
|
|
4
reader.h
4
reader.h
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
// ePUB scaling
|
// ePUB & PDF scaling
|
||||||
namespace mupdf {
|
namespace mupdf {
|
||||||
inline bool convertRelativeValues;
|
inline bool convertRelativeValues;
|
||||||
namespace epub {
|
namespace epub {
|
||||||
|
@ -64,6 +64,7 @@ public:
|
||||||
bool nextdefinition_lock = false;
|
bool nextdefinition_lock = false;
|
||||||
bool is_epub = false;
|
bool is_epub = false;
|
||||||
bool is_pdf = false;
|
bool is_pdf = false;
|
||||||
|
bool is_image = false;
|
||||||
bool parser_ran = false;
|
bool parser_ran = false;
|
||||||
bool filematch_ran = false;
|
bool filematch_ran = false;
|
||||||
bool neverRefresh = false;
|
bool neverRefresh = false;
|
||||||
|
@ -121,6 +122,7 @@ public:
|
||||||
void setCrimsonProFont();
|
void setCrimsonProFont();
|
||||||
void setIbarraFont();
|
void setIbarraFont();
|
||||||
bool pdf_file_match(QString file);
|
bool pdf_file_match(QString file);
|
||||||
|
bool image_file_match(QString file);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_nextBtn_clicked();
|
void on_nextBtn_clicked();
|
||||||
|
|
Loading…
Reference in a new issue