diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/extension/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/extension/prefdialog/widget-box.cpp | 6 | ||||
| -rw-r--r-- | src/extension/prefdialog/widget-separator.cpp | 1 | ||||
| -rw-r--r-- | src/extension/prefdialog/widget-spacer.cpp | 65 | ||||
| -rw-r--r-- | src/extension/prefdialog/widget-spacer.h | 60 | ||||
| -rw-r--r-- | src/extension/prefdialog/widget.cpp | 5 |
6 files changed, 138 insertions, 1 deletions
diff --git a/src/extension/CMakeLists.txt b/src/extension/CMakeLists.txt index a82ff3fbe..032b9cd4c 100644 --- a/src/extension/CMakeLists.txt +++ b/src/extension/CMakeLists.txt @@ -65,6 +65,7 @@ set(extension_SRC prefdialog/widget-box.cpp prefdialog/widget-label.cpp prefdialog/widget-separator.cpp + prefdialog/widget-spacer.cpp # ------ # Header @@ -142,6 +143,7 @@ set(extension_SRC prefdialog/widget-box.h prefdialog/widget-label.h prefdialog/widget-separator.h + prefdialog/widget-spacer.h ) if(WIN32) diff --git a/src/extension/prefdialog/widget-box.cpp b/src/extension/prefdialog/widget-box.cpp index d7b93e3ff..2c9d24f4a 100644 --- a/src/extension/prefdialog/widget-box.cpp +++ b/src/extension/prefdialog/widget-box.cpp @@ -84,6 +84,12 @@ Gtk::Widget *WidgetBox::get_widget(sigc::signal<void> *changeSignal) // revisit this later, possibly implementing GtkFrame or similar box->set_spacing(GUI_BOX_SPACING); + if (_orientation == HORIZONTAL) { + box->set_vexpand(false); + } else { + box->set_hexpand(false); + } + // add child widgets onto page (if any) for (auto child : _children) { Gtk::Widget *child_widget = child->get_widget(changeSignal); diff --git a/src/extension/prefdialog/widget-separator.cpp b/src/extension/prefdialog/widget-separator.cpp index 94778e027..d78894b62 100644 --- a/src/extension/prefdialog/widget-separator.cpp +++ b/src/extension/prefdialog/widget-separator.cpp @@ -35,6 +35,7 @@ Gtk::Widget *WidgetSeparator::get_widget(sigc::signal<void> *changeSignal) Gtk::Separator *separator = Gtk::manage(new Gtk::Separator()); separator->show(); + return dynamic_cast<Gtk::Widget *>(separator); } diff --git a/src/extension/prefdialog/widget-spacer.cpp b/src/extension/prefdialog/widget-spacer.cpp new file mode 100644 index 000000000..350aeb4f2 --- /dev/null +++ b/src/extension/prefdialog/widget-spacer.cpp @@ -0,0 +1,65 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/** @file + * Spacer widget for extensions + *//* + * Authors: + * Patrick Storz <eduard.braun2@gmx.de> + * + * Copyright (C) 2019 Authors + * + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#include "widget-spacer.h" + +#include <gtkmm/box.h> + +#include "xml/node.h" +#include "extension/extension.h" + +namespace Inkscape { +namespace Extension { + + +WidgetSpacer::WidgetSpacer(Inkscape::XML::Node *xml, Inkscape::Extension::Extension *ext) + : InxWidget(xml, ext) +{ + // get size + const char *size = xml->attribute("size"); + if (size) { + _size = strtol(size, nullptr, 0); + if (_size == 0) { + if (!strcmp(size, "expand")) { + _expand = true; + } else { + g_warning("Invalid value ('%s') for size spacer in extension '%s'", size, _extension->get_id()); + } + } + } +} + +/** \brief Create a label for the description */ +Gtk::Widget *WidgetSpacer::get_widget(sigc::signal<void> *changeSignal) +{ + if (_hidden) { + return nullptr; + } + + Gtk::Box *spacer = Gtk::manage(new Gtk::Box()); + spacer->set_border_width(_size/2); + + if (_expand) { + spacer->set_hexpand(); + spacer->set_vexpand(); + } else { + spacer->set_margin_start(_size); + spacer->set_margin_top(_size); + } + + spacer->show(); + + return dynamic_cast<Gtk::Widget *>(spacer); +} + +} /* namespace Extension */ +} /* namespace Inkscape */ diff --git a/src/extension/prefdialog/widget-spacer.h b/src/extension/prefdialog/widget-spacer.h new file mode 100644 index 000000000..467b5f95b --- /dev/null +++ b/src/extension/prefdialog/widget-spacer.h @@ -0,0 +1,60 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/** @file + * Spacer widget for extensions + *//* + * Authors: + * Patrick Storz <eduard.braun2@gmx.de> + * + * Copyright (C) 2019 Authors + * + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#ifndef SEEN_INK_EXTENSION_WIDGET_SPACER_H +#define SEEN_INK_EXTENSION_WIDGET_SPACER_H + +#include "widget.h" + +#include <glibmm/ustring.h> + +namespace Gtk { + class Widget; +} + +namespace Inkscape { +namespace Xml { + class Node; +} + +namespace Extension { + +/** \brief A separator widget */ +class WidgetSpacer : public InxWidget { +public: + WidgetSpacer(Inkscape::XML::Node *xml, Inkscape::Extension::Extension *ext); + + Gtk::Widget *get_widget(sigc::signal<void> *changeSignal) override; + +private: + /** size of the spacer in px */ + int _size = GUI_BOX_MARGIN; + + /** should the spacer be flexible and expand? */ + bool _expand = false; +}; + +} /* namespace Extension */ +} /* namespace Inkscape */ + +#endif /* SEEN_INK_EXTENSION_WIDGET_SPACER_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 : diff --git a/src/extension/prefdialog/widget.cpp b/src/extension/prefdialog/widget.cpp index eb9d23e07..da4b6545d 100644 --- a/src/extension/prefdialog/widget.cpp +++ b/src/extension/prefdialog/widget.cpp @@ -15,6 +15,7 @@ #include "widget-box.h" #include "widget-label.h" #include "widget-separator.h" +#include "widget-spacer.h" #include <algorithm> @@ -51,6 +52,8 @@ InxWidget *InxWidget::make(Inkscape::XML::Node *in_repr, Inkscape::Extension::Ex widget = new WidgetLabel(in_repr, in_ext); } else if (!strcmp(name, "separator")) { widget = new WidgetSeparator(in_repr, in_ext); + } else if (!strcmp(name, "spacer")) { + widget = new WidgetSpacer(in_repr, in_ext); } else if (!strcmp(name, "param")) { widget = InxParameter::make(in_repr, in_ext); } else { @@ -64,7 +67,7 @@ InxWidget *InxWidget::make(Inkscape::XML::Node *in_repr, Inkscape::Extension::Ex bool InxWidget::is_valid_widget_name(const char *name) { // keep in sync with names supported in InxWidget::make() above - static const std::vector<std::string> valid_names = {"hbox", "vbox", "label", "separator", "param"}; + static const std::vector<std::string> valid_names = {"hbox", "vbox", "label", "separator", "spacer", "param"}; if (std::find(valid_names.begin(), valid_names.end(), name) != valid_names.end()) { return true; |
