gradient-toolbar.cpp revision aa9235c966804d9b8f8daa083a2d123d9d47d2bb
/*
* Gradient aux toolbar
*
* Authors:
* bulia byak <bulia@dr.com>
* Johan Engelen <j.b.c.engelen@ewi.utwente.nl>
* Abhishek Sharma
*
* Copyright (C) 2007 Johan Engelen
* Copyright (C) 2005 authors
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "ui/widget/color-preview.h"
#include "desktop.h"
#include "document-undo.h"
#include "document.h"
#include "widgets/ege-adjustment-action.h"
#include "widgets/ege-select-one-action.h"
#include "gradient-chemistry.h"
#include "gradient-drag.h"
#include "gradient-toolbar.h"
#include "widgets/ink-action.h"
#include "macros.h"
#include "preferences.h"
#include "selection.h"
#include "sp-defs.h"
#include "sp-linear-gradient.h"
#include "sp-radial-gradient.h"
#include "sp-stop.h"
#include "style.h"
#include "toolbox.h"
#include "ui/icon-names.h"
#include "ui/tools/gradient-tool.h"
#include "verbs.h"
#include "widgets/gradient-image.h"
#include "widgets/gradient-vector.h"
using Inkscape::DocumentUndo;
void gr_apply_gradient_to_item( SPItem *item, SPGradient *gr, SPGradientType initialType, Inkscape::PaintTarget initialMode, Inkscape::PaintTarget mode );
gboolean gr_vector_list(GtkWidget *combo_box, SPDesktop *desktop, bool selection_empty, SPGradient *gr_selected, bool gr_multi);
void gr_read_selection( Inkscape::Selection *selection, GrDrag *drag, SPGradient *&gr_selected, bool &gr_multi, SPGradientSpread &spr_selected, bool &spr_multi );
static gboolean update_stop_list( GtkWidget *stop_combo, SPGradient *gradient, SPStop *new_stop, GtkWidget *widget, bool gr_multi);
static void select_stop_in_list( GtkWidget *combo_box, SPGradient *gradient, SPStop *new_stop, GtkWidget *data, gboolean block);
static void select_stop_by_drag( GtkWidget *combo_box, SPGradient *gradient, ToolBase *ev, GtkWidget *data);
//########################
//## Gradient ##
//########################
void gr_apply_gradient_to_item( SPItem *item, SPGradient *gr, SPGradientType initialType, Inkscape::PaintTarget initialMode, Inkscape::PaintTarget mode )
{
if (style
//&& SP_IS_GRADIENT(isFill ? style->getFillPaintServer() : style->getStrokePaintServer()) ) {
&& (isFill ? SP_IS_GRADIENT(style->getFillPaintServer()) : SP_IS_GRADIENT(style->getStrokePaintServer())) ) {
if ( SP_IS_LINEARGRADIENT(server) ) {
} else if ( SP_IS_RADIALGRADIENT(server) ) {
}
}
else if (initialMode == mode)
{
}
}
/**
Applies gradient vector gr to the gradients attached to the selected dragger of drag, or if none,
to all objects in selection. If there was no previous gradient on an item, uses gradient type and
gradient.
*/
{
SPGradientType initialType = static_cast<SPGradientType>(prefs->getInt("/tools/gradient/newgradient", SP_GRADIENT_TYPE_LINEAR));
Inkscape::PaintTarget initialMode = (prefs->getInt("/tools/gradient/newfillorstroke", 1) != 0) ? Inkscape::FOR_FILL : Inkscape::FOR_STROKE;
// GRADIENTFIXME: make this work for multiple selected draggers.
// First try selected dragger
for (GSList const* i = dragger->draggables; i != NULL; i = i->next) { // for all draggables of dragger
gr_apply_gradient_to_item(draggable->item, gr, initialType, initialMode, draggable->fill_or_stroke);
}
return;
}
// If no drag or no dragger selected, act on selection
}
}
gboolean gr_vector_list(GtkWidget *combo_box, SPDesktop *desktop, bool selection_empty, SPGradient *gr_selected, bool gr_multi)
{
if (blocked) {
return sensitive;
}
/* Clear old list, if there is any */
}
}
if (!gl) {
// The document has no gradients
} else if (selection_empty) {
// Document has gradients, but nothing is currently selected.
} else {
if (gr_selected == NULL) {
// Dead assignment: Value stored to 'sensitive' is never read
//sensitive = FALSE;
}
if (gr_multi) {
// Dead assignment: Value stored to 'sensitive' is never read
//sensitive = FALSE;
}
while (gl) {
if (gradient == gr_selected) {
}
idx ++;
}
}
}
else {
}
return sensitive;
}
/*
* Get the gradient of the selected desktop item
* This is gradient containing the repeat settings, not the underlying "getVector" href linked gradient.
*/
{
SPGradient *gradient = 0;
SPPaintServer *server = 0;
}
}
if ( SP_IS_GRADIENT(server) ) {
}
}
gradient = 0;
}
if (gradient) {
}
}
/*
* Get the current selection and dragger status from the desktop
*/
bool &gr_multi,
bool &spr_multi )
{
// GRADIENTFIXME: make this work for more than one selected dragger?
gradient = 0;
}
if (gr_selected) {
gr_multi = true;
} else {
}
}
if (spread != spr_selected) {
if (spr_selected != SP_GRADIENT_SPREAD_UNDEFINED) {
spr_multi = true;
} else {
}
}
}
return;
}
// If no selected dragger, read desktop selection
if ( SP_IS_GRADIENT(server) ) {
gradient = 0;
}
if (gr_selected) {
gr_multi = true;
} else {
}
}
if (spread != spr_selected) {
if (spr_selected != SP_GRADIENT_SPREAD_UNDEFINED) {
spr_multi = true;
} else {
}
}
}
}
if ( SP_IS_GRADIENT(server) ) {
gradient = 0;
}
if (gr_selected) {
gr_multi = true;
} else {
}
}
if (spread != spr_selected) {
if (spr_selected != SP_GRADIENT_SPREAD_UNDEFINED) {
spr_multi = true;
} else {
}
}
}
}
}
}
/*
* Core function, setup all the widgets whenever something changes on the desktop
*/
{
if (blocked)
return;
if (!desktop) {
return;
}
if (selection) {
if (ev) {
}
SPGradient *gr_selected = 0;
bool gr_multi = false;
bool spr_multi = false;
if ( gradient_combo ) {
gboolean sensitive = gr_vector_list(gradient_combo, desktop, selection->isEmpty(), gr_selected, gr_multi);
EgeSelectOneAction *gradient_action = (EgeSelectOneAction *) g_object_get_data(G_OBJECT(widget), "gradient_select_combo_action");
}
EgeSelectOneAction* spread = (EgeSelectOneAction *) g_object_get_data(G_OBJECT(widget), "gradient_select_repeat_action");
if (gr_selected) {
}
InkAction *reverse = (InkAction *) g_object_get_data(G_OBJECT(widget), "gradient_stops_reverse_action");
EgeSelectOneAction *stops_action = (EgeSelectOneAction *) g_object_get_data(G_OBJECT(widget), "gradient_stops_combo_action");
if ( stops_combo ) {
}
//sp_gradient_vector_widget_load_gradient(widget, gr_selected);
}
}
{
if (act1) {
if ( GTK_IS_COMBO_BOX(combodata) ) {
}
}
return combo_box;
}
static void gr_tb_selection_modified(Inkscape::Selection *selection, guint /*flags*/, gpointer data)
{
}
{
}
{
}
{
}
{
if ( cb ) {
}
}
return stop;
}
{
}
static void sp_gradient_vector_gradient_modified(SPObject *object, guint /*flags*/, GtkWidget *widget)
{
if (!blocked) {
}
}
{
g_message("Load gradient");
release_connection = (sigc::connection *)g_object_get_data(G_OBJECT(widget), "gradient_release_connection");
modified_connection = (sigc::connection *)g_object_get_data(G_OBJECT(widget), "gradient_modified_connection");
if (old) {
}
if (gradient) {
if (!release_connection) {
}
if (!modified_connection) {
}
*release_connection = gradient->connectRelease(sigc::bind<1>(sigc::ptr_fun(&sp_gradient_vector_gradient_release), widget));
*modified_connection = gradient->connectModified(sigc::bind<2>(sigc::ptr_fun(&sp_gradient_vector_gradient_modified), widget));
} else {
if (release_connection) {
delete release_connection;
}
if (modified_connection) {
delete modified_connection;
}
}
}
if (gradient) {
gradient->ensureVector();
if (!stop) {
return;
}
// Once the user edits a gradient, it stops being auto-collectable
}
} else { // no gradient, disable everything
}
}
{
if (!desktop) {
return;
}
if (!selection) {
return;
}
if (rc) {
}
}
{
if (!desktop) {
return;
}
if (!selection) {
return;
}
if (ev) {
}
if (drag) {
drag->deleteSelected();
}
}
{
if ( active ) {
} else {
}
}
{
}
/*
* Change desktop drag selection to this stop
*/
{
return;
if (!drag) {
return;
}
}
static void select_stop_by_drag(GtkWidget *combo_box, SPGradient *gradient, ToolBase *ev, GtkWidget *data)
{
return;
return;
}
gint n = 0;
// for all selected draggers
// for all draggables of dragger
n++;
}
if (n > 1) {
// Mulitple stops selected
if (!store) {
return;
}
EgeAdjustmentAction* act = (EgeAdjustmentAction *)g_object_get_data( G_OBJECT(data), "offset_action");
if (act) {
}
return;
}
if (!vector)
return;
switch (draggable->point_type) {
case POINT_LG_MID:
case POINT_RG_MID1:
case POINT_RG_MID2:
{
}
break;
case POINT_LG_END:
case POINT_RG_R1:
case POINT_RG_R2:
{
}
break;
default:
break;
}
}
}
}
static void select_stop_in_list( GtkWidget *combo_box, SPGradient *gradient, SPStop *new_stop, GtkWidget *data, gboolean block)
{
int i = 0;
if (SP_IS_STOP(ochild)) {
return;
}
i++;
}
}
}
static gboolean update_stop_list( GtkWidget *stop_combo, SPGradient *gradient, SPStop *new_stop, GtkWidget *widget, bool gr_multi)
{
if (!stop_combo) {
return sensitive;
}
if (!store) {
return sensitive;
}
/* Clear old list, if there is any */
if (!SP_IS_GRADIENT(gradient)) {
return sensitive;
}
/* Populate the combobox store */
if (SP_IS_STOP(ochild)) {
}
}
}
if (!sl) {
} else {
Inkscape::UI::Widget::ColorPreview *cpv = Gtk::manage(new Inkscape::UI::Widget::ColorPreview(stop->get_rgba32()));
// Dead assignment: Value stored to 'sensitive' is never read
//sensitive = FALSE;
}
}
}
if (gr_multi) {
}
} else {
}
return sensitive;
}
{
EgeSelectOneAction* act1 = (EgeSelectOneAction *)g_object_get_data( G_OBJECT(widget), "gradient_select_combo_action");
if (act1) {
return gr;
}
}
return gr;
}
/*
static void gr_edit(GtkWidget *button, GtkWidget *widget)
{
SPGradient *gr = gr_get_selected_gradient(widget);
if (gr) {
GtkWidget *dialog = sp_gradient_vector_editor_new(gr);
gtk_widget_show(dialog);
}
}
*/
{
if (!stop) {
return;
}
EgeAdjustmentAction* act = (EgeAdjustmentAction *)g_object_get_data( G_OBJECT(data), "offset_action");
if (!act) {
return;
}
bool isEndStop = false;
} else {
isEndStop = true;
}
} else {
isEndStop = true;
}
}
/*
* Callback functions for user actions
*/
{
gint typemode = ege_select_one_action_get_active( act ) == 0 ? SP_GRADIENT_TYPE_LINEAR : SP_GRADIENT_TYPE_RADIAL;
}
{
Inkscape::PaintTarget fsmode = (ege_select_one_action_get_active( act ) == 0) ? Inkscape::FOR_FILL : Inkscape::FOR_STROKE;
}
/*
* User selected a gradient from the combobox
*/
{
if (blocked) {
return;
}
}
if (gr) {
_("Assign gradient to object"));
}
}
{
if (blocked) {
return;
}
SPGradient *gradient = 0;
if (gradient) {
gradient->updateRepr();
_("Set gradient repeat"));
}
}
/*
* User selected a stop from the combobox
*/
{
if (blocked) {
return;
}
}
/*
* User changed the offset
*/
{
if (blocked) {
return;
}
if (stop) {
_("Change gradient stop offset"));
}
}
/*
*/
{
if (!rendered) {
}
}
static void gradient_toolbox_check_ec(SPDesktop* dt, Inkscape::UI::Tools::ToolBase* ec, GObject* holder);
/**
* Gradient auxiliary toolbar construction and setup.
*
*/
{
/* New gradient linear or radial */
{
0, _("radial"), 1, _("Create radial (elliptic or circular) gradient"), 2, INKSCAPE_ICON("paint-gradient-radial"), -1 );
EgeSelectOneAction* act = ege_select_one_action_new( "GradientNewTypeAction", (""), (""), NULL, GTK_TREE_MODEL(model) );
gint mode = prefs->getInt("/tools/gradient/newgradient", SP_GRADIENT_TYPE_LINEAR) != SP_GRADIENT_TYPE_LINEAR;
}
/* New gradient on fill or stroke*/
{
EgeSelectOneAction* act = ege_select_one_action_new( "GradientNewFillStrokeAction", (""), (""), NULL, GTK_TREE_MODEL(model) );
Inkscape::PaintTarget fsmode = (prefs->getInt("/tools/gradient/newfillorstroke", 1) != 0) ? Inkscape::FOR_FILL : Inkscape::FOR_STROKE;
}
/* Gradient Select list*/
{
EgeSelectOneAction* act1 = ege_select_one_action_new( "GradientSelectGradientAction", _("Select"), (_("Choose a gradient")), NULL, GTK_TREE_MODEL(store) );
}
// Gradient Repeat type
{
gtk_list_store_set( model, &iter, 0, C_("Gradient repeat type", "None"), 1, SP_GRADIENT_SPREAD_PAD, -1 );
(// TRANSLATORS: for info, see http://www.w3.org/TR/2000/CR-SVG-20000802/pservers.html#LinearGradientSpreadMethodAttribute
_("Whether to fill with flat color beyond the ends of the gradient vector "
"(spreadMethod=\"pad\"), or repeat the gradient in the same direction "
"(spreadMethod=\"repeat\"), or repeat the gradient in alternating opposite "
"directions (spreadMethod=\"reflect\")")),
}
/* Gradient Stop list */
{
EgeSelectOneAction* act1 = ege_select_one_action_new( "GradientEditStopsAction", _("Stops"), _("Select a stop for the current gradient"), NULL, GTK_TREE_MODEL(store) );
}
/* Offset */
{
EgeAdjustmentAction* eact = 0;
"/tools/gradient/stopoffset", 0,
0.0, 1.0, 0.01, 0.1,
0, 0, 0,
NULL /*unit tracker*/,
0.01, 2, 1.0);
}
/* Add stop */
{
_("Insert new stop"),
_("Insert new stop"),
INKSCAPE_ICON("node-add"),
}
/* Delete stop */
{
_("Delete stop"),
_("Delete stop"),
INKSCAPE_ICON("node-delete"),
}
/* Reverse */
{
_("Reverse"),
_("Reverse the direction of the gradient"),
INKSCAPE_ICON("object-flip-horizontal"),
}
// Gradients Linked toggle
{
_("Link gradients"),
_("Link gradients to change all related gradients"),
INKSCAPE_ICON("object-unlocked"),
}
}
// lp:1327267
/**
* Checks the current tool and connects gradient aux toolbox signals if it happens to be the gradient tool.
* Called every time the current tool changes by signal emission.
*/
static void gradient_toolbox_check_ec(SPDesktop* desktop, Inkscape::UI::Tools::ToolBase* ec, GObject* holder)
{
if (SP_IS_GRADIENT_CONTEXT(ec)) {
// connect to selection modified and changed signals
connChanged = selection->connectChanged(sigc::bind(sigc::ptr_fun(&gr_tb_selection_changed), holder));
connModified = selection->connectModified(sigc::bind(sigc::ptr_fun(&gr_tb_selection_modified), holder));
connSubselectionChanged = desktop->connectToolSubselectionChanged(sigc::bind(sigc::ptr_fun(&gr_drag_selection_changed), holder));
// Is this necessary? Couldn't hurt.
// connect to release and modified signals of the defs (i.e. when someone changes gradient)
connDefsRelease = document->getDefs()->connectRelease(sigc::bind<1>(sigc::ptr_fun(&gr_defs_release), GTK_WIDGET(holder)));
connDefsModified = document->getDefs()->connectModified(sigc::bind<2>(sigc::ptr_fun(&gr_defs_modified), GTK_WIDGET(holder)));
} else {
if (connChanged)
if (connModified)
if (connDefsRelease)
if (connDefsModified)
}
}
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :