From: joncruz Date: Thu, 1 Jun 2006 08:55:22 +0000 (+0000) Subject: Added opacity slider X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=a4ff05287a7222aa263aedc81216645ebd8d11f2;p=inkscape.git Added opacity slider --- diff --git a/ChangeLog b/ChangeLog index b471b225d..7e1ce4a4d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2006-06-01 Jon A. Cruz + + * src/dialogs/layers-panel.h, src/dialogs/layers-panel.cpp: + + Added layer opacity slider. + Fixes RFE #1496569. + 2006-05-31 Colin Marquardt * TRANSLATORS: Add vonHalenbach for tutorial translations. diff --git a/src/dialogs/layers-panel.cpp b/src/dialogs/layers-panel.cpp index a09ce1527..4faaec297 100644 --- a/src/dialogs/layers-panel.cpp +++ b/src/dialogs/layers-panel.cpp @@ -33,7 +33,11 @@ #include "sp-item.h" #include "widgets/icon.h" #include +#include #include "prefs-utils.h" +#include "xml/repr.h" +#include "svg/css-ostringstream.h" +#include "desktop-style.h" //#define DUMP_LAYERS 1 @@ -525,9 +529,17 @@ 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 ) { + _opacity.set_value( sp_repr_css_double_property( css, "opacity", 1.0 ) ); + } + } } } + for ( std::vector::iterator it = _watching.begin(); it != _watching.end(); ++it ) { (*it)->set_sensitive( sensitive ); } @@ -654,6 +666,35 @@ bool LayersPanel::_rowSelectFunction( Glib::RefPtr const & model 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(), 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" ); + + _opacityConnection.unblock(); + } +} + + + /** * Constructor */ @@ -709,9 +750,28 @@ 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(1.0); + _opacity.set_range(0.0, 1.0); + _opacity.set_increments(0.01, 0.1); + _opacityBox.pack_start( _opacity, Gtk::PACK_EXPAND_WIDGET ); + + Gtk::SpinButton* spinBtn = manage( new Gtk::SpinButton(*_opacity.get_adjustment(), 0.0, 3) ); + + _opacityBox.pack_end( *spinBtn, Gtk::PACK_SHRINK ); + _watching.push_back( &_opacityBox ); + _getContents()->pack_start( _scroller, Gtk::PACK_EXPAND_WIDGET ); + + _getContents()->pack_end(_opacityBox, 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 = SP_ACTIVE_DESKTOP; _buttonsRow.set_child_min_width( 16 ); diff --git a/src/dialogs/layers-panel.h b/src/dialogs/layers-panel.h index 263a0105c..76278fa4f 100644 --- a/src/dialogs/layers-panel.h +++ b/src/dialogs/layers-panel.h @@ -15,7 +15,9 @@ #include #include #include +#include #include +#include #include #include "ui/widget/panel.h" @@ -84,6 +86,8 @@ 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: @@ -92,6 +96,7 @@ private: sigc::connection _changedConnection; sigc::connection _addedConnection; sigc::connection _removedConnection; + sigc::connection _opacityConnection; int _maxNestDepth; Inkscape::LayerManager* _mgr; @@ -108,6 +113,8 @@ private: Gtk::TreeView _tree; Gtk::HButtonBox _buttonsRow; Gtk::ScrolledWindow _scroller; + Gtk::HBox _opacityBox; + Gtk::HScale _opacity; Gtk::Menu _popupMenu; };