summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: d87f13d)
raw | patch | inline | side by side (parent: d87f13d)
author | Jon A. Cruz <jon@joncruz.org> | |
Tue, 6 Jul 2010 08:28:56 +0000 (01:28 -0700) | ||
committer | Jon A. Cruz <jon@joncruz.org> | |
Tue, 6 Jul 2010 08:28:56 +0000 (01:28 -0700) |
src/sp-gradient.cpp | patch | blob | history | |
src/sp-gradient.h | patch | blob | history | |
src/ui/dialog/swatches.cpp | patch | blob | history |
diff --git a/src/sp-gradient.cpp b/src/sp-gradient.cpp
index 9c1ea0da7896016dc0d68b4b49d2420e5bf97bf9..2a3142b042d74255b1b5537bd2beadad568a1b0c 100644 (file)
--- a/src/sp-gradient.cpp
+++ b/src/sp-gradient.cpp
return spread;
}
-void SPGradient::setSwatch()
+void SPGradient::setSwatch( bool swatch )
{
- if ( !isSwatch() ) {
- if ( hasStops() && (getStopCount() == 0) ) {
- repr->setAttribute("osb:paint", "solid");
+ if ( swatch != isSwatch() ) {
+ if ( swatch ) {
+ if ( hasStops() && (getStopCount() == 0) ) {
+ repr->setAttribute( "osb:paint", "solid" );
+ } else {
+ repr->setAttribute( "osb:paint", "gradient" );
+ }
} else {
- repr->setAttribute("osb:paint", "gradient");
+ repr->setAttribute( "osb:paint", 0 );
}
- requestModified(SP_OBJECT_MODIFIED_FLAG);
+ requestModified( SP_OBJECT_MODIFIED_FLAG );
}
}
@@ -594,12 +598,19 @@ void SPGradientImpl::childAdded(SPObject *object, Inkscape::XML::Node *child, In
gr->invalidateVector();
- if (((SPObjectClass *) gradient_parent_class)->child_added)
+ if (((SPObjectClass *) gradient_parent_class)->child_added) {
(* ((SPObjectClass *) gradient_parent_class)->child_added)(object, child, ref);
+ }
SPObject *ochild = sp_object_get_child_by_repr(object, child);
if ( ochild && SP_IS_STOP(ochild) ) {
gr->has_stops = TRUE;
+ if ( gr->getStopCount() > 0 ) {
+ gchar const * attr = gr->repr->attribute("osb:paint");
+ if ( attr && !strcmp(attr, "solid") ) {
+ gr->repr->setAttribute("osb:paint", "gradient");
+ }
+ }
}
/// \todo Fixme: should we schedule "modified" here?
}
}
+ if ( gr->getStopCount() == 0 ) {
+ gchar const * attr = gr->repr->attribute("osb:paint");
+ if ( attr && !strcmp(attr, "gradient") ) {
+ gr->repr->setAttribute("osb:paint", "solid");
+ }
+ }
+
/* Fixme: should we schedule "modified" here? */
object->requestModified(SP_OBJECT_MODIFIED_FLAG);
}
diff --git a/src/sp-gradient.h b/src/sp-gradient.h
index f1705f1c1a07055efd7e3ab54d84c7e5293c31c2..b05cb5fb82f4dbb2fffa00f6014bbd91f1434935 100644 (file)
--- a/src/sp-gradient.h
+++ b/src/sp-gradient.h
SPGradientSpread fetchSpread();
SPGradientUnits fetchUnits();
- void setSwatch();
+ void setSwatch(bool swatch = true);
private:
bool invalidateVector();
index 70e3800a08814928c63c9e67c6b187b88adfda5f..e70cdaccf3963137624044858c81d29fc5ee805f 100644 (file)
{
public:
static void convertGradient( GtkMenuItem *menuitem, gpointer userData );
- static void addNewGradient( GtkMenuItem *menuitem, gpointer user_data );
+ static void deleteGradient( GtkMenuItem *menuitem, gpointer userData );
};
static void handleClick( GtkWidget* /*widget*/, gpointer callback_data ) {
}
}
-void SwatchesPanelHook::addNewGradient( GtkMenuItem */*menuitem*/, gpointer /*user_data*/ )
+void SwatchesPanelHook::convertGradient( GtkMenuItem * /*menuitem*/, gpointer userData )
{
if ( bounceTarget ) {
SwatchesPanel* swp = bouncePanel;
SPDesktop* desktop = swp ? swp->getDesktop() : 0;
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);
-
- SP_OBJECT_REPR( SP_DOCUMENT_DEFS(doc) )->addChild(repr, NULL);
+ gint index = GPOINTER_TO_INT(userData);
+ if ( doc && (index >= 0) && (static_cast<guint>(index) < popupItems.size()) ) {
+ Glib::ustring targetName = popupItems[index];
- gr = static_cast<SPGradient *>(doc->getObjectByRepr(repr));
- Inkscape::GC::release(repr);
+ const GSList *gradients = sp_document_get_resource_list(doc, "gradient");
+ for (const GSList *item = gradients; item; item = item->next) {
+ SPGradient* grad = SP_GRADIENT(item->data);
+ if ( targetName == grad->getId() ) {
+ grad->setSwatch();
+ sp_document_done(doc, SP_VERB_CONTEXT_GRADIENT,
+ _("Add gradient stop"));
+ break;
+ }
}
-
- gr->setSwatch();
-
- editGradientImpl( gr );
}
}
}
-void SwatchesPanelHook::convertGradient( GtkMenuItem * /*menuitem*/, gpointer userData )
+void SwatchesPanelHook::deleteGradient( GtkMenuItem */*menuitem*/, gpointer /*userData*/ )
{
if ( bounceTarget ) {
SwatchesPanel* swp = bouncePanel;
SPDesktop* desktop = swp ? swp->getDesktop() : 0;
SPDocument *doc = desktop ? desktop->doc() : 0;
- gint index = GPOINTER_TO_INT(userData);
- if ( doc && (index >= 0) && (static_cast<guint>(index) < popupItems.size()) ) {
- Glib::ustring targetName = popupItems[index];
-
+ if (doc) {
+ std::string targetName(bounceTarget->def.descr);
const GSList *gradients = sp_document_get_resource_list(doc, "gradient");
for (const GSList *item = gradients; item; item = item->next) {
SPGradient* grad = SP_GRADIENT(item->data);
if ( targetName == grad->getId() ) {
- grad->setSwatch();
+ //editGradientImpl( grad );
+ grad->setSwatch(false);
sp_document_done(doc, SP_VERB_CONTEXT_GRADIENT,
- _("Add gradient stop"));
+ _("Delete"));
break;
}
}
@@ -250,17 +243,13 @@ gboolean colorItemHandleButtonPress( GtkWidget* widget, GdkEventButton* event, g
gtk_menu_shell_append(GTK_MENU_SHELL(popupMenu), child);
popupExtras.push_back(child);
- child = gtk_menu_item_new_with_label(_("Add"));
+ child = gtk_menu_item_new_with_label(_("Delete"));
g_signal_connect( G_OBJECT(child),
"activate",
- G_CALLBACK(SwatchesPanelHook::addNewGradient),
+ G_CALLBACK(SwatchesPanelHook::deleteGradient),
user_data );
gtk_menu_shell_append(GTK_MENU_SHELL(popupMenu), child);
popupExtras.push_back(child);
-
- child = gtk_menu_item_new_with_label(_("Delete"));
- gtk_menu_shell_append(GTK_MENU_SHELL(popupMenu), child);
- //popupExtras.push_back(child);
gtk_widget_set_sensitive( child, FALSE );
child = gtk_menu_item_new_with_label(_("Edit..."));