Line data Source code
1 : /*
2 : * SPDX-License-Identifier: GPL-3.0-only
3 : * MuseScore-CLA-applies
4 : *
5 : * MuseScore Studio
6 : * Music Composition & Notation
7 : *
8 : * Copyright (C) 2021 MuseScore Limited and others
9 : *
10 : * This program is free software: you can redistribute it and/or modify
11 : * it under the terms of the GNU General Public License version 3 as
12 : * published by the Free Software Foundation.
13 : *
14 : * This program is distributed in the hope that it will be useful,
15 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 : * GNU General Public License for more details.
18 : *
19 : * You should have received a copy of the GNU General Public License
20 : * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 : */
22 :
23 : #include "dockmodule.h"
24 :
25 : #include "rcommand/icommandsregister.h"
26 : #include "rcommand/icommandsstate.h"
27 :
28 : #include "internal/dropcontroller.h"
29 : #include "internal/dockseparator.h"
30 : #include "internal/docktabbar.h"
31 : #include "internal/docktitlebar.h"
32 : #include "internal/dockwindowactionscontroller.h"
33 : #include "internal/dockwindowprovider.h"
34 : #include "internal/dockcommandsregister.h"
35 : #include "internal/dockcommandsstate.h"
36 :
37 : #include "kddockwidgets/src/Config.h"
38 : #include "kddockwidgets/src/ContextData.h"
39 : #include "kddockwidgets/src/core/FloatingWindow.h"
40 : #include "kddockwidgets/src/qtquick/ViewFactory.h"
41 : #include "kddockwidgets/src/qtquick/Platform.h"
42 : #include "kddockwidgets/src/qtquick/QmlConfig.h"
43 : #include "kddockwidgets/src/qtquick/views/View.h"
44 :
45 : #include "modularity/ioc.h"
46 : #include "ui/iuiengine.h"
47 :
48 : #include "muse_framework_config.h"
49 :
50 : namespace muse::dock {
51 : class HiddenRubberBand : public KDDockWidgets::QtQuick::View
52 : {
53 : public:
54 0 : explicit HiddenRubberBand(QQuickItem* parent)
55 0 : : KDDockWidgets::QtQuick::View(nullptr, KDDockWidgets::Core::ViewType::RubberBand, parent)
56 : {
57 0 : KDDockWidgets::QtQuick::View::setVisible(false);
58 0 : }
59 :
60 0 : void setVisible(bool) override
61 : {
62 0 : KDDockWidgets::QtQuick::View::setVisible(false);
63 0 : }
64 : };
65 :
66 : class DockWidgetFactory : public KDDockWidgets::QtQuick::ViewFactory
67 : {
68 : public:
69 0 : explicit DockWidgetFactory(const modularity::ContextPtr& iocCtx)
70 0 : : KDDockWidgets::QtQuick::ViewFactory(iocCtx->id), m_iocContext(iocCtx) {}
71 :
72 : KDDockWidgets::Core::ClassicIndicatorWindowViewInterface*
73 0 : createClassicIndicatorWindow(KDDockWidgets::Core::ClassicDropIndicatorOverlay* classicIndicators,
74 : KDDockWidgets::Core::View* parent = nullptr) const override
75 : {
76 0 : return new DropController(classicIndicators, parent, m_iocContext);
77 : }
78 :
79 0 : KDDockWidgets::Core::View* createRubberBand(KDDockWidgets::Core::View* parent) const override
80 : {
81 0 : return new HiddenRubberBand(KDDockWidgets::QtQuick::asQQuickItem(parent));
82 : }
83 :
84 0 : KDDockWidgets::Core::View* createSeparator(KDDockWidgets::Core::Separator* controller,
85 : KDDockWidgets::Core::View* parent = nullptr) const override
86 : {
87 0 : auto* parentItem = KDDockWidgets::QtQuick::asQQuickItem(parent);
88 0 : return new DockSeparator(controller, parentItem);
89 : }
90 :
91 0 : KDDockWidgets::Core::View* createTitleBar(KDDockWidgets::Core::TitleBar* controller,
92 : KDDockWidgets::Core::View* parent) const override
93 : {
94 0 : auto* parentItem = KDDockWidgets::QtQuick::asQQuickItem(parent);
95 0 : return new DockTitleBar(controller, parentItem);
96 : }
97 :
98 0 : KDDockWidgets::Core::View* createTabBar(KDDockWidgets::Core::TabBar* controller,
99 : KDDockWidgets::Core::View* parent = nullptr) const override
100 : {
101 0 : auto* parentItem = KDDockWidgets::QtQuick::asQQuickItem(parent);
102 0 : return new DockTabBar(controller, parentItem);
103 : }
104 :
105 0 : QUrl titleBarFilename() const override
106 : {
107 0 : return QUrl("qrc:/qt/qml/Muse/Dock/DockTitleBar.qml");
108 : }
109 :
110 0 : QUrl dockwidgetFilename() const override
111 : {
112 0 : return QUrl("qrc:/qt/qml/Muse/Dock/DockWidget.qml");
113 : }
114 :
115 0 : QUrl groupFilename() const override
116 : {
117 0 : return QUrl("qrc:/qt/qml/Muse/Dock/DockFrame.qml");
118 : }
119 :
120 0 : QUrl floatingWindowFilename() const override
121 : {
122 0 : return QUrl("qrc:/qt/qml/Muse/Dock/DockFloatingWindow.qml");
123 : }
124 :
125 0 : QUrl separatorFilename() const override
126 : {
127 0 : return QUrl("qrc:/qt/qml/Muse/Dock/DockSeparator.qml");
128 : }
129 :
130 : private:
131 : const modularity::ContextPtr m_iocContext;
132 : };
133 : }
134 :
135 : using namespace muse::dock;
136 : using namespace muse::modularity;
137 :
138 : static const std::string module_name = "dockwindow";
139 :
140 0 : std::string DockModule::moduleName() const
141 : {
142 0 : return module_name;
143 : }
144 :
145 0 : void DockModule::registerExports()
146 : {
147 0 : }
148 :
149 0 : void DockModule::resolveImports()
150 : {
151 0 : auto cr = globalIoc()->resolve<muse::rcommand::ICommandsRegister>(module_name);
152 0 : if (cr) {
153 0 : cr->reg(std::make_shared<DockCommandsRegister>());
154 : }
155 0 : }
156 :
157 0 : void DockModule::onInit(const IApplication::RunMode&)
158 : {
159 0 : }
160 :
161 : // Context
162 :
163 0 : IContextSetup* DockModule::newContext(const muse::modularity::ContextPtr& ctx) const
164 : {
165 0 : return new DockContext(ctx);
166 : }
167 :
168 0 : void DockContext::registerExports()
169 : {
170 0 : m_actionsController = std::make_shared<DockWindowActionsController>(iocContext());
171 :
172 0 : ioc()->registerExport<IDockWindowProvider>(module_name, new DockWindowProvider());
173 0 : }
174 :
175 0 : void DockContext::resolveImports()
176 : {
177 0 : auto cs = ioc()->resolve<muse::rcommand::ICommandsState>(module_name);
178 0 : if (cs) {
179 0 : cs->reg(std::make_shared<DockCommandsState>(iocContext()));
180 : }
181 0 : }
182 :
183 0 : void DockContext::onInit(const IApplication::RunMode&)
184 : {
185 0 : m_actionsController->init();
186 :
187 : // ===================================
188 : // Setup KDDockWidgets
189 : // ===================================
190 :
191 0 : QQmlEngine* engine = ioc()->resolve<ui::IUiEngine>(module_name)->qmlEngine();
192 :
193 0 : const int ctx = iocContext()->id;
194 :
195 : //! NOTE Create new context data
196 0 : KDDockWidgets::ContextData::context(ctx);
197 :
198 0 : KDDockWidgets::Config& config = KDDockWidgets::Config::self(ctx);
199 :
200 0 : config.setViewFactory(new DockWidgetFactory(iocContext()));
201 :
202 0 : KDDockWidgets::setCtxForEngine(engine, ctx);
203 0 : KDDockWidgets::QtQuick::Platform::instance()->setQmlEngine(engine);
204 :
205 0 : auto flags = config.flags()
206 0 : | KDDockWidgets::Config::Flag_HideTitleBarWhenTabsVisible;
207 :
208 0 : config.setFlags(flags);
209 :
210 : KDDockWidgets::Core::FloatingWindow::s_windowFlagsOverride = Qt::Tool
211 0 : | Qt::NoDropShadowWindowHint
212 0 : | Qt::FramelessWindowHint;
213 :
214 0 : auto internalFlags = config.internalFlags()
215 0 : | KDDockWidgets::Config::InternalFlag_UseTransparentFloatingWindow;
216 :
217 0 : config.setInternalFlags(internalFlags);
218 :
219 0 : config.setAbsoluteWidgetMinSize(QSize(10, 10));
220 0 : config.setSeparatorThickness(1);
221 0 : }
222 :
223 0 : void DockContext::onDeinit()
224 : {
225 0 : const int ctx = iocContext()->id;
226 :
227 : //! NOTE Destroy context data
228 0 : KDDockWidgets::ContextData::destroyContext(ctx);
229 0 : }
|