From 9092371858356efde3e2d6d002f692308127389c Mon Sep 17 00:00:00 2001 From: Arno Date: Sat, 23 Oct 2010 09:20:18 +0200 Subject: Fixed crash when remembering selected tab, improve performance Strange things happen. As stated in commit 19674f6, SheMov crashed when setting the archive as current tab and then changing to filesystem view. This can be resolved by first showing the MainWindow and then applying the display changes. I guess it's an qt internal thing. Also vastly improved performance when hovering by only entering the hover code path when we actually have a HoverEvent. Before CPU usage spiked at 100% even if SheMov was idle. --- fileview.cpp | 128 ++++++++++++++++++++++++++++++----------------------------- 1 file changed, 65 insertions(+), 63 deletions(-) (limited to 'fileview.cpp') diff --git a/fileview.cpp b/fileview.cpp index 2da9bc6..fdd51e4 100644 --- a/fileview.cpp +++ b/fileview.cpp @@ -54,6 +54,13 @@ void FileView::createFolder(){ mCreateFolderDialog->show(); } +void FileView::readConfig(){ + QSettings s; + mHover = s.value("ui/hoverpics", true).toBool(); + mHoverWin->setWindowOpacity(s.value("ui/hoveropacity", 10).toFloat() / 10.0); +} + + void FileView::doMark(){ int rowCount = model()->rowCount(rootIndex()); QString sRegex = mMarkDialog->text(); @@ -139,83 +146,78 @@ void FileView::resizeEvent(QResizeEvent *e){ } bool FileView::event(QEvent *e){ - QSettings s; - if(!s.value("ui/hoverpics").toBool()){ - return true; - } - - if(e->type() == QEvent::HoverLeave){ - mHoverWin->setVisible(false); - mCurHover = QModelIndex(); - return true; - } - QHoverEvent *hEvent = static_cast(e); - QPoint hotSpot(hEvent->pos().x(), hEvent->pos().y() - SmGlobals::instance()->cursorOffset()); - QModelIndex curIdx = indexAt(hotSpot); - - if(!curIdx.isValid()){ - return true; - } - if(curIdx.column() != 0){ - mHoverWin->setVisible(false); - return true; - } - - QFileInfo fi(curIdx.data(QFileSystemModel::FilePathRole).toString()); - if(!fi.exists()){ - return true; - } - - QList hoverData; - if(fi.isDir()){ - hoverData << fi.fileName(); - QDir curDir(fi.absoluteFilePath()); - QStringList files = curDir.entryList(QDir::AllEntries | QDir::NoDotAndDotDot, QDir::Name); - hoverData << files; - }else if(fi.isFile()){ - QString mimeType = Helper::mimeType(fi.absoluteFilePath()); - if(mimeType.startsWith("image")){ - QPixmap pm(fi.absoluteFilePath()); - hoverData << pm; - }else{ + if((hEvent->type() == QEvent::HoverEnter) || (hEvent->type() == QEvent::HoverLeave) || (hEvent->type() == QEvent::HoverMove)){ + if(!mHover){ + return true; + } + if(e->type() == QEvent::HoverLeave){ mHoverWin->setVisible(false); + mCurHover = QModelIndex(); return true; } - }else{ - mHoverWin->setVisible(false); - return true; - } - - QPoint globalPos = mapToGlobal(hotSpot); - QPoint where = globalPos + QPoint(30, 0); - if(e->type() == QEvent::HoverEnter){ - mCurHover = curIdx; - mHoverWin->setData(hoverData); - if(mHoverWin->pixmapHeight()){ - where = QPoint(where.x(), where.y() - mHoverWin->pixmapHeight() / 2); + QPoint hotSpot(hEvent->pos().x(), hEvent->pos().y() - SmGlobals::instance()->cursorOffset()); + QModelIndex curIdx = indexAt(hotSpot); + if(!curIdx.isValid()){ + return true; } - mHoverWin->setPos(where); - mHoverWin->setVisible(true); - return true; - } - if(e->type() == QEvent::HoverMove){ - if(curIdx != mCurHover){ + if(curIdx.column() != 0){ + mHoverWin->setVisible(false); + return true; + } + QFileInfo fi(curIdx.data(QFileSystemModel::FilePathRole).toString()); + if(!fi.exists()){ + return true; + } + QList hoverData; + if(fi.isDir()){ + hoverData << fi.fileName(); + QDir curDir(fi.absoluteFilePath()); + QStringList files = curDir.entryList(QDir::AllEntries | QDir::NoDotAndDotDot, QDir::Name); + hoverData << files; + }else if(fi.isFile()){ + QString mimeType = Helper::mimeType(fi.absoluteFilePath()); + if(mimeType.startsWith("image")){ + QPixmap pm(fi.absoluteFilePath()); + hoverData << pm; + }else{ + mHoverWin->setVisible(false); + return true; + } + }else{ + mHoverWin->setVisible(false); + return true; + } + QPoint globalPos = mapToGlobal(hotSpot); + QPoint where = globalPos + QPoint(30, 0); + if(e->type() == QEvent::HoverEnter){ mCurHover = curIdx; mHoverWin->setData(hoverData); if(mHoverWin->pixmapHeight()){ where = QPoint(where.x(), where.y() - mHoverWin->pixmapHeight() / 2); } - mHoverWin->setVisible(false); mHoverWin->setPos(where); mHoverWin->setVisible(true); return true; - }else{ - if(mHoverWin->pixmapHeight()){ - where = QPoint(where.x(), where.y() - mHoverWin->pixmapHeight() / 2); + } + if(e->type() == QEvent::HoverMove){ + if(curIdx != mCurHover){ + mCurHover = curIdx; + mHoverWin->setData(hoverData); + if(mHoverWin->pixmapHeight()){ + where = QPoint(where.x(), where.y() - mHoverWin->pixmapHeight() / 2); + } + mHoverWin->setVisible(false); + mHoverWin->setPos(where); + mHoverWin->setVisible(true); + return true; + }else{ + if(mHoverWin->pixmapHeight()){ + where = QPoint(where.x(), where.y() - mHoverWin->pixmapHeight() / 2); + } + mHoverWin->setPos(where); + return true; } - mHoverWin->setPos(where); - return true; } } return QTreeView::event(e); -- cgit v1.2.3-70-g09d2