gui: Create a custom Gtk::TreeView for queues

The QueueView doesn't contain too much in terms of code, but the
corresponding QueueView.ui file lets me remove a lot of unnecessary
stuff from temporary queue creation!

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2015-04-09 10:30:54 -04:00
parent 6dfb3c31e2
commit 1e29ba8cc6
5 changed files with 196 additions and 33 deletions

1
.gitignore vendored
View File

@ -2,6 +2,7 @@
*.sw*
*.out
*.glade~
*.ui~
share/ocarina/#*
bin/
.sconsign.dblite

View File

@ -4,10 +4,10 @@
#include <core/deck.h>
#include <core/string.h>
#include <gui/tabs.h>
#include <gui/queue/view.h>
static void renumber_queues();
static unsigned int q_col_width[] = { 20, 300, 60, 100, 100, 45, 100, 60, 1 };
static class QueueColumns : public Gtk::TreeModelColumnRecord {
public:
@ -33,6 +33,8 @@ public:
class QueueTab : public Tab {
private:
Glib::RefPtr<Gtk::Builder> builder;
/**
* Queue tab widgets
*/
@ -58,7 +60,7 @@ private:
/* Treeview widgets */
Gtk::ScrolledWindow q_window;
Gtk::TreeView q_treeview;
QueueView *q_treeview;
public:
@ -92,6 +94,9 @@ static std::map<Gtk::Widget *, QueueTab *> queue_mapping;
QueueTab :: QueueTab(Queue *pq, unsigned int num)
: Tab(pq)
{
builder = Gtk::Builder::create();
builder->add_from_file(gui :: share_file("QueueView.ui"));
/*
* Create our tab widget
*/
@ -131,12 +136,12 @@ QueueTab :: QueueTab(Queue *pq, unsigned int num)
/*
* And the treeview with scrolled window
*/
builder->get_widget_derived("QueueView", q_treeview);
q_window.set_shadow_type(Gtk::SHADOW_IN);
q_window.set_margin_left(5);
q_window.set_margin_right(5);
q_window.set_margin_bottom(5);
q_window.add(q_treeview);
setup_treeview();
q_window.add(*q_treeview);
/*
@ -158,7 +163,7 @@ QueueTab :: QueueTab(Queue *pq, unsigned int num)
tab_repeat = &q_repeat;
tab_search = &q_search;
tab_size = &q_tab_size;
tab_treeview = &q_treeview;
tab_treeview = q_treeview;
tab_widget = &q_vbox;
tab_finish_init();
@ -192,33 +197,6 @@ void QueueTab :: on_track_removed(unsigned int row)
*
*/
void QueueTab :: setup_treeview()
{
q_treeview.append_column("#", queue_cols.q_col_track);
q_treeview.append_column("Title", queue_cols.q_col_title);
q_treeview.append_column("Length", queue_cols.q_col_length);
q_treeview.append_column("Artist", queue_cols.q_col_artist);
q_treeview.append_column("Album", queue_cols.q_col_album);
q_treeview.append_column("Year", queue_cols.q_col_year);
q_treeview.append_column("Genre", queue_cols.q_col_genre);
q_treeview.append_column("Count", queue_cols.q_col_count);
q_treeview.append_column("Played", queue_cols.q_col_played);
q_treeview.set_tooltip_column(9);
q_treeview.set_enable_search(false);
q_treeview.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
q_treeview.set_rubber_banding();
std::vector<Gtk::TreeViewColumn *> columns = q_treeview.get_columns();
for (unsigned int i = 0; i < columns.size(); i++) {
columns[i]->set_resizable();
columns[i]->set_fixed_width(q_col_width[i]);
columns[i]->set_sizing(Gtk::TREE_VIEW_COLUMN_FIXED);
columns[i]->set_clickable();
}
}
void QueueTab :: on_post_init()
{
tab_init_random();
@ -284,7 +262,7 @@ void QueueTab :: queue_set_sensitive(bool sensitive)
{
q_tab_number.set_sensitive(sensitive);
q_tab_size.set_sensitive(sensitive);
q_treeview.set_sensitive(sensitive);
q_treeview->set_sensitive(sensitive);
}

14
gui/queue/view.cpp Normal file
View File

@ -0,0 +1,14 @@
/*
* Copyright 2015 (c) Anna Schumaker.
*/
#include <gui/queue/view.h>
QueueView :: QueueView(BaseObjectType *cobject,
const Glib::RefPtr<Gtk::Builder> builder)
: Gtk::TreeView(cobject), _builder(builder)
{
}
QueueView :: ~QueueView()
{
}

18
include/gui/queue/view.h Normal file
View File

@ -0,0 +1,18 @@
/*
* Copyright 2015 (c) Anna Schumaker.
*/
#ifndef OCARINA_GUI_QUEUE_VIEW_H
#define OCARINA_GUI_QUEUE_VIEW_H
#include <gtkmm.h>
class QueueView : public Gtk::TreeView {
private:
Glib::RefPtr<Gtk::Builder> _builder;
public:
QueueView(BaseObjectType *, const Glib::RefPtr<Gtk::Builder>);
~QueueView();
};
#endif /* OCARINA_GUI_QUEUE_VIEW_H */

152
share/ocarina/QueueView.ui Normal file
View File

@ -0,0 +1,152 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.18.3 -->
<interface>
<requires lib="gtk+" version="3.12"/>
<object class="GtkTreeView" id="QueueView">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="enable_search">False</property>
<property name="rubber_banding">True</property>
<property name="tooltip_column">9</property>
<child internal-child="selection">
<object class="GtkTreeSelection" id="treeview-selection1">
<property name="mode">multiple</property>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn1">
<property name="resizable">True</property>
<property name="sizing">fixed</property>
<property name="fixed_width">20</property>
<property name="title" translatable="yes">#</property>
<property name="clickable">True</property>
<child>
<object class="GtkCellRendererText" id="cellrenderertext1"/>
<attributes>
<attribute name="text">0</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn2">
<property name="resizable">True</property>
<property name="sizing">fixed</property>
<property name="fixed_width">300</property>
<property name="title" translatable="yes">Title</property>
<property name="clickable">True</property>
<child>
<object class="GtkCellRendererText" id="cellrenderertext2"/>
<attributes>
<attribute name="text">1</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn3">
<property name="resizable">True</property>
<property name="sizing">fixed</property>
<property name="fixed_width">60</property>
<property name="title" translatable="yes">Length</property>
<property name="clickable">True</property>
<child>
<object class="GtkCellRendererText" id="cellrenderertext3"/>
<attributes>
<attribute name="text">2</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn4">
<property name="resizable">True</property>
<property name="sizing">fixed</property>
<property name="fixed_width">100</property>
<property name="title" translatable="yes">Artist</property>
<property name="clickable">True</property>
<child>
<object class="GtkCellRendererText" id="cellrenderertext4"/>
<attributes>
<attribute name="text">3</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn5">
<property name="resizable">True</property>
<property name="sizing">fixed</property>
<property name="fixed_width">100</property>
<property name="title" translatable="yes">Album</property>
<property name="clickable">True</property>
<child>
<object class="GtkCellRendererText" id="cellrenderertext5"/>
<attributes>
<attribute name="text">4</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn6">
<property name="resizable">True</property>
<property name="sizing">fixed</property>
<property name="fixed_width">45</property>
<property name="title" translatable="yes">Year</property>
<property name="clickable">True</property>
<child>
<object class="GtkCellRendererText" id="cellrenderertext6"/>
<attributes>
<attribute name="text">5</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn7">
<property name="resizable">True</property>
<property name="sizing">fixed</property>
<property name="fixed_width">100</property>
<property name="title" translatable="yes">Genre</property>
<property name="clickable">True</property>
<child>
<object class="GtkCellRendererText" id="cellrenderertext7"/>
<attributes>
<attribute name="text">6</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn8">
<property name="resizable">True</property>
<property name="sizing">fixed</property>
<property name="fixed_width">60</property>
<property name="title" translatable="yes">Count</property>
<property name="clickable">True</property>
<child>
<object class="GtkCellRendererText" id="cellrenderertext8"/>
<attributes>
<attribute name="text">7</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn9">
<property name="resizable">True</property>
<property name="sizing">fixed</property>
<property name="fixed_width">1</property>
<property name="title" translatable="yes">Played</property>
<property name="clickable">True</property>
<child>
<object class="GtkCellRendererText" id="cellrenderertext9"/>
<attributes>
<attribute name="text">8</attribute>
</attributes>
</child>
</object>
</child>
</object>
</interface>