diff options
Diffstat (limited to 'src/ui/dialog')
| -rw-r--r-- | src/ui/dialog/dialog-manager.cpp | 7 | ||||
| -rw-r--r-- | src/ui/dialog/object-attributes.cpp | 211 | ||||
| -rw-r--r-- | src/ui/dialog/object-attributes.h | 124 |
3 files changed, 340 insertions, 2 deletions
diff --git a/src/ui/dialog/dialog-manager.cpp b/src/ui/dialog/dialog-manager.cpp index 95486c5e3..4781e55ba 100644 --- a/src/ui/dialog/dialog-manager.cpp +++ b/src/ui/dialog/dialog-manager.cpp @@ -45,6 +45,7 @@ //#include "ui/dialog/print-colors-preview-dialog.h" #include "util/ege-appear-time-tracker.h" #include "preferences.h" +#include "ui/dialog/object-attributes.h" #include "ui/dialog/object-properties.h" @@ -108,7 +109,8 @@ DialogManager::DialogManager() { registerFactory("LivePathEffect", &create<LivePathEffectEditor, FloatingBehavior>); registerFactory("Memory", &create<Memory, FloatingBehavior>); registerFactory("Messages", &create<Messages, FloatingBehavior>); - registerFactory("ObjectProperties", &create<ObjectProperties, FloatingBehavior>); + registerFactory("ObjectAttributes", &create<ObjectAttributes, FloatingBehavior>); + registerFactory("ObjectProperties", &create<ObjectProperties, FloatingBehavior>); // registerFactory("PrintColorsPreviewDialog", &create<PrintColorsPreviewDialog, FloatingBehavior>); registerFactory("Script", &create<ScriptDialog, FloatingBehavior>); #ifdef ENABLE_SVG_FONTS @@ -137,7 +139,8 @@ DialogManager::DialogManager() { registerFactory("LivePathEffect", &create<LivePathEffectEditor, DockBehavior>); registerFactory("Memory", &create<Memory, DockBehavior>); registerFactory("Messages", &create<Messages, DockBehavior>); - registerFactory("ObjectProperties", &create<ObjectProperties, DockBehavior>); + registerFactory("ObjectAttributes", &create<ObjectAttributes, DockBehavior>); + registerFactory("ObjectProperties", &create<ObjectProperties, DockBehavior>); // registerFactory("PrintColorsPreviewDialog", &create<PrintColorsPreviewDialog, DockBehavior>); registerFactory("Script", &create<ScriptDialog, DockBehavior>); #ifdef ENABLE_SVG_FONTS diff --git a/src/ui/dialog/object-attributes.cpp b/src/ui/dialog/object-attributes.cpp new file mode 100644 index 000000000..1f55887f4 --- /dev/null +++ b/src/ui/dialog/object-attributes.cpp @@ -0,0 +1,211 @@ +/** @file + * Generic object attribute editor + */ +/* Authors: + * Lauris Kaplinski <lauris@kaplinski.com> + * bulia byak <buliabyak@users.sf.net> + * Kris De Gussem <Kris.DeGussem@gmail.com> + * + * Copyright (C) 1999-2012 Authors + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include <glibmm/i18n.h> + +#include "desktop-handles.h" +#include "macros.h" +#include "sp-anchor.h" +#include "sp-image.h" +#include "verbs.h" +#include "xml/repr.h" +#include "ui/dialog/dialog-manager.h" +#include "ui/dialog/object-attributes.h" + +namespace Inkscape { +namespace UI { +namespace Dialog { + +struct SPAttrDesc { + gchar const *label; + gchar const *attribute; +}; + +static const SPAttrDesc anchor_desc[] = { + { N_("Href:"), "xlink:href"}, + { N_("Target:"), "target"}, + { N_("Type:"), "xlink:type"}, + // TRANSLATORS: for info, see http://www.w3.org/TR/2000/CR-SVG-20000802/linking.html#AElementXLinkRoleAttribute + // Identifies the type of the related resource with an absolute URI + { N_("Role:"), "xlink:role"}, + // TRANSLATORS: for info, see http://www.w3.org/TR/2000/CR-SVG-20000802/linking.html#AElementXLinkArcRoleAttribute + // For situations where the nature/role alone isn't enough, this offers an additional URI defining the purpose of the link. + { N_("Arcrole:"), "xlink:arcrole"}, + // TRANSLATORS: for info, see http://www.w3.org/TR/2000/CR-SVG-20000802/linking.html#AElementXLinkTitleAttribute + { N_("Title:"), "xlink:title"}, + { N_("Show:"), "xlink:show"}, + // TRANSLATORS: for info, see http://www.w3.org/TR/2000/CR-SVG-20000802/linking.html#AElementXLinkActuateAttribute + { N_("Actuate:"), "xlink:actuate"}, + { NULL, NULL} +}; + +static const SPAttrDesc image_desc[] = { + { N_("URL:"), "xlink:href"}, + { N_("X:"), "x"}, + { N_("Y:"), "y"}, + { N_("Width:"), "width"}, + { N_("Height:"), "height"}, + { NULL, NULL} +}; + +static const SPAttrDesc image_nohref_desc[] = { + { N_("X:"), "x"}, + { N_("Y:"), "y"}, + { N_("Width:"), "width"}, + { N_("Height:"), "height"}, + { NULL, NULL} +}; + +ObjectAttributes::ObjectAttributes (void) : + UI::Widget::Panel ("", "/dialogs/objectattr/", SP_VERB_DIALOG_ATTR), + blocked (false), + CurrentItem(NULL), + attrTable(), + desktop(NULL), + deskTrack(), + selectChangedConn(), + subselChangedConn(), + selectModifiedConn() +{ + attrTable.show(); + widget_setup(); + + desktopChangeConn = deskTrack.connectDesktopChanged( sigc::mem_fun(*this, &ObjectAttributes::setTargetDesktop) ); + deskTrack.connect(GTK_WIDGET(gobj())); +} + +ObjectAttributes::~ObjectAttributes (void) +{ + selectModifiedConn.disconnect(); + subselChangedConn.disconnect(); + selectChangedConn.disconnect(); + desktopChangeConn.disconnect(); + deskTrack.disconnect(); +} + +void ObjectAttributes::widget_setup (void) +{ + if (blocked) + { + return; + } + + Inkscape::Selection *selection = sp_desktop_selection (SP_ACTIVE_DESKTOP); + SPItem *item = selection->singleItem(); + if (!item) + { + set_sensitive (false); + CurrentItem = NULL; + //no selection anymore or multiple objects selected, means that we need + //to close the connections to the previously selected object + return; + } + + blocked = true; + SPObject *obj = (SPObject*)item; //to get the selected item + GObjectClass *klass = G_OBJECT_GET_CLASS(obj); //to deduce the object's type + GType type = G_TYPE_FROM_CLASS(klass); + const SPAttrDesc *desc; + + if (type == SP_TYPE_ANCHOR) + { + desc = anchor_desc; + } + else if (type == SP_TYPE_IMAGE) + { + Inkscape::XML::Node *ir = obj->getRepr(); + const gchar *href = ir->attribute("xlink:href"); + if ( (!href) || ((strncmp(href, "data:", 5) == 0)) ) + { + desc = image_nohref_desc; + } + else + { + desc = image_desc; + } + } + else + { + blocked = false; + set_sensitive (false); + return; + } + + int len = 0; + std::vector<Glib::ustring> labels; + std::vector<Glib::ustring> attrs; + if (CurrentItem != item) + { + while (desc[len].label) + { + labels.push_back(desc[len].label); + attrs.push_back (desc[len].attribute); + len += 1; + } + attrTable.set_object(obj, labels, attrs, (GtkWidget*)gobj()); + CurrentItem = item; + } + else + { + attrTable.change_object(obj); + } + + set_sensitive (true); + show_all(); + blocked = false; +} + +void ObjectAttributes::setTargetDesktop(SPDesktop *desktop) +{ + if (this->desktop != desktop) { + if (this->desktop) { + selectModifiedConn.disconnect(); + subselChangedConn.disconnect(); + selectChangedConn.disconnect(); + } + this->desktop = desktop; + if (desktop && desktop->selection) { + selectChangedConn = desktop->selection->connectChanged(sigc::hide(sigc::mem_fun(*this, &ObjectAttributes::widget_setup))); + subselChangedConn = desktop->connectToolSubselectionChanged(sigc::hide(sigc::mem_fun(*this, &ObjectAttributes::widget_setup))); + + // Must check flags, so can't call widget_setup() directly. + selectModifiedConn = desktop->selection->connectModified(sigc::hide<0>(sigc::mem_fun(*this, &ObjectAttributes::selectionModifiedCB))); + } + widget_setup(); + } +} + +void ObjectAttributes::selectionModifiedCB( guint flags ) +{ + if (flags & ( SP_OBJECT_MODIFIED_FLAG | + SP_OBJECT_PARENT_MODIFIED_FLAG | + SP_OBJECT_STYLE_MODIFIED_FLAG) ) { + attrTable.reread_properties(); + } +} + + +} +} +} + +/* + 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:fileencoding=utf-8:textwidth=99 : diff --git a/src/ui/dialog/object-attributes.h b/src/ui/dialog/object-attributes.h new file mode 100644 index 000000000..a5a361c25 --- /dev/null +++ b/src/ui/dialog/object-attributes.h @@ -0,0 +1,124 @@ +/** @file + * Generic object attribute editor + */ +/* Author: + * Lauris Kaplinski <lauris@ximian.com> + * + * Copyright (C) 2001 Ximian, Inc. + * + * Licensed under GNU GPL + */ + +#ifndef SEEN_DIALOGS_OBJECT_ATTRIBUTES_H +#define SEEN_DIALOGS_OBJECT_ATTRIBUTES_H + +#include <glib.h> + +#include "desktop.h" +#include "ui/dialog/desktop-tracker.h" +#include "ui/widget/panel.h" +#include "widgets/sp-attribute-widget.h" + +namespace Inkscape { +namespace UI { +namespace Dialog { + +/** + * A dialog widget to show object attributes (currently for images and links). + */ +class ObjectAttributes : public Widget::Panel { +public: + ObjectAttributes (); + ~ObjectAttributes (); + + /** + * Returns a new instance of the object attributes dialog. + * + * Auxiliary function needed by the DialogManager. + */ + static ObjectAttributes &getInstance() { return *new ObjectAttributes(); } + + /** + * Updates entries and other child widgets on selection change, object modification, etc. + */ + void widget_setup(void); + +private: + /** + * Is UI update bloched? + */ + bool blocked; + + /** + * Contains a pointer to the currently selected item (NULL in case nothing is or multiple objects are selected). + */ + SPItem *CurrentItem; + + /** + * Child widget to show the object attributes. + * + * attrTable makes the labels and edit boxes for the attributes defined + * in the SPAttrDesc arrays at the top of the cpp-file. This widgets also + * ensures object attribute modifications by the user are set. + */ + SPAttributeTable attrTable; + + /** + * Stores the current desktop. + */ + SPDesktop *desktop; + + /** + * Auxiliary widget to keep track of desktop changes for the floating dialog. + */ + DesktopTracker deskTrack; + + /** + * Link to callback function for a change in desktop (window). + */ + sigc::connection desktopChangeConn; + + /** + * Link to callback function for a selection change. + */ + sigc::connection selectChangedConn; + sigc::connection subselChangedConn; + + /** + * Link to callback function for a modification of the selected object. + */ + sigc::connection selectModifiedConn; + + /** + * Callback function invoked by the desktop tracker in case of a modification of the selected object. + */ + void selectionModifiedCB( guint flags ); + + /* + * Can be invoked for setting the desktop. Currently not used. + */ + // void setDesktop(SPDesktop *desktop); + + /** + * Is invoked by the desktop tracker when the desktop changes. + */ + void setTargetDesktop(SPDesktop *desktop); + +}; + +} +} +} + +#endif + +/* + 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:fileencoding=utf-8:textwidth=99 : |
