mirror of
https://github.com/Quill-OS/quill.git
synced 2024-12-26 15:47:22 -08:00
Implement highlights list dialog
This commit is contained in:
parent
cc26bcd538
commit
0874729550
9 changed files with 308 additions and 9 deletions
|
@ -30,6 +30,7 @@ SOURCES += \
|
|||
src/widgets/dialogs/library/bookoptionsdialog.cpp \
|
||||
src/widgets/dialogs/brightnessdialog.cpp \
|
||||
src/apps/calendarapp.cpp \
|
||||
src/widgets/dialogs/reader/highlightslistdialog.cpp \
|
||||
src/widgets/dialogs/reader/textdialog.cpp \
|
||||
src/widgets/reader/dictionarywidget.cpp \
|
||||
src/encfs/encryptionmanager.cpp \
|
||||
|
@ -69,6 +70,7 @@ HEADERS += \
|
|||
src/widgets/dialogs/library/bookoptionsdialog.h \
|
||||
src/widgets/dialogs/brightnessdialog.h \
|
||||
src/apps/calendarapp.h \
|
||||
src/widgets/dialogs/reader/highlightslistdialog.h \
|
||||
src/widgets/dialogs/reader/textdialog.h \
|
||||
src/widgets/reader/dictionarywidget.h \
|
||||
src/encfs/encryptionmanager.h \
|
||||
|
@ -108,6 +110,7 @@ FORMS += \
|
|||
src/widgets/dialogs/library/bookoptionsdialog.ui \
|
||||
src/widgets/dialogs/brightnessdialog.ui \
|
||||
src/apps/calendarapp.ui \
|
||||
src/widgets/dialogs/reader/highlightslistdialog.ui \
|
||||
src/widgets/dialogs/reader/textdialog.ui \
|
||||
src/widgets/reader/dictionarywidget.ui \
|
||||
src/encfs/encryptionmanager.ui \
|
||||
|
|
|
@ -166,6 +166,9 @@ namespace global {
|
|||
static inline int pinnedBooksNumberPerRow = 4;
|
||||
static inline int pinnedBooksRowNumber = global::homePageWidget::pinnedBooksNumber / global::homePageWidget::pinnedBooksNumberPerRow;
|
||||
}
|
||||
namespace highlightsListDialog {
|
||||
inline QString bookPath;
|
||||
}
|
||||
inline QString systemInfoText;
|
||||
inline bool forbidOpenSearchDialog;
|
||||
inline bool isN705 = false;
|
||||
|
|
|
@ -1449,7 +1449,6 @@ void reader::alignAndHighlightText(int alignment) {
|
|||
// Highlight
|
||||
QString htmlText = ui->text->toHtml();
|
||||
QJsonObject jsonObject = getHighlightsForBook(book_file);
|
||||
qDebug() << jsonObject;
|
||||
int keyCount = 1;
|
||||
foreach(const QString& key, jsonObject.keys()) {
|
||||
if(keyCount <= 1) {
|
||||
|
@ -2420,3 +2419,24 @@ void reader::unhighlightText() {
|
|||
highlightBookText(selected_text, book_file, true);
|
||||
alignAndHighlightText(textAlignment);
|
||||
}
|
||||
|
||||
void reader::on_viewHighlightsBtn_clicked()
|
||||
{
|
||||
log("Launching highlights list dialog for book '" + book_file + "'", className);
|
||||
QJsonObject jsonObject = getHighlightsForBook(book_file);
|
||||
if(jsonObject.isEmpty() or jsonObject.length() <= 1) {
|
||||
global::toast::delay = 3000;
|
||||
showToast("No highlights for this book");
|
||||
}
|
||||
else {
|
||||
global::highlightsListDialog::bookPath = book_file;
|
||||
highlightsListDialog * highlightsListDialogWindow = new highlightsListDialog(this);
|
||||
QObject::connect(highlightsListDialogWindow, &highlightsListDialog::destroyed, this, &reader::alignAndHighlightTextSlot);
|
||||
QObject::connect(highlightsListDialogWindow, &highlightsListDialog::showToast, this, &reader::showToast);
|
||||
highlightsListDialogWindow->setAttribute(Qt::WA_DeleteOnClose);
|
||||
}
|
||||
}
|
||||
|
||||
void reader::alignAndHighlightTextSlot() {
|
||||
alignAndHighlightText(textAlignment);
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include "toast.h"
|
||||
#include "quit.h"
|
||||
#include "textdialog.h"
|
||||
#include "highlightslistdialog.h"
|
||||
|
||||
#include <QWidget>
|
||||
#include <QGraphicsScene>
|
||||
|
@ -166,6 +167,8 @@ private slots:
|
|||
void unsetTextDialogLock();
|
||||
void highlightText();
|
||||
void unhighlightText();
|
||||
void on_viewHighlightsBtn_clicked();
|
||||
void alignAndHighlightTextSlot();
|
||||
|
||||
signals:
|
||||
void openBookFile(QString book, bool relativePath);
|
||||
|
@ -177,6 +180,7 @@ private:
|
|||
toast * toastWindow;
|
||||
quit * quitWindow;
|
||||
textDialog * textDialogWindow;
|
||||
highlightsListDialog * highlightsListDialogWindow;
|
||||
QGraphicsScene * graphicsScene;
|
||||
};
|
||||
|
||||
|
|
|
@ -102,10 +102,20 @@
|
|||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="pageNumberLabel">
|
||||
<item row="0" column="1">
|
||||
<widget class="QProgressBar" name="pageProgressBar">
|
||||
<property name="value">
|
||||
<number>0</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="4">
|
||||
<widget class="QPushButton" name="viewHighlightsBtn">
|
||||
<property name="styleSheet">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>x of x</string>
|
||||
<string>View highlights</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -116,10 +126,20 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QProgressBar" name="pageProgressBar">
|
||||
<property name="value">
|
||||
<number>0</number>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="pageNumberLabel">
|
||||
<property name="text">
|
||||
<string>x of x</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="3">
|
||||
<widget class="Line" name="line_20">
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Plain</enum>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
|
|
@ -780,7 +780,7 @@ void generalDialog::waitForGutenbergSearchDone() {
|
|||
|
||||
void generalDialog::increaseSize()
|
||||
{
|
||||
log("Resizing generalDialog", className);
|
||||
log("Resizing", className);
|
||||
|
||||
ui->topStackedWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
|
||||
ui->mainStackedWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding);
|
||||
|
|
113
src/widgets/dialogs/reader/highlightslistdialog.cpp
Normal file
113
src/widgets/dialogs/reader/highlightslistdialog.cpp
Normal file
|
@ -0,0 +1,113 @@
|
|||
#include "highlightslistdialog.h"
|
||||
#include "ui_highlightslistdialog.h"
|
||||
|
||||
#include <QScreen>
|
||||
|
||||
highlightsListDialog::highlightsListDialog(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::highlightsListDialog)
|
||||
{
|
||||
// Preventing outside interaction
|
||||
this->setModal(true);
|
||||
|
||||
ui->setupUi(this);
|
||||
ui->listWidget->setFont(QFont("u001"));
|
||||
|
||||
ui->okBtn->setProperty("type", "borderless");
|
||||
ui->cancelBtn->setProperty("type", "borderless");
|
||||
ui->selectAllBtn->setProperty("type", "borderless");
|
||||
ui->okBtn->setStyleSheet("font-size: 9pt; padding: 10px; font-weight: bold; background: lightGrey");
|
||||
ui->cancelBtn->setStyleSheet("font-size: 9pt; padding: 10px; font-weight: bold; background: lightGrey");
|
||||
ui->selectAllBtn->setStyleSheet("font-size: 9pt; padding: 10px");
|
||||
ui->listWidget->setStyleSheet("font-size: 10pt");
|
||||
ui->listWidget->setWordWrap(true);
|
||||
|
||||
QJsonObject jsonObject = getHighlightsForBook(global::highlightsListDialog::bookPath);
|
||||
int keyCount = 1;
|
||||
|
||||
foreach(const QString& key, jsonObject.keys()) {
|
||||
if(keyCount <= 1) {
|
||||
keyCount++;
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
QListWidgetItem * item = new QListWidgetItem();
|
||||
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable);
|
||||
item->setCheckState(Qt::Unchecked);
|
||||
item->setText(jsonObject.value(key).toString());
|
||||
ui->listWidget->addItem(item);
|
||||
}
|
||||
}
|
||||
|
||||
QTimer::singleShot(150, this, SLOT(increaseSize()));
|
||||
}
|
||||
|
||||
highlightsListDialog::~highlightsListDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void highlightsListDialog::increaseSize()
|
||||
{
|
||||
log("Resizing", className);
|
||||
|
||||
ui->listWidget->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
|
||||
|
||||
QRect screenGeometry = QGuiApplication::screens()[0]->geometry();
|
||||
{
|
||||
int wx = screenGeometry.width();
|
||||
int x = wx - 25;
|
||||
int y = this->height() * determineYIncrease();
|
||||
this->setFixedWidth(x);
|
||||
this->setFixedHeight(y);
|
||||
}
|
||||
{
|
||||
this->adjustSize();
|
||||
int x = (screenGeometry.width() - this->width()) / 2;
|
||||
int y = (screenGeometry.height() - this->height()) / 2;
|
||||
this->move(x, y);
|
||||
}
|
||||
|
||||
this->show();
|
||||
}
|
||||
|
||||
void highlightsListDialog::on_cancelBtn_clicked()
|
||||
{
|
||||
highlightsListDialog::close();
|
||||
}
|
||||
|
||||
void highlightsListDialog::on_okBtn_clicked()
|
||||
{
|
||||
int itemsCount = 0;
|
||||
int range = ui->listWidget->count();
|
||||
for(int i = 0; i < range; i++) {
|
||||
if(ui->listWidget->item(i)->checkState() == Qt::Checked) {
|
||||
QString highlight = ui->listWidget->item(i)->text();
|
||||
// The last argument indicates that we want to remove the specified highlight, not add it
|
||||
highlightBookText(highlight, global::highlightsListDialog::bookPath, true);
|
||||
itemsCount++;
|
||||
}
|
||||
}
|
||||
|
||||
global::toast::delay = 3000;
|
||||
if(itemsCount >= 1) {
|
||||
if(itemsCount >= 2) {
|
||||
emit showToast("Items deleted successfully");
|
||||
}
|
||||
else {
|
||||
emit showToast("Item deleted successfully");
|
||||
}
|
||||
highlightsListDialog::close();
|
||||
}
|
||||
else {
|
||||
emit showToast("Please select items to delete");
|
||||
}
|
||||
}
|
||||
|
||||
void highlightsListDialog::on_selectAllBtn_clicked()
|
||||
{
|
||||
int range = ui->listWidget->count();
|
||||
for(int i = 0; i < range; i++) {
|
||||
ui->listWidget->item(i)->setCheckState(Qt::Checked);
|
||||
}
|
||||
}
|
34
src/widgets/dialogs/reader/highlightslistdialog.h
Normal file
34
src/widgets/dialogs/reader/highlightslistdialog.h
Normal file
|
@ -0,0 +1,34 @@
|
|||
#ifndef HIGHLIGHTSLISTDIALOG_H
|
||||
#define HIGHLIGHTSLISTDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
#include "functions.h"
|
||||
|
||||
namespace Ui {
|
||||
class highlightsListDialog;
|
||||
}
|
||||
|
||||
class highlightsListDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QString className = this->metaObject()->className();
|
||||
explicit highlightsListDialog(QWidget *parent = nullptr);
|
||||
~highlightsListDialog();
|
||||
|
||||
private slots:
|
||||
void increaseSize();
|
||||
void on_cancelBtn_clicked();
|
||||
void on_okBtn_clicked();
|
||||
void on_selectAllBtn_clicked();
|
||||
|
||||
signals:
|
||||
void showToast(QString messageToDisplay);
|
||||
|
||||
private:
|
||||
Ui::highlightsListDialog *ui;
|
||||
};
|
||||
|
||||
#endif // HIGHLIGHTSLISTDIALOG_H
|
102
src/widgets/dialogs/reader/highlightslistdialog.ui
Normal file
102
src/widgets/dialogs/reader/highlightslistdialog.ui
Normal file
|
@ -0,0 +1,102 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>highlightsListDialog</class>
|
||||
<widget class="QDialog" name="highlightsListDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>50</weight>
|
||||
<bold>false</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string><font face="Inter"><b>Highlights list</b></font><font face="u001"><br>Select items to delete</br></font></string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="1" column="0">
|
||||
<widget class="QListWidget" name="listWidget"/>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QPushButton" name="selectAllBtn">
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>U001</family>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Select all</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</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>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="1" column="1">
|
||||
<widget class="QPushButton" name="okBtn">
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>OK</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QPushButton" name="cancelBtn">
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Close</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
Loading…
Reference in a new issue