/* This file is a part of Calyp project * Copyright (C) 2014-2021 by Joao Carreira (jfmcarreira@gmail.com) * Luis Lucas (luisfrlucas@gmail.com) * Joao Santos (joaompssantos@gmail.com) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ /** * \file MainWindow.cpp * \brief Definition of the main window */ #include "MainWindow.h" #include #include #include #include #include #include #include #include #include #include "AboutDialog.h" #include "ConfigureFormatDialog.h" #include "ModulesHandle.h" #include "QualityHandle.h" #include "SubWindowAbstract.h" #include "SubWindowHandle.h" #include "SubWindowSelectorDialog.h" #include "VideoHandle.h" #include "VideoSubWindow.h" #include "lib/CalypOptions.h" #include "models/VideostreamResource.h" #ifdef USE_FERVOR #include "fvupdater.h" #endif MainWindow::MainWindow() { setWindowModality( Qt::ApplicationModal ); setWindowModality( Qt::NonModal ); // DBus #ifdef USE_QTDBUS m_pDBusAdaptor = new DBusAppAdaptor( this ); #endif m_appResourceHandle = std::make_unique(); m_pcWindowHandle = new SubWindowHandle( this ); m_appModuleVideo = new VideoHandle( this, m_pcWindowHandle ); m_appModuleQuality = new QualityHandle( this, m_pcWindowHandle ); m_appModuleExtensions = new ModulesHandle( this, m_pcWindowHandle, m_appModuleVideo ); createActions(); createToolBars(); createDockWidgets(); createMenus(); createStatusBar(); updateMenus(); readSettings(); setWindowTitle( QApplication::applicationName() ); setWindowIcon( QIcon( ":logos/calyp-icon.png" ) ); setUnifiedTitleAndToolBarOnMac( true ); setCentralWidget( m_pcWindowHandle->getWidget() ); setAcceptDrops( true ); setBackgroundRole( QPalette::Window ); connect( m_pcWindowHandle, &SubWindowHandle::windowActivated, this, &MainWindow::updateMainWindow ); connect( m_pcWindowHandle, &SubWindowHandle::changed, this, &MainWindow::updateMainWindow, Qt::QueuedConnection ); connect( m_appModuleVideo, &VideoHandle::changed, this, &MainWindow::updateMainWindow, Qt::QueuedConnection ); connect( m_appModuleQuality, &QualityHandle::changed, this, &MainWindow::updateMainWindow, Qt::QueuedConnection ); connect( m_appModuleExtensions, &ModulesHandle::changed, this, &MainWindow::updateMainWindow, Qt::QueuedConnection ); } bool MainWindow::parseArgs( int argc, char* argv[] ) { bool bRet = false; CalypOptions pcCmdParser; std::vector m_apcInputs; std::string strResolution( "" ); std::string strPelFmt( "" ); pcCmdParser.addOptions() /**/ ( "input,i", m_apcInputs, "input file" ) /**/ ( "size,s", strResolution, "size (WxH)" ) /**/ ( "pel_fmt", strPelFmt, "pixel format" ); if( pcCmdParser.parse( argc, argv ) < 0 ) { bRet |= true; } if( pcCmdParser.hasOpt( "help" ) ) { printf( "Usage: %s [options] input_file[s]\n", argv[0] ); pcCmdParser.doHelp( std::cout ); bRet |= true; } if( pcCmdParser.hasOpt( "input" ) ) { for( unsigned int i = 1; i < m_apcInputs.size(); i++ ) { loadFile( QString::fromStdString( m_apcInputs[i] ) ); } } std::list& argv_unhandled = pcCmdParser.getUnhandledArgs(); for( std::list::const_iterator it = argv_unhandled.begin(); it != argv_unhandled.end(); it++ ) { loadFile( QString::fromStdString( *it ) ); } m_pcWindowHandle->tileSubWindows(); zoomToFitAll(); return bRet; } void MainWindow::about() { if( !m_pcAboutDialog ) m_pcAboutDialog = new AboutDialog( this ); m_pcAboutDialog->exec(); } void MainWindow::closeEvent( QCloseEvent* event ) { int mayCloseAll = true; int msgBoxCloseRet = QMessageBox::Yes; QList subWindowList = m_pcWindowHandle->findSubWindow(); if( subWindowList.size() >= 1 ) { QMessageBox msgBoxClose( QMessageBox::Question, "Calyp", "There are open files!", QMessageBox::Yes | QMessageBox::No, this ); msgBoxClose.setDefaultButton( QMessageBox::No ); msgBoxClose.setInformativeText( "Close all?" ); msgBoxCloseRet = msgBoxClose.exec(); } switch( msgBoxCloseRet ) { case QMessageBox::Yes: mayCloseAll = true; for( int i = 0; i < subWindowList.size(); i++ ) { mayCloseAll &= subWindowList.at( i )->mayClose(); } if( mayCloseAll ) { // m_pcPlayingTimer->stop(); closeAll(); writeSettings(); event->accept(); } else { event->ignore(); } break; case QMessageBox::No: default: event->ignore(); } } void MainWindow::closeAll() { m_pcWindowHandle->removeAllSubWindow(); } void MainWindow::loadFile( const CalypFileInfo& pStreamInfo ) { loadFile( pStreamInfo.m_cFilename, pStreamInfo ); } void MainWindow::loadFile( const QString& fileName, std::optional streamInfoOpt, bool forceDialog ) { qDebug() << fileName; if( !QFileInfo( fileName ).exists() ) { printMessage( "File " + fileName + " do not exist!", CLP_LOG_ERROR ); return; } if( auto* videoSubWindow = MainWindow::findVideoStreamSubWindow( m_pcWindowHandle, fileName ) ) { m_pcWindowHandle->setActiveSubWindow( videoSubWindow ); return; } if( !streamInfoOpt.has_value() ) { auto idx = findCalypStreamInfo( m_aRecentFileStreamInfo, fileName ); if( idx >= 0 ) streamInfoOpt = m_aRecentFileStreamInfo.at( idx ); } auto streamInfo = streamInfoOpt.has_value() ? *streamInfoOpt : CalypFileInfo{ .m_cFilename = fileName }; auto videoResource = std::make_unique(); bool opened = false; try { [[maybe_unused]] auto guessed = video_resource_guess_format( streamInfo.m_cFilename, streamInfo.m_uiWidth, streamInfo.m_uiHeight, streamInfo.m_iPelFormat, streamInfo.m_uiBitsPelPixel, streamInfo.m_iEndianness, streamInfo.m_uiFrameRate ); if( !forceDialog ) { opened = videoResource->loadFile( streamInfo, false ); } if( !opened ) { ConfigureFormatDialog formatDialog( this ); if( streamInfo.m_uiWidth == 0 ) { streamInfo.m_uiWidth = m_lastOpenWidth; } if( streamInfo.m_uiHeight == 0 ) { streamInfo.m_uiHeight = m_lastOpenHeight; } if( streamInfo.m_uiBitsPelPixel == 0 ) { streamInfo.m_uiBitsPelPixel = m_lastOpenBitPerPixel; } if( formatDialog.runConfigureFormatDialog( QFileInfo( streamInfo.m_cFilename ).fileName(), streamInfo.m_uiWidth, streamInfo.m_uiHeight, streamInfo.m_iPelFormat, streamInfo.m_uiBitsPelPixel, streamInfo.m_iEndianness, streamInfo.m_uiFrameRate ) != QDialog::Accepted ) { return; } opened = videoResource->loadFile( streamInfo, false ); } if( opened ) { const auto openedStreamInfo = videoResource->getStreamInfo(); auto resource_id = m_appResourceHandle->appendResource( std::move( videoResource ) ); auto* videoSubWindow = new VideoStreamSubWindow( m_appResourceHandle.get() ); // createSubWindow(); videoSubWindow->setResource( resource_id ); printMessage( "Loading file...", CLP_LOG_INFO ); m_pcWindowHandle->addSubWindow( videoSubWindow ); videoSubWindow->show(); m_appModuleVideo->addSubWindow( videoSubWindow ); updateZoomFactorSBox(); m_lastOpenPath = QFileInfo( openedStreamInfo.m_cFilename ).path(); m_lastOpenWidth = openedStreamInfo.m_uiWidth; m_lastOpenHeight = openedStreamInfo.m_uiHeight; m_lastOpenBitPerPixel = openedStreamInfo.m_uiBitsPelPixel; addStreamInfoToRecentList( std::move( openedStreamInfo ) ); printMessage( "File loaded", CLP_LOG_INFO ); } } catch( CalypFailure& e ) { QString warningMsg = "Cannot open file " + QFileInfo( fileName ).fileName() + " with the following error: \n" + e.what(); QMessageBox::warning( this, QApplication::applicationName(), warningMsg ); printMessage( warningMsg, CLP_LOG_ERROR ); } } // ----------------------- File Functions ----------------------- QStringList MainWindow::showFileDialog( bool bRead ) { QString supported = tr( "Supported Files (" ); QStringList formatsList; std::vector supportedFmts; if( bRead ) supportedFmts = CalypStream::supportedReadFormats(); else supportedFmts = CalypStream::supportedWriteFormats(); for( unsigned int i = 0; i < supportedFmts.size(); i++ ) { std::vector arrayExt = supportedFmts[i].getExts(); if( arrayExt.size() > 0 ) { QString currFmt( QString::fromStdString( supportedFmts[i].formatName ) ); currFmt.append( " (" ); for( std::vector::iterator e = arrayExt.begin(); e != arrayExt.end(); ++e ) { supported.append( " *." ); currFmt.append( "*." ); supported.append( QString::fromStdString( *e ) ); currFmt.append( QString::fromStdString( *e ) ); } currFmt.append( ")" ); formatsList << currFmt; } } supported.append( " )" ); QStringList filter; filter << supported << formatsList << tr( "All Files (*)" ); QStringList fileNameList; fileNameList.clear(); if( bRead ) { fileNameList = QFileDialog::getOpenFileNames( this, tr( "Open File" ), m_lastOpenPath, filter.join( ";;" ) ); } else { QString fileName = QFileDialog::getSaveFileName( this, tr( "Save File" ), m_lastOpenPath, filter.join( ";;" ) ); if( !fileName.isEmpty() ) fileNameList.append( fileName ); } return fileNameList; } void MainWindow::open() { QStringList fileNameList = showFileDialog( true ); for( int i = 0; i < fileNameList.size(); i++ ) { if( !fileNameList.at( i ).isEmpty() ) { loadFile( std::move( fileNameList.at( i ) ) ); } } } // void CalypApp::openDevice() //{ // loadFile( "/dev/video0", NULL ); //} void MainWindow::openRecent() { QAction* action = qobject_cast( sender() ); if( action ) { loadFile( action->data().value() ); } } void MainWindow::saveFrame() { auto* pcVideoSubWindow = m_pcWindowHandle->activeSubWindow(); if( pcVideoSubWindow != nullptr ) { QStringList fileNameList = showFileDialog( false ); if( fileNameList.size() == 1 ) { QString fileName = fileNameList[0]; m_lastOpenPath = QFileInfo( fileName ).path(); try { pcVideoSubWindow->save( fileName ); } catch( CalypFailure& e ) { QApplication::restoreOverrideCursor(); QString warningMsg = "Cannot save file " + QFileInfo( fileName ).fileName() + " with the following error: \n" + e.what(); QMessageBox::warning( this, QApplication::applicationName(), warningMsg ); printMessage( warningMsg, CLP_LOG_ERROR ); return; } } } } void MainWindow::saveStream() { auto* pcVideoSubWindow = m_pcWindowHandle->activeSubWindow(); if( pcVideoSubWindow != nullptr ) { QStringList fileNameList = showFileDialog( false ); if( fileNameList.size() == 1 ) { QString fileName = fileNameList[0]; m_lastOpenPath = QFileInfo( fileName ).path(); try { pcVideoSubWindow->save( fileName ); } catch( CalypFailure& e ) { QApplication::restoreOverrideCursor(); QString warningMsg = "Cannot save file " + QFileInfo( fileName ).fileName() + " with the following error: \n" + e.what(); QMessageBox::warning( this, QApplication::applicationName(), warningMsg ); printMessage( warningMsg, CLP_LOG_ERROR ); return; } } } } void MainWindow::format() { auto* pcVideoSubWindow = m_pcWindowHandle->activeSubWindow(); if( pcVideoSubWindow ) { try { auto resourceId = pcVideoSubWindow->getResourceId(); CalypFileInfo streamInfo; m_appResourceHandle->executeResourceAction( resourceId, [&streamInfo]( auto* resource ) { streamInfo = resource->getStreamInfo(); return true; } ); m_pcWindowHandle->removeSubWindow( pcVideoSubWindow ); loadFile( streamInfo.m_cFilename, streamInfo, true ); } catch( CalypFailure& e ) { QString warningMsg = "Cannot change format of " + QFileInfo( pcVideoSubWindow->getCurrentFileName() ).fileName() + " with the following error: \n" + e.what(); QMessageBox::warning( this, QApplication::applicationName(), warningMsg ); printMessage( warningMsg, CLP_LOG_ERROR ); qDebug() << warningMsg; } updateMainWindow(); } } void MainWindow::reload() { auto* activeSubWindow = m_pcWindowHandle->activeSubWindow(); if( activeSubWindow != nullptr ) { activeSubWindow->refreshSubWindow(); updateMainWindow(); } } void MainWindow::reloadAll() { unsigned int windowCategoryOrder[] = { SubWindowAbstract::VIDEO_STREAM_SUBWINDOW, SubWindowAbstract::MODULE_SUBWINDOW, SubWindowAbstract::MODULE_SUBWINDOW, }; for( unsigned int c = 0; c < 3; c++ ) { QList subWindowList = m_pcWindowHandle->findSubWindow( windowCategoryOrder[c] ); for( int i = 0; i < subWindowList.size(); i++ ) { subWindowList.at( i )->refreshSubWindow(); } } updateMainWindow(); } void MainWindow::loadAll() { auto* activeSubWindow = m_pcWindowHandle->activeSubWindow(); if( activeSubWindow != nullptr ) { printMessage( "Loading file into memory...", CLP_LOG_INFO ); activeSubWindow->loadAll(); printMessage( "File loaded", CLP_LOG_INFO ); } } // ----------------------- Zoom Functions ----------------------- void MainWindow::normalSize() { auto* activeSubWindow = m_pcWindowHandle->activeSubWindow(); if( activeSubWindow != nullptr ) { activeSubWindow->normalSize(); updateZoomFactorSBox(); } } void MainWindow::zoomToFit() { auto* activeSubWindow = m_pcWindowHandle->activeSubWindow(); if( activeSubWindow != nullptr ) { activeSubWindow->zoomToFit(); updateZoomFactorSBox(); } } void MainWindow::zoomToFitAll() { QList subWindowList = m_pcWindowHandle->findSubWindow( SubWindowAbstract::VIDEO_SUBWINDOW ); for( int i = 0; i < subWindowList.size(); i++ ) { auto* videoSubWindow = qobject_cast( subWindowList.at( i ) ); videoSubWindow->zoomToFit(); } auto* activeSubWindow = m_pcWindowHandle->activeSubWindow(); if( activeSubWindow != nullptr ) { updateZoomFactorSBox(); } } void MainWindow::scaleFrame( int ratio ) { auto* activeSubWindow = m_pcWindowHandle->activeSubWindow(); if( activeSubWindow != nullptr ) { activeSubWindow->scaleView( (double)( ratio ) / 100.0 ); updateZoomFactorSBox(); } } void MainWindow::zoomFromSBox( double zoom ) { SubWindowAbstract* activeSubWindow = m_pcWindowHandle->activeSubWindow(); double factor = zoom / 100; if( activeSubWindow ) { activeSubWindow->zoomToFactor( factor ); } } void MainWindow::updateZoomFactorSBox() { auto* activeSubWindow = m_pcWindowHandle->activeSubWindow(); if( activeSubWindow != nullptr ) { auto factor = activeSubWindow->getScaleFactor(); m_pcZoomFactorSBox->setValue( factor * 100 ); } } // ----------------------- Drag and drop functions ---------------------- void MainWindow::dragEnterEvent( QDragEnterEvent* event ) { // setText(tr("")); // mdiArea->setBackgroundRole( QPalette::Highlight ); event->acceptProposedAction(); } void MainWindow::dropEvent( QDropEvent* event ) { const QMimeData* mimeData = event->mimeData(); QList urlList = mimeData->urls(); if( urlList.size() == 1 ) { QString fileName = urlList.at( 0 ).toLocalFile(); m_lastOpenPath = QFileInfo( fileName ).path(); loadFile( fileName ); } } // ----------------------- Sub Window Functions ----------------------- VideoStreamSubWindow* MainWindow::findVideoStreamSubWindow( const SubWindowHandle* windowManager, const QString& fileName ) { QString canonicalFilePath = QFileInfo( fileName ).canonicalFilePath(); QList subWindowList = windowManager->findSubWindow( SubWindowAbstract::VIDEO_STREAM_SUBWINDOW ); for( int i = 0; i < subWindowList.size(); i++ ) { auto* pcSubWindow = qobject_cast( subWindowList.at( i ) ); if( pcSubWindow->getCurrentFileName() == canonicalFilePath ) return pcSubWindow; } return nullptr; } // ----------------------- Update Functions ----------------------- void MainWindow::updateMainWindow() { auto* activeSubWindow = m_pcWindowHandle->activeSubWindow(); auto* activeVideoSubWindow = qobject_cast( activeSubWindow ); QCoreApplication::processEvents(); // if( activeSubWindow() != m_pcCurrentSubWindow ) { if( activeSubWindow ) { if( activeVideoSubWindow != nullptr && !m_pcWindowHandle->findSubWindow( activeVideoSubWindow->getRefSubWindow() ) ) { activeVideoSubWindow->setRefSubWindow( nullptr ); } updateZoomFactorSBox(); } } //! Check this - these two function should swap order m_appModuleQuality->update( activeVideoSubWindow ); m_appModuleVideo->update( activeVideoSubWindow ); updateMenus(); } void MainWindow::printMessage( const QString& msg ) { printMessage( msg, 0 ); } void MainWindow::printMessage( const QString& msg, unsigned int logLevel ) { if( !msg.isEmpty() ) { statusBar()->showMessage( msg, 10000 ); if( logLevel >= CLP_LOG_INFO ) { m_pcWindowHandle->processLogMsg( msg ); } } } void MainWindow::updateMenus() { bool hasSubWindow = ( m_pcWindowHandle->activeSubWindow() != 0 ); bool hasVideoStreamSubWindow{ false }; bool supportsFormat{ false }; auto* pcVideoSubWindow = m_pcWindowHandle->activeSubWindow(); if( pcVideoSubWindow != nullptr && pcVideoSubWindow->getCategory() & SubWindowAbstract::VIDEO_STREAM_SUBWINDOW ) { hasVideoStreamSubWindow = true; supportsFormat = pcVideoSubWindow->supportsFormatConfiguration(); } m_arrayMenu[RECENT_MENU]->setEnabled( m_aRecentFileStreamInfo.size() > 0 ? true : false ); m_arrayActions[SAVE_ACT]->setEnabled( hasSubWindow ); m_arrayActions[CLOSE_ACT]->setEnabled( hasSubWindow ); m_arrayActions[CLOSEALL_ACT]->setEnabled( hasSubWindow ); m_arrayActions[RELOAD_ACT]->setEnabled( hasSubWindow ); m_arrayActions[RELOAD_ALL_ACT]->setEnabled( hasSubWindow ); m_arrayActions[FORMAT_ACT]->setEnabled( supportsFormat ); m_arrayActions[LOAD_ALL_ACT]->setEnabled( hasVideoStreamSubWindow ); m_arrayActions[ZOOM_IN_ACT]->setEnabled( hasSubWindow ); m_arrayActions[ZOOM_OUT_ACT]->setEnabled( hasSubWindow ); m_arrayActions[ZOOM_NORMAL_ACT]->setEnabled( hasSubWindow ); m_arrayActions[ZOOM_FIT_ACT]->setEnabled( hasSubWindow ); m_arrayActions[ZOOM_FIT_ALL_ACT]->setEnabled( hasSubWindow ); m_pcZoomFactorSBox->setEnabled( hasSubWindow ); m_appModuleVideo->updateMenus(); m_appModuleQuality->updateMenus(); m_appModuleExtensions->updateMenus(); } // ----------------------- Create Functions ----------------------- void MainWindow::createActions() { m_arrayActions.resize( TOTAL_ACT ); // ------------ File ------------ m_arrayActions[OPEN_ACT] = new QAction( tr( "&Open" ), this ); m_arrayActions[OPEN_ACT]->setIcon( style()->standardIcon( QStyle::SP_DialogOpenButton ) ); m_arrayActions[OPEN_ACT]->setShortcuts( QKeySequence::Open ); m_arrayActions[OPEN_ACT]->setStatusTip( tr( "Open stream" ) ); connect( m_arrayActions[OPEN_ACT], SIGNAL( triggered() ), this, SLOT( open() ) ); // m_arrayActions[OPEN_DEVICE_ACT] = new QAction( tr( "&Open Capture Device" // ), this ); m_arrayActions[OPEN_DEVICE_ACT]->setStatusTip( tr( "Open // capture device (webcam)" ) ); connect( m_arrayActions[OPEN_DEVICE_ACT], // SIGNAL( triggered() ), this, SLOT( openDevice() ) ); m_arrayRecentFilesActions.resize( MAX_RECENT_FILES ); for( int i = 0; i < MAX_RECENT_FILES; i++ ) { m_arrayRecentFilesActions[i] = new QAction( this ); m_arrayRecentFilesActions[i]->setVisible( false ); connect( m_arrayRecentFilesActions[i], SIGNAL( triggered() ), this, SLOT( openRecent() ) ); } m_arrayActions[SAVE_ACT] = new QAction( tr( "&Save Frame" ), this ); m_arrayActions[SAVE_ACT]->setIcon( style()->standardIcon( QStyle::SP_DialogSaveButton ) ); m_arrayActions[SAVE_ACT]->setShortcuts( QKeySequence::SaveAs ); m_arrayActions[SAVE_ACT]->setStatusTip( tr( "Save current frame" ) ); connect( m_arrayActions[SAVE_ACT], SIGNAL( triggered() ), this, SLOT( saveFrame() ) ); m_arrayActions[SAVE_STREAM_ACT] = new QAction( tr( "&Save Stream" ), this ); m_arrayActions[SAVE_STREAM_ACT]->setIcon( style()->standardIcon( QStyle::SP_DialogSaveButton ) ); m_arrayActions[SAVE_STREAM_ACT]->setShortcuts( QKeySequence::SaveAs ); m_arrayActions[SAVE_STREAM_ACT]->setStatusTip( tr( "Save current stream" ) ); connect( m_arrayActions[SAVE_STREAM_ACT], SIGNAL( triggered() ), this, SLOT( saveStream() ) ); m_arrayActions[FORMAT_ACT] = new QAction( tr( "&Format" ), this ); m_arrayActions[FORMAT_ACT]->setIcon( QIcon::fromTheme( "transform-scale" ) ); m_arrayActions[FORMAT_ACT]->setShortcut( Qt::CTRL | Qt::Key_F ); m_arrayActions[FORMAT_ACT]->setStatusTip( tr( "Open format dialog" ) ); connect( m_arrayActions[FORMAT_ACT], SIGNAL( triggered() ), this, SLOT( format() ) ); m_arrayActions[RELOAD_ACT] = new QAction( tr( "&Reload" ), this ); m_arrayActions[RELOAD_ACT]->setIcon( style()->standardIcon( QStyle::SP_BrowserReload ) ); m_arrayActions[RELOAD_ACT]->setShortcut( Qt::CTRL | Qt::Key_R ); m_arrayActions[RELOAD_ACT]->setShortcut( Qt::Key_F5 ); m_arrayActions[RELOAD_ACT]->setStatusTip( tr( "Reload current sequence" ) ); connect( m_arrayActions[RELOAD_ACT], SIGNAL( triggered() ), this, SLOT( reload() ) ); m_arrayActions[RELOAD_ALL_ACT] = new QAction( tr( "Reload All" ), this ); m_arrayActions[RELOAD_ALL_ACT]->setShortcut( Qt::CTRL | Qt::SHIFT | Qt::Key_R ); m_arrayActions[RELOAD_ALL_ACT]->setStatusTip( tr( "Reload all sequences" ) ); connect( m_arrayActions[RELOAD_ALL_ACT], SIGNAL( triggered() ), this, SLOT( reloadAll() ) ); m_arrayActions[LOAD_ALL_ACT] = new QAction( tr( "Preload" ), this ); m_arrayActions[LOAD_ALL_ACT]->setStatusTip( tr( "Load sequence into memory (caution)" ) ); connect( m_arrayActions[LOAD_ALL_ACT], SIGNAL( triggered() ), this, SLOT( loadAll() ) ); m_arrayActions[CLOSE_ACT] = new QAction( tr( "&Close" ), this ); m_arrayActions[CLOSE_ACT]->setIcon( style()->standardIcon( QStyle::SP_DialogCloseButton ) ); m_arrayActions[CLOSE_ACT]->setStatusTip( tr( "Close the active window" ) ); connect( m_arrayActions[CLOSE_ACT], SIGNAL( triggered() ), m_pcWindowHandle, SLOT( removeActiveSubWindow() ) ); m_arrayActions[CLOSEALL_ACT] = new QAction( tr( "Close &All" ), this ); m_arrayActions[CLOSEALL_ACT]->setStatusTip( tr( "Close all the windows" ) ); connect( m_arrayActions[CLOSEALL_ACT], SIGNAL( triggered() ), m_pcWindowHandle, SLOT( removeAllSubWindow() ) ); m_arrayActions[EXIT_ACT] = new QAction( tr( "E&xit" ), this ); m_arrayActions[EXIT_ACT]->setShortcuts( QKeySequence::Quit ); m_arrayActions[EXIT_ACT]->setStatusTip( tr( "Exit the application" ) ); connect( m_arrayActions[EXIT_ACT], SIGNAL( triggered() ), qApp, SLOT( closeAllWindows() ) ); // ------------ View ------------ m_arrayActions[ZOOM_IN_ACT] = new QAction( tr( "Zoom &In (+25%)" ), this ); m_arrayActions[ZOOM_IN_ACT]->setIcon( QIcon::fromTheme( "zoom-in" ) ); m_arrayActions[ZOOM_IN_ACT]->setShortcut( tr( "Ctrl++" ) ); m_arrayActions[ZOOM_IN_ACT]->setStatusTip( tr( "Scale the image up by 25%" ) ); connect( m_arrayActions[ZOOM_IN_ACT], &QAction::triggered, [this] { scaleFrame( 125 ); } ); m_arrayActions[ZOOM_OUT_ACT] = new QAction( tr( "Zoom &Out (-25%)" ), this ); m_arrayActions[ZOOM_OUT_ACT]->setIcon( QIcon::fromTheme( "zoom-out" ) ); m_arrayActions[ZOOM_OUT_ACT]->setShortcut( tr( "Ctrl+-" ) ); m_arrayActions[ZOOM_OUT_ACT]->setStatusTip( tr( "Scale the image down by 25%" ) ); connect( m_arrayActions[ZOOM_OUT_ACT], &QAction::triggered, [this] { scaleFrame( 80 ); } ); m_arrayActions[ZOOM_NORMAL_ACT] = new QAction( tr( "&Normal Size" ), this ); m_arrayActions[ZOOM_NORMAL_ACT]->setIcon( QIcon::fromTheme( "zoom-original" ) ); m_arrayActions[ZOOM_NORMAL_ACT]->setShortcut( tr( "Ctrl+N" ) ); m_arrayActions[ZOOM_NORMAL_ACT]->setStatusTip( tr( "Show the image at its original size" ) ); connect( m_arrayActions[ZOOM_NORMAL_ACT], SIGNAL( triggered() ), this, SLOT( normalSize() ) ); m_arrayActions[ZOOM_FIT_ACT] = new QAction( tr( "Zoom to &Fit" ), this ); m_arrayActions[ZOOM_FIT_ACT]->setIcon( QIcon::fromTheme( "zoom-fit-best" ) ); m_arrayActions[ZOOM_FIT_ACT]->setStatusTip( tr( "Zoom in or out to fit on the window." ) ); connect( m_arrayActions[ZOOM_FIT_ACT], SIGNAL( triggered() ), this, SLOT( zoomToFit() ) ); m_arrayActions[ZOOM_FIT_ALL_ACT] = new QAction( tr( "Zoom to Fit All" ), this ); // m_arrayActions[ZOOM_FIT_ALL_ACT]->setIcon( QIcon::fromTheme( // "zoom-fit-best", QIcon( ":/images/fittowindow.png" ) ) // ); m_arrayActions[ZOOM_FIT_ALL_ACT]->setStatusTip( tr( "Apply zoom to fit to all windows" ) ); connect( m_arrayActions[ZOOM_FIT_ALL_ACT], SIGNAL( triggered() ), this, SLOT( zoomToFitAll() ) ); m_appModuleVideo->createActions(); m_appModuleQuality->createActions(); m_appModuleExtensions->createActions(); m_pcWindowHandle->createActions(); // ------------ About ------------ #ifdef USE_FERVOR m_arrayActions[UPDATE_ACT] = new QAction( tr( "&Update" ), this ); m_arrayActions[UPDATE_ACT]->setStatusTip( tr( "Check for updates" ) ); connect( m_arrayActions[UPDATE_ACT], SIGNAL( triggered() ), FvUpdater::sharedUpdater(), SLOT( CheckForUpdatesNotSilent() ) ); #endif m_arrayActions[ABOUT_ACT] = new QAction( tr( "&About" ), this ); m_arrayActions[ABOUT_ACT]->setIcon( QIcon( ":logos/calyp-icon.png" ) ); m_arrayActions[ABOUT_ACT]->setStatusTip( tr( "Show the application's About box" ) ); connect( m_arrayActions[ABOUT_ACT], SIGNAL( triggered() ), this, SLOT( about() ) ); m_arrayActions[ABOUTQT_ACT] = new QAction( tr( "About &Qt" ), this ); m_arrayActions[ABOUTQT_ACT]->setIcon( QIcon( ":images/qt.png" ) ); m_arrayActions[ABOUTQT_ACT]->setStatusTip( tr( "Show the Qt library's About box" ) ); connect( m_arrayActions[ABOUTQT_ACT], SIGNAL( triggered() ), qApp, SLOT( aboutQt() ) ); } void MainWindow::createMenus() { m_arrayMenu.resize( TOTAL_MENUS ); m_arrayMenu[FILE_MENU] = menuBar()->addMenu( tr( "&File" ) ); m_arrayMenu[FILE_MENU]->addAction( m_arrayActions[OPEN_ACT] ); // m_arrayMenu[FILE_MENU]->addAction( m_arrayActions[OPEN_DEVICE_ACT] ); m_arrayMenu[RECENT_MENU] = m_arrayMenu[FILE_MENU]->addMenu( tr( "Open Recent" ) ); for( int i = 0; i < MAX_RECENT_FILES; ++i ) { m_arrayMenu[RECENT_MENU]->addAction( m_arrayRecentFilesActions[i] ); } m_arrayMenu[FILE_MENU]->addAction( m_arrayActions[SAVE_ACT] ); // m_arrayMenu[FILE_MENU]->addAction( m_arrayActions[SAVE_STREAM_ACT] ); m_arrayMenu[FILE_MENU]->addSeparator(); m_arrayMenu[FILE_MENU]->addAction( m_arrayActions[FORMAT_ACT] ); m_arrayMenu[FILE_MENU]->addAction( m_arrayActions[RELOAD_ACT] ); m_arrayMenu[FILE_MENU]->addAction( m_arrayActions[RELOAD_ALL_ACT] ); m_arrayMenu[FILE_MENU]->addAction( m_arrayActions[LOAD_ALL_ACT] ); m_arrayMenu[FILE_MENU]->addSeparator(); m_arrayMenu[FILE_MENU]->addAction( m_arrayActions[CLOSE_ACT] ); m_arrayMenu[FILE_MENU]->addAction( m_arrayActions[EXIT_ACT] ); m_arrayMenu[VIEW_MENU] = menuBar()->addMenu( tr( "&View" ) ); m_arrayMenu[VIEW_MENU]->addAction( m_arrayActions[ZOOM_IN_ACT] ); m_arrayMenu[VIEW_MENU]->addAction( m_arrayActions[ZOOM_OUT_ACT] ); m_arrayMenu[VIEW_MENU]->addAction( m_arrayActions[ZOOM_NORMAL_ACT] ); m_arrayMenu[VIEW_MENU]->addAction( m_arrayActions[ZOOM_FIT_ACT] ); m_arrayMenu[VIEW_MENU]->addAction( m_arrayActions[ZOOM_FIT_ALL_ACT] ); m_arrayMenu[VIEW_MENU]->addSeparator(); // createPopupMenu() Returns a popup menu containing checkable entries for // the toolbars and dock widgets present in the main window. m_arrayMenu[DOCK_VIEW_MENU] = createPopupMenu(); if( m_arrayMenu[DOCK_VIEW_MENU] ) { QAction* actionPopupMenu = m_arrayMenu[VIEW_MENU]->addMenu( m_arrayMenu[DOCK_VIEW_MENU] ); actionPopupMenu->setText( tr( "&Toolbars/Docks" ) ); } menuBar()->addMenu( m_appModuleVideo->createVideoMenu() ); menuBar()->addMenu( m_appModuleVideo->createImageMenu() ); menuBar()->addMenu( m_appModuleQuality->createMenu() ); menuBar()->addMenu( m_appModuleExtensions->createMenu() ); menuBar()->addMenu( m_pcWindowHandle->createMenu() ); menuBar()->addSeparator(); m_arrayMenu[ABOUT_MENU] = menuBar()->addMenu( tr( "&Help" ) ); #ifdef USE_FERVOR m_arrayMenu[ABOUT_MENU]->addAction( m_arrayActions[UPDATE_ACT] ); #endif m_arrayMenu[ABOUT_MENU]->addSeparator(); m_arrayMenu[ABOUT_MENU]->addAction( m_arrayActions[ABOUT_ACT] ); m_arrayMenu[ABOUT_MENU]->addAction( m_arrayActions[ABOUTQT_ACT] ); } void MainWindow::createToolBars() { auto* fileToolbar = addToolBar( tr( "File" ) ); fileToolbar->addAction( m_arrayActions[OPEN_ACT] ); fileToolbar->addAction( m_arrayActions[SAVE_ACT] ); fileToolbar->addAction( m_arrayActions[FORMAT_ACT] ); fileToolbar->addAction( m_arrayActions[RELOAD_ACT] ); fileToolbar->addAction( m_arrayActions[CLOSE_ACT] ); fileToolbar->setMovable( false ); addToolBar( Qt::TopToolBarArea, fileToolbar ); auto* viewToolBar = addToolBar( tr( "View" ) ); m_pcZoomFactorSBox = new QDoubleSpinBox; m_pcZoomFactorSBox->setRange( 1.0, 10000.0 ); m_pcZoomFactorSBox->setDecimals( 0 ); m_pcZoomFactorSBox->setSingleStep( 10.0 ); m_pcZoomFactorSBox->setValue( 100.0 ); m_pcZoomFactorSBox->setSuffix( "%" ); connect( m_pcZoomFactorSBox, SIGNAL( valueChanged( double ) ), this, SLOT( zoomFromSBox( double ) ) ); viewToolBar->addWidget( m_pcZoomFactorSBox ); viewToolBar->addAction( m_arrayActions[ZOOM_IN_ACT] ); viewToolBar->addAction( m_arrayActions[ZOOM_OUT_ACT] ); viewToolBar->addAction( m_arrayActions[ZOOM_NORMAL_ACT] ); viewToolBar->addAction( m_arrayActions[ZOOM_FIT_ACT] ); viewToolBar->setMovable( false ); addToolBar( Qt::TopToolBarArea, viewToolBar ); addToolBar( Qt::TopToolBarArea, m_appModuleVideo->createToolBar() ); } void MainWindow::createDockWidgets() { // Properties Dock Window m_arraySideBars.resize( TOTAL_DOCK ); addDockWidget( Qt::RightDockWidgetArea, m_appModuleVideo->createDock() ); addDockWidget( Qt::RightDockWidgetArea, m_appModuleQuality->createDock() ); } void MainWindow::createStatusBar() { //! Warning: the following widget cannot change size too much statusBar()->addPermanentWidget( m_appModuleVideo->createStatusBarMessage() ); printMessage( "Ready!", CLP_LOG_INFO ); } void MainWindow::addStreamInfoToRecentList( CalypFileInfo streamInfo ) { int idx = findCalypStreamInfo( m_aRecentFileStreamInfo, streamInfo.m_cFilename ); if( idx >= 0 ) m_aRecentFileStreamInfo.remove( idx ); m_aRecentFileStreamInfo.prepend( streamInfo ); while( m_aRecentFileStreamInfo.size() > MAX_RECENT_FILES ) { m_aRecentFileStreamInfo.remove( m_aRecentFileStreamInfo.size() - 1 ); } updateRecentFileActions(); QSettings appSettings; QVariant var; var.setValue( m_aRecentFileStreamInfo ); appSettings.setValue( "MainWindow/RecentFileList", var ); } void MainWindow::updateRecentFileActions() { int numRecentFiles = m_aRecentFileStreamInfo.size(); numRecentFiles = qMin( numRecentFiles, MAX_RECENT_FILES ); int actionIdx = 0; while( actionIdx < numRecentFiles ) { QString text = m_aRecentFileStreamInfo.at( actionIdx ).m_cFilename; m_arrayRecentFilesActions.at( actionIdx )->setText( QFileInfo( text ).fileName() ); m_arrayRecentFilesActions.at( actionIdx )->setToolTip( "Open File " + text ); m_arrayRecentFilesActions.at( actionIdx )->setStatusTip( "Open File " + text ); m_arrayRecentFilesActions.at( actionIdx ) ->setData( QVariant::fromValue( m_aRecentFileStreamInfo.at( actionIdx ) ) ); m_arrayRecentFilesActions.at( actionIdx )->setVisible( true ); actionIdx++; } while( actionIdx < MAX_RECENT_FILES ) { m_arrayRecentFilesActions.at( actionIdx )->setVisible( false ); actionIdx++; } m_arrayMenu[RECENT_MENU]->setEnabled( m_aRecentFileStreamInfo.size() > 0 ? true : false ); } void MainWindow::checkRecentFileActions() { int i = 0; while( i < m_aRecentFileStreamInfo.size() ) { if( !QFileInfo( m_aRecentFileStreamInfo.at( i ).m_cFilename ).exists() ) { m_aRecentFileStreamInfo.remove( i ); continue; } else { unsigned long long int fileSize = QFileInfo( m_aRecentFileStreamInfo.at( i ).m_cFilename ).size(); std::cout << m_aRecentFileStreamInfo.at( i ).m_uiFileSize << std::endl; if( m_aRecentFileStreamInfo.at( i ).m_uiFileSize != fileSize ) { m_aRecentFileStreamInfo.remove( i ); continue; } } i++; } } void MainWindow::readSettings() { QSettings appSettings; QPoint pos = appSettings.value( "MainWindow/Position", QPoint( 200, 200 ) ).toPoint(); QSize size = appSettings.value( "MainWindow/Size", QSize( 500, 400 ) ).toSize(); move( pos ); resize( size ); m_lastOpenPath = appSettings.value( "MainWindow/LastOpenPath", QDir::homePath() ).toString(); m_lastOpenWidth = appSettings.value( "MainWindow/LastWidth" ).value(); m_lastOpenHeight = appSettings.value( "MainWindow/LastHeight" ).value(); m_lastOpenBitPerPixel = appSettings.value( "MainWindow/LastBitsPerPixel" ).value(); QVariant value = appSettings.value( "MainWindow/RecentFileList" ); m_aRecentFileStreamInfo = value.value(); checkRecentFileActions(); updateRecentFileActions(); m_appModuleVideo->readSettings(); m_appModuleQuality->readSettings(); m_appModuleExtensions->readSettings(); m_pcWindowHandle->readSettings(); } void MainWindow::writeSettings() { QSettings appSettings; appSettings.setValue( "MainWindow/Position", pos() ); appSettings.setValue( "MainWindow/Size", size() ); appSettings.setValue( "MainWindow/LastOpenPath", m_lastOpenPath ); appSettings.setValue( "MainWindow/LastWidth", m_lastOpenWidth ); appSettings.setValue( "MainWindow/LastHeight", m_lastOpenHeight ); appSettings.setValue( "MainWindow/LastBitsPerPixel", m_lastOpenBitPerPixel ); QVariant var; var.setValue( m_aRecentFileStreamInfo ); appSettings.setValue( "MainWindow/RecentFileList", var ); m_appModuleVideo->writeSettings(); m_appModuleQuality->writeSettings(); m_appModuleExtensions->writeSettings(); m_pcWindowHandle->writeSettings(); }