Skip to content

Commit

Permalink
Use QgsOpacityWidget wherever appropriate
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed May 30, 2017
1 parent eed758e commit d24c64f
Show file tree
Hide file tree
Showing 32 changed files with 871 additions and 1,850 deletions.
21 changes: 6 additions & 15 deletions src/app/composer/qgscomposeritemwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,11 @@ QgsComposerItemWidget::QgsComposerItemWidget( QWidget *parent, QgsComposerItem *

initializeDataDefinedButtons();

mOpacitySpnBx->setClearValue( 100.0 );

setValuesForGuiElements();
connect( mItem->composition(), &QgsComposition::paperSizeChanged, this, &QgsComposerItemWidget::setValuesForGuiPositionElements );
connect( mItem, &QgsComposerItem::sizeChanged, this, &QgsComposerItemWidget::setValuesForGuiPositionElements );
connect( mItem, &QgsComposerObject::itemChanged, this, &QgsComposerItemWidget::setValuesForGuiNonPositionElements );

connect( mOpacitySlider, &QAbstractSlider::valueChanged, this, [ = ]( int value ) { mOpacitySpnBx->setValue( value / 10.0 ); } );
connect( mOpacityWidget, &QgsOpacityWidget::opacityChanged, this, &QgsComposerItemWidget::opacityChanged );

updateVariables();
connect( mVariableEditor, &QgsVariableEditorWidget::scopeChanged, this, &QgsComposerItemWidget::variablesChanged );
Expand Down Expand Up @@ -506,8 +503,7 @@ void QgsComposerItemWidget::setValuesForGuiNonPositionElements()
mBackgroundGroupBox->blockSignals( true );
mItemIdLineEdit->blockSignals( true );
mBlendModeCombo->blockSignals( true );
mOpacitySlider->blockSignals( true );
mOpacitySpnBx->blockSignals( true );
mOpacityWidget->blockSignals( true );
mFrameColorButton->blockSignals( true );
mFrameJoinStyleCombo->blockSignals( true );
mBackgroundColorButton->blockSignals( true );
Expand All @@ -522,8 +518,7 @@ void QgsComposerItemWidget::setValuesForGuiNonPositionElements()
mFrameGroupBox->setChecked( mItem->hasFrame() );
mBackgroundGroupBox->setChecked( mItem->hasBackground() );
mBlendModeCombo->setBlendMode( mItem->blendMode() );
mOpacitySlider->setValue( mItem->itemOpacity() * 1000.0 );
mOpacitySpnBx->setValue( mItem->itemOpacity() * 100.0 );
mOpacityWidget->setOpacity( mItem->itemOpacity() );
mItemRotationSpinBox->setValue( mItem->itemRotation( QgsComposerObject::OriginalValue ) );
mExcludeFromPrintsCheckBox->setChecked( mItem->excludeFromExports( QgsComposerObject::OriginalValue ) );

Expand All @@ -535,8 +530,7 @@ void QgsComposerItemWidget::setValuesForGuiNonPositionElements()
mBackgroundGroupBox->blockSignals( false );
mItemIdLineEdit->blockSignals( false );
mBlendModeCombo->blockSignals( false );
mOpacitySlider->blockSignals( false );
mOpacitySpnBx->blockSignals( false );
mOpacityWidget->blockSignals( false );
mItemRotationSpinBox->blockSignals( false );
mExcludeFromPrintsCheckBox->blockSignals( false );
}
Expand Down Expand Up @@ -593,15 +587,12 @@ void QgsComposerItemWidget::on_mBlendModeCombo_currentIndexChanged( int index )
}
}

void QgsComposerItemWidget::on_mOpacitySpnBx_valueChanged( double value )
void QgsComposerItemWidget::opacityChanged( double value )
{
mOpacitySlider->blockSignals( true );
mOpacitySlider->setValue( value * 10 );
mOpacitySlider->blockSignals( false );
if ( mItem )
{
mItem->beginCommand( tr( "Item opacity changed" ), QgsComposerMergeCommand::ItemOpacity );
mItem->setItemOpacity( value / 100.0 );
mItem->setItemOpacity( value );
mItem->endCommand();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/composer/qgscomposeritemwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class QgsComposerItemWidget: public QWidget, private Ui::QgsComposerItemWidgetBa
void on_mLowerRightCheckBox_stateChanged( int state );

void on_mBlendModeCombo_currentIndexChanged( int index );
void on_mOpacitySpnBx_valueChanged( double value );
void opacityChanged( double value );

void on_mItemRotationSpinBox_valueChanged( double val );
void on_mExcludeFromPrintsCheckBox_toggled( bool checked );
Expand Down
9 changes: 2 additions & 7 deletions src/app/qgsdiagramproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer *layer, QWidget *pare
mDiagramPenColorButton->setContext( QStringLiteral( "symbology" ) );
mDiagramPenColorButton->setShowNoColor( true );
mDiagramPenColorButton->setNoColorString( tr( "Transparent stroke" ) );
mOpacitySpinBox->setClearValue( 100.0 );

mMaxValueSpinBox->setShowClearButton( false );

Expand Down Expand Up @@ -262,8 +261,7 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer *layer, QWidget *pare
mDiagramFont = settingList.at( 0 ).font;
QSizeF size = settingList.at( 0 ).size;
mBackgroundColorButton->setColor( settingList.at( 0 ).backgroundColor );
mOpacitySpinBox->setValue( settingList.at( 0 ).opacity * 100.0 );
mOpacitySlider->setValue( mOpacitySpinBox->value() * 10 );
mOpacityWidget->setOpacity( settingList.at( 0 ).opacity );
mDiagramPenColorButton->setColor( settingList.at( 0 ).penColor );
mPenWidthSpinBox->setValue( settingList.at( 0 ).penWidth );
mDiagramSizeSpinBox->setValue( ( size.width() + size.height() ) / 2.0 );
Expand Down Expand Up @@ -405,9 +403,6 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer *layer, QWidget *pare
}

connect( mAddAttributeExpression, &QPushButton::clicked, this, &QgsDiagramProperties::showAddAttributeExpressionDialog );
connect( mOpacitySlider, &QSlider::valueChanged, this, [ = ]( int value ) { mOpacitySpinBox->setValue( value / 10.0 ); } );
connect( mOpacitySpinBox, static_cast < void ( QgsDoubleSpinBox::* )( double ) > ( &QgsDoubleSpinBox::valueChanged ), this, [ = ]( double value ) { mOpacitySlider->setValue( value * 10 ); } );

registerDataDefinedButton( mBackgroundColorDDBtn, QgsDiagramLayerSettings::BackgroundColor );
registerDataDefinedButton( mLineColorDDBtn, QgsDiagramLayerSettings::StrokeColor );
registerDataDefinedButton( mLineWidthDDBtn, QgsDiagramLayerSettings::StrokeWidth );
Expand Down Expand Up @@ -739,7 +734,7 @@ void QgsDiagramProperties::apply()
QgsDiagramSettings ds;
ds.enabled = ( mDiagramTypeComboBox->currentIndex() != 0 );
ds.font = mDiagramFont;
ds.opacity = mOpacitySpinBox->value() / 100.0;
ds.opacity = mOpacityWidget->opacity();

QList<QColor> categoryColors;
QList<QString> categoryAttributes;
Expand Down
24 changes: 5 additions & 19 deletions src/app/qgsprojectproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1133,7 +1133,7 @@ void QgsProjectProperties::apply()
QgsProject::instance()->writeEntry( QStringLiteral( "DefaultStyles" ), QStringLiteral( "/Line" ), cboStyleLine->currentText() );
QgsProject::instance()->writeEntry( QStringLiteral( "DefaultStyles" ), QStringLiteral( "/Fill" ), cboStyleFill->currentText() );
QgsProject::instance()->writeEntry( QStringLiteral( "DefaultStyles" ), QStringLiteral( "/ColorRamp" ), cboStyleColorRamp->currentText() );
QgsProject::instance()->writeEntry( QStringLiteral( "DefaultStyles" ), QStringLiteral( "/Opacity" ), 1.0 - mTransparencySlider->value() / 100.0 );
QgsProject::instance()->writeEntry( QStringLiteral( "DefaultStyles" ), QStringLiteral( "/Opacity" ), mDefaultOpacityWidget->opacity() );
QgsProject::instance()->writeEntry( QStringLiteral( "DefaultStyles" ), QStringLiteral( "/RandomColors" ), cbxStyleRandomColors->isChecked() );
if ( mTreeProjectColors->isDirty() )
{
Expand Down Expand Up @@ -1687,16 +1687,16 @@ void QgsProjectProperties::populateStyles()
cbxStyleRandomColors->setChecked( QgsProject::instance()->readBoolEntry( QStringLiteral( "DefaultStyles" ), QStringLiteral( "/RandomColors" ), true ) );

// alpha transparency
int transparencyInt = 255;
double opacity = 1.0;
bool ok = false;
double alpha = QgsProject::instance()->readDoubleEntry( QStringLiteral( "DefaultStyles" ), QStringLiteral( "/AlphaInt" ), 255, &ok );
if ( ok )
transparencyInt = alpha;
opacity = 1.0 - alpha / 255.0;
double newOpacity = QgsProject::instance()->readDoubleEntry( QStringLiteral( "DefaultStyles" ), QStringLiteral( "/Opacity" ), 1.0, &ok );
if ( ok )
transparencyInt = 255 - newOpacity * 255.0;
opacity = newOpacity;

mTransparencySlider->setValue( transparencyInt );
mDefaultOpacityWidget->setOpacity( opacity );
}

void QgsProjectProperties::on_pbtnStyleManager_clicked()
Expand Down Expand Up @@ -1728,20 +1728,6 @@ void QgsProjectProperties::on_pbtnStyleColorRamp_clicked()
on_pbtnStyleManager_clicked();
}

void QgsProjectProperties::on_mTransparencySlider_valueChanged( int value )
{
mTransparencySpinBox->blockSignals( true );
mTransparencySpinBox->setValue( value );
mTransparencySpinBox->blockSignals( false );
}

void QgsProjectProperties::on_mTransparencySpinBox_valueChanged( int value )
{
mTransparencySlider->blockSignals( true );
mTransparencySlider->setValue( value );
mTransparencySlider->blockSignals( false );
}

void QgsProjectProperties::editSymbol( QComboBox *cbo )
{
QString symbolName = cbo->currentText();
Expand Down
2 changes: 0 additions & 2 deletions src/app/qgsprojectproperties.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,6 @@ class APP_EXPORT QgsProjectProperties : public QgsOptionsDialogBase, private Ui:
void on_pbtnStyleLine_clicked();
void on_pbtnStyleFill_clicked();
void on_pbtnStyleColorRamp_clicked();
void on_mTransparencySlider_valueChanged( int value );
void on_mTransparencySpinBox_valueChanged( int value );

/**
* Slot to show the context help for this dialog
Expand Down
16 changes: 2 additions & 14 deletions src/app/qgsrasterlayerproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,6 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer *lyr, QgsMapCanv

connect( mOptionsStackedWidget, &QStackedWidget::currentChanged, this, &QgsRasterLayerProperties::mOptionsStackedWidget_CurrentChanged );

connect( sliderTransparency, &QAbstractSlider::valueChanged, this, &QgsRasterLayerProperties::sliderTransparency_valueChanged );

// brightness/contrast controls
connect( mSliderBrightness, &QAbstractSlider::valueChanged, mBrightnessSpinBox, &QSpinBox::setValue );
connect( mBrightnessSpinBox, static_cast < void ( QSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), mSliderBrightness, &QAbstractSlider::setValue );
Expand Down Expand Up @@ -651,10 +649,7 @@ void QgsRasterLayerProperties::sync()
QgsRasterRenderer *renderer = mRasterLayer->renderer();
if ( renderer )
{
sliderTransparency->setValue( ( 1.0 - renderer->opacity() ) * 255 );
//update the transparency percentage label
sliderTransparency_valueChanged( ( 1.0 - renderer->opacity() ) * 255 );

mOpacityWidget->setOpacity( renderer->opacity() );
cboxTransparencyBand->setBand( renderer->alphaBand() );
}

Expand Down Expand Up @@ -904,7 +899,7 @@ void QgsRasterLayerProperties::apply()
rasterRenderer->setRasterTransparency( rasterTransparency );

//set global transparency
rasterRenderer->setOpacity( ( 255 - sliderTransparency->value() ) / 255.0 );
rasterRenderer->setOpacity( mOpacityWidget->opacity() );
}

QgsDebugMsg( "processing general tab" );
Expand Down Expand Up @@ -1613,13 +1608,6 @@ void QgsRasterLayerProperties::pixelSelected( const QgsPoint &canvasPoint )
tableTransparency->resizeRowsToContents();
}

void QgsRasterLayerProperties::sliderTransparency_valueChanged( int value )
{
//set the transparency percentage label to a suitable value
int myInt = static_cast < int >( ( value / 255.0 ) * 100 ); //255.0 to prevent integer division
lblTransparencyPercent->setText( QString::number( myInt ) + '%' );
}//sliderTransparency_valueChanged

void QgsRasterLayerProperties::toggleSaturationControls( int grayscaleMode )
{
// Enable or disable saturation controls based on choice of grayscale mode
Expand Down
2 changes: 0 additions & 2 deletions src/app/qgsrasterlayerproperties.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ class APP_EXPORT QgsRasterLayerProperties : public QgsOptionsDialogBase, private
//void on_btnResetNull_clicked();

void pixelSelected( const QgsPoint & );
//! \brief slot executed when the transparency level changes.
void sliderTransparency_valueChanged( int );

private slots:
void on_mRenderTypeComboBox_currentIndexChanged( int index );
Expand Down
Loading

0 comments on commit d24c64f

Please sign in to comment.