mirror of
				https://github.com/qgis/QGIS.git
				synced 2025-11-04 00:04:25 -05:00 
			
		
		
		
	[ui] Implement scroll wheel action for symbol buttons
This commit is contained in:
		
							parent
							
								
									024ba35d5f
								
							
						
					
					
						commit
						ec9ab29dee
					
				@ -264,6 +264,9 @@ Emitted when the symbol's settings are changed.
 | 
			
		||||
    virtual void dropEvent( QDropEvent *e );
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    virtual void wheelEvent( QWheelEvent *event );
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/************************************************************************
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
@ -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();
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user