3 This file is part of Minitube.
4 Copyright 2009, Flavio Tordini <flavio.tordini@gmail.com>
6 Minitube is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 Minitube is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Minitube. If not, see <http://www.gnu.org/licenses/>.
21 #include "downloadlistview.h"
22 #include "downloadmodel.h"
23 #include "playlistitemdelegate.h"
24 #include "painterutils.h"
26 DownloadListView::DownloadListView(QWidget *parent) : QListView(parent) {
30 void DownloadListView::leaveEvent(QEvent * /* event */) {
31 DownloadModel *downloadModel = qobject_cast<DownloadModel *>(model());
32 if (downloadModel) downloadModel->clearHover();
35 void DownloadListView::mouseMoveEvent(QMouseEvent *event) {
36 // qDebug() << "DownloadListView::mouseMoveEvent" << event->pos();
38 QListView::mouseMoveEvent(event);
40 if (isHoveringPlayIcon(event)) {
41 QMetaObject::invokeMethod(model(), "enterPlayIconHover");
43 QMetaObject::invokeMethod(model(), "exitPlayIconHover");
48 void DownloadListView::mousePressEvent(QMouseEvent *event) {
49 if (event->button() == Qt::LeftButton
50 && isHoveringPlayIcon(event)) {
51 QMetaObject::invokeMethod(model(), "enterPlayIconPressed");
53 QListView::mousePressEvent(event);
57 void DownloadListView::mouseReleaseEvent(QMouseEvent *event) {
58 if (event->button() == Qt::LeftButton) {
59 QMetaObject::invokeMethod(model(), "exitPlayIconPressed");
60 if (isHoveringPlayIcon(event))
61 emit downloadButtonPushed(indexAt(event->pos()));
63 QListView::mousePressEvent(event);
67 bool DownloadListView::isHoveringPlayIcon(QMouseEvent *event) {
68 const QModelIndex itemIndex = indexAt(event->pos());
69 const QRect itemRect = visualRect(itemIndex);
70 // qDebug() << " itemRect.x()" << itemRect.x();
72 PlaylistItemDelegate *delegate = qobject_cast<PlaylistItemDelegate *>(itemDelegate());
73 if (!delegate) return false;
75 QRect buttonRect = delegate->downloadButtonRect(itemRect);
77 const int x = event->x() - itemRect.x() - buttonRect.x();
78 const int y = event->y() - itemRect.y() - buttonRect.y();
79 return x > 0 && x < buttonRect.width() && y > 0 && y < buttonRect.height();
82 void DownloadListView::paintEvent(QPaintEvent *event) {
83 QListView::paintEvent(event);
84 // PainterUtils::topShadow(viewport());