Implement local book info dialog

This commit is contained in:
Nicolas Mailloux 2022-07-12 12:34:36 -04:00
parent 80bdeb32ed
commit 03c2732aff
9 changed files with 120 additions and 58 deletions

View file

@ -30,6 +30,7 @@ bookInfoDialog::bookInfoDialog(QWidget *parent) :
stdIconWidth = sW / 4;
stdIconHeight = sH / 4;
if(global::bookInfoDialog::localInfoDialog == false) {
if(global::library::isLatestBook == true) {
QString bookNumberQstr = QString::number(global::library::latestBookNumber);
@ -77,10 +78,47 @@ bookInfoDialog::bookInfoDialog(QWidget *parent) :
}
log("Setting up book info dialog, ID: " + QString::number(global::library::bookId) + ", title: " + global::library::bookTitle, className);
}
else {
QJsonObject bookJsonObject = getBookMetadata(global::localLibrary::bookOptionsDialog::bookID);
QString bookInfo;
QString title = bookJsonObject["Title"].toString();
QString author = bookJsonObject["Author"].toString();
QString publicationDate = bookJsonObject["PublicationDate"].toString();
QString path = bookJsonObject["BookPath"].toString();
if(!title.isEmpty()) {
bookInfo.append("<b>Title:</b> " + title + "<br>");
}
if(!author.isEmpty()) {
bookInfo.append("<b>Author:</b> " + author + "<br>");
}
if(!publicationDate.isEmpty()) {
bookInfo.append("<b>Publication date:</b> " + publicationDate + "<br>");
}
if(!path.isEmpty()) {
bookInfo.append("<b>Path:</b> " + path + "<br>");
}
log(bookInfo, className);
global::text::textBrowserContents = bookInfo;
textwidget * textwidgetWindow = new textwidget(this);
ui->stackedWidget->insertWidget(1, textwidgetWindow);
ui->stackedWidget->setCurrentIndex(1);
}
QRect screenGeometry = QGuiApplication::screens()[0]->geometry();
{
int wx = screenGeometry.width();
int x = wx - 25;
int y = this->height() * determineYIncrease();
this->setFixedWidth(x);
this->setFixedHeight(y);
this->adjustSize();
}
// Centering dialog
this->adjustSize();
QRect screenGeometry = QGuiApplication::screens()[0]->geometry();
int x = (screenGeometry.width() - this->width()) / 2;
int y = (screenGeometry.height() - this->height()) / 2;
this->move(x, y);
@ -94,6 +132,7 @@ bookInfoDialog::~bookInfoDialog()
void bookInfoDialog::on_closeBtn_clicked()
{
global::library::bookTitle = "";
global::bookInfoDialog::localInfoDialog = false;
bookInfoDialog::close();
}

View file

@ -3,6 +3,8 @@
#include <QDialog>
#include "textwidget.h"
namespace Ui {
class bookInfoDialog;
}
@ -31,6 +33,7 @@ signals:
private:
Ui::bookInfoDialog * ui;
textwidget * textwidgetWindow;
};
#endif // BOOKINFODIALOG_H

View file

@ -183,7 +183,9 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="page_2"/>
<widget class="QWidget" name="page_2">
<layout class="QVBoxLayout" name="verticalLayout_3"/>
</widget>
</widget>
</item>
</layout>

View file

@ -35,9 +35,7 @@ void bookOptionsDialog::on_deleteBtn_clicked()
ui->deleteBtn->setStyleSheet("padding: 10px; color: lightGrey");
}
void bookOptionsDialog::on_infoBtn_clicked()
{
// TODO
emit openLocalBookInfoDialog();
}

View file

@ -23,6 +23,9 @@ private slots:
void on_deleteBtn_clicked();
void on_infoBtn_clicked();
signals:
void openLocalBookInfoDialog();
private:
Ui::bookOptionsDialog *ui;
};

View file

@ -126,6 +126,9 @@ namespace global {
inline bool librarySearchDialog;
inline bool libraryResults;
}
namespace bookInfoDialog {
inline bool localInfoDialog;
}
namespace localLibrary {
static inline QString rawDatabasePath = "/inkbox/LocalLibrary.db.raw";
static inline QString databaseDirectoryPath = "/mnt/onboard/onboard/.database/";
@ -184,7 +187,7 @@ namespace {
int defaultPdfPageHeight;
bool checked_box = false;
QFile logFile("/external_root/var/log/inkbox-gui.log");
void log(QString message, QString className, bool applicationStart = false) {
void log(QString message, QString className = "undefined", bool applicationStart = false) {
if(global::logger::status == true) {
QString initialTime;
if(applicationStart == true) {
@ -1001,6 +1004,20 @@ namespace {
QJsonArray jsonArrayList = jsonObject["database"].toArray();
return jsonArrayList.at(bookID - 1).toObject();
}
float determineYIncrease() {
if(global::deviceID == "n705\n" or global::deviceID == "n905\n") {
return 2;
}
else if(global::deviceID == "n613\n" or global::deviceID == "n236\n" or global::deviceID == "n306\n") {
return 2.6;
}
else if(global::deviceID == "n437\n" or global::deviceID == "n873\n") {
return 3;
}
else {
return 2;
}
}
}
#endif // FUNCTIONS_H

View file

@ -359,9 +359,10 @@ void localLibraryWidget::showToast(QString messageToDisplay) {
}
void localLibraryWidget::openBookOptionsDialog(int bookID) {
log("Opening book options dialog for book with ID " + QString::number(bookID), className);
log("Opening book options dialog for book with pseudo-ID " + QString::number(bookID), className);
global::localLibrary::bookOptionsDialog::bookID = bookID;
bookOptionsDialog * bookOptionsDialogWindow = new bookOptionsDialog(this);
QObject::connect(bookOptionsDialogWindow, &bookOptionsDialog::openLocalBookInfoDialog, this, &localLibraryWidget::openLocalBookInfoDialog);
QObject::connect(bookOptionsDialogWindow, &bookOptionsDialog::destroyed, this, &localLibraryWidget::handlePossibleBookDeletion);
bookOptionsDialogWindow->setAttribute(Qt::WA_DeleteOnClose);
bookOptionsDialogWindow->setWindowFlags(Qt::FramelessWindowHint | Qt::Popup);
@ -377,3 +378,10 @@ void localLibraryWidget::handlePossibleBookDeletion() {
QTimer::singleShot(100, this, SLOT(setupDisplay()));
}
}
void localLibraryWidget::openLocalBookInfoDialog() {
global::bookInfoDialog::localInfoDialog = true;
bookInfoDialog * bookInfoDialogWindow = new bookInfoDialog(this);
bookInfoDialogWindow->setAttribute(Qt::WA_DeleteOnClose);
bookInfoDialogWindow->show();
}

View file

@ -10,6 +10,7 @@
#include "generaldialog.h"
#include "toast.h"
#include "bookoptionsdialog.h"
#include "bookinfodialog.h"
namespace Ui {
class localLibraryWidget;
@ -55,12 +56,14 @@ private slots:
void showToast(QString messageToDisplay);
void openBookOptionsDialog(int bookID);
void handlePossibleBookDeletion();
void openLocalBookInfoDialog();
private:
Ui::localLibraryWidget * ui;
generalDialog * generalDialogWindow;
bookOptionsDialog * bookOptionsDialogWindow;
toast * toastWindow;
bookInfoDialog * bookInfoDialogWindow;
QVector<QHBoxLayout*> horizontalLayoutArray;
QVector<QLabel*> bookIconArray;
QVector<QClickableLabel*> bookBtnArray;

View file

@ -822,18 +822,7 @@ void settings::on_showSystemInfoBtn_clicked()
// Show a system info dialog
log("Showing system info dialog", className);
generalDialogWindow = new generalDialog();
if(global::deviceID == "n705\n" or global::deviceID == "n905\n") {
generalDialogWindow->yIncrease = 2;
}
else if(global::deviceID == "n613\n" or global::deviceID == "n236\n" or global::deviceID == "n306\n") {
generalDialogWindow->yIncrease = 2.6;
}
else if(global::deviceID == "n437\n" or global::deviceID == "n873\n") {
generalDialogWindow->yIncrease = 3;
}
else {
generalDialogWindow->yIncrease = 2;
}
generalDialogWindow->yIncrease = determineYIncrease();
generalDialogWindow->increaseSize();
generalDialogWindow->setAttribute(Qt::WA_DeleteOnClose);
}