-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
79 lines (66 loc) · 2.46 KB
/
Copy pathmainwindow.cpp
File metadata and controls
79 lines (66 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include "mainwindow.h"
#include "./ui_mainwindow.h"
#include "qsettings.h"
#include <QFileDialog>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(ui->folderBtn, &QPushButton::clicked,
this, &MainWindow::setFolderPath);
connect(this, &MainWindow::folderChanged,
ui->galleryWidget, &GalleryWidget::updateList);
connect(this, &MainWindow::viewTypeChanged,
ui->galleryWidget, &GalleryWidget::setLayoutType);
QSettings settings;
QString path = settings.value("main_path").toString();
qDebug() << "Saved path:" << path;
ui->pathLabel->setText(path);
// Set the saved view preference
QButtonGroup* group = ui->viewsButtonGroup;
ui->listViewRadioBtn->setChecked(true); // default preference
QString viewType = settings.value("selected_view_type", "").toString();
if (!viewType.isEmpty()) {
QList<QAbstractButton *> buttons = group->buttons();
for (QAbstractButton * button : buttons)
if (button->text() == viewType)
button->setChecked(true);
}
connect(group, &QButtonGroup::buttonClicked, this,
[this, group](QAbstractButton *button)
{
auto text = button->text();
QSettings settings;
settings.setValue("selected_view_type", text);
emit viewTypeChanged(text);
});
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::setFolderPath(){
QString directory = QFileDialog::getExistingDirectory(this,
"Pick a directory",
QDir::homePath(),
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
if (!directory.isEmpty()){
ui->pathLabel->setText(directory);
emit folderChanged(directory);
QSettings settings;
settings.setValue("main_path", directory);
}
}
void MainWindow::showEvent(QShowEvent *event)
{
qDebug() << "MainWindow::showEvent";
qDebug() << "instantanuos:" << event->spontaneous();
// Spontanous is true after the initial show event, ignore
if (event->spontaneous()) return;
QSettings settings;
QString path = settings.value("main_path").toString();
if (!path.isNull()) {
ui->galleryWidget->updateList(path);
}
}