mirror of
https://github.com/Quill-OS/quill.git
synced 2024-10-31 21:33:22 -07:00
Home screen: Implement two-row recent books
This commit is contained in:
parent
7822f65e02
commit
ebcfd349f2
6 changed files with 74 additions and 27 deletions
|
@ -145,7 +145,9 @@ namespace global {
|
|||
inline bool launchApp;
|
||||
}
|
||||
namespace homePageWidget {
|
||||
inline int recentBooksNumber = 4;
|
||||
inline int recentBooksNumber = 8;
|
||||
inline int recentBooksNumberPerRow = 4;
|
||||
inline int recentBooksRowNumber = global::homePageWidget::recentBooksNumber / global::homePageWidget::recentBooksNumberPerRow;
|
||||
}
|
||||
inline QString systemInfoText;
|
||||
inline bool forbidOpenSearchDialog;
|
||||
|
|
|
@ -11,6 +11,7 @@ homePageWidget::homePageWidget(QWidget *parent) :
|
|||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
horizontalLayoutArray.resize(global::homePageWidget::recentBooksRowNumber);
|
||||
verticalLayoutArray.resize(global::homePageWidget::recentBooksNumber);
|
||||
bookBtnArray.resize(global::homePageWidget::recentBooksNumber);
|
||||
bookTitleArray.resize(global::homePageWidget::recentBooksNumber);
|
||||
|
@ -68,37 +69,53 @@ homePageWidget::homePageWidget(QWidget *parent) :
|
|||
|
||||
log("Setting up home page", className);
|
||||
|
||||
for(int i = 1; i <= global::homePageWidget::recentBooksNumber; i++) {
|
||||
QString objectName = "Book" + QString::number(i);
|
||||
QJsonObject jsonObject = recentBooksJsonObject[objectName].toObject();
|
||||
QString bookPath = jsonObject.value("BookPath").toString();
|
||||
bookBtnArray[i] = new QClickableLabel(this);
|
||||
int in = 0;
|
||||
bool newRow = false;
|
||||
for(int i = 1; i <= (global::homePageWidget::recentBooksNumber + 1); i++) {
|
||||
if(in < global::homePageWidget::recentBooksRowNumber) {
|
||||
QString objectName = "Book" + QString::number(i);
|
||||
QJsonObject jsonObject = recentBooksJsonObject[objectName].toObject();
|
||||
QString bookPath = jsonObject.value("BookPath").toString();
|
||||
bookBtnArray[i] = new QClickableLabel(this);
|
||||
|
||||
// Iterate until we find a book matching the recently opened book's "BookPath" key/value pair
|
||||
for(int in = i; in <= databaseBooksNumber; in++) {
|
||||
QJsonObject bookJsonObject = databaseJsonArrayList.at(in - 1).toObject();
|
||||
if(bookJsonObject["BookPath"] == bookPath) {
|
||||
bookBtnArray[i]->setObjectName(QJsonDocument(bookJsonObject).toJson());
|
||||
// Iterate until we find a book matching the recently opened book's "BookPath" key/value pair
|
||||
for(int in = i; in <= databaseBooksNumber; in++) {
|
||||
QJsonObject bookJsonObject = databaseJsonArrayList.at(in - 1).toObject();
|
||||
if(bookJsonObject["BookPath"] == bookPath) {
|
||||
bookBtnArray[i]->setObjectName(QJsonDocument(bookJsonObject).toJson());
|
||||
}
|
||||
}
|
||||
|
||||
verticalLayoutArray[i] = new QVBoxLayout();
|
||||
|
||||
QObject::connect(bookBtnArray[i], &QClickableLabel::bookPath, this, &homePageWidget::openBook);
|
||||
bookBtnArray[i]->setAlignment(Qt::AlignCenter);
|
||||
bookBtnArray[i]->setFont(QFont("u001"));
|
||||
bookBtnArray[i]->setStyleSheet("color: black; background-color: white; border-radius: 10px; padding: 10px");
|
||||
|
||||
QString bookIcon = QJsonDocument::fromJson(bookBtnArray[i]->objectName().toUtf8()).object()["CoverPath"].toString();
|
||||
if(QFile::exists(bookIcon)) {
|
||||
bookBtnArray[i]->setPixmap(QPixmap(bookIcon).scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio));
|
||||
}
|
||||
else {
|
||||
bookBtnArray[i]->setPixmap(QPixmap(":/resources/cover_unavailable").scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio));
|
||||
}
|
||||
|
||||
verticalLayoutArray[i]->addWidget(bookBtnArray[i]);
|
||||
}
|
||||
|
||||
verticalLayoutArray[i] = new QVBoxLayout(this);
|
||||
|
||||
QObject::connect(bookBtnArray[i], &QClickableLabel::bookPath, this, &homePageWidget::openBook);
|
||||
bookBtnArray[i]->setAlignment(Qt::AlignCenter);
|
||||
bookBtnArray[i]->setFont(QFont("u001"));
|
||||
bookBtnArray[i]->setStyleSheet("color: black; background-color: white; border-radius: 10px; padding: 10px");
|
||||
|
||||
QString bookIcon = QJsonDocument::fromJson(bookBtnArray[i]->objectName().toUtf8()).object()["CoverPath"].toString();
|
||||
if(QFile::exists(bookIcon)) {
|
||||
bookBtnArray[i]->setPixmap(QPixmap(bookIcon).scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio));
|
||||
if(newRow == true) {
|
||||
newRow = false;
|
||||
horizontalLayoutArray[in] = new QHBoxLayout();
|
||||
for(int n = ((i - 1) - (global::homePageWidget::recentBooksNumberPerRow - 1)); n < (((i - 1) - (global::homePageWidget::recentBooksNumberPerRow - 1)) + global::homePageWidget::recentBooksNumberPerRow); n++) {
|
||||
horizontalLayoutArray[in]->addLayout(verticalLayoutArray[n]);
|
||||
}
|
||||
ui->booksVerticalLayout->addLayout(horizontalLayoutArray[in]);
|
||||
}
|
||||
else {
|
||||
bookBtnArray[i]->setPixmap(QPixmap(":/resources/cover_unavailable").scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio));
|
||||
if(!(i % global::homePageWidget::recentBooksNumberPerRow)) {
|
||||
newRow = true;
|
||||
in++;
|
||||
}
|
||||
|
||||
verticalLayoutArray[i]->addWidget(bookBtnArray[i]);
|
||||
ui->horizontalLayout->addLayout(verticalLayoutArray[i]);
|
||||
}
|
||||
QTimer::singleShot(500, this, SLOT(refreshScreenNative()));
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@ private slots:
|
|||
private:
|
||||
Ui::homePageWidget *ui;
|
||||
QVector<QLabel*> bookTitleArray;
|
||||
QVector<QHBoxLayout*> horizontalLayoutArray;
|
||||
QVector<QVBoxLayout*> verticalLayoutArray;
|
||||
QVector<QClickableLabel*> bookBtnArray;
|
||||
};
|
||||
|
|
|
@ -50,7 +50,10 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<layout class="QVBoxLayout" name="booksVerticalLayout">
|
||||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SetNoConstraint</enum>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>25</number>
|
||||
</property>
|
||||
|
|
|
@ -11,6 +11,7 @@ localLibraryWidget::localLibraryWidget(QWidget *parent) :
|
|||
{
|
||||
ui->setupUi(this);
|
||||
this->setFont(QFont("u001"));
|
||||
QObject::connect(ui->pageNumberLabel, &QClickableLabel::clicked, this, &localLibraryWidget::openGoToPageDialog);
|
||||
|
||||
ui->previousPageBtn->setProperty("type", "borderless");
|
||||
ui->previousPageBtn->setEnabled(false);
|
||||
|
@ -308,6 +309,25 @@ void localLibraryWidget::btnOpenBook(int buttonNumber) {
|
|||
localLibraryWidget::close();
|
||||
}
|
||||
|
||||
void localLibraryWidget::openGoToPageDialog() {
|
||||
log("Showing 'Go to page' dialog", className);
|
||||
global::keyboard::keypadDialog = true;
|
||||
generalDialogWindow = new generalDialog();
|
||||
generalDialogWindow->setAttribute(Qt::WA_DeleteOnClose);
|
||||
QObject::connect(generalDialogWindow, &generalDialog::gotoPageSelected, this, &localLibraryWidget::goToPage);
|
||||
}
|
||||
|
||||
void localLibraryWidget::goToPage(int page) {
|
||||
if(page > pagesNumber or page <= 0) {
|
||||
log("Page number specified (" + QString::number(page) + ") is out of range", className);
|
||||
}
|
||||
else {
|
||||
log("Going to page " + QString::number(page), className);
|
||||
setupBooksList(page);
|
||||
emit refreshScreen();
|
||||
}
|
||||
}
|
||||
|
||||
void localLibraryWidget::refreshScreenNative() {
|
||||
emit refreshScreen();
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
#include "functions.h"
|
||||
#include "qclickablelabel.h"
|
||||
#include "generaldialog.h"
|
||||
|
||||
namespace Ui {
|
||||
class localLibraryWidget;
|
||||
|
@ -46,9 +47,12 @@ private slots:
|
|||
void openBook(int id);
|
||||
void btnOpenBook(int buttonNumber);
|
||||
void refreshScreenNative();
|
||||
void openGoToPageDialog();
|
||||
void goToPage(int page);
|
||||
|
||||
private:
|
||||
Ui::localLibraryWidget * ui;
|
||||
generalDialog * generalDialogWindow;
|
||||
QVector<QHBoxLayout*> horizontalLayoutArray;
|
||||
QVector<QLabel*> bookIconArray;
|
||||
QVector<QClickableLabel*> bookBtnArray;
|
||||
|
|
Loading…
Reference in a new issue