2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2009-01-27 15:12:32 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2009-01-27 15:12:32 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2009-01-27 15:12:32 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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
|
2016-01-15 14:57:40 +01:00
|
|
|
** 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.
|
2009-01-27 15:12:32 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** 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.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2009-01-27 15:12:32 +01:00
|
|
|
|
|
|
|
|
#include "displaysettingspage.h"
|
2020-01-15 15:00:57 +01:00
|
|
|
|
2009-01-27 15:12:32 +01:00
|
|
|
#include "displaysettings.h"
|
2014-01-09 14:44:25 +01:00
|
|
|
#include "marginsettings.h"
|
2020-01-15 15:00:57 +01:00
|
|
|
#include "texteditorconstants.h"
|
2020-02-03 08:54:44 +01:00
|
|
|
#include "texteditorsettings.h"
|
2009-01-27 15:12:32 +01:00
|
|
|
|
|
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
|
2022-07-26 17:01:05 +02:00
|
|
|
#include <utils/layoutbuilder.h>
|
|
|
|
|
|
|
|
|
|
#include <QApplication>
|
|
|
|
|
#include <QCheckBox>
|
|
|
|
|
#include <QGroupBox>
|
|
|
|
|
#include <QRadioButton>
|
|
|
|
|
#include <QSpinBox>
|
|
|
|
|
|
2020-01-21 15:20:02 +01:00
|
|
|
namespace TextEditor {
|
2009-01-27 15:12:32 +01:00
|
|
|
|
2020-02-10 11:46:56 +01:00
|
|
|
class DisplaySettingsPagePrivate
|
2009-01-27 15:12:32 +01:00
|
|
|
{
|
2020-02-10 11:46:56 +01:00
|
|
|
public:
|
2020-01-21 15:20:02 +01:00
|
|
|
DisplaySettingsPagePrivate();
|
2009-01-27 15:12:32 +01:00
|
|
|
|
|
|
|
|
DisplaySettings m_displaySettings;
|
2014-01-09 14:44:25 +01:00
|
|
|
MarginSettings m_marginSettings;
|
2020-01-21 15:20:02 +01:00
|
|
|
QString m_settingsPrefix;
|
2009-01-27 15:12:32 +01:00
|
|
|
};
|
|
|
|
|
|
2020-02-10 11:46:56 +01:00
|
|
|
DisplaySettingsPagePrivate::DisplaySettingsPagePrivate()
|
2009-01-27 15:12:32 +01:00
|
|
|
{
|
2020-01-21 15:20:02 +01:00
|
|
|
m_settingsPrefix = QLatin1String("text");
|
|
|
|
|
m_displaySettings.fromSettings(m_settingsPrefix, Core::ICore::settings());
|
|
|
|
|
m_marginSettings.fromSettings(m_settingsPrefix, Core::ICore::settings());
|
2009-01-27 15:12:32 +01:00
|
|
|
}
|
|
|
|
|
|
2020-02-10 11:46:56 +01:00
|
|
|
class DisplaySettingsWidget final : public Core::IOptionsPageWidget
|
2009-01-27 15:12:32 +01:00
|
|
|
{
|
2020-02-10 11:46:56 +01:00
|
|
|
Q_DECLARE_TR_FUNCTIONS(TextEditor::DisplaySettingsPage)
|
2009-01-27 15:12:32 +01:00
|
|
|
|
2020-02-10 11:46:56 +01:00
|
|
|
public:
|
|
|
|
|
DisplaySettingsWidget(DisplaySettingsPagePrivate *data)
|
|
|
|
|
: m_data(data)
|
|
|
|
|
{
|
2022-07-26 17:01:05 +02:00
|
|
|
resize(452, 458);
|
|
|
|
|
|
|
|
|
|
enableTextWrapping = new QCheckBox(tr("Enable text &wrapping"));
|
|
|
|
|
showWrapColumn = new QCheckBox(tr("Display right &margin at column:"));
|
|
|
|
|
|
|
|
|
|
wrapColumn = new QSpinBox;
|
|
|
|
|
wrapColumn->setMaximum(999);
|
|
|
|
|
|
|
|
|
|
connect(showWrapColumn, &QAbstractButton::toggled, wrapColumn, &QWidget::setEnabled);
|
|
|
|
|
|
|
|
|
|
useIndenter = new QCheckBox(tr("Use context-specific margin"));
|
|
|
|
|
useIndenter->setToolTip(tr("If available, use a different margin. "
|
|
|
|
|
"For example, the ColumnLimit from the ClangFormat plugin."));
|
|
|
|
|
|
|
|
|
|
animateMatchingParentheses = new QCheckBox(tr("&Animate matching parentheses"));
|
|
|
|
|
scrollBarHighlights = new QCheckBox(tr("Highlight search results on the scrollbar"));
|
|
|
|
|
displayLineNumbers = new QCheckBox(tr("Display line &numbers"));
|
|
|
|
|
animateNavigationWithinFile = new QCheckBox(tr("Animate navigation within file"));
|
|
|
|
|
highlightCurrentLine = new QCheckBox(tr("Highlight current &line"));
|
|
|
|
|
highlightBlocks = new QCheckBox(tr("Highlight &blocks"));
|
|
|
|
|
markTextChanges = new QCheckBox(tr("Mark &text changes"));
|
|
|
|
|
autoFoldFirstComment = new QCheckBox(tr("Auto-fold first &comment"));
|
|
|
|
|
displayFoldingMarkers = new QCheckBox(tr("Display &folding markers"));
|
|
|
|
|
centerOnScroll = new QCheckBox(tr("Center &cursor on scroll"));
|
|
|
|
|
visualizeIndent = new QCheckBox(tr("Visualize indent"));
|
|
|
|
|
displayFileLineEnding = new QCheckBox(tr("Display file line ending"));
|
|
|
|
|
displayFileEncoding = new QCheckBox(tr("Display file encoding"));
|
|
|
|
|
openLinksInNextSplit = new QCheckBox(tr("Always open links in another split"));
|
|
|
|
|
highlightMatchingParentheses = new QCheckBox(tr("&Highlight matching parentheses"));
|
|
|
|
|
|
|
|
|
|
visualizeWhitespace = new QCheckBox(tr("&Visualize whitespace"));
|
|
|
|
|
visualizeWhitespace->setToolTip(tr("Shows tabs and spaces."));
|
|
|
|
|
|
|
|
|
|
leftAligned = new QRadioButton(tr("Next to editor content"));
|
|
|
|
|
atMargin = new QRadioButton(tr("Next to right margin"));
|
|
|
|
|
rightAligned = new QRadioButton(tr("Aligned at right side"));
|
|
|
|
|
rightAligned->setChecked(true);
|
|
|
|
|
betweenLines = new QRadioButton(tr("Between lines"));
|
|
|
|
|
|
|
|
|
|
displayAnnotations = new QGroupBox(tr("Line annotations")),
|
|
|
|
|
displayAnnotations->setCheckable(true);
|
|
|
|
|
|
|
|
|
|
using namespace Utils::Layouting;
|
|
|
|
|
|
|
|
|
|
Column {
|
|
|
|
|
leftAligned,
|
|
|
|
|
atMargin,
|
|
|
|
|
rightAligned,
|
|
|
|
|
betweenLines,
|
|
|
|
|
}.attachTo(displayAnnotations);
|
|
|
|
|
|
|
|
|
|
Column {
|
|
|
|
|
Group {
|
|
|
|
|
title(tr("Text Wrapping")),
|
|
|
|
|
Column {
|
|
|
|
|
enableTextWrapping,
|
|
|
|
|
Row { showWrapColumn, wrapColumn, useIndenter, st }
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
Group {
|
|
|
|
|
title(tr("Display")),
|
|
|
|
|
Row {
|
|
|
|
|
Column {
|
|
|
|
|
displayLineNumbers,
|
|
|
|
|
displayFoldingMarkers,
|
|
|
|
|
markTextChanges,
|
|
|
|
|
visualizeWhitespace,
|
|
|
|
|
centerOnScroll,
|
|
|
|
|
autoFoldFirstComment,
|
|
|
|
|
scrollBarHighlights,
|
|
|
|
|
animateNavigationWithinFile,
|
|
|
|
|
},
|
|
|
|
|
Column {
|
|
|
|
|
highlightCurrentLine,
|
|
|
|
|
highlightBlocks,
|
|
|
|
|
animateMatchingParentheses,
|
|
|
|
|
visualizeIndent,
|
|
|
|
|
highlightMatchingParentheses,
|
|
|
|
|
openLinksInNextSplit,
|
|
|
|
|
displayFileEncoding,
|
|
|
|
|
displayFileLineEnding,
|
|
|
|
|
st
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
displayAnnotations,
|
|
|
|
|
st
|
|
|
|
|
}.attachTo(this);
|
|
|
|
|
|
2013-12-03 14:17:03 +01:00
|
|
|
settingsToUI();
|
2009-11-24 15:05:02 +01:00
|
|
|
}
|
2009-01-27 15:12:32 +01:00
|
|
|
|
2020-02-10 11:46:56 +01:00
|
|
|
void apply() final;
|
|
|
|
|
|
|
|
|
|
void settingsFromUI(DisplaySettings &displaySettings, MarginSettings &marginSettings) const;
|
|
|
|
|
void settingsToUI();
|
|
|
|
|
void setDisplaySettings(const DisplaySettings &, const MarginSettings &newMarginSettings);
|
|
|
|
|
|
|
|
|
|
DisplaySettingsPagePrivate *m_data = nullptr;
|
2022-07-26 17:01:05 +02:00
|
|
|
|
|
|
|
|
QCheckBox *enableTextWrapping;
|
|
|
|
|
QCheckBox *showWrapColumn;
|
|
|
|
|
QSpinBox *wrapColumn;
|
|
|
|
|
QCheckBox *useIndenter;
|
|
|
|
|
QCheckBox *animateMatchingParentheses;
|
|
|
|
|
QCheckBox *scrollBarHighlights;
|
|
|
|
|
QCheckBox *displayLineNumbers;
|
|
|
|
|
QCheckBox *animateNavigationWithinFile;
|
|
|
|
|
QCheckBox *highlightCurrentLine;
|
|
|
|
|
QCheckBox *highlightBlocks;
|
|
|
|
|
QCheckBox *markTextChanges;
|
|
|
|
|
QCheckBox *autoFoldFirstComment;
|
|
|
|
|
QCheckBox *displayFoldingMarkers;
|
|
|
|
|
QCheckBox *centerOnScroll;
|
|
|
|
|
QCheckBox *visualizeIndent;
|
|
|
|
|
QCheckBox *displayFileLineEnding;
|
|
|
|
|
QCheckBox *displayFileEncoding;
|
|
|
|
|
QCheckBox *openLinksInNextSplit;
|
|
|
|
|
QCheckBox *highlightMatchingParentheses;
|
|
|
|
|
QCheckBox *visualizeWhitespace;
|
|
|
|
|
QGroupBox *displayAnnotations;
|
|
|
|
|
QRadioButton *leftAligned;
|
|
|
|
|
QRadioButton *atMargin;
|
|
|
|
|
QRadioButton *rightAligned;
|
|
|
|
|
QRadioButton *betweenLines;
|
2020-02-10 11:46:56 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void DisplaySettingsWidget::apply()
|
2009-01-27 15:12:32 +01:00
|
|
|
{
|
|
|
|
|
DisplaySettings newDisplaySettings;
|
2014-01-09 14:44:25 +01:00
|
|
|
MarginSettings newMarginSettings;
|
2009-01-27 15:12:32 +01:00
|
|
|
|
2014-01-09 14:44:25 +01:00
|
|
|
settingsFromUI(newDisplaySettings, newMarginSettings);
|
|
|
|
|
setDisplaySettings(newDisplaySettings, newMarginSettings);
|
2009-01-27 15:12:32 +01:00
|
|
|
}
|
|
|
|
|
|
2020-02-10 11:46:56 +01:00
|
|
|
void DisplaySettingsWidget::settingsFromUI(DisplaySettings &displaySettings,
|
|
|
|
|
MarginSettings &marginSettings) const
|
2010-12-02 18:28:16 +01:00
|
|
|
{
|
2022-07-26 17:01:05 +02:00
|
|
|
displaySettings.m_displayLineNumbers = displayLineNumbers->isChecked();
|
|
|
|
|
displaySettings.m_textWrapping = enableTextWrapping->isChecked();
|
|
|
|
|
marginSettings.m_showMargin = showWrapColumn->isChecked();
|
|
|
|
|
marginSettings.m_useIndenter = useIndenter->isChecked();
|
|
|
|
|
marginSettings.m_marginColumn = wrapColumn->value();
|
|
|
|
|
displaySettings.m_visualizeWhitespace = visualizeWhitespace->isChecked();
|
|
|
|
|
displaySettings.m_visualizeIndent = visualizeIndent->isChecked();
|
|
|
|
|
displaySettings.m_displayFoldingMarkers = displayFoldingMarkers->isChecked();
|
|
|
|
|
displaySettings.m_highlightCurrentLine = highlightCurrentLine->isChecked();
|
|
|
|
|
displaySettings.m_highlightBlocks = highlightBlocks->isChecked();
|
|
|
|
|
displaySettings.m_animateMatchingParentheses = animateMatchingParentheses->isChecked();
|
|
|
|
|
displaySettings.m_highlightMatchingParentheses = highlightMatchingParentheses->isChecked();
|
|
|
|
|
displaySettings.m_markTextChanges = markTextChanges->isChecked();
|
|
|
|
|
displaySettings.m_autoFoldFirstComment = autoFoldFirstComment->isChecked();
|
|
|
|
|
displaySettings.m_centerCursorOnScroll = centerOnScroll->isChecked();
|
|
|
|
|
displaySettings.m_openLinksInNextSplit = openLinksInNextSplit->isChecked();
|
|
|
|
|
displaySettings.m_displayFileEncoding = displayFileEncoding->isChecked();
|
|
|
|
|
displaySettings.m_displayFileLineEnding = displayFileLineEnding->isChecked();
|
|
|
|
|
displaySettings.m_scrollBarHighlights = scrollBarHighlights->isChecked();
|
|
|
|
|
displaySettings.m_animateNavigationWithinFile = animateNavigationWithinFile->isChecked();
|
|
|
|
|
displaySettings.m_displayAnnotations = displayAnnotations->isChecked();
|
|
|
|
|
if (leftAligned->isChecked())
|
2017-07-19 14:51:21 +02:00
|
|
|
displaySettings.m_annotationAlignment = AnnotationAlignment::NextToContent;
|
2022-07-26 17:01:05 +02:00
|
|
|
else if (atMargin->isChecked())
|
2017-07-19 14:51:21 +02:00
|
|
|
displaySettings.m_annotationAlignment = AnnotationAlignment::NextToMargin;
|
2022-07-26 17:01:05 +02:00
|
|
|
else if (rightAligned->isChecked())
|
2017-07-19 14:51:21 +02:00
|
|
|
displaySettings.m_annotationAlignment = AnnotationAlignment::RightSide;
|
2022-07-26 17:01:05 +02:00
|
|
|
else if (betweenLines->isChecked())
|
2017-10-26 15:18:56 +02:00
|
|
|
displaySettings.m_annotationAlignment = AnnotationAlignment::BetweenLines;
|
2009-01-27 15:12:32 +01:00
|
|
|
}
|
|
|
|
|
|
2020-02-10 11:46:56 +01:00
|
|
|
void DisplaySettingsWidget::settingsToUI()
|
2009-01-27 15:12:32 +01:00
|
|
|
{
|
2020-02-10 11:46:56 +01:00
|
|
|
const DisplaySettings &displaySettings = m_data->m_displaySettings;
|
|
|
|
|
const MarginSettings &marginSettings = m_data->m_marginSettings;
|
2022-07-26 17:01:05 +02:00
|
|
|
displayLineNumbers->setChecked(displaySettings.m_displayLineNumbers);
|
|
|
|
|
enableTextWrapping->setChecked(displaySettings.m_textWrapping);
|
|
|
|
|
showWrapColumn->setChecked(marginSettings.m_showMargin);
|
|
|
|
|
useIndenter->setChecked(marginSettings.m_useIndenter);
|
|
|
|
|
wrapColumn->setValue(marginSettings.m_marginColumn);
|
|
|
|
|
visualizeWhitespace->setChecked(displaySettings.m_visualizeWhitespace);
|
|
|
|
|
visualizeIndent->setChecked(displaySettings.m_visualizeIndent);
|
|
|
|
|
displayFoldingMarkers->setChecked(displaySettings.m_displayFoldingMarkers);
|
|
|
|
|
highlightCurrentLine->setChecked(displaySettings.m_highlightCurrentLine);
|
|
|
|
|
highlightBlocks->setChecked(displaySettings.m_highlightBlocks);
|
|
|
|
|
animateMatchingParentheses->setChecked(displaySettings.m_animateMatchingParentheses);
|
|
|
|
|
highlightMatchingParentheses->setChecked(displaySettings.m_highlightMatchingParentheses);
|
|
|
|
|
markTextChanges->setChecked(displaySettings.m_markTextChanges);
|
|
|
|
|
autoFoldFirstComment->setChecked(displaySettings.m_autoFoldFirstComment);
|
|
|
|
|
centerOnScroll->setChecked(displaySettings.m_centerCursorOnScroll);
|
|
|
|
|
openLinksInNextSplit->setChecked(displaySettings.m_openLinksInNextSplit);
|
|
|
|
|
displayFileEncoding->setChecked(displaySettings.m_displayFileEncoding);
|
|
|
|
|
displayFileLineEnding->setChecked(displaySettings.m_displayFileLineEnding);
|
|
|
|
|
scrollBarHighlights->setChecked(displaySettings.m_scrollBarHighlights);
|
|
|
|
|
animateNavigationWithinFile->setChecked(displaySettings.m_animateNavigationWithinFile);
|
|
|
|
|
displayAnnotations->setChecked(displaySettings.m_displayAnnotations);
|
2017-07-19 14:51:21 +02:00
|
|
|
switch (displaySettings.m_annotationAlignment) {
|
2022-07-26 17:01:05 +02:00
|
|
|
case AnnotationAlignment::NextToContent: leftAligned->setChecked(true); break;
|
|
|
|
|
case AnnotationAlignment::NextToMargin: atMargin->setChecked(true); break;
|
|
|
|
|
case AnnotationAlignment::RightSide: rightAligned->setChecked(true); break;
|
|
|
|
|
case AnnotationAlignment::BetweenLines: betweenLines->setChecked(true); break;
|
2017-07-19 14:51:21 +02:00
|
|
|
}
|
2009-01-27 15:12:32 +01:00
|
|
|
}
|
|
|
|
|
|
2010-01-20 11:27:08 +01:00
|
|
|
const DisplaySettings &DisplaySettingsPage::displaySettings() const
|
2009-01-27 15:12:32 +01:00
|
|
|
{
|
2011-09-16 13:10:06 +02:00
|
|
|
return d->m_displaySettings;
|
2009-01-27 15:12:32 +01:00
|
|
|
}
|
|
|
|
|
|
2014-01-09 14:44:25 +01:00
|
|
|
const MarginSettings &DisplaySettingsPage::marginSettings() const
|
|
|
|
|
{
|
|
|
|
|
return d->m_marginSettings;
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-10 11:46:56 +01:00
|
|
|
void DisplaySettingsWidget::setDisplaySettings(const DisplaySettings &newDisplaySettings,
|
|
|
|
|
const MarginSettings &newMarginSettings)
|
2009-01-27 15:12:32 +01:00
|
|
|
{
|
2020-02-10 11:46:56 +01:00
|
|
|
if (newDisplaySettings != m_data->m_displaySettings) {
|
|
|
|
|
m_data->m_displaySettings = newDisplaySettings;
|
|
|
|
|
m_data->m_displaySettings.toSettings(m_data->m_settingsPrefix, Core::ICore::settings());
|
2009-01-27 15:12:32 +01:00
|
|
|
|
2020-02-03 08:54:44 +01:00
|
|
|
emit TextEditorSettings::instance()->displaySettingsChanged(newDisplaySettings);
|
2009-01-27 15:12:32 +01:00
|
|
|
}
|
2014-01-09 14:44:25 +01:00
|
|
|
|
2020-02-10 11:46:56 +01:00
|
|
|
if (newMarginSettings != m_data->m_marginSettings) {
|
|
|
|
|
m_data->m_marginSettings = newMarginSettings;
|
|
|
|
|
m_data->m_marginSettings.toSettings(m_data->m_settingsPrefix, Core::ICore::settings());
|
2014-01-09 14:44:25 +01:00
|
|
|
|
2020-02-03 08:54:44 +01:00
|
|
|
emit TextEditorSettings::instance()->marginSettingsChanged(newMarginSettings);
|
2014-01-09 14:44:25 +01:00
|
|
|
}
|
2009-01-27 15:12:32 +01:00
|
|
|
}
|
2020-01-21 15:20:02 +01:00
|
|
|
|
2020-02-10 11:46:56 +01:00
|
|
|
DisplaySettingsPage::DisplaySettingsPage()
|
|
|
|
|
: d(new DisplaySettingsPagePrivate)
|
|
|
|
|
{
|
|
|
|
|
setId(Constants::TEXT_EDITOR_DISPLAY_SETTINGS);
|
|
|
|
|
setDisplayName(DisplaySettingsWidget::tr("Display"));
|
|
|
|
|
setCategory(TextEditor::Constants::TEXT_EDITOR_SETTINGS_CATEGORY);
|
|
|
|
|
setDisplayCategory(QCoreApplication::translate("TextEditor", "Text Editor"));
|
|
|
|
|
setCategoryIconPath(TextEditor::Constants::TEXT_EDITOR_SETTINGS_CATEGORY_ICON_PATH);
|
|
|
|
|
setWidgetCreator([this] { return new DisplaySettingsWidget(d); });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DisplaySettingsPage::~DisplaySettingsPage()
|
|
|
|
|
{
|
|
|
|
|
delete d;
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-21 15:20:02 +01:00
|
|
|
} // TextEditor
|