index ea0efeb2d48c12b4deb0d338939fc7a277df3d39..1f3749bda0e6b2763e2e545dc503b001544f2d0a 100644 (file)
#endif
#include <cmath>
+#include <gtkmm.h>
#include <gtkmm/optionmenu.h>
#include <gtkmm/frame.h>
#include <gtkmm/table.h>
+#include "ui/widget/button.h"
#include "ui/widget/scalar-unit.h"
#include "helper/units.h"
#include "inkscape.h"
+#include "verbs.h"
#include "desktop-handles.h"
#include "document.h"
+#include "desktop.h"
#include "page-sizer.h"
+#include "helper/action.h"
using std::pair;
{
Gtk::HBox *hbox_size = manage (new Gtk::HBox (false, 4));
pack_start (*hbox_size, false, false, 0);
- Gtk::Label *label_size = manage (new Gtk::Label (_("Page size:"), 1.0, 0.5));
+ Gtk::Label *label_size = manage (new Gtk::Label (_("P_age size:"), 1.0, 0.5));
+ label_size->set_use_underline();
hbox_size->pack_start (*label_size, false, false, 0);
_omenu_size = manage (new Gtk::OptionMenu);
+ label_size->set_mnemonic_widget (*_omenu_size);
hbox_size->pack_start (*_omenu_size, true, true, 0);
Gtk::Menu *menu_size = manage (new Gtk::Menu);
pack_start (*hbox_ori, false, false, 0);
Gtk::Label *label_ori = manage (new Gtk::Label (_("Page orientation:"), 0.0, 0.5));
hbox_ori->pack_start (*label_ori, false, false, 0);
- _rb_land = manage (new Gtk::RadioButton (_("Landscape")));
+ _rb_land = manage (new Gtk::RadioButton (_("_Landscape"), true));
Gtk::RadioButton::Group group = _rb_land->get_group();
hbox_ori->pack_end (*_rb_land, false, false, 5);
- _rb_port = manage (new Gtk::RadioButton (_("Portrait")));
+ _rb_port = manage (new Gtk::RadioButton (_("_Portrait"), true));
hbox_ori->pack_end (*_rb_port, false, false, 5);
_rb_port->set_group (group);
_rb_port->set_active (true);
/* Custom paper frame */
Gtk::Frame *frame = manage (new Gtk::Frame(_("Custom size")));
pack_start (*frame, false, false, 0);
- Gtk::Table *table = manage (new Gtk::Table (4, 2, false));
+ Gtk::Table *table = manage (new Gtk::Table (5, 2, false));
table->set_border_width (4);
table->set_row_spacings (4);
table->set_col_spacings (4);
+
+ Inkscape::UI::Widget::Button* fit_canv = manage(new Inkscape::UI::Widget::Button(_("Fit page to selection"),
+ _("Resize the page to fit the current selection, or the entire drawing if there is no selection")));
+ // prevent fit_canv from expanding
+ Gtk::Alignment *fit_canv_cont = manage(new Gtk::Alignment(1.0,0.5,0.0,0.0));
+ fit_canv_cont->add(*fit_canv);
+
frame->add (*table);
_wr = ®
- _rum.init (_("Units:"), "units", *_wr);
- _rusw.init (_("Width:"), _("Width of paper"), "width", _rum, *_wr);
- _rush.init (_("Height:"), _("Height of paper"), "height", _rum, *_wr);
+ _rum.init (_("U_nits:"), "units", *_wr);
+ _rusw.init (_("_Width:"), _("Width of paper"), "width", _rum, *_wr);
+ _rush.init (_("_Height:"), _("Height of paper"), "height", _rum, *_wr);
table->attach (*_rum._label, 0,1,0,1, Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
table->attach (*_rum._sel, 1,2,0,1, Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
table->attach (*_rusw.getSU(), 0,2,1,2, Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
table->attach (*_rush.getSU(), 0,2,2,3, Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
+ table->attach (*fit_canv_cont, 0,2,3,4, Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
_landscape_connection = _rb_land->signal_toggled().connect (sigc::mem_fun (*this, &PageSizer::on_landscape));
_portrait_connection = _rb_port->signal_toggled().connect (sigc::mem_fun (*this, &PageSizer::on_portrait));
_changedw_connection = _rusw.getSU()->signal_value_changed().connect (sigc::mem_fun (*this, &PageSizer::on_value_changed));
_changedh_connection = _rush.getSU()->signal_value_changed().connect (sigc::mem_fun (*this, &PageSizer::on_value_changed));
+ fit_canv->signal_clicked().connect(sigc::mem_fun(*this, &PageSizer::fire_fit_canvas_to_selection_or_drawing));
show_all_children();
}
if (!SP_ACTIVE_DESKTOP || _wr->isUpdating())
return;
- SPDocument *doc = SP_DT_DOCUMENT(SP_ACTIVE_DESKTOP);
+ SPDocument *doc = sp_desktop_document(SP_ACTIVE_DESKTOP);
sp_document_set_width (doc, _rusw.getSU()->getValue("px"), &_px_unit);
sp_document_set_height (doc, _rush.getSU()->getValue("px"), &_px_unit);
sp_document_done (doc);
return -1;
}
+void
+PageSizer::fire_fit_canvas_to_selection_or_drawing() {
+ SPDesktop *dt = SP_ACTIVE_DESKTOP;
+ if (!dt) return;
+ Verb *verb = Verb::get( SP_VERB_FIT_CANVAS_TO_SELECTION_OR_DRAWING );
+ if (verb) {
+ SPAction *action = verb->get_action(dt);
+ if (action) {
+ sp_action_perform(action, NULL);
+ }
+ }
+}
+
void
PageSizer::on_portrait()
{