Skip to content

Commit f9e2659

Browse files
committed
Add scrolling to checked checkboxes in file selector when clicking on a project
1 parent 2768ddf commit f9e2659

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

MainWindow.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
172172
connect(ui->projectsList->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), SLOT(projectClicked(QItemSelection,QItemSelection)));
173173
connect(ui->projectsList->model(), SIGNAL(dataChanged(QModelIndex,QModelIndex,QList<int>)), SLOT(projectNameChanged(QModelIndex)));
174174
connect(ui->projectsList, SIGNAL(deletePressed()), SLOT(removeProject()));
175+
connect(fileSelectorModel, SIGNAL(directoryLoaded(QString)), SLOT(scrollToCenter()));
176+
connect(ui->fileSelector, &QTreeView::expanded, [=](){ scrollable = false; });
175177
}
176178

177179
/*
@@ -293,6 +295,9 @@ void MainWindow::projectClicked(const QItemSelection &selected, const QItemSelec
293295
curIndex = curIndex.parent();
294296
}
295297
}
298+
299+
scrollable = true;
300+
scrollToCenter();
296301
}
297302

298303
/*
@@ -692,6 +697,19 @@ void MainWindow::sort(int column)
692697
}
693698
}
694699

700+
/*
701+
===================
702+
MainWindow::scrollToCenter
703+
===================
704+
*/
705+
void MainWindow::scrollToCenter()
706+
{
707+
if (!scrollable || ui->projectsList->currentIndex().row() < 0 || projectPathList[ui->projectsList->currentIndex().row()].isEmpty())
708+
return;
709+
710+
ui->fileSelector->scrollTo(proxyModel->mapFromSource(fileSelectorModel->index(projectPathList[ui->projectsList->currentIndex().row()][0])), QAbstractItemView::PositionAtCenter);
711+
}
712+
695713
/*
696714
===================
697715
MainWindow::resizeEvent

MainWindow.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ public Q_SLOTS:
133133
void projectNameChanged(const QModelIndex &index);
134134
void count();
135135
void sort(int column);
136+
void scrollToCenter();
136137

137138
protected:
138139

@@ -149,6 +150,7 @@ public Q_SLOTS:
149150

150151
bool counting = false;
151152
bool canUpdateDiff = false;
153+
bool scrollable = false;
152154
Ui::MainWindow *ui;
153155
QStringListModel *projectsListModel;
154156
FileSelectorModel *fileSelectorModel;

0 commit comments

Comments
 (0)