forked from qt-creator/qt-creator
Editor: Make line spacing adjustable
Fixes: QTCREATORBUG-13727 Change-Id: I3dbc3277795b339bced81dc6c5a048c828183cb6 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -1105,9 +1105,9 @@ void TextEditorWidget::print(QPrinter *printer)
|
||||
delete dlg;
|
||||
}
|
||||
|
||||
static int foldBoxWidth(const QFontMetrics &fm)
|
||||
static int foldBoxWidth()
|
||||
{
|
||||
const int lineSpacing = fm.lineSpacing();
|
||||
const int lineSpacing = TextEditorSettings::fontSettings().lineSpacing();
|
||||
return lineSpacing + lineSpacing % 2 + 1;
|
||||
}
|
||||
|
||||
@@ -3604,9 +3604,9 @@ QRect TextEditorWidgetPrivate::foldBox()
|
||||
QRectF br = q->blockBoundingGeometry(begin).translated(q->contentOffset());
|
||||
QRectF er = q->blockBoundingGeometry(end).translated(q->contentOffset());
|
||||
|
||||
return QRect(m_extraArea->width() - foldBoxWidth(q->fontMetrics()),
|
||||
return QRect(m_extraArea->width() - foldBoxWidth(),
|
||||
int(br.top()),
|
||||
foldBoxWidth(q->fontMetrics()),
|
||||
foldBoxWidth(),
|
||||
int(er.bottom() - br.top()));
|
||||
}
|
||||
|
||||
@@ -4083,7 +4083,9 @@ bool TextEditorWidgetPrivate::updateAnnotationBounds(TextBlockUserData *blockUse
|
||||
{
|
||||
const bool additionalHeightNeeded = annotationsVisible
|
||||
&& m_displaySettings.m_annotationAlignment == AnnotationAlignment::BetweenLines;
|
||||
const int additionalHeight = additionalHeightNeeded ? q->fontMetrics().lineSpacing() : 0;
|
||||
const int additionalHeight = additionalHeightNeeded
|
||||
? TextEditorSettings::fontSettings().lineSpacing()
|
||||
: 0;
|
||||
if (blockUserData->additionalAnnotationHeight() == additionalHeight)
|
||||
return false;
|
||||
blockUserData->setAdditionalAnnotationHeight(additionalHeight);
|
||||
@@ -4124,7 +4126,7 @@ void TextEditorWidgetPrivate::updateLineAnnotation(const PaintEventData &data,
|
||||
return mark1->priority() > mark2->priority();
|
||||
});
|
||||
|
||||
const qreal itemOffset = q->fontMetrics().lineSpacing();
|
||||
const qreal itemOffset = blockData.boundingRect.height();
|
||||
const qreal initialOffset = m_displaySettings.m_annotationAlignment == AnnotationAlignment::BetweenLines ? itemOffset / 2 : itemOffset * 2;
|
||||
const qreal minimalContentWidth = q->fontMetrics().horizontalAdvance('X')
|
||||
* m_displaySettings.m_minimalAnnotationContent;
|
||||
@@ -5018,7 +5020,7 @@ int TextEditorWidget::extraAreaWidth(int *markWidthPtr) const
|
||||
int markWidth = 0;
|
||||
|
||||
if (d->m_marksVisible) {
|
||||
markWidth += documentLayout->maxMarkWidthFactor * fm.lineSpacing() + 2;
|
||||
markWidth += documentLayout->maxMarkWidthFactor * TextEditorSettings::fontSettings().lineSpacing() + 2;
|
||||
|
||||
// if (documentLayout->doubleMarkCount)
|
||||
// markWidth += fm.lineSpacing() / 3;
|
||||
@@ -5033,7 +5035,7 @@ int TextEditorWidget::extraAreaWidth(int *markWidthPtr) const
|
||||
space += 4;
|
||||
|
||||
if (d->m_codeFoldingVisible)
|
||||
space += foldBoxWidth(fm);
|
||||
space += foldBoxWidth();
|
||||
|
||||
if (viewportMargins() != QMargins{isLeftToRight() ? space : 0, 0, isLeftToRight() ? 0 : space, 0})
|
||||
d->slotUpdateExtraAreaWidth(space);
|
||||
@@ -5059,9 +5061,9 @@ struct Internal::ExtraAreaPaintEventData
|
||||
, selectionStart(editor->textCursor().selectionStart())
|
||||
, selectionEnd(editor->textCursor().selectionEnd())
|
||||
, fontMetrics(d->m_extraArea->font())
|
||||
, lineSpacing(fontMetrics.lineSpacing())
|
||||
, lineSpacing(TextEditorSettings::fontSettings().lineSpacing())
|
||||
, markWidth(d->m_marksVisible ? lineSpacing : 0)
|
||||
, collapseColumnWidth(d->m_codeFoldingVisible ? foldBoxWidth(fontMetrics) : 0)
|
||||
, collapseColumnWidth(d->m_codeFoldingVisible ? foldBoxWidth() : 0)
|
||||
, extraAreaWidth(d->m_extraArea->width() - collapseColumnWidth)
|
||||
, currentLineNumberFormat(
|
||||
editor->textDocument()->fontSettings().toTextCharFormat(C_CURRENT_LINE_NUMBER))
|
||||
@@ -5185,7 +5187,7 @@ void TextEditorWidgetPrivate::paintCodeFolding(QPainter &painter,
|
||||
bool hovered = blockNumber >= extraAreaHighlightFoldBlockNumber
|
||||
&& blockNumber <= extraAreaHighlightFoldEndBlockNumber;
|
||||
|
||||
int boxWidth = foldBoxWidth(data.fontMetrics);
|
||||
int boxWidth = foldBoxWidth();
|
||||
if (hovered) {
|
||||
int itop = qRound(blockBoundingRect.top());
|
||||
int ibottom = qRound(blockBoundingRect.bottom());
|
||||
@@ -5558,8 +5560,10 @@ void TextEditorWidget::mouseMoveEvent(QMouseEvent *e)
|
||||
if (cursor.positionInBlock() == cursor.block().length()-1)
|
||||
column += (e->pos().x() - cursorRect().center().x()) / QFontMetricsF(font()).horizontalAdvance(QLatin1Char(' '));
|
||||
int block = cursor.blockNumber();
|
||||
if (block == blockCount() - 1)
|
||||
block += (e->pos().y() - cursorRect().center().y()) / QFontMetricsF(font()).lineSpacing();
|
||||
if (block == blockCount() - 1) {
|
||||
block += (e->pos().y() - cursorRect().center().y())
|
||||
/ TextEditorSettings::fontSettings().lineSpacing();
|
||||
}
|
||||
d->enableBlockSelection(block, column, block, column);
|
||||
}
|
||||
} else {
|
||||
@@ -5609,8 +5613,11 @@ void TextEditorWidget::mousePressEvent(QMouseEvent *e)
|
||||
if (cursor.positionInBlock() == cursor.block().length()-1)
|
||||
column += (e->pos().x() - cursorRect(cursor).center().x()) / QFontMetricsF(font()).horizontalAdvance(QLatin1Char(' '));
|
||||
int block = cursor.blockNumber();
|
||||
if (block == blockCount() - 1)
|
||||
block += (e->pos().y() - cursorRect(cursor).center().y()) / QFontMetricsF(font()).lineSpacing();
|
||||
if (block == blockCount() - 1) {
|
||||
block += (e->pos().y() - cursorRect(cursor).center().y())
|
||||
/ TextEditorSettings::fontSettings().lineSpacing();
|
||||
}
|
||||
|
||||
if (d->m_inBlockSelectionMode) {
|
||||
d->m_blockSelection.positionBlock = block;
|
||||
d->m_blockSelection.positionColumn = column;
|
||||
@@ -5784,7 +5791,7 @@ void TextEditorWidget::updateFoldingHighlight(const QPoint &pos)
|
||||
const int highlightBlockNumber = d->extraAreaHighlightFoldedBlockNumber;
|
||||
d->extraAreaHighlightFoldedBlockNumber = -1;
|
||||
|
||||
if (pos.x() > extraArea()->width() - foldBoxWidth(fontMetrics())) {
|
||||
if (pos.x() > extraArea()->width() - foldBoxWidth()) {
|
||||
d->extraAreaHighlightFoldedBlockNumber = cursor.blockNumber();
|
||||
} else if (d->m_displaySettings.m_highlightBlocks) {
|
||||
QTextCursor cursor = textCursor();
|
||||
@@ -5827,7 +5834,7 @@ void TextEditorWidget::extraAreaMouseEvent(QMouseEvent *e)
|
||||
int dist = (e->pos() - d->m_markDragStart).manhattanLength();
|
||||
if (dist > QApplication::startDragDistance()) {
|
||||
d->m_markDragging = true;
|
||||
const int height = fontMetrics().lineSpacing() - 1;
|
||||
const int height = TextEditorSettings::fontSettings().lineSpacing() - 1;
|
||||
const int width = int(.5 + height * d->m_dragMark->widthFactor());
|
||||
d->m_markDragCursor = QCursor(d->m_dragMark->icon().pixmap({height, width}));
|
||||
d->m_dragMark->setVisible(false);
|
||||
@@ -5845,7 +5852,7 @@ void TextEditorWidget::extraAreaMouseEvent(QMouseEvent *e)
|
||||
|
||||
if (e->type() == QEvent::MouseButtonPress || e->type() == QEvent::MouseButtonDblClick) {
|
||||
if (e->button() == Qt::LeftButton) {
|
||||
int boxWidth = foldBoxWidth(fontMetrics());
|
||||
int boxWidth = foldBoxWidth();
|
||||
if (d->m_codeFoldingVisible && e->pos().x() > extraArea()->width() - boxWidth) {
|
||||
if (!cursor.block().next().isVisible()) {
|
||||
d->toggleBlockVisible(cursor.block());
|
||||
@@ -6372,7 +6379,7 @@ void TextEditorWidgetPrivate::adjustScrollBarRanges()
|
||||
{
|
||||
if (!m_highlightScrollBarController)
|
||||
return;
|
||||
const double lineSpacing = QFontMetricsF(q->font()).lineSpacing();
|
||||
const double lineSpacing = TextEditorSettings::fontSettings().lineSpacing();
|
||||
if (lineSpacing == 0)
|
||||
return;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user