Home screen: Implement two-row recent books

This commit is contained in:
Nicolas Mailloux 2022-06-29 11:42:05 -04:00
parent 7822f65e02
commit ebcfd349f2
6 changed files with 74 additions and 27 deletions

View file

@ -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;

View file

@ -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,7 +69,10 @@ homePageWidget::homePageWidget(QWidget *parent) :
log("Setting up home page", className);
for(int i = 1; i <= global::homePageWidget::recentBooksNumber; i++) {
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();
@ -82,7 +86,7 @@ homePageWidget::homePageWidget(QWidget *parent) :
}
}
verticalLayoutArray[i] = new QVBoxLayout(this);
verticalLayoutArray[i] = new QVBoxLayout();
QObject::connect(bookBtnArray[i], &QClickableLabel::bookPath, this, &homePageWidget::openBook);
bookBtnArray[i]->setAlignment(Qt::AlignCenter);
@ -98,7 +102,20 @@ homePageWidget::homePageWidget(QWidget *parent) :
}
verticalLayoutArray[i]->addWidget(bookBtnArray[i]);
ui->horizontalLayout->addLayout(verticalLayoutArray[i]);
}
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]);
}
if(!(i % global::homePageWidget::recentBooksNumberPerRow)) {
newRow = true;
in++;
}
}
QTimer::singleShot(500, this, SLOT(refreshScreenNative()));
}

View file

@ -35,6 +35,7 @@ private slots:
private:
Ui::homePageWidget *ui;
QVector<QLabel*> bookTitleArray;
QVector<QHBoxLayout*> horizontalLayoutArray;
QVector<QVBoxLayout*> verticalLayoutArray;
QVector<QClickableLabel*> bookBtnArray;
};

View file

@ -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>

View file

@ -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();
}

View file

@ -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;