-
Notifications
You must be signed in to change notification settings - Fork 26
/
recentfiles.h
79 lines (63 loc) · 2.61 KB
/
recentfiles.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#ifndef RECENTFILES_H
#define RECENTFILES_H
#include <QMainWindow>
#include <QObject>
#include <QSettings>
#include <QStringList>
class QMenu;
class QAction;
#define recentFileCount "recentFiles/numOfRecentFiles"
#define recentFileListId "recentFiles/fileList"
/**
* @brief The RecentFiles class manages a list of recently accessed files.
*
* It handles user-settable number of most recently accessed files, provides
* a sub-menu that allows the user to select recently used files for opening.
*/
class RecentFiles : public QObject {
Q_OBJECT
public:
explicit RecentFiles(
QMainWindow *parent =
NULL); /* Parent mainwindow, just for proper heirarchy, not actually
used outside QObject constr */
~RecentFiles();
/// Inserts the sub-menu into another Menu
/// param menu The parent menu where the sub-menu should be inserted
/// param text Text of menu item after which Recent menu is inserted
void attachToMenuAfterItem(QMenu *menu, QString text, const char *slotName);
QStringList getRecentFiles()
const; ///< application calls this to get list of recent files
void setMostRecentFile(
const QString fileName); ///< called when each new file is opened
void setMostRecentSsdtFile(const QString fileName);
QString strippedName(
const QString &fullFileName); ///< returns filename from full path
void setMenuEnabled(bool tf);
/// returns how many recent files are being remenbered. see
/// setNumOfRecentFiles()
int numberOfRecentFilesToSave();
static const int MaxRecentFiles = 30; ///< Max number of names we keep.
void setTitle(QString text);
QMenu *m_recentMenu;
public slots:
/// The application can set the number of recent files retained/reported here
void setNumOfRecentFiles(int n);
signals:
void openFile(QString fileName); ///< emitted when user selects item from
///< "Open Recent" sub-menu
void newMaxFilesShown(int); ///< tells observers that the number of recent
///< files being remembered has changed.
private slots:
void openRecentFile(); ///< menu items signal this when user selects item
///< from "Open Recent" sub-menu
private:
void purgeMissingFilesFromList(QStringList &recentFileList);
void updateRecentFiles(
QSettings &settings); ///< call this with each new filename
QAction *m_recentMenuTriggeredAction;
QAction
*m_recentFileActions[MaxRecentFiles]; ///< QActions created in file menu
///< for storing recent files
};
#endif // RECENTFILES_H