diff --git a/src/dialogs/katedialogs.cpp b/src/dialogs/katedialogs.cpp --- a/src/dialogs/katedialogs.cpp +++ b/src/dialogs/katedialogs.cpp @@ -96,6 +96,9 @@ //END +enum SpacesComboBoxIndexes +{ None, Trailing, All }; + //BEGIN KateIndentConfigTab KateIndentConfigTab::KateIndentConfigTab(QWidget *parent) : KateConfigPage(parent) @@ -673,7 +676,7 @@ connect(textareaUi->cmbDynamicWordWrapIndicator, SIGNAL(activated(int)), this, SLOT(slotChanged())); connect(textareaUi->sbDynamicWordWrapDepth, SIGNAL(valueChanged(int)), this, SLOT(slotChanged())); connect(textareaUi->chkShowTabs, SIGNAL(toggled(bool)), this, SLOT(slotChanged())); - connect(textareaUi->chkShowSpaces, SIGNAL(toggled(bool)), this, SLOT(slotChanged())); + connect(textareaUi->spacesComboBox, QOverload::of(&QComboBox::currentIndexChanged), this, &KateViewDefaultsConfig::slotChanged); connect(textareaUi->chkShowIndentationLines, SIGNAL(toggled(bool)), this, SLOT(slotChanged())); connect(textareaUi->sliSetMarkerSize, SIGNAL(valueChanged(int)), this, SLOT(slotChanged())); connect(textareaUi->chkShowWholeBracketExpression, SIGNAL(toggled(bool)), this, SLOT(slotChanged())); @@ -720,7 +723,8 @@ KateViewConfig::global()->setDynWordWrapIndicators(textareaUi->cmbDynamicWordWrapIndicator->currentIndex()); KateViewConfig::global()->setDynWordWrapAlignIndent(textareaUi->sbDynamicWordWrapDepth->value()); KateDocumentConfig::global()->setShowTabs(textareaUi->chkShowTabs->isChecked()); - KateDocumentConfig::global()->setShowSpaces(textareaUi->chkShowSpaces->isChecked()); + KateDocumentConfig::global()->setShowSpaces(textareaUi->spacesComboBox->currentIndex() == Trailing); + KateDocumentConfig::global()->setShowAllSpaces(textareaUi->spacesComboBox->currentIndex() == All); KateDocumentConfig::global()->setMarkerSize(textareaUi->sliSetMarkerSize->value()); KateViewConfig::global()->setLineNumbers(bordersUi->chkLineNumbers->isChecked()); KateViewConfig::global()->setIconBar(bordersUi->chkIconBorder->isChecked()); @@ -753,7 +757,7 @@ textareaUi->cmbDynamicWordWrapIndicator->setCurrentIndex(KateViewConfig::global()->dynWordWrapIndicators()); textareaUi->sbDynamicWordWrapDepth->setValue(KateViewConfig::global()->dynWordWrapAlignIndent()); textareaUi->chkShowTabs->setChecked(KateDocumentConfig::global()->showTabs()); - textareaUi->chkShowSpaces->setChecked(KateDocumentConfig::global()->showSpaces()); + textareaUi->spacesComboBox->setCurrentIndex(KateDocumentConfig::global()->showSpaces() ? Trailing : KateDocumentConfig::global()->showAllSpaces() ? All : None); textareaUi->sliSetMarkerSize->setValue(KateDocumentConfig::global()->markerSize()); bordersUi->chkLineNumbers->setChecked(KateViewConfig::global()->lineNumbers()); bordersUi->chkIconBorder->setChecked(KateViewConfig::global()->iconBar()); diff --git a/src/dialogs/textareaappearanceconfigwidget.ui b/src/dialogs/textareaappearanceconfigwidget.ui --- a/src/dialogs/textareaappearanceconfigwidget.ui +++ b/src/dialogs/textareaappearanceconfigwidget.ui @@ -148,25 +148,27 @@ Whitespace Highlighting - - - - - The editor will display a symbol to indicate the presence of a tab in the text. - - - &Highlight tabulators - - - - - - - Highlight trailing &spaces - + + + + + + None + + + + + Trailing + + + + + All + + - + true @@ -179,28 +181,52 @@ - - - - Size of the visible highlight marker. - - - 1 - - - 5 - - - 1 - - - Qt::Horizontal - - - + + + + Size of the visible highlight marker. + + + 1 + + + 5 + + + 1 + + + Qt::Horizontal + + + + + + + Whitepaces + + + + + + + The editor will display a symbol to indicate the presence of a tab in the text. + + + + + + + + + + Highlight tabulators + + + @@ -306,9 +332,6 @@ chkDynWrapAtStaticMarker cmbDynamicWordWrapIndicator sbDynamicWordWrapDepth - chkShowTabs - chkShowSpaces - sliSetMarkerSize chkShowIndentationLines chkShowWholeBracketExpression chkAnimateBracketMatching diff --git a/src/render/katerenderer.h b/src/render/katerenderer.h --- a/src/render/katerenderer.h +++ b/src/render/katerenderer.h @@ -176,13 +176,26 @@ */ inline bool showTrailingSpaces() const { - return m_showSpaces; + return m_showTrailingSpaces; } /** * Set whether a mark should be painted for trailing spaces. */ - void setShowTrailingSpaces(bool showSpaces); + void setShowTrailingSpaces(bool showTrailingSpaces); + + /** + * @returns whether trailing spaces should be shown. + */ + inline bool showAllSpaces() const + { + return m_showAllSpaces; + } + + /** + * Set whether a mark should be painted for trailing spaces. + */ + void setShowAllSpaces(bool showAllSpaces); /** * Update marker size shown. @@ -372,7 +385,7 @@ /** * Paint a trailing space on position (x, y). */ - void paintTrailingSpace(QPainter &paint, qreal x, qreal y); + void paintSpace(QPainter &paint, qreal x, qreal y); /** * Paint a tab stop marker on position (x, y). */ @@ -410,7 +423,8 @@ bool m_drawCaret; bool m_showSelections; bool m_showTabs; - bool m_showSpaces; + bool m_showTrailingSpaces; + bool m_showAllSpaces; float m_markerSize; bool m_showNonPrintableSpaces; bool m_printerFriendly; diff --git a/src/render/katerenderer.cpp b/src/render/katerenderer.cpp --- a/src/render/katerenderer.cpp +++ b/src/render/katerenderer.cpp @@ -59,7 +59,8 @@ , m_drawCaret(true) , m_showSelections(true) , m_showTabs(true) - , m_showSpaces(true) + , m_showTrailingSpaces(true) + , m_showAllSpaces(true) , m_showNonPrintableSpaces(false) , m_printerFriendly(false) , m_config(new KateRendererConfig(this)) @@ -118,7 +119,12 @@ void KateRenderer::setShowTrailingSpaces(bool showSpaces) { - m_showSpaces = showSpaces; + m_showTrailingSpaces = showSpaces; +} + +void KateRenderer::setShowAllSpaces(bool showSpaces) +{ + m_showAllSpaces = showSpaces; } void KateRenderer::setShowNonPrintableSpaces(const bool on) @@ -271,7 +277,7 @@ paint.setPen(penBackup); } -void KateRenderer::paintTrailingSpace(QPainter &paint, qreal x, qreal y) +void KateRenderer::paintSpace(QPainter &paint, qreal x, qreal y) { QPen penBackup(paint.pen()); QPen pen(config()->tabMarkerColor()); @@ -309,6 +315,7 @@ void KateRenderer::paintNonPrintableSpaces(QPainter &paint, qreal x, qreal y, const QChar &chr) { + qDebug() << "xxxx" << x << y <spellingMistakeLineColor()); pen.setWidthF(qMax(1.0, spaceWidth() * 0.1)); @@ -723,22 +730,28 @@ } // draw trailing spaces - if (showTrailingSpaces()) { + if (showAllSpaces() || showTrailingSpaces()) { int spaceIndex = line.endCol() - 1; - int trailingPos = range->textLine()->lastChar(); + int trailingPos = showAllSpaces() ? 0 : range->textLine()->lastChar(); if (trailingPos < 0) { trailingPos = 0; } if (spaceIndex >= trailingPos) { - while (spaceIndex >= line.startCol() && text.at(spaceIndex).isSpace()) { + for (; spaceIndex >= line.startCol(); --spaceIndex) { + if (!text.at(spaceIndex).isSpace()) { + if (showTrailingSpaces()) + break; + else + continue; + } + if (text.at(spaceIndex) != QLatin1Char('\t') || !showTabs()) { if (range->layout()->textOption().alignment() == Qt::AlignRight) { // Draw on left for RTL lines - paintTrailingSpace(paint, line.lineLayout().cursorToX(spaceIndex) - xStart - spaceWidth() / 2.0, y); + paintSpace(paint, line.lineLayout().cursorToX(spaceIndex) - xStart - spaceWidth() / 2.0, y); } else { - paintTrailingSpace(paint, line.lineLayout().cursorToX(spaceIndex) - xStart + spaceWidth() / 2.0, y); + paintSpace(paint, line.lineLayout().cursorToX(spaceIndex) - xStart + spaceWidth() / 2.0, y); } } - --spaceIndex; } } } diff --git a/src/utils/kateconfig.h b/src/utils/kateconfig.h --- a/src/utils/kateconfig.h +++ b/src/utils/kateconfig.h @@ -236,9 +236,13 @@ void setShowTabs(bool on); bool showTabs() const; + ///@note this refers to trailing spaces void setShowSpaces(bool on); bool showSpaces() const; + void setShowAllSpaces(bool on); + bool showAllSpaces() const; + void setMarkerSize(uint markerSize); uint markerSize() const; @@ -362,6 +366,8 @@ bool m_showTabs : 1; bool m_showSpacesSet : 1; bool m_showSpaces : 1; + bool m_showAllSpacesSet : 1; + bool m_showAllSpaces : 1; uint m_markerSize = 1; bool m_replaceTabsDynSet : 1; bool m_replaceTabsDyn : 1; diff --git a/src/utils/kateconfig.cpp b/src/utils/kateconfig.cpp --- a/src/utils/kateconfig.cpp +++ b/src/utils/kateconfig.cpp @@ -752,6 +752,29 @@ return s_global->showSpaces(); } +void KateDocumentConfig::setShowAllSpaces(bool on) +{ + if (m_showAllSpacesSet && m_showAllSpaces == on) { + return; + } + + configStart(); + + m_showAllSpacesSet = true; + m_showAllSpaces = on; + + configEnd(); +} + +bool KateDocumentConfig::showAllSpaces() const +{ + if (m_showAllSpacesSet || isGlobal()) { + return m_showAllSpaces; + } + + return s_global->showAllSpaces(); +} + void KateDocumentConfig::setMarkerSize(uint markerSize) { if (m_markerSize == markerSize) {