Skip to content
Permalink
Browse files

[FEATURE] Transparency control for composer items

  • Loading branch information
nyalldawson committed Apr 1, 2013
1 parent 32ec65c commit 7b6e322bf9d9d00473cb4c8cd5483e3949487c66
@@ -355,6 +355,7 @@ void QgsComposerItemWidget::setValuesForGuiElements()
mItemIdLineEdit->blockSignals( true );
mItemUuidLineEdit->blockSignals( true );
mBlendModeCombo->blockSignals( true );
mTransparencySlider->blockSignals( true );
// mTransparencySpinBox->blockSignals( true );

mBackgroundColorButton->setColor( mItem->brush().color() );
@@ -373,6 +374,7 @@ void QgsComposerItemWidget::setValuesForGuiElements()
mFrameGroupBox->setChecked( mItem->hasFrame() );
mBackgroundGroupBox->setChecked( mItem->hasBackground() );
mBlendModeCombo->setBlendMode( mItem->blendMode() );
mTransparencySlider->setValue( mItem->transparency() );

// mTransparencySlider->blockSignals( false );
mOutlineWidthSpinBox->blockSignals( false );
@@ -381,6 +383,7 @@ void QgsComposerItemWidget::setValuesForGuiElements()
mItemIdLineEdit->blockSignals( false );
mItemUuidLineEdit->blockSignals( false );
mBlendModeCombo->blockSignals( false );
mTransparencySlider->blockSignals( false );
// mTransparencySpinBox->blockSignals( false );
}

@@ -393,6 +396,14 @@ void QgsComposerItemWidget::on_mBlendModeCombo_currentIndexChanged( int index )
}
}

void QgsComposerItemWidget::on_mTransparencySlider_valueChanged( int value )
{
if ( mItem )
{
mItem->setTransparency( value );
}
}

void QgsComposerItemWidget::on_mItemIdLineEdit_editingFinished()
{
if ( mItem )
@@ -71,6 +71,7 @@ class QgsComposerItemWidget: public QWidget, private Ui::QgsComposerItemWidgetBa
void on_mLowerRightCheckBox_stateChanged( int state ) { Q_UNUSED( state ); changeItemPosition(); }

void on_mBlendModeCombo_currentIndexChanged( int index );
void on_mTransparencySlider_valueChanged( int value );

void setValuesForGuiElements();
void setValuesForGuiPositionElements();
@@ -55,6 +55,7 @@ QgsComposerItem::QgsComposerItem( QgsComposition* composition, bool manageZValue
, mLastValidViewScaleFactor( -1 )
, mRotation( 0 )
, mBlendMode( QgsMapRenderer::BlendNormal )
, mTransparency( 0 )
, mLastUsedPositionMode( UpperLeft )
, mId( "" )
, mUuid( QUuid::createUuid().toString() )
@@ -75,6 +76,7 @@ QgsComposerItem::QgsComposerItem( qreal x, qreal y, qreal width, qreal height, Q
, mLastValidViewScaleFactor( -1 )
, mRotation( 0 )
, mBlendMode( QgsMapRenderer::BlendNormal )
, mTransparency( 0 )
, mLastUsedPositionMode( UpperLeft )
, mId( "" )
, mUuid( QUuid::createUuid().toString() )
@@ -205,6 +207,9 @@ bool QgsComposerItem::_writeXML( QDomElement& itemElem, QDomDocument& doc ) cons
//blend mode
composerItemElem.setAttribute( "blendMode", QString::number( mBlendMode ) );

//transparency
composerItemElem.setAttribute( "transparency", QString::number( mTransparency ) );

itemElem.appendChild( composerItemElem );

return true;
@@ -328,6 +333,9 @@ bool QgsComposerItem::_readXML( const QDomElement& itemElem, const QDomDocument&
//blend mode
setBlendMode(( QgsMapRenderer::BlendMode ) itemElem.attribute( "blendMode" , "0" ).toInt() );

//transparency
setTransparency( itemElem.attribute( "transparency" , "0" ).toInt() );

return true;
}

@@ -883,6 +891,12 @@ void QgsComposerItem::setBlendMode( QgsMapRenderer::BlendMode blendMode )
mEffect->setCompositionMode( QgsMapRenderer::getCompositionMode( mBlendMode ) );
}

void QgsComposerItem::setTransparency( int transparency )
{
mTransparency = transparency;
// Set the QGraphicItem's opacity
setOpacity( 1. - ( transparency / 100. ) );
}

void QgsComposerItem::hoverMoveEvent( QGraphicsSceneHoverEvent * event )
{
@@ -203,6 +203,11 @@ class CORE_EXPORT QgsComposerItem: public QObject, public QGraphicsRectItem
/** Sets the item's composition blending mode*/
void setBlendMode( QgsMapRenderer::BlendMode blendMode );

/** Returns the item's transparency */
int transparency() const {return mTransparency;}
/** Sets the item's transparency */
void setTransparency( int transparency );

/**Composite operations for item groups do nothing per default*/
virtual void addItem( QgsComposerItem* item ) { Q_UNUSED( item ); }
virtual void removeItems() {}
@@ -320,6 +325,9 @@ class CORE_EXPORT QgsComposerItem: public QObject, public QGraphicsRectItem

QgsComposerEffect *mEffect;

/**Item transparency*/
int mTransparency;

/**The item's position mode
@note: this member was added in version 2.0*/
ItemPositionMode mLastUsedPositionMode;
@@ -356,6 +356,23 @@
<item row="0" column="1">
<widget class="QgsBlendModeComboBox" name="mBlendModeCombo"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="labelTransparency">
<property name="text">
<string>Transparency</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSlider" name="mTransparencySlider">
<property name="maximum">
<number>100</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
</widget>
</item>

0 comments on commit 7b6e322

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