]> git.sur5r.net Git - minitube/blobdiff - src/playlistview.cpp
New upstream version 2.9
[minitube] / src / playlistview.cpp
index d8cbf99df565175607f04fbddd9fced3a3f59f43..f5a1677f5454a21a641cfc45a7882f56be9a3358 100644 (file)
@@ -1,13 +1,41 @@
+/* $BEGIN_LICENSE
+
+This file is part of Minitube.
+Copyright 2009, Flavio Tordini <flavio.tordini@gmail.com>
+
+Minitube is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+Minitube is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+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"
 
-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);
@@ -18,7 +46,7 @@ PlaylistView::PlaylistView(QWidget *parent) : QListView(parent) {
     setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
     setFrameShape(QFrame::NoFrame);
     setAttribute(Qt::WA_MacShowFocusRect, false);
-    // setMinimumSize(120, 240);
+    setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
     setUniformItemSizes(true);
 
     connect(this, SIGNAL(entered(const QModelIndex &)),
@@ -27,19 +55,17 @@ PlaylistView::PlaylistView(QWidget *parent) : QListView(parent) {
 }
 
 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);
-    // QWidget::mouseMoveEvent(event);
-
     if (isHoveringThumbnail(event)) {
         setCursor(Qt::PointingHandCursor);
     } else if (isShowMoreItem(indexAt(event->pos()))) {
@@ -51,17 +77,16 @@ 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);
+        }
+    }
+    QListView::mousePressEvent(event);
 }
 
 void PlaylistView::mouseReleaseEvent(QMouseEvent *event) {
@@ -74,14 +99,12 @@ void PlaylistView::mouseReleaseEvent(QMouseEvent *event) {
         } else 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) {
@@ -91,7 +114,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);