17#include <glibmm/i18n.h>
18#include <glibmm/regex.h>
20#include <gtkmm/comboboxtext.h>
21#include <gtkmm/entry.h>
22#include <gtkmm/entrycompletion.h>
23#include <gtkmm/label.h>
24#include <gtkmm/liststore.h>
25#include <gtkmm/popover.h>
26#include <gtkmm/separator.h>
27#include <sigc++/functors/mem_fun.h>
48class SearchCols :
public Gtk::TreeModel::ColumnRecord
58 Gtk::TreeModelColumn<Glib::ustring>
name;
59 Gtk::TreeModelColumn<Glib::ustring>
label;
60 Gtk::TreeModelColumn<Glib::ustring> key;
87 set_name(
"PageToolbar");
91 get_object<Gtk::EntryCompletion>(
builder,
"_sizes_searcher")
92 ->signal_match_selected()
94 [
this] (Gtk::TreeModel::iterator
const &iter) {
96 Gtk::TreeModel::Row row = *iter;
97 Glib::ustring preset_key = row[cols.key];
127 dynamic_cast<Gtk::Entry &
>(*
_combo_page_sizes.get_child()).set_completion(get_object<Gtk::EntryCompletion>(
builder,
"_sizes_searcher"));
132 if (!preset_key.empty()) {
141 _entry_page_sizes->set_tooltip_text(_(
"Type in width & height of a page. (ex.: 15x10cm, 10in x 100mm)\n"
142 "or choose preset from dropdown."));
146 _entry_page_sizes->signal_icon_press().connect([
this] (Gtk::Entry::IconPosition) {
151 _entry_page_sizes->set_icon_tooltip_text(_(
"Change page orientation"), Gtk::Entry::IconPosition::SECONDARY);
155 auto const display_only = !has_focus();
207 for (
auto tmod : extensions) {
208 if (!tmod->can_resize())
210 for (
auto preset : tmod->get_presets()) {
211 auto label = preset->get_label();
217 row[cols.name] = _(preset->get_name().c_str());
218 row[cols.label] =
" <small><span fgalpha=\"50%\">" +
label +
"</span></small>";
219 row[cols.key] = preset->get_key();
224 row[cols.name] = _(preset->get_name().c_str());
225 row[cols.label] =
label;
226 row[cols.key] = preset->get_key();
236 page->setLabel(text.empty() ?
nullptr : text.c_str());
249 if (
auto page = pm.getSelected()) {
250 page->setBleed(text);
264 if (
auto page = pm.getSelected()) {
265 page->setMargin(text);
293 if (
auto page = pm.getSelected()) {
294 page->setMarginSide(side, value,
false);
307 std::string orient = p_rect.
width() > p_rect.height() ?
"land" :
"port";
309 auto page = pm.getSelected();
311 {
"orientation", orient},
314 page->setSizeLabel(preset->get_name());
329 std::string
const &backup)
332 std::replace(number.begin(), number.end(),
',',
'.');
333 double value = std::stod(number);
336 if (unit_str.empty() && !backup.empty())
338 if (unit_str ==
"\"")
347 if (!unit_str.empty())
369 auto pos1 = cb_text.find_first_of(
"(");
370 auto pos2 = cb_text.find_first_of(
")");
371 if (pos1 != cb_text.npos && pos2 != cb_text.npos && pos1 < pos2) {
372 cb_text = cb_text.substr(pos1+1, pos2-pos1-1);
376 static auto const arg =
"([0-9]+[\\.,]?[0-9]*|\\.[0-9]+) ?(px|mm|cm|m|in|\\\"|ft|')?";
377 static auto const regex = Glib::Regex::create(Glib::ustring{
"^ *"} + arg +
" *([ *Xx×,\\-]) *" + arg +
" *$", Glib::Regex::CompileFlags::OPTIMIZE);
379 Glib::MatchInfo match;
380 if (regex->match(cb_text, match)) {
382 auto const width_unit = match.fetch(2);
383 auto const height_unit = match.fetch(5);
409 if (
label == row[cols.name].operator Glib::ustring().raw()) {
418 auto const icon = box.width() > box.height() ?
"page-landscape" :
"page-portrait";
419 if (box.width() == box.height()) {
422 _entry_page_sizes->set_icon_from_icon_name(INKSCAPE_ICON(icon), Gtk::Entry::IconPosition::SECONDARY);
468 auto label = Glib::ustring::compose(_(
"%1/%2"),
page->getPagePosition(), page_manager.getPageCount());
472 if (
auto page = cast<SPPage>(obj)) {
474 if (flags & SP_OBJECT_MODIFIED_FLAG) {
489 if (!page_manager.hasPrevPage() && !page_manager.hasNextPage()) {
490 _sep1.set_visible(
false);
498 _sep1.set_visible(
true);
C width() const
Get the horizontal extent of the rectangle.
static void done(SPDocument *document, Glib::ustring const &event_description, Glib::ustring const &undo_icon, unsigned int object_modified_tag=0)
static void maybeDone(SPDocument *document, const gchar *keyconst, Glib::ustring const &event_description, Glib::ustring const &undo_icon, unsigned int object_modified_tag=0)
TemplateList & get_template_list(TemplateList &ou_list)
Create a list of all the Template extensions.
std::list< Template * > TemplateList
static std::shared_ptr< TemplatePreset > get_any_preset(const std::string &key)
Return the template preset based on the key from any template class (static method).
sigc::connection connectPagesChanged(const sigc::slot< void()> &slot)
void changeOrientation()
Change page orientation, landscape to portrait and back.
void enablePages()
Enables multi page support by turning the document viewBox into the first page.
std::string getSizeLabel(SPPage *page=nullptr)
Return a page's size label, or match via width and height.
Geom::Rect getSelectedPageRect() const
Returns the selected page rect, OR the viewbox rect.
SPPage * getSelected() const
void resizePage(double width, double height)
sigc::scoped_connection _pages_changed
Gtk::Label & _label_page_pos
Inkscape::UI::Widget::MathSpinButton & _margin_left
Inkscape::UI::Widget::MathSpinButton & _margin_bottom
void setDesktop(SPDesktop *desktop) override
Glib::RefPtr< Gtk::ListStore > _sizes_list
sigc::scoped_connection _doc_connection
Inkscape::UI::Widget::MathSpinButton & _margin_top
sigc::scoped_connection _label_edited
void selectionChanged(SPPage *page)
void sizeChoose(const std::string &preset_key)
Glib::RefPtr< Gtk::ListStore > _sizes_search
Gtk::Button & _btn_move_toggle
Gtk::Button & _btn_page_backward
Gtk::Entry * _entry_page_sizes
void populate_sizes()
Take all selectable page sizes and add to search and dropdowns.
void marginBottomEdited()
void setSizeText(SPPage *page=nullptr, bool display_only=true)
Sets the size of the current page into the entry page size.
sigc::scoped_connection _page_modified
Gtk::Entry & _text_page_label
Gtk::Entry & _text_page_margins
Gtk::ComboBoxText & _combo_page_sizes
sigc::scoped_connection _size_edited
double _unit_to_size(std::string number, std::string unit_str, std::string const &backup)
Convert the parsed sections of a text input into a desktop pixel value.
Gtk::Popover & _margin_popover
Gtk::Button & _btn_page_delete
void marginSideEdited(int side, const Glib::ustring &value)
Inkscape::UI::Widget::MathSpinButton & _margin_right
void setMarginText(SPPage *page=nullptr)
void sizeChanged()
A manually typed input size, parse out what we can understand from the text or ignore it if the text ...
Gtk::Entry & _text_page_bleeds
sigc::scoped_connection _page_selected
Gtk::Button & _btn_page_foreward
static double convert(double from_dist, Unit const *from, Unit const *to)
Convert distances.
Unit const * getUnit(Glib::ustring const &name) const
Retrieve a given unit based on its string identifier.
To do: update description of desktop.
sigc::connection connectDocumentReplaced(F &&slot)
SPDocument * getDocument() const
Typed SVG document implementation.
Geom::OptRect preferredBounds() const
sigc::connection connectModified(ModifiedSignal::slot_type slot)
Inkscape::PageManager & getPageManager()
Geom::Scale getDocumentScale(bool computed=true) const
Returns document scale as defined by width/height (in pixels) and viewBox (real world to user-units).
Inkscape::Util::Unit const * getDisplayUnit()
guaranteed not to return nullptr
SPObject is an abstract base class of all of the document nodes at the SVG document level.
Editable view implementation.
TODO: insert short description here.
Macro for icon names used in Inkscape.
DB db
This is the actual database object.
Glib::RefPtr< Ob > get_object(Glib::RefPtr< Gtk::Builder > const &builder, char const *id)
static void popup_at(Gtk::Popover &popover, Gtk::Widget &widget, double const x_offset, double const y_offset, int width, int height)
W & get_widget(const Glib::RefPtr< Gtk::Builder > &builder, const char *id)
W & get_derived_widget(const Glib::RefPtr< Gtk::Builder > &builder, const char *id, Args &&... args)
Glib::RefPtr< Gtk::Builder > create_builder(const char *filename)
Inkscape::IO::Resource - simple resource API.
Glib::RefPtr< Gtk::Builder > builder