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 WindowTab;
48
49/*******************************************************************************
50 * Class WindowSection
51 ******************************************************************************/
52
56class WindowSection final : public QObject {
57 Q_OBJECT
58
59public:
60 // Signals
62
63 // Constructors / Destructor
64 WindowSection() = delete;
65 WindowSection(const WindowSection& other) = delete;
66 explicit WindowSection(GuiApplication& app,
67 QObject* parent = nullptr) noexcept;
68 ~WindowSection() noexcept;
69
70 // General Methods
71 const ui::WindowSectionData& getUiData() const noexcept { return mUiData; }
72 void setUiData(const ui::WindowSectionData& data) noexcept;
73 void setHomeTabVisible(bool visible) noexcept;
74 void addTab(std::shared_ptr<WindowTab> tab, int index = -1) noexcept;
75 std::shared_ptr<WindowTab> removeTab(int index) noexcept;
76 void triggerTab(int index, ui::TabAction a) noexcept;
77 slint::Image renderScene(float width, float height, int scene) noexcept;
78 bool processScenePointerEvent(const QPointF& pos,
79 slint::private_api::PointerEvent e) noexcept;
80 bool processSceneScrolled(const QPointF& pos,
81 slint::private_api::PointerScrollEvent e) noexcept;
82 bool processSceneKeyEvent(const slint::private_api::KeyEvent& e) noexcept;
83
84 template <typename T>
85 bool switchToTab() noexcept {
86 for (int i = 0; i < mTabs->count(); ++i) {
87 if (std::dynamic_pointer_cast<T>(mTabs->value(i))) {
89 highlight();
90 return true;
91 }
92 }
93 return false;
94 }
95
96 template <typename T>
97 bool switchToLibraryElementTab(const FilePath& fp) noexcept {
98 for (int i = 0; i < mTabs->count(); ++i) {
99 if (auto tab = std::dynamic_pointer_cast<T>(mTabs->at(i))) {
100 if (tab->getDirectoryPath() == fp) {
101 setCurrentTab(i);
102 highlight();
103 return true;
104 }
105 }
106 }
107 return false;
108 }
109
110 template <typename T>
111 bool switchToProjectTab(int prjIndex, int objIndex) noexcept {
112 for (int i = 0; i < mTabs->count(); ++i) {
113 if (auto tab = std::dynamic_pointer_cast<T>(mTabs->at(i))) {
114 if ((tab->getProjectIndex() == prjIndex) &&
115 (tab->getProjectObjectIndex() == objIndex)) {
116 setCurrentTab(i);
117 highlight();
118 return true;
119 }
120 }
121 }
122 return false;
123 }
124
137 bool requestCloseAllTabs() noexcept;
138
139 // Operator Overloadings
140 WindowSection& operator=(const WindowSection& rhs) = delete;
141
142signals:
144 void panelPageRequested(ui::PanelPage p);
145 void derivedUiDataChanged(std::size_t index);
146 void statusBarMessageChanged(const QString& message, int timeoutMs);
147 void cursorCoordinatesChanged(const Point& pos, const LengthUnit& unit);
148
149private:
150 void setCurrentTab(int index, bool forceUpdate = false) noexcept;
151 std::shared_ptr<WindowTab> getCurrentTab() noexcept;
152 void highlight() noexcept;
153 void tabCloseRequested() noexcept;
154
155 typedef UiObjectList<WindowTab, ui::TabData> TabList;
156
158 std::shared_ptr<TabList> mTabs;
159 ui::WindowSectionData mUiData;
160};
161
162/*******************************************************************************
163 * End of File
164 ******************************************************************************/
165
166} // namespace editor
167} // namespace librepcb
168
169#endif
This class represents absolute, well-formatted paths to files or directories.
Definition filepath.h:127
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:61
The UiObjectList class.
Definition uiobjectlist.h:47
The WindowSection class.
Definition windowsection.h:56
void highlight() noexcept
Definition windowsection.cpp:228
slint::Image renderScene(float width, float height, int scene) noexcept
Definition windowsection.cpp:160
void derivedUiDataChanged(std::size_t index)
UiObjectList< WindowTab, ui::TabData > TabList
Definition windowsection.h:155
std::shared_ptr< WindowTab > getCurrentTab() noexcept
Definition windowsection.cpp:224
void setCurrentTab(int index, bool forceUpdate=false) noexcept
Definition windowsection.cpp:205
bool switchToLibraryElementTab(const FilePath &fp) noexcept
Definition windowsection.h:97
void cursorCoordinatesChanged(const Point &pos, const LengthUnit &unit)
void setHomeTabVisible(bool visible) noexcept
Definition windowsection.cpp:96
bool processSceneKeyEvent(const slint::private_api::KeyEvent &e) noexcept
Definition windowsection.cpp:184
void addTab(std::shared_ptr< WindowTab > tab, int index=-1) noexcept
Definition windowsection.cpp:106
bool requestCloseAllTabs() noexcept
Request to close all tabs.
Definition windowsection.cpp:192
ui::WindowSectionData mUiData
Definition windowsection.h:159
void statusBarMessageChanged(const QString &message, int timeoutMs)
bool switchToProjectTab(int prjIndex, int objIndex) noexcept
Definition windowsection.h:111
bool processSceneScrolled(const QPointF &pos, slint::private_api::PointerScrollEvent e) noexcept
Definition windowsection.cpp:176
void tabCloseRequested() noexcept
Definition windowsection.cpp:238
void triggerTab(int index, ui::TabAction a) noexcept
Definition windowsection.cpp:154
std::shared_ptr< WindowTab > removeTab(int index) noexcept
Definition windowsection.cpp:130
void panelPageRequested(ui::PanelPage p)
void setUiData(const ui::WindowSectionData &data) noexcept
Definition windowsection.cpp:92
const ui::WindowSectionData & getUiData() const noexcept
Definition windowsection.h:71
bool processScenePointerEvent(const QPointF &pos, slint::private_api::PointerEvent e) noexcept
Definition windowsection.cpp:168
bool switchToTab() noexcept
Definition windowsection.h:85
Signal< WindowSection > onUiDataChanged
Definition windowsection.h:61
std::shared_ptr< TabList > mTabs
Definition windowsection.h:158
GuiApplication & mApp
Definition windowsection.h:157
WindowSection(const WindowSection &other)=delete
The WindowTab class.
Definition windowtab.h:51
Definition occmodel.cpp:77
Definition uuid.h:186