From 1d0f39283547d0bc7c4730d4436581986314eff8 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Sun, 19 Apr 2015 12:13:32 -0400 Subject: [PATCH] gui: Give tab labels a set_size() function This lets them set themselves whenever values change. Additionally, I update the Tab class to take a QueueLabel instead of the "size label" Signed-off-by: Anna Schumaker --- gui/collection.cpp | 6 +++--- gui/history.cpp | 5 +++-- gui/playlist.cpp | 2 ++ gui/queue.cpp | 16 ++-------------- gui/queue/label.cpp | 22 ++++++++++++++++++++++ gui/tabs.cpp | 13 +++---------- include/gui/queue/label.h | 8 ++++++++ include/gui/tabs.h | 8 +------- 8 files changed, 44 insertions(+), 36 deletions(-) diff --git a/gui/collection.cpp b/gui/collection.cpp index 725f7a56..01dcb908 100644 --- a/gui/collection.cpp +++ b/gui/collection.cpp @@ -18,10 +18,10 @@ public: tab_builder->get_widget_derived("CollectionLabel", collection_label); tab_toolbar->init(tab_pq, collection_label, tab_window, T_RANDOM); + collection_label->init(tab_pq); + tab_label = collection_label; + tab_vbox.pack_start(*tab_window, true, true); - - tab_size = collection_label->collection_size; - gui :: get_widget("o_notebook")->insert_page(tab_vbox, *collection_label, 0); } diff --git a/gui/history.cpp b/gui/history.cpp index ca3ba3d0..c2bb45cd 100644 --- a/gui/history.cpp +++ b/gui/history.cpp @@ -17,9 +17,10 @@ public: tab_builder->get_widget_derived("HistoryLabel", history_label); tab_toolbar->init(tab_pq, history_label, tab_window, 0); - tab_vbox.pack_start(*tab_window, true, true); + history_label->init(tab_pq); + tab_label = history_label; - tab_size = history_label->history_size; + tab_vbox.pack_start(*tab_window, true, true); gui :: get_widget("o_notebook")->insert_page(tab_vbox, *history_label, 0); } diff --git a/gui/playlist.cpp b/gui/playlist.cpp index 66e27d18..854bef21 100644 --- a/gui/playlist.cpp +++ b/gui/playlist.cpp @@ -84,6 +84,8 @@ public: tab_builder->get_widget_derived("PlaylistWindow", playlist_window); tab_toolbar->init(tab_pq, playlist_label, tab_window, 0); + playlist_label->init(tab_pq); + tab_label = playlist_label; playlist_hbox.pack_start(*playlist_window, false, true); playlist_hbox.pack_start(*tab_window, true, true); diff --git a/gui/queue.cpp b/gui/queue.cpp index 5fa7d7e6..f7cd7eea 100644 --- a/gui/queue.cpp +++ b/gui/queue.cpp @@ -48,7 +48,6 @@ public: * Helper functions */ bool on_key_press_event(const std::string &); - void tab_set_size(); void queue_set_number(unsigned int); void on_tab_reordered(); void on_move_queue(int); @@ -74,8 +73,9 @@ QueueTab :: QueueTab(Queue *pq, unsigned int num) q_label->temp_close->signal_clicked().connect(sigc::mem_fun(*this, &QueueTab::on_close_clicked)); + q_label->init(tab_pq); + tab_label = q_label; - tab_set_size(); queue_set_number(num); @@ -91,13 +91,6 @@ QueueTab :: QueueTab(Queue *pq, unsigned int num) tab_vbox.pack_start(*tab_window, true, true); - - /* - * Set generic tab widgets - */ - - tab_size = q_label->temp_size; - queue_mapping[&tab_vbox] = this; gui :: get_widget("o_notebook")->insert_page(tab_vbox, *q_label, num); @@ -152,11 +145,6 @@ bool QueueTab :: on_key_press_event(const std::string &key) return true; } -void QueueTab :: tab_set_size() -{ - q_label->temp_size->set_text(string :: utos(tab_pq->size())); -} - void QueueTab :: queue_set_number(unsigned int num) { q_label->temp_number->set_text(string :: utos(num) + ". "); diff --git a/gui/queue/label.cpp b/gui/queue/label.cpp index 573ceb96..1c76b7ec 100644 --- a/gui/queue/label.cpp +++ b/gui/queue/label.cpp @@ -1,6 +1,7 @@ /* * Copyright 2015 (c) Anna Schumaker. */ +#include #include @@ -15,6 +16,12 @@ QueueLabel :: ~QueueLabel() { } +void QueueLabel :: init(Queue *queue) +{ + _queue = queue; + set_size(); +} + CollectionLabel :: CollectionLabel(BaseObjectType *cobject, @@ -24,6 +31,11 @@ CollectionLabel :: CollectionLabel(BaseObjectType *cobject, _builder->get_widget("collection_size", collection_size); } +void CollectionLabel :: set_size() +{ + collection_size->set_text(string :: utos(_queue->size())); +} + HistoryLabel :: HistoryLabel(BaseObjectType *cobject, @@ -33,6 +45,11 @@ HistoryLabel :: HistoryLabel(BaseObjectType *cobject, _builder->get_widget("history_size", history_size); } +void HistoryLabel :: set_size() +{ + history_size->set_text(string :: utos(_queue->size())); +} + PlaylistLabel :: PlaylistLabel(BaseObjectType *cobject, @@ -57,3 +74,8 @@ void TempLabel :: set_sensitive(bool sensitive) temp_number->set_sensitive(sensitive); temp_size->set_sensitive(sensitive); } + +void TempLabel :: set_size() +{ + temp_size->set_text(string :: utos(_queue->size())); +} diff --git a/gui/tabs.cpp b/gui/tabs.cpp index f472198c..a69896cf 100644 --- a/gui/tabs.cpp +++ b/gui/tabs.cpp @@ -27,7 +27,7 @@ static sort_t sort_fields[] = { */ Tab :: Tab(Queue *pq) - : tab_sorting_count(0), tab_pq(pq), tab_size(NULL) + : tab_sorting_count(0), tab_pq(pq), tab_label(NULL) { pq->set_notifier(this); queue_mapping[tab_pq] = this; @@ -56,7 +56,6 @@ Tab :: Tab(Queue *pq) tab_vbox.pack_start(*tab_toolbar, false, true, 2); tab_vbox.show(); - tab_set_size(); tab_runtime_changed(); } @@ -72,14 +71,14 @@ Tab :: ~Tab() {} void Tab :: on_track_added(unsigned int row) { tab_window->q_model->on_row_inserted(row); - tab_set_size(); + tab_label->set_size(); tab_runtime_changed(); } void Tab :: on_track_removed(unsigned int row) { tab_window->q_model->on_row_deleted(row); - tab_set_size(); + tab_label->set_size(); tab_runtime_changed(); } @@ -128,12 +127,6 @@ void Tab :: tab_dec_sort_count() tab_display_sorting(); } -void Tab :: tab_set_size() -{ - if (tab_size) - tab_size->set_text(string :: utos(tab_pq->size())); -} - void Tab :: tab_unmap() { queue_mapping.erase(tab_pq); diff --git a/include/gui/queue/label.h b/include/gui/queue/label.h index 328eb86d..feb54e1e 100644 --- a/include/gui/queue/label.h +++ b/include/gui/queue/label.h @@ -4,25 +4,31 @@ #ifndef OCARINA_GUI_QUEUE_LABEL_H #define OCARINA_GUI_QUEUE_LABEL_H +#include #include class QueueLabel : public Gtk::HBox { protected: Glib::RefPtr _builder; + Queue *_queue; public: QueueLabel(BaseObjectType *, const Glib::RefPtr); ~QueueLabel(); + virtual void init(Queue *); virtual void set_sensitive(bool) {}; + virtual void set_size() {}; }; + class CollectionLabel : public QueueLabel { public: Gtk::Label *collection_size; CollectionLabel(BaseObjectType *, const Glib::RefPtr); + void set_size(); }; @@ -32,6 +38,7 @@ public: Gtk::Label *history_size; HistoryLabel(BaseObjectType *, const Glib::RefPtr); + void set_size(); }; @@ -51,6 +58,7 @@ public: TempLabel(BaseObjectType *, const Glib::RefPtr); void set_sensitive(bool); + void set_size(); }; #endif /* OCARINA_GUI_QUEUE_LABEL_H */ diff --git a/include/gui/tabs.h b/include/gui/tabs.h index 290c5919..ddabb8e6 100644 --- a/include/gui/tabs.h +++ b/include/gui/tabs.h @@ -22,18 +22,12 @@ protected: QueueToolbar *tab_toolbar; QueueWindow *tab_window; - - /** - * Optional widgets that MAY be set - */ - Gtk::Label *tab_size; - + QueueLabel *tab_label; /** * Class helper functions */ void tab_dec_sort_count(); - virtual void tab_set_size(); void tab_unmap(); public: