From 6b8a509f96f2c3e1981b871a8bfcadf0110aeea5 Mon Sep 17 00:00:00 2001 From: Gary Wang Date: Wed, 23 Sep 2020 18:33:30 +0800 Subject: [PATCH] simple preview widget --- mainwindow.cpp | 7 +++ mainwindow.h | 2 + pineapple-files.pro | 9 ++-- verticalpreviewwidget.cpp | 37 ++++++++++++++++ verticalpreviewwidget.h | 31 ++++++++++++++ verticalpreviewwidget.ui | 90 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 173 insertions(+), 3 deletions(-) create mode 100644 verticalpreviewwidget.cpp create mode 100644 verticalpreviewwidget.h create mode 100644 verticalpreviewwidget.ui diff --git a/mainwindow.cpp b/mainwindow.cpp index 9dde8a1..e9b23d4 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -2,6 +2,7 @@ #include "ui_mainwindow.h" #include "statusbarwidget.h" +#include "verticalpreviewwidget.h" #include @@ -9,12 +10,17 @@ 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); @@ -36,6 +42,7 @@ MainWindow::MainWindow(QWidget *parent) 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() diff --git a/mainwindow.h b/mainwindow.h index 6605e28..24b638c 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -8,6 +8,7 @@ namespace Ui { class MainWindow; } class QFileSystemModel; QT_END_NAMESPACE +class VerticalPreviewWidget; class MainWindow : public QMainWindow { Q_OBJECT @@ -27,5 +28,6 @@ private: Ui::MainWindow *ui; QFileSystemModel * m_fsmodel; + VerticalPreviewWidget * m_previewWidget; }; #endif // MAINWINDOW_H diff --git a/pineapple-files.pro b/pineapple-files.pro index 53cadf5..0eddf23 100644 --- a/pineapple-files.pro +++ b/pineapple-files.pro @@ -18,14 +18,17 @@ DEFINES += QT_DEPRECATED_WARNINGS SOURCES += \ main.cpp \ mainwindow.cpp \ - statusbarwidget.cpp + statusbarwidget.cpp \ + verticalpreviewwidget.cpp HEADERS += \ mainwindow.h \ - statusbarwidget.h + statusbarwidget.h \ + verticalpreviewwidget.h FORMS += \ - mainwindow.ui + mainwindow.ui \ + verticalpreviewwidget.ui # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin diff --git a/verticalpreviewwidget.cpp b/verticalpreviewwidget.cpp new file mode 100644 index 0000000..b971857 --- /dev/null +++ b/verticalpreviewwidget.cpp @@ -0,0 +1,37 @@ +#include "verticalpreviewwidget.h" +#include "ui_verticalpreviewwidget.h" + +#include +#include +#include +#include + +VerticalPreviewWidget::VerticalPreviewWidget(QWidget *parent) : + QWidget(parent), + ui(new Ui::VerticalPreviewWidget) +{ + ui->setupUi(this); +} + +VerticalPreviewWidget::~VerticalPreviewWidget() +{ + delete ui; +} + +void VerticalPreviewWidget::setModel(QFileSystemModel *fsmodel) +{ + this->m_fsmodel = fsmodel; +} + +void VerticalPreviewWidget::updatePreviewContent(const QModelIndex &index) +{ + ui->fileIconLabel->setPixmap(m_fsmodel->fileIcon(index).pixmap(64)); + ui->filenameLabel->setText(m_fsmodel->fileName(index)); + + const QFileInfo & info = m_fsmodel->fileInfo(index); + + ui->createdAtLabel->setText(info.birthTime().toString()); + ui->lastUpdateLabel->setText(info.lastModified().toString()); + +// ui->formLayout->addRow("Created at:", new QLabel(info.birthTime().toString())); +} diff --git a/verticalpreviewwidget.h b/verticalpreviewwidget.h new file mode 100644 index 0000000..0f7f96e --- /dev/null +++ b/verticalpreviewwidget.h @@ -0,0 +1,31 @@ +#ifndef VERTICALPREVIEWWIDGET_H +#define VERTICALPREVIEWWIDGET_H + +#include + +namespace Ui { +class VerticalPreviewWidget; +} + +QT_BEGIN_NAMESPACE +class QFileSystemModel; +QT_END_NAMESPACE + +class VerticalPreviewWidget : public QWidget +{ + Q_OBJECT + +public: + explicit VerticalPreviewWidget(QWidget *parent = nullptr); + ~VerticalPreviewWidget(); + + void setModel(QFileSystemModel * fsmodel); + void updatePreviewContent(const QModelIndex &index); + +private: + Ui::VerticalPreviewWidget *ui; + + QFileSystemModel * m_fsmodel = nullptr; +}; + +#endif // VERTICALPREVIEWWIDGET_H diff --git a/verticalpreviewwidget.ui b/verticalpreviewwidget.ui new file mode 100644 index 0000000..3f7f464 --- /dev/null +++ b/verticalpreviewwidget.ui @@ -0,0 +1,90 @@ + + + VerticalPreviewWidget + + + + 0 + 0 + 160 + 484 + + + + Form + + + + + + Qt::AlignCenter + + + + + + + Placeholder + + + Qt::AlignCenter + + + + + + + Qt::Horizontal + + + + + + + + + Created at: + + + + + + + TextLabel + + + + + + + TextLabel + + + + + + + Last update: + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + +