From eab16d6ea2200ffa5f301d97cdcbf8f1becfaaaf Mon Sep 17 00:00:00 2001 From: Gary Wang Date: Thu, 24 Sep 2020 17:47:56 +0800 Subject: [PATCH] now double-clickable --- mainwindow.cpp | 38 +++++++++++++++++++++++++-- mainwindow.h | 4 +++ mainwindow.ui | 5 +++- pineapple-files.pro | 1 + verticalpreviewwidget.cpp | 11 ++++++-- verticalpreviewwidget.ui | 55 ++++++++++++++++++++++++++++++++++----- 6 files changed, 103 insertions(+), 11 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index e9b23d4..999785a 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -4,7 +4,9 @@ #include "statusbarwidget.h" #include "verticalpreviewwidget.h" +#include #include +#include MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) @@ -39,9 +41,10 @@ MainWindow::MainWindow(QWidget *parent) ui->stackedWidget->setCurrentIndex(mode); }); - connect(ui->listView, &QAbstractItemView::doubleClicked, this, &MainWindow::viewGotoModelIndex); - connect(ui->treeTable, &QAbstractItemView::doubleClicked, this, &MainWindow::viewGotoModelIndex); + connect(ui->listView, &QAbstractItemView::doubleClicked, this, &MainWindow::gotoModelIndexOrOpenFile); + connect(ui->treeTable, &QAbstractItemView::doubleClicked, this, &MainWindow::gotoModelIndexOrOpenFile); connect(ui->columnView, &QAbstractItemView::clicked, this, &MainWindow::viewGotoModelIndex); + connect(ui->columnView, &QAbstractItemView::doubleClicked, this, &MainWindow::gotoModelIndexOrOpenFile); connect(ui->columnView, &QColumnView::updatePreviewWidget, m_previewWidget, &VerticalPreviewWidget::updatePreviewContent); } @@ -63,6 +66,32 @@ void MainWindow::viewGotoModelIndex(const QModelIndex &index) // if (columnClicked->selectionModel()->isSelected(index)) // flags |= QItemSelectionModel::Select; ui->columnView->selectionModel()->setCurrentIndex(index, flags); + + ui->addressEdit->setText(m_fsmodel->filePath(index)); +} + +void MainWindow::gotoModelIndexOrOpenFile(const QModelIndex &index) +{ + if (!m_fsmodel->isDir(index)) { + QDesktopServices::openUrl(QUrl::fromLocalFile(m_fsmodel->filePath(index))); + } else { + viewGotoModelIndex(index); + } +} + +bool MainWindow::gotoUrl(const QString &path) +{ + if (!QFileInfo::exists(path)) { + return false; + } + + const QModelIndex &idx = m_fsmodel->index(path); + if (idx.isValid()) { + viewGotoModelIndex(idx); + return true; + } + + return false; } void MainWindow::on_treeView_clicked(const QModelIndex &index) @@ -84,3 +113,8 @@ void MainWindow::on_cdUpButton_clicked() viewGotoModelIndex(idx.parent()); } + +void MainWindow::on_addressEdit_returnPressed() +{ + gotoUrl(ui->addressEdit->text()); +} diff --git a/mainwindow.h b/mainwindow.h index 24b638c..b669d60 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -18,12 +18,16 @@ public: ~MainWindow(); void viewGotoModelIndex(const QModelIndex &index); + void gotoModelIndexOrOpenFile(const QModelIndex &index); + bool gotoUrl(const QString & path); private slots: void on_treeView_clicked(const QModelIndex &index); void on_cdUpButton_clicked(); + void on_addressEdit_returnPressed(); + private: Ui::MainWindow *ui; diff --git a/mainwindow.ui b/mainwindow.ui index baf379d..4b1f2be 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -24,6 +24,9 @@ + + + @@ -145,7 +148,7 @@ 0 0 1153 - 25 + 23 diff --git a/pineapple-files.pro b/pineapple-files.pro index 0eddf23..44cdbb9 100644 --- a/pineapple-files.pro +++ b/pineapple-files.pro @@ -2,6 +2,7 @@ QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets +TARGET = pfile CONFIG += c++11 # The following define makes your compiler emit warnings if you use diff --git a/verticalpreviewwidget.cpp b/verticalpreviewwidget.cpp index b971857..a4cf490 100644 --- a/verticalpreviewwidget.cpp +++ b/verticalpreviewwidget.cpp @@ -5,6 +5,7 @@ #include #include #include +#include VerticalPreviewWidget::VerticalPreviewWidget(QWidget *parent) : QWidget(parent), @@ -29,9 +30,15 @@ void VerticalPreviewWidget::updatePreviewContent(const QModelIndex &index) ui->filenameLabel->setText(m_fsmodel->fileName(index)); const QFileInfo & info = m_fsmodel->fileInfo(index); + static QMimeDatabase mimetypeDatabase; + QMimeType mimeType = mimetypeDatabase.mimeTypeForFile(info); + QString mimeTypeDisplayName = mimeType.comment(); - ui->createdAtLabel->setText(info.birthTime().toString()); - ui->lastUpdateLabel->setText(info.lastModified().toString()); + ui->typeAndSizeLabel->setText(QString("%1 - %2").arg(mimeTypeDisplayName, this->locale().formattedDataSize(info.size()))); + + ui->createdAtLabel->setText(info.birthTime().toString(tr("yyyy/MM/dd hh:mm:ss", "Qt string format"))); + ui->lastUpdateLabel->setText(info.lastModified().toString(tr("yyyy/MM/dd hh:mm:ss", "Qt string format"))); + ui->lastAccessLabel->setText(info.lastRead().toString(tr("yyyy/MM/dd hh:mm:ss", "Qt string format"))); // ui->formLayout->addRow("Created at:", new QLabel(info.birthTime().toString())); } diff --git a/verticalpreviewwidget.ui b/verticalpreviewwidget.ui index 3f7f464..9729d86 100644 --- a/verticalpreviewwidget.ui +++ b/verticalpreviewwidget.ui @@ -31,6 +31,19 @@ + + + + Placeholder + + + Qt::PlainText + + + Qt::AlignCenter + + + @@ -38,6 +51,13 @@ + + + + Info + + + @@ -52,12 +72,8 @@ TextLabel - - - - - - TextLabel + + Qt::PlainText @@ -68,6 +84,33 @@ + + + + TextLabel + + + Qt::PlainText + + + + + + + Last access: + + + + + + + TextLabel + + + Qt::PlainText + + +