From 921f0aa3f361f135e5b0ccd3f4f6e8d0ececbc38 Mon Sep 17 00:00:00 2001 From: Herwig Birke Date: Fri, 7 Feb 2020 12:08:26 +0100 Subject: [PATCH] initial commit --- cfilebrowser.cpp | 90 +++++++++++++++++++++++++++++------------------- cfilebrowser.h | 11 +++++- cfilebrowser.ui | 31 ----------------- cmainwindow.cpp | 13 ++++--- cmainwindow.h | 16 ++++++--- cmainwindow.ui | 33 +++++++++++++++++- 6 files changed, 118 insertions(+), 76 deletions(-) diff --git a/cfilebrowser.cpp b/cfilebrowser.cpp index 3ed116e..7de78eb 100644 --- a/cfilebrowser.cpp +++ b/cfilebrowser.cpp @@ -17,16 +17,21 @@ #include -#include +#include +#include + +#include #include #include -cFileBrowser::cFileBrowser(QProgressBar* lpProgressBar, QList* lpImageFormats, QWidget *parent) : +cFileBrowser::cFileBrowser(QProgressBar* lpProgressBar, QList* lpImageFormats, QListView* lpSelectedList, QStandardItemModel* lpSelectedListModel, QWidget *parent) : QWidget(parent), ui(new Ui::cFileBrowser), + m_lpSelectedList(lpSelectedList), m_lpFileListModel(nullptr), + m_lpSelectedListModel(lpSelectedListModel), m_lpProgressBar(lpProgressBar), m_lpImageFormats(lpImageFormats), m_working(false) @@ -35,8 +40,7 @@ cFileBrowser::cFileBrowser(QProgressBar* lpProgressBar, QList* lpIm ui->m_lpFileList->setGridSize(QSize(THUMBNAIL_WIDTH+2+4, THUMBNAIL_WIDTH+34+4)); -// m_directoryListModel.setRootPath(""); - m_directoryListModel.setRootPath("C:/Users/birkeh/Pictures"); + m_directoryListModel.setRootPath(""); m_directoryListModel.setFilter(QDir::AllDirs | QDir::NoDotAndDotDot); ui->m_lpDirectoryList->setModel(&m_directoryListModel); ui->m_lpDirectoryList->setAnimated(false); @@ -46,9 +50,6 @@ cFileBrowser::cFileBrowser(QProgressBar* lpProgressBar, QList* lpIm m_lpFileListModel = new QStandardItemModel(0, 0); ui->m_lpFileList->setModel(m_lpFileListModel); - m_lpSelectedListModel = new QStandardItemModel(0, 0); - ui->m_lpSelectedList->setModel(m_lpSelectedListModel); - m_cacheDB = QSqlDatabase::addDatabase("QSQLITE", "cacheDB"); m_cacheDB.setHostName("localhost"); m_cacheDB.setDatabaseName(userDir() + "cache.db"); @@ -83,6 +84,18 @@ cFileBrowser::cFileBrowser(QProgressBar* lpProgressBar, QList* lpIm } } + QSettings settings; + QStringList picturesPathList = QStandardPaths::standardLocations(QStandardPaths::PicturesLocation); + QString picturesPath; + + if(picturesPathList.count()) + picturesPath = picturesPathList[0]; + + QString filePath = settings.value("lastPath", QVariant::fromValue(picturesPath)).toString(); + QModelIndex index = m_directoryListModel.index(filePath); + ui->m_lpDirectoryList->selectionModel()->setCurrentIndex(index, QItemSelectionModel::Select); + directorySelected(filePath); + connect(ui->m_lpDirectoryList->selectionModel(), &QItemSelectionModel::selectionChanged, this, &cFileBrowser::onDirectoryChanged); } @@ -96,31 +109,7 @@ cFileBrowser::~cFileBrowser() void cFileBrowser::onDirectoryChanged(const QItemSelection& selected, const QItemSelection& /*deselected*/) { - m_working = true; - - m_lpProgressBar->setVisible(true); - ui->m_lpDirectoryList->setEnabled(false); - - m_lpFileListModel->clear(); - - QFileInfo info = m_directoryListModel.fileInfo(selected.indexes()[0]); - QDir dir(info.filePath()); - - QFileInfoList list = dir.entryInfoList(generateReadList(*m_lpImageFormats), QDir::Files, QDir::Name); - - m_lpProgressBar->setRange(0, list.count()); - - for(int x = 0;x < list.count();x++) - { - addFile(list[x]); - m_lpProgressBar->setValue(x); - qApp->processEvents(); - } - - ui->m_lpDirectoryList->setEnabled(true); - m_lpProgressBar->setVisible(false); - - m_working = false; + directorySelected(m_directoryListModel.fileInfo(selected.indexes()[0]).filePath()); } void cFileBrowser::onCountChanged(cFileViewer* fileViewer) @@ -129,7 +118,7 @@ void cFileBrowser::onCountChanged(cFileViewer* fileViewer) for(int x = 0;x < m_lpSelectedListModel->rowCount();x++) { - lpFileViewer = static_cast(ui->m_lpSelectedList->indexWidget(m_lpSelectedListModel->index(x, 0))); + lpFileViewer = static_cast(m_lpSelectedList->indexWidget(m_lpSelectedListModel->index(x, 0))); if(lpFileViewer) { if(lpFileViewer->fileName() == fileViewer->fileName()) @@ -153,7 +142,7 @@ void cFileBrowser::onCountChanged(cFileViewer* fileViewer) lpFileViewer1->setCount(fileViewer->count()); m_lpSelectedListModel->appendRow(lpItem); - ui->m_lpSelectedList->setIndexWidget(m_lpSelectedListModel->index(m_lpSelectedListModel->rowCount()-1, 0), lpFileViewer1); + m_lpSelectedList->setIndexWidget(m_lpSelectedListModel->index(m_lpSelectedListModel->rowCount()-1, 0), lpFileViewer1); connect(lpFileViewer1, &cFileViewer::countChanged, this, &cFileBrowser::onCountChangedSelected); } @@ -179,6 +168,37 @@ void cFileBrowser::onCountChangedSelected(cFileViewer* fileViewer) } } +void cFileBrowser::directorySelected(const QString& filePath) +{ + m_working = true; + + m_lpProgressBar->setVisible(true); + ui->m_lpDirectoryList->setEnabled(false); + + m_lpFileListModel->clear(); + + QDir dir(filePath); + + QFileInfoList list = dir.entryInfoList(generateReadList(*m_lpImageFormats), QDir::Files, QDir::Name); + + m_lpProgressBar->setRange(0, list.count()); + + for(int x = 0;x < list.count();x++) + { + addFile(list[x]); + m_lpProgressBar->setValue(x); + qApp->processEvents(); + } + + ui->m_lpDirectoryList->setEnabled(true); + m_lpProgressBar->setVisible(false); + + QSettings settings; + settings.setValue("lastPath", QVariant::fromValue(filePath)); + + m_working = false; +} + void cFileBrowser::addFile(const QFileInfo& fileInfo) { cEXIF* lpExif = new cEXIF(&m_exifTAGList, &m_exifCompressionList, &m_exifLightSourceList, &m_exifFlashList, &m_iptcTagList, &m_xmpTagList); @@ -208,7 +228,7 @@ void cFileBrowser::addFile(const QFileInfo& fileInfo) for(int x = 0;x < m_lpSelectedListModel->rowCount();x++) { - lpFileViewer = static_cast(ui->m_lpSelectedList->indexWidget(m_lpSelectedListModel->index(x, 0))); + lpFileViewer = static_cast(m_lpSelectedList->indexWidget(m_lpSelectedListModel->index(x, 0))); if(lpFileViewer) { if(lpFileViewer->fileName() == lpFileViewerNew->fileName()) diff --git a/cfilebrowser.h b/cfilebrowser.h index 647fc24..f61c556 100644 --- a/cfilebrowser.h +++ b/cfilebrowser.h @@ -13,6 +13,7 @@ #include +#include #include #include #include @@ -45,7 +46,7 @@ public: \param lpImageFormats \param parent */ - explicit cFileBrowser(QProgressBar* lpProgressBar, QList* lpImageFormats, QWidget *parent = nullptr); + explicit cFileBrowser(QProgressBar* lpProgressBar, QList* lpImageFormats, QListView* lpSelectedList, QStandardItemModel* lpSelectedListModel, QWidget *parent = nullptr); /*! \brief @@ -55,6 +56,7 @@ public: private: Ui::cFileBrowser* ui; /*!< TODO: describe */ + QListView* m_lpSelectedList; /*!< TODO: describe */ QFileSystemModel m_directoryListModel; /*!< TODO: describe */ QStandardItemModel* m_lpFileListModel; /*!< TODO: describe */ QStandardItemModel* m_lpSelectedListModel; /*!< TODO: describe */ @@ -74,6 +76,13 @@ private: bool m_working; /*!< TODO: describe */ + /*! + \brief + + \fn directorySelected + \param filePath + */ + void directorySelected(const QString& filePath); /*! \brief diff --git a/cfilebrowser.ui b/cfilebrowser.ui index 0993de8..ec22cea 100644 --- a/cfilebrowser.ui +++ b/cfilebrowser.ui @@ -44,37 +44,6 @@ - - - - - 0 - 244 - - - - - 16777215 - 244 - - - - QListView::Free - - - QListView::LeftToRight - - - QListView::Adjust - - - - 202 - 236 - - - - diff --git a/cmainwindow.cpp b/cmainwindow.cpp index 69a553f..25babf8 100644 --- a/cmainwindow.cpp +++ b/cmainwindow.cpp @@ -34,6 +34,11 @@ cMainWindow::~cMainWindow() delete ui; } +void cMainWindow::showEvent(QShowEvent *event) +{ + QMainWindow::showEvent(event); +} + void cMainWindow::closeEvent(QCloseEvent *event) { // if(m_working) @@ -70,11 +75,11 @@ void cMainWindow::initUI() m_lpProgressBar->setVisible(false); ui->m_lpStatusBar->addPermanentWidget(m_lpProgressBar); - m_lpFileBrowser = new cFileBrowser(m_lpProgressBar, &m_imageFormats, this); - ui->m_lpMainTab->addTab(m_lpFileBrowser, "Files"); + m_lpSelectedListModel = new QStandardItemModel(0, 0); + ui->m_lpSelectedList->setModel(m_lpSelectedListModel); -// m_lpFileListModel = new QStandardItemModel; -// ui->m_lpFileList->setModel(m_lpFileListModel); + m_lpFileBrowser = new cFileBrowser(m_lpProgressBar, &m_imageFormats, ui->m_lpSelectedList, m_lpSelectedListModel, this); + ui->m_lpMainTab->addTab(m_lpFileBrowser, "Files"); if(!settings.value("main/maximized").toBool()) { diff --git a/cmainwindow.h b/cmainwindow.h index 44e61d3..a46ad8a 100644 --- a/cmainwindow.h +++ b/cmainwindow.h @@ -42,12 +42,13 @@ public: private: Ui::cMainWindow* ui; /*!< TODO: describe */ - cSplashScreen* m_lpSplashScreen; /*!< TODO: describe */ - QProgressBar* m_lpProgressBar; /*!< TODO: describe */ + cSplashScreen* m_lpSplashScreen; /*!< TODO: describe */ + QProgressBar* m_lpProgressBar; /*!< TODO: describe */ - cFileBrowser* m_lpFileBrowser; /*!< TODO: describe */ + cFileBrowser* m_lpFileBrowser; /*!< TODO: describe */ + QStandardItemModel* m_lpSelectedListModel; /*!< TODO: describe */ - QList m_imageFormats; /*!< TODO: describe */ + QList m_imageFormats; /*!< TODO: describe */ /*! \brief @@ -93,6 +94,13 @@ private: void addImageFormat(const QString& shortName, const QString& description, const QString& extension, QList& readList, QList& writeList); protected: + /*! + \brief + + \fn showEvent + \param event + */ + void showEvent(QShowEvent *event); /*! \brief diff --git a/cmainwindow.ui b/cmainwindow.ui index b20ef47..7f4831c 100644 --- a/cmainwindow.ui +++ b/cmainwindow.ui @@ -18,6 +18,37 @@ + + + + + 0 + 264 + + + + + 16777215 + 264 + + + + QListView::Free + + + QListView::LeftToRight + + + QListView::Adjust + + + + 202 + 236 + + + + @@ -26,7 +57,7 @@ 0 0 800 - 22 + 21