Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[feature] added draw background checkbox in composer items
(this allow to workaround the non-opaque background bug with atlas and is more consistent with the frame settings) )
  • Loading branch information
olivierdalang committed Jan 29, 2013
1 parent 94491b8 commit ec0d944
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 69 deletions.
24 changes: 24 additions & 0 deletions src/app/composer/qgscomposeritemwidget.cpp
Expand Up @@ -150,16 +150,40 @@ void QgsComposerItemWidget::on_mFrameCheckBox_stateChanged( int state )
mItem->beginCommand( tr( "Item frame toggled" ) );
if ( state == Qt::Checked )
{
mFrameBox->setEnabled( true );
mItem->setFrameEnabled( true );
}
else
{
mFrameBox->setEnabled( false );
mItem->setFrameEnabled( false );
}
mItem->update();
mItem->endCommand();
}

void QgsComposerItemWidget::on_mBackgroundCheckBox_stateChanged( int state )
{
if ( !mItem )
{
return;
}

mItem->beginCommand( tr( "Item background toggled" ) );
if ( state == Qt::Checked )
{
mBackgroundBox->setEnabled( true );
mItem->setBackgroundEnabled( true );
}
else
{
mBackgroundBox->setEnabled( false );
mItem->setBackgroundEnabled( false );
}
mItem->update();
mItem->endCommand();
}

void QgsComposerItemWidget::setValuesForGuiElements()
{
if ( !mItem )
Expand Down
1 change: 1 addition & 0 deletions src/app/composer/qgscomposeritemwidget.h
Expand Up @@ -38,6 +38,7 @@ class QgsComposerItemWidget: public QWidget, private Ui::QgsComposerItemWidgetBa
void on_mOpacitySpinBox_valueChanged( int value );
void on_mOutlineWidthSpinBox_valueChanged( double d );
void on_mFrameCheckBox_stateChanged( int state );
void on_mBackgroundCheckBox_stateChanged( int state );
void on_mPositionButton_clicked();
void on_mItemIdLineEdit_textChanged( const QString& text );

Expand Down
27 changes: 25 additions & 2 deletions src/core/composer/qgscomposeritem.cpp
Expand Up @@ -46,6 +46,7 @@ QgsComposerItem::QgsComposerItem( QgsComposition* composition, bool manageZValue
, mHAlignSnapItem( 0 )
, mVAlignSnapItem( 0 )
, mFrame( false )
, mBackground( true )
, mItemPositionLocked( false )
, mLastValidViewScaleFactor( -1 )
, mRotation( 0 )
Expand All @@ -61,6 +62,7 @@ QgsComposerItem::QgsComposerItem( qreal x, qreal y, qreal width, qreal height, Q
, mHAlignSnapItem( 0 )
, mVAlignSnapItem( 0 )
, mFrame( false )
, mBackground( true )
, mItemPositionLocked( false )
, mLastValidViewScaleFactor( -1 )
, mRotation( 0 )
Expand Down Expand Up @@ -130,6 +132,16 @@ bool QgsComposerItem::_writeXML( QDomElement& itemElem, QDomDocument& doc ) cons
composerItemElem.setAttribute( "frame", "false" );
}

//frame
if ( mBackground )
{
composerItemElem.setAttribute( "background", "true" );
}
else
{
composerItemElem.setAttribute( "background", "false" );
}

//scene rect
composerItemElem.setAttribute( "x", QString::number( transform().dx() ) );
composerItemElem.setAttribute( "y", QString::number( transform().dy() ) );
Expand Down Expand Up @@ -200,6 +212,17 @@ bool QgsComposerItem::_readXML( const QDomElement& itemElem, const QDomDocument&
mFrame = false;
}

//frame
QString background = itemElem.attribute( "background" );
if ( background.compare( "true", Qt::CaseInsensitive ) == 0 )
{
mBackground = true;
}
else
{
mBackground = false;
}

//position lock for mouse moves/resizes
QString positionLock = itemElem.attribute( "positionLock" );
if ( positionLock.compare( "true", Qt::CaseInsensitive ) == 0 )
Expand Down Expand Up @@ -799,9 +822,9 @@ void QgsComposerItem::setSceneRect( const QRectF& rectangle )

void QgsComposerItem::drawBackground( QPainter* p )
{
if ( p )
if ( mBackground && p )
{
p->setBrush( brush() );
p->setBrush( brush() );//this causes a problem in atlas generation
p->setPen( Qt::NoPen );
p->setRenderHint( QPainter::Antialiasing, true );
p->drawRect( QRectF( 0, 0, rect().width(), rect().height() ) );
Expand Down
18 changes: 18 additions & 0 deletions src/core/composer/qgscomposeritem.h
Expand Up @@ -175,6 +175,22 @@ class CORE_EXPORT QgsComposerItem: public QObject, public QGraphicsRectItem
*/
void setFrameEnabled( bool drawFrame ) {mFrame = drawFrame;}


/** Whether this item has a Background or not.
* @returns true if there is a Background around this item, otherwise false.
* @note introduced since 2.0
* @see hasBackground
*/
bool hasBackground() const {return mBackground;}

/** Set whether this item has a Background drawn around it or not.
* @param drawBackground draw Background
* @returns nothing
* @note introduced in 2.0
* @see hasBackground
*/
void setBackgroundEnabled( bool drawBackground ) {mBackground = drawBackground;}

/**Composite operations for item groups do nothing per default*/
virtual void addItem( QgsComposerItem* item ) { Q_UNUSED( item ); }
virtual void removeItems() {}
Expand Down Expand Up @@ -271,6 +287,8 @@ class CORE_EXPORT QgsComposerItem: public QObject, public QGraphicsRectItem

/**True if item fram needs to be painted*/
bool mFrame;
/**True if item background needs to be painted*/
bool mBackground;

/**True if item position and size cannot be changed with mouse move
@note: this member was added in version 1.2*/
Expand Down
158 changes: 91 additions & 67 deletions src/ui/qgscomposeritemwidgetbase.ui
Expand Up @@ -6,103 +6,120 @@
<rect>
<x>0</x>
<y>0</y>
<width>235</width>
<height>277</height>
<width>393</width>
<height>391</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" colspan="3">
<widget class="QPushButton" name="mFrameColorButton">
<layout class="QFormLayout" name="formLayout_2">
<item row="1" column="0">
<widget class="QCheckBox" name="mFrameCheckBox">
<property name="text">
<string>Frame color...</string>
<string>Show frame</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="3">
<widget class="QPushButton" name="mBackgroundColorButton">
<property name="text">
<string>Background color...</string>
<item row="2" column="0" colspan="2">
<widget class="QGroupBox" name="mFrameBox">
<property name="title">
<string>Frame settings</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0" colspan="2">
<widget class="QPushButton" name="mFrameColorButton">
<property name="text">
<string>Frame color...</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="mOutlineWidthLabel">
<property name="text">
<string>Thickness</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="buddy">
<cstring>mOutlineWidthSpinBox</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="mOutlineWidthSpinBox"/>
</item>
</layout>
</widget>
</item>
<item row="2" column="0" colspan="3">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="mOpacityLabel">
<property name="text">
<string>Opacity</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="buddy">
<cstring>mOpacitySlider</cstring>
</property>
</widget>
</item>
<item>
<widget class="QSlider" name="mOpacitySlider">
<property name="maximum">
<number>255</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="mOpacitySpinBox">
<property name="maximum">
<number>255</number>
</property>
</widget>
</item>
</layout>
</item>
<item row="3" column="0">
<widget class="QLabel" name="mOutlineWidthLabel">
<widget class="QCheckBox" name="mBackgroundCheckBox">
<property name="text">
<string>Outline width</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="buddy">
<cstring>mOutlineWidthSpinBox</cstring>
<string>Show background</string>
</property>
</widget>
</item>
<item row="3" column="2">
<widget class="QDoubleSpinBox" name="mOutlineWidthSpinBox"/>
</item>
<item row="4" column="0" colspan="3">
<widget class="QPushButton" name="mPositionButton">
<property name="text">
<string>Position and size...</string>
<item row="4" column="0" colspan="2">
<widget class="QGroupBox" name="mBackgroundBox">
<property name="title">
<string>Background settings</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" colspan="3">
<widget class="QPushButton" name="mBackgroundColorButton">
<property name="text">
<string>Background color...</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="mOpacityLabel">
<property name="text">
<string>Opacity</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="buddy">
<cstring>mOpacitySlider</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSlider" name="mOpacitySlider">
<property name="maximum">
<number>255</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QSpinBox" name="mOpacitySpinBox">
<property name="maximum">
<number>255</number>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="5" column="0" colspan="2">
<widget class="QCheckBox" name="mFrameCheckBox">
<property name="text">
<string>Show frame</string>
</property>
</widget>
<layout class="QHBoxLayout" name="horizontalLayout"/>
</item>
<item row="6" column="0">
<item row="7" column="0">
<widget class="QLabel" name="mIdLabel">
<property name="text">
<string>Item ID</string>
</property>
</widget>
</item>
<item row="6" column="1" colspan="2">
<item row="7" column="1">
<widget class="QLineEdit" name="mItemIdLineEdit"/>
</item>
<item row="7" column="0" colspan="2">
<item row="8" column="0" colspan="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
Expand All @@ -115,6 +132,13 @@
</property>
</spacer>
</item>
<item row="0" column="0" colspan="2">
<widget class="QPushButton" name="mPositionButton">
<property name="text">
<string>Position and size...</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
Expand Down

0 comments on commit ec0d944

Please sign in to comment.