summaryrefslogtreecommitdiffstats
path: root/src/ui/widget
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/widget')
-rw-r--r--src/ui/widget/Makefile_insert2
-rw-r--r--src/ui/widget/font-selector.cpp115
-rw-r--r--src/ui/widget/font-selector.h81
-rw-r--r--src/ui/widget/registered-widget.cpp44
-rw-r--r--src/ui/widget/registered-widget.h18
5 files changed, 260 insertions, 0 deletions
diff --git a/src/ui/widget/Makefile_insert b/src/ui/widget/Makefile_insert
index eb98e6872..bb833e5ec 100644
--- a/src/ui/widget/Makefile_insert
+++ b/src/ui/widget/Makefile_insert
@@ -33,6 +33,8 @@ ink_common_sources += \
ui/widget/entry.h \
ui/widget/filter-effect-chooser.h \
ui/widget/filter-effect-chooser.cpp \
+ ui/widget/font-selector.h \
+ ui/widget/font-selector.cpp \
ui/widget/font-variants.h \
ui/widget/font-variants.cpp \
ui/widget/gimpspinscale.c \
diff --git a/src/ui/widget/font-selector.cpp b/src/ui/widget/font-selector.cpp
new file mode 100644
index 000000000..77bf83fe1
--- /dev/null
+++ b/src/ui/widget/font-selector.cpp
@@ -0,0 +1,115 @@
+/*
+ *
+ * Released under GNU GPL. Read the file 'COPYING' for more information.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "font-selector.h"
+#include "widgets/icon.h"
+#include <glibmm/i18n.h>
+
+namespace Inkscape {
+namespace UI {
+namespace Widget {
+
+FontSelector::FontSelector(Glib::ustring const &label, Glib::ustring const &tooltip,
+ Glib::ustring const &suffix,
+ Glib::ustring const &icon,
+ bool mnemonic)
+ :_widget(new Gtk::HBox()), expanded(true)
+{
+ Gtk::VBox * vbox_expander = Gtk::manage( new Gtk::VBox() );
+ GtkWidget *fontsel = sp_font_selector_new();
+ gtk_widget_set_size_request (fontsel, 290, 150);
+ fsel = SP_FONT_SELECTOR(fontsel);
+ Gtk::Widget* pIcon = Gtk::manage( sp_icon_get_icon( "on", Inkscape::ICON_SIZE_BUTTON) );
+ Gtk::Button * pButton = Gtk::manage(new Gtk::Button());
+ pButton->set_relief(Gtk::RELIEF_NONE);
+ pIcon->show();
+ pButton->add(*pIcon);
+ pButton->show();
+ pButton->signal_clicked().connect(sigc::mem_fun(*this, &FontSelector::onFontSelectorSave));
+ pButton->set_tooltip_text(_("Save the changes to font selector"));
+ vbox_expander->pack_start(*Gtk::manage(Glib::wrap(fontsel)), true, true);
+ vbox_expander->pack_start(*pButton, true, true);
+ expander = Gtk::manage(new Gtk::Expander(Glib::ustring(_("Font Selector:"))));
+ expander->add(*vbox_expander);
+ expander->set_expanded(expanded);
+ expander->set_spacing(5);
+ expander->set_use_markup(true);
+ onExpanderChanged();
+ _widget->set_tooltip_text(tooltip);
+ expander->property_expanded().signal_changed().connect(sigc::mem_fun(*this, &FontSelector::onExpanderChanged) );
+ pack_start(*expander, true, true);
+ pack_start(*Gtk::manage(_widget), true, true);
+}
+
+void
+FontSelector::onExpanderChanged()
+{
+ expanded = expander->get_expanded();
+ if(expanded) {
+ expander->set_label (Glib::ustring(_("Font Selector:")));
+ } else {
+ expander->set_label (Glib::ustring(_("Font Selector: <b>hided</b>")));
+ }
+}
+
+Glib::ustring FontSelector::getFontSpec() const
+{
+ return _fontspec;
+}
+
+void FontSelector::setFontSpec(Glib::ustring fontspec)
+{
+ _fontspec = fontspec;
+}
+
+double FontSelector::getFontSize() const
+{
+ return _fontsize;
+}
+
+void FontSelector::setFontSize(double fontsize)
+{
+ _fontsize = fontsize;
+}
+
+void FontSelector::setValue (Glib::ustring fontspec, double fontsize)
+{
+ if (_fontsize != fontsize || _fontspec != fontspec) {
+ setFontSize(fontsize);
+ setFontSpec(fontspec);
+ sp_font_selector_set_fontspec(fsel, fontspec, fontsize);
+ }
+}
+
+void
+FontSelector::onFontSelectorSave()
+{
+ if (_fontspec != sp_font_selector_get_fontspec(fsel) || _fontsize != sp_font_selector_get_size(fsel)) {
+ setFontSpec(sp_font_selector_get_fontspec(fsel));
+ setFontSize(sp_font_selector_get_size(fsel));
+ signal_fontselupd.emit();
+ onExpanderChanged();
+ }
+}
+
+
+} // 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/font-selector.h b/src/ui/widget/font-selector.h
new file mode 100644
index 000000000..cfea54bde
--- /dev/null
+++ b/src/ui/widget/font-selector.h
@@ -0,0 +1,81 @@
+/*
+ *
+ * Copyright (C) 2007 Author
+ *
+ * Released under GNU GPL. Read the file 'COPYING' for more information.
+ */
+
+#ifndef INKSCAPE_UI_WIDGET_FONT_SELECTOR_H
+#define INKSCAPE_UI_WIDGET_FONT_SELECTOR_H
+
+#include <gtkmm.h>
+#include "widgets/font-selector.h"
+
+struct SPFontSelector;
+namespace Inkscape {
+namespace UI {
+namespace Widget {
+
+/**
+ * A labelled text box, with spin buttons and optional
+ * icon or suffix, for entering arbitrary number values. It adds an extra
+ * number called "startseed", that is not UI edittable, but should be put in SVG.
+ * This does NOT generate a random number, but provides merely the saving of
+ * the startseed value.
+ */
+class FontSelector : public Gtk::HBox
+{
+public:
+
+ /**
+ * Construct a FontSelector Widget.
+ *
+ * @param label Label.
+ * @param suffix Suffix, placed after the widget (defaults to "").
+ * @param icon Icon filename, placed before the label (defaults to "").
+ * @param mnemonic Mnemonic toggle; if true, an underscore (_) in the label
+ * indicates the next character should be used for the
+ * mnemonic accelerator key (defaults to false).
+ */
+ FontSelector( Glib::ustring const &label,
+ Glib::ustring const &tooltip,
+ Glib::ustring const &suffix = "",
+ Glib::ustring const &icon = "",
+ bool mnemonic = true);
+
+ Glib::ustring getFontSpec() const;
+ void onExpanderChanged();
+ void setFontSpec(Glib::ustring fontspec);
+ double getFontSize() const;
+ void setFontSize(double fontsize);
+ void setValue (Glib::ustring fontspec, double fontsize);
+ sigc::signal <void> signal_fontselupd;
+
+protected:
+ Gtk::Widget *_widget;
+ bool expanded;
+ Gtk::Expander * expander;
+ SPFontSelector *fsel;
+ Glib::ustring _fontspec;
+ double _fontsize;
+
+private:
+ void onFontSelectorSave();
+};
+
+} // namespace Widget
+} // namespace UI
+} // namespace Inkscape
+
+#endif // INKSCAPE_UI_WIDGET_RANDOM_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/widget/registered-widget.cpp b/src/ui/widget/registered-widget.cpp
index 298377af3..7abab25c9 100644
--- a/src/ui/widget/registered-widget.cpp
+++ b/src/ui/widget/registered-widget.cpp
@@ -25,6 +25,7 @@
#include "ui/widget/scalar-unit.h"
#include "ui/widget/point.h"
#include "ui/widget/random.h"
+#include "ui/widget/font-selector.h"
#include "widgets/spinbutton-events.h"
#include "xml/repr.h"
@@ -805,6 +806,49 @@ RegisteredRandom::on_value_changed()
_wr->setUpdating (false);
}
+/*#########################################
+ * Registered FONT-SELECTOR
+ */
+
+RegisteredFontSelector::~RegisteredFontSelector()
+{
+ _value_changed_connection.disconnect();
+}
+
+RegisteredFontSelector::RegisteredFontSelector ( const Glib::ustring& label, const Glib::ustring& tip,
+ const Glib::ustring& key, Registry& wr, Inkscape::XML::Node* repr_in,
+ SPDocument* doc_in )
+ : RegisteredWidget<FontSelector> (label, tip)
+{
+ init_parent(key, wr, repr_in, doc_in);
+ _value_changed_connection = signal_fontselupd.connect (sigc::mem_fun (*this, &RegisteredFontSelector::on_value_changed));
+}
+
+void
+RegisteredFontSelector::setValue (Glib::ustring fontspec, double fontsize)
+{
+ if (fontsize != 0) { //have value in the effect
+ FontSelector::setValue (fontspec, fontsize);
+ }
+}
+
+void
+RegisteredFontSelector::on_value_changed()
+{
+
+ if (_wr->isUpdating())
+ return;
+
+ _wr->setUpdating (true);
+
+ Inkscape::SVGOStringStream os;
+ os << getFontSpec() << " @ " << getFontSize();
+
+ write_to_xml(os.str().c_str());
+
+ _wr->setUpdating (false);
+}
+
} // namespace Dialog
} // namespace UI
} // namespace Inkscape
diff --git a/src/ui/widget/registered-widget.h b/src/ui/widget/registered-widget.h
index 9d2489712..17c04de9f 100644
--- a/src/ui/widget/registered-widget.h
+++ b/src/ui/widget/registered-widget.h
@@ -22,6 +22,7 @@
#include "ui/widget/text.h"
#include "ui/widget/random.h"
#include "ui/widget/unit-menu.h"
+#include "ui/widget/font-selector.h"
#include "ui/widget/color-picker.h"
#include "inkscape.h"
@@ -419,6 +420,23 @@ protected:
void on_value_changed();
};
+class RegisteredFontSelector : public RegisteredWidget<FontSelector> {
+public:
+ virtual ~RegisteredFontSelector();
+ RegisteredFontSelector ( const Glib::ustring& label,
+ const Glib::ustring& tip,
+ const Glib::ustring& key,
+ Registry& wr,
+ Inkscape::XML::Node* repr_in = NULL,
+ SPDocument *doc_in = NULL);
+
+ void setValue (Glib::ustring fontspec, double fontsize);
+
+protected:
+ sigc::connection _value_changed_connection;
+ void on_value_changed();
+};
+
} // namespace Widget
} // namespace UI
} // namespace Inkscape