Skip to content

Commit

Permalink
Add opacity slider to symbol button menu
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jul 24, 2017
1 parent 0414794 commit 6398b74
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/gui/qgssymbolbutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 6398b74

Please sign in to comment.