summaryrefslogtreecommitdiffstats
path: root/fileview.cpp
diff options
context:
space:
mode:
authorArno <am@disconnect.de>2010-10-23 09:20:18 +0200
committerArno <am@disconnect.de>2010-10-23 09:20:18 +0200
commit9092371858356efde3e2d6d002f692308127389c (patch)
tree10e6c25457a7710a1c8cdd1791779cba2d661511 /fileview.cpp
parent19674f64699ba883f24a97a04505ca2c7f12634e (diff)
downloadSheMov-9092371858356efde3e2d6d002f692308127389c.tar.gz
SheMov-9092371858356efde3e2d6d002f692308127389c.tar.bz2
SheMov-9092371858356efde3e2d6d002f692308127389c.zip
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.
Diffstat (limited to 'fileview.cpp')
-rw-r--r--fileview.cpp128
1 files changed, 65 insertions, 63 deletions
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<QHoverEvent*>(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<QVariant> 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<QVariant> 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);