From: mental Date: Tue, 1 Jan 2008 04:40:23 +0000 (+0000) Subject: first crack at enabling blend for layers dialog X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=17eb9e57e1550f744916bf486947162aa523bdda;p=inkscape.git first crack at enabling blend for layers dialog --- diff --git a/src/dialogs/layers-panel.cpp b/src/dialogs/layers-panel.cpp index 36105c41c..1034cd3ff 100644 --- a/src/dialogs/layers-panel.cpp +++ b/src/dialogs/layers-panel.cpp @@ -530,14 +530,6 @@ void LayersPanel::_checkTreeSelection() sensitiveNonTop = (Inkscape::next_layer(inTree->parent, inTree) != 0); sensitiveNonBottom = (Inkscape::previous_layer(inTree->parent, inTree) != 0); - if ( inTree->repr ) { - SPCSSAttr *css = sp_repr_css_attr(inTree->repr, "style"); - if ( css ) { - _opacityConnection.block(); - _opacity.set_value( sp_repr_css_double_property( css, "opacity", 1.0 ) * 100 ); - _opacityConnection.unblock(); - } - } } } @@ -670,35 +662,6 @@ bool LayersPanel::_rowSelectFunction( Glib::RefPtr const & /*mod return val; } - -void LayersPanel::_opacityChanged() -{ - SPObject* layer = _selectedLayer(); - - if ( _desktop && layer && !_opacityConnection.blocked() ) { - _opacityConnection.block(); - - Gtk::Adjustment* adj = _opacity.get_adjustment(); - SPCSSAttr *css = sp_repr_css_attr_new(); - - Inkscape::CSSOStringStream os; - os << CLAMP( adj->get_value() / 100, 0.0, 1.0 ); - sp_repr_css_set_property( css, "opacity", os.str().c_str() ); - - sp_desktop_apply_css_recursive( layer, css, true ); - layer->updateRepr(); - - sp_repr_css_attr_unref( css ); - - sp_document_maybe_done( _desktop->doc(), "layers:opacity", SP_VERB_DIALOG_LAYERS, - _("Change layer opacity")); - - _opacityConnection.unblock(); - } -} - - - /** * Constructor */ @@ -745,6 +708,7 @@ LayersPanel::LayersPanel() : _tree.set_expander_column( *_tree.get_column(nameColNum) ); + _compositeSettings.setSubject(&_subject); _selectedConnection = _tree.get_selection()->signal_changed().connect( sigc::mem_fun(*this, &LayersPanel::_pushTreeSelectionToCurrent) ); _tree.get_selection()->set_select_function( sigc::mem_fun(*this, &LayersPanel::_rowSelectFunction) ); @@ -755,28 +719,13 @@ LayersPanel::LayersPanel() : _scroller.add( _tree ); _scroller.set_policy( Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC ); - - _opacityBox.pack_start( *manage( new Gtk::Label(_("Opacity, %:"))), Gtk::PACK_SHRINK ); - - _opacity.set_draw_value(false); - _opacity.set_value(100.0); - _opacity.set_range(0.0, 100.0); - _opacity.set_increments(1, 10); - _opacityBox.pack_start( _opacity, Gtk::PACK_EXPAND_WIDGET ); - - _spinBtn.configure(*_opacity.get_adjustment(), 0, 1); - - _spinBtn.set_width_chars(5); - _opacityBox.pack_end( _spinBtn, Gtk::PACK_SHRINK ); - _watching.push_back( &_opacityBox ); + _watching.push_back( &_compositeSettings ); _getContents()->pack_start( _scroller, Gtk::PACK_EXPAND_WIDGET ); - _getContents()->pack_end(_opacityBox, Gtk::PACK_SHRINK); + _getContents()->pack_end(_compositeSettings, Gtk::PACK_SHRINK); _getContents()->pack_end(_buttonsRow, Gtk::PACK_SHRINK); - _opacityConnection = _opacity.get_adjustment()->signal_value_changed().connect( sigc::mem_fun(*this, &LayersPanel::_opacityChanged) ); - SPDesktop* targetDesktop = getDesktop(); _buttonsRow.set_child_min_width( 16 ); @@ -859,6 +808,8 @@ LayersPanel::LayersPanel() : LayersPanel::~LayersPanel() { + _compositeSettings.setSubject(NULL); + if ( _model ) { delete _model; diff --git a/src/dialogs/layers-panel.h b/src/dialogs/layers-panel.h index 7f56b3f7e..e554ad0bf 100644 --- a/src/dialogs/layers-panel.h +++ b/src/dialogs/layers-panel.h @@ -22,6 +22,7 @@ //#include "ui/previewholder.h" #include "ui/widget/panel.h" +#include "ui/widget/object-composite-settings.h" class SPObject; @@ -85,8 +86,6 @@ private: void _layersChanged(); void _addLayer( SPDocument* doc, SPObject* layer, Gtk::TreeModel::Row* parentRow, SPObject* target, int level ); - void _opacityChanged(); - SPObject* _selectedLayer(); // Hooked to the layer manager: @@ -95,7 +94,6 @@ private: sigc::connection _changedConnection; sigc::connection _addedConnection; sigc::connection _removedConnection; - sigc::connection _opacityConnection; // Internal sigc::connection _selectedConnection; @@ -115,10 +113,11 @@ private: Gtk::TreeView _tree; Gtk::HButtonBox _buttonsRow; Gtk::ScrolledWindow _scroller; - Gtk::HBox _opacityBox; - Gtk::HScale _opacity; Gtk::Menu _popupMenu; Gtk::SpinButton _spinBtn; + + UI::Widget::StyleSubject::CurrentLayer _subject; + UI::Widget::ObjectCompositeSettings _compositeSettings; }; diff --git a/src/ui/dialog/fill-and-stroke.cpp b/src/ui/dialog/fill-and-stroke.cpp index d4c216187..b9e1754ba 100644 --- a/src/ui/dialog/fill-and-stroke.cpp +++ b/src/ui/dialog/fill-and-stroke.cpp @@ -60,10 +60,13 @@ FillAndStroke::FillAndStroke() contents->pack_start(_composite_settings, false, false, 0); show_all_children(); + + _composite_settings.setSubject(&_subject); } FillAndStroke::~FillAndStroke() { + _composite_settings.setSubject(NULL); } void diff --git a/src/ui/dialog/fill-and-stroke.h b/src/ui/dialog/fill-and-stroke.h index ee8c32b4f..37aa4ccc8 100644 --- a/src/ui/dialog/fill-and-stroke.h +++ b/src/ui/dialog/fill-and-stroke.h @@ -52,6 +52,7 @@ protected: NotebookPage _page_stroke_paint; NotebookPage _page_stroke_style; + StyleSubject::Selection _subject; ObjectCompositeSettings _composite_settings; Gtk::HBox &_createPageTabLabel(const Glib::ustring &label, diff --git a/src/ui/widget/object-composite-settings.cpp b/src/ui/widget/object-composite-settings.cpp index b9a88b8da..aeb6a263a 100644 --- a/src/ui/widget/object-composite-settings.cpp +++ b/src/ui/widget/object-composite-settings.cpp @@ -36,7 +36,9 @@ void ObjectCompositeSettings::_on_desktop_switch( SPDesktop *desktop, ObjectCompositeSettings *w ) { - w->_subject.setDesktop(desktop); + if (w->_subject) { + w->_subject->setDesktop(desktop); + } } ObjectCompositeSettings::ObjectCompositeSettings() @@ -70,18 +72,30 @@ ObjectCompositeSettings::ObjectCompositeSettings() show_all_children(); _desktop_activated = g_signal_connect ( G_OBJECT (INKSCAPE), "activate_desktop", G_CALLBACK (&ObjectCompositeSettings::_on_desktop_switch), this ); - _subject.connectChanged(sigc::mem_fun(*this, &ObjectCompositeSettings::_subjectChanged)); - _subject.setDesktop(SP_ACTIVE_DESKTOP); } ObjectCompositeSettings::~ObjectCompositeSettings() { + setSubject(NULL); g_signal_handler_disconnect(G_OBJECT(INKSCAPE), _desktop_activated); } +void ObjectCompositeSettings::setSubject(StyleSubject *subject) { + _subject_changed.disconnect(); + if (subject) { + _subject = subject; + _subject_changed = _subject->connectChanged(sigc::mem_fun(*this, &ObjectCompositeSettings::_subjectChanged)); + _subject->setDesktop(SP_ACTIVE_DESKTOP); + } +} + void ObjectCompositeSettings::_blendBlurValueChanged() { - SPDesktop *desktop = _subject.getDesktop(); + if (!_subject) { + return; + } + + SPDesktop *desktop = _subject->getDesktop(); if (!desktop) { return; } @@ -93,7 +107,7 @@ ObjectCompositeSettings::_blendBlurValueChanged() // FIXME: fix for GTK breakage, see comment in SelectedStyle::on_opacity_changed; here it results in crash 1580903 sp_canvas_force_full_redraw_after_interruptions(sp_desktop_canvas(desktop), 0); - NR::Maybe bbox = _subject.getBounds(); + NR::Maybe bbox = _subject->getBounds(); if (!bbox) { return; } @@ -110,7 +124,7 @@ ObjectCompositeSettings::_blendBlurValueChanged() SPDocument *document = sp_desktop_document (desktop); //apply created filter to every selected item - for (StyleSubject::iterator i = _subject.begin() ; i != _subject.end() ; ++i ) { + for (StyleSubject::iterator i = _subject->begin() ; i != _subject->end() ; ++i ) { if (!SP_IS_ITEM(*i)) { continue; } @@ -145,7 +159,11 @@ ObjectCompositeSettings::_blendBlurValueChanged() void ObjectCompositeSettings::_opacityValueChanged() { - SPDesktop *desktop = _subject.getDesktop(); + if (!_subject) { + return; + } + + SPDesktop *desktop = _subject->getDesktop(); if (!desktop) { return; } @@ -165,7 +183,7 @@ ObjectCompositeSettings::_opacityValueChanged() os << CLAMP (_opacity_adjustment.get_value() / 100, 0.0, 1.0); sp_repr_css_set_property (css, "opacity", os.str().c_str()); - _subject.setCSS(css); + _subject->setCSS(css); sp_repr_css_attr_unref (css); @@ -180,7 +198,11 @@ ObjectCompositeSettings::_opacityValueChanged() void ObjectCompositeSettings::_subjectChanged() { - SPDesktop *desktop = _subject.getDesktop(); + if (!_subject) { + return; + } + + SPDesktop *desktop = _subject->getDesktop(); if (!desktop) { return; } @@ -190,7 +212,7 @@ ObjectCompositeSettings::_subjectChanged() { _blocked = true; SPStyle *query = sp_style_new (sp_desktop_document(desktop)); - int result = _subject.queryStyle(query, QUERY_STYLE_PROPERTY_MASTEROPACITY); + int result = _subject->queryStyle(query, QUERY_STYLE_PROPERTY_MASTEROPACITY); switch (result) { case QUERY_STYLE_NOTHING: @@ -206,7 +228,7 @@ ObjectCompositeSettings::_subjectChanged() { } //query now for current filter mode and average blurring of selection - const int blend_result = _subject.queryStyle(query, QUERY_STYLE_PROPERTY_BLEND); + const int blend_result = _subject->queryStyle(query, QUERY_STYLE_PROPERTY_BLEND); switch(blend_result) { case QUERY_STYLE_NOTHING: _fe_cb.set_sensitive(false); @@ -223,7 +245,7 @@ ObjectCompositeSettings::_subjectChanged() { } if(blend_result == QUERY_STYLE_SINGLE || blend_result == QUERY_STYLE_MULTIPLE_SAME) { - int blur_result = _subject.queryStyle(query, QUERY_STYLE_PROPERTY_BLUR); + int blur_result = _subject->queryStyle(query, QUERY_STYLE_PROPERTY_BLUR); switch (blur_result) { case QUERY_STYLE_NOTHING: //no blurring _fe_cb.set_blur_sensitive(false); @@ -231,7 +253,7 @@ ObjectCompositeSettings::_subjectChanged() { case QUERY_STYLE_SINGLE: case QUERY_STYLE_MULTIPLE_AVERAGED: case QUERY_STYLE_MULTIPLE_SAME: - NR::Maybe bbox = _subject.getBounds(); + NR::Maybe bbox = _subject->getBounds(); if (bbox) { double perimeter = bbox->extent(NR::X) + bbox->extent(NR::Y); _fe_cb.set_blur_sensitive(true); diff --git a/src/ui/widget/object-composite-settings.h b/src/ui/widget/object-composite-settings.h index 6cbcc82af..801ef76af 100644 --- a/src/ui/widget/object-composite-settings.h +++ b/src/ui/widget/object-composite-settings.h @@ -32,6 +32,8 @@ public: ObjectCompositeSettings(); ~ObjectCompositeSettings(); + void setSubject(StyleSubject *subject); + private: Gtk::VBox _opacity_vbox; Gtk::HBox _opacity_label_box; @@ -41,7 +43,7 @@ private: Gtk::HScale _opacity_hscale; Gtk::SpinButton _opacity_spin_button; - StyleSubject::Selection _subject; + StyleSubject *_subject; SimpleFilterModifier _fe_cb; Gtk::VBox _fe_vbox; @@ -49,6 +51,7 @@ private: static void _on_desktop_switch(Inkscape::Application *application, SPDesktop *desktop, ObjectCompositeSettings *w); void _subjectChanged(); + sigc::connection _subject_changed; void _blendBlurValueChanged(); void _opacityValueChanged();