@@ -240,9 +240,6 @@ NBrowserWindow::NBrowserWindow(QWidget *parent) :
240
240
factory = new PluginFactory (this );
241
241
editor->page ()->setPluginFactory (factory);
242
242
243
- editor->page ()->settings ()->setUserStyleSheetUrl (
244
- QUrl::fromLocalFile (QDir::toNativeSeparators (global.fileManager .getImageDirPath (" " ) + QString (" /checkbox.css" ))));
245
-
246
243
buttonBar->getButtonbarState ();
247
244
248
245
printPage = new QTextEdit ();
@@ -318,6 +315,7 @@ NBrowserWindow::NBrowserWindow(QWidget *parent) :
318
315
}
319
316
320
317
changeDisplayFontName (global.defaultFont );
318
+ changeDisplayFontSize (QString::number (global.defaultFontSize ) + " pt" );
321
319
}
322
320
323
321
@@ -556,6 +554,14 @@ void NBrowserWindow::setContent(qint32 lid) {
556
554
// **** END OF CALL TO PRE-LOAD EXIT
557
555
558
556
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
+
559
565
// is this an ink note?
560
566
if (inkNote)
561
567
editor->page ()->setContentEditable (false );
@@ -1415,16 +1421,10 @@ void NBrowserWindow::todoButtonPressed() {
1415
1421
QRegExp regex (" \\ r?\\ n" );
1416
1422
QStringList items = selectedText.split (regex);
1417
1423
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
-
1425
1424
QString html = " " ;
1426
1425
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>" ;
1428
1428
}
1429
1429
1430
1430
editor->page ()->mainFrame ()->evaluateJavaScript (script_start + html + script_end);
@@ -1464,28 +1464,26 @@ void NBrowserWindow::todoSetAllChecked(bool allSelected) {
1464
1464
// The font size button was pressed
1465
1465
void NBrowserWindow::fontSizeSelected (int index) {
1466
1466
int size = buttonBar->fontSizes ->itemData (index).toInt ();
1467
-
1468
- if (this ->editor ->selectedText () == " " && buttonBar->fontSizes ->currentText () == QString (size)) {
1469
- return ;
1470
- }
1471
-
1472
1467
if (size <= 0 )
1473
1468
return ;
1474
1469
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 = " ‌" ;
1470
+ if (this ->editor ->selectedText () == " " &&
1471
+ buttonBar->fontSizes ->currentText () == QString (size)) {
1472
+ return ;
1482
1473
}
1483
1474
1484
1475
// Start building a new font span.
1485
1476
int idx = buttonBar->fontNames ->currentIndex ();
1486
1477
QString font = buttonBar->fontNames ->itemText (idx);
1487
1478
1488
- if (text == " ‌" ) {
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 = " ‌" ;
1486
+
1489
1487
QString newText = " <span style=\" font-size:" + QString::number (size) +" pt;font-family:" + font + " ;\" >" + text + " </span>" ;
1490
1488
QString script2 = QString (" document.execCommand('insertHtml', false, '" + newText + " ');" );
1491
1489
editor->page ()->mainFrame ()->evaluateJavaScript (script2);
@@ -1503,9 +1501,9 @@ void NBrowserWindow::fontSizeSelected(int index) {
1503
1501
QString script = QString (" document.execCommand('fontSize', false, 5);" );
1504
1502
editor->page ()->mainFrame ()->evaluateJavaScript (script);
1505
1503
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.
1509
1507
modifyFontTagAttr (size);
1510
1508
}
1511
1509
@@ -4109,6 +4107,17 @@ QString base64_encode(QString string) {
4109
4107
// Set the editor background & font color
4110
4108
void NBrowserWindow::setEditorStyle () {
4111
4109
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
+
4112
4121
if (css.isEmpty ()) {
4113
4122
return ;
4114
4123
}
@@ -4258,11 +4267,7 @@ void NBrowserWindow::findShortcut() {
4258
4267
// * in a note.
4259
4268
// *******************************************
4260
4269
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 ();
4266
4271
}
4267
4272
4268
4273
@@ -4271,12 +4276,7 @@ void NBrowserWindow::findNextShortcut() {
4271
4276
// * text in a note.
4272
4277
// *******************************************
4273
4278
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 ();
4280
4280
}
4281
4281
4282
4282
@@ -4337,6 +4337,14 @@ void NBrowserWindow::findNextInNote() {
4337
4337
if (find != " " )
4338
4338
editor->page ()->findText (find,
4339
4339
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
4340
4348
}
4341
4349
4342
4350
@@ -4352,6 +4360,9 @@ void NBrowserWindow::findPrevInNote() {
4352
4360
findReplace->getCaseSensitive () | QWebPage::FindBackward |
4353
4361
QWebPage::FindWrapsAroundDocument);
4354
4362
4363
+ #ifdef _WIN32
4364
+ editor->page ()->findText (find, QWebPage::HighlightAllOccurrences);
4365
+ #endif
4355
4366
}
4356
4367
4357
4368
0 commit comments