1 | /* |
---|
2 | |
---|
3 | Copyright 2013 Adam Reichold |
---|
4 | |
---|
5 | This file is part of qpdfview. |
---|
6 | |
---|
7 | qpdfview is free software: you can redistribute it and/or modify |
---|
8 | it under the terms of the GNU General Public License as published by |
---|
9 | the Free Software Foundation, either version 2 of the License, or |
---|
10 | (at your option) any later version. |
---|
11 | |
---|
12 | qpdfview is distributed in the hope that it will be useful, |
---|
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
15 | GNU General Public License for more details. |
---|
16 | |
---|
17 | You should have received a copy of the GNU General Public License |
---|
18 | along with qpdfview. If not, see <http://www.gnu.org/licenses/>. |
---|
19 | |
---|
20 | */ |
---|
21 | |
---|
22 | #include "recentlyclosedmenu.h" |
---|
23 | |
---|
24 | #include "documentview.h" |
---|
25 | |
---|
26 | namespace qpdfview |
---|
27 | { |
---|
28 | |
---|
29 | RecentlyClosedMenu::RecentlyClosedMenu(int count, QWidget* parent) : QMenu(parent), |
---|
30 | m_count(count) |
---|
31 | { |
---|
32 | menuAction()->setText(tr("&Recently closed")); |
---|
33 | |
---|
34 | m_tabActionGroup = new QActionGroup(this); |
---|
35 | connect(m_tabActionGroup, SIGNAL(triggered(QAction*)), SLOT(on_tabAction_triggered(QAction*))); |
---|
36 | |
---|
37 | m_separatorAction = addSeparator(); |
---|
38 | |
---|
39 | m_clearListAction = addAction(tr("&Clear list")); |
---|
40 | connect(m_clearListAction, SIGNAL(triggered()), SLOT(on_clearList_triggered())); |
---|
41 | } |
---|
42 | |
---|
43 | void RecentlyClosedMenu::addTabAction(QAction* tabAction) |
---|
44 | { |
---|
45 | if(m_tabActionGroup->actions().count() >= m_count) |
---|
46 | { |
---|
47 | QAction* first = m_tabActionGroup->actions().first(); |
---|
48 | |
---|
49 | removeAction(first); |
---|
50 | m_tabActionGroup->removeAction(first); |
---|
51 | |
---|
52 | first->parent()->deleteLater(); |
---|
53 | } |
---|
54 | |
---|
55 | insertAction(actions().first(), tabAction); |
---|
56 | m_tabActionGroup->addAction(tabAction); |
---|
57 | } |
---|
58 | |
---|
59 | void RecentlyClosedMenu::triggerFirstTabAction() |
---|
60 | { |
---|
61 | const QList< QAction* >& actions = m_tabActionGroup->actions(); |
---|
62 | |
---|
63 | if(!actions.isEmpty()) |
---|
64 | { |
---|
65 | on_tabAction_triggered(actions.first()); |
---|
66 | } |
---|
67 | } |
---|
68 | |
---|
69 | void RecentlyClosedMenu::triggerLastTabAction() |
---|
70 | { |
---|
71 | const QList< QAction* >& actions = m_tabActionGroup->actions(); |
---|
72 | |
---|
73 | if(!actions.isEmpty()) |
---|
74 | { |
---|
75 | on_tabAction_triggered(actions.last()); |
---|
76 | } |
---|
77 | } |
---|
78 | |
---|
79 | void RecentlyClosedMenu::on_tabAction_triggered(QAction* tabAction) |
---|
80 | { |
---|
81 | removeAction(tabAction); |
---|
82 | m_tabActionGroup->removeAction(tabAction); |
---|
83 | |
---|
84 | emit tabActionTriggered(tabAction); |
---|
85 | } |
---|
86 | |
---|
87 | void RecentlyClosedMenu::on_clearList_triggered() |
---|
88 | { |
---|
89 | foreach(QAction* action, m_tabActionGroup->actions()) |
---|
90 | { |
---|
91 | action->parent()->deleteLater(); |
---|
92 | } |
---|
93 | } |
---|
94 | |
---|
95 | } // qpdfview |
---|