Skip to content
Permalink
Browse files

[needs-docs] Mouse wheeling over font buttons can change font size

With ctrl+mouse wheel changing in smaller size increments
  • Loading branch information
nyalldawson committed Jul 6, 2017
1 parent 49ad783 commit e95b65ef48b6778f08a18a4ed0fd87d54ad2e965
Showing with 52 additions and 0 deletions.
  1. +3 −0 python/gui/qgsfontbutton.sip
  2. +47 −0 src/gui/qgsfontbutton.cpp
  3. +2 −0 src/gui/qgsfontbutton.h
@@ -188,6 +188,9 @@ class QgsFontButton : QToolButton
virtual void dropEvent( QDropEvent *e );


virtual void wheelEvent( QWheelEvent *event );


};

/************************************************************************
@@ -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
@@ -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();

0 comments on commit e95b65e

Please sign in to comment.
You can’t perform that action at this time.