simple preview widget
This commit is contained in:
parent
fe1530fb97
commit
6b8a509f96
|
@ -2,6 +2,7 @@
|
||||||
#include "ui_mainwindow.h"
|
#include "ui_mainwindow.h"
|
||||||
|
|
||||||
#include "statusbarwidget.h"
|
#include "statusbarwidget.h"
|
||||||
|
#include "verticalpreviewwidget.h"
|
||||||
|
|
||||||
#include <QFileSystemModel>
|
#include <QFileSystemModel>
|
||||||
|
|
||||||
|
@ -9,12 +10,17 @@ MainWindow::MainWindow(QWidget *parent)
|
||||||
: QMainWindow(parent)
|
: QMainWindow(parent)
|
||||||
, ui(new Ui::MainWindow)
|
, ui(new Ui::MainWindow)
|
||||||
, m_fsmodel(new QFileSystemModel)
|
, m_fsmodel(new QFileSystemModel)
|
||||||
|
, m_previewWidget(new VerticalPreviewWidget)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
ui->cdUpButton->setIcon(qApp->style()->standardIcon(QStyle::SP_FileDialogToParent));
|
ui->cdUpButton->setIcon(qApp->style()->standardIcon(QStyle::SP_FileDialogToParent));
|
||||||
|
|
||||||
m_fsmodel->setRootPath("");
|
m_fsmodel->setRootPath("");
|
||||||
|
|
||||||
|
m_previewWidget->setModel(m_fsmodel);
|
||||||
|
|
||||||
|
ui->columnView->setPreviewWidget(m_previewWidget);
|
||||||
ui->columnView->setModel(m_fsmodel);
|
ui->columnView->setModel(m_fsmodel);
|
||||||
ui->listView->setModel(m_fsmodel);
|
ui->listView->setModel(m_fsmodel);
|
||||||
ui->treeView->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->listView, &QAbstractItemView::doubleClicked, this, &MainWindow::viewGotoModelIndex);
|
||||||
connect(ui->treeTable, &QAbstractItemView::doubleClicked, this, &MainWindow::viewGotoModelIndex);
|
connect(ui->treeTable, &QAbstractItemView::doubleClicked, this, &MainWindow::viewGotoModelIndex);
|
||||||
connect(ui->columnView, &QAbstractItemView::clicked, this, &MainWindow::viewGotoModelIndex);
|
connect(ui->columnView, &QAbstractItemView::clicked, this, &MainWindow::viewGotoModelIndex);
|
||||||
|
connect(ui->columnView, &QColumnView::updatePreviewWidget, m_previewWidget, &VerticalPreviewWidget::updatePreviewContent);
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
|
|
|
@ -8,6 +8,7 @@ namespace Ui { class MainWindow; }
|
||||||
class QFileSystemModel;
|
class QFileSystemModel;
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
|
class VerticalPreviewWidget;
|
||||||
class MainWindow : public QMainWindow
|
class MainWindow : public QMainWindow
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -27,5 +28,6 @@ private:
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
|
|
||||||
QFileSystemModel * m_fsmodel;
|
QFileSystemModel * m_fsmodel;
|
||||||
|
VerticalPreviewWidget * m_previewWidget;
|
||||||
};
|
};
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
||||||
|
|
|
@ -18,14 +18,17 @@ DEFINES += QT_DEPRECATED_WARNINGS
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
main.cpp \
|
main.cpp \
|
||||||
mainwindow.cpp \
|
mainwindow.cpp \
|
||||||
statusbarwidget.cpp
|
statusbarwidget.cpp \
|
||||||
|
verticalpreviewwidget.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
mainwindow.h \
|
mainwindow.h \
|
||||||
statusbarwidget.h
|
statusbarwidget.h \
|
||||||
|
verticalpreviewwidget.h
|
||||||
|
|
||||||
FORMS += \
|
FORMS += \
|
||||||
mainwindow.ui
|
mainwindow.ui \
|
||||||
|
verticalpreviewwidget.ui
|
||||||
|
|
||||||
# Default rules for deployment.
|
# Default rules for deployment.
|
||||||
qnx: target.path = /tmp/$${TARGET}/bin
|
qnx: target.path = /tmp/$${TARGET}/bin
|
||||||
|
|
37
verticalpreviewwidget.cpp
Normal file
37
verticalpreviewwidget.cpp
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
#include "verticalpreviewwidget.h"
|
||||||
|
#include "ui_verticalpreviewwidget.h"
|
||||||
|
|
||||||
|
#include <QFileSystemModel>
|
||||||
|
#include <QDateTime>
|
||||||
|
#include <QFileInfo>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
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()));
|
||||||
|
}
|
31
verticalpreviewwidget.h
Normal file
31
verticalpreviewwidget.h
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
#ifndef VERTICALPREVIEWWIDGET_H
|
||||||
|
#define VERTICALPREVIEWWIDGET_H
|
||||||
|
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
|
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
|
90
verticalpreviewwidget.ui
Normal file
90
verticalpreviewwidget.ui
Normal file
|
@ -0,0 +1,90 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>VerticalPreviewWidget</class>
|
||||||
|
<widget class="QWidget" name="VerticalPreviewWidget">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>160</width>
|
||||||
|
<height>484</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Form</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="fileIconLabel">
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="filenameLabel">
|
||||||
|
<property name="text">
|
||||||
|
<string>Placeholder</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="Line" name="line">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QFormLayout" name="formLayout">
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QLabel" name="label">
|
||||||
|
<property name="text">
|
||||||
|
<string>Created at:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="1">
|
||||||
|
<widget class="QLabel" name="createdAtLabel">
|
||||||
|
<property name="text">
|
||||||
|
<string>TextLabel</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="1">
|
||||||
|
<widget class="QLabel" name="lastUpdateLabel">
|
||||||
|
<property name="text">
|
||||||
|
<string>TextLabel</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0">
|
||||||
|
<widget class="QLabel" name="label_3">
|
||||||
|
<property name="text">
|
||||||
|
<string>Last update:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="verticalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Vertical</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>20</width>
|
||||||
|
<height>40</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
Loading…
Reference in New Issue
Block a user