28 #include <QStandardItemModel> 29 #include <QStandardItem> 31 #include <QToolButton> 35 static const int EffectItemType = QStandardItem::UserType + 1;
44 mWidget = propertiesWidget;
53 int type()
const override {
return EffectItemType; }
62 if ( role == Qt::DisplayRole || role == Qt::EditRole )
66 if ( role == Qt::CheckStateRole )
68 return mEffect->enabled() ? Qt::Checked : Qt::Unchecked;
75 if ( role == Qt::CheckStateRole )
77 mEffect->setEnabled( value.
toBool() );
78 mWidget->updatePreview();
99 , mPreviewPicture( nullptr )
118 mEffectsList->setModel(
mModel );
135 for (
int i = 0; i < stack->
count(); ++i )
145 mEffectsList->setCurrentIndex( newIndex );
175 int count = stack->
count();
176 for (
int i = count - 1; i >= 0; i-- )
178 EffectItem* effectItem =
new EffectItem( stack->
effect( i ), this );
179 effectItem->setEditable(
false );
180 parent->appendRow( effectItem );
193 QModelIndex currentIdx = mEffectsList->currentIndex();
201 int currentRow = item ? item->row() : 0;
203 mUpButton->setEnabled( currentRow > 0 );
204 mDownButton->setEnabled( currentRow < rowCount - 1 );
205 mRemoveButton->setEnabled( rowCount > 1 );
211 QImage previewImage( 150, 150, QImage::Format_ARGB32 );
212 previewImage.
fill( Qt::transparent );
213 painter.
begin( &previewImage );
220 previewPicPainter.
begin( &previewPic );
221 previewPicPainter.
setPen( Qt::red );
224 previewPicPainter.
end();
266 int index = stackedWidget->addWidget( widget );
267 stackedWidget->setCurrentIndex( index );
282 EffectItem *newEffectItem =
new EffectItem( newEffect,
this );
293 int row = item->row();
296 int layerIdx = root->
rowCount() - row - 1;
301 int newSelection = qMin( row, root->
rowCount() - 1 );
303 mEffectsList->setCurrentIndex( newIdx );
327 int row = item->row();
331 int layerIdx = root->
rowCount() - row - 1;
340 mEffectsList->setCurrentIndex( newIdx );
349 item->setEffect( newEffect );
352 int effectIdx = root->
rowCount() - item->row() - 1;
367 , mPropertiesWidget( nullptr )
395 , mEnabledCheckBox( nullptr )
397 , mPreviewPicture( nullptr )
404 mEnabledCheckBox =
new QCheckBox(
this );
405 mEnabledCheckBox->
setText(
tr(
"Draw effects" ) );
416 connect( mButton, SIGNAL( clicked() ),
this, SLOT( showDialog() ) );
417 connect( mEnabledCheckBox, SIGNAL( toggled(
bool ) ),
this, SLOT( enableToggled(
bool ) ) );
424 delete mPreviewPicture;
454 delete mPreviewPicture;
455 mPreviewPicture =
new QPicture( picture );
458 void QgsEffectStackCompactWidget::showDialog()
465 if ( mPreviewPicture )
474 void QgsEffectStackCompactWidget::enableToggled(
bool checked )
486 void QgsEffectStackCompactWidget::updateAcceptWidget(
QgsPanelWidget *panel )
489 *mStack = *widget->
stack();
494 void QgsEffectStackCompactWidget::updateEffectLive()
497 *mStack = *widget->
stack();
void setContentsMargins(int left, int top, int right, int bottom)
void setEnabled(const bool enabled)
Sets whether the effect is enabled.
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const=0
void setRenderHint(RenderHint hint, bool on)
QStandardItem * invisibleRootItem() const
QList< QStandardItem * > takeRow(int row)
static QIcon getThemeIcon(const QString &theName)
Helper to get a theme icon.
static QString iconPath(const QString &iconFile)
Returns path to the desired icon file.
Base class for visual effects which can be applied to QPicture drawings.
A generic dialog with layout and button box.
QPixmap fromImage(const QImage &image, QFlags< Qt::ImageConversionFlag > flags)
QString tr(const char *sourceText, const char *disambiguation, int n)
virtual void setData(const QVariant &value, int role)
static QgsRenderContext createRenderContext(QPainter *p)
Creates a render context for a pixel based device.
int count() const
Returns count of effects contained by the stack.
void setPreviewPicture(const QPicture &picture)
Sets the picture to use for effect previews for the dialog.
QModelIndex indexFromItem(const QStandardItem *item) const
void fill(uint pixelValue)
static QgsPaintEffectRegistry * instance()
Returns a reference to the singleton instance of the paint effect registry.
void setPen(const QColor &color)
void drawEllipse(const QRectF &rectangle)
QgsPaintEffect * effect(int index) const
Returns a pointer to the effect at a specified index within the stack.
void insertRows(int row, const QList< QStandardItem * > &items)
void setBrush(const QBrush &brush)
A paint effect which consists of a stack of other chained paint effects.
virtual QgsEffectStack * clone() const override
Duplicates an effect by creating a deep copy of the effect.
bool changeEffect(const int index, QgsPaintEffect *effect)
Replaces the effect at a specified position within the stack.
bool enabled() const
Returns whether the effect is enabled.
bool insertEffect(const int index, QgsPaintEffect *effect)
Inserts an effect at a specified index within the stack.
~QgsEffectStackPropertiesDialog()
QStandardItem * child(int row, int column) const
QgsEffectStackPropertiesDialog(QgsEffectStack *stack, QWidget *parent=nullptr, const Qt::WindowFlags &f=nullptr)
QgsEffectStackPropertiesDialog constructor.
QgsEffectStack * stack()
Returns effect stack attached to the dialog.
QgsPaintEffectAbstractMetadata * effectMetadata(const QString &name) const
Returns the metadata for a specific effect.
Contains information about the context of a rendering operation.
const QAbstractItemModel * model() const
QStandardItem * itemFromIndex(const QModelIndex &index) const
QVBoxLayout * layout()
Returns the central layout. Widgets added to it must have this dialog as parent.
void translate(const QPointF &offset)
QModelIndex index() const
void setText(const QString &text)
QgsEffectStackPropertiesWidget * mPropertiesWidget
virtual void render(QPicture &picture, QgsRenderContext &context)
Renders a picture using the effect.
A paint effect which draws the source picture with minor or no alterations.
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
bool begin(QPaintDevice *device)
void setCheckable(bool checkable)
virtual QVariant data(int role) const
void insertRow(int row, const QList< QStandardItem * > &items)
void setSpacing(int spacing)
QgsPaintEffect * takeEffect(const int index)
Removes an effect from the stack and returns a pointer to it.