init commit

This commit is contained in:
Gary Wang 2020-09-23 01:42:09 +08:00
commit fe1530fb97
9 changed files with 364 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
# User files
*.user

3
README.md Normal file
View File

@ -0,0 +1,3 @@
This is a toy project, just for testing QColumnView for file browsing.
This project is NOT recommended to use.

11
main.cpp Normal file
View File

@ -0,0 +1,11 @@
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}

79
mainwindow.cpp Normal file
View File

@ -0,0 +1,79 @@
#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());
}

31
mainwindow.h Normal file
View File

@ -0,0 +1,31 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
class QFileSystemModel;
QT_END_NAMESPACE
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
void viewGotoModelIndex(const QModelIndex &index);
private slots:
void on_treeView_clicked(const QModelIndex &index);
void on_cdUpButton_clicked();
private:
Ui::MainWindow *ui;
QFileSystemModel * m_fsmodel;
};
#endif // MAINWINDOW_H

156
mainwindow.ui Normal file
View File

@ -0,0 +1,156 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1153</width>
<height>673</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="cdUpButton">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QSplitter" name="splitter">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<widget class="QTreeView" name="treeView">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="baseSize">
<size>
<width>200</width>
<height>0</height>
</size>
</property>
<property name="headerHidden">
<bool>true</bool>
</property>
</widget>
<widget class="QStackedWidget" name="stackedWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>3</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="lineWidth">
<number>0</number>
</property>
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="page">
<layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QColumnView" name="columnView"/>
</item>
</layout>
</widget>
<widget class="QWidget" name="page_2">
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QListView" name="listView">
<property name="movement">
<enum>QListView::Snap</enum>
</property>
<property name="viewMode">
<enum>QListView::IconMode</enum>
</property>
<property name="uniformItemSizes">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="page_3">
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QTreeView" name="treeTable"/>
</item>
</layout>
</widget>
</widget>
</widget>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1153</width>
<height>25</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>

33
pineapple-files.pro Normal file
View File

@ -0,0 +1,33 @@
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++11
# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp \
mainwindow.cpp \
statusbarwidget.cpp
HEADERS += \
mainwindow.h \
statusbarwidget.h
FORMS += \
mainwindow.ui
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

30
statusbarwidget.cpp Normal file
View File

@ -0,0 +1,30 @@
#include "statusbarwidget.h"
#include <QPushButton>
#include <QVBoxLayout>
StatusbarWidget::StatusbarWidget(QWidget *parent) : QWidget(parent)
{
QHBoxLayout * layout = new QHBoxLayout;
this->setLayout(layout);
layout->setMargin(0);
QPushButton * m_columnsModeBtn = new QPushButton("Columns");
connect(m_columnsModeBtn, &QPushButton::clicked, this, [this](){
Q_EMIT requestMode(0);
});
QPushButton * m_listModeBtn = new QPushButton("List");
connect(m_listModeBtn, &QPushButton::clicked, this, [this](){
Q_EMIT requestMode(1);
});
QPushButton * m_detailsModeBtn = new QPushButton("Details");
connect(m_detailsModeBtn, &QPushButton::clicked, this, [this](){
Q_EMIT requestMode(2);
});
layout->addWidget(m_columnsModeBtn);
layout->addWidget(m_listModeBtn);
layout->addWidget(m_detailsModeBtn);
}

19
statusbarwidget.h Normal file
View File

@ -0,0 +1,19 @@
#ifndef STATUSBARWIDGET_H
#define STATUSBARWIDGET_H
#include <QObject>
#include <QWidget>
class StatusbarWidget : public QWidget
{
Q_OBJECT
public:
explicit StatusbarWidget(QWidget *parent = nullptr);
signals:
void requestMode(int mode);
public slots:
};
#endif // STATUSBARWIDGET_H