andre@0: /* Copyright (C) 2014 by Intevation GmbH andre@0: * andre@0: * This file is Free Software under the GNU GPL (v>=2) andre@0: * and comes with ABSOLUTELY NO WARRANTY! andre@0: * See LICENSE.txt for details. andre@0: */ andre@0: andre@0: /** @file See mainwindow.h */ andre@0: #include "mainwindow.h" andre@0: andre@0: #include "constants.h" andre@2: #include "metadataview.h" andre@2: #include "pngplayer.h" andre@0: andre@0: #include andre@0: #include andre@0: #include andre@0: #include andre@0: #include andre@0: #include andre@0: #include andre@0: #include andre@0: #include andre@0: #include andre@0: #include andre@0: #include andre@0: #include andre@0: #include andre@0: #include andre@0: #include andre@0: #include andre@0: #include andre@2: #include andre@2: #include andre@0: andre@0: MainWindow::MainWindow() : andre@2: mDataView(NULL) { andre@0: setStatusBar(new QStatusBar()); andre@3: //resize(1190, 500); andre@0: andre@0: setupGUI(); andre@0: readSettings(); andre@0: setAcceptDrops(true); andre@0: //QIcon windowIcon = QIcon(":/icon-64.png"); andre@0: //setWindowIcon(windowIcon); andre@0: andre@0: } andre@0: andre@2: void MainWindow::setupGUI() { andre@2: QTabWidget *tabWidget = new QTabWidget; andre@2: mDataView = new MetaDataView(this); andre@2: mPlayer = new PNGPlayer(this); andre@2: andre@2: tabWidget->addTab(mPlayer, tr("Player")); andre@2: tabWidget->addTab(mDataView, tr("Filter/Details")); andre@2: tabWidget->setMovable(true); andre@2: andre@2: setCentralWidget(tabWidget); andre@2: andre@2: connect (mPlayer, &PNGPlayer::error, this, &MainWindow::showErrorMessage); andre@2: connect (mPlayer, &PNGPlayer::advance, mDataView, &MetaDataView::selectNextRow); andre@3: connect (mPlayer, &PNGPlayer::back, mDataView, &MetaDataView::selectPrevRow); andre@3: connect (mPlayer, &PNGPlayer::jumpToFrame, mDataView, &MetaDataView::selectRow); andre@2: connect (mDataView, &MetaDataView::selectionChanged, mPlayer, andre@2: &PNGPlayer::showPicture); andre@3: mPlayer->setSpeed(mSettings.value(REPLAY_SPEED_KEY, REPLAY_SPEED_DEFAULT).toInt()); andre@0: } andre@0: andre@0: void MainWindow::showErrorMessage(const QString& errMsg) { andre@0: QMessageBox::warning(this, tr("Error!"), errMsg); andre@0: statusBar()->showMessage(errMsg); andre@0: } andre@0: andre@0: void MainWindow::closeEvent(QCloseEvent *event) { andre@0: mSettings.setValue("geometry", saveGeometry()); andre@0: mSettings.setValue("windowState", saveState()); andre@0: QMainWindow::closeEvent(event); andre@0: } andre@0: andre@0: void MainWindow::readSettings() { andre@0: restoreGeometry(mSettings.value("geometry").toByteArray()); andre@0: restoreState(mSettings.value("windowState").toByteArray()); andre@0: } andre@2: /* andre@0: void MainWindow::dragEnterEvent(QDragEnterEvent *event) andre@0: { andre@0: if (event->mimeData()->hasUrls()) { andre@0: foreach (const QUrl & url, event->mimeData()->urls()) { andre@0: if (url.isLocalFile()) { andre@0: event->acceptProposedAction(); andre@0: return; andre@0: } andre@0: } andre@0: } andre@0: } andre@0: andre@0: void MainWindow::dragMoveEvent(QDragMoveEvent *event) andre@0: { andre@0: if (event->mimeData()->hasUrls()) { andre@0: foreach (const QUrl & url, event->mimeData()->urls()) { andre@0: if (url.isLocalFile()) { andre@0: event->acceptProposedAction(); andre@0: return; andre@0: } andre@0: } andre@0: } andre@0: } andre@0: andre@0: void MainWindow::dropEvent(QDropEvent *event) andre@0: { andre@0: const QMimeData *mimeData = event->mimeData(); andre@0: andre@0: if (mimeData->hasUrls()) { andre@0: foreach (const QUrl & url, mimeData->urls()) { andre@0: if (!url.isLocalFile()) { andre@0: qDebug() << "Ignoring drop of " << url; andre@0: continue; andre@0: } andre@0: } andre@0: } andre@0: } andre@0: andre@0: void MainWindow::dragLeaveEvent(QDragLeaveEvent *event) andre@0: { andre@0: event->accept(); andre@0: } andre@2: */ andre@0: void MainWindow::setFolder(const QString& folder) andre@0: { andre@0: QFileInfo fi(folder); andre@0: if (!fi.isDir() || !fi.isReadable()) { andre@0: showErrorMessage(tr("Failed to access directory: '%1'").arg(folder)); andre@0: } andre@0: QDir dir = QDir(folder); andre@2: QFileInfo metaData = dir.absoluteFilePath("metadata.csv"); andre@2: if (!metaData.exists() || !metaData.isReadable()) { andre@2: showErrorMessage(tr("Failed to access meta data file: '%1'").arg( andre@2: metaData.filePath())); andre@0: andre@2: } andre@2: QString errorMsg = mDataView->parseMetaData(metaData.filePath()); andre@2: if (!errorMsg.isEmpty()) { andre@2: showErrorMessage(errorMsg); andre@2: return; andre@2: } andre@2: statusBar()->showMessage(tr("Parsed: '%1'").arg(metaData.filePath())); andre@2: qDebug() << "Parsed: " << metaData.filePath(); andre@2: mCurFolder = folder; andre@2: mPlayer->setBaseDir(folder); andre@3: mDataView->selectNextRow(); andre@0: }