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

With ctrl+mouse wheel changing in smaller size increments
This commit is contained in:
Nyall Dawson 2017-07-06 19:43:18 +10:00
parent 49ad7836d3
commit e95b65ef48
3 changed files with 52 additions and 0 deletions

View File

@ -188,6 +188,9 @@ class QgsFontButton : QToolButton
virtual void dropEvent( QDropEvent *e );
virtual void wheelEvent( QWheelEvent *event );
};
/************************************************************************

View File

@ -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

View File

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