open file, recent file

This commit is contained in:
2019-03-12 16:06:42 +01:00
parent aa5dbe9324
commit d9b79fa977
10 changed files with 168 additions and 132 deletions
+117 -125
View File
@@ -30,6 +30,7 @@
#include <QIcon>
#include <QPixmap>
#include <QInputDialog>
#include <QFileDialog>
cMainWindow::cMainWindow(cSplashScreen* lpSplashScreen, QWidget *parent) :
@@ -48,7 +49,12 @@ cMainWindow::cMainWindow(cSplashScreen* lpSplashScreen, QWidget *parent) :
{
initUI();
createActions();
loadData();
// onFileNew();
QSettings settings;
m_szOldPath = settings.value("file/lastPath", QDir::homePath()).toString();
m_pictureLibrary.openDatabase(m_szOldPath);
loadData(true);
updateRecentFileActions();
}
@@ -67,6 +73,8 @@ void cMainWindow::initUI()
{
ui->setupUi(this);
QIcon::setThemeName("TangoMFK");
m_lpFolderViewModel = new QStandardItemModel;
m_lpFolderSortFilterProxyModel = new cFolderSortFilterProxyModel(this);
ui->m_lpFolderView->setModel(m_lpFolderSortFilterProxyModel);
@@ -145,21 +153,77 @@ void cMainWindow::createContextActions()
connect(m_lpUnsetHDRAction, &QAction::triggered, this, &cMainWindow::onUnsetHDR);
}
void cMainWindow::closeEvent(QCloseEvent *event)
{
QSettings settings;
settings.setValue("main/width", QVariant::fromValue(size().width()));
settings.setValue("main/height", QVariant::fromValue(size().height()));
settings.setValue("main/x", QVariant::fromValue(x()));
settings.setValue("main/y", QVariant::fromValue(y()));
if(this->isMaximized())
settings.setValue("main/maximized", QVariant::fromValue(true));
else
settings.setValue("main/maximized", QVariant::fromValue(false));
QList<qint32> 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_lpFileSaveAsAction = m_lpFileMenu->addAction(tr("Save &As..."), this, &cMainWindow::onFileSaveAs);
m_lpFileSaveAsAction->setPriority(QAction::LowPriority);
m_lpFileMenu->addSeparator();
m_lpFileImportAction = m_lpFileMenu->addAction(tr("&Import..."), this, &cMainWindow::onFileImport);
m_lpFileToolBar->addAction(m_lpFileImportAction);
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::loadData(bool bProgressBar)
{
m_bLoading = true;
m_personList.clear();
m_personList.load(m_lpSplashScreen, bProgressBar ? m_lpProgressBar : nullptr);
ui->m_lpToolBoxPerson->setPersonList(&m_personList);
m_locationList.clear();
m_locationList.load(m_lpSplashScreen, bProgressBar ? m_lpProgressBar : nullptr);
ui->m_lpToolBoxLocation->setLocationList(&m_locationList);
m_tagList.clear();
m_tagList.load(m_lpSplashScreen, bProgressBar ? m_lpProgressBar : nullptr);
ui->m_lpToolBoxTags->setTagList(&m_tagList);
m_pictureList.clear();
m_pictureList.load(m_personList, m_locationList, m_tagList, m_lpSplashScreen, bProgressBar ? m_lpProgressBar : nullptr);
@@ -173,9 +237,17 @@ void cMainWindow::displayData()
{
m_lpThumbnailViewModel->clear();
m_lpFolderViewModel->clear();
ui->m_lpToolBoxPerson->clearPersonList();
ui->m_lpToolBoxLocation->clearLocationList();
ui->m_lpToolBoxTags->clearTagList();
ui->m_lpStatusBar->showMessage(tr("refreshing..."));
qApp->processEvents();
ui->m_lpToolBoxPerson->setPersonList(&m_personList);
ui->m_lpToolBoxLocation->setLocationList(&m_locationList);
ui->m_lpToolBoxTags->setTagList(&m_tagList);
m_lpRootItem = new QStandardItem("library");
m_lpFolderViewModel->appendRow(m_lpRootItem);
@@ -298,63 +370,6 @@ void cMainWindow::cleanFolderTree(const QString& folder)
}
}
void cMainWindow::closeEvent(QCloseEvent *event)
{
QSettings settings;
settings.setValue("main/width", QVariant::fromValue(size().width()));
settings.setValue("main/height", QVariant::fromValue(size().height()));
settings.setValue("main/x", QVariant::fromValue(x()));
settings.setValue("main/y", QVariant::fromValue(y()));
if(this->isMaximized())
settings.setValue("main/maximized", QVariant::fromValue(true));
else
settings.setValue("main/maximized", QVariant::fromValue(false));
QList<qint32> 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();
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*/)
{
cPictureList pictureList;
@@ -449,42 +464,21 @@ void cMainWindow::openRecentFile()
QAction* lpAction = qobject_cast<QAction*>(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;
// }
// }
// }
QSettings settings;
QString szPath = lpAction->data().toString();
if(szPath.isEmpty())
return;
// QString szProjectName = lpAction->data().toString();
// if(szProjectName.isEmpty())
// return;
if(!m_pictureLibrary.openDatabase(szPath))
return;
// delete m_lpStoryBook;
loadData(true);
// m_lpStoryBook = new cStoryBook(szProjectName);
setCurrentFile(szPath);
m_szOldPath = szPath;
settings.setValue("file/lastPath", QVariant::fromValue(m_szOldPath));
// 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();
// updateWindowTitle();
}
}
@@ -525,45 +519,43 @@ void cMainWindow::onFileNew()
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;
// }
// }
// }
QSettings settings;
QString szPath = settings.value("file/lastPath", QDir::homePath()).toString();
szPath = QFileDialog::getExistingDirectory(this, tr("Open Database"), szPath, QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
// QString szProjectName = getProjectLoadName();
if(szPath.isEmpty())
return;
if(!m_pictureLibrary.openDatabase(szPath))
return;
loadData(m_lpProgressBar);
setCurrentFile(szPath);
m_szOldPath = szPath;
settings.setValue("file/lastPath", QVariant::fromValue(m_szOldPath));
// updateWindowTitle();
}
bool cMainWindow::onFileSaveAs()
{
// QString szProjectName = getProjectSaveName();
// if(szProjectName.isEmpty())
// return;
// return(false);
// ui->m_lpMdiArea->closeAllSubWindows();
// QFile file(szProjectName);
// if(file.exists())
// file.remove();
// 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);
// if(!m_lpStoryBook->saveAs(szProjectName))
// return(false);
// m_bSomethingChanged = false;
// setCurrentFile(szProjectName);
// updateWindowTitle();
return(true);
}
void cMainWindow::onFileImport()
+10
View File
@@ -80,12 +80,15 @@ private:
cLocationList m_locationList; /*!< TODO: describe */
cTagList m_tagList; /*!< TODO: describe */
QString m_szOldPath; /*!< TODO: describe */
QMenu* m_lpFileMenu; /*!< TODO: describe */
QToolBar* m_lpFileToolBar; /*!< TODO: describe */
QAction* m_lpFileNewAction; /*!< TODO: describe */
QAction* m_lpFileOpenAction; /*!< TODO: describe */
QAction* m_lpFileSaveAsAction; /*!< TODO: describe */
QAction* m_lpFileImportAction; /*!< TODO: describe */
QAction* m_lpFileQuitAction; /*!< TODO: describe */
@@ -215,6 +218,13 @@ private slots:
/*!
\brief
\fn onFileSaveAs
\return bool
*/
bool onFileSaveAs();
/*!
\brief
\fn onFileImport
*/
void onFileImport();
+7 -6
View File
@@ -16,16 +16,15 @@
cPictureLibrary::cPictureLibrary(QObject *parent) : QObject(parent)
{
if(!openDatabase())
return;
}
bool cPictureLibrary::openDatabase()
bool cPictureLibrary::openDatabase(const QString& szPath)
{
QSettings settings;
m_szRootPath = settings.value("database/rootPath", QDir::homePath()).toString();
if(m_db.isOpen())
m_db.close();
QString szDB = m_szRootPath + "/" + "pictureLibrary.db";
m_szRootPath = "";
QString szDB = szPath + "/" + "pictureLibrary.db";
m_db = QSqlDatabase::addDatabase("QSQLITE");
m_db.setHostName("localhost");
@@ -56,6 +55,8 @@ bool cPictureLibrary::openDatabase()
query.finish();
}
m_szRootPath = szPath;
return(true);
}
+1 -1
View File
@@ -35,7 +35,7 @@ public:
\fn openDatabase
\return bool
*/
bool openDatabase();
bool openDatabase(const QString& szPath);
/*!
\brief
+5
View File
@@ -59,6 +59,11 @@ void cToolBoxLocation::createActions()
connect(m_lpLocationListModel, &QStandardItemModel::itemChanged, this, &cToolBoxLocation::onLocationChanged);
}
void cToolBoxLocation::clearLocationList()
{
m_lpLocationListModel->clear();
}
void cToolBoxLocation::setLocationList(cLocationList* lpLocationList)
{
m_bLoading = true;
+6
View File
@@ -43,6 +43,12 @@ public:
*/
~cToolBoxLocation();
/*!
\brief
\fn clearLocationList
*/
void clearLocationList();
/*!
\brief
+5
View File
@@ -64,6 +64,11 @@ void cToolBoxPerson::createActions()
connect(m_lpPersonListModel, &QStandardItemModel::itemChanged, this, &cToolBoxPerson::onPersonChanged);
}
void cToolBoxPerson::clearPersonList()
{
m_lpPersonListModel->clear();
}
void cToolBoxPerson::setPersonList(cPersonList* lpPersonList)
{
m_bLoading = true;
+6
View File
@@ -43,6 +43,12 @@ public:
*/
~cToolBoxPerson();
/*!
\brief
\fn clearPersonList
*/
void clearPersonList();
/*!
\brief
+5
View File
@@ -64,6 +64,11 @@ void cToolBoxTag::createActions()
connect(m_lpTagListModel, &QStandardItemModel::itemChanged, this, &cToolBoxTag::onTagChanged);
}
void cToolBoxTag::clearTagList()
{
m_lpTagListModel->clear();
}
void cToolBoxTag::setTagList(cTagList* lpTagList)
{
m_bLoading = true;
+6
View File
@@ -43,6 +43,12 @@ public:
*/
~cToolBoxTag();
/*!
\brief
\fn clearTagList
*/
void clearTagList();
/*!
\brief