summaryrefslogtreecommitdiffstats
path: root/src/widgets
diff options
context:
space:
mode:
authorCaroline Chao <caroline.chao@digia.com>2013-04-23 23:37:58 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-04-30 12:45:30 +0200
commitdc5a579a163f53fc7ae443fb2b9eef8c4edd66fa (patch)
tree7a5a595bf30eedd3ed994b851c8f264daba7dfe6 /src/widgets
parent7375c06328f10071b1628874c96ed13142031dd7 (diff)
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>
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/widgets/qplaintextedit.cpp46
-rw-r--r--src/widgets/widgets/qplaintextedit.h3
2 files changed, 49 insertions, 0 deletions
diff --git a/src/widgets/widgets/qplaintextedit.cpp b/src/widgets/widgets/qplaintextedit.cpp
index 95271adeb0..5a8da45a88 100644
--- a/src/widgets/widgets/qplaintextedit.cpp
+++ b/src/widgets/widgets/qplaintextedit.cpp
@@ -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
diff --git a/src/widgets/widgets/qplaintextedit.h b/src/widgets/widgets/qplaintextedit.h
index 42e8288cf3..81548818ef 100644
--- a/src/widgets/widgets/qplaintextedit.h
+++ b/src/widgets/widgets/qplaintextedit.h
@@ -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);