Merge branch “issue-28-album-art-scaling”

This commit is contained in:
coderkun 2017-12-26 09:58:00 +01:00
commit 89cf0dfcc0
2 changed files with 37 additions and 5 deletions

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.20.0 -->
<!-- Generated with glade 3.20.2 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkPopover" id="cover-toolbar-popover">
@ -214,17 +214,20 @@
<property name="orientation">vertical</property>
<child>
<object class="GtkScale" id="library-toolbar-scale">
<property name="width_request">350</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="adjustment">library-scale-adjustment</property>
<property name="restrict_to_fill_level">False</property>
<property name="fill_level">-1</property>
<property name="round_digits">0</property>
<property name="draw_value">False</property>
<property name="digits">0</property>
<property name="has_origin">False</property>
<signal name="button-release-event" handler="on_library-toolbar-scale_button_release_event" swapped="no"/>
<signal name="change-value" handler="on_library-toolbar-scale_change_value" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
@ -927,6 +930,7 @@
<property name="activate_on_single_click">True</property>
<signal name="item-activated" handler="on_library-iconview_item_activated" swapped="no"/>
<signal name="selection-changed" handler="on_library-iconview_selection_changed" swapped="no"/>
<signal name="size-allocate" handler="on_library-iconview_size_allocate" swapped="no"/>
<style>
<class name="no-bg"/>
</style>

View file

@ -1413,6 +1413,7 @@ class LibraryPanel(GObject.GObject):
self._icon_theme = Gtk.IconTheme.get_default()
self._standalone_pixbuf = None
self._selected_albums = []
self._allocation = (0, 0)
# Widgets
self._appwindow = builder.get_object('appwindow')
@ -1434,6 +1435,7 @@ class LibraryPanel(GObject.GObject):
self._progress_bar = builder.get_object('library-progress')
# Toolbar menu
self._toolbar_search_bar = builder.get_object('library-toolbar-search')
self._toolbar_popover = builder.get_object('library-toolbar-popover')
self._toolbar_sort_buttons = {
SortOrder.ARTIST: builder.get_object('library-toolbar-sort-artist'),
SortOrder.TITLE: builder.get_object('library-toolbar-sort-title'),
@ -1442,6 +1444,7 @@ class LibraryPanel(GObject.GObject):
self._toolbar_sort_order_button = builder.get_object('library-toolbar-sort-order')
self._grid_scale = builder.get_object('library-toolbar-scale')
self._grid_scale.set_value(self._item_size)
self._grid_adjustment = builder.get_object('library-scale-adjustment')
# Library Grid: Model
self._library_grid_model = Gtk.ListStore(GdkPixbuf.Pixbuf, str, str)
self._library_grid_model.set_sort_func(2, self.compare_albums, self._sort_order)
@ -1500,10 +1503,33 @@ class LibraryPanel(GObject.GObject):
'on_library-iconview_item_activated': self.on_library_grid_clicked,
'on_library-iconview_selection_changed': self.on_library_grid_selection_changed,
'on_library-standalone-scroll_size_allocate': self.on_standalone_scroll_size_allocate,
'on_headerbar-library-standalone-close_clicked': self.on_standalone_close_clicked
'on_headerbar-library-standalone-close_clicked': self.on_standalone_close_clicked,
'on_library-iconview_size_allocate': self.on_resize
}
def on_resize(self, widget, event):
new_allocation = (widget.get_allocation().width, widget.get_allocation().height)
if new_allocation == self._allocation:
return
self._allocation = new_allocation
self._grid_scale.clear_marks()
width = widget.get_allocation().width - 12
lower = int(self._grid_adjustment.get_lower())
upper = int(self._grid_adjustment.get_upper())
countMin = max(int(width / upper), 1)
countMax = max(int(width / lower), 1)
for index in range(countMin, countMax):
pixel = int(width / index)
pixel = pixel - int(pixel / 100)
self._grid_scale.add_mark(
pixel,
Gtk.PositionType.BOTTOM,
None
)
def on_search_toggled(self, widget):
self._filter_bar.set_search_mode(widget.get_active())
@ -1533,9 +1559,11 @@ class LibraryPanel(GObject.GObject):
size = round(self._grid_scale.get_value())
range = self._grid_scale.get_adjustment()
if size < range.get_lower() or size > range.get_upper():
return
return False
self.emit('item-size-changed', size)
self._toolbar_popover.popdown()
self._redraw()
return False
def on_update_clicked(self, widget):