diff options
Diffstat (limited to 'src/gui/PropertiesWindow.cpp')
-rw-r--r-- | src/gui/PropertiesWindow.cpp | 149 |
1 files changed, 101 insertions, 48 deletions
diff --git a/src/gui/PropertiesWindow.cpp b/src/gui/PropertiesWindow.cpp index 9912f73a..0dde0ab2 100644 --- a/src/gui/PropertiesWindow.cpp +++ b/src/gui/PropertiesWindow.cpp @@ -14,31 +14,64 @@ along with Ingen. If not, see <http://www.gnu.org/licenses/>. */ -#include "App.hpp" #include "PropertiesWindow.hpp" + +#include "App.hpp" #include "RDFS.hpp" #include "URIEntry.hpp" - -#include "ingen/Interface.hpp" -#include "ingen/Log.hpp" -#include "ingen/URIMap.hpp" -#include "ingen/World.hpp" -#include "ingen/client/BlockModel.hpp" -#include "ingen/client/PluginModel.hpp" - +#include "Window.hpp" + +#include <ingen/Atom.hpp> +#include <ingen/Forge.hpp> +#include <ingen/Interface.hpp> +#include <ingen/Log.hpp> +#include <ingen/Properties.hpp> +#include <ingen/URI.hpp> +#include <ingen/URIMap.hpp> +#include <ingen/URIs.hpp> +#include <ingen/World.hpp> +#include <ingen/client/ObjectModel.hpp> +#include <lilv/lilv.h> +#include <lv2/urid/urid.h> +#include <raul/Path.hpp> +#include <sord/sordmm.hpp> + +#include <glibmm/containers.h> +#include <glibmm/propertyproxy.h> +#include <glibmm/ustring.h> +#include <gtk/gtk.h> +#include <gtkmm/alignment.h> +#include <gtkmm/bin.h> +#include <gtkmm/box.h> +#include <gtkmm/builder.h> +#include <gtkmm/button.h> +#include <gtkmm/checkbutton.h> +#include <gtkmm/combobox.h> +#include <gtkmm/entry.h> +#include <gtkmm/enums.h> #include <gtkmm/label.h> +#include <gtkmm/object.h> +#include <gtkmm/scrolledwindow.h> #include <gtkmm/spinbutton.h> +#include <gtkmm/table.h> +#include <gtkmm/treeiter.h> +#include <gtkmm/widget.h> +#include <gtkmm/window.h> +#include <sigc++/adaptors/bind.h> +#include <sigc++/functors/mem_fun.h> +#include <sigc++/signal.h> #include <algorithm> #include <cfloat> #include <climits> #include <cstdint> +#include <memory> #include <set> #include <utility> namespace ingen { -using namespace client; +using client::ObjectModel; namespace gui { @@ -47,7 +80,6 @@ using URISet = std::set<URI>; PropertiesWindow::PropertiesWindow(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& xml) : Window(cobject) - , _value_type(0) { xml->get_widget("properties_vbox", _vbox); xml->get_widget("properties_scrolledwindow", _scrolledwindow); @@ -96,7 +128,7 @@ PropertiesWindow::reset() } void -PropertiesWindow::present(SPtr<const ObjectModel> model) +PropertiesWindow::present(const std::shared_ptr<const ObjectModel>& model) { set_object(model); Gtk::Window::present(); @@ -116,10 +148,12 @@ PropertiesWindow::add_property(const URI& key, const Atom& value) if (name.empty()) { name = world.rdf_world()->prefixes().qualify(key); } - Gtk::Label* label = new Gtk::Label( - std::string("<a href=\"") + key.string() + "\">" + name + "</a>", - 1.0, - 0.5); + + auto* label = new Gtk::Label(std::string("<a href=\"") + key.string() + + "\">" + name + "</a>", + 1.0, + 0.5); + label->set_use_markup(true); _app->set_tooltip(label, prop); _table->attach(*Gtk::manage(label), 0, 1, n_rows, n_rows + 1, @@ -154,16 +188,24 @@ PropertiesWindow::datatype_supported(const rdfs::URISet& types, if (types.find(_app->uris().atom_Int) != types.end()) { *widget_type = _app->uris().atom_Int; return true; - } else if (types.find(_app->uris().atom_Float) != types.end()) { + } + + if (types.find(_app->uris().atom_Float) != types.end()) { *widget_type = _app->uris().atom_Float; return true; - } else if (types.find(_app->uris().atom_Bool) != types.end()) { + } + + if (types.find(_app->uris().atom_Bool) != types.end()) { *widget_type = _app->uris().atom_Bool; return true; - } else if (types.find(_app->uris().atom_String) != types.end()) { + } + + if (types.find(_app->uris().atom_String) != types.end()) { *widget_type = _app->uris().atom_String; return true; - } else if (types.find(_app->uris().atom_URID) != types.end()) { + } + + if (types.find(_app->uris().atom_URID) != types.end()) { *widget_type = _app->uris().atom_URID; return true; } @@ -200,7 +242,7 @@ PropertiesWindow::class_supported(const rdfs::URISet& types) * This function MUST be called before using this object in any way. */ void -PropertiesWindow::set_object(SPtr<const ObjectModel> model) +PropertiesWindow::set_object(const std::shared_ptr<const ObjectModel>& model) { reset(); _model = model; @@ -245,8 +287,9 @@ PropertiesWindow::set_object(SPtr<const ObjectModel> model) } for (const auto& e : entries) { - Gtk::ListStore::iterator ki = _key_store->append(); - Gtk::ListStore::Row row = *ki; + auto ki = _key_store->append(); + auto row = *ki; + row[_combo_columns.uri_col] = e.second.string(); row[_combo_columns.label_col] = e.first; } @@ -301,19 +344,23 @@ PropertiesWindow::create_value_widget(const URI& key, widget->signal_value_changed().connect( sigc::bind(sigc::mem_fun(this, &PropertiesWindow::on_change), key)); return widget; - } else if (type == _app->uris().atom_Float) { + } + + if (type == _app->uris().atom_Float) { Gtk::SpinButton* widget = manage(new Gtk::SpinButton(0.0, 4)); widget->property_numeric() = true; widget->set_snap_to_ticks(false); - widget->set_range(-FLT_MAX, FLT_MAX); + widget->set_range(-DBL_MAX, DBL_MAX); widget->set_increments(0.1, 1.0); if (value.is_valid()) { - widget->set_value(value.get<float>()); + widget->set_value(static_cast<double>(value.get<float>())); } widget->signal_value_changed().connect( sigc::bind(sigc::mem_fun(this, &PropertiesWindow::on_change), key)); return widget; - } else if (type == _app->uris().atom_Bool) { + } + + if (type == _app->uris().atom_Bool) { Gtk::CheckButton* widget = manage(new Gtk::CheckButton()); if (value.is_valid()) { widget->set_active(value.get<int32_t>()); @@ -321,7 +368,9 @@ PropertiesWindow::create_value_widget(const URI& key, widget->signal_toggled().connect( sigc::bind(sigc::mem_fun(this, &PropertiesWindow::on_change), key)); return widget; - } else if (type == _app->uris().atom_String) { + } + + if (type == _app->uris().atom_String) { Gtk::Entry* widget = manage(new Gtk::Entry()); if (value.is_valid()) { widget->set_text(value.ptr<char>()); @@ -329,14 +378,16 @@ PropertiesWindow::create_value_widget(const URI& key, widget->signal_changed().connect( sigc::bind(sigc::mem_fun(this, &PropertiesWindow::on_change), key)); return widget; - } else if (type == _app->uris().atom_URID) { + } + + if (type == _app->uris().atom_URID) { const char* str = (value.is_valid() ? world.uri_map().unmap_uri(value.get<int32_t>()) : ""); - LilvNode* pred = lilv_new_uri(lworld, key.c_str()); - URISet ranges = rdfs::range(world, pred, true); - URIEntry* widget = manage(new URIEntry(_app, ranges, str ? str : "")); + LilvNode* pred = lilv_new_uri(lworld, key.c_str()); + const URISet ranges = rdfs::range(world, pred, true); + URIEntry* widget = manage(new URIEntry(_app, ranges, str ? str : "")); widget->signal_changed().connect( sigc::bind(sigc::mem_fun(this, &PropertiesWindow::on_change), key)); lilv_node_free(pred); @@ -352,10 +403,10 @@ PropertiesWindow::create_value_widget(const URI& key, if (type == _app->uris().atom_URI || type == _app->uris().rdfs_Class || is_class) { - LilvNode* pred = lilv_new_uri(lworld, key.c_str()); - URISet ranges = rdfs::range(world, pred, true); - const char* str = value.is_valid() ? value.ptr<const char>() : ""; - URIEntry* widget = manage(new URIEntry(_app, ranges, str)); + LilvNode* pred = lilv_new_uri(lworld, key.c_str()); + const URISet ranges = rdfs::range(world, pred, true); + const char* str = value.is_valid() ? value.ptr<const char>() : ""; + URIEntry* widget = manage(new URIEntry(_app, ranges, str)); widget->signal_changed().connect( sigc::bind(sigc::mem_fun(this, &PropertiesWindow::on_change), key)); lilv_node_free(pred); @@ -434,38 +485,40 @@ PropertiesWindow::remove_property(const URI& key, const Atom& value) Atom PropertiesWindow::get_value(LV2_URID type, Gtk::Widget* value_widget) { - Forge& forge = _app->forge(); + const Forge& forge = _app->forge(); if (type == forge.Int) { - Gtk::SpinButton* spin = dynamic_cast<Gtk::SpinButton*>(value_widget); + auto* spin = dynamic_cast<Gtk::SpinButton*>(value_widget); if (spin) { return _app->forge().make(spin->get_value_as_int()); } } else if (type == forge.Float) { - Gtk::SpinButton* spin = dynamic_cast<Gtk::SpinButton*>(value_widget); + auto* spin = dynamic_cast<Gtk::SpinButton*>(value_widget); if (spin) { return _app->forge().make(static_cast<float>(spin->get_value())); } } else if (type == forge.Bool) { - Gtk::CheckButton* check = dynamic_cast<Gtk::CheckButton*>(value_widget); + auto* check = dynamic_cast<Gtk::CheckButton*>(value_widget); if (check) { return _app->forge().make(check->get_active()); } } else if (type == forge.URI || type == forge.URID) { - URIEntry* uri_entry = dynamic_cast<URIEntry*>(value_widget); - if (uri_entry && URI::is_valid(uri_entry->get_text())) { - return _app->forge().make_urid(URI(uri_entry->get_text())); - } else { + auto* uri_entry = dynamic_cast<URIEntry*>(value_widget); + if (uri_entry) { + if (URI::is_valid(uri_entry->get_text())) { + return _app->forge().make_urid(URI(uri_entry->get_text())); + } + _app->log().error("Invalid URI <%1%>\n", uri_entry->get_text()); } } else if (type == forge.String) { - Gtk::Entry* entry = dynamic_cast<Gtk::Entry*>(value_widget); + auto* entry = dynamic_cast<Gtk::Entry*>(value_widget); if (entry) { return _app->forge().alloc(entry->get_text()); } } - return Atom(); + return {}; } void @@ -490,12 +543,12 @@ PropertiesWindow::on_change(const URI& key) std::string PropertiesWindow::active_key() const { - const Gtk::ListStore::iterator iter = _key_combo->get_active(); + const auto iter = _key_combo->get_active(); if (!iter) { return ""; } - Glib::ustring prop_uri = (*iter)[_combo_columns.uri_col]; + const Glib::ustring prop_uri = (*iter)[_combo_columns.uri_col]; return prop_uri; } |