Highlighting: Fixes

This commit is contained in:
Nicolas Mailloux 2022-08-09 15:41:50 -04:00
parent 636a9eb97a
commit 058e975919
4 changed files with 25 additions and 17 deletions

View file

@ -81,7 +81,8 @@
<file>resources/arrow-right.png</file> <file>resources/arrow-right.png</file>
<file>resources/file-text.png</file> <file>resources/file-text.png</file>
<file>resources/pin.png</file> <file>resources/pin.png</file>
<file>resources/highlight.png</file> <file>resources/highlight.png</file>
<file>resources/unhighlight.png</file> <file>resources/unhighlight.png</file>
<file>resources/view-highlights.png</file>
</qresource> </qresource>
</RCC> </RCC>

View file

@ -1041,7 +1041,7 @@ namespace {
QJsonObject mainJsonObject; QJsonObject mainJsonObject;
QJsonObject firstJsonObject; QJsonObject firstJsonObject;
firstJsonObject.insert("BookPath", QJsonValue(bookPath)); firstJsonObject.insert("BookPath", QJsonValue(bookPath));
firstJsonObject.insert("Text1", QJsonValue(text)); firstJsonObject.insert("T-" + QUuid::createUuid().toString(QUuid::WithoutBraces), QJsonValue(text));
mainJsonObject["Book1"] = firstJsonObject; mainJsonObject["Book1"] = firstJsonObject;
writeHighlightsDatabase(mainJsonObject); writeHighlightsDatabase(mainJsonObject);
} }
@ -1051,30 +1051,23 @@ namespace {
int length = jsonObject.length(); int length = jsonObject.length();
for(int i = 1; i <= length; i++) { for(int i = 1; i <= length; i++) {
if(jsonObject["Book" + QString::number(i)].toObject().value("BookPath").toString() == bookPath) { if(jsonObject["Book" + QString::number(i)].toObject().value("BookPath").toString() == bookPath) {
log("highlightBookText: Found existing book with path '" + bookPath + "'", "functions"); log("highlightBookText: Found existing book in database 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;
// Insert highlight // Insert highlight
QJsonObject highlightJsonObject = jsonObject["Book" + QString::number(i)].toObject(); QJsonObject highlightJsonObject = jsonObject["Book" + QString::number(i)].toObject();
// Finding available slot for highlight in case the one we are looking for is already occupied // 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) { while(true) {
if(highlightJsonObject.contains("Text" + QString::number(currentHighlightPosition))) { if(highlightJsonObject.contains(uuid)) {
currentHighlightPosition++; uuid = "T-" + QUuid::createUuid().toString(QUuid::WithoutBraces);
} }
else { else {
break; break;
} }
} }
} }
highlightJsonObject.insert("Text" + QString::number(currentHighlightPosition), text); highlightJsonObject.insert(uuid, text);
jsonObject["Book" + QString::number(i)] = highlightJsonObject; jsonObject["Book" + QString::number(i)] = highlightJsonObject;
writeHighlightsDatabase(jsonObject); writeHighlightsDatabase(jsonObject);
@ -1083,9 +1076,10 @@ namespace {
} }
if(highlightWrote == false) { 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; QJsonObject bookJsonObject;
bookJsonObject.insert("BookPath", QJsonValue(bookPath)); 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; jsonObject["Book" + QString::number(length + 1)] = bookJsonObject;
writeHighlightsDatabase(jsonObject); writeHighlightsDatabase(jsonObject);

View file

@ -72,6 +72,7 @@ reader::reader(QWidget *parent) :
ui->increaseScaleBtn->setProperty("type", "borderless"); ui->increaseScaleBtn->setProperty("type", "borderless");
ui->decreaseScaleBtn->setProperty("type", "borderless"); ui->decreaseScaleBtn->setProperty("type", "borderless");
ui->quitBtn->setProperty("type", "borderless"); ui->quitBtn->setProperty("type", "borderless");
ui->viewHighlightsBtn->setProperty("type", "borderless");
// Icons // Icons
ui->alignLeftBtn->setText(""); ui->alignLeftBtn->setText("");
@ -112,6 +113,8 @@ reader::reader(QWidget *parent) :
ui->optionsBtn->setIcon(QIcon(":/resources/settings.png")); ui->optionsBtn->setIcon(QIcon(":/resources/settings.png"));
ui->nextBtn->setText(""); ui->nextBtn->setText("");
ui->nextBtn->setIcon(QIcon(":/resources/arrow-right.png")); 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 // 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") { if(global::deviceID == "n705\n") {
@ -316,6 +319,7 @@ reader::reader(QWidget *parent) :
ui->fontChooser->setStyleSheet("font-size: 9pt"); ui->fontChooser->setStyleSheet("font-size: 9pt");
ui->gotoBtn->setStyleSheet("font-size: 9pt; padding: 9px; font-weight: bold; background: lightGrey"); ui->gotoBtn->setStyleSheet("font-size: 9pt; padding: 9px; font-weight: bold; background: lightGrey");
ui->pageNumberLabel->setFont(QFont("Source Serif Pro")); ui->pageNumberLabel->setFont(QFont("Source Serif Pro"));
ui->viewHighlightsBtn->setStyleSheet("padding: 9px");
// Hiding the menubar + definition widget + brightness widget + buttons bar widget // Hiding the menubar + definition widget + brightness widget + buttons bar widget
ui->menuWidget->setVisible(false); ui->menuWidget->setVisible(false);
@ -536,11 +540,19 @@ reader::reader(QWidget *parent) :
else if(is_pdf == true) { else if(is_pdf == true) {
ui->text->hide(); ui->text->hide();
ui->text->deleteLater(); ui->text->deleteLater();
ui->line_20->hide();
ui->line_20->deleteLater();
ui->viewHighlightsBtn->hide();
ui->viewHighlightsBtn->deleteLater();
setupPng(); setupPng();
} }
else if(is_image == true) { else if(is_image == true) {
ui->text->hide(); ui->text->hide();
ui->text->deleteLater(); ui->text->deleteLater();
ui->line_20->hide();
ui->line_20->deleteLater();
ui->viewHighlightsBtn->hide();
ui->viewHighlightsBtn->deleteLater();
setupPng(); setupPng();
} }
else { else {
@ -1437,6 +1449,7 @@ void reader::alignAndHighlightText(int alignment) {
// Highlight // Highlight
QString htmlText = ui->text->toHtml(); QString htmlText = ui->text->toHtml();
QJsonObject jsonObject = getHighlightsForBook(book_file); QJsonObject jsonObject = getHighlightsForBook(book_file);
qDebug() << jsonObject;
int keyCount = 1; int keyCount = 1;
foreach(const QString& key, jsonObject.keys()) { foreach(const QString& key, jsonObject.keys()) {
if(keyCount <= 1) { if(keyCount <= 1) {

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB