[vlc-commits] [Git][videolan/vlc][master] qt: refactor styles combobox and print the default style
Felix Paul Kühne (@fkuehne)
gitlab at videolan.org
Fri Sep 6 20:33:19 UTC 2024
Felix Paul Kühne pushed to branch master at VideoLAN / VLC
Commits:
ac0545c6 by Fatih Uzunoglu at 2024-09-06T20:13:12+00:00
qt: refactor styles combobox and print the default style
- Currently style handling is handled in a really fragile
manner. The order of keys provided by `QStyleFactory`
is expected to directly match the combobox. At the
same time, if the style is not overridden, then there
should be no need to save this in the settings.
- Although the first entry is the default style, it does
not provide what the style is. Now, the style itself is
printed as well.
- - - - -
1 changed file:
- modules/gui/qt/dialogs/preferences/simple_preferences.cpp
Changes:
=====================================
modules/gui/qt/dialogs/preferences/simple_preferences.cpp
=====================================
@@ -192,29 +192,7 @@ static int getDefaultAudioVolume(const char *aout)
return -1;
}
-namespace
-{
-#if !defined( _WIN32)
- void fillStylesCombo( QComboBox *stylesCombo, const QString &initialStyle)
- {
- stylesCombo->addItem( qtr("System's default") );
- stylesCombo->addItems( QStyleFactory::keys() );
- stylesCombo->setCurrentIndex( stylesCombo->findText( initialStyle ) );
- stylesCombo->insertSeparator( 1 );
- if ( stylesCombo->currentIndex() < 0 )
- stylesCombo->setCurrentIndex( 0 ); /* default */
- }
-#endif
-
- QString getQStyleKey(const QComboBox *stylesCombo, const QString &defaultStyleName)
- {
- vlc_assert( stylesCombo );
- const int index = stylesCombo->currentIndex();
- if (stylesCombo->currentIndex() == 0)
- return defaultStyleName;
- return QStyleFactory::keys().at( index - 2 );
- }
-}
+static const QString styleSettingsKey = QStringLiteral("MainWindow/QtStyle");
class PropertyResetter
{
@@ -774,7 +752,25 @@ SPrefsPanel::SPrefsPanel( qt_intf_t *_p_intf, QWidget *_parent,
}
#if !defined( _WIN32)
- fillStylesCombo( ui.stylesCombo, getSettings()->value( "MainWindow/QtStyle", "" ).toString() );
+ {
+ // Populate styles combobox:
+ assert(qApp->property("initialStyle").isValid());
+ const QString& initialStyle = qApp->property("initialStyle").toString();
+ ui.stylesCombo->addItem( qtr( "System's default (%1)" ).arg( initialStyle ), initialStyle );
+ const QStringList& styles = QStyleFactory::keys();
+ for ( const auto& i : styles )
+ {
+ ui.stylesCombo->addItem( i, i );
+ }
+ const auto style = getSettings()->value( styleSettingsKey );
+
+ if ( style.isValid() && style.canConvert<QString>() )
+ ui.stylesCombo->setCurrentText( style.toString() );
+ ui.stylesCombo->insertSeparator( 1 );
+ if ( ui.stylesCombo->currentIndex() < 0 )
+ ui.stylesCombo->setCurrentIndex( 0 ); /* default */
+ }
+
m_resetters.push_back( std::make_unique<PropertyResetter>( ui.stylesCombo, "currentIndex" ) );
connect( ui.stylesCombo, QOverload<int>::of(&QComboBox::currentIndexChanged),
@@ -1242,7 +1238,10 @@ void SPrefsPanel::apply()
//if( m_interfaceUI.qt->isChecked() )
config_PutPsz( "intf", "" );
#if !defined( _WIN32)
- getSettings()->setValue( "MainWindow/QtStyle", getQStyleKey( m_interfaceUI.stylesCombo , "" ) );
+ if ( m_interfaceUI.stylesCombo->currentIndex() > 0 )
+ getSettings()->setValue( styleSettingsKey, m_interfaceUI.stylesCombo->currentData().toString() );
+ else
+ getSettings()->remove( styleSettingsKey );
#endif
#ifdef _WIN32
@@ -1350,14 +1349,13 @@ void SPrefsPanel::lastfm_Changed( int i_state )
void SPrefsPanel::changeStyle()
{
- const QString key = getQStyleKey( m_interfaceUI.stylesCombo,
- qApp->property("initialStyle").toString() );
+ const QString style = m_interfaceUI.stylesCombo->currentData().toString();
- QMetaObject::invokeMethod( qApp, [key]() {
+ QMetaObject::invokeMethod( qApp, [style]() {
// Queue this call in order to prevent
// updating the preferences dialog when
// it is rejected:
- QApplication::setStyle( key );
+ QApplication::setStyle( style );
}, Qt::QueuedConnection );
}
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/ac0545c6c51e18d7b5faf5a1d55bdab7e0bd6ac9
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/ac0545c6c51e18d7b5faf5a1d55bdab7e0bd6ac9
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list