27 #include <QStandardItemModel> 28 #include <QStandardItem> 30 #include <QToolButton> 34 static const int EffectItemType = QStandardItem::UserType + 1;
43 mWidget = propertiesWidget;
52 int type()
const override {
return EffectItemType; }
61 if ( role == Qt::DisplayRole || role == Qt::EditRole )
65 if ( role == Qt::CheckStateRole )
67 return mEffect->enabled() ? Qt::Checked : Qt::Unchecked;
74 if ( role == Qt::CheckStateRole )
76 mEffect->setEnabled( value.
toBool() );
77 mWidget->updatePreview();
98 , mPreviewPicture( nullptr )
117 mEffectsList->setModel(
mModel );
134 mEffectsList->setCurrentIndex( newIndex );
162 int count = stack->
count();
163 for (
int i = count - 1; i >= 0; i-- )
165 EffectItem* effectItem =
new EffectItem( stack->
effect( i ), this );
166 effectItem->setEditable(
false );
167 parent->appendRow( effectItem );
180 QModelIndex currentIdx = mEffectsList->currentIndex();
188 int currentRow = item ? item->row() : 0;
190 mUpButton->setEnabled( currentRow > 0 );
191 mDownButton->setEnabled( currentRow < rowCount - 1 );
192 mRemoveButton->setEnabled( rowCount > 1 );
198 QImage previewImage( 150, 150, QImage::Format_ARGB32 );
199 previewImage.
fill( Qt::transparent );
200 painter.
begin( &previewImage );
207 previewPicPainter.
begin( &previewPic );
208 previewPicPainter.
setPen( Qt::red );
211 previewPicPainter.
end();
252 int index = stackedWidget->addWidget( widget );
253 stackedWidget->setCurrentIndex( index );
268 EffectItem *newEffectItem =
new EffectItem( newEffect,
this );
279 int row = item->row();
282 int layerIdx = root->
rowCount() - row - 1;
287 int newSelection = qMin( row, root->
rowCount() - 1 );
289 mEffectsList->setCurrentIndex( newIdx );
313 int row = item->row();
317 int layerIdx = root->
rowCount() - row - 1;
326 mEffectsList->setCurrentIndex( newIdx );
335 item->setEffect( newEffect );
338 int effectIdx = root->
rowCount() - item->row() - 1;
353 , mPropertiesWidget( nullptr )
381 , mEnabledCheckBox( nullptr )
383 , mPreviewPicture( nullptr )
390 mEnabledCheckBox =
new QCheckBox(
this );
391 mEnabledCheckBox->
setText(
tr(
"Draw effects" ) );
402 connect( mButton, SIGNAL( clicked() ),
this, SLOT( showDialog() ) );
403 connect( mEnabledCheckBox, SIGNAL( toggled(
bool ) ),
this, SLOT( enableToggled(
bool ) ) );
410 delete mPreviewPicture;
440 delete mPreviewPicture;
441 mPreviewPicture =
new QPicture( picture );
444 void QgsEffectStackCompactWidget::showDialog()
451 if ( mPreviewPicture )
455 if ( dialog.
exec() == QDialog::Accepted )
464 void QgsEffectStackCompactWidget::enableToggled(
bool checked )
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.
A dialog for modifying the properties of a QgsEffectStack, including adding and reordering effects wi...
bool enabled() const
Returns whether the effect is enabled.
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)
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 insertEffect(const int index, QgsPaintEffect *effect)
Inserts an effect at a specified index within the stack.
~QgsEffectStackPropertiesDialog()
QgsPaintEffectAbstractMetadata * effectMetadata(const QString &name) const
Returns the metadata for a specific effect.
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.
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)
QgsPaintEffect * effect(int index) const
Returns a pointer to the effect at a specified index within the stack.
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.