From 058e975919f688857be979e0bf8ef0658bb23787 Mon Sep 17 00:00:00 2001 From: Nicolas Mailloux Date: Tue, 9 Aug 2022 15:41:50 -0400 Subject: [PATCH] Highlighting: Fixes --- src/eink.qrc | 5 +++-- src/functions.h | 24 +++++++++--------------- src/reader/reader.cpp | 13 +++++++++++++ src/resources/view-highlights.png | Bin 0 -> 5659 bytes 4 files changed, 25 insertions(+), 17 deletions(-) create mode 100644 src/resources/view-highlights.png diff --git a/src/eink.qrc b/src/eink.qrc index 3f4621e..ab45a56 100644 --- a/src/eink.qrc +++ b/src/eink.qrc @@ -81,7 +81,8 @@ resources/arrow-right.png resources/file-text.png resources/pin.png - resources/highlight.png - resources/unhighlight.png + resources/highlight.png + resources/unhighlight.png + resources/view-highlights.png diff --git a/src/functions.h b/src/functions.h index 37d1db0..9df8dab 100644 --- a/src/functions.h +++ b/src/functions.h @@ -1041,7 +1041,7 @@ namespace { QJsonObject mainJsonObject; QJsonObject firstJsonObject; firstJsonObject.insert("BookPath", QJsonValue(bookPath)); - firstJsonObject.insert("Text1", QJsonValue(text)); + firstJsonObject.insert("T-" + QUuid::createUuid().toString(QUuid::WithoutBraces), QJsonValue(text)); mainJsonObject["Book1"] = firstJsonObject; writeHighlightsDatabase(mainJsonObject); } @@ -1051,30 +1051,23 @@ namespace { int length = jsonObject.length(); for(int i = 1; i <= length; i++) { if(jsonObject["Book" + QString::number(i)].toObject().value("BookPath").toString() == bookPath) { - log("highlightBookText: Found existing book with path '" + bookPath + "'", "functions"); - int keyCount = 0; - // Counting number of highlights for book - foreach(const QString& key, jsonObject["Book" + QString::number(i)].toObject().keys()) { - keyCount++; - } - // First key is 'BookPath' - int highlightsCount = keyCount - 1; - int currentHighlightPosition = highlightsCount + 1; + log("highlightBookText: Found existing book in database with path '" + bookPath + "'", "functions"); // Insert highlight QJsonObject highlightJsonObject = jsonObject["Book" + QString::number(i)].toObject(); // Finding available slot for highlight in case the one we are looking for is already occupied - if(highlightJsonObject.contains("Text" + QString::number(currentHighlightPosition))) { + QString uuid = "T-"+ QUuid::createUuid().toString(QUuid::WithoutBraces); + if(highlightJsonObject.contains(uuid)) { while(true) { - if(highlightJsonObject.contains("Text" + QString::number(currentHighlightPosition))) { - currentHighlightPosition++; + if(highlightJsonObject.contains(uuid)) { + uuid = "T-" + QUuid::createUuid().toString(QUuid::WithoutBraces); } else { break; } } } - highlightJsonObject.insert("Text" + QString::number(currentHighlightPosition), text); + highlightJsonObject.insert(uuid, text); jsonObject["Book" + QString::number(i)] = highlightJsonObject; writeHighlightsDatabase(jsonObject); @@ -1083,9 +1076,10 @@ namespace { } if(highlightWrote == false) { + // This block of code is called when the book is referenced in the database, but no highlights are currently indexed QJsonObject bookJsonObject; bookJsonObject.insert("BookPath", QJsonValue(bookPath)); - bookJsonObject.insert("Text1", QJsonValue(text)); + bookJsonObject.insert("T-" + QUuid::createUuid().toString(QUuid::WithoutBraces), QJsonValue(text)); jsonObject["Book" + QString::number(length + 1)] = bookJsonObject; writeHighlightsDatabase(jsonObject); diff --git a/src/reader/reader.cpp b/src/reader/reader.cpp index db5a333..aba9ff7 100644 --- a/src/reader/reader.cpp +++ b/src/reader/reader.cpp @@ -72,6 +72,7 @@ reader::reader(QWidget *parent) : ui->increaseScaleBtn->setProperty("type", "borderless"); ui->decreaseScaleBtn->setProperty("type", "borderless"); ui->quitBtn->setProperty("type", "borderless"); + ui->viewHighlightsBtn->setProperty("type", "borderless"); // Icons ui->alignLeftBtn->setText(""); @@ -112,6 +113,8 @@ reader::reader(QWidget *parent) : ui->optionsBtn->setIcon(QIcon(":/resources/settings.png")); ui->nextBtn->setText(""); ui->nextBtn->setIcon(QIcon(":/resources/arrow-right.png")); + ui->viewHighlightsBtn->setText(""); + ui->viewHighlightsBtn->setIcon(QIcon(":/resources/view-highlights.png")); // On the Mini with QT_FONT_DPI set to 187 (default for this device), quitBtn makes the UI go beyond the limits of the screen when the menu bar is shown if(global::deviceID == "n705\n") { @@ -316,6 +319,7 @@ reader::reader(QWidget *parent) : ui->fontChooser->setStyleSheet("font-size: 9pt"); ui->gotoBtn->setStyleSheet("font-size: 9pt; padding: 9px; font-weight: bold; background: lightGrey"); ui->pageNumberLabel->setFont(QFont("Source Serif Pro")); + ui->viewHighlightsBtn->setStyleSheet("padding: 9px"); // Hiding the menubar + definition widget + brightness widget + buttons bar widget ui->menuWidget->setVisible(false); @@ -536,11 +540,19 @@ reader::reader(QWidget *parent) : else if(is_pdf == true) { ui->text->hide(); ui->text->deleteLater(); + ui->line_20->hide(); + ui->line_20->deleteLater(); + ui->viewHighlightsBtn->hide(); + ui->viewHighlightsBtn->deleteLater(); setupPng(); } else if(is_image == true) { ui->text->hide(); ui->text->deleteLater(); + ui->line_20->hide(); + ui->line_20->deleteLater(); + ui->viewHighlightsBtn->hide(); + ui->viewHighlightsBtn->deleteLater(); setupPng(); } else { @@ -1437,6 +1449,7 @@ 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) { diff --git a/src/resources/view-highlights.png b/src/resources/view-highlights.png new file mode 100644 index 0000000000000000000000000000000000000000..af2078b5eb8dd6f7e1953299d93fd2b22083bda2 GIT binary patch literal 5659 zcmc&&c{r5&+n-4_QI?V@dxoimO4hLz(HMr4EM;wwQ_7ZR>|`k+>Y0%29MlmSvW~SZ zO}2w#FoT$6GTFlz@q0$j`(E#I-s`>If8OVMo@?&sUOxAIf4<-Qy5{>lG{+e6@*LrT zKp?!Riw2h<5NIvu*|QteRc1z)0W=eJuGPV5Pn zl#0h-ViYfpZvy9IMfl^{^D`q8GvZQbKbVx&7(z`;p1(A(>u|AdX_OD&BNcbpq`l+J zB>Xsc_xxRcNyk~NRy&)TnQPs7W#8Px=CY1ch0UVPgjCCjMIG-*A=kv!G{5FQ_8!pn zvG-;@y3=&+o||EZ@68PL^Cu5!+Ay4~&Z>-akH7en@l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