fancy fancy drag widget :o
This commit is contained in:
parent
b53801c470
commit
c6446f4352
2 changed files with 38 additions and 1 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
// song widget+drag behavior taken from gnome music
|
||||||
|
|
||||||
[GtkTemplate (ui = "/eu/callcc/audrey/ui/play_queue_song.ui")]
|
[GtkTemplate (ui = "/eu/callcc/audrey/ui/play_queue_song.ui")]
|
||||||
class Ui.PlayQueueSong : Gtk.ListBoxRow {
|
class Ui.PlayQueueSong : Gtk.ListBoxRow {
|
||||||
public bool draggable { get; set; default = false; }
|
public bool draggable { get; set; default = false; }
|
||||||
|
@ -57,12 +59,46 @@ class Ui.PlayQueueSong : Gtk.ListBoxRow {
|
||||||
return starred == null ? "non-starred" : "starred";
|
return starred == null ? "non-starred" : "starred";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private double drag_x;
|
||||||
|
private double drag_y;
|
||||||
|
|
||||||
[GtkCallback] private Gdk.ContentProvider? on_drag_prepare (double x, double y) {
|
[GtkCallback] private Gdk.ContentProvider? on_drag_prepare (double x, double y) {
|
||||||
if (this.draggable) return new Gdk.ContentProvider.for_value (this);
|
if (this.draggable) {
|
||||||
|
this.drag_x = x;
|
||||||
|
this.drag_y = y;
|
||||||
|
return new Gdk.ContentProvider.for_value (this);
|
||||||
|
}
|
||||||
else return null;
|
else return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Gtk.ListBox? drag_widget;
|
||||||
|
|
||||||
|
[GtkCallback] private void on_drag_begin (Gtk.DragSource source, Gdk.Drag drag) {
|
||||||
|
this.drag_widget = new Gtk.ListBox ();
|
||||||
|
this.drag_widget.set_size_request (this.get_width (), this.get_height ());
|
||||||
|
|
||||||
|
var drag_row = new PlayQueueSong (this.playbin);
|
||||||
|
drag_row.draggable = false;
|
||||||
|
drag_row.show_artist = this.show_artist;
|
||||||
|
drag_row.show_album = this.show_album;
|
||||||
|
drag_row.current = false;
|
||||||
|
drag_row.displayed_position = this.displayed_position;
|
||||||
|
drag_row.song = this.song;
|
||||||
|
drag_row.play_icon_name = this.play_icon_name;
|
||||||
|
|
||||||
|
this.drag_widget.append (drag_row);
|
||||||
|
this.drag_widget.drag_highlight_row (drag_row);
|
||||||
|
|
||||||
|
var drag_icon = Gtk.DragIcon.get_for_drag (drag);
|
||||||
|
drag_icon.set("child", this.drag_widget);
|
||||||
|
drag.set_hotspot ((int) this.drag_x, (int) this.drag_y);
|
||||||
|
}
|
||||||
|
|
||||||
[GtkCallback] private bool on_drop (Value value, double x, double y) {
|
[GtkCallback] private bool on_drop (Value value, double x, double y) {
|
||||||
|
this.drag_widget = null;
|
||||||
|
this.drag_x = 0.0;
|
||||||
|
this.drag_y = 0.0;
|
||||||
|
|
||||||
var source = value as PlayQueueSong;
|
var source = value as PlayQueueSong;
|
||||||
debug ("dropped %u on %u", source.displayed_position, this.displayed_position);
|
debug ("dropped %u on %u", source.displayed_position, this.displayed_position);
|
||||||
this.playbin.move_track (source.displayed_position-1, this.displayed_position-1);
|
this.playbin.move_track (source.displayed_position-1, this.displayed_position-1);
|
||||||
|
|
|
@ -124,6 +124,7 @@ template $UiPlayQueueSong: ListBoxRow {
|
||||||
propagation-phase: capture;
|
propagation-phase: capture;
|
||||||
|
|
||||||
prepare => $on_drag_prepare ();
|
prepare => $on_drag_prepare ();
|
||||||
|
drag-begin => $on_drag_begin ();
|
||||||
}
|
}
|
||||||
|
|
||||||
DropTarget {
|
DropTarget {
|
||||||
|
|
Loading…
Reference in a new issue