diff --git a/.clang-tidy b/.clang-tidy index 2a4dfb5..7ffee43 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,5 +1,5 @@ --- -Checks: 'clang-diagnostic-*,clang-analyzer-*,cppcoreguidelines-*,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-non-private-member-variables-in-classes' +Checks: 'clang-diagnostic-*,clang-analyzer-*,cppcoreguidelines-*,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-non-private-member-variables-in-classes, -cppcoreguidelines-owning-memory' WarningsAsErrors: '' HeaderFilterRegex: '' AnalyzeTemporaryDtors: false diff --git a/CMakeLists.txt b/CMakeLists.txt index 963eb47..acae397 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,7 +47,7 @@ OPTION(BUILD_APP "Build GUI Application" ON) OPTION(BUILD_TOOLS "Build Command Line Application" ON) OPTION(BUILD_EXAMPLES "Build Examples" OFF) OPTION(BUILD_DOC "Build Documentation" OFF) -OPTION(BUILD_TESTS "Build Google Tests" OFF) +OPTION(BUILD_TESTS "Build Tests" OFF) OPTION(BUILD_WITH_SANITIZERS "Build with sanitizers" OFF) OPTION(BUILD_WITH_THREAD_SANITIZER "Build with thread sanitizer" OFF) diff --git a/app/MainWindow.cpp b/app/MainWindow.cpp index f71087c..9f8ebd9 100644 --- a/app/MainWindow.cpp +++ b/app/MainWindow.cpp @@ -79,15 +79,15 @@ MainWindow::MainWindow() setWindowTitle( QApplication::applicationName() ); setWindowIcon( QIcon( ":logos/calyp-icon.png" ) ); setUnifiedTitleAndToolBarOnMac( true ); - setCentralWidget( m_pcWindowHandle ); + setCentralWidget( m_pcWindowHandle->getWidget() ); setAcceptDrops( true ); setBackgroundRole( QPalette::Window ); - connect( m_pcWindowHandle, &SubWindowHandle::windowActivated, this, &MainWindow::update ); - connect( m_pcWindowHandle, &SubWindowHandle::changed, this, &MainWindow::update, Qt::QueuedConnection ); - connect( m_appModuleVideo, &VideoHandle::changed, this, &MainWindow::update, Qt::QueuedConnection ); - connect( m_appModuleQuality, &QualityHandle::changed, this, &MainWindow::update, Qt::QueuedConnection ); - connect( m_appModuleExtensions, &ModulesHandle::changed, this, &MainWindow::update, Qt::QueuedConnection ); + 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[] ) @@ -185,7 +185,13 @@ void MainWindow::closeAll() m_pcWindowHandle->removeAllSubWindow(); } -void MainWindow::loadFile( QString fileName, CalypFileInfo* pStreamInfo ) +void MainWindow::loadFile( CalypFileInfo pStreamInfo ) +{ + QString filename{ pStreamInfo.m_cFilename }; + loadFile( std::move( filename ), std::move( pStreamInfo ) ); +} + +void MainWindow::loadFile( QString fileName, std::optional streamInfo ) { if( !QFileInfo( fileName ).exists() ) { @@ -201,21 +207,22 @@ void MainWindow::loadFile( QString fileName, CalypFileInfo* pStreamInfo ) videoSubWindow = new VideoStreamSubWindow(); // createSubWindow(); videoSubWindow->setResourceManaget( m_appResourceHandle.get() ); - if( !pStreamInfo ) + if( !streamInfo.has_value() ) { - int idx = findCalypStreamInfo( m_aRecentFileStreamInfo, fileName ); - pStreamInfo = (CalypFileInfo*)( idx >= 0 ? &m_aRecentFileStreamInfo.at( idx ) : NULL ); + auto idx = findCalypStreamInfo( m_aRecentFileStreamInfo, fileName ); + if( idx >= 0 ) + streamInfo = m_aRecentFileStreamInfo.at( idx ); } try { bool opened = false; - if( pStreamInfo != nullptr ) + if( streamInfo.has_value() ) { try { - opened = videoSubWindow->loadFile( pStreamInfo ); + opened = videoSubWindow->loadFile( std::move( *streamInfo ) ); } catch( CalypFailure& e ) { @@ -313,7 +320,7 @@ void MainWindow::open() { if( !fileNameList.at( i ).isEmpty() ) { - loadFile( fileNameList.at( i ) ); + loadFile( std::move( fileNameList.at( i ) ) ); } } } @@ -326,9 +333,10 @@ void MainWindow::open() void MainWindow::openRecent() { QAction* action = qobject_cast( sender() ); - CalypFileInfo recentFile = action->data().value(); if( action ) - loadFile( recentFile.m_cFilename, &recentFile ); + { + loadFile( action->data().value() ); + } } void MainWindow::saveFrame() @@ -408,7 +416,7 @@ void MainWindow::format() m_pcCurrentSubWindow->close(); } m_pcCurrentSubWindow = NULL; - update(); + updateMainWindow(); } } @@ -418,7 +426,7 @@ void MainWindow::reload() { m_pcCurrentSubWindow->refreshSubWindow(); m_pcCurrentSubWindow = NULL; - update(); + updateMainWindow(); } } @@ -439,7 +447,7 @@ void MainWindow::reloadAll() } } m_pcCurrentSubWindow = NULL; - update(); + updateMainWindow(); } void MainWindow::loadAll() @@ -553,7 +561,7 @@ VideoStreamSubWindow* MainWindow::findVideoStreamSubWindow( const SubWindowHandl // ----------------------- Update Functions ----------------------- -void MainWindow::update() +void MainWindow::updateMainWindow() { SubWindowAbstract* activeSubWindow = m_pcWindowHandle->activeSubWindow(); QCoreApplication::processEvents(); @@ -821,12 +829,9 @@ void MainWindow::createMenus() menuBar()->addMenu( m_appModuleVideo->createVideoMenu() ); menuBar()->addMenu( m_appModuleVideo->createImageMenu() ); - QMenu* QualityMenu = m_appModuleQuality->createMenu(); - menuBar()->addMenu( QualityMenu ); - QMenu* ModuleMenu = m_appModuleExtensions->createMenu(); - menuBar()->addMenu( ModuleMenu ); - QMenu* windowMenu = m_pcWindowHandle->createMenu(); - menuBar()->addMenu( windowMenu ); + menuBar()->addMenu( m_appModuleQuality->createMenu() ); + menuBar()->addMenu( m_appModuleExtensions->createMenu() ); + menuBar()->addMenu( m_pcWindowHandle->createMenu() ); menuBar()->addSeparator(); diff --git a/app/MainWindow.h b/app/MainWindow.h index ae731e2..13926e2 100644 --- a/app/MainWindow.h +++ b/app/MainWindow.h @@ -39,6 +39,7 @@ #include #include #include +#include #include "CommonDefs.h" #include "VideoStreamSubWindow.h" @@ -76,7 +77,8 @@ class MainWindow : public QMainWindow public: MainWindow(); bool parseArgs( int argc, char* argv[] ); - void loadFile( QString fileName, CalypFileInfo* pStreamInfo = NULL ); + void loadFile( CalypFileInfo pStreamInfo ); + void loadFile( QString fileName, std::optional pStreamInfo = {} ); public Q_SLOTS: void printMessage( const QString& msg ); @@ -117,7 +119,7 @@ private Q_SLOTS: void dragEnterEvent( QDragEnterEvent* event ); void dropEvent( QDropEvent* event ); - void update(); + void updateMainWindow(); void updateZoomFactorSBox(); private: diff --git a/app/ModulesHandle.cpp b/app/ModulesHandle.cpp index d86ee3a..6050b91 100644 --- a/app/ModulesHandle.cpp +++ b/app/ModulesHandle.cpp @@ -36,7 +36,7 @@ #include "modules/CalypModulesFactory.h" ModulesHandle::ModulesHandle( QWidget* parent, SubWindowHandle* windowManager, VideoHandle* moduleVideo ) - : QWidget( parent ), m_pcParent( parent ), m_pcMainWindowManager( windowManager ), m_appModuleVideo( moduleVideo ) + : m_pcParent( parent ), m_pcMainWindowManager( windowManager ), m_appModuleVideo( moduleVideo ) { setParent( m_pcParent ); } @@ -51,32 +51,32 @@ void ModulesHandle::createActions() connect( m_pcActionMapper, SIGNAL( mapped( int ) ), this, SLOT( processOpt( int ) ) ); // m_arrayActions[FORCE_PLAYING_REFRESH_ACT] = new QAction( "Refresh while - // playing", parent() ); + // playing", m_pcParent ); // m_arrayActions[FORCE_PLAYING_REFRESH_ACT]->setStatusTip( "Force module // refreshing while playing" ); // m_arrayActions[FORCE_PLAYING_REFRESH_ACT]->setCheckable( true ); - m_arrayActions[LOAD_EXTERNAL_ACT] = new QAction( "Load external module", parent() ); + m_arrayActions[LOAD_EXTERNAL_ACT] = new QAction( "Load external module", m_pcParent ); m_arrayActions[LOAD_EXTERNAL_ACT]->setStatusTip( "Load an externally build module" ); - connect( m_arrayActions[LOAD_EXTERNAL_ACT], SIGNAL( triggered() ), this, SLOT( loadExternalModule() ) ); + connect( m_arrayActions[LOAD_EXTERNAL_ACT], &QAction::triggered, this, &ModulesHandle::loadExternalModule ); - m_arrayActions[APPLY_ALL_ACT] = new QAction( "Apply to All", parent() ); + m_arrayActions[APPLY_ALL_ACT] = new QAction( "Apply to All", m_pcParent ); m_arrayActions[APPLY_ALL_ACT]->setStatusTip( "Apply module to all frames and save the result" ); connect( m_arrayActions[APPLY_ALL_ACT], SIGNAL( triggered() ), m_pcActionMapper, SLOT( map() ) ); m_pcActionMapper->setMapping( m_arrayActions[APPLY_ALL_ACT], APPLY_ALL_ACT ); - m_arrayActions[SWAP_FRAMES_ACT] = new QAction( "Swap frames", parent() ); + m_arrayActions[SWAP_FRAMES_ACT] = new QAction( "Swap frames", m_pcParent ); m_arrayActions[SWAP_FRAMES_ACT]->setStatusTip( "Swap Sub Window order" ); connect( m_arrayActions[SWAP_FRAMES_ACT], SIGNAL( triggered() ), m_pcActionMapper, SLOT( map() ) ); m_pcActionMapper->setMapping( m_arrayActions[SWAP_FRAMES_ACT], SWAP_FRAMES_ACT ); - m_arrayActions[DISABLE_ACT] = new QAction( "Disable Modules", parent() ); - connect( m_arrayActions[DISABLE_ACT], SIGNAL( triggered() ), this, SLOT( destroyWindowModules() ) ); + m_arrayActions[DISABLE_ACT] = new QAction( "Disable Modules", m_pcParent ); + connect( m_arrayActions[DISABLE_ACT], &QAction::triggered, this, &ModulesHandle::destroyWindowModules ); - m_arrayActions[DISABLE_ALL_ACT] = new QAction( "Disable All Modules", parent() ); - connect( m_arrayActions[DISABLE_ALL_ACT], SIGNAL( triggered() ), this, SLOT( destroyAllModulesIf() ) ); + m_arrayActions[DISABLE_ALL_ACT] = new QAction( "Disable All Modules", m_pcParent ); + connect( m_arrayActions[DISABLE_ALL_ACT], &QAction::triggered, this, &ModulesHandle::destroyAllModulesIf ); - m_arrayActions[FORCE_NEW_WINDOW_ACT] = new QAction( "Use New Window", parent() ); + m_arrayActions[FORCE_NEW_WINDOW_ACT] = new QAction( "Use New Window", m_pcParent ); m_arrayActions[FORCE_NEW_WINDOW_ACT]->setStatusTip( "Show module result in a new window. Some modules already force this " "feature" ); @@ -85,20 +85,16 @@ void ModulesHandle::createActions() QMenu* ModulesHandle::createMenu() { - m_pcModulesMenu = new QMenu( "&Modules", this ); + m_pcModulesMenu = new QMenu( "&Modules", m_pcParent ); buildMenu(); return m_pcModulesMenu; } void ModulesHandle::buildMenu() { - QString ModuleIfinternalName; - QAction* currAction; - QMenu* currSubMenu; - - for( int i = 0; i < m_arrayModulesActions.size(); i++ ) + for( auto& action : m_arrayModulesActions ) { - delete m_arrayModulesActions.at( i ); + delete action; } m_arrayModulesActions.clear(); m_pcModulesMenu->clear(); @@ -109,9 +105,9 @@ void ModulesHandle::buildMenu() for( ; it != moduleFactoryMap.end(); ++it ) { auto pcCurrModuleIf = it->second(); - ModuleIfinternalName = QString::fromLocal8Bit( it->first ); + QString ModuleIfinternalName = QString::fromLocal8Bit( it->first ); - currSubMenu = NULL; + QMenu* currSubMenu{ nullptr }; if( pcCurrModuleIf->m_iModuleAPI <= CLP_MODULE_API_2 ) { if( pcCurrModuleIf->m_pchModuleCategory ) @@ -132,7 +128,7 @@ void ModulesHandle::buildMenu() } } - currAction = new QAction( pcCurrModuleIf->getModuleLongName(), parent() ); + QAction* currAction = new QAction( pcCurrModuleIf->getModuleLongName(), m_pcParent ); QString moduleTooltip = pcCurrModuleIf->m_pchModuleTooltip; if( pcCurrModuleIf->m_uiNumberOfFrames > 1 ) moduleTooltip += QString( " | Requires %1 frames" ).arg( pcCurrModuleIf->m_uiNumberOfFrames ); @@ -140,7 +136,7 @@ void ModulesHandle::buildMenu() currAction->setStatusTip( moduleTooltip ); currAction->setData( ModuleIfinternalName ); currAction->setCheckable( false ); - connect( currAction, SIGNAL( triggered() ), this, SLOT( activateModule() ) ); + connect( currAction, &QAction::triggered, this, &ModulesHandle::activateModule ); m_arrayModulesActions.append( currAction ); if( currSubMenu ) @@ -160,20 +156,20 @@ void ModulesHandle::buildMenu() void ModulesHandle::updateMenus() { - VideoSubWindow* pcSubWindow = qobject_cast( m_pcMainWindowManager->activeSubWindow() ); - bool hasSubWindow = pcSubWindow ? true : false; - QAction* currModuleAction; + VideoSubWindow* pcSubWindow = m_pcMainWindowManager->activeSubWindow(); + + bool hasSubWindow = pcSubWindow != nullptr ? true : false; for( int i = 0; i < m_arrayModulesActions.size(); i++ ) { - currModuleAction = m_arrayModulesActions.at( i ); - //currModuleAction->setEnabled( hasSubWindow ); + auto* currModuleAction = m_arrayModulesActions.at( i ); + // currModuleAction->setEnabled( hasSubWindow ); currModuleAction->setChecked( false ); } - //for( int i = 0; i < m_pcModulesSubMenuList.size(); i++ ) + // for( int i = 0; i < m_pcModulesSubMenuList.size(); i++ ) //{ // m_pcModulesSubMenuList.at( i )->setEnabled( hasSubWindow ); - //} + // } for( int i = 0; i < m_arrayActions.size(); i++ ) { @@ -213,7 +209,7 @@ void ModulesHandle::writeSettings() void ModulesHandle::processOpt( int index ) { - VideoSubWindow* pcSubWindow = qobject_cast( m_pcMainWindowManager->activeSubWindow() ); + VideoSubWindow* pcSubWindow = m_pcMainWindowManager->activeSubWindow(); if( pcSubWindow ) { CalypAppModuleIf* pcCurrentModule = pcSubWindow->getDisplayModule(); @@ -262,7 +258,7 @@ void ModulesHandle::activateModule() Qt::KeyboardModifiers keyModifiers = QApplication::keyboardModifiers(); bool bTmpForceNewWindow = false; - VideoSubWindow* pcVideoSubWindow = qobject_cast( m_pcMainWindowManager->activeSubWindow() ); + VideoSubWindow* pcVideoSubWindow = m_pcMainWindowManager->activeSubWindow(); if( !pcVideoSubWindow ) { return; @@ -336,7 +332,7 @@ void ModulesHandle::activateModule() { videoSubWindowList.clear(); qobject_cast( m_pcParent )->printMessage( "Error! Incompatible frames", CLP_LOG_ERROR ); - //destroyModuleIf( pcCurrAppModuleIf ); + // destroyModuleIf( pcCurrAppModuleIf ); return; } } @@ -351,7 +347,7 @@ void ModulesHandle::activateModule() { qobject_cast( m_pcParent ) ->printMessage( "Error! There is no windows to apply the module", CLP_LOG_ERROR ); - //destroyModuleIf( pcCurrAppModuleIf ); + // destroyModuleIf( pcCurrAppModuleIf ); return; } @@ -366,7 +362,7 @@ void ModulesHandle::activateModule() if( moduleOptDialog.runConfiguration() == QDialog::Rejected ) { qobject_cast( m_pcParent )->printMessage( "Module canceled by user!", CLP_LOG_WARNINGS ); - //destroyModuleIf( pcCurrAppModuleIf ); + // destroyModuleIf( pcCurrAppModuleIf ); return; } } @@ -434,7 +430,7 @@ void ModulesHandle::activateModule() if( !moduleCreated ) { qobject_cast( m_pcParent )->printMessage( "Error! Module cannot be created", CLP_LOG_ERROR ); - //destroyModuleIf( pcCurrAppModuleIf ); + // destroyModuleIf( pcCurrAppModuleIf ); return; } @@ -471,7 +467,7 @@ void ModulesHandle::activateModule() void ModulesHandle::destroyWindowModules() { - VideoSubWindow* pcVideoSubWindow = qobject_cast( m_pcMainWindowManager->activeSubWindow() ); + VideoSubWindow* pcVideoSubWindow = m_pcMainWindowManager->activeSubWindow(); if( pcVideoSubWindow ) { pcVideoSubWindow->disableAllModules(); diff --git a/app/ModulesHandle.h b/app/ModulesHandle.h index 8a36b60..8a34f2a 100644 --- a/app/ModulesHandle.h +++ b/app/ModulesHandle.h @@ -39,7 +39,7 @@ class SubWindowHandle; class CalypAppModuleIf; class SubWindowHandle; -class ModulesHandle : public QWidget +class ModulesHandle : public QObject { Q_OBJECT public: diff --git a/app/QualityHandle.cpp b/app/QualityHandle.cpp index 46ca8de..8bc18f7 100644 --- a/app/QualityHandle.cpp +++ b/app/QualityHandle.cpp @@ -34,7 +34,7 @@ #include "VideoSubWindow.h" QualityHandle::QualityHandle( QWidget* parent, SubWindowHandle* windowManager ) - : m_pcParet( parent ), m_pcMainWindowManager( windowManager ) + : m_pcParent( parent ), m_pcMainWindowManager( windowManager ) { } @@ -70,7 +70,7 @@ void QualityHandle::createActions() QMenu* QualityHandle::createMenu() { - m_pcMenuQuality = new QMenu( "Quality", this ); + m_pcMenuQuality = new QMenu( "Quality", m_pcParent ); m_pcSubMenuQualityMetrics = m_pcMenuQuality->addMenu( "Quality Metrics" ); m_pcSubMenuQualityMetrics->addActions( m_actionGroupQualityMetric->actions() ); m_pcMenuQuality->addAction( m_arrayActions[SELECT_CURR_REF_ACT] ); @@ -82,8 +82,8 @@ QMenu* QualityHandle::createMenu() QDockWidget* QualityHandle::createDock() { - m_pcQualityHandleSideBar = new QualityMeasurementSidebar( m_pcParet, m_pcMainWindowManager ); - m_pcQualityHandleDock = new QDockWidget( tr( "Quality Measurement" ), this ); + m_pcQualityHandleSideBar = new QualityMeasurementSidebar( m_pcParent, m_pcMainWindowManager ); + m_pcQualityHandleDock = new QDockWidget( tr( "Quality Measurement" ), m_pcParent ); m_pcQualityHandleDock->setAllowedAreas( Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea ); m_pcQualityHandleDock->setWidget( m_pcQualityHandleSideBar ); @@ -98,7 +98,7 @@ QDockWidget* QualityHandle::createDock() void QualityHandle::updateMenus() { - VideoSubWindow* pcCurrentVideoSubWindow = qobject_cast( m_pcMainWindowManager->activeSubWindow() ); + VideoSubWindow* pcCurrentVideoSubWindow = m_pcMainWindowManager->activeSubWindow(); bool hasSubWindow = pcCurrentVideoSubWindow ? true : false; bool hasReference = false; bool isReference = false; @@ -179,7 +179,7 @@ void QualityHandle::measureQuality( QVector apcWindowList ) } pcReferenceWindow->stop(); - ProgressBar* pcProgressBar = new ProgressBar( m_pcParet, numberOfFrames ); + ProgressBar* pcProgressBar = new ProgressBar( m_pcParent, numberOfFrames ); QVector* padQualityValues = new QVector[numberOfWindows + 1]; double* padAverageQuality = new double[numberOfWindows + 1]; @@ -247,7 +247,7 @@ void QualityHandle::slotQualityMetricChanged( int idx ) void QualityHandle::slotSelectCurrentAsReference() { - VideoSubWindow* pcRefSubWindow = qobject_cast( m_pcMainWindowManager->activeSubWindow() ); + VideoSubWindow* pcRefSubWindow = m_pcMainWindowManager->activeSubWindow(); if( pcRefSubWindow ) { VideoSubWindow* pcVideoSubWindow; @@ -267,7 +267,7 @@ void QualityHandle::slotSelectCurrentAsReference() void QualityHandle::slotPlotQualitySingle() { - VideoSubWindow* pcSubWindow = qobject_cast( m_pcMainWindowManager->activeSubWindow() ); + VideoSubWindow* pcSubWindow = m_pcMainWindowManager->activeSubWindow(); if( pcSubWindow ) { if( pcSubWindow->getRefSubWindow() ) @@ -291,7 +291,7 @@ void QualityHandle::slotPlotQualitySingle() void QualityHandle::slotPlotQualitySeveral() { - VideoSubWindow* pcSubWindow = qobject_cast( m_pcMainWindowManager->activeSubWindow() ); + VideoSubWindow* pcSubWindow = m_pcMainWindowManager->activeSubWindow(); if( pcSubWindow ) { QVector apcWindowList; diff --git a/app/QualityHandle.h b/app/QualityHandle.h index 8c03722..40fe3d5 100644 --- a/app/QualityHandle.h +++ b/app/QualityHandle.h @@ -36,7 +36,7 @@ class SubWindowHandle; class VideoSubWindow; -class QualityHandle : public QWidget +class QualityHandle : public QObject { Q_OBJECT public: @@ -54,7 +54,7 @@ public: void update( VideoSubWindow* currSubWindow ); private: - QWidget* m_pcParet; + QWidget* m_pcParent; SubWindowHandle* m_pcMainWindowManager; enum diff --git a/app/SubWindowHandle.cpp b/app/SubWindowHandle.cpp index bd2b919..ca6fb59 100644 --- a/app/SubWindowHandle.cpp +++ b/app/SubWindowHandle.cpp @@ -85,7 +85,7 @@ private: }; SubWindowHandle::SubWindowHandle( QWidget* parent ) - : QWidget( parent ) + : m_pcApp( qobject_cast( parent ) ) { m_iWindowMode = -1; m_pcWindowManagerLayout = NULL; @@ -94,7 +94,7 @@ SubWindowHandle::SubWindowHandle( QWidget* parent ) m_apcSubWindowList.clear(); m_apcMdiSubWindowList.clear(); - m_pcApp = qobject_cast( parentWidget() ); + m_pcCentralWidget = new QWidget; // setWindowMode( DETACHEDSUBWINDOWMODE ); setWindowMode( MDISUBWINDOWMODE ); } @@ -152,8 +152,8 @@ void SubWindowHandle::setWindowMode( int iWindowMode ) m_apcSubWindowList.at( i )->resize( m_apcSubWindowList.at( i )->sizeHint() ); m_apcSubWindowList.at( i )->show(); } - setVisible( false ); - parentWidget()->update(); + m_pcCentralWidget->setVisible( false ); + m_pcApp->update(); m_pcApp->showNormal(); qApp->processEvents(); QSize screenSize = QGuiApplication::screens()[0]->availableGeometry().size(); @@ -164,13 +164,13 @@ void SubWindowHandle::setWindowMode( int iWindowMode ) if( iWindowMode == MDISUBWINDOWMODE ) { - setVisible( true ); + m_pcCentralWidget->setVisible( true ); m_pcMdiArea = new MdiArea; m_pcMdiArea->setActivationOrder( QMdiArea::ActivationHistoryOrder ); connect( m_pcMdiArea, SIGNAL( subWindowActivated( QMdiSubWindow* ) ), this, SLOT( updateActiveSubWindow() ) ); - m_pcWindowManagerLayout = new QHBoxLayout( this ); + m_pcWindowManagerLayout = new QHBoxLayout( m_pcCentralWidget ); m_pcWindowManagerLayout->addWidget( m_pcMdiArea ); - setLayout( m_pcWindowManagerLayout ); + m_pcCentralWidget->setLayout( m_pcWindowManagerLayout ); for( int i = 0; i < m_apcSubWindowList.size(); i++ ) { addMdiSubWindow( m_apcSubWindowList.at( i ) ); @@ -320,11 +320,6 @@ void SubWindowHandle::removeActiveSubWindow() removeSubWindow( m_pcActiveWindow ); } -SubWindowAbstract* SubWindowHandle::activeSubWindow() const -{ - return m_pcActiveWindow; -} - QList SubWindowHandle::findSubWindow( const unsigned int uiCategory ) const { QList apcSubWindowList; @@ -491,12 +486,12 @@ void SubWindowHandle::createActions() m_actionGroupWindowMode->actions().at( m_iWindowMode )->setChecked( true ); m_arrayActions[CLOSE_ACT] = new QAction( tr( "&Close" ), this ); - m_arrayActions[CLOSE_ACT]->setIcon( style()->standardIcon( QStyle::SP_DialogCloseButton ) ); + m_arrayActions[CLOSE_ACT]->setIcon( m_pcApp->style()->standardIcon( QStyle::SP_DialogCloseButton ) ); m_arrayActions[CLOSE_ACT]->setStatusTip( tr( "Close the active window" ) ); connect( m_arrayActions[CLOSE_ACT], SIGNAL( triggered() ), this, SLOT( removeActiveSubWindow() ) ); m_arrayActions[CLOSE_ACT] = new QAction( tr( "&Close" ), this ); - m_arrayActions[CLOSE_ACT]->setIcon( style()->standardIcon( QStyle::SP_DialogCloseButton ) ); + m_arrayActions[CLOSE_ACT]->setIcon( m_pcApp->style()->standardIcon( QStyle::SP_DialogCloseButton ) ); m_arrayActions[CLOSE_ACT]->setStatusTip( tr( "Close the active window" ) ); connect( m_arrayActions[CLOSE_ACT], SIGNAL( triggered() ), this, SLOT( removeActiveSubWindow() ) ); @@ -519,14 +514,14 @@ void SubWindowHandle::createActions() m_arrayActions[NEXT_WINDOWS_ACT] = new QAction( tr( "Ne&xt" ), this ); m_arrayActions[NEXT_WINDOWS_ACT]->setShortcuts( QKeySequence::NextChild ); - m_arrayActions[NEXT_WINDOWS_ACT]->setIcon( QIcon( style()->standardIcon( QStyle::SP_ArrowRight ) ) ); + m_arrayActions[NEXT_WINDOWS_ACT]->setIcon( QIcon( m_pcApp->style()->standardIcon( QStyle::SP_ArrowRight ) ) ); m_arrayActions[NEXT_WINDOWS_ACT]->setStatusTip( tr( "Move the focus to the next window" ) ); // connect( m_arrayActions[NEXT_WINDOWS_ACT], SIGNAL( triggered() ), this, // SLOT( activateNextSubWindow() ) ); m_arrayActions[PREVIOUS_WINDOWS_ACT] = new QAction( tr( "Pre&vious" ), this ); m_arrayActions[PREVIOUS_WINDOWS_ACT]->setShortcuts( QKeySequence::PreviousChild ); - m_arrayActions[PREVIOUS_WINDOWS_ACT]->setIcon( QIcon( style()->standardIcon( QStyle::SP_ArrowLeft ) ) ); + m_arrayActions[PREVIOUS_WINDOWS_ACT]->setIcon( QIcon( m_pcApp->style()->standardIcon( QStyle::SP_ArrowLeft ) ) ); m_arrayActions[PREVIOUS_WINDOWS_ACT]->setStatusTip( tr( "Move the focus to the previous window" ) ); // connect( m_arrayActions[PREVIOUS_WINDOWS_ACT], SIGNAL( triggered() ), // this, SLOT( activatePreviousSubWindow() ) ); @@ -537,12 +532,17 @@ void SubWindowHandle::createActions() QMenu* SubWindowHandle::createMenu() { - m_pcMenuWindow = new QMenu( "&Window", this ); + m_pcMenuWindow = new QMenu( "&Window", m_pcApp ); updateMenu(); connect( m_pcMenuWindow, SIGNAL( aboutToShow() ), this, SLOT( updateMenu() ) ); return m_pcMenuWindow; } +auto SubWindowHandle::getWidget() -> QWidget* +{ + return m_pcCentralWidget; +} + void SubWindowHandle::updateMenu() { m_pcMenuWindow->clear(); diff --git a/app/SubWindowHandle.h b/app/SubWindowHandle.h index f0095a3..49b0192 100644 --- a/app/SubWindowHandle.h +++ b/app/SubWindowHandle.h @@ -42,7 +42,7 @@ class SubWindowAbstract; class MdiArea; class MdiSubWindow; -class SubWindowHandle : public QWidget +class SubWindowHandle : public QObject { Q_OBJECT @@ -53,7 +53,12 @@ public: void addSubWindow( SubWindowAbstract* widget ); - SubWindowAbstract* activeSubWindow() const; + template + T* activeSubWindow() const + { + static_assert( std::is_base_of::value, "T must inherit from SubWindowAbstract" ); + return qobject_cast( m_pcActiveWindow ); + } QList findSubWindow( const unsigned int uiCategory = 0 ) const; QList findSubWindow( const QString& aName, const unsigned int uiCategory = 0 ) const; @@ -62,6 +67,8 @@ public: void createActions(); QMenu* createMenu(); + auto getWidget() -> QWidget*; + void readSettings(); void writeSettings(); @@ -76,6 +83,7 @@ private: int m_iWindowMode; QList m_apcSubWindowList; + QWidget* m_pcCentralWidget; QHBoxLayout* m_pcWindowManagerLayout; MdiArea* m_pcMdiArea; QList m_apcMdiSubWindowList; diff --git a/app/VideoHandle.cpp b/app/VideoHandle.cpp index 1c3a75c..24bd95f 100644 --- a/app/VideoHandle.cpp +++ b/app/VideoHandle.cpp @@ -44,7 +44,7 @@ #include "VideoSubWindow.h" VideoHandle::VideoHandle( QWidget* parent, SubWindowHandle* windowManager ) - : m_pcParet( parent ), m_pcMainWindowManager( windowManager ) + : m_pcParent( parent ), m_pcMainWindowManager( windowManager ) { m_pcCurrentVideoSubWindow = NULL; m_bIsPlaying = false; @@ -63,13 +63,13 @@ void VideoHandle::createActions() m_arrayActions.resize( TOTAL_ACT ); m_arrayActions[PLAY_ACT] = new QAction( "Play", this ); m_arrayActions[PLAY_ACT]->setStatusTip( "Play/Pause" ); - m_arrayActions[PLAY_ACT]->setIcon( QIcon( m_pcParet->style()->standardIcon( QStyle::SP_MediaPlay ) ) ); + m_arrayActions[PLAY_ACT]->setIcon( QIcon( m_pcParent->style()->standardIcon( QStyle::SP_MediaPlay ) ) ); m_arrayActions[PLAY_ACT]->setShortcut( Qt::Key_Space ); connect( m_arrayActions[PLAY_ACT], SIGNAL( triggered() ), this, SLOT( play() ) ); m_arrayActions[STOP_ACT] = new QAction( "Stop", this ); m_arrayActions[STOP_ACT]->setStatusTip( "Stop" ); - m_arrayActions[STOP_ACT]->setIcon( QIcon( m_pcParet->style()->standardIcon( QStyle::SP_MediaStop ) ) ); + m_arrayActions[STOP_ACT]->setIcon( QIcon( m_pcParent->style()->standardIcon( QStyle::SP_MediaStop ) ) ); connect( m_arrayActions[STOP_ACT], SIGNAL( triggered() ), this, SLOT( stop() ) ); m_mapperVideoSeek = new QSignalMapper( this ); @@ -78,7 +78,7 @@ void VideoHandle::createActions() m_arrayActions[VIDEO_BACKWARD_ACT] = new QAction( "Video Backward", this ); m_arrayActions[VIDEO_BACKWARD_ACT]->setStatusTip( "Seek backward" ); m_arrayActions[VIDEO_BACKWARD_ACT]->setIcon( - QIcon( m_pcParet->style()->standardIcon( QStyle::SP_MediaSeekBackward ) ) ); + QIcon( m_pcParent->style()->standardIcon( QStyle::SP_MediaSeekBackward ) ) ); m_arrayActions[VIDEO_BACKWARD_ACT]->setShortcut( Qt::Key_Left ); connect( m_arrayActions[VIDEO_BACKWARD_ACT], SIGNAL( triggered() ), m_mapperVideoSeek, SLOT( map() ) ); m_mapperVideoSeek->setMapping( m_arrayActions[VIDEO_BACKWARD_ACT], 0 ); @@ -86,7 +86,7 @@ void VideoHandle::createActions() m_arrayActions[VIDEO_FORWARD_ACT] = new QAction( "Video Forward", this ); m_arrayActions[VIDEO_FORWARD_ACT]->setStatusTip( "Seek forward" ); m_arrayActions[VIDEO_FORWARD_ACT]->setIcon( - QIcon( m_pcParet->style()->standardIcon( QStyle::SP_MediaSeekForward ) ) ); + QIcon( m_pcParent->style()->standardIcon( QStyle::SP_MediaSeekForward ) ) ); m_arrayActions[VIDEO_FORWARD_ACT]->setShortcut( Qt::Key_Right ); connect( m_arrayActions[VIDEO_FORWARD_ACT], SIGNAL( triggered() ), m_mapperVideoSeek, SLOT( map() ) ); m_mapperVideoSeek->setMapping( m_arrayActions[VIDEO_FORWARD_ACT], 1 ); @@ -178,7 +178,7 @@ void VideoHandle::createActions() QMenu* VideoHandle::createVideoMenu() { - m_pcMenuVideo = new QMenu( "Video", m_pcParet ); + m_pcMenuVideo = new QMenu( "Video", m_pcParent ); m_pcMenuVideo->addAction( m_arrayActions[PLAY_ACT] ); m_pcMenuVideo->addAction( m_arrayActions[STOP_ACT] ); m_pcMenuVideo->addAction( m_arrayActions[VIDEO_BACKWARD_ACT] ); @@ -193,7 +193,7 @@ QMenu* VideoHandle::createVideoMenu() QMenu* VideoHandle::createImageMenu() { - m_pcMenuImage = new QMenu( "Image", m_pcParet ); + m_pcMenuImage = new QMenu( "Image", m_pcParent ); m_pcMenuImage->addAction( m_arrayActions[NAVIGATION_TOOL_ACT] ); m_pcMenuImage->addAction( m_arrayActions[SELECTION_TOOL_ACT] ); m_pcMenuImage->addAction( m_arrayActions[BLOCK_SELECTION_TOOL_ACT] ); @@ -228,8 +228,8 @@ QToolBar* VideoHandle::createToolBar() QDockWidget* VideoHandle::createDock() { - m_pcFramePropertiesSideBar = new FramePropertiesDock( m_pcParet, &m_bIsPlaying ); - m_pcFramePropertiesDock = new QDockWidget( tr( "Frame Information" ), m_pcParet ); + m_pcFramePropertiesSideBar = new FramePropertiesDock( m_pcParent, &m_bIsPlaying ); + m_pcFramePropertiesDock = new QDockWidget( tr( "Frame Information" ), m_pcParent ); m_pcFramePropertiesDock->setAllowedAreas( Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea ); m_pcFramePropertiesDock->setWidget( m_pcFramePropertiesSideBar ); connect( m_pcFramePropertiesDock, SIGNAL( visibilityChanged( bool ) ), this, SLOT( update() ) ); @@ -270,7 +270,7 @@ QWidget* VideoHandle::createStatusBarMessage() void VideoHandle::updateMenus() { - VideoSubWindow* pcSubWindow = qobject_cast( m_pcMainWindowManager->activeSubWindow() ); + VideoSubWindow* pcSubWindow = m_pcMainWindowManager->activeSubWindow(); bool hasSubWindow = pcSubWindow ? true : false; m_arrayActions[PLAY_ACT]->setEnabled( hasSubWindow ); @@ -387,12 +387,12 @@ void VideoHandle::update() if( m_pcCurrentVideoSubWindow->isPlaying() ) { m_arrayActions[PLAY_ACT]->setText( "Pause" ); - m_arrayActions[PLAY_ACT]->setIcon( m_pcParet->style()->standardIcon( QStyle::SP_MediaPause ) ); + m_arrayActions[PLAY_ACT]->setIcon( m_pcParent->style()->standardIcon( QStyle::SP_MediaPause ) ); } else { m_arrayActions[PLAY_ACT]->setText( "Play" ); - m_arrayActions[PLAY_ACT]->setIcon( m_pcParet->style()->standardIcon( QStyle::SP_MediaPlay ) ); + m_arrayActions[PLAY_ACT]->setIcon( m_pcParent->style()->standardIcon( QStyle::SP_MediaPlay ) ); } } else @@ -716,7 +716,7 @@ void VideoHandle::playEvent() catch( const char* msg ) { QString warningMsg = "Error while playing " + m_pcCurrentVideoSubWindow->getWindowName() + " with the following error: \n" + msg; - QMessageBox::warning( m_pcParet, QApplication::applicationName(), warningMsg ); + QMessageBox::warning( m_pcParent, QApplication::applicationName(), warningMsg ); qDebug() << warningMsg; stop(); m_pcCurrentVideoSubWindow->close(); @@ -757,7 +757,7 @@ void VideoHandle::seekVideo() { if( auto* videoStreamSubWindow = qobject_cast( m_pcCurrentVideoSubWindow ) ) { - SeekStreamDialog* dialogSeekVideo = new SeekStreamDialog( videoStreamSubWindow->getInputStream(), m_pcParet ); + SeekStreamDialog* dialogSeekVideo = new SeekStreamDialog( videoStreamSubWindow->getInputStream(), m_pcParent ); int newFrameNum = dialogSeekVideo->runDialog(); if( newFrameNum >= 0 ) { @@ -815,7 +815,7 @@ void VideoHandle::videoSelectionButtonEvent() } else { - SubWindowSelectorDialog dialogWindowsSelection( m_pcParet, m_pcMainWindowManager, + SubWindowSelectorDialog dialogWindowsSelection( m_pcParent, m_pcMainWindowManager, SubWindowAbstract::VIDEO_STREAM_SUBWINDOW ); QStringList cWindowListNames; for( auto playingSubWindow : m_acPlayingSubWindows ) diff --git a/app/VideoHandle.h b/app/VideoHandle.h index a5d8d05..1b4063d 100644 --- a/app/VideoHandle.h +++ b/app/VideoHandle.h @@ -72,7 +72,7 @@ public: void addSubWindow( VideoSubWindow* subWindow ); private: - QWidget* m_pcParet; + QWidget* m_pcParent; SubWindowHandle* m_pcMainWindowManager; enum { diff --git a/app/VideoStreamSubWindow.cpp b/app/VideoStreamSubWindow.cpp index ee47a4b..1a8495b 100644 --- a/app/VideoStreamSubWindow.cpp +++ b/app/VideoStreamSubWindow.cpp @@ -75,7 +75,7 @@ QDataStream& operator>>( QDataStream& in, CalypFileInfoVector& array ) return in; } -int findCalypStreamInfo( CalypFileInfoVector array, QString filename ) +auto findCalypStreamInfo( const CalypFileInfoVector& array, const QString& filename ) -> int { for( int i = 0; i < array.size(); i++ ) if( array.at( i ).m_cFilename == filename ) @@ -188,7 +188,8 @@ bool VideoStreamSubWindow::loadFile( QString cFilename, bool bForceDialog ) BitsPel = appSettings.value( "VideoStreamSubWindow/LastBitsPerPixel" ).value(); } } - bool bRet = false; + bool bRet{ false }; + bool forceRaw{ false }; for( int iPass = 0; iPass < 2 && !bRet; iPass++ ) { if( iPass || bConfig ) @@ -202,6 +203,7 @@ bool VideoStreamSubWindow::loadFile( QString cFilename, bool bForceDialog ) try { bRet = m_pCurrStream->open( cFilename.toStdString(), Width, Height, InputFormat, BitsPel, Endianness, FrameRate, iPass == 1, CalypStream::Type::Input ); + forceRaw = iPass > 0; } catch( CalypFailure& e ) { @@ -223,6 +225,7 @@ bool VideoStreamSubWindow::loadFile( QString cFilename, bool bForceDialog ) m_sStreamInfo.m_iEndianness = Endianness; m_sStreamInfo.m_uiFrameRate = FrameRate; m_sStreamInfo.m_uiFileSize = QFileInfo( cFilename ).size(); + m_sStreamInfo.m_bForceRaw = forceRaw; QVariant var; var.setValue( Width ); @@ -248,21 +251,22 @@ bool VideoStreamSubWindow::loadFile( QString cFilename, bool bForceDialog ) return true; } -bool VideoStreamSubWindow::loadFile( CalypFileInfo* streamInfo ) +bool VideoStreamSubWindow::loadFile( CalypFileInfo streamInfo ) { assert( m_pcResourceManager != nullptr ); m_uiResourceId = m_pcResourceManager->getResource( m_pCurrStream ); m_pCurrStream = m_pcResourceManager->getResourceAsset( m_uiResourceId ); - if( !m_pCurrStream->open( streamInfo->m_cFilename.toStdString(), streamInfo->m_uiWidth, streamInfo->m_uiHeight, - streamInfo->m_iPelFormat, streamInfo->m_uiBitsPelPixel, streamInfo->m_iEndianness, - streamInfo->m_uiFrameRate, streamInfo->m_bForceRaw, CalypStream::Type::Input ) ) + if( !m_pCurrStream->open( streamInfo.m_cFilename.toStdString(), streamInfo.m_uiWidth, streamInfo.m_uiHeight, + streamInfo.m_iPelFormat, streamInfo.m_uiBitsPelPixel, streamInfo.m_iEndianness, + streamInfo.m_uiFrameRate, streamInfo.m_bForceRaw, CalypStream::Type::Input ) ) { return false; } - m_sStreamInfo = *streamInfo; + m_cFilename = streamInfo.m_cFilename; + m_sStreamInfo = std::move( streamInfo ); #ifdef CALYP_MANAGED_RESOURCES m_pcResourceManager->startResourceWorker( m_uiResourceId ); @@ -272,13 +276,12 @@ bool VideoStreamSubWindow::loadFile( CalypFileInfo* streamInfo ) refreshFrame(); - m_cFilename = streamInfo->m_cFilename; updateVideoWindowInfo(); setWindowName( QFileInfo( m_cFilename ).fileName() ); return true; } -bool VideoStreamSubWindow::guessFormat( QString filename, unsigned int& rWidth, unsigned int& rHeight, int& rInputFormat, unsigned int& rBitsPerPixel, +bool VideoStreamSubWindow::guessFormat( const QString& filename, unsigned int& rWidth, unsigned int& rHeight, int& rInputFormat, unsigned int& rBitsPerPixel, int& rEndianness, unsigned int& rFrameRate ) { std::vector stdResList = CalypStream::stdResolutionSizes(); @@ -515,7 +518,7 @@ bool VideoStreamSubWindow::goToNextFrame( bool bThreaded ) return bEndOfSeq; } -bool VideoStreamSubWindow::saveStream( QString filename ) +bool VideoStreamSubWindow::saveStream( const QString& filename ) { bool iRet = false; QApplication::setOverrideCursor( Qt::WaitCursor ); diff --git a/app/VideoStreamSubWindow.h b/app/VideoStreamSubWindow.h index a749229..f5ab40f 100644 --- a/app/VideoStreamSubWindow.h +++ b/app/VideoStreamSubWindow.h @@ -44,23 +44,23 @@ class VideoStreamSubWindow; class ResourceHandle; class CalypAppModuleIf; -typedef struct +struct CalypFileInfo { QString m_cFilename; unsigned int m_uiWidth; unsigned int m_uiHeight; int m_iPelFormat; unsigned int m_uiBitsPelPixel; - unsigned int m_iEndianness; + int m_iEndianness; unsigned int m_uiFrameRate; unsigned long long int m_uiFileSize; bool m_bForceRaw{ false }; -} CalypFileInfo; -typedef QVector CalypFileInfoVector; +}; +using CalypFileInfoVector = QVector; QDataStream& operator<<( QDataStream& out, const CalypFileInfoVector& d ); QDataStream& operator>>( QDataStream& in, CalypFileInfoVector& d ); -int findCalypStreamInfo( CalypFileInfoVector array, QString filename ); +auto findCalypStreamInfo( const CalypFileInfoVector& array, const QString& filename ) -> int; class VideoStreamSubWindow : public VideoSubWindow { @@ -83,9 +83,9 @@ public: bool supportsFormatConfiguration() const { return m_pCurrStream->supportsFormatConfiguration(); }; bool loadFile( QString cFilename, bool bForceDialog = false ); - bool loadFile( CalypFileInfo* streamInfo ); + bool loadFile( CalypFileInfo streamInfo ); void loadAll(); - bool saveStream( QString filename ); + bool saveStream( const QString& filename ); bool play(); void pause(); @@ -107,7 +107,7 @@ public: private: bool goToNextFrame( bool bThreaded ); - static bool guessFormat( QString filename, unsigned int& rWidth, unsigned int& rHeight, int& rInputFormat, unsigned int& rBitsPerPixel, + static bool guessFormat( const QString& filename, unsigned int& rWidth, unsigned int& rHeight, int& rInputFormat, unsigned int& rBitsPerPixel, int& rEndianness, unsigned int& rFrameRate ); private: // NO_LINT diff --git a/app/VideoSubWindow.cpp b/app/VideoSubWindow.cpp index 4b4008b..51ebe31 100644 --- a/app/VideoSubWindow.cpp +++ b/app/VideoSubWindow.cpp @@ -34,13 +34,12 @@ #include "SubWindowAbstract.h" VideoInformation::VideoInformation( QWidget* parent ) - : QWidget( parent ), m_bBusyWindow( false ) + : QWidget( parent ), m_pcRefreshTimer{ new QTimer }, m_bBusyWindow( false ) { setPalette( Qt::transparent ); setAttribute( Qt::WA_TransparentForMouseEvents ); m_cTopLeftTextFont.setPointSize( 8 ); m_cCenterTextFont.setPointSize( 12 ); - m_pcRefreshTimer = new QTimer; m_pcRefreshTimer->setSingleShot( true ); } @@ -83,18 +82,21 @@ void VideoInformation::paintEvent( QPaintEvent* event ) VideoSubWindow::VideoSubWindow( enum VideoSubWindowCategories category, QWidget* parent ) : SubWindowAbstract( parent, SubWindowAbstract::VIDEO_SUBWINDOW | category ) - , m_pcReferenceSubWindow( NULL ) - , m_pcUpdateTimer( NULL ) + , m_pcVideoInfo{ new VideoInformation{ this } } + , m_pcScrollArea{ new QScrollArea } + , m_cViewArea{ new ViewArea } + , m_pcReferenceSubWindow{ nullptr } + , m_pcUpdateTimer{ new QTimer{ this } } { // Create a new scroll area inside the sub-window - m_pcScrollArea = new QScrollArea; + connect( m_pcScrollArea->horizontalScrollBar(), SIGNAL( actionTriggered( int ) ), this, SLOT( updateScrollValues() ) ); connect( m_pcScrollArea->verticalScrollBar(), SIGNAL( actionTriggered( int ) ), this, SLOT( updateScrollValues() ) ); // Create a new interface to show images - m_cViewArea = new ViewArea; + connect( m_cViewArea, SIGNAL( zoomFactorChanged_byWheel( double, QPoint ) ), this, SLOT( adjustScrollBarByScale( double, QPoint ) ) ); @@ -102,7 +104,7 @@ VideoSubWindow::VideoSubWindow( enum VideoSubWindowCategories category, QWidget* SIGNAL( zoomFactorChanged( double, QPoint ) ) ); connect( m_cViewArea, SIGNAL( scrollBarMoved( QPoint ) ), this, SLOT( adjustScrollBarByOffset( QPoint ) ) ); - //connect( m_cViewArea, SIGNAL( scrollBarMoved( QPoint ) ), this, SIGNAL( scrollBarMoved( QPoint ) ) ); + // connect( m_cViewArea, SIGNAL( scrollBarMoved( QPoint ) ), this, SIGNAL( scrollBarMoved( QPoint ) ) ); connect( m_cViewArea, SIGNAL( selectionChanged( QRect ) ), this, SLOT( updateSelectedArea( QRect ) ) ); connect( m_cViewArea, SIGNAL( positionChanged( const QPoint& ) ), this, @@ -118,12 +120,8 @@ VideoSubWindow::VideoSubWindow( enum VideoSubWindowCategories category, QWidget* m_associatedModules.clear(); - m_pcUpdateTimer = new QTimer(); m_pcUpdateTimer->setInterval( 800 ); connect( m_pcUpdateTimer, SIGNAL( timeout() ), this, SLOT( updateWindowOnTimeout() ) ); - - //! Add video information - m_pcVideoInfo = new VideoInformation( this ); } VideoSubWindow::~VideoSubWindow() @@ -371,7 +369,7 @@ void VideoSubWindow::refreshFrame() } } -bool VideoSubWindow::save( QString filename ) +bool VideoSubWindow::save( const QString& filename ) { bool iRet = false; QApplication::setOverrideCursor( Qt::WaitCursor ); @@ -439,15 +437,11 @@ void VideoSubWindow::adjustScrollBarByScale( double scale, QPoint center ) } else { - int value; - int x = center.x() - cLastScroll.x(); - value = int( scale * cLastScroll.x() + ( ( scale - 1 ) * x ) ); - m_cCurrScroll.setX( value ); + m_cCurrScroll.setX( int( scale * cLastScroll.x() + ( ( scale - 1 ) * x ) ) ); int y = center.y() - cLastScroll.y(); - value = int( scale * cLastScroll.y() + ( ( scale - 1 ) * y ) ); - m_cCurrScroll.setY( value ); + m_cCurrScroll.setY( int( scale * cLastScroll.y() + ( ( scale - 1 ) * y ) ) ); } // Update window scroll @@ -464,15 +458,15 @@ void VideoSubWindow::updateScrollValues() double xPos = m_pcScrollArea->horizontalScrollBar()->value(); double yPos = m_pcScrollArea->verticalScrollBar()->value(); - m_cCurrScroll.setX( xPos ); - m_cCurrScroll.setY( yPos ); + m_cCurrScroll.setX( xPos != 0 ); + m_cCurrScroll.setY( yPos != 0 ); m_dHorScroll = m_dVerScroll = 0; - if( xPos ) + if( xPos != 0 ) m_dHorScroll = xPos / double( m_pcScrollArea->horizontalScrollBar()->maximum() ); - if( yPos ) + if( yPos != 0 ) m_dVerScroll = yPos / double( m_pcScrollArea->verticalScrollBar()->maximum() ); } @@ -496,12 +490,10 @@ void VideoSubWindow::zoomToFit() void VideoSubWindow::zoomToFactor( double factor, QPoint center ) { - double curFactor; - curFactor = getScaleFactor(); + double curFactor = getScaleFactor(); if( factor != curFactor ) { - double usedScale; - usedScale = m_cViewArea->scaleZoomFactor( factor / curFactor, center, QSize() ); + double usedScale = m_cViewArea->scaleZoomFactor( factor / curFactor, center, QSize() ); adjustScrollBarByScale( usedScale, center ); } } @@ -511,8 +503,7 @@ void VideoSubWindow::scaleView( double scale, QPoint center ) Q_ASSERT( !m_cViewArea->image().isNull() ); if( scale != 1.0 ) { - double usedScale; - usedScale = m_cViewArea->scaleZoomFactor( scale, center, getScrollSize() ); + double usedScale = m_cViewArea->scaleZoomFactor( scale, center, getScrollSize() ); adjustScrollBarByScale( usedScale, center ); } } @@ -522,18 +513,15 @@ void VideoSubWindow::scaleView( const QSize& size, QPoint center ) QSize imgViewSize; if( m_pcCurrFrameAsset ) imgViewSize = QSize( m_pcCurrFrameAsset->getWidth(), m_pcCurrFrameAsset->getHeight() ); - //else - // imgViewSize = QSize( m_pCurrStream->getWidth(), m_pCurrStream->getHeight() ); + // else + // imgViewSize = QSize( m_pCurrStream->getWidth(), m_pCurrStream->getHeight() ); QSize newSize = imgViewSize; newSize.scale( size, Qt::KeepAspectRatio ); // Calc the zoom factor - double wfactor = 1; - double hfactor = 1; - double factor; - - wfactor = (double)newSize.width() / imgViewSize.width(); - hfactor = (double)newSize.height() / imgViewSize.height(); + double wfactor = (double)newSize.width() / imgViewSize.width(); + double hfactor = (double)newSize.height() / imgViewSize.height(); + double factor{ wfactor }; if( wfactor < hfactor ) factor = wfactor; @@ -543,8 +531,7 @@ void VideoSubWindow::scaleView( const QSize& size, QPoint center ) double curFactor = getScaleFactor(); if( factor != curFactor ) { - double usedScale; - usedScale = m_cViewArea->scaleZoomFactor( factor / curFactor, center, getScrollSize() ); + double usedScale = m_cViewArea->scaleZoomFactor( factor / curFactor, center, getScrollSize() ); adjustScrollBarByScale( usedScale, center ); } } @@ -553,17 +540,15 @@ void VideoSubWindow::updatePixelValueStatusBar( const QPoint& pos ) { if( m_pcCurrFrameAsset ) { - int iWidth, iHeight; int posX = pos.x(); int posY = pos.y(); - QString strStatus; - iWidth = m_pcCurrFrameAsset->getWidth(); - iHeight = m_pcCurrFrameAsset->getHeight(); + int iWidth = m_pcCurrFrameAsset->getWidth(); + int iHeight = m_pcCurrFrameAsset->getHeight(); if( ( posX < iWidth ) && ( posX >= 0 ) && ( posY < iHeight ) && ( posY >= 0 ) ) { - strStatus = QString( "(%1,%2) " ).arg( posX ).arg( posY ); + QString strStatus = QString( "(%1,%2) " ).arg( posX ).arg( posY ); int colorSpace = m_pcCurrFrameAsset->getColorSpace(); CalypPixel pixelValue = m_pcCurrFrameAsset->getPixel( pos.x(), pos.y() ); diff --git a/app/VideoSubWindow.h b/app/VideoSubWindow.h index 4ae030c..809135f 100644 --- a/app/VideoSubWindow.h +++ b/app/VideoSubWindow.h @@ -58,7 +58,7 @@ public: void setBusyWindow( bool bFlag ); protected: - void paintEvent( QPaintEvent* event ); + void paintEvent( QPaintEvent* event ) override; private: QTimer* m_pcRefreshTimer; @@ -90,7 +90,7 @@ public: virtual auto getFrameNum() -> std::uint64_t { return 1; }; QString getVideoInformation() { return m_cStreamInformation; } - bool save( QString filename ); + bool save( const QString& filename ); void setCurrFrame( std::shared_ptr pcCurrFrame ); @@ -167,12 +167,12 @@ protected: VideoInformation* m_pcVideoInfo; QString m_cStreamInformation; std::shared_ptr m_pcCurrFrameAsset; - //bool m_bWindowBusy; - //bool m_bIsPlaying; + // bool m_bWindowBusy; + // bool m_bIsPlaying; std::vector> m_associatedModules; CalypAppModuleIf* m_pcDisplayModule{ nullptr }; - //bool m_hasAssociatedModules; + // bool m_hasAssociatedModules; private: QScrollArea* m_pcScrollArea; diff --git a/modules/tests/CMakeLists.txt b/modules/tests/CMakeLists.txt index 5a59ba3..1c4d5af 100644 --- a/modules/tests/CMakeLists.txt +++ b/modules/tests/CMakeLists.txt @@ -1,20 +1,22 @@ # # CMakeLists for playuver lib tests component # +OPTION(BUILD_MODULES_TESTS "Build unit tests of modules" ON) +IF(BUILD_MODULES_TESTS) + INCLUDE_DIRECTORIES(${GTEST_INCLUDE_DIRS}) -INCLUDE_DIRECTORIES(${GTEST_INCLUDE_DIRS}) + ADD_DEFINITIONS(-DCALYP_TEST_DATA_DIR=\"${CALYP_TEST_DATA_DIR}\") -ADD_DEFINITIONS(-DCALYP_TEST_DATA_DIR=\"${CALYP_TEST_DATA_DIR}\") + FOREACH(module ${MODULES_LIST_NAME}) + ADD_EXECUTABLE(TestModuleCreate_${module} TestModuleCreate.cpp) + TARGET_COMPILE_DEFINITIONS(TestModuleCreate_${module} PUBLIC -DCALYP_TEST_MODULE_NAME=\"${module}\") + TARGET_LINK_LIBRARIES(TestModuleCreate_${module} ${PROJECT_LIBRARY} CalypModules gtest gtest_main) + ADD_TEST(TestModuleCreate_${module} TestModuleCreate_${module}) -FOREACH(module ${MODULES_LIST_NAME}) - ADD_EXECUTABLE(TestModuleCreate_${module} TestModuleCreate.cpp) - TARGET_COMPILE_DEFINITIONS(TestModuleCreate_${module} PUBLIC -DCALYP_TEST_MODULE_NAME=\"${module}\") - TARGET_LINK_LIBRARIES(TestModuleCreate_${module} ${PROJECT_LIBRARY} CalypModules gtest gtest_main) - ADD_TEST(TestModuleCreate_${module} TestModuleCreate_${module}) + ADD_EXECUTABLE(TestModuleProcessNumberOfFrames_${module} TestModuleProcessNumberOfFrames.cpp) + TARGET_COMPILE_DEFINITIONS(TestModuleProcessNumberOfFrames_${module} PUBLIC -DCALYP_TEST_MODULE_NAME=\"${module}\") + TARGET_LINK_LIBRARIES(TestModuleProcessNumberOfFrames_${module} ${PROJECT_LIBRARY} CalypModules gtest gtest_main) + ADD_TEST(TestModuleProcessNumberOfFrames_${module} TestModuleProcessNumberOfFrames_${module}) - ADD_EXECUTABLE(TestModuleProcessNumberOfFrames_${module} TestModuleProcessNumberOfFrames.cpp) - TARGET_COMPILE_DEFINITIONS(TestModuleProcessNumberOfFrames_${module} PUBLIC -DCALYP_TEST_MODULE_NAME=\"${module}\") - TARGET_LINK_LIBRARIES(TestModuleProcessNumberOfFrames_${module} ${PROJECT_LIBRARY} CalypModules gtest gtest_main) - ADD_TEST(TestModuleProcessNumberOfFrames_${module} TestModuleProcessNumberOfFrames_${module}) - -ENDFOREACH(module ${MODULES_LIST_NAME}) + ENDFOREACH(module ${MODULES_LIST_NAME}) +ENDIF()