Browse Source

qt: replace ADD_CATEGORY macro by a function in simpleprefs

pull/162/head
Pierre Lamot 3 years ago
committed by Rémi Denis-Courmont
parent
commit
ffb06c6013
  1. 65
      modules/gui/qt/dialogs/preferences/simple_preferences.cpp

65
modules/gui/qt/dialogs/preferences/simple_preferences.cpp

@ -244,42 +244,39 @@ SPrefsCatList::SPrefsCatList( qt_intf_t *_p_intf, QWidget *_parent ) :
See QT bugs 131 & 816 and QAbstractButton's source code. */ See QT bugs 131 & 816 and QAbstractButton's source code. */
QSignalMapper *mapper = new QSignalMapper( layout ); QSignalMapper *mapper = new QSignalMapper( layout );
connect( mapper, QSIGNALMAPPER_MAPPEDINT_SIGNAL, this, &SPrefsCatList::switchPanel ); connect( mapper, QSIGNALMAPPER_MAPPEDINT_SIGNAL, this, &SPrefsCatList::switchPanel );
QPixmap scaled;
qreal dpr = devicePixelRatioF(); qreal dpr = devicePixelRatioF();
#define ADD_CATEGORY( button, label, ltooltip, icon, numb ) \ auto addCategory = [&]( QString label, QString ltooltip, QString icon, int numb) {
QToolButton * button = new QToolButton( this ); \ QToolButton * button = new QToolButton( this );
/* Scale icon to non native size outside of toolbutton to avoid widget size */\ /* Scale icon to non native size outside of toolbutton to avoid widget size */
/* computation using native size */\ /* computation using native size */
scaled = QPixmap( icon )\ QPixmap scaled = QPixmap( icon )
.scaledToHeight( ICON_HEIGHT * dpr, Qt::SmoothTransformation );\ .scaledToHeight( ICON_HEIGHT * dpr, Qt::SmoothTransformation );
scaled.setDevicePixelRatio( dpr ); \ scaled.setDevicePixelRatio( dpr );
button->setIcon( scaled ); \ button->setIcon( scaled );
button->setText( label ); \ button->setText( label );
button->setToolTip( ltooltip ); \ button->setToolTip( ltooltip );
button->setToolButtonStyle( Qt::ToolButtonTextUnderIcon ); \ button->setToolButtonStyle( Qt::ToolButtonTextUnderIcon );
button->setIconSize( QSize( ICON_WIDTH, ICON_HEIGHT ) ); \ button->setIconSize( QSize( ICON_WIDTH, ICON_HEIGHT ) );
button->setMinimumWidth( 40 + ICON_WIDTH );\ button->setMinimumWidth( 40 + ICON_WIDTH );
button->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum); \ button->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum);
button->setAutoRaise( true ); \ button->setAutoRaise( true );
button->setCheckable( true ); \ button->setCheckable( true );
button->setAutoExclusive( true ); \ button->setAutoExclusive( true );
connect( button, &QToolButton::clicked, mapper, QOverload<>::of(&QSignalMapper::map) ); \ connect( button, &QToolButton::clicked, mapper, QOverload<>::of(&QSignalMapper::map) );
mapper->setMapping( button, numb ); \ mapper->setMapping( button, numb );
layout->addWidget( button ); layout->addWidget( button );
};
ADD_CATEGORY( SPrefsInterface, qfut(INTF_TITLE), qfut(INTF_TOOLTIP), ":/prefsmenu/spref_interface.png" , 0 );
ADD_CATEGORY( SPrefsAudio, qfut(AUDIO_TITLE), qfut(AUDIO_TOOLTIP), ":/prefsmenu/spref_audio.png", 1 ); addCategory( qfut(INTF_TITLE), qfut(INTF_TOOLTIP), ":/prefsmenu/spref_interface.png" , 0 );
ADD_CATEGORY( SPrefsVideo, qfut(VIDEO_TITLE), qfut(VIDEO_TOOLTIP), ":/prefsmenu/spref_video.png", 2 ); addCategory( qfut(AUDIO_TITLE), qfut(AUDIO_TOOLTIP), ":/prefsmenu/spref_audio.png", 1 );
ADD_CATEGORY( SPrefsSubtitles, qfut(SUBPIC_TITLE), qfut(SUBPIC_TOOLTIP), ":/prefsmenu/spref_subtitles.png", 3 ); addCategory( qfut(VIDEO_TITLE), qfut(VIDEO_TOOLTIP), ":/prefsmenu/spref_video.png", 2 );
ADD_CATEGORY( SPrefsInputAndCodecs, qfut(INPUT_TITLE), qfut(INPUT_TOOLTIP), ":/prefsmenu/spref_input.png", 4 ); addCategory( qfut(SUBPIC_TITLE), qfut(SUBPIC_TOOLTIP), ":/prefsmenu/spref_subtitles.png", 3 );
ADD_CATEGORY( SPrefsHotkeys, qfut(HOTKEYS_TITLE), qfut(HOTKEYS_TOOLTIP), ":/prefsmenu/spref_hotkeys.png", 5 ); addCategory( qfut(INPUT_TITLE), qfut(INPUT_TOOLTIP), ":/prefsmenu/spref_input.png", 4 );
ADD_CATEGORY( SPrefsMediaLibrary, qfut(ML_TITLE), qfut(ML_TOOLTIP), ":/prefsmenu/spref_medialibrary.png", 6 ); addCategory( qfut(HOTKEYS_TITLE), qfut(HOTKEYS_TOOLTIP), ":/prefsmenu/spref_hotkeys.png", 5 );
addCategory( qfut(ML_TITLE), qfut(ML_TOOLTIP), ":/prefsmenu/spref_medialibrary.png", 6 );
#undef ADD_CATEGORY
qobject_cast<QToolButton*>(mapper->mapping(0))->setChecked(true);
SPrefsInterface->setChecked( true );
layout->setContentsMargins(0, 0, 0, 0); layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing( 1 ); layout->setSpacing( 1 );

Loading…
Cancel
Save