-
Notifications
You must be signed in to change notification settings - Fork 0
/
QRecentFilesMenu.h
73 lines (60 loc) · 2.22 KB
/
QRecentFilesMenu.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
#ifndef QRECENTFILESMENU_H
#define QRECENTFILESMENU_H
#include <QMenu>
#include <QStringList>
class QRecentFilesMenu : public QMenu
{
Q_OBJECT
Q_PROPERTY(int maxCount READ maxCount WRITE setMaxCount)
Q_PROPERTY(QString format READ format WRITE setFormat)
public:
//! Constructs a menu with parent parent.
QRecentFilesMenu(QWidget * parent = 0 );
//! Constructs a menu with a title and a parent.
QRecentFilesMenu(const QString & title, QWidget * parent = 0 );
//! Returns the maximum number of entries in the menu.
int maxCount() const;
/** This property holds the string used to generate the item text.
* %d is replaced by the item number
* %s is replaced by the item text
* The default value is "%d %s".
*/
void setFormat(const QString &format);
//! Returns the current format. /sa setFormat
const QString & format() const;
/** Saves the state of the recent entries.
* Typically this is used in conjunction with QSettings to remember entries
* for a future session. A version number is stored as part of the data.
* Here is an example:
* QSettings settings;
* settings.setValue("recentFiles", recentFilesMenu->saveState());
*/
QByteArray saveState() const;
/** Restores the recent entries to the state specified.
* Typically this is used in conjunction with QSettings to restore entries from a past session.
* Returns false if there are errors.
* Here is an example:
* QSettings settings;
* recentFilesMenu->restoreState(settings.value("recentFiles").toByteArray());
*/
bool restoreState(const QByteArray &state);
public slots:
//!
void addRecentFile(const QString &fileName);
//! Removes all the menu's actions.
void clearMenu();
//! Sets the maximum number of entries int he menu.
void setMaxCount(int);
signals:
//! This signal is emitted when a recent file in this menu is triggered.
void recentFileTriggered(const QString & filename);
void insertFile(const QString &filename);
private slots:
void menuTriggered(QAction*);
void updateRecentFileActions();
private:
int m_maxCount;
QString m_format;
QStringList m_files;
};
#endif // QRECENTFILEMENU_H