From a23cda29f0acef40d883c37209389c956c14e83b Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Mon, 15 Jul 2024 16:00:29 +0200 Subject: turns: perform widespread code cleanup actions --- app/src/widgets/participant_list_row.cpp | 62 +++++++++++++++++++++----------- 1 file changed, 41 insertions(+), 21 deletions(-) (limited to 'app/src/widgets') diff --git a/app/src/widgets/participant_list_row.cpp b/app/src/widgets/participant_list_row.cpp index e38b532..9be3c57 100644 --- a/app/src/widgets/participant_list_row.cpp +++ b/app/src/widgets/participant_list_row.cpp @@ -2,6 +2,7 @@ #include "turns/lang/messages.hpp" +#include #include #include @@ -16,41 +17,60 @@ namespace turns::app::widgets auto constexpr static TEMPLATE = "/ch/arknet/Turns/widgets/participant_list_row.ui"; } // namespace - participant_list_row::participant_list_row() + participant_list_row::participant_list_row(Glib::RefPtr participant) : Glib::ObjectBase(TYPE_NAME) , template_widget{TEMPLATE} + , m_delete{get_widget("delete")} + , m_edit{get_widget("edit")} + , m_subtitle{get_widget("subtitle")} + , m_title{get_widget("title")} + , m_toggle_defeated{get_widget("toggle_defeated")} + , m_subtitle_visibility{} { - m_delete = get_widget("delete"); - m_edit = get_widget("edit"); - m_subtitle = get_widget("subtitle"); - m_title = get_widget("title"); - m_toggle_defeated = get_widget("toggle_defeated"); - - m_delete->signal_clicked().connect([this] { activate_action("win.delete", Glib::Variant::create(get_index())); }); - m_edit->signal_clicked().connect([this] { activate_action("win.edit", Glib::Variant::create(get_index())); }); - m_toggle_defeated->signal_toggled().connect(sigc::mem_fun(*this, &participant_list_row::handle_toggle_defeated)); + m_delete->signal_clicked().connect(sigc::mem_fun(*this, &participant_list_row::handle_delete)); + m_edit->signal_clicked().connect(sigc::mem_fun(*this, &participant_list_row::handle_edit)); + + m_subtitle_visibility = Glib::Binding::bind_property(m_subtitle->property_label(), + m_subtitle->property_visible(), + Glib::Binding::Flags::DEFAULT, + sigc::mem_fun(&Glib::ustring::size)); + m_title_visibility = Glib::Binding::bind_property(m_title->property_label(), + m_title->property_visible(), + Glib::Binding::Flags::INVERT_BOOLEAN, + sigc::mem_fun(&Glib::ustring::size)); + m_toggle_defeated_icon = Glib::Binding::bind_property(m_toggle_defeated->property_active(), + m_toggle_defeated->property_icon_name(), + Glib::Binding::Flags::SYNC_CREATE, + [](auto active) { return active ? "face-sick-symbolic" : "face-smile-symbolic"; }); + + if (participant) + { + set_title(participant->get_name()); + auto priority = participant->get_priority(); + set_subtitle(std::vformat(_(lang::priority_number), std::make_format_args(priority))); + } } auto participant_list_row::set_subtitle(Glib::ustring const & value) -> void { - m_subtitle->set_text(value); - m_subtitle->set_visible(!value.empty()); + m_subtitle->property_label() = value; } auto participant_list_row::set_title(Glib::ustring const & value) -> void { - m_title->set_text(value); - m_title->set_visible(!value.empty()); + m_title->property_label() = value; } - auto participant_list_row::handle_toggle_defeated() -> void + auto participant_list_row::handle_delete() -> void { - if (m_toggle_defeated->get_active()) - { - m_toggle_defeated->set_icon_name("face-sick-symbolic"); - return; - } - m_toggle_defeated->set_icon_name("face-smile-symbolic"); + auto index = Glib::Variant::create(get_index()); + activate_action("win.delete", index); + } + + auto participant_list_row::handle_edit() -> void + { + auto index = Glib::Variant::create(get_index()); + activate_action("win.edit", index); } } // namespace turns::app::widgets \ No newline at end of file -- cgit v1.2.3