Skip to content

Commit ff04e13

Browse files
authored
Merge pull request #49 from berendkleinhaneveld/master
Select next/previous file from opened folder with shortcut
2 parents 36aee06 + 9f7c46f commit ff04e13

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

Diff for: src/main_window.cpp

+25
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ MainWindow::MainWindow(QWidget *parent, Qt::WindowFlags flags)
3434
swap_action = new QAction(tr("&Swap check box Watershed"), this);
3535
undo_action = new QAction(tr("&Undo"), this);
3636
redo_action = new QAction(tr("&Redo"), this);
37+
next_file_action = new QAction(tr("&Select next file"), this);
38+
previous_file_action = new QAction(tr("&Select previous file"), this);
3739
undo_action->setShortcuts(QKeySequence::Undo);
3840
redo_action->setShortcuts(QKeySequence::Redo);
3941
save_action->setShortcut(Qt::CTRL + Qt::Key_S);
@@ -42,6 +44,8 @@ MainWindow::MainWindow(QWidget *parent, Qt::WindowFlags flags)
4244
paste_mask_action->setShortcut(Qt::CTRL + Qt::Key_V);
4345
clear_mask_action->setShortcut(Qt::CTRL + Qt::Key_R);
4446
close_tab_action->setShortcut(Qt::CTRL + Qt::Key_W);
47+
next_file_action->setShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_Down);
48+
previous_file_action->setShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_Up);
4549
undo_action->setEnabled(false);
4650
redo_action->setEnabled(false);
4751

@@ -53,6 +57,8 @@ MainWindow::MainWindow(QWidget *parent, Qt::WindowFlags flags)
5357
menuEdit->addAction(paste_mask_action);
5458
menuEdit->addAction(clear_mask_action);
5559
menuEdit->addAction(swap_action);
60+
menuEdit->addAction(next_file_action);
61+
menuEdit->addAction(previous_file_action);
5662

5763
tabWidget->clear();
5864

@@ -64,6 +70,8 @@ MainWindow::MainWindow(QWidget *parent, Qt::WindowFlags flags)
6470
connect(copy_mask_action , SIGNAL(triggered()) , this, SLOT(copyMask()));
6571
connect(paste_mask_action , SIGNAL(triggered()) , this, SLOT(pasteMask()));
6672
connect(clear_mask_action , SIGNAL(triggered()) , this, SLOT(clearMask()));
73+
connect(next_file_action , SIGNAL(triggered()) , this, SLOT(nextFile()));
74+
connect(previous_file_action , SIGNAL(triggered()) , this, SLOT(previousFile()));
6775
connect(tabWidget , SIGNAL(tabCloseRequested(int)) , this, SLOT(closeTab(int) ));
6876
connect(tabWidget , SIGNAL(currentChanged(int)) , this, SLOT(updateConnect(int)));
6977
connect(tree_widget_img , SIGNAL(itemClicked(QTreeWidgetItem *,int)), this, SLOT(treeWidgetClicked()));
@@ -365,6 +373,23 @@ void MainWindow::on_actionOpenDir_triggered() {
365373
// setWindowTitle("PixelAnnotation - " + openedDir);
366374
}
367375

376+
void MainWindow::nextFile() {
377+
QTreeWidgetItem *currentItem = tree_widget_img->currentItem();
378+
if (!currentItem) return;
379+
QTreeWidgetItem *nextItem = tree_widget_img->itemBelow(currentItem);
380+
if (!nextItem) return;
381+
tree_widget_img->setCurrentItem(nextItem);
382+
treeWidgetClicked();
383+
}
384+
385+
void MainWindow::previousFile() {
386+
QTreeWidgetItem *currentItem = tree_widget_img->currentItem();
387+
if (!currentItem) return;
388+
QTreeWidgetItem *previousItem = tree_widget_img->itemAbove(currentItem);
389+
if (!previousItem) return;
390+
tree_widget_img->setCurrentItem(previousItem);
391+
treeWidgetClicked();
392+
}
368393

369394
void MainWindow::saveConfigFile() {
370395
QString file = QFileDialog::getSaveFileName(this, tr("Save Config File"), QString(), tr("JSon file (*.json)"));

Diff for: src/main_window.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ class MainWindow : public QMainWindow, public Ui::MainWindow {
5757
QAction * close_tab_action;
5858
QAction * undo_action ;
5959
QAction * swap_action;
60-
QAction * redo_action ;
60+
QAction * redo_action ;
61+
QAction * next_file_action;
62+
QAction * previous_file_action;
6163
QString curr_open_dir;
6264
public:
6365
QString currentDir() const;
@@ -84,6 +86,8 @@ public slots:
8486
void copyMask();
8587
void pasteMask();
8688
void clearMask();
89+
void nextFile();
90+
void previousFile();
8791
void updateConnect(int index);
8892
void treeWidgetClicked();
8993
void onLabelShortcut(int row);

0 commit comments

Comments
 (0)