[ui] Implement scroll wheel action for symbol buttons

This commit is contained in:
Mathieu Pellerin 2022-05-09 17:08:00 +07:00 committed by Nyall Dawson
parent 024ba35d5f
commit ec9ab29dee
3 changed files with 53 additions and 0 deletions

View File

@ -264,6 +264,9 @@ Emitted when the symbol's settings are changed.
virtual void dropEvent( QDropEvent *e );
virtual void wheelEvent( QWheelEvent *event );
};
/************************************************************************

View File

@ -388,6 +388,54 @@ void QgsSymbolButton::dropEvent( QDropEvent *e )
updatePreview();
}
void QgsSymbolButton::wheelEvent( QWheelEvent *event )
{
if ( isEnabled() && mSymbol )
{
bool symbolChanged = false;
const double increment = ( ( event->modifiers() & Qt::ControlModifier ) ? 0.1 : 1 ) *
event->angleDelta().y() > 0 ? 1 : -1;
switch ( mType )
{
case Qgis::SymbolType::Marker:
{
QgsMarkerSymbol *marker = dynamic_cast<QgsMarkerSymbol *>( mSymbol.get() );
if ( marker )
{
const double size = std::max( 0.0, marker->size() + increment );
marker->setSize( size );
symbolChanged = true;
}
break;
}
case Qgis::SymbolType::Line:
{
QgsLineSymbol *line = dynamic_cast<QgsLineSymbol *>( mSymbol.get() );
if ( line )
{
const double width = std::max( 0.0, line->width() + increment );
line->setWidth( width );
symbolChanged = true;
}
break;
}
case Qgis::SymbolType::Fill:
case Qgis::SymbolType::Hybrid:
break;
}
if ( symbolChanged )
{
updatePreview();
emit changed();
}
event->accept();
}
}
void QgsSymbolButton::prepareMenu()
{
//we need to tear down and rebuild this menu every time it is shown. Otherwise the space allocated to any

View File

@ -267,6 +267,8 @@ class GUI_EXPORT QgsSymbolButton : public QToolButton
// Reimplemented to accept dropped colors
void dropEvent( QDropEvent *e ) override;
void wheelEvent( QWheelEvent *event ) override;
private slots:
void showSettingsDialog();