28 #include <QStandardItemModel> 29 #include <QStandardItem> 31 #include <QToolButton> 35 static const int EFFECT_ITEM_TYPE = QStandardItem::UserType + 1;
37 class EffectItem :
public QStandardItem
44 mWidget = propertiesWidget;
53 int type()
const override {
return EFFECT_ITEM_TYPE; }
60 QVariant data(
int role )
const override 62 if ( role == Qt::DisplayRole || role == Qt::EditRole )
66 if ( role == Qt::CheckStateRole )
68 return mEffect->enabled() ? Qt::Checked : Qt::Unchecked;
70 return QStandardItem::data( role );
73 void setData(
const QVariant &value,
int role )
override 75 if ( role == Qt::CheckStateRole )
77 mEffect->setEnabled( value.toBool() );
78 mWidget->updatePreview();
82 QStandardItem::setData( value, role );
116 mModel =
new QStandardItemModel();
118 mEffectsList->setModel(
mModel );
120 QItemSelectionModel *selModel = mEffectsList->selectionModel();
135 for (
int i = 0; i < stack->
count(); ++i )
138 if ( stack->
effect( stack->
count() - i - 1 )->enabled() )
144 QModelIndex newIndex = mEffectsList->model()->index( initialRow, 0 );
145 mEffectsList->setCurrentIndex( newIndex );
173 EffectItem *parent =
static_cast<EffectItem *
>(
mModel->invisibleRootItem() );
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();
194 if ( !currentIdx.isValid() )
197 EffectItem *item =
static_cast<EffectItem *
>(
mModel->itemFromIndex( currentIdx ) );
199 QStandardItem *root =
mModel->invisibleRootItem();
200 int rowCount = root->rowCount();
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 );
214 painter.setRenderHint( QPainter::Antialiasing );
219 QPainter previewPicPainter;
220 previewPicPainter.begin( &previewPic );
221 previewPicPainter.setPen( Qt::red );
222 previewPicPainter.setBrush( QColor( 255, 100, 100, 255 ) );
223 previewPicPainter.drawEllipse( QPoint( 75, 75 ), 30, 30 );
224 previewPicPainter.end();
229 context.
painter()->translate( 35, 35 );
234 lblPreview->setPixmap( QPixmap::fromImage( previewImage ) );
240 QModelIndex idx = mEffectsList->currentIndex();
241 if ( !idx.isValid() )
244 EffectItem *item =
static_cast<EffectItem *
>(
mModel->itemFromIndex( idx ) );
265 int index = stackedWidget->addWidget( widget );
266 stackedWidget->setCurrentIndex( index );
281 EffectItem *newEffectItem =
new EffectItem( newEffect,
this );
284 mEffectsList->setCurrentIndex(
mModel->indexFromItem( newEffectItem ) );
292 int row = item->row();
293 QStandardItem *root =
mModel->invisibleRootItem();
295 int layerIdx = root->rowCount() - row - 1;
298 mModel->invisibleRootItem()->removeRow( row );
300 int newSelection = std::min( row, root->rowCount() - 1 );
301 QModelIndex newIdx = root->child( newSelection )->index();
302 mEffectsList->setCurrentIndex( newIdx );
326 int row = item->row();
328 QStandardItem *root =
mModel->invisibleRootItem();
330 int layerIdx = root->rowCount() - row - 1;
335 QList<QStandardItem *> toMove = root->takeRow( row );
336 root->insertRows( row + offset, toMove );
338 QModelIndex newIdx = toMove[ 0 ]->index();
339 mEffectsList->setCurrentIndex( newIdx );
348 item->setEffect( newEffect );
350 QStandardItem *root =
mModel->invisibleRootItem();
351 int effectIdx = root->rowCount() - item->row() - 1;
365 :
QgsDialog( parent, f, QDialogButtonBox::Ok | QDialogButtonBox::Cancel )
368 setWindowTitle( tr(
"Effect Properties" ) );
391 QHBoxLayout *layout =
new QHBoxLayout();
392 layout->setContentsMargins( 0, 0, 0, 0 );
393 layout->setSpacing( 6 );
396 mEnabledCheckBox =
new QCheckBox(
this );
397 mEnabledCheckBox->setText( tr(
"Draw effects" ) );
398 layout->addWidget( mEnabledCheckBox );
400 mButton =
new QToolButton(
this );
402 mButton->setToolTip( tr(
"Customise effects" ) );
403 layout->addWidget( mButton );
405 setFocusPolicy( Qt::StrongFocus );
406 setFocusProxy( mEnabledCheckBox );
408 connect( mButton, &QAbstractButton::clicked,
this, &QgsEffectStackCompactWidget::showDialog );
409 connect( mEnabledCheckBox, &QAbstractButton::toggled,
this, &QgsEffectStackCompactWidget::enableToggled );
416 delete mPreviewPicture;
423 mEnabledCheckBox->setChecked(
false );
424 mEnabledCheckBox->setEnabled(
false );
425 mButton->setEnabled(
false );
439 mEnabledCheckBox->setChecked( mStack->
enabled() );
440 mEnabledCheckBox->setEnabled(
true );
441 mButton->setEnabled( mStack->
enabled() );
451 delete mPreviewPicture;
452 mPreviewPicture =
new QPicture( picture );
455 void QgsEffectStackCompactWidget::showDialog()
462 if ( mPreviewPicture )
480 void QgsEffectStackCompactWidget::enableToggled(
bool checked )
488 mButton->setEnabled( checked );
492 void QgsEffectStackCompactWidget::updateAcceptWidget(
QgsPanelWidget *panel )
495 *mStack = *widget->
stack();
500 void QgsEffectStackCompactWidget::updateEffectLive()
503 *mStack = *widget->
stack();
void setEnabled(const bool enabled)
Sets whether the effect is enabled.
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.
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
static QgsPaintEffectRegistry * paintEffectRegistry()
Returns the application's paint effect registry, used for managing paint effects. ...
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.
QgsPaintEffect * effect(int index) const
Returns a pointer to the effect at a specified index within the stack.
static QgsRenderContext fromQPainter(QPainter *painter)
Creates a default render context given a pixel based QPainter destination.
A paint effect which consists of a stack of other chained paint effects.
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(QgsEffectStack *stack, QWidget *parent=nullptr, 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.
QPainter * painter()
Returns the destination QPainter for the render operation.
QVBoxLayout * layout()
Returns the central layout. Widgets added to it must have this dialog as parent.
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.
QgsPaintEffect * takeEffect(const int index)
Removes an effect from the stack and returns a pointer to it.