QPlainTextEdit: add missing feature zoom on Ctrl+Wheel
When the control is read only. This is documented but not implemented. Add functions to zoomIn and zoomOut. Task-number: QTBUG-30845 Change-Id: I692b5f8cc5791498d34d35ea3dafa18b6e5d3e65 Reviewed-by: Frederik Gladhorn <frederik.gladhorn@digia.com>
This commit is contained in:
parent
7375c06328
commit
dc5a579a16
@ -2223,11 +2223,57 @@ void QPlainTextEdit::changeEvent(QEvent *e)
|
||||
#ifndef QT_NO_WHEELEVENT
|
||||
void QPlainTextEdit::wheelEvent(QWheelEvent *e)
|
||||
{
|
||||
Q_D(QPlainTextEdit);
|
||||
if (!(d->control->textInteractionFlags() & Qt::TextEditable)) {
|
||||
if (e->modifiers() & Qt::ControlModifier) {
|
||||
const int delta = e->delta();
|
||||
if (delta < 0)
|
||||
zoomOut();
|
||||
else if (delta > 0)
|
||||
zoomIn();
|
||||
return;
|
||||
}
|
||||
}
|
||||
QAbstractScrollArea::wheelEvent(e);
|
||||
updateMicroFocus();
|
||||
}
|
||||
#endif
|
||||
|
||||
/*!
|
||||
\fn QPlainTextEdit::zoomIn(int range)
|
||||
|
||||
Zooms in on the text by making the base font size \a range
|
||||
points larger and recalculating all font sizes to be the new size.
|
||||
This does not change the size of any images.
|
||||
|
||||
\sa zoomOut()
|
||||
*/
|
||||
void QPlainTextEdit::zoomIn(int range)
|
||||
{
|
||||
QFont f = font();
|
||||
const int newSize = f.pointSize() + range;
|
||||
if (newSize <= 0)
|
||||
return;
|
||||
f.setPointSize(newSize);
|
||||
setFont(f);
|
||||
}
|
||||
|
||||
/*!
|
||||
\fn QPlainTextEdit::zoomOut(int range)
|
||||
|
||||
\overload
|
||||
|
||||
Zooms out on the text by making the base font size \a range points
|
||||
smaller and recalculating all font sizes to be the new size. This
|
||||
does not change the size of any images.
|
||||
|
||||
\sa zoomIn()
|
||||
*/
|
||||
void QPlainTextEdit::zoomOut(int range)
|
||||
{
|
||||
zoomIn(-range);
|
||||
}
|
||||
|
||||
#ifndef QT_NO_CONTEXTMENU
|
||||
/*! This function creates the standard context menu which is shown
|
||||
when the user clicks on the line edit with the right mouse
|
||||
|
@ -202,6 +202,9 @@ public Q_SLOTS:
|
||||
|
||||
void centerCursor();
|
||||
|
||||
void zoomIn(int range = 1);
|
||||
void zoomOut(int range = 1);
|
||||
|
||||
Q_SIGNALS:
|
||||
void textChanged();
|
||||
void undoAvailable(bool b);
|
||||
|
Loading…
Reference in New Issue
Block a user