Skip to content

Commit

Permalink
[FEATURE] Transparency control for composer items
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Apr 1, 2013
1 parent 32ec65c commit 7b6e322
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/app/composer/qgscomposeritemwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
Expand All @@ -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 );
Expand All @@ -381,6 +383,7 @@ void QgsComposerItemWidget::setValuesForGuiElements()
mItemIdLineEdit->blockSignals( false );
mItemUuidLineEdit->blockSignals( false );
mBlendModeCombo->blockSignals( false );
mTransparencySlider->blockSignals( false );
// mTransparencySpinBox->blockSignals( false );
}

Expand All @@ -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 )
Expand Down
1 change: 1 addition & 0 deletions src/app/composer/qgscomposeritemwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
14 changes: 14 additions & 0 deletions src/core/composer/qgscomposeritem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() )
Expand All @@ -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() )
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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 )
{
Expand Down
8 changes: 8 additions & 0 deletions src/core/composer/qgscomposeritem.h
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
Expand Down Expand Up @@ -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;
Expand Down
17 changes: 17 additions & 0 deletions src/ui/qgscomposeritemwidgetbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit 7b6e322

Please sign in to comment.