Commit ef29f1df authored by Prince Gupta's avatar Prince Gupta Committed by Jean-Baptiste Kempf
Browse files

qt/preferences: reset live properties on cancel

ref #25584
parent 1db0e725
......@@ -219,6 +219,28 @@ namespace
}
}
class PropertyResetter
{
public:
PropertyResetter(QWidget *control, const char * property)
: m_control {control}
, m_property {property}
, m_initialValue {m_control->property(property)}
{
}
void reset()
{
bool success = m_control->setProperty(m_property.data(), m_initialValue);
vlc_assert(success);
}
private:
QWidget *m_control;
const QByteArray m_property;
const QVariant m_initialValue;
};
/*********************************************************************
* The List of categories
*********************************************************************/
......@@ -785,6 +807,7 @@ SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
optionWidgets["qtRB"] = ui.qt;
#if !defined( _WIN32)
fillStylesCombo( ui.stylesCombo, getSettings()->value( "MainWindow/QtStyle", "" ).toString() );
m_resetters.push_back( std::make_unique<PropertyResetter>( ui.stylesCombo, "currentIndex" ) );
CONNECT( ui.stylesCombo, currentIndexChanged( int ), this, changeStyle( ) );
optionWidgets["styleCB"] = ui.stylesCombo;
......@@ -828,10 +851,12 @@ SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
CONFIG_BOOL( "qt-menubar", menuBarCheck );
ui.pinVideoControlsCheckbox->setChecked( p_intf->p_sys->p_mi->pinVideoControls() );
m_resetters.push_back(std::make_unique<PropertyResetter>(ui.pinVideoControlsCheckbox, "checked"));
QObject::connect( ui.pinVideoControlsCheckbox, &QCheckBox::stateChanged, p_intf->p_sys->p_mi, &MainInterface::setPinVideoControls );
ui.colorSchemeComboBox->insertItems(0, p_intf->p_sys->p_mi->getColorScheme()->stringList());
ui.colorSchemeComboBox->setCurrentText( p_intf->p_sys->p_mi->getColorScheme()->getCurrent() );
m_resetters.push_back(std::make_unique<PropertyResetter>( ui.colorSchemeComboBox, "currentIndex" ));
QObject::connect( ui.colorSchemeComboBox, &QComboBox::currentTextChanged, p_intf->p_sys->p_mi->getColorScheme(), &ColorSchemeModel::setCurrent );
const float intfScaleFloatFactor = 100.f;
......@@ -857,6 +882,8 @@ SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
, p_intf->p_sys->p_mi->getMaxIntfUserScaleFactor() * intfScaleFloatFactor);
updateIntfUserScaleFactorFromControls( p_intf->p_sys->p_mi->getIntfUserScaleFactor() * intfScaleFloatFactor );
m_resetters.push_back( std::make_unique<PropertyResetter>( ui.intfScaleFactorSlider, "value" ) );
QObject::connect( ui.intfScaleFactorSlider, QOverload<int>::of(&QSlider::valueChanged)
, p_intf->p_sys->p_mi , updateIntfUserScaleFactorFromControls );
QObject::connect( ui.intfScaleFactorSpinBox, QOverload<int>::of(&QSpinBox::valueChanged)
......@@ -1100,6 +1127,9 @@ void SPrefsPanel::updateAudioOptions( int number)
SPrefsPanel::~SPrefsPanel()
{
if (!m_isApplied)
clean();
qDeleteAll( controls ); controls.clear();
free( lang );
}
......@@ -1114,6 +1144,8 @@ void SPrefsPanel::updateAudioVolume( int volume )
/* Function called from the main Preferences dialog on each SPrefs Panel */
void SPrefsPanel::apply()
{
m_isApplied = true;
/* Generic save for ever panel */
QList<ConfigControl *>::const_iterator i;
for( i = controls.begin() ; i != controls.end() ; ++i )
......@@ -1250,7 +1282,10 @@ void SPrefsPanel::apply()
}
void SPrefsPanel::clean()
{}
{
for ( auto &resetter : m_resetters )
resetter->reset();
}
void SPrefsPanel::lastfm_Changed( int i_state )
{
......
......@@ -99,7 +99,6 @@ public:
SPrefsPanel( intf_thread_t *, QWidget *, int );
virtual ~SPrefsPanel();
void apply();
void clean();
#ifdef _WIN32
void cleanLang();
#endif
......@@ -124,6 +123,10 @@ private:
void saveLang();
#endif
// used to revert properties on cancel which are immediately set
bool m_isApplied = false;
std::vector<std::unique_ptr<class PropertyResetter>> m_resetters;
/* Display only the options for the selected audio output */
private slots:
void lastfm_Changed( int );
......@@ -142,6 +145,8 @@ private slots:
void configML();
void changeStyle( );
void clean();
};
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment