1 /*
2 	Copyright 2006-2019 The QElectroTech Team
3 	This file is part of QElectroTech.
4 
5 	QElectroTech is free software: you can redistribute it and/or modify
6 	it under the terms of the GNU General Public License as published by
7 	the Free Software Foundation, either version 2 of the License, or
8 	(at your option) any later version.
9 
10 	QElectroTech is distributed in the hope that it will be useful,
11 	but WITHOUT ANY WARRANTY; without even the implied warranty of
12 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 	GNU General Public License for more details.
14 
15 	You should have received a copy of the GNU General Public License
16 	along with QElectroTech.  If not, see <http://www.gnu.org/licenses/>.
17 */
18 #ifndef RECENT_FILES_H
19 #define RECENT_FILES_H
20 #include <QtCore>
21 #include <QIcon>
22 class QMenu;
23 /**
24 	This class provides a way to manage recently opened files.
25 */
26 class RecentFiles : public QObject {
27 	Q_OBJECT
28 
29 	// constructors, destructor
30 	public:
31 	RecentFiles(const QString &, int = 10, QObject * = nullptr);
32 	~RecentFiles() override;
33 	private:
34 	RecentFiles(const RecentFiles &);
35 
36 	// methods
37 	public:
38 	int size() const;
39 	QMenu *menu() const;
40 	QIcon iconForFiles() const;
41 	void setIconForFiles(const QIcon &);
42 
43 	public slots:
44 	void clear();
45 	void save();
46 	void fileWasOpened(const QString &);
47 
48 	signals:
49 	void fileOpeningRequested(const QString &);
50 
51 	private:
52 	void extractFilesFromSettings();
53 	void insertFile(const QString &);
54 	void saveFilesToSettings();
55 	void buildMenu();
56 
57 	private slots:
58 	void handleMenuRequest(const QString &);
59 
60 	// attributes
61 	private:
62 	QString identifier_;
63 	int size_;
64 	QList<QString> list_;
65 	QMenu *menu_;
66 	QSignalMapper *mapper_;
67 	QIcon files_icon_;
68 };
69 #endif
70