X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fdialogs%2Flayers-panel.cpp;h=32a52a3737ecbeee89810d1e8662438d6f0f090b;hb=5ae629c910bd31486272c4dc7c31f450b7b454fd;hp=21b3102eff88105ffe162c21a636bb800013bc58;hpb=410db19c3e005769ef7dbf538a5b5fa5f0b5b88e;p=inkscape.git diff --git a/src/dialogs/layers-panel.cpp b/src/dialogs/layers-panel.cpp index 21b3102ef..32a52a373 100644 --- a/src/dialogs/layers-panel.cpp +++ b/src/dialogs/layers-panel.cpp @@ -12,7 +12,10 @@ # include #endif +#include + #include +#include #include "inkscape.h" @@ -31,6 +34,9 @@ #include "widgets/icon.h" #include #include "prefs-utils.h" +#include "xml/repr.h" +#include "svg/css-ostringstream.h" +#include "desktop-style.h" //#define DUMP_LAYERS 1 @@ -105,6 +111,11 @@ public: return _signal_toggled; } + sigc::signal signal_pre_toggle() + { + return _signal_pre_toggle; + } + Glib::PropertyProxy property_active() { return _property_active.get_proxy(); } Glib::PropertyProxy property_activatable() { return _property_activatable.get_proxy(); } Glib::PropertyProxy< Glib::RefPtr > property_pixbuf_on(); @@ -112,6 +123,25 @@ public: // virtual Glib::PropertyProxy_Base _property_renderable(); //override protected: + + virtual void get_size_vfunc( Gtk::Widget& widget, + const Gdk::Rectangle* cell_area, + int* x_offset, + int* y_offset, + int* width, + int* height ) const + { + Gtk::CellRendererPixbuf::get_size_vfunc( widget, cell_area, x_offset, y_offset, width, height ); + + if ( width ) { + *width += (*width) >> 1; + } + if ( height ) { + *height += (*height) >> 1; + } + } + + virtual void render_vfunc( const Glib::RefPtr& window, Gtk::Widget& widget, const Gdk::Rectangle& background_area, @@ -128,10 +158,12 @@ protected: const Glib::ustring& path, const Gdk::Rectangle& background_area, const Gdk::Rectangle& cell_area, - Gtk::CellRendererState flags) { - bool val = false; + Gtk::CellRendererState flags) + { + _signal_pre_toggle.emit(event); _signal_toggled.emit(path); - return val; + + return false; } @@ -145,6 +177,7 @@ private: Glib::Property< Glib::RefPtr > _property_pixbuf_off; sigc::signal _signal_toggled; + sigc::signal _signal_pre_toggle; }; class LayersPanel::InternalUIBounce @@ -280,9 +313,13 @@ bool LayersPanel::_executeAction() { // Make sure selected layer hasn't changed since the action was triggered if ( _pending - && !( (_desktop && _desktop->currentLayer()) - && (_desktop->currentLayer() != _pending->_target) - ) ) { + && ( + (_pending->_actionCode == BUTTON_NEW) + || !( (_desktop && _desktop->currentLayer()) + && (_desktop->currentLayer() != _pending->_target) + ) + ) + ) { int val = _pending->_actionCode; // SPObject* target = _pending->_target; @@ -388,12 +425,12 @@ bool LayersPanel::_checkForSelected(const Gtk::TreePath &path, const Gtk::TreeIt bool stopGoing = false; Gtk::TreeModel::Row row = *iter; - Glib::ustring tmp = row[_model->_colLabel]; if ( layer == row[_model->_colObject] ) { _tree.expand_to_path( path ); Glib::RefPtr select = _tree.get_selection(); + select->select(iter); stopGoing = true; @@ -408,6 +445,7 @@ void LayersPanel::_layersChanged() SPDocument* document = _desktop->doc(); SPObject* root = document->root; if ( root ) { + _selectedConnection.block(); if ( _mgr && _mgr->includes( root ) ) { SPObject* target = _desktop->currentLayer(); _store->clear(); @@ -417,6 +455,7 @@ void LayersPanel::_layersChanged() #endif // DUMP_LAYERS _addLayer( document, root, 0, target, 0 ); } + _selectedConnection.unblock(); } } @@ -443,6 +482,7 @@ void LayersPanel::_addLayer( SPDocument* doc, SPObject* layer, Gtk::TreeModel::R Glib::RefPtr select = _tree.get_selection(); select->select(iter); + _checkTreeSelection(); } @@ -468,13 +508,16 @@ SPObject* LayersPanel::_selectedLayer() void LayersPanel::_pushTreeSelectionToCurrent() { SPObject* inTree = _selectedLayer(); - if ( inTree ) { - SPObject* curr = _desktop->currentLayer(); - if ( curr != inTree ) { - _desktop->setCurrentLayer( inTree ); + // TODO hunt down the possible API abuse in getting NULL + if ( _desktop->currentRoot() ) { + if ( inTree ) { + SPObject* curr = _desktop->currentLayer(); + if ( curr != inTree ) { + _mgr->setCurrentLayer( inTree ); + } + } else { + _mgr->setCurrentLayer( _desktop->doc()->root ); } - } else { - _desktop->setCurrentLayer( _desktop->doc()->root ); } } @@ -491,9 +534,19 @@ 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(); + } + } } } + for ( std::vector::iterator it = _watching.begin(); it != _watching.end(); ++it ) { (*it)->set_sensitive( sensitive ); } @@ -505,6 +558,19 @@ void LayersPanel::_checkTreeSelection() } } +void LayersPanel::_preToggle( GdkEvent const *event ) +{ + if ( _toggleEvent ) { + gdk_event_free(_toggleEvent); + _toggleEvent = 0; + } + + if ( event && (event->type == GDK_BUTTON_PRESS) ) { + // Make a copy so we can keep it around. + _toggleEvent = gdk_event_copy(const_cast(event)); + } +} + void LayersPanel::_toggled( Glib::ustring const& str, int targetCol ) { Gtk::TreeModel::Children::iterator iter = _tree.get_model()->get_iter(str); @@ -522,7 +588,8 @@ void LayersPanel::_toggled( Glib::ustring const& str, int targetCol ) row[_model->_colVisible] = newValue; item->setHidden( !newValue ); item->updateRepr(); - sp_document_done( _desktop->doc() ); + sp_document_done( _desktop->doc() , SP_VERB_DIALOG_LAYERS, + newValue? _("Unhide layer") : _("Hide layer")); } break; @@ -532,7 +599,8 @@ void LayersPanel::_toggled( Glib::ustring const& str, int targetCol ) row[_model->_colLocked] = newValue; item->setLocked( newValue ); item->updateRepr(); - sp_document_done( _desktop->doc() ); + sp_document_done( _desktop->doc() , SP_VERB_DIALOG_LAYERS, + newValue? _("Lock layer") : _("Unlock layer")); } break; } @@ -541,6 +609,7 @@ void LayersPanel::_toggled( Glib::ustring const& str, int targetCol ) void LayersPanel::_handleButtonEvent(GdkEventButton* evt) { + // TODO - fix to a better is-popup function if ( (evt->type == GDK_BUTTON_PRESS) && (evt->button == 3) ) { @@ -571,22 +640,81 @@ void LayersPanel::_handleRowChange( Gtk::TreeModel::Path const& path, Gtk::TreeM gchar const* oldLabel = obj->label(); Glib::ustring tmp = row[_model->_colLabel]; if ( oldLabel && oldLabel[0] && !tmp.empty() && (tmp != oldLabel) ) { - obj->setLabel(tmp.c_str()); + _mgr->renameLayer( obj, tmp.c_str() ); + row[_model->_colLabel] = obj->label(); + } + } + } +} + +bool LayersPanel::_rowSelectFunction( Glib::RefPtr const & model, Gtk::TreeModel::Path const & path, bool currentlySelected ) +{ + bool val = true; + if ( !currentlySelected && _toggleEvent ) + { + GdkEvent* event = gtk_get_current_event(); + if ( event ) { + // (keep these checks separate, so we know when to call gdk_event_free() + if ( event->type == GDK_BUTTON_PRESS ) { + GdkEventButton const* target = reinterpret_cast(_toggleEvent); + GdkEventButton const* evtb = reinterpret_cast(event); + + if ( (evtb->window == target->window) + && (evtb->send_event == target->send_event) + && (evtb->time == target->time) + && (evtb->state == target->state) + ) + { + // Ooooh! It's a magic one + val = false; + } } + gdk_event_free(event); } } + 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 */ LayersPanel::LayersPanel() : - Inkscape::UI::Widget::Panel( "dialogs.layers" ), + Inkscape::UI::Widget::Panel( Glib::ustring(), "dialogs.layers" ), _maxNestDepth(20), _mgr(0), _desktop(0), _model(0), - _pending(0) + _pending(0), + _toggleEvent(0) { _maxNestDepth = prefs_get_int_attribute_limited("dialogs.layers", "maxDepth", 20, 1, 1000); @@ -600,6 +728,7 @@ LayersPanel::LayersPanel() : ImageToggler* eyeRenderer = manage( new ImageToggler("visible", "hidden") ); int visibleColNum = _tree.append_column("vis", *eyeRenderer) - 1; + eyeRenderer->signal_pre_toggle().connect( sigc::mem_fun(*this, &LayersPanel::_preToggle) ); eyeRenderer->signal_toggled().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_toggled), (int)COL_VISIBLE) ); eyeRenderer->property_activatable() = true; Gtk::TreeViewColumn* col = _tree.get_column(visibleColNum); @@ -609,6 +738,7 @@ LayersPanel::LayersPanel() : ImageToggler * renderer = manage( new ImageToggler("width_height_lock", "lock_unlocked") ); int lockedColNum = _tree.append_column("lock", *renderer) - 1; + renderer->signal_pre_toggle().connect( sigc::mem_fun(*this, &LayersPanel::_preToggle) ); renderer->signal_toggled().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_toggled), (int)COL_LOCKED) ); renderer->property_activatable() = true; col = _tree.get_column(lockedColNum); @@ -621,56 +751,79 @@ LayersPanel::LayersPanel() : _tree.set_expander_column( *_tree.get_column(nameColNum) ); - _tree.get_selection()->signal_changed().connect( sigc::mem_fun(*this, &LayersPanel::_pushTreeSelectionToCurrent) ); + _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) ); _tree.get_model()->signal_row_changed().connect( sigc::mem_fun(*this, &LayersPanel::_handleRowChange) ); _tree.signal_button_press_event().connect_notify( sigc::mem_fun(*this, &LayersPanel::_handleButtonEvent) ); _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 ); + _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 ); + Gtk::Button* btn = manage( new Gtk::Button() ); - _styleButton( *btn, targetDesktop, SP_VERB_LAYER_NEW, GTK_STOCK_ADD, "Ne" ); + _styleButton( *btn, targetDesktop, SP_VERB_LAYER_NEW, GTK_STOCK_ADD, _("New") ); btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), (int)BUTTON_NEW) ); - _buttonsRow.pack_start( *btn ); + _buttonsRow.add( *btn ); btn = manage( new Gtk::Button() ); - _styleButton( *btn, targetDesktop, SP_VERB_LAYER_TO_TOP, GTK_STOCK_GOTO_TOP, "Top" ); + _styleButton( *btn, targetDesktop, SP_VERB_LAYER_TO_TOP, GTK_STOCK_GOTO_TOP, _("Top") ); btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), (int)BUTTON_TOP) ); _watchingNonTop.push_back( btn ); - _buttonsRow.pack_start( *btn ); + _buttonsRow.add( *btn ); btn = manage( new Gtk::Button() ); - _styleButton( *btn, targetDesktop, SP_VERB_LAYER_RAISE, GTK_STOCK_GO_UP, "Up" ); + _styleButton( *btn, targetDesktop, SP_VERB_LAYER_RAISE, GTK_STOCK_GO_UP, _("Up") ); btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), (int)BUTTON_UP) ); _watchingNonTop.push_back( btn ); - _buttonsRow.pack_start( *btn ); + _buttonsRow.add( *btn ); btn = manage( new Gtk::Button() ); - _styleButton( *btn, targetDesktop, SP_VERB_LAYER_LOWER, GTK_STOCK_GO_DOWN, "Dn" ); + _styleButton( *btn, targetDesktop, SP_VERB_LAYER_LOWER, GTK_STOCK_GO_DOWN, _("Dn") ); btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), (int)BUTTON_DOWN) ); _watchingNonBottom.push_back( btn ); - _buttonsRow.pack_start( *btn ); + _buttonsRow.add( *btn ); btn = manage( new Gtk::Button() ); - _styleButton( *btn, targetDesktop, SP_VERB_LAYER_TO_BOTTOM, GTK_STOCK_GOTO_BOTTOM, "Btm" ); + _styleButton( *btn, targetDesktop, SP_VERB_LAYER_TO_BOTTOM, GTK_STOCK_GOTO_BOTTOM, _("Bot") ); btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), (int)BUTTON_BOTTOM) ); _watchingNonBottom.push_back( btn ); - _buttonsRow.pack_start( *btn ); + _buttonsRow.add( *btn ); // btn = manage( new Gtk::Button("Dup") ); // btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), (int)BUTTON_DUPLICATE) ); -// _buttonsRow.pack_start( *btn ); +// _buttonsRow.add( *btn ); btn = manage( new Gtk::Button() ); - _styleButton( *btn, targetDesktop, SP_VERB_LAYER_DELETE, GTK_STOCK_REMOVE, "X" ); + _styleButton( *btn, targetDesktop, SP_VERB_LAYER_DELETE, GTK_STOCK_REMOVE, _("X") ); btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), (int)BUTTON_DELETE) ); _watching.push_back( btn ); - _buttonsRow.pack_start( *btn ); + _buttonsRow.add( *btn ); @@ -702,12 +855,8 @@ LayersPanel::LayersPanel() : } g_signal_connect( G_OBJECT(INKSCAPE), "activate_desktop", G_CALLBACK( layers_panel_activated ), this ); - - setDesktop( targetDesktop ); - - show_all_children(); restorePanelPrefs(); @@ -719,6 +868,12 @@ LayersPanel::~LayersPanel() { delete _model; } + + if ( _toggleEvent ) + { + gdk_event_free( _toggleEvent ); + _toggleEvent = 0; + } }