forked from qt-creator/qt-creator
Re-introduction of the feature to adjust the line spacing
This already has been implemented in changedc64f3207b, but was reverted with changef220cb0e23) because this does not work with text wrapping rendering, due to internal limitations of Qt. Since this is a highly requested feature (e.g. QTCREATORBUG-13727), but an internal change within Qt is not in sight, the approach taken here is to offer the text wrapping feature in the settings only when the line spacing is set to 100%. Additionally, a change has been made to the layout of the display settings page to reflect this. Fixes: QTCREATORBUG-13727 Change-Id: Ib233cf90a5f336bc591fa1bf860e162fa774dfe3 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -306,7 +306,7 @@ private:
|
|||||||
{
|
{
|
||||||
QTextCursor tc = m_editor->textCursor();
|
QTextCursor tc = m_editor->textCursor();
|
||||||
m_currentPos = tc.position();
|
m_currentPos = tc.position();
|
||||||
m_lineSpacing = m_editor->cursorRect(tc).height();
|
m_lineSpacing = m_editor->document()->documentLayout()->blockBoundingRect(tc.block()).height();
|
||||||
setFont(m_editor->extraArea()->font());
|
setFont(m_editor->extraArea()->font());
|
||||||
|
|
||||||
// Follow geometry of normal line numbers if visible,
|
// Follow geometry of normal line numbers if visible,
|
||||||
|
|||||||
@@ -10,11 +10,13 @@
|
|||||||
|
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
|
|
||||||
|
|
||||||
#include <utils/layoutbuilder.h>
|
#include <utils/layoutbuilder.h>
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QCheckBox>
|
#include <QCheckBox>
|
||||||
#include <QGroupBox>
|
#include <QGroupBox>
|
||||||
|
#include <QLabel>
|
||||||
#include <QRadioButton>
|
#include <QRadioButton>
|
||||||
#include <QSpinBox>
|
#include <QSpinBox>
|
||||||
|
|
||||||
@@ -46,6 +48,31 @@ public:
|
|||||||
resize(452, 458);
|
resize(452, 458);
|
||||||
|
|
||||||
enableTextWrapping = new QCheckBox(tr("Enable text &wrapping"));
|
enableTextWrapping = new QCheckBox(tr("Enable text &wrapping"));
|
||||||
|
|
||||||
|
enableTextWrappingHintLabel = new QLabel(tr("<i>Set <a href=\"font zoom\">font line spacing</a> "
|
||||||
|
"to 100% to enable text wrapping option.</i>"));
|
||||||
|
|
||||||
|
fontSettingsPageLineSpacing = fontSettingsPageLineSpacingLink();
|
||||||
|
|
||||||
|
if (fontSettingsPageLineSpacing) {
|
||||||
|
connect(fontSettingsPageLineSpacing, QOverload<int>::of(&QSpinBox::valueChanged),
|
||||||
|
[=](const int &value) {
|
||||||
|
if (value != 100)
|
||||||
|
enableTextWrapping->setChecked(false);
|
||||||
|
enableTextWrapping->setEnabled(value == 100);
|
||||||
|
enableTextWrappingHintLabel->setVisible(value != 100); } );
|
||||||
|
|
||||||
|
if (fontSettingsPageLineSpacing->value() != 100)
|
||||||
|
enableTextWrapping->setChecked(false);
|
||||||
|
|
||||||
|
enableTextWrapping->setEnabled(fontSettingsPageLineSpacing->value() == 100);
|
||||||
|
enableTextWrappingHintLabel->setVisible(fontSettingsPageLineSpacing->value() != 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
connect(enableTextWrappingHintLabel, &QLabel::linkActivated, []() {
|
||||||
|
Core::ICore::showOptionsDialog(Constants::TEXT_EDITOR_FONT_SETTINGS); } );
|
||||||
|
|
||||||
|
|
||||||
showWrapColumn = new QCheckBox(tr("Display right &margin at column:"));
|
showWrapColumn = new QCheckBox(tr("Display right &margin at column:"));
|
||||||
tintMarginArea = new QCheckBox(tr("Tint whole margin area"));
|
tintMarginArea = new QCheckBox(tr("Tint whole margin area"));
|
||||||
|
|
||||||
@@ -98,13 +125,19 @@ public:
|
|||||||
|
|
||||||
Column {
|
Column {
|
||||||
Group {
|
Group {
|
||||||
title(tr("Text Wrapping")),
|
title(tr("Margin")),
|
||||||
Column {
|
Column {
|
||||||
enableTextWrapping,
|
Row { showWrapColumn, wrapColumn, st },
|
||||||
Row { showWrapColumn, wrapColumn, useIndenter, tintMarginArea, st }
|
Row { useIndenter, tintMarginArea, st }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Group {
|
||||||
|
title(tr("Wrapping")),
|
||||||
|
Column {
|
||||||
|
enableTextWrapping,
|
||||||
|
Row { enableTextWrappingHintLabel, st}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
Group {
|
Group {
|
||||||
title(tr("Display")),
|
title(tr("Display")),
|
||||||
Row {
|
Row {
|
||||||
@@ -145,9 +178,12 @@ public:
|
|||||||
void settingsToUI();
|
void settingsToUI();
|
||||||
void setDisplaySettings(const DisplaySettings &, const MarginSettings &newMarginSettings);
|
void setDisplaySettings(const DisplaySettings &, const MarginSettings &newMarginSettings);
|
||||||
|
|
||||||
|
QSpinBox *fontSettingsPageLineSpacingLink();
|
||||||
|
|
||||||
DisplaySettingsPagePrivate *m_data = nullptr;
|
DisplaySettingsPagePrivate *m_data = nullptr;
|
||||||
|
|
||||||
QCheckBox *enableTextWrapping;
|
QCheckBox *enableTextWrapping;
|
||||||
|
QLabel *enableTextWrappingHintLabel;
|
||||||
QCheckBox *showWrapColumn;
|
QCheckBox *showWrapColumn;
|
||||||
QCheckBox *tintMarginArea;
|
QCheckBox *tintMarginArea;
|
||||||
QSpinBox *wrapColumn;
|
QSpinBox *wrapColumn;
|
||||||
@@ -173,6 +209,8 @@ public:
|
|||||||
QRadioButton *atMargin;
|
QRadioButton *atMargin;
|
||||||
QRadioButton *rightAligned;
|
QRadioButton *rightAligned;
|
||||||
QRadioButton *betweenLines;
|
QRadioButton *betweenLines;
|
||||||
|
|
||||||
|
QSpinBox *fontSettingsPageLineSpacing = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
void DisplaySettingsWidget::apply()
|
void DisplaySettingsWidget::apply()
|
||||||
@@ -189,6 +227,10 @@ void DisplaySettingsWidget::settingsFromUI(DisplaySettings &displaySettings,
|
|||||||
{
|
{
|
||||||
displaySettings.m_displayLineNumbers = displayLineNumbers->isChecked();
|
displaySettings.m_displayLineNumbers = displayLineNumbers->isChecked();
|
||||||
displaySettings.m_textWrapping = enableTextWrapping->isChecked();
|
displaySettings.m_textWrapping = enableTextWrapping->isChecked();
|
||||||
|
if (fontSettingsPageLineSpacing) {
|
||||||
|
if (fontSettingsPageLineSpacing->value() != 100)
|
||||||
|
displaySettings.m_textWrapping = false;
|
||||||
|
}
|
||||||
marginSettings.m_showMargin = showWrapColumn->isChecked();
|
marginSettings.m_showMargin = showWrapColumn->isChecked();
|
||||||
marginSettings.m_tintMarginArea = tintMarginArea->isChecked();
|
marginSettings.m_tintMarginArea = tintMarginArea->isChecked();
|
||||||
marginSettings.m_useIndenter = useIndenter->isChecked();
|
marginSettings.m_useIndenter = useIndenter->isChecked();
|
||||||
@@ -281,6 +323,23 @@ void DisplaySettingsWidget::setDisplaySettings(const DisplaySettings &newDisplay
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QSpinBox *DisplaySettingsWidget::fontSettingsPageLineSpacingLink()
|
||||||
|
{
|
||||||
|
for (const auto &page : Core::IOptionsPage::allOptionsPages()) {
|
||||||
|
QWidget *widget = page->widget();
|
||||||
|
|
||||||
|
if (!widget)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
for (QSpinBox *spinBox : widget->findChildren<QSpinBox *>()) {
|
||||||
|
if (spinBox->objectName() == QLatin1String("FontSettingsPage.LineSpacingSpinBox"))
|
||||||
|
return spinBox;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
DisplaySettingsPage::DisplaySettingsPage()
|
DisplaySettingsPage::DisplaySettingsPage()
|
||||||
: d(new DisplaySettingsPagePrivate)
|
: d(new DisplaySettingsPagePrivate)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
static const char fontFamilyKey[] = "FontFamily";
|
static const char fontFamilyKey[] = "FontFamily";
|
||||||
static const char fontSizeKey[] = "FontSize";
|
static const char fontSizeKey[] = "FontSize";
|
||||||
static const char fontZoomKey[] = "FontZoom";
|
static const char fontZoomKey[] = "FontZoom";
|
||||||
|
static const char lineSpacingKey[] = "LineSpacing";
|
||||||
static const char antialiasKey[] = "FontAntialias";
|
static const char antialiasKey[] = "FontAntialias";
|
||||||
static const char schemeFileNamesKey[] = "ColorSchemes";
|
static const char schemeFileNamesKey[] = "ColorSchemes";
|
||||||
|
|
||||||
@@ -38,7 +39,9 @@ FontSettings::FontSettings() :
|
|||||||
m_family(defaultFixedFontFamily()),
|
m_family(defaultFixedFontFamily()),
|
||||||
m_fontSize(defaultFontSize()),
|
m_fontSize(defaultFontSize()),
|
||||||
m_fontZoom(100),
|
m_fontZoom(100),
|
||||||
m_antialias(DEFAULT_ANTIALIAS)
|
m_lineSpacing(100),
|
||||||
|
m_antialias(DEFAULT_ANTIALIAS),
|
||||||
|
m_lineSpacingCache(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,10 +50,10 @@ void FontSettings::clear()
|
|||||||
m_family = defaultFixedFontFamily();
|
m_family = defaultFixedFontFamily();
|
||||||
m_fontSize = defaultFontSize();
|
m_fontSize = defaultFontSize();
|
||||||
m_fontZoom = 100;
|
m_fontZoom = 100;
|
||||||
|
m_lineSpacing = 100;
|
||||||
m_antialias = DEFAULT_ANTIALIAS;
|
m_antialias = DEFAULT_ANTIALIAS;
|
||||||
m_scheme.clear();
|
m_scheme.clear();
|
||||||
m_formatCache.clear();
|
clearCaches();
|
||||||
m_textCharFormatCache.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static QString settingsGroup()
|
static QString settingsGroup()
|
||||||
@@ -70,6 +73,9 @@ void FontSettings::toSettings(QSettings *s) const
|
|||||||
if (m_fontZoom!= 100 || s->contains(QLatin1String(fontZoomKey)))
|
if (m_fontZoom!= 100 || s->contains(QLatin1String(fontZoomKey)))
|
||||||
s->setValue(QLatin1String(fontZoomKey), m_fontZoom);
|
s->setValue(QLatin1String(fontZoomKey), m_fontZoom);
|
||||||
|
|
||||||
|
if (m_lineSpacing != 100 || s->contains(QLatin1String(lineSpacingKey)))
|
||||||
|
s->setValue(QLatin1String(lineSpacingKey), m_lineSpacing);
|
||||||
|
|
||||||
if (m_antialias != DEFAULT_ANTIALIAS || s->contains(QLatin1String(antialiasKey)))
|
if (m_antialias != DEFAULT_ANTIALIAS || s->contains(QLatin1String(antialiasKey)))
|
||||||
s->setValue(QLatin1String(antialiasKey), m_antialias);
|
s->setValue(QLatin1String(antialiasKey), m_antialias);
|
||||||
|
|
||||||
@@ -95,6 +101,7 @@ bool FontSettings::fromSettings(const FormatDescriptions &descriptions, const QS
|
|||||||
m_family = s->value(group + QLatin1String(fontFamilyKey), defaultFixedFontFamily()).toString();
|
m_family = s->value(group + QLatin1String(fontFamilyKey), defaultFixedFontFamily()).toString();
|
||||||
m_fontSize = s->value(group + QLatin1String(fontSizeKey), m_fontSize).toInt();
|
m_fontSize = s->value(group + QLatin1String(fontSizeKey), m_fontSize).toInt();
|
||||||
m_fontZoom= s->value(group + QLatin1String(fontZoomKey), m_fontZoom).toInt();
|
m_fontZoom= s->value(group + QLatin1String(fontZoomKey), m_fontZoom).toInt();
|
||||||
|
m_lineSpacing = s->value(group + QLatin1String(lineSpacingKey), m_lineSpacing).toInt();
|
||||||
m_antialias = s->value(group + QLatin1String(antialiasKey), DEFAULT_ANTIALIAS).toBool();
|
m_antialias = s->value(group + QLatin1String(antialiasKey), DEFAULT_ANTIALIAS).toBool();
|
||||||
|
|
||||||
if (s->contains(group + QLatin1String(schemeFileNamesKey))) {
|
if (s->contains(group + QLatin1String(schemeFileNamesKey))) {
|
||||||
@@ -114,6 +121,7 @@ bool FontSettings::equals(const FontSettings &f) const
|
|||||||
return m_family == f.m_family
|
return m_family == f.m_family
|
||||||
&& m_schemeFileName == f.m_schemeFileName
|
&& m_schemeFileName == f.m_schemeFileName
|
||||||
&& m_fontSize == f.m_fontSize
|
&& m_fontSize == f.m_fontSize
|
||||||
|
&& m_lineSpacing == f.m_lineSpacing
|
||||||
&& m_fontZoom == f.m_fontZoom
|
&& m_fontZoom == f.m_fontZoom
|
||||||
&& m_antialias == f.m_antialias
|
&& m_antialias == f.m_antialias
|
||||||
&& m_scheme == f.m_scheme;
|
&& m_scheme == f.m_scheme;
|
||||||
@@ -250,6 +258,13 @@ void FontSettings::addMixinStyle(QTextCharFormat &textCharFormat,
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FontSettings::clearCaches()
|
||||||
|
{
|
||||||
|
m_formatCache.clear();
|
||||||
|
m_textCharFormatCache.clear();
|
||||||
|
m_lineSpacingCache = 0;
|
||||||
|
}
|
||||||
|
|
||||||
QTextCharFormat FontSettings::toTextCharFormat(TextStyles textStyles) const
|
QTextCharFormat FontSettings::toTextCharFormat(TextStyles textStyles) const
|
||||||
{
|
{
|
||||||
auto textCharFormatIterator = m_textCharFormatCache.find(textStyles);
|
auto textCharFormatIterator = m_textCharFormatCache.find(textStyles);
|
||||||
@@ -290,8 +305,7 @@ QString FontSettings::family() const
|
|||||||
void FontSettings::setFamily(const QString &family)
|
void FontSettings::setFamily(const QString &family)
|
||||||
{
|
{
|
||||||
m_family = family;
|
m_family = family;
|
||||||
m_formatCache.clear();
|
clearCaches();
|
||||||
m_textCharFormatCache.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -305,8 +319,7 @@ int FontSettings::fontSize() const
|
|||||||
void FontSettings::setFontSize(int size)
|
void FontSettings::setFontSize(int size)
|
||||||
{
|
{
|
||||||
m_fontSize = size;
|
m_fontSize = size;
|
||||||
m_formatCache.clear();
|
clearCaches();
|
||||||
m_textCharFormatCache.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -320,8 +333,33 @@ int FontSettings::fontZoom() const
|
|||||||
void FontSettings::setFontZoom(int zoom)
|
void FontSettings::setFontZoom(int zoom)
|
||||||
{
|
{
|
||||||
m_fontZoom = zoom;
|
m_fontZoom = zoom;
|
||||||
m_formatCache.clear();
|
clearCaches();
|
||||||
m_textCharFormatCache.clear();
|
}
|
||||||
|
|
||||||
|
qreal FontSettings::lineSpacing() const
|
||||||
|
{
|
||||||
|
if (m_lineSpacing == 100) {
|
||||||
|
QFontMetricsF fm(font());
|
||||||
|
return fm.lineSpacing();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (qFuzzyIsNull(m_lineSpacingCache)) {
|
||||||
|
auto currentFont = font();
|
||||||
|
currentFont.setPointSize(m_fontSize * m_fontZoom / 100);
|
||||||
|
m_lineSpacingCache = QFontMetricsF(currentFont).lineSpacing() / 100 * m_lineSpacing;
|
||||||
|
}
|
||||||
|
return m_lineSpacingCache;
|
||||||
|
}
|
||||||
|
|
||||||
|
int FontSettings::relativeLineSpacing() const
|
||||||
|
{
|
||||||
|
return m_lineSpacing;
|
||||||
|
}
|
||||||
|
|
||||||
|
void FontSettings::setRelativeLineSpacing(int relativeLineSpacing)
|
||||||
|
{
|
||||||
|
m_lineSpacing = relativeLineSpacing;
|
||||||
|
m_lineSpacingCache = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
QFont FontSettings::font() const
|
QFont FontSettings::font() const
|
||||||
@@ -342,8 +380,7 @@ bool FontSettings::antialias() const
|
|||||||
void FontSettings::setAntialias(bool antialias)
|
void FontSettings::setAntialias(bool antialias)
|
||||||
{
|
{
|
||||||
m_antialias = antialias;
|
m_antialias = antialias;
|
||||||
m_formatCache.clear();
|
clearCaches();
|
||||||
m_textCharFormatCache.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -380,8 +417,8 @@ void FontSettings::setColorSchemeFileName(const QString &fileName)
|
|||||||
bool FontSettings::loadColorScheme(const QString &fileName,
|
bool FontSettings::loadColorScheme(const QString &fileName,
|
||||||
const FormatDescriptions &descriptions)
|
const FormatDescriptions &descriptions)
|
||||||
{
|
{
|
||||||
m_formatCache.clear();
|
clearCaches();
|
||||||
m_textCharFormatCache.clear();
|
|
||||||
bool loaded = true;
|
bool loaded = true;
|
||||||
m_schemeFileName = fileName;
|
m_schemeFileName = fileName;
|
||||||
|
|
||||||
@@ -445,8 +482,7 @@ const ColorScheme &FontSettings::colorScheme() const
|
|||||||
void FontSettings::setColorScheme(const ColorScheme &scheme)
|
void FontSettings::setColorScheme(const ColorScheme &scheme)
|
||||||
{
|
{
|
||||||
m_scheme = scheme;
|
m_scheme = scheme;
|
||||||
m_formatCache.clear();
|
clearCaches();
|
||||||
m_textCharFormatCache.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static QString defaultFontFamily()
|
static QString defaultFontFamily()
|
||||||
|
|||||||
@@ -53,6 +53,10 @@ public:
|
|||||||
int fontZoom() const;
|
int fontZoom() const;
|
||||||
void setFontZoom(int zoom);
|
void setFontZoom(int zoom);
|
||||||
|
|
||||||
|
qreal lineSpacing() const;
|
||||||
|
int relativeLineSpacing() const;
|
||||||
|
void setRelativeLineSpacing(int relativeLineSpacing);
|
||||||
|
|
||||||
QFont font() const;
|
QFont font() const;
|
||||||
|
|
||||||
bool antialias() const;
|
bool antialias() const;
|
||||||
@@ -81,16 +85,19 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void addMixinStyle(QTextCharFormat &textCharFormat, const MixinTextStyles &mixinStyles) const;
|
void addMixinStyle(QTextCharFormat &textCharFormat, const MixinTextStyles &mixinStyles) const;
|
||||||
|
void clearCaches();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_family;
|
QString m_family;
|
||||||
QString m_schemeFileName;
|
QString m_schemeFileName;
|
||||||
int m_fontSize;
|
int m_fontSize;
|
||||||
int m_fontZoom;
|
int m_fontZoom;
|
||||||
|
int m_lineSpacing;
|
||||||
bool m_antialias;
|
bool m_antialias;
|
||||||
ColorScheme m_scheme;
|
ColorScheme m_scheme;
|
||||||
mutable QHash<TextStyle, QTextCharFormat> m_formatCache;
|
mutable QHash<TextStyle, QTextCharFormat> m_formatCache;
|
||||||
mutable QHash<TextStyles, QTextCharFormat> m_textCharFormatCache;
|
mutable QHash<TextStyles, QTextCharFormat> m_textCharFormatCache;
|
||||||
|
mutable qreal m_lineSpacingCache;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace TextEditor
|
} // namespace TextEditor
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/stringutils.h>
|
#include <utils/stringutils.h>
|
||||||
#include <utils/theme/theme.h>
|
#include <utils/theme/theme.h>
|
||||||
|
#include <utils/utilsicons.h>
|
||||||
|
|
||||||
#include <QAbstractItemModel>
|
#include <QAbstractItemModel>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
@@ -124,6 +125,19 @@ public:
|
|||||||
m_zoomSpinBox->setSingleStep(10);
|
m_zoomSpinBox->setSingleStep(10);
|
||||||
m_zoomSpinBox->setValue(m_value.fontZoom());
|
m_zoomSpinBox->setValue(m_value.fontZoom());
|
||||||
|
|
||||||
|
m_lineSpacingSpinBox = new QSpinBox;
|
||||||
|
m_lineSpacingSpinBox->setObjectName(QLatin1String("FontSettingsPage.LineSpacingSpinBox"));
|
||||||
|
m_lineSpacingSpinBox->setSuffix(tr("%"));
|
||||||
|
m_lineSpacingSpinBox->setRange(50, 3000);
|
||||||
|
m_lineSpacingSpinBox->setValue(m_value.relativeLineSpacing());
|
||||||
|
|
||||||
|
m_lineSpacingWarningLabel = new QLabel;
|
||||||
|
m_lineSpacingWarningLabel->setPixmap(Utils::Icons::WARNING.pixmap());
|
||||||
|
m_lineSpacingWarningLabel->setToolTip(tr("A line spacing value other than 100% disables "
|
||||||
|
"text wrapping.\nA value less than 100% can result "
|
||||||
|
"in overlapping and misaligned graphics."));
|
||||||
|
m_lineSpacingWarningLabel->setVisible(m_value.relativeLineSpacing() != 100);
|
||||||
|
|
||||||
m_fontComboBox = new QFontComboBox;
|
m_fontComboBox = new QFontComboBox;
|
||||||
m_fontComboBox->setCurrentFont(m_value.family());
|
m_fontComboBox->setCurrentFont(m_value.family());
|
||||||
|
|
||||||
@@ -159,7 +173,8 @@ public:
|
|||||||
Row {
|
Row {
|
||||||
tr("Family:"), m_fontComboBox, Space(20),
|
tr("Family:"), m_fontComboBox, Space(20),
|
||||||
tr("Size:"), m_sizeComboBox, Space(20),
|
tr("Size:"), m_sizeComboBox, Space(20),
|
||||||
tr("Zoom:"), m_zoomSpinBox, st
|
tr("Zoom:"), m_zoomSpinBox, Space(20),
|
||||||
|
tr("Line spacing:"), m_lineSpacingSpinBox, m_lineSpacingWarningLabel, st
|
||||||
},
|
},
|
||||||
m_antialias
|
m_antialias
|
||||||
}
|
}
|
||||||
@@ -183,6 +198,8 @@ public:
|
|||||||
this, &FontSettingsPageWidget::fontZoomChanged);
|
this, &FontSettingsPageWidget::fontZoomChanged);
|
||||||
connect(m_antialias, &QCheckBox::toggled,
|
connect(m_antialias, &QCheckBox::toggled,
|
||||||
this, &FontSettingsPageWidget::antialiasChanged);
|
this, &FontSettingsPageWidget::antialiasChanged);
|
||||||
|
connect(m_lineSpacingSpinBox, QOverload<int>::of(&QSpinBox::valueChanged),
|
||||||
|
this, &FontSettingsPageWidget::lineSpacingChanged);
|
||||||
connect(m_schemeComboBox, &QComboBox::currentIndexChanged,
|
connect(m_schemeComboBox, &QComboBox::currentIndexChanged,
|
||||||
this, &FontSettingsPageWidget::colorSchemeSelected);
|
this, &FontSettingsPageWidget::colorSchemeSelected);
|
||||||
connect(m_copyButton, &QPushButton::clicked,
|
connect(m_copyButton, &QPushButton::clicked,
|
||||||
@@ -207,6 +224,7 @@ public:
|
|||||||
void fontSelected(const QFont &font);
|
void fontSelected(const QFont &font);
|
||||||
void fontSizeSelected(int index);
|
void fontSizeSelected(int index);
|
||||||
void fontZoomChanged();
|
void fontZoomChanged();
|
||||||
|
void lineSpacingChanged(const int &value);
|
||||||
void antialiasChanged();
|
void antialiasChanged();
|
||||||
void colorSchemeSelected(int index);
|
void colorSchemeSelected(int index);
|
||||||
void openCopyColorSchemeDialog();
|
void openCopyColorSchemeDialog();
|
||||||
@@ -230,6 +248,8 @@ public:
|
|||||||
|
|
||||||
QCheckBox *m_antialias;
|
QCheckBox *m_antialias;
|
||||||
QSpinBox *m_zoomSpinBox;
|
QSpinBox *m_zoomSpinBox;
|
||||||
|
QSpinBox *m_lineSpacingSpinBox;
|
||||||
|
QLabel *m_lineSpacingWarningLabel;
|
||||||
QFontComboBox *m_fontComboBox;
|
QFontComboBox *m_fontComboBox;
|
||||||
QComboBox *m_sizeComboBox;
|
QComboBox *m_sizeComboBox;
|
||||||
QComboBox *m_schemeComboBox;
|
QComboBox *m_schemeComboBox;
|
||||||
@@ -478,6 +498,12 @@ void FontSettingsPageWidget::antialiasChanged()
|
|||||||
m_schemeEdit->setBaseFont(m_value.font());
|
m_schemeEdit->setBaseFont(m_value.font());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FontSettingsPageWidget::lineSpacingChanged(const int &value)
|
||||||
|
{
|
||||||
|
m_value.setRelativeLineSpacing(value);
|
||||||
|
m_lineSpacingWarningLabel->setVisible(value != 100);
|
||||||
|
}
|
||||||
|
|
||||||
void FontSettingsPageWidget::colorSchemeSelected(int index)
|
void FontSettingsPageWidget::colorSchemeSelected(int index)
|
||||||
{
|
{
|
||||||
bool readOnly = true;
|
bool readOnly = true;
|
||||||
|
|||||||
@@ -2,7 +2,9 @@
|
|||||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
||||||
|
|
||||||
#include "textdocumentlayout.h"
|
#include "textdocumentlayout.h"
|
||||||
|
#include "fontsettings.h"
|
||||||
#include "textdocument.h"
|
#include "textdocument.h"
|
||||||
|
#include "texteditorsettings.h"
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
@@ -633,6 +635,13 @@ void TextDocumentLayout::requestUpdateNow()
|
|||||||
QRectF TextDocumentLayout::blockBoundingRect(const QTextBlock &block) const
|
QRectF TextDocumentLayout::blockBoundingRect(const QTextBlock &block) const
|
||||||
{
|
{
|
||||||
QRectF boundingRect = QPlainTextDocumentLayout::blockBoundingRect(block);
|
QRectF boundingRect = QPlainTextDocumentLayout::blockBoundingRect(block);
|
||||||
|
|
||||||
|
if (TextEditorSettings::fontSettings().relativeLineSpacing() != 100) {
|
||||||
|
if (boundingRect.isNull())
|
||||||
|
return boundingRect;
|
||||||
|
boundingRect.setHeight(TextEditorSettings::fontSettings().lineSpacing());
|
||||||
|
}
|
||||||
|
|
||||||
if (TextBlockUserData *userData = textUserData(block))
|
if (TextBlockUserData *userData = textUserData(block))
|
||||||
boundingRect.adjust(0, 0, 0, userData->additionalAnnotationHeight());
|
boundingRect.adjust(0, 0, 0, userData->additionalAnnotationHeight());
|
||||||
return boundingRect;
|
return boundingRect;
|
||||||
|
|||||||
@@ -1227,6 +1227,12 @@ static int foldBoxWidth(const QFontMetrics &fm)
|
|||||||
return lineSpacing + lineSpacing % 2 + 1;
|
return lineSpacing + lineSpacing % 2 + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int foldBoxWidth()
|
||||||
|
{
|
||||||
|
const int lineSpacing = TextEditorSettings::fontSettings().lineSpacing();
|
||||||
|
return lineSpacing + lineSpacing % 2 + 1;
|
||||||
|
}
|
||||||
|
|
||||||
static void printPage(int index, QPainter *painter, const QTextDocument *doc,
|
static void printPage(int index, QPainter *painter, const QTextDocument *doc,
|
||||||
const QRectF &body, const QRectF &titleBox,
|
const QRectF &body, const QRectF &titleBox,
|
||||||
const QString &title)
|
const QString &title)
|
||||||
@@ -3657,10 +3663,18 @@ QRect TextEditorWidgetPrivate::foldBox()
|
|||||||
QRectF br = q->blockBoundingGeometry(begin).translated(q->contentOffset());
|
QRectF br = q->blockBoundingGeometry(begin).translated(q->contentOffset());
|
||||||
QRectF er = q->blockBoundingGeometry(end).translated(q->contentOffset());
|
QRectF er = q->blockBoundingGeometry(end).translated(q->contentOffset());
|
||||||
|
|
||||||
|
|
||||||
|
if (TextEditorSettings::fontSettings().relativeLineSpacing() == 100) {
|
||||||
return QRect(m_extraArea->width() - foldBoxWidth(q->fontMetrics()),
|
return QRect(m_extraArea->width() - foldBoxWidth(q->fontMetrics()),
|
||||||
int(br.top()),
|
int(br.top()),
|
||||||
foldBoxWidth(q->fontMetrics()),
|
foldBoxWidth(q->fontMetrics()),
|
||||||
int(er.bottom() - br.top()));
|
int(er.bottom() - br.top()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return QRect(m_extraArea->width() - foldBoxWidth(),
|
||||||
|
int(br.top()),
|
||||||
|
foldBoxWidth(),
|
||||||
|
int(er.bottom() - br.top()));
|
||||||
}
|
}
|
||||||
|
|
||||||
QTextBlock TextEditorWidgetPrivate::foldedBlockAt(const QPoint &pos, QRect *box) const
|
QTextBlock TextEditorWidgetPrivate::foldedBlockAt(const QPoint &pos, QRect *box) const
|
||||||
@@ -3950,7 +3964,15 @@ bool TextEditorWidgetPrivate::updateAnnotationBounds(TextBlockUserData *blockUse
|
|||||||
{
|
{
|
||||||
const bool additionalHeightNeeded = annotationsVisible
|
const bool additionalHeightNeeded = annotationsVisible
|
||||||
&& m_displaySettings.m_annotationAlignment == AnnotationAlignment::BetweenLines;
|
&& m_displaySettings.m_annotationAlignment == AnnotationAlignment::BetweenLines;
|
||||||
const int additionalHeight = additionalHeightNeeded ? q->fontMetrics().lineSpacing() : 0;
|
|
||||||
|
int additionalHeight = 0;
|
||||||
|
if (additionalHeightNeeded) {
|
||||||
|
if (TextEditorSettings::fontSettings().relativeLineSpacing() == 100)
|
||||||
|
additionalHeight = q->fontMetrics().lineSpacing();
|
||||||
|
else
|
||||||
|
TextEditorSettings::fontSettings().lineSpacing();
|
||||||
|
}
|
||||||
|
|
||||||
if (blockUserData->additionalAnnotationHeight() == additionalHeight)
|
if (blockUserData->additionalAnnotationHeight() == additionalHeight)
|
||||||
return false;
|
return false;
|
||||||
blockUserData->setAdditionalAnnotationHeight(additionalHeight);
|
blockUserData->setAdditionalAnnotationHeight(additionalHeight);
|
||||||
@@ -3991,7 +4013,13 @@ void TextEditorWidgetPrivate::updateLineAnnotation(const PaintEventData &data,
|
|||||||
return mark1->priority() > mark2->priority();
|
return mark1->priority() > mark2->priority();
|
||||||
});
|
});
|
||||||
|
|
||||||
const qreal itemOffset = q->fontMetrics().lineSpacing();
|
qreal itemOffset = 0.0;
|
||||||
|
if (TextEditorSettings::fontSettings().relativeLineSpacing() == 100)
|
||||||
|
itemOffset = q->fontMetrics().lineSpacing();
|
||||||
|
else
|
||||||
|
itemOffset = blockData.boundingRect.height();
|
||||||
|
|
||||||
|
|
||||||
const qreal initialOffset = m_displaySettings.m_annotationAlignment == AnnotationAlignment::BetweenLines ? itemOffset / 2 : itemOffset * 2;
|
const qreal initialOffset = m_displaySettings.m_annotationAlignment == AnnotationAlignment::BetweenLines ? itemOffset / 2 : itemOffset * 2;
|
||||||
const qreal minimalContentWidth = q->fontMetrics().horizontalAdvance('X')
|
const qreal minimalContentWidth = q->fontMetrics().horizontalAdvance('X')
|
||||||
* m_displaySettings.m_minimalAnnotationContent;
|
* m_displaySettings.m_minimalAnnotationContent;
|
||||||
@@ -4821,7 +4849,10 @@ int TextEditorWidget::extraAreaWidth(int *markWidthPtr) const
|
|||||||
int markWidth = 0;
|
int markWidth = 0;
|
||||||
|
|
||||||
if (d->m_marksVisible) {
|
if (d->m_marksVisible) {
|
||||||
|
if (TextEditorSettings::fontSettings().relativeLineSpacing() == 100)
|
||||||
markWidth += fm.lineSpacing() + 2;
|
markWidth += fm.lineSpacing() + 2;
|
||||||
|
else
|
||||||
|
markWidth += TextEditorSettings::fontSettings().lineSpacing() + 2;
|
||||||
|
|
||||||
// if (documentLayout->doubleMarkCount)
|
// if (documentLayout->doubleMarkCount)
|
||||||
// markWidth += fm.lineSpacing() / 3;
|
// markWidth += fm.lineSpacing() / 3;
|
||||||
@@ -4835,8 +4866,12 @@ int TextEditorWidget::extraAreaWidth(int *markWidthPtr) const
|
|||||||
|
|
||||||
space += 4;
|
space += 4;
|
||||||
|
|
||||||
if (d->m_codeFoldingVisible)
|
if (d->m_codeFoldingVisible) {
|
||||||
|
if (TextEditorSettings::fontSettings().relativeLineSpacing() == 100)
|
||||||
space += foldBoxWidth(fm);
|
space += foldBoxWidth(fm);
|
||||||
|
else
|
||||||
|
space += foldBoxWidth();
|
||||||
|
}
|
||||||
|
|
||||||
if (viewportMargins() != QMargins{isLeftToRight() ? space : 0, 0, isLeftToRight() ? 0 : space, 0})
|
if (viewportMargins() != QMargins{isLeftToRight() ? space : 0, 0, isLeftToRight() ? 0 : space, 0})
|
||||||
d->slotUpdateExtraAreaWidth(space);
|
d->slotUpdateExtraAreaWidth(space);
|
||||||
@@ -4870,6 +4905,11 @@ struct Internal::ExtraAreaPaintEventData
|
|||||||
editor->textDocument()->fontSettings().toTextCharFormat(C_CURRENT_LINE_NUMBER))
|
editor->textDocument()->fontSettings().toTextCharFormat(C_CURRENT_LINE_NUMBER))
|
||||||
, palette(d->m_extraArea->palette())
|
, palette(d->m_extraArea->palette())
|
||||||
{
|
{
|
||||||
|
if (TextEditorSettings::fontSettings().relativeLineSpacing() != 100) {
|
||||||
|
lineSpacing = TextEditorSettings::fontSettings().lineSpacing();
|
||||||
|
collapseColumnWidth = d->m_codeFoldingVisible ? foldBoxWidth() : 0;
|
||||||
|
markWidth = d->m_marksVisible ? lineSpacing : 0;
|
||||||
|
}
|
||||||
palette.setCurrentColorGroup(QPalette::Active);
|
palette.setCurrentColorGroup(QPalette::Active);
|
||||||
}
|
}
|
||||||
QTextBlock block;
|
QTextBlock block;
|
||||||
@@ -4878,9 +4918,9 @@ struct Internal::ExtraAreaPaintEventData
|
|||||||
const int selectionStart;
|
const int selectionStart;
|
||||||
const int selectionEnd;
|
const int selectionEnd;
|
||||||
const QFontMetrics fontMetrics;
|
const QFontMetrics fontMetrics;
|
||||||
const int lineSpacing;
|
int lineSpacing;
|
||||||
const int markWidth;
|
int markWidth;
|
||||||
const int collapseColumnWidth;
|
int collapseColumnWidth;
|
||||||
const int extraAreaWidth;
|
const int extraAreaWidth;
|
||||||
const QTextCharFormat currentLineNumberFormat;
|
const QTextCharFormat currentLineNumberFormat;
|
||||||
QPalette palette;
|
QPalette palette;
|
||||||
@@ -5029,7 +5069,12 @@ void TextEditorWidgetPrivate::paintCodeFolding(QPainter &painter,
|
|||||||
bool hovered = blockNumber >= extraAreaHighlightFoldBlockNumber
|
bool hovered = blockNumber >= extraAreaHighlightFoldBlockNumber
|
||||||
&& blockNumber <= extraAreaHighlightFoldEndBlockNumber;
|
&& blockNumber <= extraAreaHighlightFoldEndBlockNumber;
|
||||||
|
|
||||||
int boxWidth = foldBoxWidth(data.fontMetrics);
|
int boxWidth = 0;
|
||||||
|
if (TextEditorSettings::fontSettings().relativeLineSpacing() == 100)
|
||||||
|
boxWidth = foldBoxWidth(data.fontMetrics);
|
||||||
|
else
|
||||||
|
boxWidth = foldBoxWidth();
|
||||||
|
|
||||||
if (hovered) {
|
if (hovered) {
|
||||||
int itop = qRound(blockBoundingRect.top());
|
int itop = qRound(blockBoundingRect.top());
|
||||||
int ibottom = qRound(blockBoundingRect.bottom());
|
int ibottom = qRound(blockBoundingRect.bottom());
|
||||||
@@ -5725,7 +5770,13 @@ void TextEditorWidget::updateFoldingHighlight(const QPoint &pos)
|
|||||||
const int highlightBlockNumber = d->extraAreaHighlightFoldedBlockNumber;
|
const int highlightBlockNumber = d->extraAreaHighlightFoldedBlockNumber;
|
||||||
d->extraAreaHighlightFoldedBlockNumber = -1;
|
d->extraAreaHighlightFoldedBlockNumber = -1;
|
||||||
|
|
||||||
if (pos.x() > extraArea()->width() - foldBoxWidth(fontMetrics())) {
|
int boxWidth = 0;
|
||||||
|
if (TextEditorSettings::fontSettings().relativeLineSpacing() == 100)
|
||||||
|
boxWidth = foldBoxWidth(fontMetrics());
|
||||||
|
else
|
||||||
|
boxWidth = foldBoxWidth();
|
||||||
|
|
||||||
|
if (pos.x() > extraArea()->width() - boxWidth) {
|
||||||
d->extraAreaHighlightFoldedBlockNumber = cursor.blockNumber();
|
d->extraAreaHighlightFoldedBlockNumber = cursor.blockNumber();
|
||||||
} else if (d->m_displaySettings.m_highlightBlocks) {
|
} else if (d->m_displaySettings.m_highlightBlocks) {
|
||||||
QTextCursor cursor = textCursor();
|
QTextCursor cursor = textCursor();
|
||||||
@@ -5785,7 +5836,11 @@ void TextEditorWidget::extraAreaMouseEvent(QMouseEvent *e)
|
|||||||
|
|
||||||
if (e->type() == QEvent::MouseButtonPress || e->type() == QEvent::MouseButtonDblClick) {
|
if (e->type() == QEvent::MouseButtonPress || e->type() == QEvent::MouseButtonDblClick) {
|
||||||
if (e->button() == Qt::LeftButton) {
|
if (e->button() == Qt::LeftButton) {
|
||||||
int boxWidth = foldBoxWidth(fontMetrics());
|
int boxWidth = 0;
|
||||||
|
if (TextEditorSettings::fontSettings().relativeLineSpacing() == 100)
|
||||||
|
boxWidth = foldBoxWidth(fontMetrics());
|
||||||
|
else
|
||||||
|
boxWidth = foldBoxWidth();
|
||||||
if (d->m_codeFoldingVisible && e->pos().x() > extraArea()->width() - boxWidth) {
|
if (d->m_codeFoldingVisible && e->pos().x() > extraArea()->width() - boxWidth) {
|
||||||
if (!cursor.block().next().isVisible()) {
|
if (!cursor.block().next().isVisible()) {
|
||||||
d->toggleBlockVisible(cursor.block());
|
d->toggleBlockVisible(cursor.block());
|
||||||
@@ -6330,7 +6385,7 @@ void TextEditorWidgetPrivate::adjustScrollBarRanges()
|
|||||||
{
|
{
|
||||||
if (!m_highlightScrollBarController)
|
if (!m_highlightScrollBarController)
|
||||||
return;
|
return;
|
||||||
const double lineSpacing = QFontMetricsF(q->font()).lineSpacing();
|
const double lineSpacing = TextEditorSettings::fontSettings().lineSpacing();
|
||||||
if (lineSpacing == 0)
|
if (lineSpacing == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -7320,7 +7375,15 @@ void TextEditorWidget::applyFontSettings()
|
|||||||
|
|
||||||
void TextEditorWidget::setDisplaySettings(const DisplaySettings &ds)
|
void TextEditorWidget::setDisplaySettings(const DisplaySettings &ds)
|
||||||
{
|
{
|
||||||
|
const TextEditor::FontSettings &fs = TextEditorSettings::fontSettings();
|
||||||
|
if (fs.relativeLineSpacing() == 100)
|
||||||
setLineWrapMode(ds.m_textWrapping ? QPlainTextEdit::WidgetWidth : QPlainTextEdit::NoWrap);
|
setLineWrapMode(ds.m_textWrapping ? QPlainTextEdit::WidgetWidth : QPlainTextEdit::NoWrap);
|
||||||
|
else
|
||||||
|
setLineWrapMode(QPlainTextEdit::NoWrap);
|
||||||
|
|
||||||
|
QTC_ASSERT((fs.relativeLineSpacing() == 100) || (fs.relativeLineSpacing() != 100
|
||||||
|
&& lineWrapMode() == QPlainTextEdit::NoWrap), setLineWrapMode(QPlainTextEdit::NoWrap));
|
||||||
|
|
||||||
setLineNumbersVisible(ds.m_displayLineNumbers);
|
setLineNumbersVisible(ds.m_displayLineNumbers);
|
||||||
setHighlightCurrentLine(ds.m_highlightCurrentLine);
|
setHighlightCurrentLine(ds.m_highlightCurrentLine);
|
||||||
setRevisionsVisible(ds.m_markTextChanges);
|
setRevisionsVisible(ds.m_markTextChanges);
|
||||||
|
|||||||
@@ -5,9 +5,11 @@
|
|||||||
|
|
||||||
#include "texteditor.h"
|
#include "texteditor.h"
|
||||||
#include "displaysettings.h"
|
#include "displaysettings.h"
|
||||||
|
#include "fontsettings.h"
|
||||||
#include "linenumberfilter.h"
|
#include "linenumberfilter.h"
|
||||||
#include "texteditorconstants.h"
|
#include "texteditorconstants.h"
|
||||||
#include "texteditorplugin.h"
|
#include "texteditorplugin.h"
|
||||||
|
#include "texteditorsettings.h"
|
||||||
|
|
||||||
#include <aggregation/aggregate.h>
|
#include <aggregation/aggregate.h>
|
||||||
|
|
||||||
@@ -134,6 +136,8 @@ TextEditorActionHandlerPrivate::TextEditorActionHandlerPrivate
|
|||||||
createActions();
|
createActions();
|
||||||
connect(Core::EditorManager::instance(), &Core::EditorManager::currentEditorChanged,
|
connect(Core::EditorManager::instance(), &Core::EditorManager::currentEditorChanged,
|
||||||
this, &TextEditorActionHandlerPrivate::updateCurrentEditor);
|
this, &TextEditorActionHandlerPrivate::updateCurrentEditor);
|
||||||
|
connect(TextEditorSettings::instance(), &TextEditorSettings::fontSettingsChanged,
|
||||||
|
this, &TextEditorActionHandlerPrivate::updateActions);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextEditorActionHandlerPrivate::createActions()
|
void TextEditorActionHandlerPrivate::createActions()
|
||||||
@@ -448,7 +452,12 @@ void TextEditorActionHandlerPrivate::updateActions()
|
|||||||
a->setEnabled(isWritable);
|
a->setEnabled(isWritable);
|
||||||
m_unCommentSelectionAction->setEnabled((m_optionalActions & TextEditorActionHandler::UnCommentSelection) && isWritable);
|
m_unCommentSelectionAction->setEnabled((m_optionalActions & TextEditorActionHandler::UnCommentSelection) && isWritable);
|
||||||
m_visualizeWhitespaceAction->setEnabled(m_currentEditorWidget);
|
m_visualizeWhitespaceAction->setEnabled(m_currentEditorWidget);
|
||||||
|
if (TextEditorSettings::fontSettings().relativeLineSpacing() == 100) {
|
||||||
m_textWrappingAction->setEnabled(m_currentEditorWidget);
|
m_textWrappingAction->setEnabled(m_currentEditorWidget);
|
||||||
|
} else {
|
||||||
|
m_textWrappingAction->setEnabled(false);
|
||||||
|
m_textWrappingAction->setChecked(false);
|
||||||
|
}
|
||||||
if (m_currentEditorWidget) {
|
if (m_currentEditorWidget) {
|
||||||
m_visualizeWhitespaceAction->setChecked(
|
m_visualizeWhitespaceAction->setChecked(
|
||||||
m_currentEditorWidget->displaySettings().m_visualizeWhitespace);
|
m_currentEditorWidget->displaySettings().m_visualizeWhitespace);
|
||||||
|
|||||||
Reference in New Issue
Block a user