All Classes Namespaces Functions Variables Enumerations Properties Pages
recentfilemenu.h
1 /*
2 
3 Pencil2D - Traditional Animation Software
4 Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
5 Copyright (C) 2012-2020 Matthew Chiawen Chang
6 
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; version 2 of the License.
10 
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15 
16 */
17 
18 
19 #ifndef RECENTFILEMENU_H
20 #define RECENTFILEMENU_H
21 
22 #include <map>
23 #include <QMenu>
24 #include <QStringList>
25 #include "pencildef.h"
26 
27 class QAction;
28 class ListItemModel;
29 
30 class RecentFileMenu : public QMenu
31 {
32  Q_OBJECT
33 
34 public:
35  explicit RecentFileMenu(QString title = tr("Open Recent"), QWidget* parent = nullptr);
36  ~RecentFileMenu();
37 
38  static const int MAX_RECENT_FILES = 10;
39 
40  QStringList getRecentFiles() { return mRecentFiles; }
41  void setRecentFiles(const QStringList& filenames);
42 
43  void addRecentFile(QString filename);
44  void removeRecentFile(QString filename);
45 
46  bool loadFromDisk();
47  bool saveToDisk();
48 
49 signals:
50  void loadRecentFile(QString filename);
51 
52 public slots:
53  void clear();
54 
55 protected slots:
56  void onRecentFileTriggered();
57 
58 private:
59  QStringList mRecentFiles;
60  std::map<QString, QAction*> mRecentActions;
61  QAction* mClearAction = nullptr;
62  QAction* mClearSeparator = nullptr;
63  QAction* mEmptyAction = nullptr;
64 };
65 
66 #endif // RECENTFILEMENU_H
QString tr(const char *sourceText, const char *disambiguation, int n)
Q_OBJECTQ_OBJECT
QString title() const const
QObject * parent() const const