You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

pane.cpp 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include "pane.h"
  2. #include <QListView>
  3. #include <QVBoxLayout>
  4. #include <QFileSystemModel>
  5. namespace hex {
  6. Pane::Pane(QWidget* parent) :
  7. QWidget(parent)
  8. {
  9. auto layout = new QVBoxLayout;
  10. mView = new QListView();
  11. mModel = new QFileSystemModel();
  12. mModel->setReadOnly(false);
  13. mView->setModel(mModel);
  14. mView->setSelectionMode(QAbstractItemView::ExtendedSelection);
  15. mView->setDragDropMode(QAbstractItemView::DragDrop);
  16. mModel->setRootPath("/");
  17. setPath("/home/user");
  18. layout->addWidget(mView);
  19. layout->setContentsMargins(0,0,0,0);
  20. this->setLayout(layout);
  21. QObject::connect(mView, &QListView::doubleClicked,
  22. this, &Pane::changeIndex);
  23. }
  24. bool Pane::setPath(const QString& path) {
  25. changeIndex(mModel->index(path));
  26. return true;
  27. }
  28. void Pane::changeIndex(const QModelIndex& index) {
  29. if (mModel->isDir(index)) {
  30. mView->setRootIndex(index);
  31. emit pathChanged(mModel->filePath(index));
  32. } else {
  33. //open file
  34. }
  35. }
  36. void Pane::moveUp() {
  37. changeIndex(mView->currentIndex().parent());
  38. }
  39. QString Pane::getPath() {
  40. return mModel->filePath(mView->currentIndex());
  41. }
  42. }
  43. #include "moc_pane.cpp"