Merge lp:~srazi/qpdfview/some-patches into lp:qpdfview

Proposed by Razi Alavizadeh on 2018-05-11
Status: Needs review
Proposed branch: lp:~srazi/qpdfview/some-patches
Merge into: lp:qpdfview
Diff against target: 574 lines (+285/-69)
14 files modified
application.pro (+2/-0)
sources/bookmarkitemdelegate.cpp (+75/-0)
sources/bookmarkitemdelegate.h (+45/-0)
sources/bookmarkmodel.h (+19/-0)
sources/documentview.cpp (+3/-0)
sources/documentview.h (+2/-0)
sources/mainwindow.cpp (+8/-1)
sources/mainwindow.h (+1/-1)
sources/miscellaneous.cpp (+114/-0)
sources/miscellaneous.h (+3/-0)
sources/pageitem.cpp (+6/-0)
sources/pageitem.h (+2/-0)
sources/searchitemdelegate.cpp (+5/-65)
sources/searchitemdelegate.h (+0/-2)
To merge this branch: bzr merge lp:~srazi/qpdfview/some-patches
Reviewer Review Type Date Requested Status
Adam Reichold 2018-05-11 Pending
Review via email: mp+345392@code.launchpad.net

This proposal supersedes a proposal from 2018-05-06.

Description of the change

Refactor of bookmark-work branch and add some other commits.

To post a comment you must log in.
Adam Reichold (adamreichold) wrote : Posted in a previous version of this proposal

Hello Razi,

thank you for your contribution! I am happy to be hearing from you again. Also, I will try to review your changes as soon as possible but please be patient since I am currently not sure when I will find the time.

Best regards,
Adam

Adam Reichold (adamreichold) wrote : Posted in a previous version of this proposal

Hello again,

just two general remarks:

* I think BookmarkDialog::appendComment should become Bookmark::append since it is not involved with the presentation layer at all. (And it is IMHO that only the comment can sensibly be appended to.)

* The text rendering code of BookmarkItemDelegate seems to have quite a bit of duplication with e.g. SearchItemDelegate. Could this be factored out into some common text rendering code? Can we not somehow reuse the existing text rendering used to e.g. draw QLabel?

Best regards,
Adam

Razi Alavizadeh (srazi) wrote : Posted in a previous version of this proposal

Hello,

> * I think BookmarkDialog::appendComment should become Bookmark::append since it is not involved with the presentation layer at all.

I agree.

> * The text rendering code of BookmarkItemDelegate seems to have quite a bit of duplication with e.g. SearchItemDelegate. Could this be factored out into some common text rendering code? Can we not somehow reuse the existing text rendering used to e.g. draw QLabel?

Yes, indeed it is a modified copy of SearchItemDelegate. Good idea, I will try to refactor it.

Best Regards,
Razi.

Razi Alavizadeh (srazi) wrote :

Hello again,

This branch also contains some bug fixes:
1- Fix highlighting matchedText when a part of it, is removed by QFontMetrics::elidedText()
2- Fix bookmark tooltip when comment is too long
3- Fix showing search results of a closed tab

Best Regards,
Razi.

Adam Reichold (adamreichold) wrote :

Hello Razi,

sorry that I do not have to time to review all of this. I did however merge everything that is purely a bug fix into trunk revision 2075. Could you merge trunk back into this branch to make the diff smaller?

From a first look at the code, I noticed that drawAlternativeText should be split into two functions, one with matchedText as they do not share any significant control flow (and common setup could be factored out into a helper function).

Also signal names are usually formulated in the passive voice, i.e. requestAppendToBookmarkComment should rather be appendToBookmarkRequested.

Best regards,
Adam

lp:~srazi/qpdfview/some-patches updated on 2018-05-13
2078. By Razi Alavizadeh on 2018-05-13

Merge upstream

2079. By Razi Alavizadeh on 2018-05-13

Improve code style of drawAlternativeText()

2080. By Razi Alavizadeh on 2018-05-13

Rename requestAppendToBookmarkComment() to appendToBookmarkRequested()

2081. By Razi Alavizadeh on 2018-05-13

Fix code style of appendComment() and &

Adam Reichold (adamreichold) wrote :

I am really sorry that this is taking so long, but I think I will concentrate on making a 0.4.18 for now and revisit this after that, so maybe one or two weeks. Again, I am really sorry to keep you waiting and I am very grateful for your contributions, including this one!

Razi Alavizadeh (srazi) wrote :

NP :)
Thank you.

Unmerged revisions

2081. By Razi Alavizadeh on 2018-05-13

Fix code style of appendComment() and &

2080. By Razi Alavizadeh on 2018-05-13

Rename requestAppendToBookmarkComment() to appendToBookmarkRequested()

2079. By Razi Alavizadeh on 2018-05-13

Improve code style of drawAlternativeText()

2078. By Razi Alavizadeh on 2018-05-13

Merge upstream

2077. By Razi Alavizadeh on 2018-05-10

Clear search results of a tab when closing it

2076. By Razi Alavizadeh on 2018-05-10

Fix bookmark tooltip when comment is too long

- At least on Windows long plaintext tooltips (without new line)
    are shown as a single long line. Changing tooltip format to HTML
    fixes this issue.

2075. By Razi Alavizadeh on 2018-05-10

Add ability to append selected text to bookmark comment

2074. By Razi Alavizadeh on 2018-05-10

Fix unreferenced formal parameter warning

2073. By Razi Alavizadeh on 2018-05-10

Show comment of bookmark items in Bookmarks Dock

2072. By Razi Alavizadeh on 2018-05-10

Fix highlighting matchedText when a part of it, is removed by QFontMetrics::elidedText()

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'application.pro'
2--- application.pro 2018-05-13 17:09:14 +0000
3+++ application.pro 2018-05-13 21:55:34 +0000
4@@ -34,6 +34,7 @@
5 sources/bookmarkmodel.h \
6 sources/bookmarkmenu.h \
7 sources/bookmarkdialog.h \
8+ sources/bookmarkitemdelegate.h \
9 sources/database.h \
10 sources/mainwindow.h
11
12@@ -61,6 +62,7 @@
13 sources/bookmarkmenu.cpp \
14 sources/bookmarkdialog.cpp \
15 sources/bookmarkmodel.cpp \
16+ sources/bookmarkitemdelegate.cpp \
17 sources/database.cpp \
18 sources/mainwindow.cpp \
19 sources/main.cpp
20
21=== added file 'sources/bookmarkitemdelegate.cpp'
22--- sources/bookmarkitemdelegate.cpp 1970-01-01 00:00:00 +0000
23+++ sources/bookmarkitemdelegate.cpp 2018-05-13 21:55:34 +0000
24@@ -0,0 +1,75 @@
25+/*
26+
27+Copyright 2018 Razi Alavizadeh
28+
29+This file is part of qpdfview.
30+
31+qpdfview is free software: you can redistribute it and/or modify
32+it under the terms of the GNU General Public License as published by
33+the Free Software Foundation, either version 2 of the License, or
34+(at your option) any later version.
35+
36+qpdfview is distributed in the hope that it will be useful,
37+but WITHOUT ANY WARRANTY; without even the implied warranty of
38+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
39+GNU General Public License for more details.
40+
41+You should have received a copy of the GNU General Public License
42+along with qpdfview. If not, see <http://www.gnu.org/licenses/>.
43+
44+*/
45+
46+#include "bookmarkitemdelegate.h"
47+
48+#include <QApplication>
49+
50+#include "bookmarkmodel.h"
51+#include "miscellaneous.h"
52+
53+namespace
54+{
55+ const int lineSpacing = 4;
56+} // anonymous
57+
58+namespace qpdfview
59+{
60+
61+BookmarkItemDelegate::BookmarkItemDelegate(QObject* parent) : QStyledItemDelegate(parent)
62+{
63+}
64+
65+void BookmarkItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
66+{
67+ QStyledItemDelegate::paint(painter, option, index);
68+
69+ const QString comment = index.data(BookmarkModel::CommentRole).toString().simplified();
70+
71+ if(comment.isEmpty())
72+ {
73+ return;
74+ }
75+
76+ const int textMargin = QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1;
77+ const QRect textRect = option.rect.adjusted(textMargin, option.rect.height() - option.fontMetrics.height() - textMargin, -textMargin, 0);
78+
79+ drawAlternativeText(painter, textRect, option, comment);
80+}
81+
82+QSize BookmarkItemDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
83+{
84+ QStyleOptionViewItem opt = option;
85+ initStyleOption(&opt, index);
86+ const QWidget* widget = option.widget;
87+ const QStyle* style = widget ? widget->style() : QApplication::style();
88+
89+ QSize size = style->sizeFromContents(QStyle::CT_ItemViewItem, &opt, QSize(), widget);
90+
91+ if (!index.data(BookmarkModel::CommentRole).toString().isEmpty())
92+ {
93+ size.setHeight(size.height() + opt.fontMetrics.height() + lineSpacing);
94+ }
95+
96+ return size;
97+}
98+
99+} // qpdfview
100
101=== added file 'sources/bookmarkitemdelegate.h'
102--- sources/bookmarkitemdelegate.h 1970-01-01 00:00:00 +0000
103+++ sources/bookmarkitemdelegate.h 2018-05-13 21:55:34 +0000
104@@ -0,0 +1,45 @@
105+/*
106+
107+Copyright 2018 Razi Alavizadeh
108+
109+This file is part of qpdfview.
110+
111+qpdfview is free software: you can redistribute it and/or modify
112+it under the terms of the GNU General Public License as published by
113+the Free Software Foundation, either version 2 of the License, or
114+(at your option) any later version.
115+
116+qpdfview is distributed in the hope that it will be useful,
117+but WITHOUT ANY WARRANTY; without even the implied warranty of
118+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
119+GNU General Public License for more details.
120+
121+You should have received a copy of the GNU General Public License
122+along with qpdfview. If not, see <http://www.gnu.org/licenses/>.
123+
124+*/
125+
126+#ifndef BOOKMARKITEMDELEGATE_H
127+#define BOOKMARKITEMDELEGATE_H
128+
129+#include <QStyledItemDelegate>
130+
131+namespace qpdfview
132+{
133+
134+class BookmarkItemDelegate : public QStyledItemDelegate
135+{
136+ Q_OBJECT
137+
138+public:
139+ explicit BookmarkItemDelegate(QObject* parent = 0);
140+
141+ void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
142+
143+ QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const;
144+
145+};
146+
147+} // qpdfview
148+
149+#endif // BOOKMARKITEMDELEGATE_H
150
151=== modified file 'sources/bookmarkmodel.h'
152--- sources/bookmarkmodel.h 2017-05-12 18:33:16 +0000
153+++ sources/bookmarkmodel.h 2018-05-13 21:55:34 +0000
154@@ -45,6 +45,25 @@
155 comment(comment),
156 modified(modified) {}
157
158+ void appendComment(const QString& text)
159+ {
160+ if(text.isEmpty())
161+ {
162+ return;
163+ }
164+
165+ if(comment.endsWith("\n"))
166+ {
167+ comment.append("\n");
168+ }
169+ else if(!comment.isEmpty())
170+ {
171+ comment.append("\n\n");
172+ }
173+
174+ comment.append(text);
175+ }
176+
177 };
178
179 } // namespace qpdfview
180
181=== modified file 'sources/documentview.cpp'
182--- sources/documentview.cpp 2018-05-05 05:57:24 +0000
183+++ sources/documentview.cpp 2018-05-13 21:55:34 +0000
184@@ -2770,6 +2770,9 @@
185 connect(page, SIGNAL(openInSourceEditor(int,QPointF)), SLOT(on_pages_openInSourceEditor(int,QPointF)));
186
187 connect(page, SIGNAL(wasModified()), SLOT(on_pages_wasModified()));
188+
189+ connect(page, SIGNAL(appendToBookmarkRequested(QString)),
190+ SIGNAL(appendToBookmarkRequested(QString)));
191 }
192 }
193
194
195=== modified file 'sources/documentview.h'
196--- sources/documentview.h 2018-03-28 19:19:40 +0000
197+++ sources/documentview.h 2018-05-13 21:55:34 +0000
198@@ -204,6 +204,8 @@
199 void searchFinished();
200 void searchProgressChanged(int progress);
201
202+ void appendToBookmarkRequested(const QString& comment);
203+
204 public slots:
205 void show();
206
207
208=== modified file 'sources/mainwindow.cpp'
209--- sources/mainwindow.cpp 2018-05-13 17:34:58 +0000
210+++ sources/mainwindow.cpp 2018-05-13 21:55:34 +0000
211@@ -85,6 +85,7 @@
212 #include "bookmarkmenu.h"
213 #include "bookmarkdialog.h"
214 #include "database.h"
215+#include "bookmarkitemdelegate.h"
216
217
218 namespace qpdfview
219@@ -2005,7 +2006,7 @@
220 }
221 }
222
223-void MainWindow::on_addBookmark_triggered()
224+void MainWindow::on_addBookmark_triggered(const QString& comment)
225 {
226 const QString& currentPageLabel = s_settings->mainWindow().usePageLabel() || currentTab()->hasFrontMatter()
227 ? currentTab()->pageLabelFromNumber(currentTab()->currentPage())
228@@ -2020,6 +2021,8 @@
229 model->findBookmark(bookmark);
230 }
231
232+ bookmark.appendComment(comment);
233+
234 QScopedPointer< BookmarkDialog > dialog(new BookmarkDialog(bookmark, this));
235
236 if(dialog->exec() == QDialog::Accepted)
237@@ -2793,6 +2796,8 @@
238 connect(tab, SIGNAL(searchProgressChanged(int)), SLOT(on_currentTab_searchProgressChanged(int)));
239
240 connect(tab, SIGNAL(customContextMenuRequested(QPoint)), SLOT(on_currentTab_customContextMenuRequested(QPoint)));
241+
242+ connect(tab, SIGNAL(appendToBookmarkRequested(QString)), SLOT(on_addBookmark_triggered(QString)));
243 }
244
245 void MainWindow::restorePerFileSettings(DocumentView* tab)
246@@ -2851,6 +2856,7 @@
247
248 tab->setParent(this);
249 tab->setVisible(false);
250+ tab->clearResults();
251
252 tab->clearResults();
253
254@@ -3468,6 +3474,7 @@
255 m_bookmarksView->setSelectionMode(QAbstractItemView::SingleSelection);
256 m_bookmarksView->setSelectionBehavior(QAbstractItemView::SelectRows);
257 m_bookmarksView->setContextMenuPolicy(Qt::CustomContextMenu);
258+ m_bookmarksView->setItemDelegateForColumn(0, new BookmarkItemDelegate(m_bookmarksView));
259
260 connect(m_bookmarksView->horizontalHeader(), SIGNAL(sectionCountChanged(int,int)), SLOT(on_bookmarks_sectionCountChanged()));
261 connect(m_bookmarksView, SIGNAL(clicked(QModelIndex)), SLOT(on_bookmarks_clicked(QModelIndex)));
262
263=== modified file 'sources/mainwindow.h'
264--- sources/mainwindow.h 2018-03-29 18:56:40 +0000
265+++ sources/mainwindow.h 2018-05-13 21:55:34 +0000
266@@ -235,7 +235,7 @@
267
268 void on_previousBookmark_triggered();
269 void on_nextBookmark_triggered();
270- void on_addBookmark_triggered();
271+ void on_addBookmark_triggered(const QString& comment = QString());
272 void on_removeBookmark_triggered();
273 void on_removeAllBookmarks_triggered();
274
275
276=== modified file 'sources/miscellaneous.cpp'
277--- sources/miscellaneous.cpp 2018-01-17 21:09:04 +0000
278+++ sources/miscellaneous.cpp 2018-05-13 21:55:34 +0000
279@@ -31,8 +31,10 @@
280 #include <QLabel>
281 #include <QMenu>
282 #include <QMouseEvent>
283+#include <QPainter>
284 #include <QProcess>
285 #include <QScrollBar>
286+#include <QTextLayout>
287 #include <QTimer>
288 #include <QToolTip>
289 #include <QVBoxLayout>
290@@ -63,6 +65,46 @@
291 return !indexes.isEmpty() ? indexes.first() : QModelIndex();
292 }
293
294+static void drawTextHelper(QPainter* painter, const QString& text, const QRect& textRect, const QStyleOptionViewItem& option, const QTextOption& textOption)
295+{
296+ painter->save();
297+
298+ QPalette::ColorGroup cg = option.state & QStyle::State_Enabled
299+ ? QPalette::Normal : QPalette::Disabled;
300+ if (cg == QPalette::Normal && !(option.state & QStyle::State_Active))
301+ {
302+ cg = QPalette::Inactive;
303+ }
304+
305+ if (option.state & QStyle::State_Selected) {
306+ painter->setPen(option.palette.color(cg, QPalette::HighlightedText));
307+ }
308+ else
309+ {
310+ painter->setPen(option.palette.color(cg, QPalette::Text));
311+ }
312+
313+ QFont font = option.font;
314+ font.setWeight(QFont::Light);
315+ painter->setFont(font);
316+
317+ painter->drawText(textRect, text, textOption);
318+
319+ painter->restore();
320+}
321+
322+static QTextOption& textOptionHelper(const QString& text, Qt::Alignment alignment, QTextOption::WrapMode wrap = QTextOption::NoWrap)
323+{
324+ QTextOption textOption;
325+ const Qt::LayoutDirection textDirection = text.isRightToLeft() ? Qt::RightToLeft : Qt::LeftToRight;
326+
327+ textOption.setTextDirection(textDirection);
328+ textOption.setAlignment(QStyle::visualAlignment(textDirection, alignment));
329+ textOption.setWrapMode(wrap);
330+
331+ return textOption;
332+}
333+
334 } // anonymous
335
336 GraphicsCompositionModeEffect::GraphicsCompositionModeEffect(QPainter::CompositionMode compositionMode, QObject* parent) : QGraphicsEffect(parent),
337@@ -988,4 +1030,76 @@
338 );
339 }
340
341+void drawAlternativeText(QPainter* painter, const QRect& textRect, const QStyleOptionViewItem& option, const QString& text, const QString& matchedText)
342+{
343+ const QString elidedText = option.fontMetrics.elidedText(text, option.textElideMode, textRect.width());
344+ const QTextOption textOption = textOptionHelper(text, option.displayAlignment);
345+
346+ // If matchedText is empty just use QPainter::drawText()
347+ if (matchedText.isEmpty())
348+ {
349+ drawTextHelper(painter, elidedText, textRect, option, textOption);
350+
351+ return;
352+ }
353+
354+ // When matchedText is not empty we use some QTextLayout::FormatRanges
355+ // to highlight matchedText.
356+#if QT_VERSION >= QT_VERSION_CHECK(5,6,0)
357+
358+ QVector< QTextLayout::FormatRange > additionalFormats;
359+
360+#else
361+
362+ QList< QTextLayout::FormatRange > additionalFormats;
363+
364+#endif
365+
366+ const int matchedTextLength = matchedText.length();
367+
368+ for(int index = 0; (index = text.indexOf(matchedText, index)) != -1; index += matchedTextLength)
369+ {
370+ QTextLayout::FormatRange formatRange;
371+ formatRange.start = index;
372+ formatRange.length = matchedTextLength;
373+ formatRange.format.setFontWeight(QFont::Bold);
374+
375+ additionalFormats.append(formatRange);
376+ }
377+
378+ QTextLayout textLayout;
379+ textLayout.setTextOption(textOption);
380+ textLayout.setText(elidedText);
381+
382+ QFont font = option.font;
383+ font.setWeight(QFont::Light);
384+ textLayout.setFont(font);
385+
386+ if (!additionalFormats.isEmpty())
387+ {
388+#if QT_VERSION >= QT_VERSION_CHECK(5,6,0)
389+
390+ textLayout.setFormats(additionalFormats);
391+
392+#else
393+
394+ textLayout.setAdditionalFormats(additionalFormats);
395+
396+#endif
397+ }
398+
399+ textLayout.beginLayout();
400+
401+ QTextLine textLine = textLayout.createLine();
402+
403+ if(textLine.isValid())
404+ {
405+ textLine.setLineWidth(textRect.width());
406+
407+ textLayout.endLayout();
408+
409+ textLine.draw(painter, textRect.topLeft());
410+ }
411+}
412+
413 } // qpdfview
414
415=== modified file 'sources/miscellaneous.h'
416--- sources/miscellaneous.h 2018-01-17 21:09:04 +0000
417+++ sources/miscellaneous.h 2018-05-13 21:55:34 +0000
418@@ -421,6 +421,9 @@
419
420 void openInNewWindow(const QString& filePath, int page);
421
422+
423+void drawAlternativeText(QPainter* painter, const QRect& textRect, const QStyleOptionViewItem& option, const QString& text, const QString& matchedText = QString());
424+
425 } // qpdfview
426
427 #endif // MISCELLANEOUS_H
428
429=== modified file 'sources/pageitem.cpp'
430--- sources/pageitem.cpp 2017-04-19 21:01:25 +0000
431+++ sources/pageitem.cpp 2018-05-13 21:55:34 +0000
432@@ -778,11 +778,13 @@
433 QAction* selectTextAction = menu.addAction(tr("&Select text"));
434 const QAction* copyImageAction = menu.addAction(tr("Copy &image"));
435 const QAction* saveImageToFileAction = menu.addAction(tr("Save image to &file..."));
436+ QAction* appendToBookmarkComment = menu.addAction(tr("&Appent to bookmark comment..."));
437
438 const QString text = m_page->text(m_transform.inverted().mapRect(m_rubberBand));
439
440 copyTextAction->setVisible(!text.isEmpty());
441 selectTextAction->setVisible(!text.isEmpty() && QApplication::clipboard()->supportsSelection());
442+ appendToBookmarkComment->setVisible(!text.isEmpty());
443
444 const QAction* action = menu.exec(screenPos);
445
446@@ -821,6 +823,10 @@
447 }
448 }
449 }
450+ else if(action == appendToBookmarkComment)
451+ {
452+ emit appendToBookmarkRequested(text);
453+ }
454 }
455
456 void PageItem::addAnnotation(QPoint screenPos)
457
458=== modified file 'sources/pageitem.h'
459--- sources/pageitem.h 2017-04-19 21:01:25 +0000
460+++ sources/pageitem.h 2018-05-13 21:55:34 +0000
461@@ -109,6 +109,8 @@
462
463 void wasModified();
464
465+ void appendToBookmarkRequested(const QString& comment);
466+
467 public slots:
468 void refresh(bool keepObsoletePixmaps = false, bool dropCachedPixmaps = false);
469
470
471=== modified file 'sources/searchitemdelegate.cpp'
472--- sources/searchitemdelegate.cpp 2018-05-13 17:29:42 +0000
473+++ sources/searchitemdelegate.cpp 2018-05-13 21:55:34 +0000
474@@ -28,6 +28,7 @@
475 #include <QTextLayout>
476
477 #include "searchmodel.h"
478+#include "miscellaneous.h"
479
480 namespace qpdfview
481 {
482@@ -58,7 +59,10 @@
483
484 if(!matchedText.isEmpty() && !surroundingText.isEmpty())
485 {
486- paintText(painter, option, matchedText, surroundingText);
487+ const int textMargin = QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1;
488+ const QRect textRect = option.rect.adjusted(textMargin, 0, -textMargin, 0);
489+
490+ drawAlternativeText(painter, textRect, option, surroundingText, matchedText);
491 return;
492 }
493 }
494@@ -77,68 +81,4 @@
495 painter->restore();
496 }
497
498-void SearchItemDelegate::paintText(QPainter* painter, const QStyleOptionViewItem& option,
499- const QString& matchedText, const QString& surroundingText) const
500-{
501- const int textMargin = QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1;
502- const QRect textRect = option.rect.adjusted(textMargin, 0, -textMargin, 0);
503- const QString elidedText = option.fontMetrics.elidedText(surroundingText, option.textElideMode, textRect.width());
504-
505- QTextOption textOption;
506- textOption.setWrapMode(QTextOption::NoWrap);
507- textOption.setTextDirection(elidedText.isRightToLeft() ? Qt::RightToLeft : Qt::LeftToRight);
508- textOption.setAlignment(QStyle::visualAlignment(textOption.textDirection(), option.displayAlignment));
509-
510- QTextLayout textLayout;
511- textLayout.setTextOption(textOption);
512- textLayout.setText(elidedText);
513- textLayout.setFont(option.font);
514-
515- QFont font = textLayout.font();
516- font.setWeight(QFont::Light);
517- textLayout.setFont(font);
518-
519-
520- QList< QTextLayout::FormatRange > additionalFormats;
521-
522- for(int index = 0; (index = surroundingText.indexOf(matchedText, index)) != -1; index += matchedText.length())
523- {
524- QTextLayout::FormatRange formatRange;
525- formatRange.start = index;
526- formatRange.length = matchedText.length();
527- formatRange.format.setFontWeight(QFont::Bold);
528-
529- additionalFormats.append(formatRange);
530- }
531-
532- textLayout.setAdditionalFormats(additionalFormats);
533-
534-
535- textLayout.beginLayout();
536-
537- QTextLine textLine = textLayout.createLine();
538-
539- if(!textLine.isValid())
540- {
541- return;
542- }
543-
544- textLine.setLineWidth(textRect.width());
545-
546- textLayout.endLayout();
547-
548-
549- const QSize layoutSize(textRect.width(), qFloor(textLine.height()));
550- const QRect layoutRect = QStyle::alignedRect(option.direction, option.displayAlignment, layoutSize, textRect);
551-
552- painter->save();
553-
554- painter->setClipping(true);
555- painter->setClipRect(layoutRect);
556-
557- textLine.draw(painter, layoutRect.topLeft());
558-
559- painter->restore();
560-}
561-
562 } // qpdfview
563
564=== modified file 'sources/searchitemdelegate.h'
565--- sources/searchitemdelegate.h 2015-01-24 16:36:59 +0000
566+++ sources/searchitemdelegate.h 2018-05-13 21:55:34 +0000
567@@ -39,8 +39,6 @@
568 private:
569 void paintProgress(QPainter* painter, const QStyleOptionViewItem& option,
570 int progress) const;
571- void paintText(QPainter* painter, const QStyleOptionViewItem& option,
572- const QString& matchedText, const QString& surroundingText) const;
573
574 };
575

Subscribers

People subscribed via source and target branches