Skip to content
Permalink
Browse files

Add opacity slider to symbol button menu

  • Loading branch information
nyalldawson committed Jul 24, 2017
1 parent 0414794 commit 6398b74426527754822c5ee634d53e1cfa4db090
Showing with 17 additions and 5 deletions.
  1. +17 −5 src/gui/qgssymbolbutton.cpp
@@ -244,11 +244,6 @@ void QgsSymbolButton::dropEvent( QDropEvent *e )
{
//accept drop and set new color
e->acceptProposedAction();

if ( hasAlpha )
{
mSymbol->setOpacity( mimeColor.alphaF() );
}
mimeColor.setAlphaF( 1.0 );
mSymbol->setColor( mimeColor );
QgsRecentColorScheme::addRecentColor( mimeColor );
@@ -279,6 +274,23 @@ void QgsSymbolButton::prepareMenu()
connect( colorAction, &QgsColorWidgetAction::colorChanged, this, &QgsSymbolButton::setColor );
mMenu->addAction( colorAction );

QgsColorRampWidget *alphaRamp = new QgsColorRampWidget( mMenu, QgsColorWidget::Alpha, QgsColorRampWidget::Horizontal );
QColor alphaColor = mSymbol->color();
alphaColor.setAlphaF( mSymbol->opacity() );
alphaRamp->setColor( alphaColor );
QgsColorWidgetAction *alphaAction = new QgsColorWidgetAction( alphaRamp, mMenu, mMenu );
alphaAction->setDismissOnColorSelection( false );
connect( alphaAction, &QgsColorWidgetAction::colorChanged, this, [ = ]( const QColor & color )
{
double opacity = color.alphaF();
mSymbol->setOpacity( opacity );
updatePreview();
emit changed();
} );
connect( colorAction, &QgsColorWidgetAction::colorChanged, alphaRamp, [alphaRamp]( const QColor & color ) { alphaRamp->setColor( color, false ); }
);
mMenu->addAction( alphaAction );

//get schemes with ShowInColorButtonMenu flag set
QList< QgsColorScheme * > schemeList = QgsApplication::colorSchemeRegistry()->schemes( QgsColorScheme::ShowInColorButtonMenu );
QList< QgsColorScheme * >::iterator it = schemeList.begin();

0 comments on commit 6398b74

Please sign in to comment.
You can’t perform that action at this time.