Browse Source

more basic stuff

master
hex 4 years ago
parent
commit
1b47c4b995
2 changed files with 19 additions and 3 deletions
  1. 1
    0
      include/window.h
  2. 18
    3
      src/window.cpp

+ 1
- 0
include/window.h View File

@@ -13,6 +13,7 @@ public:
explicit Window(QWidget *parent = 0);

public slots:
void moveUp();
void changeIndex(const QModelIndex& index);
private:

+ 18
- 3
src/window.cpp View File

@@ -6,28 +6,43 @@
#include <QFileSystemModel>
#include <QString>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QDesktopServices>
#include <QUrl>

Window::Window(QWidget *parent) :
QWidget(parent)
{
QVBoxLayout* navbar = new QVBoxLayout(this);
mButton = new QPushButton("^");
navbar->addWidget(mButton);

QHBoxLayout* splitter = new QHBoxLayout(this);
mListView = new QListView(this);
splitter->addWidget(mListView);
this->setLayout(splitter);
//mButton = new QPushButton("add", this);
navbar->addItem(splitter);
this->setLayout(navbar);

mModel = new QFileSystemModel();
mListView->setModel(mModel);

mModel->setRootPath("/home/user/");
mModel->setRootPath("/");
mListView->setRootIndex(mModel->index("/home/user/"));

QObject::connect(mListView, &QListView::doubleClicked,
this, &Window::changeIndex);
QObject::connect(mButton, &QPushButton::clicked,
this, &Window::moveUp);
}

void Window::moveUp() {
mListView->setRootIndex(mListView->rootIndex().parent());
}

void Window::changeIndex(const QModelIndex& index) {
if (mModel->isDir(index)) {
mListView->setRootIndex(index);
} else {
QDesktopServices::openUrl(QUrl::fromLocalFile(mModel->filePath(index)));
}
}

Loading…
Cancel
Save