Skip to content

Commit

Permalink
qtui: Enable song info popup on mouseover.
Browse files Browse the repository at this point in the history
  • Loading branch information
jlindgren90 committed Jun 23, 2018
1 parent 187f512 commit 592e3d6
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
45 changes: 43 additions & 2 deletions src/qtui/playlist-qt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@

#include <libaudcore/audstrings.h>
#include <libaudcore/drct.h>
#include <libaudcore/hook.h>
#include <libaudcore/playlist.h>
#include <libaudcore/runtime.h>
#include <libaudqt/libaudqt.h>

#include "playlist-qt.h"
#include "playlist_header.h"
Expand Down Expand Up @@ -57,6 +56,7 @@ PlaylistWidget::PlaylistWidget (QWidget * parent, Playlist playlist) :
setFrameShape (QFrame::NoFrame);
setSelectionMode (ExtendedSelection);
setDragDropMode (DragDrop);
setMouseTracking (true);

updateSettings ();
header->updateColumns ();
Expand Down Expand Up @@ -149,6 +149,25 @@ void PlaylistWidget::mouseDoubleClickEvent (QMouseEvent * event)
playCurrentIndex ();
}

void PlaylistWidget::mouseMoveEvent (QMouseEvent * event)
{
int row = indexToRow (indexAt (event->pos ()));

if (row < 0)
{
hidePopup ();
return;
}

if (aud_get_bool (nullptr, "show_filepopup_for_tuple") && m_popup_pos != row)
triggerPopup (row);
}

void PlaylistWidget::leaveEvent (QEvent *)
{
hidePopup ();
}

/* Since Qt doesn't support both DragDrop and InternalMove at once,
* this hack is needed to set the drag icon to "move" for internal drags. */
void PlaylistWidget::dragMoveEvent (QDragMoveEvent * event)
Expand Down Expand Up @@ -398,6 +417,28 @@ void PlaylistWidget::moveFocus (int distance)
setCurrentIndex (proxyModel->index (row, 0));
}

void PlaylistWidget::showPopup ()
{
audqt::infopopup_show (m_playlist, m_popup_pos);
}

void PlaylistWidget::triggerPopup (int pos)
{
audqt::infopopup_hide ();

m_popup_pos = pos;
m_popup_timer.queue (aud_get_int (nullptr, "filepopup_delay") * 100,
aud::obj_member<PlaylistWidget, & PlaylistWidget::showPopup>, this);
}

void PlaylistWidget::hidePopup ()
{
audqt::infopopup_hide ();

m_popup_pos = -1;
m_popup_timer.stop ();
}

void PlaylistWidget::updateSettings ()
{
setHeaderHidden (! aud_get_bool ("qtui", "playlist_headers"));
Expand Down
10 changes: 10 additions & 0 deletions src/qtui/playlist-qt.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <QTreeView>

#include <libaudcore/hook.h>
#include <libaudcore/mainloop.h>
#include <libaudcore/playlist.h>

class PlaylistModel;
Expand Down Expand Up @@ -60,6 +61,9 @@ class PlaylistWidget : public QTreeView
bool inUpdate = false;
int firstVisibleColumn = 0;

int m_popup_pos = -1;
QueuedFunc m_popup_timer;

QModelIndex rowToIndex (int row);
int indexToRow (const QModelIndex & index);

Expand All @@ -70,11 +74,17 @@ class PlaylistWidget : public QTreeView
void contextMenuEvent (QContextMenuEvent * event);
void keyPressEvent (QKeyEvent * event);
void mouseDoubleClickEvent (QMouseEvent * event);
void mouseMoveEvent (QMouseEvent * event);
void leaveEvent (QEvent *);
void dragMoveEvent (QDragMoveEvent * event);
void dropEvent (QDropEvent * event);
void currentChanged (const QModelIndex & current, const QModelIndex & previous);
void selectionChanged (const QItemSelection & selected, const QItemSelection & deselected);

void showPopup ();
void triggerPopup (int pos);
void hidePopup ();

void updateSettings ();

const HookReceiver<PlaylistWidget>
Expand Down

0 comments on commit 592e3d6

Please sign in to comment.