Skip to content
Permalink
Browse files
Also show annotation layer opacity, blend mode and paint effect widget
in the layer styling dock, so that live changes can be made
  • Loading branch information
nyalldawson committed Sep 10, 2021
1 parent 5e150f9 commit 0f1cbd2b075f7d1188dc38c0a422e00dee0144c4
@@ -22,14 +22,16 @@
#include "qgsannotationitem.h"
#include "qgsgui.h"
#include "qgsannotationitemguiregistry.h"
#include "qgspainteffect.h"

#include <QStackedWidget>
#include <QHBoxLayout>
#include <QLabel>

QgsAnnotationItemPropertiesWidget::QgsAnnotationItemPropertiesWidget( QgsAnnotationLayer *layer, QgsMapCanvas *canvas, QWidget *parent )
: QgsMapLayerConfigWidget( layer, canvas, parent )
{
mStack = new QStackedWidget();
setupUi( this );

mPageNoItem = new QWidget();
QSizePolicy sizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred );
@@ -46,16 +48,17 @@ QgsAnnotationItemPropertiesWidget::QgsAnnotationItemPropertiesWidget( QgsAnnotat
mStack->addWidget( mPageNoItem );
mStack->setCurrentWidget( mPageNoItem );

setDockMode( true );
connect( mOpacityWidget, &QgsOpacityWidget::opacityChanged, this, &QgsAnnotationItemPropertiesWidget::onLayerPropertyChanged );
connect( mBlendModeComboBox, qOverload< int >( &QgsBlendModeComboBox::currentIndexChanged ), this, &QgsAnnotationItemPropertiesWidget::onLayerPropertyChanged );
connect( mEffectWidget, &QgsEffectStackCompactWidget::changed, this, &QgsAnnotationItemPropertiesWidget::onLayerPropertyChanged );

QHBoxLayout *l = new QHBoxLayout();
l->setContentsMargins( 0, 0, 0, 0 );
l->addWidget( mStack );
setLayout( l );
setDockMode( true );

syncToLayer( layer );
}

QgsAnnotationItemPropertiesWidget::~QgsAnnotationItemPropertiesWidget() = default;

void QgsAnnotationItemPropertiesWidget::syncToLayer( QgsMapLayer *layer )
{
if ( layer == mLayer )
@@ -65,6 +68,17 @@ void QgsAnnotationItemPropertiesWidget::syncToLayer( QgsMapLayer *layer )
if ( !mLayer )
return;

// opacity and blend modes
mBlockLayerUpdates = true;
mBlendModeComboBox->setBlendMode( mLayer->blendMode() );
mOpacityWidget->setOpacity( mLayer->opacity() );
if ( mLayer->paintEffect() )
{
mPaintEffect.reset( mLayer->paintEffect()->clone() );
mEffectWidget->setPaintEffect( mPaintEffect.get() );
}
mBlockLayerUpdates = false;

// check context
setItemId( mMapLayerConfigWidgetContext.annotationId() );
}
@@ -95,6 +109,13 @@ void QgsAnnotationItemPropertiesWidget::apply()
if ( !mLayer )
return;

// set the blend mode and opacity for the layer
mLayer->setBlendMode( mBlendModeComboBox->blendMode() );
mLayer->setOpacity( mOpacityWidget->opacity() );

if ( mPaintEffect )
mLayer->setPaintEffect( mPaintEffect->clone() );

mLayer->triggerRepaint();
}

@@ -121,6 +142,14 @@ void QgsAnnotationItemPropertiesWidget::onChanged()
}
}

void QgsAnnotationItemPropertiesWidget::onLayerPropertyChanged()
{
if ( mBlockLayerUpdates )
return;

emit widgetChanged();
}

void QgsAnnotationItemPropertiesWidget::setItemId( const QString &itemId )
{
if ( !mLayer )
@@ -18,18 +18,20 @@

#include "qgsmaplayerconfigwidget.h"
#include "qgsmaplayerconfigwidgetfactory.h"
#include "ui_qgsannotationitempropertieswidgetbase.h"
#include <QPointer>

class QgsAnnotationLayer;
class QgsAnnotationItemBaseWidget;
class QStackedWidget;

class QgsAnnotationItemPropertiesWidget : public QgsMapLayerConfigWidget
class QgsAnnotationItemPropertiesWidget : public QgsMapLayerConfigWidget, public Ui::QgsAnnotationItemPropertiesWidgetBase
{
Q_OBJECT
public:

QgsAnnotationItemPropertiesWidget( QgsAnnotationLayer *layer, QgsMapCanvas *canvas, QWidget *parent );
~QgsAnnotationItemPropertiesWidget() override;

void syncToLayer( QgsMapLayer *layer ) override;
void setMapLayerConfigWidgetContext( const QgsMapLayerConfigWidgetContext &context ) override;
@@ -42,14 +44,17 @@ class QgsAnnotationItemPropertiesWidget : public QgsMapLayerConfigWidget
private slots:

void onChanged();
void onLayerPropertyChanged();
private:

void setItemId( const QString &itemId );

QStackedWidget *mStack = nullptr;
QPointer< QgsAnnotationLayer > mLayer;
QPointer< QgsAnnotationItemBaseWidget > mItemWidget;
QWidget *mPageNoItem = nullptr;
bool mBlockLayerUpdates = false;

std::unique_ptr< QgsPaintEffect > mPaintEffect;

};

@@ -0,0 +1,132 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>QgsAnnotationItemPropertiesWidgetBase</class>
<widget class="QWidget" name="QgsAnnotationItemPropertiesWidgetBase">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>424</width>
<height>702</height>
</rect>
</property>
<property name="windowTitle">
<string>Annotation Item Properties</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<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>
<widget class="QStackedWidget" name="mStack">
<property name="currentIndex">
<number>1</number>
</property>
<widget class="QWidget" name="page"/>
<widget class="QWidget" name="page_2"/>
</widget>
</item>
<item>
<widget class="QGroupBox" name="mLayerRenderingGroupBox">
<property name="title">
<string>Layer Rendering</string>
</property>
<property name="flat">
<bool>true</bool>
</property>
<property name="checkable">
<bool>false</bool>
</property>
<property name="collapsed" stdset="0">
<bool>true</bool>
</property>
<property name="saveCollapsedState" stdset="0">
<bool>false</bool>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>3</number>
</property>
<item row="0" column="1" colspan="3">
<widget class="QgsOpacityWidget" name="mOpacityWidget" native="true">
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="lblBlend">
<property name="text">
<string>Blending mode</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="lblTransparency">
<property name="text">
<string>Opacity</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="4">
<widget class="QgsEffectStackCompactWidget" name="mEffectWidget" native="true">
<property name="minimumSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
</widget>
</item>
<item row="1" column="1" colspan="3">
<widget class="QgsBlendModeComboBox" name="mBlendModeComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>4</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>QgsBlendModeComboBox</class>
<extends>QComboBox</extends>
<header>qgsblendmodecombobox.h</header>
</customwidget>
<customwidget>
<class>QgsEffectStackCompactWidget</class>
<extends>QWidget</extends>
<header>qgseffectstackpropertieswidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsOpacityWidget</class>
<extends>QWidget</extends>
<header>qgsopacitywidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

0 comments on commit 0f1cbd2

Please sign in to comment.