Skip to content
Permalink
Browse files
[composer] Allow setting the join style for composer item frames
  • Loading branch information
nyalldawson committed Apr 8, 2014
1 parent 040c551 commit cfc83031eff339c67e1816847bc7e93afe653781
@@ -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
@@ -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 )
@@ -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 );

@@ -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() );
@@ -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 );
@@ -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();

@@ -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 )
@@ -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 )
@@ -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 )
@@ -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 );
@@ -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 );
}
}
@@ -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() )
@@ -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
@@ -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*/
@@ -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>
@@ -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">
@@ -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>
@@ -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/>

0 comments on commit cfc8303

Please sign in to comment.