diff options
| -rw-r--r-- | ui/include/turns/ui/widgets/preferences.hpp | 29 | ||||
| -rw-r--r-- | ui/res/ui.cmb | 46 | ||||
| -rw-r--r-- | ui/src/widgets/preferences.cpp | 78 |
3 files changed, 106 insertions, 47 deletions
diff --git a/ui/include/turns/ui/widgets/preferences.hpp b/ui/include/turns/ui/widgets/preferences.hpp index 21b6eef..749d4fd 100644 --- a/ui/include/turns/ui/widgets/preferences.hpp +++ b/ui/include/turns/ui/widgets/preferences.hpp @@ -1,14 +1,15 @@ #ifndef TURNS_UI_WIDGETS_PREFERENCES_HPP #define TURNS_UI_WIDGETS_PREFERENCES_HPP -#include "turns/adw/actionrow.hpp" #include "turns/adw/preferencespage.hpp" #include "turns/ui/widgets/template_widget.hpp" #include <glibmm/refptr.h> +#include <glibmm/ustring.h> #include <giomm/settings.h> +#include <gtkmm/button.h> #include <gtkmm/colordialogbutton.h> #include <array> @@ -19,23 +20,29 @@ namespace turns::ui::widgets { auto constexpr inline static children = std::array{ - "friendly", - "hostile", - "secret", + "friendly_reset_button", + "hostile_reset_button", + "secret_reset_button", + "friendly_color_button", + "hostile_color_button", + "secret_color_button", }; explicit preferences(Glib::RefPtr<Gio::Settings> settings = {}); private: - Glib::RefPtr<Gio::Settings> m_settings; + auto bind_reset(Glib::ustring const & key, Gtk::Button * button) -> void; + auto bind_setting(Glib::ustring const & key, Gtk::ColorDialogButton * button) -> void; + auto update_sensitive(Glib::ustring const & key, Gtk::Button * button) -> void; - adw::ActionRow * m_friendly; - adw::ActionRow * m_hostile; - adw::ActionRow * m_secret; + Glib::RefPtr<Gio::Settings> m_settings; - Gtk::ColorDialogButton m_friendly_button{}; - Gtk::ColorDialogButton m_hostile_button{}; - Gtk::ColorDialogButton m_secret_button{}; + Gtk::Button * m_friendly_reset_button{}; + Gtk::Button * m_hostile_reset_button{}; + Gtk::Button * m_secret_reset_button{}; + Gtk::ColorDialogButton * m_friendly_color_button{}; + Gtk::ColorDialogButton * m_hostile_color_button{}; + Gtk::ColorDialogButton * m_secret_color_button{}; }; } // namespace turns::ui::widgets diff --git a/ui/res/ui.cmb b/ui/res/ui.cmb index 0e3de6d..2538784 100644 --- a/ui/res/ui.cmb +++ b/ui/res/ui.cmb @@ -69,9 +69,18 @@ (4,5,"GtkListBox","view",4,None,None,None,-1,None,None), (6,1,"AdwPreferencesPage","gtkmm__CustomObject_preferences",None,None,None,None,None,None,None), (6,2,"AdwPreferencesGroup","colors",1,None,None,None,None,None,None), - (6,3,"AdwActionRow","friendly",2,None,None,None,None,None,None), + (6,3,"AdwActionRow",None,2,None,None,None,None,None,None), (6,4,"AdwActionRow","hostile",2,None,None,None,1,None,None), - (6,5,"AdwActionRow","secret",2,None,None,None,2,None,None) + (6,5,"AdwActionRow","secret",2,None,None,None,2,None,None), + (6,7,"GtkColorDialogButton","friendly_color_button",3,None,None,None,-1,None,None), + (6,10,"GtkColorDialogButton","hostile_color_button",4,None,None,None,1,None,None), + (6,11,"GtkColorDialogButton","secret_color_button",5,None,None,None,1,None,None), + (6,12,"GtkColorDialog",None,7,None,None,None,-1,None,None), + (6,13,"GtkColorDialog",None,10,None,None,None,-1,None,None), + (6,14,"GtkColorDialog",None,11,None,None,None,-1,None,None), + (6,15,"GtkButton","hostile_reset_button",4,None,None,None,1,None,None), + (6,16,"GtkButton","friendly_reset_button",3,None,None,None,1,None,None), + (6,17,"GtkButton","secret_reset_button",5,None,None,None,1,None,None) </object> <object_property> (1,1,"AdwApplicationWindow","content",None,None,None,None,None,2,None,None,None,None), @@ -178,9 +187,27 @@ (4,5,"GtkWidget","valign","start",None,None,None,None,None,None,None,None,None), (6,1,"AdwPreferencesPage","icon-name","preferences-system-symbolic",None,None,None,None,None,None,None,None,None), (6,2,"AdwPreferencesGroup","title","Colors",1,None,None,None,None,None,None,None,None), + (6,3,"AdwActionRow","activatable-widget","7",None,None,None,None,None,None,None,None,None), (6,3,"AdwPreferencesRow","title","Friendly",1,None,None,None,None,None,None,None,None), + (6,4,"AdwActionRow","activatable-widget","10",None,None,None,None,None,None,None,None,None), (6,4,"AdwPreferencesRow","title","Hostile",1,None,None,None,None,None,None,None,None), - (6,5,"AdwPreferencesRow","title","Secret",1,None,None,None,None,None,None,None,None) + (6,5,"AdwActionRow","activatable-widget","11",None,None,None,None,None,None,None,None,None), + (6,5,"AdwPreferencesRow","title","Secret",1,None,None,None,None,None,None,None,None), + (6,7,"GtkColorDialogButton","dialog",None,None,None,None,None,12,None,None,None,None), + (6,7,"GtkWidget","valign","center",None,None,None,None,None,None,None,None,None), + (6,10,"GtkColorDialogButton","dialog",None,None,None,None,None,13,None,None,None,None), + (6,10,"GtkWidget","valign","center",None,None,None,None,None,None,None,None,None), + (6,11,"GtkColorDialogButton","dialog",None,None,None,None,None,14,None,None,None,None), + (6,11,"GtkWidget","valign","center",None,None,None,None,None,None,None,None,None), + (6,12,"GtkColorDialog","with-alpha","False",None,None,None,None,None,None,None,None,None), + (6,13,"GtkColorDialog","with-alpha","False",None,None,None,None,None,None,None,None,None), + (6,14,"GtkColorDialog","with-alpha","False",None,None,None,None,None,None,None,None,None), + (6,15,"GtkButton","icon-name","process-stop-symbolic",None,None,None,None,None,None,None,None,None), + (6,15,"GtkWidget","valign","center",None,None,None,None,None,None,None,None,None), + (6,16,"GtkButton","icon-name","process-stop-symbolic",None,None,None,None,None,None,None,None,None), + (6,16,"GtkWidget","valign","center",None,None,None,None,None,None,None,None,None), + (6,17,"GtkButton","icon-name","process-stop-symbolic",None,None,None,None,None,None,None,None,None), + (6,17,"GtkWidget","valign","center",None,None,None,None,None,None,None,None,None) </object_property> <object_data> (1,1,"GtkWidget",2,2,None,1,None,None,None,None), @@ -226,7 +253,13 @@ (4,5,"GtkWidget",2,2,None,1,None,None,None,None), (1,32,"GtkWidget",1,1,None,None,None,None,None,None), (1,32,"GtkWidget",2,2,None,1,None,None,None,None), - (1,32,"GtkWidget",2,3,None,1,None,None,None,None) + (1,32,"GtkWidget",2,3,None,1,None,None,None,None), + (6,15,"GtkWidget",1,1,None,None,None,None,None,None), + (6,15,"GtkWidget",2,2,None,1,None,None,None,None), + (6,16,"GtkWidget",1,1,None,None,None,None,None,None), + (6,16,"GtkWidget",2,2,None,1,None,None,None,None), + (6,17,"GtkWidget",1,1,None,None,None,None,None,None), + (6,17,"GtkWidget",2,2,None,1,None,None,None,None) </object_data> <object_data_arg> (1,1,"GtkWidget",2,2,"name","background"), @@ -253,6 +286,9 @@ (4,2,"GtkWidget",2,2,"name","osd"), (4,5,"GtkWidget",2,2,"name","boxed-list"), (1,32,"GtkWidget",2,2,"name","pill"), - (1,32,"GtkWidget",2,3,"name","suggested-action") + (1,32,"GtkWidget",2,3,"name","suggested-action"), + (6,15,"GtkWidget",2,2,"name","circular"), + (6,16,"GtkWidget",2,2,"name","circular"), + (6,17,"GtkWidget",2,2,"name","circular") </object_data_arg> </cambalache-project> diff --git a/ui/src/widgets/preferences.cpp b/ui/src/widgets/preferences.cpp index 24de613..187da2e 100644 --- a/ui/src/widgets/preferences.cpp +++ b/ui/src/widgets/preferences.cpp @@ -1,14 +1,19 @@ #include "turns/ui/widgets/preferences.hpp" -#include "turns/adw/actionrow.hpp" #include "turns/ui/widgets/template_widget.hpp" +#include <sigc++/functors/mem_fun.h> + +#include <glibmm/binding.h> #include <glibmm/objectbase.h> #include <glibmm/refptr.h> +#include <glibmm/ustring.h> +#include <glibmm/variant.h> #include <giomm/settings.h> #include <gtkmm/colordialog.h> +#include <gtkmm/colordialogbutton.h> #include <gtkmm/enums.h> #include <gdkmm/rgba.h> @@ -25,44 +30,55 @@ namespace turns::ui::widgets : Glib::ObjectBase{TYPE_NAME} , template_widget{TEMPLATE} , m_settings{settings} - , m_friendly{get_widget<adw::ActionRow>("friendly")} - , m_hostile{get_widget<adw::ActionRow>("hostile")} - , m_secret{get_widget<adw::ActionRow>("secret")} + , m_friendly_reset_button{get_widget<Gtk::Button>("friendly_reset_button")} + , m_hostile_reset_button{get_widget<Gtk::Button>("hostile_reset_button")} + , m_secret_reset_button{get_widget<Gtk::Button>("secret_reset_button")} + , m_friendly_color_button{get_widget<Gtk::ColorDialogButton>("friendly_color_button")} + , m_hostile_color_button{get_widget<Gtk::ColorDialogButton>("hostile_color_button")} + , m_secret_color_button{get_widget<Gtk::ColorDialogButton>("secret_color_button")} { if (!m_settings) { return; } - m_friendly->add_suffix(m_friendly_button); - m_friendly->set_activatable_widget(m_friendly_button); - m_friendly_button.set_dialog(Gtk::ColorDialog::create()); - m_friendly_button.set_valign(Gtk::Align::CENTER); - m_settings->bind<Glib::ustring, Gdk::RGBA>("disposition-color-friendly", - m_friendly_button.property_rgba(), - Gio::Settings::BindFlags::DEFAULT, - [](auto value) { return Gdk::RGBA{value}; }, - [](auto color) { return color.to_string(); }); + { + auto key = "disposition-color-friendly"; + bind_reset(key, m_friendly_reset_button); + bind_setting(key, m_friendly_color_button); + } + + { + auto key = "disposition-color-hostile"; + bind_reset(key, m_hostile_reset_button); + bind_setting(key, m_hostile_color_button); + } + + { + auto key = "disposition-color-secret"; + bind_reset(key, m_secret_reset_button); + bind_setting(key, m_secret_color_button); + } + } + + auto preferences::bind_reset(Glib::ustring const & key, Gtk::Button * button) -> void + { + m_settings->signal_changed(key).connect([=, this](auto) { update_sensitive(key, button); }); + update_sensitive(key, button); + button->signal_clicked().connect(sigc::bind(sigc::mem_fun(*m_settings, &Gio::Settings::reset), key)); + } - m_hostile->add_suffix(m_hostile_button); - m_hostile->set_activatable_widget(m_hostile_button); - m_hostile_button.set_dialog(Gtk::ColorDialog::create()); - m_hostile_button.set_valign(Gtk::Align::CENTER); - m_settings->bind<Glib::ustring, Gdk::RGBA>("disposition-color-hostile", - m_hostile_button.property_rgba(), - Gio::Settings::BindFlags::DEFAULT, - [](auto value) { return Gdk::RGBA{value}; }, - [](auto color) { return color.to_string(); }); + auto preferences::bind_setting(Glib::ustring const & key, Gtk::ColorDialogButton * button) -> void + { + m_settings->bind<Glib::ustring, Gdk::RGBA>(key, button->property_rgba(), Gio::Settings::BindFlags::DEFAULT, [](auto value) { + return Gdk::RGBA{value}; + }, [](auto color) { return color.to_string(); }); + } - m_secret->add_suffix(m_secret_button); - m_secret->set_activatable_widget(m_secret_button); - m_secret_button.set_dialog(Gtk::ColorDialog::create()); - m_secret_button.set_valign(Gtk::Align::CENTER); - m_settings->bind<Glib::ustring, Gdk::RGBA>("disposition-color-secret", - m_secret_button.property_rgba(), - Gio::Settings::BindFlags::DEFAULT, - [](auto value) { return Gdk::RGBA{value}; }, - [](auto color) { return color.to_string(); }); + auto preferences::update_sensitive(Glib::ustring const & key, Gtk::Button * button) -> void + { + auto v = Glib::Variant<Glib::ustring>{}; + button->set_sensitive(m_settings->get_user_value(key, v)); } } // namespace turns::ui::widgets
\ No newline at end of file |
