From d44010d181847c6fa52b828afb0b673c0e9645ab Mon Sep 17 00:00:00 2001 From: Arno Date: Fri, 13 Feb 2015 18:16:11 +0100 Subject: Center on selected directory on startup Center on the selected dir in Filemanager on startup. Unfortunately it's not as straight as one would think. scrollTo doesn't work until the widget is painted, so we have to take a little detour... --- filesystemwidget.cpp | 7 ++++++- filesystemwidget.h | 1 + shemov.cpp | 3 +++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/filesystemwidget.cpp b/filesystemwidget.cpp index 60c2d78..5568db0 100644 --- a/filesystemwidget.cpp +++ b/filesystemwidget.cpp @@ -375,7 +375,7 @@ void FilesystemWidget::readSettings(){ QModelIndex diridx = mModel->index(selectedDir); if(diridx.isValid()){ QModelIndex pidx = mDirProxy->mapFromSource(diridx); - mDirView->selectionModel()->setCurrentIndex(pidx, QItemSelectionModel::ClearAndSelect); + mDirView->selectionModel()->setCurrentIndex(pidx, QItemSelectionModel::ClearAndSelect); } } bool expensiveOps = s.value("ui/expensiveops", true).toBool(); @@ -513,6 +513,11 @@ void FilesystemWidget::selectUnpackDir(){ } } +void FilesystemWidget::centerCurrent(){ + QModelIndex curIdx = mDirView->currentIndex(); + mDirView->scrollTo(curIdx, QAbstractItemView::PositionAtCenter); +} + void FilesystemWidget::deleteRecursive(const QFileInfo &start){ if(start.isDir()){ QDir curDir = QDir(start.absoluteFilePath());; diff --git a/filesystemwidget.h b/filesystemwidget.h index 0284fb6..efff13a 100644 --- a/filesystemwidget.h +++ b/filesystemwidget.h @@ -70,6 +70,7 @@ class FilesystemWidget : public QWidget { void preview(); void unpack(); void selectUnpackDir(); + void centerCurrent(); private slots: void dirExpanded(const QModelIndex &idx); diff --git a/shemov.cpp b/shemov.cpp index 4a6094b..6e3943c 100644 --- a/shemov.cpp +++ b/shemov.cpp @@ -144,6 +144,9 @@ SheMov::SheMov(QWidget *parent, Qt::WindowFlags flags) : QMainWindow(parent, fla mArchiveBrowser->readConfig(); readSettings(); Helper::centerWidget(picViewer); + // craptastic... We can't center until it's painted, + // hence this indirection :( + mFSWidget->centerCurrent(); } void SheMov::closeEvent(QCloseEvent *event){ -- cgit v1.2.3-70-g09d2