]> git.sur5r.net Git - minitube/blobdiff - src/playlistview.cpp
Upload 3.9.3-2 to unstable
[minitube] / src / playlistview.cpp
index f5a1677f5454a21a641cfc45a7882f56be9a3358..3655f4dd36ebbade5c3008d12160100e5bac4e20 100644 (file)
@@ -19,23 +19,16 @@ along with Minitube.  If not, see <http://www.gnu.org/licenses/>.
 $END_LICENSE */
 
 #include "playlistview.h"
-#include "playlistmodel.h"
-#include "playlistitemdelegate.h"
 #include "painterutils.h"
+#include "playlistitemdelegate.h"
+#include "playlistmodel.h"
 
-PlaylistView::PlaylistView(QWidget *parent) : QListView(parent),
-    clickableAuthors(true) {
+PlaylistView::PlaylistView(QWidget *parent) : QListView(parent), clickableAuthors(true) {
     setItemDelegate(new PlaylistItemDelegate(this));
     setSelectionMode(QAbstractItemView::ExtendedSelection);
 
     setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Expanding);
 
-#if defined(APP_MAC)
-    setMinimumWidth(160);
-#else
-    setMinimumWidth(175);
-#endif
-
     // dragndrop
     setDragEnabled(true);
     setAcceptDrops(true);
@@ -49,9 +42,22 @@ PlaylistView::PlaylistView(QWidget *parent) : QListView(parent),
     setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
     setUniformItemSizes(true);
 
-    connect(this, SIGNAL(entered(const QModelIndex &)),
-            SLOT(itemEntered(const QModelIndex &)));
+    connect(this, SIGNAL(entered(const QModelIndex &)), SLOT(itemEntered(const QModelIndex &)));
     setMouseTracking(true);
+
+    QScrollBar *vScrollbar = verticalScrollBar();
+    connect(vScrollbar, &QAbstractSlider::valueChanged, this, [this, vScrollbar](int value) {
+        if (isVisible() && value == vScrollbar->maximum()) {
+            PlaylistModel *listModel = qobject_cast<PlaylistModel *>(model());
+            listModel->searchMore();
+        }
+    });
+    setMinimumHeight(PlaylistItemDelegate::thumbHeight * 4);
+
+    setMinimumWidth(PlaylistItemDelegate::thumbWidth);
+#ifndef APP_MAC
+    setMinimumWidth(minimumWidth() + vScrollbar->width());
+#endif
 }
 
 void PlaylistView::itemEntered(const QModelIndex &index) {
@@ -84,19 +90,21 @@ void PlaylistView::mousePressEvent(QMouseEvent *event) {
     if (event->button() == Qt::LeftButton) {
         if (isHoveringAuthor(event)) {
             QMetaObject::invokeMethod(model(), "enterAuthorPressed");
+        } else if (isHoveringThumbnail(event)) {
+            const QModelIndex index = indexAt(event->pos());
+            emit activated(index);
+            unsetCursor();
+            return;
         }
+        QListView::mousePressEvent(event);
     }
-    QListView::mousePressEvent(event);
 }
 
 void PlaylistView::mouseReleaseEvent(QMouseEvent *event) {
     if (event->button() == Qt::LeftButton) {
         QMetaObject::invokeMethod(model(), "exitAuthorPressed");
-        const QModelIndex index =  indexAt(event->pos());
-        if (isHoveringThumbnail(event)) {
-            emit activated(index);
-            unsetCursor();
-        } else if (isHoveringAuthor(event)) {
+        const QModelIndex index = indexAt(event->pos());
+        if (isHoveringAuthor(event)) {
             emit authorPushed(index);
         } else if (isShowMoreItem(index)) {
             PlaylistModel *listModel = qobject_cast<PlaylistModel *>(model());
@@ -129,13 +137,13 @@ bool PlaylistView::isHoveringAuthor(QMouseEvent *event) {
 bool PlaylistView::isHoveringThumbnail(QMouseEvent *event) {
     const QModelIndex index = indexAt(event->pos());
     const QRect itemRect = visualRect(index);
-    static const QRect thumbRect(0, 0, 160, 90);
+    static const QRect thumbRect(0, 0, PlaylistItemDelegate::thumbWidth,
+                                 PlaylistItemDelegate::thumbHeight);
     const int x = event->x() - itemRect.x() - thumbRect.x();
     const int y = event->y() - itemRect.y() - thumbRect.y();
     return x > 0 && x < thumbRect.width() && y > 0 && y < thumbRect.height();
 }
 
 bool PlaylistView::isShowMoreItem(const QModelIndex &index) {
-    return model()->rowCount() > 1 &&
-            model()->rowCount() == index.row() + 1;
+    return model()->rowCount() > 1 && model()->rowCount() == index.row() + 1;
 }