From da89012c7b4916c09731a3d54a8d0e0b29f5b860 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Fri, 10 Apr 2015 08:30:53 -0400 Subject: [PATCH] gui: Build QueueToolbar from a separate file This should help clean up the code a bit, especially once I convert all queues to load with the template files. Signed-off-by: Anna Schumaker --- gui/queue.cpp | 36 +++++----------- gui/queue/toolbar.cpp | 18 ++++++++ include/gui/queue/toolbar.h | 23 ++++++++++ share/ocarina/QueueToolbar.ui | 79 +++++++++++++++++++++++++++++++++++ 4 files changed, 131 insertions(+), 25 deletions(-) create mode 100644 gui/queue/toolbar.cpp create mode 100644 include/gui/queue/toolbar.h create mode 100644 share/ocarina/QueueToolbar.ui diff --git a/gui/queue.cpp b/gui/queue.cpp index 54504906..6c8a6939 100644 --- a/gui/queue.cpp +++ b/gui/queue.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include @@ -52,11 +53,7 @@ private: /** * Toolbar widgets */ - Gtk::HBox q_toolbar_box; - Gtk::SearchEntry q_search; - Gtk::ToggleButton q_random; - Gtk::ToggleButton q_repeat; - Gtk::Switch q_switch; + QueueToolbar *q_toolbar; /* Treeview widgets */ Gtk::ScrolledWindow q_window; @@ -96,6 +93,7 @@ QueueTab :: QueueTab(Queue *pq, unsigned int num) { builder = Gtk::Builder::create(); builder->add_from_file(gui :: share_file("QueueView.ui")); + builder->add_from_file(gui :: share_file("QueueToolbar.ui")); /* * Create our tab widget @@ -119,19 +117,7 @@ QueueTab :: QueueTab(Queue *pq, unsigned int num) /* * Now set up the toolbar */ - q_repeat.set_image_from_icon_name("media-playlist-repeat", Gtk::ICON_SIZE_BUTTON); - q_random.set_image_from_icon_name("media-playlist-shuffle", Gtk::ICON_SIZE_BUTTON); - - q_toolbar_box.set_margin_left(5); - q_toolbar_box.set_margin_right(5); - q_toolbar_box.set_spacing(5); - q_toolbar_box.set_homogeneous(false); - - q_toolbar_box.pack_start(q_search, true, true); - q_toolbar_box.pack_start(q_switch, false, true); - q_toolbar_box.pack_start(q_repeat, false, true); - q_toolbar_box.pack_start(q_random, false, true); - + builder->get_widget_derived("QueueToolbar", q_toolbar); /* * And the treeview with scrolled window @@ -151,7 +137,7 @@ QueueTab :: QueueTab(Queue *pq, unsigned int num) q_vbox.set_margin_left(1); q_vbox.set_margin_right(1); q_vbox.set_homogeneous(false); - q_vbox.pack_start(q_toolbar_box, false, true, 2); + q_vbox.pack_start(*q_toolbar, false, true, 2); q_vbox.pack_start(q_window, true, true); @@ -159,9 +145,9 @@ QueueTab :: QueueTab(Queue *pq, unsigned int num) * Set generic tab widgets */ - tab_random = &q_random; - tab_repeat = &q_repeat; - tab_search = &q_search; + tab_random = q_toolbar->q_random; + tab_repeat = q_toolbar->q_repeat; + tab_search = q_toolbar->q_search; tab_size = &q_tab_size; tab_treeview = q_treeview; tab_widget = &q_vbox; @@ -203,8 +189,8 @@ void QueueTab :: on_post_init() tab_init_repeat(); bool active = (tab_pq->has_flag(Q_ENABLED)); - q_switch.set_active(active); - q_switch.property_active().signal_changed().connect( + q_toolbar->q_switch->set_active(active); + q_toolbar->q_switch->property_active().signal_changed().connect( sigc::mem_fun(*this, &QueueTab :: on_switch_changed)); queue_set_sensitive(active); } @@ -281,7 +267,7 @@ void QueueTab :: on_close_clicked() void QueueTab :: on_switch_changed() { - if (q_switch.get_active()) { + if (q_toolbar->q_switch->get_active()) { tab_pq->set_flag(Q_ENABLED); queue_set_sensitive(true); } else { diff --git a/gui/queue/toolbar.cpp b/gui/queue/toolbar.cpp new file mode 100644 index 00000000..063bf0a3 --- /dev/null +++ b/gui/queue/toolbar.cpp @@ -0,0 +1,18 @@ +/* + * Copyright 2015 (c) Anna Schumaker. + */ +#include + +QueueToolbar :: QueueToolbar(BaseObjectType *cobject, + const Glib::RefPtr builder) + : Gtk::HBox(cobject), _builder(builder) +{ + _builder->get_widget("q_search", q_search); + _builder->get_widget("q_switch", q_switch); + _builder->get_widget("q_repeat", q_repeat); + _builder->get_widget("q_random", q_random); +} + +QueueToolbar :: ~QueueToolbar() +{ +} diff --git a/include/gui/queue/toolbar.h b/include/gui/queue/toolbar.h new file mode 100644 index 00000000..ddf5b30e --- /dev/null +++ b/include/gui/queue/toolbar.h @@ -0,0 +1,23 @@ +/* + * Copyright 2015 (c) Anna Schumaker. + */ +#ifndef OCARINA_GUI_QUEUE_TOOLBAR_H +#define OCARINA_GUI_QUEUE_TOOLBAR_H + +#include + +class QueueToolbar : public Gtk::HBox { +private: + Glib::RefPtr _builder; + +public: + Gtk::SearchEntry *q_search; + Gtk::Switch *q_switch; + Gtk::ToggleButton *q_repeat; + Gtk::ToggleButton *q_random; + + QueueToolbar(BaseObjectType *, const Glib::RefPtr); + ~QueueToolbar(); +}; + +#endif /* OCARINA_GUI_QUEUE_TOOLBAR_H */ diff --git a/share/ocarina/QueueToolbar.ui b/share/ocarina/QueueToolbar.ui new file mode 100644 index 00000000..79fd7c6f --- /dev/null +++ b/share/ocarina/QueueToolbar.ui @@ -0,0 +1,79 @@ + + + + + + True + False + 5 + 5 + 5 + + + True + True + edit-find-symbolic + False + False + + + True + True + 0 + + + + + True + True + True + True + + + False + True + 1 + + + + + True + True + True + False + + + True + False + media-playlist-repeat + + + + + False + True + 2 + + + + + True + True + True + False + + + True + False + media-playlist-shuffle + + + + + False + True + 3 + + + +