From bc0ad0c871071256edca595cc45d9ec040ae621c Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Mon, 24 Dec 2018 14:19:30 +0100 Subject: Add inkFlowBox widget and apply to XML inspector --- src/ui/CMakeLists.txt | 5 +- src/ui/dialog/xml-tree.cpp | 16 ++--- src/ui/dialog/xml-tree.h | 10 +-- src/ui/widget/ink-flow-box.cpp | 142 +++++++++++++++++++++++++++++++++++++++++ src/ui/widget/ink-flow-box.h | 65 +++++++++++++++++++ 5 files changed, 220 insertions(+), 18 deletions(-) create mode 100644 src/ui/widget/ink-flow-box.cpp create mode 100644 src/ui/widget/ink-flow-box.h (limited to 'src') diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt index 699f85304..f4d5640bd 100644 --- a/src/ui/CMakeLists.txt +++ b/src/ui/CMakeLists.txt @@ -16,7 +16,6 @@ set(ui_SRC tools-switch.cpp util.cpp uxmanager.cpp - cache/svg_preview_cache.cpp tool/control-point-selection.cpp @@ -153,7 +152,7 @@ set(ui_SRC widget/color-icc-selector.cpp widget/color-notebook.cpp widget/color-picker.cpp - widget/color-preview.cpp icon-loader.cpp + widget/color-preview.cpp widget/color-scales.cpp widget/color-slider.cpp widget/color-wheel-selector.cpp @@ -172,6 +171,7 @@ set(ui_SRC widget/highlight-picker.cpp widget/imagetoggler.cpp widget/ink-color-wheel.cpp + widget/ink-flow-box.cpp widget/ink-select-one-action.cpp widget/ink-spinscale.cpp widget/insertordericon.cpp @@ -397,6 +397,7 @@ set(ui_SRC widget/insertordericon.h widget/imagetoggler.h widget/ink-color-wheel.h + widget/ink-flow-box.h widget/ink-select-one-action.h widget/ink-spinscale.h widget/labelled.h diff --git a/src/ui/dialog/xml-tree.cpp b/src/ui/dialog/xml-tree.cpp index d6173c7b6..488bc8246 100644 --- a/src/ui/dialog/xml-tree.cpp +++ b/src/ui/dialog/xml-tree.cpp @@ -78,8 +78,7 @@ XmlTree::XmlTree() : if (!desktop) { return; } - - notebook_content = new Gtk::Notebook(); + flowbox_content = Gtk::manage(new Inkscape::UI::Widget::InkFlowBox("XMLFlow")); Gtk::Box *contents = _getContents(); contents->set_spacing(0); @@ -93,7 +92,7 @@ XmlTree::XmlTree() : status_box.pack_start( status, TRUE, TRUE, 0); contents->pack_end(status_box, false, false, 2); - contents->pack_start(*notebook_content, true, true, 0); + contents->pack_start(*flowbox_content, true, true, 0); _message_stack = std::make_shared(); _message_context = std::unique_ptr(new Inkscape::MessageContext(_message_stack)); @@ -101,9 +100,7 @@ XmlTree::XmlTree() : sigc::bind(sigc::ptr_fun(_set_status_message), GTK_WIDGET(status.gobj()))); /* tree view */ - notebook_content->insert_page(node_box, _("_Nodes"), NOTEBOOK_PAGE_NODES, true); - notebook_content->set_tab_detachable(node_box, true); - + flowbox_content->insert(&node_box, _("_Nodes"), FLOWBOX_PAGE_NODES, true, -1); tree = SP_XMLVIEW_TREE(sp_xmlview_tree_new(nullptr, nullptr, nullptr)); gtk_widget_set_tooltip_text( GTK_WIDGET(tree), _("Drag to reorder nodes") ); @@ -185,8 +182,7 @@ XmlTree::XmlTree() : /* attributes */ attributes = new AttrDialog; attr_box.pack_start(*attributes); - notebook_content->insert_page(attr_box, _("_Attributes"), NOTEBOOK_PAGE_ATTRS, true); - notebook_content->set_tab_detachable(attr_box, true); + flowbox_content->insert(&attr_box, _("_Attributes"), FLOWBOX_PAGE_ATTRS, false, 200); /* Signal handlers */ GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(tree)); @@ -207,15 +203,13 @@ XmlTree::XmlTree() : styles = new CssDialog; css_box.pack_start(*styles); - notebook_content->insert_page(css_box, _("_Styles"), NOTEBOOK_PAGE_STYLES, true); - notebook_content->set_tab_detachable(css_box, true); + flowbox_content->insert(&css_box, _("_Styles"), FLOWBOX_PAGE_STYLES, false, 200); desktopChangeConn = deskTrack.connectDesktopChanged( sigc::mem_fun(*this, &XmlTree::set_tree_desktop) ); deskTrack.connect(GTK_WIDGET(gobj())); /* initial show/hide */ show_all(); - tree_reset_context(); g_assert(desktop != nullptr); diff --git a/src/ui/dialog/xml-tree.h b/src/ui/dialog/xml-tree.h index 14144cacd..4a98100a8 100644 --- a/src/ui/dialog/xml-tree.h +++ b/src/ui/dialog/xml-tree.h @@ -16,12 +16,12 @@ #include #include "ui/widget/panel.h" +#include "ui/widget/ink-flow-box.h" #include #include #include #include #include -#include #include #include @@ -183,11 +183,11 @@ private: gint blocked; /* Each of the notebook page type (by number) */ - Gtk::Notebook *notebook_content; + UI::Widget::InkFlowBox *flowbox_content; enum { - NOTEBOOK_PAGE_NODES, - NOTEBOOK_PAGE_ATTRS, - NOTEBOOK_PAGE_STYLES, + FLOWBOX_PAGE_NODES, + FLOWBOX_PAGE_ATTRS, + FLOWBOX_PAGE_STYLES, }; /** diff --git a/src/ui/widget/ink-flow-box.cpp b/src/ui/widget/ink-flow-box.cpp new file mode 100644 index 000000000..b96c922cf --- /dev/null +++ b/src/ui/widget/ink-flow-box.cpp @@ -0,0 +1,142 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Notebook page widget. + * + * Author: + * Bryce Harrington + * + * Copyright (C) 2004 Bryce Harrington + * + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" // only include where actually required! +#endif + +#include "preferences.h" +#include "ui/widget/ink-flow-box.h" +#include "ui/icon-loader.h" +#include + +namespace Inkscape { +namespace UI { +namespace Widget { + +InkFlowBox::InkFlowBox(const gchar * name) +{ + set_name(name); + //_flowbox.set_homogeneous(); + this->pack_start(_controller, false, false, 0); + this->pack_start(_flowbox, true, true, 0); + _flowbox.set_activate_on_single_click(true); + Gtk::ToggleButton *tbutton = new Gtk::ToggleButton("", false); + tbutton->set_always_show_image(true); + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + tbutton->set_active(prefs->getBool(Glib::ustring("/dialogs/") + get_name() + Glib::ustring("/flowbox/lock/"), true)); + Glib::ustring iconname = "object-unlocked"; + if(tbutton->get_active()) { + iconname = "object-locked"; + } + tbutton->set_image(*sp_get_icon_image(iconname, Gtk::ICON_SIZE_MENU)); + tbutton->signal_toggled().connect(sigc::bind< Gtk::ToggleButton* >(sigc::mem_fun (*this, &InkFlowBox::on_global_toggle), tbutton) ); + _controller.pack_start(*tbutton); + tbutton->show(); + showing = 0; + sensitive = true; +} + +InkFlowBox::~InkFlowBox() {} + +Glib::ustring +InkFlowBox::getPrefsPath(gint pos) { + return Glib::ustring("/dialogs/") + get_name() + Glib::ustring("/flowbox/index_") + std::to_string(pos); +} + +bool +InkFlowBox::on_filter(Gtk::FlowBoxChild* child) { + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + if(prefs->getBool(getPrefsPath(child->get_index()), true)) { + showing ++; + return true; + } + return false; +} + +void +InkFlowBox::on_toggle(gint pos, Gtk::ToggleButton *tbutton) { + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + bool global = prefs->getBool(Glib::ustring("/dialogs/") + get_name() + Glib::ustring("/flowbox/lock"), true); + if (global && sensitive) { + sensitive = false; + bool active = true; + for (auto child:tbutton->get_parent()->get_children()) { + if (tbutton != child) { + dynamic_cast(child)->set_active(active); + active = false; + } + } + prefs->setBool(getPrefsPath(pos), true); + tbutton->set_active(true); + sensitive = true; + } else { + prefs->setBool(getPrefsPath(pos), tbutton->get_active()); + } + showing = 0; + _flowbox.set_filter_func(sigc::mem_fun (*this, &InkFlowBox::on_filter)); + _flowbox.set_max_children_per_line(showing); +} + +void +InkFlowBox::on_global_toggle(Gtk::ToggleButton *tbutton) { + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->setBool(Glib::ustring("/dialogs/") + get_name() + Glib::ustring("/flowbox/lock"), tbutton->get_active()); + sensitive = true; + if (tbutton->get_active()) { + sensitive = false; + bool active = true; + for (auto child:tbutton->get_parent()->get_children()) { + if (tbutton != child) { + dynamic_cast(child)->set_active(active); + active = false; + } + } + } + Glib::ustring iconname = "object-unlocked"; + if(tbutton->get_active()) { + iconname = "object-locked"; + } + tbutton->set_image(*sp_get_icon_image(iconname, Gtk::ICON_SIZE_MENU)); + sensitive = true; +} + +void +InkFlowBox::insert(Gtk::Widget *widget, Glib::ustring label, gint pos, bool active, int minwidth){ + Gtk::ToggleButton *tbutton = new Gtk::ToggleButton(label, true); + tbutton->set_active(active); + tbutton->signal_toggled().connect(sigc::bind(sigc::mem_fun (*this, &InkFlowBox::on_toggle),pos, tbutton) ); + _controller.pack_start(*tbutton); + tbutton->show(); + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->setBool(getPrefsPath(pos), active); + widget->set_size_request(minwidth,-1); + _flowbox.insert(*widget, pos); + showing = 0; + _flowbox.set_filter_func(sigc::mem_fun (*this, &InkFlowBox::on_filter) ); + _flowbox.set_max_children_per_line(showing); +} + +} // namespace Widget +} // 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/widget/ink-flow-box.h b/src/ui/widget/ink-flow-box.h new file mode 100644 index 000000000..3128ec39f --- /dev/null +++ b/src/ui/widget/ink-flow-box.h @@ -0,0 +1,65 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Author: + * Bryce Harrington + * + * Copyright (C) 2004 Bryce Harrington + * + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#ifndef INKSCAPE_INK_FLOW_BOX_H +#define INKSCAPE_INK_FLOW_BOX_H + +#include +#include +#include +#include +#include +#include + +namespace Inkscape { +namespace UI { +namespace Widget { + +/** + * A tabbed notebook page for dialogs. + */ + +class InkFlowBox : public Gtk::VBox { +public: + InkFlowBox(const gchar * name); + ~InkFlowBox() override; + void insert(Gtk::Widget *widget, Glib::ustring label, gint pos, bool active, int minwidth); + void on_toggle(gint pos, Gtk::ToggleButton *tbutton); + void on_global_toggle(Gtk::ToggleButton *tbutton); + void set_visible(gint pos, bool visible); + bool on_filter(Gtk::FlowBoxChild* child); + Glib::ustring getPrefsPath(gint pos); + /** + * Construct a InkFlowBox. + */ + +private: + Gtk::FlowBox _flowbox; + Gtk::ActionBar _controller; + gint showing; + bool sensitive; +}; + +} // namespace Widget +} // namespace UI +} // namespace Inkscape + +#endif // INKSCAPE_INK_FLOW_BOX_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