summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJon A. Cruz <jon@joncruz.org>2010-07-02 08:18:10 +0000
committerJon A. Cruz <jon@joncruz.org>2010-07-02 08:18:10 +0000
commit43519ed46697c28f90abe47d3b480f9bc9372c6e (patch)
tree4ad64b4e8c595322b5b5743aaaeeedd5c287cff1 /src
parentDo not remove color-profile elements during vacuum defs. Fixes bug #444225. (diff)
downloadinkscape-43519ed46697c28f90abe47d3b480f9bc9372c6e.tar.gz
inkscape-43519ed46697c28f90abe47d3b480f9bc9372c6e.zip
Rough pass of Fill-n-Stroke swatch conversion.
(bzr r9553)
Diffstat (limited to 'src')
-rw-r--r--src/sp-gradient.cpp12
-rw-r--r--src/sp-gradient.h2
-rw-r--r--src/ui/dialog/swatches.cpp71
-rw-r--r--src/widgets/fill-style.cpp6
-rw-r--r--src/widgets/paint-selector.cpp1
5 files changed, 57 insertions, 35 deletions
diff --git a/src/sp-gradient.cpp b/src/sp-gradient.cpp
index 0c0c94784..9c1ea0da7 100644
--- a/src/sp-gradient.cpp
+++ b/src/sp-gradient.cpp
@@ -288,6 +288,18 @@ SPGradientSpread SPGradient::getSpread() const
return spread;
}
+void SPGradient::setSwatch()
+{
+ if ( !isSwatch() ) {
+ if ( hasStops() && (getStopCount() == 0) ) {
+ repr->setAttribute("osb:paint", "solid");
+ } else {
+ repr->setAttribute("osb:paint", "gradient");
+ }
+ requestModified(SP_OBJECT_MODIFIED_FLAG);
+ }
+}
+
/**
* Return stop's color as 32bit value.
*/
diff --git a/src/sp-gradient.h b/src/sp-gradient.h
index 7e6afe052..f1705f1c1 100644
--- a/src/sp-gradient.h
+++ b/src/sp-gradient.h
@@ -142,6 +142,8 @@ public:
SPGradientSpread fetchSpread();
SPGradientUnits fetchUnits();
+ void setSwatch();
+
private:
bool invalidateVector();
void rebuildVector();
diff --git a/src/ui/dialog/swatches.cpp b/src/ui/dialog/swatches.cpp
index 90e9e5f7b..755a10519 100644
--- a/src/ui/dialog/swatches.cpp
+++ b/src/ui/dialog/swatches.cpp
@@ -72,7 +72,8 @@ static std::map<SwatchesPanel*, SPDocument*> docPerPanel;
class SwatchesPanelHook : public SwatchesPanel
{
public:
- static void convertGradient( GtkMenuItem * menuitem, gpointer userData );
+ static void convertGradient( GtkMenuItem *menuitem, gpointer userData );
+ static void addNewGradient( GtkMenuItem *menuitem, gpointer user_data );
};
static void handleClick( GtkWidget* /*widget*/, gpointer callback_data ) {
@@ -139,7 +140,7 @@ static void editGradient( GtkMenuItem */*menuitem*/, gpointer /*user_data*/ )
}
}
-static void addNewGradient( GtkMenuItem */*menuitem*/, gpointer /*user_data*/ )
+void SwatchesPanelHook::addNewGradient( GtkMenuItem */*menuitem*/, gpointer /*user_data*/ )
{
if ( bounceTarget ) {
SwatchesPanel* swp = bouncePanel;
@@ -147,21 +148,22 @@ static void addNewGradient( GtkMenuItem */*menuitem*/, gpointer /*user_data*/ )
SPDocument *doc = desktop ? desktop->doc() : 0;
if (doc) {
Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc);
+ SPGradient * gr = 0;
+ {
+ Inkscape::XML::Node *repr = xml_doc->createElement("svg:linearGradient");
+ Inkscape::XML::Node *stop = xml_doc->createElement("svg:stop");
+ stop->setAttribute("offset", "0");
+ stop->setAttribute("style", "stop-color:#000;stop-opacity:1;");
+ repr->appendChild(stop);
+ Inkscape::GC::release(stop);
- Inkscape::XML::Node *repr = xml_doc->createElement("svg:linearGradient");
- repr->setAttribute("osb:paint", "solid");
- Inkscape::XML::Node *stop = xml_doc->createElement("svg:stop");
- stop->setAttribute("offset", "0");
- stop->setAttribute("style", "stop-color:#000;stop-opacity:1;");
- repr->appendChild(stop);
- Inkscape::GC::release(stop);
-
- SP_OBJECT_REPR( SP_DOCUMENT_DEFS(doc) )->addChild(repr, NULL);
-
- SPGradient * gr = static_cast<SPGradient *>(doc->getObjectByRepr(repr));
+ SP_OBJECT_REPR( SP_DOCUMENT_DEFS(doc) )->addChild(repr, NULL);
- Inkscape::GC::release(repr);
+ gr = static_cast<SPGradient *>(doc->getObjectByRepr(repr));
+ Inkscape::GC::release(repr);
+ }
+ gr->setSwatch();
editGradientImpl( gr );
}
@@ -182,12 +184,9 @@ void SwatchesPanelHook::convertGradient( GtkMenuItem * /*menuitem*/, gpointer us
for (const GSList *item = gradients; item; item = item->next) {
SPGradient* grad = SP_GRADIENT(item->data);
if ( targetName == grad->getId() ) {
- grad->repr->setAttribute("osb:paint", "solid"); // TODO make conditional
-
+ grad->setSwatch();
sp_document_done(doc, SP_VERB_CONTEXT_GRADIENT,
_("Add gradient stop"));
-
- handleGradientsChange(doc); // work-around for signal not being emitted
break;
}
}
@@ -253,7 +252,7 @@ gboolean colorItemHandleButtonPress( GtkWidget* widget, GdkEventButton* event, g
child = gtk_menu_item_new_with_label(_("Add"));
g_signal_connect( G_OBJECT(child),
"activate",
- G_CALLBACK(addNewGradient),
+ G_CALLBACK(SwatchesPanelHook::addNewGradient),
user_data );
gtk_menu_shell_append(GTK_MENU_SHELL(popupMenu), child);
popupExtras.push_back(child);
@@ -887,21 +886,25 @@ void SwatchesPanel::handleDefsModified(SPDocument *document)
std::map<ColorItem*, SPGradient*> tmpGrads;
recalcSwatchContents(document, tmpColors, tmpPrevs, tmpGrads);
- int cap = std::min(docPalette->_colors.size(), tmpColors.size());
- for (int i = 0; i < cap; i++) {
- ColorItem* newColor = tmpColors[i];
- ColorItem* oldColor = docPalette->_colors[i];
- if ( (newColor->def.getType() != oldColor->def.getType()) ||
- (newColor->def.getR() != oldColor->def.getR()) ||
- (newColor->def.getG() != oldColor->def.getG()) ||
- (newColor->def.getB() != oldColor->def.getB()) ) {
- oldColor->def.setRGB(newColor->def.getR(), newColor->def.getG(), newColor->def.getB());
- }
- if (tmpGrads.find(newColor) != tmpGrads.end()) {
- oldColor->setGradient(tmpGrads[newColor]);
- }
- if ( tmpPrevs.find(newColor) != tmpPrevs.end() ) {
- oldColor->setPixData(tmpPrevs[newColor], PREVIEW_PIXBUF_WIDTH, VBLOCK);
+ if ( tmpColors.size() != docPalette->_colors.size() ) {
+ handleGradientsChange(document);
+ } else {
+ int cap = std::min(docPalette->_colors.size(), tmpColors.size());
+ for (int i = 0; i < cap; i++) {
+ ColorItem* newColor = tmpColors[i];
+ ColorItem* oldColor = docPalette->_colors[i];
+ if ( (newColor->def.getType() != oldColor->def.getType()) ||
+ (newColor->def.getR() != oldColor->def.getR()) ||
+ (newColor->def.getG() != oldColor->def.getG()) ||
+ (newColor->def.getB() != oldColor->def.getB()) ) {
+ oldColor->def.setRGB(newColor->def.getR(), newColor->def.getG(), newColor->def.getB());
+ }
+ if (tmpGrads.find(newColor) != tmpGrads.end()) {
+ oldColor->setGradient(tmpGrads[newColor]);
+ }
+ if ( tmpPrevs.find(newColor) != tmpPrevs.end() ) {
+ oldColor->setPixData(tmpPrevs[newColor], PREVIEW_PIXBUF_WIDTH, VBLOCK);
+ }
}
}
}
diff --git a/src/widgets/fill-style.cpp b/src/widgets/fill-style.cpp
index 5a7256d83..f1342f3de 100644
--- a/src/widgets/fill-style.cpp
+++ b/src/widgets/fill-style.cpp
@@ -556,8 +556,12 @@ void FillNStroke::updateFromPaint()
}
if (!vector) {
+ SPGradient *gr = sp_gradient_vector_for_object(document, desktop, SP_OBJECT(i->data), kind == FILL);
+ if ( gr && (psel->mode == SPPaintSelector::MODE_SWATCH) ) {
+ gr->setSwatch();
+ }
sp_item_set_gradient(SP_ITEM(i->data),
- sp_gradient_vector_for_object(document, desktop, SP_OBJECT(i->data), kind == FILL),
+ gr,
gradient_type, kind == FILL);
} else {
sp_item_set_gradient(SP_ITEM(i->data), vector, gradient_type, kind == FILL);
diff --git a/src/widgets/paint-selector.cpp b/src/widgets/paint-selector.cpp
index 8759854a0..a569d00bb 100644
--- a/src/widgets/paint-selector.cpp
+++ b/src/widgets/paint-selector.cpp
@@ -1102,6 +1102,7 @@ static void sp_paint_selector_set_mode_swatch(SPPaintSelector *psel, SPPaintSele
gtk_frame_set_label(GTK_FRAME(psel->frame), _("Swatch fill"));
}
+
#ifdef SP_PS_VERBOSE
g_print("Swatch req\n");
#endif