diff options
author | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io> | 2017-08-01 12:34:29 +0200 |
---|---|---|
committer | Jędrzej Nowacki <jedrzej.nowacki@qt.io> | 2017-08-06 08:16:06 +0000 |
commit | 9342a8b843e2fe924db09b2935464ac6d26adc27 (patch) | |
tree | cca3185653b41c9043b73b38c33b160910c2aef3 /src/widgets/widgets/qplaintextedit.cpp | |
parent | b03706d35f556fbaa91d4e05ee7a337220e174b8 (diff) |
Add QTextOption/QTextEdit/QPlainTextEdit::tabStopDistance property
In Qt, we have QTextOption::tabStop, QTextEdit::tabStopWidth and
QPlainTextEdit::tabStopWidth.
Neither are very good names, since the tab stop is neither a
numerical value as in the former, nor does it have any dimensions
that can be measured, as in the latter. Vertical text advances
may also be supported by Qt at some point in the future, at
which point the name would make even less sense.
At the same time, we expose the actual type of the tab stop
distance as floating point in the QTextEdit and QPlainTextEdit
API instead of always rounding it to an int.
To avoid duplicating either of these APIs in Qt Quick, we
introduce tabStopDistance as the common term instead and deprecate
the old names.
[ChangeLog][Text] Introduced tabStopDistance property in
QTextOption, QTextEdit and QPlainTextEdit as replacement for
the inconsistently named tabStop and tabStopWidth properties.
QTextOption::tabStop, QTextEdit::tabStopWidth and
QPlainTextEdit::tabStopWidth have subsequently been deprecated.
Change-Id: Ib7e01387910cddb58adaaaadcd56c0e69edc4bc2
Reviewed-by: Paolo Angelelli <paolo.angelelli@qt.io>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/widgets/widgets/qplaintextedit.cpp')
-rw-r--r-- | src/widgets/widgets/qplaintextedit.cpp | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/src/widgets/widgets/qplaintextedit.cpp b/src/widgets/widgets/qplaintextedit.cpp index 173be7aa88..e19d4d4702 100644 --- a/src/widgets/widgets/qplaintextedit.cpp +++ b/src/widgets/widgets/qplaintextedit.cpp @@ -2453,29 +2453,51 @@ void QPlainTextEdit::setOverwriteMode(bool overwrite) d->control->setOverwriteMode(overwrite); } +#if QT_DEPRECATED_SINCE(5, 10) /*! \property QPlainTextEdit::tabStopWidth \brief the tab stop width in pixels + \deprecated in Qt 5.10. Use tabStopDistance instead. By default, this property contains a value of 80. */ int QPlainTextEdit::tabStopWidth() const { - Q_D(const QPlainTextEdit); - return qRound(d->control->document()->defaultTextOption().tabStop()); + return qRound(tabStopDistance()); } void QPlainTextEdit::setTabStopWidth(int width) { + setTabStopDistance(width); +} +#endif + +/*! + \property QPlainTextEdit::tabStopDistance + \brief the tab stop distance in pixels + \since 5.10 + + By default, this property contains a value of 80. +*/ + +qreal QPlainTextEdit::tabStopDistance() const +{ + Q_D(const QPlainTextEdit); + return d->control->document()->defaultTextOption().tabStopDistance(); +} + +void QPlainTextEdit::setTabStopDistance(qreal distance) +{ Q_D(QPlainTextEdit); QTextOption opt = d->control->document()->defaultTextOption(); - if (opt.tabStop() == width || width < 0) + if (opt.tabStopDistance() == distance || distance < 0) return; - opt.setTabStop(width); + opt.setTabStopDistance(distance); d->control->document()->setDefaultTextOption(opt); } + /*! \property QPlainTextEdit::cursorWidth |