Commit 9ba6db96 authored by Dmitry Kazakov's avatar Dmitry Kazakov

Fixed problems with synchronizations of preset selection widgets

Summary:
1) Now the selector has *no* selection if the currently active preset
   is not present in the filtered list of presets
2) Clicking on the currently selected preset now either resets it,
   or does nothing depending on the "Save tweaks..." option value.
3) All the three preset selectors are now synchronized
4) The selector correctly shown the "dirty" mark right after you
   changed any property of the preset.

Test Plan:
1) Check sanity of the current selection in all the three preset
   selectors. They should be sane and synchronized.
2) Switching the current tag should keep the selection correct (no
   selection is a valid state when the active preset is not present
   in the current tag)
3) (!) Check if Brush Selector, Texture Selector, Pattern and Gradient
   popups still work correctly! They use the same codebase :(

Ref T3473

Reviewers: #krita, timotheegiet

Maniphest Tasks: T3473

Differential Revision: https://phabricator.kde.org/D2815
parent ac299eba
......@@ -461,6 +461,8 @@ KisPaintopBox::KisPaintopBox(KisViewManager *view, QWidget *parent, const char *
connect(m_presetsPopup , SIGNAL(eraserBrushOpacityToggled(bool)) , SLOT(slotEraserBrushOpacityToggled(bool)));
connect(m_presetsChooserPopup, SIGNAL(resourceSelected(KoResource*)) , SLOT(resourceSelected(KoResource*)));
connect(m_presetsChooserPopup, SIGNAL(resourceClicked(KoResource*)) , SLOT(resourceSelected(KoResource*)));
connect(m_resourceProvider , SIGNAL(sigNodeChanged(const KisNodeSP)) , SLOT(slotNodeChanged(const KisNodeSP)));
connect(m_cmbCompositeOp , SIGNAL(currentIndexChanged(int)) , SLOT(slotSetCompositeMode(int)));
connect(m_eraseAction , SIGNAL(toggled(bool)) , SLOT(slotToggleEraseMode(bool)));
......@@ -769,7 +771,12 @@ void KisPaintopBox::slotCanvasResourceChanged(int key, const QVariant &value)
updateCompositeOp(compositeOp);
resourceSelected(preset.data());
}
m_presetsChooserPopup->canvasResourceChanged(preset.data(), preset);
/**
* Update currently selected preset in both the popup widgets
*/
m_presetsChooserPopup->canvasResourceChanged(preset);
m_presetsPopup->currentPresetChanged(preset);
if (key == KisCanvasResourceProvider::CurrentCompositeOp) {
if (m_resourceProvider->currentCompositeOp() != m_currCompositeOpID) {
......
......@@ -71,6 +71,8 @@ KisPaintOpPresetsChooserPopup::KisPaintOpPresetsChooserPopup(QWidget * parent)
connect(m_d->uiWdgPaintOpPresets.wdgPresetChooser, SIGNAL(resourceSelected(KoResource*)),
this, SIGNAL(resourceSelected(KoResource*)));
connect(m_d->uiWdgPaintOpPresets.wdgPresetChooser, SIGNAL(resourceClicked(KoResource*)),
this, SIGNAL(resourceClicked(KoResource*)));
m_d->firstShown = true;
......@@ -108,16 +110,11 @@ void KisPaintOpPresetsChooserPopup::showButtons(bool show)
m_d->uiWdgPaintOpPresets.wdgPresetChooser->showButtons(show);
}
void KisPaintOpPresetsChooserPopup::canvasResourceChanged(KoResource* resource , KisPaintOpPresetSP preset2 )
void KisPaintOpPresetsChooserPopup::canvasResourceChanged(KisPaintOpPresetSP preset)
{
Q_UNUSED(preset2);
if (resource) {
if (preset) {
blockSignals(true);
KisPaintOpPresetResourceServer * rserver = KisResourceServerProvider::instance()->paintOpPresetServer();
KisPaintOpPresetSP preset = rserver->resourceByName(resource->name());
m_d->uiWdgPaintOpPresets.wdgPresetChooser->itemChooser()->setCurrentResource(preset.data());
m_d->uiWdgPaintOpPresets.wdgPresetChooser->setCurrentResource(preset.data());
blockSignals(false);
}
m_d->uiWdgPaintOpPresets.wdgPresetChooser->updateViewSettings();
......
......@@ -38,9 +38,10 @@ public:
void showButtons(bool show);
void updateViewSettings();
public Q_SLOTS:
void canvasResourceChanged( KoResource * resource, KisPaintOpPresetSP preset );
void canvasResourceChanged(KisPaintOpPresetSP preset );
Q_SIGNALS:
void resourceSelected( KoResource * resource);
void resourceClicked( KoResource * resource);
private Q_SLOTS:
void slotThumbnailMode();
......
......@@ -331,6 +331,7 @@ void KisPaintOpPresetsPopup::showScratchPad()
void KisPaintOpPresetsPopup::resourceSelected(KoResource* resource)
{
m_d->uiWdgPaintOpPresetSettings.presetWidget->smallPresetChooser->setCurrentResource(resource);
m_d->uiWdgPaintOpPresetSettings.txtPreset->setText(resource->name());
slotWatchPresetNameLineEdit();
}
......@@ -405,6 +406,11 @@ void KisPaintOpPresetsPopup::updateViewSettings()
m_d->uiWdgPaintOpPresetSettings.presetWidget->smallPresetChooser->updateViewSettings();
}
void KisPaintOpPresetsPopup::currentPresetChanged(KisPaintOpPresetSP preset)
{
m_d->uiWdgPaintOpPresetSettings.presetWidget->smallPresetChooser->setCurrentResource(preset.data());
}
void KisPaintOpPresetsPopup::updateThemedIcons()
{
m_d->uiWdgPaintOpPresetSettings.fillLayer->setIcon(KisIconUtils::loadIcon("document-new"));
......
......@@ -71,6 +71,8 @@ public:
void updateViewSettings();
void currentPresetChanged(KisPaintOpPresetSP preset);
protected:
void contextMenuEvent(QContextMenuEvent *);
void hideEvent(QHideEvent *);
......
......@@ -169,6 +169,10 @@ public:
emitRemovingResource(0);
}
QString currentPaintOpId() const {
return m_paintopID;
}
private:
QString m_paintopID;
};
......@@ -193,6 +197,8 @@ KisPresetChooser::KisPresetChooser(QWidget *parent, const char *name)
connect(m_chooser, SIGNAL(resourceSelected(KoResource*)),
this, SIGNAL(resourceSelected(KoResource*)));
connect(m_chooser, SIGNAL(resourceClicked(KoResource*)),
this, SIGNAL(resourceClicked(KoResource*)));
m_mode = THUMBNAIL;
......@@ -251,6 +257,29 @@ void KisPresetChooser::updateViewSettings()
}
}
void KisPresetChooser::setCurrentResource(KoResource *resource)
{
/**
* HACK ALERT: here we use a direct call to an adapter to notify the view
* that the preset might have changed its dirty state. This state
* doesn't affect the filtering so the server's cache must not be
* invalidated!
*
* Ideally, we should call some method of KoResourceServer instead,
* but ut seems like a bit too much effort for such a small fix.
*/
if (resource == currentResource()) {
KisPresetProxyAdapter *adapter = static_cast<KisPresetProxyAdapter*>(m_adapter.data());
KisPaintOpPreset *preset = dynamic_cast<KisPaintOpPreset*>(resource);
if (preset) {
adapter->resourceChangedNoCacheInvalidation(preset);
}
}
m_chooser->setCurrentResource(resource);
}
KoResource* KisPresetChooser::currentResource()
{
return m_chooser->currentResource();
......@@ -268,8 +297,12 @@ KoResourceItemChooser *KisPresetChooser::itemChooser()
void KisPresetChooser::setPresetFilter(const QString& paintOpId)
{
static_cast<KisPresetProxyAdapter*>(m_adapter.data())->setPresetFilter(paintOpId);
updateViewSettings();
KisPresetProxyAdapter *adapter = static_cast<KisPresetProxyAdapter*>(m_adapter.data());
if (adapter->currentPaintOpId() != paintOpId) {
adapter->setPresetFilter(paintOpId);
updateViewSettings();
}
}
......
......@@ -53,16 +53,16 @@ public:
void setViewMode(ViewMode mode);
void showButtons(bool show);
void setCurrentResource(KoResource *resource);
KoResource* currentResource();
/// Sets the visibility of tagging klineEdits
void showTaggingBar(bool show);
KoResourceItemChooser *itemChooser();
void setPresetFilter(const QString& paintOpId);
Q_SIGNALS:
void resourceSelected(KoResource * resource);
void resourceSelected(KoResource *resource);
void resourceClicked(KoResource *resource);
public Q_SLOTS:
void updateViewSettings();
......
......@@ -112,6 +112,7 @@ KoResourceItemChooser::KoResourceItemChooser(QSharedPointer<KoAbstractResourceSe
d->view->viewport()->installEventFilter(this);
connect(d->view, SIGNAL(currentResourceChanged(QModelIndex)), this, SLOT(activated(QModelIndex)));
connect(d->view, SIGNAL(currentResourceClicked(QModelIndex)), this, SLOT(clicked(QModelIndex)));
connect(d->view, SIGNAL(contextMenuRequested(QPoint)), this, SLOT(contextMenuRequested(QPoint)));
connect(d->view, SIGNAL(sigSizeChanged()), this, SLOT(updateView()));
......@@ -303,11 +304,9 @@ void KoResourceItemChooser::setCurrentResource(KoResource *resource)
}
QModelIndex index = d->model->indexFromResource(resource);
if (!index.isValid())
return;
d->view->setCurrentIndex(index);
updatePreview(resource);
updatePreview(index.isValid() ? resource : 0);
}
void KoResourceItemChooser::slotBeforeResourcesLayoutReset(KoResource *activateAfterReset)
......@@ -370,6 +369,16 @@ void KoResourceItemChooser::activated(const QModelIndex &/*index*/)
}
}
void KoResourceItemChooser::clicked(const QModelIndex &index)
{
Q_UNUSED(index);
KoResource *resource = currentResource();
if (resource) {
emit resourceClicked(resource);
}
}
void KoResourceItemChooser::updateButtonState()
{
QAbstractButton *removeButton = d->buttonGroup->button(Button_Remove);
......@@ -386,7 +395,12 @@ void KoResourceItemChooser::updateButtonState()
void KoResourceItemChooser::updatePreview(KoResource *resource)
{
if (!d->usePreview || !resource) return;
if (!d->usePreview) return;
if (!resource) {
d->previewLabel->setPixmap(QPixmap());
return;
}
QImage image = resource->image();
......
......@@ -113,12 +113,16 @@ public:
Q_SIGNALS:
/// Emitted when a resource was selected
void resourceSelected(KoResource *resource);
/// Emitted when an *already selected* resource is clicked
/// again
void resourceClicked(KoResource *resource);
void splitterMoved();
public Q_SLOTS:
void slotButtonClicked(int button);
private Q_SLOTS:
void activated(const QModelIndex &index);
void clicked(const QModelIndex &index);
void contextMenuRequested(const QPoint &pos);
void baseLengthChanged(int length);
......
......@@ -27,6 +27,7 @@
KoResourceItemView::KoResourceItemView(QWidget *parent)
: KoTableView(parent)
{
connect(this, SIGNAL(clicked(QModelIndex)), SLOT(slotItemClicked(QModelIndex)));
}
bool KoResourceItemView::viewportEvent(QEvent *event)
......@@ -55,6 +56,21 @@ void KoResourceItemView::selectionChanged(const QItemSelection &selected, const
}
}
void KoResourceItemView::mousePressEvent(QMouseEvent *event)
{
m_beforeClickIndex = currentIndex();
KoTableView::mousePressEvent(event);
}
void KoResourceItemView::slotItemClicked(const QModelIndex &index)
{
if (m_beforeClickIndex == index) {
emit currentResourceClicked(index);
}
m_beforeClickIndex = QModelIndex();
}
void KoResourceItemView::contextMenuEvent(QContextMenuEvent *event)
{
QTableView::contextMenuEvent(event);
......
......@@ -43,15 +43,22 @@ public:
Q_SIGNALS:
void currentResourceChanged(const QModelIndex &);
void currentResourceClicked(const QModelIndex &);
void contextMenuRequested(const QPoint &);
protected:
virtual void contextMenuEvent(QContextMenuEvent *event);
void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
void mousePressEvent(QMouseEvent *event);
private Q_SLOTS:
void slotItemClicked(const QModelIndex &index);
private:
KoIconToolTip m_tip;
QModelIndex m_beforeClickIndex;
};
#endif // KORESOURCEITEMVIEW_H
......@@ -166,9 +166,7 @@ void KoResourceModel::resourceAdded(KoResource *resource)
void KoResourceModel::resourceRemoved(KoResource *resource)
{
Q_UNUSED(resource);
KoResource *first = !m_resourceAdapter->resources().isEmpty() ? m_resourceAdapter->resources().first() : 0;
doSafeLayoutReset(first);
doSafeLayoutReset(0);
}
void KoResourceModel::resourceChanged(KoResource* resource)
......
......@@ -214,6 +214,10 @@ public:
emitResourceChanged(Policy::toResourcePointer(resource));
}
void resourceChangedNoCacheInvalidation(PointerType resource) {
emitResourceChanged(Policy::toResourcePointer(resource));
}
void syncTaggedResourceView() {
serverResourceCacheInvalid(true);
m_resourceFilter.rebuildCurrentTagFilenames();
......
......@@ -58,6 +58,8 @@ void PresetDockerDock::setCanvas(KoCanvasBase * canvas)
connect(m_presetChooser, SIGNAL(resourceSelected(KoResource*)),
m_canvas->viewManager()->paintOpBox(), SLOT(resourceSelected(KoResource*)));
connect(m_presetChooser, SIGNAL(resourceClicked(KoResource*)),
m_canvas->viewManager()->paintOpBox(), SLOT(resourceSelected(KoResource*)));
connect(canvas->resourceManager(), SIGNAL(canvasResourceChanged(int,QVariant)),
this, SLOT(canvasResourceChanged(int,QVariant)));
}
......@@ -68,7 +70,7 @@ void PresetDockerDock::canvasResourceChanged(int /*key*/, const QVariant& /*v*/)
sender()->blockSignals(true);
KisPaintOpPresetSP preset = m_canvas->resourceManager()->resource(KisCanvasResourceProvider::CurrentPaintOpPreset).value<KisPaintOpPresetSP>();
if(preset)
m_presetChooser->canvasResourceChanged(preset.data(), preset);
m_presetChooser->canvasResourceChanged(preset);
sender()->blockSignals(false);
m_presetChooser->updateViewSettings();
}
......
Markdown is supported
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