summaryrefslogtreecommitdiffstats
path: root/filestreewidget.cpp
diff options
context:
space:
mode:
authorArno <am@disconnect.de>2010-10-23 15:09:49 +0200
committerArno <am@disconnect.de>2010-10-23 15:09:49 +0200
commit7e0abc7cde4a9c02fabc27cc2b6506bd41f0588d (patch)
treedff223d42a9515f961ded35eaae9ceba77824580 /filestreewidget.cpp
parent9092371858356efde3e2d6d002f692308127389c (diff)
downloadSheMov-7e0abc7cde4a9c02fabc27cc2b6506bd41f0588d.tar.gz
SheMov-7e0abc7cde4a9c02fabc27cc2b6506bd41f0588d.tar.bz2
SheMov-7e0abc7cde4a9c02fabc27cc2b6506bd41f0588d.zip
Fix hover issues
Hopefully this commit fixes all issues with hovering over items. First, only use QCursor::pos() to determine the position of the hover window and fix position calculation accordingly. For that SmGlobals now return a QSize of the actual cursor size. Introduced a hoverOffeset to HoverWindow defaulting to SmGlobals::cursorSize() + 30 to prevent a HoverLeave event on showing the HoverWindow. Also fixed Qt::WindowFlags of HoverWindow. We don't want the HoverWindow to show in the taskbar or get sent to background when clicking on an item.
Diffstat (limited to 'filestreewidget.cpp')
-rw-r--r--filestreewidget.cpp99
1 files changed, 42 insertions, 57 deletions
diff --git a/filestreewidget.cpp b/filestreewidget.cpp
index e5ab111..7fbc0fc 100644
--- a/filestreewidget.cpp
+++ b/filestreewidget.cpp
@@ -290,75 +290,60 @@ void FilesTreeView::contextMenuEvent(QContextMenuEvent *event){
bool FilesTreeView::event(QEvent *e){
QHoverEvent *hEvent = static_cast<QHoverEvent*>(e);
- if((hEvent->type() == QEvent::HoverEnter) || (hEvent->type() == QEvent::HoverLeave) || (hEvent->type() == QEvent::HoverMove)){
- if(!mHover){
- return true;
+ 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);
+ if((e->type() == QEvent::HoverEnter) || (e->type() == QEvent::HoverMove)){
+ if(!curIdx.isValid() || (!curIdx.column() == 0)){
+ return exitHover();
}
- QModelIndex curIdx;
-
- if(!hEvent){
- return true;
+ 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);
}
- QPoint hotSpot(hEvent->pos().x(), hEvent->pos().y() - SmGlobals::instance()->cursorOffset());
- QPoint globalPos = mapToGlobal(hotSpot);
- QPoint where = globalPos + QPoint(30, 0);
-
- curIdx = indexAt(hotSpot);
- if((e->type() == QEvent::HoverEnter) || (e->type() == QEvent::HoverMove)){
- if(!curIdx.isValid()){
- return true;
- }
- if(!curIdx.column() == 0){
- mCurHover = QModelIndex();
- mHoverWin->setVisible(false);
- return true;
- }
- if(!curIdx.isValid()){
- return true;
- }
- QVariant fileType = curIdx.data(FilesTreeModel::FileTypeRole);
- if(!fileType.isValid()){
- mHoverWin->setVisible(false);
- return true;
- }
- if(fileType.toInt() == FilesTreeModel::Movie){
- mHoverWin->setVisible(false);
- return true;
- }
+ if(!toInt || !validFt){
+ return exitHover();
}
-
- if(e->type() == QEvent::HoverEnter){
+ }
+ if(e->type() == QEvent::HoverEnter){
+ mCurHover = curIdx;
+ QPixmap pm = QPixmap(curIdx.data(FilesTreeModel::FullPathRole).toString());
+ mHoverWin->setPixmap(pm);
+ mHoverWin->setPos();
+ mHoverWin->setVisible(true);
+ return true;
+ }
+ if(e->type() == QEvent::HoverMove){
+ if(curIdx != mCurHover){
mCurHover = curIdx;
- QPixmap pm = QPixmap(curIdx.data(FilesTreeModel::FullPathRole).toString());
- mHoverWin->setPixmap(pm);
- mHoverWin->setPos(where);
+ mHoverWin->setPixmap(QPixmap(curIdx.data(FilesTreeModel::FullPathRole).toString()));
+ mHoverWin->setPos();
mHoverWin->setVisible(true);
return true;
- }
- if(e->type() == QEvent::HoverMove){
- if(mHoverWin->pixmapHeight()){
- where = QPoint(where.x(), where.y() - mHoverWin->pixmapHeight() / 2);
- }
- if(curIdx != mCurHover){
- mCurHover = curIdx;
- mHoverWin->setPixmap(QPixmap(curIdx.data(FilesTreeModel::FullPathRole).toString()));
- mHoverWin->setVisible(false);
- mHoverWin->setPos(where);
- mHoverWin->setVisible(true);
- return true;
- }else{
- mHoverWin->setPos(where);
- return true;
- }
- }
- if(e->type() == QEvent::HoverLeave){
- mHoverWin->setVisible(false);
+ }else{
+ mHoverWin->setPos();
return true;
}
}
+ if(e->type() == QEvent::HoverLeave){
+ return exitHover();
+ }
return QTreeView::event(e);
}
+bool FilesTreeView::exitHover(bool exitVal){
+ mHoverWin->setVisible(false);
+ mCurHover = QModelIndex();
+ return exitVal;
+}
+
FilesTreeSortModel::FilesTreeSortModel(QObject *parent) : QSortFilterProxyModel(parent) {}
bool FilesTreeSortModel::lessThan(const QModelIndex &left, const QModelIndex &right) const{