Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[composer] Allow setting the join style for composer item frames
  • Loading branch information
nyalldawson committed Apr 8, 2014
1 parent 040c551 commit cfc8303
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 12 deletions.
17 changes: 17 additions & 0 deletions python/core/composer/qgscomposeritem.sip
Expand Up @@ -237,6 +237,23 @@ class QgsComposerItem : QObject, QGraphicsRectItem
*/
virtual void setFrameOutlineWidth( double outlineWidth );

/** Returns the join style used for drawing the item's frame
* @returns Join style for outline frame
* @note introduced in 2.3
* @see hasFrame
* @see setFrameJoinStyle
*/
Qt::PenJoinStyle frameJoinStyle() const;

/** Sets join style used when drawing the item's frame
* @param style Join style for outline frame
* @returns nothing
* @note introduced in 2.3
* @see setFrameEnabled
* @see frameJoinStyle
*/
void setFrameJoinStyle( Qt::PenJoinStyle style );

/** Returns the estimated amount the item's frame bleeds outside the item's
* actual rectangle. For instance, if the item has a 2mm frame outline, then
* 1mm of this frame is drawn outside the item's rect. In this case the
Expand Down
16 changes: 16 additions & 0 deletions src/app/composer/qgscomposeritemwidget.cpp
Expand Up @@ -200,6 +200,19 @@ void QgsComposerItemWidget::on_mOutlineWidthSpinBox_valueChanged( double d )
mItem->endCommand();
}

void QgsComposerItemWidget::on_mFrameJoinStyleCombo_currentIndexChanged( int index )
{
Q_UNUSED( index );
if ( !mItem )
{
return;
}

mItem->beginCommand( tr( "Item frame join style" ) );
mItem->setFrameJoinStyle( mFrameJoinStyleCombo->penJoinStyle() );
mItem->endCommand();
}

void QgsComposerItemWidget::on_mFrameGroupBox_toggled( bool state )
{
if ( !mItem )
Expand Down Expand Up @@ -339,6 +352,7 @@ void QgsComposerItemWidget::setValuesForGuiElements()
mTransparencySlider->blockSignals( true );
mTransparencySpnBx->blockSignals( true );
mFrameColorButton->blockSignals( true );
mFrameJoinStyleCombo->blockSignals( true );
mBackgroundColorButton->blockSignals( true );
mItemRotationSpinBox->blockSignals( true );

Expand All @@ -349,6 +363,7 @@ void QgsComposerItemWidget::setValuesForGuiElements()
mFrameColorButton->setColorDialogTitle( tr( "Select frame color" ) );
mFrameColorButton->setColorDialogOptions( QColorDialog::ShowAlphaChannel );
mOutlineWidthSpinBox->setValue( mItem->pen().widthF() );
mFrameJoinStyleCombo->setPenJoinStyle( mItem->frameJoinStyle() );
mItemIdLineEdit->setText( mItem->id() );
mFrameGroupBox->setChecked( mItem->hasFrame() );
mBackgroundGroupBox->setChecked( mItem->hasBackground() );
Expand All @@ -359,6 +374,7 @@ void QgsComposerItemWidget::setValuesForGuiElements()

mBackgroundColorButton->blockSignals( false );
mFrameColorButton->blockSignals( false );
mFrameJoinStyleCombo->blockSignals( false );
mOutlineWidthSpinBox->blockSignals( false );
mFrameGroupBox->blockSignals( false );
mBackgroundGroupBox->blockSignals( false );
Expand Down
1 change: 1 addition & 0 deletions src/app/composer/qgscomposeritemwidget.h
Expand Up @@ -55,6 +55,7 @@ class QgsComposerItemWidget: public QWidget, private Ui::QgsComposerItemWidgetBa
// void on_mTransparencySpinBox_valueChanged( int value );
void on_mOutlineWidthSpinBox_valueChanged( double d );
void on_mFrameGroupBox_toggled( bool state );
void on_mFrameJoinStyleCombo_currentIndexChanged( int index );
void on_mBackgroundGroupBox_toggled( bool state );
void on_mItemIdLineEdit_editingFinished();

Expand Down
24 changes: 22 additions & 2 deletions src/core/composer/qgscomposeritem.cpp
Expand Up @@ -56,6 +56,7 @@ QgsComposerItem::QgsComposerItem( QgsComposition* composition, bool manageZValue
, mFrame( false )
, mBackground( true )
, mBackgroundColor( QColor( 255, 255, 255, 255 ) )
, mFrameJoinStyle( Qt::MiterJoin )
, mItemPositionLocked( false )
, mLastValidViewScaleFactor( -1 )
, mItemRotation( 0 )
Expand All @@ -79,6 +80,7 @@ QgsComposerItem::QgsComposerItem( qreal x, qreal y, qreal width, qreal height, Q
, mFrame( false )
, mBackground( true )
, mBackgroundColor( QColor( 255, 255, 255, 255 ) )
, mFrameJoinStyle( Qt::MiterJoin )
, mItemPositionLocked( false )
, mLastValidViewScaleFactor( -1 )
, mItemRotation( 0 )
Expand All @@ -100,7 +102,7 @@ void QgsComposerItem::init( bool manageZValue )
setBrush( QBrush( QColor( 255, 255, 255, 255 ) ) );
QPen defaultPen( QColor( 0, 0, 0 ) );
defaultPen.setWidthF( 0.3 );
defaultPen.setJoinStyle( Qt::MiterJoin );
defaultPen.setJoinStyle( mFrameJoinStyle );
setPen( defaultPen );
//let z-Value be managed by composition
if ( mComposition && manageZValue )
Expand Down Expand Up @@ -175,6 +177,7 @@ bool QgsComposerItem::_writeXML( QDomElement& itemElem, QDomDocument& doc ) cons
composerItemElem.setAttribute( "positionMode", QString::number(( int ) mLastUsedPositionMode ) );
composerItemElem.setAttribute( "zValue", QString::number( zValue() ) );
composerItemElem.setAttribute( "outlineWidth", QString::number( pen().widthF() ) );
composerItemElem.setAttribute( "frameJoinStyle", QgsSymbolLayerV2Utils::encodePenJoinStyle( mFrameJoinStyle ) );
composerItemElem.setAttribute( "itemRotation", QString::number( mItemRotation ) );
composerItemElem.setAttribute( "uuid", mUuid );
composerItemElem.setAttribute( "id", mId );
Expand Down Expand Up @@ -315,11 +318,13 @@ bool QgsComposerItem::_readXML( const QDomElement& itemElem, const QDomDocument&
penGreen = frameColorElem.attribute( "green" ).toDouble( &greenOk );
penBlue = frameColorElem.attribute( "blue" ).toDouble( &blueOk );
penAlpha = frameColorElem.attribute( "alpha" ).toDouble( &alphaOk );
mFrameJoinStyle = QgsSymbolLayerV2Utils::decodePenJoinStyle( itemElem.attribute( "frameJoinStyle", "miter" ) );

if ( redOk && greenOk && blueOk && alphaOk && widthOk )
{
QPen framePen( QColor( penRed, penGreen, penBlue, penAlpha ) );
framePen.setWidthF( penWidth );
framePen.setJoinStyle( Qt::MiterJoin );
framePen.setJoinStyle( mFrameJoinStyle );
setPen( framePen );
}
}
Expand Down Expand Up @@ -370,6 +375,21 @@ void QgsComposerItem::setFrameOutlineWidth( double outlineWidth )
emit frameChanged();
}

void QgsComposerItem::setFrameJoinStyle( Qt::PenJoinStyle style )
{
if ( mFrameJoinStyle == style )
{
//no change
return;
}
mFrameJoinStyle = style;

QPen itemPen = pen();
itemPen.setJoinStyle( mFrameJoinStyle );
setPen( itemPen );
emit frameChanged();
}

double QgsComposerItem::estimatedFrameBleed() const
{
if ( !hasFrame() )
Expand Down
18 changes: 18 additions & 0 deletions src/core/composer/qgscomposeritem.h
Expand Up @@ -197,6 +197,22 @@ class CORE_EXPORT QgsComposerItem: public QObject, public QGraphicsRectItem
*/
virtual void setFrameOutlineWidth( double outlineWidth );

/** Returns the join style used for drawing the item's frame
* @returns Join style for outline frame
* @note introduced in 2.3
* @see hasFrame
* @see setFrameJoinStyle
*/
Qt::PenJoinStyle frameJoinStyle() const { return mFrameJoinStyle; }
/** Sets join style used when drawing the item's frame
* @param style Join style for outline frame
* @returns nothing
* @note introduced in 2.3
* @see setFrameEnabled
* @see frameJoinStyle
*/
void setFrameJoinStyle( Qt::PenJoinStyle style );

/** Returns the estimated amount the item's frame bleeds outside the item's
* actual rectangle. For instance, if the item has a 2mm frame outline, then
* 1mm of this frame is drawn outside the item's rect. In this case the
Expand Down Expand Up @@ -382,6 +398,8 @@ class CORE_EXPORT QgsComposerItem: public QObject, public QGraphicsRectItem
bool mBackground;
/**Background color*/
QColor mBackgroundColor;
/**Frame join style*/
Qt::PenJoinStyle mFrameJoinStyle;

/**True if item position and size cannot be changed with mouse move
@note: this member was added in version 1.2*/
Expand Down
38 changes: 28 additions & 10 deletions src/ui/qgscomposeritemwidgetbase.ui
Expand Up @@ -14,7 +14,16 @@
<string>Global Options</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="margin">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
Expand Down Expand Up @@ -264,12 +273,13 @@
<bool>true</bool>
</property>
<layout class="QFormLayout" name="formLayout_4">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<property name="labelAlignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
<item row="0" column="0" colspan="2">
<widget class="QgsColorButton" name="mFrameColorButton">
<property name="text">
<string>Color...</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="mOutlineWidthLabel">
<property name="text">
Expand All @@ -286,13 +296,16 @@
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="mOutlineWidthSpinBox"/>
</item>
<item row="0" column="0" colspan="2">
<widget class="QgsColorButton" name="mFrameColorButton">
<item row="2" column="0">
<widget class="QLabel" name="label_8">
<property name="text">
<string>Color...</string>
<string>Join style</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QgsPenJoinStyleComboBox" name="mFrameJoinStyleCombo"/>
</item>
</layout>
</widget>
</item>
Expand Down Expand Up @@ -449,6 +462,11 @@
<header location="global">qgscollapsiblegroupbox.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsPenJoinStyleComboBox</class>
<extends>QComboBox</extends>
<header>qgspenstylecombobox.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
Expand Down

0 comments on commit cfc8303

Please sign in to comment.