pineapple-files/mainwindow.cpp

80 lines
2.3 KiB
C++
Raw Normal View History

2020-09-23 01:42:09 +08:00
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "statusbarwidget.h"
#include <QFileSystemModel>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
, m_fsmodel(new QFileSystemModel)
{
ui->setupUi(this);
ui->cdUpButton->setIcon(qApp->style()->standardIcon(QStyle::SP_FileDialogToParent));
m_fsmodel->setRootPath("");
ui->columnView->setModel(m_fsmodel);
ui->listView->setModel(m_fsmodel);
ui->treeView->setModel(m_fsmodel);
ui->treeTable->setModel(m_fsmodel);
ui->treeTable->setItemsExpandable(false);
ui->treeTable->setRootIsDecorated(false);
ui->treeView->hideColumn(1);
ui->treeView->hideColumn(2);
ui->treeView->hideColumn(3);
StatusbarWidget * sb = new StatusbarWidget();
ui->statusbar->addPermanentWidget(sb);
connect(sb, &StatusbarWidget::requestMode, this, [this](int mode){
ui->stackedWidget->setCurrentIndex(mode);
});
connect(ui->listView, &QAbstractItemView::doubleClicked, this, &MainWindow::viewGotoModelIndex);
connect(ui->treeTable, &QAbstractItemView::doubleClicked, this, &MainWindow::viewGotoModelIndex);
connect(ui->columnView, &QAbstractItemView::clicked, this, &MainWindow::viewGotoModelIndex);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::viewGotoModelIndex(const QModelIndex &index)
{
if (!m_fsmodel->isDir(index)) {
return;
}
ui->listView->setRootIndex(index);
ui->treeTable->setRootIndex(index);
QItemSelectionModel::SelectionFlags flags = QItemSelectionModel::Current;
// if (columnClicked->selectionModel()->isSelected(index))
// flags |= QItemSelectionModel::Select;
ui->columnView->selectionModel()->setCurrentIndex(index, flags);
}
void MainWindow::on_treeView_clicked(const QModelIndex &index)
{
if (!m_fsmodel->isDir(index)) {
return;
}
ui->listView->setRootIndex(index);
ui->treeTable->setRootIndex(index);
ui->columnView->setRootIndex(index);
}
void MainWindow::on_cdUpButton_clicked()
{
const QModelIndex &idx = ui->listView->rootIndex();
if (!idx.parent().isValid()) {
return;
}
viewGotoModelIndex(idx.parent());
}