From c3b7144f5aef2906d85339d3b9c5bf8eaa3a6356 Mon Sep 17 00:00:00 2001 From: Arno Date: Sat, 11 Dec 2010 13:06:20 +0100 Subject: Implement hover over movies What started as an attempt to show a frame from a movie when hovering over it, ended in a huge bugfix commit for hover related stuff. This commit is definitely not atomic. When hovering over a movie present on the filesytem a frame is shown. The time frame is configurable. While digging into the code I noticed some bugs. Bugfixes: * fix label for hove archive action. It was labeled for hovering over directories in FSWidget. * Hovering over directories didn't have an action. Also read the appropriate value from QSettings. Other: * add icons for hovering over directories and hovering over movies * replace SheMov::toggleHover(pics|some other) with a QSignalMapper --- filestreewidget.cpp | 58 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 20 deletions(-) (limited to 'filestreewidget.cpp') diff --git a/filestreewidget.cpp b/filestreewidget.cpp index 941c7ac..4dd5308 100644 --- a/filestreewidget.cpp +++ b/filestreewidget.cpp @@ -288,9 +288,8 @@ void FilesTreeWidget::fileSelectionChanged(const QItemSelection &selected, const emit sizeChanged(mSelectedSize); } -FilesTreeView::FilesTreeView(QWidget *parent) : QTreeView(parent), mHoverWin(new HoverWindow), mHover(false){ +FilesTreeView::FilesTreeView(QWidget *parent) : QTreeView(parent), mHoverWin(new HoverWindow), mHoverPics(false){ setAttribute(Qt::WA_Hover); - } void FilesTreeView::setModel(QAbstractItemModel *model){ @@ -303,8 +302,9 @@ void FilesTreeView::setModel(QAbstractItemModel *model){ void FilesTreeView::readConfig(){ QSettings s; - mHover = s.value("ui/hoverpics", true).toBool(); + mHoverPics = s.value("ui/hoverpics", true).toBool(); mHoverWin->setWindowOpacity(s.value("ui/hoveropacity", 10).toFloat() / 10.0); + mHoverMovies = s.value("ui/hovermovies", true).toBool(); } void FilesTreeView::readHeaderConfig(){ @@ -341,39 +341,39 @@ bool FilesTreeView::event(QEvent *e){ if(!hEvent){ return QTreeView::event(e); } - if(!mHover){ - return true; - } QPoint hotSpot(hEvent->pos().x(), hEvent->pos().y() - SmGlobals::instance()->cursorSize().height()); QModelIndex curIdx = indexAt(hotSpot); + /* + The whole point of this if/then/else mess is to exit as early as possible + for performance reasons. We don't want the cpu to spin at 100% only + because something _could_ happen... + */ if((e->type() == QEvent::HoverEnter) || (e->type() == QEvent::HoverMove)){ if(!curIdx.isValid() || (!curIdx.column() == 0)){ return exitHover(); } bool toInt; int fileType = curIdx.data(FilesTreeModel::FileTypeRole).toInt(&toInt); - bool validFt = false; - if(toInt){ - validFt = (fileType == FilesTreeModel::FrontCover) || (fileType == FilesTreeModel::BackCover) || (fileType == FilesTreeModel::GeneralCover); - } - if(!toInt || !validFt){ + if(!toInt){ return exitHover(); } + if(fileType == FilesTreeModel::Movie){ + if(!mHoverMovies){ + return exitHover(); + } + }else{ + if(!mHoverPics){ + return exitHover(); + } + } } if(e->type() == QEvent::HoverEnter){ - mCurHover = curIdx; - QPixmap pm = QPixmap(curIdx.data(FilesTreeModel::FullPathRole).toString()); - mHoverWin->setPixmap(pm); - mHoverWin->setPos(); - mHoverWin->setVisible(true); + doHover(curIdx); return true; } if(e->type() == QEvent::HoverMove){ if(curIdx != mCurHover){ - mCurHover = curIdx; - mHoverWin->setPixmap(QPixmap(curIdx.data(FilesTreeModel::FullPathRole).toString())); - mHoverWin->setPos(); - mHoverWin->setVisible(true); + doHover(curIdx); return true; }else{ mHoverWin->setPos(); @@ -392,6 +392,24 @@ bool FilesTreeView::exitHover(bool exitVal){ return exitVal; } +void FilesTreeView::doHover(const QModelIndex &idx){ + QPixmap pm; + mCurHover = idx; + if(idx.data(FilesTreeModel::FileTypeRole).toInt() == FilesTreeModel::Movie){ + pm = Helper::grabFrame(idx.data(FilesTreeModel::FullPathRole).toString()); + if(pm.isNull()){ + return; + } + }else{ + if(!pm.load(idx.data(FilesTreeModel::FullPathRole).toString())){ + return; + } + } + mHoverWin->setPixmap(pm); + mHoverWin->setPos(); + mHoverWin->setVisible(true); +} + FilesTreeSortModel::FilesTreeSortModel(QObject *parent) : QSortFilterProxyModel(parent) {} // left + right are from the sourceModel() !!!! -- cgit v1.2.3-70-g09d2