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 0000000..af2078b Binary files /dev/null and b/src/resources/view-highlights.png differ