Commit 62c4b49b authored by Boudewijn Rempt's avatar Boudewijn Rempt

BUG:369480 Make the toggle-to-previous-preset action work again

It's inevitable to do that check -- we have several preset selector
widgets, and selecting a preset, sets the current preset on all the other
widgets, which then emit a signal to tell the world the preset has been
changed. It would be good if that didn't happen, and it's possible to
achieve that by blocking signals, but that's not robust: it's always
possible something else selects a preset and starts the updating.

Closes T3893
parent 54c43f8f
......@@ -386,7 +386,6 @@ KisPaintopBox::KisPaintopBox(KisViewManager *view, QWidget *parent, const char *
action = new QWidgetAction(this);
KisActionRegistry::instance()->propertizeAction("previous_preset", action);
view->actionCollection()->addAction("previous_preset", action);
connect(action, SIGNAL(triggered()), this, SLOT(slotSwitchToPreviousPreset()));
if (!cfg.toolOptionsInDocker()) {
......@@ -473,10 +472,6 @@ KisPaintopBox::KisPaintopBox(KisViewManager *view, QWidget *parent, const char *
connect(m_hMirrorAction , SIGNAL(toggled(bool)) , SLOT(slotHorizontalMirrorChanged(bool)));
connect(m_vMirrorAction , SIGNAL(toggled(bool)) , SLOT(slotVerticalMirrorChanged(bool)));
connect(m_reloadAction , SIGNAL(triggered()) , SLOT(slotReloadPreset()));
connect(m_sliderChooser[0]->getWidget<KisDoubleSliderSpinBox>("opacity"), SIGNAL(valueChanged(qreal)), SLOT(slotSlider1Changed()));
......@@ -537,7 +532,7 @@ void KisPaintopBox::restoreResource(KoResource* resource)
{
KisPaintOpPreset* preset = dynamic_cast<KisPaintOpPreset*>(resource);
if (preset) {
setCurrentPaintop(preset->paintOp(), preset);
setCurrentPaintop(preset);
m_presetsPopup->setPresetImage(preset->image());
m_presetsPopup->resourceSelected(resource);
......@@ -554,30 +549,38 @@ void KisPaintopBox::newOptionWidgets(const QList<QPointer<QWidget> > &optionWidg
void KisPaintopBox::resourceSelected(KoResource* resource)
{
KisPaintOpPreset* preset = dynamic_cast<KisPaintOpPreset*>(resource);
if (preset) {
if (preset && preset != m_resourceProvider->currentPreset()) {
if (!preset->settings()->isLoadable())
return;
setCurrentPaintopAndReload(preset->paintOp(), preset);
if (!m_dirtyPresetsEnabled) {
KisSignalsBlocker blocker(m_optionWidget);
if (!preset->load()) {
warnKrita << "failed to load the preset.";
}
}
setCurrentPaintop(preset);
m_presetsPopup->setPresetImage(preset->image());
m_presetsPopup->resourceSelected(resource);
}
}
void KisPaintopBox::setCurrentPaintopAndReload(const KoID& paintop, KisPaintOpPresetSP preset)
void KisPaintopBox::setCurrentPaintop(const KoID& paintop)
{
if (!m_dirtyPresetsEnabled) {
KisSignalsBlocker blocker(m_optionWidget);
if (!preset->load()) {
warnKrita << "failed to load the preset.";
}
}
setCurrentPaintop(paintop, preset);
KisPaintOpPresetSP preset = activePreset(paintop);
Q_ASSERT(preset && preset->settings());
setCurrentPaintop(preset);
}
void KisPaintopBox::setCurrentPaintop(const KoID& paintop, KisPaintOpPresetSP preset)
void KisPaintopBox::setCurrentPaintop(KisPaintOpPresetSP preset)
{
if (preset == m_resourceProvider->currentPreset()) {
return;
}
Q_ASSERT(preset);
const KoID& paintop = preset->paintOp();
m_presetConnections.clear();
if (m_resourceProvider->currentPreset()) {
......@@ -593,9 +596,6 @@ void KisPaintopBox::setCurrentPaintop(const KoID& paintop, KisPaintOpPresetSP pr
m_tabletToolMap[m_currTabletToolID].paintOpID = m_resourceProvider->currentPreset()->paintOp();
}
preset = (!preset) ? activePreset(paintop) : preset;
Q_ASSERT(preset && preset->settings());
if (!m_paintopOptionWidgets.contains(paintop))
m_paintopOptionWidgets[paintop] = KisPaintOpRegistry::instance()->get(paintop.id())->createConfigWidget(this);
......@@ -751,11 +751,16 @@ void KisPaintopBox::slotInputDeviceChanged(const KoInputDevice& inputDevice)
preset = rserver->resourceByName("Basic_tip_default");
}
if (preset) {
setCurrentPaintop(preset->paintOp(), preset);
setCurrentPaintop(preset);
}
}
else {
setCurrentPaintop(toolData->paintOpID, toolData->preset);
if (toolData->preset) {
setCurrentPaintop(toolData->preset);
}
else {
setCurrentPaintop(toolData->paintOpID);
}
}
m_currTabletToolID = TabletToolID(inputDevice);
......@@ -1101,7 +1106,7 @@ void KisPaintopBox::slotNextFavoritePreset()
void KisPaintopBox::slotSwitchToPreviousPreset()
{
if (m_resourceProvider->previousPreset()) {
setCurrentPaintop(m_resourceProvider->previousPreset()->paintOp(), m_resourceProvider->previousPreset());
setCurrentPaintop(m_resourceProvider->previousPreset());
}
}
......
......@@ -123,8 +123,8 @@ public Q_SLOTS:
private:
void setCurrentPaintop(const KoID& paintop, KisPaintOpPresetSP preset = 0);
void setCurrentPaintopAndReload(const KoID& paintop, KisPaintOpPresetSP preset);
void setCurrentPaintop(const KoID& paintop);
void setCurrentPaintop(KisPaintOpPresetSP preset);
KisPaintOpPresetSP defaultPreset(const KoID& paintOp);
KisPaintOpPresetSP activePreset(const KoID& paintOp);
......@@ -160,8 +160,8 @@ private Q_SLOTS:
void slotSaveLockedOptionToPreset(KisPropertiesConfigurationSP p);
void slotDropLockedOption(KisPropertiesConfigurationSP p);
void slotDirtyPresetToggled(bool);
void slotEraserBrushSizeToggled(bool);
void slotEraserBrushOpacityToggled(bool);
void slotEraserBrushSizeToggled(bool);
void slotEraserBrushOpacityToggled(bool);
void slotUpdateSelectionIcon();
void slotLockXMirrorToggle(bool);
......@@ -246,7 +246,7 @@ private:
bool m_dirtyPresetsEnabled;
bool m_eraserBrushSizeEnabled;
bool m_eraserBrushOpacityEnabled;
KisSignalAutoConnectionsStore m_presetConnections;
};
......
......@@ -363,7 +363,6 @@ void KoResourceItemChooser::activated(const QModelIndex &/*index*/)
d->updatesBlocked = true;
emit resourceSelected(resource);
d->updatesBlocked = false;
updatePreview(resource);
updateButtonState();
}
......
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