From 6b958fd1779e1882dbd91f714719cfae08752f67 Mon Sep 17 00:00:00 2001 From: Denis Declara Date: Mon, 26 Mar 2012 17:30:27 +0200 Subject: Added anchor-selection widget, it doesn't do much at the moment, next step will be to wire everything together, btw, you can see the widget in the 'rows and columns' panel (bzr r11073.1.3) --- src/ui/CMakeLists.txt | 2 + src/ui/dialog/tile.cpp | 1 + src/ui/dialog/tile.h | 3 + src/ui/widget/anchor-selector.cpp | 123 ++++++++++++++++++++++++++++++++++++++ src/ui/widget/anchor-selector.h | 37 ++++++++++++ 5 files changed, 166 insertions(+) create mode 100644 src/ui/widget/anchor-selector.cpp create mode 100644 src/ui/widget/anchor-selector.h (limited to 'src/ui') diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt index 484edc6e2..e21c3795f 100644 --- a/src/ui/CMakeLists.txt +++ b/src/ui/CMakeLists.txt @@ -72,6 +72,7 @@ set(ui_SRC # dialog/whiteboard-sharewithchat.cpp # dialog/whiteboard-sharewithuser.cpp + widget/anchor-selector.cpp widget/button.cpp widget/color-picker.cpp widget/color-preview.cpp @@ -200,6 +201,7 @@ set(ui_SRC view/view-widget.h view/view.h + widget/anchor-selector.h widget/attr-widget.h widget/button.h widget/color-picker.h diff --git a/src/ui/dialog/tile.cpp b/src/ui/dialog/tile.cpp index 77dae056f..5ce41c716 100644 --- a/src/ui/dialog/tile.cpp +++ b/src/ui/dialog/tile.cpp @@ -796,6 +796,7 @@ TileDialog::TileDialog() SpinsHBox.pack_start(NoOfColsBox, false, false, MARGIN); TileBox.pack_start(SpinsHBox, false, false, MARGIN); + TileBox.pack_start(anchorSelector); { /*#### Radio buttons to control spacing manually or to fit selection bbox ####*/ diff --git a/src/ui/dialog/tile.h b/src/ui/dialog/tile.h index f9e9d9842..f1493664d 100644 --- a/src/ui/dialog/tile.h +++ b/src/ui/dialog/tile.h @@ -20,6 +20,7 @@ #include #include +#include "ui/widget/anchor-selector.h" #include "ui/widget/panel.h" #include "ui/widget/spinbutton.h" #include "ui/widget/scalar-unit.h" @@ -78,6 +79,8 @@ private: bool userHidden; bool updating; + AnchorSelector anchorSelector; + Gtk::Notebook notebook; Gtk::VBox TileBox; diff --git a/src/ui/widget/anchor-selector.cpp b/src/ui/widget/anchor-selector.cpp new file mode 100644 index 000000000..f32346436 --- /dev/null +++ b/src/ui/widget/anchor-selector.cpp @@ -0,0 +1,123 @@ +/* + * anchor-selector.cpp + * + * Created on: Mar 22, 2012 + * Author: denis + */ + +#include +#include "widgets/icon.h" +#include "ui/icon-names.h" +#include "ui/widget/anchor-selector.h" + +void AnchorSelector::setupButton(const Glib::ustring& icon, Gtk::ToggleButton& button) { + Gtk::Widget* buttonIcon = Gtk::manage(sp_icon_get_icon(icon, Inkscape::ICON_SIZE_LARGE_TOOLBAR)); + buttonIcon->show(); + + button.set_relief(Gtk::RELIEF_NONE); + button.show(); + button.add(*buttonIcon); + button.set_can_focus(false); +} + +AnchorSelector::AnchorSelector() + : Gtk::Alignment(0.5, 0, 0, 0), + _container(3, 3, true) +{ + setupButton(INKSCAPE_ICON("boundingbox_top_left"), _buttons[0]); + setupButton(INKSCAPE_ICON("boundingbox_top"), _buttons[1]); + setupButton(INKSCAPE_ICON("boundingbox_top_right"), _buttons[2]); + setupButton(INKSCAPE_ICON("boundingbox_left"), _buttons[3]); + setupButton(INKSCAPE_ICON("boundingbox_center"), _buttons[4]); + setupButton(INKSCAPE_ICON("boundingbox_right"), _buttons[5]); + setupButton(INKSCAPE_ICON("boundingbox_bottom_left"), _buttons[6]); + setupButton(INKSCAPE_ICON("boundingbox_bottom"), _buttons[7]); + setupButton(INKSCAPE_ICON("boundingbox_bottom_right"), _buttons[8]); + + _buttons[0].signal_clicked().connect(sigc::mem_fun(*this, &AnchorSelector::btn_tl_activated)); + _buttons[1].signal_clicked().connect(sigc::mem_fun(*this, &AnchorSelector::btn_t_activated)); + _buttons[2].signal_clicked().connect(sigc::mem_fun(*this, &AnchorSelector::btn_tr_activated)); + _buttons[3].signal_clicked().connect(sigc::mem_fun(*this, &AnchorSelector::btn_l_activated)); + _buttons[4].signal_clicked().connect(sigc::mem_fun(*this, &AnchorSelector::btn_c_activated)); + _buttons[5].signal_clicked().connect(sigc::mem_fun(*this, &AnchorSelector::btn_r_activated)); + _buttons[6].signal_clicked().connect(sigc::mem_fun(*this, &AnchorSelector::btn_bl_activated)); + _buttons[7].signal_clicked().connect(sigc::mem_fun(*this, &AnchorSelector::btn_b_activated)); + _buttons[8].signal_clicked().connect(sigc::mem_fun(*this, &AnchorSelector::btn_br_activated)); + + for(int i = 0; i < 9; ++i) { + _container.attach(_buttons[i], i % 3, i % 3+1, i / 3, i / 3+1, Gtk::FILL, Gtk::FILL); + } + _selection = 4; + _buttons[4].set_active(); + + this->add(_container); +} + +AnchorSelector::~AnchorSelector() +{ + // TODO Auto-generated destructor stub +} + +void AnchorSelector::btn_activated(int index) +{ + if(_buttons[index].get_active()) + { + std::cout << "btn_activated(" << index << ", old=" << _selection << ");" << std::endl; + if(index != _selection) + { + _buttons[_selection].set_active(false); + _buttons[index].set_active(); + _selection = index; + } else { + _buttons[index].set_active(); + } + } +} + +void AnchorSelector::btn_tl_activated() +{ + btn_activated(0); +} + +void AnchorSelector::btn_t_activated() +{ + btn_activated(1); +} + +void AnchorSelector::btn_tr_activated() +{ + btn_activated(2); +} + +void AnchorSelector::btn_l_activated() +{ + btn_activated(3); +} + +void AnchorSelector::btn_c_activated() +{ + btn_activated(4); +} + +void AnchorSelector::btn_r_activated() +{ + btn_activated(5); +} + +void AnchorSelector::btn_bl_activated() +{ + btn_activated(6); +} + +void AnchorSelector::btn_b_activated() +{ + btn_activated(7); +} + +void AnchorSelector::btn_br_activated() +{ + btn_activated(8); +} + + + diff --git a/src/ui/widget/anchor-selector.h b/src/ui/widget/anchor-selector.h new file mode 100644 index 000000000..c852a1a5d --- /dev/null +++ b/src/ui/widget/anchor-selector.h @@ -0,0 +1,37 @@ +/* + * anchor-selector.h + * + * Created on: Mar 22, 2012 + * Author: denis + */ + +#ifndef ANCHOR_SELECTOR_H_ +#define ANCHOR_SELECTOR_H_ + +#include + +class AnchorSelector : public Gtk::Alignment +{ +private: + Gtk::ToggleButton _buttons[9]; + int _selection; + Gtk::Table _container; + + void setupButton(const Glib::ustring &icon, Gtk::ToggleButton &button); + void btn_activated(int index); + void btn_tl_activated(); + void btn_t_activated(); + void btn_tr_activated(); + void btn_l_activated(); + void btn_c_activated(); + void btn_r_activated(); + void btn_bl_activated(); + void btn_b_activated(); + void btn_br_activated(); + +public: + AnchorSelector(); + virtual ~AnchorSelector(); +}; + +#endif /* ANCHOR_SELECTOR_H_ */ -- cgit v1.2.3 From 3f7eff8696693c9b946fe47c2831c8706bffb68d Mon Sep 17 00:00:00 2001 From: Denis Declara Date: Wed, 28 Mar 2012 17:44:47 +0200 Subject: Integrated the newly created Anchor-Selection-Widget with the existing "Rows and Columns" panel. Code still needs documentation and cleenup however. (bzr r11073.1.5) --- src/ui/dialog/tile.cpp | 56 +++++++++----------------- src/ui/dialog/tile.h | 25 ++---------- src/ui/widget/anchor-selector.cpp | 82 +++++++-------------------------------- src/ui/widget/anchor-selector.h | 19 ++++----- 4 files changed, 47 insertions(+), 135 deletions(-) (limited to 'src/ui') diff --git a/src/ui/dialog/tile.cpp b/src/ui/dialog/tile.cpp index 5ce41c716..4a5e9785f 100644 --- a/src/ui/dialog/tile.cpp +++ b/src/ui/dialog/tile.cpp @@ -517,39 +517,15 @@ void TileDialog::Spacing_button_changed() } /** - * changed Radio button in Vertical Align group. + * changed Anchor selection widget. */ -void TileDialog::VertAlign_changed() +void TileDialog::Align_changed() { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - if (VertTopRadioButton.get_active()) { - VertAlign = 0; - prefs->setInt("/dialogs/gridtiler/VertAlign", 0); - } else if (VertCentreRadioButton.get_active()){ - VertAlign = 1; - prefs->setInt("/dialogs/gridtiler/VertAlign", 1); - } else if (VertBotRadioButton.get_active()){ - VertAlign = 2; - prefs->setInt("/dialogs/gridtiler/VertAlign", 2); - } -} - -/** - * changed Radio button in Vertical Align group. - */ -void TileDialog::HorizAlign_changed() -{ - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - if (HorizLeftRadioButton.get_active()) { - HorizAlign = 0; - prefs->setInt("/dialogs/gridtiler/HorizAlign", 0); - } else if (HorizCentreRadioButton.get_active()){ - HorizAlign = 1; - prefs->setInt("/dialogs/gridtiler/HorizAlign", 1); - } else if (HorizRightRadioButton.get_active()){ - HorizAlign = 2; - prefs->setInt("/dialogs/gridtiler/HorizAlign", 2); - } + VertAlign = AlignmentSelector.getVerticalAlignment(); + prefs->setInt("/dialogs/gridtiler/VertAlign", VertAlign); + HorizAlign = AlignmentSelector.getHorizontalAlignment(); + prefs->setInt("/dialogs/gridtiler/HorizAlign", HorizAlign); } /** @@ -685,8 +661,8 @@ TileDialog::TileDialog() RowHeightButton.set_tooltip_text(_("If not set, each row has the height of the tallest object in it")); RowHeightButton.signal_toggled().connect(sigc::mem_fun(*this, &TileDialog::on_RowSize_checkbutton_changed)); - { - /*#### Radio buttons to control vertical alignment ####*/ +/* { + /*#### Radio buttons to control vertical alignment ####*//* VertAlignLabel.set_label(_("Align:")); VertAlignHBox.pack_start(VertAlignLabel, false, false, MARGIN); @@ -715,7 +691,7 @@ TileDialog::TileDialog() } VertAlignHBox.pack_start(VertAlignVBox, false, false, MARGIN); NoOfRowsBox.pack_start(VertAlignHBox, false, false, MARGIN); - } + }*/ SpinsHBox.pack_start(NoOfRowsBox, false, false, MARGIN); @@ -757,8 +733,8 @@ TileDialog::TileDialog() ColumnWidthButton.signal_toggled().connect(sigc::mem_fun(*this, &TileDialog::on_ColSize_checkbutton_changed)); - { - /*#### Radio buttons to control horizontal alignment ####*/ + /*{ + /*#### Radio buttons to control horizontal alignment ####*//* HorizAlignLabel.set_label(_("Align:")); HorizAlignVBox.pack_start(HorizAlignLabel, false, false, MARGIN); @@ -791,12 +767,18 @@ TileDialog::TileDialog() } HorizAlignVBox.pack_start(HorizAlignHBox, false, false, MARGIN); NoOfColsBox.pack_start(HorizAlignVBox, false, false, MARGIN); - } + }*/ SpinsHBox.pack_start(NoOfColsBox, false, false, MARGIN); TileBox.pack_start(SpinsHBox, false, false, MARGIN); - TileBox.pack_start(anchorSelector); + + + // Anchor selection widget + AlignLabel.set_label("Alignment:"); + AlignmentSelector.on_selectionChanged().connect(sigc::mem_fun(*this, &TileDialog::Align_changed)); + TileBox.pack_start(AlignLabel, false, false, MARGIN); + TileBox.pack_start(AlignmentSelector, true, false, MARGIN); { /*#### Radio buttons to control spacing manually or to fit selection bbox ####*/ diff --git a/src/ui/dialog/tile.h b/src/ui/dialog/tile.h index f1493664d..b3bf390b6 100644 --- a/src/ui/dialog/tile.h +++ b/src/ui/dialog/tile.h @@ -67,8 +67,7 @@ public: void on_rowSize_spinbutton_changed(); void on_colSize_spinbutton_changed(); void Spacing_button_changed(); - void VertAlign_changed(); - void HorizAlign_changed(); + void Align_changed(); static TileDialog& getInstance() { return *new TileDialog(); } @@ -79,8 +78,6 @@ private: bool userHidden; bool updating; - AnchorSelector anchorSelector; - Gtk::Notebook notebook; Gtk::VBox TileBox; @@ -112,24 +109,10 @@ private: bool AutoColSize; Gtk::CheckButton ColumnWidthButton; - // Vertical align - Gtk::Label VertAlignLabel; - Gtk::HBox VertAlignHBox; - Gtk::VBox VertAlignVBox; - Gtk::RadioButtonGroup VertAlignGroup; - Gtk::RadioButton VertCentreRadioButton; - Gtk::RadioButton VertTopRadioButton; - Gtk::RadioButton VertBotRadioButton; + // Alignment + Gtk::Label AlignLabel; + AnchorSelector AlignmentSelector; double VertAlign; - - // Horizontal align - Gtk::Label HorizAlignLabel; - Gtk::VBox HorizAlignVBox; - Gtk::HBox HorizAlignHBox; - Gtk::RadioButtonGroup HorizAlignGroup; - Gtk::RadioButton HorizCentreRadioButton; - Gtk::RadioButton HorizLeftRadioButton; - Gtk::RadioButton HorizRightRadioButton; double HorizAlign; Inkscape::UI::Widget::ScalarUnit XPadding; diff --git a/src/ui/widget/anchor-selector.cpp b/src/ui/widget/anchor-selector.cpp index f32346436..aa173e0a0 100644 --- a/src/ui/widget/anchor-selector.cpp +++ b/src/ui/widget/anchor-selector.cpp @@ -3,6 +3,8 @@ * * Created on: Mar 22, 2012 * Author: denis + * + * Released under GNU GPL. Read the file 'COPYING' for more information. */ #include @@ -34,17 +36,9 @@ AnchorSelector::AnchorSelector() setupButton(INKSCAPE_ICON("boundingbox_bottom"), _buttons[7]); setupButton(INKSCAPE_ICON("boundingbox_bottom_right"), _buttons[8]); - _buttons[0].signal_clicked().connect(sigc::mem_fun(*this, &AnchorSelector::btn_tl_activated)); - _buttons[1].signal_clicked().connect(sigc::mem_fun(*this, &AnchorSelector::btn_t_activated)); - _buttons[2].signal_clicked().connect(sigc::mem_fun(*this, &AnchorSelector::btn_tr_activated)); - _buttons[3].signal_clicked().connect(sigc::mem_fun(*this, &AnchorSelector::btn_l_activated)); - _buttons[4].signal_clicked().connect(sigc::mem_fun(*this, &AnchorSelector::btn_c_activated)); - _buttons[5].signal_clicked().connect(sigc::mem_fun(*this, &AnchorSelector::btn_r_activated)); - _buttons[6].signal_clicked().connect(sigc::mem_fun(*this, &AnchorSelector::btn_bl_activated)); - _buttons[7].signal_clicked().connect(sigc::mem_fun(*this, &AnchorSelector::btn_b_activated)); - _buttons[8].signal_clicked().connect(sigc::mem_fun(*this, &AnchorSelector::btn_br_activated)); - for(int i = 0; i < 9; ++i) { + _buttons[i].signal_clicked().connect( + sigc::bind(sigc::mem_fun(*this, &AnchorSelector::btn_activated), i)); _container.attach(_buttons[i], i % 3, i % 3+1, i / 3, i / 3+1, Gtk::FILL, Gtk::FILL); } _selection = 4; @@ -60,64 +54,16 @@ AnchorSelector::~AnchorSelector() void AnchorSelector::btn_activated(int index) { - if(_buttons[index].get_active()) + + if(_selection == index && _buttons[index].get_active() == false) { - std::cout << "btn_activated(" << index << ", old=" << _selection << ");" << std::endl; - if(index != _selection) - { - _buttons[_selection].set_active(false); - _buttons[index].set_active(); - _selection = index; - } else { - _buttons[index].set_active(); - } + _buttons[index].set_active(true); + } + else if(_selection != index && _buttons[index].get_active()) + { + int old_selection = _selection; + _selection = index; + _buttons[old_selection].set_active(false); + _selectionChanged.emit(); } } - -void AnchorSelector::btn_tl_activated() -{ - btn_activated(0); -} - -void AnchorSelector::btn_t_activated() -{ - btn_activated(1); -} - -void AnchorSelector::btn_tr_activated() -{ - btn_activated(2); -} - -void AnchorSelector::btn_l_activated() -{ - btn_activated(3); -} - -void AnchorSelector::btn_c_activated() -{ - btn_activated(4); -} - -void AnchorSelector::btn_r_activated() -{ - btn_activated(5); -} - -void AnchorSelector::btn_bl_activated() -{ - btn_activated(6); -} - -void AnchorSelector::btn_b_activated() -{ - btn_activated(7); -} - -void AnchorSelector::btn_br_activated() -{ - btn_activated(8); -} - - - diff --git a/src/ui/widget/anchor-selector.h b/src/ui/widget/anchor-selector.h index c852a1a5d..ad20bf063 100644 --- a/src/ui/widget/anchor-selector.h +++ b/src/ui/widget/anchor-selector.h @@ -3,6 +3,8 @@ * * Created on: Mar 22, 2012 * Author: denis + * + * Released under GNU GPL. Read the file 'COPYING' for more information. */ #ifndef ANCHOR_SELECTOR_H_ @@ -17,19 +19,18 @@ private: int _selection; Gtk::Table _container; + sigc::signal _selectionChanged; + void setupButton(const Glib::ustring &icon, Gtk::ToggleButton &button); void btn_activated(int index); - void btn_tl_activated(); - void btn_t_activated(); - void btn_tr_activated(); - void btn_l_activated(); - void btn_c_activated(); - void btn_r_activated(); - void btn_bl_activated(); - void btn_b_activated(); - void btn_br_activated(); public: + + int getHorizontalAlignment() { return _selection % 3; } + int getVerticalAlignment() { return _selection / 3; } + + sigc::signal &on_selectionChanged() { return _selectionChanged; } + AnchorSelector(); virtual ~AnchorSelector(); }; -- cgit v1.2.3 From f31125febfcaf661ffb7227081b72da399440730 Mon Sep 17 00:00:00 2001 From: Denis Declara Date: Thu, 29 Mar 2012 18:31:07 +0200 Subject: Removed some commented code, which i replaced, and is therefore no longer used. (bzr r11073.1.7) --- src/ui/dialog/tile.cpp | 69 -------------------------------------------------- 1 file changed, 69 deletions(-) (limited to 'src/ui') diff --git a/src/ui/dialog/tile.cpp b/src/ui/dialog/tile.cpp index 4a5e9785f..4c83c7be0 100644 --- a/src/ui/dialog/tile.cpp +++ b/src/ui/dialog/tile.cpp @@ -661,38 +661,6 @@ TileDialog::TileDialog() RowHeightButton.set_tooltip_text(_("If not set, each row has the height of the tallest object in it")); RowHeightButton.signal_toggled().connect(sigc::mem_fun(*this, &TileDialog::on_RowSize_checkbutton_changed)); -/* { - /*#### Radio buttons to control vertical alignment ####*//* - - VertAlignLabel.set_label(_("Align:")); - VertAlignHBox.pack_start(VertAlignLabel, false, false, MARGIN); - - VertTopRadioButton.signal_toggled().connect(sigc::mem_fun(*this, &TileDialog::VertAlign_changed)); - VertAlignGroup = VertTopRadioButton.get_group(); - VertAlignVBox.pack_start(VertTopRadioButton, false, false, 0); - - VertCentreRadioButton.set_group(VertAlignGroup); - VertCentreRadioButton.signal_toggled().connect(sigc::mem_fun(*this, &TileDialog::VertAlign_changed)); - VertAlignVBox.pack_start(VertCentreRadioButton, false, false, 0); - - VertBotRadioButton.set_group(VertAlignGroup); - VertBotRadioButton.signal_toggled().connect(sigc::mem_fun(*this, &TileDialog::VertAlign_changed)); - VertAlignVBox.pack_start(VertBotRadioButton, false, false, 0); - - VertAlign = prefs->getInt("/dialogs/gridtiler/VertAlign", 1); - if (VertAlign == 0) { - VertTopRadioButton.set_active(TRUE); - } - else if (VertAlign == 1) { - VertCentreRadioButton.set_active(TRUE); - } - else if (VertAlign == 2){ - VertBotRadioButton.set_active(TRUE); - } - VertAlignHBox.pack_start(VertAlignVBox, false, false, MARGIN); - NoOfRowsBox.pack_start(VertAlignHBox, false, false, MARGIN); - }*/ - SpinsHBox.pack_start(NoOfRowsBox, false, false, MARGIN); @@ -732,43 +700,6 @@ TileDialog::TileDialog() ColumnWidthButton.set_tooltip_text(_("If not set, each column has the width of the widest object in it")); ColumnWidthButton.signal_toggled().connect(sigc::mem_fun(*this, &TileDialog::on_ColSize_checkbutton_changed)); - - /*{ - /*#### Radio buttons to control horizontal alignment ####*//* - - HorizAlignLabel.set_label(_("Align:")); - HorizAlignVBox.pack_start(HorizAlignLabel, false, false, MARGIN); - - HorizAlignHBox.pack_start(*(new Gtk::HBox()), true, true, 0); // centering strut - - HorizLeftRadioButton.signal_toggled().connect(sigc::mem_fun(*this, &TileDialog::HorizAlign_changed)); - HorizAlignGroup = HorizLeftRadioButton.get_group(); - HorizAlignHBox.pack_start(HorizLeftRadioButton, false, false, 0); - - HorizCentreRadioButton.set_group(HorizAlignGroup); - HorizCentreRadioButton.signal_toggled().connect(sigc::mem_fun(*this, &TileDialog::HorizAlign_changed)); - HorizAlignHBox.pack_start(HorizCentreRadioButton, false, false, 0); - - HorizRightRadioButton.set_group(HorizAlignGroup); - HorizRightRadioButton.signal_toggled().connect(sigc::mem_fun(*this, &TileDialog::HorizAlign_changed)); - HorizAlignHBox.pack_start(HorizRightRadioButton, false, false, 0); - - HorizAlignHBox.pack_start(*(new Gtk::HBox()), true, true, 0); // centering strut - - HorizAlign = prefs->getInt("/dialogs/gridtiler/HorizAlign", 1); - if (HorizAlign == 0) { - HorizLeftRadioButton.set_active(TRUE); - } - else if (HorizAlign == 1) { - HorizCentreRadioButton.set_active(TRUE); - } - else if (HorizAlign == 2) { - HorizRightRadioButton.set_active(TRUE); - } - HorizAlignVBox.pack_start(HorizAlignHBox, false, false, MARGIN); - NoOfColsBox.pack_start(HorizAlignVBox, false, false, MARGIN); - }*/ - SpinsHBox.pack_start(NoOfColsBox, false, false, MARGIN); TileBox.pack_start(SpinsHBox, false, false, MARGIN); -- cgit v1.2.3 From dc6fcf4ec96d4f4345ad86b1940d4b31d6771a0f Mon Sep 17 00:00:00 2001 From: Denis Declara Date: Sat, 31 Mar 2012 15:20:19 +0200 Subject: Brought old code, "Rows and Columns" in it's own class. Added a separate class for the panel. Still some cleanup to do. (bzr r11073.1.8) --- src/ui/dialog/dialog-manager.cpp | 4 +- src/ui/dialog/tile.cpp | 98 ++++++++++++++++++++++++++-------------- src/ui/dialog/tile.h | 56 +++++++++++++++++++---- 3 files changed, 112 insertions(+), 46 deletions(-) (limited to 'src/ui') diff --git a/src/ui/dialog/dialog-manager.cpp b/src/ui/dialog/dialog-manager.cpp index 60011ca9d..746cfc1b4 100644 --- a/src/ui/dialog/dialog-manager.cpp +++ b/src/ui/dialog/dialog-manager.cpp @@ -121,7 +121,7 @@ DialogManager::DialogManager() { registerFactory("SvgFontsDialog", &create); #endif registerFactory("Swatches", &create); - registerFactory("TileDialog", &create); + registerFactory("TileDialog", &create); registerFactory("Trace", &create); registerFactory("Transformation", &create); registerFactory("UndoHistory", &create); @@ -156,7 +156,7 @@ DialogManager::DialogManager() { registerFactory("SvgFontsDialog", &create); #endif registerFactory("Swatches", &create); - registerFactory("TileDialog", &create); + registerFactory("TileDialog", &create); registerFactory("Trace", &create); registerFactory("Transformation", &create); registerFactory("UndoHistory", &create); diff --git a/src/ui/dialog/tile.cpp b/src/ui/dialog/tile.cpp index 4c83c7be0..9297b5154 100644 --- a/src/ui/dialog/tile.cpp +++ b/src/ui/dialog/tile.cpp @@ -109,6 +109,34 @@ namespace Inkscape { namespace UI { namespace Dialog { +ArrangeDialog::ArrangeDialog() + : UI::Widget::Panel("", "/dialogs/gridtiler", SP_VERB_SELECTION_GRIDTILE), + _gridArrangeTab(new GridArrangeTab(this)) +{ + Gtk::Box *contents = this->_getContents(); + + _notebook.append_page(*_gridArrangeTab, C_("Arrange dialog", "Rectangular grid")); + _arrangeBox.pack_start(_notebook); + + _arrangeButton = this->addResponseButton(C_("Arrange dialog","_Arrange"), GTK_RESPONSE_APPLY); + _arrangeButton->set_use_underline(true); + _arrangeButton->set_tooltip_text(_("Arrange selected objects")); + _arrangeBox.pack_start(*_arrangeButton); + contents->pack_start(_arrangeBox); + show_all_children(); +} + +void ArrangeDialog::_apply() +{ + switch(_notebook.get_current_page()) + { + case 0: + _gridArrangeTab->arrange(); + break; + } +} + + //######################################################################### //## E V E N T S @@ -120,7 +148,7 @@ namespace Dialog { * */ -void TileDialog::Grid_Arrange () +void GridArrangeTab::arrange() { int cnt,row_cnt,col_cnt,a,row,col; @@ -159,7 +187,7 @@ void TileDialog::Grid_Arrange () grid_left = 99999; grid_top = 99999; - SPDesktop *desktop = getDesktop(); + SPDesktop *desktop = Parent->getDesktop(); sp_desktop_document(desktop)->ensureUpToDate(); Inkscape::Selection *selection = sp_desktop_selection (desktop); @@ -356,16 +384,16 @@ g_print("\n row = %f col = %f selection x= %f selection y = %f", total_row_h //######################################################################### -void TileDialog::_apply() +void GridArrangeTab::_apply() { - Grid_Arrange(); + arrange(); } /** * changed value in # of columns spinbox. */ -void TileDialog::on_row_spinbutton_changed() +void GridArrangeTab::on_row_spinbutton_changed() { // quit if run by the attr_changed listener if (updating) { @@ -374,7 +402,7 @@ void TileDialog::on_row_spinbutton_changed() // in turn, prevent listener from responding updating = true; - SPDesktop *desktop = getDesktop(); + SPDesktop *desktop = Parent->getDesktop(); Inkscape::Selection *selection = desktop ? desktop->selection : 0; g_return_if_fail( selection ); @@ -392,7 +420,7 @@ void TileDialog::on_row_spinbutton_changed() /** * changed value in # of rows spinbox. */ -void TileDialog::on_col_spinbutton_changed() +void GridArrangeTab::on_col_spinbutton_changed() { // quit if run by the attr_changed listener if (updating) { @@ -401,7 +429,7 @@ void TileDialog::on_col_spinbutton_changed() // in turn, prevent listener from responding updating = true; - SPDesktop *desktop = getDesktop(); + SPDesktop *desktop = Parent->getDesktop(); Inkscape::Selection *selection = desktop ? desktop->selection : 0; g_return_if_fail(selection); @@ -419,7 +447,7 @@ void TileDialog::on_col_spinbutton_changed() /** * changed value in x padding spinbox. */ -void TileDialog::on_xpad_spinbutton_changed() +void GridArrangeTab::on_xpad_spinbutton_changed() { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->setDouble("/dialogs/gridtiler/XPad", XPadding.getValue("px")); @@ -429,7 +457,7 @@ void TileDialog::on_xpad_spinbutton_changed() /** * changed value in y padding spinbox. */ -void TileDialog::on_ypad_spinbutton_changed() +void GridArrangeTab::on_ypad_spinbutton_changed() { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->setDouble("/dialogs/gridtiler/YPad", YPadding.getValue("px")); @@ -439,7 +467,7 @@ void TileDialog::on_ypad_spinbutton_changed() /** * checked/unchecked autosize Rows button. */ -void TileDialog::on_RowSize_checkbutton_changed() +void GridArrangeTab::on_RowSize_checkbutton_changed() { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); if (RowHeightButton.get_active()) { @@ -453,7 +481,7 @@ void TileDialog::on_RowSize_checkbutton_changed() /** * checked/unchecked autosize Rows button. */ -void TileDialog::on_ColSize_checkbutton_changed() +void GridArrangeTab::on_ColSize_checkbutton_changed() { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); if (ColumnWidthButton.get_active()) { @@ -467,7 +495,7 @@ void TileDialog::on_ColSize_checkbutton_changed() /** * changed value in columns spinbox. */ -void TileDialog::on_rowSize_spinbutton_changed() +void GridArrangeTab::on_rowSize_spinbutton_changed() { // quit if run by the attr_changed listener if (updating) { @@ -485,7 +513,7 @@ void TileDialog::on_rowSize_spinbutton_changed() /** * changed value in rows spinbox. */ -void TileDialog::on_colSize_spinbutton_changed() +void GridArrangeTab::on_colSize_spinbutton_changed() { // quit if run by the attr_changed listener if (updating) { @@ -503,7 +531,7 @@ void TileDialog::on_colSize_spinbutton_changed() /** * changed Radio button in Spacing group. */ -void TileDialog::Spacing_button_changed() +void GridArrangeTab::Spacing_button_changed() { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); if (SpaceManualRadioButton.get_active()) { @@ -519,7 +547,7 @@ void TileDialog::Spacing_button_changed() /** * changed Anchor selection widget. */ -void TileDialog::Align_changed() +void GridArrangeTab::Align_changed() { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); VertAlign = AlignmentSelector.getVerticalAlignment(); @@ -531,7 +559,7 @@ void TileDialog::Align_changed() /** * Desktop selection changed */ -void TileDialog::updateSelection() +void GridArrangeTab::updateSelection() { // quit if run by the attr_changed listener if (updating) { @@ -541,7 +569,7 @@ void TileDialog::updateSelection() Inkscape::Preferences *prefs = Inkscape::Preferences::get(); // in turn, prevent listener from responding updating = true; - SPDesktop *desktop = getDesktop(); + SPDesktop *desktop = Parent->getDesktop(); Inkscape::Selection *selection = desktop ? desktop->selection : 0; GSList const *items = selection ? selection->itemList() : 0; @@ -577,7 +605,7 @@ void TileDialog::updateSelection() ## Experimental ##########################*/ -static void updateSelectionCallback(Inkscape::Application */*inkscape*/, Inkscape::Selection */*selection*/, TileDialog *dlg) +static void updateSelectionCallback(Inkscape::Application */*inkscape*/, Inkscape::Selection */*selection*/, GridArrangeTab *dlg) { dlg->updateSelection(); } @@ -589,8 +617,8 @@ static void updateSelectionCallback(Inkscape::Application */*inkscape*/, Inkscap /** * Constructor */ -TileDialog::TileDialog() - : UI::Widget::Panel("", "/dialogs/gridtiler", SP_VERB_SELECTION_GRIDTILE), +GridArrangeTab::GridArrangeTab(ArrangeDialog *parent) + : Parent(parent), XPadding(_("X:"), _("Horizontal spacing between columns."), UNIT_TYPE_LINEAR, "", "object-columns"), YPadding(_("Y:"), _("Vertical spacing between rows."), XPadding, "", "object-rows") { @@ -608,13 +636,13 @@ TileDialog::TileDialog() g_signal_connect ( G_OBJECT (INKSCAPE), "change_selection", G_CALLBACK (updateSelectionCallback), this); } - Gtk::Box *contents = _getContents(); + Gtk::Box *contents = this; #define MARGIN 2 //##Set up the panel - SPDesktop *desktop = getDesktop(); + SPDesktop *desktop = Parent->getDesktop(); Inkscape::Selection *selection = desktop ? desktop->selection : 0; g_return_if_fail( selection ); @@ -642,7 +670,7 @@ TileDialog::TileDialog() NoOfRowsSpinner.set_increments(1, 0); NoOfRowsSpinner.set_range(1.0, 10000.0); NoOfRowsSpinner.set_value(PerCol); - NoOfRowsSpinner.signal_changed().connect(sigc::mem_fun(*this, &TileDialog::on_col_spinbutton_changed)); + NoOfRowsSpinner.signal_changed().connect(sigc::mem_fun(*this, &GridArrangeTab::on_col_spinbutton_changed)); NoOfRowsSpinner.set_tooltip_text(_("Number of rows")); NoOfRowsBox.pack_start(NoOfRowsSpinner, false, false, MARGIN); gtk_size_group_add_widget(_col1, (GtkWidget *) NoOfRowsBox.gobj()); @@ -659,7 +687,7 @@ TileDialog::TileDialog() NoOfRowsBox.pack_start(RowHeightButton, false, false, MARGIN); RowHeightButton.set_tooltip_text(_("If not set, each row has the height of the tallest object in it")); - RowHeightButton.signal_toggled().connect(sigc::mem_fun(*this, &TileDialog::on_RowSize_checkbutton_changed)); + RowHeightButton.signal_toggled().connect(sigc::mem_fun(*this, &GridArrangeTab::on_RowSize_checkbutton_changed)); SpinsHBox.pack_start(NoOfRowsBox, false, false, MARGIN); @@ -682,7 +710,7 @@ TileDialog::TileDialog() NoOfColsSpinner.set_increments(1, 0); NoOfColsSpinner.set_range(1.0, 10000.0); NoOfColsSpinner.set_value(PerRow); - NoOfColsSpinner.signal_changed().connect(sigc::mem_fun(*this, &TileDialog::on_row_spinbutton_changed)); + NoOfColsSpinner.signal_changed().connect(sigc::mem_fun(*this, &GridArrangeTab::on_row_spinbutton_changed)); NoOfColsSpinner.set_tooltip_text(_("Number of columns")); NoOfColsBox.pack_start(NoOfColsSpinner, false, false, MARGIN); gtk_size_group_add_widget(_col3, (GtkWidget *) NoOfColsBox.gobj()); @@ -698,7 +726,7 @@ TileDialog::TileDialog() NoOfColsBox.pack_start(ColumnWidthButton, false, false, MARGIN); ColumnWidthButton.set_tooltip_text(_("If not set, each column has the width of the widest object in it")); - ColumnWidthButton.signal_toggled().connect(sigc::mem_fun(*this, &TileDialog::on_ColSize_checkbutton_changed)); + ColumnWidthButton.signal_toggled().connect(sigc::mem_fun(*this, &GridArrangeTab::on_ColSize_checkbutton_changed)); SpinsHBox.pack_start(NoOfColsBox, false, false, MARGIN); @@ -707,7 +735,7 @@ TileDialog::TileDialog() // Anchor selection widget AlignLabel.set_label("Alignment:"); - AlignmentSelector.on_selectionChanged().connect(sigc::mem_fun(*this, &TileDialog::Align_changed)); + AlignmentSelector.on_selectionChanged().connect(sigc::mem_fun(*this, &GridArrangeTab::Align_changed)); TileBox.pack_start(AlignLabel, false, false, MARGIN); TileBox.pack_start(AlignmentSelector, true, false, MARGIN); @@ -715,7 +743,7 @@ TileDialog::TileDialog() /*#### Radio buttons to control spacing manually or to fit selection bbox ####*/ SpaceByBBoxRadioButton.set_label(_("_Fit into selection box")); SpaceByBBoxRadioButton.set_use_underline (true); - SpaceByBBoxRadioButton.signal_toggled().connect(sigc::mem_fun(*this, &TileDialog::Spacing_button_changed)); + SpaceByBBoxRadioButton.signal_toggled().connect(sigc::mem_fun(*this, &GridArrangeTab::Spacing_button_changed)); SpacingGroup = SpaceByBBoxRadioButton.get_group(); SpacingVBox.pack_start(SpaceByBBoxRadioButton, false, false, MARGIN); @@ -723,7 +751,7 @@ TileDialog::TileDialog() SpaceManualRadioButton.set_label(_("_Set spacing:")); SpaceManualRadioButton.set_use_underline (true); SpaceManualRadioButton.set_group(SpacingGroup); - SpaceManualRadioButton.signal_toggled().connect(sigc::mem_fun(*this, &TileDialog::Spacing_button_changed)); + SpaceManualRadioButton.signal_toggled().connect(sigc::mem_fun(*this, &GridArrangeTab::Spacing_button_changed)); SpacingVBox.pack_start(SpaceManualRadioButton, false, false, MARGIN); TileBox.pack_start(SpacingVBox, false, false, MARGIN); @@ -737,7 +765,7 @@ TileDialog::TileDialog() YPadding.setRange(-10000, 10000); double yPad = prefs->getDouble("/dialogs/gridtiler/YPad", 15); YPadding.setValue(yPad, "px"); - YPadding.signal_value_changed().connect(sigc::mem_fun(*this, &TileDialog::on_ypad_spinbutton_changed)); + YPadding.signal_value_changed().connect(sigc::mem_fun(*this, &GridArrangeTab::on_ypad_spinbutton_changed)); XPadding.setDigits(5); XPadding.setIncrements(0.2, 0); @@ -745,7 +773,7 @@ TileDialog::TileDialog() double xPad = prefs->getDouble("/dialogs/gridtiler/XPad", 15); XPadding.setValue(xPad, "px"); - XPadding.signal_value_changed().connect(sigc::mem_fun(*this, &TileDialog::on_xpad_spinbutton_changed)); + XPadding.signal_value_changed().connect(sigc::mem_fun(*this, &GridArrangeTab::on_xpad_spinbutton_changed)); } TileBox.pack_start(XPadding, false, false, MARGIN); TileBox.pack_start(YPadding, false, false, MARGIN); @@ -763,10 +791,10 @@ TileDialog::TileDialog() XPadding.set_sensitive (ManualSpacing); YPadding.set_sensitive (ManualSpacing); - //## The OK button - TileOkButton = addResponseButton(C_("Rows and columns dialog","_Arrange"), GTK_RESPONSE_APPLY); + //## The OK button FIXME + /*TileOkButton = addResponseButton(C_("Rows and columns dialog","_Arrange"), GTK_RESPONSE_APPLY); TileOkButton->set_use_underline(true); - TileOkButton->set_tooltip_text(_("Arrange selected objects")); + TileOkButton->set_tooltip_text(_("Arrange selected objects"));*/ show_all_children(); } diff --git a/src/ui/dialog/tile.h b/src/ui/dialog/tile.h index b3bf390b6..657841ad0 100644 --- a/src/ui/dialog/tile.h +++ b/src/ui/dialog/tile.h @@ -33,19 +33,58 @@ namespace Inkscape { namespace UI { namespace Dialog { +/** + * This interface should be implemented by each arrange mode. + * The class is a Gtk::VBox and will be displayed as a tab in + * the dialog + */ +class ArrangeTab : public Gtk::VBox +{ +public: + ArrangeTab() {}; + virtual ~ArrangeTab() {}; + + /** + * Do the actual work! + */ + virtual void arrange() = 0; +}; + +class GridArrangeTab; + +class ArrangeDialog : public UI::Widget::Panel { +private: + Gtk::VBox _arrangeBox; + Gtk::Notebook _notebook; + + GridArrangeTab *_gridArrangeTab; + + Gtk::Button *_arrangeButton; + +public: + ArrangeDialog(); + virtual ~ArrangeDialog() {}; + + /** + * Callback from Apply + */ + virtual void _apply(); + + static ArrangeDialog& getInstance() { return *new ArrangeDialog(); } +}; /** * Dialog for tiling an object */ -class TileDialog : public UI::Widget::Panel { +class GridArrangeTab : public ArrangeTab { public: - TileDialog() ; - virtual ~TileDialog() {}; + GridArrangeTab(ArrangeDialog *parent); + virtual ~GridArrangeTab() {}; /** * Do the actual work */ - void Grid_Arrange(); + virtual void arrange(); /** * Respond to selection change @@ -69,17 +108,16 @@ public: void Spacing_button_changed(); void Align_changed(); - static TileDialog& getInstance() { return *new TileDialog(); } private: - TileDialog(TileDialog const &d); // no copy - void operator=(TileDialog const &d); // no assign + GridArrangeTab(GridArrangeTab const &d); // no copy + void operator=(GridArrangeTab const &d); // no assign + + ArrangeDialog *Parent; bool userHidden; bool updating; - Gtk::Notebook notebook; - Gtk::VBox TileBox; Gtk::Button *TileOkButton; Gtk::Button *TileCancelButton; -- cgit v1.2.3 From 13a67ac44b1120308c2fc607715ddf0cf3d516e9 Mon Sep 17 00:00:00 2001 From: Denis Declara Date: Mon, 2 Apr 2012 12:08:22 +0200 Subject: Anchor widget now reads the last alignment from the settings. Anchor selection widget is also smaller now. (bzr r11073.1.10) --- src/ui/dialog/dialog-manager.cpp | 2 +- src/ui/dialog/tile.cpp | 4 ++++ src/ui/widget/anchor-selector.cpp | 11 ++++++++++- src/ui/widget/anchor-selector.h | 2 ++ 4 files changed, 17 insertions(+), 2 deletions(-) (limited to 'src/ui') diff --git a/src/ui/dialog/dialog-manager.cpp b/src/ui/dialog/dialog-manager.cpp index 746cfc1b4..528ddf5b3 100644 --- a/src/ui/dialog/dialog-manager.cpp +++ b/src/ui/dialog/dialog-manager.cpp @@ -121,7 +121,7 @@ DialogManager::DialogManager() { registerFactory("SvgFontsDialog", &create); #endif registerFactory("Swatches", &create); - registerFactory("TileDialog", &create); + registerFactory("TileDialog", &create); registerFactory("Trace", &create); registerFactory("Transformation", &create); registerFactory("UndoHistory", &create); diff --git a/src/ui/dialog/tile.cpp b/src/ui/dialog/tile.cpp index 9297b5154..ab3781630 100644 --- a/src/ui/dialog/tile.cpp +++ b/src/ui/dialog/tile.cpp @@ -732,9 +732,13 @@ GridArrangeTab::GridArrangeTab(ArrangeDialog *parent) TileBox.pack_start(SpinsHBox, false, false, MARGIN); + VertAlign = prefs->getInt("/dialogs/gridtiler/VertAlign", 1); + HorizAlign = prefs->getInt("/dialogs/gridtiler/HorizAlign", 1); // Anchor selection widget AlignLabel.set_label("Alignment:"); + AlignLabel.set_alignment(Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER); + AlignmentSelector.setAlignment(HorizAlign, VertAlign); AlignmentSelector.on_selectionChanged().connect(sigc::mem_fun(*this, &GridArrangeTab::Align_changed)); TileBox.pack_start(AlignLabel, false, false, MARGIN); TileBox.pack_start(AlignmentSelector, true, false, MARGIN); diff --git a/src/ui/widget/anchor-selector.cpp b/src/ui/widget/anchor-selector.cpp index aa173e0a0..49387fc34 100644 --- a/src/ui/widget/anchor-selector.cpp +++ b/src/ui/widget/anchor-selector.cpp @@ -13,7 +13,7 @@ #include "ui/widget/anchor-selector.h" void AnchorSelector::setupButton(const Glib::ustring& icon, Gtk::ToggleButton& button) { - Gtk::Widget* buttonIcon = Gtk::manage(sp_icon_get_icon(icon, Inkscape::ICON_SIZE_LARGE_TOOLBAR)); + Gtk::Widget* buttonIcon = Gtk::manage(sp_icon_get_icon(icon, Inkscape::ICON_SIZE_SMALL_TOOLBAR)); buttonIcon->show(); button.set_relief(Gtk::RELIEF_NONE); @@ -67,3 +67,12 @@ void AnchorSelector::btn_activated(int index) _selectionChanged.emit(); } } + +void AnchorSelector::setAlignment(int horizontal, int vertical) +{ + int index = 3 * vertical + horizontal; + if(index >= 0 && index < 9) + { + _buttons[index].set_active(!_buttons[index].get_active()); + } +} diff --git a/src/ui/widget/anchor-selector.h b/src/ui/widget/anchor-selector.h index ad20bf063..361528d11 100644 --- a/src/ui/widget/anchor-selector.h +++ b/src/ui/widget/anchor-selector.h @@ -31,6 +31,8 @@ public: sigc::signal &on_selectionChanged() { return _selectionChanged; } + void setAlignment(int horizontal, int vertical); + AnchorSelector(); virtual ~AnchorSelector(); }; -- cgit v1.2.3 From 591b007232d0806995bc24c7dd93babdec283834 Mon Sep 17 00:00:00 2001 From: Denis Declara Date: Wed, 4 Apr 2012 08:42:22 +0200 Subject: Changed enum used for alignment, which hopefully will fix daily deb builds. (bzr r11073.1.11) --- src/ui/dialog/tile.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/ui') diff --git a/src/ui/dialog/tile.cpp b/src/ui/dialog/tile.cpp index ab3781630..2e5e3f822 100644 --- a/src/ui/dialog/tile.cpp +++ b/src/ui/dialog/tile.cpp @@ -737,7 +737,7 @@ GridArrangeTab::GridArrangeTab(ArrangeDialog *parent) // Anchor selection widget AlignLabel.set_label("Alignment:"); - AlignLabel.set_alignment(Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER); + AlignLabel.set_alignment(Gtk::ALIGN_START, Gtk::ALIGN_CENTER); AlignmentSelector.setAlignment(HorizAlign, VertAlign); AlignmentSelector.on_selectionChanged().connect(sigc::mem_fun(*this, &GridArrangeTab::Align_changed)); TileBox.pack_start(AlignLabel, false, false, MARGIN); -- cgit v1.2.3 From e3102d923b09da811953f791fdaa1d0a01e13032 Mon Sep 17 00:00:00 2001 From: Denis Declara Date: Wed, 4 Apr 2012 11:08:28 +0200 Subject: Changed makefile (bzr r11073.1.12) --- src/ui/widget/Makefile_insert | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/ui') diff --git a/src/ui/widget/Makefile_insert b/src/ui/widget/Makefile_insert index 4dc83a81d..718d95979 100644 --- a/src/ui/widget/Makefile_insert +++ b/src/ui/widget/Makefile_insert @@ -1,6 +1,8 @@ ## Makefile.am fragment sourced by src/Makefile.am. ink_common_sources += \ + ui/widget/anchor-selector.h \ + ui/widget/anchor-selector.cpp \ ui/widget/attr-widget.h \ ui/widget/button.h \ ui/widget/button.cpp \ -- cgit v1.2.3 From d35a809b15aa11aa5ee3c0a035710683e8c76eaa Mon Sep 17 00:00:00 2001 From: Denis Declara Date: Mon, 9 Apr 2012 22:12:58 +0200 Subject: Added initial gui for polar arrangement tab (bzr r11073.1.13) --- src/ui/dialog/tile.cpp | 53 ++++++++++++++++++++++++++++++++++++++++-------- src/ui/dialog/tile.h | 55 +++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 91 insertions(+), 17 deletions(-) (limited to 'src/ui') diff --git a/src/ui/dialog/tile.cpp b/src/ui/dialog/tile.cpp index 2e5e3f822..0e3b24f7c 100644 --- a/src/ui/dialog/tile.cpp +++ b/src/ui/dialog/tile.cpp @@ -111,11 +111,13 @@ namespace Dialog { ArrangeDialog::ArrangeDialog() : UI::Widget::Panel("", "/dialogs/gridtiler", SP_VERB_SELECTION_GRIDTILE), - _gridArrangeTab(new GridArrangeTab(this)) + _gridArrangeTab(new GridArrangeTab(this)), + _polarArrangeTab(new PolarArrangeTab(this)) { Gtk::Box *contents = this->_getContents(); _notebook.append_page(*_gridArrangeTab, C_("Arrange dialog", "Rectangular grid")); + _notebook.append_page(*_polarArrangeTab, C_("Arrange dialog", "Polar Coordinates")); _arrangeBox.pack_start(_notebook); _arrangeButton = this->addResponseButton(C_("Arrange dialog","_Arrange"), GTK_RESPONSE_APPLY); @@ -133,9 +135,51 @@ void ArrangeDialog::_apply() case 0: _gridArrangeTab->arrange(); break; + case 1: + _polarArrangeTab->arrange(); + break; } } +PolarArrangeTab::PolarArrangeTab(ArrangeDialog *parent_) + : parent(parent_) +{ + anchorPointLabel.set_text("Anchor point:"); + anchorPointLabel.set_alignment(Gtk::ALIGN_START); + pack_start(anchorPointLabel, false, false); + + anchorBoundingBoxRadio.set_label("Object's bounding box:"); + anchorBoundingBoxRadio.set_group(anchorRadioGroup); + pack_start(anchorBoundingBoxRadio, false, false); + + pack_start(anchorSelector, false, false); + + anchorObjectPivotRadio.set_label("Object's rotational center"); + anchorObjectPivotRadio.set_group(anchorRadioGroup); + pack_start(anchorObjectPivotRadio, false, false); + + arrangeOnLabel.set_text("Arrange on:"); + arrangeOnLabel.set_alignment(Gtk::ALIGN_START); + pack_start(arrangeOnLabel, false, false); + + arrangeOnCircleRadio.set_label("Last selected circle/ellipse/arc"); + anchorObjectPivotRadio.set_group(arrangeRadioGroup); + pack_start(arrangeOnCircleRadio, false, false); + + arrangeOnParametersRadio.set_label("Parameterized:"); + anchorObjectPivotRadio.set_group(arrangeRadioGroup); + pack_start(arrangeOnParametersRadio, false, false); +} + +void PolarArrangeTab::arrange() +{ + std::cout << "PolarArrangeTab::arrange()" << std::endl; +} + +void PolarArrangeTab::updateSelection() +{ + +} //######################################################################### @@ -383,13 +427,6 @@ g_print("\n row = %f col = %f selection x= %f selection y = %f", total_row_h //## E V E N T S //######################################################################### - -void GridArrangeTab::_apply() -{ - arrange(); -} - - /** * changed value in # of columns spinbox. */ diff --git a/src/ui/dialog/tile.h b/src/ui/dialog/tile.h index 657841ad0..ab075fb28 100644 --- a/src/ui/dialog/tile.h +++ b/src/ui/dialog/tile.h @@ -51,15 +51,17 @@ public: }; class GridArrangeTab; +class PolarArrangeTab; class ArrangeDialog : public UI::Widget::Panel { private: - Gtk::VBox _arrangeBox; - Gtk::Notebook _notebook; + Gtk::VBox _arrangeBox; + Gtk::Notebook _notebook; - GridArrangeTab *_gridArrangeTab; + GridArrangeTab *_gridArrangeTab; + PolarArrangeTab *_polarArrangeTab; - Gtk::Button *_arrangeButton; + Gtk::Button *_arrangeButton; public: ArrangeDialog(); @@ -91,11 +93,6 @@ public: */ void updateSelection(); - /** - * Callback from Apply - */ - virtual void _apply(); - // Callbacks from spinbuttons void on_row_spinbutton_changed(); void on_col_spinbutton_changed(); @@ -176,6 +173,46 @@ private: Inkscape::UI::Widget::SpinButton ColumnWidthSpinner; }; +class PolarArrangeTab : public ArrangeTab { +public: + PolarArrangeTab(ArrangeDialog *parent_); + virtual ~PolarArrangeTab() {}; + + /** + * Do the actual work + */ + virtual void arrange(); + + /** + * Respond to selection change + */ + void updateSelection(); + +private: + PolarArrangeTab(PolarArrangeTab const &d); // no copy + void operator=(PolarArrangeTab const &d); // no assign + + ArrangeDialog *parent; + + Gtk::Label anchorPointLabel; + + Gtk::RadioButtonGroup anchorRadioGroup; + Gtk::RadioButton anchorBoundingBoxRadio; + Gtk::RadioButton anchorObjectPivotRadio; + AnchorSelector anchorSelector; + + Gtk::Label arrangeOnLabel; + + Gtk::RadioButtonGroup arrangeRadioGroup; + Gtk::RadioButton arrangeOnCircleRadio; + Gtk::RadioButton arrangeOnParametersRadio; + + Inkscape::UI::Widget::SpinButton centerXSpin; + Inkscape::UI::Widget::SpinButton centerYSpin; + + +}; + } //namespace Dialog } //namespace UI -- cgit v1.2.3 From ffef031f0c930b63abe89386ad7edfcff0469029 Mon Sep 17 00:00:00 2001 From: Denis Declara Date: Sun, 15 Apr 2012 14:27:18 +0200 Subject: Improved User interface. Added controls for Center, Radius and Angles. Note that none of them actually do something yet (bzr r11073.1.14) --- src/ui/dialog/tile.cpp | 31 +++++++++++++++++++++++++++---- src/ui/dialog/tile.h | 15 +++++++++++++-- 2 files changed, 40 insertions(+), 6 deletions(-) (limited to 'src/ui') diff --git a/src/ui/dialog/tile.cpp b/src/ui/dialog/tile.cpp index 0e3b24f7c..dd49ac9eb 100644 --- a/src/ui/dialog/tile.cpp +++ b/src/ui/dialog/tile.cpp @@ -142,14 +142,21 @@ void ArrangeDialog::_apply() } PolarArrangeTab::PolarArrangeTab(ArrangeDialog *parent_) - : parent(parent_) + : parent(parent_), + parametersTable(3, 3, false), + centerY("", "Y coordinate of the center", UNIT_TYPE_LINEAR), + centerX("", "X coordinate of the center", centerY), + radiusY("", "Y coordinate of the radius", UNIT_TYPE_LINEAR), + radiusX("", "X coordinate of the radius", radiusY), + angleY("", "Starting angle", UNIT_TYPE_RADIAL), + angleX("", "End angle", angleY) { anchorPointLabel.set_text("Anchor point:"); anchorPointLabel.set_alignment(Gtk::ALIGN_START); pack_start(anchorPointLabel, false, false); anchorBoundingBoxRadio.set_label("Object's bounding box:"); - anchorBoundingBoxRadio.set_group(anchorRadioGroup); + anchorRadioGroup = anchorBoundingBoxRadio.get_group(); pack_start(anchorBoundingBoxRadio, false, false); pack_start(anchorSelector, false, false); @@ -163,12 +170,28 @@ PolarArrangeTab::PolarArrangeTab(ArrangeDialog *parent_) pack_start(arrangeOnLabel, false, false); arrangeOnCircleRadio.set_label("Last selected circle/ellipse/arc"); - anchorObjectPivotRadio.set_group(arrangeRadioGroup); + arrangeRadioGroup = arrangeOnCircleRadio.get_group(); pack_start(arrangeOnCircleRadio, false, false); arrangeOnParametersRadio.set_label("Parameterized:"); - anchorObjectPivotRadio.set_group(arrangeRadioGroup); + arrangeOnParametersRadio.set_group(arrangeRadioGroup); pack_start(arrangeOnParametersRadio, false, false); + + centerLabel.set_text("Center X/Y:"); + parametersTable.attach(centerLabel, 0, 1, 0, 1); + parametersTable.attach(centerX, 1, 2, 0, 1, Gtk::EXPAND); + parametersTable.attach(centerY, 2, 3, 0, 1, Gtk::EXPAND); + + radiusLabel.set_text("Radius X/Y:"); + parametersTable.attach(radiusLabel, 0, 1, 1, 2); + parametersTable.attach(radiusX, 1, 2, 1, 2, Gtk::EXPAND); + parametersTable.attach(radiusY, 2, 3, 1, 2, Gtk::EXPAND); + + angleLabel.set_text("Center X/Y:"); + parametersTable.attach(angleLabel, 0, 1, 2, 3); + parametersTable.attach(angleX, 1, 2, 2, 3, Gtk::EXPAND); + parametersTable.attach(angleY, 2, 3, 2, 3, Gtk::EXPAND); + pack_start(parametersTable, false, false); } void PolarArrangeTab::arrange() diff --git a/src/ui/dialog/tile.h b/src/ui/dialog/tile.h index ab075fb28..40352f90d 100644 --- a/src/ui/dialog/tile.h +++ b/src/ui/dialog/tile.h @@ -207,8 +207,19 @@ private: Gtk::RadioButton arrangeOnCircleRadio; Gtk::RadioButton arrangeOnParametersRadio; - Inkscape::UI::Widget::SpinButton centerXSpin; - Inkscape::UI::Widget::SpinButton centerYSpin; + Gtk::Table parametersTable; + + Gtk::Label centerLabel; + Inkscape::UI::Widget::ScalarUnit centerY; + Inkscape::UI::Widget::ScalarUnit centerX; + + Gtk::Label radiusLabel; + Inkscape::UI::Widget::ScalarUnit radiusY; + Inkscape::UI::Widget::ScalarUnit radiusX; + + Gtk::Label angleLabel; + Inkscape::UI::Widget::ScalarUnit angleY; + Inkscape::UI::Widget::ScalarUnit angleX; }; -- cgit v1.2.3 From 35b3c61da544c8e771078a015690d4311203bf84 Mon Sep 17 00:00:00 2001 From: Denis Declara Date: Sun, 15 Apr 2012 22:21:15 +0200 Subject: Added some POC code to move objects around (bzr r11073.1.16) --- src/ui/dialog/tile.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/ui') diff --git a/src/ui/dialog/tile.cpp b/src/ui/dialog/tile.cpp index dd49ac9eb..af2319411 100644 --- a/src/ui/dialog/tile.cpp +++ b/src/ui/dialog/tile.cpp @@ -197,6 +197,18 @@ PolarArrangeTab::PolarArrangeTab(ArrangeDialog *parent_) void PolarArrangeTab::arrange() { std::cout << "PolarArrangeTab::arrange()" << std::endl; + Inkscape::Selection *selection = sp_desktop_selection(parent->getDesktop()); + const GSList *items = selection->itemList(); + int i = 0; + while(items) + { + SPItem *item = SP_ITEM(items->data); + Geom::Point move = Geom::Point(100 * i, -100 * i); + Geom::Affine const affine = Geom::Affine(Geom::Translate(move)); + item->set_i2d_affine(affine); + items = items->next; + ++i; + } } void PolarArrangeTab::updateSelection() -- cgit v1.2.3 From 88a55277617ed0a8ded158fb212669e45f19ff1c Mon Sep 17 00:00:00 2001 From: Denis Declara Date: Mon, 16 Apr 2012 15:27:44 +0200 Subject: Edited include order (putting gtkmm in first place) in the hope that it will fix the compilation issues on launchpad. (bzr r11073.1.17) --- src/ui/widget/anchor-selector.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/ui') diff --git a/src/ui/widget/anchor-selector.cpp b/src/ui/widget/anchor-selector.cpp index 49387fc34..87f50cf5f 100644 --- a/src/ui/widget/anchor-selector.cpp +++ b/src/ui/widget/anchor-selector.cpp @@ -7,10 +7,10 @@ * Released under GNU GPL. Read the file 'COPYING' for more information. */ +#include "ui/widget/anchor-selector.h" #include #include "widgets/icon.h" #include "ui/icon-names.h" -#include "ui/widget/anchor-selector.h" void AnchorSelector::setupButton(const Glib::ustring& icon, Gtk::ToggleButton& button) { Gtk::Widget* buttonIcon = Gtk::manage(sp_icon_get_icon(icon, Inkscape::ICON_SIZE_SMALL_TOOLBAR)); -- cgit v1.2.3 From 610dc4491aefb2afc144cad45893bf5435168648 Mon Sep 17 00:00:00 2001 From: Denis Declara Date: Thu, 19 Apr 2012 16:12:26 +0200 Subject: Improved UI of PolarArrangement Tab and connected some widgets to events (now parts of the GUI disable themselves when needed) (bzr r11073.1.18) --- src/ui/dialog/tile.cpp | 78 ++++++++++++++++++++++++++++++++++++++++++++++---- src/ui/dialog/tile.h | 5 ++++ 2 files changed, 77 insertions(+), 6 deletions(-) (limited to 'src/ui') diff --git a/src/ui/dialog/tile.cpp b/src/ui/dialog/tile.cpp index af2319411..9e2ba71c4 100644 --- a/src/ui/dialog/tile.cpp +++ b/src/ui/dialog/tile.cpp @@ -157,12 +157,14 @@ PolarArrangeTab::PolarArrangeTab(ArrangeDialog *parent_) anchorBoundingBoxRadio.set_label("Object's bounding box:"); anchorRadioGroup = anchorBoundingBoxRadio.get_group(); + anchorBoundingBoxRadio.signal_toggled().connect(sigc::mem_fun(*this, &PolarArrangeTab::on_anchor_radio_changed)); pack_start(anchorBoundingBoxRadio, false, false); pack_start(anchorSelector, false, false); anchorObjectPivotRadio.set_label("Object's rotational center"); anchorObjectPivotRadio.set_group(anchorRadioGroup); + anchorObjectPivotRadio.signal_toggled().connect(sigc::mem_fun(*this, &PolarArrangeTab::on_anchor_radio_changed)); pack_start(anchorObjectPivotRadio, false, false); arrangeOnLabel.set_text("Arrange on:"); @@ -171,27 +173,71 @@ PolarArrangeTab::PolarArrangeTab(ArrangeDialog *parent_) arrangeOnCircleRadio.set_label("Last selected circle/ellipse/arc"); arrangeRadioGroup = arrangeOnCircleRadio.get_group(); + arrangeOnCircleRadio.signal_toggled().connect(sigc::mem_fun(*this, &PolarArrangeTab::on_arrange_radio_changed)); pack_start(arrangeOnCircleRadio, false, false); arrangeOnParametersRadio.set_label("Parameterized:"); arrangeOnParametersRadio.set_group(arrangeRadioGroup); + arrangeOnParametersRadio.signal_toggled().connect(sigc::mem_fun(*this, &PolarArrangeTab::on_arrange_radio_changed)); pack_start(arrangeOnParametersRadio, false, false); + //FIXME: Objects in grid do not line up properly! centerLabel.set_text("Center X/Y:"); parametersTable.attach(centerLabel, 0, 1, 0, 1); - parametersTable.attach(centerX, 1, 2, 0, 1, Gtk::EXPAND); - parametersTable.attach(centerY, 2, 3, 0, 1, Gtk::EXPAND); + centerX.setDigits(2); + centerX.set_size_request(60, -1); + centerX.setIncrements(0.2, 0); + centerX.setRange(-10000, 10000); + centerX.setValue(0, "px"); + centerY.setDigits(2); + centerY.set_size_request(120, -1); + centerY.setIncrements(0.2, 0); + centerY.setRange(-10000, 10000); + centerY.setValue(0, "px"); + parametersTable.attach(centerX, 1, 2, 0, 1); + parametersTable.attach(centerY, 2, 3, 0, 1); radiusLabel.set_text("Radius X/Y:"); parametersTable.attach(radiusLabel, 0, 1, 1, 2); - parametersTable.attach(radiusX, 1, 2, 1, 2, Gtk::EXPAND); - parametersTable.attach(radiusY, 2, 3, 1, 2, Gtk::EXPAND); + radiusX.setDigits(2); + radiusX.set_size_request(60, -1); + radiusX.setIncrements(0.2, 0); + radiusX.setRange(-10000, 10000); + radiusX.setValue(0, "px"); + radiusY.setDigits(2); + radiusY.set_size_request(120, -1); + radiusY.setIncrements(0.2, 0); + radiusY.setRange(-10000, 10000); + radiusY.setValue(0, "px"); + parametersTable.attach(radiusX, 1, 2, 1, 2); + parametersTable.attach(radiusY, 2, 3, 1, 2); angleLabel.set_text("Center X/Y:"); parametersTable.attach(angleLabel, 0, 1, 2, 3); - parametersTable.attach(angleX, 1, 2, 2, 3, Gtk::EXPAND); - parametersTable.attach(angleY, 2, 3, 2, 3, Gtk::EXPAND); + angleX.setDigits(2); + angleX.set_size_request(60, -1); + angleX.setIncrements(0.2, 0); + angleX.setRange(-10000, 10000); + angleX.setValue(0, "°"); + angleY.setDigits(2); + angleY.set_size_request(120, -1); + angleY.setIncrements(0.2, 0); + angleY.setRange(-10000, 10000); + angleY.setValue(0, "°"); + parametersTable.attach(angleX, 1, 2, 2, 3); + parametersTable.attach(angleY, 2, 3, 2, 3); pack_start(parametersTable, false, false); + + rotateObjectsCheckBox.set_label("Rotate objects"); + rotateObjectsCheckBox.set_active(true); + pack_start(rotateObjectsCheckBox, false, false); + + centerX.set_sensitive(false); + centerY.set_sensitive(false); + angleX.set_sensitive(false); + angleY.set_sensitive(false); + radiusX.set_sensitive(false); + radiusY.set_sensitive(false); } void PolarArrangeTab::arrange() @@ -213,7 +259,27 @@ void PolarArrangeTab::arrange() void PolarArrangeTab::updateSelection() { +} + +void PolarArrangeTab::on_arrange_radio_changed() +{ + bool arrangeParametric = !arrangeOnCircleRadio.get_active(); + + centerX.set_sensitive(arrangeParametric); + centerY.set_sensitive(arrangeParametric); + + angleX.set_sensitive(arrangeParametric); + angleY.set_sensitive(arrangeParametric); + + radiusX.set_sensitive(arrangeParametric); + radiusY.set_sensitive(arrangeParametric); +} + +void PolarArrangeTab::on_anchor_radio_changed() +{ + bool anchorBoundingBox = anchorBoundingBoxRadio.get_active(); + anchorSelector.set_sensitive(anchorBoundingBox); } diff --git a/src/ui/dialog/tile.h b/src/ui/dialog/tile.h index 40352f90d..b09416d04 100644 --- a/src/ui/dialog/tile.h +++ b/src/ui/dialog/tile.h @@ -188,6 +188,9 @@ public: */ void updateSelection(); + void on_anchor_radio_changed(); + void on_arrange_radio_changed(); + private: PolarArrangeTab(PolarArrangeTab const &d); // no copy void operator=(PolarArrangeTab const &d); // no assign @@ -221,6 +224,8 @@ private: Inkscape::UI::Widget::ScalarUnit angleY; Inkscape::UI::Widget::ScalarUnit angleX; + Gtk::CheckButton rotateObjectsCheckBox; + }; -- cgit v1.2.3 From 64d1318049350136ae837f74c56bc5ad9a3c363c Mon Sep 17 00:00:00 2001 From: Denis Declara Date: Tue, 24 Apr 2012 22:24:04 +0200 Subject: Added first support for elliptical arrangements (bzr r11073.1.19) --- src/ui/dialog/tile.cpp | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 'src/ui') diff --git a/src/ui/dialog/tile.cpp b/src/ui/dialog/tile.cpp index 9e2ba71c4..d4c597b84 100644 --- a/src/ui/dialog/tile.cpp +++ b/src/ui/dialog/tile.cpp @@ -34,6 +34,7 @@ #include "sp-item.h" #include "widgets/icon.h" #include "desktop.h" +#include "sp-item-transform.h" /* * Sort items by their x co-ordinates, taking account of y (keeps rows intact) @@ -249,9 +250,29 @@ void PolarArrangeTab::arrange() while(items) { SPItem *item = SP_ITEM(items->data); - Geom::Point move = Geom::Point(100 * i, -100 * i); - Geom::Affine const affine = Geom::Affine(Geom::Translate(move)); - item->set_i2d_affine(affine); + + float centerx = 1000; + float centery = 2000; + + float radiusx = 1000; + float radiusy = 2000; + + float objectx = - item->documentVisualBounds()->min()[Geom::X]; + float objecty = item->documentVisualBounds()->min()[Geom::Y]; + + float angle = M_PI / 36 * i; + + float r = (radiusx * radiusy) / + sqrtf(powf(radiusy * cos(angle), 2) + powf(radiusx * sin(angle), 2)); + float calcx = cos(angle) * r; + float calcy = sin(angle) * r; + + sp_item_move_rel(item, Geom::Translate(objectx + calcx, objecty + calcy)); + sp_item_rotate_rel(item, Geom::Rotate(angle)); + + //item->set_i2d_affine(item->i2dt_affine() * toOrigin * rotation); + //item->doWriteTransform(item->getRepr(), item->transform, NULL); + items = items->next; ++i; } -- cgit v1.2.3 From 3b4367f104ffcb7e07664dc711b8a879d1122dec Mon Sep 17 00:00:00 2001 From: Denis Declara Date: Fri, 27 Apr 2012 23:43:11 +0200 Subject: Code Refactoreing. Moved parts of the code from tile.cpp tile.h to arrangetab.h, gridarrangetab(.cpp|.h), polararrangetab(.cpp|.h) Also modified the name of the verb used by the "Rows and Columns" dialog to SP_VERB_SELECTION_ARRANGE (bzr r11073.1.21) --- src/ui/CMakeLists.txt | 5 + src/ui/dialog/arrangetab.h | 54 +++ src/ui/dialog/gridarrangetab.cpp | 786 ++++++++++++++++++++++++++++++++ src/ui/dialog/gridarrangetab.h | 147 ++++++ src/ui/dialog/polararrangetab.cpp | 206 +++++++++ src/ui/dialog/polararrangetab.h | 86 ++++ src/ui/dialog/tile.cpp | 914 +------------------------------------- src/ui/dialog/tile.h | 177 +------- 8 files changed, 1291 insertions(+), 1084 deletions(-) create mode 100644 src/ui/dialog/arrangetab.h create mode 100644 src/ui/dialog/gridarrangetab.cpp create mode 100644 src/ui/dialog/gridarrangetab.h create mode 100644 src/ui/dialog/polararrangetab.cpp create mode 100644 src/ui/dialog/polararrangetab.h (limited to 'src/ui') diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt index 2c6a68569..b244b7349 100644 --- a/src/ui/CMakeLists.txt +++ b/src/ui/CMakeLists.txt @@ -42,6 +42,7 @@ set(ui_SRC dialog/find.cpp dialog/floating-behavior.cpp dialog/glyphs.cpp + dialog/gridarrangetab.cpp dialog/guides.cpp dialog/icon-preview.cpp dialog/inkscape-preferences.cpp @@ -55,6 +56,7 @@ set(ui_SRC dialog/object-attributes.cpp dialog/object-properties.cpp dialog/ocaldialogs.cpp + dialog/polararrangetab.cpp dialog/print-colors-preview-dialog.cpp dialog/print.cpp dialog/scriptdialog.cpp @@ -132,6 +134,7 @@ set(ui_SRC dialog/aboutbox.h dialog/align-and-distribute.h + dialog/arrangetab.h dialog/behavior.h dialog/calligraphic-profile-rename.h dialog/color-item.h @@ -155,6 +158,7 @@ set(ui_SRC dialog/floating-behavior.h dialog/glyphs.h dialog/guides.h + dialog/gridarrangetab.h dialog/icon-preview.h dialog/inkscape-preferences.h dialog/input.h @@ -168,6 +172,7 @@ set(ui_SRC dialog/object-properties.h dialog/ocaldialogs.h dialog/panel-dialog.h + dialog/polararrangetab.h dialog/print-colors-preview-dialog.h dialog/print.h dialog/scriptdialog.h diff --git a/src/ui/dialog/arrangetab.h b/src/ui/dialog/arrangetab.h new file mode 100644 index 000000000..3ffe1ef4c --- /dev/null +++ b/src/ui/dialog/arrangetab.h @@ -0,0 +1,54 @@ +/** + * @brief Arrange tools base class + */ +/* Authors: + * * Declara Denis + * Copyright (C) 2012 Authors + * + * Released under GNU GPL. Read the file 'COPYING' for more information. + */ + +#ifndef INKSCAPE_UI_DIALOG_ARRANGE_TAB_H +#define INKSCAPE_UI_DIALOG_ARRANGE_TAB_H + +#include + +namespace Inkscape { +namespace UI { +namespace Dialog { + +/** + * This interface should be implemented by each arrange mode. + * The class is a Gtk::VBox and will be displayed as a tab in + * the dialog + */ +class ArrangeTab : public Gtk::VBox +{ +public: + ArrangeTab() {}; + virtual ~ArrangeTab() {}; + + /** + * Do the actual work! This method is invoked to actually arrange the + * selection + */ + virtual void arrange() = 0; +}; + +} //namespace Dialog +} //namespace UI +} //namespace Inkscape + + +#endif /* INKSCAPE_UI_DIALOG_ARRANGE_TAB_H */ + +/* + 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/gridarrangetab.cpp b/src/ui/dialog/gridarrangetab.cpp new file mode 100644 index 000000000..fca7c5b0e --- /dev/null +++ b/src/ui/dialog/gridarrangetab.cpp @@ -0,0 +1,786 @@ +/* + * A simple dialog for creating grid type arrangements of selected objects + * + * Authors: + * Bob Jamison ( based off trace dialog) + * John Cliff + * Other dudes from The Inkscape Organization + * Abhishek Sharma + * Declara Denis + * + * Copyright (C) 2004 Bob Jamison + * Copyright (C) 2004 John Cliff + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ +//#define DEBUG_GRID_ARRANGE 1 + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "ui/dialog/gridarrangetab.h" +#include //for GTK_RESPONSE* types +#include +#include +#include <2geom/transforms.h> + +#include "verbs.h" +#include "preferences.h" +#include "inkscape.h" +#include "desktop-handles.h" +#include "selection.h" +#include "document.h" +#include "document-undo.h" +#include "sp-item.h" +#include "widgets/icon.h" +#include "desktop.h" +//#include "sp-item-transform.h" FIXME +#include "ui/dialog/tile.h" // for Inkscape::UI::Dialog::ArrangeDialog + +/* + * Sort items by their x co-ordinates, taking account of y (keeps rows intact) + * + * <0 *elem1 goes before *elem2 + * 0 *elem1 == *elem2 + * >0 *elem1 goes after *elem2 + */ +int sp_compare_x_position(SPItem *first, SPItem *second) +{ + using Geom::X; + using Geom::Y; + + Geom::OptRect a = first->documentVisualBounds(); + Geom::OptRect b = second->documentVisualBounds(); + + if ( !a || !b ) { + // FIXME? + return 0; + } + + double const a_height = a->dimensions()[Y]; + double const b_height = b->dimensions()[Y]; + + bool a_in_b_vert = false; + if ((a->min()[Y] < b->min()[Y] + 0.1) && (a->min()[Y] > b->min()[Y] - b_height)) { + a_in_b_vert = true; + } else if ((b->min()[Y] < a->min()[Y] + 0.1) && (b->min()[Y] > a->min()[Y] - a_height)) { + a_in_b_vert = true; + } else if (b->min()[Y] == a->min()[Y]) { + a_in_b_vert = true; + } else { + a_in_b_vert = false; + } + + if (!a_in_b_vert) { + return -1; + } + if (a_in_b_vert && a->min()[X] > b->min()[X]) { + return 1; + } + if (a_in_b_vert && a->min()[X] < b->min()[X]) { + return -1; + } + return 0; +} + +/* + * Sort items by their y co-ordinates. + */ +int sp_compare_y_position(SPItem *first, SPItem *second) +{ + Geom::OptRect a = first->documentVisualBounds(); + Geom::OptRect b = second->documentVisualBounds(); + + if ( !a || !b ) { + // FIXME? + return 0; + } + + if (a->min()[Geom::Y] > b->min()[Geom::Y]) { + return 1; + } + if (a->min()[Geom::Y] < b->min()[Geom::Y]) { + return -1; + } + + return 0; +} + +namespace Inkscape { +namespace UI { +namespace Dialog { + + +//######################################################################### +//## E V E N T S +//######################################################################### + +/* + * + * This arranges the selection in a grid pattern. + * + */ + +void GridArrangeTab::arrange() +{ + + int cnt,row_cnt,col_cnt,a,row,col; + double grid_left,grid_top,col_width,row_height,paddingx,paddingy,width, height, new_x, new_y,cx,cy; + double total_col_width,total_row_height; + col_width = 0; + row_height = 0; + total_col_width=0; + total_row_height=0; + + // check for correct numbers in the row- and col-spinners + on_col_spinbutton_changed(); + on_row_spinbutton_changed(); + + // set padding to manual values + paddingx = XPadding.getValue("px"); + paddingy = YPadding.getValue("px"); + + std::vector row_heights; + std::vector col_widths; + std::vector row_ys; + std::vector col_xs; + + int NoOfCols = NoOfColsSpinner.get_value_as_int(); + int NoOfRows = NoOfRowsSpinner.get_value_as_int(); + + width = 0; + for (a=0;agetDesktop(); + sp_desktop_document(desktop)->ensureUpToDate(); + + Inkscape::Selection *selection = sp_desktop_selection (desktop); + const GSList *items = selection ? selection->itemList() : 0; + cnt=0; + for (; items != NULL; items = items->next) { + SPItem *item = SP_ITEM(items->data); + Geom::OptRect b = item->documentVisualBounds(); + if (!b) { + continue; + } + + width = b->dimensions()[Geom::X]; + height = b->dimensions()[Geom::Y]; + + cx = b->midpoint()[Geom::X]; + cy = b->midpoint()[Geom::Y]; + + if (b->min()[Geom::X] < grid_left) { + grid_left = b->min()[Geom::X]; + } + if (b->min()[Geom::Y] < grid_top) { + grid_top = b->min()[Geom::Y]; + } + if (width > col_width) { + col_width = width; + } + if (height > row_height) { + row_height = height; + } + } + + + // require the sorting done before we can calculate row heights etc. + + g_return_if_fail(selection); + const GSList *items2 = selection->itemList(); + GSList *rev = g_slist_copy((GSList *) items2); + GSList *sorted = NULL; + rev = g_slist_sort(rev, (GCompareFunc) sp_compare_y_position); + sorted = g_slist_sort(rev, (GCompareFunc) sp_compare_x_position); + + + // Calculate individual Row and Column sizes if necessary + + + cnt=0; + const GSList *sizes = sorted; + for (; sizes != NULL; sizes = sizes->next) { + SPItem *item = SP_ITEM(sizes->data); + Geom::OptRect b = item->documentVisualBounds(); + if (b) { + width = b->dimensions()[Geom::X]; + height = b->dimensions()[Geom::Y]; + if (width > col_widths[(cnt % NoOfCols)]) { + col_widths[(cnt % NoOfCols)] = width; + } + if (height > row_heights[(cnt / NoOfCols)]) { + row_heights[(cnt / NoOfCols)] = height; + } + } + + cnt++; + } + + + /// Make sure the top and left of the grid dont move by compensating for align values. + if (RowHeightButton.get_active()){ + grid_top = grid_top - (((row_height - row_heights[0]) / 2)*(VertAlign)); + } + if (ColumnWidthButton.get_active()){ + grid_left = grid_left - (((col_width - col_widths[0]) /2)*(HorizAlign)); + } + + #ifdef DEBUG_GRID_ARRANGE + g_print("\n cx = %f cy= %f gridleft=%f",cx,cy,grid_left); + #endif + + // Calculate total widths and heights, allowing for columns and rows non uniformly sized. + + if (ColumnWidthButton.get_active()){ + total_col_width = col_width * NoOfCols; + col_widths.clear(); + for (a=0;avisualBounds(); + // Fit to bbox, calculate padding between rows accordingly. + if ( sel_bbox && !SpaceManualRadioButton.get_active() ){ +#ifdef DEBUG_GRID_ARRANGE +g_print("\n row = %f col = %f selection x= %f selection y = %f", total_row_height,total_col_width, b.extent(Geom::X), b.extent(Geom::Y)); +#endif + paddingx = (sel_bbox->width() - total_col_width) / (NoOfCols -1); + paddingy = (sel_bbox->height() - total_row_height) / (NoOfRows -1); + } + +/* + Horizontal align - Left = 0 + Centre = 1 + Right = 2 + + Vertical align - Top = 0 + Middle = 1 + Bottom = 2 + + X position is calculated by taking the grids left co-ord, adding the distance to the column, + then adding 1/2 the spacing multiplied by the align variable above, + Y position likewise, takes the top of the grid, adds the y to the current row then adds the padding in to align it. + +*/ + + // Calculate row and column x and y coords required to allow for columns and rows which are non uniformly sized. + + for (a=0;adata); + sorted = sorted->next; + } + + for (; current_row != NULL; current_row = current_row->next) { + SPItem *item=SP_ITEM(current_row->data); + Inkscape::XML::Node *repr = item->getRepr(); + Geom::OptRect b = item->documentVisualBounds(); + Geom::Point min; + if (b) { + width = b->dimensions()[Geom::X]; + height = b->dimensions()[Geom::Y]; + min = b->min(); + } else { + width = height = 0; + min = Geom::Point(0, 0); + } + + row = cnt / NoOfCols; + col = cnt % NoOfCols; + + new_x = grid_left + (((col_widths[col] - width)/2)*HorizAlign) + col_xs[col]; + new_y = grid_top + (((row_heights[row] - height)/2)*VertAlign) + row_ys[row]; + + // signs are inverted between x and y due to y inversion + Geom::Point move = Geom::Point(new_x - min[Geom::X], min[Geom::Y] - new_y); + Geom::Affine const affine = Geom::Affine(Geom::Translate(move)); + item->set_i2d_affine(item->i2dt_affine() * affine); + item->doWriteTransform(repr, item->transform, NULL); + SP_OBJECT (current_row->data)->updateRepr(); + cnt +=1; + } + g_slist_free (current_row); + } + + DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_SELECTION_ARRANGE, + _("Arrange in a grid")); + +} + + +//######################################################################### +//## E V E N T S +//######################################################################### + +/** + * changed value in # of columns spinbox. + */ +void GridArrangeTab::on_row_spinbutton_changed() +{ + // quit if run by the attr_changed listener + if (updating) { + return; + } + + // in turn, prevent listener from responding + updating = true; + SPDesktop *desktop = Parent->getDesktop(); + + Inkscape::Selection *selection = desktop ? desktop->selection : 0; + g_return_if_fail( selection ); + + GSList const *items = selection->itemList(); + int selcount = g_slist_length((GSList *)items); + + double PerCol = ceil(selcount / NoOfColsSpinner.get_value()); + NoOfRowsSpinner.set_value(PerCol); + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->setDouble("/dialogs/gridtiler/NoOfCols", NoOfColsSpinner.get_value()); + updating=false; +} + +/** + * changed value in # of rows spinbox. + */ +void GridArrangeTab::on_col_spinbutton_changed() +{ + // quit if run by the attr_changed listener + if (updating) { + return; + } + + // in turn, prevent listener from responding + updating = true; + SPDesktop *desktop = Parent->getDesktop(); + Inkscape::Selection *selection = desktop ? desktop->selection : 0; + g_return_if_fail(selection); + + GSList const *items = selection->itemList(); + int selcount = g_slist_length((GSList *)items); + + double PerRow = ceil(selcount / NoOfRowsSpinner.get_value()); + NoOfColsSpinner.set_value(PerRow); + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->setDouble("/dialogs/gridtiler/NoOfCols", PerRow); + + updating=false; +} + +/** + * changed value in x padding spinbox. + */ +void GridArrangeTab::on_xpad_spinbutton_changed() +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->setDouble("/dialogs/gridtiler/XPad", XPadding.getValue("px")); + +} + +/** + * changed value in y padding spinbox. + */ +void GridArrangeTab::on_ypad_spinbutton_changed() +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->setDouble("/dialogs/gridtiler/YPad", YPadding.getValue("px")); +} + + +/** + * checked/unchecked autosize Rows button. + */ +void GridArrangeTab::on_RowSize_checkbutton_changed() +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + if (RowHeightButton.get_active()) { + prefs->setDouble("/dialogs/gridtiler/AutoRowSize", 20); + } else { + prefs->setDouble("/dialogs/gridtiler/AutoRowSize", -20); + } + RowHeightBox.set_sensitive ( !RowHeightButton.get_active()); +} + +/** + * checked/unchecked autosize Rows button. + */ +void GridArrangeTab::on_ColSize_checkbutton_changed() +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + if (ColumnWidthButton.get_active()) { + prefs->setDouble("/dialogs/gridtiler/AutoColSize", 20); + } else { + prefs->setDouble("/dialogs/gridtiler/AutoColSize", -20); + } + ColumnWidthBox.set_sensitive ( !ColumnWidthButton.get_active()); +} + +/** + * changed value in columns spinbox. + */ +void GridArrangeTab::on_rowSize_spinbutton_changed() +{ + // quit if run by the attr_changed listener + if (updating) { + return; + } + + // in turn, prevent listener from responding + updating = true; + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->setDouble("/dialogs/gridtiler/RowHeight", RowHeightSpinner.get_value()); + updating=false; + +} + +/** + * changed value in rows spinbox. + */ +void GridArrangeTab::on_colSize_spinbutton_changed() +{ + // quit if run by the attr_changed listener + if (updating) { + return; + } + + // in turn, prevent listener from responding + updating = true; + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->setDouble("/dialogs/gridtiler/ColWidth", ColumnWidthSpinner.get_value()); + updating=false; + +} + +/** + * changed Radio button in Spacing group. + */ +void GridArrangeTab::Spacing_button_changed() +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + if (SpaceManualRadioButton.get_active()) { + prefs->setDouble("/dialogs/gridtiler/SpacingType", 20); + } else { + prefs->setDouble("/dialogs/gridtiler/SpacingType", -20); + } + + XPadding.set_sensitive ( SpaceManualRadioButton.get_active()); + YPadding.set_sensitive ( SpaceManualRadioButton.get_active()); +} + +/** + * changed Anchor selection widget. + */ +void GridArrangeTab::Align_changed() +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + VertAlign = AlignmentSelector.getVerticalAlignment(); + prefs->setInt("/dialogs/gridtiler/VertAlign", VertAlign); + HorizAlign = AlignmentSelector.getHorizontalAlignment(); + prefs->setInt("/dialogs/gridtiler/HorizAlign", HorizAlign); +} + +/** + * Desktop selection changed + */ +void GridArrangeTab::updateSelection() +{ + // quit if run by the attr_changed listener + if (updating) { + return; + } + + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + // in turn, prevent listener from responding + updating = true; + SPDesktop *desktop = Parent->getDesktop(); + Inkscape::Selection *selection = desktop ? desktop->selection : 0; + GSList const *items = selection ? selection->itemList() : 0; + + if (items) { + int selcount = g_slist_length((GSList *)items); + + if (NoOfColsSpinner.get_value() > 1 && NoOfRowsSpinner.get_value() > 1){ + // Update the number of rows assuming number of columns wanted remains same. + double NoOfRows = ceil(selcount / NoOfColsSpinner.get_value()); + NoOfRowsSpinner.set_value(NoOfRows); + + // if the selection has less than the number set for one row, reduce it appropriately + if (selcount < NoOfColsSpinner.get_value()) { + double NoOfCols = ceil(selcount / NoOfRowsSpinner.get_value()); + NoOfColsSpinner.set_value(NoOfCols); + prefs->setInt("/dialogs/gridtiler/NoOfCols", NoOfCols); + } + } else { + double PerRow = ceil(sqrt(selcount)); + double PerCol = ceil(sqrt(selcount)); + NoOfRowsSpinner.set_value(PerRow); + NoOfColsSpinner.set_value(PerCol); + prefs->setInt("/dialogs/gridtiler/NoOfCols", static_cast(PerCol)); + } + } + + updating = false; +} + + + +/*########################## +## Experimental +##########################*/ + +static void updateSelectionCallback(Inkscape::Application */*inkscape*/, Inkscape::Selection */*selection*/, GridArrangeTab *dlg) +{ + dlg->updateSelection(); +} + + +//######################################################################### +//## C O N S T R U C T O R / D E S T R U C T O R +//######################################################################### +/** + * Constructor + */ +GridArrangeTab::GridArrangeTab(ArrangeDialog *parent) + : Parent(parent), + XPadding(_("X:"), _("Horizontal spacing between columns."), UNIT_TYPE_LINEAR, "", "object-columns"), + YPadding(_("Y:"), _("Vertical spacing between rows."), XPadding, "", "object-rows") +{ + // bool used by spin button callbacks to stop loops where they change each other. + updating = false; + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + + // could not do this in gtkmm - there's no Gtk::SizeGroup public constructor (!) + GtkSizeGroup *_col1 = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); + GtkSizeGroup *_col2 = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); + GtkSizeGroup *_col3 = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); + + { + // Selection Change signal + g_signal_connect ( G_OBJECT (INKSCAPE), "change_selection", G_CALLBACK (updateSelectionCallback), this); + } + + Gtk::Box *contents = this; + +#define MARGIN 2 + + //##Set up the panel + + SPDesktop *desktop = Parent->getDesktop(); + + Inkscape::Selection *selection = desktop ? desktop->selection : 0; + g_return_if_fail( selection ); + int selcount = 1; + if (!selection->isEmpty()) { + GSList const *items = selection->itemList(); + selcount = g_slist_length((GSList *)items); + } + + + /*#### Number of Rows ####*/ + + double PerRow = ceil(sqrt(selcount)); + double PerCol = ceil(sqrt(selcount)); + + #ifdef DEBUG_GRID_ARRANGE + g_print("/n PerRox = %f PerCol = %f selcount = %d",PerRow,PerCol,selcount); + #endif + + NoOfRowsLabel.set_text_with_mnemonic(_("_Rows:")); + NoOfRowsLabel.set_mnemonic_widget(NoOfRowsSpinner); + NoOfRowsBox.pack_start(NoOfRowsLabel, false, false, MARGIN); + + NoOfRowsSpinner.set_digits(0); + NoOfRowsSpinner.set_increments(1, 0); + NoOfRowsSpinner.set_range(1.0, 10000.0); + NoOfRowsSpinner.set_value(PerCol); + NoOfRowsSpinner.signal_changed().connect(sigc::mem_fun(*this, &GridArrangeTab::on_col_spinbutton_changed)); + NoOfRowsSpinner.set_tooltip_text(_("Number of rows")); + NoOfRowsBox.pack_start(NoOfRowsSpinner, false, false, MARGIN); + gtk_size_group_add_widget(_col1, (GtkWidget *) NoOfRowsBox.gobj()); + + RowHeightButton.set_label(_("Equal _height")); + RowHeightButton.set_use_underline(true); + double AutoRow = prefs->getDouble("/dialogs/gridtiler/AutoRowSize", 15); + if (AutoRow>0) + AutoRowSize=true; + else + AutoRowSize=false; + RowHeightButton.set_active(AutoRowSize); + + NoOfRowsBox.pack_start(RowHeightButton, false, false, MARGIN); + + RowHeightButton.set_tooltip_text(_("If not set, each row has the height of the tallest object in it")); + RowHeightButton.signal_toggled().connect(sigc::mem_fun(*this, &GridArrangeTab::on_RowSize_checkbutton_changed)); + + SpinsHBox.pack_start(NoOfRowsBox, false, false, MARGIN); + + + /*#### Label for X ####*/ + padXByYLabel.set_label(" "); + XByYLabelVBox.pack_start(padXByYLabel, false, false, MARGIN); + XByYLabel.set_markup(" × "); + XByYLabelVBox.pack_start(XByYLabel, false, false, MARGIN); + SpinsHBox.pack_start(XByYLabelVBox, false, false, MARGIN); + gtk_size_group_add_widget(_col2, (GtkWidget *) XByYLabelVBox.gobj()); + + /*#### Number of columns ####*/ + + NoOfColsLabel.set_text_with_mnemonic(_("_Columns:")); + NoOfColsLabel.set_mnemonic_widget(NoOfColsSpinner); + NoOfColsBox.pack_start(NoOfColsLabel, false, false, MARGIN); + + NoOfColsSpinner.set_digits(0); + NoOfColsSpinner.set_increments(1, 0); + NoOfColsSpinner.set_range(1.0, 10000.0); + NoOfColsSpinner.set_value(PerRow); + NoOfColsSpinner.signal_changed().connect(sigc::mem_fun(*this, &GridArrangeTab::on_row_spinbutton_changed)); + NoOfColsSpinner.set_tooltip_text(_("Number of columns")); + NoOfColsBox.pack_start(NoOfColsSpinner, false, false, MARGIN); + gtk_size_group_add_widget(_col3, (GtkWidget *) NoOfColsBox.gobj()); + + ColumnWidthButton.set_label(_("Equal _width")); + ColumnWidthButton.set_use_underline(true); + double AutoCol = prefs->getDouble("/dialogs/gridtiler/AutoColSize", 15); + if (AutoCol>0) + AutoColSize=true; + else + AutoColSize=false; + ColumnWidthButton.set_active(AutoColSize); + NoOfColsBox.pack_start(ColumnWidthButton, false, false, MARGIN); + + ColumnWidthButton.set_tooltip_text(_("If not set, each column has the width of the widest object in it")); + ColumnWidthButton.signal_toggled().connect(sigc::mem_fun(*this, &GridArrangeTab::on_ColSize_checkbutton_changed)); + + SpinsHBox.pack_start(NoOfColsBox, false, false, MARGIN); + + TileBox.pack_start(SpinsHBox, false, false, MARGIN); + + VertAlign = prefs->getInt("/dialogs/gridtiler/VertAlign", 1); + HorizAlign = prefs->getInt("/dialogs/gridtiler/HorizAlign", 1); + + // Anchor selection widget + AlignLabel.set_label("Alignment:"); + AlignLabel.set_alignment(Gtk::ALIGN_START, Gtk::ALIGN_CENTER); + AlignmentSelector.setAlignment(HorizAlign, VertAlign); + AlignmentSelector.on_selectionChanged().connect(sigc::mem_fun(*this, &GridArrangeTab::Align_changed)); + TileBox.pack_start(AlignLabel, false, false, MARGIN); + TileBox.pack_start(AlignmentSelector, true, false, MARGIN); + + { + /*#### Radio buttons to control spacing manually or to fit selection bbox ####*/ + SpaceByBBoxRadioButton.set_label(_("_Fit into selection box")); + SpaceByBBoxRadioButton.set_use_underline (true); + SpaceByBBoxRadioButton.signal_toggled().connect(sigc::mem_fun(*this, &GridArrangeTab::Spacing_button_changed)); + SpacingGroup = SpaceByBBoxRadioButton.get_group(); + + SpacingVBox.pack_start(SpaceByBBoxRadioButton, false, false, MARGIN); + + SpaceManualRadioButton.set_label(_("_Set spacing:")); + SpaceManualRadioButton.set_use_underline (true); + SpaceManualRadioButton.set_group(SpacingGroup); + SpaceManualRadioButton.signal_toggled().connect(sigc::mem_fun(*this, &GridArrangeTab::Spacing_button_changed)); + SpacingVBox.pack_start(SpaceManualRadioButton, false, false, MARGIN); + + TileBox.pack_start(SpacingVBox, false, false, MARGIN); + } + + { + /*#### Padding ####*/ + + YPadding.setDigits(5); + YPadding.setIncrements(0.2, 0); + YPadding.setRange(-10000, 10000); + double yPad = prefs->getDouble("/dialogs/gridtiler/YPad", 15); + YPadding.setValue(yPad, "px"); + YPadding.signal_value_changed().connect(sigc::mem_fun(*this, &GridArrangeTab::on_ypad_spinbutton_changed)); + + XPadding.setDigits(5); + XPadding.setIncrements(0.2, 0); + XPadding.setRange(-10000, 10000); + double xPad = prefs->getDouble("/dialogs/gridtiler/XPad", 15); + XPadding.setValue(xPad, "px"); + + XPadding.signal_value_changed().connect(sigc::mem_fun(*this, &GridArrangeTab::on_xpad_spinbutton_changed)); + } + TileBox.pack_start(XPadding, false, false, MARGIN); + TileBox.pack_start(YPadding, false, false, MARGIN); + + contents->pack_start(TileBox); + + double SpacingType = prefs->getDouble("/dialogs/gridtiler/SpacingType", 15); + if (SpacingType>0) { + ManualSpacing=true; + } else { + ManualSpacing=false; + } + SpaceManualRadioButton.set_active(ManualSpacing); + SpaceByBBoxRadioButton.set_active(!ManualSpacing); + XPadding.set_sensitive (ManualSpacing); + YPadding.set_sensitive (ManualSpacing); + + //## The OK button FIXME + /*TileOkButton = addResponseButton(C_("Rows and columns dialog","_Arrange"), GTK_RESPONSE_APPLY); + TileOkButton->set_use_underline(true); + TileOkButton->set_tooltip_text(_("Arrange selected objects"));*/ + + show_all_children(); +} + +} //namespace Dialog +} //namespace UI +} //namespace Inkscape + +/* + 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/gridarrangetab.h b/src/ui/dialog/gridarrangetab.h new file mode 100644 index 000000000..bc82258b8 --- /dev/null +++ b/src/ui/dialog/gridarrangetab.h @@ -0,0 +1,147 @@ +/** + * @brief Arranges Objects into a Grid + */ +/* Authors: + * Bob Jamison ( based off trace dialog) + * John Cliff + * Other dudes from The Inkscape Organization + * Abhishek Sharma + * Declara Denis + * + * Copyright (C) 2004 Bob Jamison + * Copyright (C) 2004 John Cliff + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#ifndef INKSCAPE_UI_DIALOG_GRID_ARRANGE_TAB_H +#define INKSCAPE_UI_DIALOG_GRID_ARRANGE_TAB_H + +#include + +#include "ui/dialog/arrangetab.h" + +#include "ui/widget/anchor-selector.h" +#include "ui/widget/scalar-unit.h" +#include "ui/widget/spinbutton.h" + +namespace Inkscape { +namespace UI { +namespace Dialog { + +class ArrangeDialog; + +/** + * Dialog for tiling an object + */ +class GridArrangeTab : public ArrangeTab { +public: + GridArrangeTab(ArrangeDialog *parent); + virtual ~GridArrangeTab() {}; + + /** + * Do the actual work + */ + virtual void arrange(); + + /** + * Respond to selection change + */ + void updateSelection(); + + // Callbacks from spinbuttons + void on_row_spinbutton_changed(); + void on_col_spinbutton_changed(); + void on_xpad_spinbutton_changed(); + void on_ypad_spinbutton_changed(); + void on_RowSize_checkbutton_changed(); + void on_ColSize_checkbutton_changed(); + void on_rowSize_spinbutton_changed(); + void on_colSize_spinbutton_changed(); + void Spacing_button_changed(); + void Align_changed(); + + +private: + GridArrangeTab(GridArrangeTab const &d); // no copy + void operator=(GridArrangeTab const &d); // no assign + + ArrangeDialog *Parent; + + bool userHidden; + bool updating; + + Gtk::VBox TileBox; + Gtk::Button *TileOkButton; + Gtk::Button *TileCancelButton; + + // Number selected label + Gtk::Label SelectionContentsLabel; + + + Gtk::HBox AlignHBox; + Gtk::HBox SpinsHBox; + + // Number per Row + Gtk::VBox NoOfColsBox; + Gtk::Label NoOfColsLabel; + Inkscape::UI::Widget::SpinButton NoOfColsSpinner; + bool AutoRowSize; + Gtk::CheckButton RowHeightButton; + + Gtk::VBox XByYLabelVBox; + Gtk::Label padXByYLabel; + Gtk::Label XByYLabel; + + // Number per Column + Gtk::VBox NoOfRowsBox; + Gtk::Label NoOfRowsLabel; + Inkscape::UI::Widget::SpinButton NoOfRowsSpinner; + bool AutoColSize; + Gtk::CheckButton ColumnWidthButton; + + // Alignment + Gtk::Label AlignLabel; + AnchorSelector AlignmentSelector; + double VertAlign; + double HorizAlign; + + Inkscape::UI::Widget::ScalarUnit XPadding; + Inkscape::UI::Widget::ScalarUnit YPadding; + + // BBox or manual spacing + Gtk::VBox SpacingVBox; + Gtk::RadioButtonGroup SpacingGroup; + Gtk::RadioButton SpaceByBBoxRadioButton; + Gtk::RadioButton SpaceManualRadioButton; + bool ManualSpacing; + + // Row height + Gtk::VBox RowHeightVBox; + Gtk::HBox RowHeightBox; + Gtk::Label RowHeightLabel; + Inkscape::UI::Widget::SpinButton RowHeightSpinner; + + // Column width + Gtk::VBox ColumnWidthVBox; + Gtk::HBox ColumnWidthBox; + Gtk::Label ColumnWidthLabel; + Inkscape::UI::Widget::SpinButton ColumnWidthSpinner; +}; + +} //namespace Dialog +} //namespace UI +} //namespace Inkscape + +#endif /* INKSCAPE_UI_DIALOG_GRID_ARRANGE_TAB_H */ + +/* + 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/polararrangetab.cpp b/src/ui/dialog/polararrangetab.cpp new file mode 100644 index 000000000..d36a78759 --- /dev/null +++ b/src/ui/dialog/polararrangetab.cpp @@ -0,0 +1,206 @@ +/** + * @brief Arranges Objects into a Circle/Ellipse + */ +/* Authors: + * Declara Denis + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include <2geom/transforms.h> +#include + +#include "ui/dialog/polararrangetab.h" +#include "ui/dialog/tile.h" + +#include "verbs.h" +#include "preferences.h" +#include "inkscape.h" +#include "desktop-handles.h" +#include "selection.h" +#include "document.h" +#include "document-undo.h" +#include "sp-item.h" +#include "widgets/icon.h" +#include "desktop.h" +#include "sp-item-transform.h" + +namespace Inkscape { +namespace UI { +namespace Dialog { + +PolarArrangeTab::PolarArrangeTab(ArrangeDialog *parent_) + : parent(parent_), + parametersTable(3, 3, false), + centerY("", "Y coordinate of the center", UNIT_TYPE_LINEAR), + centerX("", "X coordinate of the center", centerY), + radiusY("", "Y coordinate of the radius", UNIT_TYPE_LINEAR), + radiusX("", "X coordinate of the radius", radiusY), + angleY("", "Starting angle", UNIT_TYPE_RADIAL), + angleX("", "End angle", angleY) +{ + anchorPointLabel.set_text("Anchor point:"); + anchorPointLabel.set_alignment(Gtk::ALIGN_START); + pack_start(anchorPointLabel, false, false); + + anchorBoundingBoxRadio.set_label("Object's bounding box:"); + anchorRadioGroup = anchorBoundingBoxRadio.get_group(); + anchorBoundingBoxRadio.signal_toggled().connect(sigc::mem_fun(*this, &PolarArrangeTab::on_anchor_radio_changed)); + pack_start(anchorBoundingBoxRadio, false, false); + + pack_start(anchorSelector, false, false); + + anchorObjectPivotRadio.set_label("Object's rotational center"); + anchorObjectPivotRadio.set_group(anchorRadioGroup); + anchorObjectPivotRadio.signal_toggled().connect(sigc::mem_fun(*this, &PolarArrangeTab::on_anchor_radio_changed)); + pack_start(anchorObjectPivotRadio, false, false); + + arrangeOnLabel.set_text("Arrange on:"); + arrangeOnLabel.set_alignment(Gtk::ALIGN_START); + pack_start(arrangeOnLabel, false, false); + + arrangeOnCircleRadio.set_label("Last selected circle/ellipse/arc"); + arrangeRadioGroup = arrangeOnCircleRadio.get_group(); + arrangeOnCircleRadio.signal_toggled().connect(sigc::mem_fun(*this, &PolarArrangeTab::on_arrange_radio_changed)); + pack_start(arrangeOnCircleRadio, false, false); + + arrangeOnParametersRadio.set_label("Parameterized:"); + arrangeOnParametersRadio.set_group(arrangeRadioGroup); + arrangeOnParametersRadio.signal_toggled().connect(sigc::mem_fun(*this, &PolarArrangeTab::on_arrange_radio_changed)); + pack_start(arrangeOnParametersRadio, false, false); + + //FIXME: Objects in grid do not line up properly! + centerLabel.set_text("Center X/Y:"); + parametersTable.attach(centerLabel, 0, 1, 0, 1); + centerX.setDigits(2); + centerX.set_size_request(60, -1); + centerX.setIncrements(0.2, 0); + centerX.setRange(-10000, 10000); + centerX.setValue(0, "px"); + centerY.setDigits(2); + centerY.set_size_request(120, -1); + centerY.setIncrements(0.2, 0); + centerY.setRange(-10000, 10000); + centerY.setValue(0, "px"); + parametersTable.attach(centerX, 1, 2, 0, 1); + parametersTable.attach(centerY, 2, 3, 0, 1); + + radiusLabel.set_text("Radius X/Y:"); + parametersTable.attach(radiusLabel, 0, 1, 1, 2); + radiusX.setDigits(2); + radiusX.set_size_request(60, -1); + radiusX.setIncrements(0.2, 0); + radiusX.setRange(-10000, 10000); + radiusX.setValue(0, "px"); + radiusY.setDigits(2); + radiusY.set_size_request(120, -1); + radiusY.setIncrements(0.2, 0); + radiusY.setRange(-10000, 10000); + radiusY.setValue(0, "px"); + parametersTable.attach(radiusX, 1, 2, 1, 2); + parametersTable.attach(radiusY, 2, 3, 1, 2); + + angleLabel.set_text("Center X/Y:"); + parametersTable.attach(angleLabel, 0, 1, 2, 3); + angleX.setDigits(2); + angleX.set_size_request(60, -1); + angleX.setIncrements(0.2, 0); + angleX.setRange(-10000, 10000); + angleX.setValue(0, "°"); + angleY.setDigits(2); + angleY.set_size_request(120, -1); + angleY.setIncrements(0.2, 0); + angleY.setRange(-10000, 10000); + angleY.setValue(0, "°"); + parametersTable.attach(angleX, 1, 2, 2, 3); + parametersTable.attach(angleY, 2, 3, 2, 3); + pack_start(parametersTable, false, false); + + rotateObjectsCheckBox.set_label("Rotate objects"); + rotateObjectsCheckBox.set_active(true); + pack_start(rotateObjectsCheckBox, false, false); + + centerX.set_sensitive(false); + centerY.set_sensitive(false); + angleX.set_sensitive(false); + angleY.set_sensitive(false); + radiusX.set_sensitive(false); + radiusY.set_sensitive(false); +} + +void PolarArrangeTab::arrange() +{ + std::cout << "PolarArrangeTab::arrange()" << std::endl; + Inkscape::Selection *selection = sp_desktop_selection(parent->getDesktop()); + const GSList *items = selection->itemList(); + int i = 0; + while(items) + { + SPItem *item = SP_ITEM(items->data); + + float centerx = 1000; + float centery = 2000; + + float radiusx = 1000; + float radiusy = 2000; + + float objectx = - item->documentVisualBounds()->min()[Geom::X]; + float objecty = item->documentVisualBounds()->min()[Geom::Y]; + + float angle = M_PI / 36 * i; + + float r = (radiusx * radiusy) / + sqrtf(powf(radiusy * cos(angle), 2) + powf(radiusx * sin(angle), 2)); + float calcx = cos(angle) * r; + float calcy = sin(angle) * r; + + sp_item_move_rel(item, Geom::Translate(objectx + calcx, objecty + calcy)); + sp_item_rotate_rel(item, Geom::Rotate(angle)); + + //item->set_i2d_affine(item->i2dt_affine() * toOrigin * rotation); + //item->doWriteTransform(item->getRepr(), item->transform, NULL); + + items = items->next; + ++i; + } +} + +void PolarArrangeTab::updateSelection() +{ +} + +void PolarArrangeTab::on_arrange_radio_changed() +{ + bool arrangeParametric = !arrangeOnCircleRadio.get_active(); + + centerX.set_sensitive(arrangeParametric); + centerY.set_sensitive(arrangeParametric); + + angleX.set_sensitive(arrangeParametric); + angleY.set_sensitive(arrangeParametric); + + radiusX.set_sensitive(arrangeParametric); + radiusY.set_sensitive(arrangeParametric); +} + +void PolarArrangeTab::on_anchor_radio_changed() +{ + bool anchorBoundingBox = anchorBoundingBoxRadio.get_active(); + + anchorSelector.set_sensitive(anchorBoundingBox); +} + +} //namespace Dialog +} //namespace UI +} //namespace Inkscape + +/* + 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/polararrangetab.h b/src/ui/dialog/polararrangetab.h new file mode 100644 index 000000000..81b7de4d9 --- /dev/null +++ b/src/ui/dialog/polararrangetab.h @@ -0,0 +1,86 @@ +/** + * @brief Arranges Objects into a Circle/Ellipse + */ +/* Authors: + * Declara Denis + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#ifndef INKSCAPE_UI_DIALOG_POLAR_ARRANGE_TAB_H +#define INKSCAPE_UI_DIALOG_POLAR_ARRANGE_TAB_H + +#include + +#include "ui/dialog/arrangetab.h" + +#include "ui/widget/anchor-selector.h" +#include "ui/widget/scalar-unit.h" + +namespace Inkscape { +namespace UI { +namespace Dialog { + +class ArrangeDialog; + +class PolarArrangeTab : public ArrangeTab { +public: + PolarArrangeTab(ArrangeDialog *parent_); + virtual ~PolarArrangeTab() {}; + + /** + * Do the actual work + */ + virtual void arrange(); + + /** + * Respond to selection change + */ + void updateSelection(); + + void on_anchor_radio_changed(); + void on_arrange_radio_changed(); + +private: + PolarArrangeTab(PolarArrangeTab const &d); // no copy + void operator=(PolarArrangeTab const &d); // no assign + + ArrangeDialog *parent; + + Gtk::Label anchorPointLabel; + + Gtk::RadioButtonGroup anchorRadioGroup; + Gtk::RadioButton anchorBoundingBoxRadio; + Gtk::RadioButton anchorObjectPivotRadio; + AnchorSelector anchorSelector; + + Gtk::Label arrangeOnLabel; + + Gtk::RadioButtonGroup arrangeRadioGroup; + Gtk::RadioButton arrangeOnCircleRadio; + Gtk::RadioButton arrangeOnParametersRadio; + + Gtk::Table parametersTable; + + Gtk::Label centerLabel; + Inkscape::UI::Widget::ScalarUnit centerY; + Inkscape::UI::Widget::ScalarUnit centerX; + + Gtk::Label radiusLabel; + Inkscape::UI::Widget::ScalarUnit radiusY; + Inkscape::UI::Widget::ScalarUnit radiusX; + + Gtk::Label angleLabel; + Inkscape::UI::Widget::ScalarUnit angleY; + Inkscape::UI::Widget::ScalarUnit angleX; + + Gtk::CheckButton rotateObjectsCheckBox; + + +}; + +} //namespace Dialog +} //namespace UI +} //namespace Inkscape + +#endif /* INKSCAPE_UI_DIALOG_POLAR_ARRANGE_TAB_H */ diff --git a/src/ui/dialog/tile.cpp b/src/ui/dialog/tile.cpp index d4c597b84..879c9182f 100644 --- a/src/ui/dialog/tile.cpp +++ b/src/ui/dialog/tile.cpp @@ -6,112 +6,28 @@ * John Cliff * Other dudes from The Inkscape Organization * Abhishek Sharma + * Declara Denis * * Copyright (C) 2004 Bob Jamison * Copyright (C) 2004 John Cliff * * Released under GNU GPL, read the file 'COPYING' for more information */ -//#define DEBUG_GRID_ARRANGE 1 -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "tile.h" -#include //for GTK_RESPONSE* types #include -#include -#include <2geom/transforms.h> +#include "tile.h" #include "verbs.h" -#include "preferences.h" -#include "inkscape.h" -#include "desktop-handles.h" -#include "selection.h" -#include "document.h" -#include "document-undo.h" -#include "sp-item.h" -#include "widgets/icon.h" -#include "desktop.h" -#include "sp-item-transform.h" - -/* - * Sort items by their x co-ordinates, taking account of y (keeps rows intact) - * - * <0 *elem1 goes before *elem2 - * 0 *elem1 == *elem2 - * >0 *elem1 goes after *elem2 - */ -int sp_compare_x_position(SPItem *first, SPItem *second) -{ - using Geom::X; - using Geom::Y; - - Geom::OptRect a = first->documentVisualBounds(); - Geom::OptRect b = second->documentVisualBounds(); - - if ( !a || !b ) { - // FIXME? - return 0; - } - - double const a_height = a->dimensions()[Y]; - double const b_height = b->dimensions()[Y]; - - bool a_in_b_vert = false; - if ((a->min()[Y] < b->min()[Y] + 0.1) && (a->min()[Y] > b->min()[Y] - b_height)) { - a_in_b_vert = true; - } else if ((b->min()[Y] < a->min()[Y] + 0.1) && (b->min()[Y] > a->min()[Y] - a_height)) { - a_in_b_vert = true; - } else if (b->min()[Y] == a->min()[Y]) { - a_in_b_vert = true; - } else { - a_in_b_vert = false; - } - - if (!a_in_b_vert) { - return -1; - } - if (a_in_b_vert && a->min()[X] > b->min()[X]) { - return 1; - } - if (a_in_b_vert && a->min()[X] < b->min()[X]) { - return -1; - } - return 0; -} - -/* - * Sort items by their y co-ordinates. - */ -int -sp_compare_y_position(SPItem *first, SPItem *second) -{ - Geom::OptRect a = first->documentVisualBounds(); - Geom::OptRect b = second->documentVisualBounds(); - - if ( !a || !b ) { - // FIXME? - return 0; - } - if (a->min()[Geom::Y] > b->min()[Geom::Y]) { - return 1; - } - if (a->min()[Geom::Y] < b->min()[Geom::Y]) { - return -1; - } - - return 0; -} +#include "ui/dialog/gridarrangetab.h" +#include "ui/dialog/polararrangetab.h" namespace Inkscape { namespace UI { namespace Dialog { ArrangeDialog::ArrangeDialog() - : UI::Widget::Panel("", "/dialogs/gridtiler", SP_VERB_SELECTION_GRIDTILE), + : UI::Widget::Panel("", "/dialogs/gridtiler", SP_VERB_SELECTION_ARRANGE), _gridArrangeTab(new GridArrangeTab(this)), _polarArrangeTab(new PolarArrangeTab(this)) { @@ -142,826 +58,6 @@ void ArrangeDialog::_apply() } } -PolarArrangeTab::PolarArrangeTab(ArrangeDialog *parent_) - : parent(parent_), - parametersTable(3, 3, false), - centerY("", "Y coordinate of the center", UNIT_TYPE_LINEAR), - centerX("", "X coordinate of the center", centerY), - radiusY("", "Y coordinate of the radius", UNIT_TYPE_LINEAR), - radiusX("", "X coordinate of the radius", radiusY), - angleY("", "Starting angle", UNIT_TYPE_RADIAL), - angleX("", "End angle", angleY) -{ - anchorPointLabel.set_text("Anchor point:"); - anchorPointLabel.set_alignment(Gtk::ALIGN_START); - pack_start(anchorPointLabel, false, false); - - anchorBoundingBoxRadio.set_label("Object's bounding box:"); - anchorRadioGroup = anchorBoundingBoxRadio.get_group(); - anchorBoundingBoxRadio.signal_toggled().connect(sigc::mem_fun(*this, &PolarArrangeTab::on_anchor_radio_changed)); - pack_start(anchorBoundingBoxRadio, false, false); - - pack_start(anchorSelector, false, false); - - anchorObjectPivotRadio.set_label("Object's rotational center"); - anchorObjectPivotRadio.set_group(anchorRadioGroup); - anchorObjectPivotRadio.signal_toggled().connect(sigc::mem_fun(*this, &PolarArrangeTab::on_anchor_radio_changed)); - pack_start(anchorObjectPivotRadio, false, false); - - arrangeOnLabel.set_text("Arrange on:"); - arrangeOnLabel.set_alignment(Gtk::ALIGN_START); - pack_start(arrangeOnLabel, false, false); - - arrangeOnCircleRadio.set_label("Last selected circle/ellipse/arc"); - arrangeRadioGroup = arrangeOnCircleRadio.get_group(); - arrangeOnCircleRadio.signal_toggled().connect(sigc::mem_fun(*this, &PolarArrangeTab::on_arrange_radio_changed)); - pack_start(arrangeOnCircleRadio, false, false); - - arrangeOnParametersRadio.set_label("Parameterized:"); - arrangeOnParametersRadio.set_group(arrangeRadioGroup); - arrangeOnParametersRadio.signal_toggled().connect(sigc::mem_fun(*this, &PolarArrangeTab::on_arrange_radio_changed)); - pack_start(arrangeOnParametersRadio, false, false); - - //FIXME: Objects in grid do not line up properly! - centerLabel.set_text("Center X/Y:"); - parametersTable.attach(centerLabel, 0, 1, 0, 1); - centerX.setDigits(2); - centerX.set_size_request(60, -1); - centerX.setIncrements(0.2, 0); - centerX.setRange(-10000, 10000); - centerX.setValue(0, "px"); - centerY.setDigits(2); - centerY.set_size_request(120, -1); - centerY.setIncrements(0.2, 0); - centerY.setRange(-10000, 10000); - centerY.setValue(0, "px"); - parametersTable.attach(centerX, 1, 2, 0, 1); - parametersTable.attach(centerY, 2, 3, 0, 1); - - radiusLabel.set_text("Radius X/Y:"); - parametersTable.attach(radiusLabel, 0, 1, 1, 2); - radiusX.setDigits(2); - radiusX.set_size_request(60, -1); - radiusX.setIncrements(0.2, 0); - radiusX.setRange(-10000, 10000); - radiusX.setValue(0, "px"); - radiusY.setDigits(2); - radiusY.set_size_request(120, -1); - radiusY.setIncrements(0.2, 0); - radiusY.setRange(-10000, 10000); - radiusY.setValue(0, "px"); - parametersTable.attach(radiusX, 1, 2, 1, 2); - parametersTable.attach(radiusY, 2, 3, 1, 2); - - angleLabel.set_text("Center X/Y:"); - parametersTable.attach(angleLabel, 0, 1, 2, 3); - angleX.setDigits(2); - angleX.set_size_request(60, -1); - angleX.setIncrements(0.2, 0); - angleX.setRange(-10000, 10000); - angleX.setValue(0, "°"); - angleY.setDigits(2); - angleY.set_size_request(120, -1); - angleY.setIncrements(0.2, 0); - angleY.setRange(-10000, 10000); - angleY.setValue(0, "°"); - parametersTable.attach(angleX, 1, 2, 2, 3); - parametersTable.attach(angleY, 2, 3, 2, 3); - pack_start(parametersTable, false, false); - - rotateObjectsCheckBox.set_label("Rotate objects"); - rotateObjectsCheckBox.set_active(true); - pack_start(rotateObjectsCheckBox, false, false); - - centerX.set_sensitive(false); - centerY.set_sensitive(false); - angleX.set_sensitive(false); - angleY.set_sensitive(false); - radiusX.set_sensitive(false); - radiusY.set_sensitive(false); -} - -void PolarArrangeTab::arrange() -{ - std::cout << "PolarArrangeTab::arrange()" << std::endl; - Inkscape::Selection *selection = sp_desktop_selection(parent->getDesktop()); - const GSList *items = selection->itemList(); - int i = 0; - while(items) - { - SPItem *item = SP_ITEM(items->data); - - float centerx = 1000; - float centery = 2000; - - float radiusx = 1000; - float radiusy = 2000; - - float objectx = - item->documentVisualBounds()->min()[Geom::X]; - float objecty = item->documentVisualBounds()->min()[Geom::Y]; - - float angle = M_PI / 36 * i; - - float r = (radiusx * radiusy) / - sqrtf(powf(radiusy * cos(angle), 2) + powf(radiusx * sin(angle), 2)); - float calcx = cos(angle) * r; - float calcy = sin(angle) * r; - - sp_item_move_rel(item, Geom::Translate(objectx + calcx, objecty + calcy)); - sp_item_rotate_rel(item, Geom::Rotate(angle)); - - //item->set_i2d_affine(item->i2dt_affine() * toOrigin * rotation); - //item->doWriteTransform(item->getRepr(), item->transform, NULL); - - items = items->next; - ++i; - } -} - -void PolarArrangeTab::updateSelection() -{ -} - -void PolarArrangeTab::on_arrange_radio_changed() -{ - bool arrangeParametric = !arrangeOnCircleRadio.get_active(); - - centerX.set_sensitive(arrangeParametric); - centerY.set_sensitive(arrangeParametric); - - angleX.set_sensitive(arrangeParametric); - angleY.set_sensitive(arrangeParametric); - - radiusX.set_sensitive(arrangeParametric); - radiusY.set_sensitive(arrangeParametric); -} - -void PolarArrangeTab::on_anchor_radio_changed() -{ - bool anchorBoundingBox = anchorBoundingBoxRadio.get_active(); - - anchorSelector.set_sensitive(anchorBoundingBox); -} - - -//######################################################################### -//## E V E N T S -//######################################################################### - -/* - * - * This arranges the selection in a grid pattern. - * - */ - -void GridArrangeTab::arrange() -{ - - int cnt,row_cnt,col_cnt,a,row,col; - double grid_left,grid_top,col_width,row_height,paddingx,paddingy,width, height, new_x, new_y,cx,cy; - double total_col_width,total_row_height; - col_width = 0; - row_height = 0; - total_col_width=0; - total_row_height=0; - - // check for correct numbers in the row- and col-spinners - on_col_spinbutton_changed(); - on_row_spinbutton_changed(); - - // set padding to manual values - paddingx = XPadding.getValue("px"); - paddingy = YPadding.getValue("px"); - - std::vector row_heights; - std::vector col_widths; - std::vector row_ys; - std::vector col_xs; - - int NoOfCols = NoOfColsSpinner.get_value_as_int(); - int NoOfRows = NoOfRowsSpinner.get_value_as_int(); - - width = 0; - for (a=0;agetDesktop(); - sp_desktop_document(desktop)->ensureUpToDate(); - - Inkscape::Selection *selection = sp_desktop_selection (desktop); - const GSList *items = selection ? selection->itemList() : 0; - cnt=0; - for (; items != NULL; items = items->next) { - SPItem *item = SP_ITEM(items->data); - Geom::OptRect b = item->documentVisualBounds(); - if (!b) { - continue; - } - - width = b->dimensions()[Geom::X]; - height = b->dimensions()[Geom::Y]; - - cx = b->midpoint()[Geom::X]; - cy = b->midpoint()[Geom::Y]; - - if (b->min()[Geom::X] < grid_left) { - grid_left = b->min()[Geom::X]; - } - if (b->min()[Geom::Y] < grid_top) { - grid_top = b->min()[Geom::Y]; - } - if (width > col_width) { - col_width = width; - } - if (height > row_height) { - row_height = height; - } - } - - - // require the sorting done before we can calculate row heights etc. - - g_return_if_fail(selection); - const GSList *items2 = selection->itemList(); - GSList *rev = g_slist_copy((GSList *) items2); - GSList *sorted = NULL; - rev = g_slist_sort(rev, (GCompareFunc) sp_compare_y_position); - sorted = g_slist_sort(rev, (GCompareFunc) sp_compare_x_position); - - - // Calculate individual Row and Column sizes if necessary - - - cnt=0; - const GSList *sizes = sorted; - for (; sizes != NULL; sizes = sizes->next) { - SPItem *item = SP_ITEM(sizes->data); - Geom::OptRect b = item->documentVisualBounds(); - if (b) { - width = b->dimensions()[Geom::X]; - height = b->dimensions()[Geom::Y]; - if (width > col_widths[(cnt % NoOfCols)]) { - col_widths[(cnt % NoOfCols)] = width; - } - if (height > row_heights[(cnt / NoOfCols)]) { - row_heights[(cnt / NoOfCols)] = height; - } - } - - cnt++; - } - - - /// Make sure the top and left of the grid dont move by compensating for align values. - if (RowHeightButton.get_active()){ - grid_top = grid_top - (((row_height - row_heights[0]) / 2)*(VertAlign)); - } - if (ColumnWidthButton.get_active()){ - grid_left = grid_left - (((col_width - col_widths[0]) /2)*(HorizAlign)); - } - - #ifdef DEBUG_GRID_ARRANGE - g_print("\n cx = %f cy= %f gridleft=%f",cx,cy,grid_left); - #endif - - // Calculate total widths and heights, allowing for columns and rows non uniformly sized. - - if (ColumnWidthButton.get_active()){ - total_col_width = col_width * NoOfCols; - col_widths.clear(); - for (a=0;avisualBounds(); - // Fit to bbox, calculate padding between rows accordingly. - if ( sel_bbox && !SpaceManualRadioButton.get_active() ){ -#ifdef DEBUG_GRID_ARRANGE -g_print("\n row = %f col = %f selection x= %f selection y = %f", total_row_height,total_col_width, b.extent(Geom::X), b.extent(Geom::Y)); -#endif - paddingx = (sel_bbox->width() - total_col_width) / (NoOfCols -1); - paddingy = (sel_bbox->height() - total_row_height) / (NoOfRows -1); - } - -/* - Horizontal align - Left = 0 - Centre = 1 - Right = 2 - - Vertical align - Top = 0 - Middle = 1 - Bottom = 2 - - X position is calculated by taking the grids left co-ord, adding the distance to the column, - then adding 1/2 the spacing multiplied by the align variable above, - Y position likewise, takes the top of the grid, adds the y to the current row then adds the padding in to align it. - -*/ - - // Calculate row and column x and y coords required to allow for columns and rows which are non uniformly sized. - - for (a=0;adata); - sorted = sorted->next; - } - - for (; current_row != NULL; current_row = current_row->next) { - SPItem *item=SP_ITEM(current_row->data); - Inkscape::XML::Node *repr = item->getRepr(); - Geom::OptRect b = item->documentVisualBounds(); - Geom::Point min; - if (b) { - width = b->dimensions()[Geom::X]; - height = b->dimensions()[Geom::Y]; - min = b->min(); - } else { - width = height = 0; - min = Geom::Point(0, 0); - } - - row = cnt / NoOfCols; - col = cnt % NoOfCols; - - new_x = grid_left + (((col_widths[col] - width)/2)*HorizAlign) + col_xs[col]; - new_y = grid_top + (((row_heights[row] - height)/2)*VertAlign) + row_ys[row]; - - // signs are inverted between x and y due to y inversion - Geom::Point move = Geom::Point(new_x - min[Geom::X], min[Geom::Y] - new_y); - Geom::Affine const affine = Geom::Affine(Geom::Translate(move)); - item->set_i2d_affine(item->i2dt_affine() * affine); - item->doWriteTransform(repr, item->transform, NULL); - SP_OBJECT (current_row->data)->updateRepr(); - cnt +=1; - } - g_slist_free (current_row); - } - - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_SELECTION_GRIDTILE, - _("Arrange in a grid")); - -} - - -//######################################################################### -//## E V E N T S -//######################################################################### - -/** - * changed value in # of columns spinbox. - */ -void GridArrangeTab::on_row_spinbutton_changed() -{ - // quit if run by the attr_changed listener - if (updating) { - return; - } - - // in turn, prevent listener from responding - updating = true; - SPDesktop *desktop = Parent->getDesktop(); - - Inkscape::Selection *selection = desktop ? desktop->selection : 0; - g_return_if_fail( selection ); - - GSList const *items = selection->itemList(); - int selcount = g_slist_length((GSList *)items); - - double PerCol = ceil(selcount / NoOfColsSpinner.get_value()); - NoOfRowsSpinner.set_value(PerCol); - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setDouble("/dialogs/gridtiler/NoOfCols", NoOfColsSpinner.get_value()); - updating=false; -} - -/** - * changed value in # of rows spinbox. - */ -void GridArrangeTab::on_col_spinbutton_changed() -{ - // quit if run by the attr_changed listener - if (updating) { - return; - } - - // in turn, prevent listener from responding - updating = true; - SPDesktop *desktop = Parent->getDesktop(); - Inkscape::Selection *selection = desktop ? desktop->selection : 0; - g_return_if_fail(selection); - - GSList const *items = selection->itemList(); - int selcount = g_slist_length((GSList *)items); - - double PerRow = ceil(selcount / NoOfRowsSpinner.get_value()); - NoOfColsSpinner.set_value(PerRow); - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setDouble("/dialogs/gridtiler/NoOfCols", PerRow); - - updating=false; -} - -/** - * changed value in x padding spinbox. - */ -void GridArrangeTab::on_xpad_spinbutton_changed() -{ - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setDouble("/dialogs/gridtiler/XPad", XPadding.getValue("px")); - -} - -/** - * changed value in y padding spinbox. - */ -void GridArrangeTab::on_ypad_spinbutton_changed() -{ - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setDouble("/dialogs/gridtiler/YPad", YPadding.getValue("px")); -} - - -/** - * checked/unchecked autosize Rows button. - */ -void GridArrangeTab::on_RowSize_checkbutton_changed() -{ - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - if (RowHeightButton.get_active()) { - prefs->setDouble("/dialogs/gridtiler/AutoRowSize", 20); - } else { - prefs->setDouble("/dialogs/gridtiler/AutoRowSize", -20); - } - RowHeightBox.set_sensitive ( !RowHeightButton.get_active()); -} - -/** - * checked/unchecked autosize Rows button. - */ -void GridArrangeTab::on_ColSize_checkbutton_changed() -{ - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - if (ColumnWidthButton.get_active()) { - prefs->setDouble("/dialogs/gridtiler/AutoColSize", 20); - } else { - prefs->setDouble("/dialogs/gridtiler/AutoColSize", -20); - } - ColumnWidthBox.set_sensitive ( !ColumnWidthButton.get_active()); -} - -/** - * changed value in columns spinbox. - */ -void GridArrangeTab::on_rowSize_spinbutton_changed() -{ - // quit if run by the attr_changed listener - if (updating) { - return; - } - - // in turn, prevent listener from responding - updating = true; - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setDouble("/dialogs/gridtiler/RowHeight", RowHeightSpinner.get_value()); - updating=false; - -} - -/** - * changed value in rows spinbox. - */ -void GridArrangeTab::on_colSize_spinbutton_changed() -{ - // quit if run by the attr_changed listener - if (updating) { - return; - } - - // in turn, prevent listener from responding - updating = true; - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setDouble("/dialogs/gridtiler/ColWidth", ColumnWidthSpinner.get_value()); - updating=false; - -} - -/** - * changed Radio button in Spacing group. - */ -void GridArrangeTab::Spacing_button_changed() -{ - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - if (SpaceManualRadioButton.get_active()) { - prefs->setDouble("/dialogs/gridtiler/SpacingType", 20); - } else { - prefs->setDouble("/dialogs/gridtiler/SpacingType", -20); - } - - XPadding.set_sensitive ( SpaceManualRadioButton.get_active()); - YPadding.set_sensitive ( SpaceManualRadioButton.get_active()); -} - -/** - * changed Anchor selection widget. - */ -void GridArrangeTab::Align_changed() -{ - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - VertAlign = AlignmentSelector.getVerticalAlignment(); - prefs->setInt("/dialogs/gridtiler/VertAlign", VertAlign); - HorizAlign = AlignmentSelector.getHorizontalAlignment(); - prefs->setInt("/dialogs/gridtiler/HorizAlign", HorizAlign); -} - -/** - * Desktop selection changed - */ -void GridArrangeTab::updateSelection() -{ - // quit if run by the attr_changed listener - if (updating) { - return; - } - - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - // in turn, prevent listener from responding - updating = true; - SPDesktop *desktop = Parent->getDesktop(); - Inkscape::Selection *selection = desktop ? desktop->selection : 0; - GSList const *items = selection ? selection->itemList() : 0; - - if (items) { - int selcount = g_slist_length((GSList *)items); - - if (NoOfColsSpinner.get_value() > 1 && NoOfRowsSpinner.get_value() > 1){ - // Update the number of rows assuming number of columns wanted remains same. - double NoOfRows = ceil(selcount / NoOfColsSpinner.get_value()); - NoOfRowsSpinner.set_value(NoOfRows); - - // if the selection has less than the number set for one row, reduce it appropriately - if (selcount < NoOfColsSpinner.get_value()) { - double NoOfCols = ceil(selcount / NoOfRowsSpinner.get_value()); - NoOfColsSpinner.set_value(NoOfCols); - prefs->setInt("/dialogs/gridtiler/NoOfCols", NoOfCols); - } - } else { - double PerRow = ceil(sqrt(selcount)); - double PerCol = ceil(sqrt(selcount)); - NoOfRowsSpinner.set_value(PerRow); - NoOfColsSpinner.set_value(PerCol); - prefs->setInt("/dialogs/gridtiler/NoOfCols", static_cast(PerCol)); - } - } - - updating = false; -} - - - -/*########################## -## Experimental -##########################*/ - -static void updateSelectionCallback(Inkscape::Application */*inkscape*/, Inkscape::Selection */*selection*/, GridArrangeTab *dlg) -{ - dlg->updateSelection(); -} - - -//######################################################################### -//## C O N S T R U C T O R / D E S T R U C T O R -//######################################################################### -/** - * Constructor - */ -GridArrangeTab::GridArrangeTab(ArrangeDialog *parent) - : Parent(parent), - XPadding(_("X:"), _("Horizontal spacing between columns."), UNIT_TYPE_LINEAR, "", "object-columns"), - YPadding(_("Y:"), _("Vertical spacing between rows."), XPadding, "", "object-rows") -{ - // bool used by spin button callbacks to stop loops where they change each other. - updating = false; - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - - // could not do this in gtkmm - there's no Gtk::SizeGroup public constructor (!) - GtkSizeGroup *_col1 = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); - GtkSizeGroup *_col2 = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); - GtkSizeGroup *_col3 = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); - - { - // Selection Change signal - g_signal_connect ( G_OBJECT (INKSCAPE), "change_selection", G_CALLBACK (updateSelectionCallback), this); - } - - Gtk::Box *contents = this; - -#define MARGIN 2 - - //##Set up the panel - - SPDesktop *desktop = Parent->getDesktop(); - - Inkscape::Selection *selection = desktop ? desktop->selection : 0; - g_return_if_fail( selection ); - int selcount = 1; - if (!selection->isEmpty()) { - GSList const *items = selection->itemList(); - selcount = g_slist_length((GSList *)items); - } - - - /*#### Number of Rows ####*/ - - double PerRow = ceil(sqrt(selcount)); - double PerCol = ceil(sqrt(selcount)); - - #ifdef DEBUG_GRID_ARRANGE - g_print("/n PerRox = %f PerCol = %f selcount = %d",PerRow,PerCol,selcount); - #endif - - NoOfRowsLabel.set_text_with_mnemonic(_("_Rows:")); - NoOfRowsLabel.set_mnemonic_widget(NoOfRowsSpinner); - NoOfRowsBox.pack_start(NoOfRowsLabel, false, false, MARGIN); - - NoOfRowsSpinner.set_digits(0); - NoOfRowsSpinner.set_increments(1, 0); - NoOfRowsSpinner.set_range(1.0, 10000.0); - NoOfRowsSpinner.set_value(PerCol); - NoOfRowsSpinner.signal_changed().connect(sigc::mem_fun(*this, &GridArrangeTab::on_col_spinbutton_changed)); - NoOfRowsSpinner.set_tooltip_text(_("Number of rows")); - NoOfRowsBox.pack_start(NoOfRowsSpinner, false, false, MARGIN); - gtk_size_group_add_widget(_col1, (GtkWidget *) NoOfRowsBox.gobj()); - - RowHeightButton.set_label(_("Equal _height")); - RowHeightButton.set_use_underline(true); - double AutoRow = prefs->getDouble("/dialogs/gridtiler/AutoRowSize", 15); - if (AutoRow>0) - AutoRowSize=true; - else - AutoRowSize=false; - RowHeightButton.set_active(AutoRowSize); - - NoOfRowsBox.pack_start(RowHeightButton, false, false, MARGIN); - - RowHeightButton.set_tooltip_text(_("If not set, each row has the height of the tallest object in it")); - RowHeightButton.signal_toggled().connect(sigc::mem_fun(*this, &GridArrangeTab::on_RowSize_checkbutton_changed)); - - SpinsHBox.pack_start(NoOfRowsBox, false, false, MARGIN); - - - /*#### Label for X ####*/ - padXByYLabel.set_label(" "); - XByYLabelVBox.pack_start(padXByYLabel, false, false, MARGIN); - XByYLabel.set_markup(" × "); - XByYLabelVBox.pack_start(XByYLabel, false, false, MARGIN); - SpinsHBox.pack_start(XByYLabelVBox, false, false, MARGIN); - gtk_size_group_add_widget(_col2, (GtkWidget *) XByYLabelVBox.gobj()); - - /*#### Number of columns ####*/ - - NoOfColsLabel.set_text_with_mnemonic(_("_Columns:")); - NoOfColsLabel.set_mnemonic_widget(NoOfColsSpinner); - NoOfColsBox.pack_start(NoOfColsLabel, false, false, MARGIN); - - NoOfColsSpinner.set_digits(0); - NoOfColsSpinner.set_increments(1, 0); - NoOfColsSpinner.set_range(1.0, 10000.0); - NoOfColsSpinner.set_value(PerRow); - NoOfColsSpinner.signal_changed().connect(sigc::mem_fun(*this, &GridArrangeTab::on_row_spinbutton_changed)); - NoOfColsSpinner.set_tooltip_text(_("Number of columns")); - NoOfColsBox.pack_start(NoOfColsSpinner, false, false, MARGIN); - gtk_size_group_add_widget(_col3, (GtkWidget *) NoOfColsBox.gobj()); - - ColumnWidthButton.set_label(_("Equal _width")); - ColumnWidthButton.set_use_underline(true); - double AutoCol = prefs->getDouble("/dialogs/gridtiler/AutoColSize", 15); - if (AutoCol>0) - AutoColSize=true; - else - AutoColSize=false; - ColumnWidthButton.set_active(AutoColSize); - NoOfColsBox.pack_start(ColumnWidthButton, false, false, MARGIN); - - ColumnWidthButton.set_tooltip_text(_("If not set, each column has the width of the widest object in it")); - ColumnWidthButton.signal_toggled().connect(sigc::mem_fun(*this, &GridArrangeTab::on_ColSize_checkbutton_changed)); - - SpinsHBox.pack_start(NoOfColsBox, false, false, MARGIN); - - TileBox.pack_start(SpinsHBox, false, false, MARGIN); - - VertAlign = prefs->getInt("/dialogs/gridtiler/VertAlign", 1); - HorizAlign = prefs->getInt("/dialogs/gridtiler/HorizAlign", 1); - - // Anchor selection widget - AlignLabel.set_label("Alignment:"); - AlignLabel.set_alignment(Gtk::ALIGN_START, Gtk::ALIGN_CENTER); - AlignmentSelector.setAlignment(HorizAlign, VertAlign); - AlignmentSelector.on_selectionChanged().connect(sigc::mem_fun(*this, &GridArrangeTab::Align_changed)); - TileBox.pack_start(AlignLabel, false, false, MARGIN); - TileBox.pack_start(AlignmentSelector, true, false, MARGIN); - - { - /*#### Radio buttons to control spacing manually or to fit selection bbox ####*/ - SpaceByBBoxRadioButton.set_label(_("_Fit into selection box")); - SpaceByBBoxRadioButton.set_use_underline (true); - SpaceByBBoxRadioButton.signal_toggled().connect(sigc::mem_fun(*this, &GridArrangeTab::Spacing_button_changed)); - SpacingGroup = SpaceByBBoxRadioButton.get_group(); - - SpacingVBox.pack_start(SpaceByBBoxRadioButton, false, false, MARGIN); - - SpaceManualRadioButton.set_label(_("_Set spacing:")); - SpaceManualRadioButton.set_use_underline (true); - SpaceManualRadioButton.set_group(SpacingGroup); - SpaceManualRadioButton.signal_toggled().connect(sigc::mem_fun(*this, &GridArrangeTab::Spacing_button_changed)); - SpacingVBox.pack_start(SpaceManualRadioButton, false, false, MARGIN); - - TileBox.pack_start(SpacingVBox, false, false, MARGIN); - } - - { - /*#### Padding ####*/ - - YPadding.setDigits(5); - YPadding.setIncrements(0.2, 0); - YPadding.setRange(-10000, 10000); - double yPad = prefs->getDouble("/dialogs/gridtiler/YPad", 15); - YPadding.setValue(yPad, "px"); - YPadding.signal_value_changed().connect(sigc::mem_fun(*this, &GridArrangeTab::on_ypad_spinbutton_changed)); - - XPadding.setDigits(5); - XPadding.setIncrements(0.2, 0); - XPadding.setRange(-10000, 10000); - double xPad = prefs->getDouble("/dialogs/gridtiler/XPad", 15); - XPadding.setValue(xPad, "px"); - - XPadding.signal_value_changed().connect(sigc::mem_fun(*this, &GridArrangeTab::on_xpad_spinbutton_changed)); - } - TileBox.pack_start(XPadding, false, false, MARGIN); - TileBox.pack_start(YPadding, false, false, MARGIN); - - contents->pack_start(TileBox); - - double SpacingType = prefs->getDouble("/dialogs/gridtiler/SpacingType", 15); - if (SpacingType>0) { - ManualSpacing=true; - } else { - ManualSpacing=false; - } - SpaceManualRadioButton.set_active(ManualSpacing); - SpaceByBBoxRadioButton.set_active(!ManualSpacing); - XPadding.set_sensitive (ManualSpacing); - YPadding.set_sensitive (ManualSpacing); - - //## The OK button FIXME - /*TileOkButton = addResponseButton(C_("Rows and columns dialog","_Arrange"), GTK_RESPONSE_APPLY); - TileOkButton->set_use_underline(true); - TileOkButton->set_tooltip_text(_("Arrange selected objects"));*/ - - show_all_children(); -} - } //namespace Dialog } //namespace UI } //namespace Inkscape diff --git a/src/ui/dialog/tile.h b/src/ui/dialog/tile.h index b09416d04..d42dd7f65 100644 --- a/src/ui/dialog/tile.h +++ b/src/ui/dialog/tile.h @@ -5,6 +5,7 @@ * Bob Jamison ( based off trace dialog) * John Cliff * Other dudes from The Inkscape Organization + * Declara Denis * * Copyright (C) 2004 Bob Jamison * Copyright (C) 2004 John Cliff @@ -20,10 +21,7 @@ #include #include -#include "ui/widget/anchor-selector.h" #include "ui/widget/panel.h" -#include "ui/widget/spinbutton.h" -#include "ui/widget/scalar-unit.h" namespace Gtk { class Button; @@ -33,23 +31,7 @@ namespace Inkscape { namespace UI { namespace Dialog { -/** - * This interface should be implemented by each arrange mode. - * The class is a Gtk::VBox and will be displayed as a tab in - * the dialog - */ -class ArrangeTab : public Gtk::VBox -{ -public: - ArrangeTab() {}; - virtual ~ArrangeTab() {}; - - /** - * Do the actual work! - */ - virtual void arrange() = 0; -}; - +class ArrangeTab; class GridArrangeTab; class PolarArrangeTab; @@ -75,161 +57,6 @@ public: static ArrangeDialog& getInstance() { return *new ArrangeDialog(); } }; -/** - * Dialog for tiling an object - */ -class GridArrangeTab : public ArrangeTab { -public: - GridArrangeTab(ArrangeDialog *parent); - virtual ~GridArrangeTab() {}; - - /** - * Do the actual work - */ - virtual void arrange(); - - /** - * Respond to selection change - */ - void updateSelection(); - - // Callbacks from spinbuttons - void on_row_spinbutton_changed(); - void on_col_spinbutton_changed(); - void on_xpad_spinbutton_changed(); - void on_ypad_spinbutton_changed(); - void on_RowSize_checkbutton_changed(); - void on_ColSize_checkbutton_changed(); - void on_rowSize_spinbutton_changed(); - void on_colSize_spinbutton_changed(); - void Spacing_button_changed(); - void Align_changed(); - - -private: - GridArrangeTab(GridArrangeTab const &d); // no copy - void operator=(GridArrangeTab const &d); // no assign - - ArrangeDialog *Parent; - - bool userHidden; - bool updating; - - Gtk::VBox TileBox; - Gtk::Button *TileOkButton; - Gtk::Button *TileCancelButton; - - // Number selected label - Gtk::Label SelectionContentsLabel; - - - Gtk::HBox AlignHBox; - Gtk::HBox SpinsHBox; - - // Number per Row - Gtk::VBox NoOfColsBox; - Gtk::Label NoOfColsLabel; - Inkscape::UI::Widget::SpinButton NoOfColsSpinner; - bool AutoRowSize; - Gtk::CheckButton RowHeightButton; - - Gtk::VBox XByYLabelVBox; - Gtk::Label padXByYLabel; - Gtk::Label XByYLabel; - - // Number per Column - Gtk::VBox NoOfRowsBox; - Gtk::Label NoOfRowsLabel; - Inkscape::UI::Widget::SpinButton NoOfRowsSpinner; - bool AutoColSize; - Gtk::CheckButton ColumnWidthButton; - - // Alignment - Gtk::Label AlignLabel; - AnchorSelector AlignmentSelector; - double VertAlign; - double HorizAlign; - - Inkscape::UI::Widget::ScalarUnit XPadding; - Inkscape::UI::Widget::ScalarUnit YPadding; - - // BBox or manual spacing - Gtk::VBox SpacingVBox; - Gtk::RadioButtonGroup SpacingGroup; - Gtk::RadioButton SpaceByBBoxRadioButton; - Gtk::RadioButton SpaceManualRadioButton; - bool ManualSpacing; - - // Row height - Gtk::VBox RowHeightVBox; - Gtk::HBox RowHeightBox; - Gtk::Label RowHeightLabel; - Inkscape::UI::Widget::SpinButton RowHeightSpinner; - - // Column width - Gtk::VBox ColumnWidthVBox; - Gtk::HBox ColumnWidthBox; - Gtk::Label ColumnWidthLabel; - Inkscape::UI::Widget::SpinButton ColumnWidthSpinner; -}; - -class PolarArrangeTab : public ArrangeTab { -public: - PolarArrangeTab(ArrangeDialog *parent_); - virtual ~PolarArrangeTab() {}; - - /** - * Do the actual work - */ - virtual void arrange(); - - /** - * Respond to selection change - */ - void updateSelection(); - - void on_anchor_radio_changed(); - void on_arrange_radio_changed(); - -private: - PolarArrangeTab(PolarArrangeTab const &d); // no copy - void operator=(PolarArrangeTab const &d); // no assign - - ArrangeDialog *parent; - - Gtk::Label anchorPointLabel; - - Gtk::RadioButtonGroup anchorRadioGroup; - Gtk::RadioButton anchorBoundingBoxRadio; - Gtk::RadioButton anchorObjectPivotRadio; - AnchorSelector anchorSelector; - - Gtk::Label arrangeOnLabel; - - Gtk::RadioButtonGroup arrangeRadioGroup; - Gtk::RadioButton arrangeOnCircleRadio; - Gtk::RadioButton arrangeOnParametersRadio; - - Gtk::Table parametersTable; - - Gtk::Label centerLabel; - Inkscape::UI::Widget::ScalarUnit centerY; - Inkscape::UI::Widget::ScalarUnit centerX; - - Gtk::Label radiusLabel; - Inkscape::UI::Widget::ScalarUnit radiusY; - Inkscape::UI::Widget::ScalarUnit radiusX; - - Gtk::Label angleLabel; - Inkscape::UI::Widget::ScalarUnit angleY; - Inkscape::UI::Widget::ScalarUnit angleX; - - Gtk::CheckButton rotateObjectsCheckBox; - - -}; - - } //namespace Dialog } //namespace UI } //namespace Inkscape -- cgit v1.2.3 From 06b0c9af0d579d4c9005bc8acf456288d7bea196 Mon Sep 17 00:00:00 2001 From: Denis Declara Date: Sat, 28 Apr 2012 18:17:05 +0200 Subject: Changed Makefile plus some minor tab vs. spaces fixes (bzr r11073.1.22) --- src/ui/dialog/Makefile_insert | 5 +++++ src/ui/dialog/gridarrangetab.h | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'src/ui') diff --git a/src/ui/dialog/Makefile_insert b/src/ui/dialog/Makefile_insert index f8b95247a..34cceae54 100644 --- a/src/ui/dialog/Makefile_insert +++ b/src/ui/dialog/Makefile_insert @@ -5,6 +5,7 @@ ink_common_sources += \ ui/dialog/aboutbox.h \ ui/dialog/align-and-distribute.cpp \ ui/dialog/align-and-distribute.h \ + ui/dialog/arrangetab.h \ ui/dialog/behavior.h \ ui/dialog/calligraphic-profile-rename.h \ ui/dialog/calligraphic-profile-rename.cpp \ @@ -48,6 +49,8 @@ ink_common_sources += \ ui/dialog/floating-behavior.h \ ui/dialog/glyphs.cpp \ ui/dialog/glyphs.h \ + ui/dialog/gridarrangetab.h \ + ui/dialog/gridarrangetab.cpp \ ui/dialog/guides.cpp \ ui/dialog/guides.h \ ui/dialog/icon-preview.cpp \ @@ -75,6 +78,8 @@ ink_common_sources += \ ui/dialog/object-properties.cpp \ ui/dialog/object-properties.h \ ui/dialog/panel-dialog.h \ + ui/dialog/polararrangetab.cpp \ + ui/dialog/polararrangetab.h \ ui/dialog/print.cpp \ ui/dialog/print.h \ ui/dialog/print-colors-preview-dialog.cpp \ diff --git a/src/ui/dialog/gridarrangetab.h b/src/ui/dialog/gridarrangetab.h index bc82258b8..16780e55f 100644 --- a/src/ui/dialog/gridarrangetab.h +++ b/src/ui/dialog/gridarrangetab.h @@ -36,7 +36,7 @@ class ArrangeDialog; */ class GridArrangeTab : public ArrangeTab { public: - GridArrangeTab(ArrangeDialog *parent); + GridArrangeTab(ArrangeDialog *parent); virtual ~GridArrangeTab() {}; /** -- cgit v1.2.3 From d1cc21d52c7800015a3713603cc0eb0ade15549d Mon Sep 17 00:00:00 2001 From: Denis Declara Date: Tue, 1 May 2012 14:16:34 +0200 Subject: Added translation support code (_(), C_()) to the polar arrange tab. (bzr r11073.1.23) --- src/ui/dialog/polararrangetab.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'src/ui') diff --git a/src/ui/dialog/polararrangetab.cpp b/src/ui/dialog/polararrangetab.cpp index d36a78759..26a163b1c 100644 --- a/src/ui/dialog/polararrangetab.cpp +++ b/src/ui/dialog/polararrangetab.cpp @@ -39,38 +39,38 @@ PolarArrangeTab::PolarArrangeTab(ArrangeDialog *parent_) angleY("", "Starting angle", UNIT_TYPE_RADIAL), angleX("", "End angle", angleY) { - anchorPointLabel.set_text("Anchor point:"); + anchorPointLabel.set_text(C_("Polar arrange tab", "Anchor point:")); anchorPointLabel.set_alignment(Gtk::ALIGN_START); pack_start(anchorPointLabel, false, false); - anchorBoundingBoxRadio.set_label("Object's bounding box:"); + anchorBoundingBoxRadio.set_label(C_("Polar arrange tab", "Object's bounding box:")); anchorRadioGroup = anchorBoundingBoxRadio.get_group(); anchorBoundingBoxRadio.signal_toggled().connect(sigc::mem_fun(*this, &PolarArrangeTab::on_anchor_radio_changed)); pack_start(anchorBoundingBoxRadio, false, false); pack_start(anchorSelector, false, false); - anchorObjectPivotRadio.set_label("Object's rotational center"); + anchorObjectPivotRadio.set_label(C_("Polar arrange tab", "Object's rotational center")); anchorObjectPivotRadio.set_group(anchorRadioGroup); anchorObjectPivotRadio.signal_toggled().connect(sigc::mem_fun(*this, &PolarArrangeTab::on_anchor_radio_changed)); pack_start(anchorObjectPivotRadio, false, false); - arrangeOnLabel.set_text("Arrange on:"); + arrangeOnLabel.set_text(C_("Polar arrange tab", "Arrange on:")); arrangeOnLabel.set_alignment(Gtk::ALIGN_START); pack_start(arrangeOnLabel, false, false); - arrangeOnCircleRadio.set_label("Last selected circle/ellipse/arc"); + arrangeOnCircleRadio.set_label(C_("Polar arrange tab", "Last selected circle/ellipse/arc")); arrangeRadioGroup = arrangeOnCircleRadio.get_group(); arrangeOnCircleRadio.signal_toggled().connect(sigc::mem_fun(*this, &PolarArrangeTab::on_arrange_radio_changed)); pack_start(arrangeOnCircleRadio, false, false); - arrangeOnParametersRadio.set_label("Parameterized:"); + arrangeOnParametersRadio.set_label(C_("Polar arrange tab", "Parameterized:")); arrangeOnParametersRadio.set_group(arrangeRadioGroup); arrangeOnParametersRadio.signal_toggled().connect(sigc::mem_fun(*this, &PolarArrangeTab::on_arrange_radio_changed)); pack_start(arrangeOnParametersRadio, false, false); //FIXME: Objects in grid do not line up properly! - centerLabel.set_text("Center X/Y:"); + centerLabel.set_text(_("Center X/Y:")); parametersTable.attach(centerLabel, 0, 1, 0, 1); centerX.setDigits(2); centerX.set_size_request(60, -1); @@ -85,7 +85,7 @@ PolarArrangeTab::PolarArrangeTab(ArrangeDialog *parent_) parametersTable.attach(centerX, 1, 2, 0, 1); parametersTable.attach(centerY, 2, 3, 0, 1); - radiusLabel.set_text("Radius X/Y:"); + radiusLabel.set_text(_("Radius X/Y:")); parametersTable.attach(radiusLabel, 0, 1, 1, 2); radiusX.setDigits(2); radiusX.set_size_request(60, -1); @@ -100,7 +100,7 @@ PolarArrangeTab::PolarArrangeTab(ArrangeDialog *parent_) parametersTable.attach(radiusX, 1, 2, 1, 2); parametersTable.attach(radiusY, 2, 3, 1, 2); - angleLabel.set_text("Center X/Y:"); + angleLabel.set_text(_("Center X/Y:")); parametersTable.attach(angleLabel, 0, 1, 2, 3); angleX.setDigits(2); angleX.set_size_request(60, -1); @@ -116,7 +116,7 @@ PolarArrangeTab::PolarArrangeTab(ArrangeDialog *parent_) parametersTable.attach(angleY, 2, 3, 2, 3); pack_start(parametersTable, false, false); - rotateObjectsCheckBox.set_label("Rotate objects"); + rotateObjectsCheckBox.set_label(_("Rotate objects")); rotateObjectsCheckBox.set_active(true); pack_start(rotateObjectsCheckBox, false, false); -- cgit v1.2.3 From d5ff00bb49276d55c53060770d7e79e4950b3906 Mon Sep 17 00:00:00 2001 From: Denis Declara Date: Tue, 1 May 2012 16:46:32 +0200 Subject: Got parametrized arrangement to work (bzr r11073.1.25) --- src/ui/dialog/polararrangetab.cpp | 198 ++++++++++++++++++++++++++++++-------- 1 file changed, 156 insertions(+), 42 deletions(-) (limited to 'src/ui') diff --git a/src/ui/dialog/polararrangetab.cpp b/src/ui/dialog/polararrangetab.cpp index 26a163b1c..faad5493b 100644 --- a/src/ui/dialog/polararrangetab.cpp +++ b/src/ui/dialog/polararrangetab.cpp @@ -71,49 +71,49 @@ PolarArrangeTab::PolarArrangeTab(ArrangeDialog *parent_) //FIXME: Objects in grid do not line up properly! centerLabel.set_text(_("Center X/Y:")); - parametersTable.attach(centerLabel, 0, 1, 0, 1); + parametersTable.attach(centerLabel, 0, 1, 0, 1, Gtk::FILL); centerX.setDigits(2); - centerX.set_size_request(60, -1); + //centerX.set_size_request(60, -1); centerX.setIncrements(0.2, 0); centerX.setRange(-10000, 10000); centerX.setValue(0, "px"); centerY.setDigits(2); - centerY.set_size_request(120, -1); + //centerY.set_size_request(120, -1); centerY.setIncrements(0.2, 0); centerY.setRange(-10000, 10000); centerY.setValue(0, "px"); - parametersTable.attach(centerX, 1, 2, 0, 1); - parametersTable.attach(centerY, 2, 3, 0, 1); + parametersTable.attach(centerX, 1, 2, 0, 1, Gtk::FILL); + parametersTable.attach(centerY, 2, 3, 0, 1, Gtk::FILL); radiusLabel.set_text(_("Radius X/Y:")); - parametersTable.attach(radiusLabel, 0, 1, 1, 2); + parametersTable.attach(radiusLabel, 0, 1, 1, 2, Gtk::FILL); radiusX.setDigits(2); - radiusX.set_size_request(60, -1); + //radiusX.set_size_request(60, -1); radiusX.setIncrements(0.2, 0); - radiusX.setRange(-10000, 10000); - radiusX.setValue(0, "px"); + radiusX.setRange(0.001, 10000); + radiusX.setValue(100, "px"); radiusY.setDigits(2); - radiusY.set_size_request(120, -1); + //radiusY.set_size_request(120, -1); radiusY.setIncrements(0.2, 0); - radiusY.setRange(-10000, 10000); - radiusY.setValue(0, "px"); - parametersTable.attach(radiusX, 1, 2, 1, 2); - parametersTable.attach(radiusY, 2, 3, 1, 2); + radiusY.setRange(0.001, 10000); + radiusY.setValue(100, "px"); + parametersTable.attach(radiusX, 1, 2, 1, 2, Gtk::FILL); + parametersTable.attach(radiusY, 2, 3, 1, 2, Gtk::FILL); - angleLabel.set_text(_("Center X/Y:")); - parametersTable.attach(angleLabel, 0, 1, 2, 3); + angleLabel.set_text(_("Angle X/Y:")); + parametersTable.attach(angleLabel, 0, 1, 2, 3, Gtk::FILL); angleX.setDigits(2); - angleX.set_size_request(60, -1); + //angleX.set_size_request(60, -1); angleX.setIncrements(0.2, 0); angleX.setRange(-10000, 10000); angleX.setValue(0, "°"); angleY.setDigits(2); - angleY.set_size_request(120, -1); + //angleY.set_size_request(120, -1); angleY.setIncrements(0.2, 0); angleY.setRange(-10000, 10000); - angleY.setValue(0, "°"); - parametersTable.attach(angleX, 1, 2, 2, 3); - parametersTable.attach(angleY, 2, 3, 2, 3); + angleY.setValue(180, "°"); + parametersTable.attach(angleX, 1, 2, 2, 3, Gtk::FILL); + parametersTable.attach(angleY, 2, 3, 2, 3, Gtk::FILL); pack_start(parametersTable, false, false); rotateObjectsCheckBox.set_label(_("Rotate objects")); @@ -128,39 +128,153 @@ PolarArrangeTab::PolarArrangeTab(ArrangeDialog *parent_) radiusY.set_sensitive(false); } +void rotateAround(SPItem *item, Geom::Point center, Geom::Rotate const &rotation) +{ + Geom::Translate const s(center); + Geom::Affine affine = Geom::Affine(s).inverse() * Geom::Affine(rotation) * Geom::Affine(s); + + // Save old center + center = item->getCenter(); + + item->set_i2d_affine(item->i2dt_affine() * affine); + item->doWriteTransform(item->getRepr(), item->transform); + + if(item->isCenterSet()) + { + item->setCenter(center * affine); + item->updateRepr(); + } +} + +float calcAngle(float arcBegin, float arcEnd, int count, int n) +{ + float arcLength = arcEnd - arcBegin; + if(abs(abs(arcLength) - 2*M_PI) > 0.0001) count--; // If not a complete circle, put an object also at the extremes of the arc; + + float angle = n / (float)count; + // Normalize for arcLength: + angle = angle * arcLength; + angle += arcBegin; + + return angle; +} + +Geom::Point calcPoint(float cx, float cy, float rx, float ry, float angle) +{ + // Parameters for radius equation + float a = ry * cos(angle); + float b = rx * sin(angle); + + float radius = (rx * ry) / sqrtf((a*a) + (b*b)); + + return Geom::Point(cos(angle) * radius + cx, sin(angle) * radius + cy); +} + +Geom::Point getAnchorPoint(int anchor, SPItem *item) +{ + Geom::Point source; + + Geom::OptRect bbox = item->documentVisualBounds(); + + switch(anchor) + { + case 0: // Top - Left + case 3: // Middle - Left + case 6: // Bottom - Left + source[0] = bbox->min()[Geom::X]; + break; + case 1: // Top - Middle + case 4: // Middle - Middle + case 7: // Bottom - Middle + source[0] = (bbox->min()[Geom::X] + bbox->max()[Geom::X]) / 2.0f; + break; + case 2: // Top - Right + case 5: // Middle - Right + case 8: // Bottom - Right + source[0] = bbox->max()[Geom::X]; + break; + }; + + switch(anchor) + { + case 0: // Top - Left + case 1: // Top - Middle + case 2: // Top - Right + source[1] = bbox->min()[Geom::Y]; + break; + case 3: // Middle - Left + case 4: // Middle - Middle + case 5: // Middle - Right + source[1] = (bbox->min()[Geom::Y] + bbox->max()[Geom::Y]) / 2.0f; + break; + case 6: // Bottom - Left + case 7: // Bottom - Middle + case 8: // Bottom - Right + source[1] = bbox->max()[Geom::Y]; + break; + }; + + // If using center + if(anchor == 9) + source = item->getCenter(); + else + { + source[1] -= item->document->getHeight(); + source[1] *= -1; + } + + return source; +} + +void moveToPoint(int anchor, SPItem *item, Geom::Point p) +{ + sp_item_move_rel(item, Geom::Translate(p - getAnchorPoint(anchor, item))); +} + void PolarArrangeTab::arrange() { std::cout << "PolarArrangeTab::arrange()" << std::endl; Inkscape::Selection *selection = sp_desktop_selection(parent->getDesktop()); - const GSList *items = selection->itemList(); - int i = 0; - while(items) - { - SPItem *item = SP_ITEM(items->data); + const GSList *items, *tmp; + tmp = items = selection->itemList(); - float centerx = 1000; - float centery = 2000; + int count = 0; + while(tmp) + { + tmp = tmp->next; + ++count; + } - float radiusx = 1000; - float radiusy = 2000; + // Read options from UI + float cx = centerX.getValue("px"); + float cy = centerY.getValue("px"); + float rx = radiusX.getValue("px"); + float ry = radiusY.getValue("px"); + float arcBeg = angleX.getValue("rad"); + float arcEnd = angleY.getValue("rad"); - float objectx = - item->documentVisualBounds()->min()[Geom::X]; - float objecty = item->documentVisualBounds()->min()[Geom::Y]; + int anchor = 9; + if(anchorBoundingBoxRadio.get_active()) + { + anchor = anchorSelector.getHorizontalAlignment() + + anchorSelector.getVerticalAlignment() * 3; + } - float angle = M_PI / 36 * i; + tmp = items; + int i = 0; + while(tmp) + { + SPItem *item = SP_ITEM(tmp->data); - float r = (radiusx * radiusy) / - sqrtf(powf(radiusy * cos(angle), 2) + powf(radiusx * sin(angle), 2)); - float calcx = cos(angle) * r; - float calcy = sin(angle) * r; + float angle = calcAngle(arcBeg, arcEnd, count, i); + Geom::Point newLocation = calcPoint(cx, cy, rx, ry, angle); - sp_item_move_rel(item, Geom::Translate(objectx + calcx, objecty + calcy)); - sp_item_rotate_rel(item, Geom::Rotate(angle)); + moveToPoint(anchor, item, newLocation); - //item->set_i2d_affine(item->i2dt_affine() * toOrigin * rotation); - //item->doWriteTransform(item->getRepr(), item->transform, NULL); + if(rotateObjectsCheckBox.get_active()) + rotateAround(item, newLocation, Geom::Rotate(angle)); - items = items->next; + tmp = tmp->next; ++i; } } -- cgit v1.2.3 From ad72a653c9ae867201bb36fc41a4e8eb2459d0d5 Mon Sep 17 00:00:00 2001 From: Denis Declara Date: Tue, 1 May 2012 17:19:13 +0200 Subject: Added undo support for polar arrangement as well as some minor fixes (bzr r11073.1.26) --- src/ui/dialog/polararrangetab.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/ui') diff --git a/src/ui/dialog/polararrangetab.cpp b/src/ui/dialog/polararrangetab.cpp index faad5493b..afb2ce680 100644 --- a/src/ui/dialog/polararrangetab.cpp +++ b/src/ui/dialog/polararrangetab.cpp @@ -149,7 +149,8 @@ void rotateAround(SPItem *item, Geom::Point center, Geom::Rotate const &rotation float calcAngle(float arcBegin, float arcEnd, int count, int n) { float arcLength = arcEnd - arcBegin; - if(abs(abs(arcLength) - 2*M_PI) > 0.0001) count--; // If not a complete circle, put an object also at the extremes of the arc; + float delta = std::abs(std::abs(arcLength) - 2*M_PI); + if(delta > 0.01) count--; // If not a complete circle, put an object also at the extremes of the arc; float angle = n / (float)count; // Normalize for arcLength: @@ -277,6 +278,9 @@ void PolarArrangeTab::arrange() tmp = tmp->next; ++i; } + + DocumentUndo::done(sp_desktop_document(parent->getDesktop()), SP_VERB_SELECTION_ARRANGE, + _("Arrange on ellipse")); } void PolarArrangeTab::updateSelection() -- cgit v1.2.3 From eb9d9b2480d4549f7887b1dc2a75339062f78895 Mon Sep 17 00:00:00 2001 From: Denis Declara Date: Thu, 3 May 2012 16:36:41 +0200 Subject: Now also the "Arrange on last selected circle" option of the polar arrangement works. (bzr r11073.1.27) --- src/ui/dialog/polararrangetab.cpp | 92 +++++++++++++++++++++++++++++++++------ 1 file changed, 79 insertions(+), 13 deletions(-) (limited to 'src/ui') diff --git a/src/ui/dialog/polararrangetab.cpp b/src/ui/dialog/polararrangetab.cpp index afb2ce680..ce78e43a4 100644 --- a/src/ui/dialog/polararrangetab.cpp +++ b/src/ui/dialog/polararrangetab.cpp @@ -23,6 +23,7 @@ #include "sp-item.h" #include "widgets/icon.h" #include "desktop.h" +#include "sp-ellipse.h" #include "sp-item-transform.h" namespace Inkscape { @@ -128,6 +129,12 @@ PolarArrangeTab::PolarArrangeTab(ArrangeDialog *parent_) radiusY.set_sensitive(false); } +/** + * This function rotates an item around a given point by a given amount + * @param item item to rotate + * @param center center of the rotation to perform + * @param rotation amount to rotate the object by + */ void rotateAround(SPItem *item, Geom::Point center, Geom::Rotate const &rotation) { Geom::Translate const s(center); @@ -146,6 +153,15 @@ void rotateAround(SPItem *item, Geom::Point center, Geom::Rotate const &rotation } } +/** + * Calculates the angle at which to put an object given the total amount + * of objects, the index of the objects as well as the arc start and end + * points + * @param arcBegin angle at which the arc begins + * @param arcEnd angle at which the arc ends + * @param count number of objects in the selection + * @param n index of the object in the selection + */ float calcAngle(float arcBegin, float arcEnd, int count, int n) { float arcLength = arcEnd - arcBegin; @@ -160,6 +176,10 @@ float calcAngle(float arcBegin, float arcEnd, int count, int n) return angle; } +/** + * Calculates the point at which the object needs to be, given the center of the ellipse, + * it's radius (x and y), as well as the angle + */ Geom::Point calcPoint(float cx, float cy, float rx, float ry, float angle) { // Parameters for radius equation @@ -220,6 +240,7 @@ Geom::Point getAnchorPoint(int anchor, SPItem *item) source = item->getCenter(); else { + // FIXME: source[1] -= item->document->getHeight(); source[1] *= -1; } @@ -235,24 +256,64 @@ void moveToPoint(int anchor, SPItem *item, Geom::Point p) void PolarArrangeTab::arrange() { std::cout << "PolarArrangeTab::arrange()" << std::endl; + Inkscape::Selection *selection = sp_desktop_selection(parent->getDesktop()); const GSList *items, *tmp; tmp = items = selection->itemList(); + SPGenericEllipse *referenceEllipse = NULL; // Last ellipse in selection int count = 0; while(tmp) { + SPItem *item = SP_ITEM(tmp->data); + + // The last selected ellipse is actually the first in list + if(SP_IS_GENERICELLIPSE(item) && referenceEllipse == NULL) + referenceEllipse = SP_GENERICELLIPSE(item); + tmp = tmp->next; ++count; } - // Read options from UI - float cx = centerX.getValue("px"); - float cy = centerY.getValue("px"); - float rx = radiusX.getValue("px"); - float ry = radiusY.getValue("px"); - float arcBeg = angleX.getValue("rad"); - float arcEnd = angleY.getValue("rad"); + float cx, cy; // Center of the ellipse + float rx, ry; // Radiuses of the ellipse in x and y direction + float arcBeg, arcEnd; // begin and end angles for arcs + Geom::Affine transformation; // Any additional transformation to apply to the objects + + if(arrangeOnCircleRadio.get_active()) + { + if(referenceEllipse == NULL) + { + Gtk::MessageDialog dialog(_("Couldn't find an ellipse in selection"), false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_CLOSE, true); + dialog.run(); + return; + } else { + cx = referenceEllipse->cx.value; + cy = referenceEllipse->cy.value; + rx = referenceEllipse->rx.value; + ry = referenceEllipse->ry.value; + arcBeg = referenceEllipse->start; + arcEnd = referenceEllipse->end; + transformation = referenceEllipse->i2dt_affine(); + + // We decrement the count by 1 as we are not going to lay + // out the reference ellipse + --count; + } + + } else { + // Read options from UI + cx = centerX.getValue("px"); + cy = centerY.getValue("px"); + rx = radiusX.getValue("px"); + ry = radiusY.getValue("px"); + arcBeg = angleX.getValue("rad"); + arcEnd = angleY.getValue("rad"); + transformation.setIdentity(); + referenceEllipse = NULL; + } + + int anchor = 9; if(anchorBoundingBoxRadio.get_active()) @@ -267,16 +328,21 @@ void PolarArrangeTab::arrange() { SPItem *item = SP_ITEM(tmp->data); - float angle = calcAngle(arcBeg, arcEnd, count, i); - Geom::Point newLocation = calcPoint(cx, cy, rx, ry, angle); + // Ignore the reference ellipse if any + if(item != referenceEllipse) + { + float angle = calcAngle(arcBeg, arcEnd, count, i); + Geom::Point newLocation = calcPoint(cx, cy, rx, ry, angle) * transformation; + + moveToPoint(anchor, item, newLocation); - moveToPoint(anchor, item, newLocation); + if(rotateObjectsCheckBox.get_active()) + rotateAround(item, newLocation, Geom::Rotate(angle)); - if(rotateObjectsCheckBox.get_active()) - rotateAround(item, newLocation, Geom::Rotate(angle)); + ++i; + } tmp = tmp->next; - ++i; } DocumentUndo::done(sp_desktop_document(parent->getDesktop()), SP_VERB_SELECTION_ARRANGE, -- cgit v1.2.3 From 822480f5f68d7a1cd6aea9f4031f98b33980215e Mon Sep 17 00:00:00 2001 From: Denis Declara Date: Sat, 5 May 2012 15:31:09 +0200 Subject: Fixed some math, so that the objects now line up correctly (bzr r11073.1.28) --- src/ui/dialog/polararrangetab.cpp | 70 ++++++++++++++++++++++++++------------- src/ui/dialog/polararrangetab.h | 3 +- 2 files changed, 49 insertions(+), 24 deletions(-) (limited to 'src/ui') diff --git a/src/ui/dialog/polararrangetab.cpp b/src/ui/dialog/polararrangetab.cpp index ce78e43a4..6968be35a 100644 --- a/src/ui/dialog/polararrangetab.cpp +++ b/src/ui/dialog/polararrangetab.cpp @@ -60,10 +60,15 @@ PolarArrangeTab::PolarArrangeTab(ArrangeDialog *parent_) arrangeOnLabel.set_alignment(Gtk::ALIGN_START); pack_start(arrangeOnLabel, false, false); - arrangeOnCircleRadio.set_label(C_("Polar arrange tab", "Last selected circle/ellipse/arc")); - arrangeRadioGroup = arrangeOnCircleRadio.get_group(); - arrangeOnCircleRadio.signal_toggled().connect(sigc::mem_fun(*this, &PolarArrangeTab::on_arrange_radio_changed)); - pack_start(arrangeOnCircleRadio, false, false); + arrangeOnFirstCircleRadio.set_label(C_("Polar arrange tab", "First selected circle/ellipse/arc")); + arrangeRadioGroup = arrangeOnFirstCircleRadio.get_group(); + arrangeOnFirstCircleRadio.signal_toggled().connect(sigc::mem_fun(*this, &PolarArrangeTab::on_arrange_radio_changed)); + pack_start(arrangeOnFirstCircleRadio, false, false); + + arrangeOnLastCircleRadio.set_label(C_("Polar arrange tab", "Last selected circle/ellipse/arc")); + arrangeOnLastCircleRadio.set_group(arrangeRadioGroup); + arrangeOnLastCircleRadio.signal_toggled().connect(sigc::mem_fun(*this, &PolarArrangeTab::on_arrange_radio_changed)); + pack_start(arrangeOnLastCircleRadio, false, false); arrangeOnParametersRadio.set_label(C_("Polar arrange tab", "Parameterized:")); arrangeOnParametersRadio.set_group(arrangeRadioGroup); @@ -182,15 +187,16 @@ float calcAngle(float arcBegin, float arcEnd, int count, int n) */ Geom::Point calcPoint(float cx, float cy, float rx, float ry, float angle) { - // Parameters for radius equation - float a = ry * cos(angle); - float b = rx * sin(angle); - - float radius = (rx * ry) / sqrtf((a*a) + (b*b)); - - return Geom::Point(cos(angle) * radius + cx, sin(angle) * radius + cy); + return Geom::Point(cx + cos(angle) * rx, cy + sin(angle) * ry); } +/** + * Returns the selected anchor point in document coordinates. If anchor + * is 0 to 8, then a bounding box point has been choosen. If it is 9 however + * the rotational center is chosen. + * @todo still using a hack to get the real coordinate space (subtracting document height + * and inverting axes) + */ Geom::Point getAnchorPoint(int anchor, SPItem *item) { Geom::Point source; @@ -262,15 +268,27 @@ void PolarArrangeTab::arrange() tmp = items = selection->itemList(); SPGenericEllipse *referenceEllipse = NULL; // Last ellipse in selection + bool arrangeOnEllipse = !arrangeOnParametersRadio.get_active(); + bool arrangeOnFirstEllipse = arrangeOnEllipse && arrangeOnFirstCircleRadio.get_active(); + int count = 0; while(tmp) { - SPItem *item = SP_ITEM(tmp->data); - - // The last selected ellipse is actually the first in list - if(SP_IS_GENERICELLIPSE(item) && referenceEllipse == NULL) - referenceEllipse = SP_GENERICELLIPSE(item); - + if(arrangeOnEllipse) + { + SPItem *item = SP_ITEM(tmp->data); + + if(arrangeOnFirstEllipse) + { + // The first selected ellipse is actually the last one in the list + if(SP_IS_GENERICELLIPSE(item)) + referenceEllipse = SP_GENERICELLIPSE(item); + } else { + // The last selected ellipse is actually the first in list + if(SP_IS_GENERICELLIPSE(item) && referenceEllipse == NULL) + referenceEllipse = SP_GENERICELLIPSE(item); + } + } tmp = tmp->next; ++count; } @@ -280,7 +298,7 @@ void PolarArrangeTab::arrange() float arcBeg, arcEnd; // begin and end angles for arcs Geom::Affine transformation; // Any additional transformation to apply to the objects - if(arrangeOnCircleRadio.get_active()) + if(arrangeOnEllipse) { if(referenceEllipse == NULL) { @@ -294,6 +312,8 @@ void PolarArrangeTab::arrange() ry = referenceEllipse->ry.value; arcBeg = referenceEllipse->start; arcEnd = referenceEllipse->end; + + std::cout << "Arc: " << arcBeg << ", " << arcEnd << std::endl; transformation = referenceEllipse->i2dt_affine(); // We decrement the count by 1 as we are not going to lay @@ -313,8 +333,6 @@ void PolarArrangeTab::arrange() referenceEllipse = NULL; } - - int anchor = 9; if(anchorBoundingBoxRadio.get_active()) { @@ -322,6 +340,8 @@ void PolarArrangeTab::arrange() anchorSelector.getVerticalAlignment() * 3; } + Geom::Point realCenter = Geom::Point(cx, cy) * transformation; + tmp = items; int i = 0; while(tmp) @@ -336,12 +356,16 @@ void PolarArrangeTab::arrange() moveToPoint(anchor, item, newLocation); - if(rotateObjectsCheckBox.get_active()) + if(rotateObjectsCheckBox.get_active()) { + // Calculate the angle by which to rotate each object + angle = -atan2f(newLocation.x() - realCenter.x(), newLocation.y() - realCenter.y()); rotateAround(item, newLocation, Geom::Rotate(angle)); + } + + std::cout << "object " << i << " out of " << count << ": " << angle << std::endl; ++i; } - tmp = tmp->next; } @@ -355,7 +379,7 @@ void PolarArrangeTab::updateSelection() void PolarArrangeTab::on_arrange_radio_changed() { - bool arrangeParametric = !arrangeOnCircleRadio.get_active(); + bool arrangeParametric = arrangeOnParametersRadio.get_active(); centerX.set_sensitive(arrangeParametric); centerY.set_sensitive(arrangeParametric); diff --git a/src/ui/dialog/polararrangetab.h b/src/ui/dialog/polararrangetab.h index 81b7de4d9..24760a8bc 100644 --- a/src/ui/dialog/polararrangetab.h +++ b/src/ui/dialog/polararrangetab.h @@ -57,7 +57,8 @@ private: Gtk::Label arrangeOnLabel; Gtk::RadioButtonGroup arrangeRadioGroup; - Gtk::RadioButton arrangeOnCircleRadio; + Gtk::RadioButton arrangeOnFirstCircleRadio; + Gtk::RadioButton arrangeOnLastCircleRadio; Gtk::RadioButton arrangeOnParametersRadio; Gtk::Table parametersTable; -- cgit v1.2.3 From 71d330c244fa7da51136dee09c2132814e84fdcf Mon Sep 17 00:00:00 2001 From: Denis Declara Date: Wed, 9 May 2012 16:50:16 +0200 Subject: Fixed runtime assertion about Parent beeing Null (bzr r11073.1.30) --- src/ui/dialog/tile.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/ui') diff --git a/src/ui/dialog/tile.cpp b/src/ui/dialog/tile.cpp index 879c9182f..917544d3d 100644 --- a/src/ui/dialog/tile.cpp +++ b/src/ui/dialog/tile.cpp @@ -40,7 +40,6 @@ ArrangeDialog::ArrangeDialog() _arrangeButton = this->addResponseButton(C_("Arrange dialog","_Arrange"), GTK_RESPONSE_APPLY); _arrangeButton->set_use_underline(true); _arrangeButton->set_tooltip_text(_("Arrange selected objects")); - _arrangeBox.pack_start(*_arrangeButton); contents->pack_start(_arrangeBox); show_all_children(); } -- cgit v1.2.3 From 2b693f8037ad4b25b368376274811f20f5864c1b Mon Sep 17 00:00:00 2001 From: Denis Declara Date: Wed, 9 May 2012 17:03:55 +0200 Subject: Renamed files to better match coding conventions (bzr r11073.1.31) --- src/ui/CMakeLists.txt | 8 +- src/ui/dialog/Makefile_insert | 8 +- src/ui/dialog/grid-arrange-tab.cpp | 786 ++++++++++++++++++++++++++++++++++++ src/ui/dialog/grid-arrange-tab.h | 147 +++++++ src/ui/dialog/gridarrangetab.cpp | 786 ------------------------------------ src/ui/dialog/gridarrangetab.h | 147 ------- src/ui/dialog/polar-arrange-tab.cpp | 414 +++++++++++++++++++ src/ui/dialog/polar-arrange-tab.h | 87 ++++ src/ui/dialog/polararrangetab.cpp | 414 ------------------- src/ui/dialog/polararrangetab.h | 87 ---- src/ui/dialog/tile.cpp | 4 +- src/ui/widget/anchor-selector.cpp | 19 + src/ui/widget/anchor-selector.h | 19 + 13 files changed, 1482 insertions(+), 1444 deletions(-) create mode 100644 src/ui/dialog/grid-arrange-tab.cpp create mode 100644 src/ui/dialog/grid-arrange-tab.h delete mode 100644 src/ui/dialog/gridarrangetab.cpp delete mode 100644 src/ui/dialog/gridarrangetab.h create mode 100644 src/ui/dialog/polar-arrange-tab.cpp create mode 100644 src/ui/dialog/polar-arrange-tab.h delete mode 100644 src/ui/dialog/polararrangetab.cpp delete mode 100644 src/ui/dialog/polararrangetab.h (limited to 'src/ui') diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt index 22f6b2bab..7435720fd 100644 --- a/src/ui/CMakeLists.txt +++ b/src/ui/CMakeLists.txt @@ -43,7 +43,7 @@ set(ui_SRC dialog/find.cpp dialog/floating-behavior.cpp dialog/glyphs.cpp - dialog/gridarrangetab.cpp + dialog/grid-arrange-tab.cpp dialog/guides.cpp dialog/icon-preview.cpp dialog/inkscape-preferences.cpp @@ -57,7 +57,7 @@ set(ui_SRC dialog/object-attributes.cpp dialog/object-properties.cpp dialog/ocaldialogs.cpp - dialog/polararrangetab.cpp + dialog/polar-arrange-tab.cpp dialog/print-colors-preview-dialog.cpp dialog/print.cpp dialog/scriptdialog.cpp @@ -160,7 +160,7 @@ set(ui_SRC dialog/floating-behavior.h dialog/glyphs.h dialog/guides.h - dialog/gridarrangetab.h + dialog/grid-arrange-tab.h dialog/icon-preview.h dialog/inkscape-preferences.h dialog/input.h @@ -174,7 +174,7 @@ set(ui_SRC dialog/object-properties.h dialog/ocaldialogs.h dialog/panel-dialog.h - dialog/polararrangetab.h + dialog/polar-arrange-tab.h dialog/print-colors-preview-dialog.h dialog/print.h dialog/scriptdialog.h diff --git a/src/ui/dialog/Makefile_insert b/src/ui/dialog/Makefile_insert index 34cceae54..53533a08f 100644 --- a/src/ui/dialog/Makefile_insert +++ b/src/ui/dialog/Makefile_insert @@ -49,8 +49,8 @@ ink_common_sources += \ ui/dialog/floating-behavior.h \ ui/dialog/glyphs.cpp \ ui/dialog/glyphs.h \ - ui/dialog/gridarrangetab.h \ - ui/dialog/gridarrangetab.cpp \ + ui/dialog/grid-arrange-tab.h \ + ui/dialog/grid-arrange-tab.cpp \ ui/dialog/guides.cpp \ ui/dialog/guides.h \ ui/dialog/icon-preview.cpp \ @@ -78,8 +78,8 @@ ink_common_sources += \ ui/dialog/object-properties.cpp \ ui/dialog/object-properties.h \ ui/dialog/panel-dialog.h \ - ui/dialog/polararrangetab.cpp \ - ui/dialog/polararrangetab.h \ + ui/dialog/polar-arrange-tab.cpp \ + ui/dialog/polar-arrange-tab.h \ ui/dialog/print.cpp \ ui/dialog/print.h \ ui/dialog/print-colors-preview-dialog.cpp \ diff --git a/src/ui/dialog/grid-arrange-tab.cpp b/src/ui/dialog/grid-arrange-tab.cpp new file mode 100644 index 000000000..54b667ed9 --- /dev/null +++ b/src/ui/dialog/grid-arrange-tab.cpp @@ -0,0 +1,786 @@ +/* + * A simple dialog for creating grid type arrangements of selected objects + * + * Authors: + * Bob Jamison ( based off trace dialog) + * John Cliff + * Other dudes from The Inkscape Organization + * Abhishek Sharma + * Declara Denis + * + * Copyright (C) 2004 Bob Jamison + * Copyright (C) 2004 John Cliff + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ +//#define DEBUG_GRID_ARRANGE 1 + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "ui/dialog/grid-arrange-tab.h" +#include //for GTK_RESPONSE* types +#include +#include +#include <2geom/transforms.h> + +#include "verbs.h" +#include "preferences.h" +#include "inkscape.h" +#include "desktop-handles.h" +#include "selection.h" +#include "document.h" +#include "document-undo.h" +#include "sp-item.h" +#include "widgets/icon.h" +#include "desktop.h" +//#include "sp-item-transform.h" FIXME +#include "ui/dialog/tile.h" // for Inkscape::UI::Dialog::ArrangeDialog + +/* + * Sort items by their x co-ordinates, taking account of y (keeps rows intact) + * + * <0 *elem1 goes before *elem2 + * 0 *elem1 == *elem2 + * >0 *elem1 goes after *elem2 + */ +int sp_compare_x_position(SPItem *first, SPItem *second) +{ + using Geom::X; + using Geom::Y; + + Geom::OptRect a = first->documentVisualBounds(); + Geom::OptRect b = second->documentVisualBounds(); + + if ( !a || !b ) { + // FIXME? + return 0; + } + + double const a_height = a->dimensions()[Y]; + double const b_height = b->dimensions()[Y]; + + bool a_in_b_vert = false; + if ((a->min()[Y] < b->min()[Y] + 0.1) && (a->min()[Y] > b->min()[Y] - b_height)) { + a_in_b_vert = true; + } else if ((b->min()[Y] < a->min()[Y] + 0.1) && (b->min()[Y] > a->min()[Y] - a_height)) { + a_in_b_vert = true; + } else if (b->min()[Y] == a->min()[Y]) { + a_in_b_vert = true; + } else { + a_in_b_vert = false; + } + + if (!a_in_b_vert) { + return -1; + } + if (a_in_b_vert && a->min()[X] > b->min()[X]) { + return 1; + } + if (a_in_b_vert && a->min()[X] < b->min()[X]) { + return -1; + } + return 0; +} + +/* + * Sort items by their y co-ordinates. + */ +int sp_compare_y_position(SPItem *first, SPItem *second) +{ + Geom::OptRect a = first->documentVisualBounds(); + Geom::OptRect b = second->documentVisualBounds(); + + if ( !a || !b ) { + // FIXME? + return 0; + } + + if (a->min()[Geom::Y] > b->min()[Geom::Y]) { + return 1; + } + if (a->min()[Geom::Y] < b->min()[Geom::Y]) { + return -1; + } + + return 0; +} + +namespace Inkscape { +namespace UI { +namespace Dialog { + + +//######################################################################### +//## E V E N T S +//######################################################################### + +/* + * + * This arranges the selection in a grid pattern. + * + */ + +void GridArrangeTab::arrange() +{ + + int cnt,row_cnt,col_cnt,a,row,col; + double grid_left,grid_top,col_width,row_height,paddingx,paddingy,width, height, new_x, new_y,cx,cy; + double total_col_width,total_row_height; + col_width = 0; + row_height = 0; + total_col_width=0; + total_row_height=0; + + // check for correct numbers in the row- and col-spinners + on_col_spinbutton_changed(); + on_row_spinbutton_changed(); + + // set padding to manual values + paddingx = XPadding.getValue("px"); + paddingy = YPadding.getValue("px"); + + std::vector row_heights; + std::vector col_widths; + std::vector row_ys; + std::vector col_xs; + + int NoOfCols = NoOfColsSpinner.get_value_as_int(); + int NoOfRows = NoOfRowsSpinner.get_value_as_int(); + + width = 0; + for (a=0;agetDesktop(); + sp_desktop_document(desktop)->ensureUpToDate(); + + Inkscape::Selection *selection = sp_desktop_selection (desktop); + const GSList *items = selection ? selection->itemList() : 0; + cnt=0; + for (; items != NULL; items = items->next) { + SPItem *item = SP_ITEM(items->data); + Geom::OptRect b = item->documentVisualBounds(); + if (!b) { + continue; + } + + width = b->dimensions()[Geom::X]; + height = b->dimensions()[Geom::Y]; + + cx = b->midpoint()[Geom::X]; + cy = b->midpoint()[Geom::Y]; + + if (b->min()[Geom::X] < grid_left) { + grid_left = b->min()[Geom::X]; + } + if (b->min()[Geom::Y] < grid_top) { + grid_top = b->min()[Geom::Y]; + } + if (width > col_width) { + col_width = width; + } + if (height > row_height) { + row_height = height; + } + } + + + // require the sorting done before we can calculate row heights etc. + + g_return_if_fail(selection); + const GSList *items2 = selection->itemList(); + GSList *rev = g_slist_copy((GSList *) items2); + GSList *sorted = NULL; + rev = g_slist_sort(rev, (GCompareFunc) sp_compare_y_position); + sorted = g_slist_sort(rev, (GCompareFunc) sp_compare_x_position); + + + // Calculate individual Row and Column sizes if necessary + + + cnt=0; + const GSList *sizes = sorted; + for (; sizes != NULL; sizes = sizes->next) { + SPItem *item = SP_ITEM(sizes->data); + Geom::OptRect b = item->documentVisualBounds(); + if (b) { + width = b->dimensions()[Geom::X]; + height = b->dimensions()[Geom::Y]; + if (width > col_widths[(cnt % NoOfCols)]) { + col_widths[(cnt % NoOfCols)] = width; + } + if (height > row_heights[(cnt / NoOfCols)]) { + row_heights[(cnt / NoOfCols)] = height; + } + } + + cnt++; + } + + + /// Make sure the top and left of the grid dont move by compensating for align values. + if (RowHeightButton.get_active()){ + grid_top = grid_top - (((row_height - row_heights[0]) / 2)*(VertAlign)); + } + if (ColumnWidthButton.get_active()){ + grid_left = grid_left - (((col_width - col_widths[0]) /2)*(HorizAlign)); + } + + #ifdef DEBUG_GRID_ARRANGE + g_print("\n cx = %f cy= %f gridleft=%f",cx,cy,grid_left); + #endif + + // Calculate total widths and heights, allowing for columns and rows non uniformly sized. + + if (ColumnWidthButton.get_active()){ + total_col_width = col_width * NoOfCols; + col_widths.clear(); + for (a=0;avisualBounds(); + // Fit to bbox, calculate padding between rows accordingly. + if ( sel_bbox && !SpaceManualRadioButton.get_active() ){ +#ifdef DEBUG_GRID_ARRANGE +g_print("\n row = %f col = %f selection x= %f selection y = %f", total_row_height,total_col_width, b.extent(Geom::X), b.extent(Geom::Y)); +#endif + paddingx = (sel_bbox->width() - total_col_width) / (NoOfCols -1); + paddingy = (sel_bbox->height() - total_row_height) / (NoOfRows -1); + } + +/* + Horizontal align - Left = 0 + Centre = 1 + Right = 2 + + Vertical align - Top = 0 + Middle = 1 + Bottom = 2 + + X position is calculated by taking the grids left co-ord, adding the distance to the column, + then adding 1/2 the spacing multiplied by the align variable above, + Y position likewise, takes the top of the grid, adds the y to the current row then adds the padding in to align it. + +*/ + + // Calculate row and column x and y coords required to allow for columns and rows which are non uniformly sized. + + for (a=0;adata); + sorted = sorted->next; + } + + for (; current_row != NULL; current_row = current_row->next) { + SPItem *item=SP_ITEM(current_row->data); + Inkscape::XML::Node *repr = item->getRepr(); + Geom::OptRect b = item->documentVisualBounds(); + Geom::Point min; + if (b) { + width = b->dimensions()[Geom::X]; + height = b->dimensions()[Geom::Y]; + min = b->min(); + } else { + width = height = 0; + min = Geom::Point(0, 0); + } + + row = cnt / NoOfCols; + col = cnt % NoOfCols; + + new_x = grid_left + (((col_widths[col] - width)/2)*HorizAlign) + col_xs[col]; + new_y = grid_top + (((row_heights[row] - height)/2)*VertAlign) + row_ys[row]; + + // signs are inverted between x and y due to y inversion + Geom::Point move = Geom::Point(new_x - min[Geom::X], min[Geom::Y] - new_y); + Geom::Affine const affine = Geom::Affine(Geom::Translate(move)); + item->set_i2d_affine(item->i2dt_affine() * affine); + item->doWriteTransform(repr, item->transform, NULL); + SP_OBJECT (current_row->data)->updateRepr(); + cnt +=1; + } + g_slist_free (current_row); + } + + DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_SELECTION_ARRANGE, + _("Arrange in a grid")); + +} + + +//######################################################################### +//## E V E N T S +//######################################################################### + +/** + * changed value in # of columns spinbox. + */ +void GridArrangeTab::on_row_spinbutton_changed() +{ + // quit if run by the attr_changed listener + if (updating) { + return; + } + + // in turn, prevent listener from responding + updating = true; + SPDesktop *desktop = Parent->getDesktop(); + + Inkscape::Selection *selection = desktop ? desktop->selection : 0; + g_return_if_fail( selection ); + + GSList const *items = selection->itemList(); + int selcount = g_slist_length((GSList *)items); + + double PerCol = ceil(selcount / NoOfColsSpinner.get_value()); + NoOfRowsSpinner.set_value(PerCol); + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->setDouble("/dialogs/gridtiler/NoOfCols", NoOfColsSpinner.get_value()); + updating=false; +} + +/** + * changed value in # of rows spinbox. + */ +void GridArrangeTab::on_col_spinbutton_changed() +{ + // quit if run by the attr_changed listener + if (updating) { + return; + } + + // in turn, prevent listener from responding + updating = true; + SPDesktop *desktop = Parent->getDesktop(); + Inkscape::Selection *selection = desktop ? desktop->selection : 0; + g_return_if_fail(selection); + + GSList const *items = selection->itemList(); + int selcount = g_slist_length((GSList *)items); + + double PerRow = ceil(selcount / NoOfRowsSpinner.get_value()); + NoOfColsSpinner.set_value(PerRow); + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->setDouble("/dialogs/gridtiler/NoOfCols", PerRow); + + updating=false; +} + +/** + * changed value in x padding spinbox. + */ +void GridArrangeTab::on_xpad_spinbutton_changed() +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->setDouble("/dialogs/gridtiler/XPad", XPadding.getValue("px")); + +} + +/** + * changed value in y padding spinbox. + */ +void GridArrangeTab::on_ypad_spinbutton_changed() +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->setDouble("/dialogs/gridtiler/YPad", YPadding.getValue("px")); +} + + +/** + * checked/unchecked autosize Rows button. + */ +void GridArrangeTab::on_RowSize_checkbutton_changed() +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + if (RowHeightButton.get_active()) { + prefs->setDouble("/dialogs/gridtiler/AutoRowSize", 20); + } else { + prefs->setDouble("/dialogs/gridtiler/AutoRowSize", -20); + } + RowHeightBox.set_sensitive ( !RowHeightButton.get_active()); +} + +/** + * checked/unchecked autosize Rows button. + */ +void GridArrangeTab::on_ColSize_checkbutton_changed() +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + if (ColumnWidthButton.get_active()) { + prefs->setDouble("/dialogs/gridtiler/AutoColSize", 20); + } else { + prefs->setDouble("/dialogs/gridtiler/AutoColSize", -20); + } + ColumnWidthBox.set_sensitive ( !ColumnWidthButton.get_active()); +} + +/** + * changed value in columns spinbox. + */ +void GridArrangeTab::on_rowSize_spinbutton_changed() +{ + // quit if run by the attr_changed listener + if (updating) { + return; + } + + // in turn, prevent listener from responding + updating = true; + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->setDouble("/dialogs/gridtiler/RowHeight", RowHeightSpinner.get_value()); + updating=false; + +} + +/** + * changed value in rows spinbox. + */ +void GridArrangeTab::on_colSize_spinbutton_changed() +{ + // quit if run by the attr_changed listener + if (updating) { + return; + } + + // in turn, prevent listener from responding + updating = true; + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->setDouble("/dialogs/gridtiler/ColWidth", ColumnWidthSpinner.get_value()); + updating=false; + +} + +/** + * changed Radio button in Spacing group. + */ +void GridArrangeTab::Spacing_button_changed() +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + if (SpaceManualRadioButton.get_active()) { + prefs->setDouble("/dialogs/gridtiler/SpacingType", 20); + } else { + prefs->setDouble("/dialogs/gridtiler/SpacingType", -20); + } + + XPadding.set_sensitive ( SpaceManualRadioButton.get_active()); + YPadding.set_sensitive ( SpaceManualRadioButton.get_active()); +} + +/** + * changed Anchor selection widget. + */ +void GridArrangeTab::Align_changed() +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + VertAlign = AlignmentSelector.getVerticalAlignment(); + prefs->setInt("/dialogs/gridtiler/VertAlign", VertAlign); + HorizAlign = AlignmentSelector.getHorizontalAlignment(); + prefs->setInt("/dialogs/gridtiler/HorizAlign", HorizAlign); +} + +/** + * Desktop selection changed + */ +void GridArrangeTab::updateSelection() +{ + // quit if run by the attr_changed listener + if (updating) { + return; + } + + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + // in turn, prevent listener from responding + updating = true; + SPDesktop *desktop = Parent->getDesktop(); + Inkscape::Selection *selection = desktop ? desktop->selection : 0; + GSList const *items = selection ? selection->itemList() : 0; + + if (items) { + int selcount = g_slist_length((GSList *)items); + + if (NoOfColsSpinner.get_value() > 1 && NoOfRowsSpinner.get_value() > 1){ + // Update the number of rows assuming number of columns wanted remains same. + double NoOfRows = ceil(selcount / NoOfColsSpinner.get_value()); + NoOfRowsSpinner.set_value(NoOfRows); + + // if the selection has less than the number set for one row, reduce it appropriately + if (selcount < NoOfColsSpinner.get_value()) { + double NoOfCols = ceil(selcount / NoOfRowsSpinner.get_value()); + NoOfColsSpinner.set_value(NoOfCols); + prefs->setInt("/dialogs/gridtiler/NoOfCols", NoOfCols); + } + } else { + double PerRow = ceil(sqrt(selcount)); + double PerCol = ceil(sqrt(selcount)); + NoOfRowsSpinner.set_value(PerRow); + NoOfColsSpinner.set_value(PerCol); + prefs->setInt("/dialogs/gridtiler/NoOfCols", static_cast(PerCol)); + } + } + + updating = false; +} + + + +/*########################## +## Experimental +##########################*/ + +static void updateSelectionCallback(Inkscape::Application */*inkscape*/, Inkscape::Selection */*selection*/, GridArrangeTab *dlg) +{ + dlg->updateSelection(); +} + + +//######################################################################### +//## C O N S T R U C T O R / D E S T R U C T O R +//######################################################################### +/** + * Constructor + */ +GridArrangeTab::GridArrangeTab(ArrangeDialog *parent) + : Parent(parent), + XPadding(_("X:"), _("Horizontal spacing between columns."), UNIT_TYPE_LINEAR, "", "object-columns"), + YPadding(_("Y:"), _("Vertical spacing between rows."), XPadding, "", "object-rows") +{ + // bool used by spin button callbacks to stop loops where they change each other. + updating = false; + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + + // could not do this in gtkmm - there's no Gtk::SizeGroup public constructor (!) + GtkSizeGroup *_col1 = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); + GtkSizeGroup *_col2 = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); + GtkSizeGroup *_col3 = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); + + { + // Selection Change signal + g_signal_connect ( G_OBJECT (INKSCAPE), "change_selection", G_CALLBACK (updateSelectionCallback), this); + } + + Gtk::Box *contents = this; + +#define MARGIN 2 + + //##Set up the panel + + SPDesktop *desktop = Parent->getDesktop(); + + Inkscape::Selection *selection = desktop ? desktop->selection : 0; + g_return_if_fail( selection ); + int selcount = 1; + if (!selection->isEmpty()) { + GSList const *items = selection->itemList(); + selcount = g_slist_length((GSList *)items); + } + + + /*#### Number of Rows ####*/ + + double PerRow = ceil(sqrt(selcount)); + double PerCol = ceil(sqrt(selcount)); + + #ifdef DEBUG_GRID_ARRANGE + g_print("/n PerRox = %f PerCol = %f selcount = %d",PerRow,PerCol,selcount); + #endif + + NoOfRowsLabel.set_text_with_mnemonic(_("_Rows:")); + NoOfRowsLabel.set_mnemonic_widget(NoOfRowsSpinner); + NoOfRowsBox.pack_start(NoOfRowsLabel, false, false, MARGIN); + + NoOfRowsSpinner.set_digits(0); + NoOfRowsSpinner.set_increments(1, 0); + NoOfRowsSpinner.set_range(1.0, 10000.0); + NoOfRowsSpinner.set_value(PerCol); + NoOfRowsSpinner.signal_changed().connect(sigc::mem_fun(*this, &GridArrangeTab::on_col_spinbutton_changed)); + NoOfRowsSpinner.set_tooltip_text(_("Number of rows")); + NoOfRowsBox.pack_start(NoOfRowsSpinner, false, false, MARGIN); + gtk_size_group_add_widget(_col1, (GtkWidget *) NoOfRowsBox.gobj()); + + RowHeightButton.set_label(_("Equal _height")); + RowHeightButton.set_use_underline(true); + double AutoRow = prefs->getDouble("/dialogs/gridtiler/AutoRowSize", 15); + if (AutoRow>0) + AutoRowSize=true; + else + AutoRowSize=false; + RowHeightButton.set_active(AutoRowSize); + + NoOfRowsBox.pack_start(RowHeightButton, false, false, MARGIN); + + RowHeightButton.set_tooltip_text(_("If not set, each row has the height of the tallest object in it")); + RowHeightButton.signal_toggled().connect(sigc::mem_fun(*this, &GridArrangeTab::on_RowSize_checkbutton_changed)); + + SpinsHBox.pack_start(NoOfRowsBox, false, false, MARGIN); + + + /*#### Label for X ####*/ + padXByYLabel.set_label(" "); + XByYLabelVBox.pack_start(padXByYLabel, false, false, MARGIN); + XByYLabel.set_markup(" × "); + XByYLabelVBox.pack_start(XByYLabel, false, false, MARGIN); + SpinsHBox.pack_start(XByYLabelVBox, false, false, MARGIN); + gtk_size_group_add_widget(_col2, (GtkWidget *) XByYLabelVBox.gobj()); + + /*#### Number of columns ####*/ + + NoOfColsLabel.set_text_with_mnemonic(_("_Columns:")); + NoOfColsLabel.set_mnemonic_widget(NoOfColsSpinner); + NoOfColsBox.pack_start(NoOfColsLabel, false, false, MARGIN); + + NoOfColsSpinner.set_digits(0); + NoOfColsSpinner.set_increments(1, 0); + NoOfColsSpinner.set_range(1.0, 10000.0); + NoOfColsSpinner.set_value(PerRow); + NoOfColsSpinner.signal_changed().connect(sigc::mem_fun(*this, &GridArrangeTab::on_row_spinbutton_changed)); + NoOfColsSpinner.set_tooltip_text(_("Number of columns")); + NoOfColsBox.pack_start(NoOfColsSpinner, false, false, MARGIN); + gtk_size_group_add_widget(_col3, (GtkWidget *) NoOfColsBox.gobj()); + + ColumnWidthButton.set_label(_("Equal _width")); + ColumnWidthButton.set_use_underline(true); + double AutoCol = prefs->getDouble("/dialogs/gridtiler/AutoColSize", 15); + if (AutoCol>0) + AutoColSize=true; + else + AutoColSize=false; + ColumnWidthButton.set_active(AutoColSize); + NoOfColsBox.pack_start(ColumnWidthButton, false, false, MARGIN); + + ColumnWidthButton.set_tooltip_text(_("If not set, each column has the width of the widest object in it")); + ColumnWidthButton.signal_toggled().connect(sigc::mem_fun(*this, &GridArrangeTab::on_ColSize_checkbutton_changed)); + + SpinsHBox.pack_start(NoOfColsBox, false, false, MARGIN); + + TileBox.pack_start(SpinsHBox, false, false, MARGIN); + + VertAlign = prefs->getInt("/dialogs/gridtiler/VertAlign", 1); + HorizAlign = prefs->getInt("/dialogs/gridtiler/HorizAlign", 1); + + // Anchor selection widget + AlignLabel.set_label("Alignment:"); + AlignLabel.set_alignment(Gtk::ALIGN_START, Gtk::ALIGN_CENTER); + AlignmentSelector.setAlignment(HorizAlign, VertAlign); + AlignmentSelector.on_selectionChanged().connect(sigc::mem_fun(*this, &GridArrangeTab::Align_changed)); + TileBox.pack_start(AlignLabel, false, false, MARGIN); + TileBox.pack_start(AlignmentSelector, true, false, MARGIN); + + { + /*#### Radio buttons to control spacing manually or to fit selection bbox ####*/ + SpaceByBBoxRadioButton.set_label(_("_Fit into selection box")); + SpaceByBBoxRadioButton.set_use_underline (true); + SpaceByBBoxRadioButton.signal_toggled().connect(sigc::mem_fun(*this, &GridArrangeTab::Spacing_button_changed)); + SpacingGroup = SpaceByBBoxRadioButton.get_group(); + + SpacingVBox.pack_start(SpaceByBBoxRadioButton, false, false, MARGIN); + + SpaceManualRadioButton.set_label(_("_Set spacing:")); + SpaceManualRadioButton.set_use_underline (true); + SpaceManualRadioButton.set_group(SpacingGroup); + SpaceManualRadioButton.signal_toggled().connect(sigc::mem_fun(*this, &GridArrangeTab::Spacing_button_changed)); + SpacingVBox.pack_start(SpaceManualRadioButton, false, false, MARGIN); + + TileBox.pack_start(SpacingVBox, false, false, MARGIN); + } + + { + /*#### Padding ####*/ + + YPadding.setDigits(5); + YPadding.setIncrements(0.2, 0); + YPadding.setRange(-10000, 10000); + double yPad = prefs->getDouble("/dialogs/gridtiler/YPad", 15); + YPadding.setValue(yPad, "px"); + YPadding.signal_value_changed().connect(sigc::mem_fun(*this, &GridArrangeTab::on_ypad_spinbutton_changed)); + + XPadding.setDigits(5); + XPadding.setIncrements(0.2, 0); + XPadding.setRange(-10000, 10000); + double xPad = prefs->getDouble("/dialogs/gridtiler/XPad", 15); + XPadding.setValue(xPad, "px"); + + XPadding.signal_value_changed().connect(sigc::mem_fun(*this, &GridArrangeTab::on_xpad_spinbutton_changed)); + } + TileBox.pack_start(XPadding, false, false, MARGIN); + TileBox.pack_start(YPadding, false, false, MARGIN); + + contents->pack_start(TileBox); + + double SpacingType = prefs->getDouble("/dialogs/gridtiler/SpacingType", 15); + if (SpacingType>0) { + ManualSpacing=true; + } else { + ManualSpacing=false; + } + SpaceManualRadioButton.set_active(ManualSpacing); + SpaceByBBoxRadioButton.set_active(!ManualSpacing); + XPadding.set_sensitive (ManualSpacing); + YPadding.set_sensitive (ManualSpacing); + + //## The OK button FIXME + /*TileOkButton = addResponseButton(C_("Rows and columns dialog","_Arrange"), GTK_RESPONSE_APPLY); + TileOkButton->set_use_underline(true); + TileOkButton->set_tooltip_text(_("Arrange selected objects"));*/ + + show_all_children(); +} + +} //namespace Dialog +} //namespace UI +} //namespace Inkscape + +/* + 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/grid-arrange-tab.h b/src/ui/dialog/grid-arrange-tab.h new file mode 100644 index 000000000..7e90accf1 --- /dev/null +++ b/src/ui/dialog/grid-arrange-tab.h @@ -0,0 +1,147 @@ +/** + * @brief Arranges Objects into a Grid + */ +/* Authors: + * Bob Jamison ( based off trace dialog) + * John Cliff + * Other dudes from The Inkscape Organization + * Abhishek Sharma + * Declara Denis + * + * Copyright (C) 2004 Bob Jamison + * Copyright (C) 2004 John Cliff + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#ifndef INKSCAPE_UI_DIALOG_GRID_ARRANGE_TAB_H +#define INKSCAPE_UI_DIALOG_GRID_ARRANGE_TAB_H + +#include + +#include "ui/dialog/arrangetab.h" + +#include "ui/widget/anchor-selector.h" +#include "ui/widget/scalar-unit.h" +#include "ui/widget/spinbutton.h" + +namespace Inkscape { +namespace UI { +namespace Dialog { + +class ArrangeDialog; + +/** + * Dialog for tiling an object + */ +class GridArrangeTab : public ArrangeTab { +public: + GridArrangeTab(ArrangeDialog *parent); + virtual ~GridArrangeTab() {}; + + /** + * Do the actual work + */ + virtual void arrange(); + + /** + * Respond to selection change + */ + void updateSelection(); + + // Callbacks from spinbuttons + void on_row_spinbutton_changed(); + void on_col_spinbutton_changed(); + void on_xpad_spinbutton_changed(); + void on_ypad_spinbutton_changed(); + void on_RowSize_checkbutton_changed(); + void on_ColSize_checkbutton_changed(); + void on_rowSize_spinbutton_changed(); + void on_colSize_spinbutton_changed(); + void Spacing_button_changed(); + void Align_changed(); + + +private: + GridArrangeTab(GridArrangeTab const &d); // no copy + void operator=(GridArrangeTab const &d); // no assign + + ArrangeDialog *Parent; + + bool userHidden; + bool updating; + + Gtk::VBox TileBox; + Gtk::Button *TileOkButton; + Gtk::Button *TileCancelButton; + + // Number selected label + Gtk::Label SelectionContentsLabel; + + + Gtk::HBox AlignHBox; + Gtk::HBox SpinsHBox; + + // Number per Row + Gtk::VBox NoOfColsBox; + Gtk::Label NoOfColsLabel; + Inkscape::UI::Widget::SpinButton NoOfColsSpinner; + bool AutoRowSize; + Gtk::CheckButton RowHeightButton; + + Gtk::VBox XByYLabelVBox; + Gtk::Label padXByYLabel; + Gtk::Label XByYLabel; + + // Number per Column + Gtk::VBox NoOfRowsBox; + Gtk::Label NoOfRowsLabel; + Inkscape::UI::Widget::SpinButton NoOfRowsSpinner; + bool AutoColSize; + Gtk::CheckButton ColumnWidthButton; + + // Alignment + Gtk::Label AlignLabel; + Inkscape::UI::Widget::AnchorSelector AlignmentSelector; + double VertAlign; + double HorizAlign; + + Inkscape::UI::Widget::ScalarUnit XPadding; + Inkscape::UI::Widget::ScalarUnit YPadding; + + // BBox or manual spacing + Gtk::VBox SpacingVBox; + Gtk::RadioButtonGroup SpacingGroup; + Gtk::RadioButton SpaceByBBoxRadioButton; + Gtk::RadioButton SpaceManualRadioButton; + bool ManualSpacing; + + // Row height + Gtk::VBox RowHeightVBox; + Gtk::HBox RowHeightBox; + Gtk::Label RowHeightLabel; + Inkscape::UI::Widget::SpinButton RowHeightSpinner; + + // Column width + Gtk::VBox ColumnWidthVBox; + Gtk::HBox ColumnWidthBox; + Gtk::Label ColumnWidthLabel; + Inkscape::UI::Widget::SpinButton ColumnWidthSpinner; +}; + +} //namespace Dialog +} //namespace UI +} //namespace Inkscape + +#endif /* INKSCAPE_UI_DIALOG_GRID_ARRANGE_TAB_H */ + +/* + 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/gridarrangetab.cpp b/src/ui/dialog/gridarrangetab.cpp deleted file mode 100644 index fca7c5b0e..000000000 --- a/src/ui/dialog/gridarrangetab.cpp +++ /dev/null @@ -1,786 +0,0 @@ -/* - * A simple dialog for creating grid type arrangements of selected objects - * - * Authors: - * Bob Jamison ( based off trace dialog) - * John Cliff - * Other dudes from The Inkscape Organization - * Abhishek Sharma - * Declara Denis - * - * Copyright (C) 2004 Bob Jamison - * Copyright (C) 2004 John Cliff - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ -//#define DEBUG_GRID_ARRANGE 1 - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "ui/dialog/gridarrangetab.h" -#include //for GTK_RESPONSE* types -#include -#include -#include <2geom/transforms.h> - -#include "verbs.h" -#include "preferences.h" -#include "inkscape.h" -#include "desktop-handles.h" -#include "selection.h" -#include "document.h" -#include "document-undo.h" -#include "sp-item.h" -#include "widgets/icon.h" -#include "desktop.h" -//#include "sp-item-transform.h" FIXME -#include "ui/dialog/tile.h" // for Inkscape::UI::Dialog::ArrangeDialog - -/* - * Sort items by their x co-ordinates, taking account of y (keeps rows intact) - * - * <0 *elem1 goes before *elem2 - * 0 *elem1 == *elem2 - * >0 *elem1 goes after *elem2 - */ -int sp_compare_x_position(SPItem *first, SPItem *second) -{ - using Geom::X; - using Geom::Y; - - Geom::OptRect a = first->documentVisualBounds(); - Geom::OptRect b = second->documentVisualBounds(); - - if ( !a || !b ) { - // FIXME? - return 0; - } - - double const a_height = a->dimensions()[Y]; - double const b_height = b->dimensions()[Y]; - - bool a_in_b_vert = false; - if ((a->min()[Y] < b->min()[Y] + 0.1) && (a->min()[Y] > b->min()[Y] - b_height)) { - a_in_b_vert = true; - } else if ((b->min()[Y] < a->min()[Y] + 0.1) && (b->min()[Y] > a->min()[Y] - a_height)) { - a_in_b_vert = true; - } else if (b->min()[Y] == a->min()[Y]) { - a_in_b_vert = true; - } else { - a_in_b_vert = false; - } - - if (!a_in_b_vert) { - return -1; - } - if (a_in_b_vert && a->min()[X] > b->min()[X]) { - return 1; - } - if (a_in_b_vert && a->min()[X] < b->min()[X]) { - return -1; - } - return 0; -} - -/* - * Sort items by their y co-ordinates. - */ -int sp_compare_y_position(SPItem *first, SPItem *second) -{ - Geom::OptRect a = first->documentVisualBounds(); - Geom::OptRect b = second->documentVisualBounds(); - - if ( !a || !b ) { - // FIXME? - return 0; - } - - if (a->min()[Geom::Y] > b->min()[Geom::Y]) { - return 1; - } - if (a->min()[Geom::Y] < b->min()[Geom::Y]) { - return -1; - } - - return 0; -} - -namespace Inkscape { -namespace UI { -namespace Dialog { - - -//######################################################################### -//## E V E N T S -//######################################################################### - -/* - * - * This arranges the selection in a grid pattern. - * - */ - -void GridArrangeTab::arrange() -{ - - int cnt,row_cnt,col_cnt,a,row,col; - double grid_left,grid_top,col_width,row_height,paddingx,paddingy,width, height, new_x, new_y,cx,cy; - double total_col_width,total_row_height; - col_width = 0; - row_height = 0; - total_col_width=0; - total_row_height=0; - - // check for correct numbers in the row- and col-spinners - on_col_spinbutton_changed(); - on_row_spinbutton_changed(); - - // set padding to manual values - paddingx = XPadding.getValue("px"); - paddingy = YPadding.getValue("px"); - - std::vector row_heights; - std::vector col_widths; - std::vector row_ys; - std::vector col_xs; - - int NoOfCols = NoOfColsSpinner.get_value_as_int(); - int NoOfRows = NoOfRowsSpinner.get_value_as_int(); - - width = 0; - for (a=0;agetDesktop(); - sp_desktop_document(desktop)->ensureUpToDate(); - - Inkscape::Selection *selection = sp_desktop_selection (desktop); - const GSList *items = selection ? selection->itemList() : 0; - cnt=0; - for (; items != NULL; items = items->next) { - SPItem *item = SP_ITEM(items->data); - Geom::OptRect b = item->documentVisualBounds(); - if (!b) { - continue; - } - - width = b->dimensions()[Geom::X]; - height = b->dimensions()[Geom::Y]; - - cx = b->midpoint()[Geom::X]; - cy = b->midpoint()[Geom::Y]; - - if (b->min()[Geom::X] < grid_left) { - grid_left = b->min()[Geom::X]; - } - if (b->min()[Geom::Y] < grid_top) { - grid_top = b->min()[Geom::Y]; - } - if (width > col_width) { - col_width = width; - } - if (height > row_height) { - row_height = height; - } - } - - - // require the sorting done before we can calculate row heights etc. - - g_return_if_fail(selection); - const GSList *items2 = selection->itemList(); - GSList *rev = g_slist_copy((GSList *) items2); - GSList *sorted = NULL; - rev = g_slist_sort(rev, (GCompareFunc) sp_compare_y_position); - sorted = g_slist_sort(rev, (GCompareFunc) sp_compare_x_position); - - - // Calculate individual Row and Column sizes if necessary - - - cnt=0; - const GSList *sizes = sorted; - for (; sizes != NULL; sizes = sizes->next) { - SPItem *item = SP_ITEM(sizes->data); - Geom::OptRect b = item->documentVisualBounds(); - if (b) { - width = b->dimensions()[Geom::X]; - height = b->dimensions()[Geom::Y]; - if (width > col_widths[(cnt % NoOfCols)]) { - col_widths[(cnt % NoOfCols)] = width; - } - if (height > row_heights[(cnt / NoOfCols)]) { - row_heights[(cnt / NoOfCols)] = height; - } - } - - cnt++; - } - - - /// Make sure the top and left of the grid dont move by compensating for align values. - if (RowHeightButton.get_active()){ - grid_top = grid_top - (((row_height - row_heights[0]) / 2)*(VertAlign)); - } - if (ColumnWidthButton.get_active()){ - grid_left = grid_left - (((col_width - col_widths[0]) /2)*(HorizAlign)); - } - - #ifdef DEBUG_GRID_ARRANGE - g_print("\n cx = %f cy= %f gridleft=%f",cx,cy,grid_left); - #endif - - // Calculate total widths and heights, allowing for columns and rows non uniformly sized. - - if (ColumnWidthButton.get_active()){ - total_col_width = col_width * NoOfCols; - col_widths.clear(); - for (a=0;avisualBounds(); - // Fit to bbox, calculate padding between rows accordingly. - if ( sel_bbox && !SpaceManualRadioButton.get_active() ){ -#ifdef DEBUG_GRID_ARRANGE -g_print("\n row = %f col = %f selection x= %f selection y = %f", total_row_height,total_col_width, b.extent(Geom::X), b.extent(Geom::Y)); -#endif - paddingx = (sel_bbox->width() - total_col_width) / (NoOfCols -1); - paddingy = (sel_bbox->height() - total_row_height) / (NoOfRows -1); - } - -/* - Horizontal align - Left = 0 - Centre = 1 - Right = 2 - - Vertical align - Top = 0 - Middle = 1 - Bottom = 2 - - X position is calculated by taking the grids left co-ord, adding the distance to the column, - then adding 1/2 the spacing multiplied by the align variable above, - Y position likewise, takes the top of the grid, adds the y to the current row then adds the padding in to align it. - -*/ - - // Calculate row and column x and y coords required to allow for columns and rows which are non uniformly sized. - - for (a=0;adata); - sorted = sorted->next; - } - - for (; current_row != NULL; current_row = current_row->next) { - SPItem *item=SP_ITEM(current_row->data); - Inkscape::XML::Node *repr = item->getRepr(); - Geom::OptRect b = item->documentVisualBounds(); - Geom::Point min; - if (b) { - width = b->dimensions()[Geom::X]; - height = b->dimensions()[Geom::Y]; - min = b->min(); - } else { - width = height = 0; - min = Geom::Point(0, 0); - } - - row = cnt / NoOfCols; - col = cnt % NoOfCols; - - new_x = grid_left + (((col_widths[col] - width)/2)*HorizAlign) + col_xs[col]; - new_y = grid_top + (((row_heights[row] - height)/2)*VertAlign) + row_ys[row]; - - // signs are inverted between x and y due to y inversion - Geom::Point move = Geom::Point(new_x - min[Geom::X], min[Geom::Y] - new_y); - Geom::Affine const affine = Geom::Affine(Geom::Translate(move)); - item->set_i2d_affine(item->i2dt_affine() * affine); - item->doWriteTransform(repr, item->transform, NULL); - SP_OBJECT (current_row->data)->updateRepr(); - cnt +=1; - } - g_slist_free (current_row); - } - - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_SELECTION_ARRANGE, - _("Arrange in a grid")); - -} - - -//######################################################################### -//## E V E N T S -//######################################################################### - -/** - * changed value in # of columns spinbox. - */ -void GridArrangeTab::on_row_spinbutton_changed() -{ - // quit if run by the attr_changed listener - if (updating) { - return; - } - - // in turn, prevent listener from responding - updating = true; - SPDesktop *desktop = Parent->getDesktop(); - - Inkscape::Selection *selection = desktop ? desktop->selection : 0; - g_return_if_fail( selection ); - - GSList const *items = selection->itemList(); - int selcount = g_slist_length((GSList *)items); - - double PerCol = ceil(selcount / NoOfColsSpinner.get_value()); - NoOfRowsSpinner.set_value(PerCol); - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setDouble("/dialogs/gridtiler/NoOfCols", NoOfColsSpinner.get_value()); - updating=false; -} - -/** - * changed value in # of rows spinbox. - */ -void GridArrangeTab::on_col_spinbutton_changed() -{ - // quit if run by the attr_changed listener - if (updating) { - return; - } - - // in turn, prevent listener from responding - updating = true; - SPDesktop *desktop = Parent->getDesktop(); - Inkscape::Selection *selection = desktop ? desktop->selection : 0; - g_return_if_fail(selection); - - GSList const *items = selection->itemList(); - int selcount = g_slist_length((GSList *)items); - - double PerRow = ceil(selcount / NoOfRowsSpinner.get_value()); - NoOfColsSpinner.set_value(PerRow); - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setDouble("/dialogs/gridtiler/NoOfCols", PerRow); - - updating=false; -} - -/** - * changed value in x padding spinbox. - */ -void GridArrangeTab::on_xpad_spinbutton_changed() -{ - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setDouble("/dialogs/gridtiler/XPad", XPadding.getValue("px")); - -} - -/** - * changed value in y padding spinbox. - */ -void GridArrangeTab::on_ypad_spinbutton_changed() -{ - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setDouble("/dialogs/gridtiler/YPad", YPadding.getValue("px")); -} - - -/** - * checked/unchecked autosize Rows button. - */ -void GridArrangeTab::on_RowSize_checkbutton_changed() -{ - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - if (RowHeightButton.get_active()) { - prefs->setDouble("/dialogs/gridtiler/AutoRowSize", 20); - } else { - prefs->setDouble("/dialogs/gridtiler/AutoRowSize", -20); - } - RowHeightBox.set_sensitive ( !RowHeightButton.get_active()); -} - -/** - * checked/unchecked autosize Rows button. - */ -void GridArrangeTab::on_ColSize_checkbutton_changed() -{ - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - if (ColumnWidthButton.get_active()) { - prefs->setDouble("/dialogs/gridtiler/AutoColSize", 20); - } else { - prefs->setDouble("/dialogs/gridtiler/AutoColSize", -20); - } - ColumnWidthBox.set_sensitive ( !ColumnWidthButton.get_active()); -} - -/** - * changed value in columns spinbox. - */ -void GridArrangeTab::on_rowSize_spinbutton_changed() -{ - // quit if run by the attr_changed listener - if (updating) { - return; - } - - // in turn, prevent listener from responding - updating = true; - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setDouble("/dialogs/gridtiler/RowHeight", RowHeightSpinner.get_value()); - updating=false; - -} - -/** - * changed value in rows spinbox. - */ -void GridArrangeTab::on_colSize_spinbutton_changed() -{ - // quit if run by the attr_changed listener - if (updating) { - return; - } - - // in turn, prevent listener from responding - updating = true; - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setDouble("/dialogs/gridtiler/ColWidth", ColumnWidthSpinner.get_value()); - updating=false; - -} - -/** - * changed Radio button in Spacing group. - */ -void GridArrangeTab::Spacing_button_changed() -{ - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - if (SpaceManualRadioButton.get_active()) { - prefs->setDouble("/dialogs/gridtiler/SpacingType", 20); - } else { - prefs->setDouble("/dialogs/gridtiler/SpacingType", -20); - } - - XPadding.set_sensitive ( SpaceManualRadioButton.get_active()); - YPadding.set_sensitive ( SpaceManualRadioButton.get_active()); -} - -/** - * changed Anchor selection widget. - */ -void GridArrangeTab::Align_changed() -{ - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - VertAlign = AlignmentSelector.getVerticalAlignment(); - prefs->setInt("/dialogs/gridtiler/VertAlign", VertAlign); - HorizAlign = AlignmentSelector.getHorizontalAlignment(); - prefs->setInt("/dialogs/gridtiler/HorizAlign", HorizAlign); -} - -/** - * Desktop selection changed - */ -void GridArrangeTab::updateSelection() -{ - // quit if run by the attr_changed listener - if (updating) { - return; - } - - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - // in turn, prevent listener from responding - updating = true; - SPDesktop *desktop = Parent->getDesktop(); - Inkscape::Selection *selection = desktop ? desktop->selection : 0; - GSList const *items = selection ? selection->itemList() : 0; - - if (items) { - int selcount = g_slist_length((GSList *)items); - - if (NoOfColsSpinner.get_value() > 1 && NoOfRowsSpinner.get_value() > 1){ - // Update the number of rows assuming number of columns wanted remains same. - double NoOfRows = ceil(selcount / NoOfColsSpinner.get_value()); - NoOfRowsSpinner.set_value(NoOfRows); - - // if the selection has less than the number set for one row, reduce it appropriately - if (selcount < NoOfColsSpinner.get_value()) { - double NoOfCols = ceil(selcount / NoOfRowsSpinner.get_value()); - NoOfColsSpinner.set_value(NoOfCols); - prefs->setInt("/dialogs/gridtiler/NoOfCols", NoOfCols); - } - } else { - double PerRow = ceil(sqrt(selcount)); - double PerCol = ceil(sqrt(selcount)); - NoOfRowsSpinner.set_value(PerRow); - NoOfColsSpinner.set_value(PerCol); - prefs->setInt("/dialogs/gridtiler/NoOfCols", static_cast(PerCol)); - } - } - - updating = false; -} - - - -/*########################## -## Experimental -##########################*/ - -static void updateSelectionCallback(Inkscape::Application */*inkscape*/, Inkscape::Selection */*selection*/, GridArrangeTab *dlg) -{ - dlg->updateSelection(); -} - - -//######################################################################### -//## C O N S T R U C T O R / D E S T R U C T O R -//######################################################################### -/** - * Constructor - */ -GridArrangeTab::GridArrangeTab(ArrangeDialog *parent) - : Parent(parent), - XPadding(_("X:"), _("Horizontal spacing between columns."), UNIT_TYPE_LINEAR, "", "object-columns"), - YPadding(_("Y:"), _("Vertical spacing between rows."), XPadding, "", "object-rows") -{ - // bool used by spin button callbacks to stop loops where they change each other. - updating = false; - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - - // could not do this in gtkmm - there's no Gtk::SizeGroup public constructor (!) - GtkSizeGroup *_col1 = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); - GtkSizeGroup *_col2 = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); - GtkSizeGroup *_col3 = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); - - { - // Selection Change signal - g_signal_connect ( G_OBJECT (INKSCAPE), "change_selection", G_CALLBACK (updateSelectionCallback), this); - } - - Gtk::Box *contents = this; - -#define MARGIN 2 - - //##Set up the panel - - SPDesktop *desktop = Parent->getDesktop(); - - Inkscape::Selection *selection = desktop ? desktop->selection : 0; - g_return_if_fail( selection ); - int selcount = 1; - if (!selection->isEmpty()) { - GSList const *items = selection->itemList(); - selcount = g_slist_length((GSList *)items); - } - - - /*#### Number of Rows ####*/ - - double PerRow = ceil(sqrt(selcount)); - double PerCol = ceil(sqrt(selcount)); - - #ifdef DEBUG_GRID_ARRANGE - g_print("/n PerRox = %f PerCol = %f selcount = %d",PerRow,PerCol,selcount); - #endif - - NoOfRowsLabel.set_text_with_mnemonic(_("_Rows:")); - NoOfRowsLabel.set_mnemonic_widget(NoOfRowsSpinner); - NoOfRowsBox.pack_start(NoOfRowsLabel, false, false, MARGIN); - - NoOfRowsSpinner.set_digits(0); - NoOfRowsSpinner.set_increments(1, 0); - NoOfRowsSpinner.set_range(1.0, 10000.0); - NoOfRowsSpinner.set_value(PerCol); - NoOfRowsSpinner.signal_changed().connect(sigc::mem_fun(*this, &GridArrangeTab::on_col_spinbutton_changed)); - NoOfRowsSpinner.set_tooltip_text(_("Number of rows")); - NoOfRowsBox.pack_start(NoOfRowsSpinner, false, false, MARGIN); - gtk_size_group_add_widget(_col1, (GtkWidget *) NoOfRowsBox.gobj()); - - RowHeightButton.set_label(_("Equal _height")); - RowHeightButton.set_use_underline(true); - double AutoRow = prefs->getDouble("/dialogs/gridtiler/AutoRowSize", 15); - if (AutoRow>0) - AutoRowSize=true; - else - AutoRowSize=false; - RowHeightButton.set_active(AutoRowSize); - - NoOfRowsBox.pack_start(RowHeightButton, false, false, MARGIN); - - RowHeightButton.set_tooltip_text(_("If not set, each row has the height of the tallest object in it")); - RowHeightButton.signal_toggled().connect(sigc::mem_fun(*this, &GridArrangeTab::on_RowSize_checkbutton_changed)); - - SpinsHBox.pack_start(NoOfRowsBox, false, false, MARGIN); - - - /*#### Label for X ####*/ - padXByYLabel.set_label(" "); - XByYLabelVBox.pack_start(padXByYLabel, false, false, MARGIN); - XByYLabel.set_markup(" × "); - XByYLabelVBox.pack_start(XByYLabel, false, false, MARGIN); - SpinsHBox.pack_start(XByYLabelVBox, false, false, MARGIN); - gtk_size_group_add_widget(_col2, (GtkWidget *) XByYLabelVBox.gobj()); - - /*#### Number of columns ####*/ - - NoOfColsLabel.set_text_with_mnemonic(_("_Columns:")); - NoOfColsLabel.set_mnemonic_widget(NoOfColsSpinner); - NoOfColsBox.pack_start(NoOfColsLabel, false, false, MARGIN); - - NoOfColsSpinner.set_digits(0); - NoOfColsSpinner.set_increments(1, 0); - NoOfColsSpinner.set_range(1.0, 10000.0); - NoOfColsSpinner.set_value(PerRow); - NoOfColsSpinner.signal_changed().connect(sigc::mem_fun(*this, &GridArrangeTab::on_row_spinbutton_changed)); - NoOfColsSpinner.set_tooltip_text(_("Number of columns")); - NoOfColsBox.pack_start(NoOfColsSpinner, false, false, MARGIN); - gtk_size_group_add_widget(_col3, (GtkWidget *) NoOfColsBox.gobj()); - - ColumnWidthButton.set_label(_("Equal _width")); - ColumnWidthButton.set_use_underline(true); - double AutoCol = prefs->getDouble("/dialogs/gridtiler/AutoColSize", 15); - if (AutoCol>0) - AutoColSize=true; - else - AutoColSize=false; - ColumnWidthButton.set_active(AutoColSize); - NoOfColsBox.pack_start(ColumnWidthButton, false, false, MARGIN); - - ColumnWidthButton.set_tooltip_text(_("If not set, each column has the width of the widest object in it")); - ColumnWidthButton.signal_toggled().connect(sigc::mem_fun(*this, &GridArrangeTab::on_ColSize_checkbutton_changed)); - - SpinsHBox.pack_start(NoOfColsBox, false, false, MARGIN); - - TileBox.pack_start(SpinsHBox, false, false, MARGIN); - - VertAlign = prefs->getInt("/dialogs/gridtiler/VertAlign", 1); - HorizAlign = prefs->getInt("/dialogs/gridtiler/HorizAlign", 1); - - // Anchor selection widget - AlignLabel.set_label("Alignment:"); - AlignLabel.set_alignment(Gtk::ALIGN_START, Gtk::ALIGN_CENTER); - AlignmentSelector.setAlignment(HorizAlign, VertAlign); - AlignmentSelector.on_selectionChanged().connect(sigc::mem_fun(*this, &GridArrangeTab::Align_changed)); - TileBox.pack_start(AlignLabel, false, false, MARGIN); - TileBox.pack_start(AlignmentSelector, true, false, MARGIN); - - { - /*#### Radio buttons to control spacing manually or to fit selection bbox ####*/ - SpaceByBBoxRadioButton.set_label(_("_Fit into selection box")); - SpaceByBBoxRadioButton.set_use_underline (true); - SpaceByBBoxRadioButton.signal_toggled().connect(sigc::mem_fun(*this, &GridArrangeTab::Spacing_button_changed)); - SpacingGroup = SpaceByBBoxRadioButton.get_group(); - - SpacingVBox.pack_start(SpaceByBBoxRadioButton, false, false, MARGIN); - - SpaceManualRadioButton.set_label(_("_Set spacing:")); - SpaceManualRadioButton.set_use_underline (true); - SpaceManualRadioButton.set_group(SpacingGroup); - SpaceManualRadioButton.signal_toggled().connect(sigc::mem_fun(*this, &GridArrangeTab::Spacing_button_changed)); - SpacingVBox.pack_start(SpaceManualRadioButton, false, false, MARGIN); - - TileBox.pack_start(SpacingVBox, false, false, MARGIN); - } - - { - /*#### Padding ####*/ - - YPadding.setDigits(5); - YPadding.setIncrements(0.2, 0); - YPadding.setRange(-10000, 10000); - double yPad = prefs->getDouble("/dialogs/gridtiler/YPad", 15); - YPadding.setValue(yPad, "px"); - YPadding.signal_value_changed().connect(sigc::mem_fun(*this, &GridArrangeTab::on_ypad_spinbutton_changed)); - - XPadding.setDigits(5); - XPadding.setIncrements(0.2, 0); - XPadding.setRange(-10000, 10000); - double xPad = prefs->getDouble("/dialogs/gridtiler/XPad", 15); - XPadding.setValue(xPad, "px"); - - XPadding.signal_value_changed().connect(sigc::mem_fun(*this, &GridArrangeTab::on_xpad_spinbutton_changed)); - } - TileBox.pack_start(XPadding, false, false, MARGIN); - TileBox.pack_start(YPadding, false, false, MARGIN); - - contents->pack_start(TileBox); - - double SpacingType = prefs->getDouble("/dialogs/gridtiler/SpacingType", 15); - if (SpacingType>0) { - ManualSpacing=true; - } else { - ManualSpacing=false; - } - SpaceManualRadioButton.set_active(ManualSpacing); - SpaceByBBoxRadioButton.set_active(!ManualSpacing); - XPadding.set_sensitive (ManualSpacing); - YPadding.set_sensitive (ManualSpacing); - - //## The OK button FIXME - /*TileOkButton = addResponseButton(C_("Rows and columns dialog","_Arrange"), GTK_RESPONSE_APPLY); - TileOkButton->set_use_underline(true); - TileOkButton->set_tooltip_text(_("Arrange selected objects"));*/ - - show_all_children(); -} - -} //namespace Dialog -} //namespace UI -} //namespace Inkscape - -/* - 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/gridarrangetab.h b/src/ui/dialog/gridarrangetab.h deleted file mode 100644 index 16780e55f..000000000 --- a/src/ui/dialog/gridarrangetab.h +++ /dev/null @@ -1,147 +0,0 @@ -/** - * @brief Arranges Objects into a Grid - */ -/* Authors: - * Bob Jamison ( based off trace dialog) - * John Cliff - * Other dudes from The Inkscape Organization - * Abhishek Sharma - * Declara Denis - * - * Copyright (C) 2004 Bob Jamison - * Copyright (C) 2004 John Cliff - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#ifndef INKSCAPE_UI_DIALOG_GRID_ARRANGE_TAB_H -#define INKSCAPE_UI_DIALOG_GRID_ARRANGE_TAB_H - -#include - -#include "ui/dialog/arrangetab.h" - -#include "ui/widget/anchor-selector.h" -#include "ui/widget/scalar-unit.h" -#include "ui/widget/spinbutton.h" - -namespace Inkscape { -namespace UI { -namespace Dialog { - -class ArrangeDialog; - -/** - * Dialog for tiling an object - */ -class GridArrangeTab : public ArrangeTab { -public: - GridArrangeTab(ArrangeDialog *parent); - virtual ~GridArrangeTab() {}; - - /** - * Do the actual work - */ - virtual void arrange(); - - /** - * Respond to selection change - */ - void updateSelection(); - - // Callbacks from spinbuttons - void on_row_spinbutton_changed(); - void on_col_spinbutton_changed(); - void on_xpad_spinbutton_changed(); - void on_ypad_spinbutton_changed(); - void on_RowSize_checkbutton_changed(); - void on_ColSize_checkbutton_changed(); - void on_rowSize_spinbutton_changed(); - void on_colSize_spinbutton_changed(); - void Spacing_button_changed(); - void Align_changed(); - - -private: - GridArrangeTab(GridArrangeTab const &d); // no copy - void operator=(GridArrangeTab const &d); // no assign - - ArrangeDialog *Parent; - - bool userHidden; - bool updating; - - Gtk::VBox TileBox; - Gtk::Button *TileOkButton; - Gtk::Button *TileCancelButton; - - // Number selected label - Gtk::Label SelectionContentsLabel; - - - Gtk::HBox AlignHBox; - Gtk::HBox SpinsHBox; - - // Number per Row - Gtk::VBox NoOfColsBox; - Gtk::Label NoOfColsLabel; - Inkscape::UI::Widget::SpinButton NoOfColsSpinner; - bool AutoRowSize; - Gtk::CheckButton RowHeightButton; - - Gtk::VBox XByYLabelVBox; - Gtk::Label padXByYLabel; - Gtk::Label XByYLabel; - - // Number per Column - Gtk::VBox NoOfRowsBox; - Gtk::Label NoOfRowsLabel; - Inkscape::UI::Widget::SpinButton NoOfRowsSpinner; - bool AutoColSize; - Gtk::CheckButton ColumnWidthButton; - - // Alignment - Gtk::Label AlignLabel; - AnchorSelector AlignmentSelector; - double VertAlign; - double HorizAlign; - - Inkscape::UI::Widget::ScalarUnit XPadding; - Inkscape::UI::Widget::ScalarUnit YPadding; - - // BBox or manual spacing - Gtk::VBox SpacingVBox; - Gtk::RadioButtonGroup SpacingGroup; - Gtk::RadioButton SpaceByBBoxRadioButton; - Gtk::RadioButton SpaceManualRadioButton; - bool ManualSpacing; - - // Row height - Gtk::VBox RowHeightVBox; - Gtk::HBox RowHeightBox; - Gtk::Label RowHeightLabel; - Inkscape::UI::Widget::SpinButton RowHeightSpinner; - - // Column width - Gtk::VBox ColumnWidthVBox; - Gtk::HBox ColumnWidthBox; - Gtk::Label ColumnWidthLabel; - Inkscape::UI::Widget::SpinButton ColumnWidthSpinner; -}; - -} //namespace Dialog -} //namespace UI -} //namespace Inkscape - -#endif /* INKSCAPE_UI_DIALOG_GRID_ARRANGE_TAB_H */ - -/* - 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/polar-arrange-tab.cpp b/src/ui/dialog/polar-arrange-tab.cpp new file mode 100644 index 000000000..a1df794a5 --- /dev/null +++ b/src/ui/dialog/polar-arrange-tab.cpp @@ -0,0 +1,414 @@ +/** + * @brief Arranges Objects into a Circle/Ellipse + */ +/* Authors: + * Declara Denis + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include <2geom/transforms.h> +#include + +#include "ui/dialog/polar-arrange-tab.h" +#include "ui/dialog/tile.h" + +#include "verbs.h" +#include "preferences.h" +#include "inkscape.h" +#include "desktop-handles.h" +#include "selection.h" +#include "document.h" +#include "document-undo.h" +#include "sp-item.h" +#include "widgets/icon.h" +#include "desktop.h" +#include "sp-ellipse.h" +#include "sp-item-transform.h" + +namespace Inkscape { +namespace UI { +namespace Dialog { + +PolarArrangeTab::PolarArrangeTab(ArrangeDialog *parent_) + : parent(parent_), + parametersTable(3, 3, false), + centerY("", "Y coordinate of the center", UNIT_TYPE_LINEAR), + centerX("", "X coordinate of the center", centerY), + radiusY("", "Y coordinate of the radius", UNIT_TYPE_LINEAR), + radiusX("", "X coordinate of the radius", radiusY), + angleY("", "Starting angle", UNIT_TYPE_RADIAL), + angleX("", "End angle", angleY) +{ + anchorPointLabel.set_text(C_("Polar arrange tab", "Anchor point:")); + anchorPointLabel.set_alignment(Gtk::ALIGN_START); + pack_start(anchorPointLabel, false, false); + + anchorBoundingBoxRadio.set_label(C_("Polar arrange tab", "Object's bounding box:")); + anchorRadioGroup = anchorBoundingBoxRadio.get_group(); + anchorBoundingBoxRadio.signal_toggled().connect(sigc::mem_fun(*this, &PolarArrangeTab::on_anchor_radio_changed)); + pack_start(anchorBoundingBoxRadio, false, false); + + pack_start(anchorSelector, false, false); + + anchorObjectPivotRadio.set_label(C_("Polar arrange tab", "Object's rotational center")); + anchorObjectPivotRadio.set_group(anchorRadioGroup); + anchorObjectPivotRadio.signal_toggled().connect(sigc::mem_fun(*this, &PolarArrangeTab::on_anchor_radio_changed)); + pack_start(anchorObjectPivotRadio, false, false); + + arrangeOnLabel.set_text(C_("Polar arrange tab", "Arrange on:")); + arrangeOnLabel.set_alignment(Gtk::ALIGN_START); + pack_start(arrangeOnLabel, false, false); + + arrangeOnFirstCircleRadio.set_label(C_("Polar arrange tab", "First selected circle/ellipse/arc")); + arrangeRadioGroup = arrangeOnFirstCircleRadio.get_group(); + arrangeOnFirstCircleRadio.signal_toggled().connect(sigc::mem_fun(*this, &PolarArrangeTab::on_arrange_radio_changed)); + pack_start(arrangeOnFirstCircleRadio, false, false); + + arrangeOnLastCircleRadio.set_label(C_("Polar arrange tab", "Last selected circle/ellipse/arc")); + arrangeOnLastCircleRadio.set_group(arrangeRadioGroup); + arrangeOnLastCircleRadio.signal_toggled().connect(sigc::mem_fun(*this, &PolarArrangeTab::on_arrange_radio_changed)); + pack_start(arrangeOnLastCircleRadio, false, false); + + arrangeOnParametersRadio.set_label(C_("Polar arrange tab", "Parameterized:")); + arrangeOnParametersRadio.set_group(arrangeRadioGroup); + arrangeOnParametersRadio.signal_toggled().connect(sigc::mem_fun(*this, &PolarArrangeTab::on_arrange_radio_changed)); + pack_start(arrangeOnParametersRadio, false, false); + + //FIXME: Objects in grid do not line up properly! + centerLabel.set_text(_("Center X/Y:")); + parametersTable.attach(centerLabel, 0, 1, 0, 1, Gtk::FILL); + centerX.setDigits(2); + //centerX.set_size_request(60, -1); + centerX.setIncrements(0.2, 0); + centerX.setRange(-10000, 10000); + centerX.setValue(0, "px"); + centerY.setDigits(2); + //centerY.set_size_request(120, -1); + centerY.setIncrements(0.2, 0); + centerY.setRange(-10000, 10000); + centerY.setValue(0, "px"); + parametersTable.attach(centerX, 1, 2, 0, 1, Gtk::FILL); + parametersTable.attach(centerY, 2, 3, 0, 1, Gtk::FILL); + + radiusLabel.set_text(_("Radius X/Y:")); + parametersTable.attach(radiusLabel, 0, 1, 1, 2, Gtk::FILL); + radiusX.setDigits(2); + //radiusX.set_size_request(60, -1); + radiusX.setIncrements(0.2, 0); + radiusX.setRange(0.001, 10000); + radiusX.setValue(100, "px"); + radiusY.setDigits(2); + //radiusY.set_size_request(120, -1); + radiusY.setIncrements(0.2, 0); + radiusY.setRange(0.001, 10000); + radiusY.setValue(100, "px"); + parametersTable.attach(radiusX, 1, 2, 1, 2, Gtk::FILL); + parametersTable.attach(radiusY, 2, 3, 1, 2, Gtk::FILL); + + angleLabel.set_text(_("Angle X/Y:")); + parametersTable.attach(angleLabel, 0, 1, 2, 3, Gtk::FILL); + angleX.setDigits(2); + //angleX.set_size_request(60, -1); + angleX.setIncrements(0.2, 0); + angleX.setRange(-10000, 10000); + angleX.setValue(0, "°"); + angleY.setDigits(2); + //angleY.set_size_request(120, -1); + angleY.setIncrements(0.2, 0); + angleY.setRange(-10000, 10000); + angleY.setValue(180, "°"); + parametersTable.attach(angleX, 1, 2, 2, 3, Gtk::FILL); + parametersTable.attach(angleY, 2, 3, 2, 3, Gtk::FILL); + pack_start(parametersTable, false, false); + + rotateObjectsCheckBox.set_label(_("Rotate objects")); + rotateObjectsCheckBox.set_active(true); + pack_start(rotateObjectsCheckBox, false, false); + + centerX.set_sensitive(false); + centerY.set_sensitive(false); + angleX.set_sensitive(false); + angleY.set_sensitive(false); + radiusX.set_sensitive(false); + radiusY.set_sensitive(false); +} + +/** + * This function rotates an item around a given point by a given amount + * @param item item to rotate + * @param center center of the rotation to perform + * @param rotation amount to rotate the object by + */ +void rotateAround(SPItem *item, Geom::Point center, Geom::Rotate const &rotation) +{ + Geom::Translate const s(center); + Geom::Affine affine = Geom::Affine(s).inverse() * Geom::Affine(rotation) * Geom::Affine(s); + + // Save old center + center = item->getCenter(); + + item->set_i2d_affine(item->i2dt_affine() * affine); + item->doWriteTransform(item->getRepr(), item->transform); + + if(item->isCenterSet()) + { + item->setCenter(center * affine); + item->updateRepr(); + } +} + +/** + * Calculates the angle at which to put an object given the total amount + * of objects, the index of the objects as well as the arc start and end + * points + * @param arcBegin angle at which the arc begins + * @param arcEnd angle at which the arc ends + * @param count number of objects in the selection + * @param n index of the object in the selection + */ +float calcAngle(float arcBegin, float arcEnd, int count, int n) +{ + float arcLength = arcEnd - arcBegin; + float delta = std::abs(std::abs(arcLength) - 2*M_PI); + if(delta > 0.01) count--; // If not a complete circle, put an object also at the extremes of the arc; + + float angle = n / (float)count; + // Normalize for arcLength: + angle = angle * arcLength; + angle += arcBegin; + + return angle; +} + +/** + * Calculates the point at which the object needs to be, given the center of the ellipse, + * it's radius (x and y), as well as the angle + */ +Geom::Point calcPoint(float cx, float cy, float rx, float ry, float angle) +{ + return Geom::Point(cx + cos(angle) * rx, cy + sin(angle) * ry); +} + +/** + * Returns the selected anchor point in document coordinates. If anchor + * is 0 to 8, then a bounding box point has been choosen. If it is 9 however + * the rotational center is chosen. + * @todo still using a hack to get the real coordinate space (subtracting document height + * and inverting axes) + */ +Geom::Point getAnchorPoint(int anchor, SPItem *item) +{ + Geom::Point source; + + Geom::OptRect bbox = item->documentVisualBounds(); + + switch(anchor) + { + case 0: // Top - Left + case 3: // Middle - Left + case 6: // Bottom - Left + source[0] = bbox->min()[Geom::X]; + break; + case 1: // Top - Middle + case 4: // Middle - Middle + case 7: // Bottom - Middle + source[0] = (bbox->min()[Geom::X] + bbox->max()[Geom::X]) / 2.0f; + break; + case 2: // Top - Right + case 5: // Middle - Right + case 8: // Bottom - Right + source[0] = bbox->max()[Geom::X]; + break; + }; + + switch(anchor) + { + case 0: // Top - Left + case 1: // Top - Middle + case 2: // Top - Right + source[1] = bbox->min()[Geom::Y]; + break; + case 3: // Middle - Left + case 4: // Middle - Middle + case 5: // Middle - Right + source[1] = (bbox->min()[Geom::Y] + bbox->max()[Geom::Y]) / 2.0f; + break; + case 6: // Bottom - Left + case 7: // Bottom - Middle + case 8: // Bottom - Right + source[1] = bbox->max()[Geom::Y]; + break; + }; + + // If using center + if(anchor == 9) + source = item->getCenter(); + else + { + // FIXME: + source[1] -= item->document->getHeight(); + source[1] *= -1; + } + + return source; +} + +void moveToPoint(int anchor, SPItem *item, Geom::Point p) +{ + sp_item_move_rel(item, Geom::Translate(p - getAnchorPoint(anchor, item))); +} + +void PolarArrangeTab::arrange() +{ + std::cout << "PolarArrangeTab::arrange()" << std::endl; + + Inkscape::Selection *selection = sp_desktop_selection(parent->getDesktop()); + const GSList *items, *tmp; + tmp = items = selection->itemList(); + SPGenericEllipse *referenceEllipse = NULL; // Last ellipse in selection + + bool arrangeOnEllipse = !arrangeOnParametersRadio.get_active(); + bool arrangeOnFirstEllipse = arrangeOnEllipse && arrangeOnFirstCircleRadio.get_active(); + + int count = 0; + while(tmp) + { + if(arrangeOnEllipse) + { + SPItem *item = SP_ITEM(tmp->data); + + if(arrangeOnFirstEllipse) + { + // The first selected ellipse is actually the last one in the list + if(SP_IS_GENERICELLIPSE(item)) + referenceEllipse = SP_GENERICELLIPSE(item); + } else { + // The last selected ellipse is actually the first in list + if(SP_IS_GENERICELLIPSE(item) && referenceEllipse == NULL) + referenceEllipse = SP_GENERICELLIPSE(item); + } + } + tmp = tmp->next; + ++count; + } + + float cx, cy; // Center of the ellipse + float rx, ry; // Radiuses of the ellipse in x and y direction + float arcBeg, arcEnd; // begin and end angles for arcs + Geom::Affine transformation; // Any additional transformation to apply to the objects + + if(arrangeOnEllipse) + { + if(referenceEllipse == NULL) + { + Gtk::MessageDialog dialog(_("Couldn't find an ellipse in selection"), false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_CLOSE, true); + dialog.run(); + return; + } else { + cx = referenceEllipse->cx.value; + cy = referenceEllipse->cy.value; + rx = referenceEllipse->rx.value; + ry = referenceEllipse->ry.value; + arcBeg = referenceEllipse->start; + arcEnd = referenceEllipse->end; + + std::cout << "Arc: " << arcBeg << ", " << arcEnd << std::endl; + transformation = referenceEllipse->i2dt_affine(); + + // We decrement the count by 1 as we are not going to lay + // out the reference ellipse + --count; + } + + } else { + // Read options from UI + cx = centerX.getValue("px"); + cy = centerY.getValue("px"); + rx = radiusX.getValue("px"); + ry = radiusY.getValue("px"); + arcBeg = angleX.getValue("rad"); + arcEnd = angleY.getValue("rad"); + transformation.setIdentity(); + referenceEllipse = NULL; + } + + int anchor = 9; + if(anchorBoundingBoxRadio.get_active()) + { + anchor = anchorSelector.getHorizontalAlignment() + + anchorSelector.getVerticalAlignment() * 3; + } + + Geom::Point realCenter = Geom::Point(cx, cy) * transformation; + + tmp = items; + int i = 0; + while(tmp) + { + SPItem *item = SP_ITEM(tmp->data); + + // Ignore the reference ellipse if any + if(item != referenceEllipse) + { + float angle = calcAngle(arcBeg, arcEnd, count, i); + Geom::Point newLocation = calcPoint(cx, cy, rx, ry, angle) * transformation; + + moveToPoint(anchor, item, newLocation); + + if(rotateObjectsCheckBox.get_active()) { + // Calculate the angle by which to rotate each object + angle = -atan2f(newLocation.x() - realCenter.x(), newLocation.y() - realCenter.y()); + rotateAround(item, newLocation, Geom::Rotate(angle)); + } + + std::cout << "object " << i << " out of " << count << ": " << angle << std::endl; + + ++i; + } + tmp = tmp->next; + } + + DocumentUndo::done(sp_desktop_document(parent->getDesktop()), SP_VERB_SELECTION_ARRANGE, + _("Arrange on ellipse")); +} + +void PolarArrangeTab::updateSelection() +{ +} + +void PolarArrangeTab::on_arrange_radio_changed() +{ + bool arrangeParametric = arrangeOnParametersRadio.get_active(); + + centerX.set_sensitive(arrangeParametric); + centerY.set_sensitive(arrangeParametric); + + angleX.set_sensitive(arrangeParametric); + angleY.set_sensitive(arrangeParametric); + + radiusX.set_sensitive(arrangeParametric); + radiusY.set_sensitive(arrangeParametric); +} + +void PolarArrangeTab::on_anchor_radio_changed() +{ + bool anchorBoundingBox = anchorBoundingBoxRadio.get_active(); + + anchorSelector.set_sensitive(anchorBoundingBox); +} + +} //namespace Dialog +} //namespace UI +} //namespace Inkscape + +/* + 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/polar-arrange-tab.h b/src/ui/dialog/polar-arrange-tab.h new file mode 100644 index 000000000..e62ebd76b --- /dev/null +++ b/src/ui/dialog/polar-arrange-tab.h @@ -0,0 +1,87 @@ +/** + * @brief Arranges Objects into a Circle/Ellipse + */ +/* Authors: + * Declara Denis + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#ifndef INKSCAPE_UI_DIALOG_POLAR_ARRANGE_TAB_H +#define INKSCAPE_UI_DIALOG_POLAR_ARRANGE_TAB_H + +#include + +#include "ui/dialog/arrangetab.h" + +#include "ui/widget/anchor-selector.h" +#include "ui/widget/scalar-unit.h" + +namespace Inkscape { +namespace UI { +namespace Dialog { + +class ArrangeDialog; + +class PolarArrangeTab : public ArrangeTab { +public: + PolarArrangeTab(ArrangeDialog *parent_); + virtual ~PolarArrangeTab() {}; + + /** + * Do the actual work + */ + virtual void arrange(); + + /** + * Respond to selection change + */ + void updateSelection(); + + void on_anchor_radio_changed(); + void on_arrange_radio_changed(); + +private: + PolarArrangeTab(PolarArrangeTab const &d); // no copy + void operator=(PolarArrangeTab const &d); // no assign + + ArrangeDialog *parent; + + Gtk::Label anchorPointLabel; + + Gtk::RadioButtonGroup anchorRadioGroup; + Gtk::RadioButton anchorBoundingBoxRadio; + Gtk::RadioButton anchorObjectPivotRadio; + Inkscape::UI::Widget::AnchorSelector anchorSelector; + + Gtk::Label arrangeOnLabel; + + Gtk::RadioButtonGroup arrangeRadioGroup; + Gtk::RadioButton arrangeOnFirstCircleRadio; + Gtk::RadioButton arrangeOnLastCircleRadio; + Gtk::RadioButton arrangeOnParametersRadio; + + Gtk::Table parametersTable; + + Gtk::Label centerLabel; + Inkscape::UI::Widget::ScalarUnit centerY; + Inkscape::UI::Widget::ScalarUnit centerX; + + Gtk::Label radiusLabel; + Inkscape::UI::Widget::ScalarUnit radiusY; + Inkscape::UI::Widget::ScalarUnit radiusX; + + Gtk::Label angleLabel; + Inkscape::UI::Widget::ScalarUnit angleY; + Inkscape::UI::Widget::ScalarUnit angleX; + + Gtk::CheckButton rotateObjectsCheckBox; + + +}; + +} //namespace Dialog +} //namespace UI +} //namespace Inkscape + +#endif /* INKSCAPE_UI_DIALOG_POLAR_ARRANGE_TAB_H */ diff --git a/src/ui/dialog/polararrangetab.cpp b/src/ui/dialog/polararrangetab.cpp deleted file mode 100644 index 6968be35a..000000000 --- a/src/ui/dialog/polararrangetab.cpp +++ /dev/null @@ -1,414 +0,0 @@ -/** - * @brief Arranges Objects into a Circle/Ellipse - */ -/* Authors: - * Declara Denis - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include <2geom/transforms.h> -#include - -#include "ui/dialog/polararrangetab.h" -#include "ui/dialog/tile.h" - -#include "verbs.h" -#include "preferences.h" -#include "inkscape.h" -#include "desktop-handles.h" -#include "selection.h" -#include "document.h" -#include "document-undo.h" -#include "sp-item.h" -#include "widgets/icon.h" -#include "desktop.h" -#include "sp-ellipse.h" -#include "sp-item-transform.h" - -namespace Inkscape { -namespace UI { -namespace Dialog { - -PolarArrangeTab::PolarArrangeTab(ArrangeDialog *parent_) - : parent(parent_), - parametersTable(3, 3, false), - centerY("", "Y coordinate of the center", UNIT_TYPE_LINEAR), - centerX("", "X coordinate of the center", centerY), - radiusY("", "Y coordinate of the radius", UNIT_TYPE_LINEAR), - radiusX("", "X coordinate of the radius", radiusY), - angleY("", "Starting angle", UNIT_TYPE_RADIAL), - angleX("", "End angle", angleY) -{ - anchorPointLabel.set_text(C_("Polar arrange tab", "Anchor point:")); - anchorPointLabel.set_alignment(Gtk::ALIGN_START); - pack_start(anchorPointLabel, false, false); - - anchorBoundingBoxRadio.set_label(C_("Polar arrange tab", "Object's bounding box:")); - anchorRadioGroup = anchorBoundingBoxRadio.get_group(); - anchorBoundingBoxRadio.signal_toggled().connect(sigc::mem_fun(*this, &PolarArrangeTab::on_anchor_radio_changed)); - pack_start(anchorBoundingBoxRadio, false, false); - - pack_start(anchorSelector, false, false); - - anchorObjectPivotRadio.set_label(C_("Polar arrange tab", "Object's rotational center")); - anchorObjectPivotRadio.set_group(anchorRadioGroup); - anchorObjectPivotRadio.signal_toggled().connect(sigc::mem_fun(*this, &PolarArrangeTab::on_anchor_radio_changed)); - pack_start(anchorObjectPivotRadio, false, false); - - arrangeOnLabel.set_text(C_("Polar arrange tab", "Arrange on:")); - arrangeOnLabel.set_alignment(Gtk::ALIGN_START); - pack_start(arrangeOnLabel, false, false); - - arrangeOnFirstCircleRadio.set_label(C_("Polar arrange tab", "First selected circle/ellipse/arc")); - arrangeRadioGroup = arrangeOnFirstCircleRadio.get_group(); - arrangeOnFirstCircleRadio.signal_toggled().connect(sigc::mem_fun(*this, &PolarArrangeTab::on_arrange_radio_changed)); - pack_start(arrangeOnFirstCircleRadio, false, false); - - arrangeOnLastCircleRadio.set_label(C_("Polar arrange tab", "Last selected circle/ellipse/arc")); - arrangeOnLastCircleRadio.set_group(arrangeRadioGroup); - arrangeOnLastCircleRadio.signal_toggled().connect(sigc::mem_fun(*this, &PolarArrangeTab::on_arrange_radio_changed)); - pack_start(arrangeOnLastCircleRadio, false, false); - - arrangeOnParametersRadio.set_label(C_("Polar arrange tab", "Parameterized:")); - arrangeOnParametersRadio.set_group(arrangeRadioGroup); - arrangeOnParametersRadio.signal_toggled().connect(sigc::mem_fun(*this, &PolarArrangeTab::on_arrange_radio_changed)); - pack_start(arrangeOnParametersRadio, false, false); - - //FIXME: Objects in grid do not line up properly! - centerLabel.set_text(_("Center X/Y:")); - parametersTable.attach(centerLabel, 0, 1, 0, 1, Gtk::FILL); - centerX.setDigits(2); - //centerX.set_size_request(60, -1); - centerX.setIncrements(0.2, 0); - centerX.setRange(-10000, 10000); - centerX.setValue(0, "px"); - centerY.setDigits(2); - //centerY.set_size_request(120, -1); - centerY.setIncrements(0.2, 0); - centerY.setRange(-10000, 10000); - centerY.setValue(0, "px"); - parametersTable.attach(centerX, 1, 2, 0, 1, Gtk::FILL); - parametersTable.attach(centerY, 2, 3, 0, 1, Gtk::FILL); - - radiusLabel.set_text(_("Radius X/Y:")); - parametersTable.attach(radiusLabel, 0, 1, 1, 2, Gtk::FILL); - radiusX.setDigits(2); - //radiusX.set_size_request(60, -1); - radiusX.setIncrements(0.2, 0); - radiusX.setRange(0.001, 10000); - radiusX.setValue(100, "px"); - radiusY.setDigits(2); - //radiusY.set_size_request(120, -1); - radiusY.setIncrements(0.2, 0); - radiusY.setRange(0.001, 10000); - radiusY.setValue(100, "px"); - parametersTable.attach(radiusX, 1, 2, 1, 2, Gtk::FILL); - parametersTable.attach(radiusY, 2, 3, 1, 2, Gtk::FILL); - - angleLabel.set_text(_("Angle X/Y:")); - parametersTable.attach(angleLabel, 0, 1, 2, 3, Gtk::FILL); - angleX.setDigits(2); - //angleX.set_size_request(60, -1); - angleX.setIncrements(0.2, 0); - angleX.setRange(-10000, 10000); - angleX.setValue(0, "°"); - angleY.setDigits(2); - //angleY.set_size_request(120, -1); - angleY.setIncrements(0.2, 0); - angleY.setRange(-10000, 10000); - angleY.setValue(180, "°"); - parametersTable.attach(angleX, 1, 2, 2, 3, Gtk::FILL); - parametersTable.attach(angleY, 2, 3, 2, 3, Gtk::FILL); - pack_start(parametersTable, false, false); - - rotateObjectsCheckBox.set_label(_("Rotate objects")); - rotateObjectsCheckBox.set_active(true); - pack_start(rotateObjectsCheckBox, false, false); - - centerX.set_sensitive(false); - centerY.set_sensitive(false); - angleX.set_sensitive(false); - angleY.set_sensitive(false); - radiusX.set_sensitive(false); - radiusY.set_sensitive(false); -} - -/** - * This function rotates an item around a given point by a given amount - * @param item item to rotate - * @param center center of the rotation to perform - * @param rotation amount to rotate the object by - */ -void rotateAround(SPItem *item, Geom::Point center, Geom::Rotate const &rotation) -{ - Geom::Translate const s(center); - Geom::Affine affine = Geom::Affine(s).inverse() * Geom::Affine(rotation) * Geom::Affine(s); - - // Save old center - center = item->getCenter(); - - item->set_i2d_affine(item->i2dt_affine() * affine); - item->doWriteTransform(item->getRepr(), item->transform); - - if(item->isCenterSet()) - { - item->setCenter(center * affine); - item->updateRepr(); - } -} - -/** - * Calculates the angle at which to put an object given the total amount - * of objects, the index of the objects as well as the arc start and end - * points - * @param arcBegin angle at which the arc begins - * @param arcEnd angle at which the arc ends - * @param count number of objects in the selection - * @param n index of the object in the selection - */ -float calcAngle(float arcBegin, float arcEnd, int count, int n) -{ - float arcLength = arcEnd - arcBegin; - float delta = std::abs(std::abs(arcLength) - 2*M_PI); - if(delta > 0.01) count--; // If not a complete circle, put an object also at the extremes of the arc; - - float angle = n / (float)count; - // Normalize for arcLength: - angle = angle * arcLength; - angle += arcBegin; - - return angle; -} - -/** - * Calculates the point at which the object needs to be, given the center of the ellipse, - * it's radius (x and y), as well as the angle - */ -Geom::Point calcPoint(float cx, float cy, float rx, float ry, float angle) -{ - return Geom::Point(cx + cos(angle) * rx, cy + sin(angle) * ry); -} - -/** - * Returns the selected anchor point in document coordinates. If anchor - * is 0 to 8, then a bounding box point has been choosen. If it is 9 however - * the rotational center is chosen. - * @todo still using a hack to get the real coordinate space (subtracting document height - * and inverting axes) - */ -Geom::Point getAnchorPoint(int anchor, SPItem *item) -{ - Geom::Point source; - - Geom::OptRect bbox = item->documentVisualBounds(); - - switch(anchor) - { - case 0: // Top - Left - case 3: // Middle - Left - case 6: // Bottom - Left - source[0] = bbox->min()[Geom::X]; - break; - case 1: // Top - Middle - case 4: // Middle - Middle - case 7: // Bottom - Middle - source[0] = (bbox->min()[Geom::X] + bbox->max()[Geom::X]) / 2.0f; - break; - case 2: // Top - Right - case 5: // Middle - Right - case 8: // Bottom - Right - source[0] = bbox->max()[Geom::X]; - break; - }; - - switch(anchor) - { - case 0: // Top - Left - case 1: // Top - Middle - case 2: // Top - Right - source[1] = bbox->min()[Geom::Y]; - break; - case 3: // Middle - Left - case 4: // Middle - Middle - case 5: // Middle - Right - source[1] = (bbox->min()[Geom::Y] + bbox->max()[Geom::Y]) / 2.0f; - break; - case 6: // Bottom - Left - case 7: // Bottom - Middle - case 8: // Bottom - Right - source[1] = bbox->max()[Geom::Y]; - break; - }; - - // If using center - if(anchor == 9) - source = item->getCenter(); - else - { - // FIXME: - source[1] -= item->document->getHeight(); - source[1] *= -1; - } - - return source; -} - -void moveToPoint(int anchor, SPItem *item, Geom::Point p) -{ - sp_item_move_rel(item, Geom::Translate(p - getAnchorPoint(anchor, item))); -} - -void PolarArrangeTab::arrange() -{ - std::cout << "PolarArrangeTab::arrange()" << std::endl; - - Inkscape::Selection *selection = sp_desktop_selection(parent->getDesktop()); - const GSList *items, *tmp; - tmp = items = selection->itemList(); - SPGenericEllipse *referenceEllipse = NULL; // Last ellipse in selection - - bool arrangeOnEllipse = !arrangeOnParametersRadio.get_active(); - bool arrangeOnFirstEllipse = arrangeOnEllipse && arrangeOnFirstCircleRadio.get_active(); - - int count = 0; - while(tmp) - { - if(arrangeOnEllipse) - { - SPItem *item = SP_ITEM(tmp->data); - - if(arrangeOnFirstEllipse) - { - // The first selected ellipse is actually the last one in the list - if(SP_IS_GENERICELLIPSE(item)) - referenceEllipse = SP_GENERICELLIPSE(item); - } else { - // The last selected ellipse is actually the first in list - if(SP_IS_GENERICELLIPSE(item) && referenceEllipse == NULL) - referenceEllipse = SP_GENERICELLIPSE(item); - } - } - tmp = tmp->next; - ++count; - } - - float cx, cy; // Center of the ellipse - float rx, ry; // Radiuses of the ellipse in x and y direction - float arcBeg, arcEnd; // begin and end angles for arcs - Geom::Affine transformation; // Any additional transformation to apply to the objects - - if(arrangeOnEllipse) - { - if(referenceEllipse == NULL) - { - Gtk::MessageDialog dialog(_("Couldn't find an ellipse in selection"), false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_CLOSE, true); - dialog.run(); - return; - } else { - cx = referenceEllipse->cx.value; - cy = referenceEllipse->cy.value; - rx = referenceEllipse->rx.value; - ry = referenceEllipse->ry.value; - arcBeg = referenceEllipse->start; - arcEnd = referenceEllipse->end; - - std::cout << "Arc: " << arcBeg << ", " << arcEnd << std::endl; - transformation = referenceEllipse->i2dt_affine(); - - // We decrement the count by 1 as we are not going to lay - // out the reference ellipse - --count; - } - - } else { - // Read options from UI - cx = centerX.getValue("px"); - cy = centerY.getValue("px"); - rx = radiusX.getValue("px"); - ry = radiusY.getValue("px"); - arcBeg = angleX.getValue("rad"); - arcEnd = angleY.getValue("rad"); - transformation.setIdentity(); - referenceEllipse = NULL; - } - - int anchor = 9; - if(anchorBoundingBoxRadio.get_active()) - { - anchor = anchorSelector.getHorizontalAlignment() + - anchorSelector.getVerticalAlignment() * 3; - } - - Geom::Point realCenter = Geom::Point(cx, cy) * transformation; - - tmp = items; - int i = 0; - while(tmp) - { - SPItem *item = SP_ITEM(tmp->data); - - // Ignore the reference ellipse if any - if(item != referenceEllipse) - { - float angle = calcAngle(arcBeg, arcEnd, count, i); - Geom::Point newLocation = calcPoint(cx, cy, rx, ry, angle) * transformation; - - moveToPoint(anchor, item, newLocation); - - if(rotateObjectsCheckBox.get_active()) { - // Calculate the angle by which to rotate each object - angle = -atan2f(newLocation.x() - realCenter.x(), newLocation.y() - realCenter.y()); - rotateAround(item, newLocation, Geom::Rotate(angle)); - } - - std::cout << "object " << i << " out of " << count << ": " << angle << std::endl; - - ++i; - } - tmp = tmp->next; - } - - DocumentUndo::done(sp_desktop_document(parent->getDesktop()), SP_VERB_SELECTION_ARRANGE, - _("Arrange on ellipse")); -} - -void PolarArrangeTab::updateSelection() -{ -} - -void PolarArrangeTab::on_arrange_radio_changed() -{ - bool arrangeParametric = arrangeOnParametersRadio.get_active(); - - centerX.set_sensitive(arrangeParametric); - centerY.set_sensitive(arrangeParametric); - - angleX.set_sensitive(arrangeParametric); - angleY.set_sensitive(arrangeParametric); - - radiusX.set_sensitive(arrangeParametric); - radiusY.set_sensitive(arrangeParametric); -} - -void PolarArrangeTab::on_anchor_radio_changed() -{ - bool anchorBoundingBox = anchorBoundingBoxRadio.get_active(); - - anchorSelector.set_sensitive(anchorBoundingBox); -} - -} //namespace Dialog -} //namespace UI -} //namespace Inkscape - -/* - 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/polararrangetab.h b/src/ui/dialog/polararrangetab.h deleted file mode 100644 index 24760a8bc..000000000 --- a/src/ui/dialog/polararrangetab.h +++ /dev/null @@ -1,87 +0,0 @@ -/** - * @brief Arranges Objects into a Circle/Ellipse - */ -/* Authors: - * Declara Denis - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#ifndef INKSCAPE_UI_DIALOG_POLAR_ARRANGE_TAB_H -#define INKSCAPE_UI_DIALOG_POLAR_ARRANGE_TAB_H - -#include - -#include "ui/dialog/arrangetab.h" - -#include "ui/widget/anchor-selector.h" -#include "ui/widget/scalar-unit.h" - -namespace Inkscape { -namespace UI { -namespace Dialog { - -class ArrangeDialog; - -class PolarArrangeTab : public ArrangeTab { -public: - PolarArrangeTab(ArrangeDialog *parent_); - virtual ~PolarArrangeTab() {}; - - /** - * Do the actual work - */ - virtual void arrange(); - - /** - * Respond to selection change - */ - void updateSelection(); - - void on_anchor_radio_changed(); - void on_arrange_radio_changed(); - -private: - PolarArrangeTab(PolarArrangeTab const &d); // no copy - void operator=(PolarArrangeTab const &d); // no assign - - ArrangeDialog *parent; - - Gtk::Label anchorPointLabel; - - Gtk::RadioButtonGroup anchorRadioGroup; - Gtk::RadioButton anchorBoundingBoxRadio; - Gtk::RadioButton anchorObjectPivotRadio; - AnchorSelector anchorSelector; - - Gtk::Label arrangeOnLabel; - - Gtk::RadioButtonGroup arrangeRadioGroup; - Gtk::RadioButton arrangeOnFirstCircleRadio; - Gtk::RadioButton arrangeOnLastCircleRadio; - Gtk::RadioButton arrangeOnParametersRadio; - - Gtk::Table parametersTable; - - Gtk::Label centerLabel; - Inkscape::UI::Widget::ScalarUnit centerY; - Inkscape::UI::Widget::ScalarUnit centerX; - - Gtk::Label radiusLabel; - Inkscape::UI::Widget::ScalarUnit radiusY; - Inkscape::UI::Widget::ScalarUnit radiusX; - - Gtk::Label angleLabel; - Inkscape::UI::Widget::ScalarUnit angleY; - Inkscape::UI::Widget::ScalarUnit angleX; - - Gtk::CheckButton rotateObjectsCheckBox; - - -}; - -} //namespace Dialog -} //namespace UI -} //namespace Inkscape - -#endif /* INKSCAPE_UI_DIALOG_POLAR_ARRANGE_TAB_H */ diff --git a/src/ui/dialog/tile.cpp b/src/ui/dialog/tile.cpp index 917544d3d..c967509f9 100644 --- a/src/ui/dialog/tile.cpp +++ b/src/ui/dialog/tile.cpp @@ -19,8 +19,8 @@ #include "tile.h" #include "verbs.h" -#include "ui/dialog/gridarrangetab.h" -#include "ui/dialog/polararrangetab.h" +#include "ui/dialog/grid-arrange-tab.h" +#include "ui/dialog/polar-arrange-tab.h" namespace Inkscape { namespace UI { diff --git a/src/ui/widget/anchor-selector.cpp b/src/ui/widget/anchor-selector.cpp index 87f50cf5f..82e27ee89 100644 --- a/src/ui/widget/anchor-selector.cpp +++ b/src/ui/widget/anchor-selector.cpp @@ -12,6 +12,10 @@ #include "widgets/icon.h" #include "ui/icon-names.h" +namespace Inkscape { +namespace UI { +namespace Widget { + void AnchorSelector::setupButton(const Glib::ustring& icon, Gtk::ToggleButton& button) { Gtk::Widget* buttonIcon = Gtk::manage(sp_icon_get_icon(icon, Inkscape::ICON_SIZE_SMALL_TOOLBAR)); buttonIcon->show(); @@ -76,3 +80,18 @@ void AnchorSelector::setAlignment(int horizontal, int vertical) _buttons[index].set_active(!_buttons[index].get_active()); } } + +} // namespace Widget +} // namespace UI +} // namespace Inkscape + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=c++:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/ui/widget/anchor-selector.h b/src/ui/widget/anchor-selector.h index 361528d11..2263438e3 100644 --- a/src/ui/widget/anchor-selector.h +++ b/src/ui/widget/anchor-selector.h @@ -12,6 +12,10 @@ #include +namespace Inkscape { +namespace UI { +namespace Widget { + class AnchorSelector : public Gtk::Alignment { private: @@ -37,4 +41,19 @@ public: virtual ~AnchorSelector(); }; +} // namespace Widget +} // namespace UI +} // namespace Inkscape + #endif /* ANCHOR_SELECTOR_H_ */ + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=c++:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : -- cgit v1.2.3 From c620ecb0f432de693f537f020999dfa4316b1859 Mon Sep 17 00:00:00 2001 From: Denis Declara Date: Wed, 9 May 2012 17:09:29 +0200 Subject: Removed debug output (bzr r11073.1.32) --- src/ui/dialog/polar-arrange-tab.cpp | 5 ----- 1 file changed, 5 deletions(-) (limited to 'src/ui') diff --git a/src/ui/dialog/polar-arrange-tab.cpp b/src/ui/dialog/polar-arrange-tab.cpp index a1df794a5..32f05c5e8 100644 --- a/src/ui/dialog/polar-arrange-tab.cpp +++ b/src/ui/dialog/polar-arrange-tab.cpp @@ -261,8 +261,6 @@ void moveToPoint(int anchor, SPItem *item, Geom::Point p) void PolarArrangeTab::arrange() { - std::cout << "PolarArrangeTab::arrange()" << std::endl; - Inkscape::Selection *selection = sp_desktop_selection(parent->getDesktop()); const GSList *items, *tmp; tmp = items = selection->itemList(); @@ -313,7 +311,6 @@ void PolarArrangeTab::arrange() arcBeg = referenceEllipse->start; arcEnd = referenceEllipse->end; - std::cout << "Arc: " << arcBeg << ", " << arcEnd << std::endl; transformation = referenceEllipse->i2dt_affine(); // We decrement the count by 1 as we are not going to lay @@ -362,8 +359,6 @@ void PolarArrangeTab::arrange() rotateAround(item, newLocation, Geom::Rotate(angle)); } - std::cout << "object " << i << " out of " << count << ": " << angle << std::endl; - ++i; } tmp = tmp->next; -- cgit v1.2.3 From 48cd3195741c6590d7129da3bae23fd72784d4a4 Mon Sep 17 00:00:00 2001 From: Denis Declara Date: Sat, 19 May 2012 14:19:14 +0200 Subject: Renamed "arrangetab.h" to "arrange-tab.h" (bzr r11073.1.33) --- src/ui/CMakeLists.txt | 2 +- src/ui/dialog/Makefile_insert | 2 +- src/ui/dialog/arrange-tab.h | 54 +++++++++++++++++++++++++++++++++++++++ src/ui/dialog/arrangetab.h | 54 --------------------------------------- src/ui/dialog/grid-arrange-tab.h | 2 +- src/ui/dialog/polar-arrange-tab.h | 2 +- 6 files changed, 58 insertions(+), 58 deletions(-) create mode 100644 src/ui/dialog/arrange-tab.h delete mode 100644 src/ui/dialog/arrangetab.h (limited to 'src/ui') diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt index 7435720fd..2e419bbc3 100644 --- a/src/ui/CMakeLists.txt +++ b/src/ui/CMakeLists.txt @@ -136,7 +136,7 @@ set(ui_SRC dialog/aboutbox.h dialog/align-and-distribute.h - dialog/arrangetab.h + dialog/arrange-tab.h dialog/behavior.h dialog/calligraphic-profile-rename.h dialog/color-item.h diff --git a/src/ui/dialog/Makefile_insert b/src/ui/dialog/Makefile_insert index 53533a08f..5a367248e 100644 --- a/src/ui/dialog/Makefile_insert +++ b/src/ui/dialog/Makefile_insert @@ -5,7 +5,7 @@ ink_common_sources += \ ui/dialog/aboutbox.h \ ui/dialog/align-and-distribute.cpp \ ui/dialog/align-and-distribute.h \ - ui/dialog/arrangetab.h \ + ui/dialog/arrange-tab.h \ ui/dialog/behavior.h \ ui/dialog/calligraphic-profile-rename.h \ ui/dialog/calligraphic-profile-rename.cpp \ diff --git a/src/ui/dialog/arrange-tab.h b/src/ui/dialog/arrange-tab.h new file mode 100644 index 000000000..3ffe1ef4c --- /dev/null +++ b/src/ui/dialog/arrange-tab.h @@ -0,0 +1,54 @@ +/** + * @brief Arrange tools base class + */ +/* Authors: + * * Declara Denis + * Copyright (C) 2012 Authors + * + * Released under GNU GPL. Read the file 'COPYING' for more information. + */ + +#ifndef INKSCAPE_UI_DIALOG_ARRANGE_TAB_H +#define INKSCAPE_UI_DIALOG_ARRANGE_TAB_H + +#include + +namespace Inkscape { +namespace UI { +namespace Dialog { + +/** + * This interface should be implemented by each arrange mode. + * The class is a Gtk::VBox and will be displayed as a tab in + * the dialog + */ +class ArrangeTab : public Gtk::VBox +{ +public: + ArrangeTab() {}; + virtual ~ArrangeTab() {}; + + /** + * Do the actual work! This method is invoked to actually arrange the + * selection + */ + virtual void arrange() = 0; +}; + +} //namespace Dialog +} //namespace UI +} //namespace Inkscape + + +#endif /* INKSCAPE_UI_DIALOG_ARRANGE_TAB_H */ + +/* + 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/arrangetab.h b/src/ui/dialog/arrangetab.h deleted file mode 100644 index 3ffe1ef4c..000000000 --- a/src/ui/dialog/arrangetab.h +++ /dev/null @@ -1,54 +0,0 @@ -/** - * @brief Arrange tools base class - */ -/* Authors: - * * Declara Denis - * Copyright (C) 2012 Authors - * - * Released under GNU GPL. Read the file 'COPYING' for more information. - */ - -#ifndef INKSCAPE_UI_DIALOG_ARRANGE_TAB_H -#define INKSCAPE_UI_DIALOG_ARRANGE_TAB_H - -#include - -namespace Inkscape { -namespace UI { -namespace Dialog { - -/** - * This interface should be implemented by each arrange mode. - * The class is a Gtk::VBox and will be displayed as a tab in - * the dialog - */ -class ArrangeTab : public Gtk::VBox -{ -public: - ArrangeTab() {}; - virtual ~ArrangeTab() {}; - - /** - * Do the actual work! This method is invoked to actually arrange the - * selection - */ - virtual void arrange() = 0; -}; - -} //namespace Dialog -} //namespace UI -} //namespace Inkscape - - -#endif /* INKSCAPE_UI_DIALOG_ARRANGE_TAB_H */ - -/* - 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/grid-arrange-tab.h b/src/ui/dialog/grid-arrange-tab.h index 7e90accf1..2744ca87f 100644 --- a/src/ui/dialog/grid-arrange-tab.h +++ b/src/ui/dialog/grid-arrange-tab.h @@ -19,7 +19,7 @@ #include -#include "ui/dialog/arrangetab.h" +#include "ui/dialog/arrange-tab.h" #include "ui/widget/anchor-selector.h" #include "ui/widget/scalar-unit.h" diff --git a/src/ui/dialog/polar-arrange-tab.h b/src/ui/dialog/polar-arrange-tab.h index e62ebd76b..3481bc4a0 100644 --- a/src/ui/dialog/polar-arrange-tab.h +++ b/src/ui/dialog/polar-arrange-tab.h @@ -12,7 +12,7 @@ #include -#include "ui/dialog/arrangetab.h" +#include "ui/dialog/arrange-tab.h" #include "ui/widget/anchor-selector.h" #include "ui/widget/scalar-unit.h" -- cgit v1.2.3 From 24e2360f100a9372e7f2d0af894ec1b2d1357ace Mon Sep 17 00:00:00 2001 From: Denis Declara Date: Sat, 19 May 2012 14:51:48 +0200 Subject: Added documentation and made helper functions in polar-arrange-tab.cpp static (bzr r11073.1.34) --- src/ui/dialog/polar-arrange-tab.cpp | 22 ++++++++++++++++------ src/ui/dialog/polar-arrange-tab.h | 17 ++++++++++++++++- 2 files changed, 32 insertions(+), 7 deletions(-) (limited to 'src/ui') diff --git a/src/ui/dialog/polar-arrange-tab.cpp b/src/ui/dialog/polar-arrange-tab.cpp index 32f05c5e8..2056c7820 100644 --- a/src/ui/dialog/polar-arrange-tab.cpp +++ b/src/ui/dialog/polar-arrange-tab.cpp @@ -140,7 +140,7 @@ PolarArrangeTab::PolarArrangeTab(ArrangeDialog *parent_) * @param center center of the rotation to perform * @param rotation amount to rotate the object by */ -void rotateAround(SPItem *item, Geom::Point center, Geom::Rotate const &rotation) +static void rotateAround(SPItem *item, Geom::Point center, Geom::Rotate const &rotation) { Geom::Translate const s(center); Geom::Affine affine = Geom::Affine(s).inverse() * Geom::Affine(rotation) * Geom::Affine(s); @@ -167,7 +167,7 @@ void rotateAround(SPItem *item, Geom::Point center, Geom::Rotate const &rotation * @param count number of objects in the selection * @param n index of the object in the selection */ -float calcAngle(float arcBegin, float arcEnd, int count, int n) +static float calcAngle(float arcBegin, float arcEnd, int count, int n) { float arcLength = arcEnd - arcBegin; float delta = std::abs(std::abs(arcLength) - 2*M_PI); @@ -182,10 +182,10 @@ float calcAngle(float arcBegin, float arcEnd, int count, int n) } /** - * Calculates the point at which the object needs to be, given the center of the ellipse, + * Calculates the point at which an object needs to be, given the center of the ellipse, * it's radius (x and y), as well as the angle */ -Geom::Point calcPoint(float cx, float cy, float rx, float ry, float angle) +static Geom::Point calcPoint(float cx, float cy, float rx, float ry, float angle) { return Geom::Point(cx + cos(angle) * rx, cy + sin(angle) * ry); } @@ -197,7 +197,7 @@ Geom::Point calcPoint(float cx, float cy, float rx, float ry, float angle) * @todo still using a hack to get the real coordinate space (subtracting document height * and inverting axes) */ -Geom::Point getAnchorPoint(int anchor, SPItem *item) +static Geom::Point getAnchorPoint(int anchor, SPItem *item) { Geom::Point source; @@ -254,7 +254,17 @@ Geom::Point getAnchorPoint(int anchor, SPItem *item) return source; } -void moveToPoint(int anchor, SPItem *item, Geom::Point p) +/** + * Moves an SPItem to a given location, the location is based on the given anchor point. + * @param anchor 0 to 8 are the various bounding box points like follows: + * 0 1 2 + * 3 4 5 + * 6 7 8 + * Anchor mode 9 is the rotational center of the object + * @param item Item to move + * @param p point at which to move the object + */ +static void moveToPoint(int anchor, SPItem *item, Geom::Point p) { sp_item_move_rel(item, Geom::Translate(p - getAnchorPoint(anchor, item))); } diff --git a/src/ui/dialog/polar-arrange-tab.h b/src/ui/dialog/polar-arrange-tab.h index 3481bc4a0..019b64511 100644 --- a/src/ui/dialog/polar-arrange-tab.h +++ b/src/ui/dialog/polar-arrange-tab.h @@ -23,13 +23,17 @@ namespace Dialog { class ArrangeDialog; +/** + * PolarArrangeTab is a Tab displayed in the Arrange dialog and contains + * enables the user to arrange objects on a circular or elliptical shape + */ class PolarArrangeTab : public ArrangeTab { public: PolarArrangeTab(ArrangeDialog *parent_); virtual ~PolarArrangeTab() {}; /** - * Do the actual work + * Do the actual arrangement */ virtual void arrange(); @@ -85,3 +89,14 @@ private: } //namespace Inkscape #endif /* INKSCAPE_UI_DIALOG_POLAR_ARRANGE_TAB_H */ + +/* + 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 : -- cgit v1.2.3 From 8d97fe84d570a73ba3b48269308bd360332b8250 Mon Sep 17 00:00:00 2001 From: Denis Declara Date: Sat, 19 May 2012 18:39:38 +0200 Subject: The Polar Arrange Tab of the Arrange Dialog now hides the parametric controls until the user selects the corresponding radio button (bzr r11073.1.35) --- src/ui/dialog/polar-arrange-tab.cpp | 9 ++------- src/ui/dialog/tile.cpp | 9 ++++++++- src/ui/dialog/tile.h | 2 ++ 3 files changed, 12 insertions(+), 8 deletions(-) (limited to 'src/ui') diff --git a/src/ui/dialog/polar-arrange-tab.cpp b/src/ui/dialog/polar-arrange-tab.cpp index 2056c7820..623aa4e3e 100644 --- a/src/ui/dialog/polar-arrange-tab.cpp +++ b/src/ui/dialog/polar-arrange-tab.cpp @@ -75,16 +75,13 @@ PolarArrangeTab::PolarArrangeTab(ArrangeDialog *parent_) arrangeOnParametersRadio.signal_toggled().connect(sigc::mem_fun(*this, &PolarArrangeTab::on_arrange_radio_changed)); pack_start(arrangeOnParametersRadio, false, false); - //FIXME: Objects in grid do not line up properly! centerLabel.set_text(_("Center X/Y:")); parametersTable.attach(centerLabel, 0, 1, 0, 1, Gtk::FILL); centerX.setDigits(2); - //centerX.set_size_request(60, -1); centerX.setIncrements(0.2, 0); centerX.setRange(-10000, 10000); centerX.setValue(0, "px"); centerY.setDigits(2); - //centerY.set_size_request(120, -1); centerY.setIncrements(0.2, 0); centerY.setRange(-10000, 10000); centerY.setValue(0, "px"); @@ -94,12 +91,10 @@ PolarArrangeTab::PolarArrangeTab(ArrangeDialog *parent_) radiusLabel.set_text(_("Radius X/Y:")); parametersTable.attach(radiusLabel, 0, 1, 1, 2, Gtk::FILL); radiusX.setDigits(2); - //radiusX.set_size_request(60, -1); radiusX.setIncrements(0.2, 0); radiusX.setRange(0.001, 10000); radiusX.setValue(100, "px"); radiusY.setDigits(2); - //radiusY.set_size_request(120, -1); radiusY.setIncrements(0.2, 0); radiusY.setRange(0.001, 10000); radiusY.setValue(100, "px"); @@ -109,12 +104,10 @@ PolarArrangeTab::PolarArrangeTab(ArrangeDialog *parent_) angleLabel.set_text(_("Angle X/Y:")); parametersTable.attach(angleLabel, 0, 1, 2, 3, Gtk::FILL); angleX.setDigits(2); - //angleX.set_size_request(60, -1); angleX.setIncrements(0.2, 0); angleX.setRange(-10000, 10000); angleX.setValue(0, "°"); angleY.setDigits(2); - //angleY.set_size_request(120, -1); angleY.setIncrements(0.2, 0); angleY.setRange(-10000, 10000); angleY.setValue(180, "°"); @@ -394,6 +387,8 @@ void PolarArrangeTab::on_arrange_radio_changed() radiusX.set_sensitive(arrangeParametric); radiusY.set_sensitive(arrangeParametric); + + parametersTable.set_visible(arrangeParametric); } void PolarArrangeTab::on_anchor_radio_changed() diff --git a/src/ui/dialog/tile.cpp b/src/ui/dialog/tile.cpp index c967509f9..1ed099120 100644 --- a/src/ui/dialog/tile.cpp +++ b/src/ui/dialog/tile.cpp @@ -41,7 +41,14 @@ ArrangeDialog::ArrangeDialog() _arrangeButton->set_use_underline(true); _arrangeButton->set_tooltip_text(_("Arrange selected objects")); contents->pack_start(_arrangeBox); - show_all_children(); + //show_all_children(); +} + + +void ArrangeDialog::on_show() +{ + UI::Widget::Panel::on_show(); + _polarArrangeTab->on_arrange_radio_changed(); } void ArrangeDialog::_apply() diff --git a/src/ui/dialog/tile.h b/src/ui/dialog/tile.h index d42dd7f65..8d4e9584b 100644 --- a/src/ui/dialog/tile.h +++ b/src/ui/dialog/tile.h @@ -54,6 +54,8 @@ public: */ virtual void _apply(); + virtual void on_show(); + static ArrangeDialog& getInstance() { return *new ArrangeDialog(); } }; -- cgit v1.2.3 From 2b34ad03d59938b3ab142cca56b71366d0cf61ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20dos=20Santos=20Oliveira?= Date: Sun, 6 Oct 2013 22:47:06 -0300 Subject: Running libdepixelize expensive process in a background thread (bzr r12667.1.1) --- src/ui/dialog/pixelartdialog.cpp | 164 ++++++++++++++++++++++++++++----------- 1 file changed, 117 insertions(+), 47 deletions(-) (limited to 'src/ui') diff --git a/src/ui/dialog/pixelartdialog.cpp b/src/ui/dialog/pixelartdialog.cpp index ff527434e..3f3ebc0b6 100644 --- a/src/ui/dialog/pixelartdialog.cpp +++ b/src/ui/dialog/pixelartdialog.cpp @@ -16,6 +16,16 @@ # include #endif +#ifdef GLIBMM_DISABLE_DEPRECATED +# undef GLIBMM_DISABLE_DEPRECATED +# include +# include +# define GLIBMM_DISABLE_DEPRECATED 1 +#else // GLIBMM_DISABLE_DEPRECATED +# include +# include +#endif // GLIBMM_DISABLE_DEPRECATED + #include "pixelartdialog.h" #include #include @@ -54,18 +64,6 @@ namespace Inkscape { namespace UI { namespace Dialog { -template -T move(T &obj) -{ -#ifdef LIBDEPIXELIZE_ENABLE_CPP11 - return std::move(obj); -#else - T ret; - std::swap(obj, ret); - return ret; -#endif // LIBDEPIXELIZE_ENABLE_CPP11 -} - /** * A dialog for adjusting pixel art -> vector tracing parameters */ @@ -77,6 +75,23 @@ public: ~PixelArtDialogImpl(); private: + struct Input + { + Glib::RefPtr pixbuf; + SVGLength x; + SVGLength y; + }; + struct Output + { + Output(Tracer::Splines splines, SVGLength x, SVGLength y) : + splines(splines), x(x), y(y) + {} + + Tracer::Splines splines; + SVGLength x; + SVGLength y; + }; + void setDesktop(SPDesktop *desktop); void setTargetDesktop(SPDesktop *desktop); @@ -89,7 +104,8 @@ private: Tracer::Kopf2011::Options options(); void vectorize(); - void processLibdepixelize(SPImage *img); + void processLibdepixelize(const Input &image); + void importOutput(const Output &out); void setDefaults(); void updatePreview(); @@ -133,9 +149,21 @@ private: Gtk::RadioButton optimizeRadioButton; #endif // LIBDEPIXELIZE_INKSCAPE_ENABLE_SMOOTH + //############ UI Logic data + SPDesktop *desktop; DesktopTracker deskTrack; sigc::connection desktopChangeConn; + + //############ Threads + void workerThread(); + void onWorkerThreadFinished(); + Glib::Thread *thread; + volatile gint abortThread; // C++11's atomic stuff is sooo much nicer + Glib::Dispatcher dispatcher; + std::vector queue; + std::vector output; + Tracer::Kopf2011::Options lastOptions; }; void PixelArtDialogImpl::setDesktop(SPDesktop *desktop) @@ -288,6 +316,9 @@ PixelArtDialogImpl::PixelArtDialogImpl() : deskTrack.connect(GTK_WIDGET(gobj())); signalResponse().connect(sigc::mem_fun(*this, &PixelArtDialogImpl::responseCallback)); + + dispatcher.connect( + sigc::mem_fun(*this, &PixelArtDialogImpl::onWorkerThreadFinished) ); } void PixelArtDialogImpl::responseCallback(int response_id) @@ -295,7 +326,8 @@ void PixelArtDialogImpl::responseCallback(int response_id) if (response_id == GTK_RESPONSE_OK) { vectorize(); } else if (response_id == GTK_RESPONSE_CANCEL) { - // TODO + // libdepixelize's interface need to be extended to allow aborts + g_atomic_int_set(&abortThread, true); } else if (response_id == GTK_RESPONSE_HELP) { setDefaults(); } else { @@ -340,60 +372,69 @@ void PixelArtDialogImpl::vectorize() return; } - bool found = false; - for ( GSList const *list = desktop->selection->itemList() ; list ; list = list->next ) { if ( !SP_IS_IMAGE(list->data) ) continue; - found = true; + SPImage *img = SP_IMAGE(list->data); + Input input; + input.pixbuf = Glib::wrap(img->pixbuf->getPixbufRaw(), true); + input.x = img->x; + input.y = img->y; + + if ( input.pixbuf->get_width() > 256 + || input.pixbuf->get_height() > 256 ) { + char *msg = _("Image looks too big. Process may take a while and is" + " wise to save your document before continue." + "\n\nContinue the procedure (without saving)?"); + Gtk::MessageDialog dialog(msg, false, Gtk::MESSAGE_WARNING, + Gtk::BUTTONS_OK_CANCEL, true); + + if ( dialog.run() != Gtk::RESPONSE_OK ) + continue; + } - processLibdepixelize(SP_IMAGE(list->data)); + queue.push_back(input); + //processLibdepixelize(SP_IMAGE(list->data)); } - if ( !found ) { + if ( !queue.size() ) { char *msg = _("Select an image to trace"); msgStack->flash(Inkscape::ERROR_MESSAGE, msg); return; } - DocumentUndo::done(desktop->doc(), SP_VERB_SELECTION_PIXEL_ART, - _("Trace pixel art")); + mainCancelButton->set_sensitive(true); + mainOkButton->set_sensitive(false); - // Flush pending updates - desktop->doc()->ensureUpToDate(); + lastOptions = options(); + + g_atomic_int_set(&abortThread, false); + thread = Glib::Thread::create( + sigc::mem_fun(*this, &PixelArtDialogImpl::workerThread) ); } -void PixelArtDialogImpl::processLibdepixelize(SPImage *img) +void PixelArtDialogImpl::processLibdepixelize(const Input &input) { - Tracer::Splines out; - - Glib::RefPtr pixbuf - = Glib::wrap(img->pixbuf->getPixbufRaw(), true); - - if ( pixbuf->get_width() > 256 || pixbuf->get_height() > 256 ) { - char *msg = _("Image looks too big. Process may take a while and is" - " wise to save your document before continue." - "\n\nContinue the procedure (without saving)?"); - Gtk::MessageDialog dialog(msg, false, Gtk::MESSAGE_WARNING, - Gtk::BUTTONS_OK_CANCEL, true); - - if ( dialog.run() != Gtk::RESPONSE_OK ) - return; - } - if ( voronoiRadioButton.get_active() ) { - out = Tracer::Kopf2011::to_voronoi(pixbuf, options()); + output.push_back(Output(Tracer::Kopf2011::to_voronoi(input.pixbuf, + lastOptions), + input.x, input.y)); } else { - out = Tracer::Kopf2011::to_splines(pixbuf, options()); + output.push_back(Output(Tracer::Kopf2011::to_splines(input.pixbuf, + lastOptions), + input.x, input.y)); } +} +void PixelArtDialogImpl::importOutput(const Output &output) +{ Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); Inkscape::XML::Node *group = xml_doc->createElement("svg:g"); - for ( Tracer::Splines::iterator it = out.begin(), end = out.end() - ; it != end ; ++it ) { + for ( Tracer::Splines::const_iterator it = output.splines.begin(), + end = output.splines.end() ; it != end ; ++it ) { Inkscape::XML::Node *repr = xml_doc->createElement("svg:path"); { @@ -421,7 +462,7 @@ void PixelArtDialogImpl::processLibdepixelize(SPImage *img) sp_repr_css_attr_unref(css); } - gchar *str = sp_svg_write_path(move(it->pathVector)); + gchar *str = sp_svg_write_path(it->pathVector); repr->setAttribute("d", str); g_free(str); @@ -433,14 +474,20 @@ void PixelArtDialogImpl::processLibdepixelize(SPImage *img) { group->setAttribute("transform", (std::string("translate(") - + sp_svg_length_write_with_units(img->x) - + ' ' + sp_svg_length_write_with_units(img->y) + + sp_svg_length_write_with_units(output.x) + + ' ' + sp_svg_length_write_with_units(output.y) + ')').c_str()); } desktop->currentLayer()->appendChildRepr(group); Inkscape::GC::release(group); + + DocumentUndo::done(desktop->doc(), SP_VERB_SELECTION_PIXEL_ART, + _("Trace pixel art")); + + // Flush pending updates + desktop->doc()->ensureUpToDate(); } void PixelArtDialogImpl::setDefaults() @@ -481,6 +528,29 @@ void PixelArtDialogImpl::updatePreview() pendingPreview = false; } +void PixelArtDialogImpl::workerThread() +{ + for ( std::vector::iterator it = queue.begin(), end = queue.end() + ; it != end && !g_atomic_int_get(&abortThread) ; ++it ) { + processLibdepixelize(*it); + } + queue.clear(); + dispatcher(); +} + +void PixelArtDialogImpl::onWorkerThreadFinished() +{ + thread->join(); + thread = NULL; + for ( std::vector::const_iterator it = output.begin(), + end = output.end() ; it != end ; ++it ) { + importOutput(*it); + } + output.clear(); + mainCancelButton->set_sensitive(false); + mainOkButton->set_sensitive(true); +} + /** * Factory method. Use this to create a new PixelArtDialog */ -- cgit v1.2.3 From 20062e01bfce8a97746e438bc0f7e89ce6400015 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20dos=20Santos=20Oliveira?= Date: Mon, 7 Oct 2013 00:26:05 -0300 Subject: Removing useless comment (bzr r12667.1.2) --- src/ui/dialog/pixelartdialog.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/ui') diff --git a/src/ui/dialog/pixelartdialog.cpp b/src/ui/dialog/pixelartdialog.cpp index 3f3ebc0b6..d5313b2c8 100644 --- a/src/ui/dialog/pixelartdialog.cpp +++ b/src/ui/dialog/pixelartdialog.cpp @@ -396,7 +396,6 @@ void PixelArtDialogImpl::vectorize() } queue.push_back(input); - //processLibdepixelize(SP_IMAGE(list->data)); } if ( !queue.size() ) { -- cgit v1.2.3 From 5eb9b4815a12cc0dafd07905f7715a7e15a92b41 Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Mon, 13 Jan 2014 00:25:39 +0100 Subject: update 2geom's copy to r2142 (bzr r12921) --- src/ui/tool/path-manipulator.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/ui') diff --git a/src/ui/tool/path-manipulator.cpp b/src/ui/tool/path-manipulator.cpp index ec58e2141..338499672 100644 --- a/src/ui/tool/path-manipulator.cpp +++ b/src/ui/tool/path-manipulator.cpp @@ -18,7 +18,7 @@ #include #include <2geom/bezier-curve.h> #include <2geom/bezier-utils.h> -#include <2geom/svg-path.h> +#include <2geom/path-sink.h> #include #include "ui/tool/path-manipulator.h" #include "desktop.h" @@ -1202,7 +1202,7 @@ void PathManipulator::_createGeometryFromControlPoints(bool alert_LPE) } ++spi; } - builder.finish(); + builder.flush(); Geom::PathVector pathv = builder.peek() * (_edit_transform * _i2d_transform).inverse(); _spcurve->set_pathvector(pathv); if (alert_LPE) { -- cgit v1.2.3 From 71abe5b8c4ed9e53a6a7299e4abc0deeb2c586a7 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Mon, 13 Jan 2014 13:55:24 +0100 Subject: Add GUI for feComponentTransfer filter primitive. (bzr r12923) --- src/ui/dialog/filter-effects-dialog.cpp | 246 ++++++++++++++++++++++++++++---- src/ui/dialog/filter-effects-dialog.h | 5 +- 2 files changed, 220 insertions(+), 31 deletions(-) (limited to 'src/ui') diff --git a/src/ui/dialog/filter-effects-dialog.cpp b/src/ui/dialog/filter-effects-dialog.cpp index 38e05a1c7..6a3a4c3f1 100644 --- a/src/ui/dialog/filter-effects-dialog.cpp +++ b/src/ui/dialog/filter-effects-dialog.cpp @@ -47,6 +47,7 @@ #include "filters/blend.h" #include "filters/colormatrix.h" #include "filters/componenttransfer.h" +#include "filters/componenttransfer-funcnode.h" #include "filters/composite.h" #include "filters/convolvematrix.h" #include "filters/displacementmap.h" @@ -369,6 +370,36 @@ public: } }; +// Used for tableValue in feComponentTransfer +class EntryAttr : public Gtk::Entry, public AttrWidget +{ +public: + EntryAttr(const SPAttributeEnum a, char* tip_text) + : AttrWidget(a) + { + signal_changed().connect(signal_attr_changed().make_slot()); + if (tip_text) { + set_tooltip_text(tip_text); + } + } + + // No validity checking is done + Glib::ustring get_as_attribute() const + { + return get_text(); + } + + void set_from_attribute(SPObject* o) + { + const gchar* val = attribute_value(o); + if(val) { + set_text( val ); + } else { + set_text( "" ); + } + } +}; + /* Displays/Edits the matrix for feConvolveMatrix or feColorMatrix */ class FilterEffectsDialog::MatrixAttr : public Gtk::Frame, public AttrWidget { @@ -746,7 +777,7 @@ public: _groups[i] = new Gtk::VBox; b.pack_start(*_groups[i], false, false); } - _current_type = 0; + //_current_type = 0; If set to 0 then update_and_show() fails to update properly. } ~Settings() @@ -766,9 +797,9 @@ public: for(unsigned i = 0; i < _groups.size(); ++i) _groups[i]->hide(); } - if(t >= 0) - _groups[t]->show_all(); - + if(t >= 0) { + _groups[t]->show(); // Do not use show_all(), it shows children than should be hidden + } _dialog.set_attrs_locked(true); for(unsigned i = 0; i < _attrwidgets[_current_type].size(); ++i) _attrwidgets[_current_type][i]->set_from_attribute(ob); @@ -800,7 +831,10 @@ public: // LightSource LightSourceControl* add_lightsource(); - // CheckBox + // Component Transfer Values + ComponentTransferValues* add_componenttransfervalues(const Glib::ustring& label, SPFeFuncNode::Channel channel); + + // CheckButton CheckButtonAttr* add_checkbutton(bool def, const SPAttributeEnum attr, const Glib::ustring& label, const Glib::ustring& tv, const Glib::ustring& fv, char* tip_text = NULL) { @@ -938,6 +972,18 @@ public: add_attr_widget(combo->get_attrwidget()); return combo->get_attrwidget(); } + + // Entry + EntryAttr* add_entry(const SPAttributeEnum attr, + const Glib::ustring& label, + char* tip_text = NULL) + { + EntryAttr* entry = new EntryAttr(attr, tip_text); + add_widget(entry, label); + add_attr_widget(entry); + return entry; + } + private: void add_attr_widget(AttrWidget* a) { @@ -973,6 +1019,154 @@ private: int _current_type, _max_types; }; +// Displays sliders and/or tables for feComponentTransfer +class FilterEffectsDialog::ComponentTransferValues : public Gtk::Frame, public AttrWidget +{ +public: + ComponentTransferValues(FilterEffectsDialog& d, SPFeFuncNode::Channel channel) + : AttrWidget(SP_ATTR_INVALID), + _dialog(d), + _settings(d, _box, sigc::mem_fun(*this, &ComponentTransferValues::set_func_attr), COMPONENTTRANSFER_TYPE_ERROR), + _type(ComponentTransferTypeConverter, SP_ATTR_TYPE, false), + _channel(channel), + _funcNode(NULL) + { + set_shadow_type(Gtk::SHADOW_IN); + add(_box); + _box.add(_type); + _box.reorder_child(_type, 0); + _type.signal_changed().connect(sigc::mem_fun(*this, &ComponentTransferValues::on_type_changed)); + + _settings.type(COMPONENTTRANSFER_TYPE_LINEAR); + _settings.add_spinscale(1, SP_ATTR_SLOPE, _("Slope"), -10, 10, 0.1, 0.01, 2); + _settings.add_spinscale(0, SP_ATTR_INTERCEPT, _("Intercept"), -10, 10, 0.1, 0.01, 2); + + _settings.type(COMPONENTTRANSFER_TYPE_GAMMA); + _settings.add_spinscale(1, SP_ATTR_AMPLITUDE, _("Amplitude"), 0, 10, 0.1, 0.01, 2); + _settings.add_spinscale(1, SP_ATTR_EXPONENT, _("Exponent"), 0, 10, 0.1, 0.01, 2); + _settings.add_spinscale(0, SP_ATTR_OFFSET, _("Offset"), -10, 10, 0.1, 0.01, 2); + + _settings.type(COMPONENTTRANSFER_TYPE_TABLE); + _settings.add_entry(SP_ATTR_TABLEVALUES, _("Table")); + + _settings.type(COMPONENTTRANSFER_TYPE_DISCRETE); + _settings.add_entry(SP_ATTR_TABLEVALUES, _("Discrete")); + + //_settings.type(COMPONENTTRANSFER_TYPE_IDENTITY); + _settings.type(-1); // Force update_and_show() to show/hide windows correctly + } + + // FuncNode can be in any order so we must search to find correct one. + SPFeFuncNode* find_node(SPFeComponentTransfer* ct) + { + SPObject* node = ct->children; + SPFeFuncNode* funcNode = NULL; + bool found = false; + for(;node;node=node->next){ + funcNode = SP_FEFUNCNODE(node); + if( funcNode->channel == _channel ) { + found = true; + break; + } + } + if( !found ) + funcNode = NULL; + + return funcNode; + } + + void set_func_attr(const AttrWidget* input) + { + _dialog.set_attr( _funcNode, input->get_attribute(), input->get_as_attribute().c_str()); + } + + // Set new type and update widget visibility + virtual void set_from_attribute(SPObject* o) + { + // See componenttransfer.cpp + if(SP_IS_FECOMPONENTTRANSFER(o)) { + SPFeComponentTransfer* ct = SP_FECOMPONENTTRANSFER(o); + + _funcNode = find_node(ct); + if( _funcNode ) { + _type.set_from_attribute( _funcNode ); + } else { + // Create + SPFilterPrimitive* prim = _dialog._primitive_list.get_selected(); + if(prim) { + Inkscape::XML::Document *xml_doc = prim->document->getReprDoc(); + Inkscape::XML::Node *repr = NULL; + switch(_channel) { + case SPFeFuncNode::R: + repr = xml_doc->createElement("svg:feFuncR"); + break; + case SPFeFuncNode::G: + repr = xml_doc->createElement("svg:feFuncG"); + break; + case SPFeFuncNode::B: + repr = xml_doc->createElement("svg:feFuncB"); + break; + case SPFeFuncNode::A: + repr = xml_doc->createElement("svg:feFuncA"); + break; + } + + //XML Tree being used directly here while it shouldn't be. + prim->getRepr()->appendChild(repr); + Inkscape::GC::release(repr); + + // Now we should find it! + _funcNode = find_node(ct); + if( _funcNode ) { + _funcNode->setAttribute( "type", "identity" ); + } else { + //std::cout << "ERROR ERROR: feFuncX not found!" << std::endl; + } + } + } + + update(); + } + } + +private: + void on_type_changed() + { + SPFilterPrimitive* prim = _dialog._primitive_list.get_selected(); + if(prim) { + + _funcNode->getRepr()->setAttribute( "type", _type.get_as_attribute().c_str() ); + + SPFilter* filter = _dialog._filter_modifier.get_selected_filter(); + filter->requestModified(SP_OBJECT_MODIFIED_FLAG); + + DocumentUndo::done(prim->document, SP_VERB_DIALOG_FILTER_EFFECTS, _("New transfer function type")); + update(); + } + } + + void update() + { + SPFilterPrimitive* prim = _dialog._primitive_list.get_selected(); + if(prim && _funcNode) { + _settings.show_and_update(_type.get_active_data()->id, _funcNode); + } + } + +public: + virtual Glib::ustring get_as_attribute() const + { + return ""; + } + + FilterEffectsDialog& _dialog; + Gtk::VBox _box; + Settings _settings; + ComboBoxEnum _type; + SPFeFuncNode::Channel _channel; // RGBA + SPFeFuncNode* _funcNode; +}; + // Settings for the three light source objects class FilterEffectsDialog::LightSourceControl : public AttrWidget { @@ -1012,6 +1206,9 @@ public: _settings.add_spinscale(1, SP_ATTR_SPECULAREXPONENT, _("Specular Exponent"), 1, 100, 1, 1, 0, _("Exponent value controlling the focus for the light source")); //TODO: here I have used 100 degrees as default value. But spec says that if not specified, no limiting cone is applied. So, there should be a way for the user to set a "no limiting cone" option. _settings.add_spinscale(100, SP_ATTR_LIMITINGCONEANGLE, _("Cone Angle"), 1, 100, 1, 1, 0, _("This is the angle between the spot light axis (i.e. the axis between the light source and the point to which it is pointing at) and the spot light cone. No light is projected outside this cone.")); + + _settings.type(-1); // Force update_and_show() to show/hide windows correctly + } Gtk::VBox& get_box() @@ -1102,6 +1299,16 @@ private: bool _locked; }; + // ComponentTransferValues +FilterEffectsDialog::ComponentTransferValues* FilterEffectsDialog::Settings::add_componenttransfervalues(const Glib::ustring& label, SPFeFuncNode::Channel channel) + { + ComponentTransferValues* ct = new ComponentTransferValues(_dialog, channel); + add_widget(ct, label); + add_attr_widget(ct); + return ct; + } + + FilterEffectsDialog::LightSourceControl* FilterEffectsDialog::Settings::add_lightsource() { LightSourceControl* ls = new LightSourceControl(_dialog); @@ -2527,7 +2734,6 @@ FilterEffectsDialog::FilterEffectsDialog() _sizegroup->set_ignore_hidden(); _add_primitive_type.remove_row(NR_FILTER_TILE); - _add_primitive_type.remove_row(NR_FILTER_COMPONENTTRANSFER); // Initialize widget hierarchy #if WITH_GTKMM_3_0 @@ -2629,15 +2835,10 @@ void FilterEffectsDialog::init_settings_widgets() colmat->signal_attr_changed().connect(sigc::mem_fun(*this, &FilterEffectsDialog::update_color_matrix)); _settings->type(NR_FILTER_COMPONENTTRANSFER); - _settings->add_notimplemented(); - /* - //TRANSLATORS: for info on "Slope" and "Intercept", see http://id.mind.net/~zona/mmts/functionInstitute/linearFunctions/lsif.html - _settings->add_combo(COMPONENTTRANSFER_TYPE_IDENTITY, SP_ATTR_TYPE, _("Type"), ComponentTransferTypeConverter); - _ct_slope = _settings->add_spinscale(1, SP_ATTR_SLOPE, _("Slope"), -10, 10, 0.1, 0.01, 2); - _ct_intercept = _settings->add_spinscale(0, SP_ATTR_INTERCEPT, _("Intercept"), -10, 10, 0.1, 0.01, 2); - _ct_amplitude = _settings->add_spinscale(1, SP_ATTR_AMPLITUDE, _("Amplitude"), 0, 10, 0.1, 0.01, 2); - _ct_exponent = _settings->add_spinscale(1, SP_ATTR_EXPONENT, _("Exponent"), 0, 10, 0.1, 0.01, 2); - _ct_offset = _settings->add_spinscale(0, SP_ATTR_OFFSET, _("Offset"), -10, 10, 0.1, 0.01, 2);*/ + _settings->add_componenttransfervalues(_("R:"), SPFeFuncNode::R); + _settings->add_componenttransfervalues(_("G:"), SPFeFuncNode::G); + _settings->add_componenttransfervalues(_("B:"), SPFeFuncNode::B); + _settings->add_componenttransfervalues(_("A:"), SPFeFuncNode::A); _settings->type(NR_FILTER_COMPOSITE); _settings->add_combo(COMPOSITE_OVER, SP_ATTR_OPERATOR, _("Operator:"), CompositeOperatorConverter); @@ -2953,21 +3154,6 @@ void FilterEffectsDialog::update_settings_sensitivity() _k3->set_sensitive(use_k); _k4->set_sensitive(use_k); -// Component transfer not yet implemented -/* - if(SP_IS_FECOMPONENTTRANSFER(prim)) { - SPFeComponentTransfer* ct = SP_FECOMPONENTTRANSFER(prim); - const bool linear = ct->type == COMPONENTTRANSFER_TYPE_LINEAR; - const bool gamma = ct->type == COMPONENTTRANSFER_TYPE_GAMMA; - - _ct_table->set_sensitive(ct->type == COMPONENTTRANSFER_TYPE_TABLE || ct->type == COMPONENTTRANSFER_TYPE_DISCRETE); - _ct_slope->set_sensitive(linear); - _ct_intercept->set_sensitive(linear); - _ct_amplitude->set_sensitive(gamma); - _ct_exponent->set_sensitive(gamma); - _ct_offset->set_sensitive(gamma); - } -*/ } void FilterEffectsDialog::update_color_matrix() diff --git a/src/ui/dialog/filter-effects-dialog.h b/src/ui/dialog/filter-effects-dialog.h index a2a2a3c6e..ccf79e60d 100644 --- a/src/ui/dialog/filter-effects-dialog.h +++ b/src/ui/dialog/filter-effects-dialog.h @@ -282,6 +282,7 @@ private: class Settings; class MatrixAttr; class ColorMatrixValues; + class ComponentTransferValues; class LightSourceControl; Settings* _settings; Settings* _filter_general_settings; @@ -290,6 +291,9 @@ private: // Color Matrix ColorMatrixValues* _color_matrix_values; + // Component Transfer + ComponentTransferValues* _component_transfer_values; + // Convolve Matrix MatrixAttr* _convolve_matrix; DualSpinButton* _convolve_order; @@ -297,7 +301,6 @@ private: // For controlling setting sensitivity Gtk::Widget* _k1, *_k2, *_k3, *_k4; - Gtk::Widget* _ct_table, *_ct_slope, *_ct_intercept, *_ct_amplitude, *_ct_exponent, *_ct_offset; // To prevent unwanted signals bool _locked; -- cgit v1.2.3 From 1261aa2ea7b3a229f7606dde8ddb7dc73752a1bc Mon Sep 17 00:00:00 2001 From: Martin Owens Date: Tue, 14 Jan 2014 10:55:26 -0500 Subject: Fix bug #1239779 by removing caching for symbols. Fixed bugs: - https://launchpad.net/bugs/1239779 (bzr r12924) --- src/ui/dialog/symbols.cpp | 65 ++++++++++++++--------------------------------- src/ui/dialog/symbols.h | 7 +++-- 2 files changed, 22 insertions(+), 50 deletions(-) (limited to 'src/ui') diff --git a/src/ui/dialog/symbols.cpp b/src/ui/dialog/symbols.cpp index fb353fec1..2f2652bb1 100644 --- a/src/ui/dialog/symbols.cpp +++ b/src/ui/dialog/symbols.cpp @@ -73,8 +73,6 @@ namespace Inkscape { namespace UI { -static Cache::SvgPreview svg_preview_cache; - namespace Dialog { // See: http://developer.gnome.org/gtkmm/stable/classGtk_1_1TreeModelColumnRecord.html @@ -276,7 +274,7 @@ SymbolsDialog::SymbolsDialog( gchar const* prefsPath ) : instanceConns.push_back(documentReplacedConn); get_symbols(); - draw_symbols( currentDocument ); /* Defaults to current document */ + add_symbols( currentDocument ); /* Defaults to current document */ sigc::connection desktopChangeConn = deskTrack.connectDesktopChanged( sigc::mem_fun(*this, &SymbolsDialog::setTargetDesktop) ); @@ -329,7 +327,7 @@ void SymbolsDialog::rebuild() { addSymbol->set_sensitive( false ); removeSymbol->set_sensitive( false ); } - draw_symbols( symbolDocument ); + add_symbols( symbolDocument ); } void SymbolsDialog::insertSymbol() { @@ -651,18 +649,18 @@ gchar const* SymbolsDialog::style_from_use( gchar const* id, SPDocument* documen return style; } -void SymbolsDialog::draw_symbols( SPDocument* symbolDocument ) { +void SymbolsDialog::add_symbols( SPDocument* symbolDocument ) { GSList* l = symbols_in_doc( symbolDocument ); for( ; l != NULL; l = l->next ) { SPObject* symbol = SP_OBJECT(l->data); if (SP_IS_SYMBOL(symbol)) { - draw_symbol( symbol ); + add_symbol( symbol ); } } } -void SymbolsDialog::draw_symbol( SPObject* symbol ) { +void SymbolsDialog::add_symbol( SPObject* symbol ) { SymbolColumns* columns = getColumns(); @@ -672,7 +670,7 @@ void SymbolsDialog::draw_symbol( SPObject* symbol ) { title = id; } - Glib::RefPtr pixbuf = create_symbol_image(id, symbol ); + Glib::RefPtr pixbuf = draw_symbol( symbol ); if( pixbuf ) { Gtk::ListStore::iterator row = store->append(); @@ -694,7 +692,7 @@ void SymbolsDialog::draw_symbol( SPObject* symbol ) { * the temporary document is rendered. */ Glib::RefPtr -SymbolsDialog::create_symbol_image(gchar const *symbol_id, SPObject *symbol) +SymbolsDialog::draw_symbol(SPObject *symbol) { // Create a copy repr of the symbol with id="the_symbol" Inkscape::XML::Document *xml_doc = previewDocument->getReprDoc(); @@ -713,7 +711,8 @@ SymbolsDialog::create_symbol_image(gchar const *symbol_id, SPObject *symbol) if( !style ) { // If no default style in , look in documents. if( symbol->document == currentDocument ) { - style = style_from_use( symbol_id, symbol->document ); + gchar const *id = symbol->getRepr()->attribute("id"); + style = style_from_use( id, symbol->document ); } else { style = symbol->document->getReprRoot()->attribute("style"); } @@ -722,9 +721,7 @@ SymbolsDialog::create_symbol_image(gchar const *symbol_id, SPObject *symbol) if( !style ) style = "fill:#bbbbbb;stroke:#808080"; // This is for display in Symbols dialog only - if( style ) { - repr->setAttribute( "style", style ); - } + if( style ) repr->setAttribute( "style", style ); // BUG: Symbols don't work if defined outside of . Causes Inkscape // crash when trying to read in such a file. @@ -733,7 +730,7 @@ SymbolsDialog::create_symbol_image(gchar const *symbol_id, SPObject *symbol) Inkscape::GC::release(repr); // Uncomment this to get the previewDocument documents saved (useful for debugging) - // FILE *fp = fopen (g_strconcat(symbol_id, ".svg", NULL), "w"); + // FILE *fp = fopen (g_strconcat(id, ".svg", NULL), "w"); // sp_repr_save_stream(previewDocument->getReprDoc(), fp); // fclose (fp); @@ -746,55 +743,31 @@ SymbolsDialog::create_symbol_image(gchar const *symbol_id, SPObject *symbol) previewDocument->getRoot()->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); previewDocument->ensureUpToDate(); - // if( object_temp == NULL || !SP_IS_ITEM(object_temp) ) { - // //std::cout << " previewDocument broken?" << std::endl; - // //return 0; - // } - SPItem *item = SP_ITEM(object_temp); - unsigned psize = SYMBOL_ICON_SIZES[in_sizes]; - /* Update to renderable state */ - Glib::ustring key = svg_preview_cache.cache_key(previewDocument->getURI(), symbol_id, psize); - //std::cout << " Key: " << key << std::endl; - Glib::RefPtr pixbuf(NULL); - GdkPixbuf *pixbuf_gobj = svg_preview_cache.get_preview_from_cache(key); - if (pixbuf_gobj) { - g_object_ref(pixbuf_gobj); // the reference in svg_preview_cache will get destroyed when it's freed - pixbuf = Glib::wrap(pixbuf_gobj); - } + // We could use cache here, but it doesn't really work with the structure + // of this user interface and we've already cached the pixbuf in the gtklist // Find object's bbox in document. // Note symbols can have own viewport... ignore for now. //Geom::OptRect dbox = item->geometricBounds(); Geom::OptRect dbox = item->documentVisualBounds(); - if (!dbox) { - //std::cout << " No dbox" << std::endl; - return pixbuf; - } - - if (!pixbuf) { + if (dbox) { /* Scale symbols to fit */ double scale = 1.0; double width = dbox->width(); double height = dbox->height(); - if( width == 0.0 ) { - width = 1.0; - } - if( height == 0.0 ) { - height = 1.0; - } - if( fitSymbol->get_active() ) { - /* Fit */ - scale = psize/std::max(width,height); - } + if( width == 0.0 ) width = 1.0; + if( height == 0.0 ) height = 1.0; + + if( fitSymbol->get_active() ) + scale = psize / std::max(width, height); pixbuf = Glib::wrap(render_pixbuf(renderDrawing, scale, *dbox, psize)); - svg_preview_cache.set_preview_in_cache(key, pixbuf->gobj()); } return pixbuf; diff --git a/src/ui/dialog/symbols.h b/src/ui/dialog/symbols.h index 074af6764..8021fb0c1 100644 --- a/src/ui/dialog/symbols.h +++ b/src/ui/dialog/symbols.h @@ -79,8 +79,8 @@ private: void iconDragDataGet(const Glib::RefPtr& context, Gtk::SelectionData& selection_data, guint info, guint time); void get_symbols(); - void draw_symbols( SPDocument* symbol_document ); - void draw_symbol( SPObject* symbol_document ); + void add_symbols( SPDocument* symbol_document ); + void add_symbol( SPObject* symbol_document ); SPDocument* symbols_preview_doc(); GSList* symbols_in_doc_recursive(SPObject *r, GSList *l); @@ -89,8 +89,7 @@ private: GSList* use_in_doc( SPDocument* document ); gchar const* style_from_use( gchar const* id, SPDocument* document); - Glib::RefPtr - create_symbol_image(gchar const *symbol_name, SPObject *symbol); + Glib::RefPtr draw_symbol(SPObject *symbol); /* Keep track of all symbol template documents */ std::map symbolSets; -- cgit v1.2.3 From bfc7eb940ec9472a1a01af0f3622f8419bd30051 Mon Sep 17 00:00:00 2001 From: Alex Valavanis Date: Tue, 14 Jan 2014 21:24:09 +0000 Subject: multi-path-manipulator: strip dead code (bzr r12930) --- src/ui/tool/multi-path-manipulator.cpp | 11 ----------- 1 file changed, 11 deletions(-) (limited to 'src/ui') diff --git a/src/ui/tool/multi-path-manipulator.cpp b/src/ui/tool/multi-path-manipulator.cpp index 1c683f717..65987ad52 100644 --- a/src/ui/tool/multi-path-manipulator.cpp +++ b/src/ui/tool/multi-path-manipulator.cpp @@ -30,17 +30,6 @@ #include -#ifdef USE_GNU_HASHES -namespace __gnu_cxx { -template<> -struct hash { - size_t operator()(Inkscape::UI::NodeList::iterator const &n) const { - return reinterpret_cast(n.ptr()); - } -}; -} // namespace __gnu_cxx -#endif // USE_GNU_HASHES - namespace Inkscape { namespace UI { -- cgit v1.2.3 From 9d40e9669a1024b7caed1db4c5ff99e06c96a57f Mon Sep 17 00:00:00 2001 From: Nicolas Dufour Date: Wed, 15 Jan 2014 16:26:12 +0100 Subject: Fix for Bug #1236282 (add full keyboard navigation support for new templates dialog). Fixed bugs: - https://launchpad.net/bugs/1236282 (bzr r12934) --- src/ui/dialog/new-from-template.cpp | 7 +++++-- src/ui/dialog/new-from-template.h | 3 +++ src/ui/dialog/template-load-tab.cpp | 7 ++++--- 3 files changed, 12 insertions(+), 5 deletions(-) (limited to 'src/ui') diff --git a/src/ui/dialog/new-from-template.cpp b/src/ui/dialog/new-from-template.cpp index 177f15195..71d1c22d0 100644 --- a/src/ui/dialog/new-from-template.cpp +++ b/src/ui/dialog/new-from-template.cpp @@ -44,10 +44,13 @@ NewFromTemplate::NewFromTemplate() void NewFromTemplate::_createFromTemplate() { _main_widget.createTemplate(); - - response(0); + _onClose(); } +void NewFromTemplate::_onClose() +{ + response(0); +} void NewFromTemplate::load_new_from_template() { diff --git a/src/ui/dialog/new-from-template.h b/src/ui/dialog/new-from-template.h index 8ebcb2863..2b40af2a6 100644 --- a/src/ui/dialog/new-from-template.h +++ b/src/ui/dialog/new-from-template.h @@ -23,6 +23,8 @@ namespace UI { class NewFromTemplate : public Gtk::Dialog { + +friend class TemplateLoadTab; public: static void load_new_from_template(); @@ -32,6 +34,7 @@ private: TemplateLoadTab _main_widget; void _createFromTemplate(); + void _onClose(); }; } diff --git a/src/ui/dialog/template-load-tab.cpp b/src/ui/dialog/template-load-tab.cpp index 057eff337..1b9b734fc 100644 --- a/src/ui/dialog/template-load-tab.cpp +++ b/src/ui/dialog/template-load-tab.cpp @@ -10,6 +10,7 @@ #include "template-widget.h" #include "template-load-tab.h" +#include "new-from-template.h" #include #include @@ -31,10 +32,8 @@ #include "xml/document.h" #include "xml/node.h" - namespace Inkscape { namespace UI { - TemplateLoadTab::TemplateLoadTab() : _current_keyword("") @@ -84,7 +83,9 @@ void TemplateLoadTab::createTemplate() void TemplateLoadTab::_onRowActivated(const Gtk::TreeModel::Path &, Gtk::TreeViewColumn*) { - _info_widget->create(); + createTemplate(); + NewFromTemplate* parent = static_cast (this->get_toplevel()); + parent->_onClose(); } void TemplateLoadTab::_displayTemplateInfo() -- cgit v1.2.3 From 82f4d9a7537fdb3267bf5570cd34aef0692b0f9f Mon Sep 17 00:00:00 2001 From: Alvin Penner Date: Wed, 15 Jan 2014 14:22:31 -0500 Subject: for rubberband outline, add shading instead of XOR (Bug 1266308) Fixed bugs: - https://launchpad.net/bugs/1266308 (bzr r12936) --- src/ui/tools/text-tool.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/ui') diff --git a/src/ui/tools/text-tool.cpp b/src/ui/tools/text-tool.cpp index 2927606a7..c73164c09 100644 --- a/src/ui/tools/text-tool.cpp +++ b/src/ui/tools/text-tool.cpp @@ -154,6 +154,7 @@ void TextTool::setup() { this->indicator = sp_canvas_item_new(sp_desktop_controls(desktop), SP_TYPE_CTRLRECT, NULL); SP_CTRLRECT(this->indicator)->setRectangle(Geom::Rect(Geom::Point(0, 0), Geom::Point(100, 100))); SP_CTRLRECT(this->indicator)->setColor(0x0000ff7f, false, 0); + SP_CTRLRECT(this->indicator)->setShadow(1, 0xffffff7f); sp_canvas_item_hide(this->indicator); this->frame = sp_canvas_item_new(sp_desktop_controls(desktop), SP_TYPE_CTRLRECT, NULL); -- cgit v1.2.3 From d1a182e5e94e5967d1ef19519e25e41ed81f3e9e Mon Sep 17 00:00:00 2001 From: Nicolas Dufour Date: Wed, 15 Jan 2014 22:08:27 +0100 Subject: i18n. New from Template entries now translatable (see Bug #383844). POT file and French translation updated. Fixed bugs: - https://launchpad.net/bugs/383844 (bzr r12937) --- src/ui/dialog/template-load-tab.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/ui') diff --git a/src/ui/dialog/template-load-tab.cpp b/src/ui/dialog/template-load-tab.cpp index 1b9b734fc..4f2d51ef7 100644 --- a/src/ui/dialog/template-load-tab.cpp +++ b/src/ui/dialog/template-load-tab.cpp @@ -291,26 +291,26 @@ void TemplateLoadTab::_getDataFromNode(Inkscape::XML::Node *dataNode, TemplateDa { Inkscape::XML::Node *currentData; if ((currentData = sp_repr_lookup_name(dataNode, "inkscape:_name")) != NULL) - data.display_name = dgettext("Document template name", currentData->firstChild()->content()); + data.display_name = _(currentData->firstChild()->content()); if ((currentData = sp_repr_lookup_name(dataNode, "inkscape:author")) != NULL) data.author = currentData->firstChild()->content(); if ((currentData = sp_repr_lookup_name(dataNode, "inkscape:_shortdesc")) != NULL) - data.short_description = dgettext("Document template short description", currentData->firstChild()->content()); + data.short_description = _( currentData->firstChild()->content()); if ((currentData = sp_repr_lookup_name(dataNode, "inkscape:_long") )!= NULL) - data.long_description = dgettext("Document template long description", currentData->firstChild()->content()); + data.long_description = _(currentData->firstChild()->content()); if ((currentData = sp_repr_lookup_name(dataNode, "inkscape:preview")) != NULL) data.preview_name = currentData->firstChild()->content(); if ((currentData = sp_repr_lookup_name(dataNode, "inkscape:date")) != NULL) data.creation_date = currentData->firstChild()->content(); if ((currentData = sp_repr_lookup_name(dataNode, "inkscape:_keywords")) != NULL){ - Glib::ustring tplKeywords = currentData->firstChild()->content(); + Glib::ustring tplKeywords = _(currentData->firstChild()->content()); while (!tplKeywords.empty()){ std::size_t pos = tplKeywords.find_first_of(" "); if (pos == Glib::ustring::npos) pos = tplKeywords.size(); - Glib::ustring keyword = dgettext("Document template keyword", tplKeywords.substr(0, pos).data()); + Glib::ustring keyword = tplKeywords.substr(0, pos).data(); data.keywords.insert(keyword.lowercase()); _keywords.insert(keyword.lowercase()); -- cgit v1.2.3 From 4531eff8dbddaabfb1c67d7907879480a8fd7309 Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Thu, 16 Jan 2014 22:12:33 +0100 Subject: fix null pointer dereference (bzr r12943) --- src/ui/tools/gradient-tool.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/ui') diff --git a/src/ui/tools/gradient-tool.cpp b/src/ui/tools/gradient-tool.cpp index e4ab7b424..10f78a8a8 100644 --- a/src/ui/tools/gradient-tool.cpp +++ b/src/ui/tools/gradient-tool.cpp @@ -339,10 +339,12 @@ sp_gradient_context_add_stops_between_selected_stops (GradientTool *rc) SPGradient *gradient = getGradient(d->item, d->fill_or_stroke); SPGradient *vector = sp_gradient_get_forked_vector_if_necessary (gradient, false); SPStop *this_stop = sp_get_stop_i (vector, d->point_i); - SPStop *next_stop = this_stop->getNextStop(); - if (this_stop && next_stop) { - these_stops = g_slist_prepend (these_stops, this_stop); - next_stops = g_slist_prepend (next_stops, next_stop); + if (this_stop) { + SPStop *next_stop = this_stop->getNextStop(); + if (next_stop) { + these_stops = g_slist_prepend (these_stops, this_stop); + next_stops = g_slist_prepend (next_stops, next_stop); + } } } } -- cgit v1.2.3 From 90867e5163a560f8905badd1a91f1688b6d9b36c Mon Sep 17 00:00:00 2001 From: Nicolas Dufour Date: Fri, 17 Jan 2014 14:29:51 +0100 Subject: i18n. Symbols are now translatable (see Bug #1261198); POT file and French translation updated. (bzr r12946) --- src/ui/dialog/symbols.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/ui') diff --git a/src/ui/dialog/symbols.cpp b/src/ui/dialog/symbols.cpp index 2f2652bb1..9a154209e 100644 --- a/src/ui/dialog/symbols.cpp +++ b/src/ui/dialog/symbols.cpp @@ -538,7 +538,8 @@ void SymbolsDialog::get_symbols() { gchar *fullname = g_build_filename((*it).c_str(), filename, NULL); - if ( !Inkscape::IO::file_test( fullname, G_FILE_TEST_IS_DIR ) ) { + if ( !Inkscape::IO::file_test( fullname, G_FILE_TEST_IS_DIR ) + && ( Glib::str_has_suffix(fullname, ".svg") || Glib::str_has_suffix(fullname, ".vss") ) ) { Glib::ustring fn( filename ); Glib::ustring tag = fn.substr( fn.find_last_of(".") + 1 ); @@ -560,7 +561,7 @@ void SymbolsDialog::get_symbols() { symbol_doc = SPDocument::createNewDoc( fullname, FALSE ); if( symbol_doc ) { - gchar *title = symbol_doc->getRoot()->title(); + const gchar *title = g_dpgettext2(NULL, "Symbol", symbol_doc->getRoot()->title()); if( title == NULL ) { title = _("Unnamed Symbols"); } @@ -675,7 +676,7 @@ void SymbolsDialog::add_symbol( SPObject* symbol ) { if( pixbuf ) { Gtk::ListStore::iterator row = store->append(); (*row)[columns->symbol_id] = Glib::ustring( id ); - (*row)[columns->symbol_title] = Glib::ustring( title ); + (*row)[columns->symbol_title] = Glib::ustring( g_dpgettext2(NULL, "Symbol", title) ); (*row)[columns->symbol_image] = pixbuf; } -- cgit v1.2.3 From 34414ec8b460d990ba48b3ed6a8e94dccc260d1f Mon Sep 17 00:00:00 2001 From: Nicolas Dufour Date: Fri, 17 Jan 2014 19:02:54 +0100 Subject: GTK3 build error in symbols.cpp. (bzr r12949) --- src/ui/dialog/symbols.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/ui') diff --git a/src/ui/dialog/symbols.cpp b/src/ui/dialog/symbols.cpp index 9a154209e..be22c1c5b 100644 --- a/src/ui/dialog/symbols.cpp +++ b/src/ui/dialog/symbols.cpp @@ -49,6 +49,7 @@ #include "symbols.h" +#include "filedialog.h" #include "selection.h" #include "desktop.h" #include "desktop-handles.h" @@ -539,7 +540,7 @@ void SymbolsDialog::get_symbols() { gchar *fullname = g_build_filename((*it).c_str(), filename, NULL); if ( !Inkscape::IO::file_test( fullname, G_FILE_TEST_IS_DIR ) - && ( Glib::str_has_suffix(fullname, ".svg") || Glib::str_has_suffix(fullname, ".vss") ) ) { + && ( hasSuffix(fullname, ".svg") || hasSuffix(fullname, ".vss") ) ) { Glib::ustring fn( filename ); Glib::ustring tag = fn.substr( fn.find_last_of(".") + 1 ); -- cgit v1.2.3 From ab4ca32239250dd70c615ec37dad2a552b66038c Mon Sep 17 00:00:00 2001 From: Nicolas Dufour Date: Fri, 17 Jan 2014 19:07:22 +0100 Subject: Better fix for GTK3 build error in symbols.cpp. (bzr r12950) --- src/ui/dialog/symbols.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/ui') diff --git a/src/ui/dialog/symbols.cpp b/src/ui/dialog/symbols.cpp index be22c1c5b..c33920117 100644 --- a/src/ui/dialog/symbols.cpp +++ b/src/ui/dialog/symbols.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include "path-prefix.h" @@ -49,7 +50,6 @@ #include "symbols.h" -#include "filedialog.h" #include "selection.h" #include "desktop.h" #include "desktop-handles.h" @@ -540,7 +540,7 @@ void SymbolsDialog::get_symbols() { gchar *fullname = g_build_filename((*it).c_str(), filename, NULL); if ( !Inkscape::IO::file_test( fullname, G_FILE_TEST_IS_DIR ) - && ( hasSuffix(fullname, ".svg") || hasSuffix(fullname, ".vss") ) ) { + && ( Glib::str_has_suffix(fullname, ".svg") || Glib::str_has_suffix(fullname, ".vss") ) ) { Glib::ustring fn( filename ); Glib::ustring tag = fn.substr( fn.find_last_of(".") + 1 ); -- cgit v1.2.3 From eac3c11251e65774a2f4f610f2799592978487d8 Mon Sep 17 00:00:00 2001 From: Martin Owens Date: Sun, 19 Jan 2014 00:38:09 -0500 Subject: Try another fix for the undo when dragging bug #168695 Fixed bugs: - https://launchpad.net/bugs/168695 (bzr r12955) --- src/ui/tools/tool-base.cpp | 14 +++++++++++--- src/ui/tools/tool-base.h | 1 + 2 files changed, 12 insertions(+), 3 deletions(-) (limited to 'src/ui') diff --git a/src/ui/tools/tool-base.cpp b/src/ui/tools/tool-base.cpp index 6c7867633..f8868ec0e 100644 --- a/src/ui/tools/tool-base.cpp +++ b/src/ui/tools/tool-base.cpp @@ -57,6 +57,7 @@ #include "shape-editor.h" #include "sp-guide.h" #include "color.h" +#include "document-undo.h" // globals for temporary switching to selector by space static bool selector_toggled = FALSE; @@ -977,9 +978,16 @@ gint sp_event_context_root_handler(ToolBase * event_context, gint sp_event_context_virtual_root_handler(ToolBase * event_context, GdkEvent * event) { gint ret = false; - if (event_context) { // If no event-context is available then do nothing, otherwise Inkscape would crash - // (see the comment in SPDesktop::set_event_context, and bug LP #622350) - //ret = (SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(event_context)))->root_handler(event_context, event); + if (event_context) { + // We want to disable undo while we drag anything + SPDocument *document = sp_desktop_document(event_context->desktop); + if (event->type == GDK_BUTTON_PRESS) { + event_context->undo_sensitive = DocumentUndo::getUndoSensitive(document); + DocumentUndo::setUndoSensitive(document, false); + } else if (event->type == GDK_BUTTON_RELEASE) { + DocumentUndo::setUndoSensitive(document, event_context->undo_sensitive); + } + ret = event_context->root_handler(event); set_event_location(event_context->desktop, event); diff --git a/src/ui/tools/tool-base.h b/src/ui/tools/tool-base.h index 7ed5875b1..068bc6402 100644 --- a/src/ui/tools/tool-base.h +++ b/src/ui/tools/tool-base.h @@ -119,6 +119,7 @@ public: gint xp, yp; ///< where drag started gint tolerance; bool within_tolerance; ///< are we still within tolerance of origin + bool undo_sensitive; /// Was undo previously sensitive before drag SPItem *item_to_select; ///< the item where mouse_press occurred, to ///< be selected if this is a click not drag -- cgit v1.2.3 From 367d97e047f3b1e1fe544efb7f15061d1e83fbf0 Mon Sep 17 00:00:00 2001 From: Nicolas Dufour Date: Sun, 19 Jan 2014 16:48:47 +0100 Subject: i18n. No need to translate strings with one single space. (bzr r12958) --- src/ui/dialog/template-widget.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/ui') diff --git a/src/ui/dialog/template-widget.cpp b/src/ui/dialog/template-widget.cpp index d1697244e..d8e6f9b4f 100644 --- a/src/ui/dialog/template-widget.cpp +++ b/src/ui/dialog/template-widget.cpp @@ -34,7 +34,7 @@ namespace UI { TemplateWidget::TemplateWidget() : _more_info_button(_("More info")) - , _short_description_label(_(" ")) + , _short_description_label(" ") , _template_name_label(_("no template selected")) , _effect_prefs(NULL) { -- cgit v1.2.3 From cca2c219973a60fb6535836559aa42ec2b9cb630 Mon Sep 17 00:00:00 2001 From: Martin Owens Date: Sun, 19 Jan 2014 20:30:15 -0500 Subject: Revert changes from r12959 and r12955, impliment new stratedgy to fix bug #168695 Fixed bugs: - https://launchpad.net/bugs/168695 (bzr r12960) --- src/ui/tools/tool-base.cpp | 16 ++++++---------- src/ui/tools/tool-base.h | 3 ++- 2 files changed, 8 insertions(+), 11 deletions(-) (limited to 'src/ui') diff --git a/src/ui/tools/tool-base.cpp b/src/ui/tools/tool-base.cpp index f8868ec0e..3b51147e0 100644 --- a/src/ui/tools/tool-base.cpp +++ b/src/ui/tools/tool-base.cpp @@ -57,7 +57,6 @@ #include "shape-editor.h" #include "sp-guide.h" #include "color.h" -#include "document-undo.h" // globals for temporary switching to selector by space static bool selector_toggled = FALSE; @@ -99,6 +98,7 @@ ToolBase::ToolBase() { this->hot_x = 0; this->yp = 0; this->within_tolerance = false; + this->is_dragging = false; this->tolerance = 0; //this->key = 0; this->item_to_select = 0; @@ -979,18 +979,14 @@ gint sp_event_context_root_handler(ToolBase * event_context, gint sp_event_context_virtual_root_handler(ToolBase * event_context, GdkEvent * event) { gint ret = false; if (event_context) { - // We want to disable undo while we drag anything - SPDocument *document = sp_desktop_document(event_context->desktop); - if (event->type == GDK_BUTTON_PRESS) { - event_context->undo_sensitive = DocumentUndo::getUndoSensitive(document); - DocumentUndo::setUndoSensitive(document, false); - } else if (event->type == GDK_BUTTON_RELEASE) { - DocumentUndo::setUndoSensitive(document, event_context->undo_sensitive); - } + if(event->type == GDK_BUTTON_PRESS) + event_context->is_dragging = true; ret = event_context->root_handler(event); - set_event_location(event_context->desktop, event); + + if(event->type == GDK_BUTTON_RELEASE) + event_context->is_dragging = false; } return ret; } diff --git a/src/ui/tools/tool-base.h b/src/ui/tools/tool-base.h index 068bc6402..ab8bd8caa 100644 --- a/src/ui/tools/tool-base.h +++ b/src/ui/tools/tool-base.h @@ -118,8 +118,9 @@ public: gint xp, yp; ///< where drag started gint tolerance; + bool is_dragging; // Is a tool currently dragging something + bool within_tolerance; ///< are we still within tolerance of origin - bool undo_sensitive; /// Was undo previously sensitive before drag SPItem *item_to_select; ///< the item where mouse_press occurred, to ///< be selected if this is a click not drag -- cgit v1.2.3 From 1534dc84087db1b26f1e86e79436eb63f3dffd3f Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Mon, 20 Jan 2014 20:56:38 +0100 Subject: cppcheck stuff (bzr r12963) --- src/ui/dialog/template-load-tab.cpp | 7 ++----- src/ui/tools/text-tool.cpp | 4 ++-- 2 files changed, 4 insertions(+), 7 deletions(-) (limited to 'src/ui') diff --git a/src/ui/dialog/template-load-tab.cpp b/src/ui/dialog/template-load-tab.cpp index 4f2d51ef7..6b1f4542f 100644 --- a/src/ui/dialog/template-load-tab.cpp +++ b/src/ui/dialog/template-load-tab.cpp @@ -220,12 +220,9 @@ TemplateLoadTab::TemplateData TemplateLoadTab::_processTemplateFile(const std::s n = result.display_name.rfind(".svg"); result.display_name.replace(n, 4, 1, ' '); - Inkscape::XML::Document *rdoc; - rdoc = sp_repr_read_file(path.data(), SP_SVG_NS_URI); - Inkscape::XML::Node *myRoot; - + Inkscape::XML::Document *rdoc = sp_repr_read_file(path.data(), SP_SVG_NS_URI); if (rdoc){ - myRoot = rdoc->root(); + Inkscape::XML::Node *myRoot = rdoc->root(); if (strcmp(myRoot->name(), "svg:svg") != 0){ // Wrong file format return result; } diff --git a/src/ui/tools/text-tool.cpp b/src/ui/tools/text-tool.cpp index c73164c09..9b5ab1016 100644 --- a/src/ui/tools/text-tool.cpp +++ b/src/ui/tools/text-tool.cpp @@ -1335,7 +1335,7 @@ bool sp_text_paste_inline(ToolBase *ec) paste_string_uchar == 0x00000009 || paste_string_uchar == 0x0000000A || paste_string_uchar == 0x0000000D) { - itr++; + ++itr; } else { itr = text.erase(itr); } @@ -1637,7 +1637,7 @@ static void sp_text_context_update_text_selection(TextTool *tc) // the selection update (can't do both atomically, alas) if (!tc->desktop) return; - for (std::vector::iterator it = tc->text_selection_quads.begin() ; it != tc->text_selection_quads.end() ; it++) { + for (std::vector::iterator it = tc->text_selection_quads.begin() ; it != tc->text_selection_quads.end() ; ++it) { sp_canvas_item_hide(*it); sp_canvas_item_destroy(*it); } -- cgit v1.2.3 From 29e005620b05165ffd5ad21c2a9751adac89d34a Mon Sep 17 00:00:00 2001 From: Martin Owens Date: Tue, 21 Jan 2014 10:21:10 -0500 Subject: Move dragging undo block from tools-base to canvas. Regarding bug #168695 (bzr r12967) --- src/ui/tools/tool-base.cpp | 7 ------- src/ui/tools/tool-base.h | 1 - 2 files changed, 8 deletions(-) (limited to 'src/ui') diff --git a/src/ui/tools/tool-base.cpp b/src/ui/tools/tool-base.cpp index 3b51147e0..cc028724a 100644 --- a/src/ui/tools/tool-base.cpp +++ b/src/ui/tools/tool-base.cpp @@ -98,7 +98,6 @@ ToolBase::ToolBase() { this->hot_x = 0; this->yp = 0; this->within_tolerance = false; - this->is_dragging = false; this->tolerance = 0; //this->key = 0; this->item_to_select = 0; @@ -979,14 +978,8 @@ gint sp_event_context_root_handler(ToolBase * event_context, gint sp_event_context_virtual_root_handler(ToolBase * event_context, GdkEvent * event) { gint ret = false; if (event_context) { - if(event->type == GDK_BUTTON_PRESS) - event_context->is_dragging = true; - ret = event_context->root_handler(event); set_event_location(event_context->desktop, event); - - if(event->type == GDK_BUTTON_RELEASE) - event_context->is_dragging = false; } return ret; } diff --git a/src/ui/tools/tool-base.h b/src/ui/tools/tool-base.h index ab8bd8caa..43edc4bd7 100644 --- a/src/ui/tools/tool-base.h +++ b/src/ui/tools/tool-base.h @@ -118,7 +118,6 @@ public: gint xp, yp; ///< where drag started gint tolerance; - bool is_dragging; // Is a tool currently dragging something bool within_tolerance; ///< are we still within tolerance of origin -- cgit v1.2.3 From 0605b3e5559d3124a89c1270ae9b453388c838c7 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Thu, 30 Jan 2014 11:22:46 +0100 Subject: Prevent crash if a symbols file does not have a title. (bzr r12985) --- src/ui/dialog/symbols.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/ui') diff --git a/src/ui/dialog/symbols.cpp b/src/ui/dialog/symbols.cpp index c33920117..7079ca001 100644 --- a/src/ui/dialog/symbols.cpp +++ b/src/ui/dialog/symbols.cpp @@ -562,10 +562,18 @@ void SymbolsDialog::get_symbols() { symbol_doc = SPDocument::createNewDoc( fullname, FALSE ); if( symbol_doc ) { - const gchar *title = g_dpgettext2(NULL, "Symbol", symbol_doc->getRoot()->title()); + + const gchar *title = symbol_doc->getRoot()->title(); + + // A user provided file may not have a title + if( title != NULL ) { + title = g_dpgettext2(NULL, "Symbol", title); // Translate + } + if( title == NULL ) { title = _("Unnamed Symbols"); } + symbolSets[Glib::ustring(title)] = symbol_doc; symbolSet->append(title); } -- cgit v1.2.3 From 77e7d632cbfdd00b7c6d61c952608ed6f26872f6 Mon Sep 17 00:00:00 2001 From: Martin Owens Date: Fri, 31 Jan 2014 14:36:53 -0500 Subject: Fix spacing/remove tabs and eliminate extra conditional. (bzr r12989) --- src/ui/dialog/symbols.cpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'src/ui') diff --git a/src/ui/dialog/symbols.cpp b/src/ui/dialog/symbols.cpp index 7079ca001..b3efb58f7 100644 --- a/src/ui/dialog/symbols.cpp +++ b/src/ui/dialog/symbols.cpp @@ -563,16 +563,14 @@ void SymbolsDialog::get_symbols() { symbol_doc = SPDocument::createNewDoc( fullname, FALSE ); if( symbol_doc ) { - const gchar *title = symbol_doc->getRoot()->title(); - - // A user provided file may not have a title - if( title != NULL ) { - title = g_dpgettext2(NULL, "Symbol", title); // Translate - } - - if( title == NULL ) { - title = _("Unnamed Symbols"); - } + const gchar *title = symbol_doc->getRoot()->title(); + + // A user provided file may not have a title + if( title != NULL ) { + title = g_dpgettext2(NULL, "Symbol", title); // Translate + } else { + title = _("Unnamed Symbols"); + } symbolSets[Glib::ustring(title)] = symbol_doc; symbolSet->append(title); -- cgit v1.2.3 From 69b758c9769ae3e38fea2e1ff04a6ed7450e75d9 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Sat, 1 Feb 2014 12:14:58 +0100 Subject: Fix some formatting problems and add formatting info at end of file. (bzr r12992) --- src/ui/dialog/symbols.cpp | 134 +++++++++++++++++++++++++--------------------- 1 file changed, 74 insertions(+), 60 deletions(-) (limited to 'src/ui') diff --git a/src/ui/dialog/symbols.cpp b/src/ui/dialog/symbols.cpp index b3efb58f7..98754fb4f 100644 --- a/src/ui/dialog/symbols.cpp +++ b/src/ui/dialog/symbols.cpp @@ -76,7 +76,7 @@ namespace UI { namespace Dialog { - // See: http://developer.gnome.org/gtkmm/stable/classGtk_1_1TreeModelColumnRecord.html +// See: http://developer.gnome.org/gtkmm/stable/classGtk_1_1TreeModelColumnRecord.html class SymbolColumns : public Gtk::TreeModel::ColumnRecord { public: @@ -399,11 +399,13 @@ SPDocument* SymbolsDialog::selectedSymbols() { } Glib::ustring SymbolsDialog::selectedSymbolId() { - #if WITH_GTKMM_3_0 - std::vector iconArray = iconView->get_selected_items(); - #else - Gtk::IconView::ArrayHandle_TreePaths iconArray = iconView->get_selected_items(); - #endif + +#if WITH_GTKMM_3_0 + std::vector iconArray = iconView->get_selected_items(); +#else + Gtk::IconView::ArrayHandle_TreePaths iconArray = iconView->get_selected_items(); +#endif + if( !iconArray.empty() ) { Gtk::TreeModel::Path const & path = *iconArray.begin(); Gtk::ListStore::iterator row = store->get_iter(path); @@ -428,12 +430,12 @@ void SymbolsDialog::iconChanged() { // First look for default style stored in gchar const* style = symbol->getAttribute("inkscape:symbol-style"); if( !style ) { - // If no default style in , look in documents. - if( symbolDocument == currentDocument ) { - style = style_from_use( symbol_id.c_str(), currentDocument ); - } else { - style = symbolDocument->getReprRoot()->attribute("style"); - } + // If no default style in , look in documents. + if( symbolDocument == currentDocument ) { + style = style_from_use( symbol_id.c_str(), currentDocument ); + } else { + style = symbolDocument->getReprRoot()->attribute("style"); + } } ClipboardManager *cm = ClipboardManager::get(); @@ -497,8 +499,8 @@ SPDocument* read_vss( gchar* fullname, gchar* filename ) { while( std::getline( iss, line ) ) { // std::cout << line << std::endl; if( line.find( "svg:svg" ) == std::string::npos ) { - tmpSVGOutput += line; - tmpSVGOutput += "\n"; + tmpSVGOutput += line; + tmpSVGOutput += "\n"; } } @@ -519,11 +521,11 @@ void SymbolsDialog::get_symbols() { std::list directories; if( Inkscape::IO::file_test( INKSCAPE_SYMBOLSDIR, G_FILE_TEST_EXISTS ) && - Inkscape::IO::file_test( INKSCAPE_SYMBOLSDIR, G_FILE_TEST_IS_DIR ) ) { + Inkscape::IO::file_test( INKSCAPE_SYMBOLSDIR, G_FILE_TEST_IS_DIR ) ) { directories.push_back( INKSCAPE_SYMBOLSDIR ); } if( Inkscape::IO::file_test( profile_path("symbols"), G_FILE_TEST_EXISTS ) && - Inkscape::IO::file_test( profile_path("symbols"), G_FILE_TEST_IS_DIR ) ) { + Inkscape::IO::file_test( profile_path("symbols"), G_FILE_TEST_IS_DIR ) ) { directories.push_back( profile_path("symbols") ); } @@ -534,53 +536,53 @@ void SymbolsDialog::get_symbols() { GDir *dir = g_dir_open( (*it).c_str(), 0, &err ); if( dir ) { - gchar *filename = 0; - while( (filename = (gchar *)g_dir_read_name( dir ) ) != NULL) { + gchar *filename = 0; + while( (filename = (gchar *)g_dir_read_name( dir ) ) != NULL) { - gchar *fullname = g_build_filename((*it).c_str(), filename, NULL); + gchar *fullname = g_build_filename((*it).c_str(), filename, NULL); - if ( !Inkscape::IO::file_test( fullname, G_FILE_TEST_IS_DIR ) - && ( Glib::str_has_suffix(fullname, ".svg") || Glib::str_has_suffix(fullname, ".vss") ) ) { + if ( !Inkscape::IO::file_test( fullname, G_FILE_TEST_IS_DIR ) + && ( Glib::str_has_suffix(fullname, ".svg") || Glib::str_has_suffix(fullname, ".vss") ) ) { - Glib::ustring fn( filename ); - Glib::ustring tag = fn.substr( fn.find_last_of(".") + 1 ); + Glib::ustring fn( filename ); + Glib::ustring tag = fn.substr( fn.find_last_of(".") + 1 ); - SPDocument* symbol_doc = NULL; + SPDocument* symbol_doc = NULL; #ifdef WITH_LIBVISIO - if( tag.compare( "vss" ) == 0 ) { + if( tag.compare( "vss" ) == 0 ) { - symbol_doc = read_vss( fullname, filename ); - if( symbol_doc ) { - symbolSets[Glib::ustring(filename)]= symbol_doc; - symbolSet->append(filename); - } - } + symbol_doc = read_vss( fullname, filename ); + if( symbol_doc ) { + symbolSets[Glib::ustring(filename)]= symbol_doc; + symbolSet->append(filename); + } + } #endif - // Try to read all remaining files as SVG - if( !symbol_doc ) { + // Try to read all remaining files as SVG + if( !symbol_doc ) { + + symbol_doc = SPDocument::createNewDoc( fullname, FALSE ); + if( symbol_doc ) { - symbol_doc = SPDocument::createNewDoc( fullname, FALSE ); - if( symbol_doc ) { + const gchar *title = symbol_doc->getRoot()->title(); - const gchar *title = symbol_doc->getRoot()->title(); + // A user provided file may not have a title + if( title != NULL ) { + title = g_dpgettext2(NULL, "Symbol", title); // Translate + } else { + title = _("Unnamed Symbols"); + } - // A user provided file may not have a title - if( title != NULL ) { - title = g_dpgettext2(NULL, "Symbol", title); // Translate - } else { - title = _("Unnamed Symbols"); + symbolSets[Glib::ustring(title)] = symbol_doc; + symbolSet->append(title); + } } - symbolSets[Glib::ustring(title)] = symbol_doc; - symbolSet->append(title); } + g_free( fullname ); } - - } - g_free( fullname ); - } - g_dir_close( dir ); + g_dir_close( dir ); } } } @@ -642,16 +644,16 @@ gchar const* SymbolsDialog::style_from_use( gchar const* id, SPDocument* documen for( ; l != NULL; l = l->next ) { SPObject* use = SP_OBJECT(l->data); if( SP_IS_USE( use ) ) { - gchar const *href = use->getRepr()->attribute("xlink:href"); - if( href ) { - Glib::ustring href2(href); - Glib::ustring id2(id); - id2 = "#" + id2; - if( !href2.compare(id2) ) { - style = use->getRepr()->attribute("style"); - break; - } - } + gchar const *href = use->getRepr()->attribute("xlink:href"); + if( href ) { + Glib::ustring href2(href); + Glib::ustring id2(id); + id2 = "#" + id2; + if( !href2.compare(id2) ) { + style = use->getRepr()->attribute("style"); + break; + } + } } } return style; @@ -808,8 +810,8 @@ void SymbolsDialog::setTargetDesktop(SPDesktop *desktop) if (this->currentDesktop != desktop) { this->currentDesktop = desktop; if( !symbolSets[symbolSet->get_active_text()] ) { - // Symbol set is from Current document, update - rebuild(); + // Symbol set is from Current document, update + rebuild(); } } } @@ -817,3 +819,15 @@ void SymbolsDialog::setTargetDesktop(SPDesktop *desktop) } //namespace Dialogs } //namespace UI } //namespace Inkscape + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-basic-offset:2 + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=2:tabstop=8:softtabstop=2:fileencoding=utf-8:textwidth=99 : -- cgit v1.2.3 From 28faf1002334ac22523e7a0cf78f170de9e91f9a Mon Sep 17 00:00:00 2001 From: Nicolas Dufour Date: Tue, 4 Feb 2014 14:58:12 +0100 Subject: Workaround for Bug #1273510 (crash in in cc_generic_knot_handler() after tool-switch). (bzr r12996) --- src/ui/tools/connector-tool.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/ui') diff --git a/src/ui/tools/connector-tool.cpp b/src/ui/tools/connector-tool.cpp index 62d52f6af..50cb00360 100644 --- a/src/ui/tools/connector-tool.cpp +++ b/src/ui/tools/connector-tool.cpp @@ -1080,7 +1080,12 @@ cc_generic_knot_handler(SPCanvasItem *, GdkEvent *event, SPKnot *knot) case GDK_LEAVE_NOTIFY: sp_knot_set_flag(knot, SP_KNOT_MOUSEOVER, FALSE); - cc->active_handle = NULL; + /* FIXME: the following test is a workaround for LP Bug #1273510. + * It seems that a signal is not correctly disconnected, maybe + * something missing in cc_clear_active_conn()? */ + if (cc) { + cc->active_handle = NULL; + } if (knot_tip) { knot->desktop->event_context->defaultMessageContext()->clear(); -- cgit v1.2.3 From c7731033ef400fccb6a49d830ded86068fcd3432 Mon Sep 17 00:00:00 2001 From: Nicolas Dufour Date: Wed, 5 Feb 2014 12:29:11 +0100 Subject: Fix for Bug #1250685 (Unnecessary gender-specific terms in code). Fixed bugs: - https://launchpad.net/bugs/1250685 (bzr r12997) --- src/ui/tools/spray-tool.cpp | 56 ++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 28 deletions(-) (limited to 'src/ui') diff --git a/src/ui/tools/spray-tool.cpp b/src/ui/tools/spray-tool.cpp index 0ded1e44b..91c606e8e 100644 --- a/src/ui/tools/spray-tool.cpp +++ b/src/ui/tools/spray-tool.cpp @@ -404,7 +404,7 @@ static bool sp_spray_recursive(SPDesktop *desktop, SPItem *item_copied; if(_fid <= population) { - // duplicate + // Duplicate SPDocument *doc = item->document; Inkscape::XML::Document* xml_doc = doc->getReprDoc(); Inkscape::XML::Node *old_repr = item->getRepr(); @@ -413,13 +413,13 @@ static bool sp_spray_recursive(SPDesktop *desktop, parent->appendChild(copy); SPObject *new_obj = doc->getObjectByRepr(copy); - item_copied = SP_ITEM(new_obj); //convertion object->item + item_copied = SP_ITEM(new_obj); // Convertion object->item Geom::Point center=item->getCenter(); sp_spray_scale_rel(center,desktop, item_copied, Geom::Scale(_scale,_scale)); sp_spray_scale_rel(center,desktop, item_copied, Geom::Scale(scale,scale)); sp_spray_rotate_rel(center,desktop,item_copied, Geom::Rotate(angle)); - //Move the cursor p + // Move the cursor p Geom::Point move = (Geom::Point(cos(tilt)*cos(dp)*dr/(1-ratio)+sin(tilt)*sin(dp)*dr/(1+ratio), -sin(tilt)*cos(dp)*dr/(1-ratio)+cos(tilt)*sin(dp)*dr/(1+ratio)))+(p-a->midpoint()); sp_item_move_rel(item_copied, Geom::Translate(move[Geom::X], -move[Geom::Y])); did = true; @@ -427,10 +427,10 @@ static bool sp_spray_recursive(SPDesktop *desktop, } } else if (mode == SPRAY_MODE_SINGLE_PATH) { - SPItem *father = NULL; //initial Object - SPItem *item_copied = NULL; //Projected Object - SPItem *unionResult = NULL; //previous union - SPItem *son = NULL; //father copy + SPItem *parent_item = NULL; // Initial object + SPItem *item_copied = NULL; // Projected object + SPItem *unionResult = NULL; // Previous union + SPItem *child_item = NULL; // Parent copy int i=1; for (GSList *items = g_slist_copy(const_cast(selection->itemList())); @@ -439,31 +439,31 @@ static bool sp_spray_recursive(SPDesktop *desktop, SPItem *item1 = SP_ITEM(items->data); if (i == 1) { - father = item1; + parent_item = item1; } if (i == 2) { unionResult = item1; } i++; } - SPDocument *doc = father->document; + SPDocument *doc = parent_item->document; Inkscape::XML::Document* xml_doc = doc->getReprDoc(); - Inkscape::XML::Node *old_repr = father->getRepr(); + Inkscape::XML::Node *old_repr = parent_item->getRepr(); Inkscape::XML::Node *parent = old_repr->parent(); - Geom::OptRect a = father->documentVisualBounds(); + Geom::OptRect a = parent_item->documentVisualBounds(); if (a) { if (i == 2) { Inkscape::XML::Node *copy1 = old_repr->duplicate(xml_doc); parent->appendChild(copy1); SPObject *new_obj1 = doc->getObjectByRepr(copy1); - son = SP_ITEM(new_obj1); // conversion object->item - unionResult = son; + child_item = SP_ITEM(new_obj1); // Conversion object->item + unionResult = child_item; Inkscape::GC::release(copy1); } if (_fid <= population) { // Rules the population of objects sprayed - // duplicates the father + // Duplicates the parent item Inkscape::XML::Node *copy2 = old_repr->duplicate(xml_doc); parent->appendChild(copy2); SPObject *new_obj2 = doc->getObjectByRepr(copy2); @@ -472,18 +472,18 @@ static bool sp_spray_recursive(SPDesktop *desktop, // Move around the cursor Geom::Point move = (Geom::Point(cos(tilt)*cos(dp)*dr/(1-ratio)+sin(tilt)*sin(dp)*dr/(1+ratio), -sin(tilt)*cos(dp)*dr/(1-ratio)+cos(tilt)*sin(dp)*dr/(1+ratio)))+(p-a->midpoint()); - Geom::Point center=father->getCenter(); + Geom::Point center = parent_item->getCenter(); sp_spray_scale_rel(center, desktop, item_copied, Geom::Scale(_scale, _scale)); sp_spray_scale_rel(center, desktop, item_copied, Geom::Scale(scale, scale)); sp_spray_rotate_rel(center, desktop, item_copied, Geom::Rotate(angle)); sp_item_move_rel(item_copied, Geom::Translate(move[Geom::X], -move[Geom::Y])); - // union and duplication + // Union and duplication selection->clear(); selection->add(item_copied); selection->add(unionResult); sp_selected_path_union_skip_undo(selection, selection->desktop()); - selection->add(father); + selection->add(parent_item); Inkscape::GC::release(copy2); did = true; } @@ -500,15 +500,15 @@ static bool sp_spray_recursive(SPDesktop *desktop, // Creation of the clone Inkscape::XML::Node *clone = xml_doc->createElement("svg:use"); - // Ad the clone to the list of the father's sons + // Ad the clone to the list of the parent's children parent->appendChild(clone); - // Generates the link between father and son attributes + // Generates the link between parent and child attributes gchar *href_str = g_strdup_printf("#%s", old_repr->attribute("id")); clone->setAttribute("xlink:href", href_str, false); g_free(href_str); SPObject *clone_object = doc->getObjectByRepr(clone); - // conversion object->item + // Conversion object->item item_copied = SP_ITEM(clone_object); Geom::Point center = item->getCenter(); sp_spray_scale_rel(center, desktop, item_copied, Geom::Scale(_scale, _scale)); @@ -582,9 +582,9 @@ static void sp_spray_update_area(SprayTool *tc) static void sp_spray_switch_mode(SprayTool *tc, gint mode, bool with_shift) { - // select the button mode + // Select the button mode SP_EVENT_CONTEXT(tc)->desktop->setToolboxSelectOneValue("spray_tool_mode", mode); - // need to set explicitly, because the prefs may not have changed by the previous + // Need to set explicitly, because the prefs may not have changed by the previous tc->mode = mode; tc->update_cursor(with_shift); } @@ -631,7 +631,7 @@ bool SprayTool::root_handler(GdkEvent* event) { Geom::Point motion_doc(desktop->dt2doc(motion_dt)); sp_spray_extinput(this, event); - // draw the dilating cursor + // Draw the dilating cursor double radius = get_dilate_radius(this); Geom::Affine const sm (Geom::Scale(radius/(1-this->ratio), radius/(1+this->ratio)) ); sp_canvas_item_affine_absolute(this->dilate_area, (sm*Geom::Rotate(this->tilt))*Geom::Translate(desktop->w2d(motion_w))); @@ -645,19 +645,19 @@ bool SprayTool::root_handler(GdkEvent* event) { this->message_context->flash(Inkscape::ERROR_MESSAGE, _("Nothing selected! Select objects to spray.")); } - // dilating: + // Dilating: if (this->is_drawing && ( event->motion.state & GDK_BUTTON1_MASK )) { sp_spray_dilate(this, motion_w, motion_doc, motion_doc - this->last_push, event->button.state & GDK_SHIFT_MASK? true : false); //this->last_push = motion_doc; this->has_dilated = true; - // it's slow, so prevent clogging up with events + // It's slow, so prevent clogging up with events gobble_motion_events(GDK_BUTTON1_MASK); return TRUE; } } break; - /*Spray with the scroll*/ + /* Spray with the scroll */ case GDK_SCROLL: { if (event->scroll.state & GDK_BUTTON1_MASK) { double temp ; @@ -708,7 +708,7 @@ bool SprayTool::root_handler(GdkEvent* event) { if (this->is_dilating && event->button.button == 1 && !this->space_panning) { if (!this->has_dilated) { - // if we did not rub, do a light tap + // If we did not rub, do a light tap this->pressure = 0.03; sp_spray_dilate(this, motion_w, desktop->dt2doc(motion_dt), Geom::Point(0,0), MOD__SHIFT(event)); } @@ -784,7 +784,7 @@ bool SprayTool::root_handler(GdkEvent* event) { if (this->width > 1.0) { this->width = 1.0; } - // the same spinbutton is for alt+x + // The same spinbutton is for alt+x desktop->setToolboxAdjustmentValue("altx-spray", this->width * 100); sp_spray_update_area(this); ret = TRUE; -- cgit v1.2.3 From d4ba8eaa4a621ac60d99a4aad7531d080cece2cd Mon Sep 17 00:00:00 2001 From: David Mathog Date: Sat, 8 Feb 2014 09:44:12 +0100 Subject: DrawingContext: change variable names ct to dc (bug #1272073) Fixed bugs: - https://launchpad.net/bugs/1272073 (bzr r13009) --- src/ui/cache/svg_preview_cache.cpp | 4 ++-- src/ui/dialog/clonetiler.cpp | 4 ++-- src/ui/tools/flood-tool.cpp | 12 ++++++------ 3 files changed, 10 insertions(+), 10 deletions(-) (limited to 'src/ui') diff --git a/src/ui/cache/svg_preview_cache.cpp b/src/ui/cache/svg_preview_cache.cpp index a09489f6d..f1d6304cb 100644 --- a/src/ui/cache/svg_preview_cache.cpp +++ b/src/ui/cache/svg_preview_cache.cpp @@ -56,9 +56,9 @@ GdkPixbuf* render_pixbuf(Inkscape::Drawing &drawing, double scale_factor, Geom:: /* Render */ cairo_surface_t *s = cairo_image_surface_create( CAIRO_FORMAT_ARGB32, psize, psize); - Inkscape::DrawingContext ct(s, area.min()); + Inkscape::DrawingContext dc(s, area.min()); - drawing.render(ct, area, Inkscape::DrawingItem::RENDER_BYPASS_CACHE); + drawing.render(dc, area, Inkscape::DrawingItem::RENDER_BYPASS_CACHE); cairo_surface_flush(s); GdkPixbuf* pixbuf = ink_pixbuf_create_from_cairo_surface(s); diff --git a/src/ui/dialog/clonetiler.cpp b/src/ui/dialog/clonetiler.cpp index 87c399339..fb131d8da 100644 --- a/src/ui/dialog/clonetiler.cpp +++ b/src/ui/dialog/clonetiler.cpp @@ -2063,9 +2063,9 @@ guint32 CloneTiler::clonetiler_trace_pick(Geom::Rect box) /* Find visible area */ cairo_surface_t *s = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, ibox.width(), ibox.height()); - Inkscape::DrawingContext ct(s, ibox.min()); + Inkscape::DrawingContext dc(s, ibox.min()); /* Render */ - trace_drawing->render(ct, ibox); + trace_drawing->render(dc, ibox); double R = 0, G = 0, B = 0, A = 0; ink_cairo_surface_average_color(s, R, G, B, A); cairo_surface_destroy(s); diff --git a/src/ui/tools/flood-tool.cpp b/src/ui/tools/flood-tool.cpp index 0b72bc9f2..4e29b8856 100644 --- a/src/ui/tools/flood-tool.cpp +++ b/src/ui/tools/flood-tool.cpp @@ -794,7 +794,7 @@ static void sp_flood_do_flood_fill(ToolBase *event_context, GdkEvent *event, boo cairo_surface_t *s = cairo_image_surface_create_for_data( px, CAIRO_FORMAT_ARGB32, width, height, stride); - Inkscape::DrawingContext ct(s, Geom::Point(0,0)); + Inkscape::DrawingContext dc(s, Geom::Point(0,0)); // cairo_translate not necessary here - surface origin is at 0,0 SPNamedView *nv = sp_desktop_namedview(desktop); @@ -802,12 +802,12 @@ static void sp_flood_do_flood_fill(ToolBase *event_context, GdkEvent *event, boo // bgcolor is 0xrrggbbaa, we need 0xaarrggbb dtc = (bgcolor >> 8) | (bgcolor << 24); - ct.setSource(bgcolor); - ct.setOperator(CAIRO_OPERATOR_SOURCE); - ct.paint(); - ct.setOperator(CAIRO_OPERATOR_OVER); + dc.setSource(bgcolor); + dc.setOperator(CAIRO_OPERATOR_SOURCE); + dc.paint(); + dc.setOperator(CAIRO_OPERATOR_OVER); - drawing.render(ct, final_bbox); + drawing.render(dc, final_bbox); //cairo_surface_write_to_png( s, "cairo.png" ); -- cgit v1.2.3 From 75ceef199c1032a2424b3aaa01c8027cea3f9ef1 Mon Sep 17 00:00:00 2001 From: Nicolas Dufour Date: Sat, 8 Feb 2014 16:02:17 +0100 Subject: Fix for Bug #879058 (Spray Single Path Mode includes original object). Fixed bugs: - https://launchpad.net/bugs/879058 (bzr r13011) --- src/ui/tools/spray-tool.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/ui') diff --git a/src/ui/tools/spray-tool.cpp b/src/ui/tools/spray-tool.cpp index 91c606e8e..4ea482461 100644 --- a/src/ui/tools/spray-tool.cpp +++ b/src/ui/tools/spray-tool.cpp @@ -453,7 +453,7 @@ static bool sp_spray_recursive(SPDesktop *desktop, Geom::OptRect a = parent_item->documentVisualBounds(); if (a) { - if (i == 2) { + if (i == 1) { Inkscape::XML::Node *copy1 = old_repr->duplicate(xml_doc); parent->appendChild(copy1); SPObject *new_obj1 = doc->getObjectByRepr(copy1); -- cgit v1.2.3 From c984c2542484ace0c54bab9e353f0c29a45f6023 Mon Sep 17 00:00:00 2001 From: Nicolas Dufour Date: Sun, 16 Feb 2014 11:55:22 +0100 Subject: Fix console messages (see Bug #879058 - Spray Single Path Mode includes original object). Fixed bugs: - https://launchpad.net/bugs/879058 (bzr r13031) --- src/ui/tools/spray-tool.cpp | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) (limited to 'src/ui') diff --git a/src/ui/tools/spray-tool.cpp b/src/ui/tools/spray-tool.cpp index 4ea482461..14a3acd9a 100644 --- a/src/ui/tools/spray-tool.cpp +++ b/src/ui/tools/spray-tool.cpp @@ -430,7 +430,6 @@ static bool sp_spray_recursive(SPDesktop *desktop, SPItem *parent_item = NULL; // Initial object SPItem *item_copied = NULL; // Projected object SPItem *unionResult = NULL; // Previous union - SPItem *child_item = NULL; // Parent copy int i=1; for (GSList *items = g_slist_copy(const_cast(selection->itemList())); @@ -453,21 +452,12 @@ static bool sp_spray_recursive(SPDesktop *desktop, Geom::OptRect a = parent_item->documentVisualBounds(); if (a) { - if (i == 1) { - Inkscape::XML::Node *copy1 = old_repr->duplicate(xml_doc); - parent->appendChild(copy1); - SPObject *new_obj1 = doc->getObjectByRepr(copy1); - child_item = SP_ITEM(new_obj1); // Conversion object->item - unionResult = child_item; - Inkscape::GC::release(copy1); - } - if (_fid <= population) { // Rules the population of objects sprayed // Duplicates the parent item - Inkscape::XML::Node *copy2 = old_repr->duplicate(xml_doc); - parent->appendChild(copy2); - SPObject *new_obj2 = doc->getObjectByRepr(copy2); - item_copied = SP_ITEM(new_obj2); + Inkscape::XML::Node *copy = old_repr->duplicate(xml_doc); + parent->appendChild(copy); + SPObject *new_obj = doc->getObjectByRepr(copy); + item_copied = SP_ITEM(new_obj); // Move around the cursor Geom::Point move = (Geom::Point(cos(tilt)*cos(dp)*dr/(1-ratio)+sin(tilt)*sin(dp)*dr/(1+ratio), -sin(tilt)*cos(dp)*dr/(1-ratio)+cos(tilt)*sin(dp)*dr/(1+ratio)))+(p-a->midpoint()); @@ -481,10 +471,12 @@ static bool sp_spray_recursive(SPDesktop *desktop, // Union and duplication selection->clear(); selection->add(item_copied); - selection->add(unionResult); + if (unionResult) { // No need to add the very first item (initialized with NULL). + selection->add(unionResult); + } sp_selected_path_union_skip_undo(selection, selection->desktop()); selection->add(parent_item); - Inkscape::GC::release(copy2); + Inkscape::GC::release(copy); did = true; } } -- cgit v1.2.3 From ae57812b967d6d67ecb223537216e98d055c170e Mon Sep 17 00:00:00 2001 From: Alvin Penner Date: Mon, 17 Feb 2014 13:53:01 -0500 Subject: scaling of viewBox on document unit change (Bug 1236257) Fixed bugs: - https://launchpad.net/bugs/1236257 (bzr r13034) --- src/ui/dialog/document-properties.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/ui') diff --git a/src/ui/dialog/document-properties.cpp b/src/ui/dialog/document-properties.cpp index d324d2d1b..d344fb1d6 100644 --- a/src/ui/dialog/document-properties.cpp +++ b/src/ui/dialog/document-properties.cpp @@ -1703,9 +1703,14 @@ void DocumentProperties::onDocUnitChange() repr->setAttribute("inkscape:document-units", os.str().c_str()); // Set viewBox - Inkscape::Util::Quantity width = doc->getWidth(); - Inkscape::Util::Quantity height = doc->getHeight(); - doc->setViewBox(Geom::Rect::from_xywh(0, 0, width.value(doc_unit), height.value(doc_unit))); + if (doc->getRoot()->viewBox_set) { + gdouble scale = Inkscape::Util::Quantity::convert(1, old_doc_unit, doc_unit); + doc->setViewBox(doc->getRoot()->viewBox*Geom::Scale(scale)); + } else { + Inkscape::Util::Quantity width = doc->getWidth(); + Inkscape::Util::Quantity height = doc->getHeight(); + doc->setViewBox(Geom::Rect::from_xywh(0, 0, width.value(doc_unit), height.value(doc_unit))); + } // TODO: Fix bug in nodes tool instead of switching away from it if (tools_active(getDesktop()) == TOOLS_NODES) { -- cgit v1.2.3 From 1eee6e772bc5ab528982db64c68ceb4a46f7f0ac Mon Sep 17 00:00:00 2001 From: Nicolas Dufour Date: Wed, 19 Feb 2014 08:18:55 +0100 Subject: Fix for Bug #1281104 (Open Clipart import dialog crashes with concurrent searches). Fixed bugs: - https://launchpad.net/bugs/1281104 (bzr r13042) --- src/ui/dialog/ocaldialogs.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/ui') diff --git a/src/ui/dialog/ocaldialogs.cpp b/src/ui/dialog/ocaldialogs.cpp index 93fcab863..f676e75fd 100644 --- a/src/ui/dialog/ocaldialogs.cpp +++ b/src/ui/dialog/ocaldialogs.cpp @@ -1166,8 +1166,6 @@ void ImportDialog::on_xml_file_read(const Glib::RefPtr& result // free the document xmlFreeDoc(doc); - // free the global variables that may have been allocated by the parser - xmlCleanupParser(); } @@ -1336,7 +1334,8 @@ ImportDialog::ImportDialog(Gtk::Window& parent_window, FileDialogType file_types */ ImportDialog::~ImportDialog() { - + // free the global variables that may have been allocated by the parser + xmlCleanupParser(); } /** -- cgit v1.2.3 From eb6473340d55ce97b87d5ae6336afb5c1faea303 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Fri, 21 Feb 2014 13:40:25 +0100 Subject: Symbols dialog: update currentDesktop and currentDocument when document replaced. (bzr r13048) --- src/ui/dialog/symbols.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/ui') diff --git a/src/ui/dialog/symbols.cpp b/src/ui/dialog/symbols.cpp index 98754fb4f..62a2f8572 100644 --- a/src/ui/dialog/symbols.cpp +++ b/src/ui/dialog/symbols.cpp @@ -381,8 +381,10 @@ void SymbolsDialog::selectionChanged(Inkscape::Selection *selection) { } } -void SymbolsDialog::documentReplaced(SPDesktop */*desktop*/, SPDocument */*document*/) +void SymbolsDialog::documentReplaced(SPDesktop *desktop, SPDocument *document) { + currentDesktop = desktop; + currentDocument = document; rebuild(); } -- cgit v1.2.3 From b3dad97ff32d34dc38ce51ebbdc0e9555a9ce5e6 Mon Sep 17 00:00:00 2001 From: Alvin Penner Date: Sat, 22 Feb 2014 16:37:43 -0500 Subject: offset of viewBox on document unit change (Bug 1280684) Fixed bugs: - https://launchpad.net/bugs/1280684 (bzr r13050) --- src/ui/dialog/document-properties.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/ui') diff --git a/src/ui/dialog/document-properties.cpp b/src/ui/dialog/document-properties.cpp index d344fb1d6..0411c789c 100644 --- a/src/ui/dialog/document-properties.cpp +++ b/src/ui/dialog/document-properties.cpp @@ -1734,8 +1734,14 @@ void DocumentProperties::onDocUnitChange() prefs->setBool("/options/transform/gradient", true); { ShapeEditor::blockSetItem(true); + gdouble viewscale = doc->getWidth().value("px")/doc->getRoot()->viewBox.width(); + if (doc->getHeight().value("px")/doc->getRoot()->viewBox.height() < viewscale) + viewscale = doc->getHeight().value("px")/doc->getRoot()->viewBox.height(); gdouble scale = Inkscape::Util::Quantity::convert(1, old_doc_unit, doc_unit); - doc->getRoot()->scaleChildItemsRec(Geom::Scale(scale), Geom::Point(0, doc->getHeight().value("px"))); + doc->getRoot()->scaleChildItemsRec(Geom::Scale(scale), Geom::Point(-viewscale*doc->getRoot()->viewBox.min()[Geom::X] + + (doc->getWidth().value("px") - viewscale*doc->getRoot()->viewBox.width())/2, + viewscale*doc->getRoot()->viewBox.min()[Geom::Y] + + (doc->getHeight().value("px") + viewscale*doc->getRoot()->viewBox.height())/2)); ShapeEditor::blockSetItem(false); } prefs->setBool("/options/transform/stroke", transform_stroke); -- cgit v1.2.3 From 9657576ce874d32248bbbc2dc204ac2fb6121dea Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sun, 23 Feb 2014 20:30:28 +0100 Subject: Fix for selcue settings. Fixed bugs: - https://launchpad.net/bugs/1274659 (bzr r13051) --- src/ui/tools/dropper-tool.cpp | 2 ++ src/ui/tools/freehand-base.cpp | 2 ++ src/ui/tools/measure-tool.cpp | 2 ++ src/ui/tools/text-tool.cpp | 2 ++ src/ui/tools/zoom-tool.cpp | 2 ++ 5 files changed, 10 insertions(+) (limited to 'src/ui') diff --git a/src/ui/tools/dropper-tool.cpp b/src/ui/tools/dropper-tool.cpp index 9c47b50e9..88ed342df 100644 --- a/src/ui/tools/dropper-tool.cpp +++ b/src/ui/tools/dropper-tool.cpp @@ -152,6 +152,8 @@ void DropperTool::finish() { #endif cursor_dropper_fill = NULL; } + + ToolBase::finish(); } /** diff --git a/src/ui/tools/freehand-base.cpp b/src/ui/tools/freehand-base.cpp index c3c269743..1e0e6b3b6 100644 --- a/src/ui/tools/freehand-base.cpp +++ b/src/ui/tools/freehand-base.cpp @@ -167,6 +167,8 @@ void FreehandBase::finish() { } spdc_free_colors(this); + + ToolBase::finish(); } void FreehandBase::set(const Inkscape::Preferences::Entry& /*value*/) { diff --git a/src/ui/tools/measure-tool.cpp b/src/ui/tools/measure-tool.cpp index 0d823dfda..4d7f1e074 100644 --- a/src/ui/tools/measure-tool.cpp +++ b/src/ui/tools/measure-tool.cpp @@ -254,6 +254,8 @@ void MeasureTool::finish() { sp_canvas_item_ungrab(this->grabbed, GDK_CURRENT_TIME); this->grabbed = NULL; } + + ToolBase::finish(); } //void MeasureTool::setup() { diff --git a/src/ui/tools/text-tool.cpp b/src/ui/tools/text-tool.cpp index 9b5ab1016..ba68c7829 100644 --- a/src/ui/tools/text-tool.cpp +++ b/src/ui/tools/text-tool.cpp @@ -266,6 +266,8 @@ void TextTool::finish() { } this->text_selection_quads.clear(); + + ToolBase::finish(); } bool TextTool::item_handler(SPItem* item, GdkEvent* event) { diff --git a/src/ui/tools/zoom-tool.cpp b/src/ui/tools/zoom-tool.cpp index d4ede1053..0996e6cf4 100644 --- a/src/ui/tools/zoom-tool.cpp +++ b/src/ui/tools/zoom-tool.cpp @@ -63,6 +63,8 @@ void ZoomTool::finish() { sp_canvas_item_ungrab(this->grabbed, GDK_CURRENT_TIME); this->grabbed = NULL; } + + ToolBase::finish(); } void ZoomTool::setup() { -- cgit v1.2.3 From 457a6606406c6b5830fc6990866b1d2cd847602b Mon Sep 17 00:00:00 2001 From: Alvin Penner Date: Sun, 23 Feb 2014 19:48:29 -0500 Subject: fix typos in page-sizer (Bug 1240308) Fixed bugs: - https://launchpad.net/bugs/1240308 (bzr r13052) --- src/ui/widget/page-sizer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/ui') diff --git a/src/ui/widget/page-sizer.cpp b/src/ui/widget/page-sizer.cpp index b13567adb..b35f35403 100644 --- a/src/ui/widget/page-sizer.cpp +++ b/src/ui/widget/page-sizer.cpp @@ -555,7 +555,7 @@ PageSizer::find_paper_size (Inkscape::Util::Quantity w, Inkscape::Util::Quantity { double smaller = w.quantity; double larger = h.quantity; - if ( h < w ) { + if ( h.quantity < w.quantity ) { smaller = h.quantity; larger = w.quantity; } @@ -568,7 +568,7 @@ PageSizer::find_paper_size (Inkscape::Util::Quantity w, Inkscape::Util::Quantity double smallX = Inkscape::Util::Quantity::convert(paper.smaller, paper.unit, w.unit); double largeX = Inkscape::Util::Quantity::convert(paper.larger, paper.unit, w.unit); - g_return_val_if_fail(smallX <= largeX, _paperSizeListStore->children().end()); + g_return_val_if_fail(smallX < largeX + 0.001, _paperSizeListStore->children().end()); if ((std::abs(smaller - smallX) <= 0.1) && (std::abs(larger - largeX) <= 0.1) ) { -- cgit v1.2.3 From f6060c9447e6f2e5a70e957c19bd4eb1ae4babef Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Mon, 24 Feb 2014 20:32:07 +0100 Subject: inspired by r13052, fix up the code to hopefully work when someone has different units for height and width of the page. Fixed bugs: - https://launchpad.net/bugs/1240308 (bzr r13053) --- src/ui/widget/page-sizer.cpp | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) (limited to 'src/ui') diff --git a/src/ui/widget/page-sizer.cpp b/src/ui/widget/page-sizer.cpp index b35f35403..eae0d4a95 100644 --- a/src/ui/widget/page-sizer.cpp +++ b/src/ui/widget/page-sizer.cpp @@ -547,36 +547,40 @@ PageSizer::updateFitMarginsUI(Inkscape::XML::Node *nv_repr) /** * Returns an iterator pointing to a row in paperSizeListStore which - * contains a paper of the specified size (specified in px), or + * contains a paper of the specified size, or * paperSizeListStore->children().end() if no such paper exists. + * + * The code is not tested for the case where w and h have different units. */ Gtk::ListStore::iterator PageSizer::find_paper_size (Inkscape::Util::Quantity w, Inkscape::Util::Quantity h) const { - double smaller = w.quantity; - double larger = h.quantity; - if ( h.quantity < w.quantity ) { - smaller = h.quantity; larger = w.quantity; + using Inkscape::Util::Quantity; + using std::swap; + + // The code below assumes that w < h, so make sure that's the case: + if ( h < w ) { + swap(h,w); } - g_return_val_if_fail(smaller <= larger, _paperSizeListStore->children().end()); + g_return_val_if_fail(w <= h, _paperSizeListStore->children().end()); std::map::const_iterator iter; for (iter = _paperSizeTable.begin() ; iter != _paperSizeTable.end() ; ++iter) { PaperSize paper = iter->second; - double smallX = Inkscape::Util::Quantity::convert(paper.smaller, paper.unit, w.unit); - double largeX = Inkscape::Util::Quantity::convert(paper.larger, paper.unit, w.unit); + Quantity smallX (paper.smaller, paper.unit); + Quantity largeX (paper.larger, paper.unit); - g_return_val_if_fail(smallX < largeX + 0.001, _paperSizeListStore->children().end()); + g_return_val_if_fail(smallX.quantity < largeX.quantity + 0.001, _paperSizeListStore->children().end()); - if ((std::abs(smaller - smallX) <= 0.1) && - (std::abs(larger - largeX) <= 0.1) ) { - Gtk::ListStore::iterator p; + if ( are_near(w, smallX, 0.1) && are_near(h, largeX, 0.1) ) { + Gtk::ListStore::iterator p = _paperSizeListStore->children().begin(); + Gtk::ListStore::iterator pend = _paperSizeListStore->children().end(); // We need to search paperSizeListStore explicitly for the // specified paper size because it is sorted in a different // way than paperSizeTable (which is sorted alphabetically) - for (p = _paperSizeListStore->children().begin(); p != _paperSizeListStore->children().end(); ++p) { + for ( ; p != pend; ++p) { if ((*p)[_paperSizeListColumns.nameColumn] == paper.name) { return p; } @@ -601,7 +605,7 @@ PageSizer::fire_fit_canvas_to_selection_or_drawing() SPDocument *doc; SPNamedView *nv; Inkscape::XML::Node *nv_repr; - + if ((doc = sp_desktop_document(SP_ACTIVE_DESKTOP)) && (nv = sp_document_namedview(doc, 0)) && (nv_repr = nv->getRepr())) { -- cgit v1.2.3 From 0917cc6ed7207c0535360dd757705bda30410a47 Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Mon, 24 Feb 2014 21:28:00 +0100 Subject: Fix infinite loop (?) by disabling saving the order of filters when they are reordered by drag&drop in the filter editor dialog. (bug 1239296) Fixed bugs: - https://launchpad.net/bugs/1239296 (bzr r13055) --- src/ui/dialog/filter-effects-dialog.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/ui') diff --git a/src/ui/dialog/filter-effects-dialog.cpp b/src/ui/dialog/filter-effects-dialog.cpp index 6a3a4c3f1..e8b09db8b 100644 --- a/src/ui/dialog/filter-effects-dialog.cpp +++ b/src/ui/dialog/filter-effects-dialog.cpp @@ -1515,11 +1515,16 @@ void FilterEffectsDialog::FilterModifier::on_name_edited(const Glib::ustring& pa } void FilterEffectsDialog::FilterModifier::on_filter_reorder(const Gtk::TreeModel::Path& /*path*/) { +/* The code below is bugged. Use of "object->getRepr()->setPosition(0)" is dangerous! + Writing back the reordered list to XML (reordering XML nodes) should be implemented differently. + Note that the dialog does also not update its list of filters when the order is manually changed + using the XML dialog for(Gtk::TreeModel::iterator i = _model->children().begin(); i != _model->children().end(); ++i) { SPObject* object = (*i)[_columns.filter]; - if(object && object->getRepr()) + if(object && object->getRepr()) ; object->getRepr()->setPosition(0); } +*/ } void FilterEffectsDialog::FilterModifier::on_selection_toggled(const Glib::ustring& path) -- cgit v1.2.3 From b777ba99030a6ae4b44bb0a78ce6282f2d99cbe8 Mon Sep 17 00:00:00 2001 From: Martin Owens Date: Mon, 24 Feb 2014 20:09:35 -0500 Subject: Move filter reordering closer to the layers.cpp patern of reordering xml (bzr r13056) --- src/ui/dialog/filter-effects-dialog.cpp | 11 ++++++----- src/ui/dialog/filter-effects-dialog.h | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) (limited to 'src/ui') diff --git a/src/ui/dialog/filter-effects-dialog.cpp b/src/ui/dialog/filter-effects-dialog.cpp index e8b09db8b..b763776c6 100644 --- a/src/ui/dialog/filter-effects-dialog.cpp +++ b/src/ui/dialog/filter-effects-dialog.cpp @@ -1363,11 +1363,9 @@ FilterEffectsDialog::FilterModifier::FilterModifier(FilterEffectsDialog& d) sw->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); _list.get_column(1)->set_resizable(true); _list.set_reorderable(true); + _list.enable_model_drag_dest (Gdk::ACTION_MOVE); - // We can track the drag/drop reordering from the row_delete (occurs after - // row_inserted and may occur many times when adding a new item) - _model->signal_row_deleted().connect( - sigc::mem_fun(*this, &FilterModifier::on_filter_reorder)); + _list.signal_drag_drop().connect( sigc::mem_fun(*this, &FilterModifier::on_filter_move), false ); sw->set_shadow_type(Gtk::SHADOW_IN); show_all_children(); @@ -1514,7 +1512,9 @@ void FilterEffectsDialog::FilterModifier::on_name_edited(const Glib::ustring& pa } } -void FilterEffectsDialog::FilterModifier::on_filter_reorder(const Gtk::TreeModel::Path& /*path*/) { +bool FilterEffectsDialog::FilterModifier::on_filter_move(const Glib::RefPtr& /*context*/, int x, int y, guint /*time*/) { + +//const Gtk::TreeModel::Path& /*path*/) { /* The code below is bugged. Use of "object->getRepr()->setPosition(0)" is dangerous! Writing back the reordered list to XML (reordering XML nodes) should be implemented differently. Note that the dialog does also not update its list of filters when the order is manually changed @@ -1525,6 +1525,7 @@ void FilterEffectsDialog::FilterModifier::on_filter_reorder(const Gtk::TreeModel object->getRepr()->setPosition(0); } */ + return false; } void FilterEffectsDialog::FilterModifier::on_selection_toggled(const Glib::ustring& path) diff --git a/src/ui/dialog/filter-effects-dialog.h b/src/ui/dialog/filter-effects-dialog.h index ccf79e60d..3fc19e7de 100644 --- a/src/ui/dialog/filter-effects-dialog.h +++ b/src/ui/dialog/filter-effects-dialog.h @@ -86,7 +86,7 @@ private: void on_filter_selection_changed(); void on_name_edited(const Glib::ustring&, const Glib::ustring&); - void on_filter_reorder(const Gtk::TreeModel::Path& path); + bool on_filter_move(const Glib::RefPtr& /*context*/, int x, int y, guint /*time*/); void on_selection_toggled(const Glib::ustring&); void update_filters(); -- cgit v1.2.3 From 7e85379f54292595afe296e5f0be240f6c8f7835 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Wed, 26 Feb 2014 02:08:53 +0100 Subject: Made constructors of tools use initializer lists. (bzr r13060) --- src/ui/tools/arc-tool.cpp | 49 +++++++++---------------- src/ui/tools/box3d-tool.cpp | 23 ++++-------- src/ui/tools/calligraphic-tool.cpp | 34 ++++++++---------- src/ui/tools/connector-tool.cpp | 73 +++++++++++++++----------------------- src/ui/tools/dropper-tool.cpp | 26 ++++++-------- src/ui/tools/dynamic-base.cpp | 69 +++++++++++++++++------------------ src/ui/tools/dynamic-base.h | 8 ++--- src/ui/tools/eraser-tool.cpp | 7 ++-- src/ui/tools/flood-tool.cpp | 15 +++----- src/ui/tools/freehand-base.cpp | 56 +++++++++++++---------------- src/ui/tools/freehand-base.h | 4 +-- src/ui/tools/gradient-tool.cpp | 22 +++++------- src/ui/tools/lpe-tool.cpp | 18 +++++----- src/ui/tools/measure-tool.cpp | 10 +++--- src/ui/tools/mesh-tool.cpp | 24 ++++++------- src/ui/tools/node-tool.cpp | 45 +++++++++++------------ src/ui/tools/pen-tool.cpp | 65 ++++++++++++++++++++------------- src/ui/tools/pen-tool.h | 3 +- src/ui/tools/pencil-tool.cpp | 21 +++++------ src/ui/tools/rect-tool.cpp | 20 ++++------- src/ui/tools/select-tool.cpp | 36 +++++++++---------- src/ui/tools/select-tool.h | 4 +-- src/ui/tools/spiral-tool.cpp | 22 ++++-------- src/ui/tools/spray-tool.cpp | 53 +++++++++++++-------------- src/ui/tools/spray-tool.h | 8 ++--- src/ui/tools/star-tool.cpp | 28 +++++---------- src/ui/tools/text-tool.cpp | 51 +++++++++++--------------- src/ui/tools/text-tool.h | 10 +++--- src/ui/tools/tool-base.cpp | 42 +++++++++++----------- src/ui/tools/tool-base.h | 8 +++-- src/ui/tools/tweak-tool.cpp | 45 ++++++++++------------- src/ui/tools/tweak-tool.h | 6 ++-- src/ui/tools/zoom-tool.cpp | 11 +++--- 33 files changed, 402 insertions(+), 514 deletions(-) (limited to 'src/ui') diff --git a/src/ui/tools/arc-tool.cpp b/src/ui/tools/arc-tool.cpp index bb7dfa21c..435f4aa4b 100644 --- a/src/ui/tools/arc-tool.cpp +++ b/src/ui/tools/arc-tool.cpp @@ -69,18 +69,10 @@ const std::string& ArcTool::getPrefsPath() { const std::string ArcTool::prefsPath = "/tools/shapes/arc"; -ArcTool::ArcTool() : ToolBase() { - this->cursor_shape = cursor_ellipse_xpm; - this->hot_x = 4; - this->hot_y = 4; - this->xp = 0; - this->yp = 0; - this->tolerance = 0; - this->within_tolerance = false; - this->item_to_select = NULL; - //this->tool_url = "/tools/shapes/arc"; - - this->arc = NULL; +ArcTool::ArcTool() + : ToolBase(cursor_ellipse_xpm, 4, 4) + , arc(NULL) +{ } void ArcTool::finish() { @@ -142,13 +134,10 @@ void ArcTool::setup() { } bool ArcTool::item_handler(SPItem* item, GdkEvent* event) { - gint ret = FALSE; - switch (event->type) { case GDK_BUTTON_PRESS: if (event->button.button == 1 && !this->space_panning) { Inkscape::setup_for_drag_start(desktop, this, event); - ret = TRUE; } break; // motion and release are always on root (why?) @@ -156,13 +145,7 @@ bool ArcTool::item_handler(SPItem* item, GdkEvent* event) { break; } -// if ((SP_EVENT_CONTEXT_CLASS(sp_arc_context_parent_class))->item_handler) { -// ret = (SP_EVENT_CONTEXT_CLASS(sp_arc_context_parent_class))->item_handler(event_context, item, event); -// } - // CPPIFY: ret is overwritten... - ret = ToolBase::item_handler(item, event); - - return ret; + return ToolBase::item_handler(item, event); } bool ArcTool::root_handler(GdkEvent* event) { @@ -173,7 +156,7 @@ bool ArcTool::root_handler(GdkEvent* event) { this->tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100); - gint ret = FALSE; + bool handled = false; switch (event->type) { case GDK_BUTTON_PRESS: @@ -191,7 +174,7 @@ bool ArcTool::root_handler(GdkEvent* event) { GDK_KEY_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK, NULL, event->button.time); - ret = TRUE; + handled = true; m.unSetup(); } break; @@ -214,7 +197,7 @@ bool ArcTool::root_handler(GdkEvent* event) { gobble_motion_events(GDK_BUTTON1_MASK); - ret = TRUE; + handled = true; } else if (!sp_event_context_knot_mouseover(this)){ SnapManager &m = desktop->namedview->snap_manager; m.setup(desktop); @@ -249,7 +232,7 @@ bool ArcTool::root_handler(GdkEvent* event) { this->xp = 0; this->yp = 0; this->item_to_select = NULL; - ret = TRUE; + handled = true; } sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate), event->button.time); break; @@ -278,14 +261,14 @@ bool ArcTool::root_handler(GdkEvent* event) { case GDK_KEY_KP_Down: // prevent the zoom field from activation if (!MOD__CTRL_ONLY(event)) - ret = TRUE; + handled = true; break; case GDK_KEY_x: case GDK_KEY_X: if (MOD__ALT_ONLY(event)) { desktop->setToolboxFocusTo ("altx-arc"); - ret = TRUE; + handled = true; } break; @@ -295,7 +278,7 @@ bool ArcTool::root_handler(GdkEvent* event) { sp_event_context_discard_delayed_snap_event(this); // if drawing, cancel, otherwise pass it up for deselecting this->cancel(); - ret = TRUE; + handled = true; } break; @@ -316,7 +299,7 @@ bool ArcTool::root_handler(GdkEvent* event) { case GDK_KEY_Delete: case GDK_KEY_KP_Delete: case GDK_KEY_BackSpace: - ret = this->deleteSelectedDrag(MOD__CTRL_ONLY(event)); + handled = this->deleteSelectedDrag(MOD__CTRL_ONLY(event)); break; default: @@ -346,11 +329,11 @@ bool ArcTool::root_handler(GdkEvent* event) { break; } - if (!ret) { - ret = ToolBase::root_handler(event); + if (!handled) { + handled = ToolBase::root_handler(event); } - return ret; + return handled; } void ArcTool::drag(Geom::Point pt, guint state) { diff --git a/src/ui/tools/box3d-tool.cpp b/src/ui/tools/box3d-tool.cpp index 2e345fef1..f0381a4a5 100644 --- a/src/ui/tools/box3d-tool.cpp +++ b/src/ui/tools/box3d-tool.cpp @@ -72,22 +72,13 @@ const std::string& Box3dTool::getPrefsPath() { const std::string Box3dTool::prefsPath = "/tools/shapes/3dbox"; -Box3dTool::Box3dTool() : ToolBase() { - this->cursor_shape = cursor_3dbox_xpm; - this->hot_x = 4; - this->hot_y = 4; - this->xp = 0; - this->yp = 0; - this->tolerance = 0; - this->within_tolerance = false; - this->item_to_select = NULL; - - this->box3d = NULL; - - this->ctrl_dragged = false; - this->extruded = false; - - this->_vpdrag = NULL; +Box3dTool::Box3dTool() + : ToolBase(cursor_3dbox_xpm, 4, 4) + , _vpdrag(NULL) + , box3d(NULL) + , ctrl_dragged(false) + , extruded(false) +{ } void Box3dTool::finish() { diff --git a/src/ui/tools/calligraphic-tool.cpp b/src/ui/tools/calligraphic-tool.cpp index 2c5e6561c..64097e834 100644 --- a/src/ui/tools/calligraphic-tool.cpp +++ b/src/ui/tools/calligraphic-tool.cpp @@ -105,30 +105,24 @@ const std::string& CalligraphicTool::getPrefsPath() { const std::string CalligraphicTool::prefsPath = "/tools/calligraphic"; -CalligraphicTool::CalligraphicTool() : DynamicBase() { - this->cursor_shape = cursor_calligraphy_xpm; - this->hot_x = 4; - this->hot_y = 4; - +CalligraphicTool::CalligraphicTool() + : DynamicBase(cursor_calligraphy_xpm, 4, 4) + , keep_selected(true) + , hatch_spacing(0) + , hatch_spacing_step(0) + , hatch_item(NULL) + , hatch_livarot_path(NULL) + , hatch_last_nearest(Geom::Point(0,0)) + , hatch_last_pointer(Geom::Point(0,0)) + , hatch_escaped(false) + , hatch_area(NULL) + , just_started_drawing(false) + , trace_bg(false) +{ this->vel_thin = 0.1; this->flatness = 0.9; this->cap_rounding = 0.0; - this->abs_width = false; - this->keep_selected = true; - - this->hatch_spacing = 0; - this->hatch_spacing_step = 0; - - this->hatch_last_nearest = Geom::Point(0,0); - this->hatch_last_pointer = Geom::Point(0,0); - this->hatch_escaped = false; - this->hatch_area = NULL; - this->hatch_item = NULL; - this->hatch_livarot_path = NULL; - - this->trace_bg = false; - this->just_started_drawing = false; } CalligraphicTool::~CalligraphicTool() { diff --git a/src/ui/tools/connector-tool.cpp b/src/ui/tools/connector-tool.cpp index 50cb00360..391bae2e5 100644 --- a/src/ui/tools/connector-tool.cpp +++ b/src/ui/tools/connector-tool.cpp @@ -182,54 +182,39 @@ const std::string& ConnectorTool::getPrefsPath() { const std::string ConnectorTool::prefsPath = "/tools/connector"; -ConnectorTool::ConnectorTool() : ToolBase() { - this->red_curve = 0; - this->isOrthogonal = false; - this->c1 = 0; - this->red_bpath = 0; - this->green_curve = 0; - this->selection = 0; - this->cl0 = 0; - this->cl1 = 0; - this->c0 = 0; - - this->cursor_shape = cursor_connector_xpm; - this->hot_x = 1; - this->hot_y = 1; - this->xp = 0; - this->yp = 0; - - this->red_color = 0xff00007f; - - this->newconn = NULL; - this->newConnRef = NULL; - this->curvature = 0.0; - - this->sel_changed_connection = sigc::connection(); - - this->active_shape = NULL; - this->active_shape_repr = NULL; - this->active_shape_layer_repr = NULL; - - this->active_conn = NULL; - this->active_conn_repr = NULL; - - this->active_handle = NULL; - - this->selected_handle = NULL; - - this->clickeditem = NULL; - this->clickedhandle = NULL; - +ConnectorTool::ConnectorTool() + : ToolBase(cursor_connector_xpm, 1, 1) + , selection(NULL) + , npoints(0) + , state(SP_CONNECTOR_CONTEXT_IDLE) + , red_bpath(NULL) + , red_curve(NULL) + , red_color(0xff00007f) + , green_curve(NULL) + , newconn(NULL) + , newConnRef(NULL) + , curvature(0.0) + , isOrthogonal(false) + , active_shape(NULL) + , active_shape_repr(NULL) + , active_shape_layer_repr(NULL) + , active_conn(NULL) + , active_conn_repr(NULL) + , active_handle(NULL) + , selected_handle(NULL) + , clickeditem(NULL) + , clickedhandle(NULL) + , shref(NULL) + , ehref(NULL) + , c0(NULL) + , c1(NULL) + , cl0(NULL) + , cl1(NULL) +{ for (int i = 0; i < 2; ++i) { this->endpt_handle[i] = NULL; this->endpt_handler_id[i] = 0; } - - this->shref = NULL; - this->ehref = NULL; - this->npoints = 0; - this->state = SP_CONNECTOR_CONTEXT_IDLE; } ConnectorTool::~ConnectorTool() { diff --git a/src/ui/tools/dropper-tool.cpp b/src/ui/tools/dropper-tool.cpp index 88ed342df..e9e2d6c39 100644 --- a/src/ui/tools/dropper-tool.cpp +++ b/src/ui/tools/dropper-tool.cpp @@ -72,21 +72,17 @@ const std::string& DropperTool::getPrefsPath() { const std::string DropperTool::prefsPath = "/tools/dropper"; -DropperTool::DropperTool() : ToolBase() { - this->R = 0; - this->G = 0; - this->B = 0; - this->alpha = 0; - this->dragging = false; - - this->grabbed = 0; - this->area = 0; - this->centre = Geom::Point(0, 0); - - this->cursor_shape = cursor_dropper_f_xpm; - this->hot_x = 7; - this->hot_y = 7; - +DropperTool::DropperTool() + : ToolBase(cursor_dropper_f_xpm, 7, 7) + , R(0) + , G(0) + , B(0) + , alpha(0) + , dragging(false) + , grabbed(NULL) + , area(NULL) + , centre(0, 0) +{ cursor_dropper_fill = sp_cursor_new_from_xpm(cursor_dropper_f_xpm , 7, 7); cursor_dropper_stroke = sp_cursor_new_from_xpm(cursor_dropper_s_xpm , 7, 7); } diff --git a/src/ui/tools/dynamic-base.cpp b/src/ui/tools/dynamic-base.cpp index cec58dce9..21b4b0532 100644 --- a/src/ui/tools/dynamic-base.cpp +++ b/src/ui/tools/dynamic-base.cpp @@ -23,40 +23,41 @@ namespace Inkscape { namespace UI { namespace Tools { -DynamicBase::DynamicBase() : - ToolBase(), - accumulated(NULL), - segments(NULL), - currentshape(NULL), - currentcurve(NULL), - cal1(NULL), - cal2(NULL), - point1(), - point2(), - repr(NULL), - cur(0,0), - vel(0,0), - vel_max(0), - acc(0,0), - ang(0,0), - last(0,0), - del(0,0), - pressure(DEFAULT_PRESSURE), - xtilt(0), - ytilt(0), - dragging(FALSE), - usepressure(FALSE), - usetilt(FALSE), - mass(0.3), - drag(DRAG_DEFAULT), - angle(30.0), - width(0.2), - vel_thin(0.1), - flatness(0.9), - tremor(0), - cap_rounding(0), - is_drawing(false), - abs_width(false) +DynamicBase::DynamicBase(gchar const *const *cursor_shape, gint hot_x, gint hot_y) + : ToolBase(cursor_shape, hot_x, hot_y) + , accumulated(NULL) + , segments(NULL) + , currentshape(NULL) + , currentcurve(NULL) + , cal1(NULL) + , cal2(NULL) + , point1() + , point2() + , npoints(0) + , repr(NULL) + , cur(0, 0) + , vel(0, 0) + , vel_max(0) + , acc(0, 0) + , ang(0, 0) + , last(0, 0) + , del(0, 0) + , pressure(DEFAULT_PRESSURE) + , xtilt(0) + , ytilt(0) + , dragging(false) + , usepressure(false) + , usetilt(false) + , mass(0.3) + , drag(DRAG_DEFAULT) + , angle(30.0) + , width(0.2) + , vel_thin(0.1) + , flatness(0.9) + , tremor(0) + , cap_rounding(0) + , is_drawing(false) + , abs_width(false) { } diff --git a/src/ui/tools/dynamic-base.h b/src/ui/tools/dynamic-base.h index 9218eabd3..76fcd0f02 100644 --- a/src/ui/tools/dynamic-base.h +++ b/src/ui/tools/dynamic-base.h @@ -31,7 +31,7 @@ namespace Tools { class DynamicBase : public ToolBase { public: - DynamicBase(); + DynamicBase(gchar const *const *cursor_shape, gint hot_x, gint hot_y); virtual ~DynamicBase(); virtual void set(const Inkscape::Preferences::Entry& val); @@ -81,9 +81,9 @@ protected: gdouble ytilt; /* attributes */ - guint dragging : 1; /* mouse state: mouse is dragging */ - guint usepressure : 1; - guint usetilt : 1; + bool dragging; /* mouse state: mouse is dragging */ + bool usepressure; + bool usetilt; double mass, drag; double angle; double width; diff --git a/src/ui/tools/eraser-tool.cpp b/src/ui/tools/eraser-tool.cpp index 270987d27..011d28663 100644 --- a/src/ui/tools/eraser-tool.cpp +++ b/src/ui/tools/eraser-tool.cpp @@ -103,10 +103,9 @@ const std::string& EraserTool::getPrefsPath() { const std::string EraserTool::prefsPath = "/tools/eraser"; -EraserTool::EraserTool() : DynamicBase() { - this->cursor_shape = cursor_eraser_xpm; - this->hot_x = 4; - this->hot_y = 4; +EraserTool::EraserTool() + : DynamicBase(cursor_eraser_xpm, 4, 4) +{ } EraserTool::~EraserTool() { diff --git a/src/ui/tools/flood-tool.cpp b/src/ui/tools/flood-tool.cpp index 4e29b8856..d74848dc6 100644 --- a/src/ui/tools/flood-tool.cpp +++ b/src/ui/tools/flood-tool.cpp @@ -94,17 +94,12 @@ const std::string& FloodTool::getPrefsPath() { const std::string FloodTool::prefsPath = "/tools/paintbucket"; -FloodTool::FloodTool() : ToolBase() { - this->cursor_shape = cursor_paintbucket_xpm; - this->hot_x = 11; - this->hot_y = 30; - this->xp = 0; - this->yp = 0; +FloodTool::FloodTool() + : ToolBase(cursor_paintbucket_xpm, 11, 30) + , item(NULL) +{ + // TODO: Why does the flood tool use a hardcoded tolerance instead of a pref? this->tolerance = 4; - this->within_tolerance = false; - this->item_to_select = NULL; - - this->item = NULL; } FloodTool::~FloodTool() { diff --git a/src/ui/tools/freehand-base.cpp b/src/ui/tools/freehand-base.cpp index 1e0e6b3b6..2fb4a3481 100644 --- a/src/ui/tools/freehand-base.cpp +++ b/src/ui/tools/freehand-base.cpp @@ -70,37 +70,31 @@ static void spdc_flush_white(FreehandBase *dc, SPCurve *gc); static void spdc_reset_white(FreehandBase *dc); static void spdc_free_colors(FreehandBase *dc); -FreehandBase::FreehandBase() : ToolBase() { - this->selection = 0; - this->grab = 0; - this->anchor_statusbar = false; - - this->attach = FALSE; - - this->red_color = 0xff00007f; - this->blue_color = 0x0000ff7f; - this->green_color = 0x00ff007f; - this->red_curve_is_valid = false; - - this->red_bpath = NULL; - this->red_curve = NULL; - - this->blue_bpath = NULL; - this->blue_curve = NULL; - - this->green_bpaths = NULL; - this->green_curve = NULL; - this->green_anchor = NULL; - this->green_closed = false; - - this->white_item = NULL; - this->white_curves = NULL; - this->white_anchors = NULL; - - this->sa = NULL; - this->ea = NULL; - - this->waiting_LPE_type = Inkscape::LivePathEffect::INVALID_LPE; +FreehandBase::FreehandBase(gchar const *const *cursor_shape, gint hot_x, gint hot_y) + : ToolBase(cursor_shape, hot_x, hot_y) + , selection(NULL) + , grab(NULL) + , attach(false) + , red_color(0xff00007f) + , blue_color(0x0000ff7f) + , green_color(0x00ff007f) + , red_bpath(NULL) + , red_curve(NULL) + , blue_bpath(NULL) + , blue_curve(NULL) + , green_bpaths(NULL) + , green_curve(NULL) + , green_anchor(NULL) + , green_closed(false) + , white_item(NULL) + , white_curves(NULL) + , white_anchors(NULL) + , sa(NULL) + , ea(NULL) + , waiting_LPE_type(Inkscape::LivePathEffect::INVALID_LPE) + , red_curve_is_valid(false) + , anchor_statusbar(false) +{ } FreehandBase::~FreehandBase() { diff --git a/src/ui/tools/freehand-base.h b/src/ui/tools/freehand-base.h index 7e53684e3..c8da9faed 100644 --- a/src/ui/tools/freehand-base.h +++ b/src/ui/tools/freehand-base.h @@ -37,13 +37,13 @@ namespace Tools { class FreehandBase : public ToolBase { public: - FreehandBase(); + FreehandBase(gchar const *const *cursor_shape, gint hot_x, gint hot_y); virtual ~FreehandBase(); Inkscape::Selection *selection; SPCanvasItem *grab; - guint attach : 1; + bool attach; guint32 red_color; guint32 blue_color; diff --git a/src/ui/tools/gradient-tool.cpp b/src/ui/tools/gradient-tool.cpp index 10f78a8a8..a0bbfbaf1 100644 --- a/src/ui/tools/gradient-tool.cpp +++ b/src/ui/tools/gradient-tool.cpp @@ -74,20 +74,16 @@ const std::string& GradientTool::getPrefsPath() { const std::string GradientTool::prefsPath = "/tools/gradient"; -GradientTool::GradientTool() : ToolBase() { - this->node_added = false; - this->subselcon = 0; - this->selcon = 0; - - this->cursor_addnode = false; - this->cursor_shape = cursor_gradient_xpm; - this->hot_x = 4; - this->hot_y = 4; - this->xp = 0; - this->yp = 0; +GradientTool::GradientTool() + : ToolBase(cursor_gradient_xpm, 4, 4) + , cursor_addnode(false) + , node_added(false) +// TODO: Why are these connections stored as pointers? + , selcon(NULL) + , subselcon(NULL) +{ + // TODO: This value is overwritten in the root handler this->tolerance = 6; - this->within_tolerance = false; - this->item_to_select = NULL; } GradientTool::~GradientTool() { diff --git a/src/ui/tools/lpe-tool.cpp b/src/ui/tools/lpe-tool.cpp index a5406f1c5..6c41bb160 100644 --- a/src/ui/tools/lpe-tool.cpp +++ b/src/ui/tools/lpe-tool.cpp @@ -81,16 +81,14 @@ const std::string& LpeTool::getPrefsPath() { const std::string LpeTool::prefsPath = "/tools/lpetool"; -LpeTool::LpeTool() : PenTool() { - this->mode = Inkscape::LivePathEffect::BEND_PATH; - this->shape_editor = 0; - - this->cursor_shape = cursor_crosshairs_xpm; - this->hot_x = 7; - this->hot_y = 7; - - this->canvas_bbox = NULL; - this->measuring_items = new std::map; +LpeTool::LpeTool() + : PenTool(cursor_crosshairs_xpm, 7, 7) + , shape_editor(NULL) + , canvas_bbox(NULL) + , mode(Inkscape::LivePathEffect::BEND_PATH) +// TODO: pointer? + , measuring_items(new std::map) +{ } LpeTool::~LpeTool() { diff --git a/src/ui/tools/measure-tool.cpp b/src/ui/tools/measure-tool.cpp index 4d7f1e074..380aa79e3 100644 --- a/src/ui/tools/measure-tool.cpp +++ b/src/ui/tools/measure-tool.cpp @@ -236,12 +236,10 @@ void createAngleDisplayCurve(SPDesktop *desktop, Geom::Point const ¢er, Geom } // namespace -MeasureTool::MeasureTool() : ToolBase() { - this->grabbed = 0; - - this->cursor_shape = cursor_measure_xpm; - this->hot_x = 4; - this->hot_y = 4; +MeasureTool::MeasureTool() + : ToolBase(cursor_measure_xpm, 4, 4) + , grabbed(NULL) +{ } MeasureTool::~MeasureTool() { diff --git a/src/ui/tools/mesh-tool.cpp b/src/ui/tools/mesh-tool.cpp index 4e7617f44..7d6d3bc23 100644 --- a/src/ui/tools/mesh-tool.cpp +++ b/src/ui/tools/mesh-tool.cpp @@ -75,20 +75,18 @@ const std::string& MeshTool::getPrefsPath() { const std::string MeshTool::prefsPath = "/tools/mesh"; -MeshTool::MeshTool() : ToolBase() { - this->selcon = 0; - this->node_added = false; - this->subselcon = 0; - - this->cursor_addnode = false; - this->cursor_shape = cursor_gradient_xpm; - this->hot_x = 4; - this->hot_y = 4; - this->xp = 0; - this->yp = 0; +// TODO: The gradient tool class looks like a 1:1 copy. + +MeshTool::MeshTool() + : ToolBase(cursor_gradient_xpm, 4, 4) + , cursor_addnode(false) + , node_added(false) +// TODO: Why are these connections stored as pointers? + , selcon(NULL) + , subselcon(NULL) +{ + // TODO: This value is overwritten in the root handler this->tolerance = 6; - this->within_tolerance = false; - this->item_to_select = NULL; } MeshTool::~MeshTool() { diff --git a/src/ui/tools/node-tool.cpp b/src/ui/tools/node-tool.cpp index 7e33b1a4c..b1e11bd66 100644 --- a/src/ui/tools/node-tool.cpp +++ b/src/ui/tools/node-tool.cpp @@ -126,30 +126,27 @@ const std::string NodeTool::prefsPath = "/tools/nodes"; SPCanvasGroup *create_control_group(SPDesktop *d); -NodeTool::NodeTool() : ToolBase() { - this->show_handles = false; - this->single_node_transform_handles = false; - this->show_transform_handles = false; - this->cursor_drag = false; - this->live_objects = false; - this->edit_clipping_paths = false; - this->live_outline = false; - this->flashed_item = 0; - this->_transform_handle_group = 0; - this->show_path_direction = false; - this->_last_over = 0; - this->edit_masks = false; - this->show_outline = false; - this->flash_tempitem = 0; - - this->cursor_shape = cursor_node_xpm; - this->hot_x = 1; - this->hot_y = 1; - - this->_selected_nodes = 0; - this->_multipath = 0; - this->_selector = 0; - this->_path_data = 0; +NodeTool::NodeTool() + : ToolBase(cursor_node_xpm, 1, 1) + , _selected_nodes(NULL) + , _multipath(NULL) + , edit_clipping_paths(false) + , edit_masks(false) + , flashed_item(NULL) + , flash_tempitem(NULL) + , _selector(NULL) + , _path_data(NULL) + , _transform_handle_group(NULL) + , _last_over(NULL) + , cursor_drag(false) + , show_handles(false) + , show_outline(false) + , live_outline(false) + , live_objects(false) + , show_path_direction(false) + , show_transform_handles(false) + , single_node_transform_handles(false) +{ } SPCanvasGroup *create_control_group(SPDesktop *d) diff --git a/src/ui/tools/pen-tool.cpp b/src/ui/tools/pen-tool.cpp index dc5e801c0..39b69f576 100644 --- a/src/ui/tools/pen-tool.cpp +++ b/src/ui/tools/pen-tool.cpp @@ -89,29 +89,44 @@ const std::string& PenTool::getPrefsPath() { const std::string PenTool::prefsPath = "/tools/freehand/pen"; -PenTool::PenTool() : FreehandBase() { - this->polylines_only = false; - this->polylines_paraxial = false; - this->expecting_clicks_for_LPE = 0; - - this->cursor_shape = cursor_pen_xpm; - this->hot_x = 4; - this->hot_y = 4; - - this->npoints = 0; - this->mode = MODE_CLICK; - this->state = POINT; - - this->c0 = NULL; - this->c1 = NULL; - this->cl0 = NULL; - this->cl1 = NULL; - - this->events_disabled = 0; +PenTool::PenTool() + : FreehandBase(cursor_pen_xpm, 4, 4) + , p() + , npoints(0) + , mode(MODE_CLICK) + , state(POINT) + , polylines_only(false) + , polylines_paraxial(false) + , num_clicks(0) + , expecting_clicks_for_LPE(0) + , waiting_LPE(NULL) + , waiting_item(NULL) + , c0(NULL) + , c1(NULL) + , cl0(NULL) + , cl1(NULL) + , events_disabled(false) +{ +} - this->num_clicks = 0; - this->waiting_LPE = NULL; - this->waiting_item = NULL; +PenTool::PenTool(gchar const *const *cursor_shape, gint hot_x, gint hot_y) + : FreehandBase(cursor_shape, hot_x, hot_y) + , p() + , npoints(0) + , mode(MODE_CLICK) + , state(POINT) + , polylines_only(false) + , polylines_paraxial(false) + , num_clicks(0) + , expecting_clicks_for_LPE(0) + , waiting_LPE(NULL) + , waiting_item(NULL) + , c0(NULL) + , c1(NULL) + , cl0(NULL) + , cl1(NULL) + , events_disabled(false) +{ } PenTool::~PenTool() { @@ -1305,13 +1320,13 @@ static void spdc_pen_finish(PenTool *const pc, gboolean const closed) } static void pen_disable_events(PenTool *const pc) { - pc->events_disabled++; + pc->events_disabled = true; } static void pen_enable_events(PenTool *const pc) { - g_return_if_fail(pc->events_disabled != 0); + g_return_if_fail(pc->events_disabled != 0); - pc->events_disabled--; + pc->events_disabled = false; } void sp_pen_context_wait_for_LPE_mouse_clicks(PenTool *pc, Inkscape::LivePathEffect::EffectType effect_type, diff --git a/src/ui/tools/pen-tool.h b/src/ui/tools/pen-tool.h index 4452dbd68..f2b1ee04a 100644 --- a/src/ui/tools/pen-tool.h +++ b/src/ui/tools/pen-tool.h @@ -23,6 +23,7 @@ namespace Tools { class PenTool : public FreehandBase { public: PenTool(); + PenTool(gchar const *const *cursor_shape, gint hot_x, gint hot_y); virtual ~PenTool(); enum Mode { @@ -60,7 +61,7 @@ public: SPCtrlLine *cl0; SPCtrlLine *cl1; - unsigned int events_disabled : 1; + bool events_disabled; static const std::string prefsPath; diff --git a/src/ui/tools/pencil-tool.cpp b/src/ui/tools/pencil-tool.cpp index 52779d551..4fbaa50f3 100644 --- a/src/ui/tools/pencil-tool.cpp +++ b/src/ui/tools/pencil-tool.cpp @@ -83,20 +83,15 @@ const std::string& PencilTool::getPrefsPath() { const std::string PencilTool::prefsPath = "/tools/freehand/pencil"; -PencilTool::PencilTool() : - FreehandBase(), - p(), - npoints(0), - state(SP_PENCIL_CONTEXT_IDLE), - req_tangent(0,0), - is_drawing(false), - ps(), - sketch_interpolation(Geom::Piecewise >())// since PencilTool is not properly constructed... +PencilTool::PencilTool() + : FreehandBase(cursor_pencil_xpm, 4, 4) + , p() + , npoints(0) + , state(SP_PENCIL_CONTEXT_IDLE) + , req_tangent(0, 0) + , is_drawing(false) + , sketch_n(0) { - this->cursor_shape = cursor_pencil_xpm; - this->hot_x = 4; - this->hot_y = 4; - this->sketch_n = 0; } void PencilTool::setup() { diff --git a/src/ui/tools/rect-tool.cpp b/src/ui/tools/rect-tool.cpp index 263fdea84..f5153e8ce 100644 --- a/src/ui/tools/rect-tool.cpp +++ b/src/ui/tools/rect-tool.cpp @@ -66,20 +66,12 @@ const std::string& RectTool::getPrefsPath() { const std::string RectTool::prefsPath = "/tools/shapes/rect"; -RectTool::RectTool() : ToolBase() { - this->cursor_shape = cursor_rect_xpm; - this->hot_x = 4; - this->hot_y = 4; - this->xp = 0; - this->yp = 0; - this->tolerance = 0; - this->within_tolerance = false; - this->item_to_select = NULL; - - this->rect = NULL; - - this->rx = 0.0; - this->ry = 0.0; +RectTool::RectTool() + : ToolBase(cursor_rect_xpm, 4, 4) + , rect(NULL) + , rx(0) + , ry(0) +{ } void RectTool::finish() { diff --git a/src/ui/tools/select-tool.cpp b/src/ui/tools/select-tool.cpp index 498882417..85bc3fd4a 100644 --- a/src/ui/tools/select-tool.cpp +++ b/src/ui/tools/select-tool.cpp @@ -90,24 +90,24 @@ sp_load_handles(int start, int count, char const **xpm) { } } -SelectTool::SelectTool() : ToolBase() { - this->grabbed = 0; - this->item = 0; - - this->dragging = FALSE; - this->moved = FALSE; - this->button_press_shift = false; - this->button_press_ctrl = false; - this->button_press_alt = false; - this->cycling_items = NULL; - this->cycling_items_cmp = NULL; - this->cycling_items_selected_before = NULL; - this->cycling_cur_item = NULL; - this->cycling_wrap = true; - this->_seltrans = NULL; - this->_describer = NULL; - - +SelectTool::SelectTool() + // Don't load a default cursor + : ToolBase(NULL, 0, 0) + , dragging(false) + , moved(false) + , button_press_shift(false) + , button_press_ctrl(false) + , button_press_alt(false) + , cycling_items(NULL) + , cycling_items_cmp(NULL) + , cycling_items_selected_before(NULL) + , cycling_cur_item(NULL) + , cycling_wrap(true) + , item(NULL) + , grabbed(NULL) + , _seltrans(NULL) + , _describer(NULL) +{ // cursors in select context CursorSelectMouseover = sp_cursor_new_from_xpm(cursor_select_m_xpm , 1, 1); CursorSelectDragging = sp_cursor_new_from_xpm(cursor_select_d_xpm , 1, 1); diff --git a/src/ui/tools/select-tool.h b/src/ui/tools/select-tool.h index b26fc03bc..81763e8b1 100644 --- a/src/ui/tools/select-tool.h +++ b/src/ui/tools/select-tool.h @@ -35,8 +35,8 @@ public: SelectTool(); virtual ~SelectTool(); - guint dragging : 1; - guint moved : 1; + bool dragging; + bool moved; bool button_press_shift; bool button_press_ctrl; bool button_press_alt; diff --git a/src/ui/tools/spiral-tool.cpp b/src/ui/tools/spiral-tool.cpp index 005b2d239..7d33b0f67 100644 --- a/src/ui/tools/spiral-tool.cpp +++ b/src/ui/tools/spiral-tool.cpp @@ -65,21 +65,13 @@ const std::string& SpiralTool::getPrefsPath() { const std::string SpiralTool::prefsPath = "/tools/shapes/spiral"; -SpiralTool::SpiralTool() : ToolBase() { - this->cursor_shape = cursor_spiral_xpm; - this->hot_x = 4; - this->hot_y = 4; - this->xp = 0; - this->yp = 0; - this->tolerance = 0; - this->within_tolerance = false; - this->item_to_select = NULL; - - this->spiral = NULL; - - this->revo = 3.0; - this->exp = 1.0; - this->t0 = 0.0; +SpiralTool::SpiralTool() + : ToolBase(cursor_spiral_xpm, 4, 4) + , spiral(NULL) + , revo(3) + , exp(1) + , t0(0) +{ } void SpiralTool::finish() { diff --git a/src/ui/tools/spray-tool.cpp b/src/ui/tools/spray-tool.cpp index 14a3acd9a..2fc3f1c91 100644 --- a/src/ui/tools/spray-tool.cpp +++ b/src/ui/tools/spray-tool.cpp @@ -134,35 +134,30 @@ static void sp_spray_scale_rel(Geom::Point c, SPDesktop */*desktop*/, SPItem *it item->doWriteTransform(item->getRepr(), item->transform); } -SprayTool::SprayTool() : ToolBase() { - this->usetilt = 0; - this->dilate_area = 0; - this->usetext = false; - this->population = 0; - this->is_drawing = false; - this->mode = 0; - this->usepressure = 0; - - this->cursor_shape = cursor_spray_xpm; - this->hot_x = 4; - this->hot_y = 4; - - /* attributes */ - this->dragging = FALSE; - this->distrib = 1; - this->width = 0.2; - this->force = 0.2; - this->ratio = 0; - this->tilt = 0; - this->mean = 0.2; - this->rotation_variation = 0; - this->standard_deviation = 0.2; - this->scale = 1; - this->scale_variation = 1; - this->pressure = TC_DEFAULT_PRESSURE; - - this->is_dilating = false; - this->has_dilated = false; +SprayTool::SprayTool() + : ToolBase(cursor_spray_xpm, 4, 4) + , pressure(TC_DEFAULT_PRESSURE) + , dragging(false) + , usepressure(0) + , usetilt(0) + , usetext(false) + , width(0.2) + , ratio(0) + , tilt(0) + , rotation_variation(0) + , force(0.2) + , population(0) + , scale_variation(1) + , scale(1) + , mean(0.2) + , standard_deviation(0.2) + , distrib(1) + , mode(0) + , is_drawing(false) + , is_dilating(false) + , has_dilated(false) + , dilate_area(NULL) +{ } SprayTool::~SprayTool() { diff --git a/src/ui/tools/spray-tool.h b/src/ui/tools/spray-tool.h index e7362fd50..1a8f98006 100644 --- a/src/ui/tools/spray-tool.h +++ b/src/ui/tools/spray-tool.h @@ -61,10 +61,10 @@ public: gdouble pressure; /* attributes */ - guint dragging : 1; /* mouse state: mouse is dragging */ - guint usepressure : 1; - guint usetilt : 1; - bool usetext ; + bool dragging; /* mouse state: mouse is dragging */ + bool usepressure; + bool usetilt; + bool usetext; double width; double ratio; diff --git a/src/ui/tools/star-tool.cpp b/src/ui/tools/star-tool.cpp index b5d8c4418..42010788f 100644 --- a/src/ui/tools/star-tool.cpp +++ b/src/ui/tools/star-tool.cpp @@ -69,25 +69,15 @@ const std::string& StarTool::getPrefsPath() { const std::string StarTool::prefsPath = "/tools/shapes/star"; -StarTool::StarTool() : ToolBase() { - this->randomized = 0; - this->rounded = 0; - - this->cursor_shape = cursor_star_xpm; - this->hot_x = 4; - this->hot_y = 4; - this->xp = 0; - this->yp = 0; - this->tolerance = 0; - this->within_tolerance = false; - this->item_to_select = NULL; - //this->tool_url = "/tools/shapes/star"; - - this->star = NULL; - - this->magnitude = 5; - this->proportion = 0.5; - this->isflatsided = false; +StarTool::StarTool() + : ToolBase(cursor_star_xpm, 4, 4) + , star(NULL) + , magnitude(5) + , proportion(0.5) + , isflatsided(false) + , rounded(0) + , randomized(0) +{ } void StarTool::finish() { diff --git a/src/ui/tools/text-tool.cpp b/src/ui/tools/text-tool.cpp index ba68c7829..00f6a853c 100644 --- a/src/ui/tools/text-tool.cpp +++ b/src/ui/tools/text-tool.cpp @@ -91,37 +91,26 @@ const std::string& TextTool::getPrefsPath() { const std::string TextTool::prefsPath = "/tools/text"; -TextTool::TextTool() : ToolBase() { - this->preedit_string = 0; - this->unipos = 0; - - this->cursor_shape = cursor_text_xpm; - this->hot_x = 7; - this->hot_y = 7; - - this->xp = 0; - this->yp = 0; - this->tolerance = 0; - this->within_tolerance = false; - - this->imc = NULL; - - this->text = NULL; - this->pdoc = Geom::Point(0, 0); - - this->unimode = false; - - this->cursor = NULL; - this->indicator = NULL; - this->frame = NULL; - this->grabbed = NULL; - this->timeout = 0; - this->show = FALSE; - this->phase = 0; - this->nascent_object = 0; - this->over_text = 0; - this->dragging = 0; - this->creating = 0; +TextTool::TextTool() + : ToolBase(cursor_text_xpm, 7, 7) + , imc(NULL) + , text(NULL) + , pdoc(0, 0) + , unimode(false) + , unipos(0) + , cursor(NULL) + , indicator(NULL) + , frame(NULL) + , timeout(0) + , show(false) + , phase(false) + , nascent_object(false) + , over_text(false) + , dragging(0) + , creating(false) + , grabbed(NULL) + , preedit_string(NULL) +{ } TextTool::~TextTool() { diff --git a/src/ui/tools/text-tool.h b/src/ui/tools/text-tool.h index ef8a67984..c5336d378 100644 --- a/src/ui/tools/text-tool.h +++ b/src/ui/tools/text-tool.h @@ -61,15 +61,15 @@ public: SPCanvasItem *frame; // hiliting the first frame of flowtext; FIXME: make this a list to accommodate arbitrarily many chained shapes std::vector text_selection_quads; gint timeout; - guint show : 1; - guint phase : 1; - guint nascent_object : 1; // true if we're clicked on canvas to put cursor, but no text typed yet so ->text is still NULL + bool show; + bool phase; + bool nascent_object; // true if we're clicked on canvas to put cursor, but no text typed yet so ->text is still NULL - guint over_text : 1; // true if cursor is over a text object + bool over_text; // true if cursor is over a text object guint dragging : 2; // dragging selection over text - guint creating : 1; // dragging rubberband to create flowtext + bool creating; // dragging rubberband to create flowtext SPCanvasItem *grabbed; // we grab while we are creating, to get events even if the mouse goes out of the window Geom::Point p0; // initial point if the flowtext rect diff --git a/src/ui/tools/tool-base.cpp b/src/ui/tools/tool-base.cpp index cc028724a..dc10e9388 100644 --- a/src/ui/tools/tool-base.cpp +++ b/src/ui/tools/tool-base.cpp @@ -90,28 +90,26 @@ SPDesktop const& ToolBase::getDesktop() const { return *desktop; } -ToolBase::ToolBase() { - this->hot_y = 0; - this->xp = 0; - this->cursor_shape = 0; - this->pref_observer = 0; - this->hot_x = 0; - this->yp = 0; - this->within_tolerance = false; - this->tolerance = 0; - //this->key = 0; - this->item_to_select = 0; - - this->desktop = NULL; - this->cursor = NULL; - this->message_context = NULL; - this->_selcue = NULL; - this->_grdrag = NULL; - this->space_panning = false; - this->shape_editor = NULL; - this->_delayed_snap_event = NULL; - this->_dse_callback_in_process = false; - //this->tool_url = NULL; +ToolBase::ToolBase(gchar const *const *cursor_shape, gint hot_x, gint hot_y) + : pref_observer(NULL) + , cursor(NULL) + , xp(0) + , yp(0) + , tolerance(0) + , within_tolerance(false) + , item_to_select(NULL) + , message_context(NULL) + , _selcue(NULL) + , _grdrag(NULL) + , shape_editor(NULL) + , space_panning(false) + , _delayed_snap_event(NULL) + , _dse_callback_in_process(false) + , desktop(NULL) + , cursor_shape(cursor_shape) + , hot_x(hot_x) + , hot_y(hot_y) +{ } ToolBase::~ToolBase() { diff --git a/src/ui/tools/tool-base.h b/src/ui/tools/tool-base.h index 43edc4bd7..a4a27a06c 100644 --- a/src/ui/tools/tool-base.h +++ b/src/ui/tools/tool-base.h @@ -110,7 +110,8 @@ public: void enableGrDrag (bool enable=true); bool deleteSelectedDrag(bool just_one); - ToolBase(); + ToolBase(gchar const *const *cursor_shape, gint hot_x, gint hot_y); + virtual ~ToolBase(); Inkscape::Preferences::Observer *pref_observer; @@ -179,8 +180,11 @@ public: SPDesktop *desktop; protected: + /// An xpm containing the shape of the tool's cursor. gchar const *const *cursor_shape; - gint hot_x, hot_y; ///< indicates the cursor's hot spot + + /// The cursor's hot spot + gint hot_x, hot_y; private: ToolBase(const ToolBase&); diff --git a/src/ui/tools/tweak-tool.cpp b/src/ui/tools/tweak-tool.cpp index 0791eff5a..75650d3af 100644 --- a/src/ui/tools/tweak-tool.cpp +++ b/src/ui/tools/tweak-tool.cpp @@ -111,32 +111,25 @@ const std::string& TweakTool::getPrefsPath() { const std::string TweakTool::prefsPath = "/tools/tweak"; -TweakTool::TweakTool() : ToolBase() { - this->mode = 0; - this->dilate_area = 0; - this->usetilt = 0; - this->usepressure = 0; - this->is_drawing = false; - this->fidelity = 0; - - this->cursor_shape = cursor_push_xpm; - this->hot_x = 4; - this->hot_y = 4; - - /* attributes */ - this->dragging = FALSE; - - this->width = 0.2; - this->force = 0.2; - this->pressure = TC_DEFAULT_PRESSURE; - - this->is_dilating = false; - this->has_dilated = false; - - this->do_h = true; - this->do_s = true; - this->do_l = true; - this->do_o = false; +TweakTool::TweakTool() + : ToolBase(cursor_push_xpm, 4, 4) + , pressure(TC_DEFAULT_PRESSURE) + , dragging(false) + , usepressure(false) + , usetilt(false) + , width(0.2) + , force(0.2) + , fidelity(0) + , mode(0) + , is_drawing(false) + , is_dilating(false) + , has_dilated(false) + , dilate_area(NULL) + , do_h(true) + , do_s(true) + , do_l(true) + , do_o(false) +{ } TweakTool::~TweakTool() { diff --git a/src/ui/tools/tweak-tool.h b/src/ui/tools/tweak-tool.h index 6cbb9aded..7fe4b1856 100644 --- a/src/ui/tools/tweak-tool.h +++ b/src/ui/tools/tweak-tool.h @@ -50,9 +50,9 @@ public: gdouble pressure; /* attributes */ - guint dragging : 1; /* mouse state: mouse is dragging */ - guint usepressure : 1; - guint usetilt : 1; + bool dragging; /* mouse state: mouse is dragging */ + bool usepressure; + bool usetilt; double width; double force; diff --git a/src/ui/tools/zoom-tool.cpp b/src/ui/tools/zoom-tool.cpp index 0996e6cf4..9f99cfe2e 100644 --- a/src/ui/tools/zoom-tool.cpp +++ b/src/ui/tools/zoom-tool.cpp @@ -45,12 +45,11 @@ const std::string& ZoomTool::getPrefsPath() { const std::string ZoomTool::prefsPath = "/tools/zoom"; -ZoomTool::ZoomTool() : ToolBase() { - this->grabbed = 0; - this->cursor_shape = cursor_zoom_xpm; - this->hot_x = 6; - this->hot_y = 6; - this->escaped = false; +ZoomTool::ZoomTool() + : ToolBase(cursor_zoom_xpm, 6, 6) + , grabbed(NULL) + , escaped(false) +{ } ZoomTool::~ZoomTool() { -- cgit v1.2.3 From 21fa74799d08edc54fa6506e3f78fab04215241a Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Wed, 26 Feb 2014 20:31:49 +0100 Subject: Added template functions as a casting-macro replacement. (bzr r13061) --- src/ui/tools/tool-base.h | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'src/ui') diff --git a/src/ui/tools/tool-base.h b/src/ui/tools/tool-base.h index a4a27a06c..79bdfe89d 100644 --- a/src/ui/tools/tool-base.h +++ b/src/ui/tools/tool-base.h @@ -215,9 +215,31 @@ void sp_toggle_dropper(SPDesktop *dt); bool sp_event_context_knot_mouseover(ToolBase *ec); +} // namespace Tools + +//#include + +namespace Tool { + +template +bool is_a(const T* t) { + //static_assert(std::is_base_of(), "Destination type not derived from ToolBase."); + //static_assert(std::is_convertible(), "Cannot cast passed pointer to ToolBase*."); + + return dynamic_cast(static_cast(t)) != NULL; } + +template +Derived* to(T* t) { + //static_assert(std::is_base_of(), "Destination type not derived from ToolBase."); + //static_assert(std::is_convertible(), "Cannot cast passed pointer to ToolBase*."); + + return dynamic_cast(static_cast(t)); } -} + +} // namespace Tool +} // namespace UI +} // namespace Inkscape #endif // SEEN_SP_EVENT_CONTEXT_H -- cgit v1.2.3 From 83e693c338fb585bed735d8302a700ba7ad39442 Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Thu, 27 Feb 2014 22:50:53 +0100 Subject: swatches dialog: properly reference count the reference to SPDocument in timer object. Fixes crash reported in comment #6 of bug 1284391! Fixed bugs: - https://launchpad.net/bugs/1284391 (bzr r13068) --- src/ui/dialog/swatches.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/ui') diff --git a/src/ui/dialog/swatches.cpp b/src/ui/dialog/swatches.cpp index 3f161ad28..06b52e2e2 100644 --- a/src/ui/dialog/swatches.cpp +++ b/src/ui/dialog/swatches.cpp @@ -746,7 +746,7 @@ class DocTrack { public: DocTrack(SPDocument *doc, sigc::connection &gradientRsrcChanged, sigc::connection &defsChanged, sigc::connection &defsModified) : - doc(doc), + doc(doc->doRef()), updatePending(false), lastGradientUpdate(0.0), gradientRsrcChanged(gradientRsrcChanged), @@ -776,6 +776,7 @@ public: gradientRsrcChanged.disconnect(); defsChanged.disconnect(); defsModified.disconnect(); + doc->doUnref(); } } -- cgit v1.2.3 From b368877bf540ce4b6b06581d1f6955b6ce37e248 Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Thu, 27 Feb 2014 23:48:55 +0100 Subject: swatches dialog: remove unused code part. cleanup some code (bzr r13069) --- src/ui/dialog/swatches.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'src/ui') diff --git a/src/ui/dialog/swatches.cpp b/src/ui/dialog/swatches.cpp index 06b52e2e2..807618b4d 100644 --- a/src/ui/dialog/swatches.cpp +++ b/src/ui/dialog/swatches.cpp @@ -777,6 +777,7 @@ public: defsChanged.disconnect(); defsModified.disconnect(); doc->doUnref(); + doc = NULL; } } @@ -859,7 +860,7 @@ bool DocTrack::queueUpdateIfNeeded( SPDocument *doc ) void SwatchesPanel::_trackDocument( SwatchesPanel *panel, SPDocument *document ) { - SPDocument *oldDoc = 0; + SPDocument *oldDoc = NULL; if (docPerPanel.find(panel) != docPerPanel.end()) { oldDoc = docPerPanel[panel]; if (!oldDoc) { @@ -868,7 +869,7 @@ void SwatchesPanel::_trackDocument( SwatchesPanel *panel, SPDocument *document ) } if (oldDoc != document) { if (oldDoc) { - docPerPanel[panel] = 0; + docPerPanel[panel] = NULL; bool found = false; for (std::map::iterator it = docPerPanel.begin(); (it != docPerPanel.end()) && !found; ++it) { found = (it->second == document); @@ -906,11 +907,6 @@ void SwatchesPanel::_trackDocument( SwatchesPanel *panel, SPDocument *document ) } } } - - std::set docs; - for (std::map::iterator it = docPerPanel.begin(); it != docPerPanel.end(); ++it) { - docs.insert(it->second); - } } void SwatchesPanel::_setDocument( SPDocument *document ) -- cgit v1.2.3 From a06efaf2a7e31b8ed38efead9259fd02560c5299 Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Fri, 28 Feb 2014 00:00:40 +0100 Subject: remove some unnecessary copying/casting (bzr r13070) --- src/ui/tools/spray-tool.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/ui') diff --git a/src/ui/tools/spray-tool.cpp b/src/ui/tools/spray-tool.cpp index 2fc3f1c91..c9f9c8e91 100644 --- a/src/ui/tools/spray-tool.cpp +++ b/src/ui/tools/spray-tool.cpp @@ -114,9 +114,9 @@ inline double NormalDistribution(double mu, double sigma) static void sp_spray_rotate_rel(Geom::Point c, SPDesktop */*desktop*/, SPItem *item, Geom::Rotate const &rotation) { Geom::Translate const s(c); - Geom::Affine affine = Geom::Affine(s).inverse() * Geom::Affine(rotation) * Geom::Affine(s); + Geom::Affine affine = s.inverse() * rotation * s; // Rotate item. - item->set_i2d_affine(item->i2dt_affine() * (Geom::Affine)affine); + item->set_i2d_affine(item->i2dt_affine() * affine); // Use each item's own transform writer, consistent with sp_selection_apply_affine() item->doWriteTransform(item->getRepr(), item->transform); // Restore the center position (it's changed because the bbox center changed) @@ -516,8 +516,8 @@ static bool sp_spray_recursive(SPDesktop *desktop, static bool sp_spray_dilate(SprayTool *tc, Geom::Point /*event_p*/, Geom::Point p, Geom::Point vector, bool reverse) { - Inkscape::Selection *selection = sp_desktop_selection(SP_EVENT_CONTEXT(tc)->desktop); - SPDesktop *desktop = SP_EVENT_CONTEXT(tc)->desktop; + SPDesktop *desktop = tc->desktop; + Inkscape::Selection *selection = sp_desktop_selection(desktop); if (selection->isEmpty()) { return false; -- cgit v1.2.3 From dd29914fcfe97975ce7145adc24cc556d67b83d2 Mon Sep 17 00:00:00 2001 From: Nicolas Dufour Date: Fri, 28 Feb 2014 14:56:31 +0100 Subject: Fix for Bug #1281859 (color gesture problems, alpha values below 0 and above 1). Fixed bugs: - https://launchpad.net/bugs/1281859 (bzr r13074) --- src/ui/widget/selected-style.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/ui') diff --git a/src/ui/widget/selected-style.cpp b/src/ui/widget/selected-style.cpp index d29554c41..042a6614e 100644 --- a/src/ui/widget/selected-style.cpp +++ b/src/ui/widget/selected-style.cpp @@ -1267,6 +1267,11 @@ RotateableSwatch::color_adjust(float *hsla, double by, guint32 cc, guint modifie } else if (modifier == 3) { // alpha double old = hsla[3]; hsla[3] += by/2; + if (hsla[3] < 0) { + hsla[3] = 0; + } else if (hsla[3] > 1) { + hsla[3] = 1; + } diff = hsla[3] - old; } else { // hue double old = hsla[0]; -- cgit v1.2.3 From e31e8d77903bd363901723b153fe901fa2e13c8f Mon Sep 17 00:00:00 2001 From: Nicolas Dufour Date: Fri, 28 Feb 2014 16:24:40 +0100 Subject: Spray tool: * Partial patch (in sp_spray_dilate) for crashes explained in Bug #1274831. * Some minor style fixes (indentation). * Due to some remaining crashes, the Single path mode is disabled in Inkscape 0.91. (bzr r13077) --- src/ui/tools/spray-tool.cpp | 90 +++++++++++++++++++++++++++++---------------- 1 file changed, 58 insertions(+), 32 deletions(-) (limited to 'src/ui') diff --git a/src/ui/tools/spray-tool.cpp b/src/ui/tools/spray-tool.cpp index c9f9c8e91..e43b6575e 100644 --- a/src/ui/tools/spray-tool.cpp +++ b/src/ui/tools/spray-tool.cpp @@ -79,6 +79,11 @@ using namespace std; #define DDC_RED_RGBA 0xff0000ff #define DYNA_MIN_WIDTH 1.0e-6 +// Disabled in 0.91 because of Bug #1274831 (crash, spraying an object +// with the mode: spray object in single path) +// Please enable again when working on 1.0 +//#define ENABLE_SPRAY_MODE_SINGLE_PATH + #include "tool-factory.h" namespace Inkscape { @@ -86,15 +91,15 @@ namespace UI { namespace Tools { namespace { - ToolBase* createSprayContext() { - return new SprayTool(); - } + ToolBase* createSprayContext() { + return new SprayTool(); + } - bool sprayContextRegistered = ToolFactory::instance().registerObject("/tools/spray", createSprayContext); + bool sprayContextRegistered = ToolFactory::instance().registerObject("/tools/spray", createSprayContext); } const std::string& SprayTool::getPrefsPath() { - return SprayTool::prefsPath; + return SprayTool::prefsPath; } const std::string SprayTool::prefsPath = "/tools/spray"; @@ -189,22 +194,22 @@ void SprayTool::update_cursor(bool /*with_shift*/) { sel_message = g_strdup_printf("%s", _("Nothing selected")); } - switch (this->mode) { - case SPRAY_MODE_COPY: - this->message_context->setF(Inkscape::NORMAL_MESSAGE, _("%s. Drag, click or click and scroll to spray copies of the initial selection."), sel_message); - break; - case SPRAY_MODE_CLONE: - this->message_context->setF(Inkscape::NORMAL_MESSAGE, _("%s. Drag, click or click and scroll to spray clones of the initial selection."), sel_message); - break; - case SPRAY_MODE_SINGLE_PATH: - this->message_context->setF(Inkscape::NORMAL_MESSAGE, _("%s. Drag, click or click and scroll to spray in a single path of the initial selection."), sel_message); - break; - default: - break; - } - - this->sp_event_context_update_cursor(); - g_free(sel_message); + switch (this->mode) { + case SPRAY_MODE_COPY: + this->message_context->setF(Inkscape::NORMAL_MESSAGE, _("%s. Drag, click or click and scroll to spray copies of the initial selection."), sel_message); + break; + case SPRAY_MODE_CLONE: + this->message_context->setF(Inkscape::NORMAL_MESSAGE, _("%s. Drag, click or click and scroll to spray clones of the initial selection."), sel_message); + break; + case SPRAY_MODE_SINGLE_PATH: + this->message_context->setF(Inkscape::NORMAL_MESSAGE, _("%s. Drag, click or click and scroll to spray in a single path of the initial selection."), sel_message); + break; + default: + break; + } + + this->sp_event_context_update_cursor(); + g_free(sel_message); } void SprayTool::setup() { @@ -420,6 +425,7 @@ static bool sp_spray_recursive(SPDesktop *desktop, did = true; } } +#ifdef ENABLE_SPRAY_MODE_SINGLE_PATH } else if (mode == SPRAY_MODE_SINGLE_PATH) { SPItem *parent_item = NULL; // Initial object @@ -475,6 +481,7 @@ static bool sp_spray_recursive(SPDesktop *desktop, did = true; } } +#endif } else if (mode == SPRAY_MODE_CLONE) { Geom::OptRect a = item->documentVisualBounds(); if (a) { @@ -541,18 +548,35 @@ static bool sp_spray_dilate(SprayTool *tc, Geom::Point /*event_p*/, Geom::Point double move_mean = get_move_mean(tc); double move_standard_deviation = get_move_standard_deviation(tc); - for (GSList *items = g_slist_copy(const_cast(selection->itemList())); - items != NULL; - items = items->next) { + { + GSList *const original_selection = g_slist_copy(const_cast(selection->itemList())); - SPItem *item = SP_ITEM(items->data); + for (GSList *items = original_selection; + items != NULL; + items = items->next) { + sp_object_ref(SP_ITEM(items->data)); + } - if (is_transform_modes(tc->mode)) { - if (sp_spray_recursive(desktop, selection, item, p, vector, tc->mode, radius, move_force, tc->population, tc->scale, tc->scale_variation, reverse, move_mean, move_standard_deviation, tc->ratio, tc->tilt, tc->rotation_variation, tc->distrib)) - did = true; - } else { - if (sp_spray_recursive(desktop, selection, item, p, vector, tc->mode, radius, path_force, tc->population, tc->scale, tc->scale_variation, reverse, path_mean, path_standard_deviation, tc->ratio, tc->tilt, tc->rotation_variation, tc->distrib)) - did = true; + for (GSList *items = original_selection; + items != NULL; + items = items->next) { + SPItem *item = SP_ITEM(items->data); + + if (is_transform_modes(tc->mode)) { + if (sp_spray_recursive(desktop, selection, item, p, vector, tc->mode, radius, move_force, tc->population, tc->scale, tc->scale_variation, reverse, move_mean, move_standard_deviation, tc->ratio, tc->tilt, tc->rotation_variation, tc->distrib)) { + did = true; + } + } else { + if (sp_spray_recursive(desktop, selection, item, p, vector, tc->mode, radius, path_force, tc->population, tc->scale, tc->scale_variation, reverse, path_mean, path_standard_deviation, tc->ratio, tc->tilt, tc->rotation_variation, tc->distrib)) { + did = true; + } + } + } + + for (GSList *items = original_selection; + items != NULL; + items = items->next) { + sp_object_unref(SP_ITEM(items->data)); } } @@ -735,6 +759,7 @@ bool SprayTool::root_handler(GdkEvent* event) { ret = TRUE; } break; +#ifdef ENABLE_SPRAY_MODE_SINGLE_PATH case GDK_KEY_l: case GDK_KEY_L: if (MOD__SHIFT_ONLY(event)) { @@ -742,6 +767,7 @@ bool SprayTool::root_handler(GdkEvent* event) { ret = TRUE; } break; +#endif case GDK_KEY_Up: case GDK_KEY_KP_Up: if (!MOD__CTRL_ONLY(event)) { @@ -854,7 +880,7 @@ bool SprayTool::root_handler(GdkEvent* event) { // if ((SP_EVENT_CONTEXT_CLASS(sp_spray_context_parent_class))->root_handler) { // ret = (SP_EVENT_CONTEXT_CLASS(sp_spray_context_parent_class))->root_handler(event_context, event); // } - ret = ToolBase::root_handler(event); + ret = ToolBase::root_handler(event); } return ret; -- cgit v1.2.3 From 9125e5147952cb8ce3d9f8b1fc833be98b4d0447 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sat, 1 Mar 2014 21:26:55 +0100 Subject: Fix for crashes on fast tool toggling. Fixed bugs: - https://launchpad.net/bugs/1265376 (bzr r13087) --- src/ui/tools/dropper-tool.cpp | 4 ++++ src/ui/tools/tool-base.cpp | 18 ++++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) (limited to 'src/ui') diff --git a/src/ui/tools/dropper-tool.cpp b/src/ui/tools/dropper-tool.cpp index e9e2d6c39..99d42a211 100644 --- a/src/ui/tools/dropper-tool.cpp +++ b/src/ui/tools/dropper-tool.cpp @@ -336,6 +336,10 @@ bool DropperTool::root_handler(GdkEvent* event) { if (prefs->getBool("/tools/dropper/onetimepick", false)) { prefs->setBool("/tools/dropper/onetimepick", false); sp_toggle_dropper(desktop); + + // sp_toggle_dropper will delete ourselves. + // Thus, make sure we return immediately. + return true; } ret = TRUE; diff --git a/src/ui/tools/tool-base.cpp b/src/ui/tools/tool-base.cpp index dc10e9388..99b72c386 100644 --- a/src/ui/tools/tool-base.cpp +++ b/src/ui/tools/tool-base.cpp @@ -739,10 +739,12 @@ bool ToolBase::root_handler(GdkEvent* event) { if (within_tolerance == true) { // Space was pressed, but not panned sp_toggle_selector(desktop); - ret = TRUE; + + // Be careful, sp_toggle_selector will delete ourselves. + // Thus, make sure we return immediately. + return true; } - within_tolerance = false; break; case GDK_KEY_Q: @@ -975,10 +977,18 @@ gint sp_event_context_root_handler(ToolBase * event_context, gint sp_event_context_virtual_root_handler(ToolBase * event_context, GdkEvent * event) { gint ret = false; + if (event_context) { - ret = event_context->root_handler(event); - set_event_location(event_context->desktop, event); + // The root handler also handles pressing the space key. + // This will toggle the current tool and delete the current one. + // Thus, save a pointer to the desktop before calling it. + SPDesktop* desktop = event_context->desktop; + + ret = event_context->root_handler(event); + + set_event_location(desktop, event); } + return ret; } -- cgit v1.2.3 From e1ab38a66877bc6665f4e0cd9ec0b186a4cd545b Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sat, 1 Mar 2014 22:02:26 +0100 Subject: Fix for crash when cycle-selecting. Fixed bugs: - https://launchpad.net/bugs/1270351 (bzr r13088) --- src/ui/tools/select-tool.cpp | 66 ++++++++++++++++++-------------------------- src/ui/tools/select-tool.h | 1 + 2 files changed, 28 insertions(+), 39 deletions(-) (limited to 'src/ui') diff --git a/src/ui/tools/select-tool.cpp b/src/ui/tools/select-tool.cpp index 85bc3fd4a..83bef17c9 100644 --- a/src/ui/tools/select-tool.cpp +++ b/src/ui/tools/select-tool.cpp @@ -125,7 +125,6 @@ SelectTool::SelectTool() //static bool within_tolerance = false; static bool is_cycling = false; static bool moved_while_cycling = false; -ToolBase *prev_event_context = NULL; SelectTool::~SelectTool() { @@ -441,24 +440,20 @@ void SelectTool::sp_select_context_cycle_through_items(Inkscape::Selection *sele } } +void SelectTool::sp_select_context_reset_opacities() { + for (GList *l = this->cycling_items; l != NULL; l = g_list_next(l)) { + Inkscape::DrawingItem *arenaitem = SP_ITEM(l->data)->get_arenaitem(this->desktop->dkey); + arenaitem->setOpacity(SP_SCALE24_TO_FLOAT(SP_ITEM(l->data)->style->opacity.value)); + } -static void -sp_select_context_reset_opacities(ToolBase *event_context) -{ - // SPDesktop *desktop = event_context->desktop; - SelectTool *sc = SP_SELECT_CONTEXT(event_context); - Inkscape::DrawingItem *arenaitem; - for (GList *l = sc->cycling_items; l != NULL; l = g_list_next(l)) { - arenaitem = SP_ITEM(l->data)->get_arenaitem(event_context->desktop->dkey); - arenaitem->setOpacity(SP_SCALE24_TO_FLOAT(SP_ITEM(l->data)->style->opacity.value)); - } - g_list_free(sc->cycling_items); - g_list_free(sc->cycling_items_selected_before); - g_list_free(sc->cycling_items_cmp); - sc->cycling_items = NULL; - sc->cycling_items_selected_before = NULL; - sc->cycling_cur_item = NULL; - sc->cycling_items_cmp = NULL; + g_list_free(this->cycling_items); + g_list_free(this->cycling_items_selected_before); + g_list_free(this->cycling_items_cmp); + + this->cycling_items = NULL; + this->cycling_items_selected_before = NULL; + this->cycling_cur_item = NULL; + this->cycling_items_cmp = NULL; } bool SelectTool::root_handler(GdkEvent* event) { @@ -545,11 +540,9 @@ bool SelectTool::root_handler(GdkEvent* event) { case GDK_MOTION_NOTIFY: { - if (is_cycling) - { - moved_while_cycling = true; - prev_event_context = this; - } + if (is_cycling) { + moved_while_cycling = true; + } tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100); @@ -811,14 +804,12 @@ bool SelectTool::root_handler(GdkEvent* event) { GdkEventScroll *scroll_event = (GdkEventScroll*) event; if (scroll_event->state & GDK_MOD1_MASK) { // alt modified pressed - if (moved_while_cycling) - { - moved_while_cycling = false; - sp_select_context_reset_opacities(prev_event_context); - prev_event_context = NULL; - } + if (moved_while_cycling) { + moved_while_cycling = false; + this->sp_select_context_reset_opacities(); + } - is_cycling = true; + is_cycling = true; bool shift_pressed = scroll_event->state & GDK_SHIFT_MASK; @@ -1205,18 +1196,15 @@ bool SelectTool::root_handler(GdkEvent* event) { Inkscape::Rubberband::get(desktop)->setMode(RUBBERBAND_MODE_RECT); } } else { - if (alt) { // TODO: Should we have a variable like is_cycling or is it harmless to run this piece of code each time? + if (alt) { // quit cycle-selection and reset opacities - if (is_cycling) - { - sp_select_context_reset_opacities(this); - is_cycling = false; - } - + if (is_cycling) { + this->sp_select_context_reset_opacities(); + is_cycling = false; + } } } - } // set cursor to default. if (!desktop->isWaitingCursor()) { // Do we need to reset the cursor here on key release ? @@ -1224,7 +1212,7 @@ bool SelectTool::root_handler(GdkEvent* event) { //gdk_window_set_cursor(window, event_context->cursor); } break; - + } default: break; } diff --git a/src/ui/tools/select-tool.h b/src/ui/tools/select-tool.h index 81763e8b1..edc4069a2 100644 --- a/src/ui/tools/select-tool.h +++ b/src/ui/tools/select-tool.h @@ -64,6 +64,7 @@ public: private: bool sp_select_context_abort(); void sp_select_context_cycle_through_items(Inkscape::Selection *selection, GdkEventScroll *scroll_event, bool shift_pressed); + void sp_select_context_reset_opacities(); }; } -- cgit v1.2.3 From 3aa344e9a40d97db7cd5a89671896bab70da33a4 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sun, 2 Mar 2014 01:31:12 +0100 Subject: Added some consts. Turned functions to member functions. (bzr r13089) --- src/ui/tools/arc-tool.cpp | 2 +- src/ui/tools/box3d-tool.cpp | 2 +- src/ui/tools/connector-tool.cpp | 584 +++++++++++++--------------- src/ui/tools/connector-tool.h | 25 +- src/ui/tools/freehand-base.cpp | 2 +- src/ui/tools/lpe-tool.cpp | 4 +- src/ui/tools/pen-tool.cpp | 814 +++++++++++++++++++--------------------- src/ui/tools/pen-tool.h | 50 ++- src/ui/tools/pencil-tool.cpp | 497 +++++++++++------------- src/ui/tools/pencil-tool.h | 18 + src/ui/tools/rect-tool.cpp | 2 +- src/ui/tools/spiral-tool.cpp | 2 +- src/ui/tools/star-tool.cpp | 2 +- src/ui/tools/text-tool.cpp | 2 +- src/ui/tools/tool-base.cpp | 13 +- src/ui/tools/tool-base.h | 5 + 16 files changed, 973 insertions(+), 1051 deletions(-) (limited to 'src/ui') diff --git a/src/ui/tools/arc-tool.cpp b/src/ui/tools/arc-tool.cpp index 435f4aa4b..43f8eb9e1 100644 --- a/src/ui/tools/arc-tool.cpp +++ b/src/ui/tools/arc-tool.cpp @@ -198,7 +198,7 @@ bool ArcTool::root_handler(GdkEvent* event) { gobble_motion_events(GDK_BUTTON1_MASK); handled = true; - } else if (!sp_event_context_knot_mouseover(this)){ + } else if (!this->sp_event_context_knot_mouseover()){ SnapManager &m = desktop->namedview->snap_manager; m.setup(desktop); diff --git a/src/ui/tools/box3d-tool.cpp b/src/ui/tools/box3d-tool.cpp index f0381a4a5..e00894d55 100644 --- a/src/ui/tools/box3d-tool.cpp +++ b/src/ui/tools/box3d-tool.cpp @@ -313,7 +313,7 @@ bool Box3dTool::root_handler(GdkEvent* event) { this->drag(event->motion.state); ret = TRUE; - } else if (!sp_event_context_knot_mouseover(this)) { + } else if (!this->sp_event_context_knot_mouseover()) { SnapManager &m = desktop->namedview->snap_manager; m.setup(desktop); diff --git a/src/ui/tools/connector-tool.cpp b/src/ui/tools/connector-tool.cpp index 391bae2e5..d2e23837c 100644 --- a/src/ui/tools/connector-tool.cpp +++ b/src/ui/tools/connector-tool.cpp @@ -115,40 +115,19 @@ namespace Inkscape { namespace UI { namespace Tools { -// Stuff borrowed from DrawContext -static void spcc_connector_set_initial_point(ConnectorTool *cc, Geom::Point const p); -static void spcc_connector_set_subsequent_point(ConnectorTool *cc, Geom::Point const p); -static void spcc_connector_finish_segment(ConnectorTool *cc, Geom::Point p); -static void spcc_reset_colors(ConnectorTool *cc); -static void spcc_connector_finish(ConnectorTool *cc); -static void spcc_concat_colors_and_flush(ConnectorTool *cc); -static void spcc_flush_white(ConnectorTool *cc, SPCurve *gc); - -// Context event handlers -static gint connector_handle_button_press(ConnectorTool *const cc, GdkEventButton const &bevent); -static gint connector_handle_motion_notify(ConnectorTool *const cc, GdkEventMotion const &mevent); -static gint connector_handle_button_release(ConnectorTool *const cc, GdkEventButton const &revent); -static gint connector_handle_key_press(ConnectorTool *const cc, guint const keyval); - -static void cc_active_shape_add_knot(ConnectorTool *cc, SPItem* item); -static void cc_set_active_shape(ConnectorTool *cc, SPItem *item); static void cc_clear_active_knots(SPKnotList k); -static void cc_clear_active_shape(ConnectorTool *cc); -static void cc_set_active_conn(ConnectorTool *cc, SPItem *item); -static void cc_clear_active_conn(ConnectorTool *cc); -static bool conn_pt_handle_test(ConnectorTool *cc, Geom::Point& p, gchar **href); -static void cc_select_handle(SPKnot* knot); -static void cc_deselect_handle(SPKnot* knot); -static bool cc_item_is_shape(SPItem *item); -static void cc_connector_rerouting_finish(ConnectorTool *const cc, - Geom::Point *const p); static void shape_event_attr_deleted(Inkscape::XML::Node *repr, Inkscape::XML::Node *child, Inkscape::XML::Node *ref, gpointer data); + static void shape_event_attr_changed(Inkscape::XML::Node *repr, gchar const *name, gchar const *old_value, gchar const *new_value, bool is_interactive, gpointer data); +static void cc_select_handle(SPKnot* knot); +static void cc_deselect_handle(SPKnot* knot); +static bool cc_item_is_shape(SPItem *item); + /*static Geom::Point connector_drag_origin_w(0, 0); static bool connector_within_tolerance = false;*/ @@ -247,7 +226,7 @@ void ConnectorTool::setup() { this->sel_changed_connection.disconnect(); this->sel_changed_connection = this->selection->connectChanged( - sigc::mem_fun(this, &ConnectorTool::selection_changed) + sigc::mem_fun(this, &ConnectorTool::_selectionChanged) ); /* Create red bpath */ @@ -264,7 +243,7 @@ void ConnectorTool::setup() { // Notice the initial selection. //cc_selection_changed(this->selection, (gpointer) this); - this->selection_changed(this->selection); + this->_selectionChanged(this->selection); this->within_tolerance = false; @@ -293,7 +272,7 @@ void ConnectorTool::set(const Inkscape::Preferences::Entry& val) { } void ConnectorTool::finish() { - spcc_connector_finish(this); + this->_finish(); this->state = SP_CONNECTOR_CONTEXT_IDLE; ToolBase::finish(); @@ -302,8 +281,8 @@ void ConnectorTool::finish() { this->selection = NULL; } - cc_clear_active_shape(this); - cc_clear_active_conn(this); + this->cc_clear_active_shape(); + this->cc_clear_active_conn(); // Restore the default event generating behaviour. this->desktop->canvas->gen_all_enter_events = false; @@ -312,28 +291,26 @@ void ConnectorTool::finish() { //----------------------------------------------------------------------------- -static void -cc_clear_active_shape(ConnectorTool *cc) -{ - if (cc->active_shape == NULL) { +void ConnectorTool::cc_clear_active_shape() { + if (this->active_shape == NULL) { return; } - g_assert( cc->active_shape_repr ); - g_assert( cc->active_shape_layer_repr ); + g_assert( this->active_shape_repr ); + g_assert( this->active_shape_layer_repr ); - cc->active_shape = NULL; + this->active_shape = NULL; - if (cc->active_shape_repr) { - sp_repr_remove_listener_by_data(cc->active_shape_repr, cc); - Inkscape::GC::release(cc->active_shape_repr); - cc->active_shape_repr = NULL; + if (this->active_shape_repr) { + sp_repr_remove_listener_by_data(this->active_shape_repr, this); + Inkscape::GC::release(this->active_shape_repr); + this->active_shape_repr = NULL; - sp_repr_remove_listener_by_data(cc->active_shape_layer_repr, cc); - Inkscape::GC::release(cc->active_shape_layer_repr); - cc->active_shape_layer_repr = NULL; + sp_repr_remove_listener_by_data(this->active_shape_layer_repr, this); + Inkscape::GC::release(this->active_shape_layer_repr); + this->active_shape_layer_repr = NULL; } - cc_clear_active_knots(cc->knots); + cc_clear_active_knots(this->knots); } static void @@ -347,38 +324,34 @@ cc_clear_active_knots(SPKnotList k) } } -static void -cc_clear_active_conn(ConnectorTool *cc) -{ - if (cc->active_conn == NULL) { +void ConnectorTool::cc_clear_active_conn() { + if (this->active_conn == NULL) { return; } - g_assert( cc->active_conn_repr ); + g_assert( this->active_conn_repr ); - cc->active_conn = NULL; + this->active_conn = NULL; - if (cc->active_conn_repr) { - sp_repr_remove_listener_by_data(cc->active_conn_repr, cc); - Inkscape::GC::release(cc->active_conn_repr); - cc->active_conn_repr = NULL; + if (this->active_conn_repr) { + sp_repr_remove_listener_by_data(this->active_conn_repr, this); + Inkscape::GC::release(this->active_conn_repr); + this->active_conn_repr = NULL; } // Hide the endpoint handles. for (int i = 0; i < 2; ++i) { - if (cc->endpt_handle[i]) { - sp_knot_hide(cc->endpt_handle[i]); + if (this->endpt_handle[i]) { + sp_knot_hide(this->endpt_handle[i]); } } } -static bool -conn_pt_handle_test(ConnectorTool *cc, Geom::Point& p, gchar **href) -{ - if (cc->active_handle && (cc->knots.find(cc->active_handle) != cc->knots.end())) +bool ConnectorTool::_ptHandleTest(Geom::Point& p, gchar **href) { + if (this->active_handle && (this->knots.find(this->active_handle) != this->knots.end())) { - p = cc->active_handle->pos; - *href = g_strdup_printf("#%s", cc->active_handle->owner->getId()); + p = this->active_handle->pos; + *href = g_strdup_printf("#%s", this->active_handle->owner->getId()); return true; } *href = NULL; @@ -414,7 +387,7 @@ bool ConnectorTool::item_handler(SPItem* item, GdkEvent* event) { case GDK_BUTTON_RELEASE: if (event->button.button == 1 && !this->space_panning) { if ((this->state == SP_CONNECTOR_CONTEXT_DRAGGING) && this->within_tolerance) { - spcc_reset_colors(this); + this->_resetColors(); this->state = SP_CONNECTOR_CONTEXT_IDLE; } @@ -435,7 +408,7 @@ bool ConnectorTool::item_handler(SPItem* item, GdkEvent* event) { */ if (item != this->active_shape && !cc_item_is_connector(item)) { - cc_set_active_shape(this, item); + this->_setActiveShape(item); } } @@ -446,7 +419,7 @@ bool ConnectorTool::item_handler(SPItem* item, GdkEvent* event) { case GDK_ENTER_NOTIFY: if (!this->selected_handle) { if (cc_item_is_shape(item)) { - cc_set_active_shape(this, item); + this->_setActiveShape(item); } ret = TRUE; @@ -465,19 +438,19 @@ bool ConnectorTool::root_handler(GdkEvent* event) { switch (event->type) { case GDK_BUTTON_PRESS: - ret = connector_handle_button_press(this, event->button); + ret = this->_handleButtonPress(event->button); break; case GDK_MOTION_NOTIFY: - ret = connector_handle_motion_notify(this, event->motion); + ret = this->_handleMotionNotify(event->motion); break; case GDK_BUTTON_RELEASE: - ret = connector_handle_button_release(this, event->button); + ret = this->_handleButtonRelease(event->button); break; case GDK_KEY_PRESS: - ret = connector_handle_key_press(this, get_group0_keyval (&event->key)); + ret = this->_handleKeyPress(get_group0_keyval (&event->key)); break; default: @@ -492,82 +465,80 @@ bool ConnectorTool::root_handler(GdkEvent* event) { } -static gint -connector_handle_button_press(ConnectorTool *const cc, GdkEventButton const &bevent) -{ +gint ConnectorTool::_handleButtonPress(GdkEventButton const &bevent) { Geom::Point const event_w(bevent.x, bevent.y); /* Find desktop coordinates */ - Geom::Point p = cc->desktop->w2d(event_w); - ToolBase *event_context = SP_EVENT_CONTEXT(cc); + Geom::Point p = this->desktop->w2d(event_w); + ToolBase *event_context = SP_EVENT_CONTEXT(this); gint ret = FALSE; if ( bevent.button == 1 && !event_context->space_panning ) { - SPDesktop *desktop = cc->desktop; + SPDesktop *desktop = this->desktop; - if (Inkscape::have_viable_layer(desktop, cc->message_context) == false) { + if (Inkscape::have_viable_layer(desktop, this->message_context) == false) { return TRUE; } Geom::Point const event_w(bevent.x, bevent.y); - cc->xp = bevent.x; - cc->yp = bevent.y; - cc->within_tolerance = true; + this->xp = bevent.x; + this->yp = bevent.y; + this->within_tolerance = true; - Geom::Point const event_dt = cc->desktop->w2d(event_w); + Geom::Point const event_dt = this->desktop->w2d(event_w); - SnapManager &m = cc->desktop->namedview->snap_manager; + SnapManager &m = this->desktop->namedview->snap_manager; - switch (cc->state) { + switch (this->state) { case SP_CONNECTOR_CONTEXT_STOP: /* This is allowed, if we just canceled curve */ case SP_CONNECTOR_CONTEXT_IDLE: { - if ( cc->npoints == 0 ) { - cc_clear_active_conn(cc); + if ( this->npoints == 0 ) { + this->cc_clear_active_conn(); - cc->desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Creating new connector")); + this->desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Creating new connector")); /* Set start anchor */ /* Create green anchor */ Geom::Point p = event_dt; // Test whether we clicked on a connection point - bool found = conn_pt_handle_test(cc, p, &cc->shref); + bool found = this->_ptHandleTest(p, &this->shref); if (!found) { // This is the first point, so just snap it to the grid // as there's no other points to go off. - m.setup(cc->desktop); + m.setup(this->desktop); m.freeSnapReturnByRef(p, Inkscape::SNAPSOURCE_OTHER_HANDLE); m.unSetup(); } - spcc_connector_set_initial_point(cc, p); + this->_setInitialPoint(p); } - cc->state = SP_CONNECTOR_CONTEXT_DRAGGING; + this->state = SP_CONNECTOR_CONTEXT_DRAGGING; ret = TRUE; break; } case SP_CONNECTOR_CONTEXT_DRAGGING: { // This is the second click of a connector creation. - m.setup(cc->desktop); + m.setup(this->desktop); m.freeSnapReturnByRef(p, Inkscape::SNAPSOURCE_OTHER_HANDLE); m.unSetup(); - spcc_connector_set_subsequent_point(cc, p); - spcc_connector_finish_segment(cc, p); + this->_setSubsequentPoint(p); + this->_finishSegment(p); - conn_pt_handle_test(cc, p, &cc->ehref); - if (cc->npoints != 0) { - spcc_connector_finish(cc); + this->_ptHandleTest(p, &this->ehref); + if (this->npoints != 0) { + this->_finish(); } - cc_set_active_conn(cc, cc->newconn); - cc->state = SP_CONNECTOR_CONTEXT_IDLE; + this->cc_set_active_conn(this->newconn); + this->state = SP_CONNECTOR_CONTEXT_IDLE; ret = TRUE; break; } @@ -580,30 +551,28 @@ connector_handle_button_press(ConnectorTool *const cc, GdkEventButton const &bev break; } } else if (bevent.button == 3) { - if (cc->state == SP_CONNECTOR_CONTEXT_REROUTING) { + if (this->state == SP_CONNECTOR_CONTEXT_REROUTING) { // A context menu is going to be triggered here, // so end the rerouting operation. - cc_connector_rerouting_finish(cc, &p); + this->_reroutingFinish(&p); - cc->state = SP_CONNECTOR_CONTEXT_IDLE; + this->state = SP_CONNECTOR_CONTEXT_IDLE; // Don't set ret to TRUE, so we drop through to the // parent handler which will open the context menu. } - else if (cc->npoints != 0) { - spcc_connector_finish(cc); - cc->state = SP_CONNECTOR_CONTEXT_IDLE; + else if (this->npoints != 0) { + this->_finish(); + this->state = SP_CONNECTOR_CONTEXT_IDLE; ret = TRUE; } } return ret; } -static gint -connector_handle_motion_notify(ConnectorTool *const cc, GdkEventMotion const &mevent) -{ +gint ConnectorTool::_handleMotionNotify(GdkEventMotion const &mevent) { gint ret = FALSE; - ToolBase *event_context = SP_EVENT_CONTEXT(cc); + ToolBase *event_context = SP_EVENT_CONTEXT(this); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); if (event_context->space_panning || mevent.state & GDK_BUTTON2_MASK || mevent.state & GDK_BUTTON3_MASK) { @@ -613,36 +582,36 @@ connector_handle_motion_notify(ConnectorTool *const cc, GdkEventMotion const &me Geom::Point const event_w(mevent.x, mevent.y); - if (cc->within_tolerance) { - cc->tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100); - if ( ( abs( (gint) mevent.x - cc->xp ) < cc->tolerance ) && - ( abs( (gint) mevent.y - cc->yp ) < cc->tolerance ) ) { + if (this->within_tolerance) { + this->tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100); + if ( ( abs( (gint) mevent.x - this->xp ) < this->tolerance ) && + ( abs( (gint) mevent.y - this->yp ) < this->tolerance ) ) { return FALSE; // Do not drag if we're within tolerance from origin. } } // Once the user has moved farther than tolerance from the original location // (indicating they intend to move the object, not click), then always process // the motion notify coordinates as given (no snapping back to origin) - cc->within_tolerance = false; + this->within_tolerance = false; - SPDesktop *const dt = cc->desktop; + SPDesktop *const dt = this->desktop; /* Find desktop coordinates */ Geom::Point p = dt->w2d(event_w); SnapManager &m = dt->namedview->snap_manager; - switch (cc->state) { + switch (this->state) { case SP_CONNECTOR_CONTEXT_DRAGGING: { gobble_motion_events(mevent.state); // This is movement during a connector creation. - if ( cc->npoints > 0 ) { + if ( this->npoints > 0 ) { m.setup(dt); m.freeSnapReturnByRef(p, Inkscape::SNAPSOURCE_OTHER_HANDLE); m.unSetup(); - cc->selection->clear(); - spcc_connector_set_subsequent_point(cc, p); + this->selection->clear(); + this->_setSubsequentPoint(p); ret = TRUE; } break; @@ -650,32 +619,32 @@ connector_handle_motion_notify(ConnectorTool *const cc, GdkEventMotion const &me case SP_CONNECTOR_CONTEXT_REROUTING: { gobble_motion_events(GDK_BUTTON1_MASK); - g_assert( SP_IS_PATH(cc->clickeditem)); + g_assert( SP_IS_PATH(this->clickeditem)); m.setup(dt); m.freeSnapReturnByRef(p, Inkscape::SNAPSOURCE_OTHER_HANDLE); m.unSetup(); // Update the hidden path - Geom::Affine i2d ( (cc->clickeditem)->i2dt_affine() ); + Geom::Affine i2d ( (this->clickeditem)->i2dt_affine() ); Geom::Affine d2i = i2d.inverse(); - SPPath *path = SP_PATH(cc->clickeditem); + SPPath *path = SP_PATH(this->clickeditem); SPCurve *curve = path->get_curve(); - if (cc->clickedhandle == cc->endpt_handle[0]) { - Geom::Point o = cc->endpt_handle[1]->pos; + if (this->clickedhandle == this->endpt_handle[0]) { + Geom::Point o = this->endpt_handle[1]->pos; curve->stretch_endpoints(p * d2i, o * d2i); } else { - Geom::Point o = cc->endpt_handle[0]->pos; + Geom::Point o = this->endpt_handle[0]->pos; curve->stretch_endpoints(o * d2i, p * d2i); } sp_conn_reroute_path_immediate(path); // Copy this to the temporary visible path - cc->red_curve = path->get_curve_for_edit(); - cc->red_curve->transform(i2d); + this->red_curve = path->get_curve_for_edit(); + this->red_curve->transform(i2d); - sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(cc->red_bpath), cc->red_curve); + sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), this->red_curve); ret = TRUE; break; } @@ -683,7 +652,7 @@ connector_handle_motion_notify(ConnectorTool *const cc, GdkEventMotion const &me /* This is perfectly valid */ break; default: - if (!sp_event_context_knot_mouseover(cc)) { + if (!this->sp_event_context_knot_mouseover()) { m.setup(dt); m.preSnap(Inkscape::SnapCandidatePoint(p, Inkscape::SNAPSOURCE_OTHER_HANDLE)); m.unSetup(); @@ -693,14 +662,12 @@ connector_handle_motion_notify(ConnectorTool *const cc, GdkEventMotion const &me return ret; } -static gint -connector_handle_button_release(ConnectorTool *const cc, GdkEventButton const &revent) -{ +gint ConnectorTool::_handleButtonRelease(GdkEventButton const &revent) { gint ret = FALSE; - ToolBase *event_context = SP_EVENT_CONTEXT(cc); + ToolBase *event_context = SP_EVENT_CONTEXT(this); if ( revent.button == 1 && !event_context->space_panning ) { - SPDesktop *desktop = cc->desktop; + SPDesktop *desktop = this->desktop; SPDocument *doc = sp_desktop_document(desktop); SnapManager &m = desktop->namedview->snap_manager; @@ -708,9 +675,9 @@ connector_handle_button_release(ConnectorTool *const cc, GdkEventButton const &r Geom::Point const event_w(revent.x, revent.y); /* Find desktop coordinates */ - Geom::Point p = cc->desktop->w2d(event_w); + Geom::Point p = this->desktop->w2d(event_w); - switch (cc->state) { + switch (this->state) { //case SP_CONNECTOR_CONTEXT_POINT: case SP_CONNECTOR_CONTEXT_DRAGGING: { @@ -718,21 +685,21 @@ connector_handle_button_release(ConnectorTool *const cc, GdkEventButton const &r m.freeSnapReturnByRef(p, Inkscape::SNAPSOURCE_OTHER_HANDLE); m.unSetup(); - if (cc->within_tolerance) + if (this->within_tolerance) { - spcc_connector_finish_segment(cc, p); + this->_finishSegment(p); return TRUE; } // Connector has been created via a drag, end it now. - spcc_connector_set_subsequent_point(cc, p); - spcc_connector_finish_segment(cc, p); + this->_setSubsequentPoint(p); + this->_finishSegment(p); // Test whether we clicked on a connection point - conn_pt_handle_test(cc, p, &cc->ehref); - if (cc->npoints != 0) { - spcc_connector_finish(cc); + this->_ptHandleTest(p, &this->ehref); + if (this->npoints != 0) { + this->_finish(); } - cc_set_active_conn(cc, cc->newconn); - cc->state = SP_CONNECTOR_CONTEXT_IDLE; + this->cc_set_active_conn(this->newconn); + this->state = SP_CONNECTOR_CONTEXT_IDLE; break; } case SP_CONNECTOR_CONTEXT_REROUTING: @@ -740,10 +707,10 @@ connector_handle_button_release(ConnectorTool *const cc, GdkEventButton const &r m.setup(desktop); m.freeSnapReturnByRef(p, Inkscape::SNAPSOURCE_OTHER_HANDLE); m.unSetup(); - cc_connector_rerouting_finish(cc, &p); + this->_reroutingFinish(&p); doc->ensureUpToDate(); - cc->state = SP_CONNECTOR_CONTEXT_IDLE; + this->state = SP_CONNECTOR_CONTEXT_IDLE; return TRUE; break; } @@ -758,39 +725,37 @@ connector_handle_button_release(ConnectorTool *const cc, GdkEventButton const &r return ret; } -static gint -connector_handle_key_press(ConnectorTool *const cc, guint const keyval) -{ +gint ConnectorTool::_handleKeyPress(guint const keyval) { gint ret = FALSE; switch (keyval) { case GDK_KEY_Return: case GDK_KEY_KP_Enter: - if (cc->npoints != 0) { - spcc_connector_finish(cc); - cc->state = SP_CONNECTOR_CONTEXT_IDLE; + if (this->npoints != 0) { + this->_finish(); + this->state = SP_CONNECTOR_CONTEXT_IDLE; ret = TRUE; } break; case GDK_KEY_Escape: - if (cc->state == SP_CONNECTOR_CONTEXT_REROUTING) { + if (this->state == SP_CONNECTOR_CONTEXT_REROUTING) { - SPDesktop *desktop = cc->desktop; + SPDesktop *desktop = this->desktop; SPDocument *doc = sp_desktop_document(desktop); - cc_connector_rerouting_finish(cc, NULL); + this->_reroutingFinish(NULL); DocumentUndo::undo(doc); - cc->state = SP_CONNECTOR_CONTEXT_IDLE; + this->state = SP_CONNECTOR_CONTEXT_IDLE; desktop->messageStack()->flash( Inkscape::NORMAL_MESSAGE, _("Connector endpoint drag cancelled.")); ret = TRUE; } - else if (cc->npoints != 0) { + else if (this->npoints != 0) { // if drawing, cancel, otherwise pass it up for deselecting - cc->state = SP_CONNECTOR_CONTEXT_STOP; - spcc_reset_colors(cc); + this->state = SP_CONNECTOR_CONTEXT_STOP; + this->_resetColors(); ret = TRUE; } break; @@ -800,95 +765,84 @@ connector_handle_key_press(ConnectorTool *const cc, guint const keyval) return ret; } - -static void -cc_connector_rerouting_finish(ConnectorTool *const cc, Geom::Point *const p) -{ - SPDesktop *desktop = cc->desktop; +void ConnectorTool::_reroutingFinish(Geom::Point *const p) { + SPDesktop *desktop = this->desktop; SPDocument *doc = sp_desktop_document(desktop); // Clear the temporary path: - cc->red_curve->reset(); - sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(cc->red_bpath), NULL); + this->red_curve->reset(); + sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), NULL); if (p != NULL) { // Test whether we clicked on a connection point gchar *shape_label; - bool found = conn_pt_handle_test(cc, *p, &shape_label); + bool found = this->_ptHandleTest(*p, &shape_label); if (found) { - if (cc->clickedhandle == cc->endpt_handle[0]) { - cc->clickeditem->setAttribute("inkscape:connection-start", shape_label, NULL); + if (this->clickedhandle == this->endpt_handle[0]) { + this->clickeditem->setAttribute("inkscape:connection-start", shape_label, NULL); } else { - cc->clickeditem->setAttribute("inkscape:connection-end", shape_label, NULL); + this->clickeditem->setAttribute("inkscape:connection-end", shape_label, NULL); } g_free(shape_label); } } - cc->clickeditem->setHidden(false); - sp_conn_reroute_path_immediate(SP_PATH(cc->clickeditem)); - cc->clickeditem->updateRepr(); + this->clickeditem->setHidden(false); + sp_conn_reroute_path_immediate(SP_PATH(this->clickeditem)); + this->clickeditem->updateRepr(); DocumentUndo::done(doc, SP_VERB_CONTEXT_CONNECTOR, _("Reroute connector")); - cc_set_active_conn(cc, cc->clickeditem); + this->cc_set_active_conn(this->clickeditem); } -static void -spcc_reset_colors(ConnectorTool *cc) -{ +void ConnectorTool::_resetColors() { /* Red */ - cc->red_curve->reset(); - sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(cc->red_bpath), NULL); + this->red_curve->reset(); + sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), NULL); - cc->green_curve->reset(); - cc->npoints = 0; + this->green_curve->reset(); + this->npoints = 0; } +void ConnectorTool::_setInitialPoint(Geom::Point const p) { + g_assert( this->npoints == 0 ); -static void -spcc_connector_set_initial_point(ConnectorTool *const cc, Geom::Point const p) -{ - g_assert( cc->npoints == 0 ); - - cc->p[0] = p; - cc->p[1] = p; - cc->npoints = 2; - sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(cc->red_bpath), NULL); + this->p[0] = p; + this->p[1] = p; + this->npoints = 2; + sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), NULL); } +void ConnectorTool::_setSubsequentPoint(Geom::Point const p) { + g_assert( this->npoints != 0 ); -static void -spcc_connector_set_subsequent_point(ConnectorTool *const cc, Geom::Point const p) -{ - g_assert( cc->npoints != 0 ); - - SPDesktop *dt = cc->desktop; - Geom::Point o = dt->dt2doc(cc->p[0]); + SPDesktop *dt = this->desktop; + Geom::Point o = dt->dt2doc(this->p[0]); Geom::Point d = dt->dt2doc(p); Avoid::Point src(o[Geom::X], o[Geom::Y]); Avoid::Point dst(d[Geom::X], d[Geom::Y]); - if (!cc->newConnRef) { + if (!this->newConnRef) { Avoid::Router *router = sp_desktop_document(dt)->router; - cc->newConnRef = new Avoid::ConnRef(router); - cc->newConnRef->setEndpoint(Avoid::VertID::src, src); - if (cc->isOrthogonal) - cc->newConnRef->setRoutingType(Avoid::ConnType_Orthogonal); + this->newConnRef = new Avoid::ConnRef(router); + this->newConnRef->setEndpoint(Avoid::VertID::src, src); + if (this->isOrthogonal) + this->newConnRef->setRoutingType(Avoid::ConnType_Orthogonal); else - cc->newConnRef->setRoutingType(Avoid::ConnType_PolyLine); + this->newConnRef->setRoutingType(Avoid::ConnType_PolyLine); } // Set new endpoint. - cc->newConnRef->setEndpoint(Avoid::VertID::tar, dst); + this->newConnRef->setEndpoint(Avoid::VertID::tar, dst); // Immediately generate new routes for connector. - cc->newConnRef->makePathInvalid(); - cc->newConnRef->router()->processTransaction(); + this->newConnRef->makePathInvalid(); + this->newConnRef->router()->processTransaction(); // Recreate curve from libavoid route. - recreateCurve( cc->red_curve, cc->newConnRef, cc->curvature ); - cc->red_curve->transform(dt->doc2dt()); - sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(cc->red_bpath), cc->red_curve); + recreateCurve( this->red_curve, this->newConnRef, this->curvature ); + this->red_curve->transform(dt->doc2dt()); + sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), this->red_curve); } @@ -897,21 +851,19 @@ spcc_connector_set_subsequent_point(ConnectorTool *const cc, Geom::Point const p * If any anchors are defined, process these, optionally removing curves from white list * Invoke _flush_white to write result back to object. */ -static void -spcc_concat_colors_and_flush(ConnectorTool *cc) -{ - SPCurve *c = cc->green_curve; - cc->green_curve = new SPCurve(); +void ConnectorTool::_concatColorsAndFlush() { + SPCurve *c = this->green_curve; + this->green_curve = new SPCurve(); - cc->red_curve->reset(); - sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(cc->red_bpath), NULL); + this->red_curve->reset(); + sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), NULL); if (c->is_empty()) { c->unref(); return; } - spcc_flush_white(cc, c); + this->_flushWhite(c); c->unref(); } @@ -925,9 +877,7 @@ spcc_concat_colors_and_flush(ConnectorTool *cc) * */ -static void -spcc_flush_white(ConnectorTool *cc, SPCurve *gc) -{ +void ConnectorTool::_flushWhite(SPCurve *gc) { SPCurve *c; if (gc) { @@ -938,9 +888,9 @@ spcc_flush_white(ConnectorTool *cc, SPCurve *gc) } /* Now we have to go back to item coordinates at last */ - c->transform(cc->desktop->dt2doc()); + c->transform(this->desktop->dt2doc()); - SPDesktop *desktop = cc->desktop; + SPDesktop *desktop = this->desktop; SPDocument *doc = sp_desktop_document(desktop); Inkscape::XML::Document *xml_doc = doc->getReprDoc(); @@ -957,42 +907,42 @@ spcc_flush_white(ConnectorTool *cc, SPCurve *gc) g_free(str); /* Attach repr */ - cc->newconn = SP_ITEM(desktop->currentLayer()->appendChildRepr(repr)); - cc->newconn->transform = SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse(); + this->newconn = SP_ITEM(desktop->currentLayer()->appendChildRepr(repr)); + this->newconn->transform = SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse(); bool connection = false; - cc->newconn->setAttribute( "inkscape:connector-type", - cc->isOrthogonal ? "orthogonal" : "polyline", NULL ); - cc->newconn->setAttribute( "inkscape:connector-curvature", - Glib::Ascii::dtostr(cc->curvature).c_str(), NULL ); - if (cc->shref) + this->newconn->setAttribute( "inkscape:connector-type", + this->isOrthogonal ? "orthogonal" : "polyline", NULL ); + this->newconn->setAttribute( "inkscape:connector-curvature", + Glib::Ascii::dtostr(this->curvature).c_str(), NULL ); + if (this->shref) { - cc->newconn->setAttribute( "inkscape:connection-start", cc->shref, NULL); + this->newconn->setAttribute( "inkscape:connection-start", this->shref, NULL); connection = true; } - if (cc->ehref) + if (this->ehref) { - cc->newconn->setAttribute( "inkscape:connection-end", cc->ehref, NULL); + this->newconn->setAttribute( "inkscape:connection-end", this->ehref, NULL); connection = true; } // Process pending updates. - cc->newconn->updateRepr(); + this->newconn->updateRepr(); doc->ensureUpToDate(); if (connection) { // Adjust endpoints to shape edge. - sp_conn_reroute_path_immediate(SP_PATH(cc->newconn)); - cc->newconn->updateRepr(); + sp_conn_reroute_path_immediate(SP_PATH(this->newconn)); + this->newconn->updateRepr(); } - cc->newconn->doWriteTransform(cc->newconn->getRepr(), cc->newconn->transform, NULL, true); + this->newconn->doWriteTransform(this->newconn->getRepr(), this->newconn->transform, NULL, true); // Only set the selection after we are finished with creating the attributes of // the connector. Otherwise, the selection change may alter the defaults for // values like curvature in the connector context, preventing subsequent lookup // of their original values. - cc->selection->set(repr); + this->selection->set(repr); Inkscape::GC::release(repr); } @@ -1002,36 +952,31 @@ spcc_flush_white(ConnectorTool *cc, SPCurve *gc) } -static void -spcc_connector_finish_segment(ConnectorTool *const cc, Geom::Point const /*p*/) -{ - if (!cc->red_curve->is_empty()) { - cc->green_curve->append_continuous(cc->red_curve, 0.0625); +void ConnectorTool::_finishSegment(Geom::Point const /*p*/) { + if (!this->red_curve->is_empty()) { + this->green_curve->append_continuous(this->red_curve, 0.0625); - cc->p[0] = cc->p[3]; - cc->p[1] = cc->p[4]; - cc->npoints = 2; + this->p[0] = this->p[3]; + this->p[1] = this->p[4]; + this->npoints = 2; - cc->red_curve->reset(); + this->red_curve->reset(); } } - -static void -spcc_connector_finish(ConnectorTool *const cc) -{ - SPDesktop *const desktop = cc->desktop; +void ConnectorTool::_finish() { + SPDesktop *const desktop = this->desktop; desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Finishing connector")); - cc->red_curve->reset(); - spcc_concat_colors_and_flush(cc); + this->red_curve->reset(); + this->_concatColorsAndFlush(); - cc->npoints = 0; + this->npoints = 0; - if (cc->newConnRef) { - cc->newConnRef->removeFromGraph(); - delete cc->newConnRef; - cc->newConnRef = NULL; + if (this->newConnRef) { + this->newConnRef->removeFromGraph(); + delete this->newConnRef; + this->newConnRef = NULL; } } @@ -1102,7 +1047,7 @@ endpt_handler(SPKnot */*knot*/, GdkEvent *event, ConnectorTool *cc) if (cc->state == SP_CONNECTOR_CONTEXT_IDLE) { cc->clickeditem = cc->active_conn; cc->clickedhandle = cc->active_handle; - cc_clear_active_conn(cc); + cc->cc_clear_active_conn(); cc->state = SP_CONNECTOR_CONTEXT_REROUTING; // Disconnect from attached shape @@ -1137,9 +1082,8 @@ endpt_handler(SPKnot */*knot*/, GdkEvent *event, ConnectorTool *cc) return consumed; } -static void cc_active_shape_add_knot(ConnectorTool *cc, SPItem* item) -{ - SPDesktop *desktop = cc->desktop; +void ConnectorTool::_activeShapeAddKnot(SPItem* item) { + SPDesktop *desktop = this->desktop; SPKnot *knot = sp_knot_new(desktop, 0); knot->owner = item; @@ -1158,48 +1102,47 @@ static void cc_active_shape_add_knot(ConnectorTool *cc, SPItem* item) G_CALLBACK(cc_generic_knot_handler), knot); sp_knot_set_position(knot, item->avoidRef->getConnectionPointPos() * desktop->doc2dt(), 0); sp_knot_show(knot); - cc->knots[knot] = 1; + this->knots[knot] = 1; } -static void cc_set_active_shape(ConnectorTool *cc, SPItem *item) -{ +void ConnectorTool::_setActiveShape(SPItem *item) { g_assert(item != NULL ); - if (cc->active_shape != item) + if (this->active_shape != item) { // The active shape has changed // Rebuild everything - cc->active_shape = item; + this->active_shape = item; // Remove existing active shape listeners - if (cc->active_shape_repr) { - sp_repr_remove_listener_by_data(cc->active_shape_repr, cc); - Inkscape::GC::release(cc->active_shape_repr); + if (this->active_shape_repr) { + sp_repr_remove_listener_by_data(this->active_shape_repr, this); + Inkscape::GC::release(this->active_shape_repr); - sp_repr_remove_listener_by_data(cc->active_shape_layer_repr, cc); - Inkscape::GC::release(cc->active_shape_layer_repr); + sp_repr_remove_listener_by_data(this->active_shape_layer_repr, this); + Inkscape::GC::release(this->active_shape_layer_repr); } // Listen in case the active shape changes - cc->active_shape_repr = item->getRepr(); - if (cc->active_shape_repr) { - Inkscape::GC::anchor(cc->active_shape_repr); - sp_repr_add_listener(cc->active_shape_repr, &shape_repr_events, cc); - - cc->active_shape_layer_repr = cc->active_shape_repr->parent(); - Inkscape::GC::anchor(cc->active_shape_layer_repr); - sp_repr_add_listener(cc->active_shape_layer_repr, &layer_repr_events, cc); + this->active_shape_repr = item->getRepr(); + if (this->active_shape_repr) { + Inkscape::GC::anchor(this->active_shape_repr); + sp_repr_add_listener(this->active_shape_repr, &shape_repr_events, this); + + this->active_shape_layer_repr = this->active_shape_repr->parent(); + Inkscape::GC::anchor(this->active_shape_layer_repr); + sp_repr_add_listener(this->active_shape_layer_repr, &layer_repr_events, this); } - cc_clear_active_knots(cc->knots); + cc_clear_active_knots(this->knots); // The idea here is to try and add a group's children to solidify // connection handling. We react to path objects with only one node. for (SPObject *child = item->firstChild() ; child ; child = child->getNext() ) { if (SP_IS_PATH(child) && SP_PATH(child)->nodesInPath() == 1) { - cc_active_shape_add_knot(cc, (SPItem *) child); + this->_activeShapeAddKnot((SPItem *) child); } } - cc_active_shape_add_knot(cc, item); + this->_activeShapeAddKnot(item); } else @@ -1210,58 +1153,55 @@ static void cc_set_active_shape(ConnectorTool *cc, SPItem *item) } } - -static void -cc_set_active_conn(ConnectorTool *cc, SPItem *item) -{ +void ConnectorTool::cc_set_active_conn(SPItem *item) { g_assert( SP_IS_PATH(item) ); const SPCurve *curve = SP_PATH(item)->get_curve_reference(); Geom::Affine i2dt = item->i2dt_affine(); - if (cc->active_conn == item) + if (this->active_conn == item) { if (curve->is_empty()) { // Connector is invisible because it is clipped to the boundary of // two overlpapping shapes. - sp_knot_hide(cc->endpt_handle[0]); - sp_knot_hide(cc->endpt_handle[1]); + sp_knot_hide(this->endpt_handle[0]); + sp_knot_hide(this->endpt_handle[1]); } else { // Just adjust handle positions. Geom::Point startpt = *(curve->first_point()) * i2dt; - sp_knot_set_position(cc->endpt_handle[0], startpt, 0); + sp_knot_set_position(this->endpt_handle[0], startpt, 0); Geom::Point endpt = *(curve->last_point()) * i2dt; - sp_knot_set_position(cc->endpt_handle[1], endpt, 0); + sp_knot_set_position(this->endpt_handle[1], endpt, 0); } return; } - cc->active_conn = item; + this->active_conn = item; // Remove existing active conn listeners - if (cc->active_conn_repr) { - sp_repr_remove_listener_by_data(cc->active_conn_repr, cc); - Inkscape::GC::release(cc->active_conn_repr); - cc->active_conn_repr = NULL; + if (this->active_conn_repr) { + sp_repr_remove_listener_by_data(this->active_conn_repr, this); + Inkscape::GC::release(this->active_conn_repr); + this->active_conn_repr = NULL; } // Listen in case the active conn changes - cc->active_conn_repr = item->getRepr(); - if (cc->active_conn_repr) { - Inkscape::GC::anchor(cc->active_conn_repr); - sp_repr_add_listener(cc->active_conn_repr, &shape_repr_events, cc); + this->active_conn_repr = item->getRepr(); + if (this->active_conn_repr) { + Inkscape::GC::anchor(this->active_conn_repr); + sp_repr_add_listener(this->active_conn_repr, &shape_repr_events, this); } for (int i = 0; i < 2; ++i) { // Create the handle if it doesn't exist - if ( cc->endpt_handle[i] == NULL ) { - SPKnot *knot = sp_knot_new(cc->desktop, + if ( this->endpt_handle[i] == NULL ) { + SPKnot *knot = sp_knot_new(this->desktop, _("Connector endpoint: drag to reroute or connect to new shapes")); knot->setShape(SP_KNOT_SHAPE_SQUARE); @@ -1280,23 +1220,23 @@ cc_set_active_conn(ConnectorTool *cc, SPItem *item) g_signal_connect(G_OBJECT(knot->item), "event", G_CALLBACK(cc_generic_knot_handler), knot); - cc->endpt_handle[i] = knot; + this->endpt_handle[i] = knot; } // Remove any existing handlers - if (cc->endpt_handler_id[i]) { + if (this->endpt_handler_id[i]) { g_signal_handlers_disconnect_by_func( - G_OBJECT(cc->endpt_handle[i]->item), - (void*)G_CALLBACK(endpt_handler), (gpointer) cc ); - cc->endpt_handler_id[i] = 0; + G_OBJECT(this->endpt_handle[i]->item), + (void*)G_CALLBACK(endpt_handler), (gpointer) this ); + this->endpt_handler_id[i] = 0; } // Setup handlers for connector endpoints, this is // is as 'after' so that cc_generic_knot_handler is // triggered first for any endpoint. - cc->endpt_handler_id[i] = g_signal_connect_after( - G_OBJECT(cc->endpt_handle[i]->item), "event", - G_CALLBACK(endpt_handler), cc); + this->endpt_handler_id[i] = g_signal_connect_after( + G_OBJECT(this->endpt_handle[i]->item), "event", + G_CALLBACK(endpt_handler), this); } if (curve->is_empty()) @@ -1307,13 +1247,13 @@ cc_set_active_conn(ConnectorTool *cc, SPItem *item) } Geom::Point startpt = *(curve->first_point()) * i2dt; - sp_knot_set_position(cc->endpt_handle[0], startpt, 0); + sp_knot_set_position(this->endpt_handle[0], startpt, 0); Geom::Point endpt = *(curve->last_point()) * i2dt; - sp_knot_set_position(cc->endpt_handle[1], endpt, 0); + sp_knot_set_position(this->endpt_handle[1], endpt, 0); - sp_knot_show(cc->endpt_handle[0]); - sp_knot_show(cc->endpt_handle[1]); + sp_knot_show(this->endpt_handle[0]); + sp_knot_show(this->endpt_handle[1]); } void cc_create_connection_point(ConnectorTool* cc) @@ -1412,7 +1352,7 @@ void cc_selection_set_avoid(bool const set_avoid) DocumentUndo::done(document, SP_VERB_CONTEXT_CONNECTOR, event_desc); } -void ConnectorTool::selection_changed(Inkscape::Selection *selection) { +void ConnectorTool::_selectionChanged(Inkscape::Selection *selection) { SPItem *item = selection->singleItem(); if (this->active_conn == item) { @@ -1421,12 +1361,12 @@ void ConnectorTool::selection_changed(Inkscape::Selection *selection) { } if (item == NULL) { - cc_clear_active_conn(this); + this->cc_clear_active_conn(); return; } if (cc_item_is_connector(item)) { - cc_set_active_conn(this, item); + this->cc_set_active_conn(item); } } @@ -1439,7 +1379,7 @@ shape_event_attr_deleted(Inkscape::XML::Node */*repr*/, Inkscape::XML::Node *chi if (child == cc->active_shape_repr) { // The active shape has been deleted. Clear active shape. - cc_clear_active_shape(cc); + cc->cc_clear_active_shape(); } } @@ -1459,12 +1399,12 @@ shape_event_attr_changed(Inkscape::XML::Node *repr, gchar const *name, { if (repr == cc->active_shape_repr) { // Active shape has moved. Clear active shape. - cc_clear_active_shape(cc); + cc->cc_clear_active_shape(); } else if (repr == cc->active_conn_repr) { // The active conn has been moved. // Set it again, which just sets new handle positions. - cc_set_active_conn(cc, cc->active_conn); + cc->cc_set_active_conn(cc->active_conn); } } } diff --git a/src/ui/tools/connector-tool.h b/src/ui/tools/connector-tool.h index 7cd6a6dad..59534a173 100644 --- a/src/ui/tools/connector-tool.h +++ b/src/ui/tools/connector-tool.h @@ -108,8 +108,31 @@ public: virtual const std::string& getPrefsPath(); + void cc_clear_active_shape(); + void cc_set_active_conn(SPItem *item); + void cc_clear_active_conn(); + private: - void selection_changed(Inkscape::Selection *selection); + void _selectionChanged(Inkscape::Selection *selection); + + gint _handleButtonPress(GdkEventButton const &bevent); + gint _handleMotionNotify(GdkEventMotion const &mevent); + gint _handleButtonRelease(GdkEventButton const &revent); + gint _handleKeyPress(guint const keyval); + + void _setInitialPoint(Geom::Point const p); + void _setSubsequentPoint(Geom::Point const p); + void _finishSegment(Geom::Point p); + void _resetColors(); + void _finish(); + void _concatColorsAndFlush(); + void _flushWhite(SPCurve *gc); + + void _activeShapeAddKnot(SPItem* item); + void _setActiveShape(SPItem *item); + bool _ptHandleTest(Geom::Point& p, gchar **href); + + void _reroutingFinish(Geom::Point *const p); }; void cc_selection_set_avoid(bool const set_ignore); diff --git a/src/ui/tools/freehand-base.cpp b/src/ui/tools/freehand-base.cpp index 2fb4a3481..288a200f4 100644 --- a/src/ui/tools/freehand-base.cpp +++ b/src/ui/tools/freehand-base.cpp @@ -331,7 +331,7 @@ static void spdc_check_for_and_apply_waiting_LPE(FreehandBase *dc, SPItem *item, } } if (SP_IS_PEN_CONTEXT(dc)) { - sp_pen_context_set_polyline_mode(SP_PEN_CONTEXT(dc)); + SP_PEN_CONTEXT(dc)->setPolylineMode(); } } } diff --git a/src/ui/tools/lpe-tool.cpp b/src/ui/tools/lpe-tool.cpp index 6c41bb160..9ab6d7814 100644 --- a/src/ui/tools/lpe-tool.cpp +++ b/src/ui/tools/lpe-tool.cpp @@ -191,7 +191,7 @@ bool LpeTool::root_handler(GdkEvent* event) { bool ret = false; - if (sp_pen_context_has_waiting_LPE(this)) { + if (this->hasWaitingLPE()) { // quit when we are waiting for a LPE to be applied //ret = ((ToolBaseClass *) sp_lpetool_context_parent_class)->root_handler(event_context, event); return PenTool::root_handler(event); @@ -222,7 +222,7 @@ bool LpeTool::root_handler(GdkEvent* event) { //bool over_stroke = lc->shape_editor->is_over_stroke(Geom::Point(event->button.x, event->button.y), true); - sp_pen_context_wait_for_LPE_mouse_clicks(this, type, Inkscape::LivePathEffect::Effect::acceptsNumClicks(type)); + this->waitForLPEMouseClicks(type, Inkscape::LivePathEffect::Effect::acceptsNumClicks(type)); // we pass the mouse click on to pen tool as the first click which it should collect //ret = ((ToolBaseClass *) sp_lpetool_context_parent_class)->root_handler(event_context, event); diff --git a/src/ui/tools/pen-tool.cpp b/src/ui/tools/pen-tool.cpp index 39b69f576..7228690b1 100644 --- a/src/ui/tools/pen-tool.cpp +++ b/src/ui/tools/pen-tool.cpp @@ -50,29 +50,8 @@ namespace Inkscape { namespace UI { namespace Tools { -static void spdc_pen_set_initial_point(PenTool *pc, Geom::Point const p); -static void spdc_pen_set_subsequent_point(PenTool *const pc, Geom::Point const p, bool statusbar, guint status = 0); -static void spdc_pen_set_ctrl(PenTool *pc, Geom::Point const p, guint state); -static void spdc_pen_finish_segment(PenTool *pc, Geom::Point p, guint state); - -static void spdc_pen_finish(PenTool *pc, gboolean closed); - -static gint pen_handle_button_press(PenTool *const pc, GdkEventButton const &bevent); -static gint pen_handle_motion_notify(PenTool *const pc, GdkEventMotion const &mevent); -static gint pen_handle_button_release(PenTool *const pc, GdkEventButton const &revent); -static gint pen_handle_2button_press(PenTool *const pc, GdkEventButton const &bevent); -static gint pen_handle_key_press(PenTool *const pc, GdkEvent *event); -static void spdc_reset_colors(PenTool *pc); - -static void pen_disable_events(PenTool *const pc); -static void pen_enable_events(PenTool *const pc); - static Geom::Point pen_drag_origin_w(0, 0); static bool pen_within_tolerance = false; - -static int pen_next_paraxial_direction(const PenTool *const pc, Geom::Point const &pt, Geom::Point const &origin, guint state); -static void pen_set_to_nearest_horiz_vert(const PenTool *const pc, Geom::Point &pt, guint const state, bool snap); - static int pen_last_paraxial_dir = 0; // last used direction in horizontal/vertical mode; 0 = horizontal, 1 = vertical namespace { @@ -153,11 +132,11 @@ PenTool::~PenTool() { } } -void sp_pen_context_set_polyline_mode(PenTool *const pc) { +void PenTool::setPolylineMode() { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); guint mode = prefs->getInt("/tools/freehand/pen/freehand-mode", 0); - pc->polylines_only = (mode == 2 || mode == 3); - pc->polylines_paraxial = (mode == 3); + this->polylines_only = (mode == 2 || mode == 3); + this->polylines_paraxial = (mode == 3); } /** @@ -187,7 +166,7 @@ void PenTool::setup() { this->anchor_statusbar = false; - sp_pen_context_set_polyline_mode(this); + this->setPolylineMode(); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); if (prefs->getBool("/tools/freehand/pen/selcue")) { @@ -195,19 +174,18 @@ void PenTool::setup() { } } -static void pen_cancel (PenTool *const pc) -{ - pc->num_clicks = 0; - pc->state = PenTool::STOP; - spdc_reset_colors(pc); - sp_canvas_item_hide(pc->c0); - sp_canvas_item_hide(pc->c1); - sp_canvas_item_hide(pc->cl0); - sp_canvas_item_hide(pc->cl1); - pc->message_context->clear(); - pc->message_context->flash(Inkscape::NORMAL_MESSAGE, _("Drawing cancelled")); - - pc->desktop->canvas->endForcedFullRedraws(); +void PenTool::_cancel() { + this->num_clicks = 0; + this->state = PenTool::STOP; + this->_resetColors(); + sp_canvas_item_hide(this->c0); + sp_canvas_item_hide(this->c1); + sp_canvas_item_hide(this->cl0); + sp_canvas_item_hide(this->cl1); + this->message_context->clear(); + this->message_context->flash(Inkscape::NORMAL_MESSAGE, _("Drawing cancelled")); + + this->desktop->canvas->endForcedFullRedraws(); } /** @@ -217,7 +195,7 @@ void PenTool::finish() { sp_event_context_discard_delayed_snap_event(this); if (this->npoints != 0) { - pen_cancel(this); + this->_cancel(); } FreehandBase::finish(); @@ -238,26 +216,31 @@ void PenTool::set(const Inkscape::Preferences::Entry& val) { } } +bool PenTool::hasWaitingLPE() { + // note: waiting_LPE_type is defined in SPDrawContext + return (this->waiting_LPE != NULL || + this->waiting_LPE_type != Inkscape::LivePathEffect::INVALID_LPE); +} + /** * Snaps new node relative to the previous node. */ -static void spdc_endpoint_snap(PenTool const *const pc, Geom::Point &p, guint const state) -{ - if ((state & GDK_CONTROL_MASK) && !pc->polylines_paraxial) { //CTRL enables angular snapping - if (pc->npoints > 0) { - spdc_endpoint_snap_rotation(pc, p, pc->p[0], state); +void PenTool::_endpointSnap(Geom::Point &p, guint const state) const { + if ((state & GDK_CONTROL_MASK) && !this->polylines_paraxial) { //CTRL enables angular snapping + if (this->npoints > 0) { + spdc_endpoint_snap_rotation(this, p, this->p[0], state); } } else { // We cannot use shift here to disable snapping because the shift-key is already used // to toggle the paraxial direction; if the user wants to disable snapping (s)he will // have to use the %-key, the menu, or the snap toolbar - if ((pc->npoints > 0) && pc->polylines_paraxial) { + if ((this->npoints > 0) && this->polylines_paraxial) { // snap constrained - pen_set_to_nearest_horiz_vert(pc, p, state, true); + this->_setToNearestHorizVert(p, state, true); } else { // snap freely - boost::optional origin = pc->npoints > 0 ? pc->p[0] : boost::optional(); - spdc_endpoint_snap_free(pc, p, origin, state); // pass the origin, to allow for perpendicular / tangential snapping + boost::optional origin = this->npoints > 0 ? this->p[0] : boost::optional(); + spdc_endpoint_snap_free(this, p, origin, state); // pass the origin, to allow for perpendicular / tangential snapping } } } @@ -265,17 +248,16 @@ static void spdc_endpoint_snap(PenTool const *const pc, Geom::Point &p, guint co /** * Snaps new node's handle relative to the new node. */ -static void spdc_endpoint_snap_handle(PenTool const *const pc, Geom::Point &p, guint const state) -{ - g_return_if_fail(( pc->npoints == 2 || - pc->npoints == 5 )); +void PenTool::_endpointSnapHandle(Geom::Point &p, guint const state) const { + g_return_if_fail(( this->npoints == 2 || + this->npoints == 5 )); if ((state & GDK_CONTROL_MASK)) { //CTRL enables angular snapping - spdc_endpoint_snap_rotation(pc, p, pc->p[pc->npoints - 2], state); + spdc_endpoint_snap_rotation(this, p, this->p[this->npoints - 2], state); } else { if (!(state & GDK_SHIFT_MASK)) { //SHIFT disables all snapping, except the angular snapping above - boost::optional origin = pc->p[pc->npoints - 2]; - spdc_endpoint_snap_free(pc, p, origin, state); + boost::optional origin = this->p[this->npoints - 2]; + spdc_endpoint_snap_free(this, p, origin, state); } } } @@ -285,10 +267,10 @@ bool PenTool::item_handler(SPItem* item, GdkEvent* event) { switch (event->type) { case GDK_BUTTON_PRESS: - ret = pen_handle_button_press(this, event->button); + ret = this->_handleButtonPress(event->button); break; case GDK_BUTTON_RELEASE: - ret = pen_handle_button_release(this, event->button); + ret = this->_handleButtonRelease(event->button); break; default: break; @@ -309,23 +291,23 @@ bool PenTool::root_handler(GdkEvent* event) { switch (event->type) { case GDK_BUTTON_PRESS: - ret = pen_handle_button_press(this, event->button); + ret = this->_handleButtonPress(event->button); break; case GDK_MOTION_NOTIFY: - ret = pen_handle_motion_notify(this, event->motion); + ret = this->_handleMotionNotify(event->motion); break; case GDK_BUTTON_RELEASE: - ret = pen_handle_button_release(this, event->button); + ret = this->_handleButtonRelease(event->button); break; case GDK_2BUTTON_PRESS: - ret = pen_handle_2button_press(this, event->button); + ret = this->_handle2ButtonPress(event->button); break; case GDK_KEY_PRESS: - ret = pen_handle_key_press(this, event); + ret = this->_handleKeyPress(event); break; default: @@ -342,32 +324,31 @@ bool PenTool::root_handler(GdkEvent* event) { /** * Handle mouse button press event. */ -static gint pen_handle_button_press(PenTool *const pc, GdkEventButton const &bevent) -{ - if (pc->events_disabled) { +gint PenTool::_handleButtonPress(GdkEventButton const &bevent) { + if (this->events_disabled) { // skip event processing if events are disabled return FALSE; } - FreehandBase * const dc = SP_DRAW_CONTEXT(pc); + FreehandBase * const dc = SP_DRAW_CONTEXT(this); SPDesktop * const desktop = dc->desktop; Geom::Point const event_w(bevent.x, bevent.y); Geom::Point event_dt(desktop->w2d(event_w)); - ToolBase *event_context = SP_EVENT_CONTEXT(pc); + ToolBase *event_context = SP_EVENT_CONTEXT(this); gint ret = FALSE; if (bevent.button == 1 && !event_context->space_panning // make sure this is not the last click for a waiting LPE (otherwise we want to finish the path) - && pc->expecting_clicks_for_LPE != 1) { + && this->expecting_clicks_for_LPE != 1) { if (Inkscape::have_viable_layer(desktop, dc->message_context) == false) { return TRUE; } - if (!pc->grab ) { + if (!this->grab ) { // Grab mouse, so release will not pass unnoticed - pc->grab = SP_CANVAS_ITEM(desktop->acetate); - sp_canvas_item_grab(pc->grab, ( GDK_KEY_PRESS_MASK | GDK_BUTTON_PRESS_MASK | + this->grab = SP_CANVAS_ITEM(desktop->acetate); + sp_canvas_item_grab(this->grab, ( GDK_KEY_PRESS_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK ), NULL, bevent.time); @@ -377,33 +358,33 @@ static gint pen_handle_button_press(PenTool *const pc, GdkEventButton const &bev pen_within_tolerance = true; // Test whether we hit any anchor. - SPDrawAnchor * const anchor = spdc_test_inside(pc, event_w); + SPDrawAnchor * const anchor = spdc_test_inside(this, event_w); - switch (pc->mode) { + switch (this->mode) { case PenTool::MODE_CLICK: // In click mode we add point on release - switch (pc->state) { + switch (this->state) { case PenTool::POINT: case PenTool::CONTROL: case PenTool::CLOSE: break; case PenTool::STOP: // This is allowed, if we just canceled curve - pc->state = PenTool::POINT; + this->state = PenTool::POINT; break; default: break; } break; case PenTool::MODE_DRAG: - switch (pc->state) { + switch (this->state) { case PenTool::STOP: // This is allowed, if we just canceled curve case PenTool::POINT: - if (pc->npoints == 0) { + if (this->npoints == 0) { Geom::Point p; - if ((bevent.state & GDK_CONTROL_MASK) && (pc->polylines_only || pc->polylines_paraxial)) { + if ((bevent.state & GDK_CONTROL_MASK) && (this->polylines_only || this->polylines_paraxial)) { p = event_dt; if (!(bevent.state & GDK_SHIFT_MASK)) { SnapManager &m = desktop->namedview->snap_manager; @@ -420,8 +401,8 @@ static gint pen_handle_button_press(PenTool *const pc, GdkEventButton const &bev // distinction so that the case of a waiting LPE is treated separately // Set start anchor - pc->sa = anchor; - if (anchor && !sp_pen_context_has_waiting_LPE(pc)) { + this->sa = anchor; + if (anchor && !this->hasWaitingLPE()) { // Adjust point to anchor if needed; if we have a waiting LPE, we need // a fresh path to be created so don't continue an existing one p = anchor->dp; @@ -431,7 +412,7 @@ static gint pen_handle_button_press(PenTool *const pc, GdkEventButton const &bev // this curve is not combined with it (unless it is drawn from its // anchor, which is handled by the sibling branch above) Inkscape::Selection * const selection = sp_desktop_selection(desktop); - if (!(bevent.state & GDK_SHIFT_MASK) || sp_pen_context_has_waiting_LPE(pc)) { + if (!(bevent.state & GDK_SHIFT_MASK) || this->hasWaitingLPE()) { // if we have a waiting LPE, we need a fresh path to be created // so don't append to an existing one selection->clear(); @@ -442,22 +423,22 @@ static gint pen_handle_button_press(PenTool *const pc, GdkEventButton const &bev // Create green anchor p = event_dt; - spdc_endpoint_snap(pc, p, bevent.state); - pc->green_anchor = sp_draw_anchor_new(pc, pc->green_curve, TRUE, p); + this->_endpointSnap(p, bevent.state); + this->green_anchor = sp_draw_anchor_new(this, this->green_curve, TRUE, p); } - spdc_pen_set_initial_point(pc, p); + this->_setInitialPoint(p); } else { // Set end anchor - pc->ea = anchor; + this->ea = anchor; Geom::Point p; if (anchor) { p = anchor->dp; // we hit an anchor, will finish the curve (either with or without closing) // in release handler - pc->state = PenTool::CLOSE; + this->state = PenTool::CLOSE; - if (pc->green_anchor && pc->green_anchor->active) { + if (this->green_anchor && this->green_anchor->active) { // we clicked on the current curve start, so close it even if // we drag a handle away from it dc->green_closed = TRUE; @@ -467,12 +448,12 @@ static gint pen_handle_button_press(PenTool *const pc, GdkEventButton const &bev } else { p = event_dt; - spdc_endpoint_snap(pc, p, bevent.state); // Snap node only if not hitting anchor. - spdc_pen_set_subsequent_point(pc, p, true); + this->_endpointSnap(p, bevent.state); // Snap node only if not hitting anchor. + this->_setSubsequentPoint(p, true); } } - pc->state = pc->polylines_only ? PenTool::POINT : PenTool::CONTROL; + this->state = this->polylines_only ? PenTool::POINT : PenTool::CONTROL; ret = TRUE; break; case PenTool::CONTROL: @@ -488,26 +469,26 @@ static gint pen_handle_button_press(PenTool *const pc, GdkEventButton const &bev default: break; } - } else if (pc->expecting_clicks_for_LPE == 1 && pc->npoints != 0) { + } else if (this->expecting_clicks_for_LPE == 1 && this->npoints != 0) { // when the last click for a waiting LPE occurs we want to finish the path - spdc_pen_finish_segment(pc, event_dt, bevent.state); - if (pc->green_closed) { + this->_finishSegment(event_dt, bevent.state); + if (this->green_closed) { // finishing at the start anchor, close curve - spdc_pen_finish(pc, TRUE); + this->_finish(TRUE); } else { // finishing at some other anchor, finish curve but not close - spdc_pen_finish(pc, FALSE); + this->_finish(FALSE); } ret = TRUE; - } else if (bevent.button == 3 && pc->npoints != 0) { + } else if (bevent.button == 3 && this->npoints != 0) { // right click - finish path - spdc_pen_finish(pc, FALSE); + this->_finish(FALSE); ret = TRUE; } - if (pc->expecting_clicks_for_LPE > 0) { - --pc->expecting_clicks_for_LPE; + if (this->expecting_clicks_for_LPE > 0) { + --this->expecting_clicks_for_LPE; } return ret; @@ -516,11 +497,10 @@ static gint pen_handle_button_press(PenTool *const pc, GdkEventButton const &bev /** * Handle motion_notify event. */ -static gint pen_handle_motion_notify(PenTool *const pc, GdkEventMotion const &mevent) -{ +gint PenTool::_handleMotionNotify(GdkEventMotion const &mevent) { gint ret = FALSE; - ToolBase *event_context = SP_EVENT_CONTEXT(pc); + ToolBase *event_context = SP_EVENT_CONTEXT(this); SPDesktop * const dt = event_context->desktop; if (event_context->space_panning || mevent.state & GDK_BUTTON2_MASK || mevent.state & GDK_BUTTON3_MASK) { @@ -528,7 +508,7 @@ static gint pen_handle_motion_notify(PenTool *const pc, GdkEventMotion const &me return FALSE; } - if (pc->events_disabled) { + if (this->events_disabled) { // skip motion events if pen events are disabled return FALSE; } @@ -551,18 +531,18 @@ static gint pen_handle_motion_notify(PenTool *const pc, GdkEventMotion const &me Geom::Point p = dt->w2d(event_w); // Test, whether we hit any anchor - SPDrawAnchor *anchor = spdc_test_inside(pc, event_w); + SPDrawAnchor *anchor = spdc_test_inside(this, event_w); - switch (pc->mode) { + switch (this->mode) { case PenTool::MODE_CLICK: - switch (pc->state) { + switch (this->state) { case PenTool::POINT: - if ( pc->npoints != 0 ) { + if ( this->npoints != 0 ) { // Only set point, if we are already appending - spdc_endpoint_snap(pc, p, mevent.state); - spdc_pen_set_subsequent_point(pc, p, true); + this->_endpointSnap(p, mevent.state); + this->_setSubsequentPoint(p, true); ret = TRUE; - } else if (!sp_event_context_knot_mouseover(pc)) { + } else if (!this->sp_event_context_knot_mouseover()) { SnapManager &m = dt->namedview->snap_manager; m.setup(dt); m.preSnap(Inkscape::SnapCandidatePoint(p, Inkscape::SNAPSOURCE_NODE_HANDLE)); @@ -572,8 +552,8 @@ static gint pen_handle_motion_notify(PenTool *const pc, GdkEventMotion const &me case PenTool::CONTROL: case PenTool::CLOSE: // Placing controls is last operation in CLOSE state - spdc_endpoint_snap(pc, p, mevent.state); - spdc_pen_set_ctrl(pc, p, mevent.state); + this->_endpointSnap(p, mevent.state); + this->_setCtrl(p, mevent.state); ret = TRUE; break; case PenTool::STOP: @@ -584,36 +564,36 @@ static gint pen_handle_motion_notify(PenTool *const pc, GdkEventMotion const &me } break; case PenTool::MODE_DRAG: - switch (pc->state) { + switch (this->state) { case PenTool::POINT: - if ( pc->npoints > 0 ) { + if ( this->npoints > 0 ) { // Only set point, if we are already appending if (!anchor) { // Snap node only if not hitting anchor - spdc_endpoint_snap(pc, p, mevent.state); - spdc_pen_set_subsequent_point(pc, p, true, mevent.state); + this->_endpointSnap(p, mevent.state); + this->_setSubsequentPoint(p, true, mevent.state); } else { - spdc_pen_set_subsequent_point(pc, anchor->dp, false, mevent.state); + this->_setSubsequentPoint(anchor->dp, false, mevent.state); } - if (anchor && !pc->anchor_statusbar) { - pc->message_context->set(Inkscape::NORMAL_MESSAGE, _("Click or click and drag to close and finish the path.")); - pc->anchor_statusbar = true; - } else if (!anchor && pc->anchor_statusbar) { - pc->message_context->clear(); - pc->anchor_statusbar = false; + if (anchor && !this->anchor_statusbar) { + this->message_context->set(Inkscape::NORMAL_MESSAGE, _("Click or click and drag to close and finish the path.")); + this->anchor_statusbar = true; + } else if (!anchor && this->anchor_statusbar) { + this->message_context->clear(); + this->anchor_statusbar = false; } ret = TRUE; } else { - if (anchor && !pc->anchor_statusbar) { - pc->message_context->set(Inkscape::NORMAL_MESSAGE, _("Click or click and drag to continue the path from this point.")); - pc->anchor_statusbar = true; - } else if (!anchor && pc->anchor_statusbar) { - pc->message_context->clear(); - pc->anchor_statusbar = false; + if (anchor && !this->anchor_statusbar) { + this->message_context->set(Inkscape::NORMAL_MESSAGE, _("Click or click and drag to continue the path from this point.")); + this->anchor_statusbar = true; + } else if (!anchor && this->anchor_statusbar) { + this->message_context->clear(); + this->anchor_statusbar = false; } - if (!sp_event_context_knot_mouseover(pc)) { + if (!this->sp_event_context_knot_mouseover()) { SnapManager &m = dt->namedview->snap_manager; m.setup(dt); m.preSnap(Inkscape::SnapCandidatePoint(p, Inkscape::SNAPSOURCE_NODE_HANDLE)); @@ -626,12 +606,12 @@ static gint pen_handle_motion_notify(PenTool *const pc, GdkEventMotion const &me // Placing controls is last operation in CLOSE state // snap the handle - spdc_endpoint_snap_handle(pc, p, mevent.state); + this->_endpointSnapHandle(p, mevent.state); - if (!pc->polylines_only) { - spdc_pen_set_ctrl(pc, p, mevent.state); + if (!this->polylines_only) { + this->_setCtrl(p, mevent.state); } else { - spdc_pen_set_ctrl(pc, pc->p[1], mevent.state); + this->_setCtrl(this->p[1], mevent.state); } gobble_motion_events(GDK_BUTTON1_MASK); ret = TRUE; @@ -640,7 +620,7 @@ static gint pen_handle_motion_notify(PenTool *const pc, GdkEventMotion const &me // This is perfectly valid break; default: - if (!sp_event_context_knot_mouseover(pc)) { + if (!this->sp_event_context_knot_mouseover()) { SnapManager &m = dt->namedview->snap_manager; m.setup(dt); m.preSnap(Inkscape::SnapCandidatePoint(p, Inkscape::SNAPSOURCE_NODE_HANDLE)); @@ -658,68 +638,67 @@ static gint pen_handle_motion_notify(PenTool *const pc, GdkEventMotion const &me /** * Handle mouse button release event. */ -static gint pen_handle_button_release(PenTool *const pc, GdkEventButton const &revent) -{ - if (pc->events_disabled) { +gint PenTool::_handleButtonRelease(GdkEventButton const &revent) { + if (this->events_disabled) { // skip event processing if events are disabled return FALSE; } gint ret = FALSE; - ToolBase *event_context = SP_EVENT_CONTEXT(pc); + ToolBase *event_context = SP_EVENT_CONTEXT(this); if ( revent.button == 1 && !event_context->space_panning) { - FreehandBase *dc = SP_DRAW_CONTEXT (pc); + FreehandBase *dc = SP_DRAW_CONTEXT (this); Geom::Point const event_w(revent.x, revent.y); // Find desktop coordinates - Geom::Point p = pc->desktop->w2d(event_w); + Geom::Point p = this->desktop->w2d(event_w); // Test whether we hit any anchor. - SPDrawAnchor *anchor = spdc_test_inside(pc, event_w); + SPDrawAnchor *anchor = spdc_test_inside(this, event_w); - switch (pc->mode) { + switch (this->mode) { case PenTool::MODE_CLICK: - switch (pc->state) { + switch (this->state) { case PenTool::POINT: - if ( pc->npoints == 0 ) { + if ( this->npoints == 0 ) { // Start new thread only with button release if (anchor) { p = anchor->dp; } - pc->sa = anchor; - spdc_pen_set_initial_point(pc, p); + this->sa = anchor; + this->_setInitialPoint(p); } else { // Set end anchor here - pc->ea = anchor; + this->ea = anchor; if (anchor) { p = anchor->dp; } } - pc->state = PenTool::CONTROL; + this->state = PenTool::CONTROL; ret = TRUE; break; case PenTool::CONTROL: // End current segment - spdc_endpoint_snap(pc, p, revent.state); - spdc_pen_finish_segment(pc, p, revent.state); - pc->state = PenTool::POINT; + this->_endpointSnap(p, revent.state); + this->_finishSegment(p, revent.state); + this->state = PenTool::POINT; ret = TRUE; break; case PenTool::CLOSE: // End current segment if (!anchor) { // Snap node only if not hitting anchor - spdc_endpoint_snap(pc, p, revent.state); + this->_endpointSnap(p, revent.state); } - spdc_pen_finish_segment(pc, p, revent.state); - spdc_pen_finish(pc, TRUE); - pc->state = PenTool::POINT; + this->_finishSegment(p, revent.state); + this->_finish(TRUE); + this->state = PenTool::POINT; ret = TRUE; break; case PenTool::STOP: // This is allowed, if we just canceled curve - pc->state = PenTool::POINT; + this->state = PenTool::POINT; ret = TRUE; break; default: @@ -727,21 +706,21 @@ static gint pen_handle_button_release(PenTool *const pc, GdkEventButton const &r } break; case PenTool::MODE_DRAG: - switch (pc->state) { + switch (this->state) { case PenTool::POINT: case PenTool::CONTROL: - spdc_endpoint_snap(pc, p, revent.state); - spdc_pen_finish_segment(pc, p, revent.state); + this->_endpointSnap(p, revent.state); + this->_finishSegment(p, revent.state); break; case PenTool::CLOSE: - spdc_endpoint_snap(pc, p, revent.state); - spdc_pen_finish_segment(pc, p, revent.state); - if (pc->green_closed) { + this->_endpointSnap(p, revent.state); + this->_finishSegment(p, revent.state); + if (this->green_closed) { // finishing at the start anchor, close curve - spdc_pen_finish(pc, TRUE); + this->_finish(TRUE); } else { // finishing at some other anchor, finish curve but not close - spdc_pen_finish(pc, FALSE); + this->_finish(FALSE); } break; case PenTool::STOP: @@ -750,17 +729,17 @@ static gint pen_handle_button_release(PenTool *const pc, GdkEventButton const &r default: break; } - pc->state = PenTool::POINT; + this->state = PenTool::POINT; ret = TRUE; break; default: break; } - if (pc->grab) { + if (this->grab) { // Release grab now - sp_canvas_item_ungrab(pc->grab, revent.time); - pc->grab = NULL; + sp_canvas_item_ungrab(this->grab, revent.time); + this->grab = NULL; } ret = TRUE; @@ -770,17 +749,17 @@ static gint pen_handle_button_release(PenTool *const pc, GdkEventButton const &r // TODO: can we be sure that the path was created correctly? // TODO: should we offer an option to collect the clicks in a list? - if (pc->expecting_clicks_for_LPE == 0 && sp_pen_context_has_waiting_LPE(pc)) { - sp_pen_context_set_polyline_mode(pc); + if (this->expecting_clicks_for_LPE == 0 && this->hasWaitingLPE()) { + this->setPolylineMode(); - ToolBase *ec = SP_EVENT_CONTEXT(pc); + ToolBase *ec = SP_EVENT_CONTEXT(this); Inkscape::Selection *selection = sp_desktop_selection (ec->desktop); - if (pc->waiting_LPE) { + if (this->waiting_LPE) { // we have an already created LPE waiting for a path - pc->waiting_LPE->acceptParamPath(SP_PATH(selection->singleItem())); - selection->add(SP_OBJECT(pc->waiting_item)); - pc->waiting_LPE = NULL; + this->waiting_LPE->acceptParamPath(SP_PATH(selection->singleItem())); + selection->add(SP_OBJECT(this->waiting_item)); + this->waiting_LPE = NULL; } else { // the case that we need to create a new LPE and apply it to the just-drawn path is // handled in spdc_check_for_and_apply_waiting_LPE() in draw-context.cpp @@ -790,125 +769,118 @@ static gint pen_handle_button_release(PenTool *const pc, GdkEventButton const &r return ret; } -static gint pen_handle_2button_press(PenTool *const pc, GdkEventButton const &bevent) -{ +gint PenTool::_handle2ButtonPress(GdkEventButton const &bevent) { gint ret = FALSE; // only end on LMB double click. Otherwise horizontal scrolling causes ending of the path - if (pc->npoints != 0 && bevent.button == 1) { - spdc_pen_finish(pc, FALSE); + if (this->npoints != 0 && bevent.button == 1) { + this->_finish(FALSE); ret = TRUE; } return ret; } -static void pen_redraw_all (PenTool *const pc) -{ +void PenTool::_redrawAll() { // green - if (pc->green_bpaths) { + if (this->green_bpaths) { // remove old piecewise green canvasitems - while (pc->green_bpaths) { - sp_canvas_item_destroy(SP_CANVAS_ITEM(pc->green_bpaths->data)); - pc->green_bpaths = g_slist_remove(pc->green_bpaths, pc->green_bpaths->data); + while (this->green_bpaths) { + sp_canvas_item_destroy(SP_CANVAS_ITEM(this->green_bpaths->data)); + this->green_bpaths = g_slist_remove(this->green_bpaths, this->green_bpaths->data); } // one canvas bpath for all of green_curve - SPCanvasItem *cshape = sp_canvas_bpath_new(sp_desktop_sketch(pc->desktop), pc->green_curve); - sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(cshape), pc->green_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); + SPCanvasItem *cshape = sp_canvas_bpath_new(sp_desktop_sketch(this->desktop), this->green_curve); + sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(cshape), this->green_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(cshape), 0, SP_WIND_RULE_NONZERO); - pc->green_bpaths = g_slist_prepend(pc->green_bpaths, cshape); + this->green_bpaths = g_slist_prepend(this->green_bpaths, cshape); } - if (pc->green_anchor) - SP_CTRL(pc->green_anchor->ctrl)->moveto(pc->green_anchor->dp); + if (this->green_anchor) + SP_CTRL(this->green_anchor->ctrl)->moveto(this->green_anchor->dp); - pc->red_curve->reset(); - pc->red_curve->moveto(pc->p[0]); - pc->red_curve->curveto(pc->p[1], pc->p[2], pc->p[3]); - sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(pc->red_bpath), pc->red_curve); + this->red_curve->reset(); + this->red_curve->moveto(this->p[0]); + this->red_curve->curveto(this->p[1], this->p[2], this->p[3]); + sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), this->red_curve); // handles - if (pc->p[0] != pc->p[1]) { - SP_CTRL(pc->c1)->moveto(pc->p[1]); - pc->cl1->setCoords(pc->p[0], pc->p[1]); - sp_canvas_item_show(pc->c1); - sp_canvas_item_show(pc->cl1); + if (this->p[0] != this->p[1]) { + SP_CTRL(this->c1)->moveto(this->p[1]); + this->cl1->setCoords(this->p[0], this->p[1]); + sp_canvas_item_show(this->c1); + sp_canvas_item_show(this->cl1); } else { - sp_canvas_item_hide(pc->c1); - sp_canvas_item_hide(pc->cl1); + sp_canvas_item_hide(this->c1); + sp_canvas_item_hide(this->cl1); } - Geom::Curve const * last_seg = pc->green_curve->last_segment(); + Geom::Curve const * last_seg = this->green_curve->last_segment(); if (last_seg) { Geom::CubicBezier const * cubic = dynamic_cast( last_seg ); if ( cubic && - (*cubic)[2] != pc->p[0] ) + (*cubic)[2] != this->p[0] ) { Geom::Point p2 = (*cubic)[2]; - SP_CTRL(pc->c0)->moveto(p2); - pc->cl0->setCoords(p2, pc->p[0]); - sp_canvas_item_show(pc->c0); - sp_canvas_item_show(pc->cl0); + SP_CTRL(this->c0)->moveto(p2); + this->cl0->setCoords(p2, this->p[0]); + sp_canvas_item_show(this->c0); + sp_canvas_item_show(this->cl0); } else { - sp_canvas_item_hide(pc->c0); - sp_canvas_item_hide(pc->cl0); + sp_canvas_item_hide(this->c0); + sp_canvas_item_hide(this->cl0); } } } -static void pen_lastpoint_move (PenTool *const pc, gdouble x, gdouble y) -{ - if (pc->npoints != 5) +void PenTool::_lastpointMove(gdouble x, gdouble y) { + if (this->npoints != 5) return; // green - if (!pc->green_curve->is_empty()) { - pc->green_curve->last_point_additive_move( Geom::Point(x,y) ); + if (!this->green_curve->is_empty()) { + this->green_curve->last_point_additive_move( Geom::Point(x,y) ); } else { // start anchor too - if (pc->green_anchor) { - pc->green_anchor->dp += Geom::Point(x, y); + if (this->green_anchor) { + this->green_anchor->dp += Geom::Point(x, y); } } // red - pc->p[0] += Geom::Point(x, y); - pc->p[1] += Geom::Point(x, y); - pen_redraw_all(pc); + this->p[0] += Geom::Point(x, y); + this->p[1] += Geom::Point(x, y); + this->_redrawAll(); } -static void pen_lastpoint_move_screen (PenTool *const pc, gdouble x, gdouble y) -{ - pen_lastpoint_move (pc, x / pc->desktop->current_zoom(), y / pc->desktop->current_zoom()); +void PenTool::_lastpointMoveScreen(gdouble x, gdouble y) { + this->_lastpointMove(x / this->desktop->current_zoom(), y / this->desktop->current_zoom()); } -static void pen_lastpoint_tocurve (PenTool *const pc) -{ - if (pc->npoints != 5) +void PenTool::_lastpointToCurve() { + if (this->npoints != 5) return; - Geom::CubicBezier const * cubic = dynamic_cast( pc->green_curve->last_segment() ); + Geom::CubicBezier const * cubic = dynamic_cast( this->green_curve->last_segment() ); if ( cubic ) { - pc->p[1] = pc->p[0] + (Geom::Point)( (*cubic)[3] - (*cubic)[2] ); + this->p[1] = this->p[0] + (Geom::Point)( (*cubic)[3] - (*cubic)[2] ); } else { - pc->p[1] = pc->p[0] + (1./3)*(pc->p[3] - pc->p[0]); + this->p[1] = this->p[0] + (1./3)*(this->p[3] - this->p[0]); } - pen_redraw_all(pc); + this->_redrawAll(); } -static void pen_lastpoint_toline (PenTool *const pc) -{ - if (pc->npoints != 5) +void PenTool::_lastpointToLine() { + if (this->npoints != 5) return; - pc->p[1] = pc->p[0]; + this->p[1] = this->p[0]; - pen_redraw_all(pc); + this->_redrawAll(); } -static gint pen_handle_key_press(PenTool *const pc, GdkEvent *event) -{ +gint PenTool::_handleKeyPress(GdkEvent *event) { gint ret = FALSE; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -920,12 +892,12 @@ static gint pen_handle_key_press(PenTool *const pc, GdkEvent *event) case GDK_KEY_KP_Left: if (!MOD__CTRL(event)) { // not ctrl if (MOD__ALT(event)) { // alt - if (MOD__SHIFT(event)) pen_lastpoint_move_screen(pc, -10, 0); // shift - else pen_lastpoint_move_screen(pc, -1, 0); // no shift + if (MOD__SHIFT(event)) this->_lastpointMoveScreen(-10, 0); // shift + else this->_lastpointMoveScreen(-1, 0); // no shift } else { // no alt - if (MOD__SHIFT(event)) pen_lastpoint_move(pc, -10*nudge, 0); // shift - else pen_lastpoint_move(pc, -nudge, 0); // no shift + if (MOD__SHIFT(event)) this->_lastpointMove(-10*nudge, 0); // shift + else this->_lastpointMove(-nudge, 0); // no shift } ret = TRUE; } @@ -934,12 +906,12 @@ static gint pen_handle_key_press(PenTool *const pc, GdkEvent *event) case GDK_KEY_KP_Up: if (!MOD__CTRL(event)) { // not ctrl if (MOD__ALT(event)) { // alt - if (MOD__SHIFT(event)) pen_lastpoint_move_screen(pc, 0, 10); // shift - else pen_lastpoint_move_screen(pc, 0, 1); // no shift + if (MOD__SHIFT(event)) this->_lastpointMoveScreen(0, 10); // shift + else this->_lastpointMoveScreen(0, 1); // no shift } else { // no alt - if (MOD__SHIFT(event)) pen_lastpoint_move(pc, 0, 10*nudge); // shift - else pen_lastpoint_move(pc, 0, nudge); // no shift + if (MOD__SHIFT(event)) this->_lastpointMove(0, 10*nudge); // shift + else this->_lastpointMove(0, nudge); // no shift } ret = TRUE; } @@ -948,12 +920,12 @@ static gint pen_handle_key_press(PenTool *const pc, GdkEvent *event) case GDK_KEY_KP_Right: if (!MOD__CTRL(event)) { // not ctrl if (MOD__ALT(event)) { // alt - if (MOD__SHIFT(event)) pen_lastpoint_move_screen(pc, 10, 0); // shift - else pen_lastpoint_move_screen(pc, 1, 0); // no shift + if (MOD__SHIFT(event)) this->_lastpointMoveScreen(10, 0); // shift + else this->_lastpointMoveScreen(1, 0); // no shift } else { // no alt - if (MOD__SHIFT(event)) pen_lastpoint_move(pc, 10*nudge, 0); // shift - else pen_lastpoint_move(pc, nudge, 0); // no shift + if (MOD__SHIFT(event)) this->_lastpointMove(10*nudge, 0); // shift + else this->_lastpointMove(nudge, 0); // no shift } ret = TRUE; } @@ -962,12 +934,12 @@ static gint pen_handle_key_press(PenTool *const pc, GdkEvent *event) case GDK_KEY_KP_Down: if (!MOD__CTRL(event)) { // not ctrl if (MOD__ALT(event)) { // alt - if (MOD__SHIFT(event)) pen_lastpoint_move_screen(pc, 0, -10); // shift - else pen_lastpoint_move_screen(pc, 0, -1); // no shift + if (MOD__SHIFT(event)) this->_lastpointMoveScreen(0, -10); // shift + else this->_lastpointMoveScreen(0, -1); // no shift } else { // no alt - if (MOD__SHIFT(event)) pen_lastpoint_move(pc, 0, -10*nudge); // shift - else pen_lastpoint_move(pc, 0, -nudge); // no shift + if (MOD__SHIFT(event)) this->_lastpointMove(0, -10*nudge); // shift + else this->_lastpointMove(0, -nudge); // no shift } ret = TRUE; } @@ -1010,90 +982,90 @@ static gint pen_handle_key_press(PenTool *const pc, GdkEvent *event) case GDK_KEY_U: case GDK_KEY_u: if (MOD__SHIFT_ONLY(event)) { - pen_lastpoint_tocurve(pc); + this->_lastpointToCurve(); ret = TRUE; } break; case GDK_KEY_L: case GDK_KEY_l: if (MOD__SHIFT_ONLY(event)) { - pen_lastpoint_toline(pc); + this->_lastpointToLine(); ret = TRUE; } break; case GDK_KEY_Return: case GDK_KEY_KP_Enter: - if (pc->npoints != 0) { - spdc_pen_finish(pc, FALSE); + if (this->npoints != 0) { + this->_finish(FALSE); ret = TRUE; } break; case GDK_KEY_Escape: - if (pc->npoints != 0) { + if (this->npoints != 0) { // if drawing, cancel, otherwise pass it up for deselecting - pen_cancel (pc); + this->_cancel (); ret = TRUE; } break; case GDK_KEY_z: case GDK_KEY_Z: - if (MOD__CTRL_ONLY(event) && pc->npoints != 0) { + if (MOD__CTRL_ONLY(event) && this->npoints != 0) { // if drawing, cancel, otherwise pass it up for undo - pen_cancel (pc); + this->_cancel (); ret = TRUE; } break; case GDK_KEY_g: case GDK_KEY_G: if (MOD__SHIFT_ONLY(event)) { - sp_selection_to_guides(SP_EVENT_CONTEXT(pc)->desktop); + sp_selection_to_guides(SP_EVENT_CONTEXT(this)->desktop); ret = true; } break; case GDK_KEY_BackSpace: case GDK_KEY_Delete: case GDK_KEY_KP_Delete: - if ( pc->green_curve->is_empty() || (pc->green_curve->last_segment() == NULL) ) { - if (!pc->red_curve->is_empty()) { - pen_cancel (pc); + if ( this->green_curve->is_empty() || (this->green_curve->last_segment() == NULL) ) { + if (!this->red_curve->is_empty()) { + this->_cancel (); ret = TRUE; } else { // do nothing; this event should be handled upstream } } else { // Reset red curve - pc->red_curve->reset(); + this->red_curve->reset(); // Destroy topmost green bpath - if (pc->green_bpaths) { - if (pc->green_bpaths->data) - sp_canvas_item_destroy(SP_CANVAS_ITEM(pc->green_bpaths->data)); - pc->green_bpaths = g_slist_remove(pc->green_bpaths, pc->green_bpaths->data); + if (this->green_bpaths) { + if (this->green_bpaths->data) + sp_canvas_item_destroy(SP_CANVAS_ITEM(this->green_bpaths->data)); + this->green_bpaths = g_slist_remove(this->green_bpaths, this->green_bpaths->data); } // Get last segment - if ( pc->green_curve->is_empty() ) { + if ( this->green_curve->is_empty() ) { g_warning("pen_handle_key_press, case GDK_KP_Delete: Green curve is empty"); break; } // The code below assumes that pc->green_curve has only ONE path ! - Geom::Curve const * crv = pc->green_curve->last_segment(); - pc->p[0] = crv->initialPoint(); + Geom::Curve const * crv = this->green_curve->last_segment(); + this->p[0] = crv->initialPoint(); if ( Geom::CubicBezier const * cubic = dynamic_cast(crv)) { - pc->p[1] = (*cubic)[1]; + this->p[1] = (*cubic)[1]; } else { - pc->p[1] = pc->p[0]; + this->p[1] = this->p[0]; } - Geom::Point const pt(( pc->npoints < 4 + Geom::Point const pt(( this->npoints < 4 ? (Geom::Point)(crv->finalPoint()) - : pc->p[3] )); - pc->npoints = 2; - pc->green_curve->backspace(); - sp_canvas_item_hide(pc->c0); - sp_canvas_item_hide(pc->c1); - sp_canvas_item_hide(pc->cl0); - sp_canvas_item_hide(pc->cl1); - pc->state = PenTool::POINT; - spdc_pen_set_subsequent_point(pc, pt, true); + : this->p[3] )); + this->npoints = 2; + this->green_curve->backspace(); + sp_canvas_item_hide(this->c0); + sp_canvas_item_hide(this->c1); + sp_canvas_item_hide(this->cl0); + sp_canvas_item_hide(this->cl1); + this->state = PenTool::POINT; + this->_setSubsequentPoint(pt, true); pen_last_paraxial_dir = !pen_last_paraxial_dir; ret = TRUE; } @@ -1104,40 +1076,38 @@ static gint pen_handle_key_press(PenTool *const pc, GdkEvent *event) return ret; } -static void spdc_reset_colors(PenTool *pc) -{ +void PenTool::_resetColors() { // Red - pc->red_curve->reset(); - sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(pc->red_bpath), NULL); + this->red_curve->reset(); + sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), NULL); // Blue - pc->blue_curve->reset(); - sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(pc->blue_bpath), NULL); + this->blue_curve->reset(); + sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->blue_bpath), NULL); // Green - while (pc->green_bpaths) { - sp_canvas_item_destroy(SP_CANVAS_ITEM(pc->green_bpaths->data)); - pc->green_bpaths = g_slist_remove(pc->green_bpaths, pc->green_bpaths->data); + while (this->green_bpaths) { + sp_canvas_item_destroy(SP_CANVAS_ITEM(this->green_bpaths->data)); + this->green_bpaths = g_slist_remove(this->green_bpaths, this->green_bpaths->data); } - pc->green_curve->reset(); - if (pc->green_anchor) { - pc->green_anchor = sp_draw_anchor_destroy(pc->green_anchor); + this->green_curve->reset(); + if (this->green_anchor) { + this->green_anchor = sp_draw_anchor_destroy(this->green_anchor); } - pc->sa = NULL; - pc->ea = NULL; - pc->npoints = 0; - pc->red_curve_is_valid = false; + this->sa = NULL; + this->ea = NULL; + this->npoints = 0; + this->red_curve_is_valid = false; } -static void spdc_pen_set_initial_point(PenTool *const pc, Geom::Point const p) -{ - g_assert( pc->npoints == 0 ); +void PenTool::_setInitialPoint(Geom::Point const p) { + g_assert( this->npoints == 0 ); - pc->p[0] = p; - pc->p[1] = p; - pc->npoints = 2; - sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(pc->red_bpath), NULL); + this->p[0] = p; + this->p[1] = p; + this->npoints = 2; + sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), NULL); - pc->desktop->canvas->forceFullRedrawAfterInterruptions(5); + this->desktop->canvas->forceFullRedrawAfterInterruptions(5); } /** @@ -1145,14 +1115,13 @@ static void spdc_pen_set_initial_point(PenTool *const pc, Geom::Point const p) * This type of message always shows angle/distance as the last * two parameters ("angle %3.2f°, distance %s"). */ -static void spdc_pen_set_angle_distance_status_message(PenTool *const pc, Geom::Point const p, int pc_point_to_compare, gchar const *message) -{ - g_assert(pc != NULL); +void PenTool::_setAngleDistanceStatusMessage(Geom::Point const p, int pc_point_to_compare, gchar const *message) { + g_assert(this != NULL); g_assert((pc_point_to_compare == 0) || (pc_point_to_compare == 3)); // exclude control handles g_assert(message != NULL); - SPDesktop *desktop = SP_EVENT_CONTEXT(pc)->desktop; - Geom::Point rel = p - pc->p[pc_point_to_compare]; + SPDesktop *desktop = SP_EVENT_CONTEXT(this)->desktop; + Geom::Point rel = p - this->p[pc_point_to_compare]; Inkscape::Util::Quantity q = Inkscape::Util::Quantity(Geom::L2(rel), "px"); GString *dist = g_string_new(q.string(desktop->namedview->doc_units).c_str()); double angle = atan2(rel[Geom::Y], rel[Geom::X]) * 180 / M_PI; @@ -1164,192 +1133,178 @@ static void spdc_pen_set_angle_distance_status_message(PenTool *const pc, Geom:: } } - pc->message_context->setF(Inkscape::IMMEDIATE_MESSAGE, message, angle, dist->str); + this->message_context->setF(Inkscape::IMMEDIATE_MESSAGE, message, angle, dist->str); g_string_free(dist, FALSE); } -static void spdc_pen_set_subsequent_point(PenTool *const pc, Geom::Point const p, bool statusbar, guint status) -{ - g_assert( pc->npoints != 0 ); +void PenTool::_setSubsequentPoint(Geom::Point const p, bool statusbar, guint status) { + g_assert( this->npoints != 0 ); // todo: Check callers to see whether 2 <= npoints is guaranteed. - pc->p[2] = p; - pc->p[3] = p; - pc->p[4] = p; - pc->npoints = 5; - pc->red_curve->reset(); + this->p[2] = p; + this->p[3] = p; + this->p[4] = p; + this->npoints = 5; + this->red_curve->reset(); bool is_curve; - pc->red_curve->moveto(pc->p[0]); - if (pc->polylines_paraxial && !statusbar) { + this->red_curve->moveto(this->p[0]); + if (this->polylines_paraxial && !statusbar) { // we are drawing horizontal/vertical lines and hit an anchor; - Geom::Point const origin = pc->p[0]; + Geom::Point const origin = this->p[0]; // if the previous point and the anchor are not aligned either horizontally or vertically... if ((abs(p[Geom::X] - origin[Geom::X]) > 1e-9) && (abs(p[Geom::Y] - origin[Geom::Y]) > 1e-9)) { // ...then we should draw an L-shaped path, consisting of two paraxial segments Geom::Point intermed = p; - pen_set_to_nearest_horiz_vert(pc, intermed, status, false); - pc->red_curve->lineto(intermed); + this->_setToNearestHorizVert(intermed, status, false); + this->red_curve->lineto(intermed); } - pc->red_curve->lineto(p); + this->red_curve->lineto(p); is_curve = false; } else { // one of the 'regular' modes - if (pc->p[1] != pc->p[0]) { - pc->red_curve->curveto(pc->p[1], p, p); + if (this->p[1] != this->p[0]) { + this->red_curve->curveto(this->p[1], p, p); is_curve = true; } else { - pc->red_curve->lineto(p); + this->red_curve->lineto(p); is_curve = false; } } - sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(pc->red_bpath), pc->red_curve); + sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), this->red_curve); if (statusbar) { gchar *message = is_curve ? _("Curve segment: angle %3.2f°, distance %s; with Ctrl to snap angle, Enter to finish the path" ): _("Line segment: angle %3.2f°, distance %s; with Ctrl to snap angle, Enter to finish the path"); - spdc_pen_set_angle_distance_status_message(pc, p, 0, message); + this->_setAngleDistanceStatusMessage(p, 0, message); } } -static void spdc_pen_set_ctrl(PenTool *const pc, Geom::Point const p, guint const state) -{ - sp_canvas_item_show(pc->c1); - sp_canvas_item_show(pc->cl1); - - if ( pc->npoints == 2 ) { - pc->p[1] = p; - sp_canvas_item_hide(pc->c0); - sp_canvas_item_hide(pc->cl0); - SP_CTRL(pc->c1)->moveto(pc->p[1]); - pc->cl1->setCoords(pc->p[0], pc->p[1]); - - spdc_pen_set_angle_distance_status_message(pc, p, 0, _("Curve handle: angle %3.2f°, length %s; with Ctrl to snap angle")); - } else if ( pc->npoints == 5 ) { - pc->p[4] = p; - sp_canvas_item_show(pc->c0); - sp_canvas_item_show(pc->cl0); +void PenTool::_setCtrl(Geom::Point const p, guint const state) { + sp_canvas_item_show(this->c1); + sp_canvas_item_show(this->cl1); + + if ( this->npoints == 2 ) { + this->p[1] = p; + sp_canvas_item_hide(this->c0); + sp_canvas_item_hide(this->cl0); + SP_CTRL(this->c1)->moveto(this->p[1]); + this->cl1->setCoords(this->p[0], this->p[1]); + + this->_setAngleDistanceStatusMessage(p, 0, _("Curve handle: angle %3.2f°, length %s; with Ctrl to snap angle")); + } else if ( this->npoints == 5 ) { + this->p[4] = p; + sp_canvas_item_show(this->c0); + sp_canvas_item_show(this->cl0); bool is_symm = false; - if ( ( ( pc->mode == PenTool::MODE_CLICK ) && ( state & GDK_CONTROL_MASK ) ) || - ( ( pc->mode == PenTool::MODE_DRAG ) && !( state & GDK_SHIFT_MASK ) ) ) { - Geom::Point delta = p - pc->p[3]; - pc->p[2] = pc->p[3] - delta; + if ( ( ( this->mode == PenTool::MODE_CLICK ) && ( state & GDK_CONTROL_MASK ) ) || + ( ( this->mode == PenTool::MODE_DRAG ) && !( state & GDK_SHIFT_MASK ) ) ) { + Geom::Point delta = p - this->p[3]; + this->p[2] = this->p[3] - delta; is_symm = true; - pc->red_curve->reset(); - pc->red_curve->moveto(pc->p[0]); - pc->red_curve->curveto(pc->p[1], pc->p[2], pc->p[3]); - sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(pc->red_bpath), pc->red_curve); + this->red_curve->reset(); + this->red_curve->moveto(this->p[0]); + this->red_curve->curveto(this->p[1], this->p[2], this->p[3]); + sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), this->red_curve); } - SP_CTRL(pc->c0)->moveto(pc->p[2]); - pc->cl0 ->setCoords(pc->p[3], pc->p[2]); - SP_CTRL(pc->c1)->moveto(pc->p[4]); - pc->cl1->setCoords(pc->p[3], pc->p[4]); + SP_CTRL(this->c0)->moveto(this->p[2]); + this->cl0 ->setCoords(this->p[3], this->p[2]); + SP_CTRL(this->c1)->moveto(this->p[4]); + this->cl1->setCoords(this->p[3], this->p[4]); gchar *message = is_symm ? _("Curve handle, symmetric: angle %3.2f°, length %s; with Ctrl to snap angle, with Shift to move this handle only") : _("Curve handle: angle %3.2f°, length %s; with Ctrl to snap angle, with Shift to move this handle only"); - spdc_pen_set_angle_distance_status_message(pc, p, 3, message); + this->_setAngleDistanceStatusMessage(p, 3, message); } else { - g_warning("Something bad happened - npoints is %d", pc->npoints); + g_warning("Something bad happened - npoints is %d", this->npoints); } } -static void spdc_pen_finish_segment(PenTool *const pc, Geom::Point const p, guint const state) -{ - if (pc->polylines_paraxial) { - pen_last_paraxial_dir = pen_next_paraxial_direction(pc, p, pc->p[0], state); +void PenTool::_finishSegment(Geom::Point const p, guint const state) { + if (this->polylines_paraxial) { + pen_last_paraxial_dir = this->nextParaxialDirection(p, this->p[0], state); } - ++pc->num_clicks; + ++this->num_clicks; - if (!pc->red_curve->is_empty()) { - pc->green_curve->append_continuous(pc->red_curve, 0.0625); - SPCurve *curve = pc->red_curve->copy(); + if (!this->red_curve->is_empty()) { + this->green_curve->append_continuous(this->red_curve, 0.0625); + SPCurve *curve = this->red_curve->copy(); /// \todo fixme: - SPCanvasItem *cshape = sp_canvas_bpath_new(sp_desktop_sketch(pc->desktop), curve); + SPCanvasItem *cshape = sp_canvas_bpath_new(sp_desktop_sketch(this->desktop), curve); curve->unref(); - sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(cshape), pc->green_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); + sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(cshape), this->green_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); - pc->green_bpaths = g_slist_prepend(pc->green_bpaths, cshape); + this->green_bpaths = g_slist_prepend(this->green_bpaths, cshape); - pc->p[0] = pc->p[3]; - pc->p[1] = pc->p[4]; - pc->npoints = 2; + this->p[0] = this->p[3]; + this->p[1] = this->p[4]; + this->npoints = 2; - pc->red_curve->reset(); + this->red_curve->reset(); } } -static void spdc_pen_finish(PenTool *const pc, gboolean const closed) -{ - if (pc->expecting_clicks_for_LPE > 1) { +void PenTool::_finish(gboolean const closed) { + if (this->expecting_clicks_for_LPE > 1) { // don't let the path be finished before we have collected the required number of mouse clicks return; } - pc->num_clicks = 0; + this->num_clicks = 0; - pen_disable_events(pc); + this->_disableEvents(); - SPDesktop *const desktop = pc->desktop; - pc->message_context->clear(); + SPDesktop *const desktop = this->desktop; + this->message_context->clear(); desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Drawing finished")); - pc->red_curve->reset(); - spdc_concat_colors_and_flush(pc, closed); - pc->sa = NULL; - pc->ea = NULL; + this->red_curve->reset(); + spdc_concat_colors_and_flush(this, closed); + this->sa = NULL; + this->ea = NULL; - pc->npoints = 0; - pc->state = PenTool::POINT; + this->npoints = 0; + this->state = PenTool::POINT; - sp_canvas_item_hide(pc->c0); - sp_canvas_item_hide(pc->c1); - sp_canvas_item_hide(pc->cl0); - sp_canvas_item_hide(pc->cl1); + sp_canvas_item_hide(this->c0); + sp_canvas_item_hide(this->c1); + sp_canvas_item_hide(this->cl0); + sp_canvas_item_hide(this->cl1); - if (pc->green_anchor) { - pc->green_anchor = sp_draw_anchor_destroy(pc->green_anchor); + if (this->green_anchor) { + this->green_anchor = sp_draw_anchor_destroy(this->green_anchor); } - pc->desktop->canvas->endForcedFullRedraws(); + this->desktop->canvas->endForcedFullRedraws(); - pen_enable_events(pc); + this->_enableEvents(); } -static void pen_disable_events(PenTool *const pc) { - pc->events_disabled = true; +void PenTool::_disableEvents() { + this->events_disabled = true; } -static void pen_enable_events(PenTool *const pc) { - g_return_if_fail(pc->events_disabled != 0); +void PenTool::_enableEvents() { + g_return_if_fail(this->events_disabled != 0); - pc->events_disabled = false; + this->events_disabled = false; } -void sp_pen_context_wait_for_LPE_mouse_clicks(PenTool *pc, Inkscape::LivePathEffect::EffectType effect_type, - unsigned int num_clicks, bool use_polylines) -{ +void PenTool::waitForLPEMouseClicks(Inkscape::LivePathEffect::EffectType effect_type, unsigned int num_clicks, bool use_polylines) { if (effect_type == Inkscape::LivePathEffect::INVALID_LPE) return; - pc->waiting_LPE_type = effect_type; - pc->expecting_clicks_for_LPE = num_clicks; - pc->polylines_only = use_polylines; - pc->polylines_paraxial = false; // TODO: think if this is correct for all cases + this->waiting_LPE_type = effect_type; + this->expecting_clicks_for_LPE = num_clicks; + this->polylines_only = use_polylines; + this->polylines_paraxial = false; // TODO: think if this is correct for all cases } -void sp_pen_context_cancel_waiting_for_LPE(PenTool *pc) -{ - pc->waiting_LPE_type = Inkscape::LivePathEffect::INVALID_LPE; - pc->expecting_clicks_for_LPE = 0; - sp_pen_context_set_polyline_mode(pc); -} - -static int pen_next_paraxial_direction(const PenTool *const pc, - Geom::Point const &pt, Geom::Point const &origin, guint state) { +int PenTool::nextParaxialDirection(Geom::Point const &pt, Geom::Point const &origin, guint state) const { // // after the first mouse click we determine whether the mouse pointer is closest to a // horizontal or vertical segment; for all subsequent mouse clicks, we use the direction @@ -1359,7 +1314,7 @@ static int pen_next_paraxial_direction(const PenTool *const pc, // (on first mouse release), in which case num_clicks immediately becomes 1. // if (pc->num_clicks == 0) { - if (pc->green_curve->is_empty()) { + if (this->green_curve->is_empty()) { // first mouse click double dist_h = fabs(pt[Geom::X] - origin[Geom::X]); double dist_v = fabs(pt[Geom::Y] - origin[Geom::Y]); @@ -1372,11 +1327,10 @@ static int pen_next_paraxial_direction(const PenTool *const pc, } } -void pen_set_to_nearest_horiz_vert(const PenTool *const pc, Geom::Point &pt, guint const state, bool snap) -{ - Geom::Point const origin = pc->p[0]; +void PenTool::_setToNearestHorizVert(Geom::Point &pt, guint const state, bool snap) const { + Geom::Point const origin = this->p[0]; - int next_dir = pen_next_paraxial_direction(pc, pt, origin, state); + int next_dir = this->nextParaxialDirection(pt, origin, state); if (!snap) { if (next_dir == 0) { @@ -1391,13 +1345,13 @@ void pen_set_to_nearest_horiz_vert(const PenTool *const pc, Geom::Point &pt, gui Inkscape::Snapper::SnapConstraint cl(origin, next_dir ? Geom::Point(0, 1) : Geom::Point(1, 0)); // Snap along the constraint line; if we didn't snap then still the constraint will be applied - SnapManager &m = pc->desktop->namedview->snap_manager; + SnapManager &m = this->desktop->namedview->snap_manager; - Inkscape::Selection *selection = sp_desktop_selection (pc->desktop); + Inkscape::Selection *selection = sp_desktop_selection (this->desktop); // selection->singleItem() is the item that is currently being drawn. This item will not be snapped to (to avoid self-snapping) // TODO: Allow snapping to the stationary parts of the item, and only ignore the last segment - m.setup(pc->desktop, true, selection->singleItem()); + m.setup(this->desktop, true, selection->singleItem()); m.constrainedSnapReturnByRef(pt, Inkscape::SNAPSOURCE_NODE_HANDLE, cl); m.unSetup(); } diff --git a/src/ui/tools/pen-tool.h b/src/ui/tools/pen-tool.h index f2b1ee04a..182d270ee 100644 --- a/src/ui/tools/pen-tool.h +++ b/src/ui/tools/pen-tool.h @@ -67,26 +67,52 @@ public: virtual const std::string& getPrefsPath(); + int nextParaxialDirection(Geom::Point const &pt, Geom::Point const &origin, guint state) const; + void setPolylineMode(); + bool hasWaitingLPE(); + void waitForLPEMouseClicks(Inkscape::LivePathEffect::EffectType effect_type, unsigned int num_clicks, bool use_polylines = true); + protected: virtual void setup(); virtual void finish(); virtual void set(const Inkscape::Preferences::Entry& val); virtual bool root_handler(GdkEvent* event); virtual bool item_handler(SPItem* item, GdkEvent* event); -}; -inline bool sp_pen_context_has_waiting_LPE(PenTool *pc) { - // note: waiting_LPE_type is defined in SPDrawContext - return (pc->waiting_LPE != NULL || - pc->waiting_LPE_type != Inkscape::LivePathEffect::INVALID_LPE); -} +private: + gint _handleButtonPress(GdkEventButton const &bevent); + gint _handleMotionNotify(GdkEventMotion const &mevent); + gint _handleButtonRelease(GdkEventButton const &revent); + gint _handle2ButtonPress(GdkEventButton const &bevent); + gint _handleKeyPress(GdkEvent *event); + + void _setInitialPoint(Geom::Point const p); + void _setSubsequentPoint(Geom::Point const p, bool statusbar, guint status = 0); + void _setCtrl(Geom::Point const p, guint state); + void _finishSegment(Geom::Point p, guint state); + + void _finish(gboolean closed); + + void _resetColors(); -void sp_pen_context_set_polyline_mode(PenTool *const pc); -void sp_pen_context_wait_for_LPE_mouse_clicks(PenTool *pc, Inkscape::LivePathEffect::EffectType effect_type, - unsigned int num_clicks, bool use_polylines = true); -void sp_pen_context_cancel_waiting_for_LPE(PenTool *pc); -void sp_pen_context_put_into_waiting_mode(SPDesktop *desktop, Inkscape::LivePathEffect::EffectType effect_type, - unsigned int num_clicks, bool use_polylines = true); + void _disableEvents(); + void _enableEvents(); + + void _setToNearestHorizVert(Geom::Point &pt, guint const state, bool snap) const; + + void _setAngleDistanceStatusMessage(Geom::Point const p, int pc_point_to_compare, gchar const *message); + + void _lastpointToLine(); + void _lastpointToCurve(); + void _lastpointMoveScreen(gdouble x, gdouble y); + void _lastpointMove(gdouble x, gdouble y); + void _redrawAll(); + + void _endpointSnapHandle(Geom::Point &p, guint const state) const; + void _endpointSnap(Geom::Point &p, guint const state) const; + + void _cancel(); +}; } } diff --git a/src/ui/tools/pencil-tool.cpp b/src/ui/tools/pencil-tool.cpp index 4fbaa50f3..230ec62af 100644 --- a/src/ui/tools/pencil-tool.cpp +++ b/src/ui/tools/pencil-tool.cpp @@ -50,20 +50,6 @@ namespace Inkscape { namespace UI { namespace Tools { -static gint pencil_handle_button_press(PencilTool *const pc, GdkEventButton const &bevent); -static gint pencil_handle_motion_notify(PencilTool *const pc, GdkEventMotion const &mevent); -static gint pencil_handle_button_release(PencilTool *const pc, GdkEventButton const &revent); -static gint pencil_handle_key_press(PencilTool *const pc, guint const keyval, guint const state); -static gint pencil_handle_key_release(PencilTool *const pc, guint const keyval, guint const state); - -static void spdc_set_startpoint(PencilTool *pc, Geom::Point const &p); -static void spdc_set_endpoint(PencilTool *pc, Geom::Point const &p); -static void spdc_finish_endpoint(PencilTool *pc); -static void spdc_add_freehand_point(PencilTool *pc, Geom::Point const &p, guint state); -static void fit_and_split(PencilTool *pc); -static void interpolate(PencilTool *pc); -static void sketch_interpolate(PencilTool *pc); - static Geom::Point pencil_drag_origin_w(0, 0); static bool pencil_within_tolerance = false; @@ -110,19 +96,17 @@ PencilTool::~PencilTool() { } /** Snaps new node relative to the previous node. */ -static void -spdc_endpoint_snap(PencilTool const *pc, Geom::Point &p, guint const state) -{ +void PencilTool::_endpointSnap(Geom::Point &p, guint const state) { if ((state & GDK_CONTROL_MASK)) { //CTRL enables constrained snapping - if (pc->npoints > 0) { - spdc_endpoint_snap_rotation(pc, p, pc->p[0], state); + if (this->npoints > 0) { + spdc_endpoint_snap_rotation(this, p, this->p[0], state); } } else { if (!(state & GDK_SHIFT_MASK)) { //SHIFT disables all snapping, except the angular snapping above //After all, the user explicitely asked for angular snapping by //pressing CTRL - boost::optional origin = pc->npoints > 0 ? pc->p[0] : boost::optional(); - spdc_endpoint_snap_free(pc, p, origin, state); + boost::optional origin = this->npoints > 0 ? this->p[0] : boost::optional(); + spdc_endpoint_snap_free(this, p, origin, state); } } } @@ -135,23 +119,23 @@ bool PencilTool::root_handler(GdkEvent* event) { switch (event->type) { case GDK_BUTTON_PRESS: - ret = pencil_handle_button_press(this, event->button); + ret = this->_handleButtonPress(event->button); break; case GDK_MOTION_NOTIFY: - ret = pencil_handle_motion_notify(this, event->motion); + ret = this->_handleMotionNotify(event->motion); break; case GDK_BUTTON_RELEASE: - ret = pencil_handle_button_release(this, event->button); + ret = this->_handleButtonRelease(event->button); break; case GDK_KEY_PRESS: - ret = pencil_handle_key_press(this, get_group0_keyval (&event->key), event->key.state); + ret = this->_handleKeyPress(get_group0_keyval (&event->key), event->key.state); break; case GDK_KEY_RELEASE: - ret = pencil_handle_key_release(this, get_group0_keyval (&event->key), event->key.state); + ret = this->_handleKeyRelease(get_group0_keyval (&event->key), event->key.state); break; default: @@ -165,14 +149,12 @@ bool PencilTool::root_handler(GdkEvent* event) { return ret; } -static gint -pencil_handle_button_press(PencilTool *const pc, GdkEventButton const &bevent) -{ +gint PencilTool::_handleButtonPress(GdkEventButton const &bevent) { gint ret = FALSE; - ToolBase *event_context = SP_EVENT_CONTEXT(pc); + ToolBase *event_context = SP_EVENT_CONTEXT(this); if ( bevent.button == 1 && !event_context->space_panning) { - FreehandBase *dc = SP_DRAW_CONTEXT (pc); + FreehandBase *dc = SP_DRAW_CONTEXT (this); SPDesktop *desktop = dc->desktop; Inkscape::Selection *selection = sp_desktop_selection(desktop); @@ -180,10 +162,10 @@ pencil_handle_button_press(PencilTool *const pc, GdkEventButton const &bevent) return TRUE; } - if (!pc->grab) { + if (!this->grab) { /* Grab mouse, so release will not pass unnoticed */ - pc->grab = SP_CANVAS_ITEM(desktop->acetate); - sp_canvas_item_grab(pc->grab, ( GDK_KEY_PRESS_MASK | GDK_BUTTON_PRESS_MASK | + this->grab = SP_CANVAS_ITEM(desktop->acetate); + sp_canvas_item_grab(this->grab, ( GDK_KEY_PRESS_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK ), NULL, bevent.time); @@ -192,15 +174,15 @@ pencil_handle_button_press(PencilTool *const pc, GdkEventButton const &bevent) Geom::Point const button_w(bevent.x, bevent.y); /* Find desktop coordinates */ - Geom::Point p = pc->desktop->w2d(button_w); + Geom::Point p = this->desktop->w2d(button_w); /* Test whether we hit any anchor. */ - SPDrawAnchor *anchor = spdc_test_inside(pc, button_w); + SPDrawAnchor *anchor = spdc_test_inside(this, button_w); pencil_drag_origin_w = Geom::Point(bevent.x,bevent.y); pencil_within_tolerance = true; - switch (pc->state) { + switch (this->state) { case SP_PENCIL_CONTEXT_ADDLINE: /* Current segment will be finished with release */ ret = TRUE; @@ -237,40 +219,38 @@ pencil_handle_button_press(PencilTool *const pc, GdkEventButton const &bevent) } m.unSetup(); } - pc->sa = anchor; - spdc_set_startpoint(pc, p); + this->sa = anchor; + this->_setStartpoint(p); ret = TRUE; break; } - pc->is_drawing = true; + this->is_drawing = true; } return ret; } -static gint -pencil_handle_motion_notify(PencilTool *const pc, GdkEventMotion const &mevent) -{ - SPDesktop *const dt = pc->desktop; +gint PencilTool::_handleMotionNotify(GdkEventMotion const &mevent) { + SPDesktop *const dt = this->desktop; if ((mevent.state & GDK_CONTROL_MASK) && (mevent.state & GDK_BUTTON1_MASK)) { // mouse was accidentally moved during Ctrl+click; // ignore the motion and create a single point - pc->is_drawing = false; + this->is_drawing = false; return TRUE; } gint ret = FALSE; - ToolBase *event_context = SP_EVENT_CONTEXT(pc); + ToolBase *event_context = SP_EVENT_CONTEXT(this); if (event_context->space_panning || mevent.state & GDK_BUTTON2_MASK || mevent.state & GDK_BUTTON3_MASK) { // allow scrolling return FALSE; } - if ( ( mevent.state & GDK_BUTTON1_MASK ) && !pc->grab && pc->is_drawing) { + if ( ( mevent.state & GDK_BUTTON1_MASK ) && !this->grab && this->is_drawing) { /* Grab mouse, so release will not pass unnoticed */ - pc->grab = SP_CANVAS_ITEM(dt->acetate); - sp_canvas_item_grab(pc->grab, ( GDK_KEY_PRESS_MASK | GDK_BUTTON_PRESS_MASK | + this->grab = SP_CANVAS_ITEM(dt->acetate); + sp_canvas_item_grab(this->grab, ( GDK_KEY_PRESS_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK ), NULL, mevent.time); @@ -280,7 +260,7 @@ pencil_handle_motion_notify(PencilTool *const pc, GdkEventMotion const &mevent) Geom::Point p = dt->w2d(Geom::Point(mevent.x, mevent.y)); /* Test whether we hit any anchor. */ - SPDrawAnchor *anchor = spdc_test_inside(pc, Geom::Point(mevent.x, mevent.y)); + SPDrawAnchor *anchor = spdc_test_inside(this, Geom::Point(mevent.x, mevent.y)); if (pencil_within_tolerance) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -295,71 +275,71 @@ pencil_handle_motion_notify(PencilTool *const pc, GdkEventMotion const &mevent) // motion notify coordinates as given (no snapping back to origin) pencil_within_tolerance = false; - switch (pc->state) { + switch (this->state) { case SP_PENCIL_CONTEXT_ADDLINE: /* Set red endpoint */ if (anchor) { p = anchor->dp; } else { Geom::Point ptnr(p); - spdc_endpoint_snap(pc, ptnr, mevent.state); + this->_endpointSnap(ptnr, mevent.state); p = ptnr; } - spdc_set_endpoint(pc, p); + this->_setEndpoint(p); ret = TRUE; break; default: /* We may be idle or already freehand */ - if ( mevent.state & GDK_BUTTON1_MASK && pc->is_drawing ) { - if (pc->state == SP_PENCIL_CONTEXT_IDLE) { + if ( mevent.state & GDK_BUTTON1_MASK && this->is_drawing ) { + if (this->state == SP_PENCIL_CONTEXT_IDLE) { sp_event_context_discard_delayed_snap_event(event_context); } - pc->state = SP_PENCIL_CONTEXT_FREEHAND; + this->state = SP_PENCIL_CONTEXT_FREEHAND; - if ( !pc->sa && !pc->green_anchor ) { + if ( !this->sa && !this->green_anchor ) { /* Create green anchor */ - pc->green_anchor = sp_draw_anchor_new(pc, pc->green_curve, TRUE, pc->p[0]); + this->green_anchor = sp_draw_anchor_new(this, this->green_curve, TRUE, this->p[0]); } if (anchor) { p = anchor->dp; } - if ( pc->npoints != 0) { // buttonpress may have happened before we entered draw context! - if (pc->ps.empty()) { + if ( this->npoints != 0) { // buttonpress may have happened before we entered draw context! + if (this->ps.empty()) { // Only in freehand mode we have to add the first point also to pc->ps (apparently) // - We cannot add this point in spdc_set_startpoint, because we only need it for freehand // - We cannot do this in the button press handler because at that point we don't know yet // wheter we're going into freehand mode or not - pc->ps.push_back(pc->p[0]); + this->ps.push_back(this->p[0]); } - spdc_add_freehand_point(pc, p, mevent.state); + this->_addFreehandPoint(p, mevent.state); ret = TRUE; } - if (anchor && !pc->anchor_statusbar) { - pc->message_context->set(Inkscape::NORMAL_MESSAGE, _("Release here to close and finish the path.")); - pc->anchor_statusbar = true; - } else if (!anchor && pc->anchor_statusbar) { - pc->message_context->clear(); - pc->anchor_statusbar = false; + if (anchor && !this->anchor_statusbar) { + this->message_context->set(Inkscape::NORMAL_MESSAGE, _("Release here to close and finish the path.")); + this->anchor_statusbar = true; + } else if (!anchor && this->anchor_statusbar) { + this->message_context->clear(); + this->anchor_statusbar = false; } else if (!anchor) { - pc->message_context->set(Inkscape::NORMAL_MESSAGE, _("Drawing a freehand path")); + this->message_context->set(Inkscape::NORMAL_MESSAGE, _("Drawing a freehand path")); } } else { - if (anchor && !pc->anchor_statusbar) { - pc->message_context->set(Inkscape::NORMAL_MESSAGE, _("Drag to continue the path from this point.")); - pc->anchor_statusbar = true; - } else if (!anchor && pc->anchor_statusbar) { - pc->message_context->clear(); - pc->anchor_statusbar = false; + if (anchor && !this->anchor_statusbar) { + this->message_context->set(Inkscape::NORMAL_MESSAGE, _("Drag to continue the path from this point.")); + this->anchor_statusbar = true; + } else if (!anchor && this->anchor_statusbar) { + this->message_context->clear(); + this->anchor_statusbar = false; } } // Show the pre-snap indicator to communicate to the user where we would snap to if he/she were to // a) press the mousebutton to start a freehand drawing, or // b) release the mousebutton to finish a freehand drawing - if (!sp_event_context_knot_mouseover(pc)) { + if (!this->sp_event_context_knot_mouseover()) { SnapManager &m = dt->namedview->snap_manager; m.setup(dt); m.preSnap(Inkscape::SnapCandidatePoint(p, Inkscape::SNAPSOURCE_NODE_HANDLE)); @@ -370,31 +350,29 @@ pencil_handle_motion_notify(PencilTool *const pc, GdkEventMotion const &mevent) return ret; } -static gint -pencil_handle_button_release(PencilTool *const pc, GdkEventButton const &revent) -{ +gint PencilTool::_handleButtonRelease(GdkEventButton const &revent) { gint ret = FALSE; - ToolBase *event_context = SP_EVENT_CONTEXT(pc); - if ( revent.button == 1 && pc->is_drawing && !event_context->space_panning) { - SPDesktop *const dt = pc->desktop; + ToolBase *event_context = SP_EVENT_CONTEXT(this); + if ( revent.button == 1 && this->is_drawing && !event_context->space_panning) { + SPDesktop *const dt = this->desktop; - pc->is_drawing = false; + this->is_drawing = false; /* Find desktop coordinates */ Geom::Point p = dt->w2d(Geom::Point(revent.x, revent.y)); /* Test whether we hit any anchor. */ - SPDrawAnchor *anchor = spdc_test_inside(pc, Geom::Point(revent.x, + SPDrawAnchor *anchor = spdc_test_inside(this, Geom::Point(revent.x, revent.y)); - switch (pc->state) { + switch (this->state) { case SP_PENCIL_CONTEXT_IDLE: /* Releasing button in idle mode means single click */ /* We have already set up start point/anchor in button_press */ if (!(revent.state & GDK_CONTROL_MASK)) { // Ctrl+click creates a single point so only set context in ADDLINE mode when Ctrl isn't pressed - pc->state = SP_PENCIL_CONTEXT_ADDLINE; + this->state = SP_PENCIL_CONTEXT_ADDLINE; } ret = TRUE; break; @@ -403,12 +381,12 @@ pencil_handle_button_release(PencilTool *const pc, GdkEventButton const &revent) if (anchor) { p = anchor->dp; } else { - spdc_endpoint_snap(pc, p, revent.state); + this->_endpointSnap(p, revent.state); } - pc->ea = anchor; - spdc_set_endpoint(pc, p); - spdc_finish_endpoint(pc); - pc->state = SP_PENCIL_CONTEXT_IDLE; + this->ea = anchor; + this->_setEndpoint(p); + this->_finishEndpoint(); + this->state = SP_PENCIL_CONTEXT_IDLE; sp_event_context_discard_delayed_snap_event(event_context); ret = TRUE; break; @@ -416,13 +394,13 @@ pencil_handle_button_release(PencilTool *const pc, GdkEventButton const &revent) if (revent.state & GDK_MOD1_MASK) { /* sketch mode: interpolate the sketched path and improve the current output path with the new interpolation. don't finish sketch */ - sketch_interpolate(pc); + this->_sketchInterpolate(); - if (pc->green_anchor) { - pc->green_anchor = sp_draw_anchor_destroy(pc->green_anchor); + if (this->green_anchor) { + this->green_anchor = sp_draw_anchor_destroy(this->green_anchor); } - pc->state = SP_PENCIL_CONTEXT_SKETCH; + this->state = SP_PENCIL_CONTEXT_SKETCH; } else { /* Finish segment now */ /// \todo fixme: Clean up what follows (Lauris) @@ -430,28 +408,28 @@ pencil_handle_button_release(PencilTool *const pc, GdkEventButton const &revent) p = anchor->dp; } else { Geom::Point p_end = p; - spdc_endpoint_snap(pc, p_end, revent.state); + this->_endpointSnap(p_end, revent.state); if (p_end != p) { // then we must have snapped! - spdc_add_freehand_point(pc, p_end, revent.state); + this->_addFreehandPoint(p_end, revent.state); } } - pc->ea = anchor; + this->ea = anchor; /* Write curves to object */ dt->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Finishing freehand")); - interpolate(pc); - spdc_concat_colors_and_flush(pc, FALSE); - pc->sa = NULL; - pc->ea = NULL; - if (pc->green_anchor) { - pc->green_anchor = sp_draw_anchor_destroy(pc->green_anchor); + this->_interpolate(); + spdc_concat_colors_and_flush(this, FALSE); + this->sa = NULL; + this->ea = NULL; + if (this->green_anchor) { + this->green_anchor = sp_draw_anchor_destroy(this->green_anchor); } - pc->state = SP_PENCIL_CONTEXT_IDLE; + this->state = SP_PENCIL_CONTEXT_IDLE; // reset sketch mode too - pc->sketch_n = 0; + this->sketch_n = 0; } ret = TRUE; break; @@ -460,10 +438,10 @@ pencil_handle_button_release(PencilTool *const pc, GdkEventButton const &revent) break; } - if (pc->grab) { + if (this->grab) { /* Release grab now */ - sp_canvas_item_ungrab(pc->grab, revent.time); - pc->grab = NULL; + sp_canvas_item_ungrab(this->grab, revent.time); + this->grab = NULL; } ret = TRUE; @@ -471,39 +449,35 @@ pencil_handle_button_release(PencilTool *const pc, GdkEventButton const &revent) return ret; } -static void -pencil_cancel (PencilTool *const pc) -{ - if (pc->grab) { +void PencilTool::_cancel() { + if (this->grab) { /* Release grab now */ - sp_canvas_item_ungrab(pc->grab, 0); - pc->grab = NULL; + sp_canvas_item_ungrab(this->grab, 0); + this->grab = NULL; } - pc->is_drawing = false; - pc->state = SP_PENCIL_CONTEXT_IDLE; - sp_event_context_discard_delayed_snap_event(SP_EVENT_CONTEXT(pc)); - - pc->red_curve->reset(); - sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(pc->red_bpath), NULL); - while (pc->green_bpaths) { - sp_canvas_item_destroy(SP_CANVAS_ITEM(pc->green_bpaths->data)); - pc->green_bpaths = g_slist_remove(pc->green_bpaths, pc->green_bpaths->data); + this->is_drawing = false; + this->state = SP_PENCIL_CONTEXT_IDLE; + sp_event_context_discard_delayed_snap_event(SP_EVENT_CONTEXT(this)); + + this->red_curve->reset(); + sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), NULL); + while (this->green_bpaths) { + sp_canvas_item_destroy(SP_CANVAS_ITEM(this->green_bpaths->data)); + this->green_bpaths = g_slist_remove(this->green_bpaths, this->green_bpaths->data); } - pc->green_curve->reset(); - if (pc->green_anchor) { - pc->green_anchor = sp_draw_anchor_destroy(pc->green_anchor); + this->green_curve->reset(); + if (this->green_anchor) { + this->green_anchor = sp_draw_anchor_destroy(this->green_anchor); } - pc->message_context->clear(); - pc->message_context->flash(Inkscape::NORMAL_MESSAGE, _("Drawing cancelled")); + this->message_context->clear(); + this->message_context->flash(Inkscape::NORMAL_MESSAGE, _("Drawing cancelled")); - pc->desktop->canvas->endForcedFullRedraws(); + this->desktop->canvas->endForcedFullRedraws(); } -static gint -pencil_handle_key_press(PencilTool *const pc, guint const keyval, guint const state) -{ +gint PencilTool::_handleKeyPress(guint const keyval, guint const state) { gint ret = FALSE; switch (keyval) { case GDK_KEY_Up: @@ -516,20 +490,20 @@ pencil_handle_key_press(PencilTool *const pc, guint const keyval, guint const st } break; case GDK_KEY_Escape: - if (pc->npoints != 0) { + if (this->npoints != 0) { // if drawing, cancel, otherwise pass it up for deselecting - if (pc->state != SP_PENCIL_CONTEXT_IDLE) { - pencil_cancel (pc); + if (this->state != SP_PENCIL_CONTEXT_IDLE) { + this->_cancel(); ret = TRUE; } } break; case GDK_KEY_z: case GDK_KEY_Z: - if (mod_ctrl_only(state) && pc->npoints != 0) { + if (mod_ctrl_only(state) && this->npoints != 0) { // if drawing, cancel, otherwise pass it up for undo - if (pc->state != SP_PENCIL_CONTEXT_IDLE) { - pencil_cancel (pc); + if (this->state != SP_PENCIL_CONTEXT_IDLE) { + this->_cancel(); ret = TRUE; } } @@ -537,7 +511,7 @@ pencil_handle_key_press(PencilTool *const pc, guint const keyval, guint const st case GDK_KEY_g: case GDK_KEY_G: if (mod_shift_only(state)) { - sp_selection_to_guides(SP_EVENT_CONTEXT(pc)->desktop); + sp_selection_to_guides(SP_EVENT_CONTEXT(this)->desktop); ret = true; } break; @@ -545,8 +519,8 @@ pencil_handle_key_press(PencilTool *const pc, guint const keyval, guint const st case GDK_KEY_Alt_R: case GDK_KEY_Meta_L: case GDK_KEY_Meta_R: - if (pc->state == SP_PENCIL_CONTEXT_IDLE) { - pc->desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Sketch mode: holding Alt interpolates between sketched paths. Release Alt to finalize.")); + if (this->state == SP_PENCIL_CONTEXT_IDLE) { + this->desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Sketch mode: holding Alt interpolates between sketched paths. Release Alt to finalize.")); } break; default: @@ -555,26 +529,24 @@ pencil_handle_key_press(PencilTool *const pc, guint const keyval, guint const st return ret; } -static gint -pencil_handle_key_release(PencilTool *const pc, guint const keyval, guint const /*state*/) -{ +gint PencilTool::_handleKeyRelease(guint const keyval, guint const /*state*/) { gint ret = FALSE; switch (keyval) { case GDK_KEY_Alt_L: case GDK_KEY_Alt_R: case GDK_KEY_Meta_L: case GDK_KEY_Meta_R: - if (pc->state == SP_PENCIL_CONTEXT_SKETCH) { - spdc_concat_colors_and_flush(pc, FALSE); - pc->sketch_n = 0; - pc->sa = NULL; - pc->ea = NULL; - if (pc->green_anchor) { - pc->green_anchor = sp_draw_anchor_destroy(pc->green_anchor); + if (this->state == SP_PENCIL_CONTEXT_SKETCH) { + spdc_concat_colors_and_flush(this, FALSE); + this->sketch_n = 0; + this->sa = NULL; + this->ea = NULL; + if (this->green_anchor) { + this->green_anchor = sp_draw_anchor_destroy(this->green_anchor); } - pc->state = SP_PENCIL_CONTEXT_IDLE; - sp_event_context_discard_delayed_snap_event(SP_EVENT_CONTEXT(pc)); - pc->desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Finishing freehand sketch")); + this->state = SP_PENCIL_CONTEXT_IDLE; + sp_event_context_discard_delayed_snap_event(SP_EVENT_CONTEXT(this)); + this->desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Finishing freehand sketch")); ret = TRUE; } break; @@ -587,13 +559,11 @@ pencil_handle_key_release(PencilTool *const pc, guint const keyval, guint const /** * Reset points and set new starting point. */ -static void -spdc_set_startpoint(PencilTool *const pc, Geom::Point const &p) -{ - pc->npoints = 0; - pc->red_curve_is_valid = false; +void PencilTool::_setStartpoint(Geom::Point const &p) { + this->npoints = 0; + this->red_curve_is_valid = false; if (in_svg_plane(p)) { - pc->p[pc->npoints++] = p; + this->p[this->npoints++] = p; } } @@ -607,31 +577,29 @@ spdc_set_startpoint(PencilTool *const pc, Geom::Point const &p) * Number of points is (re)set to 2 always, 2nd point is modified. * We change RED curve. */ -static void -spdc_set_endpoint(PencilTool *const pc, Geom::Point const &p) -{ - if (pc->npoints == 0) { +void PencilTool::_setEndpoint(Geom::Point const &p) { + if (this->npoints == 0) { return; /* May occur if first point wasn't in SVG plane (e.g. weird w2d transform, perhaps from bad * zoom setting). */ } - g_return_if_fail( pc->npoints > 0 ); + g_return_if_fail( this->npoints > 0 ); - pc->red_curve->reset(); - if ( ( p == pc->p[0] ) + this->red_curve->reset(); + if ( ( p == this->p[0] ) || !in_svg_plane(p) ) { - pc->npoints = 1; + this->npoints = 1; } else { - pc->p[1] = p; - pc->npoints = 2; + this->p[1] = p; + this->npoints = 2; - pc->red_curve->moveto(pc->p[0]); - pc->red_curve->lineto(pc->p[1]); - pc->red_curve_is_valid = true; + this->red_curve->moveto(this->p[0]); + this->red_curve->lineto(this->p[1]); + this->red_curve_is_valid = true; - sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(pc->red_bpath), pc->red_curve); + sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), this->red_curve); } } @@ -642,35 +610,30 @@ spdc_set_endpoint(PencilTool *const pc, Geom::Point const &p) * fixme: I'd like remove red reset from concat colors (lauris). * Still not sure, how it will make most sense. */ -static void -spdc_finish_endpoint(PencilTool *const pc) -{ - if ( ( pc->red_curve->is_empty() ) - || ( *(pc->red_curve->first_point()) == *(pc->red_curve->second_point()) ) ) +void PencilTool::_finishEndpoint() { + if ( ( this->red_curve->is_empty() ) + || ( *(this->red_curve->first_point()) == *(this->red_curve->second_point()) ) ) { - pc->red_curve->reset(); - sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(pc->red_bpath), NULL); + this->red_curve->reset(); + sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), NULL); } else { /* Write curves to object. */ - spdc_concat_colors_and_flush(pc, FALSE); - pc->sa = NULL; - pc->ea = NULL; + spdc_concat_colors_and_flush(this, FALSE); + this->sa = NULL; + this->ea = NULL; } } +void PencilTool::_addFreehandPoint(Geom::Point const &p, guint /*state*/) { + g_assert( this->npoints > 0 ); + g_return_if_fail(unsigned(this->npoints) < G_N_ELEMENTS(this->p)); -static void -spdc_add_freehand_point(PencilTool *pc, Geom::Point const &p, guint /*state*/) -{ - g_assert( pc->npoints > 0 ); - g_return_if_fail(unsigned(pc->npoints) < G_N_ELEMENTS(pc->p)); - - if ( ( p != pc->p[ pc->npoints - 1 ] ) + if ( ( p != this->p[ this->npoints - 1 ] ) && in_svg_plane(p) ) { - pc->ps.push_back(p); - pc->p[pc->npoints++] = p; - fit_and_split(pc); + this->ps.push_back(p); + this->p[this->npoints++] = p; + this->_fitAndSplit(); } } @@ -680,31 +643,29 @@ square(double const x) return x * x; } -static void -interpolate(PencilTool *pc) -{ - if ( pc->ps.size() <= 1 ) { +void PencilTool::_interpolate() { + if ( this->ps.size() <= 1 ) { return; } Inkscape::Preferences *prefs = Inkscape::Preferences::get(); double const tol = prefs->getDoubleLimited("/tools/freehand/pencil/tolerance", 10.0, 1.0, 100.0) * 0.4; - double const tolerance_sq = 0.02 * square( pc->desktop->w2d().descrim() * + double const tolerance_sq = 0.02 * square( this->desktop->w2d().descrim() * tol) * exp(0.2*tol - 2); - g_assert(is_zero(pc->req_tangent) - || is_unit_vector(pc->req_tangent)); + g_assert(is_zero(this->req_tangent) + || is_unit_vector(this->req_tangent)); Geom::Point const tHatEnd(0, 0); - guint n_points = pc->ps.size(); - pc->green_curve->reset(); - pc->red_curve->reset(); - pc->red_curve_is_valid = false; + guint n_points = this->ps.size(); + this->green_curve->reset(); + this->red_curve->reset(); + this->red_curve_is_valid = false; Geom::Point * b = g_new(Geom::Point, 4*n_points); Geom::Point * points = g_new(Geom::Point, 4*n_points); - for (unsigned int i = 0; i < pc->ps.size(); i++) { - points[i] = pc->ps[i]; + for (unsigned int i = 0; i < this->ps.size(); i++) { + points[i] = this->ps[i]; } // worst case gives us a segment per point @@ -716,62 +677,60 @@ interpolate(PencilTool *pc) if ( n_segs > 0) { /* Fit and draw and reset state */ - pc->green_curve->moveto(b[0]); + this->green_curve->moveto(b[0]); for (int c = 0; c < n_segs; c++) { - pc->green_curve->curveto(b[4*c+1], b[4*c+2], b[4*c+3]); + this->green_curve->curveto(b[4*c+1], b[4*c+2], b[4*c+3]); } - sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(pc->red_bpath), pc->green_curve); + sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), this->green_curve); /* Fit and draw and copy last point */ - g_assert(!pc->green_curve->is_empty()); + g_assert(!this->green_curve->is_empty()); /* Set up direction of next curve. */ { - Geom::Curve const * last_seg = pc->green_curve->last_segment(); + Geom::Curve const * last_seg = this->green_curve->last_segment(); g_assert( last_seg ); // Relevance: validity of (*last_seg) - pc->p[0] = last_seg->finalPoint(); - pc->npoints = 1; + this->p[0] = last_seg->finalPoint(); + this->npoints = 1; Geom::Curve *last_seg_reverse = last_seg->reverse(); Geom::Point const req_vec( -last_seg_reverse->unitTangentAt(0) ); delete last_seg_reverse; - pc->req_tangent = ( ( Geom::is_zero(req_vec) || !in_svg_plane(req_vec) ) + this->req_tangent = ( ( Geom::is_zero(req_vec) || !in_svg_plane(req_vec) ) ? Geom::Point(0, 0) : Geom::unit_vector(req_vec) ); } } g_free(b); g_free(points); - pc->ps.clear(); + this->ps.clear(); } /* interpolates the sketched curve and tweaks the current sketch interpolation*/ -static void -sketch_interpolate(PencilTool *pc) -{ - if ( pc->ps.size() <= 1 ) { +void PencilTool::_sketchInterpolate() { + if ( this->ps.size() <= 1 ) { return; } Inkscape::Preferences *prefs = Inkscape::Preferences::get(); double const tol = prefs->getDoubleLimited("/tools/freehand/pencil/tolerance", 10.0, 1.0, 100.0) * 0.4; - double const tolerance_sq = 0.02 * square( pc->desktop->w2d().descrim() * + double const tolerance_sq = 0.02 * square( this->desktop->w2d().descrim() * tol) * exp(0.2*tol - 2); bool average_all_sketches = prefs->getBool("/tools/freehand/pencil/average_all_sketches", true); - g_assert(is_zero(pc->req_tangent) - || is_unit_vector(pc->req_tangent)); + g_assert(is_zero(this->req_tangent) + || is_unit_vector(this->req_tangent)); Geom::Point const tHatEnd(0, 0); - guint n_points = pc->ps.size(); - pc->red_curve->reset(); - pc->red_curve_is_valid = false; + guint n_points = this->ps.size(); + this->red_curve->reset(); + this->red_curve_is_valid = false; Geom::Point * b = g_new(Geom::Point, 4*n_points); Geom::Point * points = g_new(Geom::Point, 4*n_points); - for (unsigned i = 0; i < pc->ps.size(); i++) { - points[i] = pc->ps[i]; + for (unsigned i = 0; i < this->ps.size(); i++) { + points[i] = this->ps[i]; } // worst case gives us a segment per point @@ -788,110 +747,108 @@ sketch_interpolate(PencilTool *pc) } Geom::Piecewise > fit_pwd2 = fit.toPwSb(); - if ( pc->sketch_n > 0 ) { + if ( this->sketch_n > 0 ) { double t =0.; if (average_all_sketches) { // Average = (sum of all) / n // = (sum of all + new one) / n+1 // = ((old average)*n + new one) / n+1 - t = pc->sketch_n / (pc->sketch_n + 1.); + t = this->sketch_n / (this->sketch_n + 1.); } else { t = 0.5; } - pc->sketch_interpolation = Geom::lerp(t, fit_pwd2, pc->sketch_interpolation); + this->sketch_interpolation = Geom::lerp(t, fit_pwd2, this->sketch_interpolation); // simplify path, to eliminate small segments Path *path = new Path; - path->LoadPathVector(Geom::path_from_piecewise(pc->sketch_interpolation, 0.01)); + path->LoadPathVector(Geom::path_from_piecewise(this->sketch_interpolation, 0.01)); path->Simplify(0.5); Geom::PathVector *pathv = path->MakePathVector(); - pc->sketch_interpolation = (*pathv)[0].toPwSb(); + this->sketch_interpolation = (*pathv)[0].toPwSb(); delete path; delete pathv; } else { - pc->sketch_interpolation = fit_pwd2; + this->sketch_interpolation = fit_pwd2; } - pc->sketch_n++; + this->sketch_n++; - pc->green_curve->reset(); - pc->green_curve->set_pathvector(Geom::path_from_piecewise(pc->sketch_interpolation, 0.01)); - sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(pc->red_bpath), pc->green_curve); + this->green_curve->reset(); + this->green_curve->set_pathvector(Geom::path_from_piecewise(this->sketch_interpolation, 0.01)); + sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), this->green_curve); /* Fit and draw and copy last point */ - g_assert(!pc->green_curve->is_empty()); + g_assert(!this->green_curve->is_empty()); /* Set up direction of next curve. */ { - Geom::Curve const * last_seg = pc->green_curve->last_segment(); + Geom::Curve const * last_seg = this->green_curve->last_segment(); g_assert( last_seg ); // Relevance: validity of (*last_seg) - pc->p[0] = last_seg->finalPoint(); - pc->npoints = 1; + this->p[0] = last_seg->finalPoint(); + this->npoints = 1; Geom::Curve *last_seg_reverse = last_seg->reverse(); Geom::Point const req_vec( -last_seg_reverse->unitTangentAt(0) ); delete last_seg_reverse; - pc->req_tangent = ( ( Geom::is_zero(req_vec) || !in_svg_plane(req_vec) ) + this->req_tangent = ( ( Geom::is_zero(req_vec) || !in_svg_plane(req_vec) ) ? Geom::Point(0, 0) : Geom::unit_vector(req_vec) ); } } g_free(b); g_free(points); - pc->ps.clear(); + this->ps.clear(); } -static void -fit_and_split(PencilTool *pc) -{ - g_assert( pc->npoints > 1 ); +void PencilTool::_fitAndSplit() { + g_assert( this->npoints > 1 ); double const tolerance_sq = 0; Geom::Point b[4]; - g_assert(is_zero(pc->req_tangent) - || is_unit_vector(pc->req_tangent)); + g_assert(is_zero(this->req_tangent) + || is_unit_vector(this->req_tangent)); Geom::Point const tHatEnd(0, 0); - int const n_segs = Geom::bezier_fit_cubic_full(b, NULL, pc->p, pc->npoints, - pc->req_tangent, tHatEnd, + int const n_segs = Geom::bezier_fit_cubic_full(b, NULL, this->p, this->npoints, + this->req_tangent, tHatEnd, tolerance_sq, 1); if ( n_segs > 0 - && unsigned(pc->npoints) < G_N_ELEMENTS(pc->p) ) + && unsigned(this->npoints) < G_N_ELEMENTS(this->p) ) { /* Fit and draw and reset state */ - pc->red_curve->reset(); - pc->red_curve->moveto(b[0]); - pc->red_curve->curveto(b[1], b[2], b[3]); - sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(pc->red_bpath), pc->red_curve); - pc->red_curve_is_valid = true; + this->red_curve->reset(); + this->red_curve->moveto(b[0]); + this->red_curve->curveto(b[1], b[2], b[3]); + sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), this->red_curve); + this->red_curve_is_valid = true; } else { /* Fit and draw and copy last point */ - g_assert(!pc->red_curve->is_empty()); + g_assert(!this->red_curve->is_empty()); /* Set up direction of next curve. */ { - Geom::Curve const * last_seg = pc->red_curve->last_segment(); + Geom::Curve const * last_seg = this->red_curve->last_segment(); g_assert( last_seg ); // Relevance: validity of (*last_seg) - pc->p[0] = last_seg->finalPoint(); - pc->npoints = 1; + this->p[0] = last_seg->finalPoint(); + this->npoints = 1; Geom::Curve *last_seg_reverse = last_seg->reverse(); Geom::Point const req_vec( -last_seg_reverse->unitTangentAt(0) ); delete last_seg_reverse; - pc->req_tangent = ( ( Geom::is_zero(req_vec) || !in_svg_plane(req_vec) ) + this->req_tangent = ( ( Geom::is_zero(req_vec) || !in_svg_plane(req_vec) ) ? Geom::Point(0, 0) : Geom::unit_vector(req_vec) ); } - pc->green_curve->append_continuous(pc->red_curve, 0.0625); - SPCurve *curve = pc->red_curve->copy(); + this->green_curve->append_continuous(this->red_curve, 0.0625); + SPCurve *curve = this->red_curve->copy(); /// \todo fixme: - SPCanvasItem *cshape = sp_canvas_bpath_new(sp_desktop_sketch(pc->desktop), curve); + SPCanvasItem *cshape = sp_canvas_bpath_new(sp_desktop_sketch(this->desktop), curve); curve->unref(); - sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(cshape), pc->green_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); + sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(cshape), this->green_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); - pc->green_bpaths = g_slist_prepend(pc->green_bpaths, cshape); + this->green_bpaths = g_slist_prepend(this->green_bpaths, cshape); - pc->red_curve_is_valid = false; + this->red_curve_is_valid = false; } } diff --git a/src/ui/tools/pencil-tool.h b/src/ui/tools/pencil-tool.h index 6ced9eb56..efc1f60e0 100644 --- a/src/ui/tools/pencil-tool.h +++ b/src/ui/tools/pencil-tool.h @@ -48,6 +48,24 @@ public: protected: virtual void setup(); virtual bool root_handler(GdkEvent* event); + +private: + gint _handleButtonPress(GdkEventButton const &bevent); + gint _handleMotionNotify(GdkEventMotion const &mevent); + gint _handleButtonRelease(GdkEventButton const &revent); + gint _handleKeyPress(guint const keyval, guint const state); + gint _handleKeyRelease(guint const keyval, guint const state); + + void _setStartpoint(Geom::Point const &p); + void _setEndpoint(Geom::Point const &p); + void _finishEndpoint(); + void _addFreehandPoint(Geom::Point const &p, guint state); + void _fitAndSplit(); + void _interpolate(); + void _sketchInterpolate(); + + void _cancel(); + void _endpointSnap(Geom::Point &p, guint const state); }; } diff --git a/src/ui/tools/rect-tool.cpp b/src/ui/tools/rect-tool.cpp index f5153e8ce..39f422c1a 100644 --- a/src/ui/tools/rect-tool.cpp +++ b/src/ui/tools/rect-tool.cpp @@ -235,7 +235,7 @@ bool RectTool::root_handler(GdkEvent* event) { this->drag(motion_dt, event->motion.state); // this will also handle the snapping gobble_motion_events(GDK_BUTTON1_MASK); ret = TRUE; - } else if (!sp_event_context_knot_mouseover(this)) { + } else if (!this->sp_event_context_knot_mouseover()) { SnapManager &m = desktop->namedview->snap_manager; m.setup(desktop); diff --git a/src/ui/tools/spiral-tool.cpp b/src/ui/tools/spiral-tool.cpp index 7d33b0f67..5ae229df8 100644 --- a/src/ui/tools/spiral-tool.cpp +++ b/src/ui/tools/spiral-tool.cpp @@ -209,7 +209,7 @@ bool SpiralTool::root_handler(GdkEvent* event) { gobble_motion_events(GDK_BUTTON1_MASK); ret = TRUE; - } else if (!sp_event_context_knot_mouseover(this)) { + } else if (!this->sp_event_context_knot_mouseover()) { SnapManager &m = desktop->namedview->snap_manager; m.setup(desktop); Geom::Point const motion_w(event->motion.x, event->motion.y); diff --git a/src/ui/tools/star-tool.cpp b/src/ui/tools/star-tool.cpp index 42010788f..68f998920 100644 --- a/src/ui/tools/star-tool.cpp +++ b/src/ui/tools/star-tool.cpp @@ -218,7 +218,7 @@ bool StarTool::root_handler(GdkEvent* event) { gobble_motion_events(GDK_BUTTON1_MASK); ret = TRUE; - } else if (!sp_event_context_knot_mouseover(this)) { + } else if (!this->sp_event_context_knot_mouseover()) { SnapManager &m = desktop->namedview->snap_manager; m.setup(desktop); diff --git a/src/ui/tools/text-tool.cpp b/src/ui/tools/text-tool.cpp index 00f6a853c..4a171d1bd 100644 --- a/src/ui/tools/text-tool.cpp +++ b/src/ui/tools/text-tool.cpp @@ -602,7 +602,7 @@ bool TextTool::root_handler(GdkEvent* event) { g_string_free(xs, FALSE); g_string_free(ys, FALSE); - } else if (!sp_event_context_knot_mouseover(this)) { + } else if (!this->sp_event_context_knot_mouseover()) { SnapManager &m = desktop->namedview->snap_manager; m.setup(desktop); diff --git a/src/ui/tools/tool-base.cpp b/src/ui/tools/tool-base.cpp index 99b72c386..45b519fb4 100644 --- a/src/ui/tools/tool-base.cpp +++ b/src/ui/tools/tool-base.cpp @@ -143,9 +143,9 @@ ToolBase::~ToolBase() { /** * Set the cursor to a standard GDK cursor */ -static void sp_event_context_set_cursor(ToolBase *event_context, GdkCursorType cursor_type) { +void ToolBase::sp_event_context_set_cursor(GdkCursorType cursor_type) { - GtkWidget *w = GTK_WIDGET(sp_desktop_canvas(event_context->desktop)); + GtkWidget *w = GTK_WIDGET(sp_desktop_canvas(this->desktop)); GdkDisplay *display = gdk_display_get_default(); GdkCursor *cursor = gdk_cursor_new_for_display(display, cursor_type); @@ -480,7 +480,7 @@ bool ToolBase::root_handler(GdkEvent* event) { if (panning_cursor == 0) { panning_cursor = 1; - sp_event_context_set_cursor(this, GDK_FLEUR); + this->sp_event_context_set_cursor(GDK_FLEUR); } Geom::Point const motion_w(event->motion.x, event->motion.y); @@ -876,10 +876,9 @@ bool ToolBase::item_handler(SPItem* item, GdkEvent* event) { /** * Returns true if we're hovering above a knot (needed because we don't want to pre-snap in that case). */ -bool sp_event_context_knot_mouseover(ToolBase *ec) -{ - if (ec->shape_editor) { - return ec->shape_editor->knot_mouseover(); +bool ToolBase::sp_event_context_knot_mouseover() const { + if (this->shape_editor) { + return this->shape_editor->knot_mouseover(); } return false; diff --git a/src/ui/tools/tool-base.h b/src/ui/tools/tool-base.h index 79bdfe89d..3a536fc2c 100644 --- a/src/ui/tools/tool-base.h +++ b/src/ui/tools/tool-base.h @@ -186,9 +186,14 @@ protected: /// The cursor's hot spot gint hot_x, hot_y; + bool sp_event_context_knot_mouseover() const; + private: ToolBase(const ToolBase&); ToolBase& operator=(const ToolBase&); + + void sp_event_context_set_cursor(GdkCursorType cursor_type); + }; void sp_event_context_read(ToolBase *ec, gchar const *key); -- cgit v1.2.3 From 5417f369168ac22a58f9f4e5bdccaf500dd0e170 Mon Sep 17 00:00:00 2001 From: "Jon A. Cruz" Date: Sun, 2 Mar 2014 11:41:46 -0800 Subject: Avoid crashing when the document is set to NULL (upon cleanup, window closing, etc.) (bzr r13092) --- src/ui/dialog/filter-effects-dialog.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/ui') diff --git a/src/ui/dialog/filter-effects-dialog.cpp b/src/ui/dialog/filter-effects-dialog.cpp index b763776c6..65bebbd14 100644 --- a/src/ui/dialog/filter-effects-dialog.cpp +++ b/src/ui/dialog/filter-effects-dialog.cpp @@ -1430,7 +1430,10 @@ void FilterEffectsDialog::FilterModifier::on_document_replaced(SPDesktop * /*des if (_resource_changed) { _resource_changed.disconnect(); } - _resource_changed = document->connectResourcesChanged("filter",sigc::mem_fun(*this, &FilterModifier::update_filters)); + if (document) + { + _resource_changed = document->connectResourcesChanged("filter",sigc::mem_fun(*this, &FilterModifier::update_filters)); + } update_filters(); } -- cgit v1.2.3 From 8121aa1985103b201ee846de9b3a3669b66d183b Mon Sep 17 00:00:00 2001 From: "Jon A. Cruz" Date: Sun, 2 Mar 2014 12:36:19 -0800 Subject: Stop tracking SPDocuments as they are deleted. (bzr r13095) --- src/ui/dialog/swatches.cpp | 103 ++++++++++++++++++++++++++++++++------------- src/ui/dialog/swatches.h | 2 + 2 files changed, 75 insertions(+), 30 deletions(-) (limited to 'src/ui') diff --git a/src/ui/dialog/swatches.cpp b/src/ui/dialog/swatches.cpp index 807618b4d..5e77a28ab 100644 --- a/src/ui/dialog/swatches.cpp +++ b/src/ui/dialog/swatches.cpp @@ -745,10 +745,11 @@ void SwatchesPanel::setDesktop( SPDesktop* desktop ) class DocTrack { public: - DocTrack(SPDocument *doc, sigc::connection &gradientRsrcChanged, sigc::connection &defsChanged, sigc::connection &defsModified) : - doc(doc->doRef()), + DocTrack(SPDocument *doc, sigc::connection &docDestroy, sigc::connection &gradientRsrcChanged, sigc::connection &defsChanged, sigc::connection &defsModified) : + doc(doc), updatePending(false), lastGradientUpdate(0.0), + docDestroy(docDestroy), gradientRsrcChanged(gradientRsrcChanged), defsChanged(defsChanged), defsModified(defsModified) @@ -773,10 +774,10 @@ public: } } if (doc) { + docDestroy.disconnect(); gradientRsrcChanged.disconnect(); defsChanged.disconnect(); defsModified.disconnect(); - doc->doUnref(); doc = NULL; } } @@ -797,6 +798,7 @@ public: SPDocument *doc; bool updatePending; double lastGradientUpdate; + sigc::connection docDestroy; sigc::connection gradientRsrcChanged; sigc::connection defsChanged; sigc::connection defsModified; @@ -892,11 +894,12 @@ void SwatchesPanel::_trackDocument( SwatchesPanel *panel, SPDocument *document ) } docPerPanel[panel] = document; if (!found) { + sigc::connection conn0 = document->connectDestroy(sigc::bind(sigc::ptr_fun(&SwatchesPanel::handleDocumentDestroy), document)); sigc::connection conn1 = document->connectResourcesChanged( "gradient", sigc::bind(sigc::ptr_fun(&SwatchesPanel::handleGradientsChange), document) ); sigc::connection conn2 = document->getDefs()->connectRelease( sigc::hide(sigc::bind(sigc::ptr_fun(&SwatchesPanel::handleDefsModified), document)) ); sigc::connection conn3 = document->getDefs()->connectModified( sigc::hide(sigc::hide(sigc::bind(sigc::ptr_fun(&SwatchesPanel::handleDefsModified), document))) ); - DocTrack *dt = new DocTrack(document, conn1, conn2, conn3); + DocTrack *dt = new DocTrack(document, conn0, conn1, conn2, conn3); docTrackings.push_back(dt); if (docPalettes.find(document) == docPalettes.end()) { @@ -925,11 +928,13 @@ static void recalcSwatchContents(SPDocument* doc, { std::vector newList; - const GSList *gradients = doc->getResourceList("gradient"); - for (const GSList *item = gradients; item; item = item->next) { - SPGradient* grad = SP_GRADIENT(item->data); - if ( grad->isSwatch() ) { - newList.push_back(SP_GRADIENT(item->data)); + if (doc) { + const GSList *gradients = doc->getResourceList("gradient"); + for (const GSList *item = gradients; item; item = item->next) { + SPGradient* grad = SP_GRADIENT(item->data); + if ( grad->isSwatch() ) { + newList.push_back(SP_GRADIENT(item->data)); + } } } @@ -968,6 +973,37 @@ static void recalcSwatchContents(SPDocument* doc, } } +void SwatchesPanel::handleDocumentDestroy(SPDocument *document) +{ + if (document) { + for (std::vector::iterator it = docTrackings.begin(); it != docTrackings.end(); ++it){ + if ((*it)->doc == document) { + delete *it; + docTrackings.erase(it); + break; + } + } + + if (docPalettes.find(document) != docPalettes.end()) { + docPalettes.erase(document); + } + + for (std::map::iterator it = docPerPanel.begin(); it != docPerPanel.end(); ++it) { + if (it->second == document) { + SwatchesPanel* swp = it->first; + std::vector pages = swp->_getSwatchSets(); + if ((swp->_currentIndex >= static_cast(pages.size())) && (pages.size() > 0)) + { + swp->_setSelectedIndex(swp->_getSwatchSets().size() - 1); + } + swp->_rebuild(); + docPerPanel.erase(it); + break; + } + } + } +} + void SwatchesPanel::handleGradientsChange(SPDocument *document) { SwatchPage *docPalette = (docPalettes.find(document) != docPalettes.end()) ? docPalettes[document] : 0; @@ -1142,38 +1178,45 @@ void SwatchesPanel::_handleAction( int setId, int itemId ) switch( setId ) { case 3: { - std::vector pages = _getSwatchSets(); - if ( itemId >= 0 && itemId < static_cast(pages.size()) ) { - _currentIndex = itemId; + _setSelectedIndex(itemId); + } + break; + } +} - if ( !_prefs_path.empty() ) { - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setString(_prefs_path + "/palette", pages[_currentIndex]->_name); - } +void SwatchesPanel::_setSelectedIndex( int index ) +{ + std::vector pages = _getSwatchSets(); + if ( index >= 0 && index < static_cast(pages.size()) ) { + _currentIndex = index; - _rebuild(); - } + if ( !_prefs_path.empty() ) { + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->setString(_prefs_path + "/palette", pages[_currentIndex]->_name); } - break; + + _rebuild(); } } void SwatchesPanel::_rebuild() { std::vector pages = _getSwatchSets(); - SwatchPage* curr = pages[_currentIndex]; - _holder->clear(); + if (_currentIndex < static_cast(pages.size())) { + SwatchPage* curr = pages[_currentIndex]; + _holder->clear(); - if ( curr->_prefWidth > 0 ) { - _holder->setColumnPref( curr->_prefWidth ); - } - _holder->freezeUpdates(); - // TODO restore once 'clear' works _holder->addPreview(_clear); - _holder->addPreview(_remove); - for ( boost::ptr_vector::iterator it = curr->_colors.begin(); it != curr->_colors.end(); ++it) { - _holder->addPreview(&*it); + if ( curr->_prefWidth > 0 ) { + _holder->setColumnPref( curr->_prefWidth ); + } + _holder->freezeUpdates(); + // TODO restore once 'clear' works _holder->addPreview(_clear); + _holder->addPreview(_remove); + for ( boost::ptr_vector::iterator it = curr->_colors.begin(); it != curr->_colors.end(); ++it) { + _holder->addPreview(&*it); + } + _holder->thawUpdates(); } - _holder->thawUpdates(); } } //namespace Dialogs diff --git a/src/ui/dialog/swatches.h b/src/ui/dialog/swatches.h index ca4c1687d..3abb81d98 100644 --- a/src/ui/dialog/swatches.h +++ b/src/ui/dialog/swatches.h @@ -43,11 +43,13 @@ public: virtual int getSelectedIndex() {return _currentIndex;} // temporary protected: + static void handleDocumentDestroy(SPDocument *document); static void handleGradientsChange(SPDocument *document); virtual void _updateFromSelection(); virtual void _handleAction( int setId, int itemId ); virtual void _setDocument( SPDocument *document ); + virtual void _setSelectedIndex( int index ); virtual void _rebuild(); virtual std::vector _getSwatchSets() const; -- cgit v1.2.3 From 0590fab15842f57c3fd54bae7c658d1427e6b8d7 Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Tue, 4 Mar 2014 20:58:18 +0100 Subject: static code analysis: references for string classes that are function input parameters (bzr r13114) --- src/ui/dialog/export.cpp | 502 ++++++++++++++++++++++++----------------------- src/ui/dialog/export.h | 48 +++-- 2 files changed, 282 insertions(+), 268 deletions(-) (limited to 'src/ui') diff --git a/src/ui/dialog/export.cpp b/src/ui/dialog/export.cpp index 340a3dad0..f0a5f1bf5 100644 --- a/src/ui/dialog/export.cpp +++ b/src/ui/dialog/export.cpp @@ -144,11 +144,13 @@ namespace Dialog { /** A list of strings that is used both in the preferences, and in the data fields to describe the various values of \c selection_type. */ static const char * selection_names[SELECTION_NUMBER_OF] = { - "page", "drawing", "selection", "custom"}; + "page", "drawing", "selection", "custom" +}; /** The names on the buttons for the various selection types. */ static const char * selection_labels[SELECTION_NUMBER_OF] = { - N_("_Page"), N_("_Drawing"), N_("_Selection"), N_("_Custom")}; + N_("_Page"), N_("_Drawing"), N_("_Selection"), N_("_Custom") +}; Export::Export (void) : UI::Widget::Panel ("", "/dialogs/export/", SP_VERB_DIALOG_EXPORT), @@ -201,7 +203,7 @@ Export::Export (void) : /* gets added to the vbox later, but the unit selector is needed earlier than that */ unit_selector.setUnitType(Inkscape::Util::UNIT_TYPE_LINEAR); - + SPDesktop *desktop = SP_ACTIVE_DESKTOP; if (desktop) { unit_selector.setUnit(sp_desktop_namedview(desktop)->doc_units->abbr); @@ -232,28 +234,28 @@ Export::Export (void) : #endif x0_adj = createSpinbutton ( "x0", 0.0, -1000000.0, 1000000.0, 0.1, 1.0, - t, 0, 0, _("_x0:"), "", EXPORT_COORD_PRECISION, 1, - &Export::onAreaX0Change); + t, 0, 0, _("_x0:"), "", EXPORT_COORD_PRECISION, 1, + &Export::onAreaX0Change); x1_adj = createSpinbutton ( "x1", 0.0, -1000000.0, 1000000.0, 0.1, 1.0, - t, 0, 1, _("x_1:"), "", EXPORT_COORD_PRECISION, 1, - &Export::onAreaX1Change); + t, 0, 1, _("x_1:"), "", EXPORT_COORD_PRECISION, 1, + &Export::onAreaX1Change); width_adj = createSpinbutton ( "width", 0.0, 0.0, PNG_UINT_31_MAX, 0.1, 1.0, - t, 0, 2, _("Wid_th:"), "", EXPORT_COORD_PRECISION, 1, - &Export::onAreaWidthChange); + t, 0, 2, _("Wid_th:"), "", EXPORT_COORD_PRECISION, 1, + &Export::onAreaWidthChange); y0_adj = createSpinbutton ( "y0", 0.0, -1000000.0, 1000000.0, 0.1, 1.0, - t, 2, 0, _("_y0:"), "", EXPORT_COORD_PRECISION, 1, - &Export::onAreaY0Change); + t, 2, 0, _("_y0:"), "", EXPORT_COORD_PRECISION, 1, + &Export::onAreaY0Change); y1_adj = createSpinbutton ( "y1", 0.0, -1000000.0, 1000000.0, 0.1, 1.0, - t, 2, 1, _("y_1:"), "", EXPORT_COORD_PRECISION, 1, - &Export::onAreaY1Change); + t, 2, 1, _("y_1:"), "", EXPORT_COORD_PRECISION, 1, + &Export::onAreaY1Change); height_adj = createSpinbutton ( "height", 0.0, 0.0, PNG_UINT_31_MAX, 0.1, 1.0, - t, 2, 2, _("Hei_ght:"), "", EXPORT_COORD_PRECISION, 1, - &Export::onAreaHeightChange); + t, 2, 2, _("Hei_ght:"), "", EXPORT_COORD_PRECISION, 1, + &Export::onAreaHeightChange); area_box.pack_start(togglebox, false, false, 3); area_box.pack_start(*t, false, false, 0); @@ -284,27 +286,27 @@ Export::Export (void) : size_box.pack_start(*t); bmwidth_adj = createSpinbutton ( "bmwidth", 16.0, 1.0, 1000000.0, 1.0, 10.0, - t, 0, 0, - _("_Width:"), _("pixels at"), 0, 1, - &Export::onBitmapWidthChange); + t, 0, 0, + _("_Width:"), _("pixels at"), 0, 1, + &Export::onBitmapWidthChange); xdpi_adj = createSpinbutton ( "xdpi", - prefs->getDouble("/dialogs/export/defaultxdpi/value", DPI_BASE), - 0.01, 100000.0, 0.1, 1.0, t, 3, 0, - "", _("dp_i"), 2, 1, - &Export::onExportXdpiChange); + prefs->getDouble("/dialogs/export/defaultxdpi/value", DPI_BASE), + 0.01, 100000.0, 0.1, 1.0, t, 3, 0, + "", _("dp_i"), 2, 1, + &Export::onExportXdpiChange); bmheight_adj = createSpinbutton ( "bmheight", 16.0, 1.0, 1000000.0, 1.0, 10.0, - t, 0, 1, - _("_Height:"), _("pixels at"), 0, 1, - &Export::onBitmapHeightChange); + t, 0, 1, + _("_Height:"), _("pixels at"), 0, 1, + &Export::onBitmapHeightChange); /** TODO * There's no way to set ydpi currently, so we use the defaultxdpi value here, too... */ ydpi_adj = createSpinbutton ( "ydpi", prefs->getDouble("/dialogs/export/defaultxdpi/value", DPI_BASE), - 0.01, 100000.0, 0.1, 1.0, t, 3, 1, - "", _("dpi"), 2, 0, NULL ); + 0.01, 100000.0, 0.1, 1.0, t, 3, 1, + "", _("dpi"), 2, 0, NULL ); singleexport_box.pack_start(size_box); } @@ -482,18 +484,18 @@ void Export::set_default_filename () { #if WITH_GTKMM_3_0 Glib::RefPtr Export::createSpinbutton( gchar const * /*key*/, float val, float min, float max, - float step, float page, - Gtk::Grid *t, int x, int y, - const Glib::ustring ll, const Glib::ustring lr, - int digits, unsigned int sensitive, - void (Export::*cb)() ) + float step, float page, + Gtk::Grid *t, int x, int y, + const Glib::ustring& ll, const Glib::ustring& lr, + int digits, unsigned int sensitive, + void (Export::*cb)() ) #else Gtk::Adjustment * Export::createSpinbutton( gchar const * /*key*/, float val, float min, float max, - float step, float page, - Gtk::Table *t, int x, int y, - const Glib::ustring ll, const Glib::ustring lr, - int digits, unsigned int sensitive, - void (Export::*cb)() ) + float step, float page, + Gtk::Table *t, int x, int y, + const Glib::ustring& ll, const Glib::ustring& lr, + int digits, unsigned int sensitive, + void (Export::*cb)() ) #endif { #if WITH_GTKMM_3_0 @@ -535,7 +537,9 @@ Gtk::Adjustment * Export::createSpinbutton( gchar const * /*key*/, float val, fl sb->set_sensitive (sensitive); pos++; - if (!ll.empty()) { l->set_mnemonic_widget(*sb);} + if (!ll.empty()) { + l->set_mnemonic_widget(*sb); + } if (!lr.empty()) { l = new Gtk::Label(lr,true); @@ -565,7 +569,7 @@ Gtk::Adjustment * Export::createSpinbutton( gchar const * /*key*/, float val, fl Glib::ustring Export::create_filepath_from_id (Glib::ustring id, const Glib::ustring &file_entry_text) { if (id.empty()) - { /* This should never happen */ + { /* This should never happen */ id = "bitmap"; } @@ -678,35 +682,35 @@ void Export::onSelectionModified ( guint /*flags*/ ) { Inkscape::Selection * Sel; switch (current_key) { - case SELECTION_DRAWING: - if ( SP_ACTIVE_DESKTOP ) { - SPDocument *doc; - doc = sp_desktop_document (SP_ACTIVE_DESKTOP); - Geom::OptRect bbox = doc->getRoot()->desktopVisualBounds(); - if (bbox) { - setArea ( bbox->left(), - bbox->top(), - bbox->right(), - bbox->bottom()); - } + case SELECTION_DRAWING: + if ( SP_ACTIVE_DESKTOP ) { + SPDocument *doc; + doc = sp_desktop_document (SP_ACTIVE_DESKTOP); + Geom::OptRect bbox = doc->getRoot()->desktopVisualBounds(); + if (bbox) { + setArea ( bbox->left(), + bbox->top(), + bbox->right(), + bbox->bottom()); } - break; - case SELECTION_SELECTION: - Sel = sp_desktop_selection(SP_ACTIVE_DESKTOP); - if (Sel->isEmpty() == false) { - Geom::OptRect bbox = Sel->visualBounds(); - if (bbox) - { - setArea ( bbox->left(), - bbox->top(), - bbox->right(), - bbox->bottom()); - } + } + break; + case SELECTION_SELECTION: + Sel = sp_desktop_selection(SP_ACTIVE_DESKTOP); + if (Sel->isEmpty() == false) { + Geom::OptRect bbox = Sel->visualBounds(); + if (bbox) + { + setArea ( bbox->left(), + bbox->top(), + bbox->right(), + bbox->bottom()); } - break; - default: - /* Do nothing for page or for custom */ - break; + } + break; + default: + /* Do nothing for page or for custom */ + break; } return; @@ -738,39 +742,39 @@ void Export::onAreaToggled () various backups. If you modify this without noticing you'll probabaly screw something up. */ switch (key) { - case SELECTION_SELECTION: - if ((sp_desktop_selection(SP_ACTIVE_DESKTOP))->isEmpty() == false) - { - bbox = sp_desktop_selection (SP_ACTIVE_DESKTOP)->visualBounds(); - /* Only if there is a selection that we can set - do we break, otherwise we fall through to the - drawing */ - // std::cout << "Using selection: SELECTION" << std::endl; - key = SELECTION_SELECTION; - break; - } - case SELECTION_DRAWING: - /** \todo - * This returns wrong values if the document has a viewBox. - */ - bbox = doc->getRoot()->desktopVisualBounds(); - /* If the drawing is valid, then we'll use it and break - otherwise we drop through to the page settings */ - if (bbox) { - // std::cout << "Using selection: DRAWING" << std::endl; - key = SELECTION_DRAWING; - break; - } - case SELECTION_PAGE: - bbox = Geom::Rect(Geom::Point(0.0, 0.0), - Geom::Point(doc->getWidth().value("px"), doc->getHeight().value("px"))); - - // std::cout << "Using selection: PAGE" << std::endl; - key = SELECTION_PAGE; + case SELECTION_SELECTION: + if ((sp_desktop_selection(SP_ACTIVE_DESKTOP))->isEmpty() == false) + { + bbox = sp_desktop_selection (SP_ACTIVE_DESKTOP)->visualBounds(); + /* Only if there is a selection that we can set + do we break, otherwise we fall through to the + drawing */ + // std::cout << "Using selection: SELECTION" << std::endl; + key = SELECTION_SELECTION; break; - case SELECTION_CUSTOM: - default: + } + case SELECTION_DRAWING: + /** \todo + * This returns wrong values if the document has a viewBox. + */ + bbox = doc->getRoot()->desktopVisualBounds(); + /* If the drawing is valid, then we'll use it and break + otherwise we drop through to the page settings */ + if (bbox) { + // std::cout << "Using selection: DRAWING" << std::endl; + key = SELECTION_DRAWING; break; + } + case SELECTION_PAGE: + bbox = Geom::Rect(Geom::Point(0.0, 0.0), + Geom::Point(doc->getWidth().value("px"), doc->getHeight().value("px"))); + + // std::cout << "Using selection: PAGE" << std::endl; + key = SELECTION_PAGE; + break; + case SELECTION_CUSTOM: + default: + break; } // switch current_key = key; @@ -780,9 +784,9 @@ void Export::onAreaToggled () if ( key != SELECTION_CUSTOM && bbox ) { setArea ( bbox->min()[Geom::X], - bbox->min()[Geom::Y], - bbox->max()[Geom::X], - bbox->max()[Geom::Y]); + bbox->min()[Geom::Y], + bbox->max()[Geom::X], + bbox->max()[Geom::Y]); } } // end of if ( SP_ACTIVE_DESKTOP ) @@ -793,43 +797,43 @@ void Export::onAreaToggled () float xdpi = 0.0, ydpi = 0.0; switch (key) { - case SELECTION_PAGE: - case SELECTION_DRAWING: { - SPDocument * doc = SP_ACTIVE_DOCUMENT; - sp_document_get_export_hints (doc, filename, &xdpi, &ydpi); - - if (filename.empty()) { - if (!doc_export_name.empty()) { - filename = doc_export_name; - } + case SELECTION_PAGE: + case SELECTION_DRAWING: { + SPDocument * doc = SP_ACTIVE_DOCUMENT; + sp_document_get_export_hints (doc, filename, &xdpi, &ydpi); + + if (filename.empty()) { + if (!doc_export_name.empty()) { + filename = doc_export_name; } - break; } - case SELECTION_SELECTION: - if ((sp_desktop_selection(SP_ACTIVE_DESKTOP))->isEmpty() == false) { - - sp_selection_get_export_hints (sp_desktop_selection(SP_ACTIVE_DESKTOP), filename, &xdpi, &ydpi); - - /* If we still don't have a filename -- let's build - one that's nice */ - if (filename.empty()) { - const gchar * id = "object"; - const GSList * reprlst = sp_desktop_selection(SP_ACTIVE_DESKTOP)->reprList(); - for(; reprlst != NULL; reprlst = reprlst->next) { - Inkscape::XML::Node * repr = (Inkscape::XML::Node *)reprlst->data; - if (repr->attribute("id")) { - id = repr->attribute("id"); - break; - } - } + break; + } + case SELECTION_SELECTION: + if ((sp_desktop_selection(SP_ACTIVE_DESKTOP))->isEmpty() == false) { - filename = create_filepath_from_id (id, filename_entry.get_text()); + sp_selection_get_export_hints (sp_desktop_selection(SP_ACTIVE_DESKTOP), filename, &xdpi, &ydpi); + + /* If we still don't have a filename -- let's build + one that's nice */ + if (filename.empty()) { + const gchar * id = "object"; + const GSList * reprlst = sp_desktop_selection(SP_ACTIVE_DESKTOP)->reprList(); + for(; reprlst != NULL; reprlst = reprlst->next) { + Inkscape::XML::Node * repr = (Inkscape::XML::Node *)reprlst->data; + if (repr->attribute("id")) { + id = repr->attribute("id"); + break; + } } + + filename = create_filepath_from_id (id, filename_entry.get_text()); } - break; - case SELECTION_CUSTOM: - default: - break; + } + break; + case SELECTION_CUSTOM: + default: + break; } if (!filename.empty()) { @@ -895,8 +899,8 @@ unsigned int Export::onProgressCallback(float value, void *dlg) int evtcount = 0; while ((evtcount < 16) && gdk_events_pending()) { - gtk_main_iteration_do(FALSE); - evtcount += 1; + gtk_main_iteration_do(FALSE); + evtcount += 1; } gtk_main_iteration_do(FALSE); @@ -960,7 +964,7 @@ Glib::ustring Export::filename_add_extension (Glib::ustring filename, Glib::ustr } else { - return filename = filename + "." + extension; + return filename = filename + "." + extension; } } } @@ -1057,9 +1061,9 @@ void Export::onExport () // Do export gchar * safeFile = Inkscape::IO::sanitizeString(path.c_str()); MessageCleaner msgCleanup(desktop->messageStack()->pushF(Inkscape::IMMEDIATE_MESSAGE, - _("Exporting file %s..."), safeFile), desktop); + _("Exporting file %s..."), safeFile), desktop); MessageCleaner msgFlashCleanup(desktop->messageStack()->flashF(Inkscape::IMMEDIATE_MESSAGE, - _("Exporting file %s..."), safeFile), desktop); + _("Exporting file %s..."), safeFile), desktop); if (!sp_export_png_file (doc, path.c_str(), *area, width, height, dpi, dpi, @@ -1067,7 +1071,7 @@ void Export::onExport () onProgressCallback, (void*)prog_dlg, TRUE, // overwrite without asking hide ? const_cast(sp_desktop_selection(desktop)->itemList()) : NULL - )) { + )) { gchar * error = g_strdup_printf(_("Could not export to filename %s.\n"), safeFile); desktop->messageStack()->flashF(Inkscape::ERROR_MESSAGE, @@ -1096,7 +1100,7 @@ void Export::onExport () } else { Glib::ustring filename = filename_entry.get_text(); - if (filename.empty()){ + if (filename.empty()) { desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("You have to enter a filename.")); sp_ui_error_dialog(_("You have to enter a filename")); return; @@ -1125,7 +1129,7 @@ void Export::onExport () Glib::ustring dirname = Glib::path_get_dirname(path); if ( dirname.empty() - || !Inkscape::IO::file_test(dirname.c_str(), (GFileTest)(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) ) + || !Inkscape::IO::file_test(dirname.c_str(), (GFileTest)(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) ) { gchar *safeDir = Inkscape::IO::sanitizeString(dirname.c_str()); gchar *error = g_strdup_printf(_("Directory %s does not exist or is not a directory.\n"), @@ -1151,12 +1155,12 @@ void Export::onExport () /* Do export */ ExportResult status = sp_export_png_file(sp_desktop_document(desktop), path.c_str(), - Geom::Rect(Geom::Point(x0, y0), Geom::Point(x1, y1)), width, height, xdpi, ydpi, - nv->pagecolor, - onProgressCallback, (void*)prog_dlg, - FALSE, - hide ? const_cast(sp_desktop_selection(desktop)->itemList()) : NULL - ); + Geom::Rect(Geom::Point(x0, y0), Geom::Point(x1, y1)), width, height, xdpi, ydpi, + nv->pagecolor, + onProgressCallback, (void*)prog_dlg, + FALSE, + hide ? const_cast(sp_desktop_selection(desktop)->itemList()) : NULL + ); if (status == EXPORT_ERROR) { gchar * safeFile = Inkscape::IO::sanitizeString(path.c_str()); gchar * error = g_strdup_printf(_("Could not export to filename %s.\n"), safeFile); @@ -1189,19 +1193,65 @@ void Export::onExport () /* Setup the values in the document */ switch (current_key) { - case SELECTION_PAGE: - case SELECTION_DRAWING: { - SPDocument * doc = SP_ACTIVE_DOCUMENT; - Inkscape::XML::Node * repr = doc->getReprRoot(); - bool modified = false; - - bool saved = DocumentUndo::getUndoSensitive(doc); - DocumentUndo::setUndoSensitive(doc, false); - - gchar const *temp_string = repr->attribute("inkscape:export-filename"); - if (temp_string == NULL || (filename_ext != temp_string)) { - repr->setAttribute("inkscape:export-filename", filename_ext.c_str()); - modified = true; + case SELECTION_PAGE: + case SELECTION_DRAWING: { + SPDocument * doc = SP_ACTIVE_DOCUMENT; + Inkscape::XML::Node * repr = doc->getReprRoot(); + bool modified = false; + + bool saved = DocumentUndo::getUndoSensitive(doc); + DocumentUndo::setUndoSensitive(doc, false); + + gchar const *temp_string = repr->attribute("inkscape:export-filename"); + if (temp_string == NULL || (filename_ext != temp_string)) { + repr->setAttribute("inkscape:export-filename", filename_ext.c_str()); + modified = true; + } + temp_string = repr->attribute("inkscape:export-xdpi"); + if (temp_string == NULL || xdpi != atof(temp_string)) { + sp_repr_set_svg_double(repr, "inkscape:export-xdpi", xdpi); + modified = true; + } + temp_string = repr->attribute("inkscape:export-ydpi"); + if (temp_string == NULL || ydpi != atof(temp_string)) { + sp_repr_set_svg_double(repr, "inkscape:export-ydpi", ydpi); + modified = true; + } + DocumentUndo::setUndoSensitive(doc, saved); + + if (modified) { + doc->setModifiedSinceSave(); + } + break; + } + case SELECTION_SELECTION: { + const GSList * reprlst; + SPDocument * doc = SP_ACTIVE_DOCUMENT; + bool modified = false; + + bool saved = DocumentUndo::getUndoSensitive(doc); + DocumentUndo::setUndoSensitive(doc, false); + reprlst = sp_desktop_selection(desktop)->reprList(); + + for(; reprlst != NULL; reprlst = reprlst->next) { + Inkscape::XML::Node * repr = static_cast(reprlst->data); + const gchar * temp_string; + Glib::ustring dir = Glib::path_get_dirname(filename.c_str()); + const gchar* docURI=SP_ACTIVE_DOCUMENT->getURI(); + Glib::ustring docdir; + if (docURI) + { + docdir = Glib::path_get_dirname(docURI); + } + if (repr->attribute("id") == NULL || + !(filename_ext.find_last_of(repr->attribute("id")) && + ( !docURI || + (dir == docdir)))) { + temp_string = repr->attribute("inkscape:export-filename"); + if (temp_string == NULL || (filename_ext != temp_string)) { + repr->setAttribute("inkscape:export-filename", filename_ext.c_str()); + modified = true; + } } temp_string = repr->attribute("inkscape:export-xdpi"); if (temp_string == NULL || xdpi != atof(temp_string)) { @@ -1213,62 +1263,16 @@ void Export::onExport () sp_repr_set_svg_double(repr, "inkscape:export-ydpi", ydpi); modified = true; } - DocumentUndo::setUndoSensitive(doc, saved); - - if (modified) { - doc->setModifiedSinceSave(); - } - break; } - case SELECTION_SELECTION: { - const GSList * reprlst; - SPDocument * doc = SP_ACTIVE_DOCUMENT; - bool modified = false; - - bool saved = DocumentUndo::getUndoSensitive(doc); - DocumentUndo::setUndoSensitive(doc, false); - reprlst = sp_desktop_selection(desktop)->reprList(); - - for(; reprlst != NULL; reprlst = reprlst->next) { - Inkscape::XML::Node * repr = static_cast(reprlst->data); - const gchar * temp_string; - Glib::ustring dir = Glib::path_get_dirname(filename.c_str()); - const gchar* docURI=SP_ACTIVE_DOCUMENT->getURI(); - Glib::ustring docdir; - if (docURI) - { - docdir = Glib::path_get_dirname(docURI); - } - if (repr->attribute("id") == NULL || - !(filename_ext.find_last_of(repr->attribute("id")) && - ( !docURI || - (dir == docdir)))) { - temp_string = repr->attribute("inkscape:export-filename"); - if (temp_string == NULL || (filename_ext != temp_string)) { - repr->setAttribute("inkscape:export-filename", filename_ext.c_str()); - modified = true; - } - } - temp_string = repr->attribute("inkscape:export-xdpi"); - if (temp_string == NULL || xdpi != atof(temp_string)) { - sp_repr_set_svg_double(repr, "inkscape:export-xdpi", xdpi); - modified = true; - } - temp_string = repr->attribute("inkscape:export-ydpi"); - if (temp_string == NULL || ydpi != atof(temp_string)) { - sp_repr_set_svg_double(repr, "inkscape:export-ydpi", ydpi); - modified = true; - } - } - DocumentUndo::setUndoSensitive(doc, saved); + DocumentUndo::setUndoSensitive(doc, saved); - if (modified) { - doc->setModifiedSinceSave(); - } - break; + if (modified) { + doc->setModifiedSinceSave(); } - default: - break; + break; + } + default: + break; } } @@ -1331,8 +1335,8 @@ void Export::onBrowse () // Copy the selected file name, converting from UTF-8 to UTF-16 std::string dirname = Glib::path_get_dirname(filename.raw()); if ( !Glib::file_test(dirname, Glib::FILE_TEST_EXISTS) || - Glib::file_test(filename, Glib::FILE_TEST_IS_DIR) || - dirname.empty() ) + Glib::file_test(filename, Glib::FILE_TEST_IS_DIR) || + dirname.empty() ) { Glib::ustring tmp; filename = create_filepath_from_id(tmp, tmp); @@ -1407,11 +1411,11 @@ bool Export::bbox_equal(Geom::Rect const &one, Geom::Rect const &two) { double const epsilon = pow(10.0, -EXPORT_COORD_PRECISION); return ( - (fabs(one.min()[Geom::X] - two.min()[Geom::X]) < epsilon) && - (fabs(one.min()[Geom::Y] - two.min()[Geom::Y]) < epsilon) && - (fabs(one.max()[Geom::X] - two.max()[Geom::X]) < epsilon) && - (fabs(one.max()[Geom::Y] - two.max()[Geom::Y]) < epsilon) - ); + (fabs(one.min()[Geom::X] - two.min()[Geom::X]) < epsilon) && + (fabs(one.min()[Geom::Y] - two.min()[Geom::Y]) < epsilon) && + (fabs(one.max()[Geom::X] - two.max()[Geom::X]) < epsilon) && + (fabs(one.max()[Geom::Y] - two.max()[Geom::Y]) < epsilon) + ); } /** @@ -1454,48 +1458,48 @@ void Export::detectSize() { for (int i = 0; i < SELECTION_NUMBER_OF + 1 && - key == SELECTION_NUMBER_OF && - SP_ACTIVE_DESKTOP != NULL; + key == SELECTION_NUMBER_OF && + SP_ACTIVE_DESKTOP != NULL; i++) { switch (this_test[i]) { - case SELECTION_SELECTION: - if ((sp_desktop_selection(SP_ACTIVE_DESKTOP))->isEmpty() == false) { - Geom::OptRect bbox = (sp_desktop_selection (SP_ACTIVE_DESKTOP))->bounds(SPItem::VISUAL_BBOX); + case SELECTION_SELECTION: + if ((sp_desktop_selection(SP_ACTIVE_DESKTOP))->isEmpty() == false) { + Geom::OptRect bbox = (sp_desktop_selection (SP_ACTIVE_DESKTOP))->bounds(SPItem::VISUAL_BBOX); - if ( bbox && bbox_equal(*bbox,current_bbox)) { - key = SELECTION_SELECTION; - } + if ( bbox && bbox_equal(*bbox,current_bbox)) { + key = SELECTION_SELECTION; } - break; - case SELECTION_DRAWING: { - SPDocument *doc = sp_desktop_document (SP_ACTIVE_DESKTOP); + } + break; + case SELECTION_DRAWING: { + SPDocument *doc = sp_desktop_document (SP_ACTIVE_DESKTOP); - Geom::OptRect bbox = doc->getRoot()->desktopVisualBounds(); + Geom::OptRect bbox = doc->getRoot()->desktopVisualBounds(); - if ( bbox && bbox_equal(*bbox,current_bbox) ) { - key = SELECTION_DRAWING; - } - break; + if ( bbox && bbox_equal(*bbox,current_bbox) ) { + key = SELECTION_DRAWING; } + break; + } - case SELECTION_PAGE: { - SPDocument *doc; + case SELECTION_PAGE: { + SPDocument *doc; - doc = sp_desktop_document (SP_ACTIVE_DESKTOP); + doc = sp_desktop_document (SP_ACTIVE_DESKTOP); - Geom::Point x(0.0, 0.0); - Geom::Point y(doc->getWidth().value("px"), - doc->getHeight().value("px")); - Geom::Rect bbox(x, y); + Geom::Point x(0.0, 0.0); + Geom::Point y(doc->getWidth().value("px"), + doc->getHeight().value("px")); + Geom::Rect bbox(x, y); - if (bbox_equal(bbox,current_bbox)) { - key = SELECTION_PAGE; - } + if (bbox_equal(bbox,current_bbox)) { + key = SELECTION_PAGE; + } - break; - } + break; + } default: - break; + break; } } // std::cout << std::endl; @@ -1579,7 +1583,7 @@ void Export::areaYChange (Gtk::Adjustment *adj) height = SP_EXPORT_MIN_SIZE; //key = (const gchar *)g_object_get_data(G_OBJECT (adj), "key"); if (adj == y1_adj) { - //if (!strcmp (key, "y0")) { + //if (!strcmp (key, "y0")) { y1 = y0 + height * DPI_BASE / ydpi; setValuePx(y1_adj, y1); } else { diff --git a/src/ui/dialog/export.h b/src/ui/dialog/export.h index 79e597414..6f3c0dfac 100644 --- a/src/ui/dialog/export.h +++ b/src/ui/dialog/export.h @@ -56,7 +56,9 @@ public: Export (); ~Export (); - static Export &getInstance() { return *new Export(); } + static Export &getInstance() { + return *new Export(); + } private: @@ -97,7 +99,7 @@ private: float getValue (Gtk::Adjustment *adj); float getValuePx (Gtk::Adjustment *adj); #endif - + /** * Helper function to create, style and pack spinbuttons for the export dialog. * @@ -121,20 +123,20 @@ private: */ #if WITH_GTKMM_3_0 Glib::RefPtr createSpinbutton( gchar const *key, float val, float min, float max, - float step, float page, - Gtk::Grid *t, int x, int y, - const Glib::ustring ll, const Glib::ustring lr, - int digits, unsigned int sensitive, - void (Export::*cb)() ); + float step, float page, + Gtk::Grid *t, int x, int y, + const Glib::ustring& ll, const Glib::ustring& lr, + int digits, unsigned int sensitive, + void (Export::*cb)() ); #else Gtk::Adjustment * createSpinbutton( gchar const *key, float val, float min, float max, - float step, float page, - Gtk::Table *t, int x, int y, - const Glib::ustring ll, const Glib::ustring lr, - int digits, unsigned int sensitive, - void (Export::*cb)() ); + float step, float page, + Gtk::Table *t, int x, int y, + const Glib::ustring& ll, const Glib::ustring& lr, + int digits, unsigned int sensitive, + void (Export::*cb)() ); #endif - + /** * One of the area select radio buttons was pressed */ @@ -153,8 +155,12 @@ private: /** * Area X value changed callback */ - void onAreaX0Change() {areaXChange(x0_adj);} ; - void onAreaX1Change() {areaXChange(x1_adj);} ; + void onAreaX0Change() { + areaXChange(x0_adj); + } ; + void onAreaX1Change() { + areaXChange(x1_adj); + } ; #if WITH_GTKMM_3_0 void areaXChange(Glib::RefPtr& adj); #else @@ -164,8 +170,12 @@ private: /** * Area Y value changed callback */ - void onAreaY0Change() {areaYChange(y0_adj);} ; - void onAreaY1Change() {areaYChange(y1_adj);} ; + void onAreaY0Change() { + areaYChange(y0_adj); + } ; + void onAreaY1Change() { + areaYChange(y1_adj); + } ; #if WITH_GTKMM_3_0 void areaYChange(Glib::RefPtr& adj); #else @@ -235,14 +245,14 @@ private: /** * Creates progress dialog for batch exporting. - * + * * @param progress_text Text to be shown in the progress bar */ Gtk::Dialog * create_progress_dialog (Glib::ustring progress_text); /** * Callback to be used in for loop to update the progress bar. - * + * * @param value number between 0 and 1 indicating the fraction of progress (0.17 = 17 % progress) * @param dlg void pointer to the Gtk::Dialog progress dialog */ -- cgit v1.2.3 From 7366f7cc4018447f99dc42c22d9e67a504cd059c Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Thu, 6 Mar 2014 00:30:47 +0100 Subject: Derive ToolBase from sigc::trackable for easier slot management. Fix TextTool to use mem_fun instead of ptr_fun to avoid the generation of stale slots. (bzr r13118) --- src/ui/tools/text-tool.cpp | 213 ++++++++++++++++++++------------------------- src/ui/tools/text-tool.h | 6 ++ src/ui/tools/tool-base.h | 5 +- 3 files changed, 104 insertions(+), 120 deletions(-) (limited to 'src/ui') diff --git a/src/ui/tools/text-tool.cpp b/src/ui/tools/text-tool.cpp index 4a171d1bd..bf37937c4 100644 --- a/src/ui/tools/text-tool.cpp +++ b/src/ui/tools/text-tool.cpp @@ -61,11 +61,6 @@ namespace Inkscape { namespace UI { namespace Tools { -static void sp_text_context_selection_changed(Inkscape::Selection *selection, TextTool *tc); -static void sp_text_context_selection_modified(Inkscape::Selection *selection, guint flags, TextTool *tc); -static bool sp_text_context_style_set(SPCSSAttr const *css, TextTool *tc); -static int sp_text_context_style_query(SPStyle *style, int property, TextTool *tc); - static void sp_text_context_validate_cursor_iterators(TextTool *tc); static void sp_text_context_update_cursor(TextTool *tc, bool scroll_to_see = true); static void sp_text_context_update_text_selection(TextTool *tc); @@ -77,15 +72,15 @@ static gint sptc_focus_out(GtkWidget *widget, GdkEventFocus *event, TextTool *tc static void sptc_commit(GtkIMContext *imc, gchar *string, TextTool *tc); namespace { - ToolBase* createTextContext() { - return new TextTool(); - } + ToolBase* createTextContext() { + return new TextTool(); + } - bool textContextRegistered = ToolFactory::instance().registerObject("/tools/text", createTextContext); + bool textContextRegistered = ToolFactory::instance().registerObject("/tools/text", createTextContext); } const std::string& TextTool::getPrefsPath() { - return TextTool::prefsPath; + return TextTool::prefsPath; } const std::string TextTool::prefsPath = "/tools/text"; @@ -165,7 +160,7 @@ void TextTool::setup() { */ gtk_im_context_set_use_preedit(this->imc, FALSE); gtk_im_context_set_client_window(this->imc, - gtk_widget_get_window (canvas)); + gtk_widget_get_window (canvas)); g_signal_connect(G_OBJECT(canvas), "focus_in_event", G_CALLBACK(sptc_focus_in), this); g_signal_connect(G_OBJECT(canvas), "focus_out_event", G_CALLBACK(sptc_focus_out), this); @@ -186,19 +181,19 @@ void TextTool::setup() { } this->sel_changed_connection = sp_desktop_selection(desktop)->connectChanged( - sigc::bind(sigc::ptr_fun(&sp_text_context_selection_changed), this) - ); + sigc::mem_fun(*this, &TextTool::_selectionChanged) + ); this->sel_modified_connection = sp_desktop_selection(desktop)->connectModified( - sigc::bind(sigc::ptr_fun(&sp_text_context_selection_modified), this) - ); + sigc::mem_fun(*this, &TextTool::_selectionModified) + ); this->style_set_connection = desktop->connectSetStyle( - sigc::bind(sigc::ptr_fun(&sp_text_context_style_set), this) - ); + sigc::mem_fun(*this, &TextTool::_styleSet) + ); this->style_query_connection = desktop->connectQueryStyle( - sigc::bind(sigc::ptr_fun(&sp_text_context_style_query), this) - ); + sigc::mem_fun(*this, &TextTool::_styleQueried) + ); - sp_text_context_selection_changed(sp_desktop_selection(desktop), this); + _selectionChanged(sp_desktop_selection(desktop)); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); if (prefs->getBool("/tools/text/selcue")) { @@ -396,7 +391,7 @@ bool TextTool::item_handler(SPItem* item, GdkEvent* event) { } if (!ret) { - ret = ToolBase::item_handler(item, event); + ret = ToolBase::item_handler(item, event); } return ret; @@ -437,7 +432,7 @@ static void sp_text_context_setup_text(TextTool *tc) text_item->updateRepr(); text_item->doWriteTransform(text_item->getRepr(), text_item->transform, NULL, true); DocumentUndo::done(sp_desktop_document(ec->desktop), SP_VERB_CONTEXT_TEXT, - _("Create text")); + _("Create text")); } /** @@ -477,7 +472,7 @@ static void insert_uni_char(TextTool *const tc) sp_text_context_update_cursor(tc); sp_text_context_update_text_selection(tc); DocumentUndo::done(sp_desktop_document(tc->desktop), SP_VERB_DIALOG_TRANSFORM, - _("Insert Unicode character")); + _("Insert Unicode character")); } } @@ -667,8 +662,7 @@ bool TextTool::root_handler(GdkEvent* event) { sp_desktop_apply_style_tool(desktop, ft->getRepr(), "/tools/text", true); sp_desktop_selection(desktop)->set(ft); desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Flowed text is created.")); - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_TEXT, - _("Create flowed text")); + DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_TEXT, _("Create flowed text")); } else { desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("The frame is too small for the current font size. Flowed text not created.")); } @@ -807,8 +801,7 @@ bool TextTool::root_handler(GdkEvent* event) { sp_text_context_update_cursor(this); sp_text_context_update_text_selection(this); desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("No-break space")); - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_TEXT, - _("Insert no-break space")); + DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_TEXT, _("Insert no-break space")); return TRUE; } break; @@ -844,8 +837,7 @@ bool TextTool::root_handler(GdkEvent* event) { sp_repr_css_set_property(css, "font-weight", "normal"); sp_te_apply_style(this->text, this->text_sel_start, this->text_sel_end, css); sp_repr_css_attr_unref(css); - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_TEXT, - _("Make bold")); + DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_TEXT, _("Make bold")); sp_text_context_update_cursor(this); sp_text_context_update_text_selection(this); return TRUE; @@ -862,8 +854,7 @@ bool TextTool::root_handler(GdkEvent* event) { sp_repr_css_set_property(css, "font-style", "italic"); sp_te_apply_style(this->text, this->text_sel_start, this->text_sel_end, css); sp_repr_css_attr_unref(css); - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_TEXT, - _("Make italic")); + DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_TEXT, _("Make italic")); sp_text_context_update_cursor(this); sp_text_context_update_text_selection(this); return TRUE; @@ -901,8 +892,7 @@ bool TextTool::root_handler(GdkEvent* event) { sp_text_context_update_cursor(this); sp_text_context_update_text_selection(this); - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_TEXT, - _("New line")); + DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_TEXT, _("New line")); return TRUE; } case GDK_KEY_BackSpace: @@ -943,8 +933,7 @@ bool TextTool::root_handler(GdkEvent* event) { sp_text_context_update_cursor(this); sp_text_context_update_text_selection(this); - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_TEXT, - _("Backspace")); + DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_TEXT, _("Backspace")); } return TRUE; case GDK_KEY_Delete: @@ -982,8 +971,7 @@ bool TextTool::root_handler(GdkEvent* event) { sp_text_context_update_cursor(this); sp_text_context_update_text_selection(this); - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_TEXT, - _("Delete")); + DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_TEXT, _("Delete")); } return TRUE; case GDK_KEY_Left: @@ -999,8 +987,7 @@ bool TextTool::root_handler(GdkEvent* event) { sp_te_adjust_kerning_screen(this->text, this->text_sel_start, this->text_sel_end, desktop, Geom::Point(mul*-1, 0)); sp_text_context_update_cursor(this); sp_text_context_update_text_selection(this); - DocumentUndo::maybeDone(sp_desktop_document(desktop), "kern:left", SP_VERB_CONTEXT_TEXT, - _("Kern to the left")); + DocumentUndo::maybeDone(sp_desktop_document(desktop), "kern:left", SP_VERB_CONTEXT_TEXT, _("Kern to the left")); } else { if (MOD__CTRL(event)) this->text_sel_end.cursorLeftWithControl(); @@ -1024,8 +1011,7 @@ bool TextTool::root_handler(GdkEvent* event) { sp_te_adjust_kerning_screen(this->text, this->text_sel_start, this->text_sel_end, desktop, Geom::Point(mul*1, 0)); sp_text_context_update_cursor(this); sp_text_context_update_text_selection(this); - DocumentUndo::maybeDone(sp_desktop_document(desktop), "kern:right", SP_VERB_CONTEXT_TEXT, - _("Kern to the right")); + DocumentUndo::maybeDone(sp_desktop_document(desktop), "kern:right", SP_VERB_CONTEXT_TEXT, _("Kern to the right")); } else { if (MOD__CTRL(event)) this->text_sel_end.cursorRightWithControl(); @@ -1049,8 +1035,7 @@ bool TextTool::root_handler(GdkEvent* event) { sp_te_adjust_kerning_screen(this->text, this->text_sel_start, this->text_sel_end, desktop, Geom::Point(0, mul*-1)); sp_text_context_update_cursor(this); sp_text_context_update_text_selection(this); - DocumentUndo::maybeDone(sp_desktop_document(desktop), "kern:up", SP_VERB_CONTEXT_TEXT, - _("Kern up")); + DocumentUndo::maybeDone(sp_desktop_document(desktop), "kern:up", SP_VERB_CONTEXT_TEXT, _("Kern up")); } else { if (MOD__CTRL(event)) this->text_sel_end.cursorUpWithControl(); @@ -1074,8 +1059,7 @@ bool TextTool::root_handler(GdkEvent* event) { sp_te_adjust_kerning_screen(this->text, this->text_sel_start, this->text_sel_end, desktop, Geom::Point(0, mul*1)); sp_text_context_update_cursor(this); sp_text_context_update_text_selection(this); - DocumentUndo::maybeDone(sp_desktop_document(desktop), "kern:down", SP_VERB_CONTEXT_TEXT, - _("Kern down")); + DocumentUndo::maybeDone(sp_desktop_document(desktop), "kern:down", SP_VERB_CONTEXT_TEXT, _("Kern down")); } else { if (MOD__CTRL(event)) this->text_sel_end.cursorDownWithControl(); @@ -1150,8 +1134,7 @@ bool TextTool::root_handler(GdkEvent* event) { } else { sp_te_adjust_rotation(this->text, this->text_sel_start, this->text_sel_end, desktop, -90); } - DocumentUndo::maybeDone(sp_desktop_document(desktop), "textrot:ccw", SP_VERB_CONTEXT_TEXT, - _("Rotate counterclockwise")); + DocumentUndo::maybeDone(sp_desktop_document(desktop), "textrot:ccw", SP_VERB_CONTEXT_TEXT, _("Rotate counterclockwise")); sp_text_context_update_cursor(this); sp_text_context_update_text_selection(this); return TRUE; @@ -1171,8 +1154,7 @@ bool TextTool::root_handler(GdkEvent* event) { } else { sp_te_adjust_rotation(this->text, this->text_sel_start, this->text_sel_end, desktop, 90); } - DocumentUndo::maybeDone(sp_desktop_document(desktop), "textrot:cw", SP_VERB_CONTEXT_TEXT, - _("Rotate clockwise")); + DocumentUndo::maybeDone(sp_desktop_document(desktop), "textrot:cw", SP_VERB_CONTEXT_TEXT, _("Rotate clockwise")); sp_text_context_update_cursor(this); sp_text_context_update_text_selection(this); return TRUE; @@ -1188,15 +1170,13 @@ bool TextTool::root_handler(GdkEvent* event) { sp_te_adjust_linespacing_screen(this->text, this->text_sel_start, this->text_sel_end, desktop, -10); else sp_te_adjust_linespacing_screen(this->text, this->text_sel_start, this->text_sel_end, desktop, -1); - DocumentUndo::maybeDone(sp_desktop_document(desktop), "linespacing:dec", SP_VERB_CONTEXT_TEXT, - _("Contract line spacing")); + DocumentUndo::maybeDone(sp_desktop_document(desktop), "linespacing:dec", SP_VERB_CONTEXT_TEXT, _("Contract line spacing")); } else { if (MOD__SHIFT(event)) sp_te_adjust_tspan_letterspacing_screen(this->text, this->text_sel_start, this->text_sel_end, desktop, -10); else sp_te_adjust_tspan_letterspacing_screen(this->text, this->text_sel_start, this->text_sel_end, desktop, -1); - DocumentUndo::maybeDone(sp_desktop_document(desktop), "letterspacing:dec", SP_VERB_CONTEXT_TEXT, - _("Contract letter spacing")); + DocumentUndo::maybeDone(sp_desktop_document(desktop), "letterspacing:dec", SP_VERB_CONTEXT_TEXT, _("Contract letter spacing")); } sp_text_context_update_cursor(this); sp_text_context_update_text_selection(this); @@ -1213,15 +1193,13 @@ bool TextTool::root_handler(GdkEvent* event) { sp_te_adjust_linespacing_screen(this->text, this->text_sel_start, this->text_sel_end, desktop, 10); else sp_te_adjust_linespacing_screen(this->text, this->text_sel_start, this->text_sel_end, desktop, 1); - DocumentUndo::maybeDone(sp_desktop_document(desktop), "linespacing:inc", SP_VERB_CONTEXT_TEXT, - _("Expand line spacing")); + DocumentUndo::maybeDone(sp_desktop_document(desktop), "linespacing:inc", SP_VERB_CONTEXT_TEXT, _("Expand line spacing")); } else { if (MOD__SHIFT(event)) sp_te_adjust_tspan_letterspacing_screen(this->text, this->text_sel_start, this->text_sel_end, desktop, 10); else sp_te_adjust_tspan_letterspacing_screen(this->text, this->text_sel_start, this->text_sel_end, desktop, 1); - DocumentUndo::maybeDone(sp_desktop_document(desktop), "letterspacing:inc", SP_VERB_CONTEXT_TEXT, - _("Expand letter spacing"));\ + DocumentUndo::maybeDone(sp_desktop_document(desktop), "letterspacing:inc", SP_VERB_CONTEXT_TEXT, _("Expand letter spacing"));\ } sp_text_context_update_cursor(this); sp_text_context_update_text_selection(this); @@ -1305,32 +1283,32 @@ bool sp_text_paste_inline(ToolBase *ec) Glib::ustring const clip_text = refClipboard->wait_for_text(); if (!clip_text.empty()) { - // Fix for 244940 - // The XML standard defines the following as valid characters - // (Extensible Markup Language (XML) 1.0 (Fourth Edition) paragraph 2.2) - // char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF] - // Since what comes in off the paste buffer will go right into XML, clean - // the text here. - Glib::ustring text(clip_text); - Glib::ustring::iterator itr = text.begin(); - gunichar paste_string_uchar; - - while(itr != text.end()) - { - paste_string_uchar = *itr; - - // Make sure we don't have a control character. We should really check - // for the whole range above... Add the rest of the invalid cases from - // above if we find additional issues - if(paste_string_uchar >= 0x00000020 || - paste_string_uchar == 0x00000009 || - paste_string_uchar == 0x0000000A || - paste_string_uchar == 0x0000000D) { - ++itr; - } else { - itr = text.erase(itr); - } - } + // Fix for 244940 + // The XML standard defines the following as valid characters + // (Extensible Markup Language (XML) 1.0 (Fourth Edition) paragraph 2.2) + // char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF] + // Since what comes in off the paste buffer will go right into XML, clean + // the text here. + Glib::ustring text(clip_text); + Glib::ustring::iterator itr = text.begin(); + gunichar paste_string_uchar; + + while(itr != text.end()) + { + paste_string_uchar = *itr; + + // Make sure we don't have a control character. We should really check + // for the whole range above... Add the rest of the invalid cases from + // above if we find additional issues + if(paste_string_uchar >= 0x00000020 || + paste_string_uchar == 0x00000009 || + paste_string_uchar == 0x0000000A || + paste_string_uchar == 0x0000000D) { + ++itr; + } else { + itr = text.erase(itr); + } + } if (!tc->text) { // create text if none (i.e. if nascent_object) sp_text_context_setup_text(tc); @@ -1351,7 +1329,7 @@ bool sp_text_paste_inline(ToolBase *ec) begin = end + 1; } DocumentUndo::done(sp_desktop_document(ec->desktop), SP_VERB_CONTEXT_TEXT, - _("Paste text")); + _("Paste text")); return true; } @@ -1427,12 +1405,11 @@ bool sp_text_delete_selection(ToolBase *ec) /** * \param selection Should not be NULL. */ -static void -sp_text_context_selection_changed(Inkscape::Selection *selection, TextTool *tc) +void TextTool::_selectionChanged(Inkscape::Selection *selection) { g_assert(selection != NULL); - ToolBase *ec = SP_EVENT_CONTEXT(tc); + ToolBase *ec = SP_EVENT_CONTEXT(this); ec->shape_editor->unset_item(SH_KNOTHOLDER); SPItem *item = selection->singleItem(); @@ -1440,70 +1417,68 @@ sp_text_context_selection_changed(Inkscape::Selection *selection, TextTool *tc) ec->shape_editor->set_item(item, SH_KNOTHOLDER); } - if (tc->text && (item != tc->text)) { - sp_text_context_forget_text(tc); + if (this->text && (item != this->text)) { + sp_text_context_forget_text(this); } - tc->text = NULL; + this->text = NULL; if (SP_IS_TEXT(item) || SP_IS_FLOWTEXT(item)) { - tc->text = item; - Inkscape::Text::Layout const *layout = te_get_layout(tc->text); + this->text = item; + Inkscape::Text::Layout const *layout = te_get_layout(this->text); if (layout) - tc->text_sel_start = tc->text_sel_end = layout->end(); + this->text_sel_start = this->text_sel_end = layout->end(); } else { - tc->text = NULL; + this->text = NULL; } // we update cursor without scrolling, because this position may not be final; // item_handler moves cusros to the point of click immediately - sp_text_context_update_cursor(tc, false); - sp_text_context_update_text_selection(tc); + sp_text_context_update_cursor(this, false); + sp_text_context_update_text_selection(this); } -static void -sp_text_context_selection_modified(Inkscape::Selection */*selection*/, guint /*flags*/, TextTool *tc) +void TextTool::_selectionModified(Inkscape::Selection */*selection*/, guint /*flags*/) { - sp_text_context_update_cursor(tc); - sp_text_context_update_text_selection(tc); + sp_text_context_update_cursor(this); + sp_text_context_update_text_selection(this); } -static bool sp_text_context_style_set(SPCSSAttr const *css, TextTool *tc) +bool TextTool::_styleSet(SPCSSAttr const *css) { - if (tc->text == NULL) + if (this->text == NULL) return false; - if (tc->text_sel_start == tc->text_sel_end) + if (this->text_sel_start == this->text_sel_end) return false; // will get picked up by the parent and applied to the whole text object - sp_te_apply_style(tc->text, tc->text_sel_start, tc->text_sel_end, css); - DocumentUndo::done(sp_desktop_document(tc->desktop), SP_VERB_CONTEXT_TEXT, - _("Set text style")); - sp_text_context_update_cursor(tc); - sp_text_context_update_text_selection(tc); + sp_te_apply_style(this->text, this->text_sel_start, this->text_sel_end, css); + DocumentUndo::done(sp_desktop_document(this->desktop), SP_VERB_CONTEXT_TEXT, + _("Set text style")); + sp_text_context_update_cursor(this); + sp_text_context_update_text_selection(this); return true; } -static int -sp_text_context_style_query(SPStyle *style, int property, TextTool *tc) +int TextTool::_styleQueried(SPStyle *style, int property) { - if (tc->text == NULL) { + if (this->text == NULL) { return QUERY_STYLE_NOTHING; } - const Inkscape::Text::Layout *layout = te_get_layout(tc->text); + const Inkscape::Text::Layout *layout = te_get_layout(this->text); if (layout == NULL) { return QUERY_STYLE_NOTHING; } - sp_text_context_validate_cursor_iterators(tc); + sp_text_context_validate_cursor_iterators(this); GSList *styles_list = NULL; Inkscape::Text::Layout::iterator begin_it, end_it; - if (tc->text_sel_start < tc->text_sel_end) { - begin_it = tc->text_sel_start; - end_it = tc->text_sel_end; + if (this->text_sel_start < this->text_sel_end) { + begin_it = this->text_sel_start; + end_it = this->text_sel_end; } else { - begin_it = tc->text_sel_end; - end_it = tc->text_sel_start; + begin_it = this->text_sel_end; + end_it = this->text_sel_start; } if (begin_it == end_it) { if (!begin_it.prevCharacter()) { @@ -1717,7 +1692,7 @@ static void sptc_commit(GtkIMContext */*imc*/, gchar *string, TextTool *tc) sp_text_context_update_text_selection(tc); DocumentUndo::done(tc->text->document, SP_VERB_CONTEXT_TEXT, - _("Type text")); + _("Type text")); } void sp_text_context_place_cursor (TextTool *tc, SPObject *text, Inkscape::Text::Layout::iterator where) diff --git a/src/ui/tools/text-tool.h b/src/ui/tools/text-tool.h index c5336d378..ca2b3d19a 100644 --- a/src/ui/tools/text-tool.h +++ b/src/ui/tools/text-tool.h @@ -84,6 +84,12 @@ public: virtual bool item_handler(SPItem* item, GdkEvent* event); virtual const std::string& getPrefsPath(); + +private: + void _selectionChanged(Inkscape::Selection *selection); + void _selectionModified(Inkscape::Selection *selection, guint flags); + bool _styleSet(SPCSSAttr const *css); + int _styleQueried(SPStyle *style, int property); }; bool sp_text_paste_inline(ToolBase *ec); diff --git a/src/ui/tools/tool-base.h b/src/ui/tools/tool-base.h index 3a536fc2c..eb8908f3e 100644 --- a/src/ui/tools/tool-base.h +++ b/src/ui/tools/tool-base.h @@ -14,6 +14,7 @@ #include #include +#include #include "knot.h" #include "2geom/forward.h" @@ -104,7 +105,9 @@ void sp_event_context_snap_delay_handler(ToolBase *ec, gpointer const dse_item, * plus few abstract base classes. Writing a new tool involves * subclassing ToolBase. */ -class ToolBase { +class ToolBase + : public sigc::trackable +{ public: void enableSelectionCue (bool enable=true); void enableGrDrag (bool enable=true); -- cgit v1.2.3 From 6ef6a1f8505298a969ddbdbf577678fead2b9dbb Mon Sep 17 00:00:00 2001 From: Nicolas Dufour Date: Thu, 6 Mar 2014 17:07:00 +0100 Subject: Fix for Bug #1288401 (Hovering in symbols dialog over symbols with ampersand in description result in console warning). Fixed bugs: - https://launchpad.net/bugs/1288401 (bzr r13122) --- src/ui/dialog/symbols.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/ui') diff --git a/src/ui/dialog/symbols.cpp b/src/ui/dialog/symbols.cpp index 62a2f8572..9479430d2 100644 --- a/src/ui/dialog/symbols.cpp +++ b/src/ui/dialog/symbols.cpp @@ -687,7 +687,7 @@ void SymbolsDialog::add_symbol( SPObject* symbol ) { if( pixbuf ) { Gtk::ListStore::iterator row = store->append(); (*row)[columns->symbol_id] = Glib::ustring( id ); - (*row)[columns->symbol_title] = Glib::ustring( g_dpgettext2(NULL, "Symbol", title) ); + (*row)[columns->symbol_title] = Glib::Markup::escape_text(Glib::ustring( g_dpgettext2(NULL, "Symbol", title) )); (*row)[columns->symbol_image] = pixbuf; } -- cgit v1.2.3 From 05626af9add3d277c847ae695488fba4e871733b Mon Sep 17 00:00:00 2001 From: Nicolas Dufour Date: Fri, 7 Mar 2014 17:59:44 +0100 Subject: Symbols. Adding missing include. (bzr r13126) --- src/ui/dialog/symbols.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/ui') diff --git a/src/ui/dialog/symbols.cpp b/src/ui/dialog/symbols.cpp index 9479430d2..8e0d085a4 100644 --- a/src/ui/dialog/symbols.cpp +++ b/src/ui/dialog/symbols.cpp @@ -39,7 +39,7 @@ #include #include #include - +#include #include #include "path-prefix.h" #include "io/sys.h" -- cgit v1.2.3 From 19d4e1aa3f982b4b841c76eed22491a3a63084cb Mon Sep 17 00:00:00 2001 From: "Jon A. Cruz" Date: Fri, 7 Mar 2014 19:14:20 -0800 Subject: Reconnect correctly as documents are replaced. Removed hardcoding to only a single panel. (bzr r13127) --- src/ui/dialog/undo-history.cpp | 130 +++++++++++++++++++++++++++++------------ src/ui/dialog/undo-history.h | 11 +++- 2 files changed, 103 insertions(+), 38 deletions(-) (limited to 'src/ui') diff --git a/src/ui/dialog/undo-history.cpp b/src/ui/dialog/undo-history.cpp index a487eb930..2412c3ec9 100644 --- a/src/ui/dialog/undo-history.cpp +++ b/src/ui/dialog/undo-history.cpp @@ -5,8 +5,9 @@ /* Author: * Gustav Broberg * Abhishek Sharma + * Jon A. Cruz * - * Copyright (C) 2006 Authors + * Copyright (C) 2014 Authors * Released under GNU GPL. Read the file 'COPYING' for more information. */ @@ -24,6 +25,7 @@ #include "inkscape.h" #include "verbs.h" #include "desktop-handles.h" +#include "util/signal-blocker.h" #include "desktop.h" #include @@ -131,39 +133,19 @@ UndoHistory& UndoHistory::getInstance() return *new UndoHistory(); } -void -UndoHistory::setDesktop(SPDesktop* desktop) -{ - Panel::setDesktop(desktop); - - if (!desktop) return; - - _document = sp_desktop_document(desktop); - - _event_log = desktop->event_log; - - _callback_connections[EventLog::CALLB_SELECTION_CHANGE].block(); - - _event_list_store = _event_log->getEventListStore(); - _event_list_view.set_model(_event_list_store); - _event_list_selection = _event_list_view.get_selection(); - - _event_log->connectWithDialog(&_event_list_view, &_callback_connections); - _event_list_view.scroll_to_row(_event_list_store->get_path(_event_list_selection->get_selected())); - - _callback_connections[EventLog::CALLB_SELECTION_CHANGE].block(false); -} - UndoHistory::UndoHistory() : UI::Widget::Panel ("", "/dialogs/undo-history", SP_VERB_DIALOG_UNDO_HISTORY), - _document (sp_desktop_document(getDesktop())), - _event_log (getDesktop() ? getDesktop()->event_log : NULL), - _columns (_event_log ? &_event_log->getColumns() : NULL), - _event_list_selection (_event_list_view.get_selection()), - _desktop(NULL), + _document_replaced_connection(), + _desktop(getDesktop()), + _document(_desktop ? _desktop->doc() : NULL), + _event_log(_desktop ? _desktop->event_log : NULL), + _columns(_event_log ? &_event_log->getColumns() : NULL), + _scrolled_window(), + _event_list_store(), + _event_list_selection(_event_list_view.get_selection()), _deskTrack(), - _desktopChangeConn() - + _desktopChangeConn(), + _callback_connections() { if ( !_document || !_event_log || !_columns ) return; @@ -172,9 +154,9 @@ UndoHistory::UndoHistory() _getContents()->pack_start(_scrolled_window); _scrolled_window.set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC); - _event_list_store = _event_log->getEventListStore(); + // connect with the EventLog + _connectEventLog(); - _event_list_view.set_model(_event_list_store); _event_list_view.set_rules_hint(false); _event_list_view.set_enable_search(false); _event_list_view.set_headers_visible(false); @@ -221,12 +203,12 @@ UndoHistory::UndoHistory() _callback_connections[EventLog::CALLB_COLLAPSE] = _event_list_view.signal_row_collapsed().connect(sigc::mem_fun(*this, &Inkscape::UI::Dialog::UndoHistory::_onCollapseEvent)); - // connect with the EventLog - _event_log->connectWithDialog(&_event_list_view, &_callback_connections); - _desktopChangeConn = _deskTrack.connectDesktopChanged( sigc::mem_fun(*this, &UndoHistory::setDesktop) ); _deskTrack.connect(GTK_WIDGET(gobj())); + // connect to be informed of document changes + signalDocumentReplaced().connect(sigc::mem_fun(*this, &UndoHistory::_handleDocumentReplaced)); + show_all_children(); // scroll to the selected row @@ -239,6 +221,82 @@ UndoHistory::~UndoHistory() } +void UndoHistory::setDesktop(SPDesktop* desktop) +{ + Panel::setDesktop(desktop); + + EventLog *newEventLog = desktop ? desktop->event_log : NULL; + if ((_desktop == desktop) && (_event_log == newEventLog)) { + // same desktop set + } + else + { + _connectDocument(desktop, desktop ? desktop->doc() : NULL); + } +} + +void UndoHistory::_connectDocument(SPDesktop* desktop, SPDocument *document) +{ + // disconnect from prior + if (_event_log) { + _event_log->removeDialogConnection(&_event_list_view, &_callback_connections); + } + + SignalBlocker blocker(&_callback_connections[EventLog::CALLB_SELECTION_CHANGE]); + + _event_list_view.unset_model(); + + // connect to new EventLog/Desktop + _desktop = desktop; + _event_log = desktop ? desktop->event_log : NULL; + _document = desktop ? desktop->doc() : NULL; + _connectEventLog(); +} + +void UndoHistory::_connectEventLog() +{ + if (_event_log) { + _event_log->add_destroy_notify_callback(this, &_handleEventLogDestroyCB); + _event_list_store = _event_log->getEventListStore(); + + _event_list_view.set_model(_event_list_store); + + _event_log->addDialogConnection(&_event_list_view, &_callback_connections); + _event_list_view.scroll_to_row(_event_list_store->get_path(_event_list_selection->get_selected())); + } +} + +void UndoHistory::_handleDocumentReplaced(SPDesktop* desktop, SPDocument *document) +{ + if ((desktop != _desktop) || (document != _document)) { + _connectDocument(desktop, document); + } +} + +void *UndoHistory::_handleEventLogDestroyCB(void *data) +{ + void *result = NULL; + if (data) { + UndoHistory *self = reinterpret_cast(data); + result = self->_handleEventLogDestroy(); + } + return result; +} + +// called *after* _event_log has been destroyed. +void *UndoHistory::_handleEventLogDestroy() +{ + if (_event_log) { + SignalBlocker blocker(&_callback_connections[EventLog::CALLB_SELECTION_CHANGE]); + + _event_list_view.unset_model(); + _event_list_store.reset(); + _event_log = NULL; + } + + return NULL; +} + void UndoHistory::_onListSelectionChange() { diff --git a/src/ui/dialog/undo-history.h b/src/ui/dialog/undo-history.h index adf4f1936..b0cc283cf 100644 --- a/src/ui/dialog/undo-history.h +++ b/src/ui/dialog/undo-history.h @@ -3,8 +3,9 @@ */ /* Author: * Gustav Broberg + * Jon A. Cruz * - * Copyright (C) 2006 Authors + * Copyright (C) 2014 Authors * Released under GNU GPL. Read the file 'COPYING' for more information. */ @@ -134,6 +135,7 @@ public: protected: + SPDesktop *_desktop; SPDocument *_document; EventLog *_event_log; @@ -146,12 +148,17 @@ protected: Gtk::TreeView _event_list_view; Glib::RefPtr _event_list_selection; - SPDesktop *_desktop; DesktopTracker _deskTrack; sigc::connection _desktopChangeConn; EventLog::CallbackMap _callback_connections; + static void *_handleEventLogDestroyCB(void *data); + + void _connectDocument(SPDesktop* desktop, SPDocument *document); + void _connectEventLog(); + void _handleDocumentReplaced(SPDesktop* desktop, SPDocument *document); + void *_handleEventLogDestroy(); void _onListSelectionChange(); void _onExpandEvent(const Gtk::TreeModel::iterator &iter, const Gtk::TreeModel::Path &path); void _onCollapseEvent(const Gtk::TreeModel::iterator &iter, const Gtk::TreeModel::Path &path); -- cgit v1.2.3 From cf86d4abd17be00d1d148258053d9a1193e3c93d Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Sat, 8 Mar 2014 17:02:21 +0100 Subject: Fix crashes caused by the desktop's query_style signal being called before the selection's changed signal was processed in the text tool. Also fix similar crashes in the gradient dragger. Fixes LP #1271004. Fixed bugs: - https://launchpad.net/bugs/1271004 (bzr r13129) --- src/ui/tools/text-tool.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/ui') diff --git a/src/ui/tools/text-tool.cpp b/src/ui/tools/text-tool.cpp index bf37937c4..ac830fe6b 100644 --- a/src/ui/tools/text-tool.cpp +++ b/src/ui/tools/text-tool.cpp @@ -180,10 +180,10 @@ void TextTool::setup() { this->shape_editor->set_item(item, SH_KNOTHOLDER); } - this->sel_changed_connection = sp_desktop_selection(desktop)->connectChanged( + this->sel_changed_connection = sp_desktop_selection(desktop)->connectChangedFirst( sigc::mem_fun(*this, &TextTool::_selectionChanged) ); - this->sel_modified_connection = sp_desktop_selection(desktop)->connectModified( + this->sel_modified_connection = sp_desktop_selection(desktop)->connectModifiedFirst( sigc::mem_fun(*this, &TextTool::_selectionModified) ); this->style_set_connection = desktop->connectSetStyle( -- cgit v1.2.3 From 6f85c82ab5114e8cc97702ea8ab33e58b68a2163 Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Sun, 9 Mar 2014 03:35:00 +0100 Subject: Fix random crashes when spraying in single path mode. Fixes LP bug #1274831 Fixed bugs: - https://launchpad.net/bugs/1274831 (bzr r13131) --- src/ui/tools/spray-tool.cpp | 4 ++-- src/ui/tools/tool-base.cpp | 28 ++++++++++++++++++++++------ src/ui/tools/tool-base.h | 4 +++- 3 files changed, 27 insertions(+), 9 deletions(-) (limited to 'src/ui') diff --git a/src/ui/tools/spray-tool.cpp b/src/ui/tools/spray-tool.cpp index e43b6575e..08d3119a1 100644 --- a/src/ui/tools/spray-tool.cpp +++ b/src/ui/tools/spray-tool.cpp @@ -82,7 +82,7 @@ using namespace std; // Disabled in 0.91 because of Bug #1274831 (crash, spraying an object // with the mode: spray object in single path) // Please enable again when working on 1.0 -//#define ENABLE_SPRAY_MODE_SINGLE_PATH +#define ENABLE_SPRAY_MODE_SINGLE_PATH #include "tool-factory.h" @@ -140,7 +140,7 @@ static void sp_spray_scale_rel(Geom::Point c, SPDesktop */*desktop*/, SPItem *it } SprayTool::SprayTool() - : ToolBase(cursor_spray_xpm, 4, 4) + : ToolBase(cursor_spray_xpm, 4, 4, false) , pressure(TC_DEFAULT_PRESSURE) , dragging(false) , usepressure(0) diff --git a/src/ui/tools/tool-base.cpp b/src/ui/tools/tool-base.cpp index 45b519fb4..752053be1 100644 --- a/src/ui/tools/tool-base.cpp +++ b/src/ui/tools/tool-base.cpp @@ -90,7 +90,7 @@ SPDesktop const& ToolBase::getDesktop() const { return *desktop; } -ToolBase::ToolBase(gchar const *const *cursor_shape, gint hot_x, gint hot_y) +ToolBase::ToolBase(gchar const *const *cursor_shape, gint hot_x, gint hot_y, bool uses_snap) : pref_observer(NULL) , cursor(NULL) , xp(0) @@ -106,6 +106,7 @@ ToolBase::ToolBase(gchar const *const *cursor_shape, gint hot_x, gint hot_y) , _delayed_snap_event(NULL) , _dse_callback_in_process(false) , desktop(NULL) + , _uses_snap(uses_snap) , cursor_shape(cursor_shape) , hot_x(hot_x) , hot_y(hot_y) @@ -384,7 +385,9 @@ bool ToolBase::root_handler(GdkEvent* event) { case 1: if (this->space_panning) { // When starting panning, make sure there are no snap events pending because these might disable the panning again - sp_event_context_discard_delayed_snap_event(this); + if (_uses_snap) { + sp_event_context_discard_delayed_snap_event(this); + } panning = 1; sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate), @@ -402,7 +405,9 @@ bool ToolBase::root_handler(GdkEvent* event) { zoom_rb = 2; } else { // When starting panning, make sure there are no snap events pending because these might disable the panning again - sp_event_context_discard_delayed_snap_event(this); + if (_uses_snap) { + sp_event_context_discard_delayed_snap_event(this); + } panning = 2; sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate), @@ -418,7 +423,9 @@ bool ToolBase::root_handler(GdkEvent* event) { case 3: if ((event->button.state & GDK_SHIFT_MASK) || (event->button.state & GDK_CONTROL_MASK)) { // When starting panning, make sure there are no snap events pending because these might disable the panning again - sp_event_context_discard_delayed_snap_event(this); + if (_uses_snap) { + sp_event_context_discard_delayed_snap_event(this); + } panning = 3; sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate), @@ -946,6 +953,10 @@ void sp_event_context_read(ToolBase *ec, gchar const *key) { gint sp_event_context_root_handler(ToolBase * event_context, GdkEvent * event) { + if (!event_context->_uses_snap) { + return sp_event_context_virtual_root_handler(event_context, event); + } + switch (event->type) { case GDK_MOTION_NOTIFY: sp_event_context_snap_delay_handler(event_context, NULL, NULL, @@ -995,7 +1006,12 @@ gint sp_event_context_virtual_root_handler(ToolBase * event_context, GdkEvent * * Calls virtual item_handler(), the item event handling function. */ gint sp_event_context_item_handler(ToolBase * event_context, - SPItem * item, GdkEvent * event) { + SPItem * item, GdkEvent * event) +{ + if (!event_context->_uses_snap) { + return sp_event_context_virtual_item_handler(event_context, item, event); + } + switch (event->type) { case GDK_MOTION_NOTIFY: sp_event_context_snap_delay_handler(event_context, (gpointer) item, NULL, (GdkEventMotion *) event, DelayedSnapEvent::EVENTCONTEXT_ITEM_HANDLER); @@ -1232,7 +1248,7 @@ void sp_event_context_snap_delay_handler(ToolBase *ec, static guint32 prev_time; static boost::optional prev_pos; - if (ec->_dse_callback_in_process) { + if (!ec->_uses_snap || ec->_dse_callback_in_process) { return; } diff --git a/src/ui/tools/tool-base.h b/src/ui/tools/tool-base.h index eb8908f3e..def6e3d91 100644 --- a/src/ui/tools/tool-base.h +++ b/src/ui/tools/tool-base.h @@ -113,7 +113,7 @@ public: void enableGrDrag (bool enable=true); bool deleteSelectedDrag(bool just_one); - ToolBase(gchar const *const *cursor_shape, gint hot_x, gint hot_y); + ToolBase(gchar const *const *cursor_shape, gint hot_x, gint hot_y, bool uses_snap = true); virtual ~ToolBase(); @@ -181,6 +181,7 @@ public: void sp_event_context_update_cursor(); SPDesktop *desktop; + bool _uses_snap; // TODO: make protected or private protected: /// An xpm containing the shape of the tool's cursor. @@ -188,6 +189,7 @@ protected: /// The cursor's hot spot gint hot_x, hot_y; + /// Whether the tool should receive delayed snap events bool sp_event_context_knot_mouseover() const; -- cgit v1.2.3 From eb89a74bb3f220bba82de3c7ce3a73df951fab77 Mon Sep 17 00:00:00 2001 From: Martin Owens Date: Sat, 8 Mar 2014 22:44:03 -0500 Subject: Remove unused includes to tidy up the code. (bzr r13132) --- src/ui/widget/filter-effect-chooser.h | 1 - src/ui/widget/style-swatch.h | 1 - 2 files changed, 2 deletions(-) (limited to 'src/ui') diff --git a/src/ui/widget/filter-effect-chooser.h b/src/ui/widget/filter-effect-chooser.h index 6f0c2f26e..8d2389b15 100644 --- a/src/ui/widget/filter-effect-chooser.h +++ b/src/ui/widget/filter-effect-chooser.h @@ -25,7 +25,6 @@ #include "combo-enums.h" #include "filter-enums.h" -#include "spin-slider.h" #include "spin-scale.h" namespace Inkscape { diff --git a/src/ui/widget/style-swatch.h b/src/ui/widget/style-swatch.h index 6da58a2dd..23ecbdfda 100644 --- a/src/ui/widget/style-swatch.h +++ b/src/ui/widget/style-swatch.h @@ -27,7 +27,6 @@ #include #include "desktop.h" -#include "button.h" #include "preferences.h" struct SPStyle; -- cgit v1.2.3 From e7a3f5b74d1f5a95390ee95b06371d184c1812f7 Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Thu, 13 Mar 2014 05:45:38 +0100 Subject: Provide a toggle in the document properties to optionally turn off antialiasing for display and export. Fixes a nearly 10 year old bug #170356 Fixed bugs: - https://launchpad.net/bugs/170356 (bzr r13144) --- src/ui/dialog/document-properties.cpp | 19 +++++++++++-------- src/ui/dialog/document-properties.h | 1 + 2 files changed, 12 insertions(+), 8 deletions(-) (limited to 'src/ui') diff --git a/src/ui/dialog/document-properties.cpp b/src/ui/dialog/document-properties.cpp index 0411c789c..ef7c9ee1d 100644 --- a/src/ui/dialog/document-properties.cpp +++ b/src/ui/dialog/document-properties.cpp @@ -106,6 +106,7 @@ DocumentProperties::DocumentProperties() _page_metadata1(Gtk::manage(new UI::Widget::NotebookPage(1, 1))), _page_metadata2(Gtk::manage(new UI::Widget::NotebookPage(1, 1))), //--------------------------------------------------------------- + _rcb_antialias(_("Use antialiasing"), _("If unset, no antialiasing will be done on the drawing"), "inkscape:antialiasing", _wr, false), _rcb_canb(_("Show page _border"), _("If set, rectangular page border is shown"), "showborder", _wr, false), _rcb_bord(_("Border on _top of drawing"), _("If set, border is always on top of the drawing"), "borderlayer", _wr, false), _rcb_shad(_("_Show border shadow"), _("If set, page border shows a shadow on its right and lower side"), "inkscape:showpageshadow", _wr, false), @@ -239,7 +240,8 @@ inline void attach_all(Gtk::Table &table, Gtk::Widget *const arr[], unsigned con yoptions = Gtk::FILL|Gtk::EXPAND; } if (docum_prop_flag) { - if( i==(n-4) || i==(n-6) ) { + // this sets the padding for subordinate widgets on the "Page" page + if( i==(n-8) || i==(n-10) ) { #if WITH_GTKMM_3_0 arr[i+1]->set_hexpand(); arr[i+1]->set_margin_left(20); @@ -316,28 +318,28 @@ void DocumentProperties::build_page() Gtk::Label* label_gen = manage (new Gtk::Label); label_gen->set_markup (_("General")); - Gtk::Label* label_col = manage (new Gtk::Label); - label_col->set_markup (_("Color")); - Gtk::Label* label_bor = manage (new Gtk::Label); - label_bor->set_markup (_("Border")); Gtk::Label *label_for = manage (new Gtk::Label); label_for->set_markup (_("Page Size")); + Gtk::Label* label_dsp = manage (new Gtk::Label); + label_dsp->set_markup (_("Display")); _page_sizer.init(); Gtk::Widget *const widget_array[] = { label_gen, 0, 0, &_rum_deflt, - label_col, 0, - _rcp_bg._label, &_rcp_bg, + //label_col, 0, + //_rcp_bg._label, &_rcp_bg, 0, 0, label_for, 0, 0, &_page_sizer, 0, 0, - label_bor, 0, + label_dsp, 0, 0, &_rcb_canb, 0, &_rcb_bord, 0, &_rcb_shad, + 0, &_rcb_antialias, + _rcp_bg._label, &_rcp_bg, _rcp_bord._label, &_rcp_bord, }; @@ -1472,6 +1474,7 @@ void DocumentProperties::update() _rcb_bord.setActive (nv->borderlayer == SP_BORDER_LAYER_TOP); _rcp_bord.setRgba32 (nv->bordercolor); _rcb_shad.setActive (nv->showpageshadow); + _rcb_antialias.setActive(nv->antialiasing); if (nv->doc_units) { _rum_deflt.setUnit (nv->doc_units->abbr); diff --git a/src/ui/dialog/document-properties.h b/src/ui/dialog/document-properties.h index e3ca91731..495f3177d 100644 --- a/src/ui/dialog/document-properties.h +++ b/src/ui/dialog/document-properties.h @@ -117,6 +117,7 @@ protected: UI::Widget::Registry _wr; //--------------------------------------------------------------- + UI::Widget::RegisteredCheckButton _rcb_antialias; UI::Widget::RegisteredCheckButton _rcb_canb; UI::Widget::RegisteredCheckButton _rcb_bord; UI::Widget::RegisteredCheckButton _rcb_shad; -- cgit v1.2.3 From 32ef25632164e5af8766a5364400b579edde4ebf Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Thu, 13 Mar 2014 23:37:07 +0100 Subject: Reimplement global aliasing toggle as a 'shape-rendering' property on the root element. (bzr r13146) --- src/ui/dialog/document-properties.cpp | 8 ++++++-- src/ui/widget/registered-widget.cpp | 6 ++++-- src/ui/widget/registered-widget.h | 8 +++++++- 3 files changed, 17 insertions(+), 5 deletions(-) (limited to 'src/ui') diff --git a/src/ui/dialog/document-properties.cpp b/src/ui/dialog/document-properties.cpp index ef7c9ee1d..a31ab1a09 100644 --- a/src/ui/dialog/document-properties.cpp +++ b/src/ui/dialog/document-properties.cpp @@ -35,6 +35,7 @@ #include "sp-namedview.h" #include "sp-root.h" #include "sp-script.h" +#include "style.h" #include "svg/stringstream.h" #include "tools-switch.h" #include "ui/widget/color-picker.h" @@ -106,7 +107,7 @@ DocumentProperties::DocumentProperties() _page_metadata1(Gtk::manage(new UI::Widget::NotebookPage(1, 1))), _page_metadata2(Gtk::manage(new UI::Widget::NotebookPage(1, 1))), //--------------------------------------------------------------- - _rcb_antialias(_("Use antialiasing"), _("If unset, no antialiasing will be done on the drawing"), "inkscape:antialiasing", _wr, false), + _rcb_antialias(_("Use antialiasing"), _("If unset, no antialiasing will be done on the drawing"), "shape-rendering", _wr, false, NULL, NULL, NULL, "crispEdges"), _rcb_canb(_("Show page _border"), _("If set, rectangular page border is shown"), "showborder", _wr, false), _rcb_bord(_("Border on _top of drawing"), _("If set, border is always on top of the drawing"), "borderlayer", _wr, false), _rcb_shad(_("_Show border shadow"), _("If set, page border shows a shadow on its right and lower side"), "inkscape:showpageshadow", _wr, false), @@ -1474,7 +1475,10 @@ void DocumentProperties::update() _rcb_bord.setActive (nv->borderlayer == SP_BORDER_LAYER_TOP); _rcp_bord.setRgba32 (nv->bordercolor); _rcb_shad.setActive (nv->showpageshadow); - _rcb_antialias.setActive(nv->antialiasing); + + SPRoot *root = dt->getDocument()->getRoot(); + _rcb_antialias.set_xml_target(root->getRepr(), dt->getDocument()); + _rcb_antialias.setActive(root->style->shape_rendering.computed != SP_CSS_SHAPE_RENDERING_CRISPEDGES); if (nv->doc_units) { _rum_deflt.setUnit (nv->doc_units->abbr); diff --git a/src/ui/widget/registered-widget.cpp b/src/ui/widget/registered-widget.cpp index ae6a7d1e0..175f6471c 100644 --- a/src/ui/widget/registered-widget.cpp +++ b/src/ui/widget/registered-widget.cpp @@ -49,8 +49,10 @@ RegisteredCheckButton::~RegisteredCheckButton() _toggled_connection.disconnect(); } -RegisteredCheckButton::RegisteredCheckButton (const Glib::ustring& label, const Glib::ustring& tip, const Glib::ustring& key, Registry& wr, bool right, Inkscape::XML::Node* repr_in, SPDocument *doc_in) +RegisteredCheckButton::RegisteredCheckButton (const Glib::ustring& label, const Glib::ustring& tip, const Glib::ustring& key, Registry& wr, bool right, Inkscape::XML::Node* repr_in, SPDocument *doc_in, char const *active_str, char const *inactive_str) : RegisteredWidget() + , _active_str(active_str) + , _inactive_str(inactive_str) { init_parent(key, wr, repr_in, doc_in); @@ -88,7 +90,7 @@ RegisteredCheckButton::on_toggled() return; _wr->setUpdating (true); - write_to_xml(get_active() ? "true" : "false"); + write_to_xml(get_active() ? _active_str : _inactive_str); //The slave button is greyed out if the master button is unchecked for (std::list::const_iterator i = _slavewidgets.begin(); i != _slavewidgets.end(); ++i) { (*i)->set_sensitive(get_active()); diff --git a/src/ui/widget/registered-widget.h b/src/ui/widget/registered-widget.h index 883a9e1a2..d64c09c16 100644 --- a/src/ui/widget/registered-widget.h +++ b/src/ui/widget/registered-widget.h @@ -55,6 +55,11 @@ public: event_description = _event_description; write_undo = true; } + void set_xml_target(Inkscape::XML::Node *xml_node, SPDocument *document) + { + repr = xml_node; + doc = document; + } bool is_updating() {if (_wr) return _wr->isUpdating(); else return false;} @@ -136,7 +141,7 @@ private: class RegisteredCheckButton : public RegisteredWidget { public: virtual ~RegisteredCheckButton(); - RegisteredCheckButton (const Glib::ustring& label, const Glib::ustring& tip, const Glib::ustring& key, Registry& wr, bool right=true, Inkscape::XML::Node* repr_in=NULL, SPDocument *doc_in=NULL); + RegisteredCheckButton (const Glib::ustring& label, const Glib::ustring& tip, const Glib::ustring& key, Registry& wr, bool right=true, Inkscape::XML::Node* repr_in=NULL, SPDocument *doc_in=NULL, char const *active_str = "true", char const *inactive_str = "false"); void setActive (bool); @@ -153,6 +158,7 @@ public: // if a callback checks it, it must reset it back to false protected: + char const *_active_str, *_inactive_str; sigc::connection _toggled_connection; void on_toggled(); }; -- cgit v1.2.3 From 32457e67afc4fbf99da57dcb32ec9a730a5b7901 Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Sat, 15 Mar 2014 05:07:04 +0100 Subject: Make the Object Properties dialog code adhere to the coding style. (bzr r13153) --- src/ui/dialog/object-properties.cpp | 544 ++++++++++++++++++------------------ src/ui/dialog/object-properties.h | 126 +++------ 2 files changed, 320 insertions(+), 350 deletions(-) (limited to 'src/ui') diff --git a/src/ui/dialog/object-properties.cpp b/src/ui/dialog/object-properties.cpp index 82b2cf6b1..c07f39819 100644 --- a/src/ui/dialog/object-properties.cpp +++ b/src/ui/dialog/object-properties.cpp @@ -28,9 +28,9 @@ #include "object-properties.h" #include "widgets/sp-attribute-widget.h" -#include "../../desktop-handles.h" -#include "../../document.h" -#include "../../document-undo.h" +#include "desktop-handles.h" +#include "document.h" +#include "document-undo.h" #include "verbs.h" #include "inkscape.h" #include "selection.h" @@ -51,481 +51,482 @@ namespace Inkscape { namespace UI { namespace Dialog { -ObjectProperties::ObjectProperties (void) : - UI::Widget::Panel ("", "/dialogs/object/", SP_VERB_DIALOG_ITEM), - blocked (false), - CurrentItem(NULL), -#if WITH_GTKMM_3_0 - TopTable(Gtk::manage(new Gtk::Grid())), -#else - TopTable(Gtk::manage(new Gtk::Table(4, 4))), -#endif - LabelID(_("_ID:"), 1), - LabelLabel(_("_Label:"), 1), - LabelTitle(_("_Title:"),1), - LabelImageRendering(_("_Image Rendering:"),1), - LabelDescription(_("_Description:"),1), - FrameDescription("", FALSE), - HBoxCheck(FALSE, 0), -#if WITH_GTKMM_3_0 - CheckTable(Gtk::manage(new Gtk::Grid())), -#else - CheckTable(Gtk::manage(new Gtk::Table(1, 2, true))), -#endif - CBHide(_("_Hide"), 1), - CBLock(_("L_ock"), 1), - BSet (_("_Set"), 1), - LabelInteractivity(_("_Interactivity"), 1), - attrTable(Gtk::manage(new SPAttributeTable())), - desktop(NULL), - deskTrack(), - selectChangedConn(), - subselChangedConn() +ObjectProperties::ObjectProperties() + : UI::Widget::Panel ("", "/dialogs/object/", SP_VERB_DIALOG_ITEM) + , _blocked (false) + , _current_item(NULL) + , _label_id(_("_ID:"), 1) + , _label_label(_("_Label:"), 1) + , _label_title(_("_Title:"), 1) + , _label_image_rendering(_("_Image Rendering:"), 1) + , _cb_hide(_("_Hide"), 1) + , _cb_lock(_("L_ock"), 1) + , _attr_table(Gtk::manage(new SPAttributeTable())) + , _desktop(NULL) { //initialize labels for the table at the bottom of the dialog - int_attrs.push_back("onclick"); - int_attrs.push_back("onmouseover"); - int_attrs.push_back("onmouseout"); - int_attrs.push_back("onmousedown"); - int_attrs.push_back("onmouseup"); - int_attrs.push_back("onmousemove"); - int_attrs.push_back("onfocusin"); - int_attrs.push_back("onfocusout"); - int_attrs.push_back("onload"); - - int_labels.push_back("onclick:"); - int_labels.push_back("onmouseover:"); - int_labels.push_back("onmouseout:"); - int_labels.push_back("onmousedown:"); - int_labels.push_back("onmouseup:"); - int_labels.push_back("onmousemove:"); - int_labels.push_back("onfocusin:"); - int_labels.push_back("onfocusout:"); - int_labels.push_back("onload:"); - - desktopChangeConn = deskTrack.connectDesktopChanged( sigc::mem_fun(*this, &ObjectProperties::setTargetDesktop) ); - deskTrack.connect(GTK_WIDGET(gobj())); + _int_attrs.push_back("onclick"); + _int_attrs.push_back("onmouseover"); + _int_attrs.push_back("onmouseout"); + _int_attrs.push_back("onmousedown"); + _int_attrs.push_back("onmouseup"); + _int_attrs.push_back("onmousemove"); + _int_attrs.push_back("onfocusin"); + _int_attrs.push_back("onfocusout"); + _int_attrs.push_back("onload"); + + _int_labels.push_back("onclick:"); + _int_labels.push_back("onmouseover:"); + _int_labels.push_back("onmouseout:"); + _int_labels.push_back("onmousedown:"); + _int_labels.push_back("onmouseup:"); + _int_labels.push_back("onmousemove:"); + _int_labels.push_back("onfocusin:"); + _int_labels.push_back("onfocusout:"); + _int_labels.push_back("onload:"); + + _desktop_changed_connection = _desktop_tracker.connectDesktopChanged( + sigc::mem_fun(*this, &ObjectProperties::_setTargetDesktop) + ); + _desktop_tracker.connect(GTK_WIDGET(gobj())); #if WITH_GTKMM_3_0 CheckTable->set_row_homogeneous(); CheckTable->set_column_homogeneous(true); #endif - MakeWidget(); + _init(); } -ObjectProperties::~ObjectProperties (void) +ObjectProperties::~ObjectProperties() { - subselChangedConn.disconnect(); - selectChangedConn.disconnect(); - desktopChangeConn.disconnect(); - deskTrack.disconnect(); + _subselection_changed_connection.disconnect(); + _selection_changed_connection.disconnect(); + _desktop_changed_connection.disconnect(); + _desktop_tracker.disconnect(); } -void ObjectProperties::MakeWidget(void) +void ObjectProperties::_init() { Gtk::Box *contents = _getContents(); contents->set_spacing(0); - - TopTable->set_border_width(4); #if WITH_GTKMM_3_0 - TopTable->set_row_spacing(4); - TopTable->set_column_spacing(0); + Gtk::Grid *grid_top = Gtk::manage(new Gtk::Grid()); + grid_top->set_row_spacing(4); + grid_top->set_column_spacing(0); #else - TopTable->set_row_spacings(4); - TopTable->set_col_spacings(0); + Gtk::Table *grid_top = Gtk::manage(new Gtk::Table(4, 4)); + grid_top->set_row_spacings(4); + grid_top->set_col_spacings(0); #endif - contents->pack_start (*TopTable, false, false, 0); + grid_top->set_border_width(4); + + contents->pack_start(*grid_top, false, false, 0); + /* Create the label for the object id */ - LabelID.set_label (LabelID.get_label() + " "); - LabelID.set_alignment (1, 0.5); + _label_id.set_label(_label_id.get_label() + " "); + _label_id.set_alignment(1, 0.5); #if WITH_GTKMM_3_0 - LabelID.set_valign(Gtk::ALIGN_CENTER); - TopTable->attach(LabelID, 0, 0, 1, 1); + _label_id.set_valign(Gtk::ALIGN_CENTER); + grid_top->attach(_label_id, 0, 0, 1, 1); #else - TopTable->attach(LabelID, 0, 1, 0, 1, - Gtk::SHRINK | Gtk::FILL, - Gtk::AttachOptions(), 0, 0 ); + grid_top->attach(_label_id, 0, 1, 0, 1, + Gtk::SHRINK | Gtk::FILL, + Gtk::AttachOptions(), 0, 0 ); #endif + /* Create the entry box for the object id */ - EntryID.set_tooltip_text (_("The id= attribute (only letters, digits, and the characters .-_: allowed)")); - EntryID.set_max_length (64); + _entry_id.set_tooltip_text(_("The id= attribute (only letters, digits, and the characters .-_: allowed)")); + _entry_id.set_max_length(64); #if WITH_GTKMM_3_0 - EntryID.set_valign(Gtk::ALIGN_CENTER); - TopTable->attach(EntryID, 1, 0, 1, 1); + _entry_id.set_valign(Gtk::ALIGN_CENTER); + grid_top->attach(_entry_id, 1, 0, 1, 1); #else - TopTable->attach(EntryID, 1, 2, 0, 1, + grid_top->attach(_entry_id, 1, 2, 0, 1, Gtk::EXPAND | Gtk::FILL, Gtk::AttachOptions(), 0, 0 ); #endif - LabelID.set_mnemonic_widget (EntryID); + _label_id.set_mnemonic_widget(_entry_id); // pressing enter in the id field is the same as clicking Set: - EntryID.signal_activate().connect(sigc::mem_fun(this, &ObjectProperties::label_changed)); + _entry_id.signal_activate().connect(sigc::mem_fun(this, &ObjectProperties::_labelChanged)); // focus is in the id field initially: - EntryID.grab_focus(); + _entry_id.grab_focus(); + /* Create the label for the object label */ - LabelLabel.set_label (LabelLabel.get_label() + " "); - LabelLabel.set_alignment (1, 0.5); + _label_label.set_label(_label_label.get_label() + " "); + _label_label.set_alignment(1, 0.5); #if WITH_GTKMM_3_0 - LabelLabel.set_valign(Gtk::ALIGN_CENTER); - TopTable->attach(LabelLabel, 0, 1, 1, 1); + _label_label.set_valign(Gtk::ALIGN_CENTER); + grid_top->attach(_label_label, 0, 1, 1, 1); #else - TopTable->attach(LabelLabel, 0, 1, 1, 2, + grid_top->attach(_label_label, 0, 1, 1, 2, Gtk::SHRINK | Gtk::FILL, Gtk::AttachOptions(), 0, 0 ); #endif + /* Create the entry box for the object label */ - EntryLabel.set_tooltip_text (_("A freeform label for the object")); - EntryLabel.set_max_length (256); + _entry_label.set_tooltip_text(_("A freeform label for the object")); + _entry_label.set_max_length(256); #if WITH_GTKMM_3_0 - EntryLabel.set_hexpand(); - EntryLabel.set_valign(Gtk::ALIGN_CENTER); - TopTable->attach(EntryLabel, 1, 1, 1, 1); + _entry_label.set_hexpand(); + _entry_label.set_valign(Gtk::ALIGN_CENTER); + grid_top->attach(_entry_label, 1, 1, 1, 1); #else - TopTable->attach(EntryLabel, 1, 2, 1, 2, + grid_top->attach(_entry_label, 1, 2, 1, 2, Gtk::EXPAND | Gtk::FILL, Gtk::AttachOptions(), 0, 0 ); #endif - LabelLabel.set_mnemonic_widget (EntryLabel); + _label_label.set_mnemonic_widget(_entry_label); // pressing enter in the label field is the same as clicking Set: - EntryLabel.signal_activate().connect(sigc::mem_fun(this, &ObjectProperties::label_changed)); + _entry_label.signal_activate().connect(sigc::mem_fun(this, &ObjectProperties::_labelChanged)); + /* Create the label for the object title */ - LabelTitle.set_label (LabelTitle.get_label() + " "); - LabelTitle.set_alignment (1, 0.5); + _label_title.set_label(_label_title.get_label() + " "); + _label_title.set_alignment (1, 0.5); #if WITH_GTKMM_3_0 - LabelTitle.set_valign(Gtk::ALIGN_CENTER); - TopTable->attach(LabelTitle, 0, 2, 1, 1); + _label_title.set_valign(Gtk::ALIGN_CENTER); + grid_top->attach(_label_title, 0, 2, 1, 1); #else - TopTable->attach(LabelTitle, 0, 1, 2, 3, + grid_top->attach(_label_title, 0, 1, 2, 3, Gtk::SHRINK | Gtk::FILL, Gtk::AttachOptions(), 0, 0 ); #endif /* Create the entry box for the object title */ - EntryTitle.set_sensitive (FALSE); - EntryTitle.set_max_length (256); + _entry_title.set_sensitive (FALSE); + _entry_title.set_max_length (256); #if WITH_GTKMM_3_0 - EntryTitle.set_hexpand(); - EntryTitle.set_valign(Gtk::ALIGN_CENTER); - TopTable->attach(EntryTitle, 1, 2, 1, 1); + _entry_title.set_hexpand(); + _entry_title.set_valign(Gtk::ALIGN_CENTER); + grid_top->attach(_entry_title, 1, 2, 1, 1); #else - TopTable->attach(EntryTitle, 1, 2, 2, 3, + grid_top->attach(_entry_title, 1, 2, 2, 3, Gtk::EXPAND | Gtk::FILL, Gtk::AttachOptions(), 0, 0 ); #endif - LabelTitle.set_mnemonic_widget (EntryTitle); + _label_title.set_mnemonic_widget(_entry_title); // pressing enter in the label field is the same as clicking Set: - EntryTitle.signal_activate().connect(sigc::mem_fun(this, &ObjectProperties::label_changed)); + _entry_title.signal_activate().connect(sigc::mem_fun(this, &ObjectProperties::_labelChanged)); /* Create the frame for the object description */ - FrameDescription.set_label_widget (LabelDescription); - FrameDescription.set_padding (0,0,0,0); - contents->pack_start (FrameDescription, true, true, 0); + Gtk::Label *label_desc = Gtk::manage(new Gtk::Label(_("_Description:"), 1)); + UI::Widget::Frame *frame_desc = Gtk::manage(new UI::Widget::Frame("", FALSE)); + frame_desc->set_label_widget(*label_desc); + frame_desc->set_padding (0,0,0,0); + contents->pack_start(*frame_desc, true, true, 0); /* Create the text view box for the object description */ - FrameTextDescription.set_border_width(4); - FrameTextDescription.set_sensitive (FALSE); - FrameDescription.add (FrameTextDescription); - FrameTextDescription.set_shadow_type (Gtk::SHADOW_IN); + _ft_description.set_border_width(4); + _ft_description.set_sensitive(FALSE); + frame_desc->add(_ft_description); + _ft_description.set_shadow_type(Gtk::SHADOW_IN); - TextViewDescription.set_wrap_mode(Gtk::WRAP_WORD); - TextViewDescription.get_buffer()->set_text(""); - FrameTextDescription.add (TextViewDescription); - TextViewDescription.add_mnemonic_label(LabelDescription); + _tv_description.set_wrap_mode(Gtk::WRAP_WORD); + _tv_description.get_buffer()->set_text(""); + _ft_description.add(_tv_description); + _tv_description.add_mnemonic_label(*label_desc); /* Image rendering */ /* Create the label for the object ImageRendering */ - LabelImageRendering.set_label (LabelImageRendering.get_label() + " "); - LabelImageRendering.set_alignment (1, 0.5); + _label_image_rendering.set_label(_label_image_rendering.get_label() + " "); + _label_image_rendering.set_alignment(1, 0.5); #if WITH_GTKMM_3_0 - LabelImageRendering.set_valign(Gtk::ALIGN_CENTER); - TopTable->attach(LabelImageRendering, 0, 3, 1, 1); + _label_image_rendering.set_valign(Gtk::ALIGN_CENTER); + grid_top->attach(_label_image_rendering, 0, 3, 1, 1); #else - TopTable->attach(LabelImageRendering, 0, 1, 3, 4, - Gtk::SHRINK | Gtk::FILL, - Gtk::AttachOptions(), 0, 0 ); + grid_top->attach(_label_image_rendering, 0, 1, 3, 4, + Gtk::SHRINK | Gtk::FILL, + Gtk::AttachOptions(), 0, 0 ); #endif /* Create the combo box text for the 'image-rendering' property */ - ComboBoxTextImageRendering.append( "auto" ); - ComboBoxTextImageRendering.append( "optimizeQuality" ); - ComboBoxTextImageRendering.append( "optimizeSpeed" ); - ComboBoxTextImageRendering.set_tooltip_text (_("The 'image-rendering' property can influence how a bitmap is up-scaled:\n\t'auto' no preference;\n\t'optimizeQuality' smooth;\n\t'optimizeSpeed' blocky.\nNote that this behaviour is not defined in the SVG 1.1 specification and not all browsers follow this interpretation.")); + _combo_image_rendering.append( "auto" ); + _combo_image_rendering.append( "optimizeQuality" ); + _combo_image_rendering.append( "optimizeSpeed" ); + _combo_image_rendering.set_tooltip_text(_("The 'image-rendering' property can influence how a bitmap is up-scaled:\n\t'auto' no preference;\n\t'optimizeQuality' smooth;\n\t'optimizeSpeed' blocky.\nNote that this behaviour is not defined in the SVG 1.1 specification and not all browsers follow this interpretation.")); #if WITH_GTKMM_3_0 - ComboBoxTextImageRendering.set_valign(Gtk::ALIGN_CENTER); - TopTable->attach(ComboBoxTextImageRendering, 1, 3, 1, 1); + _combo_image_rendering.set_valign(Gtk::ALIGN_CENTER); + grid_top->attach(_combo_image_rendering, 1, 3, 1, 1); #else - TopTable->attach(ComboBoxTextImageRendering, 1, 2, 3, 4, + grid_top->attach(_combo_image_rendering, 1, 2, 3, 4, Gtk::EXPAND | Gtk::FILL, Gtk::AttachOptions(), 0, 0 ); #endif - LabelImageRendering.set_mnemonic_widget (ComboBoxTextImageRendering); + _label_image_rendering.set_mnemonic_widget(_combo_image_rendering); - ComboBoxTextImageRendering.signal_changed().connect(sigc::mem_fun(this, &ObjectProperties::image_rendering_changed)); + _combo_image_rendering.signal_changed().connect( + sigc::mem_fun(this, &ObjectProperties::_imageRenderingChanged) + ); /* Check boxes */ - contents->pack_start (HBoxCheck, FALSE, FALSE, 0); - CheckTable->set_border_width(4); - HBoxCheck.pack_start(*CheckTable, true, true, 0); + Gtk::HBox *hb_checkboxes = Gtk::manage(new Gtk::HBox()); + contents->pack_start(*hb_checkboxes, FALSE, FALSE, 0); + +#if WITH_GTKMM_3_0 + Gtk::Grid *grid_cb = Gtk::manage(new Gtk::Grid()); +#else + Gtk::Table *grid_cb = Gtk::manage(new Gtk::Table(1, 2, true)); +#endif + + grid_cb->set_border_width(4); + hb_checkboxes->pack_start(*grid_cb, true, true, 0); /* Hide */ - CBHide.set_tooltip_text (_("Check to make the object invisible")); + _cb_hide.set_tooltip_text (_("Check to make the object invisible")); #if WITH_GTKMM_3_0 - CBHide.set_hexpand(); - CBHide.set_valign(Gtk::ALIGN_CENTER); - CheckTable->attach(CBHide, 0, 0, 1, 1); + _cb_hide.set_hexpand(); + _cb_hide.set_valign(Gtk::ALIGN_CENTER); + grid_cb->attach(_cb_hide, 0, 0, 1, 1); #else - CheckTable->attach(CBHide, 0, 1, 0, 1, + grid_cb->attach(_cb_hide, 0, 1, 0, 1, Gtk::EXPAND | Gtk::FILL, Gtk::AttachOptions(), 0, 0 ); #endif - CBHide.signal_toggled().connect(sigc::mem_fun(this, &ObjectProperties::hidden_toggled)); + _cb_hide.signal_toggled().connect(sigc::mem_fun(this, &ObjectProperties::_hiddenToggled)); /* Lock */ // TRANSLATORS: "Lock" is a verb here - CBLock.set_tooltip_text (_("Check to make the object insensitive (not selectable by mouse)")); + _cb_lock.set_tooltip_text(_("Check to make the object insensitive (not selectable by mouse)")); #if WITH_GTKMM_3_0 - CBLock.set_hexpand(); - CBLock.set_valign(Gtk::ALIGN_CENTER); - CheckTable->attach(CBLock, 1, 0, 1, 1); + _cb_lock.set_hexpand(); + _cb_lock.set_valign(Gtk::ALIGN_CENTER); + grid_cb->attach(_cb_lock, 1, 0, 1, 1); #else - CheckTable->attach(CBLock, 1, 2, 0, 1, - Gtk::EXPAND | Gtk::FILL, - Gtk::AttachOptions(), 0, 0 ); + grid_cb->attach(_cb_lock, 1, 2, 0, 1, + Gtk::EXPAND | Gtk::FILL, + Gtk::AttachOptions(), 0, 0 ); #endif - CBLock.signal_toggled().connect(sigc::mem_fun(this, &ObjectProperties::sensitivity_toggled)); + _cb_lock.signal_toggled().connect(sigc::mem_fun(this, &ObjectProperties::_sensitivityToggled)); /* Button for setting the object's id, label, title and description. */ + Gtk::Button *btn_set = Gtk::manage(new Gtk::Button(_("_Set"), 1)); #if WITH_GTKMM_3_0 - BSet.set_hexpand(); - BSet.set_valign(Gtk::ALIGN_CENTER); - CheckTable->attach(BSet, 2, 0, 1, 1); + btn_set->set_hexpand(); + btn_set->set_valign(Gtk::ALIGN_CENTER); + grid_cb->attach(*btn_set, 2, 0, 1, 1); #else - CheckTable->attach(BSet, 2, 3, 0, 1, - Gtk::EXPAND | Gtk::FILL, - Gtk::AttachOptions(), 0, 0 ); + grid_cb->attach(*btn_set, 2, 3, 0, 1, + Gtk::EXPAND | Gtk::FILL, + Gtk::AttachOptions(), 0, 0 ); #endif - BSet.signal_clicked().connect(sigc::mem_fun(this, &ObjectProperties::label_changed)); + btn_set->signal_clicked().connect(sigc::mem_fun(this, &ObjectProperties::_labelChanged)); /* Create the frame for interactivity options */ - EInteractivity.set_label_widget (LabelInteractivity); - contents->pack_start (EInteractivity, FALSE, FALSE, 0); - show_all (); - widget_setup(); + Gtk::Label *label_interactivity = Gtk::manage(new Gtk::Label(_("_Interactivity"), 1)); + _exp_interactivity.set_label_widget(*label_interactivity); + contents->pack_start(_exp_interactivity, FALSE, FALSE, 0); + + show_all(); + update(); } -void ObjectProperties::widget_setup(void) +void ObjectProperties::update() { - if (blocked || !desktop) - { + if (_blocked || !_desktop) { return; } - if (SP_ACTIVE_DESKTOP != desktop) - { + if (SP_ACTIVE_DESKTOP != _desktop) { return; } - Inkscape::Selection *selection = sp_desktop_selection (SP_ACTIVE_DESKTOP); + Inkscape::Selection *selection = sp_desktop_selection(SP_ACTIVE_DESKTOP); Gtk::Box *contents = _getContents(); if (!selection->singleItem()) { contents->set_sensitive (false); - CurrentItem = NULL; + _current_item = NULL; //no selection anymore or multiple objects selected, means that we need //to close the connections to the previously selected object - attrTable->clear(); + _attr_table->clear(); return; } else { contents->set_sensitive (true); } SPItem *item = selection->singleItem(); - if (CurrentItem == item) + if (_current_item == item) { //otherwise we would end up wasting resources through the modify selection - //callback when moving an object (endlessly setting the labels and recreating attrTable) + //callback when moving an object (endlessly setting the labels and recreating _attr_table) return; } - blocked = true; + _blocked = true; - CBLock.set_active (item->isLocked()); /* Sensitive */ - CBHide.set_active (item->isExplicitlyHidden()); /* Hidden */ + _cb_lock.set_active(item->isLocked()); /* Sensitive */ + _cb_hide.set_active(item->isExplicitlyHidden()); /* Hidden */ if (item->cloned) { /* ID */ - EntryID.set_text (""); - EntryID.set_sensitive (FALSE); - LabelID.set_text (_("Ref")); + _entry_id.set_text(""); + _entry_id.set_sensitive(FALSE); + _label_id.set_text(_("Ref")); /* Label */ - EntryLabel.set_text (""); - EntryLabel.set_sensitive (FALSE); - LabelLabel.set_text (_("Ref")); + _entry_label.set_text(""); + _entry_label.set_sensitive(FALSE); + _label_label.set_text(_("Ref")); } else { SPObject *obj = static_cast(item); /* ID */ - EntryID.set_text (obj->getId()); - EntryID.set_sensitive (TRUE); - LabelID.set_markup_with_mnemonic (_("_ID:")); + _entry_id.set_text(obj->getId()); + _entry_id.set_sensitive(TRUE); + _label_id.set_markup_with_mnemonic(_("_ID:") + Glib::ustring(" ")); /* Label */ - EntryLabel.set_text(obj->defaultLabel()); - EntryLabel.set_sensitive (TRUE); + _entry_label.set_text(obj->defaultLabel()); + _entry_label.set_sensitive(TRUE); /* Title */ gchar *title = obj->title(); if (title) { - EntryTitle.set_text(title); + _entry_title.set_text(title); g_free(title); } else { - EntryTitle.set_text(""); + _entry_title.set_text(""); } - EntryTitle.set_sensitive(TRUE); + _entry_title.set_sensitive(TRUE); /* Image Rendering */ - if( SP_IS_IMAGE( item ) ) { - ComboBoxTextImageRendering.show(); - LabelImageRendering.show(); + if (SP_IS_IMAGE(item)) { + _combo_image_rendering.show(); + _label_image_rendering.show(); char const *str = obj->getStyleProperty( "image-rendering", "auto" ); - if( strcmp( str, "auto" ) == 0 ) { - ComboBoxTextImageRendering.set_active(0); - } else if( strcmp( str, "optimizeQuality" ) == 0 ) { - ComboBoxTextImageRendering.set_active(1); - } else { - ComboBoxTextImageRendering.set_active(2); + if (strcmp( str, "auto" ) == 0) { + _combo_image_rendering.set_active(0); + } else if (strcmp(str, "optimizeQuality") == 0) { + _combo_image_rendering.set_active(1); + } else { + _combo_image_rendering.set_active(2); } } else { - ComboBoxTextImageRendering.hide(); - ComboBoxTextImageRendering.unset_active(); - LabelImageRendering.hide(); + _combo_image_rendering.hide(); + _combo_image_rendering.unset_active(); + _label_image_rendering.hide(); } /* Description */ gchar *desc = obj->desc(); if (desc) { - TextViewDescription.get_buffer()->set_text(desc); + _tv_description.get_buffer()->set_text(desc); g_free(desc); } else { - TextViewDescription.get_buffer()->set_text(""); + _tv_description.get_buffer()->set_text(""); } - FrameTextDescription.set_sensitive(TRUE); + _ft_description.set_sensitive(TRUE); - if (CurrentItem == NULL) - { - attrTable->set_object(obj, int_labels, int_attrs, (GtkWidget*)EInteractivity.gobj()); - } - else - { - attrTable->change_object(obj); + if (_current_item == NULL) { + _attr_table->set_object(obj, _int_labels, _int_attrs, (GtkWidget*) _exp_interactivity.gobj()); + } else { + _attr_table->change_object(obj); } - attrTable->show_all(); + _attr_table->show_all(); } - CurrentItem = item; - blocked = false; + _current_item = item; + _blocked = false; } -void ObjectProperties::label_changed(void) +void ObjectProperties::_labelChanged() { - if (blocked) - { + if (_blocked) { return; } SPItem *item = sp_desktop_selection(SP_ACTIVE_DESKTOP)->singleItem(); g_return_if_fail (item != NULL); - blocked = true; + _blocked = true; /* Retrieve the label widget for the object's id */ - gchar *id = g_strdup(EntryID.get_text().c_str()); - g_strcanon (id, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.:", '_'); - if (!strcmp (id, item->getId())) { - LabelID.set_markup_with_mnemonic(_("_ID:")); + gchar *id = g_strdup(_entry_id.get_text().c_str()); + g_strcanon(id, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.:", '_'); + if (strcmp(id, item->getId()) == 0) { + _label_id.set_markup_with_mnemonic(_("_ID:")); } else if (!*id || !isalnum (*id)) { - LabelID.set_text (_("Id invalid! ")); + _label_id.set_text(_("Id invalid! ")); } else if (SP_ACTIVE_DOCUMENT->getObjectById(id) != NULL) { - LabelID.set_text (_("Id exists! ")); + _label_id.set_text(_("Id exists! ")); } else { SPException ex; - LabelID.set_markup_with_mnemonic(_("_ID:")); - SP_EXCEPTION_INIT (&ex); + _label_id.set_markup_with_mnemonic(_("_ID:")); + SP_EXCEPTION_INIT(&ex); item->setAttribute("id", id, &ex); DocumentUndo::done(SP_ACTIVE_DOCUMENT, SP_VERB_DIALOG_ITEM, _("Set object ID")); } - g_free (id); + g_free(id); /* Retrieve the label widget for the object's label */ - Glib::ustring label = EntryLabel.get_text(); + Glib::ustring label = _entry_label.get_text(); /* Give feedback on success of setting the drawing object's label * using the widget's label text */ SPObject *obj = static_cast(item); - if (label.compare (obj->defaultLabel())) { + if (label.compare(obj->defaultLabel())) { obj->setLabel(label.c_str()); DocumentUndo::done(SP_ACTIVE_DOCUMENT, SP_VERB_DIALOG_ITEM, _("Set object label")); } /* Retrieve the title */ - if (obj->setTitle(EntryTitle.get_text().c_str())) + if (obj->setTitle(_entry_title.get_text().c_str())) { DocumentUndo::done(SP_ACTIVE_DOCUMENT, SP_VERB_DIALOG_ITEM, _("Set object title")); + } /* Retrieve the description */ Gtk::TextBuffer::iterator start, end; - TextViewDescription.get_buffer()->get_bounds(start, end); - Glib::ustring desc = TextViewDescription.get_buffer()->get_text(start, end, TRUE); - if (obj->setDesc(desc.c_str())) + _tv_description.get_buffer()->get_bounds(start, end); + Glib::ustring desc = _tv_description.get_buffer()->get_text(start, end, TRUE); + if (obj->setDesc(desc.c_str())) { DocumentUndo::done(SP_ACTIVE_DOCUMENT, SP_VERB_DIALOG_ITEM, _("Set object description")); + } - blocked = false; + _blocked = false; } -void ObjectProperties::image_rendering_changed(void) +void ObjectProperties::_imageRenderingChanged() { - if (blocked) - { + if (_blocked) { return; } SPItem *item = sp_desktop_selection(SP_ACTIVE_DESKTOP)->singleItem(); g_return_if_fail (item != NULL); - blocked = true; + _blocked = true; - Glib::ustring scale = ComboBoxTextImageRendering.get_active_text(); + Glib::ustring scale = _combo_image_rendering.get_active_text(); // We should unset if the parent computed value is auto and the desired value is auto. SPCSSAttr *css = sp_repr_css_attr_new(); @@ -536,64 +537,67 @@ void ObjectProperties::image_rendering_changed(void) } sp_repr_css_attr_unref( css ); - blocked = false; + _blocked = false; } -void ObjectProperties::sensitivity_toggled (void) +void ObjectProperties::_sensitivityToggled() { - if (blocked) - { + if (_blocked) { return; } SPItem *item = sp_desktop_selection(SP_ACTIVE_DESKTOP)->singleItem(); - g_return_if_fail (item != NULL); + g_return_if_fail(item != NULL); - blocked = true; - item->setLocked(CBLock.get_active()); + _blocked = true; + item->setLocked(_cb_lock.get_active()); DocumentUndo::done(SP_ACTIVE_DOCUMENT, SP_VERB_DIALOG_ITEM, - CBLock.get_active()? _("Lock object") : _("Unlock object")); - blocked = false; + _cb_lock.get_active() ? _("Lock object") : _("Unlock object")); + _blocked = false; } -void ObjectProperties::hidden_toggled(void) +void ObjectProperties::_hiddenToggled() { - if (blocked) - { + if (_blocked) { return; } SPItem *item = sp_desktop_selection(SP_ACTIVE_DESKTOP)->singleItem(); - g_return_if_fail (item != NULL); + g_return_if_fail(item != NULL); - blocked = true; - item->setExplicitlyHidden(CBHide.get_active()); + _blocked = true; + item->setExplicitlyHidden(_cb_hide.get_active()); DocumentUndo::done(SP_ACTIVE_DOCUMENT, SP_VERB_DIALOG_ITEM, - CBHide.get_active()? _("Hide object") : _("Unhide object")); - blocked = false; + _cb_hide.get_active() ? _("Hide object") : _("Unhide object")); + _blocked = false; } -void ObjectProperties::setDesktop(SPDesktop *desktop) +void ObjectProperties::_setDesktop(SPDesktop *desktop) { Panel::setDesktop(desktop); - deskTrack.setBase(desktop); + _desktop_tracker.setBase(desktop); } -void ObjectProperties::setTargetDesktop(SPDesktop *desktop) +void ObjectProperties::_setTargetDesktop(SPDesktop *desktop) { - if (this->desktop != desktop) { - if (this->desktop) { - subselChangedConn.disconnect(); - selectChangedConn.disconnect(); + if (this->_desktop != desktop) { + if (this->_desktop) { + _subselection_changed_connection.disconnect(); + _selection_changed_connection.disconnect(); } - this->desktop = desktop; + this->_desktop = desktop; if (desktop && desktop->selection) { - selectChangedConn = desktop->selection->connectChanged(sigc::hide(sigc::mem_fun(*this, &ObjectProperties::widget_setup))); - subselChangedConn = desktop->connectToolSubselectionChanged(sigc::hide(sigc::mem_fun(*this, &ObjectProperties::widget_setup))); + _selection_changed_connection = desktop->selection->connectChanged( + sigc::hide(sigc::mem_fun(*this, &ObjectProperties::update)) + ); + _subselection_changed_connection = desktop->connectToolSubselectionChanged( + sigc::hide(sigc::mem_fun(*this, &ObjectProperties::update)) + ); } - widget_setup(); + update(); } } + } } } diff --git a/src/ui/dialog/object-properties.h b/src/ui/dialog/object-properties.h index 721c12c56..093f273f6 100644 --- a/src/ui/dialog/object-properties.h +++ b/src/ui/dialog/object-properties.h @@ -69,98 +69,64 @@ namespace Dialog { */ class ObjectProperties : public Widget::Panel { public: - ObjectProperties (); - ~ObjectProperties (); + ObjectProperties(); + ~ObjectProperties(); static ObjectProperties &getInstance() { return *new ObjectProperties(); } - /** - * Updates entries and other child widgets on selection change, object modification, etc. - */ - void widget_setup(void); + /// Updates entries and other child widgets on selection change, object modification, etc. + void update(); private: - bool blocked; - SPItem *CurrentItem; //to store the current item, for not wasting resources - std::vector int_attrs; - std::vector int_labels; + bool _blocked; + SPItem *_current_item; //to store the current item, for not wasting resources + std::vector _int_attrs; + std::vector _int_labels; + + Gtk::Label _label_id; //the label for the object ID + Gtk::Entry _entry_id; //the entry for the object ID + Gtk::Label _label_label; //the label for the object label + Gtk::Entry _entry_label; //the entry for the object label + Gtk::Label _label_title; //the label for the object title + Gtk::Entry _entry_title; //the entry for the object title + Gtk::Label _label_image_rendering; // the label for 'image-rendering' + Gtk::ComboBoxText _combo_image_rendering; // the combo box text for 'image-rendering' -#if WITH_GTKMM_3_0 - Gtk::Grid *TopTable; //the table with the object properties -#else - Gtk::Table *TopTable; //the table with the object properties -#endif + Gtk::Frame _ft_description; //the frame for the text of the object description + Gtk::TextView _tv_description; //the text view object showing the object description - Gtk::Label LabelID; //the label for the object ID - Gtk::Entry EntryID; //the entry for the object ID - Gtk::Label LabelLabel; //the label for the object label - Gtk::Entry EntryLabel; //the entry for the object label - Gtk::Label LabelTitle; //the label for the object title - Gtk::Entry EntryTitle; //the entry for the object title - Gtk::Label LabelImageRendering; // the label for 'image-rendering' - Gtk::ComboBoxText ComboBoxTextImageRendering; // the combo box text for 'image-rendering' + Gtk::CheckButton _cb_hide; //the check button hide + Gtk::CheckButton _cb_lock; //the check button lock + + Gtk::Expander _exp_interactivity; //the expander for interactivity + SPAttributeTable *_attr_table; //the widget for showing the on... names at the bottom - Gtk::Label LabelDescription; //the label for the object description - UI::Widget::Frame FrameDescription; //the frame for the object description - Gtk::Frame FrameTextDescription; //the frame for the text of the object description - Gtk::TextView TextViewDescription; //the text view object showing the object description + SPDesktop *_desktop; + DesktopTracker _desktop_tracker; + sigc::connection _desktop_changed_connection; + sigc::connection _selection_changed_connection; + sigc::connection _subselection_changed_connection; - Gtk::HBox HBoxCheck; // the HBox for the check boxes + /// Constructor auxiliary function creating the child widgets. + void _init(); -#if WITH_GTKMM_3_0 - Gtk::Grid *CheckTable; //the table for the check boxes -#else - Gtk::Table *CheckTable; //the table for the check boxes -#endif + /// Sets object properties (ID, label, title, description) on user input. + void _labelChanged(); - Gtk::CheckButton CBHide; //the check button hide - Gtk::CheckButton CBLock; //the check button lock - Gtk::Button BSet; //the button set - - Gtk::Label LabelInteractivity; //the label for interactivity - Gtk::Expander EInteractivity; //the label for interactivity - SPAttributeTable *attrTable; //the widget for showing the on... names at the bottom - - SPDesktop *desktop; - DesktopTracker deskTrack; - sigc::connection desktopChangeConn; - sigc::connection selectChangedConn; - sigc::connection subselChangedConn; - - /** - * Constructor auxiliary function creating the child widgets. - */ - void MakeWidget(void); - - /** - * Sets object properties (ID, label, title, description) on user input. - */ - void label_changed(void); - - /** - * Callback for 'image-rendering'. - */ - void image_rendering_changed(void); - - /** - * Callback for checkbox Lock. - */ - void sensitivity_toggled (void); - - /** - * Callback for checkbox Hide. - */ - void hidden_toggled(void); - - /** - * Can be invoked for setting the desktop. Currently not used. - */ - void setDesktop(SPDesktop *desktop); + /// Callback for 'image-rendering'. + void _imageRenderingChanged(); + + /// Callback for checkbox Lock. + void _sensitivityToggled(); + + /// Callback for checkbox Hide. + void _hiddenToggled(); + + /// 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); + /// Is invoked by the desktop tracker when the desktop changes. + void _setTargetDesktop(SPDesktop *desktop); }; } -- cgit v1.2.3 From 0f447656fa20753681f2f88713a08df3bfabcb7f Mon Sep 17 00:00:00 2001 From: Nicolas Dufour Date: Sat, 15 Mar 2014 09:16:21 +0100 Subject: UI. Fix for Bug #1016889 (GTK3: status bar of XML Editor triggers resize of dialog window. Fixed bugs: - https://launchpad.net/bugs/1016889 (bzr r13155) --- src/ui/dialog/xml-tree.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/ui') diff --git a/src/ui/dialog/xml-tree.cpp b/src/ui/dialog/xml-tree.cpp index 0e1e9f7a6..55d0aff09 100644 --- a/src/ui/dialog/xml-tree.cpp +++ b/src/ui/dialog/xml-tree.cpp @@ -100,6 +100,9 @@ XmlTree::XmlTree (void) : status.set_alignment( 0.0, 0.5); status.set_size_request(1, -1); status.set_markup(""); +#if WITH_GTKMM_3_0 + status.set_line_wrap(true); +#endif status_box.pack_start( status, TRUE, TRUE, 0); contents->pack_end(status_box, false, false, 2); -- cgit v1.2.3 From eca101b9f434da89b05ee70531546ae95541d47a Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Sun, 16 Mar 2014 00:10:01 +0100 Subject: Fix build failure with GTK 3.0 (bzr r13156) --- src/ui/dialog/object-properties.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'src/ui') diff --git a/src/ui/dialog/object-properties.cpp b/src/ui/dialog/object-properties.cpp index c07f39819..28e9b360b 100644 --- a/src/ui/dialog/object-properties.cpp +++ b/src/ui/dialog/object-properties.cpp @@ -90,11 +90,6 @@ ObjectProperties::ObjectProperties() ); _desktop_tracker.connect(GTK_WIDGET(gobj())); -#if WITH_GTKMM_3_0 - CheckTable->set_row_homogeneous(); - CheckTable->set_column_homogeneous(true); -#endif - _init(); } @@ -285,6 +280,8 @@ void ObjectProperties::_init() #if WITH_GTKMM_3_0 Gtk::Grid *grid_cb = Gtk::manage(new Gtk::Grid()); + grid_cb->set_row_homogeneous(); + grid_cb->set_column_homogeneous(true); #else Gtk::Table *grid_cb = Gtk::manage(new Gtk::Table(1, 2, true)); #endif -- cgit v1.2.3 From c39ff7ba3dc2c7042f6d316d1df0ee047da82b26 Mon Sep 17 00:00:00 2001 From: Nicolas Dufour Date: Mon, 17 Mar 2014 15:07:28 +0100 Subject: Fix for Bug #1158506 (Batch export DPI always at 90). Fixed bugs: - https://launchpad.net/bugs/1158506 (bzr r13160) --- src/ui/dialog/export.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/ui') diff --git a/src/ui/dialog/export.cpp b/src/ui/dialog/export.cpp index f0a5f1bf5..913713e5c 100644 --- a/src/ui/dialog/export.cpp +++ b/src/ui/dialog/export.cpp @@ -1049,7 +1049,7 @@ void Export::onExport () dpi = atof(dpi_hint); } if (dpi == 0.0) { - dpi = DPI_BASE; + dpi = getValue(xdpi_adj); } Geom::OptRect area = item->desktopVisualBounds(); -- cgit v1.2.3 From b74a8597149d17529201fb8c9d9a92e29cc821ad Mon Sep 17 00:00:00 2001 From: "Jon A. Cruz" Date: Mon, 17 Mar 2014 18:52:59 -0700 Subject: Warning cleanups. (bzr r13162) --- src/ui/dialog/filter-effects-dialog.cpp | 2 +- src/ui/dialog/undo-history.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/ui') diff --git a/src/ui/dialog/filter-effects-dialog.cpp b/src/ui/dialog/filter-effects-dialog.cpp index 65bebbd14..c2367c2a2 100644 --- a/src/ui/dialog/filter-effects-dialog.cpp +++ b/src/ui/dialog/filter-effects-dialog.cpp @@ -1515,7 +1515,7 @@ void FilterEffectsDialog::FilterModifier::on_name_edited(const Glib::ustring& pa } } -bool FilterEffectsDialog::FilterModifier::on_filter_move(const Glib::RefPtr& /*context*/, int x, int y, guint /*time*/) { +bool FilterEffectsDialog::FilterModifier::on_filter_move(const Glib::RefPtr& /*context*/, int /*x*/, int /*y*/, guint /*time*/) { //const Gtk::TreeModel::Path& /*path*/) { /* The code below is bugged. Use of "object->getRepr()->setPosition(0)" is dangerous! diff --git a/src/ui/dialog/undo-history.cpp b/src/ui/dialog/undo-history.cpp index 2412c3ec9..53691cd37 100644 --- a/src/ui/dialog/undo-history.cpp +++ b/src/ui/dialog/undo-history.cpp @@ -235,7 +235,7 @@ void UndoHistory::setDesktop(SPDesktop* desktop) } } -void UndoHistory::_connectDocument(SPDesktop* desktop, SPDocument *document) +void UndoHistory::_connectDocument(SPDesktop* desktop, SPDocument * /*document*/) { // disconnect from prior if (_event_log) { -- cgit v1.2.3 From 1d584c4ddd28280f5c9224175ce39aea9e690600 Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Fri, 21 Mar 2014 00:16:02 +0100 Subject: control-point-selection : fix a (very unlikely) crash upon dereferencing unitialized bound variable (bzr r13176) --- src/ui/tool/control-point-selection.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/ui') diff --git a/src/ui/tool/control-point-selection.cpp b/src/ui/tool/control-point-selection.cpp index b5ee0a597..d10ed0f0d 100644 --- a/src/ui/tool/control-point-selection.cpp +++ b/src/ui/tool/control-point-selection.cpp @@ -194,6 +194,8 @@ void ControlPointSelection::align(Geom::Dim2 axis) bound.unionWith(Geom::OptInterval((*i)->position()[d])); } + if (!bound) { return; } + double new_coord = bound->middle(); for (iterator i = _points.begin(); i != _points.end(); ++i) { Geom::Point pos = (*i)->position(); @@ -220,6 +222,8 @@ void ControlPointSelection::distribute(Geom::Dim2 d) bound.unionWith(Geom::OptInterval(pos[d])); } + if (!bound) { return; } + // now we iterate over the multimap and set aligned positions. double step = size() == 1 ? 0 : bound->extent() / (size() - 1); double start = bound->min(); -- cgit v1.2.3 From 9df0bd626eed33451e8eeebffcb393fb7ae0f0d8 Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Sat, 22 Mar 2014 13:21:38 +0100 Subject: tool/node.cpp : don't rely on g_error terminating the program, allow more graceful error handling. (bzr r13183) --- src/ui/tool/node.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/ui') diff --git a/src/ui/tool/node.cpp b/src/ui/tool/node.cpp index e246bf997..fbbc4be64 100644 --- a/src/ui/tool/node.cpp +++ b/src/ui/tool/node.cpp @@ -1217,6 +1217,7 @@ Handle *Node::handleToward(Node *to) return back(); } g_error("Node::handleToward(): second node is not adjacent!"); + return NULL; } Node *Node::nodeToward(Handle *dir) @@ -1228,6 +1229,7 @@ Node *Node::nodeToward(Handle *dir) return _prev(); } g_error("Node::nodeToward(): handle is not a child of this node!"); + return NULL; } Handle *Node::handleAwayFrom(Node *to) @@ -1239,6 +1241,7 @@ Handle *Node::handleAwayFrom(Node *to) return front(); } g_error("Node::handleAwayFrom(): second node is not adjacent!"); + return NULL; } Node *Node::nodeAwayFrom(Handle *h) @@ -1250,6 +1253,7 @@ Node *Node::nodeAwayFrom(Handle *h) return _next(); } g_error("Node::nodeAwayFrom(): handle is not a child of this node!"); + return NULL; } Glib::ustring Node::_getTip(unsigned state) const -- cgit v1.2.3 From 149a53e28c2ba291e9bca8a0b7512db3231c92f5 Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Sun, 23 Mar 2014 21:46:53 +0100 Subject: "fix" GTK3 build. (bzr r13192) --- src/ui/dialog/input.cpp | 82 ++++++++++++++++++++++++++----------------------- 1 file changed, 43 insertions(+), 39 deletions(-) (limited to 'src/ui') diff --git a/src/ui/dialog/input.cpp b/src/ui/dialog/input.cpp index 82e65435d..2d4755fd2 100644 --- a/src/ui/dialog/input.cpp +++ b/src/ui/dialog/input.cpp @@ -53,10 +53,10 @@ /* XPM */ static char const * core_xpm[] = { "16 16 4 1", -" c None", -". c #808080", -"+ c #000000", -"@ c #FFFFFF", +" c None", +". c #808080", +"+ c #000000", +"@ c #FFFFFF", " ", " ", " ", @@ -291,9 +291,9 @@ static char const *button_on[] = { /* XPM */ static char const * axis_none_xpm[] = { "24 8 3 1", -" c None", -". c #000000", -"+ c #808080", +" c None", +". c #000000", +"+ c #808080", " ", " .++++++++++++++++++. ", " .+ . .+. ", @@ -305,10 +305,10 @@ static char const * axis_none_xpm[] = { /* XPM */ static char const * axis_off_xpm[] = { "24 8 4 1", -" c None", -". c #808080", -"+ c #000000", -"@ c #FFFFFF", +" c None", +". c #808080", +"+ c #000000", +"@ c #FFFFFF", " ", " .++++++++++++++++++. ", " .+@@@@@@@@@@@@@@@@@@+. ", @@ -320,9 +320,9 @@ static char const * axis_off_xpm[] = { /* XPM */ static char const * axis_on_xpm[] = { "24 8 3 1", -" c None", -". c #000000", -"+ c #00FF00", +" c None", +". c #000000", +"+ c #00FF00", " ", " .................... ", " ..++++++++++++++++++.. ", @@ -1707,9 +1707,9 @@ void InputDialogImpl::updateTestAxes( Glib::ustring const& key, GdkDevice* dev ) axesValues[i].set_sensitive(true); if ( dev && (i < static_cast(G_N_ELEMENTS(axesValues)) ) ) { // FIXME: Device axis ranges are inaccessible in GTK+ 3 and - // are deprecated in GTK+ 2. Progress-bar ranges are disabled - // until we find an alternative solution - + // are deprecated in GTK+ 2. Progress-bar ranges are disabled + // until we find an alternative solution + // if ( (dev->axes[i].max - dev->axes[i].min) > epsilon ) { axesValues[i].set_sensitive(true); // axesValues[i].set_fraction( (axesMap[key][i].second- dev->axes[i].min) / (dev->axes[i].max - dev->axes[i].min) ); @@ -1726,10 +1726,10 @@ void InputDialogImpl::updateTestAxes( Glib::ustring const& key, GdkDevice* dev ) if ( dev && (i < static_cast(G_N_ELEMENTS(axesValues)) ) ) { // FIXME: Device axis ranges are inaccessible in GTK+ 3 and - // are deprecated in GTK+ 2. Progress-bar ranges are disabled - // until we find an alternative solution + // are deprecated in GTK+ 2. Progress-bar ranges are disabled + // until we find an alternative solution - // if ( (dev->axes[i].max - dev->axes[i].min) > epsilon ) { + // if ( (dev->axes[i].max - dev->axes[i].min) > epsilon ) { axesValues[i].set_sensitive(true); // axesValues[i].set_fraction( (axesMap[key][i].second- dev->axes[i].min) / (dev->axes[i].max - dev->axes[i].min) ); // } @@ -1860,8 +1860,8 @@ bool InputDialogImpl::eventSnoop(GdkEvent* event) GdkEventButton* btnEvt = reinterpret_cast(event); if ( btnEvt->device ) { key = getKeyFor(btnEvt->device); - source = gdk_device_get_source(btnEvt->device); - devName = gdk_device_get_name(btnEvt->device); + source = gdk_device_get_source(btnEvt->device); + devName = gdk_device_get_name(btnEvt->device); mapAxesValues(key, btnEvt->axes, btnEvt->device); if ( buttonMap[key].find(btnEvt->button) == buttonMap[key].end() ) { @@ -1889,8 +1889,8 @@ bool InputDialogImpl::eventSnoop(GdkEvent* event) GdkEventMotion* btnMtn = reinterpret_cast(event); if ( btnMtn->device ) { key = getKeyFor(btnMtn->device); - source = gdk_device_get_source(btnMtn->device); - devName = gdk_device_get_name(btnMtn->device); + source = gdk_device_get_source(btnMtn->device); + devName = gdk_device_get_name(btnMtn->device); mapAxesValues(key, btnMtn->axes, btnMtn->device); } gchar* name = gtk_accelerator_name(0, static_cast(btnMtn->state)); @@ -1915,19 +1915,16 @@ bool InputDialogImpl::eventSnoop(GdkEvent* event) if ( (lastSourceSeen != source) || (lastDevnameSeen != devName) ) { switch (source) { - case GDK_SOURCE_MOUSE: - { + case GDK_SOURCE_MOUSE: { testThumb.set(getPix(PIX_CORE)); + break; } - break; - case GDK_SOURCE_CURSOR: - { -// g_message("flip to cursor"); + case GDK_SOURCE_CURSOR: { +// g_message("flip to cursor"); testThumb.set(getPix(PIX_MOUSE)); + break; } - break; - case GDK_SOURCE_PEN: - { + case GDK_SOURCE_PEN: { if (devName == _("pad")) { // g_message("flip to pad"); testThumb.set(getPix(PIX_SIDEBUTTONS)); @@ -1935,17 +1932,24 @@ bool InputDialogImpl::eventSnoop(GdkEvent* event) // g_message("flip to pen"); testThumb.set(getPix(PIX_TIP)); } + break; } - break; - case GDK_SOURCE_ERASER: - { + case GDK_SOURCE_ERASER: { // g_message("flip to eraser"); testThumb.set(getPix(PIX_ERASER)); + break; } - break; -// default: -// g_message("gurgle"); +#if WITH_GTKMM_3_0 + /// \fixme GTK3 added new GDK_SOURCEs that should be handled here! + case GDK_SOURCE_KEYBOARD: + case GDK_SOURCE_TOUCHSCREEN: + case GDK_SOURCE_TOUCHPAD: { + g_warning("InputDialogImpl::eventSnoop : unhandled GDK_SOURCE type!"); + break; + } +#endif } + updateTestButtons(key, hotButton); lastSourceSeen = source; lastDevnameSeen = devName; -- cgit v1.2.3 From 16507e4f829223da3d7a8037155257842fbd113e Mon Sep 17 00:00:00 2001 From: buliabyak <> Date: Wed, 26 Mar 2014 01:35:07 -0300 Subject: fix crash when spelling error is in hidden part of a text on path (bzr r13212) --- src/ui/dialog/spellcheck.cpp | 88 ++++++++++++++++++++++---------------------- 1 file changed, 45 insertions(+), 43 deletions(-) (limited to 'src/ui') diff --git a/src/ui/dialog/spellcheck.cpp b/src/ui/dialog/spellcheck.cpp index 00bd445bf..8a4ddc57e 100644 --- a/src/ui/dialog/spellcheck.cpp +++ b/src/ui/dialog/spellcheck.cpp @@ -590,52 +590,54 @@ SpellCheck::nextWord() // draw rect std::vector points = _layout->createSelectionShape(_begin_w, _end_w, _text->i2dt_affine()); - Geom::Point tl, br; - tl = br = points.front(); - for (unsigned i = 0 ; i < points.size() ; i ++) { - if (points[i][Geom::X] < tl[Geom::X]) - tl[Geom::X] = points[i][Geom::X]; - if (points[i][Geom::Y] < tl[Geom::Y]) - tl[Geom::Y] = points[i][Geom::Y]; - if (points[i][Geom::X] > br[Geom::X]) - br[Geom::X] = points[i][Geom::X]; - if (points[i][Geom::Y] > br[Geom::Y]) - br[Geom::Y] = points[i][Geom::Y]; - } + if (points.size() >= 4) { // we may not have a single quad if this is a clipped part of text on path; in that case skip drawing the rect + Geom::Point tl, br; + tl = br = points.front(); + for (unsigned i = 0 ; i < points.size() ; i ++) { + if (points[i][Geom::X] < tl[Geom::X]) + tl[Geom::X] = points[i][Geom::X]; + if (points[i][Geom::Y] < tl[Geom::Y]) + tl[Geom::Y] = points[i][Geom::Y]; + if (points[i][Geom::X] > br[Geom::X]) + br[Geom::X] = points[i][Geom::X]; + if (points[i][Geom::Y] > br[Geom::Y]) + br[Geom::Y] = points[i][Geom::Y]; + } - // expand slightly - Geom::Rect area = Geom::Rect(tl, br); - double mindim = fabs(tl[Geom::Y] - br[Geom::Y]); - if (fabs(tl[Geom::X] - br[Geom::X]) < mindim) - mindim = fabs(tl[Geom::X] - br[Geom::X]); - area.expandBy(MAX(0.05 * mindim, 1)); - - // create canvas path rectangle, red stroke - SPCanvasItem *rect = sp_canvas_bpath_new(sp_desktop_sketch(desktop), NULL); - sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(rect), 0xff0000ff, 3.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); - sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(rect), 0, SP_WIND_RULE_NONZERO); - SPCurve *curve = new SPCurve(); - curve->moveto(area.corner(0)); - curve->lineto(area.corner(1)); - curve->lineto(area.corner(2)); - curve->lineto(area.corner(3)); - curve->lineto(area.corner(0)); - sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(rect), curve); - sp_canvas_item_show(rect); - _rects = g_slist_prepend(_rects, rect); - - // scroll to make it all visible - Geom::Point const center = desktop->get_display_area().midpoint(); - area.expandBy(0.5 * mindim); - Geom::Point scrollto; - double dist = 0; - for (unsigned corner = 0; corner < 4; corner ++) { - if (Geom::L2(area.corner(corner) - center) > dist) { - dist = Geom::L2(area.corner(corner) - center); - scrollto = area.corner(corner); + // expand slightly + Geom::Rect area = Geom::Rect(tl, br); + double mindim = fabs(tl[Geom::Y] - br[Geom::Y]); + if (fabs(tl[Geom::X] - br[Geom::X]) < mindim) + mindim = fabs(tl[Geom::X] - br[Geom::X]); + area.expandBy(MAX(0.05 * mindim, 1)); + + // create canvas path rectangle, red stroke + SPCanvasItem *rect = sp_canvas_bpath_new(sp_desktop_sketch(desktop), NULL); + sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(rect), 0xff0000ff, 3.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); + sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(rect), 0, SP_WIND_RULE_NONZERO); + SPCurve *curve = new SPCurve(); + curve->moveto(area.corner(0)); + curve->lineto(area.corner(1)); + curve->lineto(area.corner(2)); + curve->lineto(area.corner(3)); + curve->lineto(area.corner(0)); + sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(rect), curve); + sp_canvas_item_show(rect); + _rects = g_slist_prepend(_rects, rect); + + // scroll to make it all visible + Geom::Point const center = desktop->get_display_area().midpoint(); + area.expandBy(0.5 * mindim); + Geom::Point scrollto; + double dist = 0; + for (unsigned corner = 0; corner < 4; corner ++) { + if (Geom::L2(area.corner(corner) - center) > dist) { + dist = Geom::L2(area.corner(corner) - center); + scrollto = area.corner(corner); + } } + desktop->scroll_to_point (scrollto, 1.0); } - desktop->scroll_to_point (scrollto, 1.0); // select text; if in Text tool, position cursor to the beginning of word // unless it is already in the word -- cgit v1.2.3 From 2af3266fc2db760a1c8771e5945a0c94587d18e8 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Wed, 26 Mar 2014 22:14:16 +0100 Subject: Cleaned up includes of tools / revert experimental casting macro replacements from r13061 (bzr r13216) --- src/ui/tools/arc-tool.h | 10 ++++- src/ui/tools/box3d-tool.h | 19 +++++++-- src/ui/tools/calligraphic-tool.h | 10 ++++- src/ui/tools/connector-tool.h | 33 ++++++++------ src/ui/tools/dropper-tool.h | 4 ++ src/ui/tools/dynamic-base.cpp | 1 + src/ui/tools/dynamic-base.h | 11 ++++- src/ui/tools/eraser-tool.cpp | 1 + src/ui/tools/eraser-tool.h | 2 + src/ui/tools/freehand-base.h | 25 +++++++---- src/ui/tools/measure-tool.cpp | 1 + src/ui/tools/pencil-tool.h | 4 ++ src/ui/tools/tool-base.cpp | 1 + src/ui/tools/tool-base.h | 92 +++++++++++++++++++++------------------- 14 files changed, 142 insertions(+), 72 deletions(-) (limited to 'src/ui') diff --git a/src/ui/tools/arc-tool.h b/src/ui/tools/arc-tool.h index eaa50f2b9..c4c67660d 100644 --- a/src/ui/tools/arc-tool.h +++ b/src/ui/tools/arc-tool.h @@ -16,12 +16,18 @@ */ #include -#include #include <2geom/point.h> +#include + #include "ui/tools/tool-base.h" -#include "sp-ellipse.h" +class SPItem; +class SPGenericEllipse; + +namespace Inkscape { + class Selection; +} #define SP_ARC_CONTEXT(obj) (dynamic_cast((Inkscape::UI::Tools::ToolBase*)obj)) #define SP_IS_ARC_CONTEXT(obj) (dynamic_cast(const Inkscape::UI::Tools::ToolBase*(obj)) != NULL) diff --git a/src/ui/tools/box3d-tool.h b/src/ui/tools/box3d-tool.h index 99bf99a7a..1dd6bb5f8 100644 --- a/src/ui/tools/box3d-tool.h +++ b/src/ui/tools/box3d-tool.h @@ -16,12 +16,25 @@ */ #include -#include -#include "ui/tools/tool-base.h" + +#include <2geom/point.h> +#include + #include "proj_pt.h" #include "vanishing-point.h" -#include "box3d.h" +#include "ui/tools/tool-base.h" + +class SPItem; +class SPBox3D; + +namespace Box3D { + struct VPDrag; +} + +namespace Inkscape { + class Selection; +} #define SP_BOX3D_CONTEXT(obj) (dynamic_cast((Inkscape::UI::Tools::ToolBase*)obj)) #define SP_IS_BOX3D_CONTEXT(obj) (dynamic_cast((const Inkscape::UI::Tools::ToolBase*)obj) != NULL) diff --git a/src/ui/tools/calligraphic-tool.h b/src/ui/tools/calligraphic-tool.h index 926e9d126..83b4d73ff 100644 --- a/src/ui/tools/calligraphic-tool.h +++ b/src/ui/tools/calligraphic-tool.h @@ -18,8 +18,16 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ +#include +#include + +#include <2geom/point.h> + #include "ui/tools/dynamic-base.h" -#include "splivarot.h" + +class SPItem; +class Path; +struct SPCanvasItem; #define DDC_MIN_PRESSURE 0.0 #define DDC_MAX_PRESSURE 1.0 diff --git a/src/ui/tools/connector-tool.h b/src/ui/tools/connector-tool.h index 59534a173..b85412a53 100644 --- a/src/ui/tools/connector-tool.h +++ b/src/ui/tools/connector-tool.h @@ -12,25 +12,34 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include -#include -#include -#include "ui/tools/tool-base.h" +#include +#include + #include <2geom/point.h> -#include "libavoid/connector.h" -#include +#include -#define SP_CONNECTOR_CONTEXT(obj) (dynamic_cast((Inkscape::UI::Tools::ToolBase*)obj)) -//#define SP_IS_CONNECTOR_CONTEXT(obj) (dynamic_cast((const ToolBase*)obj) != NULL) +#include "ui/tools/tool-base.h" -struct SPKnot; +class SPItem; class SPCurve; +struct SPKnot; +struct SPCanvasItem; + +namespace Avoid { + class ConnRef; +} + +namespace Inkscape { + class Selection; -namespace Inkscape -{ - class Selection; + namespace XML { + class Node; + } } +#define SP_CONNECTOR_CONTEXT(obj) (dynamic_cast((Inkscape::UI::Tools::ToolBase*)obj)) +//#define SP_IS_CONNECTOR_CONTEXT(obj) (dynamic_cast((const ToolBase*)obj) != NULL) + enum { SP_CONNECTOR_CONTEXT_IDLE, SP_CONNECTOR_CONTEXT_DRAGGING, diff --git a/src/ui/tools/dropper-tool.h b/src/ui/tools/dropper-tool.h index dd6f25bb6..cfeb91dab 100644 --- a/src/ui/tools/dropper-tool.h +++ b/src/ui/tools/dropper-tool.h @@ -12,8 +12,12 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ +#include <2geom/point.h> + #include "ui/tools/tool-base.h" +struct SPCanvasItem; + #define SP_DROPPER_CONTEXT(obj) (dynamic_cast((Inkscape::UI::Tools::ToolBase*)obj)) #define SP_IS_DROPPER_CONTEXT(obj) (dynamic_cast((const Inkscape::UI::Tools::ToolBase*)obj) != NULL) diff --git a/src/ui/tools/dynamic-base.cpp b/src/ui/tools/dynamic-base.cpp index 21b4b0532..eb789d850 100644 --- a/src/ui/tools/dynamic-base.cpp +++ b/src/ui/tools/dynamic-base.cpp @@ -10,6 +10,7 @@ #include "preferences.h" #include "display/sp-canvas-item.h" #include "desktop.h" +#include "display/curve.h" #define MIN_PRESSURE 0.0 #define MAX_PRESSURE 1.0 diff --git a/src/ui/tools/dynamic-base.h b/src/ui/tools/dynamic-base.h index 76fcd0f02..c948fa286 100644 --- a/src/ui/tools/dynamic-base.h +++ b/src/ui/tools/dynamic-base.h @@ -20,8 +20,15 @@ */ #include "ui/tools/tool-base.h" -#include "display/curve.h" -#include <2geom/point.h> + +struct SPCanvasItem; +class SPCurve; + +namespace Inkscape { + namespace XML { + class Node; + } +} #define SAMPLING_SIZE 8 /* fixme: ?? */ diff --git a/src/ui/tools/eraser-tool.cpp b/src/ui/tools/eraser-tool.cpp index 011d28663..4106785e7 100644 --- a/src/ui/tools/eraser-tool.cpp +++ b/src/ui/tools/eraser-tool.cpp @@ -66,6 +66,7 @@ #include "verbs.h" #include <2geom/math-utils.h> #include <2geom/pathvector.h> +#include "display/curve.h" #include "ui/tools/eraser-tool.h" diff --git a/src/ui/tools/eraser-tool.h b/src/ui/tools/eraser-tool.h index eb7eb16e8..110f57ba3 100644 --- a/src/ui/tools/eraser-tool.h +++ b/src/ui/tools/eraser-tool.h @@ -19,6 +19,8 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ +#include <2geom/point.h> + #include "ui/tools/dynamic-base.h" #define ERC_MIN_PRESSURE 0.0 diff --git a/src/ui/tools/freehand-base.h b/src/ui/tools/freehand-base.h index c8da9faed..5a4b91800 100644 --- a/src/ui/tools/freehand-base.h +++ b/src/ui/tools/freehand-base.h @@ -14,22 +14,29 @@ * Released under GNU GPL */ -#include -#include -#include <2geom/point.h> +#include + #include "ui/tools/tool-base.h" -#include "live_effects/effect.h" +#include "live_effects/effect-enum.h" + +struct SPCanvasItem; +class SPCurve; +struct SPDrawAnchor; + +namespace Inkscape { + class Selection; +} + +namespace boost { + template + class optional; +} /* Freehand context */ #define SP_DRAW_CONTEXT(obj) (dynamic_cast((Inkscape::UI::Tools::ToolBase*)obj)) #define SP_IS_DRAW_CONTEXT(obj) (dynamic_cast((const Inkscape::UI::Tools::ToolBase*)obj) != NULL) -struct SPDrawAnchor; -namespace Inkscape -{ - class Selection; -} namespace Inkscape { namespace UI { diff --git a/src/ui/tools/measure-tool.cpp b/src/ui/tools/measure-tool.cpp index 380aa79e3..2c85874bc 100644 --- a/src/ui/tools/measure-tool.cpp +++ b/src/ui/tools/measure-tool.cpp @@ -43,6 +43,7 @@ #include "sp-namedview.h" #include "enums.h" #include "ui/control-manager.h" +#include "knot-enums.h" using Inkscape::ControlManager; using Inkscape::CTLINE_SECONDARY; diff --git a/src/ui/tools/pencil-tool.h b/src/ui/tools/pencil-tool.h index efc1f60e0..2ad05606d 100644 --- a/src/ui/tools/pencil-tool.h +++ b/src/ui/tools/pencil-tool.h @@ -7,6 +7,10 @@ #include "ui/tools/freehand-base.h" +#include <2geom/piecewise.h> +#include <2geom/d2.h> +#include <2geom/sbasis.h> + #define SP_PENCIL_CONTEXT(obj) (dynamic_cast((ToolBase*)obj)) #define SP_IS_PENCIL_CONTEXT(obj) (dynamic_cast((const ToolBase*)obj) != NULL) diff --git a/src/ui/tools/tool-base.cpp b/src/ui/tools/tool-base.cpp index 752053be1..96ac95926 100644 --- a/src/ui/tools/tool-base.cpp +++ b/src/ui/tools/tool-base.cpp @@ -57,6 +57,7 @@ #include "shape-editor.h" #include "sp-guide.h" #include "color.h" +#include "knot.h" // globals for temporary switching to selector by space static bool selector_toggled = FALSE; diff --git a/src/ui/tools/tool-base.h b/src/ui/tools/tool-base.h index def6e3d91..e11a22296 100644 --- a/src/ui/tools/tool-base.h +++ b/src/ui/tools/tool-base.h @@ -12,25 +12,29 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include +#include +#include + +#include <2geom/point.h> #include +#include #include #include "knot.h" -#include "2geom/forward.h" #include "preferences.h" -class GrDrag; -class SPDesktop; -class SPItem; -class ShapeEditor; +namespace Glib { + class ustring; +} + +class GrDrag; +class SPDesktop; +class SPItem; +class ShapeEditor; namespace Inkscape { class MessageContext; class SelCue; - namespace XML { - class Node; - } } #define SP_EVENT_CONTEXT(obj) (dynamic_cast((Inkscape::UI::Tools::ToolBase*)obj)) @@ -45,8 +49,7 @@ class ToolBase; gboolean sp_event_context_snap_watchdog_callback(gpointer data); void sp_event_context_discard_delayed_snap_event(ToolBase *ec); -class DelayedSnapEvent -{ +class DelayedSnapEvent { public: enum DelayedSnapEventOrigin { UNDEFINED_HANDLER = 0, @@ -60,12 +63,19 @@ public: }; DelayedSnapEvent(ToolBase *event_context, gpointer const dse_item, gpointer dse_item2, GdkEventMotion const *event, DelayedSnapEvent::DelayedSnapEventOrigin const origin) - : _timer_id(0), _event(NULL), _item(dse_item), _item2(dse_item2), _origin(origin), _event_context(event_context) + : _timer_id(0) + , _event(NULL) + , _item(dse_item) + , _item2(dse_item2) + , _origin(origin) + , _event_context(event_context) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); double value = prefs->getDoubleLimited("/options/snapdelay/value", 0, 0, 1000); + _timer_id = g_timeout_add(value, &sp_event_context_snap_watchdog_callback, this); _event = gdk_event_copy((GdkEvent*) event); + ((GdkEventMotion *)_event)->time = GDK_CURRENT_TIME; } @@ -74,11 +84,25 @@ public: if (_event != NULL) gdk_event_free(_event); // Remove the copy of the original event } - ToolBase* getEventContext() {return _event_context;} - DelayedSnapEventOrigin getOrigin() {return _origin;} - GdkEvent* getEvent() {return _event;} - gpointer getItem() {return _item;} - gpointer getItem2() {return _item2;} + ToolBase* getEventContext() { + return _event_context; + } + + DelayedSnapEventOrigin getOrigin() { + return _origin; + } + + GdkEvent* getEvent() { + return _event; + } + + gpointer getItem() { + return _item; + } + + gpointer getItem2() { + return _item2; + } private: guint _timer_id; @@ -137,7 +161,10 @@ public: Inkscape::SelCue *_selcue; GrDrag *_grdrag; - GrDrag *get_drag () {return _grdrag;} + + GrDrag *get_drag () { + return _grdrag; + } ShapeEditor* shape_editor; @@ -162,8 +189,10 @@ public: */ class ToolPrefObserver: public Inkscape::Preferences::Observer { public: - ToolPrefObserver(Glib::ustring const &path, ToolBase *ec) : - Inkscape::Preferences::Observer(path), ec(ec) { + ToolPrefObserver(Glib::ustring const &path, ToolBase *ec) + : Inkscape::Preferences::Observer(path) + , ec(ec) + { } virtual void notify(Inkscape::Preferences::Entry const &val) { @@ -189,7 +218,6 @@ protected: /// The cursor's hot spot gint hot_x, hot_y; - /// Whether the tool should receive delayed snap events bool sp_event_context_knot_mouseover() const; @@ -226,28 +254,6 @@ void sp_toggle_dropper(SPDesktop *dt); bool sp_event_context_knot_mouseover(ToolBase *ec); } // namespace Tools - -//#include - -namespace Tool { - -template -bool is_a(const T* t) { - //static_assert(std::is_base_of(), "Destination type not derived from ToolBase."); - //static_assert(std::is_convertible(), "Cannot cast passed pointer to ToolBase*."); - - return dynamic_cast(static_cast(t)) != NULL; -} - -template -Derived* to(T* t) { - //static_assert(std::is_base_of(), "Destination type not derived from ToolBase."); - //static_assert(std::is_convertible(), "Cannot cast passed pointer to ToolBase*."); - - return dynamic_cast(static_cast(t)); -} - -} // namespace Tool } // namespace UI } // namespace Inkscape -- cgit v1.2.3 From 490cccade871fc530f7927f9eb8e7425e0e928db Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Wed, 26 Mar 2014 22:24:57 +0100 Subject: Cleaned up connector-tool, pen-tool, and pencil-tool. (bzr r13217) --- src/ui/tools/connector-tool.cpp | 96 ++++++++---------- src/ui/tools/pen-tool.cpp | 212 ++++++++++++++++++++++------------------ src/ui/tools/pencil-tool.cpp | 93 ++++++++---------- 3 files changed, 199 insertions(+), 202 deletions(-) (limited to 'src/ui') diff --git a/src/ui/tools/connector-tool.cpp b/src/ui/tools/connector-tool.cpp index d2e23837c..b72ce5346 100644 --- a/src/ui/tools/connector-tool.cpp +++ b/src/ui/tools/connector-tool.cpp @@ -379,7 +379,7 @@ cc_deselect_handle(SPKnot* knot) } bool ConnectorTool::item_handler(SPItem* item, GdkEvent* event) { - gint ret = FALSE; + bool ret = false; Geom::Point p(event->button.x, event->button.y); @@ -412,7 +412,7 @@ bool ConnectorTool::item_handler(SPItem* item, GdkEvent* event) { } } - ret = TRUE; + ret = true; } break; @@ -422,7 +422,7 @@ bool ConnectorTool::item_handler(SPItem* item, GdkEvent* event) { this->_setActiveShape(item); } - ret = TRUE; + ret = true; } break; @@ -434,7 +434,7 @@ bool ConnectorTool::item_handler(SPItem* item, GdkEvent* event) { } bool ConnectorTool::root_handler(GdkEvent* event) { - gint ret = FALSE; + bool ret = false; switch (event->type) { case GDK_BUTTON_PRESS: @@ -469,20 +469,15 @@ gint ConnectorTool::_handleButtonPress(GdkEventButton const &bevent) { Geom::Point const event_w(bevent.x, bevent.y); /* Find desktop coordinates */ Geom::Point p = this->desktop->w2d(event_w); - ToolBase *event_context = SP_EVENT_CONTEXT(this); - gint ret = FALSE; - - if ( bevent.button == 1 && !event_context->space_panning ) { - - SPDesktop *desktop = this->desktop; + bool ret = false; + if ( bevent.button == 1 && !this->space_panning ) { if (Inkscape::have_viable_layer(desktop, this->message_context) == false) { - return TRUE; + return true; } - Geom::Point const event_w(bevent.x, - bevent.y); + Geom::Point const event_w(bevent.x, bevent.y); this->xp = bevent.x; this->yp = bevent.y; @@ -520,7 +515,7 @@ gint ConnectorTool::_handleButtonPress(GdkEventButton const &bevent) { } this->state = SP_CONNECTOR_CONTEXT_DRAGGING; - ret = TRUE; + ret = true; break; } case SP_CONNECTOR_CONTEXT_DRAGGING: @@ -539,7 +534,7 @@ gint ConnectorTool::_handleButtonPress(GdkEventButton const &bevent) { } this->cc_set_active_conn(this->newconn); this->state = SP_CONNECTOR_CONTEXT_IDLE; - ret = TRUE; + ret = true; break; } case SP_CONNECTOR_CONTEXT_CLOSE: @@ -564,20 +559,19 @@ gint ConnectorTool::_handleButtonPress(GdkEventButton const &bevent) { else if (this->npoints != 0) { this->_finish(); this->state = SP_CONNECTOR_CONTEXT_IDLE; - ret = TRUE; + ret = true; } } return ret; } gint ConnectorTool::_handleMotionNotify(GdkEventMotion const &mevent) { - gint ret = FALSE; - ToolBase *event_context = SP_EVENT_CONTEXT(this); + bool ret = false; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - if (event_context->space_panning || mevent.state & GDK_BUTTON2_MASK || mevent.state & GDK_BUTTON3_MASK) { + if (this->space_panning || mevent.state & GDK_BUTTON2_MASK || mevent.state & GDK_BUTTON3_MASK) { // allow middle-button scrolling - return FALSE; + return false; } Geom::Point const event_w(mevent.x, mevent.y); @@ -586,7 +580,7 @@ gint ConnectorTool::_handleMotionNotify(GdkEventMotion const &mevent) { this->tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100); if ( ( abs( (gint) mevent.x - this->xp ) < this->tolerance ) && ( abs( (gint) mevent.y - this->yp ) < this->tolerance ) ) { - return FALSE; // Do not drag if we're within tolerance from origin. + return false; // Do not drag if we're within tolerance from origin. } } // Once the user has moved farther than tolerance from the original location @@ -594,12 +588,10 @@ gint ConnectorTool::_handleMotionNotify(GdkEventMotion const &mevent) { // the motion notify coordinates as given (no snapping back to origin) this->within_tolerance = false; - SPDesktop *const dt = this->desktop; - /* Find desktop coordinates */ - Geom::Point p = dt->w2d(event_w); + Geom::Point p = desktop->w2d(event_w); - SnapManager &m = dt->namedview->snap_manager; + SnapManager &m = desktop->namedview->snap_manager; switch (this->state) { case SP_CONNECTOR_CONTEXT_DRAGGING: @@ -607,12 +599,12 @@ gint ConnectorTool::_handleMotionNotify(GdkEventMotion const &mevent) { gobble_motion_events(mevent.state); // This is movement during a connector creation. if ( this->npoints > 0 ) { - m.setup(dt); + m.setup(desktop); m.freeSnapReturnByRef(p, Inkscape::SNAPSOURCE_OTHER_HANDLE); m.unSetup(); this->selection->clear(); this->_setSubsequentPoint(p); - ret = TRUE; + ret = true; } break; } @@ -621,7 +613,7 @@ gint ConnectorTool::_handleMotionNotify(GdkEventMotion const &mevent) { gobble_motion_events(GDK_BUTTON1_MASK); g_assert( SP_IS_PATH(this->clickeditem)); - m.setup(dt); + m.setup(desktop); m.freeSnapReturnByRef(p, Inkscape::SNAPSOURCE_OTHER_HANDLE); m.unSetup(); @@ -645,7 +637,7 @@ gint ConnectorTool::_handleMotionNotify(GdkEventMotion const &mevent) { this->red_curve->transform(i2d); sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), this->red_curve); - ret = TRUE; + ret = true; break; } case SP_CONNECTOR_CONTEXT_STOP: @@ -653,7 +645,7 @@ gint ConnectorTool::_handleMotionNotify(GdkEventMotion const &mevent) { break; default: if (!this->sp_event_context_knot_mouseover()) { - m.setup(dt); + m.setup(desktop); m.preSnap(Inkscape::SnapCandidatePoint(p, Inkscape::SNAPSOURCE_OTHER_HANDLE)); m.unSetup(); } @@ -663,13 +655,10 @@ gint ConnectorTool::_handleMotionNotify(GdkEventMotion const &mevent) { } gint ConnectorTool::_handleButtonRelease(GdkEventButton const &revent) { - gint ret = FALSE; - ToolBase *event_context = SP_EVENT_CONTEXT(this); - if ( revent.button == 1 && !event_context->space_panning ) { + bool ret = false; - SPDesktop *desktop = this->desktop; + if ( revent.button == 1 && !this->space_panning ) { SPDocument *doc = sp_desktop_document(desktop); - SnapManager &m = desktop->namedview->snap_manager; Geom::Point const event_w(revent.x, revent.y); @@ -688,7 +677,7 @@ gint ConnectorTool::_handleButtonRelease(GdkEventButton const &revent) { if (this->within_tolerance) { this->_finishSegment(p); - return TRUE; + return true; } // Connector has been created via a drag, end it now. this->_setSubsequentPoint(p); @@ -711,7 +700,7 @@ gint ConnectorTool::_handleButtonRelease(GdkEventButton const &revent) { doc->ensureUpToDate(); this->state = SP_CONNECTOR_CONTEXT_IDLE; - return TRUE; + return true; break; } case SP_CONNECTOR_CONTEXT_STOP: @@ -720,13 +709,13 @@ gint ConnectorTool::_handleButtonRelease(GdkEventButton const &revent) { default: break; } - ret = TRUE; + ret = true; } return ret; } gint ConnectorTool::_handleKeyPress(guint const keyval) { - gint ret = FALSE; + bool ret = false; switch (keyval) { case GDK_KEY_Return: @@ -734,13 +723,11 @@ gint ConnectorTool::_handleKeyPress(guint const keyval) { if (this->npoints != 0) { this->_finish(); this->state = SP_CONNECTOR_CONTEXT_IDLE; - ret = TRUE; + ret = true; } break; case GDK_KEY_Escape: if (this->state == SP_CONNECTOR_CONTEXT_REROUTING) { - - SPDesktop *desktop = this->desktop; SPDocument *doc = sp_desktop_document(desktop); this->_reroutingFinish(NULL); @@ -750,13 +737,13 @@ gint ConnectorTool::_handleKeyPress(guint const keyval) { this->state = SP_CONNECTOR_CONTEXT_IDLE; desktop->messageStack()->flash( Inkscape::NORMAL_MESSAGE, _("Connector endpoint drag cancelled.")); - ret = TRUE; + ret = true; } else if (this->npoints != 0) { // if drawing, cancel, otherwise pass it up for deselecting this->state = SP_CONNECTOR_CONTEXT_STOP; this->_resetColors(); - ret = TRUE; + ret = true; } break; default: @@ -766,7 +753,6 @@ gint ConnectorTool::_handleKeyPress(guint const keyval) { } void ConnectorTool::_reroutingFinish(Geom::Point *const p) { - SPDesktop *desktop = this->desktop; SPDocument *doc = sp_desktop_document(desktop); // Clear the temporary path: @@ -819,14 +805,13 @@ void ConnectorTool::_setInitialPoint(Geom::Point const p) { void ConnectorTool::_setSubsequentPoint(Geom::Point const p) { g_assert( this->npoints != 0 ); - SPDesktop *dt = this->desktop; - Geom::Point o = dt->dt2doc(this->p[0]); - Geom::Point d = dt->dt2doc(p); + Geom::Point o = desktop->dt2doc(this->p[0]); + Geom::Point d = desktop->dt2doc(p); Avoid::Point src(o[Geom::X], o[Geom::Y]); Avoid::Point dst(d[Geom::X], d[Geom::Y]); if (!this->newConnRef) { - Avoid::Router *router = sp_desktop_document(dt)->router; + Avoid::Router *router = sp_desktop_document(desktop)->router; this->newConnRef = new Avoid::ConnRef(router); this->newConnRef->setEndpoint(Avoid::VertID::src, src); if (this->isOrthogonal) @@ -841,7 +826,7 @@ void ConnectorTool::_setSubsequentPoint(Geom::Point const p) { this->newConnRef->router()->processTransaction(); // Recreate curve from libavoid route. recreateCurve( this->red_curve, this->newConnRef, this->curvature ); - this->red_curve->transform(dt->doc2dt()); + this->red_curve->transform(desktop->doc2dt()); sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), this->red_curve); } @@ -890,7 +875,6 @@ void ConnectorTool::_flushWhite(SPCurve *gc) { /* Now we have to go back to item coordinates at last */ c->transform(this->desktop->dt2doc()); - SPDesktop *desktop = this->desktop; SPDocument *doc = sp_desktop_document(desktop); Inkscape::XML::Document *xml_doc = doc->getReprDoc(); @@ -965,7 +949,6 @@ void ConnectorTool::_finishSegment(Geom::Point const /*p*/) { } void ConnectorTool::_finish() { - SPDesktop *const desktop = this->desktop; desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Finishing connector")); this->red_curve->reset(); @@ -1083,7 +1066,6 @@ endpt_handler(SPKnot */*knot*/, GdkEvent *event, ConnectorTool *cc) } void ConnectorTool::_activeShapeAddKnot(SPItem* item) { - SPDesktop *desktop = this->desktop; SPKnot *knot = sp_knot_new(desktop, 0); knot->owner = item; @@ -1096,10 +1078,12 @@ void ConnectorTool::_activeShapeAddKnot(SPItem* item) { // We don't want to use the standard knot handler. g_signal_handler_disconnect(G_OBJECT(knot->item), knot->_event_handler_id); + knot->_event_handler_id = 0; g_signal_connect(G_OBJECT(knot->item), "event", G_CALLBACK(cc_generic_knot_handler), knot); + sp_knot_set_position(knot, item->avoidRef->getConnectionPointPos() * desktop->doc2dt(), 0); sp_knot_show(knot); this->knots[knot] = 1; @@ -1198,7 +1182,6 @@ void ConnectorTool::cc_set_active_conn(SPItem *item) { } for (int i = 0; i < 2; ++i) { - // Create the handle if it doesn't exist if ( this->endpt_handle[i] == NULL ) { SPKnot *knot = sp_knot_new(this->desktop, @@ -1215,6 +1198,7 @@ void ConnectorTool::cc_set_active_conn(SPItem *item) { // since we don't want this knot to be draggable. g_signal_handler_disconnect(G_OBJECT(knot->item), knot->_event_handler_id); + knot->_event_handler_id = 0; g_signal_connect(G_OBJECT(knot->item), "event", @@ -1228,6 +1212,7 @@ void ConnectorTool::cc_set_active_conn(SPItem *item) { g_signal_handlers_disconnect_by_func( G_OBJECT(this->endpt_handle[i]->item), (void*)G_CALLBACK(endpt_handler), (gpointer) this ); + this->endpt_handler_id[i] = 0; } @@ -1264,10 +1249,13 @@ void cc_create_connection_point(ConnectorTool* cc) { cc_deselect_handle( cc->selected_handle ); } + SPKnot *knot = sp_knot_new(cc->desktop, 0); + // We do not process events on this knot. g_signal_handler_disconnect(G_OBJECT(knot->item), knot->_event_handler_id); + knot->_event_handler_id = 0; cc_select_handle( knot ); diff --git a/src/ui/tools/pen-tool.cpp b/src/ui/tools/pen-tool.cpp index 7228690b1..ea66360d0 100644 --- a/src/ui/tools/pen-tool.cpp +++ b/src/ui/tools/pen-tool.cpp @@ -263,7 +263,7 @@ void PenTool::_endpointSnapHandle(Geom::Point &p, guint const state) const { } bool PenTool::item_handler(SPItem* item, GdkEvent* event) { - gint ret = FALSE; + bool ret = false; switch (event->type) { case GDK_BUTTON_PRESS: @@ -287,7 +287,7 @@ bool PenTool::item_handler(SPItem* item, GdkEvent* event) { * Callback to handle all pen events. */ bool PenTool::root_handler(GdkEvent* event) { - gint ret = FALSE; + bool ret = false; switch (event->type) { case GDK_BUTTON_PRESS: @@ -327,22 +327,20 @@ bool PenTool::root_handler(GdkEvent* event) { gint PenTool::_handleButtonPress(GdkEventButton const &bevent) { if (this->events_disabled) { // skip event processing if events are disabled - return FALSE; + return false; } - FreehandBase * const dc = SP_DRAW_CONTEXT(this); - SPDesktop * const desktop = dc->desktop; Geom::Point const event_w(bevent.x, bevent.y); Geom::Point event_dt(desktop->w2d(event_w)); - ToolBase *event_context = SP_EVENT_CONTEXT(this); - gint ret = FALSE; - if (bevent.button == 1 && !event_context->space_panning + bool ret = false; + + if (bevent.button == 1 && !this->space_panning // make sure this is not the last click for a waiting LPE (otherwise we want to finish the path) && this->expecting_clicks_for_LPE != 1) { - if (Inkscape::have_viable_layer(desktop, dc->message_context) == false) { - return TRUE; + if (Inkscape::have_viable_layer(desktop, this->message_context) == false) { + return true; } if (!this->grab ) { @@ -392,8 +390,8 @@ gint PenTool::_handleButtonPress(GdkEventButton const &bevent) { m.freeSnapReturnByRef(p, Inkscape::SNAPSOURCE_NODE_HANDLE); m.unSetup(); } - spdc_create_single_dot(event_context, p, "/tools/freehand/pen", bevent.state); - ret = TRUE; + spdc_create_single_dot(this, p, "/tools/freehand/pen", bevent.state); + ret = true; break; } @@ -441,9 +439,9 @@ gint PenTool::_handleButtonPress(GdkEventButton const &bevent) { if (this->green_anchor && this->green_anchor->active) { // we clicked on the current curve start, so close it even if // we drag a handle away from it - dc->green_closed = TRUE; + this->green_closed = TRUE; } - ret = TRUE; + ret = true; break; } else { @@ -454,7 +452,7 @@ gint PenTool::_handleButtonPress(GdkEventButton const &bevent) { } this->state = this->polylines_only ? PenTool::POINT : PenTool::CONTROL; - ret = TRUE; + ret = true; break; case PenTool::CONTROL: g_warning("Button down in CONTROL state"); @@ -474,17 +472,17 @@ gint PenTool::_handleButtonPress(GdkEventButton const &bevent) { this->_finishSegment(event_dt, bevent.state); if (this->green_closed) { // finishing at the start anchor, close curve - this->_finish(TRUE); + this->_finish(true); } else { // finishing at some other anchor, finish curve but not close - this->_finish(FALSE); + this->_finish(false); } - ret = TRUE; + ret = true; } else if (bevent.button == 3 && this->npoints != 0) { // right click - finish path - this->_finish(FALSE); - ret = TRUE; + this->_finish(false); + ret = true; } if (this->expecting_clicks_for_LPE > 0) { @@ -498,28 +496,25 @@ gint PenTool::_handleButtonPress(GdkEventButton const &bevent) { * Handle motion_notify event. */ gint PenTool::_handleMotionNotify(GdkEventMotion const &mevent) { - gint ret = FALSE; - - ToolBase *event_context = SP_EVENT_CONTEXT(this); - SPDesktop * const dt = event_context->desktop; + bool ret = false; - if (event_context->space_panning || mevent.state & GDK_BUTTON2_MASK || mevent.state & GDK_BUTTON3_MASK) { + if (this->space_panning || mevent.state & GDK_BUTTON2_MASK || mevent.state & GDK_BUTTON3_MASK) { // allow scrolling - return FALSE; + return false; } if (this->events_disabled) { // skip motion events if pen events are disabled - return FALSE; + return false; } - Geom::Point const event_w(mevent.x, - mevent.y); + Geom::Point const event_w(mevent.x, mevent.y); + if (pen_within_tolerance) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); gint const tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100); if ( Geom::LInfty( event_w - pen_drag_origin_w ) < tolerance ) { - return FALSE; // Do not drag if we're within tolerance from origin. + return false; // Do not drag if we're within tolerance from origin. } } // Once the user has moved farther than tolerance from the original location @@ -528,7 +523,7 @@ gint PenTool::_handleMotionNotify(GdkEventMotion const &mevent) { pen_within_tolerance = false; // Find desktop coordinates - Geom::Point p = dt->w2d(event_w); + Geom::Point p = desktop->w2d(event_w); // Test, whether we hit any anchor SPDrawAnchor *anchor = spdc_test_inside(this, event_w); @@ -543,8 +538,8 @@ gint PenTool::_handleMotionNotify(GdkEventMotion const &mevent) { this->_setSubsequentPoint(p, true); ret = TRUE; } else if (!this->sp_event_context_knot_mouseover()) { - SnapManager &m = dt->namedview->snap_manager; - m.setup(dt); + SnapManager &m = desktop->namedview->snap_manager; + m.setup(desktop); m.preSnap(Inkscape::SnapCandidatePoint(p, Inkscape::SNAPSOURCE_NODE_HANDLE)); m.unSetup(); } @@ -554,7 +549,7 @@ gint PenTool::_handleMotionNotify(GdkEventMotion const &mevent) { // Placing controls is last operation in CLOSE state this->_endpointSnap(p, mevent.state); this->_setCtrl(p, mevent.state); - ret = TRUE; + ret = true; break; case PenTool::STOP: // This is perfectly valid @@ -584,7 +579,7 @@ gint PenTool::_handleMotionNotify(GdkEventMotion const &mevent) { this->anchor_statusbar = false; } - ret = TRUE; + ret = true; } else { if (anchor && !this->anchor_statusbar) { this->message_context->set(Inkscape::NORMAL_MESSAGE, _("Click or click and drag to continue the path from this point.")); @@ -594,8 +589,8 @@ gint PenTool::_handleMotionNotify(GdkEventMotion const &mevent) { this->anchor_statusbar = false; } if (!this->sp_event_context_knot_mouseover()) { - SnapManager &m = dt->namedview->snap_manager; - m.setup(dt); + SnapManager &m = desktop->namedview->snap_manager; + m.setup(desktop); m.preSnap(Inkscape::SnapCandidatePoint(p, Inkscape::SNAPSOURCE_NODE_HANDLE)); m.unSetup(); } @@ -614,15 +609,15 @@ gint PenTool::_handleMotionNotify(GdkEventMotion const &mevent) { this->_setCtrl(this->p[1], mevent.state); } gobble_motion_events(GDK_BUTTON1_MASK); - ret = TRUE; + ret = true; break; case PenTool::STOP: // This is perfectly valid break; default: if (!this->sp_event_context_knot_mouseover()) { - SnapManager &m = dt->namedview->snap_manager; - m.setup(dt); + SnapManager &m = desktop->namedview->snap_manager; + m.setup(desktop); m.preSnap(Inkscape::SnapCandidatePoint(p, Inkscape::SNAPSOURCE_NODE_HANDLE)); m.unSetup(); } @@ -641,17 +636,14 @@ gint PenTool::_handleMotionNotify(GdkEventMotion const &mevent) { gint PenTool::_handleButtonRelease(GdkEventButton const &revent) { if (this->events_disabled) { // skip event processing if events are disabled - return FALSE; + return false; } - gint ret = FALSE; - ToolBase *event_context = SP_EVENT_CONTEXT(this); - if ( revent.button == 1 && !event_context->space_panning) { + bool ret = false; - FreehandBase *dc = SP_DRAW_CONTEXT (this); + if (revent.button == 1 && !this->space_panning) { + Geom::Point const event_w(revent.x, revent.y); - Geom::Point const event_w(revent.x, - revent.y); // Find desktop coordinates Geom::Point p = this->desktop->w2d(event_w); @@ -677,14 +669,14 @@ gint PenTool::_handleButtonRelease(GdkEventButton const &revent) { } } this->state = PenTool::CONTROL; - ret = TRUE; + ret = true; break; case PenTool::CONTROL: // End current segment this->_endpointSnap(p, revent.state); this->_finishSegment(p, revent.state); this->state = PenTool::POINT; - ret = TRUE; + ret = true; break; case PenTool::CLOSE: // End current segment @@ -692,14 +684,14 @@ gint PenTool::_handleButtonRelease(GdkEventButton const &revent) { this->_endpointSnap(p, revent.state); } this->_finishSegment(p, revent.state); - this->_finish(TRUE); + this->_finish(true); this->state = PenTool::POINT; - ret = TRUE; + ret = true; break; case PenTool::STOP: // This is allowed, if we just canceled curve this->state = PenTool::POINT; - ret = TRUE; + ret = true; break; default: break; @@ -717,10 +709,10 @@ gint PenTool::_handleButtonRelease(GdkEventButton const &revent) { this->_finishSegment(p, revent.state); if (this->green_closed) { // finishing at the start anchor, close curve - this->_finish(TRUE); + this->_finish(true); } else { // finishing at some other anchor, finish curve but not close - this->_finish(FALSE); + this->_finish(false); } break; case PenTool::STOP: @@ -730,7 +722,7 @@ gint PenTool::_handleButtonRelease(GdkEventButton const &revent) { break; } this->state = PenTool::POINT; - ret = TRUE; + ret = true; break; default: break; @@ -742,9 +734,9 @@ gint PenTool::_handleButtonRelease(GdkEventButton const &revent) { this->grab = NULL; } - ret = TRUE; + ret = true; - dc->green_closed = FALSE; + this->green_closed = FALSE; } // TODO: can we be sure that the path was created correctly? @@ -752,13 +744,12 @@ gint PenTool::_handleButtonRelease(GdkEventButton const &revent) { if (this->expecting_clicks_for_LPE == 0 && this->hasWaitingLPE()) { this->setPolylineMode(); - ToolBase *ec = SP_EVENT_CONTEXT(this); - Inkscape::Selection *selection = sp_desktop_selection (ec->desktop); + Inkscape::Selection *selection = sp_desktop_selection(this->desktop); if (this->waiting_LPE) { // we have an already created LPE waiting for a path this->waiting_LPE->acceptParamPath(SP_PATH(selection->singleItem())); - selection->add(SP_OBJECT(this->waiting_item)); + selection->add(this->waiting_item); this->waiting_LPE = NULL; } else { // the case that we need to create a new LPE and apply it to the just-drawn path is @@ -770,11 +761,11 @@ gint PenTool::_handleButtonRelease(GdkEventButton const &revent) { } gint PenTool::_handle2ButtonPress(GdkEventButton const &bevent) { - gint ret = FALSE; + bool ret = false; // only end on LMB double click. Otherwise horizontal scrolling causes ending of the path if (this->npoints != 0 && bevent.button == 1) { this->_finish(FALSE); - ret = TRUE; + ret = true; } return ret; } @@ -881,67 +872,97 @@ void PenTool::_lastpointToLine() { gint PenTool::_handleKeyPress(GdkEvent *event) { - - gint ret = FALSE; + bool ret = false; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); gdouble const nudge = prefs->getDoubleLimited("/options/nudgedistance/value", 2, 0, 1000, "px"); // in px switch (get_group0_keyval (&event->key)) { - case GDK_KEY_Left: // move last point left case GDK_KEY_KP_Left: if (!MOD__CTRL(event)) { // not ctrl if (MOD__ALT(event)) { // alt - if (MOD__SHIFT(event)) this->_lastpointMoveScreen(-10, 0); // shift - else this->_lastpointMoveScreen(-1, 0); // no shift + if (MOD__SHIFT(event)) { + this->_lastpointMoveScreen(-10, 0); // shift + } + else { + this->_lastpointMoveScreen(-1, 0); // no shift + } } else { // no alt - if (MOD__SHIFT(event)) this->_lastpointMove(-10*nudge, 0); // shift - else this->_lastpointMove(-nudge, 0); // no shift + if (MOD__SHIFT(event)) { + this->_lastpointMove(-10*nudge, 0); // shift + } + else { + this->_lastpointMove(-nudge, 0); // no shift + } } - ret = TRUE; + ret = true; } break; case GDK_KEY_Up: // move last point up case GDK_KEY_KP_Up: if (!MOD__CTRL(event)) { // not ctrl if (MOD__ALT(event)) { // alt - if (MOD__SHIFT(event)) this->_lastpointMoveScreen(0, 10); // shift - else this->_lastpointMoveScreen(0, 1); // no shift + if (MOD__SHIFT(event)) { + this->_lastpointMoveScreen(0, 10); // shift + } + else { + this->_lastpointMoveScreen(0, 1); // no shift + } } else { // no alt - if (MOD__SHIFT(event)) this->_lastpointMove(0, 10*nudge); // shift - else this->_lastpointMove(0, nudge); // no shift + if (MOD__SHIFT(event)) { + this->_lastpointMove(0, 10*nudge); // shift + } + else { + this->_lastpointMove(0, nudge); // no shift + } } - ret = TRUE; + ret = true; } break; case GDK_KEY_Right: // move last point right case GDK_KEY_KP_Right: if (!MOD__CTRL(event)) { // not ctrl if (MOD__ALT(event)) { // alt - if (MOD__SHIFT(event)) this->_lastpointMoveScreen(10, 0); // shift - else this->_lastpointMoveScreen(1, 0); // no shift + if (MOD__SHIFT(event)) { + this->_lastpointMoveScreen(10, 0); // shift + } + else { + this->_lastpointMoveScreen(1, 0); // no shift + } } else { // no alt - if (MOD__SHIFT(event)) this->_lastpointMove(10*nudge, 0); // shift - else this->_lastpointMove(nudge, 0); // no shift + if (MOD__SHIFT(event)) { + this->_lastpointMove(10*nudge, 0); // shift + } + else { + this->_lastpointMove(nudge, 0); // no shift + } } - ret = TRUE; + ret = true; } break; case GDK_KEY_Down: // move last point down case GDK_KEY_KP_Down: if (!MOD__CTRL(event)) { // not ctrl if (MOD__ALT(event)) { // alt - if (MOD__SHIFT(event)) this->_lastpointMoveScreen(0, -10); // shift - else this->_lastpointMoveScreen(0, -1); // no shift + if (MOD__SHIFT(event)) { + this->_lastpointMoveScreen(0, -10); // shift + } + else { + this->_lastpointMoveScreen(0, -1); // no shift + } } else { // no alt - if (MOD__SHIFT(event)) this->_lastpointMove(0, -10*nudge); // shift - else this->_lastpointMove(0, -nudge); // no shift + if (MOD__SHIFT(event)) { + this->_lastpointMove(0, -10*nudge); // shift + } + else { + this->_lastpointMove(0, -nudge); // no shift + } } - ret = TRUE; + ret = true; } break; @@ -983,29 +1004,29 @@ gint PenTool::_handleKeyPress(GdkEvent *event) { case GDK_KEY_u: if (MOD__SHIFT_ONLY(event)) { this->_lastpointToCurve(); - ret = TRUE; + ret = true; } break; case GDK_KEY_L: case GDK_KEY_l: if (MOD__SHIFT_ONLY(event)) { this->_lastpointToLine(); - ret = TRUE; + ret = true; } break; case GDK_KEY_Return: case GDK_KEY_KP_Enter: if (this->npoints != 0) { - this->_finish(FALSE); - ret = TRUE; + this->_finish(false); + ret = true; } break; case GDK_KEY_Escape: if (this->npoints != 0) { // if drawing, cancel, otherwise pass it up for deselecting this->_cancel (); - ret = TRUE; + ret = true; } break; case GDK_KEY_z: @@ -1013,13 +1034,13 @@ gint PenTool::_handleKeyPress(GdkEvent *event) { if (MOD__CTRL_ONLY(event) && this->npoints != 0) { // if drawing, cancel, otherwise pass it up for undo this->_cancel (); - ret = TRUE; + ret = true; } break; case GDK_KEY_g: case GDK_KEY_G: if (MOD__SHIFT_ONLY(event)) { - sp_selection_to_guides(SP_EVENT_CONTEXT(this)->desktop); + sp_selection_to_guides(this->desktop); ret = true; } break; @@ -1029,7 +1050,7 @@ gint PenTool::_handleKeyPress(GdkEvent *event) { if ( this->green_curve->is_empty() || (this->green_curve->last_segment() == NULL) ) { if (!this->red_curve->is_empty()) { this->_cancel (); - ret = TRUE; + ret = true; } else { // do nothing; this event should be handled upstream } @@ -1067,7 +1088,7 @@ gint PenTool::_handleKeyPress(GdkEvent *event) { this->state = PenTool::POINT; this->_setSubsequentPoint(pt, true); pen_last_paraxial_dir = !pen_last_paraxial_dir; - ret = TRUE; + ret = true; } break; default: @@ -1120,7 +1141,6 @@ void PenTool::_setAngleDistanceStatusMessage(Geom::Point const p, int pc_point_t g_assert((pc_point_to_compare == 0) || (pc_point_to_compare == 3)); // exclude control handles g_assert(message != NULL); - SPDesktop *desktop = SP_EVENT_CONTEXT(this)->desktop; Geom::Point rel = p - this->p[pc_point_to_compare]; Inkscape::Util::Quantity q = Inkscape::Util::Quantity(Geom::L2(rel), "px"); GString *dist = g_string_new(q.string(desktop->namedview->doc_units).c_str()); @@ -1257,7 +1277,6 @@ void PenTool::_finish(gboolean const closed) { this->_disableEvents(); - SPDesktop *const desktop = this->desktop; this->message_context->clear(); desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Drawing finished")); @@ -1278,7 +1297,6 @@ void PenTool::_finish(gboolean const closed) { this->green_anchor = sp_draw_anchor_destroy(this->green_anchor); } - this->desktop->canvas->endForcedFullRedraws(); this->_enableEvents(); diff --git a/src/ui/tools/pencil-tool.cpp b/src/ui/tools/pencil-tool.cpp index 230ec62af..88bba34cf 100644 --- a/src/ui/tools/pencil-tool.cpp +++ b/src/ui/tools/pencil-tool.cpp @@ -115,7 +115,7 @@ void PencilTool::_endpointSnap(Geom::Point &p, guint const state) { * Callback for handling all pencil context events. */ bool PencilTool::root_handler(GdkEvent* event) { - gint ret = FALSE; + bool ret = false; switch (event->type) { case GDK_BUTTON_PRESS: @@ -150,16 +150,13 @@ bool PencilTool::root_handler(GdkEvent* event) { } gint PencilTool::_handleButtonPress(GdkEventButton const &bevent) { - gint ret = FALSE; - ToolBase *event_context = SP_EVENT_CONTEXT(this); - if ( bevent.button == 1 && !event_context->space_panning) { + bool ret = false; - FreehandBase *dc = SP_DRAW_CONTEXT (this); - SPDesktop *desktop = dc->desktop; + if ( bevent.button == 1 && !this->space_panning) { Inkscape::Selection *selection = sp_desktop_selection(desktop); - if (Inkscape::have_viable_layer(desktop, dc->message_context) == false) { - return TRUE; + if (Inkscape::have_viable_layer(desktop, this->message_context) == false) { + return true; } if (!this->grab) { @@ -185,7 +182,7 @@ gint PencilTool::_handleButtonPress(GdkEventButton const &bevent) { switch (this->state) { case SP_PENCIL_CONTEXT_ADDLINE: /* Current segment will be finished with release */ - ret = TRUE; + ret = true; break; default: /* Set first point of sequence */ @@ -196,7 +193,7 @@ gint PencilTool::_handleButtonPress(GdkEventButton const &bevent) { if (!(bevent.state & GDK_SHIFT_MASK)) { m.freeSnapReturnByRef(p, Inkscape::SNAPSOURCE_NODE_HANDLE); } - spdc_create_single_dot(event_context, p, "/tools/freehand/pencil", bevent.state); + spdc_create_single_dot(this, p, "/tools/freehand/pencil", bevent.state); m.unSetup(); ret = true; break; @@ -221,7 +218,7 @@ gint PencilTool::_handleButtonPress(GdkEventButton const &bevent) { } this->sa = anchor; this->_setStartpoint(p); - ret = TRUE; + ret = true; break; } @@ -231,25 +228,23 @@ gint PencilTool::_handleButtonPress(GdkEventButton const &bevent) { } gint PencilTool::_handleMotionNotify(GdkEventMotion const &mevent) { - SPDesktop *const dt = this->desktop; - if ((mevent.state & GDK_CONTROL_MASK) && (mevent.state & GDK_BUTTON1_MASK)) { // mouse was accidentally moved during Ctrl+click; // ignore the motion and create a single point this->is_drawing = false; - return TRUE; + return true; } - gint ret = FALSE; - ToolBase *event_context = SP_EVENT_CONTEXT(this); - if (event_context->space_panning || mevent.state & GDK_BUTTON2_MASK || mevent.state & GDK_BUTTON3_MASK) { + bool ret = false; + + if (this->space_panning || mevent.state & GDK_BUTTON2_MASK || mevent.state & GDK_BUTTON3_MASK) { // allow scrolling - return FALSE; + return false; } if ( ( mevent.state & GDK_BUTTON1_MASK ) && !this->grab && this->is_drawing) { /* Grab mouse, so release will not pass unnoticed */ - this->grab = SP_CANVAS_ITEM(dt->acetate); + this->grab = SP_CANVAS_ITEM(desktop->acetate); sp_canvas_item_grab(this->grab, ( GDK_KEY_PRESS_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK ), @@ -257,7 +252,7 @@ gint PencilTool::_handleMotionNotify(GdkEventMotion const &mevent) { } /* Find desktop coordinates */ - Geom::Point p = dt->w2d(Geom::Point(mevent.x, mevent.y)); + Geom::Point p = desktop->w2d(Geom::Point(mevent.x, mevent.y)); /* Test whether we hit any anchor. */ SPDrawAnchor *anchor = spdc_test_inside(this, Geom::Point(mevent.x, mevent.y)); @@ -266,7 +261,7 @@ gint PencilTool::_handleMotionNotify(GdkEventMotion const &mevent) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); gint const tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100); if ( Geom::LInfty( Geom::Point(mevent.x,mevent.y) - pencil_drag_origin_w ) < tolerance ) { - return FALSE; // Do not drag if we're within tolerance from origin. + return false; // Do not drag if we're within tolerance from origin. } } @@ -286,13 +281,13 @@ gint PencilTool::_handleMotionNotify(GdkEventMotion const &mevent) { p = ptnr; } this->_setEndpoint(p); - ret = TRUE; + ret = true; break; default: /* We may be idle or already freehand */ if ( mevent.state & GDK_BUTTON1_MASK && this->is_drawing ) { if (this->state == SP_PENCIL_CONTEXT_IDLE) { - sp_event_context_discard_delayed_snap_event(event_context); + sp_event_context_discard_delayed_snap_event(this); } this->state = SP_PENCIL_CONTEXT_FREEHAND; @@ -313,7 +308,7 @@ gint PencilTool::_handleMotionNotify(GdkEventMotion const &mevent) { this->ps.push_back(this->p[0]); } this->_addFreehandPoint(p, mevent.state); - ret = TRUE; + ret = true; } if (anchor && !this->anchor_statusbar) { @@ -340,8 +335,8 @@ gint PencilTool::_handleMotionNotify(GdkEventMotion const &mevent) { // a) press the mousebutton to start a freehand drawing, or // b) release the mousebutton to finish a freehand drawing if (!this->sp_event_context_knot_mouseover()) { - SnapManager &m = dt->namedview->snap_manager; - m.setup(dt); + SnapManager &m = desktop->namedview->snap_manager; + m.setup(desktop); m.preSnap(Inkscape::SnapCandidatePoint(p, Inkscape::SNAPSOURCE_NODE_HANDLE)); m.unSetup(); } @@ -351,20 +346,16 @@ gint PencilTool::_handleMotionNotify(GdkEventMotion const &mevent) { } gint PencilTool::_handleButtonRelease(GdkEventButton const &revent) { - gint ret = FALSE; - - ToolBase *event_context = SP_EVENT_CONTEXT(this); - if ( revent.button == 1 && this->is_drawing && !event_context->space_panning) { - SPDesktop *const dt = this->desktop; + bool ret = false; + if ( revent.button == 1 && this->is_drawing && !this->space_panning) { this->is_drawing = false; /* Find desktop coordinates */ - Geom::Point p = dt->w2d(Geom::Point(revent.x, revent.y)); + Geom::Point p = desktop->w2d(Geom::Point(revent.x, revent.y)); /* Test whether we hit any anchor. */ - SPDrawAnchor *anchor = spdc_test_inside(this, Geom::Point(revent.x, - revent.y)); + SPDrawAnchor *anchor = spdc_test_inside(this, Geom::Point(revent.x, revent.y)); switch (this->state) { case SP_PENCIL_CONTEXT_IDLE: @@ -374,7 +365,7 @@ gint PencilTool::_handleButtonRelease(GdkEventButton const &revent) { // Ctrl+click creates a single point so only set context in ADDLINE mode when Ctrl isn't pressed this->state = SP_PENCIL_CONTEXT_ADDLINE; } - ret = TRUE; + ret = true; break; case SP_PENCIL_CONTEXT_ADDLINE: /* Finish segment now */ @@ -387,13 +378,12 @@ gint PencilTool::_handleButtonRelease(GdkEventButton const &revent) { this->_setEndpoint(p); this->_finishEndpoint(); this->state = SP_PENCIL_CONTEXT_IDLE; - sp_event_context_discard_delayed_snap_event(event_context); - ret = TRUE; + sp_event_context_discard_delayed_snap_event(this); + ret = true; break; case SP_PENCIL_CONTEXT_FREEHAND: if (revent.state & GDK_MOD1_MASK) { /* sketch mode: interpolate the sketched path and improve the current output path with the new interpolation. don't finish sketch */ - this->_sketchInterpolate(); if (this->green_anchor) { @@ -418,7 +408,7 @@ gint PencilTool::_handleButtonRelease(GdkEventButton const &revent) { this->ea = anchor; /* Write curves to object */ - dt->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Finishing freehand")); + desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Finishing freehand")); this->_interpolate(); spdc_concat_colors_and_flush(this, FALSE); @@ -431,7 +421,7 @@ gint PencilTool::_handleButtonRelease(GdkEventButton const &revent) { // reset sketch mode too this->sketch_n = 0; } - ret = TRUE; + ret = true; break; case SP_PENCIL_CONTEXT_SKETCH: default: @@ -444,7 +434,7 @@ gint PencilTool::_handleButtonRelease(GdkEventButton const &revent) { this->grab = NULL; } - ret = TRUE; + ret = true; } return ret; } @@ -458,7 +448,7 @@ void PencilTool::_cancel() { this->is_drawing = false; this->state = SP_PENCIL_CONTEXT_IDLE; - sp_event_context_discard_delayed_snap_event(SP_EVENT_CONTEXT(this)); + sp_event_context_discard_delayed_snap_event(this); this->red_curve->reset(); sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), NULL); @@ -478,7 +468,8 @@ void PencilTool::_cancel() { } gint PencilTool::_handleKeyPress(guint const keyval, guint const state) { - gint ret = FALSE; + bool ret = false; + switch (keyval) { case GDK_KEY_Up: case GDK_KEY_Down: @@ -486,7 +477,7 @@ gint PencilTool::_handleKeyPress(guint const keyval, guint const state) { case GDK_KEY_KP_Down: // Prevent the zoom field from activation. if (!mod_ctrl_only(state)) { - ret = TRUE; + ret = true; } break; case GDK_KEY_Escape: @@ -494,7 +485,7 @@ gint PencilTool::_handleKeyPress(guint const keyval, guint const state) { // if drawing, cancel, otherwise pass it up for deselecting if (this->state != SP_PENCIL_CONTEXT_IDLE) { this->_cancel(); - ret = TRUE; + ret = true; } } break; @@ -504,14 +495,14 @@ gint PencilTool::_handleKeyPress(guint const keyval, guint const state) { // if drawing, cancel, otherwise pass it up for undo if (this->state != SP_PENCIL_CONTEXT_IDLE) { this->_cancel(); - ret = TRUE; + ret = true; } } break; case GDK_KEY_g: case GDK_KEY_G: if (mod_shift_only(state)) { - sp_selection_to_guides(SP_EVENT_CONTEXT(this)->desktop); + sp_selection_to_guides(this->desktop); ret = true; } break; @@ -530,14 +521,14 @@ gint PencilTool::_handleKeyPress(guint const keyval, guint const state) { } gint PencilTool::_handleKeyRelease(guint const keyval, guint const /*state*/) { - gint ret = FALSE; + bool ret = false; switch (keyval) { case GDK_KEY_Alt_L: case GDK_KEY_Alt_R: case GDK_KEY_Meta_L: case GDK_KEY_Meta_R: if (this->state == SP_PENCIL_CONTEXT_SKETCH) { - spdc_concat_colors_and_flush(this, FALSE); + spdc_concat_colors_and_flush(this, false); this->sketch_n = 0; this->sa = NULL; this->ea = NULL; @@ -545,9 +536,9 @@ gint PencilTool::_handleKeyRelease(guint const keyval, guint const /*state*/) { this->green_anchor = sp_draw_anchor_destroy(this->green_anchor); } this->state = SP_PENCIL_CONTEXT_IDLE; - sp_event_context_discard_delayed_snap_event(SP_EVENT_CONTEXT(this)); + sp_event_context_discard_delayed_snap_event(this); this->desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Finishing freehand sketch")); - ret = TRUE; + ret = true; } break; default: -- cgit v1.2.3 From f8c86a279932d95dc938cab0343fb22383e9fa86 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Wed, 26 Mar 2014 23:06:03 +0100 Subject: Cleaned up pencil-tool. (bzr r13219) --- src/ui/tools/pencil-tool.cpp | 84 +++++++++++++++++++------------------------- 1 file changed, 37 insertions(+), 47 deletions(-) (limited to 'src/ui') diff --git a/src/ui/tools/pencil-tool.cpp b/src/ui/tools/pencil-tool.cpp index 88bba34cf..86274928b 100644 --- a/src/ui/tools/pencil-tool.cpp +++ b/src/ui/tools/pencil-tool.cpp @@ -237,7 +237,7 @@ gint PencilTool::_handleMotionNotify(GdkEventMotion const &mevent) { bool ret = false; - if (this->space_panning || mevent.state & GDK_BUTTON2_MASK || mevent.state & GDK_BUTTON3_MASK) { + if (this->space_panning || (mevent.state & GDK_BUTTON2_MASK) || (mevent.state & GDK_BUTTON3_MASK)) { // allow scrolling return false; } @@ -285,7 +285,7 @@ gint PencilTool::_handleMotionNotify(GdkEventMotion const &mevent) { break; default: /* We may be idle or already freehand */ - if ( mevent.state & GDK_BUTTON1_MASK && this->is_drawing ) { + if ( (mevent.state & GDK_BUTTON1_MASK) && this->is_drawing ) { if (this->state == SP_PENCIL_CONTEXT_IDLE) { sp_event_context_discard_delayed_snap_event(this); } @@ -641,37 +641,31 @@ void PencilTool::_interpolate() { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); double const tol = prefs->getDoubleLimited("/tools/freehand/pencil/tolerance", 10.0, 1.0, 100.0) * 0.4; - double const tolerance_sq = 0.02 * square( this->desktop->w2d().descrim() * - tol) * exp(0.2*tol - 2); + double const tolerance_sq = 0.02 * square(this->desktop->w2d().descrim() * tol) * exp(0.2 * tol - 2); - g_assert(is_zero(this->req_tangent) - || is_unit_vector(this->req_tangent)); - Geom::Point const tHatEnd(0, 0); + g_assert(is_zero(this->req_tangent) || is_unit_vector(this->req_tangent)); - guint n_points = this->ps.size(); this->green_curve->reset(); this->red_curve->reset(); this->red_curve_is_valid = false; - Geom::Point * b = g_new(Geom::Point, 4*n_points); - Geom::Point * points = g_new(Geom::Point, 4*n_points); - for (unsigned int i = 0; i < this->ps.size(); i++) { - points[i] = this->ps[i]; - } + int n_points = this->ps.size(); // worst case gives us a segment per point - int max_segs = 4*n_points; + int max_segs = 4 * n_points; - int const n_segs = Geom::bezier_fit_cubic_r(b, points, n_points, - tolerance_sq, max_segs); + std::vector b(max_segs); - if ( n_segs > 0) - { + int const n_segs = Geom::bezier_fit_cubic_r(b.data(), this->ps.data(), n_points, tolerance_sq, max_segs); + + if (n_segs > 0) { /* Fit and draw and reset state */ this->green_curve->moveto(b[0]); + for (int c = 0; c < n_segs; c++) { - this->green_curve->curveto(b[4*c+1], b[4*c+2], b[4*c+3]); + this->green_curve->curveto(b[4 * c + 1], b[4 * c + 2], b[4 * c + 3]); } + sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), this->green_curve); /* Fit and draw and copy last point */ @@ -691,8 +685,7 @@ void PencilTool::_interpolate() { : Geom::unit_vector(req_vec) ); } } - g_free(b); - g_free(points); + this->ps.clear(); } @@ -705,41 +698,36 @@ void PencilTool::_sketchInterpolate() { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); double const tol = prefs->getDoubleLimited("/tools/freehand/pencil/tolerance", 10.0, 1.0, 100.0) * 0.4; - double const tolerance_sq = 0.02 * square( this->desktop->w2d().descrim() * - tol) * exp(0.2*tol - 2); + double const tolerance_sq = 0.02 * square(this->desktop->w2d().descrim() * tol) * exp(0.2 * tol - 2); bool average_all_sketches = prefs->getBool("/tools/freehand/pencil/average_all_sketches", true); - g_assert(is_zero(this->req_tangent) - || is_unit_vector(this->req_tangent)); - Geom::Point const tHatEnd(0, 0); + g_assert(is_zero(this->req_tangent) || is_unit_vector(this->req_tangent)); - guint n_points = this->ps.size(); this->red_curve->reset(); this->red_curve_is_valid = false; - Geom::Point * b = g_new(Geom::Point, 4*n_points); - Geom::Point * points = g_new(Geom::Point, 4*n_points); - for (unsigned i = 0; i < this->ps.size(); i++) { - points[i] = this->ps[i]; - } + int n_points = this->ps.size(); // worst case gives us a segment per point - int max_segs = 4*n_points; + int max_segs = 4 * n_points; - int const n_segs = Geom::bezier_fit_cubic_r(b, points, n_points, - tolerance_sq, max_segs); + std::vector b(max_segs); - if ( n_segs > 0) - { + int const n_segs = Geom::bezier_fit_cubic_r(b.data(), this->ps.data(), n_points, tolerance_sq, max_segs); + + if (n_segs > 0) { Geom::Path fit(b[0]); + for (int c = 0; c < n_segs; c++) { - fit.appendNew(b[4*c+1], b[4*c+2], b[4*c+3]); + fit.appendNew(b[4 * c + 1], b[4 * c + 2], b[4 * c + 3]); } + Geom::Piecewise > fit_pwd2 = fit.toPwSb(); - if ( this->sketch_n > 0 ) { - double t =0.; + if (this->sketch_n > 0) { + double t; + if (average_all_sketches) { // Average = (sum of all) / n // = (sum of all + new one) / n+1 @@ -748,18 +736,21 @@ void PencilTool::_sketchInterpolate() { } else { t = 0.5; } + this->sketch_interpolation = Geom::lerp(t, fit_pwd2, this->sketch_interpolation); + // simplify path, to eliminate small segments - Path *path = new Path; - path->LoadPathVector(Geom::path_from_piecewise(this->sketch_interpolation, 0.01)); - path->Simplify(0.5); - Geom::PathVector *pathv = path->MakePathVector(); + Path path; + path.LoadPathVector(Geom::path_from_piecewise(this->sketch_interpolation, 0.01)); + path.Simplify(0.5); + + Geom::PathVector *pathv = path.MakePathVector(); this->sketch_interpolation = (*pathv)[0].toPwSb(); - delete path; delete pathv; } else { this->sketch_interpolation = fit_pwd2; } + this->sketch_n++; this->green_curve->reset(); @@ -783,8 +774,7 @@ void PencilTool::_sketchInterpolate() { : Geom::unit_vector(req_vec) ); } } - g_free(b); - g_free(points); + this->ps.clear(); } -- cgit v1.2.3 From 60e6c1d025ba5923e15a49763378732eaabe4f5a Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Thu, 27 Mar 2014 01:11:46 +0100 Subject: Changed some return types from gint to bool. (bzr r13220) --- src/ui/tools/connector-tool.cpp | 8 ++++---- src/ui/tools/connector-tool.h | 8 ++++---- src/ui/tools/pen-tool.cpp | 10 +++++----- src/ui/tools/pen-tool.h | 10 +++++----- src/ui/tools/pencil-tool.cpp | 10 +++++----- src/ui/tools/pencil-tool.h | 10 +++++----- 6 files changed, 28 insertions(+), 28 deletions(-) (limited to 'src/ui') diff --git a/src/ui/tools/connector-tool.cpp b/src/ui/tools/connector-tool.cpp index b72ce5346..e19f35832 100644 --- a/src/ui/tools/connector-tool.cpp +++ b/src/ui/tools/connector-tool.cpp @@ -465,7 +465,7 @@ bool ConnectorTool::root_handler(GdkEvent* event) { } -gint ConnectorTool::_handleButtonPress(GdkEventButton const &bevent) { +bool ConnectorTool::_handleButtonPress(GdkEventButton const &bevent) { Geom::Point const event_w(bevent.x, bevent.y); /* Find desktop coordinates */ Geom::Point p = this->desktop->w2d(event_w); @@ -565,7 +565,7 @@ gint ConnectorTool::_handleButtonPress(GdkEventButton const &bevent) { return ret; } -gint ConnectorTool::_handleMotionNotify(GdkEventMotion const &mevent) { +bool ConnectorTool::_handleMotionNotify(GdkEventMotion const &mevent) { bool ret = false; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -654,7 +654,7 @@ gint ConnectorTool::_handleMotionNotify(GdkEventMotion const &mevent) { return ret; } -gint ConnectorTool::_handleButtonRelease(GdkEventButton const &revent) { +bool ConnectorTool::_handleButtonRelease(GdkEventButton const &revent) { bool ret = false; if ( revent.button == 1 && !this->space_panning ) { @@ -714,7 +714,7 @@ gint ConnectorTool::_handleButtonRelease(GdkEventButton const &revent) { return ret; } -gint ConnectorTool::_handleKeyPress(guint const keyval) { +bool ConnectorTool::_handleKeyPress(guint const keyval) { bool ret = false; switch (keyval) { diff --git a/src/ui/tools/connector-tool.h b/src/ui/tools/connector-tool.h index b85412a53..9a9ae64cf 100644 --- a/src/ui/tools/connector-tool.h +++ b/src/ui/tools/connector-tool.h @@ -124,10 +124,10 @@ public: private: void _selectionChanged(Inkscape::Selection *selection); - gint _handleButtonPress(GdkEventButton const &bevent); - gint _handleMotionNotify(GdkEventMotion const &mevent); - gint _handleButtonRelease(GdkEventButton const &revent); - gint _handleKeyPress(guint const keyval); + bool _handleButtonPress(GdkEventButton const &bevent); + bool _handleMotionNotify(GdkEventMotion const &mevent); + bool _handleButtonRelease(GdkEventButton const &revent); + bool _handleKeyPress(guint const keyval); void _setInitialPoint(Geom::Point const p); void _setSubsequentPoint(Geom::Point const p); diff --git a/src/ui/tools/pen-tool.cpp b/src/ui/tools/pen-tool.cpp index ea66360d0..09c0a2a4f 100644 --- a/src/ui/tools/pen-tool.cpp +++ b/src/ui/tools/pen-tool.cpp @@ -324,7 +324,7 @@ bool PenTool::root_handler(GdkEvent* event) { /** * Handle mouse button press event. */ -gint PenTool::_handleButtonPress(GdkEventButton const &bevent) { +bool PenTool::_handleButtonPress(GdkEventButton const &bevent) { if (this->events_disabled) { // skip event processing if events are disabled return false; @@ -495,7 +495,7 @@ gint PenTool::_handleButtonPress(GdkEventButton const &bevent) { /** * Handle motion_notify event. */ -gint PenTool::_handleMotionNotify(GdkEventMotion const &mevent) { +bool PenTool::_handleMotionNotify(GdkEventMotion const &mevent) { bool ret = false; if (this->space_panning || mevent.state & GDK_BUTTON2_MASK || mevent.state & GDK_BUTTON3_MASK) { @@ -633,7 +633,7 @@ gint PenTool::_handleMotionNotify(GdkEventMotion const &mevent) { /** * Handle mouse button release event. */ -gint PenTool::_handleButtonRelease(GdkEventButton const &revent) { +bool PenTool::_handleButtonRelease(GdkEventButton const &revent) { if (this->events_disabled) { // skip event processing if events are disabled return false; @@ -760,7 +760,7 @@ gint PenTool::_handleButtonRelease(GdkEventButton const &revent) { return ret; } -gint PenTool::_handle2ButtonPress(GdkEventButton const &bevent) { +bool PenTool::_handle2ButtonPress(GdkEventButton const &bevent) { bool ret = false; // only end on LMB double click. Otherwise horizontal scrolling causes ending of the path if (this->npoints != 0 && bevent.button == 1) { @@ -871,7 +871,7 @@ void PenTool::_lastpointToLine() { } -gint PenTool::_handleKeyPress(GdkEvent *event) { +bool PenTool::_handleKeyPress(GdkEvent *event) { bool ret = false; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); gdouble const nudge = prefs->getDoubleLimited("/options/nudgedistance/value", 2, 0, 1000, "px"); // in px diff --git a/src/ui/tools/pen-tool.h b/src/ui/tools/pen-tool.h index 182d270ee..4dec7b4fe 100644 --- a/src/ui/tools/pen-tool.h +++ b/src/ui/tools/pen-tool.h @@ -80,11 +80,11 @@ protected: virtual bool item_handler(SPItem* item, GdkEvent* event); private: - gint _handleButtonPress(GdkEventButton const &bevent); - gint _handleMotionNotify(GdkEventMotion const &mevent); - gint _handleButtonRelease(GdkEventButton const &revent); - gint _handle2ButtonPress(GdkEventButton const &bevent); - gint _handleKeyPress(GdkEvent *event); + bool _handleButtonPress(GdkEventButton const &bevent); + bool _handleMotionNotify(GdkEventMotion const &mevent); + bool _handleButtonRelease(GdkEventButton const &revent); + bool _handle2ButtonPress(GdkEventButton const &bevent); + bool _handleKeyPress(GdkEvent *event); void _setInitialPoint(Geom::Point const p); void _setSubsequentPoint(Geom::Point const p, bool statusbar, guint status = 0); diff --git a/src/ui/tools/pencil-tool.cpp b/src/ui/tools/pencil-tool.cpp index 86274928b..374846539 100644 --- a/src/ui/tools/pencil-tool.cpp +++ b/src/ui/tools/pencil-tool.cpp @@ -149,7 +149,7 @@ bool PencilTool::root_handler(GdkEvent* event) { return ret; } -gint PencilTool::_handleButtonPress(GdkEventButton const &bevent) { +bool PencilTool::_handleButtonPress(GdkEventButton const &bevent) { bool ret = false; if ( bevent.button == 1 && !this->space_panning) { @@ -227,7 +227,7 @@ gint PencilTool::_handleButtonPress(GdkEventButton const &bevent) { return ret; } -gint PencilTool::_handleMotionNotify(GdkEventMotion const &mevent) { +bool PencilTool::_handleMotionNotify(GdkEventMotion const &mevent) { if ((mevent.state & GDK_CONTROL_MASK) && (mevent.state & GDK_BUTTON1_MASK)) { // mouse was accidentally moved during Ctrl+click; // ignore the motion and create a single point @@ -345,7 +345,7 @@ gint PencilTool::_handleMotionNotify(GdkEventMotion const &mevent) { return ret; } -gint PencilTool::_handleButtonRelease(GdkEventButton const &revent) { +bool PencilTool::_handleButtonRelease(GdkEventButton const &revent) { bool ret = false; if ( revent.button == 1 && this->is_drawing && !this->space_panning) { @@ -467,7 +467,7 @@ void PencilTool::_cancel() { this->desktop->canvas->endForcedFullRedraws(); } -gint PencilTool::_handleKeyPress(guint const keyval, guint const state) { +bool PencilTool::_handleKeyPress(guint const keyval, guint const state) { bool ret = false; switch (keyval) { @@ -520,7 +520,7 @@ gint PencilTool::_handleKeyPress(guint const keyval, guint const state) { return ret; } -gint PencilTool::_handleKeyRelease(guint const keyval, guint const /*state*/) { +bool PencilTool::_handleKeyRelease(guint const keyval, guint const /*state*/) { bool ret = false; switch (keyval) { case GDK_KEY_Alt_L: diff --git a/src/ui/tools/pencil-tool.h b/src/ui/tools/pencil-tool.h index 2ad05606d..e01b0afb5 100644 --- a/src/ui/tools/pencil-tool.h +++ b/src/ui/tools/pencil-tool.h @@ -54,11 +54,11 @@ protected: virtual bool root_handler(GdkEvent* event); private: - gint _handleButtonPress(GdkEventButton const &bevent); - gint _handleMotionNotify(GdkEventMotion const &mevent); - gint _handleButtonRelease(GdkEventButton const &revent); - gint _handleKeyPress(guint const keyval, guint const state); - gint _handleKeyRelease(guint const keyval, guint const state); + bool _handleButtonPress(GdkEventButton const &bevent); + bool _handleMotionNotify(GdkEventMotion const &mevent); + bool _handleButtonRelease(GdkEventButton const &revent); + bool _handleKeyPress(guint const keyval, guint const state); + bool _handleKeyRelease(guint const keyval, guint const state); void _setStartpoint(Geom::Point const &p); void _setEndpoint(Geom::Point const &p); -- cgit v1.2.3 From 3c85270dc7bfe702a7b88dfc0361ef1ac31376f2 Mon Sep 17 00:00:00 2001 From: Martin Owens Date: Thu, 27 Mar 2014 15:22:24 -0400 Subject: Get pollar tiling working agains with trunk (bzr r11073.1.37) --- src/ui/dialog/dialog-manager.cpp | 6 +----- src/ui/dialog/grid-arrange-tab.cpp | 7 ++++++- src/ui/dialog/polar-arrange-tab.cpp | 8 ++++---- src/ui/dialog/polar-arrange-tab.h | 2 -- src/ui/dialog/tile.cpp | 6 +++--- 5 files changed, 14 insertions(+), 15 deletions(-) (limited to 'src/ui') diff --git a/src/ui/dialog/dialog-manager.cpp b/src/ui/dialog/dialog-manager.cpp index 32ceb397a..47e1fdd30 100644 --- a/src/ui/dialog/dialog-manager.cpp +++ b/src/ui/dialog/dialog-manager.cpp @@ -150,12 +150,8 @@ DialogManager::DialogManager() { // registerFactory("PrintColorsPreviewDialog", &create); registerFactory("SvgFontsDialog", &create); registerFactory("Swatches", &create); -<<<<<<< TREE - registerFactory("TileDialog", &create); -======= + registerFactory("TileDialog", &create); registerFactory("Symbols", &create); - registerFactory("TileDialog", &create); ->>>>>>> MERGE-SOURCE registerFactory("Trace", &create); registerFactory("PixelArt", &create); registerFactory("Transformation", &create); diff --git a/src/ui/dialog/grid-arrange-tab.cpp b/src/ui/dialog/grid-arrange-tab.cpp index 7ff915265..8c0a4dc66 100644 --- a/src/ui/dialog/grid-arrange-tab.cpp +++ b/src/ui/dialog/grid-arrange-tab.cpp @@ -587,7 +587,12 @@ static void updateSelectionCallback(Inkscape::Application */*inkscape*/, Inkscap GridArrangeTab::GridArrangeTab(ArrangeDialog *parent) : Parent(parent), XPadding(_("X:"), _("Horizontal spacing between columns."), UNIT_TYPE_LINEAR, "", "object-columns", &PaddingUnitMenu), - YPadding(_("Y:"), _("Vertical spacing between rows."), XPadding, "", "object-rows", &PaddingUnitMenu) + YPadding(_("Y:"), _("Vertical spacing between rows."), XPadding, "", "object-rows", &PaddingUnitMenu), +#if WITH_GTKMM_3_0 + PaddingTable(Gtk::manage(new Gtk::Grid())) +#else + PaddingTable(Gtk::manage(new Gtk::Table(2, 2, false))) +#endif { // bool used by spin button callbacks to stop loops where they change each other. updating = false; diff --git a/src/ui/dialog/polar-arrange-tab.cpp b/src/ui/dialog/polar-arrange-tab.cpp index 623aa4e3e..a00b8fc02 100644 --- a/src/ui/dialog/polar-arrange-tab.cpp +++ b/src/ui/dialog/polar-arrange-tab.cpp @@ -7,12 +7,12 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include <2geom/transforms.h> -#include - #include "ui/dialog/polar-arrange-tab.h" #include "ui/dialog/tile.h" +#include <2geom/transforms.h> +#include + #include "verbs.h" #include "preferences.h" #include "inkscape.h" @@ -240,7 +240,7 @@ static Geom::Point getAnchorPoint(int anchor, SPItem *item) else { // FIXME: - source[1] -= item->document->getHeight(); + source[1] -= item->document->getHeight().value("px"); source[1] *= -1; } diff --git a/src/ui/dialog/polar-arrange-tab.h b/src/ui/dialog/polar-arrange-tab.h index 019b64511..bfed40bbd 100644 --- a/src/ui/dialog/polar-arrange-tab.h +++ b/src/ui/dialog/polar-arrange-tab.h @@ -10,8 +10,6 @@ #ifndef INKSCAPE_UI_DIALOG_POLAR_ARRANGE_TAB_H #define INKSCAPE_UI_DIALOG_POLAR_ARRANGE_TAB_H -#include - #include "ui/dialog/arrange-tab.h" #include "ui/widget/anchor-selector.h" diff --git a/src/ui/dialog/tile.cpp b/src/ui/dialog/tile.cpp index 1ed099120..a3cffb3d4 100644 --- a/src/ui/dialog/tile.cpp +++ b/src/ui/dialog/tile.cpp @@ -14,14 +14,14 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ +#include "ui/dialog/grid-arrange-tab.h" +#include "ui/dialog/polar-arrange-tab.h" + #include #include "tile.h" #include "verbs.h" -#include "ui/dialog/grid-arrange-tab.h" -#include "ui/dialog/polar-arrange-tab.h" - namespace Inkscape { namespace UI { namespace Dialog { -- cgit v1.2.3 From 3053ad943c47f23399ae172f32e7f5f630c53be9 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Fri, 28 Mar 2014 00:18:25 +0100 Subject: First step of refactoring SPKnot. (bzr r13223) --- src/ui/tools/connector-tool.cpp | 53 ++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 25 deletions(-) (limited to 'src/ui') diff --git a/src/ui/tools/connector-tool.cpp b/src/ui/tools/connector-tool.cpp index e19f35832..4f918b483 100644 --- a/src/ui/tools/connector-tool.cpp +++ b/src/ui/tools/connector-tool.cpp @@ -201,7 +201,8 @@ ConnectorTool::~ConnectorTool() { for (int i = 0; i < 2; ++i) { if (this->endpt_handle[1]) { - g_object_unref(this->endpt_handle[i]); + //g_object_unref(this->endpt_handle[i]); + knot_unref(this->endpt_handle[i]); this->endpt_handle[i] = NULL; } } @@ -319,7 +320,7 @@ cc_clear_active_knots(SPKnotList k) // Hide the connection points if they exist. if (k.size()) { for (SPKnotList::iterator it = k.begin(); it != k.end(); ++it) { - sp_knot_hide(it->first); + it->first->hide(); } } } @@ -341,7 +342,7 @@ void ConnectorTool::cc_clear_active_conn() { // Hide the endpoint handles. for (int i = 0; i < 2; ++i) { if (this->endpt_handle[i]) { - sp_knot_hide(this->endpt_handle[i]); + this->endpt_handle[i]->hide(); } } } @@ -365,7 +366,7 @@ cc_select_handle(SPKnot* knot) knot->setSize(10); knot->setAnchor(SP_ANCHOR_CENTER); knot->setFill(0x0000ffff, 0x0000ffff, 0x0000ffff); - sp_knot_update_ctrl(knot); + knot->update_ctrl(); } static void @@ -375,7 +376,7 @@ cc_deselect_handle(SPKnot* knot) knot->setSize(8); knot->setAnchor(SP_ANCHOR_CENTER); knot->setFill(0xffffff00, 0xff0000ff, 0xff0000ff); - sp_knot_update_ctrl(knot); + knot->update_ctrl(); } bool ConnectorTool::item_handler(SPItem* item, GdkEvent* event) { @@ -969,7 +970,8 @@ cc_generic_knot_handler(SPCanvasItem *, GdkEvent *event, SPKnot *knot) { g_assert (knot != NULL); - g_object_ref(knot); + //g_object_ref(knot); + knot_ref(knot); ConnectorTool *cc = SP_CONNECTOR_CONTEXT( knot->desktop->event_context); @@ -979,7 +981,7 @@ cc_generic_knot_handler(SPCanvasItem *, GdkEvent *event, SPKnot *knot) gchar const *knot_tip = "Click to join at this point"; switch (event->type) { case GDK_ENTER_NOTIFY: - sp_knot_set_flag(knot, SP_KNOT_MOUSEOVER, TRUE); + knot->set_flag(SP_KNOT_MOUSEOVER, TRUE); cc->active_handle = knot; if (knot_tip) @@ -991,7 +993,7 @@ cc_generic_knot_handler(SPCanvasItem *, GdkEvent *event, SPKnot *knot) consumed = TRUE; break; case GDK_LEAVE_NOTIFY: - sp_knot_set_flag(knot, SP_KNOT_MOUSEOVER, FALSE); + knot->set_flag(SP_KNOT_MOUSEOVER, FALSE); /* FIXME: the following test is a workaround for LP Bug #1273510. * It seems that a signal is not correctly disconnected, maybe @@ -1010,7 +1012,8 @@ cc_generic_knot_handler(SPCanvasItem *, GdkEvent *event, SPKnot *knot) break; } - g_object_unref(knot); + //g_object_unref(knot); + knot_unref(knot); return consumed; } @@ -1066,14 +1069,14 @@ endpt_handler(SPKnot */*knot*/, GdkEvent *event, ConnectorTool *cc) } void ConnectorTool::_activeShapeAddKnot(SPItem* item) { - SPKnot *knot = sp_knot_new(desktop, 0); + SPKnot *knot = new SPKnot(desktop, 0); knot->owner = item; knot->setShape(SP_KNOT_SHAPE_SQUARE); knot->setSize(8); knot->setAnchor(SP_ANCHOR_CENTER); knot->setFill(0xffffff00, 0xff0000ff, 0xff0000ff); - sp_knot_update_ctrl(knot); + knot->update_ctrl(); // We don't want to use the standard knot handler. g_signal_handler_disconnect(G_OBJECT(knot->item), @@ -1084,8 +1087,8 @@ void ConnectorTool::_activeShapeAddKnot(SPItem* item) { g_signal_connect(G_OBJECT(knot->item), "event", G_CALLBACK(cc_generic_knot_handler), knot); - sp_knot_set_position(knot, item->avoidRef->getConnectionPointPos() * desktop->doc2dt(), 0); - sp_knot_show(knot); + knot->set_position(item->avoidRef->getConnectionPointPos() * desktop->doc2dt(), 0); + knot->show(); this->knots[knot] = 1; } @@ -1149,17 +1152,17 @@ void ConnectorTool::cc_set_active_conn(SPItem *item) { { // Connector is invisible because it is clipped to the boundary of // two overlpapping shapes. - sp_knot_hide(this->endpt_handle[0]); - sp_knot_hide(this->endpt_handle[1]); + this->endpt_handle[0]->hide(); + this->endpt_handle[1]->hide(); } else { // Just adjust handle positions. Geom::Point startpt = *(curve->first_point()) * i2dt; - sp_knot_set_position(this->endpt_handle[0], startpt, 0); + this->endpt_handle[0]->set_position(startpt, 0); Geom::Point endpt = *(curve->last_point()) * i2dt; - sp_knot_set_position(this->endpt_handle[1], endpt, 0); + this->endpt_handle[1]->set_position(endpt, 0); } return; @@ -1184,7 +1187,7 @@ void ConnectorTool::cc_set_active_conn(SPItem *item) { for (int i = 0; i < 2; ++i) { // Create the handle if it doesn't exist if ( this->endpt_handle[i] == NULL ) { - SPKnot *knot = sp_knot_new(this->desktop, + SPKnot *knot = new SPKnot(this->desktop, _("Connector endpoint: drag to reroute or connect to new shapes")); knot->setShape(SP_KNOT_SHAPE_SQUARE); @@ -1192,7 +1195,7 @@ void ConnectorTool::cc_set_active_conn(SPItem *item) { knot->setAnchor(SP_ANCHOR_CENTER); knot->setFill(0xffffff00, 0xff0000ff, 0xff0000ff); knot->setStroke(0x000000ff, 0x000000ff, 0x000000ff); - sp_knot_update_ctrl(knot); + knot->update_ctrl(); // We don't want to use the standard knot handler, // since we don't want this knot to be draggable. @@ -1232,13 +1235,13 @@ void ConnectorTool::cc_set_active_conn(SPItem *item) { } Geom::Point startpt = *(curve->first_point()) * i2dt; - sp_knot_set_position(this->endpt_handle[0], startpt, 0); + this->endpt_handle[0]->set_position(startpt, 0); Geom::Point endpt = *(curve->last_point()) * i2dt; - sp_knot_set_position(this->endpt_handle[1], endpt, 0); + this->endpt_handle[1]->set_position(endpt, 0); - sp_knot_show(this->endpt_handle[0]); - sp_knot_show(this->endpt_handle[1]); + this->endpt_handle[0]->show(); + this->endpt_handle[1]->show(); } void cc_create_connection_point(ConnectorTool* cc) @@ -1250,7 +1253,7 @@ void cc_create_connection_point(ConnectorTool* cc) cc_deselect_handle( cc->selected_handle ); } - SPKnot *knot = sp_knot_new(cc->desktop, 0); + SPKnot *knot = new SPKnot(cc->desktop, 0); // We do not process events on this knot. g_signal_handler_disconnect(G_OBJECT(knot->item), @@ -1260,7 +1263,7 @@ void cc_create_connection_point(ConnectorTool* cc) cc_select_handle( knot ); cc->selected_handle = knot; - sp_knot_show(cc->selected_handle); + cc->selected_handle->show(); cc->state = SP_CONNECTOR_CONTEXT_NEWCONNPOINT; } } -- cgit v1.2.3 From 24289d6eedbc912f228c21914176b82e8eecee51 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Fri, 28 Mar 2014 16:13:33 +0100 Subject: Further refactored SPKnot. (bzr r13226) --- src/ui/tools/connector-tool.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'src/ui') diff --git a/src/ui/tools/connector-tool.cpp b/src/ui/tools/connector-tool.cpp index 4f918b483..d1355e807 100644 --- a/src/ui/tools/connector-tool.cpp +++ b/src/ui/tools/connector-tool.cpp @@ -366,7 +366,7 @@ cc_select_handle(SPKnot* knot) knot->setSize(10); knot->setAnchor(SP_ANCHOR_CENTER); knot->setFill(0x0000ffff, 0x0000ffff, 0x0000ffff); - knot->update_ctrl(); + knot->updateCtrl(); } static void @@ -376,7 +376,7 @@ cc_deselect_handle(SPKnot* knot) knot->setSize(8); knot->setAnchor(SP_ANCHOR_CENTER); knot->setFill(0xffffff00, 0xff0000ff, 0xff0000ff); - knot->update_ctrl(); + knot->updateCtrl(); } bool ConnectorTool::item_handler(SPItem* item, GdkEvent* event) { @@ -981,7 +981,7 @@ cc_generic_knot_handler(SPCanvasItem *, GdkEvent *event, SPKnot *knot) gchar const *knot_tip = "Click to join at this point"; switch (event->type) { case GDK_ENTER_NOTIFY: - knot->set_flag(SP_KNOT_MOUSEOVER, TRUE); + knot->setFlag(SP_KNOT_MOUSEOVER, TRUE); cc->active_handle = knot; if (knot_tip) @@ -993,7 +993,7 @@ cc_generic_knot_handler(SPCanvasItem *, GdkEvent *event, SPKnot *knot) consumed = TRUE; break; case GDK_LEAVE_NOTIFY: - knot->set_flag(SP_KNOT_MOUSEOVER, FALSE); + knot->setFlag(SP_KNOT_MOUSEOVER, FALSE); /* FIXME: the following test is a workaround for LP Bug #1273510. * It seems that a signal is not correctly disconnected, maybe @@ -1076,7 +1076,7 @@ void ConnectorTool::_activeShapeAddKnot(SPItem* item) { knot->setSize(8); knot->setAnchor(SP_ANCHOR_CENTER); knot->setFill(0xffffff00, 0xff0000ff, 0xff0000ff); - knot->update_ctrl(); + knot->updateCtrl(); // We don't want to use the standard knot handler. g_signal_handler_disconnect(G_OBJECT(knot->item), @@ -1087,7 +1087,7 @@ void ConnectorTool::_activeShapeAddKnot(SPItem* item) { g_signal_connect(G_OBJECT(knot->item), "event", G_CALLBACK(cc_generic_knot_handler), knot); - knot->set_position(item->avoidRef->getConnectionPointPos() * desktop->doc2dt(), 0); + knot->setPosition(item->avoidRef->getConnectionPointPos() * desktop->doc2dt(), 0); knot->show(); this->knots[knot] = 1; } @@ -1159,10 +1159,10 @@ void ConnectorTool::cc_set_active_conn(SPItem *item) { { // Just adjust handle positions. Geom::Point startpt = *(curve->first_point()) * i2dt; - this->endpt_handle[0]->set_position(startpt, 0); + this->endpt_handle[0]->setPosition(startpt, 0); Geom::Point endpt = *(curve->last_point()) * i2dt; - this->endpt_handle[1]->set_position(endpt, 0); + this->endpt_handle[1]->setPosition(endpt, 0); } return; @@ -1195,7 +1195,7 @@ void ConnectorTool::cc_set_active_conn(SPItem *item) { knot->setAnchor(SP_ANCHOR_CENTER); knot->setFill(0xffffff00, 0xff0000ff, 0xff0000ff); knot->setStroke(0x000000ff, 0x000000ff, 0x000000ff); - knot->update_ctrl(); + knot->updateCtrl(); // We don't want to use the standard knot handler, // since we don't want this knot to be draggable. @@ -1235,10 +1235,10 @@ void ConnectorTool::cc_set_active_conn(SPItem *item) { } Geom::Point startpt = *(curve->first_point()) * i2dt; - this->endpt_handle[0]->set_position(startpt, 0); + this->endpt_handle[0]->setPosition(startpt, 0); Geom::Point endpt = *(curve->last_point()) * i2dt; - this->endpt_handle[1]->set_position(endpt, 0); + this->endpt_handle[1]->setPosition(endpt, 0); this->endpt_handle[0]->show(); this->endpt_handle[1]->show(); -- cgit v1.2.3 From f43fb7b917895a14e31b7e7f621f2216665732f7 Mon Sep 17 00:00:00 2001 From: Martin Owens Date: Fri, 28 Mar 2014 16:07:11 -0400 Subject: Remove _onApply and strdup the char from the label before it gets corrupted. Fixes bug #1299185 Fixed bugs: - https://launchpad.net/bugs/1299185 (bzr r13227) --- src/ui/dialog/guides.cpp | 14 +++----------- src/ui/dialog/guides.h | 1 - 2 files changed, 3 insertions(+), 12 deletions(-) (limited to 'src/ui') diff --git a/src/ui/dialog/guides.cpp b/src/ui/dialog/guides.cpp index e84f25733..0e754106d 100644 --- a/src/ui/dialog/guides.cpp +++ b/src/ui/dialog/guides.cpp @@ -100,7 +100,7 @@ void GuidelinePropertiesDialog::_modeChanged() } } -void GuidelinePropertiesDialog::_onApply() +void GuidelinePropertiesDialog::_onOK() { double deg_angle = _spin_angle.getValue(DEG); if (!_mode) @@ -125,17 +125,13 @@ void GuidelinePropertiesDialog::_onApply() sp_guide_moveto(*_guide, newpos, true); const gchar* name = _label_entry.getEntry()->get_text().c_str(); - sp_guide_set_label(*_guide, name, true); + + sp_guide_set_label(*_guide, g_strdup(name), true); DocumentUndo::done(_guide->document, SP_VERB_NONE, _("Set guide properties")); } -void GuidelinePropertiesDialog::_onOK() -{ - _onApply(); -} - void GuidelinePropertiesDialog::_onDelete() { SPDocument *doc = _guide->document; @@ -157,10 +153,6 @@ void GuidelinePropertiesDialog::_response(gint response) break; case Gtk::RESPONSE_DELETE_EVENT: break; -/* case GTK_RESPONSE_APPLY: - _onApply(); - break; -*/ default: g_assert_not_reached(); } diff --git a/src/ui/dialog/guides.h b/src/ui/dialog/guides.h index 422fed7fe..76b830e70 100644 --- a/src/ui/dialog/guides.h +++ b/src/ui/dialog/guides.h @@ -62,7 +62,6 @@ public: protected: void _setup(); - void _onApply(); void _onOK(); void _onDelete(); -- cgit v1.2.3 From b8a04c5946f23e3cc09e398d1b6603bbba6ceed9 Mon Sep 17 00:00:00 2001 From: Martin Owens Date: Fri, 28 Mar 2014 17:16:35 -0400 Subject: Guides: Clean up memory a bit better and move color changed to OK so we don't set the colour before OK (bzr r13228) --- src/ui/dialog/guides.cpp | 33 ++++++++++++++------------------- src/ui/dialog/guides.h | 1 - 2 files changed, 14 insertions(+), 20 deletions(-) (limited to 'src/ui') diff --git a/src/ui/dialog/guides.cpp b/src/ui/dialog/guides.cpp index 0e754106d..80740113c 100644 --- a/src/ui/dialog/guides.cpp +++ b/src/ui/dialog/guides.cpp @@ -68,20 +68,6 @@ void GuidelinePropertiesDialog::showDialog(SPGuide *guide, SPDesktop *desktop) { dialog.run(); } -void GuidelinePropertiesDialog::_colorChanged() -{ -#if WITH_GTKMM_3_0 - const Gdk::RGBA c = _color.get_rgba(); - unsigned r = c.get_red_u()/257, g = c.get_green_u()/257, b = c.get_blue_u()/257; -#else - const Gdk::Color c = _color.get_color(); - unsigned r = c.get_red()/257, g = c.get_green()/257, b = c.get_blue()/257; -#endif - //TODO: why 257? verify this! - - sp_guide_set_color(*_guide, r, g, b, true); -} - void GuidelinePropertiesDialog::_modeChanged() { _mode = !_relative_toggle.get_active(); @@ -124,9 +110,21 @@ void GuidelinePropertiesDialog::_onOK() sp_guide_moveto(*_guide, newpos, true); - const gchar* name = _label_entry.getEntry()->get_text().c_str(); + const gchar* name = g_strdup( _label_entry.getEntry()->get_text().c_str() ); - sp_guide_set_label(*_guide, g_strdup(name), true); + sp_guide_set_label(*_guide, name, true); + g_free((gpointer) name); + +#if WITH_GTKMM_3_0 + const Gdk::RGBA c = _color.get_rgba(); + unsigned r = c.get_red_u()/257, g = c.get_green_u()/257, b = c.get_blue_u()/257; +#else + const Gdk::Color c = _color.get_color(); + unsigned r = c.get_red()/257, g = c.get_green()/257, b = c.get_blue()/257; +#endif + //TODO: why 257? verify this! + + sp_guide_set_color(*_guide, r, g, b, true); DocumentUndo::done(_guide->document, SP_VERB_NONE, _("Set guide properties")); @@ -214,9 +212,6 @@ void GuidelinePropertiesDialog::_setup() { 1, 3, 3, 4, Gtk::EXPAND | Gtk::FILL, Gtk::FILL); #endif - _color.signal_color_set().connect(sigc::mem_fun(*this, &GuidelinePropertiesDialog::_colorChanged)); - - // unitmenus /* fixme: We should allow percents here too, as percents of the canvas size */ _unit_menu.setUnitType(UNIT_TYPE_LINEAR); diff --git a/src/ui/dialog/guides.h b/src/ui/dialog/guides.h index 76b830e70..22bf5097a 100644 --- a/src/ui/dialog/guides.h +++ b/src/ui/dialog/guides.h @@ -67,7 +67,6 @@ protected: void _response(gint response); void _modeChanged(); - void _colorChanged(); private: GuidelinePropertiesDialog(GuidelinePropertiesDialog const &); // no copy -- cgit v1.2.3 From 3c12cff9a89350a47eb4823194946982bd918677 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sat, 29 Mar 2014 01:57:47 +0100 Subject: Removed obsolete header file. (bzr r13229) --- src/ui/dialog/dialog.cpp | 4 ++-- src/ui/tools/pencil-tool.cpp | 21 +++++++++++---------- src/ui/tools/pencil-tool.h | 4 ++-- src/ui/tools/tool-base.cpp | 2 +- src/ui/tools/tool-base.h | 2 +- 5 files changed, 17 insertions(+), 16 deletions(-) (limited to 'src/ui') diff --git a/src/ui/dialog/dialog.cpp b/src/ui/dialog/dialog.cpp index 3cc3f3d88..645294bb5 100644 --- a/src/ui/dialog/dialog.cpp +++ b/src/ui/dialog/dialog.cpp @@ -26,11 +26,11 @@ #include "ui/tools/tool-base.h" #include "desktop.h" #include "desktop-handles.h" -#include "modifier-fns.h" #include "shortcuts.h" #include "preferences.h" #include "interface.h" #include "verbs.h" +#include "ui/tool/event-utils.h" #include @@ -279,7 +279,7 @@ bool Dialog::_onEvent(GdkEvent *event) case GDK_KEY_F4: case GDK_KEY_w: case GDK_KEY_W: { - if (mod_ctrl_only(event->key.state)) { + if (Inkscape::UI::held_only_control(event->key)) { _close(); ret = true; } diff --git a/src/ui/tools/pencil-tool.cpp b/src/ui/tools/pencil-tool.cpp index 374846539..fb4e82c32 100644 --- a/src/ui/tools/pencil-tool.cpp +++ b/src/ui/tools/pencil-tool.cpp @@ -26,7 +26,6 @@ #include "draw-anchor.h" #include "message-stack.h" #include "message-context.h" -#include "modifier-fns.h" #include "sp-path.h" #include "preferences.h" #include "snap.h" @@ -45,6 +44,7 @@ #include "display/curve.h" #include "livarot/Path.h" #include "tool-factory.h" +#include "ui/tool/event-utils.h" namespace Inkscape { namespace UI { @@ -131,11 +131,11 @@ bool PencilTool::root_handler(GdkEvent* event) { break; case GDK_KEY_PRESS: - ret = this->_handleKeyPress(get_group0_keyval (&event->key), event->key.state); + ret = this->_handleKeyPress(event->key); break; case GDK_KEY_RELEASE: - ret = this->_handleKeyRelease(get_group0_keyval (&event->key), event->key.state); + ret = this->_handleKeyRelease(event->key); break; default: @@ -467,16 +467,16 @@ void PencilTool::_cancel() { this->desktop->canvas->endForcedFullRedraws(); } -bool PencilTool::_handleKeyPress(guint const keyval, guint const state) { +bool PencilTool::_handleKeyPress(GdkEventKey const &event) { bool ret = false; - switch (keyval) { + switch (get_group0_keyval(&event)) { case GDK_KEY_Up: case GDK_KEY_Down: case GDK_KEY_KP_Up: case GDK_KEY_KP_Down: // Prevent the zoom field from activation. - if (!mod_ctrl_only(state)) { + if (!Inkscape::UI::held_only_control(event)) { ret = true; } break; @@ -491,7 +491,7 @@ bool PencilTool::_handleKeyPress(guint const keyval, guint const state) { break; case GDK_KEY_z: case GDK_KEY_Z: - if (mod_ctrl_only(state) && this->npoints != 0) { + if (Inkscape::UI::held_only_control(event) && this->npoints != 0) { // if drawing, cancel, otherwise pass it up for undo if (this->state != SP_PENCIL_CONTEXT_IDLE) { this->_cancel(); @@ -501,7 +501,7 @@ bool PencilTool::_handleKeyPress(guint const keyval, guint const state) { break; case GDK_KEY_g: case GDK_KEY_G: - if (mod_shift_only(state)) { + if (Inkscape::UI::held_only_shift(event)) { sp_selection_to_guides(this->desktop); ret = true; } @@ -520,9 +520,10 @@ bool PencilTool::_handleKeyPress(guint const keyval, guint const state) { return ret; } -bool PencilTool::_handleKeyRelease(guint const keyval, guint const /*state*/) { +bool PencilTool::_handleKeyRelease(GdkEventKey const &event) { bool ret = false; - switch (keyval) { + + switch (get_group0_keyval(&event)) { case GDK_KEY_Alt_L: case GDK_KEY_Alt_R: case GDK_KEY_Meta_L: diff --git a/src/ui/tools/pencil-tool.h b/src/ui/tools/pencil-tool.h index e01b0afb5..e8d156dbd 100644 --- a/src/ui/tools/pencil-tool.h +++ b/src/ui/tools/pencil-tool.h @@ -57,8 +57,8 @@ private: bool _handleButtonPress(GdkEventButton const &bevent); bool _handleMotionNotify(GdkEventMotion const &mevent); bool _handleButtonRelease(GdkEventButton const &revent); - bool _handleKeyPress(guint const keyval, guint const state); - bool _handleKeyRelease(guint const keyval, guint const state); + bool _handleKeyPress(GdkEventKey const &event); + bool _handleKeyRelease(GdkEventKey const &event); void _setStartpoint(Geom::Point const &p); void _setEndpoint(Geom::Point const &p); diff --git a/src/ui/tools/tool-base.cpp b/src/ui/tools/tool-base.cpp index 96ac95926..4195c9eb2 100644 --- a/src/ui/tools/tool-base.cpp +++ b/src/ui/tools/tool-base.cpp @@ -1132,7 +1132,7 @@ void sp_event_show_modifier_tip(Inkscape::MessageContext *message_context, * Use this instead of simply event->keyval, so that your keyboard shortcuts * work regardless of layouts (e.g., in Cyrillic). */ -guint get_group0_keyval(GdkEventKey *event) { +guint get_group0_keyval(GdkEventKey const *event) { guint keyval = 0; gdk_keymap_translate_keyboard_state(gdk_keymap_get_for_display( diff --git a/src/ui/tools/tool-base.h b/src/ui/tools/tool-base.h index e11a22296..b27de9030 100644 --- a/src/ui/tools/tool-base.h +++ b/src/ui/tools/tool-base.h @@ -244,7 +244,7 @@ gint gobble_motion_events(gint mask); void sp_event_show_modifier_tip(Inkscape::MessageContext *message_context, GdkEvent *event, gchar const *ctrl_tip, gchar const *shift_tip, gchar const *alt_tip); -guint get_group0_keyval(GdkEventKey *event); +guint get_group0_keyval(GdkEventKey const *event); SPItem *sp_event_context_find_item (SPDesktop *desktop, Geom::Point const &p, bool select_under, bool into_groups); SPItem *sp_event_context_over_item (SPDesktop *desktop, SPItem *item, Geom::Point const &p); -- cgit v1.2.3 From 03a14fa94b3260fecfbab5848de10751218a3b19 Mon Sep 17 00:00:00 2001 From: Alex Valavanis Date: Sun, 30 Mar 2014 13:10:32 +0100 Subject: Fix some mismatched tags (bzr r13230) --- src/ui/tools/connector-tool.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/ui') diff --git a/src/ui/tools/connector-tool.h b/src/ui/tools/connector-tool.h index 9a9ae64cf..868b8e77c 100644 --- a/src/ui/tools/connector-tool.h +++ b/src/ui/tools/connector-tool.h @@ -22,7 +22,7 @@ class SPItem; class SPCurve; -struct SPKnot; +class SPKnot; struct SPCanvasItem; namespace Avoid { -- cgit v1.2.3 From 88878512e24f1b2e1c0c1c0177921f8d848033c5 Mon Sep 17 00:00:00 2001 From: Alex Valavanis Date: Sun, 30 Mar 2014 14:01:28 +0100 Subject: Fix checking for unordered containers on incomplete C++11 implementations (bzr r13232) --- src/ui/tool/node.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/ui') diff --git a/src/ui/tool/node.h b/src/ui/tool/node.h index b874949f5..4582d998a 100644 --- a/src/ui/tool/node.h +++ b/src/ui/tool/node.h @@ -12,6 +12,10 @@ #ifndef SEEN_UI_TOOL_NODE_H #define SEEN_UI_TOOL_NODE_H +#if HAVE_CONFIG_H + #include "config.h" +#endif + #include #include #include @@ -37,7 +41,7 @@ template class NodeIterator; } } -#if __cplusplus < 201103L +#if HAVE_TR1_UNORDERED_SET namespace std { namespace tr1 { template struct hash< Inkscape::UI::NodeIterator >; -- cgit v1.2.3 From 1a8f0cfdf29561e9929216e0d9d6db637ab31d54 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sun, 30 Mar 2014 23:43:02 +0200 Subject: Added "Gtk::" scope to "manage" function calls. (bzr r13236) --- src/ui/dialog/document-metadata.cpp | 8 +++--- src/ui/dialog/document-properties.cpp | 48 ++++++++++++++++----------------- src/ui/dialog/fill-and-stroke.cpp | 8 +++--- src/ui/dialog/inkscape-preferences.cpp | 10 +++---- src/ui/dialog/input.cpp | 4 +-- src/ui/dialog/layer-properties.cpp | 6 ++--- src/ui/dialog/layers.cpp | 32 +++++++++++----------- src/ui/dialog/livepatheffect-editor.cpp | 2 +- src/ui/dialog/new-from-template.cpp | 2 +- src/ui/dialog/swatches.cpp | 2 +- src/ui/dialog/template-load-tab.cpp | 6 ++--- src/ui/dialog/template-widget.cpp | 2 +- src/ui/dialog/tracedialog.cpp | 2 +- src/ui/previewholder.cpp | 34 +++++++++++------------ src/ui/widget/licensor.cpp | 8 +++--- src/ui/widget/panel.cpp | 30 ++++++++++----------- src/ui/widget/registered-widget.cpp | 6 ++--- src/ui/widget/tolerance-slider.cpp | 16 +++++------ 18 files changed, 113 insertions(+), 113 deletions(-) (limited to 'src/ui') diff --git a/src/ui/dialog/document-metadata.cpp b/src/ui/dialog/document-metadata.cpp index efe25d843..09c505860 100644 --- a/src/ui/dialog/document-metadata.cpp +++ b/src/ui/dialog/document-metadata.cpp @@ -122,7 +122,7 @@ DocumentMetadata::build_metadata() _page_metadata1.show(); - Gtk::Label *label = manage (new Gtk::Label); + Gtk::Label *label = Gtk::manage (new Gtk::Label); label->set_markup (_("Dublin Core Entities")); label->set_alignment (0.0); @@ -140,7 +140,7 @@ DocumentMetadata::build_metadata() if ( entity->editable == RDF_EDIT_GENERIC ) { EntityEntry *w = EntityEntry::create (entity, _wr); _rdflist.push_back (w); - Gtk::HBox *space = manage (new Gtk::HBox); + Gtk::HBox *space = Gtk::manage (new Gtk::HBox); space->set_size_request (SPACE_SIZE_X, SPACE_SIZE_Y); #if WITH_GTKMM_3_0 @@ -164,7 +164,7 @@ DocumentMetadata::build_metadata() _page_metadata2.show(); row = 0; - Gtk::Label *llabel = manage (new Gtk::Label); + Gtk::Label *llabel = Gtk::manage (new Gtk::Label); llabel->set_markup (_("License")); llabel->set_alignment (0.0); @@ -178,7 +178,7 @@ DocumentMetadata::build_metadata() /* add license selector pull-down and URI */ ++row; _licensor.init (_wr); - Gtk::HBox *space = manage (new Gtk::HBox); + Gtk::HBox *space = Gtk::manage (new Gtk::HBox); space->set_size_request (SPACE_SIZE_X, SPACE_SIZE_Y); #if WITH_GTKMM_3_0 diff --git a/src/ui/dialog/document-properties.cpp b/src/ui/dialog/document-properties.cpp index a31ab1a09..508fc52b1 100644 --- a/src/ui/dialog/document-properties.cpp +++ b/src/ui/dialog/document-properties.cpp @@ -297,7 +297,7 @@ inline void attach_all(Gtk::Table &table, Gtk::Widget *const arr[], unsigned con table.attach (label, 0, 3, r, r+1, Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0); #endif } else { - Gtk::HBox *space = manage (new Gtk::HBox); + Gtk::HBox *space = Gtk::manage (new Gtk::HBox); space->set_size_request (SPACE_SIZE_X, SPACE_SIZE_Y); #if WITH_GTKMM_3_0 @@ -317,11 +317,11 @@ void DocumentProperties::build_page() { _page_page->show(); - Gtk::Label* label_gen = manage (new Gtk::Label); + Gtk::Label* label_gen = Gtk::manage (new Gtk::Label); label_gen->set_markup (_("General")); - Gtk::Label *label_for = manage (new Gtk::Label); + Gtk::Label *label_for = Gtk::manage (new Gtk::Label); label_for->set_markup (_("Page Size")); - Gtk::Label* label_dsp = manage (new Gtk::Label); + Gtk::Label* label_dsp = Gtk::manage (new Gtk::Label); label_dsp->set_markup (_("Display")); _page_sizer.init(); @@ -356,7 +356,7 @@ void DocumentProperties::build_guides() { _page_guides->show(); - Gtk::Label *label_gui = manage (new Gtk::Label); + Gtk::Label *label_gui = Gtk::manage (new Gtk::Label); label_gui->set_markup (_("Guides")); Gtk::Widget *const widget_array[] = @@ -374,13 +374,13 @@ void DocumentProperties::build_snap() { _page_snap->show(); - Gtk::Label *label_o = manage (new Gtk::Label); + Gtk::Label *label_o = Gtk::manage (new Gtk::Label); label_o->set_markup (_("Snap to objects")); - Gtk::Label *label_gr = manage (new Gtk::Label); + Gtk::Label *label_gr = Gtk::manage (new Gtk::Label); label_gr->set_markup (_("Snap to grids")); - Gtk::Label *label_gu = manage (new Gtk::Label); + Gtk::Label *label_gu = Gtk::manage (new Gtk::Label); label_gu->set_markup (_("Snap to guides")); - Gtk::Label *label_m = manage (new Gtk::Label); + Gtk::Label *label_m = Gtk::manage (new Gtk::Label); label_m->set_markup (_("Miscellaneous")); Gtk::Widget *const array[] = @@ -607,9 +607,9 @@ void DocumentProperties::removeSelectedProfile(){ void DocumentProperties::build_cms() { _page_cms->show(); - Gtk::Label *label_link= manage (new Gtk::Label("", Gtk::ALIGN_START)); + Gtk::Label *label_link= Gtk::manage (new Gtk::Label("", Gtk::ALIGN_START)); label_link->set_markup (_("Linked Color Profiles:")); - Gtk::Label *label_avail = manage (new Gtk::Label("", Gtk::ALIGN_START)); + Gtk::Label *label_avail = Gtk::manage (new Gtk::Label("", Gtk::ALIGN_START)); label_avail->set_markup (_("Available Color Profiles:")); _link_btn.set_tooltip_text(_("Link Profile")); @@ -746,7 +746,7 @@ void DocumentProperties::build_scripting() //# External scripts tab _page_external_scripts->show(); - Gtk::Label *label_external= manage (new Gtk::Label("", Gtk::ALIGN_START)); + Gtk::Label *label_external= Gtk::manage (new Gtk::Label("", Gtk::ALIGN_START)); label_external->set_markup (_("External script files:")); _external_add_btn.set_tooltip_text(_("Add the current file name or browse for a file")); @@ -835,7 +835,7 @@ void DocumentProperties::build_scripting() //# Embedded scripts tab _page_embedded_scripts->show(); - Gtk::Label *label_embedded= manage (new Gtk::Label("", Gtk::ALIGN_START)); + Gtk::Label *label_embedded= Gtk::manage (new Gtk::Label("", Gtk::ALIGN_START)); label_embedded->set_markup (_("Embedded script files:")); _embed_new_btn.set_tooltip_text(_("New")); @@ -922,7 +922,7 @@ void DocumentProperties::build_scripting() // TODO restore? _EmbeddedScriptsList.set_fixed_height_mode(true); //# Set up the Embedded Scripts content box - Gtk::Label *label_embedded_content= manage (new Gtk::Label("", Gtk::ALIGN_START)); + Gtk::Label *label_embedded_content= Gtk::manage (new Gtk::Label("", Gtk::ALIGN_START)); label_embedded_content->set_markup (_("Content:")); label_embedded_content->set_alignment(0.0); @@ -1001,7 +1001,7 @@ void DocumentProperties::build_metadata() _page_metadata1->show(); - Gtk::Label *label = manage (new Gtk::Label); + Gtk::Label *label = Gtk::manage (new Gtk::Label); label->set_markup (_("Dublin Core Entities")); label->set_alignment (0.0); @@ -1019,7 +1019,7 @@ void DocumentProperties::build_metadata() if ( entity->editable == RDF_EDIT_GENERIC ) { EntityEntry *w = EntityEntry::create (entity, _wr); _rdflist.push_back (w); - Gtk::HBox *space = manage (new Gtk::HBox); + Gtk::HBox *space = Gtk::manage (new Gtk::HBox); space->set_size_request (SPACE_SIZE_X, SPACE_SIZE_Y); #if WITH_GTKMM_3_0 @@ -1040,15 +1040,15 @@ void DocumentProperties::build_metadata() } } - Gtk::Button *button_save = manage (new Gtk::Button(_("_Save as default"),1)); + Gtk::Button *button_save = Gtk::manage (new Gtk::Button(_("_Save as default"),1)); button_save->set_tooltip_text(_("Save this metadata as the default metadata")); - Gtk::Button *button_load = manage (new Gtk::Button(_("Use _default"),1)); + Gtk::Button *button_load = Gtk::manage (new Gtk::Button(_("Use _default"),1)); button_load->set_tooltip_text(_("Use the previously saved default metadata here")); #if WITH_GTKMM_3_0 - Gtk::ButtonBox *box_buttons = manage (new Gtk::ButtonBox); + Gtk::ButtonBox *box_buttons = Gtk::manage (new Gtk::ButtonBox); #else - Gtk::HButtonBox *box_buttons = manage (new Gtk::HButtonBox); + Gtk::HButtonBox *box_buttons = Gtk::manage (new Gtk::HButtonBox); #endif box_buttons->set_layout(Gtk::BUTTONBOX_END); @@ -1063,7 +1063,7 @@ void DocumentProperties::build_metadata() _page_metadata2->show(); row = 0; - Gtk::Label *llabel = manage (new Gtk::Label); + Gtk::Label *llabel = Gtk::manage (new Gtk::Label); llabel->set_markup (_("License")); llabel->set_alignment (0.0); @@ -1077,7 +1077,7 @@ void DocumentProperties::build_metadata() /* add license selector pull-down and URI */ ++row; _licensor.init (_wr); - Gtk::HBox *space = manage (new Gtk::HBox); + Gtk::HBox *space = Gtk::manage (new Gtk::HBox); space->set_size_request (SPACE_SIZE_X, SPACE_SIZE_Y); #if WITH_GTKMM_3_0 @@ -1545,12 +1545,12 @@ void DocumentProperties::update() Gtk::HBox& DocumentProperties::_createPageTabLabel(const Glib::ustring& label, const char *label_image) { - Gtk::HBox *_tab_label_box = manage(new Gtk::HBox(false, 0)); + Gtk::HBox *_tab_label_box = Gtk::manage(new Gtk::HBox(false, 0)); _tab_label_box->set_spacing(4); _tab_label_box->pack_start(*Glib::wrap(sp_icon_new(Inkscape::ICON_SIZE_DECORATION, label_image))); - Gtk::Label *_tab_label = manage(new Gtk::Label(label, true)); + Gtk::Label *_tab_label = Gtk::manage(new Gtk::Label(label, true)); _tab_label_box->pack_start(*_tab_label); _tab_label_box->show_all(); diff --git a/src/ui/dialog/fill-and-stroke.cpp b/src/ui/dialog/fill-and-stroke.cpp index 19b873d54..c55d55cda 100644 --- a/src/ui/dialog/fill-and-stroke.cpp +++ b/src/ui/dialog/fill-and-stroke.cpp @@ -131,7 +131,7 @@ FillAndStroke::_savePagePref(guint page_num) void FillAndStroke::_layoutPageFill() { - fillWdgt = manage(sp_fill_style_widget_new()); + fillWdgt = Gtk::manage(sp_fill_style_widget_new()); #if WITH_GTKMM_3_0 _page_fill->table().attach(*fillWdgt, 0, 0, 1, 1); @@ -143,7 +143,7 @@ FillAndStroke::_layoutPageFill() void FillAndStroke::_layoutPageStrokePaint() { - strokeWdgt = manage(sp_stroke_style_paint_widget_new()); + strokeWdgt = Gtk::manage(sp_stroke_style_paint_widget_new()); #if WITH_GTKMM_3_0 _page_stroke_paint->table().attach(*strokeWdgt, 0, 0, 1, 1); @@ -195,11 +195,11 @@ FillAndStroke::showPageStrokeStyle() Gtk::HBox& FillAndStroke::_createPageTabLabel(const Glib::ustring& label, const char *label_image) { - Gtk::HBox *_tab_label_box = manage(new Gtk::HBox(false, 4)); + Gtk::HBox *_tab_label_box = Gtk::manage(new Gtk::HBox(false, 4)); _tab_label_box->pack_start(*Glib::wrap(sp_icon_new(Inkscape::ICON_SIZE_DECORATION, label_image))); - Gtk::Label *_tab_label = manage(new Gtk::Label(label, true)); + Gtk::Label *_tab_label = Gtk::manage(new Gtk::Label(label, true)); _tab_label_box->pack_start(*_tab_label); _tab_label_box->show_all(); diff --git a/src/ui/dialog/inkscape-preferences.cpp b/src/ui/dialog/inkscape-preferences.cpp index 03108b403..d826ece09 100644 --- a/src/ui/dialog/inkscape-preferences.cpp +++ b/src/ui/dialog/inkscape-preferences.cpp @@ -1534,9 +1534,9 @@ void InkscapePreferences::initKeyboardShortcuts(Gtk::TreeModel::iterator iter_ui row++; #if WITH_GTKMM_3_0 - Gtk::ButtonBox *box_buttons = manage(new Gtk::ButtonBox); + Gtk::ButtonBox *box_buttons = Gtk::manage(new Gtk::ButtonBox); #else - Gtk::HButtonBox *box_buttons = manage (new Gtk::HButtonBox); + Gtk::HButtonBox *box_buttons = Gtk::manage (new Gtk::HButtonBox); #endif box_buttons->set_layout(Gtk::BUTTONBOX_END); @@ -1549,14 +1549,14 @@ void InkscapePreferences::initKeyboardShortcuts(Gtk::TreeModel::iterator iter_ui _page_keyshortcuts.attach(*box_buttons, 0, 3, row, row+1, Gtk::EXPAND | Gtk::FILL, Gtk::SHRINK); #endif - UI::Widget::Button *kb_reset = manage(new UI::Widget::Button(_("Reset"), _("Remove all your customized keyboard shortcuts, and revert to the shortcuts in the shortcut file listed above"))); + UI::Widget::Button *kb_reset = Gtk::manage(new UI::Widget::Button(_("Reset"), _("Remove all your customized keyboard shortcuts, and revert to the shortcuts in the shortcut file listed above"))); box_buttons->pack_start(*kb_reset, true, true, 6); box_buttons->set_child_secondary(*kb_reset); - UI::Widget::Button *kb_import = manage(new UI::Widget::Button(_("Import ..."), _("Import custom keyboard shortcuts from a file"))); + UI::Widget::Button *kb_import = Gtk::manage(new UI::Widget::Button(_("Import ..."), _("Import custom keyboard shortcuts from a file"))); box_buttons->pack_end(*kb_import, true, true, 6); - UI::Widget::Button *kb_export = manage(new UI::Widget::Button(_("Export ..."), _("Export custom keyboard shortcuts to a file"))); + UI::Widget::Button *kb_export = Gtk::manage(new UI::Widget::Button(_("Export ..."), _("Export custom keyboard shortcuts to a file"))); box_buttons->pack_end(*kb_export, true, true, 6); kb_reset->signal_clicked().connect( sigc::mem_fun(*this, &InkscapePreferences::onKBReset) ); diff --git a/src/ui/dialog/input.cpp b/src/ui/dialog/input.cpp index 2d4755fd2..4be6716a5 100644 --- a/src/ui/dialog/input.cpp +++ b/src/ui/dialog/input.cpp @@ -1151,9 +1151,9 @@ InputDialogImpl::ConfPanel::ConfPanel() : useExt.signal_toggled().connect(sigc::mem_fun(*this, &InputDialogImpl::ConfPanel::useExtToggled)); #if WITH_GTKMM_3_0 - Gtk::ButtonBox *buttonBox = manage(new Gtk::ButtonBox); + Gtk::ButtonBox *buttonBox = Gtk::manage(new Gtk::ButtonBox); #else - Gtk::HButtonBox *buttonBox = manage (new Gtk::HButtonBox); + Gtk::HButtonBox *buttonBox = Gtk::manage (new Gtk::HButtonBox); #endif buttonBox->set_layout (Gtk::BUTTONBOX_END); diff --git a/src/ui/dialog/layer-properties.cpp b/src/ui/dialog/layer-properties.cpp index f19828b1f..d5540b88a 100644 --- a/src/ui/dialog/layer-properties.cpp +++ b/src/ui/dialog/layer-properties.cpp @@ -213,7 +213,7 @@ LayerPropertiesDialog::_setup_layers_controls() { _tree.set_model( _store ); _tree.set_headers_visible(false); - Inkscape::UI::Widget::ImageToggler *eyeRenderer = manage( new Inkscape::UI::Widget::ImageToggler( + Inkscape::UI::Widget::ImageToggler *eyeRenderer = Gtk::manage( new Inkscape::UI::Widget::ImageToggler( INKSCAPE_ICON("object-visible"), INKSCAPE_ICON("object-hidden")) ); int visibleColNum = _tree.append_column("vis", *eyeRenderer) - 1; Gtk::TreeViewColumn* col = _tree.get_column(visibleColNum); @@ -221,7 +221,7 @@ LayerPropertiesDialog::_setup_layers_controls() { col->add_attribute( eyeRenderer->property_active(), _model->_colVisible ); } - Inkscape::UI::Widget::ImageToggler * renderer = manage( new Inkscape::UI::Widget::ImageToggler( + Inkscape::UI::Widget::ImageToggler * renderer = Gtk::manage( new Inkscape::UI::Widget::ImageToggler( INKSCAPE_ICON("object-locked"), INKSCAPE_ICON("object-unlocked")) ); int lockedColNum = _tree.append_column("lock", *renderer) - 1; col = _tree.get_column(lockedColNum); @@ -229,7 +229,7 @@ LayerPropertiesDialog::_setup_layers_controls() { col->add_attribute( renderer->property_active(), _model->_colLocked ); } - Gtk::CellRendererText *_text_renderer = manage(new Gtk::CellRendererText()); + Gtk::CellRendererText *_text_renderer = Gtk::manage(new Gtk::CellRendererText()); int nameColNum = _tree.append_column("Name", *_text_renderer) - 1; Gtk::TreeView::Column *_name_column = _tree.get_column(nameColNum); _name_column->add_attribute(_text_renderer->property_text(), _model->_colLabel); diff --git a/src/ui/dialog/layers.cpp b/src/ui/dialog/layers.cpp index 381810f1e..b5dac0595 100644 --- a/src/ui/dialog/layers.cpp +++ b/src/ui/dialog/layers.cpp @@ -92,7 +92,7 @@ void LayersPanel::_styleButton( Gtk::Button& btn, SPDesktop *desktop, unsigned i if ( iconName ) { GtkWidget *child = sp_icon_new( Inkscape::ICON_SIZE_SMALL_TOOLBAR, iconName ); gtk_widget_show( child ); - btn.add( *manage(Glib::wrap(child)) ); + btn.add( *Gtk::manage(Glib::wrap(child)) ); btn.set_relief(Gtk::RELIEF_NONE); set = true; } @@ -104,7 +104,7 @@ void LayersPanel::_styleButton( Gtk::Button& btn, SPDesktop *desktop, unsigned i if ( !set && action && action->image ) { GtkWidget *child = sp_icon_new( Inkscape::ICON_SIZE_SMALL_TOOLBAR, action->image ); gtk_widget_show( child ); - btn.add( *manage(Glib::wrap(child)) ); + btn.add( *Gtk::manage(Glib::wrap(child)) ); set = true; } @@ -149,7 +149,7 @@ Gtk::MenuItem& LayersPanel::_addPopupItem( SPDesktop *desktop, unsigned int code Gtk::Widget* wrapped = 0; if ( iconWidget ) { - wrapped = manage(Glib::wrap(iconWidget)); + wrapped = Gtk::manage(Glib::wrap(iconWidget)); wrapped->show(); } @@ -809,7 +809,7 @@ LayersPanel::LayersPanel() : _tree.set_reorderable(true); _tree.enable_model_drag_dest (Gdk::ACTION_MOVE); - Inkscape::UI::Widget::ImageToggler *eyeRenderer = manage( new Inkscape::UI::Widget::ImageToggler( + Inkscape::UI::Widget::ImageToggler *eyeRenderer = Gtk::manage( new Inkscape::UI::Widget::ImageToggler( INKSCAPE_ICON("object-visible"), INKSCAPE_ICON("object-hidden")) ); int visibleColNum = _tree.append_column("vis", *eyeRenderer) - 1; eyeRenderer->signal_pre_toggle().connect( sigc::mem_fun(*this, &LayersPanel::_preToggle) ); @@ -821,7 +821,7 @@ LayersPanel::LayersPanel() : } - Inkscape::UI::Widget::ImageToggler * renderer = manage( new Inkscape::UI::Widget::ImageToggler( + Inkscape::UI::Widget::ImageToggler * renderer = Gtk::manage( new Inkscape::UI::Widget::ImageToggler( INKSCAPE_ICON("object-locked"), INKSCAPE_ICON("object-unlocked")) ); int lockedColNum = _tree.append_column("lock", *renderer) - 1; renderer->signal_pre_toggle().connect( sigc::mem_fun(*this, &LayersPanel::_preToggle) ); @@ -832,7 +832,7 @@ LayersPanel::LayersPanel() : col->add_attribute( renderer->property_active(), _model->_colLocked ); } - _text_renderer = manage(new Gtk::CellRendererText()); + _text_renderer = Gtk::manage(new Gtk::CellRendererText()); int nameColNum = _tree.append_column("Name", *_text_renderer) - 1; _name_column = _tree.get_column(nameColNum); _name_column->add_attribute(_text_renderer->property_text(), _model->_colLabel); @@ -880,40 +880,40 @@ LayersPanel::LayersPanel() : SPDesktop* targetDesktop = getDesktop(); - Gtk::Button* btn = manage( new Gtk::Button() ); + Gtk::Button* btn = Gtk::manage( new Gtk::Button() ); _styleButton( *btn, targetDesktop, SP_VERB_LAYER_NEW, INKSCAPE_ICON("list-add"), C_("Layers", "New") ); btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), (int)BUTTON_NEW) ); _buttonsSecondary.pack_start(*btn, Gtk::PACK_SHRINK); - btn = manage( new Gtk::Button() ); + btn = Gtk::manage( new Gtk::Button() ); _styleButton( *btn, targetDesktop, SP_VERB_LAYER_TO_BOTTOM, INKSCAPE_ICON("go-bottom"), C_("Layers", "Bot") ); btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), (int)BUTTON_BOTTOM) ); _watchingNonBottom.push_back( btn ); _buttonsPrimary.pack_end(*btn, Gtk::PACK_SHRINK); - btn = manage( new Gtk::Button() ); + btn = Gtk::manage( new Gtk::Button() ); _styleButton( *btn, targetDesktop, SP_VERB_LAYER_LOWER, INKSCAPE_ICON("go-down"), C_("Layers", "Dn") ); btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), (int)BUTTON_DOWN) ); _watchingNonBottom.push_back( btn ); _buttonsPrimary.pack_end(*btn, Gtk::PACK_SHRINK); - btn = manage( new Gtk::Button() ); + btn = Gtk::manage( new Gtk::Button() ); _styleButton( *btn, targetDesktop, SP_VERB_LAYER_RAISE, INKSCAPE_ICON("go-up"), C_("Layers", "Up") ); btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), (int)BUTTON_UP) ); _watchingNonTop.push_back( btn ); _buttonsPrimary.pack_end(*btn, Gtk::PACK_SHRINK); - btn = manage( new Gtk::Button() ); + btn = Gtk::manage( new Gtk::Button() ); _styleButton( *btn, targetDesktop, SP_VERB_LAYER_TO_TOP, INKSCAPE_ICON("go-top"), C_("Layers", "Top") ); btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), (int)BUTTON_TOP) ); _watchingNonTop.push_back( btn ); _buttonsPrimary.pack_end(*btn, Gtk::PACK_SHRINK); -// btn = manage( new Gtk::Button("Dup") ); +// btn = Gtk::manage( new Gtk::Button("Dup") ); // btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), (int)BUTTON_DUPLICATE) ); // _buttonsRow.add( *btn ); - btn = manage( new Gtk::Button() ); + btn = Gtk::manage( new Gtk::Button() ); _styleButton( *btn, targetDesktop, SP_VERB_LAYER_DELETE, INKSCAPE_ICON("list-remove"), _("X") ); btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), (int)BUTTON_DELETE) ); _watching.push_back( btn ); @@ -930,19 +930,19 @@ LayersPanel::LayersPanel() : _watching.push_back( &_addPopupItem( targetDesktop, SP_VERB_LAYER_DUPLICATE, 0, "Duplicate", (int)BUTTON_DUPLICATE ) ); _watching.push_back( &_addPopupItem( targetDesktop, SP_VERB_LAYER_NEW, 0, "New", (int)BUTTON_NEW ) ); - _popupMenu.append(*manage(new Gtk::SeparatorMenuItem())); + _popupMenu.append(*Gtk::manage(new Gtk::SeparatorMenuItem())); _watching.push_back( &_addPopupItem( targetDesktop, SP_VERB_LAYER_SOLO, 0, "Solo", (int)BUTTON_SOLO ) ); _watching.push_back( &_addPopupItem( targetDesktop, SP_VERB_LAYER_SHOW_ALL, 0, "Show All", (int)BUTTON_SHOW_ALL ) ); _watching.push_back( &_addPopupItem( targetDesktop, SP_VERB_LAYER_HIDE_ALL, 0, "Hide All", (int)BUTTON_HIDE_ALL ) ); - _popupMenu.append(*manage(new Gtk::SeparatorMenuItem())); + _popupMenu.append(*Gtk::manage(new Gtk::SeparatorMenuItem())); _watching.push_back( &_addPopupItem( targetDesktop, SP_VERB_LAYER_LOCK_OTHERS, 0, "Lock Others", (int)BUTTON_LOCK_OTHERS ) ); _watching.push_back( &_addPopupItem( targetDesktop, SP_VERB_LAYER_LOCK_ALL, 0, "Lock All", (int)BUTTON_LOCK_ALL ) ); _watching.push_back( &_addPopupItem( targetDesktop, SP_VERB_LAYER_UNLOCK_ALL, 0, "Unlock All", (int)BUTTON_UNLOCK_ALL ) ); - _popupMenu.append(*manage(new Gtk::SeparatorMenuItem())); + _popupMenu.append(*Gtk::manage(new Gtk::SeparatorMenuItem())); _watchingNonTop.push_back( &_addPopupItem( targetDesktop, SP_VERB_LAYER_RAISE, INKSCAPE_ICON("go-up"), "Up", (int)BUTTON_UP ) ); _watchingNonBottom.push_back( &_addPopupItem( targetDesktop, SP_VERB_LAYER_LOWER, INKSCAPE_ICON("go-down"), "Down", (int)BUTTON_DOWN ) ); diff --git a/src/ui/dialog/livepatheffect-editor.cpp b/src/ui/dialog/livepatheffect-editor.cpp index b81b300e2..0ab2fc9f7 100644 --- a/src/ui/dialog/livepatheffect-editor.cpp +++ b/src/ui/dialog/livepatheffect-editor.cpp @@ -172,7 +172,7 @@ LivePathEffectEditor::LivePathEffectEditor() effectlist_selection->signal_changed().connect( sigc::mem_fun(*this, &LivePathEffectEditor::on_effect_selection_changed) ); //Add the visibility icon column: - Inkscape::UI::Widget::ImageToggler *eyeRenderer = manage( new Inkscape::UI::Widget::ImageToggler( + Inkscape::UI::Widget::ImageToggler *eyeRenderer = Gtk::manage( new Inkscape::UI::Widget::ImageToggler( INKSCAPE_ICON("object-visible"), INKSCAPE_ICON("object-hidden")) ); int visibleColNum = effectlist_view.append_column("is_visible", *eyeRenderer) - 1; eyeRenderer->signal_toggled().connect( sigc::mem_fun(*this, &LivePathEffectEditor::on_visibility_toggled) ); diff --git a/src/ui/dialog/new-from-template.cpp b/src/ui/dialog/new-from-template.cpp index 71d1c22d0..f326bb3ee 100644 --- a/src/ui/dialog/new-from-template.cpp +++ b/src/ui/dialog/new-from-template.cpp @@ -29,7 +29,7 @@ NewFromTemplate::NewFromTemplate() get_vbox()->pack_start(_main_widget); Gtk::Alignment *align; - align = manage(new Gtk::Alignment(Gtk::ALIGN_END, Gtk::ALIGN_CENTER, 0.0, 0.0)); + align = Gtk::manage(new Gtk::Alignment(Gtk::ALIGN_END, Gtk::ALIGN_CENTER, 0.0, 0.0)); get_vbox()->pack_end(*align, Gtk::PACK_SHRINK); align->set_padding(0, 0, 0, 15); align->add(_create_template_button); diff --git a/src/ui/dialog/swatches.cpp b/src/ui/dialog/swatches.cpp index 5e77a28ab..4f0cb211a 100644 --- a/src/ui/dialog/swatches.cpp +++ b/src/ui/dialog/swatches.cpp @@ -645,7 +645,7 @@ SwatchesPanel::SwatchesPanel(gchar const* prefsPath) : std::vector swatchSets = _getSwatchSets(); for ( std::vector::iterator it = swatchSets.begin(); it != swatchSets.end(); ++it) { SwatchPage* curr = *it; - Gtk::RadioMenuItem* single = manage(new Gtk::RadioMenuItem(groupOne, curr->_name)); + Gtk::RadioMenuItem* single = Gtk::manage(new Gtk::RadioMenuItem(groupOne, curr->_name)); if ( curr == first ) { hotItem = single; } diff --git a/src/ui/dialog/template-load-tab.cpp b/src/ui/dialog/template-load-tab.cpp index 6b1f4542f..d75f81456 100644 --- a/src/ui/dialog/template-load-tab.cpp +++ b/src/ui/dialog/template-load-tab.cpp @@ -42,10 +42,10 @@ TemplateLoadTab::TemplateLoadTab() { set_border_width(10); - _info_widget = manage(new TemplateWidget()); + _info_widget = Gtk::manage(new TemplateWidget()); Gtk::Label *title; - title = manage(new Gtk::Label(_("Search:"))); + title = Gtk::manage(new Gtk::Label(_("Search:"))); _search_box.pack_start(*title, Gtk::PACK_SHRINK); _search_box.pack_start(_keywords_combo, Gtk::PACK_SHRINK, 5); @@ -55,7 +55,7 @@ TemplateLoadTab::TemplateLoadTab() pack_start(*_info_widget, Gtk::PACK_EXPAND_WIDGET, 5); Gtk::ScrolledWindow *scrolled; - scrolled = manage(new Gtk::ScrolledWindow()); + scrolled = Gtk::manage(new Gtk::ScrolledWindow()); scrolled->set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC); scrolled->add(_tlist_view); _tlist_box.pack_start(*scrolled, Gtk::PACK_EXPAND_WIDGET, 5); diff --git a/src/ui/dialog/template-widget.cpp b/src/ui/dialog/template-widget.cpp index d8e6f9b4f..ef91962d4 100644 --- a/src/ui/dialog/template-widget.cpp +++ b/src/ui/dialog/template-widget.cpp @@ -47,7 +47,7 @@ TemplateWidget::TemplateWidget() _short_description_label.set_line_wrap(true); Gtk::Alignment *align; - align = manage(new Gtk::Alignment(Gtk::ALIGN_END, Gtk::ALIGN_CENTER, 0.0, 0.0)); + align = Gtk::manage(new Gtk::Alignment(Gtk::ALIGN_END, Gtk::ALIGN_CENTER, 0.0, 0.0)); pack_end(*align, Gtk::PACK_SHRINK); align->add(_more_info_button); diff --git a/src/ui/dialog/tracedialog.cpp b/src/ui/dialog/tracedialog.cpp index bd467555e..11e75391b 100644 --- a/src/ui/dialog/tracedialog.cpp +++ b/src/ui/dialog/tracedialog.cpp @@ -778,7 +778,7 @@ TraceDialogImpl::TraceDialogImpl() : rightVBox.pack_start(sioxBox, false, false, 0); //## preview - Gtk::HBox *previewButtonHBox = manage(new Gtk::HBox(false, MARGIN )); + Gtk::HBox *previewButtonHBox = Gtk::manage(new Gtk::HBox(false, MARGIN )); previewLiveButton.set_label(_("Live Preview")); previewLiveButton.set_use_underline(true); previewLiveCallback(); diff --git a/src/ui/previewholder.cpp b/src/ui/previewholder.cpp index 38f6f353f..21f3f38d7 100644 --- a/src/ui/previewholder.cpp +++ b/src/ui/previewholder.cpp @@ -49,25 +49,25 @@ PreviewHolder::PreviewHolder() : _wrap(false), _border(BORDER_NONE) { - _scroller = manage(new Gtk::ScrolledWindow()); + _scroller = Gtk::manage(new Gtk::ScrolledWindow()); ((Gtk::ScrolledWindow *)_scroller)->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); #if WITH_GTKMM_3_0 - _insides = manage(new Gtk::Grid()); + _insides = Gtk::manage(new Gtk::Grid()); _insides->set_column_spacing(8); // Add a container with the scroller and a spacer - Gtk::Grid* spaceHolder = manage(new Gtk::Grid()); + Gtk::Grid* spaceHolder = Gtk::manage(new Gtk::Grid()); _scroller->set_hexpand(); _scroller->set_vexpand(); #else - _insides = manage(new Gtk::Table( 1, 2 )); + _insides = Gtk::manage(new Gtk::Table( 1, 2 )); _insides->set_col_spacings( 8 ); // Add a container with the scroller and a spacer - Gtk::Table* spaceHolder = manage( new Gtk::Table(1, 2) ); + Gtk::Table* spaceHolder = Gtk::manage( new Gtk::Table(1, 2) ); #endif _scroller->add( *_insides ); @@ -134,8 +134,8 @@ void PreviewHolder::addPreview( Previewable* preview ) switch(_view) { case VIEW_TYPE_LIST: { - Gtk::Widget* label = manage(preview->getPreview(PREVIEW_STYLE_BLURB, VIEW_TYPE_LIST, _baseSize, _ratio, _border)); - Gtk::Widget* thing = manage(preview->getPreview(PREVIEW_STYLE_PREVIEW, VIEW_TYPE_LIST, _baseSize, _ratio, _border)); + Gtk::Widget* label = Gtk::manage(preview->getPreview(PREVIEW_STYLE_BLURB, VIEW_TYPE_LIST, _baseSize, _ratio, _border)); + Gtk::Widget* thing = Gtk::manage(preview->getPreview(PREVIEW_STYLE_PREVIEW, VIEW_TYPE_LIST, _baseSize, _ratio, _border)); #if WITH_GTKMM_3_0 thing->set_hexpand(); @@ -154,7 +154,7 @@ void PreviewHolder::addPreview( Previewable* preview ) break; case VIEW_TYPE_GRID: { - Gtk::Widget* thing = manage(items[i]->getPreview(PREVIEW_STYLE_PREVIEW, VIEW_TYPE_GRID, _baseSize, _ratio, _border)); + Gtk::Widget* thing = Gtk::manage(items[i]->getPreview(PREVIEW_STYLE_PREVIEW, VIEW_TYPE_GRID, _baseSize, _ratio, _border)); int width = 1; int height = 1; @@ -408,10 +408,10 @@ void PreviewHolder::rebuildUI() { #if WITH_GTKMM_3_0 - _insides = manage(new Gtk::Grid()); + _insides = Gtk::manage(new Gtk::Grid()); _insides->set_column_spacing(8); #else - _insides = manage(new Gtk::Table( 1, 2 )); + _insides = Gtk::manage(new Gtk::Table( 1, 2 )); _insides->set_col_spacings( 8 ); #endif @@ -424,10 +424,10 @@ void PreviewHolder::rebuildUI() } for ( unsigned int i = 0; i < items.size(); i++ ) { - Gtk::Widget* label = manage(items[i]->getPreview(PREVIEW_STYLE_BLURB, _view, _baseSize, _ratio, _border)); + Gtk::Widget* label = Gtk::manage(items[i]->getPreview(PREVIEW_STYLE_BLURB, _view, _baseSize, _ratio, _border)); //label->set_alignment(Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER); - Gtk::Widget* thing = manage(items[i]->getPreview(PREVIEW_STYLE_PREVIEW, _view, _baseSize, _ratio, _border)); + Gtk::Widget* thing = Gtk::manage(items[i]->getPreview(PREVIEW_STYLE_PREVIEW, _view, _baseSize, _ratio, _border)); #if WITH_GTKMM_3_0 thing->set_hexpand(); @@ -458,19 +458,19 @@ void PreviewHolder::rebuildUI() // If this is the last row, flag so the previews can draw a bottom ::BorderStyle border = ((row == height -1) && (_border == BORDER_SOLID)) ? BORDER_SOLID_LAST_ROW : _border; - Gtk::Widget* thing = manage(items[i]->getPreview(PREVIEW_STYLE_PREVIEW, _view, _baseSize, _ratio, border)); + Gtk::Widget* thing = Gtk::manage(items[i]->getPreview(PREVIEW_STYLE_PREVIEW, _view, _baseSize, _ratio, border)); if ( !_insides ) { calcGridSize( thing, items.size(), width, height ); #if WITH_GTKMM_3_0 - _insides = manage(new Gtk::Grid()); + _insides = Gtk::manage(new Gtk::Grid()); if (_border == BORDER_WIDE) { _insides->set_column_spacing(1); _insides->set_row_spacing(1); } #else - _insides = manage(new Gtk::Table( height, width )); + _insides = Gtk::manage(new Gtk::Table( height, width )); if (_border == BORDER_WIDE) { _insides->set_col_spacings( 1 ); _insides->set_row_spacings( 1 ); @@ -493,9 +493,9 @@ void PreviewHolder::rebuildUI() } if ( !_insides ) { #if WITH_GTKMM_3_0 - _insides = manage(new Gtk::Grid()); + _insides = Gtk::manage(new Gtk::Grid()); #else - _insides = manage(new Gtk::Table( 1, 2 )); + _insides = Gtk::manage(new Gtk::Table( 1, 2 )); #endif } diff --git a/src/ui/widget/licensor.cpp b/src/ui/widget/licensor.cpp index c729354cb..42f352e3c 100644 --- a/src/ui/widget/licensor.cpp +++ b/src/ui/widget/licensor.cpp @@ -97,7 +97,7 @@ void Licensor::init (Registry& wr) LicenseItem *i; wr.setUpdating (true); - i = manage (new LicenseItem (&_proprietary_license, _eentry, wr, NULL)); + i = Gtk::manage (new LicenseItem (&_proprietary_license, _eentry, wr, NULL)); Gtk::RadioButtonGroup group = i->get_group(); add (*i); LicenseItem *pd = i; @@ -105,17 +105,17 @@ void Licensor::init (Registry& wr) for (struct rdf_license_t * license = rdf_licenses; license && license->name; license++) { - i = manage (new LicenseItem (license, _eentry, wr, &group)); + i = Gtk::manage (new LicenseItem (license, _eentry, wr, &group)); add(*i); } // add Other at the end before the URI field for the confused ppl. - LicenseItem *io = manage (new LicenseItem (&_other_license, _eentry, wr, &group)); + LicenseItem *io = Gtk::manage (new LicenseItem (&_other_license, _eentry, wr, &group)); add (*io); pd->set_active(); wr.setUpdating (false); - Gtk::HBox *box = manage (new Gtk::HBox); + Gtk::HBox *box = Gtk::manage (new Gtk::HBox); pack_start (*box, true, true, 0); box->pack_start (_eentry->_label, false, false, 5); diff --git a/src/ui/widget/panel.cpp b/src/ui/widget/panel.cpp index d60eeefe0..b37137228 100644 --- a/src/ui/widget/panel.cpp +++ b/src/ui/widget/panel.cpp @@ -115,8 +115,8 @@ void Panel::_init() Gtk::RadioMenuItem::Group group; Glib::ustring one_label(_("List")); Glib::ustring two_label(_("Grid")); - Gtk::RadioMenuItem *one = manage(new Gtk::RadioMenuItem(group, one_label)); - Gtk::RadioMenuItem *two = manage(new Gtk::RadioMenuItem(group, two_label)); + Gtk::RadioMenuItem *one = Gtk::manage(new Gtk::RadioMenuItem(group, one_label)); + Gtk::RadioMenuItem *two = Gtk::manage(new Gtk::RadioMenuItem(group, two_label)); if (panel_mode == 0) { one->set_active(true); @@ -128,7 +128,7 @@ void Panel::_init() _non_horizontal.push_back(one); _menu->append(*two); _non_horizontal.push_back(two); - Gtk::MenuItem* sep = manage(new Gtk::SeparatorMenuItem()); + Gtk::MenuItem* sep = Gtk::manage(new Gtk::SeparatorMenuItem()); _menu->append(*sep); _non_horizontal.push_back(sep); one->signal_activate().connect(sigc::bind(sigc::mem_fun(*this, &Panel::_bounceCall), PANEL_SETTING_MODE, 0)); @@ -147,14 +147,14 @@ void Panel::_init() NC_("Swatches height", "Huge") }; - Gtk::MenuItem *sizeItem = manage(new Gtk::MenuItem(heightItemLabel)); - Gtk::Menu *sizeMenu = manage(new Gtk::Menu()); + Gtk::MenuItem *sizeItem = Gtk::manage(new Gtk::MenuItem(heightItemLabel)); + Gtk::Menu *sizeMenu = Gtk::manage(new Gtk::Menu()); sizeItem->set_submenu(*sizeMenu); Gtk::RadioMenuItem::Group heightGroup; for (unsigned int i = 0; i < G_N_ELEMENTS(heightLabels); i++) { Glib::ustring _label(g_dpgettext2(NULL, "Swatches height", heightLabels[i])); - Gtk::RadioMenuItem* _item = manage(new Gtk::RadioMenuItem(heightGroup, _label)); + Gtk::RadioMenuItem* _item = Gtk::manage(new Gtk::RadioMenuItem(heightGroup, _label)); sizeMenu->append(*_item); if (i == panel_size) { _item->set_active(true); @@ -177,8 +177,8 @@ void Panel::_init() NC_("Swatches width", "Wider") }; - Gtk::MenuItem *item = manage( new Gtk::MenuItem(widthItemLabel)); - Gtk::Menu *type_menu = manage(new Gtk::Menu()); + Gtk::MenuItem *item = Gtk::manage( new Gtk::MenuItem(widthItemLabel)); + Gtk::Menu *type_menu = Gtk::manage(new Gtk::Menu()); item->set_submenu(*type_menu); _menu->append(*item); @@ -194,7 +194,7 @@ void Panel::_init() } for ( guint i = 0; i < G_N_ELEMENTS(widthLabels); ++i ) { Glib::ustring _label(g_dpgettext2(NULL, "Swatches width", widthLabels[i])); - Gtk::RadioMenuItem *_item = manage(new Gtk::RadioMenuItem(widthGroup, _label)); + Gtk::RadioMenuItem *_item = Gtk::manage(new Gtk::RadioMenuItem(widthGroup, _label)); type_menu->append(*_item); if ( i <= hot_index ) { _item->set_active(true); @@ -213,8 +213,8 @@ void Panel::_init() NC_("Swatches border", "Wide"), }; - Gtk::MenuItem *item = manage( new Gtk::MenuItem(widthItemLabel)); - Gtk::Menu *type_menu = manage(new Gtk::Menu()); + Gtk::MenuItem *item = Gtk::manage( new Gtk::MenuItem(widthItemLabel)); + Gtk::Menu *type_menu = Gtk::manage(new Gtk::Menu()); item->set_submenu(*type_menu); _menu->append(*item); @@ -230,7 +230,7 @@ void Panel::_init() } for ( guint i = 0; i < G_N_ELEMENTS(widthLabels); ++i ) { Glib::ustring _label(g_dpgettext2(NULL, "Swatches border", widthLabels[i])); - Gtk::RadioMenuItem *_item = manage(new Gtk::RadioMenuItem(widthGroup, _label)); + Gtk::RadioMenuItem *_item = Gtk::manage(new Gtk::RadioMenuItem(widthGroup, _label)); type_menu->append(*_item); if ( i <= hot_index ) { _item->set_active(true); @@ -242,7 +242,7 @@ void Panel::_init() { //TRANSLATORS: "Wrap" indicates how colour swatches are displayed Glib::ustring wrap_label(C_("Swatches","Wrap")); - Gtk::CheckMenuItem *check = manage(new Gtk::CheckMenuItem(wrap_label)); + Gtk::CheckMenuItem *check = Gtk::manage(new Gtk::CheckMenuItem(wrap_label)); check->set_active(panel_wrap); _menu->append(*check); _non_vertical.push_back(check); @@ -251,7 +251,7 @@ void Panel::_init() } Gtk::SeparatorMenuItem *sep; - sep = manage(new Gtk::SeparatorMenuItem()); + sep = Gtk::manage(new Gtk::SeparatorMenuItem()); _menu->append(*sep); _menu->show_all_children(); @@ -284,7 +284,7 @@ void Panel::_init() pack_start(_top_bar, false, false); - Gtk::HBox* boxy = manage(new Gtk::HBox()); + Gtk::HBox* boxy = Gtk::manage(new Gtk::HBox()); boxy->pack_start(_contents, true, true); boxy->pack_start(_right_bar, false, true); diff --git a/src/ui/widget/registered-widget.cpp b/src/ui/widget/registered-widget.cpp index 175f6471c..92cb3f03d 100644 --- a/src/ui/widget/registered-widget.cpp +++ b/src/ui/widget/registered-widget.cpp @@ -429,11 +429,11 @@ RegisteredRadioButtonPair::RegisteredRadioButtonPair (const Glib::ustring& label setProgrammatically = false; - add (*manage (new Gtk::Label (label))); - _rb1 = manage (new Gtk::RadioButton (label1, true)); + add(*Gtk::manage(new Gtk::Label(label))); + _rb1 = Gtk::manage(new Gtk::RadioButton(label1, true)); add (*_rb1); Gtk::RadioButtonGroup group = _rb1->get_group(); - _rb2 = manage (new Gtk::RadioButton (group, label2, true)); + _rb2 = Gtk::manage(new Gtk::RadioButton(group, label2, true)); add (*_rb2); _rb2->set_active(); _rb1->set_tooltip_text(tip1); diff --git a/src/ui/widget/tolerance-slider.cpp b/src/ui/widget/tolerance-slider.cpp index d166e3831..5fc588fdc 100644 --- a/src/ui/widget/tolerance-slider.cpp +++ b/src/ui/widget/tolerance-slider.cpp @@ -71,19 +71,19 @@ void ToleranceSlider::init (const Glib::ustring& label1, const Glib::ustring& la // hbox _vbox = new Gtk::VBox; - _hbox = manage (new Gtk::HBox); + _hbox = Gtk::manage(new Gtk::HBox); - Gtk::Label *theLabel1 = manage (new Gtk::Label (label1)); + Gtk::Label *theLabel1 = Gtk::manage(new Gtk::Label(label1)); theLabel1->set_use_underline(); theLabel1->set_alignment(0, 0.5); // align the label with the checkbox text above by indenting 22 px. _hbox->pack_start(*theLabel1, Gtk::PACK_EXPAND_WIDGET, 22); #if WITH_GTKMM_3_0 - _hscale = manage(new Gtk::Scale(Gtk::ORIENTATION_HORIZONTAL)); + _hscale = Gtk::manage(new Gtk::Scale(Gtk::ORIENTATION_HORIZONTAL)); _hscale->set_range(1.0, 51.0); #else - _hscale = manage (new Gtk::HScale (1.0, 51, 1.0)); + _hscale = Gtk::manage (new Gtk::HScale (1.0, 51, 1.0)); #endif theLabel1->set_mnemonic_widget (*_hscale); @@ -96,13 +96,13 @@ void ToleranceSlider::init (const Glib::ustring& label1, const Glib::ustring& la _hbox->add (*_hscale); - Gtk::Label *theLabel2 = manage (new Gtk::Label (label2)); + Gtk::Label *theLabel2 = Gtk::manage(new Gtk::Label(label2)); theLabel2->set_use_underline(); - Gtk::Label *theLabel3 = manage (new Gtk::Label (label3)); + Gtk::Label *theLabel3 = Gtk::manage(new Gtk::Label(label3)); theLabel3->set_use_underline(); - _button1 = manage (new Gtk::RadioButton); + _button1 = Gtk::manage(new Gtk::RadioButton); _radio_button_group = _button1->get_group(); - _button2 = manage (new Gtk::RadioButton); + _button2 = Gtk::manage(new Gtk::RadioButton); _button2->set_group(_radio_button_group); _button1->set_tooltip_text (tip2); _button2->set_tooltip_text (tip3); -- cgit v1.2.3 From 8ad7f3d261619d168ee0bf0e54824f9f354d2970 Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Mon, 31 Mar 2014 00:44:37 +0200 Subject: imageicon: clean up unnecessary file existance check introduced in rev 12263. Could theoretically lead to uninitialized value use (of "info" struct) same for filedialogimpl-gtkmm (bzr r13240) --- src/ui/dialog/filedialogimpl-gtkmm.cpp | 31 ++++++++++--------- src/ui/widget/imageicon.cpp | 55 +++++++++++++--------------------- 2 files changed, 36 insertions(+), 50 deletions(-) (limited to 'src/ui') diff --git a/src/ui/dialog/filedialogimpl-gtkmm.cpp b/src/ui/dialog/filedialogimpl-gtkmm.cpp index fdc9cecc3..60b437575 100644 --- a/src/ui/dialog/filedialogimpl-gtkmm.cpp +++ b/src/ui/dialog/filedialogimpl-gtkmm.cpp @@ -514,10 +514,11 @@ void SVGPreview::showTooLarge(long fileLength) bool SVGPreview::set(Glib::ustring &fileName, int dialogType) { - if (!Glib::file_test(fileName, Glib::FILE_TEST_EXISTS)) + if (!Glib::file_test(fileName, Glib::FILE_TEST_EXISTS)) { + showNoPreview(); return false; + } - //g_message("fname:%s", fileName.c_str()); if (Glib::file_test(fileName, Glib::FILE_TEST_IS_DIR)) { showNoPreview(); @@ -525,24 +526,22 @@ bool SVGPreview::set(Glib::ustring &fileName, int dialogType) } if (Glib::file_test(fileName, Glib::FILE_TEST_IS_REGULAR)) - { + { Glib::ustring fileNameUtf8 = Glib::filename_to_utf8(fileName); - gchar *fName = const_cast(fileNameUtf8.c_str()); + gchar *fName = const_cast(fileNameUtf8.c_str()); // const-cast probably not necessary? (not necessary on Windows version of stat()) struct stat info; - if (g_file_test (fName, G_FILE_TEST_EXISTS) && g_stat(fName, &info)) - { - g_warning("SVGPreview::set() : %s : %s", - fName, strerror(errno)); - return FALSE; - } - long fileLen = info.st_size; - if (fileLen > 0xA00000L) - { + if (g_stat(fName, &info)) // stat returns 0 upon success + { + g_warning("SVGPreview::set() : %s : %s", fName, strerror(errno)); + return false; + } + if (info.st_size > 0xA00000L) + { showingNoPreview = false; - showTooLarge(fileLen); - return FALSE; - } + showTooLarge(info.st_size); + return false; } + } Glib::ustring svg = ".svg"; Glib::ustring svgz = ".svgz"; diff --git a/src/ui/widget/imageicon.cpp b/src/ui/widget/imageicon.cpp index cf41a16a4..22abd04ba 100644 --- a/src/ui/widget/imageicon.cpp +++ b/src/ui/widget/imageicon.cpp @@ -369,60 +369,47 @@ isValidImageIconFile(const Glib::ustring &fileName) return false; } +/// \fixme This function is almost an exact duplicate of SVGPreview::set() in ui/dialog/filedialogimpl-gtkmm.cpp. bool ImageIcon::show(const Glib::ustring &fileName) { - - if (!Glib::file_test(fileName, Glib::FILE_TEST_EXISTS)) + if (!Glib::file_test(fileName, Glib::FILE_TEST_EXISTS)) { + showBrokenImage("File does not exist"); return false; + } - gchar *fName = const_cast(fileName.c_str()); - //g_message("fname:%s\n", fName); - - - if (Glib::file_test(fileName, Glib::FILE_TEST_IS_REGULAR)) - { + if (Glib::file_test(fileName, Glib::FILE_TEST_IS_REGULAR)) { + gchar *fName = const_cast(fileName.c_str()); // this const-cast seems not necessary, was it put there because of older sys/stat.h version? struct stat info; - if (g_file_test (fName, G_FILE_TEST_EXISTS) && stat(fName, &info)) - { - Glib::ustring err = "cannot get file info"; - showBrokenImage(err); + if (stat(fName, &info)) // stat returns 0 upon success + { + showBrokenImage("Cannot get file info"); return false; - } - long fileLen = info.st_size; - if (fileLen > 0x150000L) - { - Glib::ustring err = "File too large"; - showBrokenImage(err); + } + if (info.st_size > 0x150000L) { + showBrokenImage("File too large"); return false; - } } + } Glib::ustring svg = ".svg"; Glib::ustring svgz = ".svgz"; - if (hasSuffix(fileName, svg) || hasSuffix(fileName, svgz) ) - { - if (!showSvgFile(fileName)) - { + if (hasSuffix(fileName, svg) || hasSuffix(fileName, svgz)) { + if (!showSvgFile(fileName)) { showBrokenImage(bitmapError); return false; - } - return true; } - else if (isValidImageIconFile(fileName)) - { - if (!showBitmap(fileName)) - { + return true; + } else if (isValidImageIconFile(fileName)) { + if (!showBitmap(fileName)) { showBrokenImage(bitmapError); return false; - } - return true; } - else - { + return true; + } else { showBrokenImage("unsupported file type"); return false; - } + } } -- cgit v1.2.3 From 4f1e7157051832f957fc9acfe4ebc71a9e76c4e8 Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Mon, 31 Mar 2014 00:55:21 +0200 Subject: better code format filedialogimpl-gtkmm.cpp. Also cleanup some minor code issues (bzr r13241) --- src/ui/dialog/filedialogimpl-gtkmm.cpp | 1163 +++++++++++++++----------------- 1 file changed, 549 insertions(+), 614 deletions(-) (limited to 'src/ui') diff --git a/src/ui/dialog/filedialogimpl-gtkmm.cpp b/src/ui/dialog/filedialogimpl-gtkmm.cpp index 60b437575..8ba3ad684 100644 --- a/src/ui/dialog/filedialogimpl-gtkmm.cpp +++ b/src/ui/dialog/filedialogimpl-gtkmm.cpp @@ -18,7 +18,7 @@ */ #ifdef HAVE_CONFIG_H -# include +#include #endif #include "filedialogimpl-gtkmm.h" @@ -29,7 +29,7 @@ #include "preferences.h" #ifdef WITH_GNOME_VFS -# include +#include #endif #include @@ -46,24 +46,19 @@ #include "svg-view-widget.h" #include "inkscape.h" -//Routines from file.cpp +// Routines from file.cpp #undef INK_DUMP_FILENAME_CONV #ifdef INK_DUMP_FILENAME_CONV -void dump_str( const gchar* str, const gchar* prefix ); -void dump_ustr( const Glib::ustring& ustr ); +void dump_str(const gchar *str, const gchar *prefix); +void dump_ustr(const Glib::ustring &ustr); #endif -namespace Inkscape -{ -namespace UI -{ -namespace Dialog -{ - - +namespace Inkscape { +namespace UI { +namespace Dialog { @@ -71,64 +66,51 @@ namespace Dialog //### U T I L I T Y //######################################################################## -void -fileDialogExtensionToPattern(Glib::ustring &pattern, - Glib::ustring &extension) +void fileDialogExtensionToPattern(Glib::ustring &pattern, Glib::ustring &extension) { - for (unsigned int i = 0; i < extension.length(); i++ ) - { + for (unsigned int i = 0; i < extension.length(); ++i) { Glib::ustring::value_type ch = extension[i]; - if ( Glib::Unicode::isalpha(ch) ) - { + if (Glib::Unicode::isalpha(ch)) { pattern += '['; pattern += Glib::Unicode::toupper(ch); pattern += Glib::Unicode::tolower(ch); pattern += ']'; - } - else - { + } else { pattern += ch; - } } + } } -void -findEntryWidgets(Gtk::Container *parent, - std::vector &result) +void findEntryWidgets(Gtk::Container *parent, std::vector &result) { - if (!parent) + if (!parent) { return; + } std::vector children = parent->get_children(); - for (unsigned int i=0; igobj(); if (GTK_IS_ENTRY(wid)) - result.push_back(dynamic_cast(child)); + result.push_back(dynamic_cast(child)); else if (GTK_IS_CONTAINER(wid)) findEntryWidgets(dynamic_cast(child), result); - } - + } } -void -findExpanderWidgets(Gtk::Container *parent, - std::vector &result) +void findExpanderWidgets(Gtk::Container *parent, std::vector &result) { if (!parent) return; std::vector children = parent->get_children(); - for (unsigned int i=0; igobj(); if (GTK_IS_EXPANDER(wid)) - result.push_back(dynamic_cast(child)); + result.push_back(dynamic_cast(child)); else if (GTK_IS_CONTAINER(wid)) findExpanderWidgets(dynamic_cast(child), result); - } - + } } @@ -144,13 +126,13 @@ bool SVGPreview::setDocument(SPDocument *doc) doc->doRef(); document = doc; - //This should remove it from the box, and free resources + // This should remove it from the box, and free resources if (viewerGtk) Gtk::Container::remove(*viewerGtk); - viewerGtk = Glib::wrap(sp_svg_view_widget_new(doc)); + viewerGtk = Glib::wrap(sp_svg_view_widget_new(doc)); Gtk::VBox *vbox = Glib::wrap(gobj()); - vbox->pack_start(*viewerGtk, TRUE, TRUE, 0); + vbox->pack_start(*viewerGtk, TRUE, TRUE, 0); viewerGtk->show(); return true; } @@ -166,7 +148,7 @@ bool SVGPreview::setFileName(Glib::ustring &theFileName) * I don't know why passing false to keepalive is bad. But it * prevents the display of an svg with a non-ascii filename */ - SPDocument *doc = SPDocument::createNewDoc (fileName.c_str(), true); + SPDocument *doc = SPDocument::createNewDoc(fileName.c_str(), true); if (!doc) { g_warning("SVGView: error loading document '%s'\n", fileName.c_str()); return false; @@ -189,7 +171,7 @@ bool SVGPreview::setFromMem(char const *xmlBuffer) gint len = (gint)strlen(xmlBuffer); SPDocument *doc = SPDocument::createNewDocFromMem(xmlBuffer, len, 0); if (!doc) { - g_warning("SVGView: error loading buffer '%s'\n",xmlBuffer); + g_warning("SVGView: error loading buffer '%s'\n", xmlBuffer); return false; } @@ -216,21 +198,22 @@ void SVGPreview::showImage(Glib::ustring &theFileName) # display it nicely? #####################################*/ - //Arbitrary size of svg doc -- rather 'portrait' shaped - gint previewWidth = 400; + // Arbitrary size of svg doc -- rather 'portrait' shaped + gint previewWidth = 400; gint previewHeight = 600; - //Get some image info. Smart pointer does not need to be deleted + // Get some image info. Smart pointer does not need to be deleted Glib::RefPtr img(NULL); - try { + try + { img = Gdk::Pixbuf::create_from_file(fileName); } - catch (const Glib::FileError & e) + catch (const Glib::FileError &e) { g_message("caught Glib::FileError in SVGPreview::showImage"); return; } - catch (const Gdk::PixbufError & e) + catch (const Gdk::PixbufError &e) { g_message("Gdk::PixbufError in SVGPreview::showImage"); return; @@ -241,70 +224,66 @@ void SVGPreview::showImage(Glib::ustring &theFileName) return; } - gint imgWidth = img->get_width(); + gint imgWidth = img->get_width(); gint imgHeight = img->get_height(); - //Find the minimum scale to fit the image inside the preview area - double scaleFactorX = (0.9 *(double)previewWidth) / ((double)imgWidth); - double scaleFactorY = (0.9 *(double)previewHeight) / ((double)imgHeight); + // Find the minimum scale to fit the image inside the preview area + double scaleFactorX = (0.9 * (double)previewWidth) / ((double)imgWidth); + double scaleFactorY = (0.9 * (double)previewHeight) / ((double)imgHeight); double scaleFactor = scaleFactorX; if (scaleFactorX > scaleFactorY) scaleFactor = scaleFactorY; - //Now get the resized values - gint scaledImgWidth = (int) (scaleFactor * (double)imgWidth); - gint scaledImgHeight = (int) (scaleFactor * (double)imgHeight); + // Now get the resized values + gint scaledImgWidth = (int)(scaleFactor * (double)imgWidth); + gint scaledImgHeight = (int)(scaleFactor * (double)imgHeight); - //center the image on the area - gint imgX = (previewWidth - scaledImgWidth) / 2; + // center the image on the area + gint imgX = (previewWidth - scaledImgWidth) / 2; gint imgY = (previewHeight - scaledImgHeight) / 2; - //wrap a rectangle around the image - gint rectX = imgX-1; - gint rectY = imgY-1; - gint rectWidth = scaledImgWidth +2; - gint rectHeight = scaledImgHeight+2; - - //Our template. Modify to taste - gchar const *xformat = - "\n" - "\n" //# VALUES HERE - "\n" - "\n" - "\n" - "%d x %d\n" //# VALUES HERE - "\n\n"; - - //if (!Glib::get_charset()) //If we are not utf8 + // wrap a rectangle around the image + gint rectX = imgX - 1; + gint rectY = imgY - 1; + gint rectWidth = scaledImgWidth + 2; + gint rectHeight = scaledImgHeight + 2; + + // Our template. Modify to taste + gchar const *xformat = "\n" + "\n" //# VALUES HERE + "\n" + "\n" + "\n" + "%d x %d\n" //# VALUES HERE + "\n\n"; + + // if (!Glib::get_charset()) //If we are not utf8 fileName = Glib::filename_to_utf8(fileName); - //Fill in the template + // Fill in the template /* FIXME: Do proper XML quoting for fileName. */ - gchar *xmlBuffer = g_strdup_printf(xformat, - previewWidth, previewHeight, - imgX, imgY, scaledImgWidth, scaledImgHeight, - fileName.c_str(), - rectX, rectY, rectWidth, rectHeight, - imgWidth, imgHeight); + gchar *xmlBuffer = + g_strdup_printf(xformat, previewWidth, previewHeight, imgX, imgY, scaledImgWidth, scaledImgHeight, + fileName.c_str(), rectX, rectY, rectWidth, rectHeight, imgWidth, imgHeight); - //g_message("%s\n", xmlBuffer); + // g_message("%s\n", xmlBuffer); - //now show it! + // now show it! setFromMem(xmlBuffer); g_free(xmlBuffer); } @@ -313,97 +292,95 @@ void SVGPreview::showImage(Glib::ustring &theFileName) void SVGPreview::showNoPreview() { - //Are we already showing it? + // Are we already showing it? if (showingNoPreview) return; - //Arbitrary size of svg doc -- rather 'portrait' shaped - gint previewWidth = 300; + // Arbitrary size of svg doc -- rather 'portrait' shaped + gint previewWidth = 300; gint previewHeight = 600; - //Our template. Modify to taste + // Our template. Modify to taste gchar const *xformat = - "\n" - "\n" //# VALUES HERE - "\n" - "\n" - "\n" - "\n" - "\n" - "\n" - " \n" - "%s\n" //# VALUE HERE - "\n\n"; - - //Fill in the template - gchar *xmlBuffer = g_strdup_printf(xformat, - previewWidth, previewHeight, _("No preview")); - - //g_message("%s\n", xmlBuffer); - - //now show it! + "\n" + "\n" //# VALUES HERE + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + " \n" + "%s\n" //# VALUE HERE + "\n\n"; + + // Fill in the template + gchar *xmlBuffer = g_strdup_printf(xformat, previewWidth, previewHeight, _("No preview")); + + // g_message("%s\n", xmlBuffer); + + // now show it! setFromMem(xmlBuffer); g_free(xmlBuffer); showingNoPreview = true; - } @@ -414,101 +391,99 @@ void SVGPreview::showNoPreview() void SVGPreview::showTooLarge(long fileLength) { - //Arbitrary size of svg doc -- rather 'portrait' shaped - gint previewWidth = 300; + // Arbitrary size of svg doc -- rather 'portrait' shaped + gint previewWidth = 300; gint previewHeight = 600; - //Our template. Modify to taste + // Our template. Modify to taste gchar const *xformat = - "\n" - "\n" //# VALUES HERE - "\n" - "\n" - "\n" - "\n" - "\n" - "\n" - "\n" - "%5.1f MB\n" //# VALUE HERE - "%s\n" //# VALUE HERE - "\n\n"; - - //Fill in the template + "\n" + "\n" //# VALUES HERE + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "%5.1f MB\n" //# VALUE HERE + "%s\n" //# VALUE HERE + "\n\n"; + + // Fill in the template double floatFileLength = ((double)fileLength) / 1048576.0; - //printf("%ld %f\n", fileLength, floatFileLength); - gchar *xmlBuffer = g_strdup_printf(xformat, - previewWidth, previewHeight, floatFileLength, - _("too large for preview")); + // printf("%ld %f\n", fileLength, floatFileLength); + gchar *xmlBuffer = + g_strdup_printf(xformat, previewWidth, previewHeight, floatFileLength, _("too large for preview")); - //g_message("%s\n", xmlBuffer); + // g_message("%s\n", xmlBuffer); - //now show it! + // now show it! setFromMem(xmlBuffer); g_free(xmlBuffer); - } bool SVGPreview::set(Glib::ustring &fileName, int dialogType) @@ -525,18 +500,17 @@ bool SVGPreview::set(Glib::ustring &fileName, int dialogType) return false; } - if (Glib::file_test(fileName, Glib::FILE_TEST_IS_REGULAR)) - { + if (Glib::file_test(fileName, Glib::FILE_TEST_IS_REGULAR)) { Glib::ustring fileNameUtf8 = Glib::filename_to_utf8(fileName); - gchar *fName = const_cast(fileNameUtf8.c_str()); // const-cast probably not necessary? (not necessary on Windows version of stat()) + gchar *fName = const_cast( + fileNameUtf8.c_str()); // const-cast probably not necessary? (not necessary on Windows version of stat()) struct stat info; if (g_stat(fName, &info)) // stat returns 0 upon success { g_warning("SVGPreview::set() : %s : %s", fName, strerror(errno)); return false; } - if (info.st_size > 0xA00000L) - { + if (info.st_size > 0xA00000L) { showingNoPreview = false; showTooLarge(info.st_size); return false; @@ -547,8 +521,7 @@ bool SVGPreview::set(Glib::ustring &fileName, int dialogType) Glib::ustring svgz = ".svgz"; if ((dialogType == SVG_TYPES || dialogType == IMPORT_TYPES) && - (hasSuffix(fileName, svg) || hasSuffix(fileName, svgz) ) - ) { + (hasSuffix(fileName, svg) || hasSuffix(fileName, svgz))) { bool retval = setFileName(fileName); showingNoPreview = false; return retval; @@ -566,16 +539,15 @@ bool SVGPreview::set(Glib::ustring &fileName, int dialogType) SVGPreview::SVGPreview() { if (!INKSCAPE) - inkscape_application_init("",false); + inkscape_application_init("", false); document = NULL; viewerGtk = NULL; - set_size_request(150,150); + set_size_request(150, 150); showingNoPreview = false; } SVGPreview::~SVGPreview() { - } @@ -588,32 +560,30 @@ void FileDialogBaseGtk::internalSetup() // Open executable file dialogs don't need the preview panel if (_dialogType != EXE_TYPES) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - bool enablePreview = prefs->getBool( preferenceBase + "/enable_preview", true); + bool enablePreview = prefs->getBool(preferenceBase + "/enable_preview", true); - previewCheckbox.set_label( Glib::ustring(_("Enable preview")) ); - previewCheckbox.set_active( enablePreview ); + previewCheckbox.set_label(Glib::ustring(_("Enable preview"))); + previewCheckbox.set_active(enablePreview); - previewCheckbox.signal_toggled().connect( - sigc::mem_fun(*this, &FileDialogBaseGtk::_previewEnabledCB) ); + previewCheckbox.signal_toggled().connect(sigc::mem_fun(*this, &FileDialogBaseGtk::_previewEnabledCB)); - //Catch selection-changed events, so we can adjust the text widget - signal_update_preview().connect( - sigc::mem_fun(*this, &FileDialogBaseGtk::_updatePreviewCallback) ); + // Catch selection-changed events, so we can adjust the text widget + signal_update_preview().connect(sigc::mem_fun(*this, &FileDialogBaseGtk::_updatePreviewCallback)); //###### Add a preview widget set_preview_widget(svgPreview); - set_preview_widget_active( enablePreview ); - set_use_preview_label (false); + set_preview_widget_active(enablePreview); + set_use_preview_label(false); } } -void FileDialogBaseGtk::cleanup( bool showConfirmed ) +void FileDialogBaseGtk::cleanup(bool showConfirmed) { if (_dialogType != EXE_TYPES) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - if ( showConfirmed ) { - prefs->setBool( preferenceBase + "/enable_preview", previewCheckbox.get_active() ); + if (showConfirmed) { + prefs->setBool(preferenceBase + "/enable_preview", previewCheckbox.get_active()); } } } @@ -623,7 +593,7 @@ void FileDialogBaseGtk::_previewEnabledCB() { bool enabled = previewCheckbox.get_active(); set_preview_widget_active(enabled); - if ( enabled ) { + if (enabled) { _updatePreviewCallback(); } else { // Clears out any current preview image. @@ -642,12 +612,12 @@ void FileDialogBaseGtk::_updatePreviewCallback() bool enabled = previewCheckbox.get_active(); #ifdef WITH_GNOME_VFS - if ( fileName.empty() && gnome_vfs_initialized() ) { + if (fileName.empty() && gnome_vfs_initialized()) { fileName = get_preview_uri(); } #endif - if ( enabled && !fileName.empty() ) { + if (enabled && !fileName.empty()) { svgPreview.set(fileName, _dialogType); } else { svgPreview.showNoPreview(); @@ -662,11 +632,9 @@ void FileDialogBaseGtk::_updatePreviewCallback() /** * Constructor. Not called directly. Use the factory. */ -FileOpenDialogImplGtk::FileOpenDialogImplGtk(Gtk::Window& parentWindow, - const Glib::ustring &dir, - FileDialogType fileTypes, - const Glib::ustring &title) : - FileDialogBaseGtk(parentWindow, title, Gtk::FILE_CHOOSER_ACTION_OPEN, fileTypes, "/dialogs/open") +FileOpenDialogImplGtk::FileOpenDialogImplGtk(Gtk::Window &parentWindow, const Glib::ustring &dir, + FileDialogType fileTypes, const Glib::ustring &title) + : FileDialogBaseGtk(parentWindow, title, Gtk::FILE_CHOOSER_ACTION_OPEN, fileTypes, "/dialogs/open") { @@ -699,7 +667,8 @@ FileOpenDialogImplGtk::FileOpenDialogImplGtk(Gtk::Window& parentWindow, Glib::ustring::size_type len = udir.length(); // leaving a trailing backslash on the directory name leads to the infamous // double-directory bug on win32 - if (len != 0 && udir[len - 1] == '\\') udir.erase(len - 1); + if (len != 0 && udir[len - 1] == '\\') + udir.erase(len - 1); if (_dialogType == EXE_TYPES) { set_filename(udir.c_str()); } else { @@ -708,21 +677,18 @@ FileOpenDialogImplGtk::FileOpenDialogImplGtk(Gtk::Window& parentWindow, } if (_dialogType != EXE_TYPES) { - set_extra_widget( previewCheckbox ); + set_extra_widget(previewCheckbox); } //###### Add the file types menu createFilterMenu(); add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); - set_default(*add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK)); + set_default(*add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK)); //###### Allow easy access to our examples folder - if ( Inkscape::IO::file_test(INKSCAPE_EXAMPLESDIR, G_FILE_TEST_EXISTS) - && Inkscape::IO::file_test(INKSCAPE_EXAMPLESDIR, G_FILE_TEST_IS_DIR) - && g_path_is_absolute(INKSCAPE_EXAMPLESDIR) - ) - { + if (Inkscape::IO::file_test(INKSCAPE_EXAMPLESDIR, G_FILE_TEST_EXISTS) && + Inkscape::IO::file_test(INKSCAPE_EXAMPLESDIR, G_FILE_TEST_IS_DIR) && g_path_is_absolute(INKSCAPE_EXAMPLESDIR)) { add_shortcut_folder(INKSCAPE_EXAMPLESDIR); } } @@ -732,23 +698,22 @@ FileOpenDialogImplGtk::FileOpenDialogImplGtk(Gtk::Window& parentWindow, */ FileOpenDialogImplGtk::~FileOpenDialogImplGtk() { - } void FileOpenDialogImplGtk::addFilterMenu(Glib::ustring name, Glib::ustring pattern) { #if WITH_GTKMM_3_0 - Glib::RefPtr allFilter = Gtk::FileFilter::create(); - allFilter->set_name(_(name.c_str())); - allFilter->add_pattern(pattern); + Glib::RefPtr allFilter = Gtk::FileFilter::create(); + allFilter->set_name(_(name.c_str())); + allFilter->add_pattern(pattern); #else - Gtk::FileFilter allFilter; - allFilter.set_name(_(name.c_str())); - allFilter.add_pattern(pattern); + Gtk::FileFilter allFilter; + allFilter.set_name(_(name.c_str())); + allFilter.add_pattern(pattern); #endif - extensionMap[Glib::ustring(_("All Files"))]=NULL; - add_filter(allFilter); + extensionMap[Glib::ustring(_("All Files"))] = NULL; + add_filter(allFilter); } void FileOpenDialogImplGtk::createFilterMenu() @@ -767,68 +732,69 @@ void FileOpenDialogImplGtk::createFilterMenu() allFilter.set_name(_("All Files")); allFilter.add_pattern("*"); #endif - extensionMap[Glib::ustring(_("All Files"))]=NULL; + extensionMap[Glib::ustring(_("All Files"))] = NULL; add_filter(allFilter); } else { #if WITH_GTKMM_3_0 Glib::RefPtr allInkscapeFilter = Gtk::FileFilter::create(); allInkscapeFilter->set_name(_("All Inkscape Files")); - - Glib::RefPtr allFilter = Gtk::FileFilter::create(); + + Glib::RefPtr allFilter = Gtk::FileFilter::create(); allFilter->set_name(_("All Files")); allFilter->add_pattern("*"); - - Glib::RefPtr allImageFilter = Gtk::FileFilter::create(); + + Glib::RefPtr allImageFilter = Gtk::FileFilter::create(); allImageFilter->set_name(_("All Images")); - - Glib::RefPtr allVectorFilter = Gtk::FileFilter::create(); + + Glib::RefPtr allVectorFilter = Gtk::FileFilter::create(); allVectorFilter->set_name(_("All Vectors")); - - Glib::RefPtr allBitmapFilter = Gtk::FileFilter::create(); + + Glib::RefPtr allBitmapFilter = Gtk::FileFilter::create(); allBitmapFilter->set_name(_("All Bitmaps")); #else Gtk::FileFilter allInkscapeFilter; allInkscapeFilter.set_name(_("All Inkscape Files")); - - Gtk::FileFilter allFilter; + + Gtk::FileFilter allFilter; allFilter.set_name(_("All Files")); allFilter.add_pattern("*"); - - Gtk::FileFilter allImageFilter; + + Gtk::FileFilter allImageFilter; allImageFilter.set_name(_("All Images")); - - Gtk::FileFilter allVectorFilter; + + Gtk::FileFilter allVectorFilter; allVectorFilter.set_name(_("All Vectors")); - - Gtk::FileFilter allBitmapFilter; + + Gtk::FileFilter allBitmapFilter; allBitmapFilter.set_name(_("All Bitmaps")); #endif - extensionMap[Glib::ustring(_("All Inkscape Files"))]=NULL; + extensionMap[Glib::ustring(_("All Inkscape Files"))] = NULL; add_filter(allInkscapeFilter); - extensionMap[Glib::ustring(_("All Files"))]=NULL; + extensionMap[Glib::ustring(_("All Files"))] = NULL; add_filter(allFilter); - - extensionMap[Glib::ustring(_("All Images"))]=NULL; + + extensionMap[Glib::ustring(_("All Images"))] = NULL; add_filter(allImageFilter); - extensionMap[Glib::ustring(_("All Vectors"))]=NULL; + extensionMap[Glib::ustring(_("All Vectors"))] = NULL; add_filter(allVectorFilter); - extensionMap[Glib::ustring(_("All Bitmaps"))]=NULL; + extensionMap[Glib::ustring(_("All Bitmaps"))] = NULL; add_filter(allBitmapFilter); - //patterns added dynamically below + // patterns added dynamically below Inkscape::Extension::DB::InputList extension_list; Inkscape::Extension::db.get_input_list(extension_list); for (Inkscape::Extension::DB::InputList::iterator current_item = extension_list.begin(); current_item != extension_list.end(); ++current_item) { - Inkscape::Extension::Input * imod = *current_item; + Inkscape::Extension::Input *imod = *current_item; // FIXME: would be nice to grey them out instead of not listing them - if (imod->deactivated()) continue; + if (imod->deactivated()) + continue; Glib::ustring upattern("*"); Glib::ustring extension = imod->get_extension(); @@ -837,7 +803,7 @@ void FileOpenDialogImplGtk::createFilterMenu() Glib::ustring uname(_(imod->get_filetypename())); #if WITH_GTKMM_3_0 - Glib::RefPtr filter = Gtk::FileFilter::create(); + Glib::RefPtr filter = Gtk::FileFilter::create(); filter->set_name(uname); filter->add_pattern(upattern); #else @@ -849,14 +815,14 @@ void FileOpenDialogImplGtk::createFilterMenu() add_filter(filter); extensionMap[uname] = imod; - //g_message("ext %s:%s '%s'\n", ioext->name, ioext->mimetype, upattern.c_str()); +// g_message("ext %s:%s '%s'\n", ioext->name, ioext->mimetype, upattern.c_str()); #if WITH_GTKMM_3_0 allInkscapeFilter->add_pattern(upattern); - if ( strncmp("image", imod->get_mimetype(), 5)==0 ) + if (strncmp("image", imod->get_mimetype(), 5) == 0) allImageFilter->add_pattern(upattern); #else allInkscapeFilter.add_pattern(upattern); - if ( strncmp("image", imod->get_mimetype(), 5)==0 ) + if (strncmp("image", imod->get_mimetype(), 5) == 0) allImageFilter.add_pattern(upattern); #endif @@ -864,32 +830,32 @@ void FileOpenDialogImplGtk::createFilterMenu() // g_print ("%s\n", imod->get_mimetype()); // I don't know of any other way to define "bitmap" formats other than by listing them - if ( - strncmp("image/png", imod->get_mimetype(), 9)==0 || - strncmp("image/jpeg", imod->get_mimetype(), 10)==0 || - strncmp("image/gif", imod->get_mimetype(), 9)==0 || - strncmp("image/x-icon", imod->get_mimetype(), 12)==0 || - strncmp("image/x-navi-animation", imod->get_mimetype(), 22)==0 || - strncmp("image/x-cmu-raster", imod->get_mimetype(), 18)==0 || - strncmp("image/x-xpixmap", imod->get_mimetype(), 15)==0 || - strncmp("image/bmp", imod->get_mimetype(), 9)==0 || - strncmp("image/vnd.wap.wbmp", imod->get_mimetype(), 18)==0 || - strncmp("image/tiff", imod->get_mimetype(), 10)==0 || - strncmp("image/x-xbitmap", imod->get_mimetype(), 15)==0 || - strncmp("image/x-tga", imod->get_mimetype(), 11)==0 || - strncmp("image/x-pcx", imod->get_mimetype(), 11)==0 - ) + if (strncmp("image/png", imod->get_mimetype(), 9) == 0 || + strncmp("image/jpeg", imod->get_mimetype(), 10) == 0 || + strncmp("image/gif", imod->get_mimetype(), 9) == 0 || + strncmp("image/x-icon", imod->get_mimetype(), 12) == 0 || + strncmp("image/x-navi-animation", imod->get_mimetype(), 22) == 0 || + strncmp("image/x-cmu-raster", imod->get_mimetype(), 18) == 0 || + strncmp("image/x-xpixmap", imod->get_mimetype(), 15) == 0 || + strncmp("image/bmp", imod->get_mimetype(), 9) == 0 || + strncmp("image/vnd.wap.wbmp", imod->get_mimetype(), 18) == 0 || + strncmp("image/tiff", imod->get_mimetype(), 10) == 0 || + strncmp("image/x-xbitmap", imod->get_mimetype(), 15) == 0 || + strncmp("image/x-tga", imod->get_mimetype(), 11) == 0 || + strncmp("image/x-pcx", imod->get_mimetype(), 11) == 0) + { #if WITH_GTKMM_3_0 allBitmapFilter->add_pattern(upattern); #else allBitmapFilter.add_pattern(upattern); #endif - else + } else { #if WITH_GTKMM_3_0 allVectorFilter->add_pattern(upattern); #else allVectorFilter.add_pattern(upattern); #endif + } } } return; @@ -898,50 +864,43 @@ void FileOpenDialogImplGtk::createFilterMenu() /** * Show this dialog modally. Return true if user hits [OK] */ -bool -FileOpenDialogImplGtk::show() +bool FileOpenDialogImplGtk::show() { - set_modal (TRUE); //Window - sp_transientize(GTK_WIDGET(gobj())); //Make transient - gint b = run(); //Dialog + set_modal(TRUE); // Window + sp_transientize(GTK_WIDGET(gobj())); // Make transient + gint b = run(); // Dialog svgPreview.showNoPreview(); hide(); - if (b == Gtk::RESPONSE_OK) - { - //This is a hack, to avoid the warning messages that - //Gtk::FileChooser::get_filter() returns - //should be: Gtk::FileFilter *filter = get_filter(); + if (b == Gtk::RESPONSE_OK) { + // This is a hack, to avoid the warning messages that + // Gtk::FileChooser::get_filter() returns + // should be: Gtk::FileFilter *filter = get_filter(); GtkFileChooser *gtkFileChooser = Gtk::FileChooser::gobj(); GtkFileFilter *filter = gtk_file_chooser_get_filter(gtkFileChooser); - if (filter) - { - //Get which extension was chosen, if any + if (filter) { + // Get which extension was chosen, if any extension = extensionMap[gtk_file_filter_get_name(filter)]; - } + } myFilename = get_filename(); #ifdef WITH_GNOME_VFS if (myFilename.empty() && gnome_vfs_initialized()) myFilename = get_uri(); #endif - cleanup( true ); - return TRUE; - } - else - { - cleanup( false ); - return FALSE; - } + cleanup(true); + return true; + } else { + cleanup(false); + return false; + } } - /** * Get the file extension type that was selected by the user. Valid after an [OK] */ -Inkscape::Extension::Extension * -FileOpenDialogImplGtk::getSelectionType() +Inkscape::Extension::Extension *FileOpenDialogImplGtk::getSelectionType() { return extension; } @@ -950,8 +909,7 @@ FileOpenDialogImplGtk::getSelectionType() /** * Get the file name chosen by the user. Valid after an [OK] */ -Glib::ustring -FileOpenDialogImplGtk::getFilename (void) +Glib::ustring FileOpenDialogImplGtk::getFilename(void) { return myFilename; } @@ -960,7 +918,7 @@ FileOpenDialogImplGtk::getFilename (void) /** * To Get Multiple filenames selected at-once. */ -std::vectorFileOpenDialogImplGtk::getFilenames() +std::vector FileOpenDialogImplGtk::getFilenames() { #if WITH_GTKMM_3_0 std::vector result_tmp = get_filenames(); @@ -968,9 +926,8 @@ std::vectorFileOpenDialogImplGtk::getFilenames() // Copy filenames to a vector of type Glib::ustring std::vector result; - for (std::vector::iterator it = result_tmp.begin(); - it != result_tmp.end(); ++it) - result.push_back(*it); + for (std::vector::iterator it = result_tmp.begin(); it != result_tmp.end(); ++it) + result.push_back(*it); #else std::vector result = get_filenames(); @@ -990,7 +947,6 @@ Glib::ustring FileOpenDialogImplGtk::getCurrentDirectory() - //######################################################################## //# F I L E S A V E //######################################################################## @@ -998,16 +954,14 @@ Glib::ustring FileOpenDialogImplGtk::getCurrentDirectory() /** * Constructor */ -FileSaveDialogImplGtk::FileSaveDialogImplGtk( Gtk::Window &parentWindow, - const Glib::ustring &dir, - FileDialogType fileTypes, - const Glib::ustring &title, - const Glib::ustring &/*default_key*/, - const gchar* docTitle, - const Inkscape::Extension::FileSaveMethod save_method) : - FileDialogBaseGtk(parentWindow, title, Gtk::FILE_CHOOSER_ACTION_SAVE, fileTypes, - (save_method == Inkscape::Extension::FILE_SAVE_METHOD_SAVE_COPY) ? "/dialogs/save_copy" : "/dialogs/save_as"), - save_method(save_method) +FileSaveDialogImplGtk::FileSaveDialogImplGtk(Gtk::Window &parentWindow, const Glib::ustring &dir, + FileDialogType fileTypes, const Glib::ustring &title, + const Glib::ustring & /*default_key*/, const gchar *docTitle, + const Inkscape::Extension::FileSaveMethod save_method) + : FileDialogBaseGtk(parentWindow, title, Gtk::FILE_CHOOSER_ACTION_SAVE, fileTypes, + (save_method == Inkscape::Extension::FILE_SAVE_METHOD_SAVE_COPY) ? "/dialogs/save_copy" + : "/dialogs/save_as") + , save_method(save_method) { FileSaveDialog::myDocTitle = docTitle; @@ -1029,18 +983,19 @@ FileSaveDialogImplGtk::FileSaveDialogImplGtk( Gtk::Window &parentWindow, _dialogType = fileTypes; /* Set the pwd and/or the filename */ - if (dir.size() > 0) - { + if (dir.size() > 0) { Glib::ustring udir(dir); Glib::ustring::size_type len = udir.length(); // leaving a trailing backslash on the directory name leads to the infamous // double-directory bug on win32 - if (len != 0 && udir[len - 1] == '\\') udir.erase(len - 1); - myFilename = udir; + if ((len != 0) && (udir[len - 1] == '\\')) { + udir.erase(len - 1); } + myFilename = udir; + } //###### Add the file types menu - //createFilterMenu(); + // createFilterMenu(); //###### Do we want the .xxx extension automatically added? Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -1054,60 +1009,54 @@ FileSaveDialogImplGtk::FileSaveDialogImplGtk( Gtk::Window &parentWindow, if (_dialogType != CUSTOM_TYPE) createFileTypeMenu(); - fileTypeComboBox.set_size_request(200,40); - fileTypeComboBox.signal_changed().connect( - sigc::mem_fun(*this, &FileSaveDialogImplGtk::fileTypeChangedCallback) ); + fileTypeComboBox.set_size_request(200, 40); + fileTypeComboBox.signal_changed().connect(sigc::mem_fun(*this, &FileSaveDialogImplGtk::fileTypeChangedCallback)); - childBox.pack_start( checksBox ); - childBox.pack_end( fileTypeComboBox ); - checksBox.pack_start( fileTypeCheckbox ); - checksBox.pack_start( previewCheckbox ); + childBox.pack_start(checksBox); + childBox.pack_end(fileTypeComboBox); + checksBox.pack_start(fileTypeCheckbox); + checksBox.pack_start(previewCheckbox); - set_extra_widget( childBox ); + set_extra_widget(childBox); - //Let's do some customization + // Let's do some customization fileNameEntry = NULL; Gtk::Container *cont = get_toplevel(); std::vector entries; findEntryWidgets(cont, entries); - //g_message("Found %d entry widgets\n", entries.size()); - if (!entries.empty()) - { - //Catch when user hits [return] on the text field + // g_message("Found %d entry widgets\n", entries.size()); + if (!entries.empty()) { + // Catch when user hits [return] on the text field fileNameEntry = entries[0]; fileNameEntry->signal_activate().connect( - sigc::mem_fun(*this, &FileSaveDialogImplGtk::fileNameEntryChangedCallback) ); - } + sigc::mem_fun(*this, &FileSaveDialogImplGtk::fileNameEntryChangedCallback)); + } - //Let's do more customization + // Let's do more customization std::vector expanders; findExpanderWidgets(cont, expanders); - //g_message("Found %d expander widgets\n", expanders.size()); - if (!expanders.empty()) - { - //Always show the file list + // g_message("Found %d expander widgets\n", expanders.size()); + if (!expanders.empty()) { + // Always show the file list Gtk::Expander *expander = expanders[0]; expander->set_expanded(true); - } + } // allow easy access to the user's own templates folder - gchar *templates = profile_path ("templates"); - if ( Inkscape::IO::file_test(templates, G_FILE_TEST_EXISTS) - && Inkscape::IO::file_test(templates, G_FILE_TEST_IS_DIR) - && g_path_is_absolute(templates) - ) - { + gchar *templates = profile_path("templates"); + if (Inkscape::IO::file_test(templates, G_FILE_TEST_EXISTS) && + Inkscape::IO::file_test(templates, G_FILE_TEST_IS_DIR) && g_path_is_absolute(templates)) { add_shortcut_folder(templates); } - g_free (templates); + g_free(templates); - //if (extension == NULL) + // if (extension == NULL) // checkbox.set_sensitive(FALSE); add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); - set_default(*add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK)); + set_default(*add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK)); show_all_children(); } @@ -1128,27 +1077,27 @@ void FileSaveDialogImplGtk::fileNameEntryChangedCallback() return; Glib::ustring fileName = fileNameEntry->get_text(); - if (!Glib::get_charset()) //If we are not utf8 + if (!Glib::get_charset()) // If we are not utf8 fileName = Glib::filename_to_utf8(fileName); - //g_message("User hit return. Text is '%s'\n", fileName.c_str()); + // g_message("User hit return. Text is '%s'\n", fileName.c_str()); if (!Glib::path_is_absolute(fileName)) { - //try appending to the current path + // try appending to the current path // not this way: fileName = get_current_folder() + "/" + fileName; std::vector pathSegments; - pathSegments.push_back( get_current_folder() ); - pathSegments.push_back( fileName ); + pathSegments.push_back(get_current_folder()); + pathSegments.push_back(fileName); fileName = Glib::build_filename(pathSegments); } - //g_message("path:'%s'\n", fileName.c_str()); + // g_message("path:'%s'\n", fileName.c_str()); if (Glib::file_test(fileName, Glib::FILE_TEST_IS_DIR)) { set_current_folder(fileName); - } else if (/*Glib::file_test(fileName, Glib::FILE_TEST_IS_REGULAR)*/1) { - //dialog with either (1) select a regular file or (2) cd to dir - //simulate an 'OK' + } else if (/*Glib::file_test(fileName, Glib::FILE_TEST_IS_REGULAR)*/ 1) { + // dialog with either (1) select a regular file or (2) cd to dir + // simulate an 'OK' set_filename(fileName); response(Gtk::RESPONSE_OK); } @@ -1162,10 +1111,11 @@ void FileSaveDialogImplGtk::fileNameEntryChangedCallback() void FileSaveDialogImplGtk::fileTypeChangedCallback() { int sel = fileTypeComboBox.get_active_row_number(); - if (sel<0 || sel >= (int)fileTypes.size()) + if ((sel < 0) || (sel >= (int)fileTypes.size())) return; + FileType type = fileTypes[sel]; - //g_message("selected: %s\n", type.name.c_str()); + // g_message("selected: %s\n", type.name.c_str()); extension = type.extension; #if WITH_GTKMM_3_0 @@ -1192,7 +1142,7 @@ void FileSaveDialogImplGtk::addFileType(Glib::ustring name, Glib::ustring patter fileTypeComboBox.set_active(0); - fileTypeChangedCallback(); //call at least once to set the filter + fileTypeChangedCallback(); // call at least once to set the filter } void FileSaveDialogImplGtk::createFileTypeMenu() @@ -1202,20 +1152,20 @@ void FileSaveDialogImplGtk::createFileTypeMenu() knownExtensions.clear(); for (Inkscape::Extension::DB::OutputList::iterator current_item = extension_list.begin(); - current_item != extension_list.end(); ++current_item) - { - Inkscape::Extension::Output * omod = *current_item; + current_item != extension_list.end(); ++current_item) { + Inkscape::Extension::Output *omod = *current_item; // FIXME: would be nice to grey them out instead of not listing them - if (omod->deactivated()) continue; + if (omod->deactivated()) + continue; FileType type; - type.name = (_(omod->get_filetypename())); - type.pattern = "*"; + type.name = (_(omod->get_filetypename())); + type.pattern = "*"; Glib::ustring extension = omod->get_extension(); - knownExtensions.insert( extension.casefold() ); - fileDialogExtensionToPattern (type.pattern, extension); - type.extension= omod; + knownExtensions.insert(extension.casefold()); + fileDialogExtensionToPattern(type.pattern, extension); + type.extension = omod; fileTypeComboBox.append(type.name); fileTypes.push_back(type); } @@ -1230,23 +1180,20 @@ void FileSaveDialogImplGtk::createFileTypeMenu() fileTypeComboBox.set_active(0); - fileTypeChangedCallback(); //call at least once to set the filter + fileTypeChangedCallback(); // call at least once to set the filter } - - /** * Show this dialog modally. Return true if user hits [OK] */ -bool -FileSaveDialogImplGtk::show() +bool FileSaveDialogImplGtk::show() { change_path(myFilename); - set_modal (TRUE); //Window - sp_transientize(GTK_WIDGET(gobj())); //Make transient - gint b = run(); //Dialog + set_modal(TRUE); // Window + sp_transientize(GTK_WIDGET(gobj())); // Make transient + gint b = run(); // Dialog svgPreview.showNoPreview(); set_preview_widget_active(false); hide(); @@ -1254,7 +1201,7 @@ FileSaveDialogImplGtk::show() if (b == Gtk::RESPONSE_OK) { updateNameAndExtension(); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - + // Store changes of the "Append filename automatically" checkbox back to preferences. if (save_method == Inkscape::Extension::FILE_SAVE_METHOD_SAVE_COPY) { prefs->setBool("/dialogs/save_copy/append_extension", fileTypeCheckbox.get_active()); @@ -1262,14 +1209,14 @@ FileSaveDialogImplGtk::show() prefs->setBool("/dialogs/save_as/append_extension", fileTypeCheckbox.get_active()); } - Inkscape::Extension::store_file_extension_in_prefs ((extension != NULL ? extension->get_id() : "" ), save_method); + Inkscape::Extension::store_file_extension_in_prefs((extension != NULL ? extension->get_id() : ""), save_method); - cleanup( true ); + cleanup(true); - return TRUE; + return true; } else { - cleanup( false ); - return FALSE; + cleanup(false); + return false; } } @@ -1277,23 +1224,22 @@ FileSaveDialogImplGtk::show() /** * Get the file extension type that was selected by the user. Valid after an [OK] */ -Inkscape::Extension::Extension * -FileSaveDialogImplGtk::getSelectionType() +Inkscape::Extension::Extension *FileSaveDialogImplGtk::getSelectionType() { return extension; } -void FileSaveDialogImplGtk::setSelectionType( Inkscape::Extension::Extension * key ) +void FileSaveDialogImplGtk::setSelectionType(Inkscape::Extension::Extension *key) { // If no pointer to extension is passed in, look up based on filename extension. - if ( !key ) { + if (!key) { // Not quite UTF-8 here. gchar *filenameLower = g_ascii_strdown(myFilename.c_str(), -1); - for ( int i = 0; !key && (i < (int)fileTypes.size()); i++ ) { - Inkscape::Extension::Output *ext = dynamic_cast(fileTypes[i].extension); - if ( ext && ext->get_extension() ) { - gchar *extensionLower = g_ascii_strdown( ext->get_extension(), -1 ); - if ( g_str_has_suffix(filenameLower, extensionLower) ) { + for (int i = 0; !key && (i < (int)fileTypes.size()); i++) { + Inkscape::Extension::Output *ext = dynamic_cast(fileTypes[i].extension); + if (ext && ext->get_extension()) { + gchar *extensionLower = g_ascii_strdown(ext->get_extension(), -1); + if (g_str_has_suffix(filenameLower, extensionLower)) { key = fileTypes[i].extension; } g_free(extensionLower); @@ -1303,17 +1249,17 @@ void FileSaveDialogImplGtk::setSelectionType( Inkscape::Extension::Extension * k } // Ensure the proper entry in the combo box is selected. - if ( key ) { + if (key) { extension = key; - gchar const * extensionID = extension->get_id(); - if ( extensionID ) { - for ( int i = 0; i < (int)fileTypes.size(); i++ ) { + gchar const *extensionID = extension->get_id(); + if (extensionID) { + for (int i = 0; i < (int)fileTypes.size(); i++) { Inkscape::Extension::Extension *ext = fileTypes[i].extension; - if ( ext ) { - gchar const * id = ext->get_id(); - if ( id && ( strcmp(extensionID, id) == 0) ) { + if (ext) { + gchar const *id = ext->get_id(); + if (id && (strcmp(extensionID, id) == 0)) { int oldSel = fileTypeComboBox.get_active_row_number(); - if ( i != oldSel ) { + if (i != oldSel) { fileTypeComboBox.set_active(i); } break; @@ -1339,32 +1285,34 @@ FileSaveDialogImplGtk::change_title(const Glib::ustring& title) /** * Change the default save path location. */ -void -FileSaveDialogImplGtk::change_path(const Glib::ustring& path) +void FileSaveDialogImplGtk::change_path(const Glib::ustring &path) { myFilename = path; if (Glib::file_test(myFilename, Glib::FILE_TEST_IS_DIR)) { - //fprintf(stderr,"set_current_folder(%s)\n",myFilename.c_str()); + // fprintf(stderr,"set_current_folder(%s)\n",myFilename.c_str()); set_current_folder(myFilename); } else { - //fprintf(stderr,"set_filename(%s)\n",myFilename.c_str()); - if ( Glib::file_test( myFilename, Glib::FILE_TEST_EXISTS ) ) { + // fprintf(stderr,"set_filename(%s)\n",myFilename.c_str()); + if (Glib::file_test(myFilename, Glib::FILE_TEST_EXISTS)) { set_filename(myFilename); } else { - std::string dirName = Glib::path_get_dirname( myFilename ); - if ( dirName != get_current_folder() ) { + std::string dirName = Glib::path_get_dirname(myFilename); + if (dirName != get_current_folder()) { set_current_folder(dirName); } } Glib::ustring basename = Glib::path_get_basename(myFilename); - //fprintf(stderr,"set_current_name(%s)\n",basename.c_str()); - try { - set_current_name( Glib::filename_to_utf8(basename) ); - } catch ( Glib::ConvertError& e ) { - g_warning( "Error converting save filename to UTF-8." ); + // fprintf(stderr,"set_current_name(%s)\n",basename.c_str()); + try + { + set_current_name(Glib::filename_to_utf8(basename)); + } + catch (Glib::ConvertError &e) + { + g_warning("Error converting save filename to UTF-8."); // try a fallback. - set_current_name( basename ); + set_current_name(basename); } } } @@ -1374,16 +1322,16 @@ void FileSaveDialogImplGtk::updateNameAndExtension() // Pick up any changes the user has typed in. Glib::ustring tmp = get_filename(); #ifdef WITH_GNOME_VFS - if ( tmp.empty() && gnome_vfs_initialized() ) { + if (tmp.empty() && gnome_vfs_initialized()) { tmp = get_uri(); } #endif - if ( !tmp.empty() ) { + if (!tmp.empty()) { myFilename = tmp; } - Inkscape::Extension::Output* newOut = extension ? dynamic_cast(extension) : 0; - if ( fileTypeCheckbox.get_active() && newOut ) { + Inkscape::Extension::Output *newOut = extension ? dynamic_cast(extension) : 0; + if (fileTypeCheckbox.get_active() && newOut) { // Append the file extension if it's not already present and display it in the file name entry field appendExtension(myFilename, newOut); change_path(myFilename); @@ -1406,27 +1354,27 @@ void FileExportDialogImpl::fileNameEntryChangedCallback() return; Glib::ustring fileName = fileNameEntry->get_text(); - if (!Glib::get_charset()) //If we are not utf8 + if (!Glib::get_charset()) // If we are not utf8 fileName = Glib::filename_to_utf8(fileName); - //g_message("User hit return. Text is '%s'\n", fileName.c_str()); + // g_message("User hit return. Text is '%s'\n", fileName.c_str()); if (!Glib::path_is_absolute(fileName)) { - //try appending to the current path + // try appending to the current path // not this way: fileName = get_current_folder() + "/" + fileName; std::vector pathSegments; - pathSegments.push_back( get_current_folder() ); - pathSegments.push_back( fileName ); + pathSegments.push_back(get_current_folder()); + pathSegments.push_back(fileName); fileName = Glib::build_filename(pathSegments); } - //g_message("path:'%s'\n", fileName.c_str()); + // g_message("path:'%s'\n", fileName.c_str()); if (Glib::file_test(fileName, Glib::FILE_TEST_IS_DIR)) { set_current_folder(fileName); - } else if (/*Glib::file_test(fileName, Glib::FILE_TEST_IS_REGULAR)*/1) { - //dialog with either (1) select a regular file or (2) cd to dir - //simulate an 'OK' + } else if (/*Glib::file_test(fileName, Glib::FILE_TEST_IS_REGULAR)*/ 1) { + // dialog with either (1) select a regular file or (2) cd to dir + // simulate an 'OK' set_filename(fileName); response(Gtk::RESPONSE_OK); } @@ -1440,10 +1388,11 @@ void FileExportDialogImpl::fileNameEntryChangedCallback() void FileExportDialogImpl::fileTypeChangedCallback() { int sel = fileTypeComboBox.get_active_row_number(); - if (sel<0 || sel >= (int)fileTypes.size()) + if ((sel < 0) || (sel >= (int)fileTypes.size())) return; + FileType type = fileTypes[sel]; - //g_message("selected: %s\n", type.name.c_str()); + // g_message("selected: %s\n", type.name.c_str()); Gtk::FileFilter filter; filter.add_pattern(type.pattern); set_filter(filter); @@ -1457,19 +1406,19 @@ void FileExportDialogImpl::createFileTypeMenu() Inkscape::Extension::db.get_output_list(extension_list); for (Inkscape::Extension::DB::OutputList::iterator current_item = extension_list.begin(); - current_item != extension_list.end(); ++current_item) - { - Inkscape::Extension::Output * omod = *current_item; + current_item != extension_list.end(); ++current_item) { + Inkscape::Extension::Output *omod = *current_item; // FIXME: would be nice to grey them out instead of not listing them - if (omod->deactivated()) continue; + if (omod->deactivated()) + continue; FileType type; - type.name = (_(omod->get_filetypename())); - type.pattern = "*"; + type.name = (_(omod->get_filetypename())); + type.pattern = "*"; Glib::ustring extension = omod->get_extension(); - fileDialogExtensionToPattern (type.pattern, extension); - type.extension= omod; + fileDialogExtensionToPattern(type.pattern, extension); + type.extension = omod; fileTypeComboBox.append_text(type.name); fileTypes.push_back(type); } @@ -1484,28 +1433,26 @@ void FileExportDialogImpl::createFileTypeMenu() fileTypeComboBox.set_active(0); - fileTypeChangedCallback(); //call at least once to set the filter + fileTypeChangedCallback(); // call at least once to set the filter } /** * Constructor */ -FileExportDialogImpl::FileExportDialogImpl( Gtk::Window& parentWindow, - const Glib::ustring &dir, - FileDialogType fileTypes, - const Glib::ustring &title, - const Glib::ustring &/*default_key*/ ) : - FileDialogBaseGtk(parentWindow, title, Gtk::FILE_CHOOSER_ACTION_SAVE, fileTypes, "/dialogs/export"), - sourceX0Spinner("X0", _("Left edge of source")), - sourceY0Spinner("Y0", _("Top edge of source")), - sourceX1Spinner("X1", _("Right edge of source")), - sourceY1Spinner("Y1", _("Bottom edge of source")), - sourceWidthSpinner("Width", _("Source width")), - sourceHeightSpinner("Height", _("Source height")), - destWidthSpinner("Width", _("Destination width")), - destHeightSpinner("Height", _("Destination height")), - destDPISpinner("DPI", _("Resolution (dots per inch)")) +FileExportDialogImpl::FileExportDialogImpl(Gtk::Window &parentWindow, const Glib::ustring &dir, + FileDialogType fileTypes, const Glib::ustring &title, + const Glib::ustring & /*default_key*/) + : FileDialogBaseGtk(parentWindow, title, Gtk::FILE_CHOOSER_ACTION_SAVE, fileTypes, "/dialogs/export") + , sourceX0Spinner("X0", _("Left edge of source")) + , sourceY0Spinner("Y0", _("Top edge of source")) + , sourceX1Spinner("X1", _("Right edge of source")) + , sourceY1Spinner("Y1", _("Bottom edge of source")) + , sourceWidthSpinner("Width", _("Source width")) + , sourceHeightSpinner("Height", _("Source height")) + , destWidthSpinner("Width", _("Destination width")) + , destHeightSpinner("Height", _("Destination height")) + , destDPISpinner("DPI", _("Resolution (dots per inch)")) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); append_extension = prefs->getBool("/dialogs/save_export/append_extension", true); @@ -1528,15 +1475,15 @@ FileExportDialogImpl::FileExportDialogImpl( Gtk::Window& parentWindow, _dialogType = fileTypes; /* Set the pwd and/or the filename */ - if (dir.size()>0) - { + if (dir.size() > 0) { Glib::ustring udir(dir); Glib::ustring::size_type len = udir.length(); // leaving a trailing backslash on the directory name leads to the infamous // double-directory bug on win32 - if (len != 0 && udir[len - 1] == '\\') udir.erase(len - 1); + if ((len != 0) && (udir[len - 1] == '\\')) + udir.erase(len - 1); set_current_folder(udir.c_str()); - } + } //######################################### //## EXTRA WIDGET -- SOURCE SIDE @@ -1563,16 +1510,16 @@ FileExportDialogImpl::FileExportDialogImpl( Gtk::Window& parentWindow, - //dimension buttons - sourceTable.resize(3,3); - sourceTable.attach(sourceX0Spinner, 0,1,0,1); - sourceTable.attach(sourceY0Spinner, 1,2,0,1); + // dimension buttons + sourceTable.resize(3, 3); + sourceTable.attach(sourceX0Spinner, 0, 1, 0, 1); + sourceTable.attach(sourceY0Spinner, 1, 2, 0, 1); sourceUnitsSpinner.setUnitType(UNIT_TYPE_LINEAR); - sourceTable.attach(sourceUnitsSpinner, 2,3,0,1); - sourceTable.attach(sourceX1Spinner, 0,1,1,2); - sourceTable.attach(sourceY1Spinner, 1,2,1,2); - sourceTable.attach(sourceWidthSpinner, 0,1,2,3); - sourceTable.attach(sourceHeightSpinner, 1,2,2,3); + sourceTable.attach(sourceUnitsSpinner, 2, 3, 0, 1); + sourceTable.attach(sourceX1Spinner, 0, 1, 1, 2); + sourceTable.attach(sourceY1Spinner, 1, 2, 1, 2); + sourceTable.attach(sourceWidthSpinner, 0, 1, 2, 3); + sourceTable.attach(sourceHeightSpinner, 1, 2, 2, 3); sourceBox.pack_start(sourceTable); sourceFrame.set_label(_("Source")); @@ -1585,12 +1532,12 @@ FileExportDialogImpl::FileExportDialogImpl( Gtk::Window& parentWindow, //######################################### - destTable.resize(3,3); - destTable.attach(destWidthSpinner, 0,1,0,1); - destTable.attach(destHeightSpinner, 1,2,0,1); + destTable.resize(3, 3); + destTable.attach(destWidthSpinner, 0, 1, 0, 1); + destTable.attach(destHeightSpinner, 1, 2, 0, 1); destUnitsSpinner.setUnitType(UNIT_TYPE_LINEAR); - destTable.attach(destUnitsSpinner, 2,3,0,1); - destTable.attach(destDPISpinner, 0,1,1,2); + destTable.attach(destUnitsSpinner, 2, 3, 0, 1); + destTable.attach(destDPISpinner, 0, 1, 1, 2); destBox.pack_start(destTable); @@ -1608,8 +1555,6 @@ FileExportDialogImpl::FileExportDialogImpl( Gtk::Window& parentWindow, - - //###### File options //###### Do we want the .xxx extension automatically added? fileTypeCheckbox.set_label(Glib::ustring(_("Append filename extension automatically"))); @@ -1618,9 +1563,8 @@ FileExportDialogImpl::FileExportDialogImpl( Gtk::Window& parentWindow, //###### File type menu createFileTypeMenu(); - fileTypeComboBox.set_size_request(200,40); - fileTypeComboBox.signal_changed().connect( - sigc::mem_fun(*this, &FileExportDialogImpl::fileTypeChangedCallback) ); + fileTypeComboBox.set_size_request(200, 40); + fileTypeComboBox.signal_changed().connect(sigc::mem_fun(*this, &FileExportDialogImpl::fileTypeChangedCallback)); destBox.pack_start(fileTypeComboBox); @@ -1636,38 +1580,35 @@ FileExportDialogImpl::FileExportDialogImpl( Gtk::Window& parentWindow, - - //Let's do some customization + // Let's do some customization fileNameEntry = NULL; Gtk::Container *cont = get_toplevel(); std::vector entries; findEntryWidgets(cont, entries); - //g_message("Found %d entry widgets\n", entries.size()); - if (!entries.empty()) - { - //Catch when user hits [return] on the text field + // g_message("Found %d entry widgets\n", entries.size()); + if (!entries.empty()) { + // Catch when user hits [return] on the text field fileNameEntry = entries[0]; fileNameEntry->signal_activate().connect( - sigc::mem_fun(*this, &FileExportDialogImpl::fileNameEntryChangedCallback) ); - } + sigc::mem_fun(*this, &FileExportDialogImpl::fileNameEntryChangedCallback)); + } - //Let's do more customization + // Let's do more customization std::vector expanders; findExpanderWidgets(cont, expanders); - //g_message("Found %d expander widgets\n", expanders.size()); - if (!expanders.empty()) - { - //Always show the file list + // g_message("Found %d expander widgets\n", expanders.size()); + if (!expanders.empty()) { + // Always show the file list Gtk::Expander *expander = expanders[0]; expander->set_expanded(true); - } + } - //if (extension == NULL) + // if (extension == NULL) // checkbox.set_sensitive(FALSE); add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); - set_default(*add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK)); + set_default(*add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK)); show_all_children(); } @@ -1684,30 +1625,28 @@ FileExportDialogImpl::~FileExportDialogImpl() /** * Show this dialog modally. Return true if user hits [OK] */ -bool -FileExportDialogImpl::show() +bool FileExportDialogImpl::show() { - Glib::ustring s = Glib::filename_to_utf8 (get_current_folder()); - if (s.length() == 0) - s = getcwd (NULL, 0); - set_current_folder(Glib::filename_from_utf8(s)); //hack to force initial dir listing - set_modal (TRUE); //Window - sp_transientize(GTK_WIDGET(gobj())); //Make transient - gint b = run(); //Dialog + Glib::ustring s = Glib::filename_to_utf8(get_current_folder()); + if (s.length() == 0) { + s = getcwd(NULL, 0); + } + set_current_folder(Glib::filename_from_utf8(s)); // hack to force initial dir listing + set_modal(TRUE); // Window + sp_transientize(GTK_WIDGET(gobj())); // Make transient + gint b = run(); // Dialog svgPreview.showNoPreview(); hide(); - if (b == Gtk::RESPONSE_OK) - { - int sel = fileTypeComboBox.get_active_row_number (); - if (sel>=0 && sel< (int)fileTypes.size()) - { + if (b == Gtk::RESPONSE_OK) { + int sel = fileTypeComboBox.get_active_row_number(); + if (sel >= 0 && sel < (int)fileTypes.size()) { FileType &type = fileTypes[sel]; extension = type.extension; - } + } myFilename = get_filename(); #ifdef WITH_GNOME_VFS - if ( myFilename.empty() && gnome_vfs_initialized() ) { + if (myFilename.empty() && gnome_vfs_initialized()) { myFilename = get_uri(); } #endif @@ -1721,20 +1660,17 @@ FileExportDialogImpl::show() prefs->setBool("/dialogs/save_export/append_extension", append_extension); prefs->setBool("/dialogs/save_export/default", ( extension != NULL ? extension->get_id() : "" )); */ - return TRUE; - } - else - { - return FALSE; - } + return true; + } else { + return false; + } } /** * Get the file extension type that was selected by the user. Valid after an [OK] */ -Inkscape::Extension::Extension * -FileExportDialogImpl::getSelectionType() +Inkscape::Extension::Extension *FileExportDialogImpl::getSelectionType() { return extension; } @@ -1743,8 +1679,7 @@ FileExportDialogImpl::getSelectionType() /** * Get the file name chosen by the user. Valid after an [OK] */ -Glib::ustring -FileExportDialogImpl::getFilename() +Glib::ustring FileExportDialogImpl::getFilename() { return myFilename; } @@ -1752,9 +1687,9 @@ FileExportDialogImpl::getFilename() #endif // NEW_EXPORT_DIALOG -} //namespace Dialog -} //namespace UI -} //namespace Inkscape +} // namespace Dialog +} // namespace UI +} // namespace Inkscape /* Local Variables: -- cgit v1.2.3 From 08692dea2a2b45f0358a70db8e7d08fd73c6e3e4 Mon Sep 17 00:00:00 2001 From: Alex Valavanis Date: Mon, 31 Mar 2014 11:10:00 +0100 Subject: Fix Gtkmm 3.8 build issues on systems with Gtk+ 3.10 (bzr r13242) --- src/ui/dialog/document-properties.cpp | 12 ++++++------ src/ui/dialog/livepatheffect-editor.cpp | 8 ++++---- src/ui/dialog/polar-arrange-tab.h | 3 +-- 3 files changed, 11 insertions(+), 12 deletions(-) (limited to 'src/ui') diff --git a/src/ui/dialog/document-properties.cpp b/src/ui/dialog/document-properties.cpp index 508fc52b1..67e788e21 100644 --- a/src/ui/dialog/document-properties.cpp +++ b/src/ui/dialog/document-properties.cpp @@ -613,7 +613,7 @@ void DocumentProperties::build_cms() label_avail->set_markup (_("Available Color Profiles:")); _link_btn.set_tooltip_text(_("Link Profile")); -#if GTK_CHECK_VERSION(3,10,0) +#if WITH_GTKMM_3_10 _link_btn.set_image_from_icon_name(INKSCAPE_ICON("list-add"), Gtk::ICON_SIZE_SMALL_TOOLBAR); #else Gtk::Image *image_link = Gtk::manage(new Gtk::Image()); @@ -622,7 +622,7 @@ void DocumentProperties::build_cms() #endif _unlink_btn.set_tooltip_text(_("Unlink Profile")); -#if GTK_CHECK_VERSION(3,10,0) +#if WITH_GTKMM_3_10 _unlink_btn.set_image_from_icon_name(INKSCAPE_ICON("list-remove"), Gtk::ICON_SIZE_SMALL_TOOLBAR); #else Gtk::Image *image_unlink = Gtk::manage(new Gtk::Image()); @@ -750,7 +750,7 @@ void DocumentProperties::build_scripting() label_external->set_markup (_("External script files:")); _external_add_btn.set_tooltip_text(_("Add the current file name or browse for a file")); -#if GTK_CHECK_VERSION(3,10,0) +#if WITH_GTKMM_3_10 _external_add_btn.set_image_from_icon_name(INKSCAPE_ICON("list-add"), Gtk::ICON_SIZE_SMALL_TOOLBAR); #else Gtk::Image *image_ext_add = Gtk::manage(new Gtk::Image()); @@ -759,7 +759,7 @@ void DocumentProperties::build_scripting() #endif _external_remove_btn.set_tooltip_text(_("Remove")); -#if GTK_CHECK_VERSION(3,10,0) +#if WITH_GTKMM_3_10 _external_remove_btn.set_image_from_icon_name(INKSCAPE_ICON("list-remove"), Gtk::ICON_SIZE_SMALL_TOOLBAR); #else Gtk::Image *image_ext_rm = Gtk::manage(new Gtk::Image()); @@ -839,7 +839,7 @@ void DocumentProperties::build_scripting() label_embedded->set_markup (_("Embedded script files:")); _embed_new_btn.set_tooltip_text(_("New")); -#if GTK_CHECK_VERSION(3,10,0) +#if WITH_GTKMM_3_10 _embed_new_btn.set_image_from_icon_name(INKSCAPE_ICON("list-add"), Gtk::ICON_SIZE_SMALL_TOOLBAR); #else Gtk::Image *image_embed_new = Gtk::manage(new Gtk::Image()); @@ -848,7 +848,7 @@ void DocumentProperties::build_scripting() #endif _embed_remove_btn.set_tooltip_text(_("Remove")); -#if GTK_CHECK_VERSION(3,10,0) +#if WITH_GTKMM_3_10 _embed_remove_btn.set_image_from_icon_name(INKSCAPE_ICON("list-remove"), Gtk::ICON_SIZE_SMALL_TOOLBAR); #else Gtk::Image *image_embed_rm = Gtk::manage(new Gtk::Image()); diff --git a/src/ui/dialog/livepatheffect-editor.cpp b/src/ui/dialog/livepatheffect-editor.cpp index 0ab2fc9f7..9a569725c 100644 --- a/src/ui/dialog/livepatheffect-editor.cpp +++ b/src/ui/dialog/livepatheffect-editor.cpp @@ -107,7 +107,7 @@ LivePathEffectEditor::LivePathEffectEditor() effectcontrol_frame.add(effectcontrol_vbox); button_add.set_tooltip_text(_("Add path effect")); -#if GTK_CHECK_VERSION(3,10,0) +#if WITH_GTKMM_3_10 button_add.set_image_from_icon_name(INKSCAPE_ICON("list-add"), Gtk::ICON_SIZE_SMALL_TOOLBAR); #else Gtk::Image *image_add = Gtk::manage(new Gtk::Image()); @@ -117,7 +117,7 @@ LivePathEffectEditor::LivePathEffectEditor() button_add.set_relief(Gtk::RELIEF_NONE); button_remove.set_tooltip_text(_("Delete current path effect")); -#if GTK_CHECK_VERSION(3,10,0) +#if WITH_GTKMM_3_10 button_remove.set_image_from_icon_name(INKSCAPE_ICON("list-remove"), Gtk::ICON_SIZE_SMALL_TOOLBAR); #else Gtk::Image *image_remove = Gtk::manage(new Gtk::Image()); @@ -127,7 +127,7 @@ LivePathEffectEditor::LivePathEffectEditor() button_remove.set_relief(Gtk::RELIEF_NONE); button_up.set_tooltip_text(_("Raise the current path effect")); -#if GTK_CHECK_VERSION(3,10,0) +#if WITH_GTKMM_3_10 button_up.set_image_from_icon_name(INKSCAPE_ICON("go-up"), Gtk::ICON_SIZE_SMALL_TOOLBAR); #else Gtk::Image *image_up = Gtk::manage(new Gtk::Image()); @@ -137,7 +137,7 @@ LivePathEffectEditor::LivePathEffectEditor() button_up.set_relief(Gtk::RELIEF_NONE); button_down.set_tooltip_text(_("Lower the current path effect")); -#if GTK_CHECK_VERSION(3,10,0) +#if WITH_GTKMM_3_10 button_down.set_image_from_icon_name(INKSCAPE_ICON("go-down"), Gtk::ICON_SIZE_SMALL_TOOLBAR); #else Gtk::Image *image_down = Gtk::manage(new Gtk::Image()); diff --git a/src/ui/dialog/polar-arrange-tab.h b/src/ui/dialog/polar-arrange-tab.h index bfed40bbd..f6c3b2906 100644 --- a/src/ui/dialog/polar-arrange-tab.h +++ b/src/ui/dialog/polar-arrange-tab.h @@ -10,9 +10,8 @@ #ifndef INKSCAPE_UI_DIALOG_POLAR_ARRANGE_TAB_H #define INKSCAPE_UI_DIALOG_POLAR_ARRANGE_TAB_H -#include "ui/dialog/arrange-tab.h" - #include "ui/widget/anchor-selector.h" +#include "ui/dialog/arrange-tab.h" #include "ui/widget/scalar-unit.h" namespace Inkscape { -- cgit v1.2.3 From 24335d0da5da0df3e7ee0f235d04e57807c97a69 Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Mon, 31 Mar 2014 22:55:53 +0200 Subject: fix windows build (bzr r13245) --- src/ui/dialog/pixelartdialog.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/ui') diff --git a/src/ui/dialog/pixelartdialog.cpp b/src/ui/dialog/pixelartdialog.cpp index 31449d4e7..2d25f54d7 100644 --- a/src/ui/dialog/pixelartdialog.cpp +++ b/src/ui/dialog/pixelartdialog.cpp @@ -410,8 +410,8 @@ void PixelArtDialogImpl::vectorize() lastOptions = options(); g_atomic_int_set(&abortThread, false); - thread = Glib::Thread::create( - sigc::mem_fun(*this, &PixelArtDialogImpl::workerThread) ); + thread = Glib::Thread::create(sigc::mem_fun(*this, &PixelArtDialogImpl::workerThread), + /*joinable =*/true); } void PixelArtDialogImpl::processLibdepixelize(const Input &input) -- cgit v1.2.3