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
|
2011-07-06 10:38:53 +02:00
|
|
|
|
2011-02-03 15:48:14 +01:00
|
|
|
#include "tabsettingswidget.h"
|
2022-07-25 13:35:19 +02:00
|
|
|
|
2011-02-03 15:48:14 +01:00
|
|
|
#include "tabsettings.h"
|
2023-01-17 18:02:43 +01:00
|
|
|
#include "texteditortr.h"
|
2011-02-03 15:48:14 +01:00
|
|
|
|
2022-07-25 13:35:19 +02:00
|
|
|
#include <QApplication>
|
|
|
|
|
#include <QComboBox>
|
|
|
|
|
#include <QLabel>
|
|
|
|
|
#include <QSpinBox>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QTextStream>
|
2011-02-03 15:48:14 +01:00
|
|
|
|
2022-07-25 13:35:19 +02:00
|
|
|
#include <utils/layoutbuilder.h>
|
|
|
|
|
|
2011-02-03 15:48:14 +01:00
|
|
|
namespace TextEditor {
|
|
|
|
|
|
2022-07-25 13:35:19 +02:00
|
|
|
QString continuationTooltip()
|
|
|
|
|
{
|
|
|
|
|
// FIXME: This is unfair towards translators.
|
2023-01-17 18:02:43 +01:00
|
|
|
return Tr::tr(
|
2022-07-25 13:35:19 +02:00
|
|
|
"<html><head/><body>\n"
|
|
|
|
|
"Influences the indentation of continuation lines.\n"
|
|
|
|
|
"\n"
|
|
|
|
|
"<ul>\n"
|
|
|
|
|
"<li>Not At All: Do not align at all. Lines will only be indented to the current logical indentation depth.\n"
|
|
|
|
|
"<pre>\n"
|
|
|
|
|
"(tab)int i = foo(a, b\n"
|
|
|
|
|
"(tab)c, d);\n"
|
|
|
|
|
"</pre>\n"
|
|
|
|
|
"</li>\n"
|
|
|
|
|
"\n"
|
|
|
|
|
"<li>With Spaces: Always use spaces for alignment, regardless of the other indentation settings.\n"
|
|
|
|
|
"<pre>\n"
|
|
|
|
|
"(tab)int i = foo(a, b\n"
|
|
|
|
|
"(tab) c, d);\n"
|
|
|
|
|
"</pre>\n"
|
|
|
|
|
"</li>\n"
|
|
|
|
|
"\n"
|
|
|
|
|
"<li>With Regular Indent: Use tabs and/or spaces for alignment, as configured above.\n"
|
|
|
|
|
"<pre>\n"
|
|
|
|
|
"(tab)int i = foo(a, b\n"
|
|
|
|
|
"(tab)(tab)(tab) c, d);\n"
|
|
|
|
|
"</pre>\n"
|
|
|
|
|
"</li>\n"
|
|
|
|
|
"</ul></body></html>");
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-03 15:48:14 +01:00
|
|
|
TabSettingsWidget::TabSettingsWidget(QWidget *parent) :
|
2022-07-25 13:35:19 +02:00
|
|
|
QGroupBox(parent)
|
2011-02-03 15:48:14 +01:00
|
|
|
{
|
2023-01-17 18:02:43 +01:00
|
|
|
setTitle(Tr::tr("Tabs And Indentation"));
|
2022-07-25 13:35:19 +02:00
|
|
|
|
|
|
|
|
m_codingStyleWarning = new QLabel(
|
2023-01-17 18:02:43 +01:00
|
|
|
Tr::tr("<i>Code indentation is configured in <a href=\"C++\">C++</a> "
|
2022-07-25 13:35:19 +02:00
|
|
|
"and <a href=\"QtQuick\">Qt Quick</a> settings.</i>"));
|
|
|
|
|
m_codingStyleWarning->setVisible(false);
|
|
|
|
|
m_codingStyleWarning->setWordWrap(true);
|
|
|
|
|
m_codingStyleWarning->setToolTip(
|
2023-01-17 18:02:43 +01:00
|
|
|
Tr::tr("The text editor indentation setting is used for non-code files only. See the C++ "
|
2022-07-25 13:35:19 +02:00
|
|
|
"and Qt Quick coding style settings to configure indentation for code files."));
|
|
|
|
|
|
|
|
|
|
m_tabPolicy = new QComboBox(this);
|
|
|
|
|
m_tabPolicy->setMinimumContentsLength(28);
|
2023-01-17 18:02:43 +01:00
|
|
|
m_tabPolicy->addItem(Tr::tr("Spaces Only"));
|
|
|
|
|
m_tabPolicy->addItem(Tr::tr("Tabs Only"));
|
|
|
|
|
m_tabPolicy->addItem(Tr::tr("Mixed"));
|
2022-07-25 13:35:19 +02:00
|
|
|
|
2023-01-17 18:02:43 +01:00
|
|
|
auto tabSizeLabel = new QLabel(Tr::tr("Ta&b size:"));
|
2022-07-25 13:35:19 +02:00
|
|
|
|
|
|
|
|
m_tabSize = new QSpinBox(this);
|
|
|
|
|
m_tabSize->setRange(1, 20);
|
2011-02-03 15:48:14 +01:00
|
|
|
|
2023-01-17 18:02:43 +01:00
|
|
|
auto indentSizeLabel = new QLabel(Tr::tr("&Indent size:"));
|
2022-07-25 13:35:19 +02:00
|
|
|
|
|
|
|
|
m_indentSize = new QSpinBox(this);
|
|
|
|
|
m_indentSize->setRange(1, 20);
|
|
|
|
|
|
|
|
|
|
m_continuationAlignBehavior = new QComboBox;
|
2023-01-17 18:02:43 +01:00
|
|
|
m_continuationAlignBehavior->addItem(Tr::tr("Not At All"));
|
|
|
|
|
m_continuationAlignBehavior->addItem(Tr::tr("With Spaces"));
|
|
|
|
|
m_continuationAlignBehavior->addItem(Tr::tr("With Regular Indent"));
|
2022-07-25 13:35:19 +02:00
|
|
|
m_continuationAlignBehavior->setToolTip(continuationTooltip());
|
|
|
|
|
|
|
|
|
|
tabSizeLabel->setBuddy(m_tabSize);
|
|
|
|
|
indentSizeLabel->setBuddy(m_indentSize);
|
|
|
|
|
|
2023-04-25 10:15:07 +02:00
|
|
|
using namespace Layouting;
|
2022-07-25 13:35:19 +02:00
|
|
|
const auto indent = [](QWidget *inner) { return Row { Space(30), inner }; };
|
|
|
|
|
|
|
|
|
|
Column {
|
|
|
|
|
m_codingStyleWarning,
|
2023-01-17 18:02:43 +01:00
|
|
|
Tr::tr("Tab policy:"),
|
2022-07-25 13:35:19 +02:00
|
|
|
indent(m_tabPolicy),
|
|
|
|
|
Row { tabSizeLabel, m_tabSize, indentSizeLabel, m_indentSize, st },
|
2023-01-17 18:02:43 +01:00
|
|
|
Tr::tr("Align continuation lines:"),
|
2022-07-25 13:35:19 +02:00
|
|
|
indent(m_continuationAlignBehavior)
|
|
|
|
|
}.attachTo(this);
|
|
|
|
|
|
|
|
|
|
connect(m_codingStyleWarning, &QLabel::linkActivated,
|
2015-12-13 01:18:33 +02:00
|
|
|
this, &TabSettingsWidget::codingStyleLinkActivated);
|
2022-07-25 13:35:19 +02:00
|
|
|
connect(m_tabPolicy, &QComboBox::currentIndexChanged,
|
2015-12-13 01:18:33 +02:00
|
|
|
this, &TabSettingsWidget::slotSettingsChanged);
|
2022-07-25 13:35:19 +02:00
|
|
|
connect(m_tabSize, &QSpinBox::valueChanged,
|
2015-12-13 01:18:33 +02:00
|
|
|
this, &TabSettingsWidget::slotSettingsChanged);
|
2022-07-25 13:35:19 +02:00
|
|
|
connect(m_indentSize, &QSpinBox::valueChanged,
|
2015-12-13 01:18:33 +02:00
|
|
|
this, &TabSettingsWidget::slotSettingsChanged);
|
2022-07-25 13:35:19 +02:00
|
|
|
connect(m_continuationAlignBehavior, &QComboBox::currentIndexChanged,
|
2015-12-13 01:18:33 +02:00
|
|
|
this, &TabSettingsWidget::slotSettingsChanged);
|
2011-02-03 15:48:14 +01:00
|
|
|
}
|
|
|
|
|
|
2022-07-25 13:35:19 +02:00
|
|
|
TabSettingsWidget::~TabSettingsWidget() = default;
|
2011-02-03 15:48:14 +01:00
|
|
|
|
2022-07-25 13:35:19 +02:00
|
|
|
void TabSettingsWidget::setTabSettings(const TabSettings &s)
|
2011-02-03 15:48:14 +01:00
|
|
|
{
|
2017-09-30 07:12:57 +02:00
|
|
|
QSignalBlocker blocker(this);
|
2022-07-25 13:35:19 +02:00
|
|
|
m_tabPolicy->setCurrentIndex(s.m_tabPolicy);
|
|
|
|
|
m_tabSize->setValue(s.m_tabSize);
|
|
|
|
|
m_indentSize->setValue(s.m_indentSize);
|
|
|
|
|
m_continuationAlignBehavior->setCurrentIndex(s.m_continuationAlignBehavior);
|
2011-02-03 15:48:14 +01:00
|
|
|
}
|
|
|
|
|
|
2011-08-16 10:45:23 +02:00
|
|
|
TabSettings TabSettingsWidget::tabSettings() const
|
2011-02-03 15:48:14 +01:00
|
|
|
{
|
|
|
|
|
TabSettings set;
|
|
|
|
|
|
2022-07-25 13:35:19 +02:00
|
|
|
set.m_tabPolicy = TabSettings::TabPolicy(m_tabPolicy->currentIndex());
|
|
|
|
|
set.m_tabSize = m_tabSize->value();
|
|
|
|
|
set.m_indentSize = m_indentSize->value();
|
|
|
|
|
set.m_continuationAlignBehavior =
|
|
|
|
|
TabSettings::ContinuationAlignBehavior(m_continuationAlignBehavior->currentIndex());
|
2011-02-03 15:48:14 +01:00
|
|
|
|
|
|
|
|
return set;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TabSettingsWidget::slotSettingsChanged()
|
|
|
|
|
{
|
2011-08-16 10:45:23 +02:00
|
|
|
emit settingsChanged(tabSettings());
|
2011-02-03 15:48:14 +01:00
|
|
|
}
|
|
|
|
|
|
2013-04-04 11:17:13 +02:00
|
|
|
void TabSettingsWidget::codingStyleLinkActivated(const QString &linkString)
|
|
|
|
|
{
|
|
|
|
|
if (linkString == QLatin1String("C++"))
|
|
|
|
|
emit codingStyleLinkClicked(CppLink);
|
|
|
|
|
else if (linkString == QLatin1String("QtQuick"))
|
|
|
|
|
emit codingStyleLinkClicked(QtQuickLink);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TabSettingsWidget::setCodingStyleWarningVisible(bool visible)
|
|
|
|
|
{
|
2022-07-25 13:35:19 +02:00
|
|
|
m_codingStyleWarning->setVisible(visible);
|
2013-04-04 11:17:13 +02:00
|
|
|
}
|
|
|
|
|
|
2022-07-25 13:35:19 +02:00
|
|
|
} // TextEditor
|