Fix startup, and quitting, fixed squishing, added hover and double clicking, added back button

This commit is contained in:
2024-07-03 17:41:33 +02:00
parent abc97d95ef
commit 7ff0f8b71a
12 changed files with 164 additions and 61 deletions

View File

@@ -4,45 +4,57 @@
GridItemView::GridItemView(QWidget* parent)
: QFrame(parent), fileController(FileController::instance( )) {
QGridLayout* mainLayout = new QGridLayout( );
QVBoxLayout* mainLayout = new QVBoxLayout(this);
QGridLayout* gridLayout = new QGridLayout( );
this->setLayout(mainLayout);
gridLayout->setAlignment(Qt::AlignTop);
mainLayout->addLayout(gridLayout);
setLayout(mainLayout);
connect(fileController, &FileController::pathChanged, this,
[this, mainLayout](const std::filesystem::path path) {
[this, gridLayout](const std::filesystem::path path) {
// No, QT Does not offer a better way to clear a layout, at least this solution doesnt segfault
QLayoutItem* wItem;
while ((wItem = mainLayout->takeAt(0)) != 0) {
while ((wItem = gridLayout->takeAt(0)) != 0) {
if (wItem->widget( ))
wItem->widget( )->setParent(nullptr);
delete wItem;
}
gridMap.clear( );
});
connect(fileController, &FileController::contentChanged, this, [this, mainLayout](std::filesystem::path path, FileEvent event) {
connect(fileController, &FileController::contentChanged, this, [this, gridLayout](std::filesystem::path path, FileEvent event) {
if (event == FileEvent::created) {
auto w = new GridItem(path);
gridMap[path] = w;
connect(w, &GridItem::clicked, this, [this, path]( ) {
connect(w, &GridItem::doubleClicked, this, [this, path]( ) {
if (!std::filesystem::is_directory(path))
return;
emit fileController->updatePath(path);
});
connect(w, &GridItem::clicked, this, [this, path]( ) {
if (std::filesystem::is_directory(path))
return;
std::string cmd = "xdg-open \"" + path.string( ) + "\"";
std::system(cmd.c_str( ));
});
int pos = gridMap.size( ) - 1;
mainLayout->addWidget(w, pos / 8, pos % 8);
gridLayout->addWidget(w, pos / 8, pos % 8);
w->show( );
} else if (event == FileEvent::erased) {
mainLayout->removeWidget(gridMap[path]);
gridLayout->removeWidget(gridMap[path]);
delete gridMap[path];
gridMap.erase(path);
int pos = 0;
for (const auto& [key, widget] : gridMap) {
mainLayout->addWidget(widget, pos / 8, pos % 8);
gridLayout->addWidget(widget, pos / 8, pos % 8);
pos++;
}
} else if (event == FileEvent::modified) {
std::cout << "modified" << std::endl;
// Idk what this would be used for
}
});