Skip to content

Commit

Permalink
fix Files icon view sometimes not scrollable
Browse files Browse the repository at this point in the history
  • Loading branch information
ddennedy committed Jan 5, 2025
1 parent fed0fcc commit b210e57
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
35 changes: 23 additions & 12 deletions src/docks/filesdock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ FilesDock::FilesDock(QWidget *parent)
toggleViewAction()->setIcon(windowIcon());

const auto ls = QStandardPaths::standardLocations(QStandardPaths::HomeLocation);
ui->locationsCombo->addItem(QString());
ui->locationsCombo->addItem(tr("Home", "The user's home folder in the file system"), ls.first());
ui->locationsCombo->addItem(tr("Current Project"), "");
ui->locationsCombo->addItem(tr("Documents"),
Expand Down Expand Up @@ -582,8 +583,7 @@ FilesDock::FilesDock(QWidget *parent)
LOG_DEBUG() << "clicked" << filePath;
auto sourceIndex = m_filesModel->setRootPath(filePath);
Settings.setFilesCurrentDir(m_filesModel->rootPath());
m_view->setRootIndex(m_filesProxyModel->mapFromSource(sourceIndex));
m_view->scrollToTop();
changeFilesDirectory(m_filesProxyModel->mapFromSource(sourceIndex));
});

setupActions();
Expand Down Expand Up @@ -650,7 +650,7 @@ FilesDock::FilesDock(QWidget *parent)
connect(lineEdit, &QLineEdit::textChanged, this, [ = ](const QString & search) {
m_filesProxyModel->setFilterFixedString(search);
if (search.isEmpty()) {
m_view->setRootIndex(m_filesProxyModel->mapFromSource(m_filesModel->index(
changeFilesDirectory(m_filesProxyModel->mapFromSource(m_filesModel->index(
m_filesModel->rootPath())));
}
m_view->scrollToTop();
Expand Down Expand Up @@ -678,9 +678,8 @@ FilesDock::FilesDock(QWidget *parent)
if (m_filesModel->isDir(sourceIndex)) {
m_filesModel->setRootPath(filePath);
Settings.setFilesCurrentDir(filePath);
m_view->setRootIndex(index);
changeFilesDirectory(index);
m_view->setCurrentIndex(QModelIndex());
m_view->scrollToTop();
const auto dirsIndex = m_dirsModel->index(filePath);
ui->treeView->setExpanded(dirsIndex, true);
ui->treeView->scrollTo(dirsIndex);
Expand Down Expand Up @@ -944,8 +943,7 @@ void FilesDock::setupActions()
const auto filePath = dir.absolutePath();
const auto index = m_filesModel->setRootPath(filePath);
Settings.setFilesCurrentDir(filePath);
m_view->setRootIndex(m_filesProxyModel->mapFromSource(index));
m_view->scrollToTop();
changeFilesDirectory(m_filesProxyModel->mapFromSource(index));
const auto dirsIndex = m_dirsModel->index(filePath);
ui->treeView->setExpanded(dirsIndex, true);
ui->treeView->scrollTo(dirsIndex);
Expand Down Expand Up @@ -1068,7 +1066,7 @@ void FilesDock::onOpenActionTriggered()
}
}

void FilesDock::changeDirectory(const QString &filePath)
void FilesDock::changeDirectory(const QString &filePath, bool resetLocations)
{
LOG_DEBUG() << filePath;
QFileInfo info(filePath);
Expand All @@ -1080,6 +1078,9 @@ void FilesDock::changeDirectory(const QString &filePath)
index = m_filesModel->setRootPath(path);
Settings.setFilesCurrentDir(path);
m_view->setRootIndex(m_filesProxyModel->mapFromSource(index));
m_iconsView->updateSizes();
if (resetLocations)
ui->locationsCombo->setCurrentIndex(0);
if (info.isDir()) {
m_view->scrollToTop();
} else {
Expand All @@ -1091,6 +1092,14 @@ void FilesDock::changeDirectory(const QString &filePath)
}
}

void FilesDock::changeFilesDirectory(const QModelIndex &index)
{
m_view->setRootIndex(index);
m_iconsView->updateSizes();
ui->locationsCombo->setCurrentIndex(0);
m_view->scrollToTop();
}

void FilesDock::viewCustomContextMenuRequested(const QPoint &pos)
{
QModelIndex index = m_view->currentIndex();
Expand Down Expand Up @@ -1128,6 +1137,7 @@ void FilesDock::updateViewMode()
}
m_view->setRootIndex(m_filesProxyModel->mapFromSource(m_filesModel->index(
m_filesModel->rootPath())));
m_iconsView->updateSizes();
m_view->show();
}

Expand All @@ -1143,8 +1153,7 @@ void FilesDock::keyPressEvent(QKeyEvent *event)
if (m_filesModel->isDir(sourceIndex)) {
m_filesModel->setRootPath(filePath);
Settings.setFilesCurrentDir(filePath);
m_view->setRootIndex(index);
m_view->scrollToTop();
changeFilesDirectory(index);
const auto dirsIndex = m_dirsModel->index(filePath);
ui->treeView->setExpanded(dirsIndex, true);
ui->treeView->scrollTo(dirsIndex);
Expand Down Expand Up @@ -1254,8 +1263,10 @@ void FilesDock::onOpenOtherRemove()
}
}

void FilesDock::on_locationsCombo_activated(int)
void FilesDock::on_locationsCombo_activated(int index)
{
if (0 == index)
return;
auto path = ui->locationsCombo->currentData().toString();
if (path.isEmpty() && !MAIN.fileName().isEmpty())
path = QFileInfo(MAIN.fileName()).absolutePath();
Expand All @@ -1265,7 +1276,7 @@ void FilesDock::on_locationsCombo_activated(int)
if (QLatin1String("/") == path)
path = QStringLiteral("C:/");
#endif
changeDirectory(path);
changeDirectory(path, false);
}

void FilesDock::on_addLocationButton_clicked()
Expand Down
3 changes: 2 additions & 1 deletion src/docks/filesdock.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ class FilesDock : public QDockWidget

public slots:
void onOpenActionTriggered();
void changeDirectory(const QString &path);
void changeDirectory(const QString &path, bool resetLocations = true);
void changeFilesDirectory(const QModelIndex &index);

private slots:
void viewCustomContextMenuRequested(const QPoint &pos);
Expand Down
4 changes: 1 addition & 3 deletions src/widgets/playlisticonview.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class PlaylistIconView : public QAbstractItemView
PlaylistIconView(QWidget *parent);
void resetMultiSelect();
void setIconRole(int role);
void updateSizes();

QRect visualRect(const QModelIndex &index) const Q_DECL_OVERRIDE;
void scrollTo(const QModelIndex &index, ScrollHint hint = EnsureVisible) Q_DECL_OVERRIDE;
Expand Down Expand Up @@ -58,9 +59,6 @@ protected slots:
void selectionChanged(const QItemSelection &selected,
const QItemSelection &deselected) Q_DECL_OVERRIDE;

private slots:
void updateSizes();

private:
int rowWidth() const;
QAbstractItemView::DropIndicatorPosition position(const QPoint &pos, const QRect &rect,
Expand Down

0 comments on commit b210e57

Please sign in to comment.