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_EDITOR_CONTROLPANEL_H
21 #define LIBREPCB_EDITOR_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 class Library;
38 class Project;
39 class Workspace;
40 
41 namespace editor {
42 
43 class FavoriteProjectsModel;
44 class LibraryEditor;
45 class LibraryManager;
46 class ProjectEditor;
47 class ProjectLibraryUpdater;
48 class ProjectTreeModel;
49 class RecentProjectsModel;
50 class StandardEditorCommandHandler;
51 
52 namespace Ui {
53 class ControlPanel;
54 }
55 
56 /*******************************************************************************
57  * Class ControlPanel
58  ******************************************************************************/
59 
63 class ControlPanel final : public QMainWindow {
64  Q_OBJECT
65 
66  // ProjectLibraryUpdater needs access to openProject() and getOpenProject()
67  friend class ProjectLibraryUpdater;
68 
69 public:
70  // Constructors / Destructor
71  ControlPanel() = delete;
72  ControlPanel(const ControlPanel& other) = delete;
73  explicit ControlPanel(Workspace& workspace, bool fileFormatIsOutdated);
74  virtual ~ControlPanel() noexcept;
75 
76  // Operator Overloadings
77  ControlPanel& operator=(const ControlPanel& rhs) = delete;
78 
79 public slots:
80  void showControlPanel() noexcept;
81  void openProjectLibraryUpdater(const FilePath& project) noexcept;
82 
83 protected:
84  // Inherited Methods
85  virtual void closeEvent(QCloseEvent* event) override;
86  virtual bool eventFilter(QObject* watched, QEvent* event) override;
87 
88 private slots:
89  // private slots
90  void openProjectsPassedByCommandLine() noexcept;
91  void openProjectPassedByOs(const QString& file, bool silent = false) noexcept;
92  void projectEditorClosed() noexcept;
93 
94  // Actions
95  void on_projectTreeView_clicked(const QModelIndex& index);
96  void on_projectTreeView_doubleClicked(const QModelIndex& index);
97  void on_projectTreeView_customContextMenuRequested(const QPoint& pos);
98  void on_recentProjectsListView_entered(const QModelIndex& index);
99  void on_favoriteProjectsListView_entered(const QModelIndex& index);
100  void on_recentProjectsListView_clicked(const QModelIndex& index);
101  void on_favoriteProjectsListView_clicked(const QModelIndex& index);
102  void on_recentProjectsListView_customContextMenuRequested(const QPoint& pos);
103  void on_favoriteProjectsListView_customContextMenuRequested(
104  const QPoint& pos);
105 
106 private:
107  // General private methods
108  void createActions() noexcept;
109  void createMenus() noexcept;
110  void saveSettings();
111  void loadSettings();
112  void updateDesktopIntegrationMessage() noexcept;
113  void openLibraryManager() noexcept;
114  void addExampleProjects() noexcept;
115  void switchWorkspace() noexcept;
116  void showProjectReadmeInBrowser(const FilePath& projectFilePath) noexcept;
117  void removeProjectsTreeItem(const FilePath& fp) noexcept;
118 
119  // Project Management
120 
121  ProjectEditor* newProject(bool eagleImport = false,
122  FilePath parentDir = FilePath()) noexcept;
123 
133  ProjectEditor* openProject(FilePath filepath = FilePath()) noexcept;
134 
143  bool closeProject(ProjectEditor& editor, bool askForSave) noexcept;
144 
153  bool closeProject(const FilePath& filepath, bool askForSave) noexcept;
154 
163  bool closeAllProjects(bool askForSave) noexcept;
164 
177  ProjectEditor* getOpenProject(const FilePath& filepath) const noexcept;
178 
189  static bool askForRestoringBackup(const FilePath& dir);
190 
191  // Library Management
192  void openLibraryEditor(const FilePath& libDir) noexcept;
193  void libraryEditorDestroyed() noexcept;
194 
203  bool closeAllLibraryEditors(bool askForSave) noexcept;
204 
205  // Attributes
206  Workspace& mWorkspace;
207  QScopedPointer<Ui::ControlPanel> mUi;
208  QScopedPointer<StandardEditorCommandHandler> mStandardCommandHandler;
209  QScopedPointer<ProjectTreeModel> mProjectTreeModel;
210  QScopedPointer<RecentProjectsModel> mRecentProjectsModel;
211  QScopedPointer<FavoriteProjectsModel> mFavoriteProjectsModel;
212  QScopedPointer<LibraryManager> mLibraryManager;
213  QHash<QString, ProjectEditor*> mOpenProjectEditors;
214  QHash<FilePath, LibraryEditor*> mOpenLibraryEditors;
215  QScopedPointer<ProjectLibraryUpdater> mProjectLibraryUpdater;
216 
217  // Actions
218  QScopedPointer<QAction> mActionLibraryManager;
219  QScopedPointer<QAction> mActionWorkspaceSettings;
220  QScopedPointer<QAction> mActionRescanLibraries;
221  QScopedPointer<QAction> mActionSwitchWorkspace;
222  QScopedPointer<QAction> mActionNewProject;
223  QScopedPointer<QAction> mActionOpenProject;
224  QScopedPointer<QAction> mActionCloseAllProjects;
225  QScopedPointer<QAction> mActionAddExampleProjects;
226  QScopedPointer<QAction> mActionImportEagleProject;
227  QScopedPointer<QAction> mActionAboutLibrePcb;
228  QScopedPointer<QAction> mActionAboutQt;
229  QScopedPointer<QAction> mActionOnlineDocumentation;
230  QScopedPointer<QAction> mActionKeyboardShortcutsReference;
231  QScopedPointer<QAction> mActionWebsite;
232  QScopedPointer<QAction> mActionQtQuickTest;
233  QScopedPointer<QAction> mActionQuit;
234 };
235 
236 /*******************************************************************************
237  * End of File
238  ******************************************************************************/
239 
240 } // namespace editor
241 } // namespace librepcb
242 
243 #endif
The ProjectEditor class.
Definition: projecteditor.h:62
Definition: occmodel.cpp:77
The ProjectTreeModel class.
Definition: projecttreemodel.h:45
The FavoriteProjectsModel class.
Definition: favoriteprojectsmodel.h:47
The RecentProjectsModel class.
Definition: recentprojectsmodel.h:47
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:129
Helper to handle some of the librepcb::editor::EditorCommand actions.
Definition: standardeditorcommandhandler.h:48
The LibraryManager class.
Definition: librarymanager.h:55
The ControlPanel class.
Definition: controlpanel.h:63
The LibraryEditor class.
Definition: libraryeditor.h:65
The Workspace class represents a workspace with all its data (library, projects, settings, ...)
Definition: workspace.h:54
The ProjectLibraryUpdater class.
Definition: projectlibraryupdater.h:62