87 lines
2.6 KiB
C++
87 lines
2.6 KiB
C++
#include "mainwindow.h"
|
|
#include "ui_mainwindow.h"
|
|
|
|
#include "statusbarwidget.h"
|
|
#include "verticalpreviewwidget.h"
|
|
|
|
#include <QFileSystemModel>
|
|
|
|
MainWindow::MainWindow(QWidget *parent)
|
|
: QMainWindow(parent)
|
|
, ui(new Ui::MainWindow)
|
|
, m_fsmodel(new QFileSystemModel)
|
|
, m_previewWidget(new VerticalPreviewWidget)
|
|
{
|
|
ui->setupUi(this);
|
|
|
|
ui->cdUpButton->setIcon(qApp->style()->standardIcon(QStyle::SP_FileDialogToParent));
|
|
|
|
m_fsmodel->setRootPath("");
|
|
|
|
m_previewWidget->setModel(m_fsmodel);
|
|
|
|
ui->columnView->setPreviewWidget(m_previewWidget);
|
|
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);
|
|
connect(ui->columnView, &QColumnView::updatePreviewWidget, m_previewWidget, &VerticalPreviewWidget::updatePreviewContent);
|
|
}
|
|
|
|
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());
|
|
}
|