From 5f6ad706df15b7364a2bb850d27c59e272b5299e Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Thu, 27 Oct 2016 16:40:37 +0100 Subject: [PATCH] Fix saving of custom resolutions --- app/ConfigureFormatDialog.cpp | 66 +++++++++++++++++++++++++++++++++-- app/ConfigureFormatDialog.h | 12 +++++++ app/main.cpp | 3 ++ 3 files changed, 78 insertions(+), 3 deletions(-) diff --git a/app/ConfigureFormatDialog.cpp b/app/ConfigureFormatDialog.cpp index 1829a08..659ea58 100644 --- a/app/ConfigureFormatDialog.cpp +++ b/app/ConfigureFormatDialog.cpp @@ -29,17 +29,48 @@ #include #include #include +#include #include #include #include #include "lib/PlaYUVerFrame.h" -#include "lib/PlaYUVerStream.h" #include "ConfigureFormatDialog.h" #define MAX_SUPPORTED_RESOLUTION 9999 +QDataStream& operator<<( QDataStream& out, const PlaYUVerStdResolutionVector& array ) +{ + PlaYUVerStdResolution d; + out << array.size(); + for( Int i = 0; i < array.size(); i++ ) + { + d = array.at( i ); + out << QString::fromStdString( d.shortName ) + << d.uiWidth + << d.uiHeight; + } + return out; +} + +QDataStream& operator>>( QDataStream& in, PlaYUVerStdResolutionVector& array ) +{ + PlaYUVerStdResolution d; + QString auxName; + Int array_size; + in >> array_size; + for( Int i = 0; i < array_size; i++ ) + { + in >> auxName; + d.shortName = auxName.toStdString(); + in >> d.uiWidth; + in >> d.uiHeight; + array.append( d ); + } + return in; +} + class AddCustomFormat: public QDialog { public: @@ -113,6 +144,17 @@ ConfigureFormatDialog::ConfigureFormatDialog( QWidget *parent ) : { QString Name; UInt uiWidth, uiHeight; + + readSettings(); + for( UInt i = 0; i < aRCustomFileFormats.size(); i++ ) + { + Name = QString::fromStdString( aRCustomFileFormats[i].shortName ); + uiWidth = aRCustomFileFormats[i].uiWidth; + uiHeight = aRCustomFileFormats[i].uiHeight; + standardResolutionNames.append( QString( "%1 (%2x%3)" ).arg( Name ).arg( uiWidth ).arg( uiHeight ) ); + standardResolutionSizes.append( QSize( uiWidth, uiHeight ) ); + } + std::vector listPlaYUVerStdResolution = PlaYUVerStream::stdResolutionSizes(); for( UInt i = 0; i < listPlaYUVerStdResolution.size(); i++ ) { @@ -391,6 +433,7 @@ Int ConfigureFormatDialog::runConfigureFormatDialog( const QString& Filename, UI } if( exec() == QDialog::Rejected ) { + writeSettings(); return QDialog::Rejected; } rWidth = m_spinBoxWidth->value(); @@ -409,6 +452,7 @@ Int ConfigureFormatDialog::runConfigureFormatDialog( const QString& Filename, UI rBits = m_spinBoxBits->value(); rEndianess = m_comboBoxEndianness->currentIndex(); rFrameRate = m_spinBoxFrameRate->value(); + writeSettings(); return QDialog::Accepted; } @@ -418,12 +462,13 @@ void ConfigureFormatDialog::slotStandardResolutionSelected( Int idx ) { AddCustomFormat* pcCustomFmtDialog = new AddCustomFormat; PlaYUVerStdResolution customResolution = pcCustomFmtDialog->runDialog(); + aRCustomFileFormats.append( customResolution ); if( customResolution.shortName != "" ) { QString name = QString::fromStdString( customResolution.shortName ); name.append( QString( " (%2x%3)" ).arg( customResolution.uiWidth ).arg( customResolution.uiHeight ) ); - standardResolutionNames.append( name ); - standardResolutionSizes.append( QSize( customResolution.uiWidth, customResolution.uiHeight ) ); + standardResolutionNames.insert( 0, name ); + standardResolutionSizes.insert( 0, QSize( customResolution.uiWidth, customResolution.uiHeight ) ); m_comboBoxStandardResolution->blockSignals( true ); m_comboBoxStandardResolution->insertItem( 0, name ); @@ -484,3 +529,18 @@ Void ConfigureFormatDialog::slotBitsChange( Int idx ) } } +Void ConfigureFormatDialog::readSettings() +{ + QSettings appSettings; + QVariant value = appSettings.value( "ConfigureFormatDialog/CustomFormats" ); + aRCustomFileFormats = value.value(); + +} + +Void ConfigureFormatDialog::writeSettings() +{ + QSettings appSettings; + QVariant var; + var.setValue( aRCustomFileFormats ); + appSettings.setValue( "ConfigureFormatDialog/CustomFormats", var ); +} diff --git a/app/ConfigureFormatDialog.h b/app/ConfigureFormatDialog.h index fc78f3b..8e5daec 100644 --- a/app/ConfigureFormatDialog.h +++ b/app/ConfigureFormatDialog.h @@ -29,6 +29,7 @@ #include #include "PlaYUVerAppDefs.h" +#include "lib/PlaYUVerStream.h" class QComboBox; class QHBoxLayout; @@ -37,6 +38,10 @@ class QSpinBox; class QString; class QWidget; +typedef QVector PlaYUVerStdResolutionVector; +QDataStream& operator<<( QDataStream& out, const PlaYUVerStdResolutionVector& array ); +QDataStream& operator>>( QDataStream& in, PlaYUVerStdResolutionVector& array ); + /** * */ @@ -49,6 +54,9 @@ public: ConfigureFormatDialog( QWidget *parent = 0 ); Int runConfigureFormatDialog( const QString& Filename, UInt& rWidth, UInt& rHeight, Int& rInputFormat, UInt& rBits, Int& rEndianess, UInt& rFrameRate ); + Void readSettings(); + Void writeSettings(); + private Q_SLOTS: void slotStandardResolutionSelected( int ); void slotResolutionChange(); @@ -58,6 +66,7 @@ private Q_SLOTS: private: QStringList standardResolutionNames; QVector standardResolutionSizes; + PlaYUVerStdResolutionVector aRCustomFileFormats; QLabel* m_labelFilename; QComboBox *m_comboBoxStandardResolution; @@ -73,4 +82,7 @@ private: }; +Q_DECLARE_METATYPE( PlaYUVerStdResolution ); +Q_DECLARE_METATYPE( PlaYUVerStdResolutionVector ); + #endif // __CONFIGUREFORMATDIALOG_H__ diff --git a/app/main.cpp b/app/main.cpp index e707bfa..fdadc31 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -27,6 +27,7 @@ #include "PlaYUVerAppDefs.h" #include "PlaYUVerApp.h" #include "VideoSubWindow.h" +#include "ConfigureFormatDialog.h" #ifdef USE_QTDBUS #include "PlaYUVerAppAdaptor.h" #endif @@ -42,6 +43,8 @@ int main( int argc, char *argv[] ) { qRegisterMetaType(); qRegisterMetaTypeStreamOperators(); + qRegisterMetaType(); + qRegisterMetaTypeStreamOperators(); QApplication application( argc, argv ); QApplication::setApplicationName( "PlaYUVer" );