3
Copyright 2012 Adam Reichold
5
This file is part of qpdfview.
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.
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.
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/>.
22
#include "recentlyusedmenu.h"
24
RecentlyUsedMenu::RecentlyUsedMenu(QWidget* parent) : QMenu(parent)
26
menuAction()->setText(tr("Recently &used"));
27
menuAction()->setIcon(QIcon::fromTheme("document-open-recent"));
28
menuAction()->setIconVisibleInMenu(true);
30
m_openActionGroup = new QActionGroup(this);
31
connect(m_openActionGroup, SIGNAL(triggered(QAction*)), SLOT(on_open_triggered(QAction*)));
33
m_separatorAction = addSeparator();
35
m_clearListAction = addAction(tr("&Clear list"));
36
connect(m_clearListAction, SIGNAL(triggered()), SLOT(on_clearList_triggered()));
39
void RecentlyUsedMenu::addOpenAction(const QString& filePath)
41
foreach(QAction* action, m_openActionGroup->actions())
43
if(action->data().toString() == QFileInfo(filePath).absoluteFilePath())
46
m_openActionGroup->removeAction(action);
48
insertAction(m_separatorAction, action);
49
m_openActionGroup->addAction(action);
55
if(m_openActionGroup->actions().count() == 10)
57
QAction* first = m_openActionGroup->actions().first();
60
m_openActionGroup->removeAction(first);
65
QFileInfo fileInfo(filePath);
67
QAction* action = new QAction(fileInfo.completeBaseName(), this);
68
action->setToolTip(fileInfo.absoluteFilePath());
69
action->setData(fileInfo.absoluteFilePath());
71
insertAction(m_separatorAction, action);
72
m_openActionGroup->addAction(action);
75
void RecentlyUsedMenu::removeOpenAction(const QString& filePath)
77
foreach(QAction* action, m_openActionGroup->actions())
79
if(action->data().toString() == QFileInfo(filePath).absoluteFilePath())
88
QStringList RecentlyUsedMenu::filePaths() const
90
QStringList filePaths;
92
foreach(QAction* action, m_openActionGroup->actions())
94
filePaths.append(action->data().toString());
100
void RecentlyUsedMenu::on_open_triggered(QAction* action)
102
emit openTriggered(action->data().toString());
105
void RecentlyUsedMenu::on_clearList_triggered()
107
qDeleteAll(m_openActionGroup->actions());