2020-02-11 11:33:25 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** Copyright (C) 2020 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** 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.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "edit3dwidget.h"
|
|
|
|
|
#include "edit3dview.h"
|
|
|
|
|
#include "edit3dcanvas.h"
|
|
|
|
|
#include "edit3dactions.h"
|
|
|
|
|
|
|
|
|
|
#include "qmldesignerplugin.h"
|
|
|
|
|
#include "designersettings.h"
|
|
|
|
|
#include "qmldesignerconstants.h"
|
|
|
|
|
#include "viewmanager.h"
|
|
|
|
|
|
2020-03-20 16:27:55 +02:00
|
|
|
#include <coreplugin/actionmanager/actionmanager.h>
|
|
|
|
|
#include <coreplugin/actionmanager/command.h>
|
2020-03-12 15:55:30 +02:00
|
|
|
#include <coreplugin/icore.h>
|
2020-02-11 11:33:25 +02:00
|
|
|
#include <toolbox.h>
|
|
|
|
|
#include <utils/utilsicons.h>
|
2020-09-18 10:54:22 +02:00
|
|
|
|
|
|
|
|
#include <QActionGroup>
|
2020-02-11 11:33:25 +02:00
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
|
|
|
|
|
namespace QmlDesigner {
|
|
|
|
|
|
|
|
|
|
Edit3DWidget::Edit3DWidget(Edit3DView *view) :
|
|
|
|
|
m_view(view)
|
|
|
|
|
{
|
2020-03-12 15:55:30 +02:00
|
|
|
Core::Context context(Constants::C_QMLEDITOR3D);
|
|
|
|
|
m_context = new Core::IContext(this);
|
|
|
|
|
m_context->setContext(context);
|
|
|
|
|
m_context->setWidget(this);
|
|
|
|
|
|
2020-02-11 11:33:25 +02:00
|
|
|
setMouseTracking(true);
|
|
|
|
|
setFocusPolicy(Qt::WheelFocus);
|
|
|
|
|
|
|
|
|
|
auto fillLayout = new QVBoxLayout(this);
|
|
|
|
|
fillLayout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
fillLayout->setSpacing(0);
|
|
|
|
|
setLayout(fillLayout);
|
|
|
|
|
|
|
|
|
|
// Initialize toolbar
|
|
|
|
|
m_toolBox = new ToolBox(this);
|
|
|
|
|
fillLayout->addWidget(m_toolBox.data());
|
|
|
|
|
|
|
|
|
|
// Iterate through view actions. A null action indicates a separator and a second null action
|
|
|
|
|
// after separator indicates an exclusive group.
|
2020-03-20 16:27:55 +02:00
|
|
|
auto addActionsToToolBox = [this, &context](const QVector<Edit3DAction *> &actions, bool left) {
|
2020-02-11 11:33:25 +02:00
|
|
|
bool previousWasSeparator = true;
|
|
|
|
|
QActionGroup *group = nullptr;
|
|
|
|
|
for (auto action : actions) {
|
|
|
|
|
if (action) {
|
|
|
|
|
if (group)
|
|
|
|
|
group->addAction(action->action());
|
|
|
|
|
addAction(action->action());
|
|
|
|
|
if (left)
|
|
|
|
|
m_toolBox->addLeftSideAction(action->action());
|
|
|
|
|
else
|
|
|
|
|
m_toolBox->addRightSideAction(action->action());
|
|
|
|
|
previousWasSeparator = false;
|
2020-03-20 16:27:55 +02:00
|
|
|
|
|
|
|
|
// Register action as creator command to make it configurable
|
|
|
|
|
Core::Command *command = Core::ActionManager::registerAction(
|
2020-11-16 21:58:53 +01:00
|
|
|
action->action(), action->menuId().constData(), context);
|
2020-03-20 16:27:55 +02:00
|
|
|
command->setDefaultKeySequence(action->action()->shortcut());
|
|
|
|
|
command->augmentActionWithShortcutToolTip(action->action());
|
|
|
|
|
// Clear action shortcut so it doesn't conflict with command's override action
|
|
|
|
|
action->action()->setShortcut({});
|
2020-02-11 11:33:25 +02:00
|
|
|
} else {
|
|
|
|
|
if (previousWasSeparator) {
|
|
|
|
|
group = new QActionGroup(this);
|
|
|
|
|
previousWasSeparator = false;
|
|
|
|
|
} else {
|
|
|
|
|
group = nullptr;
|
|
|
|
|
auto separator = new QAction(this);
|
|
|
|
|
separator->setSeparator(true);
|
|
|
|
|
addAction(separator);
|
|
|
|
|
m_toolBox->addLeftSideAction(separator);
|
|
|
|
|
previousWasSeparator = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
addActionsToToolBox(view->leftActions(), true);
|
|
|
|
|
addActionsToToolBox(view->rightActions(), false);
|
|
|
|
|
|
2020-03-19 13:05:36 +02:00
|
|
|
// Onboarding label contains instructions for new users how to get 3D content into the project
|
|
|
|
|
m_onboardingLabel = new QLabel(this);
|
|
|
|
|
QString labelText =
|
2020-04-24 12:21:35 +03:00
|
|
|
tr("Your file does not import Qt Quick 3D.<br><br>"
|
2021-07-02 14:44:38 +02:00
|
|
|
"To create a 3D view, add the QtQuick3D module in the Library view. Or click"
|
2020-04-24 12:21:35 +03:00
|
|
|
" <a href=\"#add_import\"><span style=\"text-decoration:none;color:%1\">here</span></a> "
|
|
|
|
|
"here to add it immediately.<br><br>"
|
2021-07-02 14:44:38 +02:00
|
|
|
"To import 3D assets from another tool, click the \"Add New Assets...\" button in the Assets tab of the Library view.");
|
2020-03-19 13:05:36 +02:00
|
|
|
m_onboardingLabel->setText(labelText.arg(Utils::creatorTheme()->color(Utils::Theme::TextColorLink).name()));
|
|
|
|
|
m_onboardingLabel->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
|
|
|
|
connect(m_onboardingLabel, &QLabel::linkActivated, this, &Edit3DWidget::linkActivated);
|
|
|
|
|
fillLayout->addWidget(m_onboardingLabel.data());
|
|
|
|
|
|
2020-02-11 11:33:25 +02:00
|
|
|
// Canvas is used to render the actual edit 3d view
|
|
|
|
|
m_canvas = new Edit3DCanvas(this);
|
|
|
|
|
fillLayout->addWidget(m_canvas.data());
|
2020-03-19 13:05:36 +02:00
|
|
|
showCanvas(false);
|
2020-02-11 11:33:25 +02:00
|
|
|
}
|
|
|
|
|
|
2020-03-12 15:55:30 +02:00
|
|
|
void Edit3DWidget::contextHelp(const Core::IContext::HelpCallback &callback) const
|
|
|
|
|
{
|
|
|
|
|
if (m_view)
|
|
|
|
|
m_view->contextHelp(callback);
|
|
|
|
|
|
|
|
|
|
callback({});
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-19 13:05:36 +02:00
|
|
|
void Edit3DWidget::showCanvas(bool show)
|
|
|
|
|
{
|
|
|
|
|
if (!show) {
|
|
|
|
|
QImage emptyImage;
|
|
|
|
|
m_canvas->updateRenderImage(emptyImage);
|
|
|
|
|
}
|
|
|
|
|
m_canvas->setVisible(show);
|
|
|
|
|
m_onboardingLabel->setVisible(!show);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Edit3DWidget::linkActivated(const QString &link)
|
|
|
|
|
{
|
2020-03-30 15:56:55 +02:00
|
|
|
Q_UNUSED(link)
|
2020-03-19 13:05:36 +02:00
|
|
|
if (m_view)
|
|
|
|
|
m_view->addQuick3DImport();
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-11 11:33:25 +02:00
|
|
|
Edit3DCanvas *Edit3DWidget::canvas() const
|
|
|
|
|
{
|
|
|
|
|
return m_canvas.data();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Edit3DView *Edit3DWidget::view() const
|
|
|
|
|
{
|
|
|
|
|
return m_view.data();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|