From e95b65ef48b6778f08a18a4ed0fd87d54ad2e965 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Thu, 6 Jul 2017 19:43:18 +1000 Subject: [PATCH] [needs-docs] Mouse wheeling over font buttons can change font size With ctrl+mouse wheel changing in smaller size increments --- python/gui/qgsfontbutton.sip | 3 +++ src/gui/qgsfontbutton.cpp | 47 ++++++++++++++++++++++++++++++++++++ src/gui/qgsfontbutton.h | 2 ++ 3 files changed, 52 insertions(+) diff --git a/python/gui/qgsfontbutton.sip b/python/gui/qgsfontbutton.sip index 3764f8eee32..da6a0437933 100644 --- a/python/gui/qgsfontbutton.sip +++ b/python/gui/qgsfontbutton.sip @@ -188,6 +188,9 @@ class QgsFontButton : QToolButton virtual void dropEvent( QDropEvent *e ); + virtual void wheelEvent( QWheelEvent *event ); + + }; /************************************************************************ diff --git a/src/gui/qgsfontbutton.cpp b/src/gui/qgsfontbutton.cpp index 234af0de939..70453554ddc 100644 --- a/src/gui/qgsfontbutton.cpp +++ b/src/gui/qgsfontbutton.cpp @@ -305,6 +305,53 @@ void QgsFontButton::dropEvent( QDropEvent *e ) updatePreview(); } +void QgsFontButton::wheelEvent( QWheelEvent *event ) +{ + double size = 0; + switch ( mMode ) + { + case ModeTextRenderer: + size = mFormat.size(); + break; + + case ModeQFont: + size = mFont.pointSizeF(); + break; + } + + double increment = event->modifiers() & Qt::ControlModifier ? 0.1 : 1; + if ( event->delta() > 0 ) + { + size += increment; + } + else + { + size -= increment; + } + size = qMax( size, 1.0 ); + + switch ( mMode ) + { + case ModeTextRenderer: + { + QgsTextFormat newFormat = mFormat; + newFormat.setSize( size ); + setTextFormat( newFormat ); + break; + } + + case ModeQFont: + { + QFont newFont = mFont; + newFont.setPointSizeF( size ); + setCurrentFont( newFont ); + break; + } + } + + event->accept(); +} + QPixmap QgsFontButton::createColorIcon( const QColor &color ) const { //create an icon pixmap diff --git a/src/gui/qgsfontbutton.h b/src/gui/qgsfontbutton.h index 7b4eed7103c..425d4df1e38 100644 --- a/src/gui/qgsfontbutton.h +++ b/src/gui/qgsfontbutton.h @@ -199,6 +199,8 @@ class GUI_EXPORT QgsFontButton : public QToolButton // Reimplemented to accept dropped colors void dropEvent( QDropEvent *e ) override; + void wheelEvent( QWheelEvent *event ) override; + private slots: void showSettingsDialog();