LibrePCB Developers Documentation
controlpanel.h
Go to the documentation of this file.
1 /*
2  * LibrePCB - Professional EDA for everyone!
3  * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors.
4  * https://librepcb.org/
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef LIBREPCB_CONTROLPANEL_H
21 #define LIBREPCB_CONTROLPANEL_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
27 
28 #include <QtCore>
29 #include <QtWidgets>
30 
31 /*******************************************************************************
32  * Namespace / Forward Declarations
33  ******************************************************************************/
34 namespace librepcb {
35 
36 class FilePath;
37 
38 namespace library {
39 class Library;
40 
41 namespace editor {
42 class LibraryEditor;
43 }
44 
45 namespace manager {
46 class LibraryManager;
47 }
48 } // namespace library
49 
50 namespace project {
51 class Project;
52 
53 namespace editor {
54 class ProjectEditor;
55 }
56 } // namespace project
57 
58 namespace workspace {
59 class Workspace;
60 }
61 
62 namespace application {
63 
64 class ProjectLibraryUpdater;
65 
66 namespace Ui {
67 class ControlPanel;
68 }
69 
70 /*******************************************************************************
71  * Class ControlPanel
72  ******************************************************************************/
73 
77 class ControlPanel final : public QMainWindow {
78  Q_OBJECT
79 
80  friend class ProjectLibraryUpdater; // needs access to openProject() and
81  // getOpenProject()
82 
83 public:
84  // Constructors / Destructor
85  explicit ControlPanel(workspace::Workspace& workspace);
86  ~ControlPanel();
87 
88 public slots:
89 
90  void showControlPanel() noexcept;
91  void openProjectLibraryUpdater(const FilePath& project) noexcept;
92 
93 protected:
94  // Inherited Methods
95  virtual void closeEvent(QCloseEvent* event);
96 
97 private slots:
98 
99  // private slots
100  void openProjectsPassedByCommandLine() noexcept;
101  void projectEditorClosed() noexcept;
102 
103  // Actions
104  void on_actionNew_Project_triggered();
105  void on_actionOpen_Project_triggered();
106  void on_actionOpen_Library_Manager_triggered();
107  void on_actionClose_all_open_projects_triggered();
108  void on_actionSwitch_Workspace_triggered();
109  void on_actionWorkspace_Settings_triggered();
110  void on_projectTreeView_clicked(const QModelIndex& index);
111  void on_projectTreeView_doubleClicked(const QModelIndex& index);
112  void on_projectTreeView_customContextMenuRequested(const QPoint& pos);
113  void on_recentProjectsListView_entered(const QModelIndex& index);
114  void on_favoriteProjectsListView_entered(const QModelIndex& index);
115  void on_recentProjectsListView_clicked(const QModelIndex& index);
116  void on_favoriteProjectsListView_clicked(const QModelIndex& index);
117  void on_recentProjectsListView_customContextMenuRequested(const QPoint& pos);
118  void on_favoriteProjectsListView_customContextMenuRequested(
119  const QPoint& pos);
120  void on_actionRescanLibraries_triggered();
121 
122 private:
123  // make some methods inaccessible...
124  ControlPanel();
125  ControlPanel(const ControlPanel& other);
126  ControlPanel& operator=(const ControlPanel& rhs);
127 
128  // General private methods
129  void saveSettings();
130  void loadSettings();
131  void updateNoLibrariesWarningVisibility() noexcept;
132  void showProjectReadmeInBrowser(const FilePath& projectFilePath) noexcept;
133 
134  // Project Management
135 
136  project::editor::ProjectEditor* newProject(
137  const FilePath& parentDir) noexcept;
138 
147  project::editor::ProjectEditor* openProject(
148  project::Project& project) noexcept;
149 
158  project::editor::ProjectEditor* openProject(
159  const FilePath& filepath) noexcept;
160 
169  bool closeProject(project::editor::ProjectEditor& editor,
170  bool askForSave) noexcept;
171 
180  bool closeProject(const FilePath& filepath, bool askForSave) noexcept;
181 
190  bool closeAllProjects(bool askForSave) noexcept;
191 
204  project::editor::ProjectEditor* getOpenProject(const FilePath& filepath) const
205  noexcept;
206 
217  static bool askForRestoringBackup(const FilePath& dir);
218 
219  // Library Management
220  void openLibraryEditor(const FilePath& libDir) noexcept;
221  void libraryEditorDestroyed() noexcept;
222 
231  bool closeAllLibraryEditors(bool askForSave) noexcept;
232 
233  // Attributes
234  workspace::Workspace& mWorkspace;
235  QScopedPointer<Ui::ControlPanel> mUi;
236  QScopedPointer<library::manager::LibraryManager> mLibraryManager;
237  QHash<QString, project::editor::ProjectEditor*> mOpenProjectEditors;
238  QHash<FilePath, library::editor::LibraryEditor*> mOpenLibraryEditors;
239  QScopedPointer<ProjectLibraryUpdater> mProjectLibraryUpdater;
240 };
241 
242 /*******************************************************************************
243  * End of File
244  ******************************************************************************/
245 
246 } // namespace application
247 } // namespace librepcb
248 
249 #endif // LIBREPCB_CONTROLPANEL_H
The Workspace class represents a workspace with all its data (library, projects, settings, ...)
Definition: workspace.h:62
The ProjectLibraryUpdater class.
Definition: projectlibraryupdater.h:65
Definition: mainwindow.h:10
The LibraryManager class.
Definition: librarymanager.h:60
Definition: airwiresbuilder.cpp:32
The ControlPanel class.
Definition: controlpanel.h:77
The Project class represents a whole (opened) project with all its content.
Definition: project.h:80
The ProjectEditor class.
Definition: projecteditor.h:63
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:127