diff options
| author | Jon A. Cruz <jon@joncruz.org> | 2006-06-01 08:55:22 +0000 |
|---|---|---|
| committer | joncruz <joncruz@users.sourceforge.net> | 2006-06-01 08:55:22 +0000 |
| commit | d2b4ccf785a810829e729cbcc28f3fb547091bc6 (patch) | |
| tree | d8d5c8e6b6aff8b559baecad3be35c8d4a32dc8b /src/dialogs/layers-panel.cpp | |
| parent | Removed debugging messages (diff) | |
| download | inkscape-d2b4ccf785a810829e729cbcc28f3fb547091bc6.tar.gz inkscape-d2b4ccf785a810829e729cbcc28f3fb547091bc6.zip | |
Added opacity slider
(bzr r1120)
Diffstat (limited to 'src/dialogs/layers-panel.cpp')
| -rw-r--r-- | src/dialogs/layers-panel.cpp | 60 |
1 files changed, 60 insertions, 0 deletions
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 <gtkmm/widget.h> +#include <gtkmm/spinbutton.h> #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<Gtk::Widget*>::iterator it = _watching.begin(); it != _watching.end(); ++it ) { (*it)->set_sensitive( sensitive ); } @@ -654,6 +666,35 @@ bool LayersPanel::_rowSelectFunction( Glib::RefPtr<Gtk::TreeModel> 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 ); |
