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') 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') 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') 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') 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') 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') 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') 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') 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') 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') 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') 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') 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') 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/desktop.cpp | 2 +- src/menus-skeleton.h | 2 +- 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 +------- src/verbs.cpp | 8 +- src/verbs.h | 2 +- 12 files changed, 1298 insertions(+), 1091 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') diff --git a/src/desktop.cpp b/src/desktop.cpp index 7aabb1245..f7a060670 100644 --- a/src/desktop.cpp +++ b/src/desktop.cpp @@ -1827,7 +1827,7 @@ SPDesktop::show_dialogs() mapVerbPreference.insert(std::make_pair ((int)SP_VERB_DIALOG_SVG_FONTS, "/dialogs/svgfonts") ); mapVerbPreference.insert(std::make_pair ((int)SP_VERB_DIALOG_INPUT, "/dialogs/inputdevices") ); mapVerbPreference.insert(std::make_pair ((int)SP_VERB_DIALOG_DISPLAY, "/dialogs/preferences") ); - mapVerbPreference.insert(std::make_pair ((int)SP_VERB_SELECTION_GRIDTILE, "/dialogs/gridtiler") ); + mapVerbPreference.insert(std::make_pair ((int)SP_VERB_SELECTION_ARRANGE, "/dialogs/gridtiler") ); //FIXME: denis: change also preferences? mapVerbPreference.insert(std::make_pair ((int)SP_VERB_SELECTION_TRACE, "/dialogs/trace") ); mapVerbPreference.insert(std::make_pair ((int)SP_VERB_DIALOG_TEXT, "/dialogs/textandfont") ); mapVerbPreference.insert(std::make_pair ((int)SP_VERB_DIALOG_EXPORT, "/dialogs/export") ); diff --git a/src/menus-skeleton.h b/src/menus-skeleton.h index 84ecc83ea..459b3d378 100644 --- a/src/menus-skeleton.h +++ b/src/menus-skeleton.h @@ -210,7 +210,7 @@ static char const menus_skeleton[] = " \n" " \n" " \n" -" \n" +" \n" " \n" " \n" " \n" 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 diff --git a/src/verbs.cpp b/src/verbs.cpp index 1b57ad4ff..5d5414213 100644 --- a/src/verbs.cpp +++ b/src/verbs.cpp @@ -1127,9 +1127,9 @@ void SelectionVerb::perform(SPAction *action, void *data) case SP_VERB_SELECTION_BREAK_APART: sp_selected_path_break_apart(dt); break; - case SP_VERB_SELECTION_GRIDTILE: + case SP_VERB_SELECTION_ARRANGE: inkscape_dialogs_unhide(); - dt->_dlg_mgr->showDialog("TileDialog"); + dt->_dlg_mgr->showDialog("TileDialog"); //FIXME: denis: What's this string (to be changed) break; default: break; @@ -2412,8 +2412,8 @@ Verb *Verb::_base_verbs[] = { // Advanced tutorial for more info new SelectionVerb(SP_VERB_SELECTION_BREAK_APART, "SelectionBreakApart", N_("Break _Apart"), N_("Break selected paths into subpaths"), INKSCAPE_ICON("path-break-apart")), - new SelectionVerb(SP_VERB_SELECTION_GRIDTILE, "DialogGridArrange", N_("Ro_ws and Columns..."), - N_("Arrange selected objects in a table"), INKSCAPE_ICON("dialog-rows-and-columns")), + new SelectionVerb(SP_VERB_SELECTION_ARRANGE, "DialogArrange", N_("_Arrange..."), + N_("Arrange selected objects in a table or circle"), INKSCAPE_ICON("dialog-rows-and-columns")), // Layer new LayerVerb(SP_VERB_LAYER_NEW, "LayerNew", N_("_Add Layer..."), N_("Create a new layer"), INKSCAPE_ICON("layer-new")), diff --git a/src/verbs.h b/src/verbs.h index 1a9efdb81..b666ec92b 100644 --- a/src/verbs.h +++ b/src/verbs.h @@ -130,7 +130,7 @@ enum { SP_VERB_SELECTION_CREATE_BITMAP, SP_VERB_SELECTION_COMBINE, SP_VERB_SELECTION_BREAK_APART, - SP_VERB_SELECTION_GRIDTILE, + SP_VERB_SELECTION_ARRANGE, // Former SP_VERB_SELECTION_GRIDTILE /* Layer */ SP_VERB_LAYER_NEW, SP_VERB_LAYER_RENAME, -- 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') 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') 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') 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') 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') 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') 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') 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') 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') 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') 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') 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') 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') 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') 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 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/desktop.cpp | 60 ++++++++++++++++++------------------- 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 ++-- 6 files changed, 44 insertions(+), 45 deletions(-) (limited to 'src') diff --git a/src/desktop.cpp b/src/desktop.cpp index b010d6e59..22c00d4f1 100644 --- a/src/desktop.cpp +++ b/src/desktop.cpp @@ -1852,36 +1852,36 @@ SPDesktop::show_dialogs() * Get each dialogs previous state from preferences and reopen on startup if needed, without grabbing focus (canvas retains focus). * Map dialog manager's dialog IDs to dialog last visible state preference. FIXME: store this correspondence in dialogs themselves! */ - std::map mapVerbPreference; - std::map::const_iterator iter; - mapVerbPreference.insert(std::make_pair ((int)SP_VERB_DIALOG_LAYERS, "/dialogs/layers") ); - mapVerbPreference.insert(std::make_pair ((int)SP_VERB_DIALOG_FILL_STROKE, "/dialogs/fillstroke") ); - mapVerbPreference.insert(std::make_pair ((int)SP_VERB_DIALOG_EXTENSIONEDITOR, "/dialogs/extensioneditor") ); - mapVerbPreference.insert(std::make_pair ((int)SP_VERB_DIALOG_ALIGN_DISTRIBUTE, "/dialogs/align") ); - mapVerbPreference.insert(std::make_pair ((int)SP_VERB_DIALOG_METADATA, "/dialogs/documentmetadata") ); - mapVerbPreference.insert(std::make_pair ((int)SP_VERB_DIALOG_NAMEDVIEW, "/dialogs/documentoptions") ); - mapVerbPreference.insert(std::make_pair ((int)SP_VERB_DIALOG_FILTER_EFFECTS, "/dialogs/filtereffects") ); - mapVerbPreference.insert(std::make_pair ((int)SP_VERB_DIALOG_FIND, "/dialogs/find") ); - mapVerbPreference.insert(std::make_pair ((int)SP_VERB_DIALOG_GLYPHS, "/dialogs/glyphs") ); - mapVerbPreference.insert(std::make_pair ((int)SP_VERB_DIALOG_DEBUG, "/dialogs/messages") ); - mapVerbPreference.insert(std::make_pair ((int)SP_VERB_HELP_MEMORY, "/dialogs/memory") ); - mapVerbPreference.insert(std::make_pair ((int)SP_VERB_DIALOG_LIVE_PATH_EFFECT, "/dialogs/livepatheffect") ); - mapVerbPreference.insert(std::make_pair ((int)SP_VERB_DIALOG_UNDO_HISTORY, "/dialogs/undo-history") ); - mapVerbPreference.insert(std::make_pair ((int)SP_VERB_DIALOG_TRANSFORM, "/dialogs/transformation") ); - mapVerbPreference.insert(std::make_pair ((int)SP_VERB_DIALOG_SWATCHES, "/dialogs/swatches") ); - mapVerbPreference.insert(std::make_pair ((int)SP_VERB_VIEW_ICON_PREVIEW, "/dialogs/iconpreview") ); - mapVerbPreference.insert(std::make_pair ((int)SP_VERB_DIALOG_SVG_FONTS, "/dialogs/svgfonts") ); - mapVerbPreference.insert(std::make_pair ((int)SP_VERB_DIALOG_INPUT, "/dialogs/inputdevices") ); - mapVerbPreference.insert(std::make_pair ((int)SP_VERB_DIALOG_DISPLAY, "/dialogs/preferences") ); - mapVerbPreference.insert(std::make_pair ((int)SP_VERB_SELECTION_ARRANGE, "/dialogs/gridtiler") ); //FIXME: denis: change also preferences? - mapVerbPreference.insert(std::make_pair ((int)SP_VERB_SELECTION_TRACE, "/dialogs/trace") ); - mapVerbPreference.insert(std::make_pair ((int)SP_VERB_DIALOG_TEXT, "/dialogs/textandfont") ); - mapVerbPreference.insert(std::make_pair ((int)SP_VERB_DIALOG_EXPORT, "/dialogs/export") ); - mapVerbPreference.insert(std::make_pair ((int)SP_VERB_DIALOG_XML_EDITOR, "/dialogs/xml") ); - mapVerbPreference.insert(std::make_pair ((int)SP_VERB_DIALOG_FIND, "/dialogs/find") ); - mapVerbPreference.insert(std::make_pair ((int)SP_VERB_DIALOG_CLONETILER, "/dialogs/clonetiler") ); - mapVerbPreference.insert(std::make_pair ((int)SP_VERB_DIALOG_ITEM, "/dialogs/object") ); - mapVerbPreference.insert(std::make_pair ((int)SP_VERB_DIALOG_SPELLCHECK, "/dialogs/spellcheck") ); + std::map mapVerbPreference; + mapVerbPreference.insert(std::make_pair ("LayersPanel", "/dialogs/layers") ); + mapVerbPreference.insert(std::make_pair ("FillAndStroke", "/dialogs/fillstroke") ); + mapVerbPreference.insert(std::make_pair ("ExtensionEditor", "/dialogs/extensioneditor") ); + mapVerbPreference.insert(std::make_pair ("AlignAndDistribute", "/dialogs/align") ); + mapVerbPreference.insert(std::make_pair ("DocumentMetadata", "/dialogs/documentmetadata") ); + mapVerbPreference.insert(std::make_pair ("DocumentProperties", "/dialogs/documentoptions") ); + mapVerbPreference.insert(std::make_pair ("FilterEffectsDialog", "/dialogs/filtereffects") ); + mapVerbPreference.insert(std::make_pair ("Find", "/dialogs/find") ); + mapVerbPreference.insert(std::make_pair ("Glyphs", "/dialogs/glyphs") ); + mapVerbPreference.insert(std::make_pair ("Messages", "/dialogs/messages") ); + mapVerbPreference.insert(std::make_pair ("Memory", "/dialogs/memory") ); + mapVerbPreference.insert(std::make_pair ("LivePathEffect", "/dialogs/livepatheffect") ); + mapVerbPreference.insert(std::make_pair ("UndoHistory", "/dialogs/undo-history") ); + mapVerbPreference.insert(std::make_pair ("Transformation", "/dialogs/transformation") ); + mapVerbPreference.insert(std::make_pair ("Swatches", "/dialogs/swatches") ); + mapVerbPreference.insert(std::make_pair ("IconPreviewPanel", "/dialogs/iconpreview") ); + mapVerbPreference.insert(std::make_pair ("SvgFontsDialog", "/dialogs/svgfonts") ); + mapVerbPreference.insert(std::make_pair ("InputDevices", "/dialogs/inputdevices") ); + mapVerbPreference.insert(std::make_pair ("InkscapePreferences", "/dialogs/preferences") ); + mapVerbPreference.insert(std::make_pair ("TileDialog", "/dialogs/gridtiler") ); + mapVerbPreference.insert(std::make_pair ("Trace", "/dialogs/trace") ); + mapVerbPreference.insert(std::make_pair ("PixelArt", "/dialogs/pixelart") ); + mapVerbPreference.insert(std::make_pair ("TextFont", "/dialogs/textandfont") ); + mapVerbPreference.insert(std::make_pair ("Export", "/dialogs/export") ); + mapVerbPreference.insert(std::make_pair ("XmlTree", "/dialogs/xml") ); + mapVerbPreference.insert(std::make_pair ("CloneTiler", "/dialogs/clonetiler") ); + mapVerbPreference.insert(std::make_pair ("ObjectProperties", "/dialogs/object") ); + mapVerbPreference.insert(std::make_pair ("SpellCheck", "/dialogs/spellcheck") ); + mapVerbPreference.insert(std::make_pair ("Symbols", "/dialogs/symbols") ); for (std::map::const_iterator iter = mapVerbPreference.begin(); iter != mapVerbPreference.end(); ++iter) { Glib::ustring pref = iter->second; 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 75d5e200d382253aaf12c01fdb0c988933d9453c Mon Sep 17 00:00:00 2001 From: David Mathog Date: Thu, 27 Mar 2014 21:34:17 +0100 Subject: Patch for libuemf. ----- Somewhere along the line during the clang patches the version of libUEMF in inkscape acquired changes not in the upstream library. Small patch which puts them back in sync. (bzr r13222) --- src/libuemf/uemf.h | 6 ++++-- src/libuemf/uemf_endian.c | 11 +++-------- src/libuemf/upmf.c | 4 ++-- src/libuemf/uwmf_endian.c | 14 ++++++-------- 4 files changed, 15 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/libuemf/uemf.h b/src/libuemf/uemf.h index a75ba801b..cde1b6c85 100644 --- a/src/libuemf/uemf.h +++ b/src/libuemf/uemf.h @@ -95,8 +95,8 @@ these WMF enumerations is by referencing the following table: /* File: uemf.h -Version: 0.0.25 -Date: 15-JAN-2014 +Version: 0.0.26 +Date: 27-MAR-2014 Author: David Mathog, Biology Division, Caltech email: mathog@caltech.edu Copyright: 2014 David Mathog and California Institute of Technology (Caltech) @@ -129,6 +129,8 @@ extern "C" { #define U_SYSPAL_NOSTATIC 2 #define U_ELF_VENDOR_SIZE 4 + +#define UNUSED_PARAMETER(x) (void)(x) /** \endcond */ // *************************************************************************** diff --git a/src/libuemf/uemf_endian.c b/src/libuemf/uemf_endian.c index 8f2be57da..2d19361e1 100644 --- a/src/libuemf/uemf_endian.c +++ b/src/libuemf/uemf_endian.c @@ -19,8 +19,8 @@ /* File: uemf_endian.c -Version: 0.0.15 -Date: 24-MAR-2014 +Version: 0.0.16 +Date: 27-MAR-2014 Author: David Mathog, Biology Division, Caltech email: mathog@caltech.edu Copyright: 2014 David Mathog and California Institute of Technology (Caltech) @@ -36,10 +36,6 @@ extern "C" { #include "uemf.h" #include "uemf_endian.h" -// Unfortunately, C does not allow unnamed function arguments, so use this macro instead... -#define UNUSED(x) (void)(x) - - // hide almost everuything in here from Doxygen //! \cond @@ -429,8 +425,7 @@ by end user code and to further that end prototypes are NOT provided and they ar // all core*_swap call this, U_EMRSETMARGN_swap and some others all it directly // numbered as core5 to be consistent with uemf.c, but must appear before the others as there is no prototype void core5_swap(char *record, int torev){ - UNUSED(torev); - + UNUSED_PARAMETER(torev); PU_ENHMETARECORD pEMR = (PU_ENHMETARECORD)(record); U_swap4(pEMR,2); // iType nSize } diff --git a/src/libuemf/upmf.c b/src/libuemf/upmf.c index 3c652c9b8..01f7ba3a4 100644 --- a/src/libuemf/upmf.c +++ b/src/libuemf/upmf.c @@ -21,8 +21,8 @@ /* File: upmf.c -Version: 0.0.5 -Date: 24-MAR-2014 +Version: 0.0.6 +Date: 26-MAR-2014 Author: David Mathog, Biology Division, Caltech email: mathog@caltech.edu Copyright: 2014 David Mathog and California Institute of Technology (Caltech) diff --git a/src/libuemf/uwmf_endian.c b/src/libuemf/uwmf_endian.c index 5fbb450dc..38a321ad0 100644 --- a/src/libuemf/uwmf_endian.c +++ b/src/libuemf/uwmf_endian.c @@ -6,11 +6,11 @@ /* File: uwmf_endian.c -Version: 0.1.2 -Date: 18-FEB-2013 +Version: 0.1.3 +Date: 27-MAR-2014 Author: David Mathog, Biology Division, Caltech email: mathog@caltech.edu -Copyright: 2012 David Mathog and California Institute of Technology (Caltech) +Copyright: 2014 David Mathog and California Institute of Technology (Caltech) */ #ifdef __cplusplus @@ -24,8 +24,6 @@ extern "C" { #include "uwmf.h" #include "uwmf_endian.h" -#define UNUSED(x) (void)(x) - // hide almost everything in this file from Doxygen //! \cond /* Prototypes for functions used here and defined in uemf_endian.c, but which are not supposed @@ -284,7 +282,7 @@ by end user code and to further that end prototypes are NOT provided and they ar /* Size16 EVERY record type should call this, directly or indirectly*/ void U_WMRCORE_SIZE16_swap(char *record, int torev){ - UNUSED(torev); + UNUSED_PARAMETER(torev); U_swap4(record, 1); /* Size16_4 is at offset 0 in U_METARECORD */ } @@ -309,7 +307,7 @@ void U_WMRCORE_U16_N16_swap(char *record, int torev){ /* all records that specify palette objects */ void U_WMRCORE_PALETTE_swap(char *record, int torev){ - UNUSED(torev); + UNUSED_PARAMETER(torev); U_WMRCORE_SIZE16_swap(record, torev); palette_swap(record + offsetof(U_WMRANIMATEPALETTE,Palette)); } @@ -702,7 +700,7 @@ void U_WMRDIBCREATEPATTERNBRUSH_swap(char *record, int torev){ } void U_WMRSTRETCHDIB_swap(char *record, int torev){ - UNUSED(torev); + UNUSED_PARAMETER(torev); U_WMRCORE_U32_N16_swap(record,9,torev); dibheader_swap(record + offsetof(U_WMRSTRETCHDIB,dib), torev); } -- 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/gradient-drag.cpp | 60 ++-- src/gradient-drag.h | 8 +- src/knot-holder-entity.cpp | 9 +- src/knot.cpp | 637 +++++++++++++++++----------------------- src/knot.h | 235 +++++---------- src/knotholder.cpp | 4 +- src/knotholder.h | 2 +- src/seltrans.cpp | 64 ++-- src/ui/tools/connector-tool.cpp | 53 ++-- src/vanishing-point.cpp | 29 +- src/vanishing-point.h | 4 + 11 files changed, 465 insertions(+), 640 deletions(-) (limited to 'src') diff --git a/src/gradient-drag.cpp b/src/gradient-drag.cpp index 8a0d7ee26..7b9daf57e 100644 --- a/src/gradient-drag.cpp +++ b/src/gradient-drag.cpp @@ -803,7 +803,7 @@ static void gr_knot_moved_handler(SPKnot *knot, Geom::Point const &ppointer, gui m.unSetup(); if (s.getSnapped()) { p = s.getPoint(); - sp_knot_moveto (knot, p); + knot->moveto(p); } } else if (state & GDK_CONTROL_MASK) { IntermSnapResults isr; @@ -888,7 +888,7 @@ static void gr_knot_moved_handler(SPKnot *knot, Geom::Point const &ppointer, gui } //p = isr.points.front().getPoint(); p = bsp.getPoint(); - sp_knot_moveto (knot, p); + knot->moveto(p); } drag->keep_selection = (bool) g_list_find(drag->selected, dragger); @@ -989,8 +989,6 @@ static void gr_midpoint_limits(GrDragger *dragger, SPObject *server, Geom::Point *high_lim = dragger->point - (highest_dragger->point - *end); } - - /** * Called when a midpoint knot is dragged. */ @@ -1046,7 +1044,7 @@ static void gr_knot_moved_midpoint_handler(SPKnot */*knot*/, Geom::Point const & } } drg->point += this_move; - sp_knot_moveto (drgknot, drg->point); + drgknot->moveto(drg->point); drg->fireDraggables (false); drg->updateDependencies(false); } @@ -1388,7 +1386,7 @@ GrDragger::updateHandles ( Geom::Point pc_old, MeshNodeOperation op ) GrDragger *handle = drag->getDraggerFor( item, POINT_MG_HANDLE, i, fill_or_stroke ); SPKnot *knot = handle->knot; Geom::Point pk = getGradientCoords( item, POINT_MG_HANDLE, i, fill_or_stroke ); - sp_knot_moveto( knot, pk ); + knot->moveto(pk); } @@ -1397,7 +1395,7 @@ GrDragger::updateHandles ( Geom::Point pc_old, MeshNodeOperation op ) GrDragger *handle = drag->getDraggerFor( item, POINT_MG_TENSOR, i, fill_or_stroke ); SPKnot *knot = handle->knot; Geom::Point pk = getGradientCoords( item, POINT_MG_TENSOR, i, fill_or_stroke ); - sp_knot_moveto( knot, pk ); + knot->moveto(pk); } @@ -1483,7 +1481,7 @@ void GrDragger::moveThisToDraggable(SPItem *item, GrPointType point_type, gint p this->point = getGradientCoords(dr_first->item, dr_first->point_type, dr_first->point_i, dr_first->fill_or_stroke); this->point_original = this->point; - sp_knot_moveto(this->knot, this->point); + this->knot->moveto(this->point); for (GSList const* i = draggables; i != NULL; i = i->next) { GrDraggable *da = (GrDraggable *) i->data; @@ -1593,15 +1591,15 @@ GrDragger::GrDragger(GrDrag *parent, Geom::Point p, GrDraggable *draggable) this->parent = parent; // create the knot - this->knot = sp_knot_new (parent->desktop, NULL); + this->knot = new SPKnot(parent->desktop, NULL); this->knot->setMode(SP_KNOT_MODE_XOR); this->knot->setFill(GR_KNOT_COLOR_NORMAL, GR_KNOT_COLOR_MOUSEOVER, GR_KNOT_COLOR_MOUSEOVER); this->knot->setStroke(0x0000007f, 0x0000007f, 0x0000007f); - sp_knot_update_ctrl(this->knot); + this->knot->update_ctrl(); // move knot to the given point - sp_knot_set_position (this->knot, p, SP_KNOT_STATE_NORMAL); - sp_knot_show (this->knot); + this->knot->set_position(p, SP_KNOT_STATE_NORMAL); + this->knot->show(); // connect knot's signals if ( (draggable) // it can be NULL if a node in unsnapped (eg. focus point unsnapped from center) @@ -1610,18 +1608,21 @@ GrDragger::GrDragger(GrDrag *parent, Geom::Point p, GrDraggable *draggable) || (draggable->point_type == POINT_RG_MID1) || (draggable->point_type == POINT_RG_MID2) ) ) { - this->handler_id = g_signal_connect (G_OBJECT (this->knot), "moved", G_CALLBACK (gr_knot_moved_midpoint_handler), this); + this->_moved_connection = this->knot->_moved_signal.connect(sigc::bind(sigc::ptr_fun(gr_knot_moved_midpoint_handler), this)); } else { - this->handler_id = g_signal_connect (G_OBJECT (this->knot), "moved", G_CALLBACK (gr_knot_moved_handler), this); + this->_moved_connection = this->knot->_moved_signal.connect(sigc::bind(sigc::ptr_fun(gr_knot_moved_handler), this)); } - g_signal_connect (G_OBJECT (this->knot), "clicked", G_CALLBACK (gr_knot_clicked_handler), this); - g_signal_connect (G_OBJECT (this->knot), "doubleclicked", G_CALLBACK (gr_knot_doubleclicked_handler), this); - g_signal_connect (G_OBJECT (this->knot), "grabbed", G_CALLBACK (gr_knot_grabbed_handler), this); - g_signal_connect (G_OBJECT (this->knot), "ungrabbed", G_CALLBACK (gr_knot_ungrabbed_handler), this); + + this->_clicked_connection = this->knot->_click_signal.connect(sigc::bind(sigc::ptr_fun(gr_knot_clicked_handler), this)); + this->_doubleclicked_connection = this->knot->_doubleclicked_signal.connect(sigc::bind(sigc::ptr_fun(gr_knot_doubleclicked_handler), this)); + this->_grabbed_connection = this->knot->_grabbed_signal.connect(sigc::bind(sigc::ptr_fun(gr_knot_grabbed_handler), this)); + this->_ungrabbed_connection = this->knot->_ungrabbed_signal.connect(sigc::bind(sigc::ptr_fun(gr_knot_ungrabbed_handler), this)); // add the initial draggable - if (draggable) + if (draggable) { this->addDraggable (draggable); + } + updateKnotShape(); } @@ -1634,19 +1635,20 @@ GrDragger::~GrDragger() //this->parent->setDeselected(this); // disconnect signals - g_signal_handlers_disconnect_by_func(G_OBJECT(this->knot), (gpointer) G_CALLBACK (gr_knot_moved_handler), this); - g_signal_handlers_disconnect_by_func(G_OBJECT(this->knot), (gpointer) G_CALLBACK (gr_knot_clicked_handler), this); - g_signal_handlers_disconnect_by_func(G_OBJECT(this->knot), (gpointer) G_CALLBACK (gr_knot_doubleclicked_handler), this); - g_signal_handlers_disconnect_by_func(G_OBJECT(this->knot), (gpointer) G_CALLBACK (gr_knot_grabbed_handler), this); - g_signal_handlers_disconnect_by_func(G_OBJECT(this->knot), (gpointer) G_CALLBACK (gr_knot_ungrabbed_handler), this); + this->_moved_connection.disconnect(); + this->_clicked_connection.disconnect(); + this->_doubleclicked_connection.disconnect(); + this->_grabbed_connection.disconnect(); + this->_ungrabbed_connection.disconnect(); /* unref should call destroy */ - g_object_unref (G_OBJECT (this->knot)); + knot_unref(this->knot); // delete all draggables for (GSList const* i = this->draggables; i != NULL; i = i->next) { delete ((GrDraggable *) i->data); } + g_slist_free (this->draggables); this->draggables = NULL; } @@ -2043,7 +2045,7 @@ void GrDrag::addDraggersMesh(SPMeshGradient *mg, SPItem *item, Inkscape::PaintTa void GrDrag::grabKnot(GrDragger *dragger, gint x, gint y, guint32 etime) { if (dragger) { - sp_knot_start_dragging (dragger->knot, dragger->point, x, y, etime); + dragger->knot->start_dragging(dragger->point, x, y, etime); } } @@ -2055,7 +2057,7 @@ void GrDrag::grabKnot(SPItem *item, GrPointType point_type, gint point_i, Inksca { GrDragger *dragger = getDraggerFor(item, point_type, point_i, fill_or_stroke); if (dragger) { - sp_knot_start_dragging (dragger->knot, dragger->point, x, y, etime); + dragger->knot->start_dragging(dragger->point, x, y, etime); } } @@ -2358,7 +2360,7 @@ void GrDrag::selected_move(double x, double y, bool write_repr, bool scale_radia Geom::Point p_old = d->point; d->point += Geom::Point (x, y); d->point_original = d->point; - sp_knot_moveto (d->knot, d->point); + d->knot->moveto(d->point); d->fireDraggables (write_repr, scale_radial); d->updateHandles( p_old, MG_NODE_NO_SCALE ); @@ -2394,7 +2396,7 @@ void GrDrag::selected_move(double x, double y, bool write_repr, bool scale_radia GrDragger *drg = (GrDragger*) i->data; SPKnot *drgknot = drg->knot; drg->point += displacement; - sp_knot_moveto (drgknot, drg->point); + drgknot->moveto(drg->point); drg->fireDraggables (true); drg->updateDependencies(true); did = true; diff --git a/src/gradient-drag.h b/src/gradient-drag.h index 4ed13b9f7..e22b48e19 100644 --- a/src/gradient-drag.h +++ b/src/gradient-drag.h @@ -87,7 +87,13 @@ struct GrDragger { Geom::Point point_original; /** Connection to \a knot's "moved" signal, for blocking it (unused?). */ - guint handler_id; + //guint handler_id; + + sigc::connection _moved_connection; + sigc::connection _clicked_connection; + sigc::connection _doubleclicked_connection; + sigc::connection _grabbed_connection; + sigc::connection _ungrabbed_connection; GSList *draggables; diff --git a/src/knot-holder-entity.cpp b/src/knot-holder-entity.cpp index 043685460..48096489e 100644 --- a/src/knot-holder-entity.cpp +++ b/src/knot-holder-entity.cpp @@ -34,7 +34,7 @@ void KnotHolderEntity::create(SPDesktop *desktop, SPItem *item, KnotHolder *pare const gchar *tip, SPKnotShapeType shape, SPKnotModeType mode, guint32 color) { - knot = sp_knot_new(desktop, tip); + knot = new SPKnot(desktop, tip); this->parent_holder = parent; this->item = item; // TODO: remove the item either from here or from knotholder.cpp @@ -52,7 +52,7 @@ void KnotHolderEntity::create(SPDesktop *desktop, SPItem *item, KnotHolder *pare g_object_set (G_OBJECT(knot->item), "fill_color", color, NULL); update_knot(); - sp_knot_show(knot); + knot->show(); _moved_connection = knot->_moved_signal.connect(sigc::mem_fun(*parent_holder, &KnotHolder::knot_moved_handler)); _click_connection = knot->_click_signal.connect(sigc::mem_fun(*parent_holder, &KnotHolder::knot_clicked_handler)); @@ -68,7 +68,8 @@ KnotHolderEntity::~KnotHolderEntity() /* unref should call destroy */ if (knot) { - g_object_unref(knot); + //g_object_unref(knot); + knot_unref(knot); } else { // FIXME: This shouldn't occur. Perhaps it is caused by LPE PointParams being knotholder entities, too // If so, it will likely be fixed with upcoming refactoring efforts. @@ -84,7 +85,7 @@ KnotHolderEntity::update_knot() Geom::Point dp(knot_get() * i2dt); _moved_connection.block(); - sp_knot_set_position(knot, dp, SP_KNOT_STATE_NORMAL); + knot->set_position(dp, SP_KNOT_STATE_NORMAL); _moved_connection.unblock(); } diff --git a/src/knot.cpp b/src/knot.cpp index 2179bc3d5..59d048d8b 100644 --- a/src/knot.cpp +++ b/src/knot.cpp @@ -17,7 +17,6 @@ #endif #include #include -#include "helper/sp-marshal.h" #include "display/sodipodi-ctrl.h" #include "desktop.h" #include "desktop-handles.h" @@ -36,10 +35,11 @@ using Inkscape::DocumentUndo; GDK_POINTER_MOTION_HINT_MASK | \ GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK) -static bool nograb = false; +const gchar *nograbenv = getenv("INKSCAPE_NO_GRAB"); +static bool nograb = (nograbenv && *nograbenv && (*nograbenv != '0')); -static bool grabbed = FALSE; -static bool moved = FALSE; +static bool grabbed = false; +static bool moved = false; static gint xp = 0, yp = 0; // where drag started static gint tolerance = 0; @@ -47,247 +47,136 @@ static bool within_tolerance = false; static bool transform_escaped = false; // true iff resize or rotate was cancelled by esc. -enum { - EVENT, - CLICKED, - DOUBLECLICKED, - GRABBED, - UNGRABBED, - MOVED, - REQUEST, - DISTANCE, - LAST_SIGNAL -}; - -static void sp_knot_class_init(SPKnotClass *klass); -static void sp_knot_init(SPKnot *knot); -static void sp_knot_dispose(GObject *object); +void knot_ref(SPKnot* knot) { + knot->ref_count++; +} + +void knot_unref(SPKnot* knot) { + if (--knot->ref_count < 1) { + delete knot; + } +} + static int sp_knot_handler(SPCanvasItem *item, GdkEvent *event, SPKnot *knot); -static void sp_knot_set_ctrl_state(SPKnot *knot); -static GObjectClass *parent_class; -static guint knot_signals[LAST_SIGNAL] = { 0 }; +SPKnot::SPKnot(SPDesktop *desktop, const gchar *tip) : ref_count(1) { + this->desktop = NULL; + this->item = NULL; + this->owner = NULL; + this->flags = 0; -GType sp_knot_get_type() -{ - static GType type = 0; - if (!type) { - GTypeInfo info = { - sizeof(SPKnotClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) sp_knot_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (SPKnot), - 16, /* n_preallocs */ - (GInstanceInitFunc) sp_knot_init, - NULL - }; - type = g_type_register_static (G_TYPE_OBJECT, "SPKnot", &info, (GTypeFlags) 0); + this->size = 8; + this->pos = Geom::Point(0, 0); + this->grabbed_rel_pos = Geom::Point(0, 0); + this->anchor = SP_ANCHOR_CENTER; + this->shape = SP_KNOT_SHAPE_SQUARE; + this->mode = SP_KNOT_MODE_XOR; + this->tip = NULL; + this->_event_handler_id = 0; + this->pressure = 0; + + this->fill[SP_KNOT_STATE_NORMAL] = 0xffffff00; + this->fill[SP_KNOT_STATE_MOUSEOVER] = 0xff0000ff; + this->fill[SP_KNOT_STATE_DRAGGING] = 0x0000ffff; + + this->stroke[SP_KNOT_STATE_NORMAL] = 0x01000000; + this->stroke[SP_KNOT_STATE_MOUSEOVER] = 0x01000000; + this->stroke[SP_KNOT_STATE_DRAGGING] = 0x01000000; + + this->image[SP_KNOT_STATE_NORMAL] = NULL; + this->image[SP_KNOT_STATE_MOUSEOVER] = NULL; + this->image[SP_KNOT_STATE_DRAGGING] = NULL; + + this->cursor[SP_KNOT_STATE_NORMAL] = NULL; + this->cursor[SP_KNOT_STATE_MOUSEOVER] = NULL; + this->cursor[SP_KNOT_STATE_DRAGGING] = NULL; + + this->saved_cursor = NULL; + this->pixbuf = NULL; + + + this->desktop = desktop; + this->flags = SP_KNOT_VISIBLE; + + if (tip) { + this->tip = g_strdup (tip); } - return type; -} -/** - * SPKnot vtable initialization. - */ -static void sp_knot_class_init(SPKnotClass *klass) -{ - GObjectClass *object_class = (GObjectClass*)klass; - - parent_class = (GObjectClass*) g_type_class_peek_parent(klass); - - object_class->dispose = sp_knot_dispose; - - knot_signals[EVENT] = g_signal_new("event", - G_TYPE_FROM_CLASS(klass), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET(SPKnotClass, event), - NULL, NULL, - sp_marshal_BOOLEAN__POINTER, - G_TYPE_BOOLEAN, 1, - GDK_TYPE_EVENT); - - knot_signals[CLICKED] = g_signal_new("clicked", - G_TYPE_FROM_CLASS(klass), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET(SPKnotClass, clicked), - NULL, NULL, - g_cclosure_marshal_VOID__UINT, - G_TYPE_NONE, 1, - G_TYPE_UINT); - - knot_signals[DOUBLECLICKED] = g_signal_new("doubleclicked", - G_TYPE_FROM_CLASS(klass), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET(SPKnotClass, doubleclicked), - NULL, NULL, - g_cclosure_marshal_VOID__UINT, - G_TYPE_NONE, 1, - G_TYPE_UINT); - - knot_signals[GRABBED] = g_signal_new("grabbed", - G_TYPE_FROM_CLASS(klass), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET(SPKnotClass, grabbed), - NULL, NULL, - g_cclosure_marshal_VOID__UINT, - G_TYPE_NONE, 1, - G_TYPE_UINT); - - knot_signals[UNGRABBED] = g_signal_new("ungrabbed", - G_TYPE_FROM_CLASS(klass), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET(SPKnotClass, ungrabbed), - NULL, NULL, - g_cclosure_marshal_VOID__UINT, - G_TYPE_NONE, 1, - G_TYPE_UINT); - - knot_signals[MOVED] = g_signal_new("moved", - G_TYPE_FROM_CLASS(klass), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET(SPKnotClass, moved), - NULL, NULL, - sp_marshal_NONE__POINTER_UINT, - G_TYPE_NONE, 2, - G_TYPE_POINTER, G_TYPE_UINT); - - knot_signals[REQUEST] = g_signal_new("request", - G_TYPE_FROM_CLASS(klass), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET(SPKnotClass, request), - NULL, NULL, - sp_marshal_BOOLEAN__POINTER_UINT, - G_TYPE_BOOLEAN, 2, - G_TYPE_POINTER, G_TYPE_UINT); - - knot_signals[DISTANCE] = g_signal_new("distance", - G_TYPE_FROM_CLASS(klass), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET(SPKnotClass, distance), - NULL, NULL, - sp_marshal_DOUBLE__POINTER_UINT, - G_TYPE_DOUBLE, 2, - G_TYPE_POINTER, G_TYPE_UINT); - - const gchar *nograbenv = getenv("INKSCAPE_NO_GRAB"); - nograb = (nograbenv && *nograbenv && (*nograbenv != '0')); -} + this->item = sp_canvas_item_new(sp_desktop_controls (desktop), + SP_TYPE_CTRL, + "anchor", SP_ANCHOR_CENTER, + "size", 8.0, + "filled", TRUE, + "fill_color", 0xffffff00, + "stroked", TRUE, + "stroke_color", 0x01000000, + "mode", SP_KNOT_MODE_XOR, + NULL); -/** - * Callback for SPKnot initialization. - */ -static void sp_knot_init(SPKnot *knot) -{ - knot->desktop = NULL; - knot->item = NULL; - knot->owner = NULL; - knot->flags = 0; - - knot->size = 8; - knot->pos = Geom::Point(0, 0); - knot->grabbed_rel_pos = Geom::Point(0, 0); - knot->anchor = SP_ANCHOR_CENTER; - knot->shape = SP_KNOT_SHAPE_SQUARE; - knot->mode = SP_KNOT_MODE_XOR; - knot->tip = NULL; - knot->_event_handler_id = 0; - knot->pressure = 0; - - knot->fill[SP_KNOT_STATE_NORMAL] = 0xffffff00; - knot->fill[SP_KNOT_STATE_MOUSEOVER] = 0xff0000ff; - knot->fill[SP_KNOT_STATE_DRAGGING] = 0x0000ffff; - - knot->stroke[SP_KNOT_STATE_NORMAL] = 0x01000000; - knot->stroke[SP_KNOT_STATE_MOUSEOVER] = 0x01000000; - knot->stroke[SP_KNOT_STATE_DRAGGING] = 0x01000000; - - knot->image[SP_KNOT_STATE_NORMAL] = NULL; - knot->image[SP_KNOT_STATE_MOUSEOVER] = NULL; - knot->image[SP_KNOT_STATE_DRAGGING] = NULL; - - knot->cursor[SP_KNOT_STATE_NORMAL] = NULL; - knot->cursor[SP_KNOT_STATE_MOUSEOVER] = NULL; - knot->cursor[SP_KNOT_STATE_DRAGGING] = NULL; - - knot->saved_cursor = NULL; - knot->pixbuf = NULL; + this->_event_handler_id = g_signal_connect(G_OBJECT(this->item), "event", + G_CALLBACK(sp_knot_handler), this); } -/** - * Called before SPKnot destruction. - */ -static void sp_knot_dispose(GObject *object) -{ - SPKnot *knot = static_cast(object); - +SPKnot::~SPKnot() { #if GTK_CHECK_VERSION(3,0,0) GdkDisplay *display = gdk_display_get_default(); GdkDeviceManager *dm = gdk_display_get_device_manager(display); GdkDevice *device = gdk_device_manager_get_client_pointer(dm); - if ((knot->flags & SP_KNOT_GRABBED) && gdk_display_device_is_grabbed(display, device)) { + if ((this->flags & SP_KNOT_GRABBED) && gdk_display_device_is_grabbed(display, device)) { // This happens e.g. when deleting a node in node tool while dragging it gdk_device_ungrab(device, GDK_CURRENT_TIME); } #else - if ((knot->flags & SP_KNOT_GRABBED) && gdk_pointer_is_grabbed ()) { + if ((this->flags & SP_KNOT_GRABBED) && gdk_pointer_is_grabbed ()) { // This happens e.g. when deleting a node in node tool while dragging it gdk_pointer_ungrab (GDK_CURRENT_TIME); } #endif - if (knot->_event_handler_id > 0) - { - g_signal_handler_disconnect(G_OBJECT (knot->item), knot->_event_handler_id); - knot->_event_handler_id = 0; - } + if (this->_event_handler_id > 0) { + g_signal_handler_disconnect(G_OBJECT (this->item), this->_event_handler_id); + this->_event_handler_id = 0; + } - if (knot->item) { - sp_canvas_item_destroy(knot->item); - knot->item = NULL; + if (this->item) { + sp_canvas_item_destroy(this->item); + this->item = NULL; } for (gint i = 0; i < SP_KNOT_VISIBLE_STATES; i++) { - if (knot->cursor[i]) { + if (this->cursor[i]) { #if GTK_CHECK_VERSION(3,0,0) - g_object_unref(knot->cursor[i]); + g_object_unref(this->cursor[i]); #else - gdk_cursor_unref(knot->cursor[i]); + gdk_cursor_unref(this->cursor[i]); #endif - knot->cursor[i] = NULL; + this->cursor[i] = NULL; } } - if (knot->tip) { - g_free(knot->tip); - knot->tip = NULL; - } - - if (parent_class->dispose) { - (*parent_class->dispose) (object); + if (this->tip) { + g_free(this->tip); + this->tip = NULL; } } -void sp_knot_start_dragging(SPKnot *knot, Geom::Point const &p, gint x, gint y, guint32 etime) -{ +void SPKnot::start_dragging(Geom::Point const &p, gint x, gint y, guint32 etime) { // save drag origin xp = x; yp = y; within_tolerance = true; - knot->grabbed_rel_pos = p - knot->pos; - knot->drag_origin = knot->pos; + this->grabbed_rel_pos = p - this->pos; + this->drag_origin = this->pos; + if (!nograb) { - sp_canvas_item_grab(knot->item, - KNOT_EVENT_MASK, - knot->cursor[SP_KNOT_STATE_DRAGGING], - etime); + sp_canvas_item_grab(this->item, KNOT_EVENT_MASK, this->cursor[SP_KNOT_STATE_DRAGGING], etime); } - sp_knot_set_flag(knot, SP_KNOT_GRABBED, TRUE); + + this->set_flag(SP_KNOT_GRABBED, TRUE); + grabbed = TRUE; } @@ -300,23 +189,21 @@ static int sp_knot_handler(SPCanvasItem */*item*/, GdkEvent *event, SPKnot *knot g_assert(SP_IS_KNOT(knot)); /* Run client universal event handler, if present */ - - gboolean consumed = FALSE; - - g_signal_emit(knot, knot_signals[EVENT], 0, event, &consumed); + bool consumed = knot->_event_signal.emit(knot, event); if (consumed) { - return TRUE; + return true; } - g_object_ref(knot); + knot_ref(knot); + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100); switch (event->type) { case GDK_2BUTTON_PRESS: if (event->button.button == 1) { - g_signal_emit(knot, knot_signals[DOUBLECLICKED], 0, event->button.state); + knot->_doubleclicked_signal.emit(knot, event->button.state); grabbed = FALSE; moved = FALSE; @@ -326,7 +213,8 @@ static int sp_knot_handler(SPCanvasItem */*item*/, GdkEvent *event, SPKnot *knot case GDK_BUTTON_PRESS: if ((event->button.button == 1) && knot->desktop && knot->desktop->event_context && !knot->desktop->event_context->space_panning) { Geom::Point const p = knot->desktop->w2d(Geom::Point(event->button.x, event->button.y)); - sp_knot_start_dragging(knot, p, (gint) event->button.x, (gint) event->button.y, event->button.time); + knot->start_dragging(p, (gint) event->button.x, (gint) event->button.y, event->button.time); + consumed = TRUE; } break; @@ -340,28 +228,25 @@ static int sp_knot_handler(SPCanvasItem */*item*/, GdkEvent *event, SPKnot *knot sp_event_context_discard_delayed_snap_event(knot->desktop->event_context); knot->pressure = 0; + if (transform_escaped) { transform_escaped = false; consumed = TRUE; } else { - sp_knot_set_flag(knot, SP_KNOT_GRABBED, FALSE); + knot->set_flag(SP_KNOT_GRABBED, FALSE); + if (!nograb) { sp_canvas_item_ungrab(knot->item, event->button.time); } + if (moved) { - sp_knot_set_flag(knot, - SP_KNOT_DRAGGING, - FALSE); - g_signal_emit(knot, - knot_signals[UNGRABBED], 0, - event->button.state); - knot->_ungrabbed_signal.emit(knot); + knot->set_flag(SP_KNOT_DRAGGING, FALSE); + + knot->_ungrabbed_signal.emit(knot, event->button.state); } else { - g_signal_emit(knot, - knot_signals[CLICKED], 0, - event->button.state); knot->_click_signal.emit(knot, event->button.state); } + grabbed = FALSE; moved = FALSE; consumed = TRUE; @@ -383,27 +268,26 @@ static int sp_knot_handler(SPCanvasItem */*item*/, GdkEvent *event, SPKnot *knot // motion notify coordinates as given (no snapping back to origin) within_tolerance = false; - if (gdk_event_get_axis (event, GDK_AXIS_PRESSURE, &knot->pressure)) + if (gdk_event_get_axis (event, GDK_AXIS_PRESSURE, &knot->pressure)) { knot->pressure = CLAMP (knot->pressure, 0, 1); - else + } else { knot->pressure = 0.5; + } if (!moved) { - g_signal_emit(knot, - knot_signals[GRABBED], 0, - event->motion.state); - sp_knot_set_flag(knot, - SP_KNOT_DRAGGING, - TRUE); + knot->_grabbed_signal.emit(knot, event->motion.state); + + knot->set_flag(SP_KNOT_DRAGGING, TRUE); } + sp_event_context_snap_delay_handler(knot->desktop->event_context, NULL, (gpointer) knot, (GdkEventMotion *)event, Inkscape::UI::Tools::DelayedSnapEvent::KNOT_HANDLER); sp_knot_handler_request_position(event, knot); moved = TRUE; } break; case GDK_ENTER_NOTIFY: - sp_knot_set_flag(knot, SP_KNOT_MOUSEOVER, TRUE); - sp_knot_set_flag(knot, SP_KNOT_GRABBED, FALSE); + knot->set_flag(SP_KNOT_MOUSEOVER, TRUE); + knot->set_flag(SP_KNOT_GRABBED, FALSE); if (knot->tip && knot->desktop && knot->desktop->event_context) { knot->desktop->event_context->defaultMessageContext()->set(Inkscape::NORMAL_MESSAGE, knot->tip); @@ -414,8 +298,8 @@ static int sp_knot_handler(SPCanvasItem */*item*/, GdkEvent *event, SPKnot *knot consumed = TRUE; break; case GDK_LEAVE_NOTIFY: - sp_knot_set_flag(knot, SP_KNOT_MOUSEOVER, FALSE); - sp_knot_set_flag(knot, SP_KNOT_GRABBED, FALSE); + knot->set_flag(SP_KNOT_MOUSEOVER, FALSE); + knot->set_flag(SP_KNOT_GRABBED, FALSE); if (knot->tip && knot->desktop && knot->desktop->event_context) { knot->desktop->event_context->defaultMessageContext()->clear(); @@ -428,24 +312,26 @@ static int sp_knot_handler(SPCanvasItem */*item*/, GdkEvent *event, SPKnot *knot case GDK_KEY_PRESS: // keybindings for knot switch (Inkscape::UI::Tools::get_group0_keyval(&event->key)) { case GDK_KEY_Escape: - sp_knot_set_flag(knot, SP_KNOT_GRABBED, FALSE); + knot->set_flag(SP_KNOT_GRABBED, FALSE); + if (!nograb) { sp_canvas_item_ungrab(knot->item, event->button.time); } + if (moved) { - sp_knot_set_flag(knot, - SP_KNOT_DRAGGING, - FALSE); - g_signal_emit(knot, - knot_signals[UNGRABBED], 0, - event->button.state); + knot->set_flag(SP_KNOT_DRAGGING, FALSE); + + knot->_ungrabbed_signal.emit(knot, event->button.state); + DocumentUndo::undo(sp_desktop_document(knot->desktop)); knot->desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Node or handle drag canceled.")); transform_escaped = true; consumed = TRUE; } + grabbed = FALSE; moved = FALSE; + sp_event_context_discard_delayed_snap_event(knot->desktop->event_context); break; default: @@ -457,164 +343,82 @@ static int sp_knot_handler(SPCanvasItem */*item*/, GdkEvent *event, SPKnot *knot break; } - g_object_unref(knot); + knot_unref(knot); return consumed || grabbed; } -void sp_knot_handler_request_position(GdkEvent *event, SPKnot *knot) -{ +void sp_knot_handler_request_position(GdkEvent *event, SPKnot *knot) { Geom::Point const motion_w(event->motion.x, event->motion.y); Geom::Point const motion_dt = knot->desktop->w2d(motion_w); Geom::Point p = motion_dt - knot->grabbed_rel_pos; - sp_knot_request_position (knot, p, event->motion.state); + + knot->request_position(p, event->motion.state); knot->desktop->scroll_to_point (motion_dt); knot->desktop->set_coordinate_status(knot->pos); // display the coordinate of knot, not cursor - they may be different! - if (event->motion.state & GDK_BUTTON1_MASK) - Inkscape::UI::Tools::gobble_motion_events(GDK_BUTTON1_MASK); -} - -SPKnot *sp_knot_new(SPDesktop *desktop, const gchar *tip) -{ - g_return_val_if_fail(desktop != NULL, NULL); - - SPKnot * knot = static_cast(g_object_new(SP_TYPE_KNOT, 0)); - knot->desktop = desktop; - knot->flags = SP_KNOT_VISIBLE; - if (tip) { - knot->tip = g_strdup (tip); + if (event->motion.state & GDK_BUTTON1_MASK) { + Inkscape::UI::Tools::gobble_motion_events(GDK_BUTTON1_MASK); } - - knot->item = sp_canvas_item_new(sp_desktop_controls (desktop), - SP_TYPE_CTRL, - "anchor", SP_ANCHOR_CENTER, - "size", 8.0, - "filled", TRUE, - "fill_color", 0xffffff00, - "stroked", TRUE, - "stroke_color", 0x01000000, - "mode", SP_KNOT_MODE_XOR, - NULL); - - knot->_event_handler_id = g_signal_connect(G_OBJECT(knot->item), "event", - G_CALLBACK(sp_knot_handler), knot); - - return knot; } -void sp_knot_show(SPKnot *knot) -{ - g_return_if_fail(knot != NULL); - g_return_if_fail(SP_IS_KNOT (knot)); - - sp_knot_set_flag(knot, SP_KNOT_VISIBLE, TRUE); +void SPKnot::show() { + this->set_flag(SP_KNOT_VISIBLE, TRUE); } -void sp_knot_hide(SPKnot *knot) -{ - g_return_if_fail(knot != NULL); - g_return_if_fail(SP_IS_KNOT(knot)); - - sp_knot_set_flag(knot, SP_KNOT_VISIBLE, FALSE); +void SPKnot::hide() { + this->set_flag(SP_KNOT_VISIBLE, FALSE); } -void sp_knot_request_position(SPKnot *knot, Geom::Point const &p, guint state) -{ - g_return_if_fail(knot != NULL); - g_return_if_fail(SP_IS_KNOT(knot)); - - gboolean done = FALSE; - - g_signal_emit(knot, - knot_signals[REQUEST], 0, - &p, - state, - &done); +void SPKnot::request_position(Geom::Point const &p, guint state) { + bool done = this->_request_signal.emit(this, &const_cast(p), state); /* If user did not complete, we simply move knot to new position */ - if (!done) { - sp_knot_set_position (knot, p, state); + this->set_position(p, state); } } -gdouble sp_knot_distance(SPKnot * knot, Geom::Point const &p, guint state) -{ - g_return_val_if_fail(knot != NULL, 1e18); - g_return_val_if_fail(SP_IS_KNOT(knot), 1e18); - - gdouble distance = Geom::L2(p - knot->pos); +void SPKnot::set_position(Geom::Point const &p, guint state) { + this->pos = p; - g_signal_emit(knot, - knot_signals[DISTANCE], 0, - &p, - state, - &distance); - - return distance; -} - -void sp_knot_set_position(SPKnot *knot, Geom::Point const &p, guint state) -{ - g_return_if_fail(knot != NULL); - g_return_if_fail(SP_IS_KNOT (knot)); - - knot->pos = p; - - if (knot->item) { - SP_CTRL(knot->item)->moveto (p); + if (this->item) { + SP_CTRL(this->item)->moveto(p); } - g_signal_emit(knot, - knot_signals[MOVED], 0, - &p, - state); - knot->_moved_signal.emit(knot, p, state); + this->_moved_signal.emit(this, p, state); } -void sp_knot_moveto(SPKnot *knot, Geom::Point const &p) -{ - g_return_if_fail(knot != NULL); - g_return_if_fail(SP_IS_KNOT(knot)); - - knot->pos = p; +void SPKnot::moveto(Geom::Point const &p) { + this->pos = p; - if (knot->item) { - SP_CTRL(knot->item)->moveto (p); + if (this->item) { + SP_CTRL(this->item)->moveto(p); } } -Geom::Point sp_knot_position(SPKnot const *knot) -{ - g_assert(knot != NULL); - g_assert(SP_IS_KNOT (knot)); - - return knot->pos; +Geom::Point SPKnot::position() const { + return this->pos; } -void sp_knot_set_flag(SPKnot *knot, guint flag, bool set) -{ - g_assert(knot != NULL); - g_assert(SP_IS_KNOT(knot)); - +void SPKnot::set_flag(guint flag, bool set) { if (set) { - knot->flags |= flag; + this->flags |= flag; } else { - knot->flags &= ~flag; + this->flags &= ~flag; } switch (flag) { case SP_KNOT_VISIBLE: if (set) { - sp_canvas_item_show(knot->item); + sp_canvas_item_show(this->item); } else { - sp_canvas_item_hide(knot->item); + sp_canvas_item_hide(this->item); } break; case SP_KNOT_MOUSEOVER: case SP_KNOT_DRAGGING: - sp_knot_set_ctrl_state(knot); + this->set_ctrl_state(); break; case SP_KNOT_GRABBED: break; @@ -624,39 +428,130 @@ void sp_knot_set_flag(SPKnot *knot, guint flag, bool set) } } -void sp_knot_update_ctrl(SPKnot *knot) -{ - if (!knot->item) { +void SPKnot::update_ctrl() { + if (!this->item) { return; } - g_object_set(knot->item, "shape", knot->shape, NULL); - g_object_set(knot->item, "mode", knot->mode, NULL); - g_object_set(knot->item, "size", (gdouble) knot->size, NULL); - g_object_set(knot->item, "anchor", knot->anchor, NULL); - if (knot->pixbuf) { - g_object_set(knot->item, "pixbuf", knot->pixbuf, NULL); + g_object_set(this->item, "shape", this->shape, NULL); + g_object_set(this->item, "mode", this->mode, NULL); + g_object_set(this->item, "size", (gdouble) this->size, NULL); + g_object_set(this->item, "anchor", this->anchor, NULL); + + if (this->pixbuf) { + g_object_set(this->item, "pixbuf", this->pixbuf, NULL); } - sp_knot_set_ctrl_state(knot); + this->set_ctrl_state(); } -/** - * Set knot control state (dragging/mouseover/normal). - */ -static void sp_knot_set_ctrl_state(SPKnot *knot) -{ +void SPKnot::set_ctrl_state() { int state = SP_KNOT_STATE_NORMAL; - if (knot->flags & SP_KNOT_DRAGGING) { + + if (this->flags & SP_KNOT_DRAGGING) { state = SP_KNOT_STATE_DRAGGING; - } else if (knot->flags & SP_KNOT_MOUSEOVER) { + } else if (this->flags & SP_KNOT_MOUSEOVER) { state = SP_KNOT_STATE_MOUSEOVER; } - g_object_set(knot->item, "fill_color", knot->fill[state], NULL); - g_object_set(knot->item, "stroke_color", knot->stroke[state], NULL); + + g_object_set(this->item, "fill_color", this->fill[state], NULL); + g_object_set(this->item, "stroke_color", this->stroke[state], NULL); +} + + +void SPKnot::setSize(guint i) { + size = i; +} + +void SPKnot::setShape(guint i) { + shape = (SPKnotShapeType) i; +} + +void SPKnot::setAnchor(guint i) { + anchor = (SPAnchorType) i; +} + +void SPKnot::setMode(guint i) { + mode = (SPKnotModeType) i; +} + +void SPKnot::setPixbuf(gpointer p) { + pixbuf = p; } +void SPKnot::setFill(guint32 normal, guint32 mouseover, guint32 dragging) { + fill[SP_KNOT_STATE_NORMAL] = normal; + fill[SP_KNOT_STATE_MOUSEOVER] = mouseover; + fill[SP_KNOT_STATE_DRAGGING] = dragging; +} + +void SPKnot::setStroke(guint32 normal, guint32 mouseover, guint32 dragging) { + stroke[SP_KNOT_STATE_NORMAL] = normal; + stroke[SP_KNOT_STATE_MOUSEOVER] = mouseover; + stroke[SP_KNOT_STATE_DRAGGING] = dragging; +} +void SPKnot::setImage(guchar* normal, guchar* mouseover, guchar* dragging) { + image[SP_KNOT_STATE_NORMAL] = normal; + image[SP_KNOT_STATE_MOUSEOVER] = mouseover; + image[SP_KNOT_STATE_DRAGGING] = dragging; +} + +void SPKnot::setCursor(GdkCursor* normal, GdkCursor* mouseover, GdkCursor* dragging) { + if (cursor[SP_KNOT_STATE_NORMAL]) { +#if GTK_CHECK_VERSION(3,0,0) + g_object_unref(cursor[SP_KNOT_STATE_NORMAL]); +#else + gdk_cursor_unref(cursor[SP_KNOT_STATE_NORMAL]); +#endif + } + + cursor[SP_KNOT_STATE_NORMAL] = normal; + + if (normal) { +#if GTK_CHECK_VERSION(3,0,0) + g_object_ref(normal); +#else + gdk_cursor_ref(normal); +#endif + } + + if (cursor[SP_KNOT_STATE_MOUSEOVER]) { +#if GTK_CHECK_VERSION(3,0,0) + g_object_unref(cursor[SP_KNOT_STATE_MOUSEOVER]); +#else + gdk_cursor_unref(cursor[SP_KNOT_STATE_MOUSEOVER]); +#endif + } + + cursor[SP_KNOT_STATE_MOUSEOVER] = mouseover; + + if (mouseover) { +#if GTK_CHECK_VERSION(3,0,0) + g_object_ref(mouseover); +#else + gdk_cursor_ref(mouseover); +#endif + } + + if (cursor[SP_KNOT_STATE_DRAGGING]) { +#if GTK_CHECK_VERSION(3,0,0) + g_object_unref(cursor[SP_KNOT_STATE_DRAGGING]); +#else + gdk_cursor_unref(cursor[SP_KNOT_STATE_DRAGGING]); +#endif + } + + cursor[SP_KNOT_STATE_DRAGGING] = dragging; + + if (dragging) { +#if GTK_CHECK_VERSION(3,0,0) + g_object_ref(dragging); +#else + gdk_cursor_ref(dragging); +#endif + } +} /* Local Variables: diff --git a/src/knot.h b/src/knot.h index 4d87d703f..c8812a466 100644 --- a/src/knot.h +++ b/src/knot.h @@ -26,11 +26,8 @@ class SPDesktop; struct SPCanvasItem; -#define SP_TYPE_KNOT (sp_knot_get_type()) -#define SP_KNOT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), SP_TYPE_KNOT, SPKnot)) -#define SP_KNOT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), SP_TYPE_KNOT, SPKnotClass)) -#define SP_IS_KNOT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), SP_TYPE_KNOT)) -#define SP_IS_KNOT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), SP_TYPE_KNOT)) +#define SP_KNOT(obj) (dynamic_cast(static_cast(obj))) +#define SP_IS_KNOT(obj) (dynamic_cast(static_cast(obj)) != NULL) /** @@ -39,7 +36,15 @@ struct SPCanvasItem; * A knot is a draggable object, with callbacks to change something by * dragging it, visuably represented by a canvas item (mostly square). */ -struct SPKnot : GObject { +class SPKnot { +public: + SPKnot(SPDesktop *desktop, const gchar *tip); + virtual ~SPKnot(); + + + int ref_count; + + SPDesktop *desktop; /**< Desktop we are on. */ SPCanvasItem *item; /**< Our CanvasItem. */ SPItem *owner; /**< Optional Owner Item */ @@ -69,180 +74,94 @@ struct SPKnot : GObject { double pressure; /**< The tablet pen pressure when the knot is being dragged. */ - // C++ signals - /** - sigc::signal _moved_signal; - sigc::signal _click_signal; - sigc::signal _ungrabbed_signal; - **/ - sigc::signal _moved_signal; sigc::signal _click_signal; - sigc::signal _ungrabbed_signal; + sigc::signal _doubleclicked_signal; + sigc::signal _grabbed_signal; + sigc::signal _ungrabbed_signal; + sigc::signal _moved_signal; + sigc::signal _event_signal; - //TODO: all the members above should eventualle become private, accessible via setters/getters - inline void setSize (guint i) {size = i;} - inline void setShape (guint i) {shape = (SPKnotShapeType) i;} - inline void setAnchor (guint i) {anchor = (SPAnchorType) i;} - inline void setMode (guint i) {mode = (SPKnotModeType) i;} - inline void setPixbuf (gpointer p) {pixbuf = p;} - inline void setFill (guint32 normal, guint32 mouseover, guint32 dragging) { - fill[SP_KNOT_STATE_NORMAL] = normal; - fill[SP_KNOT_STATE_MOUSEOVER] = mouseover; - fill[SP_KNOT_STATE_DRAGGING] = dragging; - } - inline void setStroke (guint32 normal, guint32 mouseover, guint32 dragging) { - stroke[SP_KNOT_STATE_NORMAL] = normal; - stroke[SP_KNOT_STATE_MOUSEOVER] = mouseover; - stroke[SP_KNOT_STATE_DRAGGING] = dragging; - } - inline void setImage (guchar* normal, guchar* mouseover, guchar* dragging) { - image[SP_KNOT_STATE_NORMAL] = normal; - image[SP_KNOT_STATE_MOUSEOVER] = mouseover; - image[SP_KNOT_STATE_DRAGGING] = dragging; - } - inline void setCursor (GdkCursor* normal, GdkCursor* mouseover, GdkCursor* dragging) { - if (cursor[SP_KNOT_STATE_NORMAL]) { -#if GTK_CHECK_VERSION(3,0,0) - g_object_unref(cursor[SP_KNOT_STATE_NORMAL]); -#else - gdk_cursor_unref(cursor[SP_KNOT_STATE_NORMAL]); -#endif - } - cursor[SP_KNOT_STATE_NORMAL] = normal; - if (normal) { -#if GTK_CHECK_VERSION(3,0,0) - g_object_ref(normal); -#else - gdk_cursor_ref(normal); -#endif - } - - if (cursor[SP_KNOT_STATE_MOUSEOVER]) { -#if GTK_CHECK_VERSION(3,0,0) - g_object_unref(cursor[SP_KNOT_STATE_MOUSEOVER]); -#else - gdk_cursor_unref(cursor[SP_KNOT_STATE_MOUSEOVER]); -#endif - } - cursor[SP_KNOT_STATE_MOUSEOVER] = mouseover; - if (mouseover) { -#if GTK_CHECK_VERSION(3,0,0) - g_object_ref(mouseover); -#else - gdk_cursor_ref(mouseover); -#endif - } - - if (cursor[SP_KNOT_STATE_DRAGGING]) { -#if GTK_CHECK_VERSION(3,0,0) - g_object_unref(cursor[SP_KNOT_STATE_DRAGGING]); -#else - gdk_cursor_unref(cursor[SP_KNOT_STATE_DRAGGING]); -#endif - } - cursor[SP_KNOT_STATE_DRAGGING] = dragging; - if (dragging) { -#if GTK_CHECK_VERSION(3,0,0) - g_object_ref(dragging); -#else - gdk_cursor_ref(dragging); -#endif - } - } + sigc::signal _request_signal; -}; -/// The SPKnot vtable. -struct SPKnotClass { - GObjectClass parent_class; - gint (* event) (SPKnot *knot, GdkEvent *event); - - /* - * These are unconditional. - */ + //TODO: all the members above should eventualle become private, accessible via setters/getters + void setSize(guint i); + void setShape(guint i); + void setAnchor(guint i); + void setMode(guint i); + void setPixbuf(gpointer p); - void (* clicked) (SPKnot *knot, guint state); - void (* doubleclicked) (SPKnot *knot, guint state); - void (* grabbed) (SPKnot *knot, guint state); - void (* ungrabbed) (SPKnot *knot, guint state); - void (* moved) (SPKnot *knot, Geom::Point const &position, guint state); - void (* stamped) (SPKnot *know, guint state); + void setFill(guint32 normal, guint32 mouseover, guint32 dragging); + void setStroke(guint32 normal, guint32 mouseover, guint32 dragging); + void setImage(guchar* normal, guchar* mouseover, guchar* dragging); - /** Request knot to move to absolute position. */ - bool (* request) (SPKnot *knot, Geom::Point const &pos, guint state); + void setCursor(GdkCursor* normal, GdkCursor* mouseover, GdkCursor* dragging); - /** Find complex distance from knot to point. */ - gdouble (* distance) (SPKnot *knot, Geom::Point const &pos, guint state); -}; + /** + * Show knot on its canvas. + */ + void show(); -/** - * Registers SPKnot class and returns its type number. - */ -GType sp_knot_get_type(); + /** + * Hide knot on its canvas. + */ + void hide(); -/** - * Return new knot object. - */ -SPKnot *sp_knot_new(SPDesktop *desktop, gchar const *tip = NULL); + /** + * Set flag in knot, with side effects. + */ + void set_flag(guint flag, bool set); -#define SP_KNOT_IS_VISIBLE(k) ((k->flags & SP_KNOT_VISIBLE) != 0) -#define SP_KNOT_IS_MOUSEOVER(k) ((k->flags & SP_KNOT_MOUSEOVER) != 0) -#define SP_KNOT_IS_DRAGGING(k) ((k->flags & SP_KNOT_DRAGGING) != 0) -#define SP_KNOT_IS_GRABBED(k) ((k->flags & SP_KNOT_GRABBED) != 0) + /** + * Update knot's pixbuf and set its control state. + */ + void update_ctrl(); -/** - * Show knot on its canvas. - */ -void sp_knot_show(SPKnot *knot); + /** + * Request or set new position for knot. + */ + void request_position(Geom::Point const &pos, guint state); -/** - * Hide knot on its canvas. - */ -void sp_knot_hide(SPKnot *knot); + /** + * Update knot for dragging and tell canvas an item was grabbed. + */ + void start_dragging(Geom::Point const &p, gint x, gint y, guint32 etime); -/** - * Set flag in knot, with side effects. - */ -void sp_knot_set_flag(SPKnot *knot, guint flag, bool set); + /** + * Move knot to new position and emits "moved" signal. + */ + void set_position(Geom::Point const &p, guint state); -/** - * Update knot's pixbuf and set its control state. - */ -void sp_knot_update_ctrl(SPKnot *knot); + /** + * Move knot to new position, without emitting a MOVED signal. + */ + void moveto(Geom::Point const &p); -/** - * Request or set new position for knot. - */ -void sp_knot_request_position(SPKnot *knot, Geom::Point const &pos, guint state); + /** + * Returns position of knot. + */ + Geom::Point position() const; -/** - * Return distance of point to knot's position; unused. - */ -gdouble sp_knot_distance(SPKnot *knot, Geom::Point const &p, guint state); +private: + SPKnot(const SPKnot&); + SPKnot& operator=(const SPKnot&); -/** - * Update knot for dragging and tell canvas an item was grabbed. - */ -void sp_knot_start_dragging(SPKnot *knot, Geom::Point const &p, gint x, gint y, guint32 etime); + /** + * Set knot control state (dragging/mouseover/normal). + */ + void set_ctrl_state(); +}; -/** - * Move knot to new position and emits "moved" signal. - */ -void sp_knot_set_position(SPKnot *knot, Geom::Point const &p, guint state); +void knot_ref(SPKnot* knot); +void knot_unref(SPKnot* knot); -/** - * Move knot to new position, without emitting a MOVED signal. - */ -void sp_knot_moveto(SPKnot *knot, Geom::Point const &p); +#define SP_KNOT_IS_VISIBLE(k) ((k->flags & SP_KNOT_VISIBLE) != 0) +#define SP_KNOT_IS_MOUSEOVER(k) ((k->flags & SP_KNOT_MOUSEOVER) != 0) +#define SP_KNOT_IS_DRAGGING(k) ((k->flags & SP_KNOT_DRAGGING) != 0) +#define SP_KNOT_IS_GRABBED(k) ((k->flags & SP_KNOT_GRABBED) != 0) void sp_knot_handler_request_position(GdkEvent *event, SPKnot *knot); -/** - * Returns position of knot. - */ -Geom::Point sp_knot_position(SPKnot const *knot); - - #endif // SEEN_SP_KNOT_H /* diff --git a/src/knotholder.cpp b/src/knotholder.cpp index bef89f3af..cf87423d4 100644 --- a/src/knotholder.cpp +++ b/src/knotholder.cpp @@ -63,14 +63,12 @@ KnotHolder::KnotHolder(SPDesktop *desktop, SPItem *item, SPKnotHolderReleasedFun g_print ("Error! Throw an exception, please!\n"); } - //g_object_ref(G_OBJECT(item)); // TODO: is this still needed after C++-ification? sp_object_ref(item); sizeUpdatedConn = ControlManager::getManager().connectCtrlSizeChanged(sigc::mem_fun(*this, &KnotHolder::updateControlSizes)); } KnotHolder::~KnotHolder() { - //g_object_unref(G_OBJECT(item)); sp_object_unref(item); for (std::list::iterator i = entity.begin(); i != entity.end(); ++i) @@ -187,7 +185,7 @@ KnotHolder::knot_moved_handler(SPKnot *knot, Geom::Point const &p, guint state) } void -KnotHolder::knot_ungrabbed_handler(SPKnot */*knot*/) +KnotHolder::knot_ungrabbed_handler(SPKnot */*knot*/, guint) { this->dragging = false; diff --git a/src/knotholder.h b/src/knotholder.h index fc91a56fc..d531ae288 100644 --- a/src/knotholder.h +++ b/src/knotholder.h @@ -48,7 +48,7 @@ public: void knot_moved_handler(SPKnot *knot, Geom::Point const &p, guint state); void knot_clicked_handler(SPKnot *knot, guint state); - void knot_ungrabbed_handler(SPKnot *knot); + void knot_ungrabbed_handler(SPKnot *knot, guint); void add(KnotHolderEntity *e); diff --git a/src/seltrans.cpp b/src/seltrans.cpp index a55bc3c0d..858985625 100644 --- a/src/seltrans.cpp +++ b/src/seltrans.cpp @@ -54,15 +54,15 @@ using Inkscape::ControlManager; using Inkscape::DocumentUndo; -static void sp_sel_trans_handle_grab(SPKnot *knot, guint state, gpointer data); -static void sp_sel_trans_handle_ungrab(SPKnot *knot, guint state, gpointer data); -static void sp_sel_trans_handle_click(SPKnot *knot, guint state, gpointer data); -static void sp_sel_trans_handle_new_event(SPKnot *knot, Geom::Point *position, guint32 state, gpointer data); -static gboolean sp_sel_trans_handle_request(SPKnot *knot, Geom::Point *p, guint state, gboolean *data); +static void sp_sel_trans_handle_grab(SPKnot *knot, guint state, SPSelTransHandle const* data); +static void sp_sel_trans_handle_ungrab(SPKnot *knot, guint state, SPSelTransHandle const* data); +static void sp_sel_trans_handle_click(SPKnot *knot, guint state, SPSelTransHandle const* data); +static void sp_sel_trans_handle_new_event(SPKnot *knot, Geom::Point const &position, guint32 state, SPSelTransHandle const* data); +static gboolean sp_sel_trans_handle_request(SPKnot *knot, Geom::Point *p, guint state, SPSelTransHandle const *data); extern GdkPixbuf *handles[]; -static gboolean sp_sel_trans_handle_event(SPKnot *knot, GdkEvent *event, gpointer) +static gboolean sp_sel_trans_handle_event(SPKnot *knot, GdkEvent *event, SPSelTransHandle const*) { switch (event->type) { case GDK_MOTION_NOTIFY: @@ -186,7 +186,7 @@ Inkscape::SelTrans::~SelTrans() _sel_modified_connection.disconnect(); for (int i = 0; i < NUMHANDS; i++) { - g_object_unref(G_OBJECT(knots[i])); + knot_unref(knots[i]); knots[i] = NULL; } @@ -574,7 +574,7 @@ void Inkscape::SelTrans::stamp() void Inkscape::SelTrans::_updateHandles() { for (int i = 0; i < NUMHANDS; i++) - sp_knot_hide(knots[i]); + knots[i]->hide(); if ( !_show_handles || _empty ) return; @@ -627,13 +627,13 @@ void Inkscape::SelTrans::_showHandles(SPSelTransType type) // Position knots to scale the selection bbox Geom::Point const bpos(hands[i].x, hands[i].y); Geom::Point p(_bbox->min() + (_bbox->dimensions() * Geom::Scale(bpos))); - sp_knot_moveto(knots[i], p); - sp_knot_show(knots[i]); + knots[i]->moveto(p); + knots[i]->show(); // This controls the center handle's position, because the default can // be moved and needs to be remembered. if( type == HANDLE_CENTER && _center ) - sp_knot_moveto(knots[i], *_center); + knots[i]->moveto(*_center); } } @@ -641,7 +641,7 @@ void Inkscape::SelTrans::_makeHandles() { for (int i = 0; i < NUMHANDS; i++) { SPSelTransTypeInfo info = handtypes[hands[i].type]; - knots[i] = sp_knot_new(_desktop, info.tip); + knots[i] = new SPKnot(_desktop, info.tip); knots[i]->setShape(SP_CTRL_SHAPE_BITMAP); knots[i]->setSize(13); @@ -650,50 +650,46 @@ void Inkscape::SelTrans::_makeHandles() knots[i]->setFill(info.color[0], info.color[1], info.color[2]); knots[i]->setStroke(info.color[3], info.color[4], info.color[5]); knots[i]->setPixbuf(handles[hands[i].control]); - sp_knot_update_ctrl(knots[i]); - - g_signal_connect(G_OBJECT(knots[i]), "request", - G_CALLBACK(sp_sel_trans_handle_request), (gpointer) &hands[i]); - g_signal_connect(G_OBJECT(knots[i]), "moved", - G_CALLBACK(sp_sel_trans_handle_new_event), (gpointer) &hands[i]); - g_signal_connect(G_OBJECT(knots[i]), "grabbed", - G_CALLBACK(sp_sel_trans_handle_grab), (gpointer) &hands[i]); - g_signal_connect(G_OBJECT(knots[i]), "ungrabbed", - G_CALLBACK(sp_sel_trans_handle_ungrab), (gpointer) &hands[i]); - g_signal_connect(G_OBJECT(knots[i]), "clicked", - G_CALLBACK(sp_sel_trans_handle_click), (gpointer) &hands[i]); - g_signal_connect(G_OBJECT(knots[i]), "event", - G_CALLBACK(sp_sel_trans_handle_event), (gpointer) &hands[i]); + knots[i]->update_ctrl(); + + knots[i]->_request_signal.connect(sigc::bind(sigc::ptr_fun(sp_sel_trans_handle_request), &hands[i])); + knots[i]->_moved_signal.connect(sigc::bind(sigc::ptr_fun(sp_sel_trans_handle_new_event), &hands[i])); + knots[i]->_grabbed_signal.connect(sigc::bind(sigc::ptr_fun(sp_sel_trans_handle_grab), &hands[i])); + knots[i]->_ungrabbed_signal.connect(sigc::bind(sigc::ptr_fun(sp_sel_trans_handle_ungrab), &hands[i])); + knots[i]->_click_signal.connect(sigc::bind(sigc::ptr_fun(sp_sel_trans_handle_click), &hands[i])); + knots[i]->_event_signal.connect(sigc::bind(sigc::ptr_fun(sp_sel_trans_handle_event), &hands[i])); } } -static void sp_sel_trans_handle_grab(SPKnot *knot, guint state, gpointer data) +static void sp_sel_trans_handle_grab(SPKnot *knot, guint state, SPSelTransHandle const* data) { SP_SELECT_CONTEXT(knot->desktop->event_context)->_seltrans->handleGrab( knot, state, *(SPSelTransHandle const *) data ); } -static void sp_sel_trans_handle_ungrab(SPKnot *knot, guint /*state*/, gpointer /*data*/) +static void sp_sel_trans_handle_ungrab(SPKnot *knot, guint /*state*/, SPSelTransHandle const* /*data*/) { SP_SELECT_CONTEXT(knot->desktop->event_context)->_seltrans->ungrab(); } -static void sp_sel_trans_handle_new_event(SPKnot *knot, Geom::Point *position, guint state, gpointer data) +static void sp_sel_trans_handle_new_event(SPKnot *knot, Geom::Point const& position, guint state, SPSelTransHandle const *data) { + Geom::Point pos = position; + SP_SELECT_CONTEXT(knot->desktop->event_context)->_seltrans->handleNewEvent( - knot, position, state, *(SPSelTransHandle const *) data + knot, &pos, state, *(SPSelTransHandle const *) data ); } -static gboolean sp_sel_trans_handle_request(SPKnot *knot, Geom::Point *position, guint state, gboolean *data) +static gboolean sp_sel_trans_handle_request(SPKnot *knot, Geom::Point *position, guint state, SPSelTransHandle const *data) { return SP_SELECT_CONTEXT(knot->desktop->event_context)->_seltrans->handleRequest( knot, position, state, *(SPSelTransHandle const *) data ); } -static void sp_sel_trans_handle_click(SPKnot *knot, guint state, gpointer data) +static void sp_sel_trans_handle_click(SPKnot *knot, guint state, SPSelTransHandle const* data) { SP_SELECT_CONTEXT(knot->desktop->event_context)->_seltrans->handleClick( knot, state, *(SPSelTransHandle const *) data @@ -742,7 +738,7 @@ void Inkscape::SelTrans::handleGrab(SPKnot *knot, guint /*state*/, SPSelTransHan break; } - grab(sp_knot_position(knot), handle.x, handle.y, FALSE, FALSE); + grab(knot->position(), handle.x, handle.y, FALSE, FALSE); } @@ -800,7 +796,7 @@ gboolean Inkscape::SelTrans::handleRequest(SPKnot *knot, Geom::Point *position, return TRUE; } if (request(handle, *position, state)) { - sp_knot_set_position(knot, *position, state); + knot->set_position(*position, state); SP_CTRL(_grip)->moveto(*position); if (handle.type == HANDLE_CENTER) { SP_CTRL(_norm)->moveto(*position); 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; } } diff --git a/src/vanishing-point.cpp b/src/vanishing-point.cpp index 361a7a0de..a0f3692a5 100644 --- a/src/vanishing-point.cpp +++ b/src/vanishing-point.cpp @@ -85,12 +85,12 @@ have_VPs_of_same_perspective (VPDragger *dr1, VPDragger *dr2) } static void -vp_knot_moved_handler (SPKnot *knot, Geom::Point const *ppointer, guint state, gpointer data) +vp_knot_moved_handler (SPKnot *knot, Geom::Point const &ppointer, guint state, gpointer data) { VPDragger *dragger = (VPDragger *) data; VPDrag *drag = dragger->parent; - Geom::Point p = *ppointer; + Geom::Point p = ppointer; // FIXME: take from prefs double snap_dist = SNAP_DIST / inkscape_active_desktop()->current_zoom(); @@ -188,7 +188,7 @@ vp_knot_moved_handler (SPKnot *knot, Geom::Point const *ppointer, guint state, g m.unSetup(); if (s.getSnapped()) { p = s.getPoint(); - sp_knot_moveto(knot, p); + knot->moveto(p); } } @@ -277,22 +277,22 @@ VPDragger::VPDragger(VPDrag *parent, Geom::Point p, VanishingPoint &vp) if (vp.is_finite()) { // create the knot - this->knot = sp_knot_new(inkscape_active_desktop(), NULL); + this->knot = new SPKnot(inkscape_active_desktop(), NULL); this->knot->setMode(SP_KNOT_MODE_XOR); this->knot->setFill(VP_KNOT_COLOR_NORMAL, VP_KNOT_COLOR_NORMAL, VP_KNOT_COLOR_NORMAL); this->knot->setStroke(0x000000ff, 0x000000ff, 0x000000ff); - sp_knot_update_ctrl(this->knot); + this->knot->update_ctrl(); knot->item->ctrlType = CTRL_TYPE_ANCHOR; ControlManager::getManager().track(knot->item); // move knot to the given point - sp_knot_set_position (this->knot, this->point, SP_KNOT_STATE_NORMAL); - sp_knot_show (this->knot); + this->knot->set_position(this->point, SP_KNOT_STATE_NORMAL); + this->knot->show(); // connect knot's signals - g_signal_connect (G_OBJECT (this->knot), "moved", G_CALLBACK (vp_knot_moved_handler), this); - g_signal_connect (G_OBJECT (this->knot), "grabbed", G_CALLBACK (vp_knot_grabbed_handler), this); - g_signal_connect (G_OBJECT (this->knot), "ungrabbed", G_CALLBACK (vp_knot_ungrabbed_handler), this); + this->_moved_connection = this->knot->_moved_signal.connect(sigc::bind(sigc::ptr_fun(vp_knot_moved_handler), this)); + this->_grabbed_connection = this->knot->_grabbed_signal.connect(sigc::bind(sigc::ptr_fun(vp_knot_grabbed_handler), this)); + this->_ungrabbed_connection = this->knot->_ungrabbed_signal.connect(sigc::bind(sigc::ptr_fun(vp_knot_ungrabbed_handler), this)); // add the initial VP (which may be NULL!) this->addVP (vp); @@ -302,11 +302,12 @@ VPDragger::VPDragger(VPDrag *parent, Geom::Point p, VanishingPoint &vp) VPDragger::~VPDragger() { // disconnect signals - g_signal_handlers_disconnect_by_func(G_OBJECT(this->knot), (gpointer) G_CALLBACK (vp_knot_moved_handler), this); - g_signal_handlers_disconnect_by_func(G_OBJECT(this->knot), (gpointer) G_CALLBACK (vp_knot_grabbed_handler), this); - g_signal_handlers_disconnect_by_func(G_OBJECT(this->knot), (gpointer) G_CALLBACK (vp_knot_ungrabbed_handler), this); + this->_moved_connection.disconnect(); + this->_grabbed_connection.disconnect(); + this->_ungrabbed_connection.disconnect(); + /* unref should call destroy */ - g_object_unref (G_OBJECT (this->knot)); + knot_unref(this->knot); } /** diff --git a/src/vanishing-point.h b/src/vanishing-point.h index 53366fe66..ed66aab0a 100644 --- a/src/vanishing-point.h +++ b/src/vanishing-point.h @@ -133,6 +133,10 @@ public: bool dragging_started; + sigc::connection _moved_connection; + sigc::connection _grabbed_connection; + sigc::connection _ungrabbed_connection; + std::list vps; void addVP(VanishingPoint &vp, bool update_pos = false); -- 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/gradient-drag.cpp | 20 ++++++------- src/gradient-drag.h | 16 +++++----- src/knot-holder-entity.cpp | 8 ++--- src/knot-holder-entity.h | 1 + src/knot.cpp | 66 +++++++++++++++++++++-------------------- src/knot.h | 32 ++++++++++---------- src/seltrans.cpp | 16 +++++----- src/ui/tools/connector-tool.cpp | 22 +++++++------- src/vanishing-point.cpp | 10 +++---- src/vanishing-point.h | 9 +++--- 10 files changed, 101 insertions(+), 99 deletions(-) (limited to 'src') diff --git a/src/gradient-drag.cpp b/src/gradient-drag.cpp index 7b9daf57e..ee4c1bc8c 100644 --- a/src/gradient-drag.cpp +++ b/src/gradient-drag.cpp @@ -1595,10 +1595,10 @@ GrDragger::GrDragger(GrDrag *parent, Geom::Point p, GrDraggable *draggable) this->knot->setMode(SP_KNOT_MODE_XOR); this->knot->setFill(GR_KNOT_COLOR_NORMAL, GR_KNOT_COLOR_MOUSEOVER, GR_KNOT_COLOR_MOUSEOVER); this->knot->setStroke(0x0000007f, 0x0000007f, 0x0000007f); - this->knot->update_ctrl(); + this->knot->updateCtrl(); // move knot to the given point - this->knot->set_position(p, SP_KNOT_STATE_NORMAL); + this->knot->setPosition(p, SP_KNOT_STATE_NORMAL); this->knot->show(); // connect knot's signals @@ -1608,15 +1608,15 @@ GrDragger::GrDragger(GrDrag *parent, Geom::Point p, GrDraggable *draggable) || (draggable->point_type == POINT_RG_MID1) || (draggable->point_type == POINT_RG_MID2) ) ) { - this->_moved_connection = this->knot->_moved_signal.connect(sigc::bind(sigc::ptr_fun(gr_knot_moved_midpoint_handler), this)); + this->_moved_connection = this->knot->moved_signal.connect(sigc::bind(sigc::ptr_fun(gr_knot_moved_midpoint_handler), this)); } else { - this->_moved_connection = this->knot->_moved_signal.connect(sigc::bind(sigc::ptr_fun(gr_knot_moved_handler), this)); + this->_moved_connection = this->knot->moved_signal.connect(sigc::bind(sigc::ptr_fun(gr_knot_moved_handler), this)); } - this->_clicked_connection = this->knot->_click_signal.connect(sigc::bind(sigc::ptr_fun(gr_knot_clicked_handler), this)); - this->_doubleclicked_connection = this->knot->_doubleclicked_signal.connect(sigc::bind(sigc::ptr_fun(gr_knot_doubleclicked_handler), this)); - this->_grabbed_connection = this->knot->_grabbed_signal.connect(sigc::bind(sigc::ptr_fun(gr_knot_grabbed_handler), this)); - this->_ungrabbed_connection = this->knot->_ungrabbed_signal.connect(sigc::bind(sigc::ptr_fun(gr_knot_ungrabbed_handler), this)); + this->_clicked_connection = this->knot->click_signal.connect(sigc::bind(sigc::ptr_fun(gr_knot_clicked_handler), this)); + this->_doubleclicked_connection = this->knot->doubleclicked_signal.connect(sigc::bind(sigc::ptr_fun(gr_knot_doubleclicked_handler), this)); + this->_grabbed_connection = this->knot->grabbed_signal.connect(sigc::bind(sigc::ptr_fun(gr_knot_grabbed_handler), this)); + this->_ungrabbed_connection = this->knot->ungrabbed_signal.connect(sigc::bind(sigc::ptr_fun(gr_knot_ungrabbed_handler), this)); // add the initial draggable if (draggable) { @@ -2045,7 +2045,7 @@ void GrDrag::addDraggersMesh(SPMeshGradient *mg, SPItem *item, Inkscape::PaintTa void GrDrag::grabKnot(GrDragger *dragger, gint x, gint y, guint32 etime) { if (dragger) { - dragger->knot->start_dragging(dragger->point, x, y, etime); + dragger->knot->startDragging(dragger->point, x, y, etime); } } @@ -2057,7 +2057,7 @@ void GrDrag::grabKnot(SPItem *item, GrPointType point_type, gint point_i, Inksca { GrDragger *dragger = getDraggerFor(item, point_type, point_i, fill_or_stroke); if (dragger) { - dragger->knot->start_dragging(dragger->point, x, y, etime); + dragger->knot->startDragging(dragger->point, x, y, etime); } } diff --git a/src/gradient-drag.h b/src/gradient-drag.h index e22b48e19..4ee59bb0f 100644 --- a/src/gradient-drag.h +++ b/src/gradient-drag.h @@ -86,15 +86,6 @@ struct GrDragger { // position of the knot before it began to drag; updated when released Geom::Point point_original; - /** Connection to \a knot's "moved" signal, for blocking it (unused?). */ - //guint handler_id; - - sigc::connection _moved_connection; - sigc::connection _clicked_connection; - sigc::connection _doubleclicked_connection; - sigc::connection _grabbed_connection; - sigc::connection _ungrabbed_connection; - GSList *draggables; void addDraggable(GrDraggable *draggable); @@ -123,6 +114,13 @@ struct GrDragger { bool isA(SPItem *item, GrPointType point_type, gint point_i, Inkscape::PaintTarget fill_or_stroke); void fireDraggables(bool write_repr, bool scale_radial = false, bool merging_focus = false); + +private: + sigc::connection _moved_connection; + sigc::connection _clicked_connection; + sigc::connection _doubleclicked_connection; + sigc::connection _grabbed_connection; + sigc::connection _ungrabbed_connection; }; /** diff --git a/src/knot-holder-entity.cpp b/src/knot-holder-entity.cpp index 48096489e..6471124ec 100644 --- a/src/knot-holder-entity.cpp +++ b/src/knot-holder-entity.cpp @@ -54,9 +54,9 @@ void KnotHolderEntity::create(SPDesktop *desktop, SPItem *item, KnotHolder *pare update_knot(); knot->show(); - _moved_connection = knot->_moved_signal.connect(sigc::mem_fun(*parent_holder, &KnotHolder::knot_moved_handler)); - _click_connection = knot->_click_signal.connect(sigc::mem_fun(*parent_holder, &KnotHolder::knot_clicked_handler)); - _ungrabbed_connection = knot->_ungrabbed_signal.connect(sigc::mem_fun(*parent_holder, &KnotHolder::knot_ungrabbed_handler)); + _moved_connection = knot->moved_signal.connect(sigc::mem_fun(*parent_holder, &KnotHolder::knot_moved_handler)); + _click_connection = knot->click_signal.connect(sigc::mem_fun(*parent_holder, &KnotHolder::knot_clicked_handler)); + _ungrabbed_connection = knot->ungrabbed_signal.connect(sigc::mem_fun(*parent_holder, &KnotHolder::knot_ungrabbed_handler)); } @@ -85,7 +85,7 @@ KnotHolderEntity::update_knot() Geom::Point dp(knot_get() * i2dt); _moved_connection.block(); - knot->set_position(dp, SP_KNOT_STATE_NORMAL); + knot->setPosition(dp, SP_KNOT_STATE_NORMAL); _moved_connection.unblock(); } diff --git a/src/knot-holder-entity.h b/src/knot-holder-entity.h index a4e6528cf..2737f23e1 100644 --- a/src/knot-holder-entity.h +++ b/src/knot-holder-entity.h @@ -84,6 +84,7 @@ public: /** Connection to \a knot's "ungrabbed" signal. */ guint _ungrab_handler_id; +private: sigc::connection _moved_connection; sigc::connection _click_connection; sigc::connection _ungrabbed_connection; diff --git a/src/knot.cpp b/src/knot.cpp index 59d048d8b..61d0dff39 100644 --- a/src/knot.cpp +++ b/src/knot.cpp @@ -60,7 +60,9 @@ void knot_unref(SPKnot* knot) { static int sp_knot_handler(SPCanvasItem *item, GdkEvent *event, SPKnot *knot); -SPKnot::SPKnot(SPDesktop *desktop, const gchar *tip) : ref_count(1) { +SPKnot::SPKnot(SPDesktop *desktop, gchar const *tip) + : ref_count(1) +{ this->desktop = NULL; this->item = NULL; this->owner = NULL; @@ -162,7 +164,7 @@ SPKnot::~SPKnot() { } } -void SPKnot::start_dragging(Geom::Point const &p, gint x, gint y, guint32 etime) { +void SPKnot::startDragging(Geom::Point const &p, gint x, gint y, guint32 etime) { // save drag origin xp = x; yp = y; @@ -175,7 +177,7 @@ void SPKnot::start_dragging(Geom::Point const &p, gint x, gint y, guint32 etime) sp_canvas_item_grab(this->item, KNOT_EVENT_MASK, this->cursor[SP_KNOT_STATE_DRAGGING], etime); } - this->set_flag(SP_KNOT_GRABBED, TRUE); + this->setFlag(SP_KNOT_GRABBED, TRUE); grabbed = TRUE; } @@ -189,7 +191,7 @@ static int sp_knot_handler(SPCanvasItem */*item*/, GdkEvent *event, SPKnot *knot g_assert(SP_IS_KNOT(knot)); /* Run client universal event handler, if present */ - bool consumed = knot->_event_signal.emit(knot, event); + bool consumed = knot->event_signal.emit(knot, event); if (consumed) { return true; @@ -203,7 +205,7 @@ static int sp_knot_handler(SPCanvasItem */*item*/, GdkEvent *event, SPKnot *knot switch (event->type) { case GDK_2BUTTON_PRESS: if (event->button.button == 1) { - knot->_doubleclicked_signal.emit(knot, event->button.state); + knot->doubleclicked_signal.emit(knot, event->button.state); grabbed = FALSE; moved = FALSE; @@ -213,7 +215,7 @@ static int sp_knot_handler(SPCanvasItem */*item*/, GdkEvent *event, SPKnot *knot case GDK_BUTTON_PRESS: if ((event->button.button == 1) && knot->desktop && knot->desktop->event_context && !knot->desktop->event_context->space_panning) { Geom::Point const p = knot->desktop->w2d(Geom::Point(event->button.x, event->button.y)); - knot->start_dragging(p, (gint) event->button.x, (gint) event->button.y, event->button.time); + knot->startDragging(p, (gint) event->button.x, (gint) event->button.y, event->button.time); consumed = TRUE; } @@ -233,18 +235,18 @@ static int sp_knot_handler(SPCanvasItem */*item*/, GdkEvent *event, SPKnot *knot transform_escaped = false; consumed = TRUE; } else { - knot->set_flag(SP_KNOT_GRABBED, FALSE); + knot->setFlag(SP_KNOT_GRABBED, FALSE); if (!nograb) { sp_canvas_item_ungrab(knot->item, event->button.time); } if (moved) { - knot->set_flag(SP_KNOT_DRAGGING, FALSE); + knot->setFlag(SP_KNOT_DRAGGING, FALSE); - knot->_ungrabbed_signal.emit(knot, event->button.state); + knot->ungrabbed_signal.emit(knot, event->button.state); } else { - knot->_click_signal.emit(knot, event->button.state); + knot->click_signal.emit(knot, event->button.state); } grabbed = FALSE; @@ -275,9 +277,9 @@ static int sp_knot_handler(SPCanvasItem */*item*/, GdkEvent *event, SPKnot *knot } if (!moved) { - knot->_grabbed_signal.emit(knot, event->motion.state); + knot->grabbed_signal.emit(knot, event->motion.state); - knot->set_flag(SP_KNOT_DRAGGING, TRUE); + knot->setFlag(SP_KNOT_DRAGGING, TRUE); } sp_event_context_snap_delay_handler(knot->desktop->event_context, NULL, (gpointer) knot, (GdkEventMotion *)event, Inkscape::UI::Tools::DelayedSnapEvent::KNOT_HANDLER); @@ -286,8 +288,8 @@ static int sp_knot_handler(SPCanvasItem */*item*/, GdkEvent *event, SPKnot *knot } break; case GDK_ENTER_NOTIFY: - knot->set_flag(SP_KNOT_MOUSEOVER, TRUE); - knot->set_flag(SP_KNOT_GRABBED, FALSE); + knot->setFlag(SP_KNOT_MOUSEOVER, TRUE); + knot->setFlag(SP_KNOT_GRABBED, FALSE); if (knot->tip && knot->desktop && knot->desktop->event_context) { knot->desktop->event_context->defaultMessageContext()->set(Inkscape::NORMAL_MESSAGE, knot->tip); @@ -298,8 +300,8 @@ static int sp_knot_handler(SPCanvasItem */*item*/, GdkEvent *event, SPKnot *knot consumed = TRUE; break; case GDK_LEAVE_NOTIFY: - knot->set_flag(SP_KNOT_MOUSEOVER, FALSE); - knot->set_flag(SP_KNOT_GRABBED, FALSE); + knot->setFlag(SP_KNOT_MOUSEOVER, FALSE); + knot->setFlag(SP_KNOT_GRABBED, FALSE); if (knot->tip && knot->desktop && knot->desktop->event_context) { knot->desktop->event_context->defaultMessageContext()->clear(); @@ -312,16 +314,16 @@ static int sp_knot_handler(SPCanvasItem */*item*/, GdkEvent *event, SPKnot *knot case GDK_KEY_PRESS: // keybindings for knot switch (Inkscape::UI::Tools::get_group0_keyval(&event->key)) { case GDK_KEY_Escape: - knot->set_flag(SP_KNOT_GRABBED, FALSE); + knot->setFlag(SP_KNOT_GRABBED, FALSE); if (!nograb) { sp_canvas_item_ungrab(knot->item, event->button.time); } if (moved) { - knot->set_flag(SP_KNOT_DRAGGING, FALSE); + knot->setFlag(SP_KNOT_DRAGGING, FALSE); - knot->_ungrabbed_signal.emit(knot, event->button.state); + knot->ungrabbed_signal.emit(knot, event->button.state); DocumentUndo::undo(sp_desktop_document(knot->desktop)); knot->desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Node or handle drag canceled.")); @@ -353,7 +355,7 @@ void sp_knot_handler_request_position(GdkEvent *event, SPKnot *knot) { Geom::Point const motion_dt = knot->desktop->w2d(motion_w); Geom::Point p = motion_dt - knot->grabbed_rel_pos; - knot->request_position(p, event->motion.state); + knot->requestPosition(p, event->motion.state); knot->desktop->scroll_to_point (motion_dt); knot->desktop->set_coordinate_status(knot->pos); // display the coordinate of knot, not cursor - they may be different! @@ -363,30 +365,30 @@ void sp_knot_handler_request_position(GdkEvent *event, SPKnot *knot) { } void SPKnot::show() { - this->set_flag(SP_KNOT_VISIBLE, TRUE); + this->setFlag(SP_KNOT_VISIBLE, TRUE); } void SPKnot::hide() { - this->set_flag(SP_KNOT_VISIBLE, FALSE); + this->setFlag(SP_KNOT_VISIBLE, FALSE); } -void SPKnot::request_position(Geom::Point const &p, guint state) { - bool done = this->_request_signal.emit(this, &const_cast(p), state); +void SPKnot::requestPosition(Geom::Point const &p, guint state) { + bool done = this->request_signal.emit(this, &const_cast(p), state); /* If user did not complete, we simply move knot to new position */ if (!done) { - this->set_position(p, state); + this->setPosition(p, state); } } -void SPKnot::set_position(Geom::Point const &p, guint state) { +void SPKnot::setPosition(Geom::Point const &p, guint state) { this->pos = p; if (this->item) { SP_CTRL(this->item)->moveto(p); } - this->_moved_signal.emit(this, p, state); + this->moved_signal.emit(this, p, state); } void SPKnot::moveto(Geom::Point const &p) { @@ -401,7 +403,7 @@ Geom::Point SPKnot::position() const { return this->pos; } -void SPKnot::set_flag(guint flag, bool set) { +void SPKnot::setFlag(guint flag, bool set) { if (set) { this->flags |= flag; } else { @@ -418,7 +420,7 @@ void SPKnot::set_flag(guint flag, bool set) { break; case SP_KNOT_MOUSEOVER: case SP_KNOT_DRAGGING: - this->set_ctrl_state(); + this->_setCtrlState(); break; case SP_KNOT_GRABBED: break; @@ -428,7 +430,7 @@ void SPKnot::set_flag(guint flag, bool set) { } } -void SPKnot::update_ctrl() { +void SPKnot::updateCtrl() { if (!this->item) { return; } @@ -442,10 +444,10 @@ void SPKnot::update_ctrl() { g_object_set(this->item, "pixbuf", this->pixbuf, NULL); } - this->set_ctrl_state(); + this->_setCtrlState(); } -void SPKnot::set_ctrl_state() { +void SPKnot::_setCtrlState() { int state = SP_KNOT_STATE_NORMAL; if (this->flags & SP_KNOT_DRAGGING) { diff --git a/src/knot.h b/src/knot.h index c8812a466..b18f89566 100644 --- a/src/knot.h +++ b/src/knot.h @@ -38,7 +38,7 @@ struct SPCanvasItem; */ class SPKnot { public: - SPKnot(SPDesktop *desktop, const gchar *tip); + SPKnot(SPDesktop *desktop, gchar const *tip); virtual ~SPKnot(); @@ -74,14 +74,14 @@ public: double pressure; /**< The tablet pen pressure when the knot is being dragged. */ - sigc::signal _click_signal; - sigc::signal _doubleclicked_signal; - sigc::signal _grabbed_signal; - sigc::signal _ungrabbed_signal; - sigc::signal _moved_signal; - sigc::signal _event_signal; + sigc::signal click_signal; + sigc::signal doubleclicked_signal; + sigc::signal grabbed_signal; + sigc::signal ungrabbed_signal; + sigc::signal moved_signal; + sigc::signal event_signal; - sigc::signal _request_signal; + sigc::signal request_signal; //TODO: all the members above should eventualle become private, accessible via setters/getters @@ -110,27 +110,27 @@ public: /** * Set flag in knot, with side effects. */ - void set_flag(guint flag, bool set); + void setFlag(guint flag, bool set); /** * Update knot's pixbuf and set its control state. */ - void update_ctrl(); + void updateCtrl(); /** * Request or set new position for knot. */ - void request_position(Geom::Point const &pos, guint state); + void requestPosition(Geom::Point const &pos, guint state); /** * Update knot for dragging and tell canvas an item was grabbed. */ - void start_dragging(Geom::Point const &p, gint x, gint y, guint32 etime); + void startDragging(Geom::Point const &p, gint x, gint y, guint32 etime); /** * Move knot to new position and emits "moved" signal. */ - void set_position(Geom::Point const &p, guint state); + void setPosition(Geom::Point const &p, guint state); /** * Move knot to new position, without emitting a MOVED signal. @@ -143,13 +143,13 @@ public: Geom::Point position() const; private: - SPKnot(const SPKnot&); - SPKnot& operator=(const SPKnot&); + SPKnot(SPKnot const&); + SPKnot& operator=(SPKnot const&); /** * Set knot control state (dragging/mouseover/normal). */ - void set_ctrl_state(); + void _setCtrlState(); }; void knot_ref(SPKnot* knot); diff --git a/src/seltrans.cpp b/src/seltrans.cpp index 858985625..60a0bfa11 100644 --- a/src/seltrans.cpp +++ b/src/seltrans.cpp @@ -650,14 +650,14 @@ void Inkscape::SelTrans::_makeHandles() knots[i]->setFill(info.color[0], info.color[1], info.color[2]); knots[i]->setStroke(info.color[3], info.color[4], info.color[5]); knots[i]->setPixbuf(handles[hands[i].control]); - knots[i]->update_ctrl(); + knots[i]->updateCtrl(); - knots[i]->_request_signal.connect(sigc::bind(sigc::ptr_fun(sp_sel_trans_handle_request), &hands[i])); - knots[i]->_moved_signal.connect(sigc::bind(sigc::ptr_fun(sp_sel_trans_handle_new_event), &hands[i])); - knots[i]->_grabbed_signal.connect(sigc::bind(sigc::ptr_fun(sp_sel_trans_handle_grab), &hands[i])); - knots[i]->_ungrabbed_signal.connect(sigc::bind(sigc::ptr_fun(sp_sel_trans_handle_ungrab), &hands[i])); - knots[i]->_click_signal.connect(sigc::bind(sigc::ptr_fun(sp_sel_trans_handle_click), &hands[i])); - knots[i]->_event_signal.connect(sigc::bind(sigc::ptr_fun(sp_sel_trans_handle_event), &hands[i])); + knots[i]->request_signal.connect(sigc::bind(sigc::ptr_fun(sp_sel_trans_handle_request), &hands[i])); + knots[i]->moved_signal.connect(sigc::bind(sigc::ptr_fun(sp_sel_trans_handle_new_event), &hands[i])); + knots[i]->grabbed_signal.connect(sigc::bind(sigc::ptr_fun(sp_sel_trans_handle_grab), &hands[i])); + knots[i]->ungrabbed_signal.connect(sigc::bind(sigc::ptr_fun(sp_sel_trans_handle_ungrab), &hands[i])); + knots[i]->click_signal.connect(sigc::bind(sigc::ptr_fun(sp_sel_trans_handle_click), &hands[i])); + knots[i]->event_signal.connect(sigc::bind(sigc::ptr_fun(sp_sel_trans_handle_event), &hands[i])); } } @@ -796,7 +796,7 @@ gboolean Inkscape::SelTrans::handleRequest(SPKnot *knot, Geom::Point *position, return TRUE; } if (request(handle, *position, state)) { - knot->set_position(*position, state); + knot->setPosition(*position, state); SP_CTRL(_grip)->moveto(*position); if (handle.type == HANDLE_CENTER) { SP_CTRL(_norm)->moveto(*position); 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(); diff --git a/src/vanishing-point.cpp b/src/vanishing-point.cpp index a0f3692a5..bb6a2c4d7 100644 --- a/src/vanishing-point.cpp +++ b/src/vanishing-point.cpp @@ -281,18 +281,18 @@ VPDragger::VPDragger(VPDrag *parent, Geom::Point p, VanishingPoint &vp) this->knot->setMode(SP_KNOT_MODE_XOR); this->knot->setFill(VP_KNOT_COLOR_NORMAL, VP_KNOT_COLOR_NORMAL, VP_KNOT_COLOR_NORMAL); this->knot->setStroke(0x000000ff, 0x000000ff, 0x000000ff); - this->knot->update_ctrl(); + this->knot->updateCtrl(); knot->item->ctrlType = CTRL_TYPE_ANCHOR; ControlManager::getManager().track(knot->item); // move knot to the given point - this->knot->set_position(this->point, SP_KNOT_STATE_NORMAL); + this->knot->setPosition(this->point, SP_KNOT_STATE_NORMAL); this->knot->show(); // connect knot's signals - this->_moved_connection = this->knot->_moved_signal.connect(sigc::bind(sigc::ptr_fun(vp_knot_moved_handler), this)); - this->_grabbed_connection = this->knot->_grabbed_signal.connect(sigc::bind(sigc::ptr_fun(vp_knot_grabbed_handler), this)); - this->_ungrabbed_connection = this->knot->_ungrabbed_signal.connect(sigc::bind(sigc::ptr_fun(vp_knot_ungrabbed_handler), this)); + this->_moved_connection = this->knot->moved_signal.connect(sigc::bind(sigc::ptr_fun(vp_knot_moved_handler), this)); + this->_grabbed_connection = this->knot->grabbed_signal.connect(sigc::bind(sigc::ptr_fun(vp_knot_grabbed_handler), this)); + this->_ungrabbed_connection = this->knot->ungrabbed_signal.connect(sigc::bind(sigc::ptr_fun(vp_knot_ungrabbed_handler), this)); // add the initial VP (which may be NULL!) this->addVP (vp); diff --git a/src/vanishing-point.h b/src/vanishing-point.h index ed66aab0a..ca34d9118 100644 --- a/src/vanishing-point.h +++ b/src/vanishing-point.h @@ -133,10 +133,6 @@ public: bool dragging_started; - sigc::connection _moved_connection; - sigc::connection _grabbed_connection; - sigc::connection _ungrabbed_connection; - std::list vps; void addVP(VanishingPoint &vp, bool update_pos = false); @@ -156,6 +152,11 @@ public: void updateZOrders(); void printVPs(); + +private: + sigc::connection _moved_connection; + sigc::connection _grabbed_connection; + sigc::connection _ungrabbed_connection; }; struct VPDrag { -- 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') 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/sp-guide.cpp | 2 ++ src/ui/dialog/guides.cpp | 33 ++++++++++++++------------------- src/ui/dialog/guides.h | 1 - 3 files changed, 16 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/sp-guide.cpp b/src/sp-guide.cpp index a0aa9692e..60f15a79d 100644 --- a/src/sp-guide.cpp +++ b/src/sp-guide.cpp @@ -183,6 +183,8 @@ void SPGuide::release() { void SPGuide::set(unsigned int key, const gchar *value) { switch (key) { case SP_ATTR_INKSCAPE_LABEL: + if (this->label) g_free(this->label); + if (value) { this->label = g_strdup(value); } else { 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/CMakeLists.txt | 1 - src/Makefile_insert | 1 - src/main.cpp | 2 +- src/modifier-fns.h | 64 -------------------------------------------- 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 +- 9 files changed, 18 insertions(+), 83 deletions(-) delete mode 100644 src/modifier-fns.h (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c34bd2e62..e1e0afa79 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -369,7 +369,6 @@ set(inkscape_SRC message.h mod360-test.h mod360.h - modifier-fns.h number-opt-number.h object-edit.h object-hierarchy.h diff --git a/src/Makefile_insert b/src/Makefile_insert index 5ff44b253..8872b045d 100644 --- a/src/Makefile_insert +++ b/src/Makefile_insert @@ -94,7 +94,6 @@ ink_common_sources += \ message.h \ message-stack.cpp message-stack.h \ mod360.cpp mod360.h \ - modifier-fns.h \ object-edit.cpp object-edit.h \ object-hierarchy.cpp object-hierarchy.h \ object-snapper.cpp object-snapper.h \ diff --git a/src/main.cpp b/src/main.cpp index 25f813c2b..00d0fcbb6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -925,7 +925,7 @@ namespace Inkscape { namespace UI { namespace Tools { -guint get_group0_keyval(GdkEventKey* event); +guint get_group0_keyval(GdkEventKey const* event); } } diff --git a/src/modifier-fns.h b/src/modifier-fns.h deleted file mode 100644 index cab110467..000000000 --- a/src/modifier-fns.h +++ /dev/null @@ -1,64 +0,0 @@ -#ifndef SEEN_MODIFIER_FNS_H -#define SEEN_MODIFIER_FNS_H - -/** \file - * Functions on GdkEventKey.state that test modifier keys. - * - * The MOD__SHIFT macro in macros.h is equivalent to mod_shift(event-\>key.state). - */ - -/* - * Hereby placed in public domain. - */ - -#include -#include - -inline bool -mod_shift(guint const state) -{ - return state & GDK_SHIFT_MASK; -} - -inline bool -mod_ctrl(guint const state) -{ - return state & GDK_CONTROL_MASK; -} - -inline bool -mod_alt(guint const state) -{ - return state & GDK_MOD1_MASK; -} - -inline bool -mod_shift_only(guint const state) -{ - return (state & GDK_SHIFT_MASK) && !(state & GDK_CONTROL_MASK) && !(state & GDK_MOD1_MASK); -} - -inline bool -mod_ctrl_only(guint const state) -{ - return !(state & GDK_SHIFT_MASK) && (state & GDK_CONTROL_MASK) && !(state & GDK_MOD1_MASK); -} - -inline bool -mod_alt_only(guint const state) -{ - return !(state & GDK_SHIFT_MASK) && !(state & GDK_CONTROL_MASK) && (state & GDK_MOD1_MASK); -} - -#endif /* !SEEN_MODIFIER_FNS_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/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/gradient-drag.h | 2 +- src/knot-holder-entity.h | 5 ++--- src/knotholder.h | 2 +- src/seltrans.h | 2 +- src/ui/tools/connector-tool.h | 2 +- 5 files changed, 6 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/gradient-drag.h b/src/gradient-drag.h index 4ee59bb0f..964ea8093 100644 --- a/src/gradient-drag.h +++ b/src/gradient-drag.h @@ -28,7 +28,7 @@ #include "sp-gradient.h" // TODO refactor enums to external .h file #include "sp-mesh-array.h" -struct SPKnot; +class SPKnot; class SPDesktop; class SPCSSAttr; diff --git a/src/knot-holder-entity.h b/src/knot-holder-entity.h index 2737f23e1..a9268d396 100644 --- a/src/knot-holder-entity.h +++ b/src/knot-holder-entity.h @@ -20,9 +20,8 @@ #include "snapper.h" #include "display/sp-canvas-item.h" -class SPItem; -struct SPKnot; - +class SPItem; +class SPKnot; class SPDesktop; class KnotHolder; diff --git a/src/knotholder.h b/src/knotholder.h index d531ae288..3632635f5 100644 --- a/src/knotholder.h +++ b/src/knotholder.h @@ -34,7 +34,7 @@ class PowerStrokePointArrayParamKnotHolderEntity; class KnotHolderEntity; class SPItem; class SPDesktop; -struct SPKnot; +class SPKnot; /* fixme: Think how to make callbacks most sensitive (Lauris) */ typedef void (* SPKnotHolderReleasedFunc) (SPItem *item); diff --git a/src/seltrans.h b/src/seltrans.h index d97375520..44268ed69 100644 --- a/src/seltrans.h +++ b/src/seltrans.h @@ -27,7 +27,7 @@ #include "sp-item.h" #include "seltrans-handles.h" -struct SPKnot; +class SPKnot; class SPDesktop; struct SPCanvasItem; struct SPCtrlLine; 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 c238cf70cf7cd2b3ad6e347076e15d74304294c2 Mon Sep 17 00:00:00 2001 From: Alex Valavanis Date: Sun, 30 Mar 2014 13:39:02 +0100 Subject: End support for obsolete GNU hash. Supported either natively, through TR1 or Boost now Fixed bugs: - https://launchpad.net/bugs/1269346 (bzr r13231) --- src/util/unordered-containers.h | 31 ------------------------------- 1 file changed, 31 deletions(-) (limited to 'src') diff --git a/src/util/unordered-containers.h b/src/util/unordered-containers.h index 98c2fa3c9..b92f2e7ea 100644 --- a/src/util/unordered-containers.h +++ b/src/util/unordered-containers.h @@ -69,37 +69,6 @@ struct hash : public std::unary_function -# include -# include -# define INK_UNORDERED_SET __gnu_cxx::hash_set -# define INK_UNORDERED_MAP __gnu_cxx::hash_map -# define INK_HASH __gnu_cxx::hash - -#include - -namespace __gnu_cxx { -// hash function for pointers -// TR1 and Boost have this defined by default, __gnu_cxx doesn't -template -struct hash : public std::unary_function { - std::size_t operator()(T *p) const { - // Taken from Boost - std::size_t x = static_cast(reinterpret_cast(p)); - return x + (x >> 3); - } -}; - -template <> -struct hash : public std::unary_function { - std::size_t operator()(Glib::ustring const &s) const { - return hash()(s.raw()); - } -}; -} // namespace __gnu_cxx #endif #else -- 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') 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 93cffb85dbe5e7e522e061fa21e00df9c8270fbc Mon Sep 17 00:00:00 2001 From: Alex Valavanis Date: Sun, 30 Mar 2014 17:34:19 +0100 Subject: Migrate inkjar to cstdio functions to fix build issues on Free BSD (Thanks Markus Engel); see bug #1232474 (bzr r13233) --- src/io/inkjar.cpp | 18 +++++++++--------- src/io/inkjar.h | 6 +++--- 2 files changed, 12 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/io/inkjar.cpp b/src/io/inkjar.cpp index 4af140737..b9335c556 100644 --- a/src/io/inkjar.cpp +++ b/src/io/inkjar.cpp @@ -68,7 +68,7 @@ JarFile::JarFile(gchar const*new_filename) { _filename = g_strdup(new_filename); _last_filename = NULL; - fd = -1; + fd = NULL; } //fixme: the following should probably just return a const gchar* and not @@ -104,7 +104,7 @@ bool JarFile::init_inflation() bool JarFile::open() { - if ((fd = ::open(_filename, O_RDONLY)) < 0) { + if ((fd = fopen(_filename, O_RDONLY)) < 0) { fprintf(stderr, "open failed.\n"); return false; } @@ -116,7 +116,7 @@ bool JarFile::open() bool JarFile::close() { - if (fd >= 0 && !::close(fd)) { + if (fd >= 0 && !fclose(fd)) { inflateEnd(&_zs); return true; } @@ -257,7 +257,7 @@ GByteArray *JarFile::get_next_file_contents() if (method == 8 || flags & 0x0008) { unsigned int file_length = 0;//uncompressed file length - lseek(fd, eflen, SEEK_CUR); + fseek(fd, eflen, SEEK_CUR); guint8 *file_data = get_compressed_file(compressed_size, file_length, crc, flags); if (file_data == NULL) { @@ -275,7 +275,7 @@ GByteArray *JarFile::get_next_file_contents() } g_byte_array_append(gba, file_data, compressed_size); } else { - lseek(fd, compressed_size+eflen, SEEK_CUR); + fseek(fd, compressed_size+eflen, SEEK_CUR); g_byte_array_free(gba, FALSE); return NULL; } @@ -314,7 +314,7 @@ guint8 *JarFile::get_uncompressed_file(guint32 compressed_size, guint32 crc, std::printf("%u bytes written\n", out_a); #endif } - lseek(fd, eflen, SEEK_CUR); + fseek(fd, eflen, SEEK_CUR); g_free(bytes); if (!check_crc(crc, crc2, flags)) { @@ -329,7 +329,7 @@ guint8 *JarFile::get_uncompressed_file(guint32 compressed_size, guint32 crc, int JarFile::read(guint8 *buf, int count) { int nbytes; - if ((nbytes = ::read(fd, buf, count)) != count) { + if ((nbytes = fread(buf, 1, count, fd)) != count) { fprintf(stderr, "read error\n"); exit(1); return 0; @@ -358,8 +358,8 @@ guint8 *JarFile::get_compressed_file(guint32 compressed_size, if (!_zs.avail_in) { - if ((nbytes = ::read(fd, in_buffer, - (leftover_in < RDSZ ? leftover_in : RDSZ))) + if ((nbytes = fread(in_buffer, 1, + (leftover_in < RDSZ ? leftover_in : RDSZ), fd)) < 0) { fprintf(stderr, "jarfile read error"); } diff --git a/src/io/inkjar.h b/src/io/inkjar.h index ea4b0ee32..ee6e33526 100644 --- a/src/io/inkjar.h +++ b/src/io/inkjar.h @@ -27,6 +27,7 @@ #endif #include +#include namespace Inkjar { @@ -87,11 +88,10 @@ typedef uint32_t ub4; * * All memory allocations are done with g_malloc. */ - class JarFile { public: - JarFile() : fd(-1), _filename(NULL), _last_filename(NULL) {} + JarFile() : fd(NULL), _filename(NULL), _last_filename(NULL) {} virtual ~JarFile(); JarFile(gchar const *new_filename); @@ -106,7 +106,7 @@ public: private: - int fd; + FILE *fd; // File descriptor gchar *_filename; z_stream _zs; gchar *_last_filename; -- cgit v1.2.3 From 71d8e96e4874875d7b5ae2707f0a88296ea3b238 Mon Sep 17 00:00:00 2001 From: Alex Valavanis Date: Sun, 30 Mar 2014 22:09:32 +0100 Subject: inkjar: Fix access mode string (bzr r13235) --- src/io/inkjar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/io/inkjar.cpp b/src/io/inkjar.cpp index b9335c556..b31b98336 100644 --- a/src/io/inkjar.cpp +++ b/src/io/inkjar.cpp @@ -104,7 +104,7 @@ bool JarFile::init_inflation() bool JarFile::open() { - if ((fd = fopen(_filename, O_RDONLY)) < 0) { + if ((fd = fopen(_filename, "r")) < 0) { fprintf(stderr, "open failed.\n"); return false; } -- 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/display/canvas-axonomgrid.cpp | 2 +- src/display/canvas-grid.cpp | 2 +- src/interface.cpp | 64 ++++++++++++++++----------------- 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 ++++----- src/widgets/stroke-style.cpp | 12 +++---- 22 files changed, 153 insertions(+), 153 deletions(-) (limited to 'src') diff --git a/src/display/canvas-axonomgrid.cpp b/src/display/canvas-axonomgrid.cpp index 858312f5b..312a8d655 100644 --- a/src/display/canvas-axonomgrid.cpp +++ b/src/display/canvas-axonomgrid.cpp @@ -141,7 +141,7 @@ attach_all(Gtk::Table &table, Gtk::Widget const *const arr[], unsigned size, int 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 space->set_halign(Gtk::ALIGN_CENTER); diff --git a/src/display/canvas-grid.cpp b/src/display/canvas-grid.cpp index 3c4ad9b00..4b1dbd1ed 100644 --- a/src/display/canvas-grid.cpp +++ b/src/display/canvas-grid.cpp @@ -469,7 +469,7 @@ static inline void attach_all(Gtk::Table &table, Gtk::Widget const *const arr[], 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 space->set_halign(Gtk::ALIGN_CENTER); diff --git a/src/interface.cpp b/src/interface.cpp index 6eb1b6a5a..1cbeb44a3 100644 --- a/src/interface.cpp +++ b/src/interface.cpp @@ -1524,7 +1524,7 @@ ContextMenu::~ContextMenu(void) Gtk::SeparatorMenuItem* ContextMenu::AddSeparator(void) { - Gtk::SeparatorMenuItem* sep = manage(new Gtk::SeparatorMenuItem()); + Gtk::SeparatorMenuItem* sep = Gtk::manage(new Gtk::SeparatorMenuItem()); sep->show(); append(*sep); return sep; @@ -1556,7 +1556,7 @@ void ContextMenu::AppendItemFromVerb(Inkscape::Verb *verb)//, SPDesktop *view)// return; } - Gtk::ImageMenuItem *item = manage(new Gtk::ImageMenuItem(action->name, true)); + Gtk::ImageMenuItem *item = Gtk::manage(new Gtk::ImageMenuItem(action->name, true)); sp_shortcut_add_accelerator(GTK_WIDGET(item->gobj()), sp_shortcut_get_primary(verb)); @@ -1638,7 +1638,7 @@ void ContextMenu::MakeItemMenu (void) Gtk::MenuItem* mi; /* Item dialog */ - mi = manage(new Gtk::MenuItem(_("_Object Properties..."),1)); + mi = Gtk::manage(new Gtk::MenuItem(_("_Object Properties..."),1)); mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::ItemProperties)); mi->show(); append(*mi);//insert(*mi,positionOfLastDialog++); @@ -1647,7 +1647,7 @@ void ContextMenu::MakeItemMenu (void) /* Select item */ if (Inkscape::Verb::getbyid( "org.inkscape.followlink" )) { - mi = manage(new Gtk::MenuItem(_("_Select This"),1)); + mi = Gtk::manage(new Gtk::MenuItem(_("_Select This"), 1)); if (_desktop->selection->includes(_item)) { mi->set_sensitive(FALSE); } else { @@ -1658,9 +1658,9 @@ void ContextMenu::MakeItemMenu (void) } - mi = manage(new Gtk::MenuItem(_("Select Same"))); + mi = Gtk::manage(new Gtk::MenuItem(_("Select Same"))); mi->show(); - Gtk::Menu *select_same_submenu = manage(new Gtk::Menu()); + Gtk::Menu *select_same_submenu = Gtk::manage(new Gtk::Menu()); if (_desktop->selection->isEmpty()) { mi->set_sensitive(FALSE); } @@ -1668,42 +1668,42 @@ void ContextMenu::MakeItemMenu (void) append(*mi); /* Select same fill and stroke */ - mi = manage(new Gtk::MenuItem(_("Fill and Stroke"),1)); + mi = Gtk::manage(new Gtk::MenuItem(_("Fill and Stroke"), 1)); mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::SelectSameFillStroke)); mi->set_sensitive(!SP_IS_ANCHOR(_item)); mi->show(); select_same_submenu->append(*mi); /* Select same fill color */ - mi = manage(new Gtk::MenuItem(_("Fill Color"),1)); + mi = Gtk::manage(new Gtk::MenuItem(_("Fill Color"), 1)); mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::SelectSameFillColor)); mi->set_sensitive(!SP_IS_ANCHOR(_item)); mi->show(); select_same_submenu->append(*mi); /* Select same stroke color */ - mi = manage(new Gtk::MenuItem(_("Stroke Color"),1)); + mi = Gtk::manage(new Gtk::MenuItem(_("Stroke Color"), 1)); mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::SelectSameStrokeColor)); mi->set_sensitive(!SP_IS_ANCHOR(_item)); mi->show(); select_same_submenu->append(*mi); /* Select same stroke style */ - mi = manage(new Gtk::MenuItem(_("Stroke Style"),1)); + mi = Gtk::manage(new Gtk::MenuItem(_("Stroke Style"), 1)); mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::SelectSameStrokeStyle)); mi->set_sensitive(!SP_IS_ANCHOR(_item)); mi->show(); select_same_submenu->append(*mi); /* Select same stroke style */ - mi = manage(new Gtk::MenuItem(_("Object type"),1)); + mi = Gtk::manage(new Gtk::MenuItem(_("Object type"), 1)); mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::SelectSameObjectType)); mi->set_sensitive(!SP_IS_ANCHOR(_item)); mi->show(); select_same_submenu->append(*mi); /* Move to layer */ - mi = manage(new Gtk::MenuItem(_("_Move to layer ..."),1)); + mi = Gtk::manage(new Gtk::MenuItem(_("_Move to layer ..."), 1)); if (_desktop->selection->isEmpty()) { mi->set_sensitive(FALSE); } else { @@ -1713,7 +1713,7 @@ void ContextMenu::MakeItemMenu (void) append(*mi); /* Create link */ - mi = manage(new Gtk::MenuItem(_("Create _Link"),1)); + mi = Gtk::manage(new Gtk::MenuItem(_("Create _Link"), 1)); mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::ItemCreateLink)); mi->set_sensitive(!SP_IS_ANCHOR(_item)); mi->show(); @@ -1736,7 +1736,7 @@ void ContextMenu::MakeItemMenu (void) } } /* Set mask */ - mi = manage(new Gtk::MenuItem(_("Set Mask"),1)); + mi = Gtk::manage(new Gtk::MenuItem(_("Set Mask"), 1)); mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::SetMask)); if (ClipRefOK || MaskRefOK) { mi->set_sensitive(FALSE); @@ -1747,7 +1747,7 @@ void ContextMenu::MakeItemMenu (void) append(*mi); /* Release mask */ - mi = manage(new Gtk::MenuItem(_("Release Mask"),1)); + mi = Gtk::manage(new Gtk::MenuItem(_("Release Mask"), 1)); mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::ReleaseMask)); if (MaskRefOK) { mi->set_sensitive(TRUE); @@ -1758,7 +1758,7 @@ void ContextMenu::MakeItemMenu (void) append(*mi); /* Set Clip */ - mi = manage(new Gtk::MenuItem(_("Set Cl_ip"),1)); + mi = Gtk::manage(new Gtk::MenuItem(_("Set Cl_ip"), 1)); mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::SetClip)); if (ClipRefOK || MaskRefOK) { mi->set_sensitive(FALSE); @@ -1769,7 +1769,7 @@ void ContextMenu::MakeItemMenu (void) append(*mi); /* Release Clip */ - mi = manage(new Gtk::MenuItem(_("Release C_lip"),1)); + mi = Gtk::manage(new Gtk::MenuItem(_("Release C_lip"), 1)); mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::ReleaseClip)); if (ClipRefOK) { mi->set_sensitive(TRUE); @@ -1780,7 +1780,7 @@ void ContextMenu::MakeItemMenu (void) append(*mi); /* Group */ - mi = manage(new Gtk::MenuItem(_("_Group"),1)); + mi = Gtk::manage(new Gtk::MenuItem(_("_Group"), 1)); mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::ActivateGroup)); if (_desktop->selection->isEmpty() || _desktop->selection->single()) { mi->set_sensitive(FALSE); @@ -1882,7 +1882,7 @@ void ContextMenu::ReleaseClip(void) void ContextMenu::MakeGroupMenu(void) { /* Ungroup */ - Gtk::MenuItem* mi = manage(new Gtk::MenuItem(_("_Ungroup"),1)); + Gtk::MenuItem* mi = Gtk::manage(new Gtk::MenuItem(_("_Ungroup"), 1)); mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::ActivateUngroup)); mi->show(); append(*mi); @@ -1907,19 +1907,19 @@ void ContextMenu::MakeAnchorMenu(void) Gtk::MenuItem* mi; /* Link dialog */ - mi = manage(new Gtk::MenuItem(_("Link _Properties..."),1)); + mi = Gtk::manage(new Gtk::MenuItem(_("Link _Properties..."), 1)); mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::AnchorLinkProperties)); mi->show(); insert(*mi,positionOfLastDialog++); /* Select item */ - mi = manage(new Gtk::MenuItem(_("_Follow Link"),1)); + mi = Gtk::manage(new Gtk::MenuItem(_("_Follow Link"), 1)); mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::AnchorLinkFollow)); mi->show(); append(*mi); /* Reset transformations */ - mi = manage(new Gtk::MenuItem(_("_Remove Link"),1)); + mi = Gtk::manage(new Gtk::MenuItem(_("_Remove Link"), 1)); mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::AnchorLinkRemove)); mi->show(); append(*mi); @@ -1961,13 +1961,13 @@ void ContextMenu::MakeImageMenu (void) const gchar *href = ir->attribute("xlink:href"); /* Image properties */ - mi = manage(new Gtk::MenuItem(_("Image _Properties..."),1)); + mi = Gtk::manage(new Gtk::MenuItem(_("Image _Properties..."), 1)); mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::ImageProperties)); mi->show(); insert(*mi,positionOfLastDialog++); /* Edit externally */ - mi = manage(new Gtk::MenuItem(_("Edit Externally..."),1)); + mi = Gtk::manage(new Gtk::MenuItem(_("Edit Externally..."), 1)); mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::ImageEdit)); mi->show(); insert(*mi,positionOfLastDialog++); @@ -1976,7 +1976,7 @@ void ContextMenu::MakeImageMenu (void) } /* Trace Bitmap */ - mi = manage(new Gtk::MenuItem(_("_Trace Bitmap..."),1)); + mi = Gtk::manage(new Gtk::MenuItem(_("_Trace Bitmap..."), 1)); mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::ImageTraceBitmap)); mi->show(); insert(*mi,positionOfLastDialog++); @@ -1985,7 +1985,7 @@ void ContextMenu::MakeImageMenu (void) } /* Trace Pixel Art */ - mi = manage(new Gtk::MenuItem(_("Trace Pixel Art"),1)); + mi = Gtk::manage(new Gtk::MenuItem(_("Trace Pixel Art"), 1)); mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::ImageTracePixelArt)); mi->show(); insert(*mi,positionOfLastDialog++); @@ -1995,7 +1995,7 @@ void ContextMenu::MakeImageMenu (void) /* Embed image */ if (Inkscape::Verb::getbyid( "org.ekips.filter.embedselectedimages" )) { - mi = manage(new Gtk::MenuItem(C_("Context menu", "Embed Image"))); + mi = Gtk::manage(new Gtk::MenuItem(C_("Context menu", "Embed Image"))); mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::ImageEmbed)); mi->show(); insert(*mi,positionOfLastDialog++); @@ -2006,7 +2006,7 @@ void ContextMenu::MakeImageMenu (void) /* Extract image */ if (Inkscape::Verb::getbyid( "org.ekips.filter.extractimage" )) { - mi = manage(new Gtk::MenuItem(C_("Context menu", "Extract Image..."))); + mi = Gtk::manage(new Gtk::MenuItem(C_("Context menu", "Extract Image..."))); mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::ImageExtract)); mi->show(); insert(*mi,positionOfLastDialog++); @@ -2151,7 +2151,7 @@ void ContextMenu::MakeShapeMenu (void) Gtk::MenuItem* mi; /* Item dialog */ - mi = manage(new Gtk::MenuItem(_("_Fill and Stroke..."),1)); + mi = Gtk::manage(new Gtk::MenuItem(_("_Fill and Stroke..."), 1)); mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::FillSettings)); mi->show(); insert(*mi,positionOfLastDialog++); @@ -2171,19 +2171,19 @@ void ContextMenu::MakeTextMenu (void) Gtk::MenuItem* mi; /* Fill and Stroke dialog */ - mi = manage(new Gtk::MenuItem(_("_Fill and Stroke..."),1)); + mi = Gtk::manage(new Gtk::MenuItem(_("_Fill and Stroke..."), 1)); mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::FillSettings)); mi->show(); insert(*mi,positionOfLastDialog++); /* Edit Text dialog */ - mi = manage(new Gtk::MenuItem(_("_Text and Font..."),1)); + mi = Gtk::manage(new Gtk::MenuItem(_("_Text and Font..."), 1)); mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::TextSettings)); mi->show(); insert(*mi,positionOfLastDialog++); /* Spellcheck dialog */ - mi = manage(new Gtk::MenuItem(_("Check Spellin_g..."),1)); + mi = Gtk::manage(new Gtk::MenuItem(_("Check Spellin_g..."), 1)); mi->signal_activate().connect(sigc::mem_fun(*this, &ContextMenu::SpellcheckSettings)); mi->show(); insert(*mi,positionOfLastDialog++); 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); diff --git a/src/widgets/stroke-style.cpp b/src/widgets/stroke-style.cpp index 9567f81ba..a4cca9472 100644 --- a/src/widgets/stroke-style.cpp +++ b/src/widgets/stroke-style.cpp @@ -114,7 +114,7 @@ StrokeStyle::StrokeStyleButton::StrokeStyleButton(Gtk::RadioButtonGroup &grp, show(); set_mode(false); - Gtk::Widget *px = manage(Glib::wrap(sp_icon_new(Inkscape::ICON_SIZE_LARGE_TOOLBAR, icon))); + Gtk::Widget *px = Gtk::manage(Glib::wrap(sp_icon_new(Inkscape::ICON_SIZE_LARGE_TOOLBAR, icon))); g_assert(px != NULL); px->show(); add(*px); @@ -198,7 +198,7 @@ StrokeStyle::StrokeStyle() : hb->pack_start(*widthSpin, false, false, 0); unitSelector = new Inkscape::UI::Widget::UnitMenu(); unitSelector->setUnitType(Inkscape::Util::UNIT_TYPE_LINEAR); - Gtk::Widget *us = manage(unitSelector); + Gtk::Widget *us = Gtk::manage(unitSelector); SPDesktop *desktop = SP_ACTIVE_DESKTOP; unitSelector->addUnit(*unit_table.getUnit("%")); @@ -328,7 +328,7 @@ StrokeStyle::StrokeStyle() : // implement a set_mnemonic_source function in the // SPDashSelector class, so that we do not have to // expose any of the underlying widgets? - dashSelector = manage(new SPDashSelector); + dashSelector = Gtk::manage(new SPDashSelector); dashSelector->show(); @@ -354,7 +354,7 @@ StrokeStyle::StrokeStyle() : hb = spw_hbox(table, 1, 1, i); i++; - startMarkerCombo = manage(new MarkerComboBox("marker-start", SP_MARKER_LOC_START)); + startMarkerCombo = Gtk::manage(new MarkerComboBox("marker-start", SP_MARKER_LOC_START)); startMarkerCombo->set_tooltip_text(_("Start Markers are drawn on the first node of a path or shape")); startMarkerConn = startMarkerCombo->signal_changed().connect( sigc::bind( @@ -363,7 +363,7 @@ StrokeStyle::StrokeStyle() : hb->pack_start(*startMarkerCombo, true, true, 0); - midMarkerCombo = manage(new MarkerComboBox("marker-mid", SP_MARKER_LOC_MID)); + midMarkerCombo = Gtk::manage(new MarkerComboBox("marker-mid", SP_MARKER_LOC_MID)); midMarkerCombo->set_tooltip_text(_("Mid Markers are drawn on every node of a path or shape except the first and last nodes")); midMarkerConn = midMarkerCombo->signal_changed().connect( sigc::bind( @@ -372,7 +372,7 @@ StrokeStyle::StrokeStyle() : hb->pack_start(*midMarkerCombo, true, true, 0); - endMarkerCombo = manage(new MarkerComboBox("marker-end", SP_MARKER_LOC_END)); + endMarkerCombo = Gtk::manage(new MarkerComboBox("marker-end", SP_MARKER_LOC_END)); endMarkerCombo->set_tooltip_text(_("End Markers are drawn on the last node of a path or shape")); endMarkerConn = endMarkerCombo->signal_changed().connect( sigc::bind( -- cgit v1.2.3