2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2022-04-02 12:15:26 +02:00
|
|
|
|
|
|
|
|
#include "qmljscodestylepreferenceswidget.h"
|
2022-04-07 21:56:10 +02:00
|
|
|
|
2022-04-02 12:15:26 +02:00
|
|
|
#include "qmljscodestylepreferences.h"
|
|
|
|
|
#include "qmljscodestylesettings.h"
|
2022-04-07 21:56:10 +02:00
|
|
|
#include "qmljscodestylesettingswidget.h"
|
2022-04-02 12:15:26 +02:00
|
|
|
|
|
|
|
|
#include <QLabel>
|
2022-04-07 21:56:10 +02:00
|
|
|
#include <QVBoxLayout>
|
2022-04-02 12:15:26 +02:00
|
|
|
|
|
|
|
|
namespace QmlJSTools {
|
|
|
|
|
|
|
|
|
|
QmlJSCodeStylePreferencesWidget::QmlJSCodeStylePreferencesWidget(QWidget *parent) :
|
|
|
|
|
QWidget(parent)
|
|
|
|
|
{
|
|
|
|
|
m_codeStyleSettingsWidget = new QmlJSCodeStyleSettingsWidget(this);
|
|
|
|
|
auto layout = new QVBoxLayout(this);
|
|
|
|
|
layout->addWidget(m_codeStyleSettingsWidget);
|
|
|
|
|
layout->setContentsMargins(QMargins());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlJSCodeStylePreferencesWidget::setPreferences(QmlJSCodeStylePreferences *preferences)
|
|
|
|
|
{
|
|
|
|
|
if (m_preferences == preferences)
|
|
|
|
|
return; // nothing changes
|
|
|
|
|
|
2022-09-02 12:18:32 +02:00
|
|
|
slotCurrentPreferencesChanged(preferences);
|
|
|
|
|
|
2022-04-02 12:15:26 +02:00
|
|
|
// cleanup old
|
|
|
|
|
if (m_preferences) {
|
|
|
|
|
disconnect(m_preferences, &QmlJSCodeStylePreferences::currentCodeStyleSettingsChanged,
|
|
|
|
|
m_codeStyleSettingsWidget, &QmlJSCodeStyleSettingsWidget::setCodeStyleSettings);
|
|
|
|
|
disconnect(m_preferences, &QmlJSCodeStylePreferences::currentPreferencesChanged,
|
|
|
|
|
this, &QmlJSCodeStylePreferencesWidget::slotCurrentPreferencesChanged);
|
|
|
|
|
disconnect(m_codeStyleSettingsWidget, &QmlJSCodeStyleSettingsWidget::settingsChanged,
|
|
|
|
|
this, &QmlJSCodeStylePreferencesWidget::slotSettingsChanged);
|
|
|
|
|
}
|
|
|
|
|
m_preferences = preferences;
|
|
|
|
|
// fillup new
|
|
|
|
|
if (m_preferences) {
|
|
|
|
|
m_codeStyleSettingsWidget->setCodeStyleSettings(m_preferences->currentCodeStyleSettings());
|
|
|
|
|
|
|
|
|
|
connect(m_preferences, &QmlJSCodeStylePreferences::currentCodeStyleSettingsChanged,
|
|
|
|
|
m_codeStyleSettingsWidget, &QmlJSCodeStyleSettingsWidget::setCodeStyleSettings);
|
|
|
|
|
connect(m_preferences, &QmlJSCodeStylePreferences::currentPreferencesChanged,
|
|
|
|
|
this, &QmlJSCodeStylePreferencesWidget::slotCurrentPreferencesChanged);
|
|
|
|
|
connect(m_codeStyleSettingsWidget, &QmlJSCodeStyleSettingsWidget::settingsChanged,
|
|
|
|
|
this, &QmlJSCodeStylePreferencesWidget::slotSettingsChanged);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlJSCodeStylePreferencesWidget::slotCurrentPreferencesChanged(TextEditor::ICodeStylePreferences *preferences)
|
|
|
|
|
{
|
2022-09-02 12:18:32 +02:00
|
|
|
m_codeStyleSettingsWidget->setEnabled(preferences && preferences->currentPreferences() &&
|
|
|
|
|
!preferences->currentPreferences()->isReadOnly());
|
2022-04-02 12:15:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlJSCodeStylePreferencesWidget::slotSettingsChanged(const QmlJSCodeStyleSettings &settings)
|
|
|
|
|
{
|
|
|
|
|
if (!m_preferences)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
QmlJSCodeStylePreferences *current = qobject_cast<QmlJSCodeStylePreferences*>(m_preferences->currentPreferences());
|
|
|
|
|
if (!current)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
current->setCodeStyleSettings(settings);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace QmlJSTools
|