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

Proposed by Razi Alavizadeh
Status: Merged
Approved by: Adam Reichold
Approved revision: 1694
Merged at revision: 1691
Proposed branch: lp:~srazi/qpdfview/small-patches
Merge into: lp:qpdfview
Diff against target: 118 lines (+23/-33)
3 files modified
sources/djvumodel.cpp (+10/-18)
sources/mainwindow.cpp (+1/-1)
sources/pageitem.cpp (+12/-14)
To merge this branch: bzr merge lp:~srazi/qpdfview/small-patches
Reviewer Review Type Date Requested Status
Adam Reichold Approve
Review via email: mp+234985@code.launchpad.net

Description of the change

Hi Adam,

Some explanations:
Commit Message: "Show text related context-menu's actions only when selected rectangle contains text."
- I think showing "Copy text" when just image is available is confusing.

Commit Message: "Correctly determines word when searching through DjVu document."
- For example searching (book: "Megginson R. An introduction to Banach space theory") for "Banach" now can find "Hahn-Banach", "Banach's". (1229 results improved to 1382 results!)
Indeed, I found this issue when I implemented an extended search dock. It's completed but I didn't push it here because you said there are enough features for new release. (but if you want to review it then I'll push it tonight)

Best Regards,
Razi.

To post a comment you must log in.
Revision history for this message
Adam Reichold (adamreichold) wrote :

Hello Razi,

I don't have time to review and merge right now, but the changes look correct and I will merge as soon as I can and definitely before the next release (since functional analysis without the Hahn-Banach theorem won't get you very far). Just a small thing, could you revert the usage of "QUrl::fromLocalFile" since that is not available on Qt 4.6 which we are currently still targeting. Thanks!

Best regards, Adam.

review: Approve
Revision history for this message
Adam Reichold (adamreichold) wrote :

Hello again,

sorry I was wrong, it was "QUrl::isLocalFile" that was introduced only in Qt 4.8. So I'll take that fix in as well.

Best regards, Adam.

Revision history for this message
Razi Alavizadeh (srazi) wrote :

Hello Adam,
> I don't have time to review and merge right now, but the changes look correct and I will merge as soon as I can and definitely before the next release (since functional analysis without the Hahn-Banach theorem won't get you very far). Just a small thing, could you revert the usage of "QUrl::fromLocalFile" since that is not available on Qt 4.6 which we are currently still targeting. Thanks!
It feels good to see a man of computer's world knows about mathematics's world.

Sorry again unrelated discussions:
1- I suggest that the HelpDialog should be non-modal, then user can read it and test application without closing it.
2- I want to save firstPage state to database (indeed I wrote the patch) but I don't understand the following part of preparePerFileSettings_v2()?

    if(Settings::instance()->mainWindow().restorePerFileSettings())
    {
        query.exec("DELETE FROM perfilesettings_v2 WHERE filePath IN (SELECT filePath FROM perfilesettings_v2 ORDER BY lastUsed DESC LIMIT -1 OFFSET 1000)");
    }
    else
    {
        query.exec("DELETE FROM perfilesettings_v2");
    }

Best Regards,
Razi.

Revision history for this message
Adam Reichold (adamreichold) wrote :

Hello Razi,

Am 19.09.2014 um 22:31 schrieb S. Razi Alavizadeh:
> Hello Adam,
>> I don't have time to review and merge right now, but the changes look correct and I will merge as soon as I can and definitely before the next release (since functional analysis without the Hahn-Banach theorem won't get you very far). Just a small thing, could you revert the usage of "QUrl::fromLocalFile" since that is not available on Qt 4.6 which we are currently still targeting. Thanks!
> It feels good to see a man of computer's world knows about mathematics's world.
>
> Sorry again unrelated discussions:

Again, the mailing list would be best. :-)

> 1- I suggest that the HelpDialog should be non-modal, then user can read it and test application without closing it.

I agree, the change sounds sensible. Can you write up the patch as I
will be travelling until Sunday evening (CEST).

> 2- I want to save firstPage state to database (indeed I wrote the patch) but I don't understand the following part of preparePerFileSettings_v2()?
>
> if(Settings::instance()->mainWindow().restorePerFileSettings())
> {
> query.exec("DELETE FROM perfilesettings_v2 WHERE filePath IN (SELECT filePath FROM perfilesettings_v2 ORDER BY lastUsed DESC LIMIT -1 OFFSET 1000)");
> }
> else
> {
> query.exec("DELETE FROM perfilesettings_v2");
> }

It is our probably not very elegant way to keep only the 1000 least
recently used entries of the per-file settings table (or completely
clear it if the user disabled the option). The number 1000 is pretty
arbitrary and was chosen conservatively and could propbably be improved.
More elegant SQL to keep only the last N entries would of course also be
welcome.

> Best Regards,
> Razi.

Best regards, Adam.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'sources/djvumodel.cpp'
2--- sources/djvumodel.cpp 2014-03-30 09:43:56 +0000
3+++ sources/djvumodel.cpp 2014-09-17 14:08:17 +0000
4@@ -519,6 +519,8 @@
5 QRectF rect;
6 int index = 0;
7
8+ const QTransform transform = QTransform::fromScale(72.0 / m_resolution, 72.0 / m_resolution);
9+
10 while(!words.isEmpty())
11 {
12 miniexp_t textExp = words.takeFirst();
13@@ -531,7 +533,9 @@
14 {
15 const QString word = QString::fromUtf8(miniexp_to_str(miniexp_nth(5, textExp)));
16
17- if(text.indexOf(word, index, matchCase ? Qt::CaseSensitive : Qt::CaseInsensitive) == index)
18+ index = word.indexOf(text, index, (matchCase ? Qt::CaseSensitive : Qt::CaseInsensitive));
19+
20+ if (index != -1)
21 {
22 const int xmin = miniexp_to_int(miniexp_nth(1, textExp));
23 const int ymin = miniexp_to_int(miniexp_nth(2, textExp));
24@@ -540,16 +544,11 @@
25
26 rect = rect.united(QRectF(xmin, m_size.height() - ymax, xmax - xmin, ymax - ymin));
27
28- index += word.length();
29-
30- while(text.length() > index && text.at(index).isSpace())
31- {
32- ++index;
33- }
34-
35- if(text.length() == index)
36- {
37- results.append(rect);
38+ index += text.length();
39+
40+ if (!word.at(index).isLetter())
41+ {
42+ results.append(transform.mapRect(rect));
43
44 rect = QRectF();
45 index = 0;
46@@ -573,13 +572,6 @@
47
48 ddjvu_miniexp_release(m_parent->m_document, pageTextExp);
49
50- const QTransform transform = QTransform::fromScale(72.0 / m_resolution, 72.0 / m_resolution);
51-
52- for(int index = 0; index < results.size(); ++index)
53- {
54- results[index] = transform.mapRect(results[index]);
55- }
56-
57 return results;
58 }
59
60
61=== modified file 'sources/mainwindow.cpp'
62--- sources/mainwindow.cpp 2014-09-10 18:57:50 +0000
63+++ sources/mainwindow.cpp 2014-09-17 14:08:17 +0000
64@@ -910,7 +910,7 @@
65
66 void MainWindow::on_openContainingFolder_triggered()
67 {
68- QDesktopServices::openUrl(currentTab()->fileInfo().absolutePath());
69+ QDesktopServices::openUrl(QUrl::fromLocalFile(currentTab()->fileInfo().absolutePath()));
70 }
71
72 void MainWindow::on_refresh_triggered()
73
74=== modified file 'sources/pageitem.cpp'
75--- sources/pageitem.cpp 2014-09-16 21:07:02 +0000
76+++ sources/pageitem.cpp 2014-09-17 14:08:17 +0000
77@@ -756,29 +756,27 @@
78 {
79 QMenu menu;
80
81- const QAction* copyTextAction = menu.addAction(tr("Copy &text"));
82+ QAction* copyTextAction = menu.addAction(tr("Copy &text"));
83 QAction* selectTextAction = menu.addAction(tr("&Select text"));
84 const QAction* copyImageAction = menu.addAction(tr("Copy &image"));
85 const QAction* saveImageToFileAction = menu.addAction(tr("Save image to &file..."));
86
87- selectTextAction->setVisible(QApplication::clipboard()->supportsSelection());
88+ const QString text = m_page->text(m_transform.inverted().mapRect(m_rubberBand));
89+
90+ selectTextAction->setVisible(QApplication::clipboard()->supportsSelection() && !text.isEmpty());
91+ copyTextAction->setVisible(!text.isEmpty());
92
93 const QAction* action = menu.exec(screenPos);
94
95 if(action == copyTextAction || action == selectTextAction)
96 {
97- const QString text = m_page->text(m_transform.inverted().mapRect(m_rubberBand));
98-
99- if(!text.isEmpty())
100- {
101- if(action == copyTextAction)
102- {
103- QApplication::clipboard()->setText(text);
104- }
105- else
106- {
107- QApplication::clipboard()->setText(text, QClipboard::Selection);
108- }
109+ if(action == copyTextAction)
110+ {
111+ QApplication::clipboard()->setText(text);
112+ }
113+ else
114+ {
115+ QApplication::clipboard()->setText(text, QClipboard::Selection);
116 }
117 }
118 else if(action == copyImageAction || action == saveImageToFileAction)

Subscribers

People subscribed via source and target branches