1 | /* |
---|
2 | |
---|
3 | Copyright 2014 S. Razi Alavizadeh |
---|
4 | Copyright 2012-2014 Adam Reichold |
---|
5 | |
---|
6 | This file is part of qpdfview. |
---|
7 | |
---|
8 | qpdfview is free software: you can redistribute it and/or modify |
---|
9 | it under the terms of the GNU General Public License as published by |
---|
10 | the Free Software Foundation, either version 2 of the License, or |
---|
11 | (at your option) any later version. |
---|
12 | |
---|
13 | qpdfview is distributed in the hope that it will be useful, |
---|
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
16 | GNU General Public License for more details. |
---|
17 | |
---|
18 | You should have received a copy of the GNU General Public License |
---|
19 | along with qpdfview. If not, see <http://www.gnu.org/licenses/>. |
---|
20 | |
---|
21 | */ |
---|
22 | |
---|
23 | #include "bookmarkmenu.h" |
---|
24 | |
---|
25 | #include "miscellaneous.h" |
---|
26 | |
---|
27 | #include <QFileInfo> |
---|
28 | |
---|
29 | namespace qpdfview |
---|
30 | { |
---|
31 | |
---|
32 | BookmarkMenu::BookmarkMenu(const QFileInfo& fileInfo, QWidget* parent) : QMenu(parent) |
---|
33 | { |
---|
34 | menuAction()->setText(fileInfo.completeBaseName()); |
---|
35 | menuAction()->setToolTip(fileInfo.absoluteFilePath()); |
---|
36 | |
---|
37 | menuAction()->setData(fileInfo.absoluteFilePath()); |
---|
38 | |
---|
39 | m_openAction = addAction(tr("&Open")); |
---|
40 | m_openAction->setIcon(loadIconWithFallback(QLatin1String("document-open"))); |
---|
41 | m_openAction->setIconVisibleInMenu(true); |
---|
42 | connect(m_openAction, SIGNAL(triggered()), SLOT(on_open_triggered())); |
---|
43 | |
---|
44 | m_openInNewTabAction = addAction(tr("Open in new &tab")); |
---|
45 | m_openInNewTabAction->setIcon(loadIconWithFallback(QLatin1String("tab-new"))); |
---|
46 | m_openInNewTabAction->setIconVisibleInMenu(true); |
---|
47 | connect(m_openInNewTabAction, SIGNAL(triggered()), SLOT(on_openInNewTab_triggered())); |
---|
48 | |
---|
49 | m_jumpToPageActionGroup = new QActionGroup(this); |
---|
50 | connect(m_jumpToPageActionGroup, SIGNAL(triggered(QAction*)), SLOT(on_jumpToPage_triggered(QAction*))); |
---|
51 | |
---|
52 | m_separatorAction = addSeparator(); |
---|
53 | |
---|
54 | m_removeBookmarkAction = addAction(tr("&Remove bookmark")); |
---|
55 | connect(m_removeBookmarkAction, SIGNAL(triggered()), SLOT(on_removeBookmark_triggered())); |
---|
56 | } |
---|
57 | |
---|
58 | void BookmarkMenu::addJumpToPageAction(int page, const QString& label) |
---|
59 | { |
---|
60 | QAction* before = m_separatorAction; |
---|
61 | |
---|
62 | foreach(QAction* action, m_jumpToPageActionGroup->actions()) |
---|
63 | { |
---|
64 | if(action->data().toInt() == page) |
---|
65 | { |
---|
66 | action->setText(label); |
---|
67 | |
---|
68 | return; |
---|
69 | } |
---|
70 | else if(action->data().toInt() > page) |
---|
71 | { |
---|
72 | before = action; |
---|
73 | |
---|
74 | break; |
---|
75 | } |
---|
76 | } |
---|
77 | |
---|
78 | QAction* action = new QAction(label, this); |
---|
79 | action->setIcon(loadIconWithFallback(QLatin1String("go-jump"))); |
---|
80 | action->setIconVisibleInMenu(true); |
---|
81 | action->setData(page); |
---|
82 | |
---|
83 | insertAction(before, action); |
---|
84 | m_jumpToPageActionGroup->addAction(action); |
---|
85 | } |
---|
86 | |
---|
87 | void BookmarkMenu::removeJumpToPageAction(int page) |
---|
88 | { |
---|
89 | foreach(QAction* action, m_jumpToPageActionGroup->actions()) |
---|
90 | { |
---|
91 | if(action->data().toInt() == page) |
---|
92 | { |
---|
93 | delete action; |
---|
94 | |
---|
95 | break; |
---|
96 | } |
---|
97 | } |
---|
98 | } |
---|
99 | |
---|
100 | void BookmarkMenu::on_open_triggered() |
---|
101 | { |
---|
102 | emit openTriggered(absoluteFilePath()); |
---|
103 | } |
---|
104 | |
---|
105 | void BookmarkMenu::on_openInNewTab_triggered() |
---|
106 | { |
---|
107 | emit openInNewTabTriggered(absoluteFilePath()); |
---|
108 | } |
---|
109 | |
---|
110 | void BookmarkMenu::on_jumpToPage_triggered(QAction* action) |
---|
111 | { |
---|
112 | emit jumpToPageTriggered(absoluteFilePath(), action->data().toInt()); |
---|
113 | } |
---|
114 | |
---|
115 | void BookmarkMenu::on_removeBookmark_triggered() |
---|
116 | { |
---|
117 | emit removeBookmarkTriggered(absoluteFilePath()); |
---|
118 | } |
---|
119 | |
---|
120 | } // qpdfview |
---|