summaryrefslogtreecommitdiffstats
path: root/src/ui
diff options
context:
space:
mode:
authorJabier Arraiza <jabier.arraiza@marker.es>2019-01-26 05:52:13 +0000
committerJabier Arraiza <jabier.arraiza@marker.es>2019-01-27 00:41:20 +0000
commit5f64983988239d9cbd34b5389944919948aadfd3 (patch)
tree1ecf3d24ac867329a9c54afbbf47e8b897beba66 /src/ui
parentAdding styling refactoring, moving after to other branch the CSS part (diff)
downloadinkscape-5f64983988239d9cbd34b5389944919948aadfd3.tar.gz
inkscape-5f64983988239d9cbd34b5389944919948aadfd3.zip
Improvements to CSS to easy tweak widgets
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/dialog/filter-editor.cpp2
-rw-r--r--src/ui/dialog/livepatheffect-add.cpp225
-rw-r--r--src/ui/dialog/livepatheffect-add.h70
3 files changed, 143 insertions, 154 deletions
diff --git a/src/ui/dialog/filter-editor.cpp b/src/ui/dialog/filter-editor.cpp
index ba2c7357a..6ad9dca61 100644
--- a/src/ui/dialog/filter-editor.cpp
+++ b/src/ui/dialog/filter-editor.cpp
@@ -69,7 +69,7 @@ FilterEditorDialog::FilterEditorDialog() : UI::Widget::Panel("/dialogs/filtereff
{
const std::string req_widgets[] = {"FilterEditor", "FilterList", "FilterFERX", "FilterFERY", "FilterFERH", "FilterFERW", "FilterPreview", "FilterPrimitiveDescImage", "FilterPrimitiveList", "FilterPrimitiveDescText", "FilterPrimitiveAdd"};
- Glib::ustring gladefile = get_filename(UIS, "dialog-filter-editor.ui");
+ Glib::ustring gladefile = get_filename(UIS, "filter-editor.glade");
try {
builder = Gtk::Builder::create_from_file(gladefile);
} catch(const Glib::Error& ex) {
diff --git a/src/ui/dialog/livepatheffect-add.cpp b/src/ui/dialog/livepatheffect-add.cpp
index 9eea4cccd..1fae9a513 100644
--- a/src/ui/dialog/livepatheffect-add.cpp
+++ b/src/ui/dialog/livepatheffect-add.cpp
@@ -13,10 +13,9 @@
# include "config.h" // only include where actually required!
#endif
-#include "live_effects/effect.h"
#include "livepatheffect-add.h"
#include <glibmm/i18n.h>
-#include "io/resource.h"
+
#include "desktop.h"
namespace Inkscape {
@@ -24,153 +23,93 @@ namespace UI {
namespace Dialog {
LivePathEffectAdd::LivePathEffectAdd() :
- converter(Inkscape::LivePathEffect::LPETypeConverter)
+ add_button(_("_Add"), true),
+ close_button(_("_Cancel"), true),
+ converter(Inkscape::LivePathEffect::LPETypeConverter),
+ applied(false)
{
- const std::string req_widgets[] = {"LPEDialogSelector", "LPESelector", "LPESelectorFlowBox"};
- Glib::ustring gladefile = get_filename(Inkscape::IO::Resource::UIS, "dialog-livepatheffect-add.ui");
- try {
- _builder = Gtk::Builder::create_from_file(gladefile);
- } catch(const Glib::Error& ex) {
- g_warning("Glade file loading failed for filter effect dialog");
- return;
- }
+ set_title(_("Add Path Effect"));
+
+ /**
+ * Scrolled Window
+ */
+ scrolled_window.add(effectlist_treeview);
+ scrolled_window.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
+ scrolled_window.set_shadow_type(Gtk::SHADOW_IN);
+ scrolled_window.set_size_request(250, 200);
+ scrolled_window.set_can_focus();
+
+ /**
+ * Effect Store and Tree
+ */
+ effectlist_store = Gtk::ListStore::create(_columns);
+ effectlist_store->set_sort_column (_columns.name, Gtk::SORT_ASCENDING );
+
+ effectlist_treeview.set_model(effectlist_store);
+ effectlist_treeview.set_headers_visible(false);
+ effectlist_treeview.append_column("Name", _columns.name);
+ //effectlist_treeview.set_activates_default(true);
- Gtk::Object* test;
- for(std::string w:req_widgets) {
- _builder->get_widget(w,test);
- if(!test){
- g_warning("Required widget %s does not exist", w.c_str());
- return;
- }
- }
- _builder->get_widget("LPEDialogSelector", _LPEDialogSelector);
/**
* Initialize Effect list
*/
- _builder->get_widget("LPESelectorFlowBox", _LPESelectorFlowBox);
- _builder->get_widget("LPEFilter", _LPEFilter);
- _builder->get_widget("LPEInfo", _LPEInfo);
- _LPEFilter->signal_search_changed().connect(sigc::mem_fun(*this, &LivePathEffectAdd::on_search));
- const std::string le_widgets[] = {"LPESelectorEffect", "LPEName","LPEDescription"};
- Glib::ustring le_gladefile = get_filename(Inkscape::IO::Resource::UIS, "dialog-livepatheffect-add-effect.ui");
- for(int i = 0; i < static_cast<int>(converter._length); ++i) {
-
- try {
- _builder = Gtk::Builder::create_from_file(le_gladefile);
- } catch(const Glib::Error& ex) {
- g_warning("Glade file loading failed for filter effect dialog");
- return;
- }
+ int show = LivePathEffect::ATTACH_PATH;
+#ifdef LPE_ENABLE_TEST_EFFECTS
+ //TODO: Handle when showing the experimental effects without setting flag
+ show = LivePathEffect::ANGLE_BISECTOR;
+#elif WITH_LPETOOL
+ //TODO: Handle when showing the experimental effects without setting flag
+ show = LivePathEffect::ANGLE_BISECTOR;
+#endif
- Gtk::Object* test;
- for(std::string w:le_widgets) {
- _builder->get_widget(w,test);
- if(!test){
- g_warning("Required widget %s does not exist", w.c_str());
- return;
- }
+ for(int i = 0; i < static_cast<int>(converter._length); ++i) {
+ Gtk::TreeModel::Row row = *(effectlist_store->append());
+ const Util::EnumData<LivePathEffect::EffectType>* data = &converter.data(i);
+ row[_columns.name] = _( converter.get_label(data->id).c_str() );
+ row[_columns.data] = data;
+ if (i == show) {
+ Glib::RefPtr<Gtk::TreeSelection> select = effectlist_treeview.get_selection();
+ select->select(row);
}
- const LivePathEffect::EnumEffectData<LivePathEffect::EffectType>* data = &converter.data(i);
- Gtk::Label * LPEName;
- _builder->get_widget("LPEName", LPEName);
- Glib::ustring newid = "LPEName_" + Glib::ustring::format(i);
- (*LPEName).set_name(newid);
- (*LPEName).set_text(converter.get_label(data->id).c_str());
- Gtk::Label * LPEDescription;
- _builder->get_widget("LPEDescription", LPEDescription);
- newid = "LPEDescription_" + Glib::ustring::format(i);
- (*LPEDescription).set_name(newid);
- (*LPEDescription).set_text(converter.get_description(data->id));
- Gtk::Image * LPEIcon;
- _builder->get_widget("LPEIcon", LPEIcon);
- newid = "LPEIcon_" + Glib::ustring::format(i);
- (*LPEIcon).set_name(newid);
- (*LPEIcon).set_from_icon_name(converter.get_icon(data->id),Gtk::BuiltinIconSize(Gtk::ICON_SIZE_DIALOG));
- Gtk::Box * LPESelectorEffect;
- _builder->get_widget("LPESelectorEffect", LPESelectorEffect);
- newid = "LPESelectorEffect" + Glib::ustring::format(i);
- (*LPESelectorEffect).set_name(newid);
- _LPESelectorFlowBox->insert(*LPESelectorEffect, i);
}
- _visiblelpe = _LPESelectorFlowBox->get_children().size();
- _LPESelectorFlowBox->signal_child_activated().connect(sigc::mem_fun(*this, &LivePathEffectAdd::on_activate));
- _LPEDialogSelector->set_title(_("Live Efects Selector"));
- _LPEDialogSelector->show_all_children();
- _LPEInfo->set_visible(false);
-}
-void LivePathEffectAdd::on_activate(Gtk::FlowBoxChild *child){
- for (auto i:_LPESelectorFlowBox->get_children()) {
- Gtk::FlowBoxChild * leitem = dynamic_cast<Gtk::FlowBoxChild *>(i);
- leitem->get_style_context()->remove_class("lpeactive");
- leitem->get_style_context()->remove_class("colorinverse");
- leitem->get_style_context()->remove_class("backgroundinverse");
- Gtk::Box *box = dynamic_cast<Gtk::Box *>(leitem->get_child());
- if (box) {
- std::vector<Gtk::Widget*> contents = box->get_children();
- Gtk::Box *actions = dynamic_cast<Gtk::Box *>(contents[3]);
- if (actions) {
- actions->set_visible(false);
- }
- }
- }
- child->get_style_context()->add_class("lpeactive");
- child->get_style_context()->add_class("colorinverse");
- child->get_style_context()->add_class("backgroundinverse");
- child->show_all_children();
-}
+ /**
+ * Buttons
+ */
+ //close_button.set_can_default();
+ add_button.set_use_underline(true);
+ add_button.set_can_default();
-bool LivePathEffectAdd::on_filter(Gtk::FlowBoxChild *child)
-{
- if (_LPEFilter->get_text().length() < 4) {
- _visiblelpe = _LPESelectorFlowBox->get_children().size();
- return true;
- }
- Gtk::Box *box = dynamic_cast<Gtk::Box *>(child->get_child());
- if (box) {
- std::vector<Gtk::Widget*> contents = box->get_children();
- Gtk::Label *lpename = dynamic_cast<Gtk::Label *>(contents[1]);
- if (lpename) {
- size_t s = lpename->get_text().uppercase().find(_LPEFilter->get_text().uppercase(),0);
- if(s != -1) {
- _visiblelpe++;
- return true;
- }
- }
- Gtk::Label *lpedesc = dynamic_cast<Gtk::Label *>(contents[2]);
- if (lpedesc) {
- size_t s = lpedesc->get_text().uppercase().find(_LPEFilter->get_text().uppercase(),0);
- if(s != -1) {
- _visiblelpe++;
- return true;
- }
- }
- }
- return false;
-}
+ auto mainVBox = get_content_area();
-void LivePathEffectAdd::on_search()
-{
- _visiblelpe = 0;
- _LPESelectorFlowBox->set_filter_func(sigc::mem_fun(*this, &LivePathEffectAdd::on_filter));
- if (_visiblelpe == 0) {
- _LPEInfo->set_text(_("Your search do a empty result, please try again"));
- _LPEInfo->set_visible(true);
- _LPEInfo->get_style_context()->add_class("lpeinfowarn");
- } else {
- _LPEInfo->set_visible(false);
- _LPEInfo->get_style_context()->remove_class("lpeinfowarn");
- }
+ mainVBox->pack_start(scrolled_window, true, true);
+ add_action_widget(close_button, Gtk::RESPONSE_CLOSE);
+ add_action_widget(add_button, Gtk::RESPONSE_APPLY);
+
+
+ /**
+ * Signal handlers
+ */
+ effectlist_treeview.signal_button_press_event().connect_notify( sigc::mem_fun(*this, &LivePathEffectAdd::onButtonEvent) );
+ effectlist_treeview.signal_key_press_event().connect_notify(sigc::mem_fun(*this, &LivePathEffectAdd::onKeyEvent));
+ close_button.signal_clicked().connect(sigc::mem_fun(*this, &LivePathEffectAdd::onClose));
+ add_button.signal_clicked().connect(sigc::mem_fun(*this, &LivePathEffectAdd::onAdd));
+ signal_delete_event().connect( sigc::bind_return(sigc::hide(sigc::mem_fun(*this, &LivePathEffectAdd::onClose)), true ) );
+
+ add_button.grab_default();
+
+ show_all_children();
}
void LivePathEffectAdd::onAdd()
{
+ applied = true;
onClose();
}
void LivePathEffectAdd::onClose()
{
- _LPEDialogSelector->hide();
+ hide();
}
void LivePathEffectAdd::onKeyEvent(GdkEventKey* evt)
@@ -183,10 +122,36 @@ void LivePathEffectAdd::onKeyEvent(GdkEventKey* evt)
}
}
+void LivePathEffectAdd::onButtonEvent(GdkEventButton* evt)
+{
+ // Double click on tree is same as clicking the add button
+ if (evt->type == GDK_2BUTTON_PRESS) {
+ onAdd();
+ }
+}
+
+const Util::EnumData<LivePathEffect::EffectType>*
+LivePathEffectAdd::getActiveData()
+{
+ Gtk::TreeModel::iterator iter = instance().effectlist_treeview.get_selection()->get_selected();
+ if ( iter ) {
+ Gtk::TreeModel::Row row = *iter;
+ return row[instance()._columns.data];
+ }
+
+ return nullptr;
+}
+
+
void LivePathEffectAdd::show(SPDesktop *desktop)
{
LivePathEffectAdd &dial = instance();
- dial._LPEDialogSelector->run();
+ dial.applied=false;
+ dial.set_modal(true);
+ desktop->setWindowTransient (dial.gobj());
+ dial.property_destroy_with_parent() = true;
+ dial.effectlist_treeview.grab_focus();
+ dial.run();
}
} // namespace Dialog
diff --git a/src/ui/dialog/livepatheffect-add.h b/src/ui/dialog/livepatheffect-add.h
index 17d46487a..84901385c 100644
--- a/src/ui/dialog/livepatheffect-add.h
+++ b/src/ui/dialog/livepatheffect-add.h
@@ -12,14 +12,10 @@
#ifndef INKSCAPE_DIALOG_LIVEPATHEFFECT_ADD_H
#define INKSCAPE_DIALOG_LIVEPATHEFFECT_ADD_H
-#include <gtkmm/box.h>
-#include <gtkmm/builder.h>
-#include <gtkmm/label.h>
-#include <gtkmm/flowbox.h>
-#include <gtkmm/stylecontext.h>
-#include <gtkmm/flowboxchild.h>
-#include <gtkmm/searchentry.h>
#include <gtkmm/dialog.h>
+#include <gtkmm/liststore.h>
+#include <gtkmm/treeview.h>
+#include <gtkmm/scrolledwindow.h>
#include "live_effects/effect-enum.h"
class SPDesktop;
@@ -41,23 +37,31 @@ public:
* Show the dialog
*/
static void show(SPDesktop *desktop);
+
+ /**
+ * Returns true is the "Add" button was pressed
+ */
static bool isApplied() {
- return false;
+ return instance().applied;
}
- static const Util::EnumData<LivePathEffect::EffectType>* getActiveData(){return NULL;};
+ /**
+ * Return the data associated with the currently selected item
+ */
+ static const Util::EnumData<LivePathEffect::EffectType>* getActiveData();
+
protected:
+
/**
* Close button was clicked
*/
void onClose();
- bool on_filter(Gtk::FlowBoxChild *child);
- void on_search();
- void on_activate(Gtk::FlowBoxChild *child);
+
/**
* Add button was clicked
*/
void onAdd();
+
/**
* Tree was clicked
*/
@@ -68,17 +72,37 @@ protected:
*/
void onKeyEvent(GdkEventKey* evt);
private:
- Gtk::Button _add_button;
- Gtk::Button _close_button;
- Gtk::Dialog *_LPEDialogSelector;
- Glib::RefPtr<Gtk::Builder> _builder;
- Gtk::FlowBox *_LPESelectorFlowBox;
- Gtk::SearchEntry *_LPEFilter;
- Gtk::Label *_LPEInfo;
- Gtk::Box *_LPESelector;
- guint _visiblelpe;
- class Effect;
- const LivePathEffect::EnumEffectDataConverter<LivePathEffect::EffectType>& converter;
+
+ Gtk::TreeView effectlist_treeview;
+ Gtk::ScrolledWindow scrolled_window;
+ Gtk::Button add_button;
+ Gtk::Button close_button;
+
+ class ModelColumns : public Gtk::TreeModel::ColumnRecord
+ {
+ public:
+ ModelColumns()
+ {
+ add(name);
+ //add(desc);
+ add(data);
+ }
+ ~ModelColumns() override = default;
+
+ Gtk::TreeModelColumn<Glib::ustring> name;
+ /**
+ * TODO - Get detailed descriptions of each Effect to show in the dialog
+ */
+ //Gtk::TreeModelColumn<Glib::ustring> desc;
+ Gtk::TreeModelColumn<const Util::EnumData<LivePathEffect::EffectType>*> data;
+ };
+
+ ModelColumns _columns;
+ Glib::RefPtr<Gtk::ListStore> effectlist_store;
+ const Util::EnumDataConverter<LivePathEffect::EffectType>& converter;
+
+ bool applied;
+
static LivePathEffectAdd &instance() {
static LivePathEffectAdd instance_;
return instance_;