Skip to content

Commit

Permalink
[needs-docs] Mouse wheeling over font buttons can change font size
Browse files Browse the repository at this point in the history
With ctrl+mouse wheel changing in smaller size increments
  • Loading branch information
nyalldawson committed Jul 6, 2017
1 parent 49ad783 commit e95b65e
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
3 changes: 3 additions & 0 deletions python/gui/qgsfontbutton.sip
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ class QgsFontButton : QToolButton
virtual void dropEvent( QDropEvent *e );


virtual void wheelEvent( QWheelEvent *event );


};

/************************************************************************
Expand Down
47 changes: 47 additions & 0 deletions src/gui/qgsfontbutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/gui/qgsfontbutton.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit e95b65e

Please sign in to comment.