2022-06-28 23:15:13 -07:00
|
|
|
#include <QJsonDocument>
|
|
|
|
#include <QJsonObject>
|
|
|
|
|
2022-06-23 12:34:40 -07:00
|
|
|
#include "qclickablelabel.h"
|
|
|
|
|
|
|
|
QClickableLabel::QClickableLabel(QWidget* parent, Qt::WindowFlags f)
|
2022-07-17 23:40:32 -07:00
|
|
|
: QLabel(parent) {}
|
2022-06-23 12:34:40 -07:00
|
|
|
|
|
|
|
QClickableLabel::~QClickableLabel() {}
|
|
|
|
|
2022-06-23 16:15:33 -07:00
|
|
|
void QClickableLabel::mousePressEvent(QMouseEvent * event) {
|
2022-07-06 11:24:23 -07:00
|
|
|
timeAtClick = QDateTime::currentMSecsSinceEpoch();
|
2022-06-23 12:34:40 -07:00
|
|
|
emit clicked();
|
2022-06-28 23:15:13 -07:00
|
|
|
if(objectName() == "pageNumberLabel") {
|
2022-07-01 15:56:34 -07:00
|
|
|
QClickableLabel::setStyleSheet("border-radius: 10px; padding-left: 10px; padding-right: 10px");
|
2022-06-28 23:15:13 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
QClickableLabel::setStyleSheet("color: white; background-color: black; border-radius: 10px; padding: 10px");
|
|
|
|
}
|
2022-06-23 16:15:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void QClickableLabel::mouseReleaseEvent(QMouseEvent * event) {
|
2022-07-06 11:24:23 -07:00
|
|
|
if(QDateTime::currentMSecsSinceEpoch() >= timeAtClick + 500) {
|
2022-07-17 23:40:32 -07:00
|
|
|
if(objectName().toInt()) {
|
|
|
|
emit longPressInt(objectName().toInt());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
emit longPressString(QJsonDocument::fromJson(qUncompress(QByteArray::fromBase64(objectName().toUtf8()))).object()["BookPath"].toString());
|
|
|
|
}
|
2022-07-06 11:24:23 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
emit unclicked();
|
|
|
|
emit bookID(objectName().toInt());
|
2022-07-17 23:40:32 -07:00
|
|
|
emit bookPath(QJsonDocument::fromJson(qUncompress(QByteArray::fromBase64(objectName().toUtf8()))).object()["BookPath"].toString());
|
2022-07-06 11:24:23 -07:00
|
|
|
}
|
2022-06-28 23:15:13 -07:00
|
|
|
if(objectName() == "pageNumberLabel") {
|
2022-07-01 15:56:34 -07:00
|
|
|
QClickableLabel::setStyleSheet("border-radius: 10px; padding-left: 10px; padding-right: 10px");
|
2022-06-28 23:15:13 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
QClickableLabel::setStyleSheet("color: black; background-color: white; border-radius: 10px; padding: 10px");
|
|
|
|
}
|
2022-06-23 12:34:40 -07:00
|
|
|
}
|