]> git.sur5r.net Git - minitube/blobdiff - src/playlistview.cpp
New upstream version 3.1
[minitube] / src / playlistview.cpp
index 41b54d3258998fb15c3a69c3c5227b3b4b47c434..3655f4dd36ebbade5c3008d12160100e5bac4e20 100644 (file)
@@ -19,17 +19,15 @@ 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);
-    setMinimumWidth(175);
 
     // dragndrop
     setDragEnabled(true);
@@ -44,24 +42,36 @@ 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) {
-    PlaylistModel *listModel = dynamic_cast<PlaylistModel *>(model());
+    PlaylistModel *listModel = qobject_cast<PlaylistModel *>(model());
     if (listModel) listModel->setHoveredRow(index.row());
 }
 
-void PlaylistView::leaveEvent(QEvent * /* event */) {
-    PlaylistModel *listModel = dynamic_cast<PlaylistModel *>(model());
+void PlaylistView::leaveEvent(QEvent *event) {
+    QListView::leaveEvent(event);
+    PlaylistModel *listModel = qobject_cast<PlaylistModel *>(model());
     if (listModel) listModel->clearHover();
 }
 
 void PlaylistView::mouseMoveEvent(QMouseEvent *event) {
-    QListView::mouseMoveEvent(event);
-
     if (isHoveringThumbnail(event)) {
         setCursor(Qt::PointingHandCursor);
     } else if (isShowMoreItem(indexAt(event->pos()))) {
@@ -73,37 +83,36 @@ void PlaylistView::mouseMoveEvent(QMouseEvent *event) {
         QMetaObject::invokeMethod(model(), "exitAuthorHover");
         unsetCursor();
     }
+    QListView::mouseMoveEvent(event);
 }
 
 void PlaylistView::mousePressEvent(QMouseEvent *event) {
     if (event->button() == Qt::LeftButton) {
-        if (isHoveringThumbnail(event)) {
-            event->accept();
-        } else if (isHoveringAuthor(event)) {
+        if (isHoveringAuthor(event)) {
             QMetaObject::invokeMethod(model(), "enterAuthorPressed");
-            event->ignore();
-        } else QListView::mousePressEvent(event);
-    } else QListView::mousePressEvent(event);
+        } else if (isHoveringThumbnail(event)) {
+            const QModelIndex index = indexAt(event->pos());
+            emit activated(index);
+            unsetCursor();
+            return;
+        }
+        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 = dynamic_cast<PlaylistModel *>(model());
+            PlaylistModel *listModel = qobject_cast<PlaylistModel *>(model());
             listModel->searchMore();
             unsetCursor();
         }
-
-    } else {
-        QListView::mousePressEvent(event);
     }
+    QListView::mouseReleaseEvent(event);
 }
 
 bool PlaylistView::isHoveringAuthor(QMouseEvent *event) {
@@ -113,7 +122,7 @@ bool PlaylistView::isHoveringAuthor(QMouseEvent *event) {
     const QRect itemRect = visualRect(itemIndex);
     // qDebug() << " itemRect.x()" <<  itemRect.x();
 
-    PlaylistItemDelegate *delegate = dynamic_cast<PlaylistItemDelegate *>(itemDelegate());
+    PlaylistItemDelegate *delegate = qobject_cast<PlaylistItemDelegate *>(itemDelegate());
     if (!delegate) return false;
 
     QRect rect = delegate->authorRect(itemIndex);
@@ -128,18 +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;
-}
-
-void PlaylistView::paintEvent(QPaintEvent *event) {
-    QListView::paintEvent(event);
-    PainterUtils::topShadow(viewport());
+    return model()->rowCount() > 1 && model()->rowCount() == index.row() + 1;
 }