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 
80 class ControlPanel final : public QMainWindow {
81  Q_OBJECT
82 
83  friend class ProjectLibraryUpdater; // needs access to openProject() and
84  // getOpenProject()
85 
86 public:
87  // Constructors / Destructor
88  explicit ControlPanel(workspace::Workspace& workspace);
89  ~ControlPanel();
90 
91 public slots:
92 
93  void showControlPanel() noexcept;
94  void openProjectLibraryUpdater(const FilePath& project) noexcept;
95 
96 protected:
97  // Inherited Methods
98  virtual void closeEvent(QCloseEvent* event);
99 
100 private slots:
101 
102  // private slots
103  void openProjectsPassedByCommandLine() noexcept;
104  void projectEditorClosed() noexcept;
105 
106  // Actions
112  void on_projectTreeView_clicked(const QModelIndex& index);
113  void on_projectTreeView_doubleClicked(const QModelIndex& index);
114  void on_projectTreeView_customContextMenuRequested(const QPoint& pos);
115  void on_recentProjectsListView_entered(const QModelIndex& index);
116  void on_favoriteProjectsListView_entered(const QModelIndex& index);
117  void on_recentProjectsListView_clicked(const QModelIndex& index);
118  void on_favoriteProjectsListView_clicked(const QModelIndex& index);
121  const QPoint& pos);
123 
124 private:
125  // make some methods inaccessible...
126  ControlPanel();
127  ControlPanel(const ControlPanel& other);
128  ControlPanel& operator=(const ControlPanel& rhs);
129 
130  // General private methods
131  void saveSettings();
132  void loadSettings();
133  void updateNoLibrariesWarningVisibility() noexcept;
134  void showProjectReadmeInBrowser(const FilePath& projectFilePath) noexcept;
135 
136  // Project Management
137 
138  project::editor::ProjectEditor* newProject(
139  const FilePath& parentDir) noexcept;
140 
149  project::editor::ProjectEditor* openProject(
150  project::Project& project) noexcept;
151 
160  project::editor::ProjectEditor* openProject(
161  const FilePath& filepath) noexcept;
162 
171  bool closeProject(project::editor::ProjectEditor& editor,
172  bool askForSave) noexcept;
173 
182  bool closeProject(const FilePath& filepath, bool askForSave) noexcept;
183 
192  bool closeAllProjects(bool askForSave) noexcept;
193 
206  project::editor::ProjectEditor* getOpenProject(const FilePath& filepath) const
207  noexcept;
208 
209  // Library Management
210  void openLibraryEditor(const FilePath& libDir) noexcept;
211  void libraryEditorDestroyed() noexcept;
212 
221  bool closeAllLibraryEditors(bool askForSave) noexcept;
222 
223  // Attributes
224  workspace::Workspace& mWorkspace;
225  QScopedPointer<Ui::ControlPanel> mUi;
226  QScopedPointer<library::manager::LibraryManager> mLibraryManager;
227  QHash<QString, project::editor::ProjectEditor*> mOpenProjectEditors;
228  QHash<FilePath, library::editor::LibraryEditor*> mOpenLibraryEditors;
230 };
231 
232 /*******************************************************************************
233  * End of File
234  ******************************************************************************/
235 
236 } // namespace application
237 } // namespace librepcb
238 
239 #endif // LIBREPCB_CONTROLPANEL_H
project::editor::ProjectEditor * newProject(const FilePath &parentDir) noexcept
Definition: controlpanel.cpp:275
void on_recentProjectsListView_entered(const QModelIndex &index)
Definition: controlpanel.cpp:654
The Workspace class represents a workspace with all its data (library, projects, settings, ...)
Definition: workspace.h:65
void libraryEditorDestroyed() noexcept
Definition: controlpanel.cpp:412
void projectEditorClosed() noexcept
Definition: controlpanel.cpp:452
QScopedPointer< library::manager::LibraryManager > mLibraryManager
Definition: controlpanel.h:226
The ProjectLibraryUpdater class.
Definition: projectlibraryupdater.h:65
workspace::Workspace & mWorkspace
Definition: controlpanel.h:224
void saveSettings()
Definition: controlpanel.cpp:195
The LibraryManager class.
Definition: librarymanager.h:63
The ControlPanel class.
Definition: controlpanel.h:80
void on_recentProjectsListView_customContextMenuRequested(const QPoint &pos)
Definition: controlpanel.cpp:676
QScopedPointer< Ui::ControlPanel > mUi
Definition: controlpanel.h:225
The Project class represents a whole (opened) project with all its content.
Definition: project.h:82
~ControlPanel()
Definition: controlpanel.cpp:149
bool closeAllLibraryEditors(bool askForSave) noexcept
Close all open library editors.
Definition: controlpanel.cpp:425
The ProjectEditor class.
Definition: projecteditor.h:65
void on_actionSwitch_Workspace_triggered()
Definition: controlpanel.cpp:499
void on_projectTreeView_customContextMenuRequested(const QPoint &pos)
Definition: controlpanel.cpp:530
void on_actionClose_all_open_projects_triggered()
Definition: controlpanel.cpp:495
QHash< FilePath, library::editor::LibraryEditor * > mOpenLibraryEditors
Definition: controlpanel.h:228
virtual void closeEvent(QCloseEvent *event)
Definition: controlpanel.cpp:157
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:289
void on_actionRescanLibrary_triggered()
Definition: controlpanel.cpp:732
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:378
void showControlPanel() noexcept
Definition: controlpanel.cpp:179
void openProjectLibraryUpdater(const FilePath &project) noexcept
Definition: controlpanel.cpp:185
void on_favoriteProjectsListView_customContextMenuRequested(const QPoint &pos)
Definition: controlpanel.cpp:710
void updateNoLibrariesWarningVisibility() noexcept
Definition: controlpanel.cpp:249
bool closeAllProjects(bool askForSave) noexcept
Close all open project editors.
Definition: controlpanel.cpp:370
void on_actionOpen_Library_Manager_triggered()
Definition: controlpanel.cpp:488
void openProjectsPassedByCommandLine() noexcept
Definition: controlpanel.cpp:442
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:130
void on_actionNew_Project_triggered()
Definition: controlpanel.cpp:466
QHash< QString, project::editor::ProjectEditor * > mOpenProjectEditors
Definition: controlpanel.h:227
bool closeProject(project::editor::ProjectEditor &editor, bool askForSave) noexcept
Close an opened project editor.
Definition: controlpanel.cpp:347
void on_recentProjectsListView_clicked(const QModelIndex &index)
Definition: controlpanel.cpp:665
void on_favoriteProjectsListView_entered(const QModelIndex &index)
Definition: controlpanel.cpp:659
void loadSettings()
Definition: controlpanel.cpp:222
void openLibraryEditor(const FilePath &libDir) noexcept
Definition: controlpanel.cpp:390
void on_projectTreeView_clicked(const QModelIndex &index)
Definition: controlpanel.cpp:509
QScopedPointer< ProjectLibraryUpdater > mProjectLibraryUpdater
Definition: controlpanel.h:229
void showProjectReadmeInBrowser(const FilePath &projectFilePath) noexcept
Definition: controlpanel.cpp:259
void on_projectTreeView_doubleClicked(const QModelIndex &index)
Definition: controlpanel.cpp:518
void on_favoriteProjectsListView_clicked(const QModelIndex &index)
Definition: controlpanel.cpp:670
void on_actionOpen_Project_triggered()
Definition: controlpanel.cpp:470