Commit 1df3b27c authored by Halla Rempt's avatar Halla Rempt
Browse files

Automatically select the last used filter for filter layers and masks

Only one glitch: the initial preview image is a bit squash, and I have
no idea why.

CCBUG:338888
parent 15989657
......@@ -66,7 +66,7 @@ KisDlgAdjustmentLayer::KisDlgAdjustmentLayer(KisNodeSP node,
connect(wdgFilterNodeCreation.filterSelector, SIGNAL(configurationChanged()), SLOT(slotConfigChanged()));
connect(wdgFilterNodeCreation.layerName, SIGNAL(textChanged(QString)), SLOT(slotNameChanged(QString)));
enableButtonOk(false);
enableButtonOk(true);
}
KisDlgAdjustmentLayer::~KisDlgAdjustmentLayer()
......
......@@ -101,6 +101,7 @@ KisFiltersModel::KisFiltersModel(bool showAll, KisPaintDeviceSP thumb)
qSort(d->categoriesKeys);
d->previewCacheWatcher = new QSignalMapper(this);
connect(d->previewCacheWatcher, SIGNAL(mapped(int)), SLOT(previewUpdated(int)));
}
KisFiltersModel::~KisFiltersModel()
......
......@@ -92,6 +92,7 @@ KisFilterSelectorWidget::KisFilterSelectorWidget(QWidget* parent) : d(new Privat
d->widgetLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::MinimumExpanding, QSizePolicy::Minimum), 0, 0, 1, 2);
d->widgetLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding), 0, 0, 2, 1);
}
KisFilterSelectorWidget::~KisFilterSelectorWidget()
......@@ -112,12 +113,22 @@ void KisFilterSelectorWidget::setPaintDevice(bool showAll, KisPaintDeviceSP _pai
{
if (!_paintDevice) return;
if (d->filtersModel) delete d->filtersModel;
d->paintDevice = _paintDevice;
d->thumb = d->paintDevice->createThumbnailDevice(100, 100);
d->thumb->setDefaultBounds(new ThumbnailBounds());
d->filtersModel = new KisFiltersModel(showAll, d->thumb);
d->uiFilterSelector.filtersSelector->setFilterModel(d->filtersModel);
d->uiFilterSelector.filtersSelector->header()->setVisible(false);
KisConfig cfg;
QModelIndex idx = d->filtersModel->indexForFilter(cfg.readEntry<QString>("FilterSelector/LastUsedFilter", "levels"));
if (isFilterGalleryVisible()) {
d->uiFilterSelector.filtersSelector->activateFilter(idx);
}
}
void KisFilterSelectorWidget::showFilterGallery(bool visible)
......@@ -125,8 +136,11 @@ void KisFilterSelectorWidget::showFilterGallery(bool visible)
QList<int> sizes;
int currentCentralWidgetWidth = d->currentCentralWidget ? d->currentCentralWidget->width() : 0;
if (visible) {
d->uiFilterSelector.filtersSelector->setMidLineWidth(200);
sizes << d->uiFilterSelector.filtersSelector->sizeHint().width() << currentCentralWidgetWidth;
} else {
d->uiFilterSelector.filtersSelector->setMidLineWidth(0);
sizes << 0 << currentCentralWidgetWidth;
}
d->uiFilterSelector.splitter->setSizes(sizes);
......@@ -192,7 +206,8 @@ void KisFilterSelectorWidget::setFilterIndex(const QModelIndex& idx)
KisFilter* filter = const_cast<KisFilter*>(d->filtersModel->indexToFilter(idx));
if (filter) {
setFilter(filter);
} else {
}
else {
if (d->currentFilter) {
bool v = d->uiFilterSelector.filtersSelector->blockSignals(true);
QModelIndex idx = d->filtersModel->indexForFilter(d->currentFilter->id());
......@@ -201,6 +216,9 @@ void KisFilterSelectorWidget::setFilterIndex(const QModelIndex& idx)
d->uiFilterSelector.filtersSelector->blockSignals(v);
}
}
KisConfig cfg;
cfg.writeEntry<QString>("FilterSelector/LastUsedFilter", d->currentFilter->id());
emit(configurationChanged());
}
......@@ -236,4 +254,20 @@ KisFilterConfiguration* KisFilterSelectorWidget::configuration()
}
void KisFilterTree::setFilterModel(QAbstractItemModel *model)
{
m_model = model;
}
void KisFilterTree::activateFilter(QModelIndex idx)
{
setModel(m_model);
selectionModel()->select(idx, QItemSelectionModel::SelectCurrent);
expand(idx);
scrollTo(idx);
emit activated(idx);
}
#include "kis_filter_selector_widget.moc"
......@@ -69,10 +69,8 @@ public:
KisFilterTree(QWidget *parent) : QTreeView(parent) {}
void setFilterModel(QAbstractItemModel * model)
{
m_model = model;
}
void setFilterModel(QAbstractItemModel * model);
void activateFilter(QModelIndex idx);
protected:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment