~ubuntu-branches/debian/sid/qpdfview/sid

« back to all changes in this revision

Viewing changes to sources/recentlyusedmenu.cpp

  • Committer: Package Import Robot
  • Author(s): Benjamin Eltzner
  • Date: 2012-09-02 15:18:34 UTC
  • mfrom: (1.2.1) (4.1.1 experimental)
  • Revision ID: package-import@ubuntu.com-20120902151834-xa61s2fuphrrdwxs
Tags: 0.3.3-1
* Fixed some rendering artifacts.
* Improved navigation using bookmarks.
* Reorganized settings dialog and made keyboard modifiers for several mouse
  actions configurable.
* Added menu and tool bar actions to copy texts or images or add annotations.
* Added Ukrainian translation. Thanks to Vladimir Smolyar.
* Updated Slovak translation. Thanks to DAG Software.
* Updated Czech translation. Thanks to Pavel Fric.
* Updated Russian translation. Thanks to Eugene Marshal and Vladimir Smolyar.
* Added MIME file. (Closes: #685599)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 
 
3
Copyright 2012 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 "recentlyusedmenu.h"
 
23
 
 
24
RecentlyUsedMenu::RecentlyUsedMenu(QWidget* parent) : QMenu(parent)
 
25
{
 
26
    menuAction()->setText(tr("Recently &used"));
 
27
    menuAction()->setIcon(QIcon::fromTheme("document-open-recent"));
 
28
    menuAction()->setIconVisibleInMenu(true);
 
29
 
 
30
    m_openActionGroup = new QActionGroup(this);
 
31
    connect(m_openActionGroup, SIGNAL(triggered(QAction*)), SLOT(on_open_triggered(QAction*)));
 
32
 
 
33
    m_separatorAction = addSeparator();
 
34
 
 
35
    m_clearListAction = addAction(tr("&Clear list"));
 
36
    connect(m_clearListAction, SIGNAL(triggered()), SLOT(on_clearList_triggered()));
 
37
}
 
38
 
 
39
void RecentlyUsedMenu::addOpenAction(const QString& filePath)
 
40
{
 
41
    foreach(QAction* action, m_openActionGroup->actions())
 
42
    {
 
43
        if(action->data().toString() == QFileInfo(filePath).absoluteFilePath())
 
44
        {
 
45
            removeAction(action);
 
46
            m_openActionGroup->removeAction(action);
 
47
 
 
48
            insertAction(m_separatorAction, action);
 
49
            m_openActionGroup->addAction(action);
 
50
 
 
51
            return;
 
52
        }
 
53
    }
 
54
 
 
55
    if(m_openActionGroup->actions().count() == 10)
 
56
    {
 
57
        QAction* first = m_openActionGroup->actions().first();
 
58
 
 
59
        removeAction(first);
 
60
        m_openActionGroup->removeAction(first);
 
61
 
 
62
        delete first;
 
63
    }
 
64
 
 
65
    QFileInfo fileInfo(filePath);
 
66
 
 
67
    QAction* action = new QAction(fileInfo.completeBaseName(), this);
 
68
    action->setToolTip(fileInfo.absoluteFilePath());
 
69
    action->setData(fileInfo.absoluteFilePath());
 
70
 
 
71
    insertAction(m_separatorAction, action);
 
72
    m_openActionGroup->addAction(action);
 
73
}
 
74
 
 
75
void RecentlyUsedMenu::removeOpenAction(const QString& filePath)
 
76
{
 
77
    foreach(QAction* action, m_openActionGroup->actions())
 
78
    {
 
79
        if(action->data().toString() == QFileInfo(filePath).absoluteFilePath())
 
80
        {
 
81
            delete action;
 
82
 
 
83
            break;
 
84
        }
 
85
    }
 
86
}
 
87
 
 
88
QStringList RecentlyUsedMenu::filePaths() const
 
89
{
 
90
    QStringList filePaths;
 
91
 
 
92
    foreach(QAction* action, m_openActionGroup->actions())
 
93
    {
 
94
        filePaths.append(action->data().toString());
 
95
    }
 
96
 
 
97
    return filePaths;
 
98
}
 
99
 
 
100
void RecentlyUsedMenu::on_open_triggered(QAction* action)
 
101
{
 
102
    emit openTriggered(action->data().toString());
 
103
}
 
104
 
 
105
void RecentlyUsedMenu::on_clearList_triggered()
 
106
{
 
107
    qDeleteAll(m_openActionGroup->actions());
 
108
}