Skip to content

Commit

Permalink
(core): Update widgets documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
smolBlackCat committed Nov 2, 2024
1 parent ba7265c commit 8ef401e
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 114 deletions.
189 changes: 104 additions & 85 deletions src/resources/ui/app-window.ui
Original file line number Diff line number Diff line change
@@ -1,92 +1,111 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version='1.0' encoding='UTF-8'?>
<!-- Created with Cambalache 0.92.1 -->
<interface>
<requires lib="gtk" version="4.10"/>
<object class="GtkApplicationWindow" id="app-window">
<property name="title">Progress</property>
<property name="width-request">400</property>
<property name="height-request">400</property>
<property name="titlebar">
<object class="GtkHeaderBar">
<child type="start">
<object class="GtkButton" id="home-button">
<property name="icon-name">go-home</property>
<property name="tooltip-text" translatable="yes">Homepage</property>
<property name="visible">false</property>
</object>
</child>
<child type="start">
<object class="GtkButton" id="add-board-button">
<property name="icon-name">list-add-symbolic</property>
<property name="tooltip-text" translatable="yes">Add Board</property>
<property name="visible">true</property>
</object>
</child>
<child type="end">
<object class="GtkMenuButton" id="app-menu-button">
<property name="menu-model">board-grid-menu</property>
<property name="icon-name">open-menu-symbolic</property>
<property name="tooltip-text" translatable="yes">Main Menu</property>
<property name="primary">true</property>
</object>
<!-- interface-name app-window.ui -->
<requires lib="gtk" version="4.10"/>
<requires lib="gio" version="2.0"/>
<object class="GtkApplicationWindow" id="app-window">
<property name="height-request">400</property>
<property name="title">Progress</property>
<property name="titlebar">
<object class="GtkHeaderBar">
<child type="start">
<object class="GtkButton" id="home-button">
<property name="icon-name">go-home</property>
<property name="tooltip-text" translatable="yes">Homepage</property>
<property name="visible">false</property>
</object>
</child>
<child type="start">
<object class="GtkButton" id="add-board-button">
<property name="icon-name">list-add-symbolic</property>
<property name="tooltip-text" translatable="yes">Add Board</property>
<property name="visible">true</property>
</object>
</child>
<child type="end">
<object class="GtkMenuButton" id="app-menu-button">
<property name="icon-name">open-menu-symbolic</property>
<property name="menu-model">board-grid-menu</property>
<property name="primary">true</property>
<property name="tooltip-text" translatable="yes">Main Menu</property>
</object>
</child>
</object>
</property>
<property name="width-request">400</property>
<child>
<object class="GtkStack" id="app-stack">
<property name="transition-type">slide-left-right</property>
<property name="visible-child-name">board-grid-page</property>
<child>
<object class="GtkStackPage">
<property name="child">
<object class="GtkOverlay" id="app-overlay">
<child>
<object class="GtkScrolledWindow">
<property name="child">
<object class="GtkFlowBox" id="boards-grid">
<property name="margin-bottom">10</property>
<property name="margin-end">10</property>
<property name="margin-start">10</property>
<property name="margin-top">10</property>
<property name="selection-mode">none</property>
<property name="valign">start</property>
</object>
</property>
<property name="height-request">-1</property>
<property name="width-request">-1</property>
</object>
</child>
</object>
</property>
</object>
</property>
<property name="name">board-grid-page</property>
</object>
</child>
<child>
<object class="GtkStack" id="app-stack">
<property name="transition-type">GTK_STACK_TRANSITION_TYPE_SLIDE_LEFT_RIGHT</property>
<object class="GtkStackPage">
<property name="child">
<object class="GtkBox">
<child>
<object class="GtkStackPage">
<property name="name">board-grid-page</property>
<property name="child">
<object class="GtkOverlay" id="app-overlay">
<child>
<object class="GtkScrolledWindow">
<property name="width-request">-1</property>
<property name="height-request">-1</property>
<property name="child">
<object class="GtkFlowBox" id="boards-grid">
<property name="valign">start</property>
<property name="margin-top">10</property>
<property name="margin-end">10</property>
<property name="margin-bottom">10</property>
<property name="margin-start">10</property>
<property name="selection-mode">GTK_SELECTION_NONE</property>
</object>
</property>
</object>
</child>
<!--To add DeleteBoardsBar here-->
</object>
</property>
</object>
<object class="GtkSpinner">
<property name="halign">center</property>
<property name="hexpand">True</property>
<property name="spinning">True</property>
<property name="valign">center</property>
<property name="vexpand">True</property>
</object>
</child>
<!--To add BoardWidget here-->
</object>
</object>
</property>
<property name="name">loading-page</property>
</object>
</child>
</object>
<menu id="board-grid-menu">
<section>
<item>
<attribute name="label" translatable="yes">Delete Boards</attribute>
<attribute name="action">win.delete</attribute>
</item>
<item>
<attribute name="label" translatable="yes">About Progress</attribute>
<attribute name="action">win.about</attribute>
</item>
</section>
</menu>
<menu id="board-menu">
<section>
<item>
<attribute name="label" translatable="yes">Preferences</attribute>
<attribute name="action">win.preferences</attribute>
</item>
<item>
<attribute name="label" translatable="yes">About Progress</attribute>
<attribute name="action">win.about</attribute>
</item>
</section>
</menu>
</object>
</child>
</object>
<menu id="board-grid-menu">
<section>
<item>
<attribute name="action">win.delete</attribute>
<attribute name="label" translatable="yes">Delete Boards</attribute>
</item>
<item>
<attribute name="action">win.about</attribute>
<attribute name="label" translatable="yes">About Progress</attribute>
</item>
</section>
</menu>
<menu id="board-menu">
<section>
<item>
<attribute name="action">win.preferences</attribute>
<attribute name="label" translatable="yes">Preferences</attribute>
</item>
<item>
<attribute name="action">win.about</attribute>
<attribute name="label" translatable="yes">About Progress</attribute>
</item>
</section>
</menu>
</interface>

36 changes: 29 additions & 7 deletions src/widgets/card.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ class CardWidget : public Gtk::Box {
/**
* @brief CardWidget constructor
*
* @param card_ptr a smart pointer pointing to a Card object.
* @param card a smart pointer pointing to a Card object.
* @param is_new flag indicating whether this object is being created from
* scratch rather than being loaded from a Progress board file. True means
* the Card did not come from a file otherwise False
*/
CardWidget(BaseObjectType* cobject,
const Glib::RefPtr<Gtk::Builder>& builder,
std::shared_ptr<Card> card_refptr, bool is_new = false);
std::shared_ptr<Card> card, bool is_new = false);

void set_label(const std::string& label);
void set_title(const std::string& label);

std::string get_text() const;
std::string get_title() const;

/**
* @brief Removes itself from the associated CardlistWidget object.
Expand All @@ -41,9 +41,6 @@ class CardWidget : public Gtk::Box {
* @brief Sets a new parent to this card.
*
* @param cardlist_p pointer to a new CardlistWidget object (parent)
*
* @details Cards in Progress Tracker are the only ones that changes parents
* with a certain frequency, that's why this method exists.
*/
void set_cardlist(ui::CardlistWidget* cardlist_p);

Expand All @@ -61,13 +58,38 @@ class CardWidget : public Gtk::Box {
*/
std::shared_ptr<Card> get_card();

/**
* @brief Gets the cardlist widget from which this widget is associated with
*/
CardlistWidget const* get_cardlist_widget() const;

/**
* @brief Updates label informing the amount of tasks complete
*/
void update_complete_tasks();

/**
* @brief Updates label informing due date for this card
*/
void update_due_date();

/**
* @brief Changes due date label colour depending on the card's
* situation. Red if it is past due date, green if it is complete and plain
* colour if it is due but not yet complete
*/
void update_due_date_label_style();

/**
* @brief Changes the complete tasks label colour depending on the amount of
* tasks complete. Green if all tasks are complete, Yellow if half of the
* tasks are complete and Red if less than half of the task are complete
*/
void update_complete_tasks_style(unsigned long n_complete_tasks);

/**
* @brief Helper method for creating a tooltip text for the card widget
*/
std::string create_details_text() const;

protected:
Expand Down
28 changes: 14 additions & 14 deletions src/widgets/cardlist-widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ui::CardlistWidget::CardlistWidget(BoardWidget& board,
: Gtk::ListBox{},
add_card_button{_("Add card")},
root{Gtk::Orientation::VERTICAL},
cards_tracker{},
card_widgets{},
board{board},
cardlist{cardlist_refptr},
is_new{is_new},
Expand Down Expand Up @@ -47,7 +47,7 @@ ui::CardlistWidget::CardlistWidget(BoardWidget& board,
add_card_button.set_halign(Gtk::Align::FILL);
add_card_button.set_hexpand(true);
add_card_button.signal_clicked().connect(
[this]() { this->add_card(Card{_("New Card")}, true); });
[this]() { this->add(Card{_("New Card")}, true); });
root.append(add_card_button);

append(cardlist_header);
Expand All @@ -57,7 +57,7 @@ ui::CardlistWidget::CardlistWidget(BoardWidget& board,
auto cardwidget =
Gtk::manage(cur_builder->get_widget_derived<CardWidget>(
cur_builder, "card-root", card));
cards_tracker.push_back(cardwidget);
card_widgets.push_back(cardwidget);
cardwidget->set_cardlist(this);
root.append(*cardwidget);
root.reorder_child_after(add_card_button, *cardwidget);
Expand All @@ -83,15 +83,15 @@ ui::CardlistWidget::CardlistWidget(BoardWidget& board,

ui::CardlistWidget::~CardlistWidget() {}

void ui::CardlistWidget::reorder_cardwidget(ui::CardWidget& next,
void ui::CardlistWidget::reorder(ui::CardWidget& next,
ui::CardWidget& sibling) {
root.reorder_child_after(next, sibling);
cardlist->reorder(*next.get_card(), *sibling.get_card());
}

const std::vector<ui::CardWidget*>&
ui::CardlistWidget::get_cardwidget_vector() {
return cards_tracker;
ui::CardlistWidget::get_card_widgets() {
return card_widgets;
}

void ui::CardlistWidget::setup_drag_and_drop() {
Expand Down Expand Up @@ -168,7 +168,7 @@ void ui::CardlistWidget::setup_drag_and_drop() {
if (!this->is_child(dropped_card)) {
auto card_in_dropped = dropped_card->get_card();
dropped_card->remove_from_parent();
this->add_card(*card_in_dropped);
this->add(*card_in_dropped);
}
return true;
}
Expand All @@ -178,26 +178,26 @@ void ui::CardlistWidget::setup_drag_and_drop() {
add_controller(drop_target_card);
}

void ui::CardlistWidget::remove_card(ui::CardWidget* card) {
void ui::CardlistWidget::remove(ui::CardWidget* card) {
root.remove(*card);
cardlist->remove(*card->get_card());

for (size_t i = 0; i < cards_tracker.size(); i++) {
if (cards_tracker[i] == card) {
cards_tracker.erase(cards_tracker.begin() + i);
for (size_t i = 0; i < card_widgets.size(); i++) {
if (card_widgets[i] == card) {
card_widgets.erase(card_widgets.begin() + i);
}
}
}

ui::CardWidget* ui::CardlistWidget::add_card(const Card& card,
ui::CardWidget* ui::CardlistWidget::add(const Card& card,
bool editing_mode) {
auto card_builder = Gtk::Builder::create_from_resource(
"/io/github/smolblackcat/Progress/card-widget.ui");
auto new_card = Gtk::manage(Gtk::Builder::get_widget_derived<CardWidget>(
card_builder, "card-root", cardlist->add(card), editing_mode));
new_card->set_cardlist(this);

cards_tracker.push_back(new_card);
card_widgets.push_back(new_card);
root.append(*new_card);
root.reorder_child_after(add_card_button, *new_card);
return new_card;
Expand All @@ -208,7 +208,7 @@ const std::shared_ptr<CardList>& ui::CardlistWidget::get_cardlist() {
}

bool ui::CardlistWidget::is_child(ui::CardWidget* card) {
for (auto& card_ : cards_tracker) {
for (auto& card_ : card_widgets) {
if (card == card_) return true;
}
return false;
Expand Down
Loading

0 comments on commit 8ef401e

Please sign in to comment.