2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2022 The Qt Company Ltd.
|
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
2022-05-06 14:27:58 +03:00
|
|
|
|
|
|
|
|
#include "qdslandingpage.h"
|
2022-06-20 23:51:16 +02:00
|
|
|
#include "projectfilecontenttools.h"
|
2022-05-23 10:35:18 +03:00
|
|
|
#include "qdslandingpagetheme.h"
|
2022-06-20 23:51:16 +02:00
|
|
|
#include "qmlprojectconstants.h"
|
|
|
|
|
#include "qmlprojectgen/qmlprojectgenerator.h"
|
|
|
|
|
#include "qmlprojectplugin.h"
|
2022-05-06 14:27:58 +03:00
|
|
|
#include "utils/algorithm.h"
|
|
|
|
|
|
2022-06-20 23:51:16 +02:00
|
|
|
#include <coreplugin/coreconstants.h>
|
|
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
2022-05-06 14:27:58 +03:00
|
|
|
#include <coreplugin/icore.h>
|
2022-06-20 23:51:16 +02:00
|
|
|
#include <coreplugin/modemanager.h>
|
2022-05-06 14:27:58 +03:00
|
|
|
|
2022-06-20 23:51:16 +02:00
|
|
|
#include <QDesktopServices>
|
2022-06-01 17:33:39 +03:00
|
|
|
#include <QHBoxLayout>
|
2022-05-06 14:27:58 +03:00
|
|
|
#include <QQuickItem>
|
2022-06-20 23:51:16 +02:00
|
|
|
#include <QtQml/QQmlEngine>
|
2022-05-06 14:27:58 +03:00
|
|
|
|
|
|
|
|
namespace QmlProjectManager {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2022-06-20 23:51:16 +02:00
|
|
|
const char INSTALL_QDS_URL[] = "https://www.qt.io/product/ui-design-tools";
|
2022-05-06 14:27:58 +03:00
|
|
|
|
2022-06-01 17:33:39 +03:00
|
|
|
QdsLandingPageWidget::QdsLandingPageWidget(QWidget* parent)
|
|
|
|
|
: QWidget(parent)
|
2022-05-06 14:27:58 +03:00
|
|
|
{
|
2022-06-01 17:33:39 +03:00
|
|
|
setLayout(new QHBoxLayout());
|
|
|
|
|
layout()->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QdsLandingPageWidget::~QdsLandingPageWidget()
|
|
|
|
|
{
|
|
|
|
|
if (m_widget)
|
|
|
|
|
m_widget->deleteLater();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QQuickWidget *QdsLandingPageWidget::widget()
|
|
|
|
|
{
|
|
|
|
|
if (!m_widget) {
|
|
|
|
|
m_widget = new QQuickWidget();
|
2022-06-20 23:51:16 +02:00
|
|
|
|
|
|
|
|
const QString resourcePath
|
|
|
|
|
= Core::ICore::resourcePath(QmlProjectManager::Constants::QML_RESOURCE_PATH).toString();
|
|
|
|
|
const QString landingPath
|
|
|
|
|
= Core::ICore::resourcePath(QmlProjectManager::Constants::LANDING_PAGE_PATH).toString();
|
|
|
|
|
|
|
|
|
|
QdsLandingPageTheme::setupTheme(m_widget->engine());
|
|
|
|
|
|
|
|
|
|
m_widget->setResizeMode(QQuickWidget::SizeRootObjectToView);
|
|
|
|
|
m_widget->engine()->addImportPath(landingPath + "/imports");
|
|
|
|
|
m_widget->engine()->addImportPath(resourcePath);
|
2022-07-18 18:50:26 +02:00
|
|
|
m_widget->engine()->addImportPath("qrc:/studiofonts");
|
2022-06-20 23:51:16 +02:00
|
|
|
m_widget->setSource(QUrl::fromLocalFile(landingPath + "/main.qml"));
|
|
|
|
|
m_widget->hide();
|
|
|
|
|
|
2022-06-01 17:33:39 +03:00
|
|
|
layout()->addWidget(m_widget);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return m_widget;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-20 23:51:16 +02:00
|
|
|
QdsLandingPage::QdsLandingPage()
|
|
|
|
|
: m_widget{nullptr}
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
void QdsLandingPage::openQtc(bool rememberSelection)
|
2022-06-01 17:33:39 +03:00
|
|
|
{
|
2022-06-20 23:51:16 +02:00
|
|
|
if (rememberSelection)
|
|
|
|
|
Core::ICore::settings()->setValue(QmlProjectManager::Constants::ALWAYS_OPEN_UI_MODE,
|
|
|
|
|
Core::Constants::MODE_EDIT);
|
2022-06-01 17:33:39 +03:00
|
|
|
|
2022-06-20 23:51:16 +02:00
|
|
|
hide();
|
2022-05-06 14:27:58 +03:00
|
|
|
|
2022-06-20 23:51:16 +02:00
|
|
|
Core::ModeManager::activateMode(Core::Constants::MODE_EDIT);
|
|
|
|
|
}
|
2022-05-06 14:27:58 +03:00
|
|
|
|
2022-06-20 23:51:16 +02:00
|
|
|
void QdsLandingPage::openQds(bool rememberSelection)
|
|
|
|
|
{
|
|
|
|
|
if (rememberSelection)
|
|
|
|
|
Core::ICore::settings()->setValue(QmlProjectManager::Constants::ALWAYS_OPEN_UI_MODE,
|
|
|
|
|
Core::Constants::MODE_DESIGN);
|
2022-06-01 17:33:39 +03:00
|
|
|
|
2022-06-20 23:51:16 +02:00
|
|
|
auto editor = Core::EditorManager::currentEditor();
|
|
|
|
|
if (editor)
|
|
|
|
|
QmlProjectPlugin::openInQDSWithProject(editor->document()->filePath());
|
|
|
|
|
}
|
2022-06-01 17:33:39 +03:00
|
|
|
|
2022-06-20 23:51:16 +02:00
|
|
|
void QdsLandingPage::installQds()
|
|
|
|
|
{
|
|
|
|
|
QDesktopServices::openUrl(QUrl(INSTALL_QDS_URL));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QdsLandingPage::generateProjectFile()
|
|
|
|
|
{
|
|
|
|
|
GenerateQmlProject::QmlProjectFileGenerator generator;
|
|
|
|
|
|
|
|
|
|
Core::IEditor *editor = Core::EditorManager::currentEditor();
|
|
|
|
|
if (!editor)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (generator.prepareForUiQmlFile(editor->document()->filePath())) {
|
|
|
|
|
if (generator.execute()) {
|
|
|
|
|
const QString qtVersion = ProjectFileContentTools::qtVersion(generator.targetFile());
|
|
|
|
|
const QString qdsVersion = ProjectFileContentTools::qdsVersion(generator.targetFile());
|
|
|
|
|
setProjectFileExists(generator.targetFile().exists());
|
|
|
|
|
setQtVersion(qtVersion);
|
|
|
|
|
setQdsVersion(qdsVersion);
|
|
|
|
|
}
|
2022-05-18 08:58:43 +02:00
|
|
|
}
|
2022-06-20 23:51:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QdsLandingPage::setWidget(QWidget *widget)
|
|
|
|
|
{
|
|
|
|
|
m_widget = widget;
|
2022-05-06 14:27:58 +03:00
|
|
|
}
|
|
|
|
|
|
2022-06-01 17:33:39 +03:00
|
|
|
QWidget *QdsLandingPage::widget()
|
2022-05-06 14:27:58 +03:00
|
|
|
{
|
2022-06-01 17:33:39 +03:00
|
|
|
return m_widget;
|
2022-05-06 14:27:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QdsLandingPage::show()
|
|
|
|
|
{
|
2022-06-20 23:51:16 +02:00
|
|
|
if (!m_widget)
|
|
|
|
|
return;
|
|
|
|
|
|
2022-06-01 17:33:39 +03:00
|
|
|
m_widget->show();
|
2022-05-06 14:27:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QdsLandingPage::hide()
|
|
|
|
|
{
|
2022-06-20 23:51:16 +02:00
|
|
|
if (!m_widget)
|
|
|
|
|
return;
|
|
|
|
|
|
2022-06-01 17:33:39 +03:00
|
|
|
m_widget->hide();
|
2022-05-06 14:27:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool QdsLandingPage::qdsInstalled() const
|
|
|
|
|
{
|
|
|
|
|
return m_qdsInstalled;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QdsLandingPage::setQdsInstalled(bool installed)
|
|
|
|
|
{
|
2022-06-20 23:51:16 +02:00
|
|
|
if (m_qdsInstalled != installed) {
|
|
|
|
|
m_qdsInstalled = installed;
|
|
|
|
|
emit qdsInstalledChanged();
|
|
|
|
|
}
|
2022-05-06 14:27:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool QdsLandingPage::projectFileExists() const
|
|
|
|
|
{
|
|
|
|
|
return m_projectFileExists;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QdsLandingPage::setProjectFileExists(bool exists)
|
|
|
|
|
{
|
2022-06-20 23:51:16 +02:00
|
|
|
if (m_projectFileExists != exists) {
|
|
|
|
|
m_projectFileExists = exists;
|
|
|
|
|
emit projectFileExistshanged();
|
|
|
|
|
}
|
2022-05-06 14:27:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QString QdsLandingPage::qtVersion() const
|
|
|
|
|
{
|
|
|
|
|
return m_qtVersion;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QdsLandingPage::setQtVersion(const QString &version)
|
|
|
|
|
{
|
2022-06-20 23:51:16 +02:00
|
|
|
if (m_qtVersion != version) {
|
|
|
|
|
m_qtVersion = version;
|
|
|
|
|
emit qtVersionChanged();
|
|
|
|
|
}
|
2022-05-06 14:27:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QString QdsLandingPage::qdsVersion() const
|
|
|
|
|
{
|
|
|
|
|
return m_qdsVersion;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QdsLandingPage::setQdsVersion(const QString &version)
|
|
|
|
|
{
|
2022-06-20 23:51:16 +02:00
|
|
|
if (m_qdsVersion != version) {
|
|
|
|
|
m_qdsVersion = version;
|
|
|
|
|
emit qdsVersionChanged();
|
|
|
|
|
}
|
2022-05-06 14:27:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QStringList QdsLandingPage::cmakeResources() const
|
|
|
|
|
{
|
|
|
|
|
return m_cmakeResources;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QdsLandingPage::setCmakeResources(const Utils::FilePaths &resources)
|
|
|
|
|
{
|
|
|
|
|
QStringList strings = Utils::transform(resources,
|
|
|
|
|
[](const Utils::FilePath &path)
|
|
|
|
|
{ return path.fileName(); });
|
|
|
|
|
setCmakeResources(strings);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QdsLandingPage::setCmakeResources(const QStringList &resources)
|
|
|
|
|
{
|
|
|
|
|
m_cmakeResources = resources;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace QmlProjectManager
|