From 9bc94a0afde35e7b54f7a319b45d5ef4c20a79a6 Mon Sep 17 00:00:00 2001 From: Herwig Birke Date: Tue, 12 Feb 2019 15:32:09 +0100 Subject: [PATCH] import dialog --- cimportdialog.cpp | 62 ++++++++++ cimportdialog.h | 37 ++++++ cimportdialog.ui | 159 +++++++++++++++++++++++++ cmainwindow.cpp | 287 ++++++++++++++++++++++++++++++++++++++++++++- cmainwindow.h | 67 +++++++++++ cpicturelibrary.h | 2 +- pictureLibrary.pro | 11 +- 7 files changed, 618 insertions(+), 7 deletions(-) create mode 100644 cimportdialog.cpp create mode 100644 cimportdialog.h create mode 100644 cimportdialog.ui diff --git a/cimportdialog.cpp b/cimportdialog.cpp new file mode 100644 index 0000000..d5e8edb --- /dev/null +++ b/cimportdialog.cpp @@ -0,0 +1,62 @@ +#include "cimportdialog.h" +#include "ui_cimportdialog.h" + +#include +#include +#include + + +cImportDialog::cImportDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::cImportDialog) +{ + ui->setupUi(this); + + QSettings settings; + + if(settings.value("main/maximized").toBool()) + { + qint32 iX = settings.value("import/x", QVariant::fromValue(-1)).toInt(); + qint32 iY = settings.value("import/y", QVariant::fromValue(-1)).toInt(); + qint32 iWidth = settings.value("import/width", QVariant::fromValue(-1)).toInt(); + qint32 iHeight = settings.value("import/height", QVariant::fromValue(-1)).toInt(); + + if(iWidth != -1 && iHeight != -1) + resize(iWidth, iHeight); + if(iX != -1 && iY != -1) + move(iX, iY); + } +} + +cImportDialog::~cImportDialog() +{ + delete ui; +} + +void cImportDialog::on_m_lpPathSelect_clicked() +{ + QSettings settings; + QString szPath = settings.value("import/path", QDir::homePath()).toString(); + szPath = QFileDialog::getExistingDirectory(this, tr("Import Directory"), szPath, QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); + + if(szPath.isEmpty()) + return; + + ui->m_lpPath->setText(szPath); + settings.setValue("import/path", szPath); +} + +void cImportDialog::closeEvent(QCloseEvent *event) +{ + QSettings settings; + settings.setValue("import/width", QVariant::fromValue(size().width())); + settings.setValue("import/height", QVariant::fromValue(size().height())); + settings.setValue("import/x", QVariant::fromValue(x())); + settings.setValue("import/y", QVariant::fromValue(y())); + if(this->isMaximized()) + settings.setValue("import/maximized", QVariant::fromValue(true)); + else + settings.setValue("import/maximized", QVariant::fromValue(false)); + + event->accept(); +} diff --git a/cimportdialog.h b/cimportdialog.h new file mode 100644 index 0000000..d3cd8d5 --- /dev/null +++ b/cimportdialog.h @@ -0,0 +1,37 @@ +#ifndef CIMPORTDIALOG_H +#define CIMPORTDIALOG_H + + +#include +#include + + +namespace Ui { +class cImportDialog; +} + +class cImportDialog : public QDialog +{ + Q_OBJECT + +public: + explicit cImportDialog(QWidget *parent = nullptr); + ~cImportDialog(); + +private slots: + void on_m_lpPathSelect_clicked(); + +private: + Ui::cImportDialog *ui; + +protected: + /*! + \brief + + \fn closeEvent + \param event + */ + void closeEvent(QCloseEvent* event); +}; + +#endif // CIMPORTDIALOG_H diff --git a/cimportdialog.ui b/cimportdialog.ui new file mode 100644 index 0000000..96a0ced --- /dev/null +++ b/cimportdialog.ui @@ -0,0 +1,159 @@ + + + cImportDialog + + + + 0 + 0 + 653 + 563 + + + + Import + + + + + + + + + + Path: + + + + + + + + + + ... + + + + + + + + + + + recursive + + + + + + + + + copy + + + true + + + copy_or_move + + + + + + + move + + + copy_or_move + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + QAbstractItemView::ExtendedSelection + + + + 160 + 120 + + + + QListView::IconMode + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + m_lpButtonBox + accepted() + cImportDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + m_lpButtonBox + rejected() + cImportDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + + + + diff --git a/cmainwindow.cpp b/cmainwindow.cpp index c647d65..ee15599 100644 --- a/cmainwindow.cpp +++ b/cmainwindow.cpp @@ -1,6 +1,8 @@ #include "common.h" #include "cmainwindow.h" +#include "cimportdialog.h" + #include "ui_cmainwindow.h" #include @@ -18,11 +20,16 @@ cMainWindow::cMainWindow(cSplashScreen* lpSplashScreen, QWidget *parent) : QMainWindow(parent), ui(new Ui::cMainWindow), - m_lpSplashScreen(lpSplashScreen) + m_lpSplashScreen(lpSplashScreen), + m_lpFileMenu(nullptr), + m_lpFileToolBar(nullptr) { initUI(); createActions(); loadData(); + + updateRecentFileActions(); + // cPicture picture; // picture.fromFile(QDir::homePath() + "\\OneDrive - WINDESIGN\\exif-samples-master\\IMG_1371.CR2"); // picture.toDB(); @@ -63,13 +70,34 @@ void cMainWindow::initUI() ui->m_lpThumbnailView->setModel(m_lpThumbnailViewModel); QIcon::setThemeName("TangoMFK"); + + QSettings settings; + + if(!settings.value("main/maximized").toBool()) + { + qint32 iX = settings.value("main/x", QVariant::fromValue(-1)).toInt(); + qint32 iY = settings.value("main/y", QVariant::fromValue(-1)).toInt(); + qint32 iWidth = settings.value("main/width", QVariant::fromValue(-1)).toInt(); + qint32 iHeight = settings.value("main/height", QVariant::fromValue(-1)).toInt(); + + if(iWidth != -1 && iHeight != -1) + resize(iWidth, iHeight); + if(iX != -1 && iY != -1) + move(iX, iY); + } + + qint32 iWidth1 = settings.value("main/splitter1", QVariant::fromValue(-1)).toInt(); + qint32 iWidth2 = settings.value("main/splitter2", QVariant::fromValue(-1)).toInt(); + qint32 iWidth3 = settings.value("main/splitter3", QVariant::fromValue(-1)).toInt(); + + ui->m_lpSplitter->setSizes(QList() << iWidth1 << iWidth2 << iWidth3); } void cMainWindow::createActions() { setToolButtonStyle(Qt::ToolButtonFollowStyle); -// createFileActions(); + createFileActions(); // createEditActions(); // createTextActions(); // createToolsActions(); @@ -138,9 +166,84 @@ void cMainWindow::closeEvent(QCloseEvent *event) else settings.setValue("main/maximized", QVariant::fromValue(false)); + QList sizes = ui->m_lpSplitter->sizes(); + + for(int x = 0;x < sizes.count();x++) + settings.setValue(QString("main/splitter%1").arg(x+1), QVariant::fromValue(sizes[x])); + event->accept(); } +void cMainWindow::createFileActions() +{ + m_lpFileMenu = menuBar()->addMenu(tr("&File")); + m_lpFileToolBar = addToolBar(tr("File Actions")); + + const QIcon newIcon = QIcon::fromTheme("document-new"); + m_lpFileNewAction = m_lpFileMenu->addAction(newIcon, tr("&New"), this, &cMainWindow::onFileNew); + m_lpFileToolBar->addAction(m_lpFileNewAction); + m_lpFileNewAction->setPriority(QAction::LowPriority); + m_lpFileNewAction->setShortcut(QKeySequence::New); + + const QIcon openIcon = QIcon::fromTheme("document-open"); + m_lpFileOpenAction = m_lpFileMenu->addAction(openIcon, tr("&Open..."), this, &cMainWindow::onFileOpen); + m_lpFileOpenAction->setShortcut(QKeySequence::Open); + m_lpFileToolBar->addAction(m_lpFileOpenAction); + + m_lpFileMenu->addSeparator(); + + m_lpFileImportAction = m_lpFileMenu->addAction(tr("&Import..."), this, &cMainWindow::onFileImport); + m_lpFileToolBar->addAction(m_lpFileImportAction); + + m_lpFileMenu->addSeparator(); + +// const QIcon saveIcon = QIcon::fromTheme("document-save"); +// m_lpFileSaveAction = m_lpFileMenu->addAction(saveIcon, tr("&Save"), this, &cMainWindow::onFileSave); +// m_lpFileSaveAction->setShortcut(QKeySequence::Save); +// m_lpFileSaveAction->setEnabled(false); +// m_lpFileToolBar->addAction(m_lpFileSaveAction); + +// m_lpFileSaveAsAction = m_lpFileMenu->addAction(tr("Save &As..."), this, &cMainWindow::onFileSaveAs); +// m_lpFileSaveAsAction->setPriority(QAction::LowPriority); +// m_lpFileMenu->addSeparator(); + +//#ifndef QT_NO_PRINTER +// const QIcon printIcon = QIcon::fromTheme("document-print"); +// m_lpFilePrintAction = m_lpFileMenu->addAction(printIcon, tr("&Print..."), this, &cMainWindow::onFilePrint); +// m_lpFilePrintAction->setPriority(QAction::LowPriority); +// m_lpFilePrintAction->setShortcut(QKeySequence::Print); +// m_lpFileToolBar->addAction(m_lpFilePrintAction); + +// const QIcon filePrintIcon = QIcon::fromTheme("document-print"); +// m_lpFilePrintPreviewAction = m_lpFileMenu->addAction(filePrintIcon, tr("Print Preview..."), this, &cMainWindow::onFilePrintPreview); + +// const QIcon exportPdfIcon = QIcon::fromTheme("document-pdf"); +// m_lpFileExportPDFAction = m_lpFileMenu->addAction(exportPdfIcon, tr("&Export PDF..."), this, &cMainWindow::onFilePrintPdf); +// m_lpFileExportPDFAction->setPriority(QAction::LowPriority); +// m_lpFileExportPDFAction->setShortcut(Qt::CTRL + Qt::Key_D); +// m_lpFileToolBar->addAction(m_lpFileExportPDFAction); + +// m_lpFileMenu->addSeparator(); +//#endif + +// m_lpFilePropertiesAction = m_lpFileMenu->addAction(tr("P&roperties..."), this, &cMainWindow::onFileProperties); +// m_lpFilePropertiesAction->setPriority(QAction::LowPriority); +// m_lpFileMenu->addSeparator(); + + for(int i = 0; i < MaxRecentFiles;i++) + { + m_lpRecentFileAction[i] = new QAction(this); + m_lpRecentFileAction[i]->setVisible(false); + m_lpFileMenu->addAction(m_lpRecentFileAction[i]); + connect(m_lpRecentFileAction[i], &QAction::triggered, this, &cMainWindow::openRecentFile); + } + m_lpSeparatorRecent = m_lpFileMenu->addSeparator(); + m_lpSeparatorRecent->setVisible(false); + + m_lpFileQuitAction = m_lpFileMenu->addAction(tr("&Quit"), this, &QWidget::close); + m_lpFileQuitAction->setShortcut(Qt::CTRL + Qt::Key_Q); +} + void cMainWindow::onThumbnailSelected(const QItemSelection& /*selection*/, const QItemSelection& /*previous*/) { cToolBoxInfo* lpToolBoxInfo = static_cast(ui->m_lpToolBox->widget(0)); @@ -155,3 +258,183 @@ void cMainWindow::onThumbnailSelected(const QItemSelection& /*selection*/, const cPicture* lpPicture = lpItem->data().value(); lpToolBoxInfo->setPicture(lpPicture); } + +void cMainWindow::setCurrentFile(const QString& fileName) +{ + QSettings settings; + QStringList files = settings.value("file/recentFiles").toStringList(); + files.removeAll(fileName); + files.prepend(fileName); + while(files.size() > MaxRecentFiles) + files.removeLast(); + + settings.setValue("file/recentFiles", files); + + updateRecentFileActions(); +} + +void cMainWindow::updateRecentFileActions() +{ + QSettings settings; + QStringList files = settings.value("file/recentFiles").toStringList(); + + int numRecentFiles = qMin(files.size(), (int)MaxRecentFiles); + + for(int i = 0; i < numRecentFiles; i++) + { + QString text = tr("&%1 %2").arg(i + 1).arg(QFileInfo(files[i]).fileName()); + m_lpRecentFileAction[i]->setText(text); + m_lpRecentFileAction[i]->setData(files[i]); + m_lpRecentFileAction[i]->setVisible(true); + } + + for(int j = numRecentFiles; j < MaxRecentFiles; j++) + m_lpRecentFileAction[j]->setVisible(false); + + m_lpSeparatorRecent->setVisible(numRecentFiles > 0); +} + +void cMainWindow::openRecentFile() +{ + QAction* lpAction = qobject_cast(sender()); + if(lpAction) + { +// if(m_lpStoryBook) +// { +// if(m_bSomethingChanged) +// { +// switch(QMessageBox::question(this, tr("Save"), m_lpStoryBook->title() + tr(" has been changed.\nDo you want to save?"), QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel)) +// { +// case QMessageBox::Yes: +// if(!onFileSave()) +// return; +// break; +// case QMessageBox::No: +// break; +// case QMessageBox::Cancel: +// return; +// default: +// return; +// } +// } +// } + +// QString szProjectName = lpAction->data().toString(); +// if(szProjectName.isEmpty()) +// return; + +// delete m_lpStoryBook; + +// m_lpStoryBook = new cStoryBook(szProjectName); + +// m_lpStoryBook->fillOutlineList(ui->m_lpOutlineList); +// m_lpStoryBook->fillCharacterList(ui->m_lpCharacterList); +// m_lpStoryBook->fillPlaceList(ui->m_lpPlaceList); +// m_lpStoryBook->fillObjectList(ui->m_lpObjectList); +// m_lpStoryBook->fillRechercheList(ui->m_lpRechercheList); + +// setCurrentFile(szProjectName); +// updateWindowTitle(); + } +} +void cMainWindow::onFileNew() +{ +// if(m_bSomethingChanged) +// { +// switch(QMessageBox::question(this, tr("Save"), m_lpStoryBook->title() + tr(" has been changed.\nDo you want to save?"), QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel)) +// { +// case QMessageBox::Yes: +// if(!onFileSave()) +// return; +// break; +// case QMessageBox::No: +// break; +// case QMessageBox::Cancel: +// return; +// default: +// return; +// } +// } + +// ui->m_lpMdiArea->closeAllSubWindows(); + +// if(m_lpStoryBook) +// delete m_lpStoryBook; + +// m_lpStoryBook = new cStoryBook; + +// m_lpStoryBook->fillOutlineList(ui->m_lpOutlineList); +// m_lpStoryBook->fillCharacterList(ui->m_lpCharacterList); +// m_lpStoryBook->fillPlaceList(ui->m_lpPlaceList); +// m_lpStoryBook->fillObjectList(ui->m_lpObjectList); +// m_lpStoryBook->fillRechercheList(ui->m_lpRechercheList); + +// updateWindowTitle(); +} + +void cMainWindow::onFileOpen() +{ +// if(m_lpStoryBook) +// { +// if(m_bSomethingChanged) +// { +// switch(QMessageBox::question(this, tr("Save"), m_lpStoryBook->title() + tr(" has been changed.\nDo you want to save?"), QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel)) +// { +// case QMessageBox::Yes: +// if(!onFileSave()) +// return; +// break; +// case QMessageBox::No: +// break; +// case QMessageBox::Cancel: +// return; +// default: +// return; +// } +// } +// } + +// QString szProjectName = getProjectLoadName(); +// if(szProjectName.isEmpty()) +// return; + +// ui->m_lpMdiArea->closeAllSubWindows(); + +// if(m_lpStoryBook) +// delete m_lpStoryBook; + +// m_lpStoryBook = new cStoryBook(szProjectName); + +// m_lpStoryBook->fillOutlineList(ui->m_lpOutlineList); +// m_lpStoryBook->fillCharacterList(ui->m_lpCharacterList); +// m_lpStoryBook->fillPlaceList(ui->m_lpPlaceList); +// m_lpStoryBook->fillObjectList(ui->m_lpObjectList); +// m_lpStoryBook->fillRechercheList(ui->m_lpRechercheList); + +// setCurrentFile(szProjectName); +// updateWindowTitle(); +} + +void cMainWindow::onFileImport() +{ + cImportDialog importDialog(this); + + QSettings settings; + qint32 iX = settings.value("import/x", QVariant::fromValue(-1)).toInt(); + qint32 iY = settings.value("import/y", QVariant::fromValue(-1)).toInt(); + qint32 iWidth = settings.value("import/width", QVariant::fromValue(-1)).toInt(); + qint32 iHeight = settings.value("import/height", QVariant::fromValue(-1)).toInt(); + + if(iX != -1 && iY != -1) + importDialog.move(iX, iY); + if(iWidth != -1 && iHeight != -1) + importDialog.resize(iWidth, iHeight); + + if(importDialog.exec() == QDialog::Rejected) + return; + + settings.setValue("import/width", QVariant::fromValue(importDialog.size().width())); + settings.setValue("import/height", QVariant::fromValue(importDialog.size().height())); + settings.setValue("import/x", QVariant::fromValue(importDialog.x())); + settings.setValue("import/y", QVariant::fromValue(importDialog.y())); +} diff --git a/cmainwindow.h b/cmainwindow.h index a95fd6f..f08e11b 100644 --- a/cmainwindow.h +++ b/cmainwindow.h @@ -14,6 +14,9 @@ #include #include +#include +#include + namespace Ui { class cMainWindow; @@ -48,6 +51,19 @@ private: cPictureLibrary m_pictureLibrary; /**< TODO: describe */ cPictureList m_pictureList; /**< TODO: describe */ + QMenu* m_lpFileMenu; /*!< Pointer to the file menu */ + + QToolBar* m_lpFileToolBar; /*!< Pointer to the file toolbar */ + + QAction* m_lpFileNewAction; /*!< TODO: describe */ + QAction* m_lpFileOpenAction; /*!< TODO: describe */ + QAction* m_lpFileImportAction; /*!< TODO: describe */ + QAction* m_lpFileQuitAction; /*!< TODO: describe */ + + QAction* m_lpSeparatorRecent; /*!< TODO: describe */ + enum { MaxRecentFiles = 5 }; /*!< TODO: describe */ + QAction* m_lpRecentFileAction[MaxRecentFiles]; /*!< TODO: describe */ + /*! \brief @@ -60,6 +76,33 @@ private: \fn createActions */ void createActions(); + /*! + \brief + + \fn createFileActions + */ + void createFileActions(); + + /*! + \brief + + \fn setCurrentFile + \param szFileName + */ + void setCurrentFile(const QString& szFileName); + /*! + \brief + + \fn updateRecentFileActions + */ + void updateRecentFileActions(); + /*! + \brief + + \fn openRecentFile + */ + void openRecentFile(); + /*! \brief @@ -77,7 +120,31 @@ protected: void closeEvent(QCloseEvent* event); private slots: + /*! + \brief + \param selection + \param previous + \fn onThumbnailSelected + */ void onThumbnailSelected(const QItemSelection& selection, const QItemSelection& previous); + /*! + \brief + + \fn onFileNew + */ + void onFileNew(); + /*! + \brief + + \fn onFileOpen + */ + void onFileOpen(); + /*! + \brief + + \fn onFileImport + */ + void onFileImport(); }; #endif // CMAINWINDOW_H diff --git a/cpicturelibrary.h b/cpicturelibrary.h index a125406..2c98256 100644 --- a/cpicturelibrary.h +++ b/cpicturelibrary.h @@ -35,7 +35,7 @@ public: \fn rootPath \return QString */ - QString rootPath(); + QString rootPath(); /*! \brief diff --git a/pictureLibrary.pro b/pictureLibrary.pro index 76f8d85..0460570 100644 --- a/pictureLibrary.pro +++ b/pictureLibrary.pro @@ -33,7 +33,7 @@ win32-g++ { unix { message("*nix") - -lraw -lexiv2 + LIBS += -lraw -lexiv2 } QMAKE_CXXFLAGS += -DLIBRAW_NODLL -DLIBRAW_NOTHREADS @@ -61,7 +61,8 @@ SOURCES += \ cpicturelibrary.cpp \ cpicture.cpp \ cimage.cpp \ - ctoolboxinfo.cpp + ctoolboxinfo.cpp \ + cimportdialog.cpp HEADERS += \ cmainwindow.h \ @@ -71,11 +72,13 @@ HEADERS += \ cpicturelibrary.h \ cpicture.h \ cimage.h \ - ctoolboxinfo.h + ctoolboxinfo.h \ + cimportdialog.h FORMS += \ cmainwindow.ui \ - ctoolboxinfo.ui + ctoolboxinfo.ui \ + cimportdialog.ui # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin