Skip to content

Commit 060cedd

Browse files
authored
Merge pull request #193 from boo-yee/develop
Fixed: windows edition find results background color, recently updated menu width, memory leaks, and font size unconsistence
2 parents 53bf1c7 + a7fa723 commit 060cedd

File tree

9 files changed

+82
-46
lines changed

9 files changed

+82
-46
lines changed

changelog.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
NixNote (2.1.7) stable; urgency=low
2+
* Made the font size in the setting dialog consistent with the one in the editor button bar.
3+
* Made the Windows editon's results of find more recognizable.
4+
* Limited the max length of the recently updated menu of the tray.
5+
* Fixed memory leaks caused by Qt Webview.
26
* Fixed: To-do Formatting is not in parity with Official Client - issue #131
37
* Fixed: In-App Note links don't work when there is an apostrophe in the title - issue #168
48
* Fixed: Nixnote2 exits when network gets disconnected - issue #189

debian/changelog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
NixNote (2.1.7) stable; urgency=low
2+
* Made the font size in the setting dialog consistent with the one in the editor button bar.
3+
* Made the Windows editon's results of find more recognizable.
4+
* Limited the max length of the recently updated menu of the tray.
5+
* Fixed memory leaks caused by Qt Webview.
26
* Fixed: To-do Formatting is not in parity with Official Client - issue #131
37
* Fixed: In-App Note links don't work when there is an apostrophe in the title - issue #168
48
* Fixed: Nixnote2 exits when network gets disconnected - issue #189

resources/images/checkbox.css

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
img.todo-icon {
2-
vertical-align: text-bottom !important;
2+
vertical-align: baseline !important;
33
cursor: pointer;
44
padding-right: 5px;
55

66
user-drag: none;
77
-webkit-user-drag: none;
88
}
99

10-
font > img.todo-icon, span > img.todo-icon {
11-
vertical-align: baseline !important;
12-
}
10+

src/dialog/preferences/appearancepreferences.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,9 @@ void AppearancePreferences::saveValues() {
297297
// QWebkit DPI is hard coded to 96. Hence, we calculate the correct
298298
// font size based on desktop logical DPI.
299299
if (global.defaultFontSize > 0) {
300-
settings->setFontSize(QWebSettings::DefaultFontSize, global.defaultFontSize * (QApplication::desktop()->logicalDpiX() / 96.0));
300+
settings->setFontSize(QWebSettings::DefaultFontSize,
301+
(4.0/3.0) * global.defaultFontSize *
302+
(QApplication::desktop()->logicalDpiX() / 96.0));
301303
}
302304
}
303305

src/global.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ void Global::setup(StartupConfig startupConfig, bool guiAvailable) {
173173
// QWebkit DPI is hard coded to 96. Hence, we calculate the correct
174174
// font size based on desktop logical DPI.
175175
settings->setFontSize(QWebSettings::DefaultFontSize,
176-
defaultFontSize * (QApplication::desktop()->logicalDpiX() / 96.0)
176+
(4.0/3.0) * defaultFontSize *
177+
(QApplication::desktop()->logicalDpiX() / 96.0)
177178
);
178179
}
179180
if (defaultFont != "" && defaultFontSize <= 0 && this->guiAvailable) {

src/gui/nbrowserwindow.cpp

Lines changed: 49 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,6 @@ NBrowserWindow::NBrowserWindow(QWidget *parent) :
240240
factory = new PluginFactory(this);
241241
editor->page()->setPluginFactory(factory);
242242

243-
editor->page()->settings()->setUserStyleSheetUrl(
244-
QUrl::fromLocalFile(QDir::toNativeSeparators(global.fileManager.getImageDirPath("") + QString("/checkbox.css"))));
245-
246243
buttonBar->getButtonbarState();
247244

248245
printPage = new QTextEdit();
@@ -318,6 +315,7 @@ NBrowserWindow::NBrowserWindow(QWidget *parent) :
318315
}
319316

320317
changeDisplayFontName(global.defaultFont);
318+
changeDisplayFontSize(QString::number(global.defaultFontSize) + "pt");
321319
}
322320

323321

@@ -556,6 +554,14 @@ void NBrowserWindow::setContent(qint32 lid) {
556554
//**** END OF CALL TO PRE-LOAD EXIT
557555

558556
editor->setContent(content);
557+
558+
// Qt Webview memory leaks solution:
559+
// https://forum.qt.io/topic/10832/memory-size-increases-per-page-load/4
560+
QWebElement body = editor->page()->mainFrame()->findFirstElement("body");
561+
body.setAttribute("onunload", "_function() {}");
562+
QWebSettings::clearMemoryCaches();
563+
editor->history()->clear();
564+
559565
// is this an ink note?
560566
if (inkNote)
561567
editor->page()->setContentEditable(false);
@@ -1415,16 +1421,10 @@ void NBrowserWindow::todoButtonPressed() {
14151421
QRegExp regex("\\r?\\n");
14161422
QStringList items = selectedText.split(regex);
14171423

1418-
// Add a font element to set vertical-align:middle attribute
1419-
// in the css file for the text in the todo item.
1420-
QString font = buttonBar->fontNames->currentText();
1421-
QString fontSize = buttonBar->fontSizes->currentText();
1422-
QString fontElement = QString("<font style=\"font-size:") +
1423-
fontSize + "pt;\"" + QString(" face=\"") + font + QString(";\">");
1424-
14251424
QString html = "";
14261425
for (int i = 0; i < items.size(); i++) {
1427-
html += "<div>" + global.getCheckboxElement(false, true) +items[i] + "</div>";
1426+
html += "<div>" + global.getCheckboxElement(false, true) + items[i] +
1427+
"</div>";
14281428
}
14291429

14301430
editor->page()->mainFrame()->evaluateJavaScript(script_start + html + script_end);
@@ -1464,28 +1464,26 @@ void NBrowserWindow::todoSetAllChecked(bool allSelected) {
14641464
// The font size button was pressed
14651465
void NBrowserWindow::fontSizeSelected(int index) {
14661466
int size = buttonBar->fontSizes->itemData(index).toInt();
1467-
1468-
if (this->editor->selectedText() == "" && buttonBar->fontSizes->currentText() == QString(size)) {
1469-
return;
1470-
}
1471-
14721467
if (size <= 0)
14731468
return;
14741469

1475-
QString text = editor->selectedHtml();
1476-
if (text.trimmed() == "") {
1477-
// Add an invisible charactor in order to set the cursor position
1478-
// to the innerhtml part of the <span> tags added below. If not,
1479-
// the text typed in after font size changed will be added beyond
1480-
// the <span> tags scope.
1481-
text = "&zwnj;";
1470+
if (this->editor->selectedText() == "" &&
1471+
buttonBar->fontSizes->currentText() == QString(size)) {
1472+
return;
14821473
}
14831474

14841475
// Start building a new font span.
14851476
int idx = buttonBar->fontNames->currentIndex();
14861477
QString font = buttonBar->fontNames->itemText(idx);
14871478

1488-
if (text == "&zwnj;") {
1479+
QString text = editor->selectedHtml();
1480+
if (text.trimmed() == "") {
1481+
// Add an invisible charactor in order to focus on the innerhtml
1482+
// part of the <span> tags added below. If not, the text typed
1483+
// in after font size changed will be added beyond the <span>
1484+
// tags scope.
1485+
text = "&zwnj;";
1486+
14891487
QString newText = "<span style=\"font-size:" + QString::number(size) +"pt;font-family:" + font + ";\">" + text + "</span>";
14901488
QString script2 = QString("document.execCommand('insertHtml', false, '" + newText + "');");
14911489
editor->page()->mainFrame()->evaluateJavaScript(script2);
@@ -1503,9 +1501,9 @@ void NBrowserWindow::fontSizeSelected(int index) {
15031501
QString script = QString("document.execCommand('fontSize', false, 5);");
15041502
editor->page()->mainFrame()->evaluateJavaScript(script);
15051503

1506-
// document.execCommand fontSize will generate font tag with size attribute set,
1507-
// which may make the following font setting out of order. So replace it with
1508-
// css style here.
1504+
// document.execCommand fontSize will generate font tag with 'size'
1505+
// attribute set, which now and then makes the following font size
1506+
// setting in trouble. So replace it with 'font-size' here.
15091507
modifyFontTagAttr(size);
15101508
}
15111509

@@ -4109,6 +4107,17 @@ QString base64_encode(QString string) {
41094107
// Set the editor background & font color
41104108
void NBrowserWindow::setEditorStyle() {
41114109
QString css = global.getEditorCss();
4110+
4111+
QString path = global.fileManager.getImageDirPath("") +
4112+
QString("checkbox.css");
4113+
path.replace("file:///", "").replace("file://", "");
4114+
QFile f(QDir::toNativeSeparators(path));
4115+
f.open(QFile::ReadOnly);
4116+
QTextStream in(&f);
4117+
QString checkbox = in.readAll();
4118+
f.close();
4119+
css += checkbox;
4120+
41124121
if (css.isEmpty()) {
41134122
return;
41144123
}
@@ -4258,11 +4267,7 @@ void NBrowserWindow::findShortcut() {
42584267
//* in a note.
42594268
//*******************************************
42604269
void NBrowserWindow::findNextShortcut() {
4261-
findReplace->showFind();
4262-
QString find = findReplace->findLine->text();
4263-
if (find != "")
4264-
editor->page()->findText(find,
4265-
findReplace->getCaseSensitive() | QWebPage::FindWrapsAroundDocument);
4270+
this->findNextInNote();
42664271
}
42674272

42684273

@@ -4271,12 +4276,7 @@ void NBrowserWindow::findNextShortcut() {
42714276
//* text in a note.
42724277
//*******************************************
42734278
void NBrowserWindow::findPrevShortcut() {
4274-
findReplace->showFind();
4275-
QString find = findReplace->findLine->text();
4276-
if (find != "")
4277-
editor->page()->findText(find,
4278-
findReplace->getCaseSensitive() | QWebPage::FindBackward |
4279-
QWebPage::FindWrapsAroundDocument);
4279+
this->findPrevInNote();
42804280
}
42814281

42824282

@@ -4337,6 +4337,14 @@ void NBrowserWindow::findNextInNote() {
43374337
if (find != "")
43384338
editor->page()->findText(find,
43394339
findReplace->getCaseSensitive() | QWebPage::FindWrapsAroundDocument);
4340+
// The background color of the occurances
4341+
// when finding text under Windows is
4342+
// light gray, not recognizable enough,
4343+
// for better experience, add a background
4344+
// color for them here.
4345+
#ifdef _WIN32
4346+
editor->page()->findText(find, QWebPage::HighlightAllOccurrences);
4347+
#endif
43404348
}
43414349

43424350

@@ -4352,6 +4360,9 @@ void NBrowserWindow::findPrevInNote() {
43524360
findReplace->getCaseSensitive() | QWebPage::FindBackward |
43534361
QWebPage::FindWrapsAroundDocument);
43544362

4363+
#ifdef _WIN32
4364+
editor->page()->findText(find, QWebPage::HighlightAllOccurrences);
4365+
#endif
43554366
}
43564367

43574368

src/gui/ntableview.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -613,13 +613,22 @@ void NTableView::mouseReleaseEvent(QMouseEvent *e) {
613613
// Listen for up & down arrows
614614
void NTableView::keyPressEvent(QKeyEvent *event) {
615615
QTableView::keyPressEvent(event);
616-
if (event->key() == Qt::Key_Up || event->key() == Qt::Key_Down ||
617-
event->key() == Qt::Key_PageUp || event->key() == Qt::Key_PageDown)
616+
if (event->key() == Qt::Key_PageUp || event->key() == Qt::Key_PageDown)
618617
this->openSelectedLids(false);
618+
}
619619

620+
void NTableView::keyReleaseEvent(QKeyEvent *event) {
621+
if (event->isAutoRepeat()) {
622+
return;
623+
}
624+
QTableView::keyReleaseEvent(event);
625+
if (event->key() == Qt::Key_Up || event->key() == Qt::Key_Down) {
626+
this->openSelectedLids(false);
627+
}
620628
}
621629

622630

631+
623632
// Open a selected note. This is not done via the context menu.
624633
void NTableView::openSelectedLids(bool newWindow) {
625634

src/gui/ntableview.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class NTableView : public QTableView
6262
void openSelectedLids(bool newWindow);
6363
void refreshSelection();
6464
void keyPressEvent(QKeyEvent *event);
65+
void keyReleaseEvent(QKeyEvent *event);
6566

6667
QMenu *contextMenu;
6768
QMenu *colorMenu;

src/gui/traymenu.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ void TrayMenu::buildActionMenu() {
8181
if (recentlyUpdatedMenu) {
8282
records.clear();;
8383
noteTable.getRecentlyUpdated(records);
84+
const int MAX_LENGTH = 30;
85+
for (int i = 0; i < records.length(); i++) {
86+
if (records[i].second.length() > MAX_LENGTH) {
87+
records[i].second = records[i].second.left(MAX_LENGTH) + "...";
88+
}
89+
}
8490
buildMenu("recentlyUpdatedMenu", recentlyUpdatedMenu, records);
8591
}
8692

0 commit comments

Comments
 (0)