mirror of
https://github.com/Quill-OS/quill.git
synced 2024-10-31 21:33:22 -07:00
Local library: Functional improvements
This commit is contained in:
parent
4a104522f5
commit
2014500317
3 changed files with 69 additions and 8 deletions
|
@ -1,7 +1,7 @@
|
||||||
#include "locallibrarywidget.h"
|
#include "locallibrarywidget.h"
|
||||||
#include "ui_locallibrarywidget.h"
|
#include "ui_locallibrarywidget.h"
|
||||||
|
|
||||||
#include <QHBoxLayout>
|
#include <QVBoxLayout>
|
||||||
#include <QSpacerItem>
|
#include <QSpacerItem>
|
||||||
#include <QScreen>
|
#include <QScreen>
|
||||||
|
|
||||||
|
@ -13,10 +13,12 @@ localLibraryWidget::localLibraryWidget(QWidget *parent) :
|
||||||
this->setFont(QFont("u001"));
|
this->setFont(QFont("u001"));
|
||||||
|
|
||||||
ui->previousPageBtn->setProperty("type", "borderless");
|
ui->previousPageBtn->setProperty("type", "borderless");
|
||||||
|
ui->previousPageBtn->setEnabled(false);
|
||||||
ui->nextPageBtn->setProperty("type", "borderless");
|
ui->nextPageBtn->setProperty("type", "borderless");
|
||||||
ui->previousPageBtn->setIcon(QIcon(":/resources/chevron-left.png"));
|
ui->previousPageBtn->setIcon(QIcon(":/resources/chevron-left.png"));
|
||||||
ui->nextPageBtn->setIcon(QIcon(":/resources/chevron-right.png"));
|
ui->nextPageBtn->setIcon(QIcon(":/resources/chevron-right.png"));
|
||||||
ui->pageNumberLabel->setFont(QFont("Source Serif Pro"));
|
ui->pageNumberLabel->setFont(QFont("Source Serif Pro"));
|
||||||
|
ui->verticalLayout->setSpacing(4);
|
||||||
|
|
||||||
if(global::deviceID == "n705\n" or global::deviceID == "n905\n") {
|
if(global::deviceID == "n705\n" or global::deviceID == "n905\n") {
|
||||||
buttonsNumber = 4;
|
buttonsNumber = 4;
|
||||||
|
@ -55,7 +57,7 @@ localLibraryWidget::localLibraryWidget(QWidget *parent) :
|
||||||
|
|
||||||
for(int i = 1; i <= buttonsNumber; i++) {
|
for(int i = 1; i <= buttonsNumber; i++) {
|
||||||
// Horizontal layout that will contain the book button and its icon
|
// Horizontal layout that will contain the book button and its icon
|
||||||
QHBoxLayout * horizontalLayout = new QHBoxLayout(this);
|
horizontalLayoutArray[i] = new QHBoxLayout(this);
|
||||||
|
|
||||||
// Book icon label
|
// Book icon label
|
||||||
bookIconArray[i] = new QLabel(this);
|
bookIconArray[i] = new QLabel(this);
|
||||||
|
@ -69,9 +71,18 @@ localLibraryWidget::localLibraryWidget(QWidget *parent) :
|
||||||
bookBtnArray[i]->setStyleSheet("color: black; background-color: white; border-radius: 10px; padding: 10px");
|
bookBtnArray[i]->setStyleSheet("color: black; background-color: white; border-radius: 10px; padding: 10px");
|
||||||
bookBtnArray[i]->setFont(QFont("u001"));
|
bookBtnArray[i]->setFont(QFont("u001"));
|
||||||
|
|
||||||
horizontalLayout->addWidget(bookIconArray[i]);
|
horizontalLayoutArray[i]->addWidget(bookIconArray[i]);
|
||||||
horizontalLayout->addWidget(bookBtnArray[i]);
|
horizontalLayoutArray[i]->addWidget(bookBtnArray[i]);
|
||||||
ui->booksVerticalLayout->addLayout(horizontalLayout);
|
ui->booksVerticalLayout->addLayout(horizontalLayoutArray[i]);
|
||||||
|
|
||||||
|
// Line
|
||||||
|
if(i < buttonsNumber) {
|
||||||
|
lineArray[i] = new QFrame(this);
|
||||||
|
lineArray[i]->setFrameShape(QFrame::HLine);
|
||||||
|
lineArray[i]->setFrameShadow(QFrame::Plain);
|
||||||
|
lineArray[i]->setLineWidth(1);
|
||||||
|
ui->booksVerticalLayout->addWidget(lineArray[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
setupDatabase();
|
setupDatabase();
|
||||||
setupBooksList(currentPageNumber);
|
setupBooksList(currentPageNumber);
|
||||||
|
@ -130,6 +141,9 @@ void localLibraryWidget::setupDatabase() {
|
||||||
// Parse JSON data
|
// Parse JSON data
|
||||||
databaseJsonObject = databaseJsonDocument.object();
|
databaseJsonObject = databaseJsonDocument.object();
|
||||||
databaseJsonArrayList = databaseJsonObject["database"].toArray();
|
databaseJsonArrayList = databaseJsonObject["database"].toArray();
|
||||||
|
// Determine maximum page number
|
||||||
|
booksNumber = databaseJsonArrayList.size();
|
||||||
|
pagesNumber = std::ceil((double)booksNumber / buttonsNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
void localLibraryWidget::setupBooksList(int pageNumber) {
|
void localLibraryWidget::setupBooksList(int pageNumber) {
|
||||||
|
@ -137,25 +151,50 @@ void localLibraryWidget::setupBooksList(int pageNumber) {
|
||||||
int in = 1;
|
int in = 1;
|
||||||
for(int i = (1 * pageNumber * buttonsNumber) - (buttonsNumber - 1); i <= (1 * pageNumber * buttonsNumber); i++) {
|
for(int i = (1 * pageNumber * buttonsNumber) - (buttonsNumber - 1); i <= (1 * pageNumber * buttonsNumber); i++) {
|
||||||
// Read database info for each book and display the corresponding information on each button
|
// Read database info for each book and display the corresponding information on each button
|
||||||
|
bookIconArray[in]->show();
|
||||||
|
bookBtnArray[in]->show();
|
||||||
|
lineArray[(in - 1)]->show();
|
||||||
|
|
||||||
QJsonObject jsonObject = databaseJsonArrayList.at(i - 1).toObject();
|
QJsonObject jsonObject = databaseJsonArrayList.at(i - 1).toObject();
|
||||||
QString bookTitle = jsonObject["Title"].toString();
|
QString bookTitle = jsonObject["Title"].toString();
|
||||||
QString bookAuthor = jsonObject["Author"].toString();
|
QString bookAuthor = jsonObject["Author"].toString();
|
||||||
QString coverPath = jsonObject["CoverPath"].toString();
|
QString coverPath = jsonObject["CoverPath"].toString();
|
||||||
QString bookID = jsonObject["BookID"].toString();
|
QString bookID = jsonObject["BookID"].toString();
|
||||||
if(!coverPath.isEmpty()) {
|
if(!coverPath.isEmpty()) {
|
||||||
|
// Display book cover if found
|
||||||
QPixmap pixmap(coverPath);
|
QPixmap pixmap(coverPath);
|
||||||
bookIconArray[in]->setPixmap(pixmap);
|
bookIconArray[in]->setPixmap(pixmap);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
QPixmap pixmap(":/resources/cover_unavailable.png");
|
||||||
|
bookIconArray[in]->setPixmap(pixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio));
|
||||||
|
}
|
||||||
|
// Display book title
|
||||||
idList->append(bookID.toInt());
|
idList->append(bookID.toInt());
|
||||||
bookBtnArray[in]->setText("<b>" + bookTitle + "</b>" + "<br>" + bookAuthor);
|
bookBtnArray[in]->setText("<b>" + bookTitle + "</b>" + "<br>" + bookAuthor);
|
||||||
in++;
|
if(!bookID.isEmpty()) {
|
||||||
|
in++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ui->pageNumberLabel->setText("Page " + QString::number(pageNumber) + " <i>of</i> " + "10");
|
if(in < buttonsNumber) {
|
||||||
|
for(int i = in; i <= buttonsNumber; i++) {
|
||||||
|
bookIconArray[i]->hide();
|
||||||
|
bookBtnArray[i]->hide();
|
||||||
|
if(i - 1 <= buttonsNumber) {
|
||||||
|
lineArray[(i - 1)]->hide();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ui->pageNumberLabel->setText("Page " + QString::number(pageNumber) + " <i>of</i> " + QString::number(pagesNumber));
|
||||||
}
|
}
|
||||||
|
|
||||||
void localLibraryWidget::on_previousPageBtn_clicked()
|
void localLibraryWidget::on_previousPageBtn_clicked()
|
||||||
{
|
{
|
||||||
currentPageNumber--;
|
currentPageNumber--;
|
||||||
|
if(currentPageNumber - 1 < 1) {
|
||||||
|
ui->previousPageBtn->setEnabled(false);
|
||||||
|
ui->nextPageBtn->setEnabled(true);
|
||||||
|
}
|
||||||
setupBooksList(currentPageNumber);
|
setupBooksList(currentPageNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,6 +202,10 @@ void localLibraryWidget::on_previousPageBtn_clicked()
|
||||||
void localLibraryWidget::on_nextPageBtn_clicked()
|
void localLibraryWidget::on_nextPageBtn_clicked()
|
||||||
{
|
{
|
||||||
currentPageNumber++;
|
currentPageNumber++;
|
||||||
|
if(currentPageNumber + 1 > pagesNumber) {
|
||||||
|
ui->previousPageBtn->setEnabled(true);
|
||||||
|
ui->nextPageBtn->setEnabled(false);
|
||||||
|
}
|
||||||
setupBooksList(currentPageNumber);
|
setupBooksList(currentPageNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,5 +219,5 @@ void localLibraryWidget::openBook(int bookID) {
|
||||||
void localLibraryWidget::btnOpenBook(int buttonNumber) {
|
void localLibraryWidget::btnOpenBook(int buttonNumber) {
|
||||||
int id = idList->at(buttonNumber - 1);
|
int id = idList->at(buttonNumber - 1);
|
||||||
openBook(id);
|
openBook(id);
|
||||||
// localLibraryWidget::close();
|
localLibraryWidget::close();
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
|
#include <QHBoxLayout>
|
||||||
|
|
||||||
#include "functions.h"
|
#include "functions.h"
|
||||||
#include "qclickablelabel.h"
|
#include "qclickablelabel.h"
|
||||||
|
@ -28,6 +29,8 @@ public:
|
||||||
QJsonObject databaseJsonObject;
|
QJsonObject databaseJsonObject;
|
||||||
QJsonArray databaseJsonArrayList;
|
QJsonArray databaseJsonArrayList;
|
||||||
int currentPageNumber = 1;
|
int currentPageNumber = 1;
|
||||||
|
int pagesNumber;
|
||||||
|
int booksNumber;
|
||||||
QList<int> idList[4];
|
QList<int> idList[4];
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
@ -40,8 +43,10 @@ private slots:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::localLibraryWidget * ui;
|
Ui::localLibraryWidget * ui;
|
||||||
|
QHBoxLayout * horizontalLayoutArray[4];
|
||||||
QLabel * bookIconArray[4];
|
QLabel * bookIconArray[4];
|
||||||
QClickableLabel * bookBtnArray[4];
|
QClickableLabel * bookBtnArray[4];
|
||||||
|
QFrame * lineArray[3];
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void openBookSignal(QString bookFile, bool relativePath);
|
void openBookSignal(QString bookFile, bool relativePath);
|
||||||
|
|
|
@ -84,6 +84,19 @@
|
||||||
</property>
|
</property>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="verticalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Vertical</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>20</width>
|
||||||
|
<height>40</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources/>
|
||||||
|
|
Loading…
Reference in a new issue