1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
#include "turns/app/widgets/participant_row.hpp"
#include "turns/lang/messages.hpp"
#include <format>
#include <print>
#include <glibmm/i18n.h>
#include <glibmm/ustring.h>
#include <glibmm/variant.h>
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<domain::participant> participant)
: Glib::ObjectBase(TYPE_NAME)
, template_widget<participant_row, Gtk::ListBoxRow>{TEMPLATE}
, m_delete{get_widget<Gtk::Button>("delete")}
, m_edit{get_widget<Gtk::Button>("edit")}
, m_subtitle{get_widget<Gtk::Label>("subtitle")}
, m_title{get_widget<Gtk::Label>("title")}
, m_toggle_defeated{get_widget<Gtk::ToggleButton>("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)
{
m_title_label = Glib::Binding::bind_property(participant->property_name(), m_title->property_label(), Glib::Binding::Flags::SYNC_CREATE);
m_subtitle_label = Glib::Binding::bind_property(participant->property_priority(),
m_subtitle->property_label(),
Glib::Binding::Flags::SYNC_CREATE,
[](auto n) { return std::vformat(_(lang::priority_number), std::make_format_args(n)); });
}
}
auto participant_row::handle_delete() -> void
{
auto index = Glib::Variant<int>::create(get_index());
activate_action("win.delete", index);
}
auto participant_row::handle_edit() -> void
{
auto index = Glib::Variant<int>::create(get_index());
activate_action("win.edit", index);
}
} // namespace turns::app::widgets
|