diff --git a/inkbox.pro b/inkbox.pro index 3f632cb..f0a0e06 100644 --- a/inkbox.pro +++ b/inkbox.pro @@ -40,6 +40,7 @@ SOURCES += \ main.cpp \ mainwindow.cpp \ otamanager.cpp \ + qclickablelabel.cpp \ quit.cpp \ reader.cpp \ savedwords.cpp \ @@ -71,6 +72,7 @@ HEADERS += \ locallibrarywidget.h \ mainwindow.h \ otamanager.h \ + qclickablelabel.h \ quit.h \ reader.h \ savedwords.h \ diff --git a/locallibrarywidget.cpp b/locallibrarywidget.cpp index 2797f4d..d8ef05f 100644 --- a/locallibrarywidget.cpp +++ b/locallibrarywidget.cpp @@ -1,14 +1,91 @@ #include "locallibrarywidget.h" #include "ui_locallibrarywidget.h" +#include +#include +#include + localLibraryWidget::localLibraryWidget(QWidget *parent) : QWidget(parent), ui(new Ui::localLibraryWidget) { ui->setupUi(this); + this->setFont(QFont("u001")); + + /*for(int i = 7; i <= 9; i++) { + bookBtnArray[i]->deleteLater(); + bookIconArray[i]->deleteLater(); + }*/ + //bookBtnArray[7]->deleteLater(); + + if(global::deviceID == "n705\n" or global::deviceID == "n905\n") { + buttonsNumber = 4; + } + else if(global::deviceID == "n613\n" or global::deviceID == "n236\n" or global::deviceID == "n306\n") { + buttonsNumber = 5; + } + else if(global::deviceID == "n437\n" or global::deviceID == "n873\n") { + buttonsNumber = 5; + } + else { + buttonsNumber = 3; + } + + // Getting the screen's size + sW = QGuiApplication::screens()[0]->size().width(); + sH = QGuiApplication::screens()[0]->size().height(); + + // Defining what the default icon size will be + if(global::deviceID == "n705\n") { + stdIconWidth = sW / 16; + stdIconHeight = sH / 16; + } + else if(global::deviceID == "n905\n" or global::deviceID == "kt\n") { + stdIconWidth = sW / 18; + stdIconHeight = sH / 18; + } + else if(global::deviceID == "n613\n" or global::deviceID == "n236\n" or global::deviceID == "n437\n" or global::deviceID == "n306\n" or global::deviceID == "emu\n") { + stdIconWidth = sW / 16.5; + stdIconHeight = sH / 16.5; + } + else { + stdIconWidth = sW / 18; + stdIconHeight = sH / 18; + } + + for(int i = 1; i <= buttonsNumber; i++) { + // Horizontal layout that will contain the book button and its icon + QHBoxLayout * horizontalLayout = new QHBoxLayout(this); + + // Book icon + bookIconArray[i] = new QLabel(this); + + // Book button + bookBtnArray[i] = new QClickableLabel(this); + bookBtnArray[i]->setProperty("type", "borderless"); + bookIconArray[i]->setStyleSheet("padding: 20px"); + bookBtnArray[i]->setFont(QFont("u001")); + + // Spacer + QSpacerItem * horizontalSpacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Expanding); + + horizontalLayout->addWidget(bookIconArray[i]); + horizontalLayout->addWidget(bookBtnArray[i]); + horizontalLayout->addSpacerItem(horizontalSpacer); + ui->booksVerticalLayout->addLayout(horizontalLayout); + } + setupBooksList(); } localLibraryWidget::~localLibraryWidget() { delete ui; } + +void localLibraryWidget::setupBooksList() { + for(int i = 1; i <= buttonsNumber; i++) { + QPixmap pixmap(":/resources/starred_star.png"); + bookIconArray[i]->setPixmap(pixmap.scaled(stdIconWidth, stdIconHeight)); + bookBtnArray[i]->setText("Book " + QString::number(i) + "
Description"); + } +} diff --git a/locallibrarywidget.h b/locallibrarywidget.h index 071a794..da82eaa 100644 --- a/locallibrarywidget.h +++ b/locallibrarywidget.h @@ -2,6 +2,10 @@ #define LOCALLIBRARYWIDGET_H #include +#include + +#include "functions.h" +#include "qclickablelabel.h" namespace Ui { class localLibraryWidget; @@ -12,11 +16,22 @@ class localLibraryWidget : public QWidget Q_OBJECT public: + QString className = this->metaObject()->className(); explicit localLibraryWidget(QWidget *parent = nullptr); ~localLibraryWidget(); + int buttonsNumber; + int sW; + int sH; + int stdIconWidth; + int stdIconHeight; + +private slots: + void setupBooksList(); private: - Ui::localLibraryWidget *ui; + Ui::localLibraryWidget * ui; + QLabel * bookIconArray[10]; + QClickableLabel * bookBtnArray[10]; }; #endif // LOCALLIBRARYWIDGET_H diff --git a/locallibrarywidget.ui b/locallibrarywidget.ui index 0317ba1..c675c78 100644 --- a/locallibrarywidget.ui +++ b/locallibrarywidget.ui @@ -10,19 +10,40 @@ 300 + + + 75 + true + + Form + + 0 + + + 0 + + + 0 + + + 0 + - - - - - Hello - - - + + + <b>Local library</b> + + + + + + + QLayout::SetMaximumSize + diff --git a/mainwindow.cpp b/mainwindow.cpp index cd62e29..5a6074e 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -998,5 +998,6 @@ void MainWindow::resetWifiIconClickedWhileReconnecting() { void MainWindow::setupLocalLibraryWidget() { localLibraryWidgetWindow = new localLibraryWidget(); libraryWidgetWindow->setAttribute(Qt::WA_DeleteOnClose); - ui->stackedWidget->insertWidget(1, localLibraryWidgetWindow); + ui->homeStackedWidget->insertWidget(1, localLibraryWidgetWindow); + ui->homeStackedWidget->setCurrentIndex(1); } diff --git a/mainwindow.ui b/mainwindow.ui index 7f76a4b..d0359d1 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -191,6 +191,18 @@ + + 0 + + + 0 + + + 0 + + + 0 + @@ -359,7 +371,20 @@ - + + + 0 + + + 0 + + + 0 + + + 0 + + diff --git a/qclickablelabel.cpp b/qclickablelabel.cpp new file mode 100644 index 0000000..4960700 --- /dev/null +++ b/qclickablelabel.cpp @@ -0,0 +1,12 @@ +#include "qclickablelabel.h" + +QClickableLabel::QClickableLabel(QWidget* parent, Qt::WindowFlags f) + : QLabel(parent) { + +} + +QClickableLabel::~QClickableLabel() {} + +void QClickableLabel::mousePressEvent(QMouseEvent* event) { + emit clicked(); +} diff --git a/qclickablelabel.h b/qclickablelabel.h new file mode 100644 index 0000000..2d716a9 --- /dev/null +++ b/qclickablelabel.h @@ -0,0 +1,23 @@ +#ifndef QCLICKABLELABEL_H +#define QCLICKABLELABEL_H + +#include +#include +#include + +class QClickableLabel : public QLabel { + Q_OBJECT + +public: + explicit QClickableLabel(QWidget* parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags()); + ~QClickableLabel(); + +signals: + void clicked(); + +protected: + void mousePressEvent(QMouseEvent* event); + +}; + +#endif // CLICKABLELABEL_H