LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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
109  void on_projectTreeView_clicked(const QModelIndex& index);
110  void on_projectTreeView_doubleClicked(const QModelIndex& index);
111  void on_projectTreeView_customContextMenuRequested(const QPoint& pos);
112  void on_recentProjectsListView_entered(const QModelIndex& index);
113  void on_favoriteProjectsListView_entered(const QModelIndex& index);
114  void on_recentProjectsListView_clicked(const QModelIndex& index);
115  void on_favoriteProjectsListView_clicked(const QModelIndex& index);
118  const QPoint& pos);
120 
121 private:
122  // make some methods inaccessible...
123  ControlPanel();
124  ControlPanel(const ControlPanel& other);
125  ControlPanel& operator=(const ControlPanel& rhs);
126 
127  // General private methods
128  void saveSettings();
129  void loadSettings();
130  void updateNoLibrariesWarningVisibility() noexcept;
131  void showProjectReadmeInBrowser(const FilePath& projectFilePath) noexcept;
132 
133  // Project Management
134 
135  project::editor::ProjectEditor* newProject(
136  const FilePath& parentDir) noexcept;
137 
146  project::editor::ProjectEditor* openProject(
147  project::Project& project) noexcept;
148 
157  project::editor::ProjectEditor* openProject(
158  const FilePath& filepath) noexcept;
159 
168  bool closeProject(project::editor::ProjectEditor& editor,
169  bool askForSave) noexcept;
170 
179  bool closeProject(const FilePath& filepath, bool askForSave) noexcept;
180 
189  bool closeAllProjects(bool askForSave) noexcept;
190 
203  project::editor::ProjectEditor* getOpenProject(const FilePath& filepath) const
204  noexcept;
205 
206  // Library Management
207  void openLibraryEditor(const FilePath& libDir) noexcept;
208  void libraryEditorDestroyed() noexcept;
209 
218  bool closeAllLibraryEditors(bool askForSave) noexcept;
219 
220  // Attributes
221  workspace::Workspace& mWorkspace;
222  QScopedPointer<Ui::ControlPanel> mUi;
223  QScopedPointer<library::manager::LibraryManager> mLibraryManager;
224  QHash<QString, project::editor::ProjectEditor*> mOpenProjectEditors;
225  QHash<FilePath, library::editor::LibraryEditor*> mOpenLibraryEditors;
227 };
228 
229 /*******************************************************************************
230  * End of File
231  ******************************************************************************/
232 
233 } // namespace application
234 } // namespace librepcb
235 
236 #endif // LIBREPCB_CONTROLPANEL_H
project::editor::ProjectEditor * newProject(const FilePath &parentDir) noexcept
Definition: controlpanel.cpp:271
void on_recentProjectsListView_entered(const QModelIndex &index)
Definition: controlpanel.cpp:652
The Workspace class represents a workspace with all its data (library, projects, settings, ...)
Definition: workspace.h:62
void libraryEditorDestroyed() noexcept
Definition: controlpanel.cpp:408
void projectEditorClosed() noexcept
Definition: controlpanel.cpp:448
QScopedPointer< library::manager::LibraryManager > mLibraryManager
Definition: controlpanel.h:223
The ProjectLibraryUpdater class.
Definition: projectlibraryupdater.h:65
workspace::Workspace & mWorkspace
Definition: controlpanel.h:221
void saveSettings()
Definition: controlpanel.cpp:191
The LibraryManager class.
Definition: librarymanager.h:60
The ControlPanel class.
Definition: controlpanel.h:77
void on_recentProjectsListView_customContextMenuRequested(const QPoint &pos)
Definition: controlpanel.cpp:674
QScopedPointer< Ui::ControlPanel > mUi
Definition: controlpanel.h:222
The Project class represents a whole (opened) project with all its content.
Definition: project.h:79
~ControlPanel()
Definition: controlpanel.cpp:145
bool closeAllLibraryEditors(bool askForSave) noexcept
Close all open library editors.
Definition: controlpanel.cpp:421
The ProjectEditor class.
Definition: projecteditor.h:62
void on_actionSwitch_Workspace_triggered()
Definition: controlpanel.cpp:497
void on_projectTreeView_customContextMenuRequested(const QPoint &pos)
Definition: controlpanel.cpp:528
void on_actionClose_all_open_projects_triggered()
Definition: controlpanel.cpp:493
QHash< FilePath, library::editor::LibraryEditor * > mOpenLibraryEditors
Definition: controlpanel.h:225
virtual void closeEvent(QCloseEvent *event)
Definition: controlpanel.cpp:153
project::editor::ProjectEditor * openProject(project::Project &project) noexcept
Open a project with the editor (or bring an already opened editor to front)
Definition: controlpanel.cpp:285
void on_actionRescanLibrary_triggered()
Definition: controlpanel.cpp:730
project::editor::ProjectEditor * getOpenProject(const FilePath &filepath) const noexcept
Get the pointer to an already open project editor by its project filepath.
Definition: controlpanel.cpp:374
void showControlPanel() noexcept
Definition: controlpanel.cpp:175
void openProjectLibraryUpdater(const FilePath &project) noexcept
Definition: controlpanel.cpp:181
void on_favoriteProjectsListView_customContextMenuRequested(const QPoint &pos)
Definition: controlpanel.cpp:708
void updateNoLibrariesWarningVisibility() noexcept
Definition: controlpanel.cpp:245
bool closeAllProjects(bool askForSave) noexcept
Close all open project editors.
Definition: controlpanel.cpp:366
void on_actionOpen_Library_Manager_triggered()
Definition: controlpanel.cpp:486
void openProjectsPassedByCommandLine() noexcept
Definition: controlpanel.cpp:438
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:127
void on_actionNew_Project_triggered()
Definition: controlpanel.cpp:464
QHash< QString, project::editor::ProjectEditor * > mOpenProjectEditors
Definition: controlpanel.h:224
bool closeProject(project::editor::ProjectEditor &editor, bool askForSave) noexcept
Close an opened project editor.
Definition: controlpanel.cpp:343
void on_recentProjectsListView_clicked(const QModelIndex &index)
Definition: controlpanel.cpp:663
void on_favoriteProjectsListView_entered(const QModelIndex &index)
Definition: controlpanel.cpp:657
void loadSettings()
Definition: controlpanel.cpp:218
void openLibraryEditor(const FilePath &libDir) noexcept
Definition: controlpanel.cpp:386
void on_projectTreeView_clicked(const QModelIndex &index)
Definition: controlpanel.cpp:507
QScopedPointer< ProjectLibraryUpdater > mProjectLibraryUpdater
Definition: controlpanel.h:226
void showProjectReadmeInBrowser(const FilePath &projectFilePath) noexcept
Definition: controlpanel.cpp:255
void on_projectTreeView_doubleClicked(const QModelIndex &index)
Definition: controlpanel.cpp:516
void on_favoriteProjectsListView_clicked(const QModelIndex &index)
Definition: controlpanel.cpp:668
void on_actionOpen_Project_triggered()
Definition: controlpanel.cpp:468