mirror of
https://github.com/Quill-OS/quill.git
synced 2024-12-25 15:17:21 -08:00
Home page: Implement QToolTipLabel and book titles
This commit is contained in:
parent
ebcfd349f2
commit
5c50911642
8 changed files with 91 additions and 3 deletions
|
@ -16,6 +16,16 @@ homePageWidget::homePageWidget(QWidget *parent) :
|
|||
bookBtnArray.resize(global::homePageWidget::recentBooksNumber);
|
||||
bookTitleArray.resize(global::homePageWidget::recentBooksNumber);
|
||||
|
||||
if(global::deviceID == "n705\n") {
|
||||
bookTitleTruncateThreshold = 20;
|
||||
}
|
||||
else if(global::deviceID == "n873\n") {
|
||||
bookTitleTruncateThreshold = 35;
|
||||
}
|
||||
else {
|
||||
bookTitleTruncateThreshold = 25;
|
||||
}
|
||||
|
||||
// Getting the screen's size
|
||||
sW = QGuiApplication::screens()[0]->size().width();
|
||||
sH = QGuiApplication::screens()[0]->size().height();
|
||||
|
@ -77,6 +87,7 @@ homePageWidget::homePageWidget(QWidget *parent) :
|
|||
QJsonObject jsonObject = recentBooksJsonObject[objectName].toObject();
|
||||
QString bookPath = jsonObject.value("BookPath").toString();
|
||||
bookBtnArray[i] = new QClickableLabel(this);
|
||||
bookTitleArray[i] = new QToolTipLabel(this);
|
||||
|
||||
// Iterate until we find a book matching the recently opened book's "BookPath" key/value pair
|
||||
for(int in = i; in <= databaseBooksNumber; in++) {
|
||||
|
@ -88,10 +99,32 @@ homePageWidget::homePageWidget(QWidget *parent) :
|
|||
|
||||
verticalLayoutArray[i] = new QVBoxLayout();
|
||||
|
||||
// Book icon button
|
||||
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");
|
||||
// Book title label
|
||||
bookTitleArray[i]->setWordWrap(true);
|
||||
bookTitleArray[i]->setAlignment(Qt::AlignCenter);
|
||||
bookTitleArray[i]->setFont(QFont("u001"));
|
||||
bookTitleArray[i]->setStyleSheet("font-size: 7pt");
|
||||
|
||||
QString bookTitle = QJsonDocument::fromJson(bookBtnArray[i]->objectName().toUtf8()).object()["Title"].toString();
|
||||
bookTitleArray[i]->setObjectName(bookTitle);
|
||||
|
||||
int localBookTitleTruncateThreshold;
|
||||
if(!bookTitle.contains(" ")) {
|
||||
localBookTitleTruncateThreshold = bookTitleTruncateThreshold - 10;
|
||||
}
|
||||
else {
|
||||
localBookTitleTruncateThreshold = bookTitleTruncateThreshold;
|
||||
}
|
||||
if(bookTitle.length() > localBookTitleTruncateThreshold) {
|
||||
bookTitle.truncate(localBookTitleTruncateThreshold);
|
||||
bookTitle.append("...");
|
||||
}
|
||||
bookTitleArray[i]->setText(bookTitle);
|
||||
|
||||
QString bookIcon = QJsonDocument::fromJson(bookBtnArray[i]->objectName().toUtf8()).object()["CoverPath"].toString();
|
||||
if(QFile::exists(bookIcon)) {
|
||||
|
@ -102,6 +135,7 @@ homePageWidget::homePageWidget(QWidget *parent) :
|
|||
}
|
||||
|
||||
verticalLayoutArray[i]->addWidget(bookBtnArray[i]);
|
||||
verticalLayoutArray[i]->addWidget(bookTitleArray[i]);
|
||||
}
|
||||
|
||||
if(newRow == true) {
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <QWidget>
|
||||
#include <QVBoxLayout>
|
||||
#include "qclickablelabel.h"
|
||||
#include "qtooltiplabel.h"
|
||||
|
||||
namespace Ui {
|
||||
class homePageWidget;
|
||||
|
@ -23,6 +24,7 @@ public:
|
|||
int stdIconHeight;
|
||||
float stdIconWidthDivider;
|
||||
float stdIconHeightDivider;
|
||||
int bookTitleTruncateThreshold;
|
||||
|
||||
signals:
|
||||
void openBookSignal(QString bookPath, bool relativePath);
|
||||
|
@ -34,7 +36,7 @@ private slots:
|
|||
|
||||
private:
|
||||
Ui::homePageWidget *ui;
|
||||
QVector<QLabel*> bookTitleArray;
|
||||
QVector<QToolTipLabel*> bookTitleArray;
|
||||
QVector<QHBoxLayout*> horizontalLayoutArray;
|
||||
QVector<QVBoxLayout*> verticalLayoutArray;
|
||||
QVector<QClickableLabel*> bookBtnArray;
|
||||
|
|
|
@ -55,10 +55,20 @@
|
|||
<enum>QLayout::SetNoConstraint</enum>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>25</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Line" name="line">
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Plain</enum>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
|
|
|
@ -42,6 +42,7 @@ SOURCES += \
|
|||
mainwindow.cpp \
|
||||
otamanager.cpp \
|
||||
qclickablelabel.cpp \
|
||||
qtooltiplabel.cpp \
|
||||
quit.cpp \
|
||||
reader.cpp \
|
||||
savedwords.cpp \
|
||||
|
@ -75,6 +76,7 @@ HEADERS += \
|
|||
mainwindow.h \
|
||||
otamanager.h \
|
||||
qclickablelabel.h \
|
||||
qtooltiplabel.h \
|
||||
quit.h \
|
||||
reader.h \
|
||||
savedwords.h \
|
||||
|
|
|
@ -448,6 +448,9 @@
|
|||
<property name="frameShadow">
|
||||
<enum>QFrame::Plain</enum>
|
||||
</property>
|
||||
<property name="lineWidth">
|
||||
<number>4</number>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#include <QLabel>
|
||||
#include <QWidget>
|
||||
#include <Qt>
|
||||
|
||||
class QClickableLabel : public QLabel {
|
||||
Q_OBJECT
|
||||
|
|
18
qtooltiplabel.cpp
Normal file
18
qtooltiplabel.cpp
Normal file
|
@ -0,0 +1,18 @@
|
|||
#include <QToolTip>
|
||||
|
||||
#include "qtooltiplabel.h"
|
||||
|
||||
QToolTipLabel::QToolTipLabel(QWidget* parent, Qt::WindowFlags f)
|
||||
: QLabel(parent) {
|
||||
this->setStyleSheet("QToolTip { font-size: 40pt }");
|
||||
}
|
||||
|
||||
QToolTipLabel::~QToolTipLabel() {}
|
||||
|
||||
void QToolTipLabel::mousePressEvent(QMouseEvent * event) {
|
||||
QToolTip::showText(mapToGlobal(QPoint(0, 0)), "<font face='u001' size=-2>" + objectName() + "</font>");
|
||||
}
|
||||
|
||||
void QToolTipLabel::mouseReleaseEvent(QMouseEvent * event) {
|
||||
|
||||
}
|
20
qtooltiplabel.h
Normal file
20
qtooltiplabel.h
Normal file
|
@ -0,0 +1,20 @@
|
|||
#ifndef QTOOLTIPLABEL_H
|
||||
#define QTOOLTIPLABEL_H
|
||||
|
||||
#include <QLabel>
|
||||
#include <QWidget>
|
||||
|
||||
class QToolTipLabel : public QLabel {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit QToolTipLabel(QWidget* parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags());
|
||||
~QToolTipLabel();
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QMouseEvent * event);
|
||||
void mouseReleaseEvent(QMouseEvent * event);
|
||||
|
||||
};
|
||||
|
||||
#endif // CLICKABLELABEL_H
|
Loading…
Reference in a new issue