-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
RabbitRecentMenu.h
133 lines (106 loc) · 3.59 KB
/
RabbitRecentMenu.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/** @copyright Copyright (c) Kang Lin studio, All Rights Reserved
* @author Kang Lin <[email protected]>
* @abstract Tools
*/
#ifndef CRabbitRecentMenu_H
#define CRabbitRecentMenu_H
#pragma once
#include <QMenu>
#include <QList>
#include "rabbitcommon_export.h"
namespace RabbitCommon {
/**
* \~chinese 最近打开菜单
*
* \~english Recently opened menu
*
* \~
* \ingroup API
*/
class RABBITCOMMON_EXPORT CRecentMenu : 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.
CRecentMenu(QWidget * parent = 0);
//! Constructs a menu with a title and a parent.
CRecentMenu(const QString & title, QWidget * parent = 0);
//! Constructs a menu with a title, icon and a parent.
CRecentMenu(const QString & title, const QIcon& icon, 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;
//! Default enable save state
bool disableSaveState(bool disable);
/*! 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, const QString& title = QString());
//! 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);
private slots:
void menuTriggered(QAction*);
void updateRecentFileActions();
void slotSaveState();
signals:
void sigSaveState();
private:
int m_maxCount;
QString m_format;
class _Content
{
public:
_Content(){}
_Content(const QString& title, const QString& file) {
m_szTitle = title;
m_szFile = file;
}
_Content(const _Content& c) {
m_szTitle = c.m_szTitle;
m_szFile = c.m_szFile;
}
bool operator==(const _Content& c) const {
if(m_szFile == c.m_szFile && m_szTitle == c.m_szTitle)
return true;
return false;
}
QString m_szTitle;
QString m_szFile;
};
friend QDataStream & operator<< (QDataStream& d, const _Content& image);
friend QDataStream & operator>> (QDataStream& d, _Content& image);
QList<_Content> m_OpenContent;
bool m_DisableSaveState;
bool m_bUpdate;
};
} //namespace RabbitCommon
#endif // QRECENTFILEMENU_H