summaryrefslogtreecommitdiffstats
path: root/src/Authoring/Studio/Palettes/PaletteManager.cpp
blob: 02ec8324ff2ef89964726da552b66a3223bb8235 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
/****************************************************************************
**
** Copyright (C) 2002 NVIDIA Corporation.
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt 3D Studio.
**
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

//==============================================================================
//	Includes
//==============================================================================
#include "PaletteManager.h"
#include "StudioApp.h"
#include "MainFrm.h"
#include "TimelineWidget.h"
#include "BasicObjectsView.h"
#include "SlideView.h"
#include "WidgetControl.h"
#include "InspectorControlView.h"
#include "ActionView.h"
#include "IDragable.h"
#include "ActionView.h"
#include "ProjectView.h"
#include "TabOrderHandler.h"
#include "StudioPreferences.h"

#include <QtWidgets/qdockwidget.h>
#include <QtWidgets/qboxlayout.h>

//==============================================================================
/**
 * Constructor
 */
CPaletteManager::CPaletteManager(CMainFrame *inMainFrame)
    : m_MainFrame(inMainFrame)
{
    // Position tabs to the right
    inMainFrame->setTabPosition(Qt::AllDockWidgetAreas, QTabWidget::East);

    m_projectDock = new QDockWidget(QObject::tr("Project"), inMainFrame);
    m_projectDock->setObjectName("project");
    m_projectDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea
                                   | Qt::BottomDockWidgetArea);
    // Give the preferred size as percentages of the mainframe size
    m_projectView = new ProjectView(QSize(inMainFrame->width() * 0.2,
                                          inMainFrame->height() * 0.8),
                                    m_projectDock);
    m_projectView->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
    m_projectDock->setWidget(m_projectView);
    inMainFrame->addDockWidget(Qt::RightDockWidgetArea, m_projectDock);
    m_ControlList.insert(std::make_pair(CONTROLTYPE_PROJECT, m_projectDock));

    m_inspectorDock = new QDockWidget(QObject::tr("Inspector Control"), inMainFrame);
    m_inspectorDock->setObjectName("inspector_control");
    m_inspectorDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea
                                     | Qt::BottomDockWidgetArea);
    // Give the preferred size as percentages of the mainframe size
    auto inspectorView = new InspectorControlView(QSize(inMainFrame->width() * 0.2,
                                                        inMainFrame->height() * 0.8),
                                                  m_inspectorDock);
    inspectorView->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
    m_inspectorDock->setWidget(inspectorView);
    inMainFrame->addDockWidget(Qt::RightDockWidgetArea, m_inspectorDock);
    inMainFrame->tabifyDockWidget(m_projectDock, m_inspectorDock);
    m_ControlList.insert(std::make_pair(CONTROLTYPE_INSPECTOR, m_inspectorDock));

    m_slideDock = new QDockWidget(QObject::tr("Slide"), inMainFrame);
    m_slideDock->setObjectName("slide");
    m_slideDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
    // Slide palette has a fixed size hint
    auto slideView = new SlideView(m_slideDock);
    slideView->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
    m_slideDock->setWidget(slideView);
    QObject::connect(slideView, &SlideView::slideFocused,
                     m_MainFrame, &CMainFrame::onSlideActive);
    inMainFrame->addDockWidget(Qt::LeftDockWidgetArea, m_slideDock);
    m_ControlList.insert(std::make_pair(CONTROLTYPE_SLIDE, m_slideDock));

    m_basicObjectsDock = new QDockWidget(QObject::tr("Basic Objects"), inMainFrame);
    m_basicObjectsDock->setObjectName("basic_objects");
    m_basicObjectsDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea
                                        | Qt::BottomDockWidgetArea);
    // Basic objects palette has a fixed size hint
    auto basicObjectsView = new BasicObjectsView(m_basicObjectsDock);
    basicObjectsView->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
    m_basicObjectsDock->setWidget(basicObjectsView);
    inMainFrame->addDockWidget(Qt::LeftDockWidgetArea, m_basicObjectsDock);
    inMainFrame->tabifyDockWidget(m_basicObjectsDock, m_slideDock);
    m_ControlList.insert(std::make_pair(CONTROLTYPE_BASICOBJECTS, m_basicObjectsDock));

    m_timelineDock = new QDockWidget(QObject::tr("Timeline"));
    m_timelineDock->setObjectName("timeline");
    m_timelineDock->setAllowedAreas(Qt::BottomDockWidgetArea);

    // Give the preferred size as percentages of the mainframe size
    // -25 is applied to width to compensate the action palette having no tabs by default
    m_timelineWidget = new TimelineWidget(QSize(inMainFrame->width() * 0.8 - 25,
                                                inMainFrame->height() * 0.2));
    m_timelineWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
    WidgetControl *timeLineWidgetControl = new WidgetControl(m_timelineWidget, m_timelineDock);
    timeLineWidgetControl->RegisterForDnd(timeLineWidgetControl);
    timeLineWidgetControl->AddMainFlavor(QT3DS_FLAVOR_FILE);
    timeLineWidgetControl->AddMainFlavor(QT3DS_FLAVOR_ASSET_UICFILE);
    timeLineWidgetControl->AddMainFlavor(QT3DS_FLAVOR_ASSET_LIB);
    timeLineWidgetControl->AddMainFlavor(QT3DS_FLAVOR_ASSET_TL);
    timeLineWidgetControl->AddMainFlavor(QT3DS_FLAVOR_BASIC_OBJECTS);

    m_timelineWidget->setParent(timeLineWidgetControl);

    m_timelineDock->setWidget(timeLineWidgetControl);
    inMainFrame->addDockWidget(Qt::BottomDockWidgetArea, m_timelineDock);
    m_ControlList.insert(std::make_pair(CONTROLTYPE_TIMELINE, m_timelineDock));

    m_actionDock = new QDockWidget(QObject::tr("Action"), inMainFrame);
    m_actionDock->setObjectName("action");
    m_actionDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea
                                  | Qt::BottomDockWidgetArea);
    // Give the preferred size as percentages of the mainframe size
    // +25 is applied to width to compensate the action palette having no tabs by default
    auto actionView = new ActionView(QSize(inMainFrame->width() * 0.2 + 25,
                                           inMainFrame->height() * 0.2),
                                     m_actionDock);
    actionView->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
    m_actionDock->setWidget(actionView);
    QObject::connect(actionView, &ActionView::actionFocused,
                     m_MainFrame, &CMainFrame::onActionActive);
    inMainFrame->addDockWidget(Qt::BottomDockWidgetArea, m_actionDock);
    m_ControlList.insert(std::make_pair(CONTROLTYPE_ACTION, m_actionDock));

    m_basicObjectsDock->setEnabled(false);
    m_projectDock->setEnabled(false);
    m_slideDock->setEnabled(false);
    m_actionDock->setEnabled(false);
    m_inspectorDock->setEnabled(false);
    m_timelineDock->setEnabled(false);
}

//==============================================================================
/**
 * Destructor
 */
CPaletteManager::~CPaletteManager()
{
    TControlMap::iterator theIterator = m_ControlList.begin();
    TControlMap::iterator theEndIterator = m_ControlList.end();
    // Delete all the controls
    for (theIterator = m_ControlList.begin(); theIterator != theEndIterator; ++theIterator)
        delete theIterator->second;
}

//=============================================================================
/**
 *  Force a control to become invisible
 */
void CPaletteManager::HideControl(long inType)
{
    auto dock = GetControl(inType);

    if (dock) {
        // Make sure the control is invisible
        dock->setVisible(false);
    }
}
//=============================================================================
/**
 *	Detemine if a control is currently visible
 */
bool CPaletteManager::IsControlVisible(long inType) const
{
    auto dock = GetControl(inType);
    return dock && dock->isVisible();
}

//=============================================================================
/**
 *	Force a control to become visible
 */
void CPaletteManager::ShowControl(long inType)
{
    auto dock = GetControl(inType);

    if (dock) {
        // Make sure the control is visible
        dock->setVisible(true);
        dock->setFocus();
    }
}

//=============================================================================
/**
 *  Flip the visible state of a control
 */
void CPaletteManager::ToggleControl(long inType)
{
    if (IsControlVisible(inType))
        HideControl(inType);
    else
        ShowControl(inType);
}

//==============================================================================
/**
 *	Return the Control (Palette) according to its EControlTypes enum.
 *	@param inType	EControlTypes
 */
QDockWidget *CPaletteManager::GetControl(long inType) const
{
    auto dock = m_ControlList.find(inType);
    if (dock != m_ControlList.end() && dock->second)
        return dock->second;
    else
        return nullptr;
}

QWidget *CPaletteManager::getFocusWidget() const
{
    TControlMap::const_iterator end = m_ControlList.end();
    for (TControlMap::const_iterator iter = m_ControlList.begin(); iter != end; ++iter) {
        if (iter->second->widget()->hasFocus())
            return iter->second->widget();
    }
    return nullptr;
}

bool CPaletteManager::tabNavigateFocusedWidget(bool tabForward)
{
    QWidget *palette = getFocusWidget();
    if (palette) {
        if (auto inspector = qobject_cast<InspectorControlView *>(palette)) {
            inspector->tabOrderHandler()->tabNavigate(tabForward);
            return true;
        } else if (auto actionview = qobject_cast<ActionView *>(palette)) {
            actionview->tabOrderHandler()->tabNavigate(tabForward);
            return true;
        }
    }
    return false;
}

void CPaletteManager::onTimeChanged(long time)
{
    //m_timeLineToolbar->onTimeChanged(time);
}

ProjectView *CPaletteManager::projectView() const
{
    return m_projectView;
}

void CPaletteManager::EnablePalettes()
{
    m_basicObjectsDock->setEnabled(true);
    m_projectDock->setEnabled(true);
    m_slideDock->setEnabled(true);
    m_timelineDock->setEnabled(true);
    m_actionDock->setEnabled(true);
    m_inspectorDock->setEnabled(true);
}