LibrePCB Developers Documentation
Loading...
Searching...
No Matches
windowsection.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_WINDOWSECTION_H
21#define LIBREPCB_EDITOR_WINDOWSECTION_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
26#include "appwindow.h"
27#include "utils/uiobjectlist.h"
28
30
31#include <QtCore>
32
33#include <memory>
34
35/*******************************************************************************
36 * Namespace / Forward Declarations
37 ******************************************************************************/
38namespace librepcb {
39
40class FilePath;
41class LengthUnit;
42class Point;
43
44namespace editor {
45
46class GuiApplication;
47class MainWindow;
48class WindowTab;
49
50/*******************************************************************************
51 * Class WindowSection
52 ******************************************************************************/
53
57class WindowSection final : public QObject {
58 Q_OBJECT
59
60public:
61 // Signals
63
64 // Constructors / Destructor
65 WindowSection() = delete;
66 WindowSection(const WindowSection& other) = delete;
67 explicit WindowSection(GuiApplication& app, MainWindow& win,
68 QObject* parent = nullptr) noexcept;
69 ~WindowSection() noexcept;
70
71 // General Methods
72 const ui::WindowSectionData& getUiData() const noexcept { return mUiData; }
73 void setUiData(const ui::WindowSectionData& data) noexcept;
74 void setHomeTabVisible(bool visible) noexcept;
75 void addTab(std::shared_ptr<WindowTab> tab, int index = -1,
76 bool switchToTab = true) noexcept;
77 std::shared_ptr<WindowTab> removeTab(int index,
78 bool* wasCurrent = nullptr) noexcept;
79 void triggerTab(int index, ui::TabAction a) noexcept;
80 slint::Image renderScene(float width, float height, int scene) noexcept;
81 bool processScenePointerEvent(const QPointF& pos,
82 slint::private_api::PointerEvent e) noexcept;
83 bool processSceneScrolled(const QPointF& pos,
84 slint::private_api::PointerScrollEvent e) noexcept;
85 bool processSceneKeyEvent(const slint::private_api::KeyEvent& e) noexcept;
86
87 template <typename T>
88 bool switchToTab() noexcept {
89 for (int i = 0; i < mTabs->count(); ++i) {
90 if (std::dynamic_pointer_cast<T>(mTabs->value(i))) {
92 highlight();
93 return true;
94 }
95 }
96 return false;
97 }
98
99 template <typename T>
100 bool switchToLibraryElementTab(const FilePath& fp) noexcept {
101 for (int i = 0; i < mTabs->count(); ++i) {
102 if (auto tab = std::dynamic_pointer_cast<T>(mTabs->at(i))) {
103 if (tab->getDirectoryPath() == fp) {
104 setCurrentTab(i);
105 highlight();
106 return true;
107 }
108 }
109 }
110 return false;
111 }
112
113 template <typename T>
114 std::shared_ptr<T> switchToProjectTab(int prjIndex, int objIndex) noexcept {
115 for (int i = 0; i < mTabs->count(); ++i) {
116 if (auto tab = std::dynamic_pointer_cast<T>(mTabs->at(i))) {
117 if ((tab->getProjectIndex() == prjIndex) &&
118 (tab->getProjectObjectIndex() == objIndex)) {
119 setCurrentTab(i);
120 highlight();
121 return tab;
122 }
123 }
124 }
125 return nullptr;
126 }
127
140 bool requestCloseAllTabs() noexcept;
141
142 // Operator Overloadings
143 WindowSection& operator=(const WindowSection& rhs) = delete;
144
145signals:
147 void panelPageRequested(ui::PanelPage p);
148 void derivedUiDataChanged(std::size_t index);
149 void statusBarMessageChanged(const QString& message, int timeoutMs);
150 void cursorCoordinatesChanged(const Point& pos, const LengthUnit& unit);
151
152private:
153 void setCurrentTab(int index, bool forceUpdate = false) noexcept;
154 std::shared_ptr<WindowTab> getCurrentTab() noexcept;
155 void highlight() noexcept;
156 void tabCloseRequested() noexcept;
157
158 typedef UiObjectList<WindowTab, ui::TabData> TabList;
159
162 std::shared_ptr<TabList> mTabs;
163 ui::WindowSectionData mUiData;
164};
165
166/*******************************************************************************
167 * End of File
168 ******************************************************************************/
169
170} // namespace editor
171} // namespace librepcb
172
173#endif
This class represents absolute, well-formatted paths to files or directories.
Definition filepath.h:127
The Image class.
Definition image.h:49
The LengthUnit class represents a length unit (millimeters, inches,...) and provides some useful meth...
Definition lengthunit.h:62
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5....
Definition point.h:78
The Signal class is used to emit signals on non-QObject derived classes.
Definition signalslot.h:65
The GuiApplication class.
Definition guiapplication.h:75
The MainWindow class.
Definition mainwindow.h:59
The UiObjectList class.
Definition uiobjectlist.h:47
The WindowSection class.
Definition windowsection.h:57
void highlight() noexcept
Definition windowsection.cpp:261
slint::Image renderScene(float width, float height, int scene) noexcept
Definition windowsection.cpp:193
void derivedUiDataChanged(std::size_t index)
UiObjectList< WindowTab, ui::TabData > TabList
Definition windowsection.h:158
std::shared_ptr< WindowTab > getCurrentTab() noexcept
Definition windowsection.cpp:257
void setCurrentTab(int index, bool forceUpdate=false) noexcept
Definition windowsection.cpp:238
bool switchToLibraryElementTab(const FilePath &fp) noexcept
Definition windowsection.h:100
std::shared_ptr< T > switchToProjectTab(int prjIndex, int objIndex) noexcept
Definition windowsection.h:114
void cursorCoordinatesChanged(const Point &pos, const LengthUnit &unit)
void setHomeTabVisible(bool visible) noexcept
Definition windowsection.cpp:112
bool processSceneKeyEvent(const slint::private_api::KeyEvent &e) noexcept
Definition windowsection.cpp:217
bool requestCloseAllTabs() noexcept
Request to close all tabs.
Definition windowsection.cpp:225
ui::WindowSectionData mUiData
Definition windowsection.h:163
void statusBarMessageChanged(const QString &message, int timeoutMs)
std::shared_ptr< WindowTab > removeTab(int index, bool *wasCurrent=nullptr) noexcept
Definition windowsection.cpp:153
bool processSceneScrolled(const QPointF &pos, slint::private_api::PointerScrollEvent e) noexcept
Definition windowsection.cpp:209
void tabCloseRequested() noexcept
Definition windowsection.cpp:271
void triggerTab(int index, ui::TabAction a) noexcept
Definition windowsection.cpp:184
MainWindow & mWindow
Definition windowsection.h:161
void panelPageRequested(ui::PanelPage p)
void setUiData(const ui::WindowSectionData &data) noexcept
Definition windowsection.cpp:108
const ui::WindowSectionData & getUiData() const noexcept
Definition windowsection.h:72
bool processScenePointerEvent(const QPointF &pos, slint::private_api::PointerEvent e) noexcept
Definition windowsection.cpp:201
bool switchToTab() noexcept
Definition windowsection.h:88
Signal< WindowSection > onUiDataChanged
Definition windowsection.h:62
void addTab(std::shared_ptr< WindowTab > tab, int index=-1, bool switchToTab=true) noexcept
Definition windowsection.cpp:122
std::shared_ptr< TabList > mTabs
Definition windowsection.h:162
GuiApplication & mApp
Definition windowsection.h:160
WindowSection(const WindowSection &other)=delete
The WindowTab class.
Definition windowtab.h:52
Definition occmodel.cpp:77
Definition uuid.h:186