Omnidome
Fulldome Mapping Software Toolkit
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RecentSessions.h
Go to the documentation of this file.
1 /* Copyright (c) 2014-2016 "Omnidome" by cr8tr
2  * Dome Mapping Projection Software (http://omnido.me).
3  * Omnidome was created by Michael Winkelmann aka Wilston Oreo (@WilstonOreo)
4  *
5  * This file is part of Omnidome.
6  *
7  * Omnidome is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU Affero General Public License for more details.
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef OMNI_UI_RECENTSESSIONS_H_
21 #define OMNI_UI_RECENTSESSIONS_H_
22 
23 #include <deque>
24 #include <QMenu>
25 #include <QString>
26 #include <omni/util.h>
27 
28 namespace omni {
29  namespace ui {
30  /// Action for recent file
31  class RecentFileAction : public QAction {
32  Q_OBJECT
33  public:
34  RecentFileAction(QString const& _file, QObject* = nullptr);
36 
37  /// Check if file exists
38  bool fileExists() const;
39 
40  signals:
41  void fileToBeLoaded(QString const&);
42 
43  public slots:
44  /// Load session triggers fileToBeLoaded signal
45  void loadSession();
46 
47  /// Action is disabled when file does not exist
48  void setState();
49 
50  private:
51  QString file_;
52  };
53 
54  /// Data structure and menu to store default sessions
55  class RecentSessions : public QObject {
56  Q_OBJECT
57  public:
58  RecentSessions(QObject * = nullptr);
60 
61  /// Return pointer to menu
62  QMenu* menu();
63 
64  /// Read recent files from settings
65  void readFromSettings();
66 
67  /// Write recent files to settings
68  void writeToSettings() const;
69 
70  /// Return maximum number of files
71  int numberOfFiles() const;
72 
73  public slots:
74  /// Clear list of recent files
75  void clear();
76 
77  /// Add a new file to list
78  void addFile(QString const&);
79 
80  /// Set maximum number of files
81  void setNumberOfFiles(int);
82 
83  /// Disable action for which file does not exists
84  void setActionStates();
85 
86  signals:
87  void fileToBeLoaded(QString const&);
88 
89  private:
90  /// Add file and optionally regenerate menu
91  void addFile(QString const&, bool _regenerateMenu);
92 
93  /// Return index of file if in list, return -1 if not
94  int fileInList(QString const&) const;
95 
96  /// Generate menu from recent files, create new menu if necessary
97  void generateMenu();
98 
99  std::deque<QString> recentFiles_;
100  std::vector<RecentFileAction*> actions_;
101  QUniquePtr<QMenu> menu_;
102  int numberOfFiles_ = 16;
103  };
104  }
105 }
106 
107 #endif /* OMNI_RECENTSESSIONS_H_ */
RecentFileAction(QString const &_file, QObject *=nullptr)
Definition: RecentSessions.cpp:29
void readFromSettings()
Read recent files from settings.
Definition: RecentSessions.cpp:104
Data structure and menu to store default sessions.
Definition: RecentSessions.h:55
void generateMenu()
Generate menu from recent files, create new menu if necessary.
Definition: RecentSessions.cpp:140
std::deque< QString > recentFiles_
Definition: RecentSessions.h:99
void setState()
Action is disabled when file does not exist.
Definition: RecentSessions.cpp:48
std::vector< RecentFileAction * > actions_
Definition: RecentSessions.h:100
~RecentSessions()
Definition: RecentSessions.cpp:56
~RecentFileAction()
Definition: RecentSessions.cpp:37
void fileToBeLoaded(QString const &)
void loadSession()
Load session triggers fileToBeLoaded signal.
Definition: RecentSessions.cpp:39
void addFile(QString const &)
Add a new file to list.
Definition: RecentSessions.cpp:67
QUniquePtr< QMenu > menu_
Definition: RecentSessions.h:101
void writeToSettings() const
Write recent files to settings.
Definition: RecentSessions.cpp:117
bool fileExists() const
Check if file exists.
Definition: RecentSessions.cpp:44
void setNumberOfFiles(int)
Set maximum number of files.
Definition: RecentSessions.cpp:59
Action for recent file.
Definition: RecentSessions.h:31
int numberOfFiles_
Definition: RecentSessions.h:102
void clear()
Clear list of recent files.
Definition: RecentSessions.cpp:129
void fileToBeLoaded(QString const &)
int numberOfFiles() const
Return maximum number of files.
Definition: RecentSessions.cpp:63
QMenu * menu()
Return pointer to menu.
Definition: RecentSessions.cpp:100
void setActionStates()
Disable action for which file does not exists.
Definition: RecentSessions.cpp:134
int fileInList(QString const &) const
Return index of file if in list, return -1 if not.
Definition: RecentSessions.cpp:89
QString file_
Definition: RecentSessions.h:51
RecentSessions(QObject *=nullptr)
Definition: RecentSessions.cpp:52