From e28cff88c03afa5cd90951deeff62b4efb910421 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Mon, 15 Jul 2024 16:45:46 +0200 Subject: app: rename participant_list_row --- app/CMakeLists.txt | 2 +- .../turns/app/widgets/participant_list_row.hpp | 50 -------------- app/include/turns/app/widgets/participant_row.hpp | 50 ++++++++++++++ app/src/widgets/participant_list_row.cpp | 76 ---------------------- app/src/widgets/participant_row.cpp | 76 ++++++++++++++++++++++ app/src/windows/main.cpp | 4 +- 6 files changed, 129 insertions(+), 129 deletions(-) delete mode 100644 app/include/turns/app/widgets/participant_list_row.hpp create mode 100644 app/include/turns/app/widgets/participant_row.hpp delete mode 100644 app/src/widgets/participant_list_row.cpp create mode 100644 app/src/widgets/participant_row.cpp (limited to 'app') diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index a65a489..eaf16b6 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -2,7 +2,7 @@ add_library("app" "src/application.cpp" - "src/widgets/participant_list_row.cpp" + "src/widgets/participant_row.cpp" "src/windows/main.cpp" "src/windows/participant_editor.cpp" ) diff --git a/app/include/turns/app/widgets/participant_list_row.hpp b/app/include/turns/app/widgets/participant_list_row.hpp deleted file mode 100644 index 6a9a6c2..0000000 --- a/app/include/turns/app/widgets/participant_list_row.hpp +++ /dev/null @@ -1,50 +0,0 @@ -#ifndef TURNS_APP_WIDGETS_PARTICIPANT_LIST_ROW_HPP -#define TURNS_APP_WIDGETS_PARTICIPANT_LIST_ROW_HPP - -#include "turns/app/widgets/template_widget.hpp" -#include "turns/domain/participant.hpp" - -#include - -#include -#include -#include -#include -#include -#include -#include - -namespace turns::app::widgets -{ - struct participant_list_row : template_widget - { - auto constexpr inline static children = std::array{ - "delete", - "edit", - "subtitle", - "title", - "toggle_defeated", - }; - - participant_list_row(Glib::RefPtr participant); - - auto set_subtitle(Glib::ustring const & value) -> void; - auto set_title(Glib::ustring const & value) -> void; - - private: - auto handle_delete() -> void; - auto handle_edit() -> void; - - Gtk::Button * m_delete; - Gtk::Button * m_edit; - Gtk::Label * m_subtitle; - Gtk::Label * m_title; - Gtk::ToggleButton * m_toggle_defeated; - - Glib::RefPtr m_subtitle_visibility{}; - Glib::RefPtr m_title_visibility{}; - Glib::RefPtr m_toggle_defeated_icon{}; - }; -} // namespace turns::app::widgets - -#endif \ No newline at end of file diff --git a/app/include/turns/app/widgets/participant_row.hpp b/app/include/turns/app/widgets/participant_row.hpp new file mode 100644 index 0000000..a8f225f --- /dev/null +++ b/app/include/turns/app/widgets/participant_row.hpp @@ -0,0 +1,50 @@ +#ifndef TURNS_APP_WIDGETS_PARTICIPANT_ROW_HPP +#define TURNS_APP_WIDGETS_PARTICIPANT_ROW_HPP + +#include "turns/app/widgets/template_widget.hpp" +#include "turns/domain/participant.hpp" + +#include + +#include +#include +#include +#include +#include +#include +#include + +namespace turns::app::widgets +{ + struct participant_row : template_widget + { + auto constexpr inline static children = std::array{ + "delete", + "edit", + "subtitle", + "title", + "toggle_defeated", + }; + + participant_row(Glib::RefPtr participant); + + auto set_subtitle(Glib::ustring const & value) -> void; + auto set_title(Glib::ustring const & value) -> void; + + private: + auto handle_delete() -> void; + auto handle_edit() -> void; + + Gtk::Button * m_delete; + Gtk::Button * m_edit; + Gtk::Label * m_subtitle; + Gtk::Label * m_title; + Gtk::ToggleButton * m_toggle_defeated; + + Glib::RefPtr m_subtitle_visibility{}; + Glib::RefPtr m_title_visibility{}; + Glib::RefPtr m_toggle_defeated_icon{}; + }; +} // namespace turns::app::widgets + +#endif \ No newline at end of file diff --git a/app/src/widgets/participant_list_row.cpp b/app/src/widgets/participant_list_row.cpp deleted file mode 100644 index 9be3c57..0000000 --- a/app/src/widgets/participant_list_row.cpp +++ /dev/null @@ -1,76 +0,0 @@ -#include "turns/app/widgets/participant_list_row.hpp" - -#include "turns/lang/messages.hpp" - -#include -#include - -#include -#include -#include - -namespace turns::app::widgets -{ - namespace - { - auto constexpr static TYPE_NAME = "participant_list_row"; - auto constexpr static TEMPLATE = "/ch/arknet/Turns/widgets/participant_list_row.ui"; - } // namespace - - 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->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->property_label() = value; - } - - auto participant_list_row::set_title(Glib::ustring const & value) -> void - { - m_title->property_label() = value; - } - - auto participant_list_row::handle_delete() -> void - { - 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 diff --git a/app/src/widgets/participant_row.cpp b/app/src/widgets/participant_row.cpp new file mode 100644 index 0000000..9e0419a --- /dev/null +++ b/app/src/widgets/participant_row.cpp @@ -0,0 +1,76 @@ +#include "turns/app/widgets/participant_row.hpp" + +#include "turns/lang/messages.hpp" + +#include +#include + +#include +#include +#include + +namespace turns::app::widgets +{ + namespace + { + auto constexpr static TYPE_NAME = "participant_row"; + auto constexpr static TEMPLATE = "/ch/arknet/Turns/widgets/participant_row.ui"; + } // namespace + + participant_row::participant_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->signal_clicked().connect(sigc::mem_fun(*this, &participant_row::handle_delete)); + m_edit->signal_clicked().connect(sigc::mem_fun(*this, &participant_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_row::set_subtitle(Glib::ustring const & value) -> void + { + m_subtitle->property_label() = value; + } + + auto participant_row::set_title(Glib::ustring const & value) -> void + { + m_title->property_label() = value; + } + + auto participant_row::handle_delete() -> void + { + auto index = Glib::Variant::create(get_index()); + activate_action("win.delete", index); + } + + auto participant_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 diff --git a/app/src/windows/main.cpp b/app/src/windows/main.cpp index 95ed221..4f0f8c0 100644 --- a/app/src/windows/main.cpp +++ b/app/src/windows/main.cpp @@ -1,6 +1,6 @@ #include "turns/app/windows/main.hpp" -#include "turns/app/widgets/participant_list_row.hpp" +#include "turns/app/widgets/participant_row.hpp" #include "turns/app/windows/participant_editor.hpp" #include "turns/lang/messages.hpp" @@ -57,7 +57,7 @@ namespace turns::app::windows auto main::handle_create_list_row(Glib::RefPtr const item) -> Gtk::Widget * { auto participant = std::dynamic_pointer_cast(item); - return Gtk::make_managed(participant); + return Gtk::make_managed(participant); } auto main::handle_add_participant() -> void -- cgit v1.2.3