[gnome-music/wip/jfelder/gtk4-v3] songsview: Add favorites back



commit 0a9987f942624d3a59b082a0d945f5111f75745a
Author: Marinus Schraal <mschraal gnome org>
Date:   Fri Feb 11 21:34:28 2022 +0100

    songsview: Add favorites back

 data/ui/SongListItem.ui       | 15 +++++++++++++++
 gnomemusic/views/songsview.py | 31 ++++++++++++++++++++++++++++++-
 2 files changed, 45 insertions(+), 1 deletion(-)
---
diff --git a/data/ui/SongListItem.ui b/data/ui/SongListItem.ui
index 58cee7430..42b32b03e 100644
--- a/data/ui/SongListItem.ui
+++ b/data/ui/SongListItem.ui
@@ -33,5 +33,20 @@
           </child>
       </object>
     </child>
+    <child>
+      <object class="GtkBox" id="_star_box">
+        <property name="focusable">0</property>
+        <property name="halign">end</property>
+        <property name="valign">center</property>
+        <child>
+          <object class="StarImage" id="_star_image">
+            <property name="focusable">False</property>
+            <property name="valign">center</property>
+            <property name="margin-end">12</property>
+            <property name="margin-start">12</property>
+          </object>
+        </child>
+      </object>
+    </child>
   </object>
 </interface>
diff --git a/gnomemusic/views/songsview.py b/gnomemusic/views/songsview.py
index 531abef3a..acee0d06e 100644
--- a/gnomemusic/views/songsview.py
+++ b/gnomemusic/views/songsview.py
@@ -23,7 +23,7 @@
 # delete this exception statement from your version.
 
 from gettext import gettext as _
-from gi.repository import Adw, GObject, Gtk
+from gi.repository import Adw, GObject, Gdk, Gtk
 
 from gnomemusic.coresong import CoreSong
 from gnomemusic.utils import SongStateIcon
@@ -111,10 +111,36 @@ class SongsView(Gtk.Box):
 
         check = list_row.get_first_child()
         info_box = check.get_next_sibling()
+        star_image = info_box.get_next_sibling().get_first_child()
         title_label = info_box.get_first_child()
         album_label = title_label.get_next_sibling()
         artist_label = album_label.get_next_sibling()
 
+        def _on_star_toggle(
+                controller: Gtk.GestureClick, n_press: int, x: float,
+                y: float) -> None:
+            controller.set_state(Gtk.EventSequenceState.CLAIMED)
+            coresong.props.favorite = not coresong.props.favorite
+            star_image.props.favorite = coresong.props.favorite
+
+        star_click = Gtk.GestureClick()
+        star_click.props.button = 1
+        star_click.connect("released", _on_star_toggle)
+        star_image.add_controller(star_click)
+
+        def _on_star_enter(
+                controller: Gtk.EventControllerMotion, x: float,
+                y: float) -> None:
+            star_image.props.hover = True
+
+        def _on_star_leave(controller: Gtk.EventControllerMotion) -> None:
+            star_image.props.hover = False
+
+        star_hover = Gtk.EventControllerMotion()
+        star_hover.connect("enter", _on_star_enter)
+        star_hover.connect("leave", _on_star_leave)
+        star_image.add_controller(star_hover)
+
         coresong.bind_property(
             "title", title_label, "label",
             GObject.BindingFlags.SYNC_CREATE)
@@ -125,6 +151,9 @@ class SongsView(Gtk.Box):
             "artist", artist_label, "label",
             GObject.BindingFlags.SYNC_CREATE)
 
+        coresong.bind_property(
+            "favorite", star_image, "favorite")
+
         list_item.bind_property(
             "selected", coresong, "selected",
             GObject.BindingFlags.SYNC_CREATE)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]