Skip to content

Commit e95b65e

Browse files
committedJul 6, 2017
[needs-docs] Mouse wheeling over font buttons can change font size
With ctrl+mouse wheel changing in smaller size increments
1 parent 49ad783 commit e95b65e

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed
 

‎python/gui/qgsfontbutton.sip

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,9 @@ class QgsFontButton : QToolButton
188188
virtual void dropEvent( QDropEvent *e );
189189

190190

191+
virtual void wheelEvent( QWheelEvent *event );
192+
193+
191194
};
192195

193196
/************************************************************************

‎src/gui/qgsfontbutton.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,53 @@ void QgsFontButton::dropEvent( QDropEvent *e )
305305
updatePreview();
306306
}
307307

308+
void QgsFontButton::wheelEvent( QWheelEvent *event )
309+
{
310+
double size = 0;
311+
switch ( mMode )
312+
{
313+
case ModeTextRenderer:
314+
size = mFormat.size();
315+
break;
316+
317+
case ModeQFont:
318+
size = mFont.pointSizeF();
319+
break;
320+
}
321+
322+
double increment = event->modifiers() & Qt::ControlModifier ? 0.1 : 1;
323+
if ( event->delta() > 0 )
324+
{
325+
size += increment;
326+
}
327+
else
328+
{
329+
size -= increment;
330+
}
331+
size = qMax( size, 1.0 );
332+
333+
switch ( mMode )
334+
{
335+
case ModeTextRenderer:
336+
{
337+
QgsTextFormat newFormat = mFormat;
338+
newFormat.setSize( size );
339+
setTextFormat( newFormat );
340+
break;
341+
}
342+
343+
case ModeQFont:
344+
{
345+
QFont newFont = mFont;
346+
newFont.setPointSizeF( size );
347+
setCurrentFont( newFont );
348+
break;
349+
}
350+
}
351+
352+
event->accept();
353+
}
354+
308355
QPixmap QgsFontButton::createColorIcon( const QColor &color ) const
309356
{
310357
//create an icon pixmap

‎src/gui/qgsfontbutton.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ class GUI_EXPORT QgsFontButton : public QToolButton
199199
// Reimplemented to accept dropped colors
200200
void dropEvent( QDropEvent *e ) override;
201201

202+
void wheelEvent( QWheelEvent *event ) override;
203+
202204
private slots:
203205

204206
void showSettingsDialog();

0 commit comments

Comments
 (0)
Please sign in to comment.