Commit 1fdb15d0 authored by Dmitry Kazakov's avatar Dmitry Kazakov

Fix color of the shape being synched with the color selectors

1) When the shape is selected, its color now loaded into the color selector
2) If the shape was deselected without editing the color, then
   old color (before selection) is recovered back
3) If the shape is deselected after its color was modified in any way,
   then the newly selected color is kept in the selector.

CCBUG:381784
parent 02bdc53a
......@@ -209,6 +209,8 @@ public:
Ui_KoFillConfigWidget *ui;
std::vector<KisAcyclicSignalConnector::Blocker> deactivationLocks;
boost::optional<KoColor> overriddenColorFromProvider;
};
KoFillConfigWidget::KoFillConfigWidget(KoCanvasBase *canvas, KoFlake::FillVariant fillVariant, bool trackShapeSelection, QWidget *parent)
......@@ -239,6 +241,10 @@ KoFillConfigWidget::KoFillConfigWidget(KoCanvasBase *canvas, KoFlake::FillVarian
this, SIGNAL(sigInternalRequestColorToResourceManager()),
this, SLOT(slotProposeCurrentColorToResourceManager()));
KisAcyclicSignalConnector *resetConnector = d->resourceManagerAcyclicConnector.createCoordinatedConnector();
resetConnector->connectForwardVoid(
this, SIGNAL(sigInternalRecoverColorInResourceManager()),
this, SLOT(slotRecoverColorInResourceManager()));
// configure GUI
......@@ -518,6 +524,8 @@ void KoFillConfigWidget::colorChanged()
return;
}
d->overriddenColorFromProvider = boost::none;
KoShapeFillWrapper wrapper(selectedShapes, d->fillVariant);
......@@ -573,6 +581,11 @@ void KoFillConfigWidget::slotProposeCurrentColorToResourceManager()
}
if (hasColor) {
if (!d->overriddenColorFromProvider) {
d->overriddenColorFromProvider =
d->canvas->resourceManager()->resource(colorSlot).value<KoColor>();
}
/**
* Don't let opacity leak to our resource manager system
*
......@@ -584,6 +597,19 @@ void KoFillConfigWidget::slotProposeCurrentColorToResourceManager()
}
}
void KoFillConfigWidget::slotRecoverColorInResourceManager()
{
if (d->overriddenColorFromProvider) {
KoCanvasResourceProvider::CanvasResource colorSlot = KoCanvasResourceProvider::ForegroundColor;
if (d->fillVariant == KoFlake::StrokeFill) {
colorSlot = KoCanvasResourceProvider::BackgroundColor;
}
d->canvas->resourceManager()->setResource(colorSlot, QVariant::fromValue(*d->overriddenColorFromProvider));
d->overriddenColorFromProvider = boost::none;
}
}
template <class ResourceServer>
QString findFirstAvailableResourceName(const QString &baseName, ResourceServer *server)
{
......@@ -777,6 +803,8 @@ void KoFillConfigWidget::shapeChanged()
d->previousShapeSelected = shapes;
}
bool shouldUploadColorToResourceManager = false;
if (shapes.isEmpty() ||
(shapes.size() > 1 && KoShapeFillWrapper(shapes, d->fillVariant).isMixedFill())) {
......@@ -793,6 +821,8 @@ void KoFillConfigWidget::shapeChanged()
KoShape *shape = shapes.first();
updateFillIndexFromShape(shape);
updateFillColorFromShape(shape); // updates tool options fields
shouldUploadColorToResourceManager = true;
}
// updates the UI
......@@ -800,6 +830,12 @@ void KoFillConfigWidget::shapeChanged()
updateWidgetComponentVisbility();
slotUpdateFillTitle();
if (shouldUploadColorToResourceManager) {
emit sigInternalRequestColorToResourceManager();
} else {
emit sigInternalRecoverColorInResourceManager();
}
}
void KoFillConfigWidget::updateFillIndexFromShape(KoShape *shape)
......
......@@ -98,11 +98,13 @@ private Q_SLOTS:
void slotGradientRepeatChanged();
void slotProposeCurrentColorToResourceManager();
void slotRecoverColorInResourceManager();
Q_SIGNALS:
void sigFillChanged();
void sigInternalRequestColorToResourceManager();
void sigInternalRecoverColorInResourceManager();
private:
void uploadNewGradientBackground(const QGradient *gradient);
......
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