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 <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2015-04-19 12:13:32 -04:00
parent 2c45cf3972
commit 1d0f392835
8 changed files with 44 additions and 36 deletions

View File

@ -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<Gtk::Notebook>("o_notebook")->insert_page(tab_vbox, *collection_label, 0);
}

View File

@ -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<Gtk::Notebook>("o_notebook")->insert_page(tab_vbox, *history_label, 0);
}

View File

@ -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);

View File

@ -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<Gtk::Notebook>("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) + ". ");

View File

@ -1,6 +1,7 @@
/*
* Copyright 2015 (c) Anna Schumaker.
*/
#include <core/string.h>
#include <gui/queue/label.h>
@ -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()));
}

View File

@ -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);

View File

@ -4,25 +4,31 @@
#ifndef OCARINA_GUI_QUEUE_LABEL_H
#define OCARINA_GUI_QUEUE_LABEL_H
#include <core/queue.h>
#include <gtkmm.h>
class QueueLabel : public Gtk::HBox {
protected:
Glib::RefPtr<Gtk::Builder> _builder;
Queue *_queue;
public:
QueueLabel(BaseObjectType *, const Glib::RefPtr<Gtk::Builder>);
~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<Gtk::Builder>);
void set_size();
};
@ -32,6 +38,7 @@ public:
Gtk::Label *history_size;
HistoryLabel(BaseObjectType *, const Glib::RefPtr<Gtk::Builder>);
void set_size();
};
@ -51,6 +58,7 @@ public:
TempLabel(BaseObjectType *, const Glib::RefPtr<Gtk::Builder>);
void set_sensitive(bool);
void set_size();
};
#endif /* OCARINA_GUI_QUEUE_LABEL_H */

View File

@ -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: