gui: Split apart tab and tab label
I made a new tab label class to make it easier to have a few labels with different layouts. Signed-off-by: Anna Schumaker <schumaker.anna@gmail.com>
This commit is contained in:
parent
9e68f8213b
commit
7d10ebe5c3
|
@ -52,6 +52,8 @@
|
|||
<object class="GtkFileChooserWidget" id="o_collection_chooser">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="margin_left">5</property>
|
||||
<property name="margin_right">5</property>
|
||||
<property name="action">select-folder</property>
|
||||
<property name="create_folders">False</property>
|
||||
<property name="preview_widget_active">False</property>
|
||||
|
|
104
gui/tabs.cpp
104
gui/tabs.cpp
|
@ -10,8 +10,8 @@
|
|||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
class OcarinaTab;
|
||||
static std::map<Playqueue *, OcarinaTab *> tab_map;
|
||||
class OcarinaPage;
|
||||
static std::map<Playqueue *, OcarinaPage *> tab_map;
|
||||
|
||||
static class QueueColumns : public Gtk::TreeModelColumnRecord {
|
||||
public:
|
||||
|
@ -33,18 +33,60 @@ public:
|
|||
static unsigned int q_col_width[] = { 20, 300, 60, 100, 100, 45, 100, 60, 1 };
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Tab class definition
|
||||
*/
|
||||
class OcarinaTab {
|
||||
public:
|
||||
Gtk::Label name_label;
|
||||
Gtk::Label size_label;
|
||||
Gtk::Image tab_icon;
|
||||
Gtk::HBox box;
|
||||
Gtk::VBox inner_box;
|
||||
|
||||
OcarinaTab(const std::string &, const std::string &);
|
||||
~OcarinaTab();
|
||||
void set_size(unsigned int);
|
||||
};
|
||||
|
||||
OcarinaTab::OcarinaTab(const std::string &name, const std::string &icon)
|
||||
: name_label("<big>" + name + "</big>", 1, 0.5),
|
||||
size_label("0", 0.5, 0.5)
|
||||
{
|
||||
tab_icon.set_from_icon_name(icon, Gtk::ICON_SIZE_MENU);
|
||||
name_label.set_use_markup();
|
||||
name_label.set_margin_right(1);
|
||||
box.set_spacing(5);
|
||||
|
||||
inner_box.pack_start(name_label);
|
||||
inner_box.pack_start(size_label);
|
||||
|
||||
box.pack_start(tab_icon);
|
||||
box.pack_start(inner_box);
|
||||
box.show_all();
|
||||
}
|
||||
|
||||
OcarinaTab::~OcarinaTab() {}
|
||||
|
||||
void OcarinaTab::set_size(unsigned int size)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << size;
|
||||
size_label.set_text(ss.str());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Ocarina class definition
|
||||
*/
|
||||
class OcarinaPage {
|
||||
private:
|
||||
Glib::RefPtr<PlayqueueModel> model;
|
||||
Gtk::Notebook *notebook;
|
||||
|
||||
/* Tab widgets */
|
||||
Gtk::VBox tab_box;
|
||||
Gtk::Label tab_name;
|
||||
Gtk::Label tab_size;
|
||||
OcarinaTab tab;
|
||||
|
||||
/* Page widgets */
|
||||
Gtk::VBox page_box;
|
||||
|
@ -59,8 +101,8 @@ private:
|
|||
void set_tab_size();
|
||||
|
||||
public:
|
||||
OcarinaTab(const std::string &, Playqueue *);
|
||||
~OcarinaTab();
|
||||
OcarinaPage(const std::string &, const std::string &, Playqueue *);
|
||||
~OcarinaPage();
|
||||
bool is_current_tab();
|
||||
bool is_current_tab(unsigned int);
|
||||
|
||||
|
@ -70,22 +112,14 @@ public:
|
|||
};
|
||||
|
||||
|
||||
OcarinaTab::OcarinaTab(const std::string &text, Playqueue *pq)
|
||||
: tab_name("<big>" + text + "</big>", 1, 0.5),
|
||||
tab_size("0", 1, 0.5)
|
||||
OcarinaPage::OcarinaPage(const std::string &name, const std::string &icon,
|
||||
Playqueue *pq)
|
||||
: tab(name, icon)
|
||||
{
|
||||
get_builder()->get_widget("o_notebook", notebook);
|
||||
model = Glib::RefPtr<PlayqueueModel>(new PlayqueueModel(pq));
|
||||
|
||||
|
||||
/* Make tab label */
|
||||
tab_name.set_use_markup();
|
||||
tab_box.pack_start(tab_name);
|
||||
tab_box.pack_start(tab_size);
|
||||
tab_box.show_all();
|
||||
set_tab_size();
|
||||
|
||||
|
||||
/* Make page content */
|
||||
page_random.set_image_from_icon_name("media-playlist-shuffle");
|
||||
page_random.set_active(pq->get_flags() & PQ_RANDOM);
|
||||
|
@ -115,17 +149,17 @@ OcarinaTab::OcarinaTab(const std::string &text, Playqueue *pq)
|
|||
|
||||
|
||||
/* Add to notebook */
|
||||
notebook->prepend_page(page_box, tab_box);
|
||||
notebook->prepend_page(page_box, tab.box);
|
||||
tab_map[pq] = this;
|
||||
};
|
||||
|
||||
OcarinaTab::~OcarinaTab()
|
||||
OcarinaPage::~OcarinaPage()
|
||||
{
|
||||
notebook->remove_page(page_box);
|
||||
tab_map.erase(model->queue);
|
||||
}
|
||||
|
||||
void OcarinaTab::setup_columns()
|
||||
void OcarinaPage::setup_columns()
|
||||
{
|
||||
std::vector<Gtk::TreeViewColumn *> columns = page_view.get_columns();
|
||||
for (unsigned int i = 0; i < columns.size(); i++) {
|
||||
|
@ -135,24 +169,22 @@ void OcarinaTab::setup_columns()
|
|||
}
|
||||
}
|
||||
|
||||
bool OcarinaTab::is_current_tab()
|
||||
bool OcarinaPage::is_current_tab()
|
||||
{
|
||||
return notebook->page_num(page_box) == notebook->get_current_page();
|
||||
}
|
||||
|
||||
bool OcarinaTab::is_current_tab(unsigned int tab)
|
||||
bool OcarinaPage::is_current_tab(unsigned int tab)
|
||||
{
|
||||
return notebook->page_num(page_box) == (int)tab;
|
||||
}
|
||||
|
||||
void OcarinaTab::set_tab_size()
|
||||
void OcarinaPage::set_tab_size()
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << model->queue->size();
|
||||
tab_size.set_text(ss.str());
|
||||
tab.set_size(model->queue->size());
|
||||
}
|
||||
|
||||
void OcarinaTab::on_row_inserted(unsigned int row)
|
||||
void OcarinaPage::on_row_inserted(unsigned int row)
|
||||
{
|
||||
model->on_row_inserted(row);
|
||||
set_tab_size();
|
||||
|
@ -160,7 +192,7 @@ void OcarinaTab::on_row_inserted(unsigned int row)
|
|||
on_runtime_changed();
|
||||
}
|
||||
|
||||
void OcarinaTab::on_row_deleted(unsigned int row)
|
||||
void OcarinaPage::on_row_deleted(unsigned int row)
|
||||
{
|
||||
model->on_row_deleted(row);
|
||||
set_tab_size();
|
||||
|
@ -168,7 +200,7 @@ void OcarinaTab::on_row_deleted(unsigned int row)
|
|||
on_runtime_changed();
|
||||
}
|
||||
|
||||
void OcarinaTab::on_runtime_changed()
|
||||
void OcarinaPage::on_runtime_changed()
|
||||
{
|
||||
Gtk::Label *label;
|
||||
get_builder()->get_widget("o_queue_time", label);
|
||||
|
@ -183,7 +215,7 @@ void OcarinaTab::on_runtime_changed()
|
|||
*/
|
||||
static void on_track_added(Playqueue *pq, unsigned int row)
|
||||
{
|
||||
std::map<Playqueue *, OcarinaTab *>::iterator it;
|
||||
std::map<Playqueue *, OcarinaPage *>::iterator it;
|
||||
it = tab_map.find(pq);
|
||||
if (it != tab_map.end())
|
||||
it->second->on_row_inserted(row);
|
||||
|
@ -191,7 +223,7 @@ static void on_track_added(Playqueue *pq, unsigned int row)
|
|||
|
||||
static void on_track_deleted(Playqueue *pq, unsigned int row)
|
||||
{
|
||||
std::map<Playqueue *, OcarinaTab *>::iterator it;
|
||||
std::map<Playqueue *, OcarinaPage *>::iterator it;
|
||||
it = tab_map.find(pq);
|
||||
if (it != tab_map.end())
|
||||
it->second->on_row_deleted(row);
|
||||
|
@ -200,7 +232,7 @@ static void on_track_deleted(Playqueue *pq, unsigned int row)
|
|||
static void on_switch_page(Gtk::Widget *page, unsigned int num)
|
||||
{
|
||||
Gtk::Label *label;
|
||||
std::map<Playqueue *, OcarinaTab *>::iterator it;
|
||||
std::map<Playqueue *, OcarinaPage *>::iterator it;
|
||||
get_builder()->get_widget("o_queue_time", label);
|
||||
|
||||
for (it = tab_map.begin(); it != tab_map.end(); it++) {
|
||||
|
@ -219,7 +251,7 @@ void init_tabs()
|
|||
Gtk::Notebook *notebook;
|
||||
get_builder()->get_widget("o_notebook", notebook);
|
||||
|
||||
new OcarinaTab("Collection", deck::get_library_pq());
|
||||
new OcarinaPage("Collection", "media-optical", deck::get_library_pq());
|
||||
get_callbacks()->on_queue_track_add = on_track_added;
|
||||
get_callbacks()->on_queue_track_del = on_track_deleted;
|
||||
|
||||
|
@ -228,7 +260,7 @@ void init_tabs()
|
|||
|
||||
void cleanup_tabs()
|
||||
{
|
||||
std::map<Playqueue *, OcarinaTab *>::iterator it;
|
||||
std::map<Playqueue *, OcarinaPage *>::iterator it;
|
||||
for (it = tab_map.begin(); it != tab_map.end(); it++)
|
||||
delete it->second;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue