#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "ui_qt_widgets.h" #include "ui_qt.h" #include "ui_qt_float_sync.h" /* RetroArch-internal headers are included here, OUTSIDE the extern "C" * block below. They self-guard their C declarations with * RETRO_BEGIN_DECLS / RETRO_END_DECLS, and several of them transitively * include libretro-common/include/retro_atomic.h, which in C++ mode * pulls in the C++ header. Templates inside extern "C" are a * hard error, so these must live outside the extern "C" block. */ #include "../../config.def.h" #include "../../command.h" #include "../../driver.h" #include "../../core_info.h" #include "../../core_option_manager.h" #include "../../file_path_special.h" #include "../../msg_hash.h" #include "../../paths.h" #include "../../tasks/tasks_internal.h" #include "../../verbosity.h" #include "../../version.h" #include "../../gfx/video_display_server.h" #include "../../input/input_driver.h" #include "../../input/input_remapping.h" #include "../../network/netplay/netplay.h" #include "../../playlist.h" #ifdef HAVE_MENU #include "../../menu/menu_driver.h" #include "../../menu/menu_entries.h" #include "../../menu/menu_displaylist.h" #if defined(HAVE_CG) || defined(HAVE_GLSL) || defined(HAVE_SLANG) || defined(HAVE_HLSL) #include "../../menu/menu_shader.h" #endif #endif #ifndef CXX_BUILD extern "C" { #endif #include #include #include #include #include #include #include #include #ifndef CXX_BUILD } #endif /* Replace characters unsafe in URLs / file names with '_' */ /* The hidden-playlist list (desktop_menu_hidden_playlists in * retroarch.cfg) is parsed and written by the shared core, in C: Qt's * own split() takes its empty-parts flag from Qt::SkipEmptyParts on * 5.14+ and QString::SkipEmptyParts before that, and string_split() * drops empty parts on every Qt back to 4. The natives use the same * two calls. */ static bool qt_playlist_hidden(const QString &path) { return companion_core_playlist_is_hidden(ui_companion_qt_core(), path.toUtf8().constData()); } static void qt_set_playlist_hidden(const QString &path, bool hidden) { companion_core_playlist_set_hidden(ui_companion_qt_core(), path.toUtf8().constData(), hidden); } #ifdef HAVE_MENU static const QRegularExpression decimalsRegex("%.(\\d)f"); /* Qt shows a plain-text tooltip on one line however long it is - a * sublabel paragraph ran the width of a 2560 px desktop. It wraps * rich text to a sane width, so tips go in as escaped rich text. */ static inline QString wrapped_tooltip(const char *text) { return QStringLiteral("") + QString::fromUtf8(text).toHtmlEscaped() + QStringLiteral(""); } static inline void add_sublabel_and_whats_this( QWidget *widget, rarch_setting_t *setting) { char tmp[512]; tmp[0] = '\0'; if (menu_cbs_sublabel_for_enum((enum msg_hash_enums)setting->enum_idx, (unsigned)setting->type, setting->size, tmp, sizeof(tmp))) widget->setToolTip(wrapped_tooltip(tmp)); msg_hash_get_help_enum((enum msg_hash_enums)setting->enum_idx, tmp, sizeof(tmp)); if (!string_is_equal(tmp, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NO_INFORMATION_AVAILABLE))) widget->setWhatsThis(tmp); } /* A setting's range is stored as float; converting a float outside * int range to int is undefined, and on x86 it produces INT_MIN, which * collapses a spin box's range to a single unreachable value. Bounds are * therefore clamped in double, where every int is exact, and an * unenforced or NaN bound takes the widget's own default. */ static int qt_setting_bound(const rarch_setting_t *setting, unsigned flag, double value, int fallback) { if (!(setting->flags & flag) || value != value) return fallback; if (value >= (double)INT_MAX) return INT_MAX; if (value <= (double)INT_MIN) return INT_MIN; return (int)value; } /* The most choices a radio-button group lays out. */ #define QT_RADIO_BUTTONS_MAX 256 /* The value a spin box can show for a stored value: the stored value * clamped to the box's range. The paint-time resync compares against * this, so an out-of-range stored value is shown at the nearest bound * once instead of being re-set (and repainted) on every paint. */ static int qt_spinbox_shown(const QSpinBox *box, double value) { if (value >= (double)box->maximum()) return box->maximum(); if (value <= (double)box->minimum()) return box->minimum(); return (int)value; } static inline QString sanitize_ampersand(QString input) { return input.replace("&", "&&"); } static inline QString form_label(rarch_setting_t *setting) { return QString(sanitize_ampersand(setting->short_description)) + ":"; } FormLayout::FormLayout(QWidget *parent) : QFormLayout(parent) { } void FormLayout::addCheckBox(rarch_setting_t *setting) { if (setting && setting->short_description) addRow(new CheckBox(setting)); } void FormLayout::addUIntRadioButtons(rarch_setting_t *setting) { if (setting && setting->short_description) addRow(new UIntRadioButtons(setting)); } void FormLayout::addUIntComboBox(rarch_setting_t *setting) { if (setting && setting->short_description) addRow(form_label(setting), new UIntComboBox(setting)); } void FormLayout::addStringComboBox(rarch_setting_t *setting) { if (setting && setting->short_description) addRow(form_label(setting), new StringComboBox(setting)); } void FormLayout::addStringLineEdit(rarch_setting_t *setting) { if (setting && setting->short_description) addRow(form_label(setting), new StringLineEdit(setting)); } void FormLayout::addPasswordLineEdit(rarch_setting_t *setting) { if (setting && setting->short_description) addRow(form_label(setting), new PasswordLineEdit(setting)); } void FormLayout::addUIntSpinBox(rarch_setting_t *setting) { if (setting && setting->short_description) { /* Small, discrete integer settings with a representation callback * are enumerations, not numeric quantities. Use the same labels as * RetroArch's menu instead of exposing their internal integer values. */ if (setting->actions && setting->actions->repr && setting->step == 1.0f && (setting->flags & SD_FLAG_ENFORCE_MINRANGE) && (setting->flags & SD_FLAG_ENFORCE_MAXRANGE) && setting->max >= setting->min && (setting->max - setting->min) <= 32.0f) addRow(form_label(setting), new UIntComboBox(setting, setting->min, setting->max)); else { UIntSpinBox *spinBox = new UIntSpinBox(setting); if (setting->enum_idx == MENU_ENUM_LABEL_MENU_SCROLL_DELAY) spinBox->setMaximumWidth(150); addRow(form_label(setting), spinBox); } } } void FormLayout::addSizeSpinBox(rarch_setting_t *setting, unsigned scale) { if (setting && setting->short_description) addRow(form_label(setting), new SizeSpinBox(setting, scale)); } void FormLayout::addFloatSpinBox(rarch_setting_t *setting) { if (setting && setting->short_description) addRow(form_label(setting), new FloatSpinBox(setting)); } void FormLayout::addRefreshRateControl(rarch_setting_t *setting) { if (setting && setting->short_description) addRow(form_label(setting), new RefreshRateControl(setting)); } void FormLayout::addDirectorySelector(rarch_setting_t *setting) { if (setting && setting->short_description) addRow(form_label(setting), new DirectorySelector(setting)); } void FormLayout::addFileSelector(rarch_setting_t *setting) { if (setting && setting->short_description) addRow(form_label(setting), new FileSelector(setting)); } void FormLayout::addFloatSliderAndSpinBox(rarch_setting_t *setting) { if (setting && setting->short_description) addRow(form_label(setting), new FloatSliderAndSpinBox(setting)); } void FormLayout::addUIntColorButton(const QString &title, msg_hash_enums r, msg_hash_enums g, msg_hash_enums b) { rarch_setting_t *red = menu_setting_find_enum(r); rarch_setting_t *green = menu_setting_find_enum(g); rarch_setting_t *blue = menu_setting_find_enum(b); if (red && green && blue) addRow(title, new UIntColorButton(red, green, blue)); } bool FormLayout::addBindButton(rarch_setting_t *setting) { if (!setting || !setting->short_description) return false; addRow(QString(setting->short_description), new BindButton(setting)); return true; } SettingsGroup::SettingsGroup(const QString &title, QWidget *parent) : QGroupBox(title, parent) ,m_layout(new FormLayout(this)) { } SettingsGroup::SettingsGroup(QWidget *parent) : QGroupBox(parent) ,m_layout(new FormLayout(this)) { } void SettingsGroup::addWidget(QWidget *widget) { m_layout->addWidget(widget); } void SettingsGroup::addRow(QString label, QWidget *widget) { m_layout->addRow(label, widget); } void SettingsGroup::addRow(QWidget *widget) { m_layout->addRow(widget); } void SettingsGroup::addRow(QLayout *layout) { m_layout->addRow(layout); } void SettingsGroup::addRow(QString label, QLayout *layout) { m_layout->addRow(label, layout); } /* Add a path setting as a compact horizontal row. This avoids the wide label * column reserved by QFormLayout and gives the editable path more room. */ static void qt_settings_group_add_compact_path(SettingsGroup *group, enum msg_hash_enums enum_idx, bool isDirectory) { rarch_setting_t *setting = menu_setting_find_enum(enum_idx); QHBoxLayout *row; QLabel *textLabel; if (!group || !setting || !setting->short_description) return; /* The setting's own (translated) label, as every other row uses. */ row = new QHBoxLayout; textLabel = new QLabel(form_label(setting)); textLabel->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred); row->addWidget(textLabel); if (isDirectory) row->addLayout(new DirectorySelector(setting)); else row->addWidget(new StringLineEdit(setting)); group->addRow(row); } void SettingsGroup::addCheckBox(rarch_setting_t *setting) { m_layout->addCheckBox(setting); } void SettingsGroup::addDirectorySelector(rarch_setting_t *setting) { m_layout->addDirectorySelector(setting); } void SettingsGroup::addFileSelector(rarch_setting_t *setting) { m_layout->addFileSelector(setting); } void SettingsGroup::addStringLineEdit(rarch_setting_t *setting) { m_layout->addStringLineEdit(setting); } void SettingsGroup::addPasswordLineEdit(rarch_setting_t *setting) { m_layout->addPasswordLineEdit(setting); } void SettingsGroup::addStringComboBox(rarch_setting_t *setting) { m_layout->addStringComboBox(setting); } void SettingsGroup::addUIntComboBox(rarch_setting_t *setting) { m_layout->addUIntComboBox(setting); } void SettingsGroup::addUIntRadioButtons(rarch_setting_t *setting) { m_layout->addUIntRadioButtons(setting); } void SettingsGroup::addUIntSpinBox(rarch_setting_t *setting) { m_layout->addUIntSpinBox(setting); } void SettingsGroup::addFloatSpinBox(rarch_setting_t *setting) { m_layout->addFloatSpinBox(setting); } void SettingsGroup::addRefreshRateControl(rarch_setting_t *setting) { m_layout->addRefreshRateControl(setting); } void SettingsGroup::addFloatSliderAndSpinBox(rarch_setting_t *setting) { m_layout->addFloatSliderAndSpinBox(setting); } void SettingsGroup::addUIntColorButton(const QString &title, msg_hash_enums r, msg_hash_enums g, msg_hash_enums b) { m_layout->addUIntColorButton(title, r, g, b); } void SettingsGroup::addBindButton(rarch_setting_t *setting) { m_layout->addBindButton(setting); } CheckBox::CheckBox(rarch_setting_t *setting, QWidget *parent) : QCheckBox(sanitize_ampersand(setting->short_description), parent) ,m_setting(setting) ,m_value(setting->value.target.boolean) { QAbstractButton::setChecked(*m_value); /* TODO/FIXME only one of these should be necessary */ connect(this, SIGNAL(toggled(bool)), this, SLOT(onClicked(bool))); connect(this, SIGNAL(clicked(bool)), this, SLOT(onClicked(bool))); add_sublabel_and_whats_this(this, m_setting); } CheckBox::CheckBox(msg_hash_enums enum_idx, QWidget *parent) : CheckBox(menu_setting_find_enum(enum_idx), parent) { } void CheckBox::onClicked(bool checked) { *m_value = checked; setting_generic_handle_change(m_setting); } void CheckBox::paintEvent(QPaintEvent *event) { if (*m_value != QAbstractButton::isChecked()) { blockSignals(true); QAbstractButton::setChecked(*m_value); blockSignals(false); } QCheckBox::paintEvent(event); } CheckableSettingsGroup::CheckableSettingsGroup(rarch_setting_t *setting, QWidget *parent) : SettingsGroup(parent) { if (setting && setting->short_description) { m_setting = setting; m_value = setting->value.target.boolean; setTitle(setting->short_description); setCheckable(true); setChecked(*m_value); connect(this, SIGNAL(clicked(bool)), this, SLOT(onClicked(bool))); add_sublabel_and_whats_this(this, m_setting); } } CheckableSettingsGroup::CheckableSettingsGroup(msg_hash_enums enum_idx, QWidget *parent) : CheckableSettingsGroup(menu_setting_find_enum(enum_idx), parent) { } void CheckableSettingsGroup::onClicked(bool checked) { *m_value = checked; setting_generic_handle_change(m_setting); } void CheckableSettingsGroup::paintEvent(QPaintEvent *event) { if (*m_value != isChecked()) { blockSignals(true); setChecked(*m_value); blockSignals(false); } QGroupBox::paintEvent(event); } CheckableIcon::CheckableIcon(msg_hash_enums enum_idx, const QIcon &icon, QWidget *parent) : CheckableIcon(menu_setting_find_enum(enum_idx), icon, parent) { } CheckableIcon::CheckableIcon(rarch_setting_t *setting, const QIcon &icon, QWidget *parent) : QToolButton(parent) ,m_setting(setting) ,m_value(setting->value.target.boolean) { setIcon(icon); setCheckable(true); QAbstractButton::setChecked(*m_value); connect(this, SIGNAL(toggled(bool)), this, SLOT(onToggled(bool))); add_sublabel_and_whats_this(this, m_setting); } void CheckableIcon::onToggled(bool checked) { *m_value = QAbstractButton::isChecked(); setting_generic_handle_change(m_setting); QAbstractButton::setChecked(checked); } void CheckableIcon::paintEvent(QPaintEvent *event) { if (QAbstractButton::isChecked() != *m_value) { blockSignals(true); QAbstractButton::setChecked(*m_value); blockSignals(false); } QToolButton::paintEvent(event); } StringLineEdit::StringLineEdit(rarch_setting_t *setting, QWidget *parent) : QLineEdit(setting->value.target.string) ,m_setting(setting) ,m_value(setting->value.target.string) { connect(this, SIGNAL(editingFinished()), this, SLOT(onEditingFinished())); add_sublabel_and_whats_this(this, m_setting); } void StringLineEdit::onEditingFinished() { strlcpy(m_value, text().toUtf8().data(), m_setting->size); setting_generic_handle_change(m_setting); setModified(false); } void StringLineEdit::paintEvent(QPaintEvent *event) { if (!isModified() && m_value != text()) { setText(m_value); setModified(false); } QLineEdit::paintEvent(event); } PasswordLineEdit::PasswordLineEdit(rarch_setting_t *setting, QWidget *parent) : StringLineEdit(setting) { setEchoMode(QLineEdit::Password); } StringComboBox::StringComboBox(rarch_setting_t *setting, QWidget *parent) : QComboBox(parent) ,m_setting(setting) ,m_value(setting->value.target.string) { addItems(QString(setting->aux.values).split('|')); connect(this, SIGNAL(currentTextChanged(const QString&)), this, SLOT(onCurrentTextChanged(const QString&))); add_sublabel_and_whats_this(this, m_setting); } void StringComboBox::onCurrentTextChanged(const QString &text) { strlcpy(m_value, text.toUtf8().data(), m_setting->size); setting_generic_handle_change(m_setting); } void StringComboBox::paintEvent(QPaintEvent *event) { setCurrentText(m_value); QComboBox::paintEvent(event); } UIntComboBox::UIntComboBox(rarch_setting_t *setting, QWidget *parent) : QComboBox(parent) ,m_setting(setting) { float min = (setting->flags & SD_FLAG_ENFORCE_MINRANGE) ? setting->min : 0.00f; float max = (setting->flags & SD_FLAG_ENFORCE_MAXRANGE) ? setting->max : 999.00f; populate(min, max); connect(this, SIGNAL(currentIndexChanged(int)), this, SLOT(onCurrentIndexChanged(int))); add_sublabel_and_whats_this(this, m_setting); } UIntComboBox::UIntComboBox(rarch_setting_t *setting, double min, double max, QWidget *parent) : QComboBox(parent) ,m_setting(setting) { populate(min, max); connect(this, SIGNAL(currentIndexChanged(int)), this, SLOT(onCurrentIndexChanged(int))); add_sublabel_and_whats_this(this, m_setting); } void UIntComboBox::populate(double min, double max) { float i; unsigned orig_value = setting_uint_get(m_setting); float step = m_setting->step; bool checked_found = false; unsigned count = 0; if (m_setting->actions->repr) { for (i = min; i <= max; i += step) { char val_s[NAME_MAX_LENGTH]; unsigned val = (unsigned)i; setting_uint_set(m_setting, val); m_setting->actions->repr(m_setting, val_s, sizeof(val_s)); m_hash[i] = QString(val_s); addItem(m_hash[i], i); if (!checked_found && val == orig_value) { setCurrentIndex(count); checked_found = true; } count++; } setting_uint_set(m_setting, orig_value); } } UIntComboBox::UIntComboBox(msg_hash_enums enum_idx, QWidget *parent) : UIntComboBox(menu_setting_find_enum(enum_idx), parent) { } UIntComboBox::UIntComboBox(msg_hash_enums enum_idx, double min, double max, QWidget *parent) : UIntComboBox(menu_setting_find_enum(enum_idx), min, max, parent) { } void UIntComboBox::onCurrentIndexChanged(int index) { (void)(index); setting_uint_set(m_setting, currentData().toUInt()); setting_generic_handle_change(m_setting); } void UIntComboBox::paintEvent(QPaintEvent *event) { setCurrentText(m_hash.value(setting_uint_get(m_setting))); QComboBox::paintEvent(event); } UIntSpinBox::UIntSpinBox(rarch_setting_t *setting, QWidget *parent) : QSpinBox(parent) ,m_setting(setting) { setRange( qt_setting_bound(setting, SD_FLAG_ENFORCE_MINRANGE, setting->min, 0), qt_setting_bound(setting, SD_FLAG_ENFORCE_MAXRANGE, setting->max, INT_MAX)); setSingleStep(setting->step); connect(this, SIGNAL(valueChanged(int)), this, SLOT(onValueChanged(int))); add_sublabel_and_whats_this(this, m_setting); } UIntSpinBox::UIntSpinBox(msg_hash_enums enum_idx, QWidget *parent) : UIntSpinBox(menu_setting_find_enum(enum_idx), parent) { } void UIntSpinBox::onValueChanged(int value) { setting_uint_set(m_setting, (unsigned)value); setting_generic_handle_change(m_setting); } void UIntSpinBox::paintEvent(QPaintEvent *event) { int shown = qt_spinbox_shown(this, (double)setting_uint_get(m_setting)); if (value() != shown) { blockSignals(true); setValue(shown); blockSignals(false); } QSpinBox::paintEvent(event); } SizeSpinBox::SizeSpinBox(rarch_setting_t *setting, unsigned scale, QWidget *parent) : QSpinBox(parent) ,m_setting(setting) ,m_value(setting->value.target.sizet) ,m_scale(scale) { setRange( qt_setting_bound(setting, SD_FLAG_ENFORCE_MINRANGE, (double)setting->min / m_scale, 0), qt_setting_bound(setting, SD_FLAG_ENFORCE_MAXRANGE, (double)setting->max / m_scale, INT_MAX)); setSingleStep(setting->step / m_scale); setValue(*m_value / m_scale); connect(this, SIGNAL(valueChanged(int)), this, SLOT(onValueChanged(int))); add_sublabel_and_whats_this(this, m_setting); } SizeSpinBox::SizeSpinBox(msg_hash_enums enum_idx, unsigned scale, QWidget *parent) : SizeSpinBox(menu_setting_find_enum(enum_idx), scale, parent) { } void SizeSpinBox::onValueChanged(int value) { *m_value = value * m_scale; setting_generic_handle_change(m_setting); } void SizeSpinBox::paintEvent(QPaintEvent *event) { int shown = qt_spinbox_shown(this, (double)(*m_value / m_scale)); if (value() != shown) { blockSignals(true); setValue(shown); blockSignals(false); } QSpinBox::paintEvent(event); } UIntRadioButton::UIntRadioButton(msg_hash_enums enum_idx, unsigned value, QWidget *parent) : QRadioButton(parent) ,m_setting(menu_setting_find_enum(enum_idx)) ,m_value(value) { char val_s[NAME_MAX_LENGTH]; unsigned orig_value = setting_uint_get(m_setting); setting_uint_set(m_setting, value); m_setting->actions->repr(m_setting, val_s, sizeof(val_s)); setting_uint_set(m_setting, orig_value); setText(val_s); if (m_value == orig_value) setChecked(true); connect(this, SIGNAL(clicked(bool)), this, SLOT(onClicked(bool))); } UIntRadioButton::UIntRadioButton(const QString &text, rarch_setting_t *setting, unsigned value, QWidget *parent) : QRadioButton(text, parent) ,m_setting(setting) ,m_value(value) { connect(this, SIGNAL(clicked(bool)), this, SLOT(onClicked(bool))); } void UIntRadioButton::onClicked(bool) { setting_uint_set(m_setting, m_value); setting_generic_handle_change(m_setting); } void UIntRadioButton::paintEvent(QPaintEvent *event) { if (setting_uint_get(m_setting) == m_value) setChecked(true); else setChecked(false); QRadioButton::paintEvent(event); } UIntRadioButtons::UIntRadioButtons(rarch_setting_t *setting, QWidget *parent) : QGroupBox(setting->short_description, parent) ,m_setting(setting) ,m_buttonGroup(new QButtonGroup(this)) { QVBoxLayout *layout = new QVBoxLayout(this); /* The choices are enumerated in unsigned integers: a float counter * stops advancing past 2^24, and a missing or non-positive step * would never reach the end. The button id is an int, so the range * is bounded to [0, INT_MAX], and at most QT_RADIO_BUTTONS_MAX * buttons are made, which also bounds a row with no enforced * maximum. */ unsigned orig_value = setting_uint_get(setting); unsigned min = (unsigned)qt_setting_bound(setting, SD_FLAG_ENFORCE_MINRANGE, setting->min < 0.0f ? 0.0 : setting->min, 0); unsigned max = (unsigned)qt_setting_bound(setting, SD_FLAG_ENFORCE_MAXRANGE, setting->max < 0.0f ? 0.0 : setting->max, INT_MAX); unsigned step = 1; bool checked_found = false; if (setting->step >= (float)INT_MAX) step = INT_MAX; else if (setting->step >= 1.0f) step = (unsigned)setting->step; if (setting->actions->repr && min <= max) { unsigned i = min; unsigned count = 0; for (;;) { char val_s[NAME_MAX_LENGTH]; QRadioButton *button = NULL; setting_uint_set(setting, i); setting->actions->repr(setting, val_s, sizeof(val_s)); button = new QRadioButton(QString(val_s), this); m_buttonGroup->addButton(button, (int)i); layout->addWidget(button); if (!checked_found && i == orig_value) { button->setChecked(true); checked_found = true; } if (++count >= QT_RADIO_BUTTONS_MAX || max - i < step) break; i += step; } setting_uint_set(setting, orig_value); } add_sublabel_and_whats_this(this, m_setting); #if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) connect(m_buttonGroup, &QButtonGroup::idClicked, this, &UIntRadioButtons::onButtonClicked); #else connect(m_buttonGroup, SIGNAL(buttonClicked(int)), this, SLOT(onButtonClicked(int))); #endif } UIntRadioButtons::UIntRadioButtons(msg_hash_enums enum_idx, QWidget *parent) : UIntRadioButtons(menu_setting_find_enum(enum_idx), parent) { } void UIntRadioButtons::onButtonClicked(int id) { setting_uint_set(m_setting, (unsigned)id); setting_generic_handle_change(m_setting); } IntSpinBox::IntSpinBox(rarch_setting_t *setting, QWidget *parent) : QSpinBox(parent) ,m_setting(setting) { setRange( qt_setting_bound(setting, SD_FLAG_ENFORCE_MINRANGE, setting->min, INT_MIN), qt_setting_bound(setting, SD_FLAG_ENFORCE_MAXRANGE, setting->max, INT_MAX)); setSingleStep(setting->step); connect(this, SIGNAL(valueChanged(int)), this, SLOT(onValueChanged(int))); add_sublabel_and_whats_this(this, m_setting); } void IntSpinBox::onValueChanged(int value) { setting_int_set(m_setting, value); setting_generic_handle_change(m_setting); } void IntSpinBox::paintEvent(QPaintEvent *event) { int shown = qt_spinbox_shown(this, (double)setting_int_get(m_setting)); if (value() != shown) { blockSignals(true); setValue(shown); blockSignals(false); } QSpinBox::paintEvent(event); } RefreshRateControl::RefreshRateControl(rarch_setting_t *setting, QWidget *parent) : QWidget(parent) ,m_setting(setting) ,m_slider(new QSlider(Qt::Horizontal, this)) ,m_spinBox(new QDoubleSpinBox(this)) ,m_scale(1) ,m_synced(*setting->value.target.fraction) ,m_dirty(false) { int i; QPushButton *setButton = new QPushButton(QObject::tr("Set"), this); const char *fmt = setting->aux.rounding_fraction; /* "%.Nf" - read N directly instead of compiling a regex per widget. */ int decimals = (fmt && fmt[0] == '%' && fmt[1] == '.' && fmt[2] >= '0' && fmt[2] <= '9' && fmt[3] == 'f') ? fmt[2] - '0' : 3; for (i = 0; i < decimals; i++) m_scale *= 10; m_spinBox->setDecimals(decimals); m_spinBox->setRange( (setting->flags & SD_FLAG_ENFORCE_MINRANGE) ? setting->min : 0.0, (setting->flags & SD_FLAG_ENFORCE_MAXRANGE) ? setting->max : 999.0); m_spinBox->setSingleStep(setting->step > 0.0f ? setting->step : 0.001f); m_spinBox->setValue(*setting->value.target.fraction); m_slider->setRange( (int)(m_spinBox->minimum() * m_scale), (int)(m_spinBox->maximum() * m_scale)); m_slider->setSingleStep(qMax(1, (int)(m_spinBox->singleStep() * m_scale))); m_slider->setPageStep(qMax(1, m_scale / 10)); m_slider->setValue((int)(m_spinBox->value() * m_scale)); setButton->setAutoDefault(false); QHBoxLayout *layout = new QHBoxLayout(this); layout->setContentsMargins(0, 0, 0, 0); layout->addWidget(m_slider, 1); layout->addWidget(m_spinBox); layout->addWidget(setButton); connect(m_slider, &QSlider::valueChanged, this, [this](int value) { m_dirty = true; m_spinBox->setValue((double)value / m_scale); }); connect(m_spinBox, QOverload::of(&QDoubleSpinBox::valueChanged), this, [this](double value) { m_dirty = true; m_slider->setValue((int)(value * m_scale + 0.5)); }); connect(setButton, &QPushButton::clicked, this, [this]() { float refresh_rate = (float)m_spinBox->value(); /* Use the same driver path as the display-reported action. This also * updates settings->floats.video_refresh_rate and emits RetroArch's * standard refresh-rate OSD notification. */ driver_ctl(RARCH_DRIVER_CTL_SET_REFRESH_RATE, &refresh_rate); command_event(CMD_EVENT_VIDEO_SET_BLOCKING_STATE, NULL); m_dirty = false; if (ui_qt_float_resync(&m_synced, *m_setting->value.target.fraction)) syncValue(); }); add_sublabel_and_whats_this(m_spinBox, setting); } void RefreshRateControl::syncValue() { float value = *m_setting->value.target.fraction; QSignalBlocker sliderBlock(m_slider); QSignalBlocker spinBlock(m_spinBox); m_spinBox->setValue(value); m_slider->setValue((int)(value * m_scale + 0.5)); } void RefreshRateControl::paintEvent(QPaintEvent *event) { QWidget::paintEvent(event); /* The display-reported action updates the same RetroArch setting through * the driver. Refresh this staged editor when that happens externally, * but never overwrite an uncommitted value being edited here. */ if (!m_dirty && ui_qt_float_resync(&m_synced, *m_setting->value.target.fraction)) syncValue(); } FloatSpinBox::FloatSpinBox(msg_hash_enums enum_idx, QWidget *parent) : FloatSpinBox(menu_setting_find_enum(enum_idx), parent) { } const QRegularExpression FloatSpinBox::DECIMALS_REGEX = QRegularExpression("%.(\\d)f"); FloatSpinBox::FloatSpinBox(rarch_setting_t *setting, QWidget *parent) : QDoubleSpinBox(parent) ,m_setting(setting) ,m_value(setting->value.target.fraction) { QRegularExpressionMatch match = DECIMALS_REGEX.match(setting->aux.rounding_fraction); if (match.hasMatch()) setDecimals(match.captured(1).toInt()); setMinimum((setting->flags & SD_FLAG_ENFORCE_MINRANGE) ? setting->min : 0.00f); setMaximum((setting->flags & SD_FLAG_ENFORCE_MAXRANGE) ? setting->max : 999.00f); setValue(*m_value); m_synced = *m_value; setSingleStep(setting->step); /* Commit typed values when the user presses Return or leaves the * field: with keyboard tracking off, QAbstractSpinBox emits * valueChanged() exactly once at that point (and only if the value * changed), instead of once per keystroke. */ setKeyboardTracking(false); connect(this, SIGNAL(valueChanged(double)), this, SLOT(onValueChanged(double))); add_sublabel_and_whats_this(this, m_setting); } void FloatSpinBox::onValueChanged(double value) { *m_value = (float)value; m_synced = *m_value; /* Match the internal menu's ordinary float-setting path: update the * setting value, then let its generic change handler mark the settings * modified and run any descriptor-specific change callback. In * particular, do not invoke the separate display-reported refresh-rate * action when editing VIDEO_REFRESH_RATE. */ setting_generic_handle_change(m_setting); } void FloatSpinBox::paintEvent(QPaintEvent *event) { if (ui_qt_float_resync(&m_synced, *m_value)) { blockSignals(true); if (*m_value < minimum() || *m_value > maximum()) { *m_value = m_setting->default_value.fraction; m_synced = *m_value; } setValue(*m_value); blockSignals(false); } QDoubleSpinBox::paintEvent(event); } PathButton::PathButton(rarch_setting_t *setting, QWidget *parent) : QPushButton("Browse...", parent) ,m_setting(setting) ,m_value(setting->value.target.string) ,m_dir(setting->default_value.string) { connect(this, SIGNAL(clicked(bool)), this, SLOT(onClicked(bool))); add_sublabel_and_whats_this(this, m_setting); } QString PathButton::currentPath() { QString current(m_setting->value.target.string); if (current.isEmpty()) current = m_setting->default_value.string; return current; } void DirectoryButton::onClicked(bool) { QString dir = QFileDialog::getExistingDirectory( this, "Choose " + QString(m_setting->short_description) + " Directory", currentPath()); if (!dir.isNull()) { strlcpy(m_setting->value.target.string, QDir::toNativeSeparators(dir).toUtf8().data(), m_setting->size); setting_generic_handle_change(m_setting); } emit changed(); } void FileButton::onClicked(bool) { QString file = QFileDialog::getOpenFileName( this, "Choose File", currentPath(), QString(m_setting->short_description) + " (*." + QString(m_setting->aux.values) + ")"); if (!file.isNull()) { strlcpy(m_setting->value.target.string, QDir::toNativeSeparators(file).toUtf8().data(), m_setting->size); setting_generic_handle_change(m_setting); } emit changed(); } DirectorySelector::DirectorySelector(rarch_setting_t *setting, QWidget *parent) : QHBoxLayout(parent) ,m_lineEdit(new StringLineEdit(setting)) ,m_button(new DirectoryButton(setting)) { addWidget(m_lineEdit); addWidget(m_button); connect(m_button, SIGNAL(changed()), m_lineEdit, SLOT(update())); } FileSelector::FileSelector(rarch_setting_t *setting, QWidget *parent) : QHBoxLayout(parent) ,m_lineEdit(new StringLineEdit(setting)) ,m_button(new FileButton(setting)) { addWidget(m_lineEdit); addWidget(m_button); connect(m_button, SIGNAL(changed()), m_lineEdit, SLOT(update())); } FloatSlider::FloatSlider(rarch_setting_t *setting, QWidget *parent) : QSlider(Qt::Horizontal, parent) ,m_setting(setting) ,m_value(setting->value.target.fraction) ,m_decimalsRegEx("%.(\\d)f") { QRegularExpressionMatch match = m_decimalsRegEx.match(setting->aux.rounding_fraction); if (match.hasMatch()) m_precision = pow(10, match.captured(1).toInt()); else m_precision = 10 * 10 * 10; setMinimum((setting->flags & SD_FLAG_ENFORCE_MINRANGE) ? setting->min * m_precision : 0.00f * m_precision); setMaximum((setting->flags & SD_FLAG_ENFORCE_MAXRANGE) ? setting->max * m_precision : 999.00f * m_precision); setSingleStep(setting->step * m_precision); setValue(*m_value * m_precision); m_synced = *m_value; connect(this, SIGNAL(valueChanged(int)), this, SLOT(onValueChanged(int))); add_sublabel_and_whats_this(this, m_setting); } void FloatSlider::onValueChanged(int value) { *m_value = (float)value / m_precision; m_synced = *m_value; setting_generic_handle_change(m_setting); } void FloatSlider::paintEvent(QPaintEvent *event) { if (ui_qt_float_resync(&m_synced, *m_value)) { blockSignals(true); setValue(*m_value * m_precision); blockSignals(false); } QSlider::paintEvent(event); } FloatSliderAndSpinBox::FloatSliderAndSpinBox(msg_hash_enums enum_idx, QWidget *parent) : FloatSliderAndSpinBox(menu_setting_find_enum(enum_idx), parent) { } FloatSliderAndSpinBox::FloatSliderAndSpinBox(rarch_setting_t *setting, QWidget *parent) : QHBoxLayout(parent) ,m_slider(new FloatSlider(setting)) ,m_spinBox(new FloatSpinBox(setting)) { addWidget(m_slider); addWidget(m_spinBox); connect(m_slider, SIGNAL(valueChanged(int)), this, SLOT(onSliderValueChanged(int))); connect(m_spinBox, SIGNAL(valueChanged(double)), this, SLOT(onSpinBoxValueChanged(double))); } void FloatSliderAndSpinBox::onSliderValueChanged(int value) { (void)(value); m_spinBox->update(); } void FloatSliderAndSpinBox::onSpinBoxValueChanged(double value) { (void)(value); m_slider->update(); } BindButton::BindButton(rarch_setting_t *setting, QWidget *parent) : QPushButton(parent) ,m_setting(setting) { char val_s[NAME_MAX_LENGTH]; setting->actions->repr(setting, val_s, sizeof(val_s)); setText(val_s); setAutoDefault(false); connect(this, SIGNAL(clicked(bool)), this, SLOT(onClicked(bool))); } BindButton::BindButton(msg_hash_enums enum_idx, QWidget *parent) : BindButton(menu_setting_find_enum(enum_idx), parent) { } void BindButton::onClicked(bool checked) { (void)(checked); m_setting->actions->ok(m_setting, 0, false); } ColorButton::ColorButton(rarch_setting_t *red, rarch_setting_t *green, rarch_setting_t *blue, QWidget *parent) : QToolButton(parent) ,m_red(red) ,m_green(green) ,m_blue(blue) ,m_dialog(new QColorDialog(this)) { setMinimumSize(64, 0); m_dialog->setOptions(QColorDialog::NoButtons); connect(this, SIGNAL(clicked()), m_dialog, SLOT(open())); connect(m_dialog, SIGNAL(currentColorChanged(const QColor&)), this, SLOT(onColorChanged(const QColor&))); } ColorButton::ColorButton(msg_hash_enums red, msg_hash_enums green, msg_hash_enums blue, QWidget *parent) : ColorButton(menu_setting_find_enum(red), menu_setting_find_enum(green), menu_setting_find_enum(blue), parent) { } /* Stolen from Qt Creator's QtColorButton */ void ColorButton::paintEvent(QPaintEvent *event) { const int pixSize = 10; const int corr = 5; const QColor frameColor1(0, 0, 0, 26); const QColor frameColor2(0, 0, 0, 51); QToolButton::paintEvent(event); if (!isEnabled()) return; QBrush br(color()); QPainter p(this); QRect r = rect().adjusted(corr, corr, -corr, -corr); p.setBrushOrigin((r.width() % pixSize + pixSize) / 2 + corr, (r.height() % pixSize + pixSize) / 2 + corr); p.fillRect(r, br); p.setPen(frameColor1); p.drawRect(r.adjusted(1, 1, -2, -2)); p.setPen(frameColor2); p.drawRect(r.adjusted(0, 0, -1, -1)); } UIntColorButton::UIntColorButton(msg_hash_enums red, msg_hash_enums green, msg_hash_enums blue, QWidget *parent) : ColorButton(red, green, blue, parent) { } UIntColorButton::UIntColorButton(rarch_setting_t *red, rarch_setting_t *green, rarch_setting_t *blue, QWidget *parent) : ColorButton(red, green, blue, parent) { } void UIntColorButton::onColorChanged(const QColor &color) { if (color.isValid()) { *m_red->value.target.unsigned_integer = color.red(); *m_green->value.target.unsigned_integer = color.green(); *m_blue->value.target.unsigned_integer = color.blue(); } } QColor UIntColorButton::color() { return QColor( *m_red->value.target.unsigned_integer, *m_green->value.target.unsigned_integer, *m_blue->value.target.unsigned_integer); } FloatColorButton::FloatColorButton(msg_hash_enums red, msg_hash_enums green, msg_hash_enums blue, QWidget *parent) : ColorButton(red, green, blue, parent) { } void FloatColorButton::onColorChanged(const QColor &color) { if (color.isValid()) { *m_red->value.target.fraction = color.red() / 255.0f; *m_green->value.target.fraction = color.green() / 255.0f; *m_blue->value.target.fraction = color.blue() / 255.0f; } } QColor FloatColorButton::color() { return QColor( *m_red->value.target.fraction * 255, *m_green->value.target.fraction * 255, *m_blue->value.target.fraction * 255); } #endif FileDropWidget::FileDropWidget(QWidget *parent) : QStackedWidget(parent) { setAcceptDrops(true); } void FileDropWidget::paintEvent(QPaintEvent *event) { QStyleOption o; QPainter p; o.initFrom(this); p.begin(this); style()->drawPrimitive( QStyle::PE_Widget, &o, &p, this); p.end(); QWidget::paintEvent(event); } void FileDropWidget::keyPressEvent(QKeyEvent *event) { int key = event->key(); if ( key == Qt::Key_Return || key == Qt::Key_Enter) { event->accept(); emit enterPressed(); } else if (key == Qt::Key_Delete) { event->accept(); emit deletePressed(); } else QWidget::keyPressEvent(event); } void FileDropWidget::dragEnterEvent(QDragEnterEvent *event) { const QMimeData *data = event->mimeData(); if (data->hasUrls()) event->acceptProposedAction(); } /* Workaround for QTBUG-72844. Without it, you can't drop on this if you * first drag over another widget that doesn't accept drops. */ void FileDropWidget::dragMoveEvent(QDragMoveEvent *event) { event->acceptProposedAction(); } void FileDropWidget::dropEvent(QDropEvent *event) { const QMimeData *data = event->mimeData(); if (data->hasUrls()) { int i; QStringList files; QList urls = data->urls(); for (i = 0; i < urls.count(); i++) { QString path(urls.at(i).toLocalFile()); files.append(path); } emit filesDropped(files); } } void MainWindow::onFileDropWidgetContextMenuRequested(const QPoint &pos) { QScopedPointer menu; QScopedPointer downloadThumbnailAction; QScopedPointer addEntryAction; QScopedPointer addFilesAction; QScopedPointer addFolderAction; QScopedPointer editAction; QScopedPointer deleteAction; QPointer selectedAction; QPoint cursorPos = QCursor::pos(); PlaylistEntry currentEntry = getCurrentContentEntry(); bool specialPlaylist = currentPlaylistIsSpecial(); bool allPlaylist = currentPlaylistIsAll(); bool actionsAdded = false; menu.reset(new QMenu(this)); if (!specialPlaylist) { downloadThumbnailAction.reset(new QAction( QString(msg_hash_to_str( MENU_ENUM_LABEL_VALUE_QT_DOWNLOAD_THUMBNAIL)), this)); menu->addAction(downloadThumbnailAction.data()); } if (!allPlaylist) { addEntryAction.reset(new QAction(QString(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_ADD_ENTRY)), this)); menu->addAction(addEntryAction.data()); addFilesAction.reset(new QAction(QString(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_ADD_FILES)), this)); menu->addAction(addFilesAction.data()); addFolderAction.reset(new QAction(QString(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_ADD_FOLDER)), this)); menu->addAction(addFolderAction.data()); editAction.reset(new QAction(QString(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_EDIT)), this)); deleteAction.reset(new QAction(QString(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_DELETE)), this)); if (!currentEntry.path.isEmpty()) { menu->addAction(editAction.data()); menu->addAction(deleteAction.data()); } actionsAdded = true; } if (actionsAdded) selectedAction = menu->exec(cursorPos); if (!selectedAction) return; if (!specialPlaylist) { if (selectedAction == downloadThumbnailAction.data()) { PlaylistEntry entry = getCurrentContentEntry(); QString system = QFileInfo(getCurrentPlaylistPath()).completeBaseName(); QString title = entry.label; if (!title.isEmpty()) { if (m_pendingThumbnailDownloadTypes.isEmpty()) { m_pendingThumbnailDownloadTypes.append(THUMBNAIL_BOXART); m_pendingThumbnailDownloadTypes.append(THUMBNAIL_SCREENSHOT); m_pendingThumbnailDownloadTypes.append(THUMBNAIL_TITLE); m_pendingThumbnailDownloadTypes.append(THUMBNAIL_LOGO); downloadThumbnail(system, title); } else { showMessageBox(msg_hash_to_str( MENU_ENUM_LABEL_VALUE_QT_DOWNLOAD_ALREADY_IN_PROGRESS), MainWindow::MSGBOX_TYPE_ERROR, Qt::ApplicationModal, false); } } } } if (!allPlaylist) { if (selectedAction == addFilesAction.data()) { QStringList filePaths = QFileDialog::getOpenFileNames( this, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_SELECT_FILES)); if (!filePaths.isEmpty()) addFilesToPlaylist(filePaths); } else if (selectedAction == addEntryAction.data()) addFilesToPlaylist(QStringList()); else if (selectedAction == addFolderAction.data()) { QString dirPath = QFileDialog::getExistingDirectory(this, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_SELECT_FOLDER), QString(), QFileDialog::ShowDirsOnly); if (!dirPath.isEmpty()) addFilesToPlaylist(QStringList() << dirPath); } else if (selectedAction == editAction.data()) { QString selectedDatabase; QString selectedName; QString selectedPath; QHash selectedCore; PlaylistEntryDialog *playlistDialog = playlistEntryDialog(); QString currentPlaylistPath = getCurrentPlaylistPath(); if (!playlistDialog->showDialog(currentEntry)) return; selectedName = m_playlistEntryDialog->getSelectedName(); selectedPath = m_playlistEntryDialog->getSelectedPath(); selectedCore = m_playlistEntryDialog->getSelectedCore(); selectedDatabase = m_playlistEntryDialog->getSelectedDatabase(); if (selectedCore.isEmpty()) { selectedCore["core_name"] = "DETECT"; selectedCore["core_path"] = "DETECT"; } if (selectedDatabase.isEmpty()) selectedDatabase = QFileInfo(currentPlaylistPath).fileName().remove(".lpl"); currentEntry.label = selectedName; currentEntry.path = selectedPath; currentEntry.coreName = selectedCore.value("core_name"); currentEntry.corePath = selectedCore.value("core_path"); currentEntry.dbName = selectedDatabase; if (!updateCurrentPlaylistEntry(currentEntry)) { showMessageBox(msg_hash_to_str( MENU_ENUM_LABEL_VALUE_QT_COULD_NOT_UPDATE_PLAYLIST_ENTRY), MainWindow::MSGBOX_TYPE_ERROR, Qt::ApplicationModal, false); return; } } else if (selectedAction == deleteAction.data()) deleteCurrentPlaylistItem(); } } /* http://www.informit.com/articles/article.aspx?p=1613548 */ ThumbnailDelegate::ThumbnailDelegate(const GridItem &gridItem, QObject* parent) : QStyledItemDelegate(parent), m_style(gridItem) { } void ThumbnailDelegate::paint(QPainter* painter, const QStyleOptionViewItem &option, const QModelIndex& index) const { QStyleOptionViewItem opt = option; const QWidget *widget = opt.widget; QStyle *style = widget->style(); int padding = m_style.padding; int text_top_margin = 4; /* Qt seemingly reports -4 the actual line height. */ int text_height = painter->fontMetrics().height() + padding + padding; QRect rect = opt.rect; QRect adjusted = rect.adjusted(padding, padding, -padding, -text_height + text_top_margin); QPixmap pixmap = index.data( PlaylistModel::THUMBNAIL).value(); painter->save(); initStyleOption(&opt, index); /* draw the background */ style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, widget); /* draw the image */ if (!pixmap.isNull()) { QPixmap pixmapScaled = pixmap.scaled(adjusted.size(), Qt::KeepAspectRatio, Qt::SmoothTransformation); style->drawItemPixmap(painter, adjusted, Qt::AlignHCenter | m_style.thumbnailVerticalAlignmentFlag, pixmapScaled); } /* draw the text */ if (!opt.text.isEmpty()) { QPalette::ColorGroup cg = opt.state & QStyle::State_Enabled ? QPalette::Normal : QPalette::Disabled; QRect textRect = QRect(rect.x() + padding, rect.y() + adjusted.height() - text_top_margin + padding, rect.width() - 2 * padding, text_height); QString elidedText = painter->fontMetrics().elidedText(opt.text, opt.textElideMode, textRect.width(), Qt::TextShowMnemonic); if (cg == QPalette::Normal && !(opt.state & QStyle::State_Active)) cg = QPalette::Inactive; if (opt.state & QStyle::State_Selected) painter->setPen(opt.palette.color(cg, QPalette::HighlightedText)); else painter->setPen(opt.palette.color(cg, QPalette::Text)); painter->setFont(opt.font); painter->drawText(textRect, Qt::AlignCenter, elidedText); } painter->restore(); } GridView::GridView(QWidget *parent) : QAbstractItemView(parent), m_idealHeight(0), m_hashIsDirty(false) { setFocusPolicy(Qt::WheelFocus); horizontalScrollBar()->setRange(0, 0); verticalScrollBar()->setRange(0, 0); } void GridView::setModel(QAbstractItemModel *newModel) { if (model()) disconnect(model(), SIGNAL(rowsRemoved(QModelIndex, int, int)), this, SLOT(rowsRemoved(QModelIndex, int, int))); QAbstractItemView::setModel(newModel); connect(newModel, SIGNAL(rowsRemoved(QModelIndex, int, int)), this, SLOT(rowsRemoved(QModelIndex, int, int))); m_hashIsDirty = true; } void GridView::setviewMode(ViewMode mode) { m_viewMode = mode; } void GridView::calculateRectsIfNecessary() const { int x, y; int row, nextX; if (!m_hashIsDirty) return; x = m_spacing; y = m_spacing; const int maxWidth = viewport()->width(); if (m_size + m_spacing * 2 > maxWidth) { m_rectForRow[0] = QRectF(x, y, m_size, m_size); for (row = 1; row < model()->rowCount(); ++row) { y += m_size + m_spacing; m_rectForRow[row] = QRectF(x, y, m_size, m_size); } } else { switch (m_viewMode) { case Anchored: { int columns = (maxWidth - m_spacing) / (m_size + m_spacing); if (columns > 0) { const int actualSpacing = (maxWidth - m_spacing - m_size - (columns - 1) * m_size) / columns; for (row = 0; row < model()->rowCount(); ++row) { nextX = x + m_size + actualSpacing; if (nextX > maxWidth) { x = m_spacing; y += m_size + m_spacing; nextX = x + m_size + actualSpacing; } m_rectForRow[row] = QRectF(x, y, m_size, m_size); x = nextX; } } break; } case Centered: { int columns = (maxWidth - m_spacing) / (m_size + m_spacing); if (columns > 0) { const int actualSpacing = (maxWidth - columns * m_size) / (columns + 1); x = actualSpacing; for (row = 0; row < model()->rowCount(); ++row) { nextX = x + m_size + actualSpacing; if (nextX > maxWidth) { x = actualSpacing; y += m_size + m_spacing; nextX = x + m_size + actualSpacing; } m_rectForRow[row] = QRectF(x, y, m_size, m_size); x = nextX; } } break; } case Simple: for (row = 0; row < model()->rowCount(); ++row) { nextX = x + m_size + m_spacing; if (nextX > maxWidth) { x = m_spacing; y += m_size + m_spacing; nextX = x + m_size + m_spacing; } m_rectForRow[row] = QRectF(x, y, m_size, m_size); x = nextX; } break; } } m_idealHeight = y + m_size + m_spacing; m_hashIsDirty = false; viewport()->update(); } QRect GridView::visualRect(const QModelIndex &index) const { QRect rect; if (index.isValid()) rect = viewportRectForRow(index.row()).toRect(); return rect; } QRectF GridView::viewportRectForRow(int row) const { QRectF rect; calculateRectsIfNecessary(); rect = m_rectForRow.value(row).toRect(); if (!rect.isValid()) return rect; return QRectF( rect.x() - horizontalScrollBar()->value(), rect.y() - verticalScrollBar()->value(), rect.width(), rect.height()); } void GridView::scrollTo(const QModelIndex &index, QAbstractItemView::ScrollHint) { QRect viewRect = viewport()->rect(); QRect itemRect = visualRect(index); if (itemRect.left() < viewRect.left()) horizontalScrollBar()->setValue(horizontalScrollBar()->value() + itemRect.left() - viewRect.left()); else if (itemRect.right() > viewRect.right()) horizontalScrollBar()->setValue(horizontalScrollBar()->value() + ((itemRect.right() - viewRect.right()) < (itemRect.left() - viewRect.left()) ? (itemRect.right() - viewRect.right()) : (itemRect.left() - viewRect.left()))); if (itemRect.top() < viewRect.top()) verticalScrollBar()->setValue(verticalScrollBar()->value() + itemRect.top() - viewRect.top()); else if (itemRect.bottom() > viewRect.bottom()) verticalScrollBar()->setValue(verticalScrollBar()->value() + ((itemRect.bottom() - viewRect.bottom()) < (itemRect.top() - viewRect.top()) ? (itemRect.bottom() - viewRect.bottom()) : (itemRect.top() - viewRect.top()))); viewport()->update(); } /* TODO: Make this more efficient by changing m_rectForRow for * another data structure. Look at how Qt's own views do it. */ QModelIndex GridView::indexAt(const QPoint &point_) const { QPoint point(point_); QHash::const_iterator i; point.rx() += horizontalScrollBar()->value(); point.ry() += verticalScrollBar()->value(); calculateRectsIfNecessary(); i = m_rectForRow.constBegin(); while (i != m_rectForRow.constEnd()) { if (i.value().contains(point)) return model()->index(i.key(), 0, rootIndex()); i++; } return QModelIndex(); } void GridView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector &roles) { m_hashIsDirty = true; QAbstractItemView::dataChanged(topLeft, bottomRight); } void GridView::refresh() { m_hashIsDirty = true; calculateRectsIfNecessary(); updateGeometries(); } void GridView::rowsInserted(const QModelIndex &parent, int start, int end) { QAbstractItemView::rowsInserted(parent, start, end); refresh(); } void GridView::rowsRemoved(const QModelIndex &parent, int start, int end) { refresh(); } void GridView::setGridSize(const int newSize) { if (newSize != m_size) { m_size = newSize; refresh(); } } /* The item rectangles are cached and only recomputed when the hash is * marked dirty. resizeEvent() does that, but a hidden widget receives * no resize events: the desktop menu is hidden while content runs, and * anything that changes the viewport width in the meantime - window * geometry, dock layout, a scroll bar appearing - leaves the cached * rectangles describing a width the viewport no longer has. They are * then reused on the next paint, and the grid stays misaligned until * something else happens to call refresh(). * * Recompute whenever the view becomes visible again, so the layout is * always derived from the viewport it is actually being drawn into. */ void GridView::showEvent(QShowEvent *event) { QAbstractItemView::showEvent(event); refresh(); } void GridView::resizeEvent(QResizeEvent*) { refresh(); } void GridView::reset() { m_visibleIndexes.clear(); QAbstractItemView::reset(); refresh(); } QModelIndex GridView::moveCursor(QAbstractItemView::CursorAction cursorAction, Qt::KeyboardModifiers) { QModelIndex index = currentIndex(); if (index.isValid()) { if ( (cursorAction == MoveLeft && index.row() > 0) || (cursorAction == MoveRight && index.row() + 1 < model()->rowCount())) { const int offset = (cursorAction == MoveLeft ? -1 : 1); index = model()->index(index.row() + offset, index.column(), index.parent()); } else if ((cursorAction == MoveUp && index.row() > 0) || (cursorAction == MoveDown && index.row() + 1 < model()->rowCount())) { const int offset = ((m_size + m_spacing) * (cursorAction == MoveUp ? -1 : 1)); QRect rect = viewportRectForRow(index.row()).toRect(); QPoint point(rect.center().x(), rect.center().y() + offset); index = indexAt(point); } } return index; } int GridView::horizontalOffset() const { return horizontalScrollBar()->value(); } int GridView::verticalOffset() const { return verticalScrollBar()->value(); } void GridView::scrollContentsBy(int dx, int dy) { scrollDirtyRegion(dx, dy); viewport()->scroll(dx, dy); emit(visibleItemsChangedMaybe()); } /* TODO: Maybe add a way to get the previous/next visible indexes. */ QVector GridView::visibleIndexes() const { return m_visibleIndexes; } void GridView::setSelection(const QRect &rect, QFlags flags) { QRect rectangle; QHash::const_iterator i; int firstRow = model()->rowCount(); int lastRow = -1; calculateRectsIfNecessary(); rectangle = rect.translated(horizontalScrollBar()->value(), verticalScrollBar()->value()).normalized(); i = m_rectForRow.constBegin(); while (i != m_rectForRow.constEnd()) { if (i.value().intersects(rectangle)) { firstRow = firstRow < i.key() ? firstRow : i.key(); lastRow = lastRow > i.key() ? lastRow : i.key(); } i++; } if (firstRow != model()->rowCount() && lastRow != -1) { QItemSelection selection(model()->index( firstRow, 0, rootIndex()), model()->index(lastRow, 0, rootIndex())); selectionModel()->select(selection, flags); } else { QModelIndex invalid; QItemSelection selection(invalid, invalid); selectionModel()->select(selection, flags); } } QRegion GridView::visualRegionForSelection(const QItemSelection &selection) const { int i; QRegion region; QItemSelectionRange range; for (i = 0; i < selection.size(); i++) { range = selection.at(i); int row; for (row = range.top(); row <= range.bottom(); row++) { int column; for (column = range.left(); column < range.right(); column++) { QModelIndex index = model()->index(row, column, rootIndex()); region += visualRect(index); } } } return region; } void GridView::paintEvent(QPaintEvent*) { QPainter painter(viewport()); int row; painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing); m_visibleIndexes.clear(); for (row = 0; row < model()->rowCount(rootIndex()); ++row) { QModelIndex index = model()->index(row, 0, rootIndex()); QRectF rect = viewportRectForRow(row); #if (QT_VERSION > QT_VERSION_CHECK(6, 0, 0)) QStyleOptionViewItem option; initViewItemOption(&option); #else QStyleOptionViewItem option = viewOptions(); #endif if ( !rect.isValid() || rect.bottom() < 0 || rect.y() > viewport()->height()) continue; m_visibleIndexes.append(index); option.rect = rect.toRect(); if (selectionModel()->isSelected(index)) option.state |= QStyle::State_Selected; if (currentIndex() == index) option.state |= QStyle::State_HasFocus; itemDelegate()->paint(&painter, option, index); } } void GridView::updateGeometries() { const int RowHeight = m_size + m_spacing; QAbstractItemView::updateGeometries(); verticalScrollBar()->setSingleStep(RowHeight); verticalScrollBar()->setPageStep(viewport()->height()); verticalScrollBar()->setRange(0, ((0) > (m_idealHeight - viewport()->height()) ? (0) : (m_idealHeight - viewport()->height()))); horizontalScrollBar()->setPageStep(viewport()->width()); horizontalScrollBar()->setRange(0, ((0) > (RowHeight - viewport()->width()) ? (0) : (RowHeight - viewport()->width()))); emit(visibleItemsChangedMaybe()); } QString GridView::getLayout() const { switch (m_viewMode) { case Simple: return QString("simple"); case Anchored: return QString("anchored"); case Centered: default: break; } return QString("centered"); } void GridView::setLayout(QString layout) { if (layout == QLatin1String("anchored")) m_viewMode = Anchored; else if (layout == QLatin1String("centered")) m_viewMode = Centered; else if (layout == QLatin1String("fixed")) m_viewMode = Simple; } int GridView::getSpacing() const { return m_spacing; } void GridView::setSpacing(const int spacing) { m_spacing = spacing; } GridItem::GridItem(QWidget* parent) : QWidget(parent) , thumbnailVerticalAlignmentFlag(Qt::AlignBottom) , padding(11) { } int GridItem::getPadding() const { return padding; } void GridItem::setPadding(const int value) { padding = value; } QString GridItem::getThumbnailVerticalAlign() const { switch (thumbnailVerticalAlignmentFlag) { case Qt::AlignTop: return QString("top"); case Qt::AlignVCenter: return QString("center"); case Qt::AlignBottom: default: break; } return QString("bottom"); } void GridItem::setThumbnailVerticalAlign(const QString valign) { if (valign == QLatin1String("top")) thumbnailVerticalAlignmentFlag = Qt::AlignTop; else if (valign == QLatin1String("center")) thumbnailVerticalAlignmentFlag = Qt::AlignVCenter; else if (valign == QLatin1String("bottom")) thumbnailVerticalAlignmentFlag = Qt::AlignBottom; } #if defined(_MSC_VER) && !defined(_XBOX) && (_MSC_VER >= 1500 && _MSC_VER < 1900) /* https://support.microsoft.com/en-us/kb/980263 */ #pragma execution_character_set("utf-8") #endif static inline bool comp_string_lower(const QString &lhs, const QString &rhs) { return lhs.toLower() < rhs.toLower(); } static inline bool comp_hash_ui_display_name_key_lower(const QHash &lhs, const QHash &rhs) { return lhs.value("ui_display_name").toLower() < rhs.value("ui_display_name").toLower(); } PlaylistEntryDialog::PlaylistEntryDialog(MainWindow *mainwindow, QWidget *parent) : QDialog(parent) ,m_mainwindow(mainwindow) ,m_nameLineEdit(new QLineEdit(this)) ,m_pathLineEdit(new QLineEdit(this)) ,m_extensionsLineEdit(new QLineEdit(this)) ,m_coreComboBox(new QComboBox(this)) ,m_databaseComboBox(new QComboBox(this)) ,m_extensionArchiveCheckBox(new QCheckBox( msg_hash_to_str( MENU_ENUM_LABEL_VALUE_QT_PLAYLIST_ENTRY_FILTER_INSIDE_ARCHIVES), this)) { QFormLayout *form = new QFormLayout(); QDialogButtonBox *buttonBox = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel); QVBoxLayout *databaseVBoxLayout = new QVBoxLayout(); QHBoxLayout *pathHBoxLayout = new QHBoxLayout(); QHBoxLayout *extensionHBoxLayout = new QHBoxLayout(); QLabel *databaseLabel = new QLabel(msg_hash_to_str( MENU_ENUM_LABEL_VALUE_QT_FOR_THUMBNAILS), this); QToolButton *pathPushButton = new QToolButton(this); pathPushButton->setText(QString("...")); pathHBoxLayout->addWidget(m_pathLineEdit); pathHBoxLayout->addWidget(pathPushButton); databaseVBoxLayout->addWidget(m_databaseComboBox); databaseVBoxLayout->addWidget(databaseLabel); extensionHBoxLayout->addWidget(m_extensionsLineEdit); extensionHBoxLayout->addWidget(m_extensionArchiveCheckBox); m_extensionsLineEdit->setPlaceholderText(msg_hash_to_str( MENU_ENUM_LABEL_VALUE_QT_PLAYLIST_ENTRY_EXTENSIONS_PLACEHOLDER)); /* Ensure placeholder text is completely visible. */ m_extensionsLineEdit->setMinimumWidth(QFontMetrics( m_extensionsLineEdit->font()).boundingRect( m_extensionsLineEdit->placeholderText()).width() + m_extensionsLineEdit->frameSize().width()); setWindowTitle(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_PLAYLIST_ENTRY)); form->setFormAlignment(Qt::AlignCenter); form->setLabelAlignment(Qt::AlignCenter); setLayout(new QVBoxLayout(this)); connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); connect(this, SIGNAL(accepted()), this, SLOT(onAccepted())); connect(this, SIGNAL(rejected()), this, SLOT(onRejected())); form->addRow(msg_hash_to_str( MENU_ENUM_LABEL_VALUE_QT_PLAYLIST_ENTRY_NAME), m_nameLineEdit); form->addRow(msg_hash_to_str( MENU_ENUM_LABEL_VALUE_QT_PLAYLIST_ENTRY_PATH), pathHBoxLayout); form->addRow(msg_hash_to_str( MENU_ENUM_LABEL_VALUE_QT_PLAYLIST_ENTRY_CORE), m_coreComboBox); form->addRow(msg_hash_to_str( MENU_ENUM_LABEL_VALUE_QT_PLAYLIST_ENTRY_DATABASE), databaseVBoxLayout); form->addRow(msg_hash_to_str( MENU_ENUM_LABEL_VALUE_QT_PLAYLIST_ENTRY_EXTENSIONS), extensionHBoxLayout); qobject_cast(layout())->addLayout(form); layout()->addItem(new QSpacerItem(20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding)); layout()->addWidget(buttonBox); connect(pathPushButton, SIGNAL(clicked()), this, SLOT(onPathClicked())); } bool PlaylistEntryDialog::filterInArchive() { return m_extensionArchiveCheckBox->isChecked(); } void PlaylistEntryDialog::onPathClicked() { QString filePath = QFileDialog::getOpenFileName(this); if (filePath.isEmpty()) return; m_pathLineEdit->setText(filePath); } void PlaylistEntryDialog::loadPlaylistOptions() { unsigned i, j; core_info_list_t *core_info_list = NULL; m_nameLineEdit->clear(); m_pathLineEdit->clear(); m_coreComboBox->clear(); m_databaseComboBox->clear(); m_coreComboBox->addItem( msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_CORE_SELECTION_ASK)); m_databaseComboBox->addItem( QString("<") + msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NOT_AVAILABLE) + ">", QFileInfo(m_mainwindow->getCurrentPlaylistPath()).fileName().remove(".lpl")); core_info_get_list(&core_info_list); if (core_info_list && core_info_list->count > 0) { QVector > allCores; QStringList allDatabases; for (i = 0; i < core_info_list->count; i++) { QString ui_display_name; QHash hash; const core_info_t *core = &core_info_list->list[i]; QStringList databases = QString(core->databases).split('|'); hash["core_name"] = core->core_name; hash["core_display_name"] = core->display_name; hash["core_path"] = core->path; hash["core_databases"] = core->databases; ui_display_name = hash.value("core_name"); if (ui_display_name.isEmpty()) ui_display_name = hash.value("core_display_name"); if (ui_display_name.isEmpty()) ui_display_name = QFileInfo( hash.value("core_path")).fileName(); if (ui_display_name.isEmpty()) continue; hash["ui_display_name"] = ui_display_name; for (j = 0; static_cast(j) < databases.count(); j++) { QString database = databases.at(static_cast(j)); if (database.isEmpty()) continue; if (!allDatabases.contains(database)) allDatabases.append(database); } if (!allCores.contains(hash)) allCores.append(hash); } std::sort(allCores.begin(), allCores.end(), comp_hash_ui_display_name_key_lower); std::sort(allDatabases.begin(), allDatabases.end(), comp_string_lower); for (j = 0; static_cast(j) < allCores.count(); j++) { const QHash &hash = allCores.at(static_cast(j)); m_coreComboBox->addItem(hash.value("ui_display_name"), QVariant::fromValue(hash)); } for (j = 0; static_cast(j) < allDatabases.count(); j++) { QString database = allDatabases.at(static_cast(j)); m_databaseComboBox->addItem(database, database); } } } bool PlaylistEntryDialog::nameFieldEnabled() { return m_nameLineEdit->isEnabled(); } void PlaylistEntryDialog::setEntryValues( const PlaylistEntry &entry) { QString db; const QString &coreName = entry.coreName; int foundDB = 0; int i = 0; loadPlaylistOptions(); if (entry.path.isEmpty()) { m_nameLineEdit->setText( msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_FIELD_MULTIPLE)); m_pathLineEdit->setText( msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_FIELD_MULTIPLE)); m_nameLineEdit->setEnabled(false); m_pathLineEdit->setEnabled(false); } else { m_nameLineEdit->setText(entry.label); m_pathLineEdit->setText(entry.path); m_nameLineEdit->setEnabled(true); m_pathLineEdit->setEnabled(true); } for (i = 0; i < m_coreComboBox->count(); i++) { const QHash hash = m_coreComboBox->itemData(i, Qt::UserRole).value >(); if (hash.isEmpty() || coreName.isEmpty()) continue; if (hash.value("core_name") == coreName) { m_coreComboBox->setCurrentIndex(i); break; } } db = entry.dbName; if (!db.isEmpty()) { foundDB = m_databaseComboBox->findText(db); if (foundDB >= 0) m_databaseComboBox->setCurrentIndex(foundDB); } } const QHash PlaylistEntryDialog::getSelectedCore() { return m_coreComboBox->currentData( Qt::UserRole).value >(); } const QString PlaylistEntryDialog::getSelectedName() { return m_nameLineEdit->text(); } const QString PlaylistEntryDialog::getSelectedPath() { return m_pathLineEdit->text(); } const QString PlaylistEntryDialog::getSelectedDatabase() { return m_databaseComboBox->currentData(Qt::UserRole).toString(); } const QStringList PlaylistEntryDialog::getSelectedExtensions() { QStringList list; QString text = m_extensionsLineEdit->text(); /* Otherwise it would create a QStringList with a single blank entry... */ if (!text.isEmpty()) list = text.split(' '); return list; } void PlaylistEntryDialog::onAccepted() { } void PlaylistEntryDialog::onRejected() { } void PlaylistEntryDialog::hideDialog() { reject(); } bool PlaylistEntryDialog::showDialog(const PlaylistEntry &entry) { loadPlaylistOptions(); setEntryValues(entry); return (exec() == QDialog::Accepted); } ShortcutsDialog::ShortcutsDialog(QWidget *parent) : QDialog(parent) ,m_table(new QTableWidget(0, 2, this)) ,m_help(new QLabel(this)) ,m_edit(new QLineEdit(this)) { QHBoxLayout *row = new QHBoxLayout(); QPushButton *apply = new QPushButton("Apply", this); QPushButton *close = new QPushButton("Close", this); QVBoxLayout *layout = new QVBoxLayout(); QStringList headers; setWindowTitle(QString(msg_hash_to_str( MENU_ENUM_LABEL_VALUE_QT_MENU_VIEW_CONTROLLER_SHORTCUTS)).remove('&')); headers << "Shortcut" << "As written"; m_table->setHorizontalHeaderLabels(headers); m_table->setSelectionBehavior(QAbstractItemView::SelectRows); m_table->setSelectionMode(QAbstractItemView::SingleSelection); m_table->setEditTriggers(QAbstractItemView::NoEditTriggers); m_table->horizontalHeader()->setStretchLastSection(true); m_table->verticalHeader()->hide(); m_help->setWordWrap(true); apply->setDefault(true); row->addWidget(m_edit, 1); row->addWidget(apply); row->addWidget(close); layout->addWidget(m_table, 1); layout->addWidget(m_help); layout->addLayout(row); setLayout(layout); resize(640, 420); connect(m_table, SIGNAL(itemSelectionChanged()), this, SLOT(onRowChanged())); connect(m_edit, SIGNAL(returnPressed()), this, SLOT(onApply())); connect(apply, SIGNAL(clicked()), this, SLOT(onApply())); connect(close, SIGNAL(clicked()), this, SLOT(hide())); } void ShortcutsDialog::fill(int keep) { companion_core_t *core = ui_companion_qt_core(); size_t i, n = companion_core_shortcut_count(core); char label[64], text[512]; m_table->blockSignals(true); m_table->setRowCount((int)n); for (i = 0; i < n; i++) { m_table->setItem((int)i, 0, new QTableWidgetItem(QString::fromUtf8( companion_core_shortcut_label(core, i, label, sizeof(label))))); m_table->setItem((int)i, 1, new QTableWidgetItem(QString::fromUtf8( companion_core_shortcut_get(core, i, text, sizeof(text))))); } m_table->blockSignals(false); if (keep >= 0 && keep < (int)n) m_table->selectRow(keep); onRowChanged(); } void ShortcutsDialog::onRowChanged() { companion_core_t *core = ui_companion_qt_core(); int row = m_table->currentRow(); char text[512], help[2048]; if (row < 0) return; m_edit->setText(QString::fromUtf8(companion_core_shortcut_get(core, (size_t)row, text, sizeof(text)))); m_help->setText(QString::fromUtf8(companion_core_shortcut_help(core, companion_core_shortcut_is_macro(core, (size_t)row), help, sizeof(help)))); } void ShortcutsDialog::onApply() { int row = m_table->currentRow(); QByteArray in = m_edit->text().toUtf8(); if (row < 0 || !companion_core_shortcut_set(ui_companion_qt_core(), (size_t)row, in.constData())) { QApplication::beep(); return; } fill(row); } void ShortcutsDialog::showDialog() { fill(0); show(); raise(); activateWindow(); } CoreInfoDialog::CoreInfoDialog(MainWindow *mainwindow, QWidget *parent) : QDialog(parent) ,m_formLayout(new QFormLayout()) ,m_mainwindow(mainwindow) { QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok); connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); setWindowTitle(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_CORE_INFORMATION)); m_formLayout->setFormAlignment(Qt::AlignCenter); m_formLayout->setLabelAlignment(Qt::AlignCenter); setLayout(new QVBoxLayout()); qobject_cast(layout())->addLayout(m_formLayout); layout()->addItem(new QSpacerItem(20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding)); layout()->addWidget(buttonBox); } void CoreInfoDialog::showCoreInfo() { int i, row; int row_count = m_formLayout->rowCount(); QVector > info_list = m_mainwindow->getCoreInfo(); if (row_count > 0) { for (row = 0; row < row_count; row++) { #if (QT_VERSION >= QT_VERSION_CHECK(5, 8, 0)) /* removeRow() and takeRow() was only added in 5.8! */ m_formLayout->removeRow(0); #else /* something is buggy here... * sometimes items appear duplicated, and other times not */ QLayoutItem *item = m_formLayout->itemAt(0); QWidget *w = NULL; if (item) { w = item->widget(); if (w) { QWidget *label = m_formLayout->labelForField(w); if (label) delete label; m_formLayout->removeWidget(w); delete w; } } #endif } } if (info_list.count() == 0) return; for (i = 0; i < info_list.count(); i++) { const QHash &line = info_list.at(i); QLabel *label = new QLabel(line.value("key")); CoreInfoLabel *value = new CoreInfoLabel(line.value("value")); QString labelStyle = line.value("label_style"); QString valueStyle = line.value("value_style"); if (!labelStyle.isEmpty()) label->setStyleSheet(labelStyle); if (!valueStyle.isEmpty()) value->setStyleSheet(valueStyle); m_formLayout->addRow(label, value); } show(); } #ifdef HAVE_MENU QPixmap getColorizedPixmap(const QPixmap& oldPixmap, const QColor& color) { QPixmap pixmap = oldPixmap; QBitmap mask = pixmap.createMaskFromColor(Qt::transparent, Qt::MaskInColor); pixmap.fill(color); pixmap.setMask(mask); return pixmap; } QColor getLabelColor(const QString& objectName) { QLabel dummyColor; dummyColor.setObjectName(objectName); dummyColor.ensurePolished(); return dummyColor.palette().color(QPalette::WindowText); } /* stolen from Qt Creator */ class SmartScrollArea : public QScrollArea { public: explicit SmartScrollArea(QWidget *parent) : QScrollArea(parent) { setFrameStyle(QFrame::NoFrame | QFrame::Plain); viewport()->setAutoFillBackground(false); setWidgetResizable(true); } private: void resizeEvent(QResizeEvent *event) final { QWidget *inner = widget(); if (inner) { int fw = frameWidth() * 2; QSize innerSize = event->size() - QSize(fw, fw); QSize innerSizeHint = inner->minimumSizeHint(); /* Widget wants to be bigger than available space */ if (innerSizeHint.height() > innerSize.height()) { innerSize.setWidth(innerSize.width() - scrollBarWidth()); innerSize.setHeight(innerSizeHint.height()); } inner->resize(innerSize); } QScrollArea::resizeEvent(event); } QSize minimumSizeHint() const final { static const int max_min_width = 250; static const int max_min_height = 250; QWidget *inner = widget(); if (inner) { int fw = frameWidth() * 2; QSize minSize = inner->minimumSizeHint(); minSize += QSize(fw, fw); minSize += QSize(scrollBarWidth(), 0); minSize.setWidth(((minSize.width()) < (max_min_width) ? (minSize.width()) : (max_min_width))); minSize.setHeight(((minSize.height()) < (max_min_height) ? (minSize.height()) : (max_min_height))); return minSize; } return QSize(0, 0); } bool event(QEvent *event) final { if (event->type() == QEvent::LayoutRequest) updateGeometry(); return QScrollArea::event(event); } int scrollBarWidth() const { SmartScrollArea *that = const_cast(this); QWidgetList list = that->scrollBarWidgets(Qt::AlignRight); if (list.isEmpty()) return 0; return list.first()->sizeHint().width(); } }; class QtDisplayListCategory : public OptionsCategory { public: QtDisplayListCategory(msg_hash_enums title, const QString &icon, enum menu_displaylist_ctl_state state, QObject *parent = nullptr) : OptionsCategory(parent), m_state(state) { setDisplayName(title); setCategoryIcon(icon); } QVector pages() { QVector result; result << new SimplePage(m_state, this); return result; } private: enum menu_displaylist_ctl_state m_state; }; ViewOptionsDialog::ViewOptionsDialog(MainWindow *mainwindow, QWidget *parent) : QDialog(mainwindow) ,m_optionsList(new QListWidget(this)) ,m_optionsStack(new QStackedLayout) { int width; QGridLayout *layout = new QGridLayout(this); QLabel *m_headerLabel = new QLabel(this); /* Header label with large font and a bit of spacing * (align with group boxes) */ QFont headerLabelFont = m_headerLabel->font(); const int pointSize = headerLabelFont.pointSize(); QHBoxLayout *headerHLayout = new QHBoxLayout; const int leftMargin = QApplication::style()->pixelMetric( QStyle::PM_LayoutLeftMargin); #if (QT_VERSION > QT_VERSION_CHECK(6, 0, 0)) m_optionsStack->setContentsMargins(0, 0, 0, 0); #else m_optionsStack->setMargin(0); #endif headerLabelFont.setBold(true); /* Paranoia: Should a font be set in pixels... */ if (pointSize > 0) headerLabelFont.setPointSize(pointSize + 2); m_headerLabel->setFont(headerLabelFont); headerHLayout->addSpacerItem(new QSpacerItem(leftMargin, 0, QSizePolicy::Fixed, QSizePolicy::Ignored)); headerHLayout->addWidget(m_headerLabel); addCategory(new DriversCategory(this)); addCategory(new VideoCategory(this)); addCategory(new AudioCategory(this)); addCategory(new InputCategory(this)); addCategory(new LatencyCategory(this)); addCategory(new QtDisplayListCategory( MENU_ENUM_LABEL_VALUE_ACCESSIBILITY_SETTINGS, "menu_accessibility", DISPLAYLIST_ACCESSIBILITY_SETTINGS_LIST, this)); addCategory(new QtDisplayListCategory( MENU_ENUM_LABEL_VALUE_POWER_MANAGEMENT_SETTINGS, "menu_power", DISPLAYLIST_POWER_MANAGEMENT_SETTINGS_LIST, this)); addCategory(new CoreCategory(this)); addCategory(new ConfigurationCategory(this)); addCategory(new SavingCategory(this)); addCategory(new LoggingCategory(this)); addCategory(new FrameThrottleCategory(this)); addCategory(new RecordingCategory(this)); addCategory(new OnscreenDisplayCategory(this)); addCategory(new UserInterfaceCategory(mainwindow, this)); addCategory(new AIServiceCategory(this)); #ifdef HAVE_CHEEVOS addCategory(new AchievementsCategory(this)); #endif #if defined(HAVE_NETWORKING) && defined(HAVE_WIFI) addCategory(new QtDisplayListCategory( MENU_ENUM_LABEL_VALUE_WIFI_SETTINGS, "menu_network", DISPLAYLIST_WIFI_SETTINGS_LIST, this)); #endif #ifdef HAVE_NETWORKING /* Netplay and updater settings do not exist in a build without * networking; NetplayPage constructs CheckBoxes straight from the * setting lookups, which are NULL then (crashed the offscreen * companion test's --disable-networking build at startup). */ addCategory(new NetworkCategory(this)); #endif #ifdef HAVE_MIST addCategory(new QtDisplayListCategory( MENU_ENUM_LABEL_VALUE_STEAM_SETTINGS, "menu_steam", DISPLAYLIST_STEAM_SETTINGS_LIST, this)); #endif addCategory(new PlaylistsCategory(this)); addCategory(new UserCategory(this)); addCategory(new DirectoryCategory(this)); width = m_optionsList->sizeHintForColumn(0) + m_optionsList->frameWidth() * 2 + 5; width += m_optionsList->verticalScrollBar()->sizeHint().width(); m_optionsList->setMaximumWidth(width); m_optionsList->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum); setWindowTitle(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_MENU_VIEW_OPTIONS_TITLE)); layout->addWidget(m_optionsList, 0, 0, 2, 1); layout->addLayout(headerHLayout, 0, 1); layout->addLayout(m_optionsStack, 1, 1); connect(m_optionsList, SIGNAL(currentRowChanged(int)), m_optionsStack, SLOT(setCurrentIndex(int))); connect(m_optionsList, SIGNAL(currentTextChanged(const QString&)), m_headerLabel, SLOT(setText(const QString&))); connect(this, SIGNAL(rejected()), this, SLOT(onRejected())); } QIcon getIcon(OptionsCategory *category) { settings_t *settings = config_get_ptr(); const char *path_dir_assets = settings->paths.directory_assets; QPixmap pixmap = QPixmap(QString(path_dir_assets) + "/xmb/monochrome/png/" + category->categoryIconName() + ".png"); return QIcon(getColorizedPixmap(pixmap, getLabelColor("iconColor"))); } void ViewOptionsDialog::addCategory(OptionsCategory *category) { QTabWidget *tabWidget = new QTabWidget(); m_categoryList.append(category); for (OptionsPage* page : category->pages()) { SmartScrollArea *scrollArea = new SmartScrollArea(this); QWidget *widget = page->widget(); scrollArea->setWidget(widget); widget->setAutoFillBackground(false); tabWidget->addTab(scrollArea, page->displayName()); } #if (QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)) tabWidget->setTabBarAutoHide(true); #else /* TODO remove the tabBar's space */ if (tabWidget->count() < 2) tabWidget->tabBar()->hide(); #endif m_optionsList->addItem( new QListWidgetItem(getIcon(category), category->displayName())); m_optionsStack->addWidget(tabWidget); } void ViewOptionsDialog::repaintIcons() { unsigned i; size_t list_size = (size_t)m_categoryList.size(); for (i = 0; i < list_size; i++) m_optionsList->item(i)->setIcon(getIcon(m_categoryList.at(i))); } #else ViewOptionsDialog::ViewOptionsDialog(MainWindow *mainwindow, QWidget *parent) : QDialog(mainwindow) , m_viewOptionsWidget(new ViewOptionsWidget(mainwindow)) { QVBoxLayout *layout = new QVBoxLayout; QDialogButtonBox *buttonBox = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel); connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); connect(this, SIGNAL(accepted()), m_viewOptionsWidget, SLOT(onAccepted())); connect(this, SIGNAL(rejected()), m_viewOptionsWidget, SLOT(onRejected())); setWindowTitle(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_MENU_VIEW_OPTIONS_TITLE)); layout->setContentsMargins(0, 0, 0, 0); layout->addWidget(m_viewOptionsWidget); layout->addWidget(buttonBox); setLayout(layout); } #endif void ViewOptionsDialog::showDialog() { #ifdef HAVE_MENU unsigned i; size_t list_size = (size_t)m_categoryList.size(); for (i = 0; i < list_size; i++) m_categoryList.at(i)->load(); #else m_viewOptionsWidget->loadViewOptions(); #endif if (!isVisible()) restoreGeometry(); show(); activateWindow(); } void ViewOptionsDialog::persistGeometry() { settings_t *settings = config_get_ptr(); QRect g; if (!settings->bools.desktop_menu_save_geometry || !isVisible() || isMinimized()) return; g = geometry(); if (g.width() <= 0 || g.height() <= 0) return; snprintf(settings->arrays.desktop_menu_options_window, sizeof(settings->arrays.desktop_menu_options_window), "%d,%d,%d,%d", g.x() < 0 ? 0 : g.x(), g.y() < 0 ? 0 : g.y(), g.width(), g.height()); } void ViewOptionsDialog::restoreGeometry() { settings_t *settings = config_get_ptr(); int x = 0, y = 0, w = 0, h = 0; if (!settings->bools.desktop_menu_save_geometry) return; if (sscanf(settings->arrays.desktop_menu_options_window, "%d,%d,%d,%d", &x, &y, &w, &h) != 4) return; if (w <= 0 || h <= 0 || w > 32767 || h > 32767 || x < 0 || y < 0) return; setGeometry(x, y, w, h); } void ViewOptionsDialog::resizeEvent(QResizeEvent *event) { QDialog::resizeEvent(event); persistGeometry(); } void ViewOptionsDialog::moveEvent(QMoveEvent *event) { QDialog::moveEvent(event); persistGeometry(); } void ViewOptionsDialog::hideDialog() { reject(); } void ViewOptionsDialog::onRejected() { #ifdef HAVE_MENU unsigned i; size_t list_size = (size_t)m_categoryList.size(); for (i = 0; i < list_size; i++) m_categoryList.at(i)->apply(); #endif } ViewOptionsWidget::ViewOptionsWidget(MainWindow *mainwindow, QWidget *parent) : QWidget(parent) ,m_mainwindow(mainwindow) ,m_saveGeometryCheckBox(new QCheckBox(this)) ,m_saveLastTabCheckBox(new QCheckBox(this)) ,m_saveDockPositionsCheckBox(new QCheckBox(this)) ,m_showHiddenFilesCheckBox(new QCheckBox(this)) ,m_themeComboBox(new QComboBox(this)) ,m_thumbnailCacheSpinBox(new QSpinBox(this)) ,m_thumbnailDropSizeSpinBox(new QSpinBox(this)) ,m_startupPlaylistComboBox(new QComboBox(this)) ,m_highlightColorPushButton(new QPushButton( msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_CHOOSE), this)) ,m_highlightColor() ,m_highlightColorLabel(new QLabel( msg_hash_to_str( MENU_ENUM_LABEL_VALUE_QT_MENU_VIEW_OPTIONS_HIGHLIGHT_COLOR), this)) ,m_customThemePath() ,m_suggestLoadedCoreFirstCheckBox(new QCheckBox(this)) /* ,m_allPlaylistsListMaxCountSpinBox(new QSpinBox(this)) */ /* ,m_allPlaylistsGridMaxCountSpinBox(new QSpinBox(this)) */ { QVBoxLayout *layout = new QVBoxLayout; QFormLayout *form = new QFormLayout; m_themeComboBox->addItem(msg_hash_to_str( MENU_ENUM_LABEL_VALUE_QT_MENU_VIEW_OPTIONS_THEME_SYSTEM_DEFAULT), MainWindow::THEME_SYSTEM_DEFAULT); m_themeComboBox->addItem(msg_hash_to_str( MENU_ENUM_LABEL_VALUE_QT_MENU_VIEW_OPTIONS_THEME_DARK), MainWindow::THEME_DARK); m_themeComboBox->addItem(msg_hash_to_str( MENU_ENUM_LABEL_VALUE_QT_MENU_VIEW_OPTIONS_THEME_CUSTOM), MainWindow::THEME_CUSTOM); m_thumbnailCacheSpinBox->setSuffix(" MB"); m_thumbnailCacheSpinBox->setRange(0, 99999); m_thumbnailDropSizeSpinBox->setSuffix(" px"); m_thumbnailDropSizeSpinBox->setRange(0, 99999); /* m_allPlaylistsListMaxCountSpinBox->setRange(0, 99999); */ /* m_allPlaylistsGridMaxCountSpinBox->setRange(0, 99999); */ form->setFormAlignment(Qt::AlignCenter); form->setLabelAlignment(Qt::AlignCenter); form->addRow(msg_hash_to_str( MENU_ENUM_LABEL_VALUE_QT_MENU_VIEW_OPTIONS_SAVE_GEOMETRY), m_saveGeometryCheckBox); form->addRow(msg_hash_to_str( MENU_ENUM_LABEL_VALUE_QT_MENU_VIEW_OPTIONS_SAVE_DOCK_POSITIONS), m_saveDockPositionsCheckBox); form->addRow(msg_hash_to_str( MENU_ENUM_LABEL_VALUE_QT_MENU_VIEW_OPTIONS_SAVE_LAST_TAB), m_saveLastTabCheckBox); form->addRow(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_MENU_VIEW_OPTIONS_SHOW_HIDDEN_FILES), m_showHiddenFilesCheckBox); form->addRow(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_MENU_VIEW_OPTIONS_SUGGEST_LOADED_CORE_FIRST), m_suggestLoadedCoreFirstCheckBox); form->addRow(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_MENU_VIEW_OPTIONS_STARTUP_PLAYLIST), m_startupPlaylistComboBox); form->addRow(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_MENU_VIEW_OPTIONS_THUMBNAIL_CACHE_LIMIT), m_thumbnailCacheSpinBox); form->addRow(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_MENU_VIEW_OPTIONS_THUMBNAIL_DROP_SIZE_LIMIT), m_thumbnailDropSizeSpinBox); form->addRow(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_MENU_VIEW_OPTIONS_THEME), m_themeComboBox); form->addRow(m_highlightColorLabel, m_highlightColorPushButton); /* The same one-line help the Win32 and Cocoa companions show for * these rows, on both the label and the control. The text is the * menu's, and so is wrapped_tooltip() - a build without the menu * has neither. */ #ifdef HAVE_MENU { struct { QWidget *w; enum msg_hash_enums help; } tips[] = { { m_saveGeometryCheckBox, MENU_ENUM_SUBLABEL_QT_MENU_VIEW_OPTIONS_SAVE_GEOMETRY }, { m_saveLastTabCheckBox, MENU_ENUM_SUBLABEL_QT_MENU_VIEW_OPTIONS_SAVE_LAST_TAB }, { m_showHiddenFilesCheckBox, MENU_ENUM_SUBLABEL_QT_MENU_VIEW_OPTIONS_SHOW_HIDDEN_FILES }, { m_suggestLoadedCoreFirstCheckBox, MENU_ENUM_SUBLABEL_QT_MENU_VIEW_OPTIONS_SUGGEST_LOADED_CORE_FIRST }, { m_startupPlaylistComboBox, MENU_ENUM_SUBLABEL_QT_MENU_VIEW_OPTIONS_STARTUP_PLAYLIST }, { m_thumbnailCacheSpinBox, MENU_ENUM_SUBLABEL_QT_MENU_VIEW_OPTIONS_THUMBNAIL_CACHE_LIMIT }, { m_thumbnailDropSizeSpinBox, MENU_ENUM_SUBLABEL_QT_MENU_VIEW_OPTIONS_THUMBNAIL_DROP_SIZE_LIMIT }, { m_themeComboBox, MENU_ENUM_SUBLABEL_QT_MENU_VIEW_OPTIONS_THEME }, { m_highlightColorPushButton, MENU_ENUM_SUBLABEL_QT_MENU_VIEW_OPTIONS_HIGHLIGHT_COLOR }, { m_highlightColorLabel, MENU_ENUM_SUBLABEL_QT_MENU_VIEW_OPTIONS_HIGHLIGHT_COLOR }, }; for (size_t i = 0; i < sizeof(tips) / sizeof(tips[0]); i++) { QString tip = wrapped_tooltip(msg_hash_to_str(tips[i].help)); tips[i].w->setToolTip(tip); if (QWidget *label = form->labelForField(tips[i].w)) label->setToolTip(tip); } } #endif layout->addLayout(form); layout->addItem(new QSpacerItem(20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding)); setLayout(layout); loadViewOptions(); connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onThemeComboBoxIndexChanged(int))); connect(m_highlightColorPushButton, SIGNAL(clicked()), this, SLOT(onHighlightColorChoose())); } void ViewOptionsWidget::onThemeComboBoxIndexChanged(int) { MainWindow::Theme theme = static_cast(m_themeComboBox->currentData(Qt::UserRole).toInt()); if (theme == MainWindow::THEME_CUSTOM) { QString filePath = QFileDialog::getOpenFileName(this, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_SELECT_THEME)); if (filePath.isEmpty()) { int oldThemeIndex = m_themeComboBox->findData((int)config_get_ptr()->uints.desktop_menu_theme); if (m_themeComboBox->count() > oldThemeIndex) { disconnect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onThemeComboBoxIndexChanged(int))); m_themeComboBox->setCurrentIndex(oldThemeIndex); connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onThemeComboBoxIndexChanged(int))); } } else { m_customThemePath = filePath; if (m_mainwindow->setCustomThemeFile(filePath)) m_mainwindow->setTheme(theme); } } else m_mainwindow->setTheme(theme); showOrHideHighlightColor(); } void ViewOptionsWidget::onHighlightColorChoose() { QPixmap highlightPixmap(m_highlightColorPushButton->iconSize()); QColor currentHighlightColor = string_is_empty(config_get_ptr()->arrays.desktop_menu_highlight_color) ? QApplication::palette().highlight().color() : QColor(QString::fromUtf8(config_get_ptr()->arrays.desktop_menu_highlight_color)); QColor newHighlightColor = QColorDialog::getColor( currentHighlightColor, this, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_SELECT_COLOR)); if (newHighlightColor.isValid()) { MainWindow::Theme theme = static_cast( m_themeComboBox->currentData(Qt::UserRole).toInt()); m_highlightColor = newHighlightColor; strlcpy(config_get_ptr()->arrays.desktop_menu_highlight_color, m_highlightColor.name().toUtf8().constData(), sizeof(config_get_ptr()->arrays.desktop_menu_highlight_color)); highlightPixmap.fill(m_highlightColor); m_highlightColorPushButton->setIcon(highlightPixmap); m_mainwindow->setTheme(theme); } } void ViewOptionsWidget::loadViewOptions() { int i; int themeIndex = 0; int playlistIndex = 0; settings_t *settings = config_get_ptr(); QColor highlightColor = string_is_empty(settings->arrays.desktop_menu_highlight_color) ? QApplication::palette().highlight().color() : QColor(QString::fromUtf8(settings->arrays.desktop_menu_highlight_color)); QPixmap highlightPixmap(m_highlightColorPushButton->iconSize()); QVector > playlists = m_mainwindow->getPlaylists(); QString initialPlaylist = string_is_empty(settings->paths.desktop_menu_initial_playlist) ? QString(ALL_PLAYLISTS_TOKEN) : QString::fromUtf8(settings->paths.desktop_menu_initial_playlist); m_saveGeometryCheckBox->setChecked(settings->bools.desktop_menu_save_geometry); m_saveLastTabCheckBox->setChecked(settings->bools.desktop_menu_save_last_tab); m_saveDockPositionsCheckBox->setChecked(settings->bools.desktop_menu_save_dock_positions); m_showHiddenFilesCheckBox->setChecked(settings->bools.show_hidden_files); m_suggestLoadedCoreFirstCheckBox->setChecked(settings->bools.desktop_menu_suggest_loaded_core_first); m_thumbnailCacheSpinBox->setValue((int)settings->uints.desktop_menu_thumbnail_cache_limit); m_thumbnailDropSizeSpinBox->setValue((int)settings->uints.desktop_menu_thumbnail_max_size); themeIndex = m_themeComboBox->findData((int)settings->uints.desktop_menu_theme); if (m_themeComboBox->count() > themeIndex) m_themeComboBox->setCurrentIndex(themeIndex); if (highlightColor.isValid()) { m_highlightColor = highlightColor; highlightPixmap.fill(m_highlightColor); m_highlightColorPushButton->setIcon(highlightPixmap); } showOrHideHighlightColor(); m_startupPlaylistComboBox->clear(); for (i = 0; i < playlists.count(); i++) { const QPair &pair = playlists.at(i); m_startupPlaylistComboBox->addItem(pair.first, pair.second); } playlistIndex = m_startupPlaylistComboBox->findData( initialPlaylist, Qt::UserRole, Qt::MatchFixedString); if (playlistIndex >= 0) m_startupPlaylistComboBox->setCurrentIndex(playlistIndex); } void ViewOptionsWidget::showOrHideHighlightColor() { if (m_mainwindow->theme() == MainWindow::THEME_DARK) { m_highlightColorLabel->show(); m_highlightColorPushButton->show(); } else { m_highlightColorLabel->hide(); m_highlightColorPushButton->hide(); } } void ViewOptionsWidget::saveViewOptions() { /* Into retroarch.cfg's settings_t, shared with the native companions; * RetroArch writes the file on exit. */ settings_t *settings = config_get_ptr(); QByteArray initial = m_startupPlaylistComboBox->currentData(Qt::UserRole).toString().toUtf8(); QByteArray color = m_highlightColor.name().toUtf8(); QByteArray theme = m_customThemePath.toUtf8(); settings->bools.desktop_menu_save_geometry = m_saveGeometryCheckBox->isChecked(); settings->bools.desktop_menu_save_last_tab = m_saveLastTabCheckBox->isChecked(); settings->bools.desktop_menu_save_dock_positions = m_saveDockPositionsCheckBox->isChecked(); settings->uints.desktop_menu_theme = (unsigned)m_themeComboBox->currentData(Qt::UserRole).toInt(); settings->bools.show_hidden_files = m_showHiddenFilesCheckBox->isChecked(); strlcpy(settings->arrays.desktop_menu_highlight_color, color.constData(), sizeof(settings->arrays.desktop_menu_highlight_color)); settings->bools.desktop_menu_suggest_loaded_core_first = m_suggestLoadedCoreFirstCheckBox->isChecked(); strlcpy(settings->paths.desktop_menu_initial_playlist, initial.constData(), sizeof(settings->paths.desktop_menu_initial_playlist)); settings->uints.desktop_menu_thumbnail_cache_limit = (unsigned)m_thumbnailCacheSpinBox->value(); settings->uints.desktop_menu_thumbnail_max_size = (unsigned)m_thumbnailDropSizeSpinBox->value(); if (!m_mainwindow->customThemeString().isEmpty()) strlcpy(settings->paths.desktop_menu_custom_theme, theme.constData(), sizeof(settings->paths.desktop_menu_custom_theme)); m_mainwindow->setThumbnailCacheLimit(m_thumbnailCacheSpinBox->value()); } void ViewOptionsWidget::onAccepted() { saveViewOptions(); } void ViewOptionsWidget::onRejected() { loadViewOptions(); } CoreOptionsDialog::CoreOptionsDialog(QWidget *parent) : QDialog(parent) ,m_layout() ,m_scrollArea() { setWindowTitle(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_CORE_OPTIONS)); setObjectName("coreOptionsDialog"); resize(720, 480); QTimer::singleShot(0, this, SLOT(clearLayout())); } CoreOptionsDialog::~CoreOptionsDialog() { } void CoreOptionsDialog::resizeEvent(QResizeEvent *event) { QDialog::resizeEvent(event); if (!m_scrollArea) return; m_scrollArea->resize(event->size()); emit resized(event->size()); } void CoreOptionsDialog::closeEvent(QCloseEvent *event) { QDialog::closeEvent(event); emit closed(); } void CoreOptionsDialog::paintEvent(QPaintEvent *event) { QStyleOption o; QPainter p; o.initFrom(this); p.begin(this); style()->drawPrimitive( QStyle::PE_Widget, &o, &p, this); p.end(); QDialog::paintEvent(event); } void CoreOptionsDialog::clearLayout() { QWidget *widget = NULL; if (m_scrollArea) { { QList _children = children(); for (int _i = 0; _i < _children.size(); _i++) _children[_i]->deleteLater(); } } m_layout = new QVBoxLayout(); widget = new QWidget(); widget->setLayout(m_layout); widget->setObjectName("coreOptionsWidget"); m_scrollArea = new QScrollArea(); m_scrollArea->setParent(this); m_scrollArea->setWidgetResizable(true); m_scrollArea->setWidget(widget); m_scrollArea->setObjectName("coreOptionsScrollArea"); m_scrollArea->show(); } void CoreOptionsDialog::reload() { buildLayout(); } void CoreOptionsDialog::onSaveGameSpecificOptions() { #ifdef HAVE_MENU struct menu_state *menu_st = menu_state_get_ptr(); #endif if (!core_options_create_override(true)) QMessageBox::critical(this, msg_hash_to_str(MSG_ERROR), msg_hash_to_str(MSG_ERROR_SAVING_CORE_OPTIONS_FILE)); #ifdef HAVE_MENU menu_st->flags |= MENU_ST_FLAG_ENTRIES_NEED_REFRESH | MENU_ST_FLAG_PREVENT_POPULATE; #endif } void CoreOptionsDialog::onSaveFolderSpecificOptions() { #ifdef HAVE_MENU struct menu_state *menu_st = menu_state_get_ptr(); #endif if (!core_options_create_override(false)) QMessageBox::critical(this, msg_hash_to_str(MSG_ERROR), msg_hash_to_str(MSG_ERROR_SAVING_CORE_OPTIONS_FILE)); #ifdef HAVE_MENU menu_st->flags |= MENU_ST_FLAG_ENTRIES_NEED_REFRESH | MENU_ST_FLAG_PREVENT_POPULATE; #endif } void CoreOptionsDialog::onCoreOptionComboBoxCurrentIndexChanged(int index) { unsigned i, k; QString key, val; runloop_state_t *runloop_st = runloop_state_get_ptr(); QComboBox *combo_box = qobject_cast(sender()); if (!combo_box) return; key = combo_box->itemData(index, Qt::UserRole).toString(); val = combo_box->itemText(index); if (runloop_st->core_options) { core_option_manager_t *coreopts = NULL; retroarch_ctl(RARCH_CTL_CORE_OPTIONS_LIST_GET, &coreopts); if (coreopts) { size_t opts = runloop_st->core_options->size; for (i = 0; i < opts; i++) { QString optKey; struct core_option *option = static_cast(&coreopts->opts[i]); if (!option) continue; optKey = option->key; if (key == optKey) { for (k = 0; k < option->vals->size; k++) { QString str = option->vals->elems[k].data; if (!str.isEmpty() && str == val) core_option_manager_set_val(coreopts, i, k, true); } } } } } } void CoreOptionsDialog::buildLayout() { unsigned j, k; QFormLayout *form = NULL; settings_t *settings = config_get_ptr(); runloop_state_t *runloop_st = runloop_state_get_ptr(); bool has_core_options = (runloop_st->core_options != NULL); size_t opts = (runloop_st->core_options) ? runloop_st->core_options->size : 0; clearLayout(); if (has_core_options) { core_option_manager_t *coreopts = NULL; form = new QFormLayout(); if (settings->bools.game_specific_options) { QString contentLabel; QString label; rarch_system_info_t *sys_info = &runloop_st->system; /* TODO/FIXME - why have this check here? sys_info is not used */ if (sys_info) contentLabel = QFileInfo(path_get(RARCH_PATH_BASENAME)).completeBaseName(); if (!contentLabel.isEmpty()) { if (!label.isEmpty()) { QHBoxLayout *gameOptionsLayout = new QHBoxLayout(); QPushButton *button = new QPushButton(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_SAVE), this); connect(button, SIGNAL(clicked()), this, SLOT(onSaveGameSpecificOptions())); gameOptionsLayout->addWidget(new QLabel(contentLabel, this)); gameOptionsLayout->addSpacerItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Preferred)); gameOptionsLayout->addWidget(button); form->addRow(label, gameOptionsLayout); } } } retroarch_ctl(RARCH_CTL_CORE_OPTIONS_LIST_GET, &coreopts); if (coreopts) { QToolButton *resetAllButton = new QToolButton(this); resetAllButton->setDefaultAction(new QAction(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_RESET_ALL), this)); connect(resetAllButton, SIGNAL(clicked()), this, SLOT(onCoreOptionResetAllClicked())); for (j = 0; j < opts; j++) { QString desc = core_option_manager_get_desc(coreopts, j, false); QString val = core_option_manager_get_val(coreopts, j); QComboBox *combo_box = NULL; QLabel *descLabel = NULL; QHBoxLayout *comboLayout = NULL; QToolButton *resetButton = NULL; struct core_option *option = NULL; if (desc.isEmpty() || !coreopts->opts) continue; option = static_cast(&coreopts->opts[j]); if (!option->vals || option->vals->size == 0) continue; comboLayout = new QHBoxLayout(); descLabel = new QLabel(desc, this); combo_box = new QComboBox(this); combo_box->setObjectName("coreOptionComboBox"); resetButton = new QToolButton(this); resetButton->setObjectName("resetButton"); resetButton->setDefaultAction(new QAction(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_RESET), this)); resetButton->setProperty("comboBox", QVariant::fromValue(combo_box)); connect(resetButton, SIGNAL(clicked()), this, SLOT(onCoreOptionResetClicked())); if (option->info && *option->info) { char *new_info; size_t option_info_len = strlen(option->info); size_t new_info_len = option_info_len + 1; if (!(new_info = (char *)malloc(new_info_len))) return; new_info[0] = '\0'; word_wrap(new_info, new_info_len, option->info, option_info_len, 50, 100, 0); /* already wrapped to 50 columns: keep the line breaks */ descLabel->setToolTip(QStringLiteral("
")
                     + QString::fromUtf8(new_info).toHtmlEscaped()
                     + QStringLiteral("
")); combo_box->setToolTip(descLabel->toolTip()); free(new_info); } for (k = 0; k < option->vals->size; k++) combo_box->addItem(option->vals->elems[k].data, QVariant::fromValue(QString(option->key))); combo_box->setCurrentText(val); combo_box->setProperty("default_index", static_cast(option->default_index)); /* Only connect the signal after setting the default item */ connect(combo_box, SIGNAL(currentIndexChanged(int)), this, SLOT(onCoreOptionComboBoxCurrentIndexChanged(int))); comboLayout->addWidget(combo_box); comboLayout->addWidget(resetButton); form->addRow(descLabel, comboLayout); } form->addRow(resetAllButton, new QWidget(this)); m_layout->addLayout(form); } } if (!opts) { QLabel *noParamsLabel = new QLabel(msg_hash_to_str( MENU_ENUM_LABEL_VALUE_NO_CORE_OPTIONS_AVAILABLE), this); noParamsLabel->setAlignment(Qt::AlignCenter); m_layout->addWidget(noParamsLabel); } m_layout->addItem(new QSpacerItem(20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding)); resize(width() + 1, height()); show(); resize(width() - 1, height()); } void CoreOptionsDialog::onCoreOptionResetClicked() { bool ok = false; QToolButton *button = qobject_cast(sender()); QComboBox *combo_box = NULL; int default_index = 0; if (!button) return; combo_box = qobject_cast(button->property("comboBox").value()); if (!combo_box) return; default_index = combo_box->property("default_index").toInt(&ok); if (!ok) return; if (default_index >= 0 && default_index < combo_box->count()) combo_box->setCurrentIndex(default_index); } void CoreOptionsDialog::onCoreOptionResetAllClicked() { int i; QList combo_boxes = findChildren("coreOptionComboBox"); for (i = 0; i < combo_boxes.count(); i++) { int default_index = 0; bool ok = false; QComboBox *combo_box = combo_boxes.at(i); if (!combo_box) continue; default_index = combo_box->property("default_index").toInt(&ok); if (!ok) continue; if (default_index >= 0 && default_index < combo_box->count()) combo_box->setCurrentIndex(default_index); } } #if defined(HAVE_MENU) #if defined(HAVE_CG) || defined(HAVE_GLSL) || defined(HAVE_SLANG) || defined(HAVE_HLSL) enum { QT_SHADER_PRESET_GLOBAL = 0, QT_SHADER_PRESET_CORE, QT_SHADER_PRESET_PARENT, QT_SHADER_PRESET_GAME, QT_SHADER_PRESET_NORMAL }; ShaderPass::ShaderPass(struct video_shader_pass *passToCopy) : pass(NULL) { if (passToCopy) { pass = (struct video_shader_pass*)calloc(1, sizeof(*pass)); memcpy(pass, passToCopy, sizeof(*pass)); } } ShaderPass::ShaderPass(const ShaderPass &other) : pass(NULL) { if (other.pass) { pass = (struct video_shader_pass*)calloc(1, sizeof(*pass)); memcpy(pass, other.pass, sizeof(*pass)); } } ShaderPass::~ShaderPass() { if (pass) free(pass); } ShaderPass& ShaderPass::operator=(const ShaderPass &other) { if (this != &other) { /* Free any buffer we already own before taking a copy of * other's, otherwise assigning into a non-empty ShaderPass * leaks the previous allocation. */ if (pass) { free(pass); pass = NULL; } if (other.pass) { pass = (struct video_shader_pass*)calloc(1, sizeof(*pass)); memcpy(pass, other.pass, sizeof(*pass)); } } return *this; } ShaderParamsDialog::ShaderParamsDialog(QWidget *parent) : QDialog(parent) ,m_layout() ,m_scrollArea() { setWindowTitle(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_SHADER_OPTIONS)); setObjectName("shaderParamsDialog"); resize(720, 480); QTimer::singleShot(0, this, SLOT(clearLayout())); } ShaderParamsDialog::~ShaderParamsDialog() { } void ShaderParamsDialog::resizeEvent(QResizeEvent *event) { QDialog::resizeEvent(event); if (!m_scrollArea) return; m_scrollArea->resize(event->size()); emit resized(event->size()); } void ShaderParamsDialog::closeEvent(QCloseEvent *event) { QDialog::closeEvent(event); emit closed(); } void ShaderParamsDialog::paintEvent(QPaintEvent *event) { QStyleOption o; QPainter p; o.initFrom(this); p.begin(this); style()->drawPrimitive( QStyle::PE_Widget, &o, &p, this); p.end(); QDialog::paintEvent(event); } QString ShaderParamsDialog::getFilterLabel(unsigned filter) { QString filterString; switch (filter) { case 0: filterString = msg_hash_to_str(MENU_ENUM_LABEL_VALUE_DONT_CARE); break; case 1: filterString = msg_hash_to_str(MENU_ENUM_LABEL_VALUE_LINEAR); break; case 2: filterString = msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NEAREST); break; default: break; } return filterString; } void ShaderParamsDialog::clearLayout() { QWidget *widget = NULL; if (m_scrollArea) { { QList _children = children(); for (int _i = 0; _i < _children.size(); _i++) delete _children[_i]; } } m_layout = new QVBoxLayout(); widget = new QWidget(); widget->setLayout(m_layout); widget->setObjectName("shaderParamsWidget"); m_scrollArea = new QScrollArea(); m_scrollArea->setParent(this); m_scrollArea->setWidgetResizable(true); m_scrollArea->setWidget(widget); m_scrollArea->setObjectName("shaderParamsScrollArea"); m_scrollArea->show(); } void ShaderParamsDialog::getShaders(struct video_shader **menu_shader, struct video_shader **video_shader) { video_shader_ctx_t shader_info = {0}; struct video_shader *shader = menu_shader_get(); if (menu_shader) { if (shader) *menu_shader = shader; else *menu_shader = NULL; } if (video_shader) { if (shader) *video_shader = shader_info.data; else *video_shader = NULL; } if (video_shader) { if (!video_shader_driver_get_current_shader(&shader_info)) { *video_shader = NULL; return; } if (!shader_info.data || shader_info.data->num_parameters > GFX_MAX_PARAMETERS) { *video_shader = NULL; return; } if (shader_info.data) *video_shader = shader_info.data; else *video_shader = NULL; } } void ShaderParamsDialog::onFilterComboBoxIndexChanged(int) { QVariant passVariant; QComboBox *comboBox = qobject_cast(sender()); int pass = 0; bool ok = false; struct video_shader *menu_shader = NULL; struct video_shader *video_shader = NULL; getShaders(&menu_shader, &video_shader); if (!comboBox) return; passVariant = comboBox->property("pass"); if (!passVariant.isValid()) return; pass = passVariant.toInt(&ok); if (!ok) return; if ( menu_shader && (pass >= 0) && (pass < static_cast(menu_shader->passes))) { QVariant data = comboBox->currentData(); if (data.isValid()) { unsigned filter = data.toUInt(&ok); if (ok) { if (menu_shader) menu_shader->pass[pass].filter = filter; if (video_shader) { video_shader->pass[pass].filter = filter; video_shader->flags |= SHDR_FLAG_MODIFIED; } command_event(CMD_EVENT_SHADERS_APPLY_CHANGES, NULL); } } } } void ShaderParamsDialog::onScaleComboBoxIndexChanged(int) { QVariant passVariant; QComboBox *comboBox = qobject_cast(sender()); int pass = 0; bool ok = false; struct video_shader *menu_shader = NULL; struct video_shader *video_shader = NULL; getShaders(&menu_shader, &video_shader); if (!comboBox) return; passVariant = comboBox->property("pass"); if (!passVariant.isValid()) return; pass = passVariant.toInt(&ok); if (!ok) return; if (menu_shader && pass >= 0 && pass < static_cast(menu_shader->passes)) { QVariant data = comboBox->currentData(); if (data.isValid()) { unsigned scale = data.toUInt(&ok); if (ok) { if (menu_shader) { menu_shader->pass[pass].fbo.scale_x = scale; menu_shader->pass[pass].fbo.scale_y = scale; if (scale) menu_shader->pass[pass].fbo.flags |= FBO_SCALE_FLAG_VALID; else menu_shader->pass[pass].fbo.flags &= ~FBO_SCALE_FLAG_VALID; } if (video_shader) { video_shader->pass[pass].fbo.scale_x = scale; video_shader->pass[pass].fbo.scale_y = scale; if (scale) video_shader->pass[pass].fbo.flags |= FBO_SCALE_FLAG_VALID; else video_shader->pass[pass].fbo.flags &= ~FBO_SCALE_FLAG_VALID; video_shader->flags |= SHDR_FLAG_MODIFIED; } command_event(CMD_EVENT_SHADERS_APPLY_CHANGES, NULL); } } } } /* The pass a parameter belongs to follows from the order the sources * sit in, so a swap is settled by resolving again rather than by * moving indices by hand: a parameter both of the swapped passes * declare belongs to whichever ends up first, which an index shift * cannot work out. A resolve returns every parameter to its initial * value, so the values in hand are carried across by id. */ static void shader_reresolve_keeping_values(struct video_shader *shader) { QHash values; unsigned i; if (!shader) return; for (i = 0; i < shader->num_parameters; i++) values.insert(QString(shader->parameters[i].id), video_shader_param_get(&shader->parameters[i])); video_shader_resolve_parameters(shader); for (i = 0; i < shader->num_parameters; i++) { QHash::const_iterator it = values.constFind(QString(shader->parameters[i].id)); if (it != values.constEnd()) video_shader_param_set(&shader->parameters[i], it.value()); } } void ShaderParamsDialog::onShaderPassMoveDownClicked() { QVariant passVariant; bool ok = false; struct video_shader *menu_shader = NULL; struct video_shader *video_shader = NULL; QToolButton *button = qobject_cast(sender()); int pass = 0; getShaders(&menu_shader, &video_shader); if (!button) return; passVariant = button->property("pass"); if (!passVariant.isValid()) return; pass = passVariant.toInt(&ok); if (!ok || pass < 0) return; if (video_shader) { ShaderPass tempPass; if (pass >= static_cast(video_shader->passes) - 1) return; tempPass = ShaderPass(&video_shader->pass[pass]); memcpy(&video_shader->pass[pass], &video_shader->pass[pass + 1], sizeof(struct video_shader_pass)); memcpy(&video_shader->pass[pass + 1], tempPass.pass, sizeof(struct video_shader_pass)); } if (menu_shader) { ShaderPass tempPass; if (pass >= static_cast(menu_shader->passes) - 1) return; tempPass = ShaderPass(&menu_shader->pass[pass]); memcpy(&menu_shader->pass[pass], &menu_shader->pass[pass + 1], sizeof(struct video_shader_pass)); memcpy(&menu_shader->pass[pass + 1], tempPass.pass, sizeof(struct video_shader_pass)); } shader_reresolve_keeping_values(video_shader); shader_reresolve_keeping_values(menu_shader); if (menu_shader) menu_shader->flags |= SHDR_FLAG_MODIFIED; reload(); } void ShaderParamsDialog::onShaderPassMoveUpClicked() { QVariant passVariant; int pass = 0; bool ok = false; struct video_shader *menu_shader = NULL; struct video_shader *video_shader = NULL; QToolButton *button = qobject_cast(sender()); getShaders(&menu_shader, &video_shader); if (!button) return; passVariant = button->property("pass"); if (!passVariant.isValid()) return; pass = passVariant.toInt(&ok); if (!ok || pass <= 0) return; if (video_shader) { ShaderPass tempPass; if (pass > static_cast(video_shader->passes) - 1) return; tempPass = ShaderPass(&video_shader->pass[pass - 1]); memcpy(&video_shader->pass[pass - 1], &video_shader->pass[pass], sizeof(struct video_shader_pass)); memcpy(&video_shader->pass[pass], tempPass.pass, sizeof(struct video_shader_pass)); } if (menu_shader) { ShaderPass tempPass; if (pass > static_cast(menu_shader->passes) - 1) return; tempPass = ShaderPass(&menu_shader->pass[pass - 1]); memcpy(&menu_shader->pass[pass - 1], &menu_shader->pass[pass], sizeof(struct video_shader_pass)); memcpy(&menu_shader->pass[pass], tempPass.pass, sizeof(struct video_shader_pass)); } shader_reresolve_keeping_values(video_shader); shader_reresolve_keeping_values(menu_shader); if (menu_shader) menu_shader->flags |= SHDR_FLAG_MODIFIED; reload(); } void ShaderParamsDialog::onShaderLoadPresetClicked() { QString path, filter; QByteArray pathArray; gfx_ctx_flags_t flags; struct video_shader *menu_shader = NULL; struct video_shader *video_shader = NULL; const char *pathData = NULL; enum rarch_shader_type type = RARCH_SHADER_NONE; #if !defined(HAVE_MENU) settings_t *settings = config_get_ptr(); const char *shader_preset_dir = settings->paths.directory_video_shader; #else const char *shader_preset_dir = NULL; menu_driver_get_last_shader_preset_path(&shader_preset_dir, NULL); #endif getShaders(&menu_shader, &video_shader); if (!menu_shader) return; filter.append("Shader Preset ("); flags.flags = 0; video_context_driver_get_flags(&flags); /* NOTE: Maybe we should have a way to get a list * of all shader types instead of hard-coding this? */ if (BIT32_GET(flags.flags, GFX_CTX_FLAGS_SHADERS_CG)) { filter.append(QLatin1String(" *")); filter.append(".cgp"); } if (BIT32_GET(flags.flags, GFX_CTX_FLAGS_SHADERS_GLSL)) { filter.append(QLatin1String(" *")); filter.append(".glslp"); } if (BIT32_GET(flags.flags, GFX_CTX_FLAGS_SHADERS_SLANG)) { filter.append(QLatin1String(" *")); filter.append(".slangp"); } filter.append(")"); path = QFileDialog::getOpenFileName( this, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_VIDEO_SHADER_PRESET), shader_preset_dir, filter); if (path.isEmpty()) return; pathArray = path.toUtf8(); pathData = pathArray.constData(); type = video_shader_parse_type(pathData); #if defined(HAVE_MENU) /* Cache selected shader parent directory */ menu_driver_set_last_shader_preset_path(pathData); #endif menu_shader_manager_set_preset(menu_shader, type, pathData, true); } void ShaderParamsDialog::onShaderResetPass(int pass) { unsigned i; struct video_shader *menu_shader = NULL; struct video_shader *video_shader = NULL; getShaders(&menu_shader, &video_shader); if (menu_shader) { for (i = 0; i < menu_shader->num_parameters; i++) { struct video_shader_parameter *param = &menu_shader->parameters[i]; /* if pass < 0, reset all params, * otherwise only reset the selected pass */ if (pass >= 0 && param->pass != pass) continue; video_shader_param_set(param, param->initial); } } if (video_shader) { for (i = 0; i < video_shader->num_parameters; i++) { struct video_shader_parameter *param = &video_shader->parameters[i]; /* if pass < 0, reset all params, * otherwise only reset the selected pass */ if (pass >= 0 && param->pass != pass) continue; video_shader_param_set(param, param->initial); } video_shader->flags |= SHDR_FLAG_MODIFIED; } reload(); } void ShaderParamsDialog::onShaderResetParameter(QString parameter) { struct video_shader *menu_shader = NULL; struct video_shader *video_shader = NULL; getShaders(&menu_shader, &video_shader); if (menu_shader) { int i; struct video_shader_parameter *param = NULL; for (i = 0; i < static_cast(menu_shader->num_parameters); i++) { QString id = menu_shader->parameters[i].id; if (id == parameter) param = &menu_shader->parameters[i]; } if (param) video_shader_param_set(param, param->initial); } if (video_shader) { int i; struct video_shader_parameter *param = NULL; for (i = 0; i < static_cast(video_shader->num_parameters); i++) { QString id = video_shader->parameters[i].id; if (id == parameter) param = &video_shader->parameters[i]; } if (param) video_shader_param_set(param, param->initial); video_shader->flags |= SHDR_FLAG_MODIFIED; } reload(); } void ShaderParamsDialog::onShaderResetAllPasses() { onShaderResetPass(-1); } void ShaderParamsDialog::onShaderAddPassClicked() { gfx_ctx_flags_t flags; QString path, filter; QByteArray pathArray; struct video_shader *menu_shader = NULL; struct video_shader *video_shader = NULL; struct video_shader_pass *shader_pass = NULL; const char *pathData = NULL; #if !defined(HAVE_MENU) settings_t *settings = config_get_ptr(); const char *shader_pass_dir = settings->paths.directory_video_shader; #else const char *shader_pass_dir = NULL; menu_driver_get_last_shader_pass_path(&shader_pass_dir, NULL); #endif getShaders(&menu_shader, &video_shader); if (!menu_shader) return; filter.append("Shader ("); flags.flags = 0; video_context_driver_get_flags(&flags); /* NOTE: Maybe we should have a way to get a list * of all shader types instead of hard-coding this? */ if (BIT32_GET(flags.flags, GFX_CTX_FLAGS_SHADERS_CG)) filter.append(QLatin1String(" *.cg")); if (BIT32_GET(flags.flags, GFX_CTX_FLAGS_SHADERS_GLSL)) filter.append(QLatin1String(" *.glsl")); if (BIT32_GET(flags.flags, GFX_CTX_FLAGS_SHADERS_SLANG)) filter.append(QLatin1String(" *.slang")); filter.append(")"); path = QFileDialog::getOpenFileName( this, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_VIDEO_SHADER_PRESET), shader_pass_dir, filter); if (path.isEmpty()) return; /* Qt uses '/' as a directory separator regardless * of host platform. Have to convert to native separators, * or video_shader_resolve_parameters() will fail on * non-Linux platforms */ path = QDir::toNativeSeparators(path); pathArray = path.toUtf8(); pathData = pathArray.constData(); if (menu_shader->passes < GFX_MAX_SHADERS) menu_shader->passes++; else return; menu_shader->flags |= SHDR_FLAG_MODIFIED; shader_pass = &menu_shader->pass[menu_shader->passes - 1]; if (!shader_pass) return; strlcpy(shader_pass->source.path, pathData, sizeof(shader_pass->source.path)); #if defined(HAVE_MENU) /* Cache selected shader parent directory */ menu_driver_set_last_shader_pass_path(pathData); #endif video_shader_resolve_parameters(menu_shader); command_event(CMD_EVENT_SHADERS_APPLY_CHANGES, NULL); } void ShaderParamsDialog::onShaderSavePresetAsClicked() { QByteArray pathArray; const char *pathData = NULL; settings_t *settings = config_get_ptr(); const char *path_dir_video_shader = settings->paths.directory_video_shader; QString path = QFileDialog::getSaveFileName(this, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_VIDEO_SHADER_PRESET_SAVE_AS), path_dir_video_shader); if (path.isEmpty()) return; pathArray = path.toUtf8(); pathData = pathArray.constData(); operateShaderPreset(true, pathData, QT_SHADER_PRESET_NORMAL); } /** save or remove shader preset */ void ShaderParamsDialog::operateShaderPreset(bool save, const char *path, unsigned action_type) { bool ret; enum auto_shader_type preset_type; settings_t *settings = config_get_ptr(); const char *path_dir_video_shader = settings->paths.directory_video_shader; const char *path_dir_menu_config = settings->paths.directory_menu_config; switch (action_type) { case QT_SHADER_PRESET_GLOBAL: preset_type = SHADER_PRESET_GLOBAL; break; case QT_SHADER_PRESET_CORE: preset_type = SHADER_PRESET_CORE; break; case QT_SHADER_PRESET_PARENT: preset_type = SHADER_PRESET_PARENT; break; case QT_SHADER_PRESET_GAME: preset_type = SHADER_PRESET_GAME; break; case QT_SHADER_PRESET_NORMAL: break; default: return; } if (save) { if (action_type == QT_SHADER_PRESET_NORMAL) ret = menu_shader_manager_save_preset( menu_shader_get(), path, path_dir_video_shader, path_dir_menu_config, true); else ret = menu_shader_manager_save_auto_preset( menu_shader_get(), preset_type, path_dir_video_shader, path_dir_menu_config, true); if (ret) { const char *_msg = msg_hash_to_str(MSG_SHADER_PRESET_SAVED_SUCCESSFULLY); runloop_msg_queue_push(_msg, strlen(_msg), 1, 100, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO); } else { const char *_msg = msg_hash_to_str(MSG_ERROR_SAVING_SHADER_PRESET); runloop_msg_queue_push(_msg, strlen(_msg), 1, 100, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_ERROR); } } else { if (action_type != QT_SHADER_PRESET_NORMAL && menu_shader_manager_remove_auto_preset(preset_type, path_dir_video_shader, path_dir_menu_config)) { const char *_msg = msg_hash_to_str(MSG_SHADER_PRESET_REMOVED_SUCCESSFULLY); runloop_msg_queue_push(_msg, strlen(_msg), 1, 100, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO); #ifdef HAVE_MENU menu_state_get_ptr()->flags |= MENU_ST_FLAG_ENTRIES_NEED_REFRESH; #endif } else { const char *_msg = msg_hash_to_str(MSG_ERROR_REMOVING_SHADER_PRESET); runloop_msg_queue_push(_msg, strlen(_msg), 1, 100, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_ERROR); } } } void ShaderParamsDialog::onShaderSaveGlobalPresetClicked() { operateShaderPreset(true, NULL, QT_SHADER_PRESET_GLOBAL); } void ShaderParamsDialog::onShaderSaveCorePresetClicked() { operateShaderPreset(true, NULL, QT_SHADER_PRESET_CORE); } void ShaderParamsDialog::onShaderSaveParentPresetClicked() { operateShaderPreset(true, NULL, QT_SHADER_PRESET_PARENT); } void ShaderParamsDialog::onShaderSaveGamePresetClicked() { operateShaderPreset(true, NULL, QT_SHADER_PRESET_GAME); } void ShaderParamsDialog::onShaderRemoveGlobalPresetClicked() { operateShaderPreset(false, NULL, QT_SHADER_PRESET_GLOBAL); } void ShaderParamsDialog::onShaderRemoveCorePresetClicked() { operateShaderPreset(false, NULL, QT_SHADER_PRESET_CORE); } void ShaderParamsDialog::onShaderRemoveParentPresetClicked() { operateShaderPreset(false, NULL, QT_SHADER_PRESET_PARENT); } void ShaderParamsDialog::onShaderRemoveGamePresetClicked() { operateShaderPreset(false, NULL, QT_SHADER_PRESET_GAME); } void ShaderParamsDialog::onShaderRemoveAllPassesClicked() { struct video_shader *menu_shader = NULL; struct video_shader *video_shader = NULL; getShaders(&menu_shader, &video_shader); if (!menu_shader) return; menu_shader->passes = 0; menu_shader->flags |= SHDR_FLAG_MODIFIED; onShaderApplyClicked(); } void ShaderParamsDialog::onShaderRemovePassClicked() { QVariant passVariant; QAction *action = qobject_cast(sender()); int pass = 0; bool ok = false; if (!action) return; passVariant = action->data(); if (!passVariant.isValid()) return; pass = passVariant.toInt(&ok); if (!ok) return; onShaderRemovePass(pass); } void ShaderParamsDialog::onShaderRemovePass(int pass) { int i; struct video_shader *menu_shader = NULL; struct video_shader *video_shader = NULL; getShaders(&menu_shader, &video_shader); if (!menu_shader || menu_shader->passes == 0) return; if (pass < 0 || pass > static_cast(menu_shader->passes)) return; /* move selected pass to the bottom */ for (i = pass; i < static_cast(menu_shader->passes) - 1; i++) std::swap(menu_shader->pass[i], menu_shader->pass[i + 1]); menu_shader->passes--; menu_shader->flags |= SHDR_FLAG_MODIFIED; onShaderApplyClicked(); } void ShaderParamsDialog::onShaderApplyClicked() { command_event(CMD_EVENT_SHADERS_APPLY_CHANGES, NULL); } void ShaderParamsDialog::updateRemovePresetButtonsState() { settings_t *settings = config_get_ptr(); const char *path_dir_video_shader = settings->paths.directory_video_shader; const char *path_dir_menu_config = settings->paths.directory_menu_config; if (removeGlobalPresetAction) removeGlobalPresetAction->setEnabled( menu_shader_manager_auto_preset_exists( SHADER_PRESET_GLOBAL, path_dir_video_shader, path_dir_menu_config )); if (removeCorePresetAction) removeCorePresetAction->setEnabled( menu_shader_manager_auto_preset_exists( SHADER_PRESET_CORE, path_dir_video_shader, path_dir_menu_config )); if (removeParentPresetAction) removeParentPresetAction->setEnabled( menu_shader_manager_auto_preset_exists( SHADER_PRESET_PARENT, path_dir_video_shader, path_dir_menu_config )); if (removeGamePresetAction) removeGamePresetAction->setEnabled( menu_shader_manager_auto_preset_exists( SHADER_PRESET_GAME, path_dir_video_shader, path_dir_menu_config )); } void ShaderParamsDialog::reload() { buildLayout(); } void ShaderParamsDialog::buildLayout() { unsigned i; bool hasPasses = false; #if defined(HAVE_MENU) CheckableSettingsGroup *topSettingsGroup = NULL; #endif QPushButton *loadButton = NULL; QPushButton *saveButton = NULL; QPushButton *removeButton = NULL; QPushButton *removePassButton = NULL; QPushButton *applyButton = NULL; QHBoxLayout *topButtonLayout = NULL; QMenu *loadMenu = NULL; QMenu *saveMenu = NULL; QMenu *removeMenu = NULL; QMenu *removePassMenu = NULL; struct video_shader *menu_shader = NULL; struct video_shader *video_shader = NULL; struct video_shader *avail_shader = NULL; const char *shader_path = NULL; getShaders(&menu_shader, &video_shader); /* NOTE: For some reason, menu_shader_get() returns a COPY * of what get_current_shader() gives us. * And if you want to be able to change shader settings/parameters * from both the raster menu and * Qt at the same time... you must change BOTH or one will * overwrite the other. * * AND, during a context reset, video_shader will be NULL * but not menu_shader, so don't totally bail * just because video_shader is NULL. * * Someone please fix this mess. */ if (video_shader) { avail_shader = video_shader; if (video_shader->passes == 0) setWindowTitle(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_SHADER_OPTIONS)); } /* Normally we'd only use video_shader, * but the Vulkan driver returns a NULL shader when there * are zero passes, so just fall back to menu_shader. */ else if (menu_shader) { avail_shader = menu_shader; if (menu_shader->passes == 0) setWindowTitle(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_SHADER_OPTIONS)); } else { setWindowTitle(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_SHADER_OPTIONS)); /* no shader is available yet, just keep retrying until it is */ QTimer::singleShot(0, this, SLOT(buildLayout())); return; } clearLayout(); /* Only check video_shader for the path, menu_shader seems stale... * e.g. if you remove all the shader passes, * it still has the old path in it, but video_shader does not */ if (video_shader) { if (*video_shader->path) { shader_path = video_shader->path; setWindowTitle(QString(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_CURRENT_SHADER)) + ": " + QFileInfo(shader_path).fileName()); } } else if (menu_shader) { if (*menu_shader->path) { shader_path = menu_shader->path; setWindowTitle(QString(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_CURRENT_SHADER)) + ": " + QFileInfo(shader_path).fileName()); } } else setWindowTitle(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_SHADER_OPTIONS)); loadButton = new QPushButton(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_LOAD), this); saveButton = new QPushButton(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_SAVE), this); removeButton = new QPushButton(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_REMOVE), this); removePassButton = new QPushButton(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_REMOVE_PASSES), this); applyButton = new QPushButton(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_APPLY), this); loadMenu = new QMenu(loadButton); loadMenu->addAction(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_VIDEO_SHADER_PRESET), this, SLOT(onShaderLoadPresetClicked())); loadMenu->addAction(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_SHADER_ADD_PASS), this, SLOT(onShaderAddPassClicked())); loadButton->setMenu(loadMenu); saveMenu = new QMenu(saveButton); saveMenu->addAction(QString(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_VIDEO_SHADER_PRESET_SAVE_AS)) + "...", this, SLOT(onShaderSavePresetAsClicked())); saveMenu->addAction(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_VIDEO_SHADER_PRESET_SAVE_GLOBAL), this, SLOT(onShaderSaveGlobalPresetClicked())); saveMenu->addAction(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_VIDEO_SHADER_PRESET_SAVE_CORE), this, SLOT(onShaderSaveCorePresetClicked())); saveMenu->addAction(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_VIDEO_SHADER_PRESET_SAVE_PARENT), this, SLOT(onShaderSaveParentPresetClicked())); saveMenu->addAction(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_VIDEO_SHADER_PRESET_SAVE_GAME), this, SLOT(onShaderSaveGamePresetClicked())); saveButton->setMenu(saveMenu); removeMenu = new QMenu(removeButton); removeGlobalPresetAction = removeMenu->addAction(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_VIDEO_SHADER_PRESET_REMOVE_GLOBAL), this, SLOT(onShaderRemoveGlobalPresetClicked())); removeCorePresetAction = removeMenu->addAction(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_VIDEO_SHADER_PRESET_REMOVE_CORE), this, SLOT(onShaderRemoveCorePresetClicked())); removeParentPresetAction = removeMenu->addAction(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_VIDEO_SHADER_PRESET_REMOVE_PARENT), this, SLOT(onShaderRemoveParentPresetClicked())); removeGamePresetAction = removeMenu->addAction(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_VIDEO_SHADER_PRESET_REMOVE_GAME), this, SLOT(onShaderRemoveGamePresetClicked())); removeButton->setMenu(removeMenu); connect(removeMenu, SIGNAL(aboutToShow()), this, SLOT(updateRemovePresetButtonsState())); removePassMenu = new QMenu(removeButton); /* When there are no passes, at least on first startup, it seems video_shader erroneously shows 1 pass, with an empty source file. * So we use menu_shader instead for that. */ if (menu_shader) { for (i = 0; i < menu_shader->passes; i++) { QFileInfo fileInfo(menu_shader->pass[i].source.path); QString shaderBasename = fileInfo.completeBaseName(); QAction *action = removePassMenu->addAction(shaderBasename, this, SLOT(onShaderRemovePassClicked())); action->setData(i); } } removePassMenu->addAction(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_SHADER_CLEAR_ALL_PASSES), this, SLOT(onShaderRemoveAllPassesClicked())); removePassButton->setMenu(removePassMenu); connect(applyButton, SIGNAL(clicked()), this, SLOT(onShaderApplyClicked())); #if defined(HAVE_MENU) topSettingsGroup = new CheckableSettingsGroup(MENU_ENUM_LABEL_VIDEO_SHADERS_ENABLE); topSettingsGroup->add(MENU_ENUM_LABEL_VIDEO_SHADER_PRESET_SAVE_REFERENCE); topSettingsGroup->add(MENU_ENUM_LABEL_SHADER_WATCH_FOR_CHANGES); topSettingsGroup->add(MENU_ENUM_LABEL_VIDEO_SHADER_REMEMBER_LAST_DIR); #endif topButtonLayout = new QHBoxLayout(); topButtonLayout->addWidget(loadButton); topButtonLayout->addWidget(saveButton); topButtonLayout->addWidget(removeButton); topButtonLayout->addWidget(removePassButton); topButtonLayout->addWidget(applyButton); #if defined(HAVE_MENU) m_layout->addWidget(topSettingsGroup); #endif m_layout->addLayout(topButtonLayout); /* NOTE: We assume that parameters are always grouped in order by the pass number, e.g., all parameters for pass 0 come first, then params for pass 1, etc. */ for (i = 0; avail_shader && i < avail_shader->passes; i++) { QFormLayout *form = NULL; QGroupBox *groupBox = NULL; QFileInfo fileInfo(avail_shader->pass[i].source.path); QString shaderBasename = fileInfo.completeBaseName(); QHBoxLayout *filterScaleHBoxLayout = NULL; QComboBox *filterComboBox = new QComboBox(this); QComboBox *scaleComboBox = new QComboBox(this); QToolButton *moveDownButton = NULL; QToolButton *moveUpButton = NULL; unsigned j = 0; /* Sometimes video_shader shows 1 pass with no source file, when there are really 0 passes. */ if (shaderBasename.isEmpty()) continue; hasPasses = true; filterComboBox->setProperty("pass", i); scaleComboBox->setProperty("pass", i); moveDownButton = new QToolButton(this); moveDownButton->setText("↓"); moveDownButton->setProperty("pass", i); moveUpButton = new QToolButton(this); moveUpButton->setText("↑"); moveUpButton->setProperty("pass", i); /* Can't move down if we're already at the bottom. */ if (i < avail_shader->passes - 1) connect(moveDownButton, SIGNAL(clicked()), this, SLOT(onShaderPassMoveDownClicked())); else moveDownButton->setDisabled(true); /* Can't move up if we're already at the top. */ if (i > 0) connect(moveUpButton, SIGNAL(clicked()), this, SLOT(onShaderPassMoveUpClicked())); else moveUpButton->setDisabled(true); for (;;) { QString filterLabel = getFilterLabel(j); if (filterLabel.isEmpty()) break; if (j == 0) filterLabel = msg_hash_to_str(MENU_ENUM_LABEL_VALUE_DONT_CARE); filterComboBox->addItem(filterLabel, j); j++; } for (j = 0; j < 7; j++) { QString label; if (j == 0) label = msg_hash_to_str(MENU_ENUM_LABEL_VALUE_DONT_CARE); else label = QString::number(j) + "x"; scaleComboBox->addItem(label, j); } filterComboBox->setCurrentIndex(static_cast(avail_shader->pass[i].filter)); scaleComboBox->setCurrentIndex(static_cast(avail_shader->pass[i].fbo.scale_x)); /* connect the signals only after the initial index is set */ connect(filterComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onFilterComboBoxIndexChanged(int))); connect(scaleComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onScaleComboBoxIndexChanged(int))); form = new QFormLayout(); groupBox = new QGroupBox(shaderBasename); groupBox->setLayout(form); groupBox->setProperty("pass", i); groupBox->setContextMenuPolicy(Qt::CustomContextMenu); connect(groupBox, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(onGroupBoxContextMenuRequested(const QPoint&))); m_layout->addWidget(groupBox); filterScaleHBoxLayout = new QHBoxLayout(); filterScaleHBoxLayout->addSpacerItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Preferred)); filterScaleHBoxLayout->addWidget(new QLabel(QString(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_FILTER)) + ":", this)); filterScaleHBoxLayout->addWidget(filterComboBox); filterScaleHBoxLayout->addWidget(new QLabel(QString(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_SCALE)) + ":", this)); filterScaleHBoxLayout->addWidget(scaleComboBox); filterScaleHBoxLayout->addSpacerItem(new QSpacerItem(20, 0, QSizePolicy::Preferred, QSizePolicy::Preferred)); if (moveUpButton) filterScaleHBoxLayout->addWidget(moveUpButton); if (moveDownButton) filterScaleHBoxLayout->addWidget(moveDownButton); form->addRow("", filterScaleHBoxLayout); for (j = 0; j < avail_shader->num_parameters; j++) { struct video_shader_parameter *param = &avail_shader->parameters[j]; if (param->pass != static_cast(i)) continue; addShaderParam(param, form); } } if (!hasPasses) { QLabel *noParamsLabel = new QLabel(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_SHADER_NO_PASSES), this); noParamsLabel->setAlignment(Qt::AlignCenter); m_layout->addWidget(noParamsLabel); } m_layout->addItem(new QSpacerItem(20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding)); /* Why is this required?? The layout is corrupt without both resizes. */ resize(width() + 1, height()); show(); resize(width() - 1, height()); } void ShaderParamsDialog::onParameterLabelContextMenuRequested(const QPoint&) { QVariant paramVariant; QString parameter; QPointer action; QList actions; QScopedPointer resetParamAction; QLabel *label = qobject_cast(sender()); if (!label) return; paramVariant = label->property("parameter"); if (!paramVariant.isValid()) return; parameter = paramVariant.toString(); resetParamAction.reset(new QAction(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_RESET_PARAMETER), 0)); actions.append(resetParamAction.data()); action = QMenu::exec(actions, QCursor::pos(), NULL, label); if (!action) return; if (action == resetParamAction.data()) onShaderResetParameter(parameter); } void ShaderParamsDialog::onGroupBoxContextMenuRequested(const QPoint&) { QPointer action; QList actions; QScopedPointer resetPassAction; QScopedPointer resetAllPassesAction; QVariant passVariant; int pass = 0; bool ok = false; QGroupBox *groupBox = qobject_cast(sender()); if (!groupBox) return; passVariant = groupBox->property("pass"); if (!passVariant.isValid()) return; pass = passVariant.toInt(&ok); if (!ok) return; resetPassAction.reset(new QAction(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_RESET_PASS), 0)); resetAllPassesAction.reset(new QAction(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_RESET_ALL_PASSES), 0)); actions.append(resetPassAction.data()); actions.append(resetAllPassesAction.data()); action = QMenu::exec(actions, QCursor::pos(), NULL, groupBox); if (!action) return; if (action == resetPassAction.data()) onShaderResetPass(pass); else if (action == resetAllPassesAction.data()) onShaderResetAllPasses(); } void ShaderParamsDialog::addShaderParam(struct video_shader_parameter *param, QFormLayout *form) { QString desc = param->desc; QString parameter = param->id; QLabel *label = new QLabel(desc); label->setProperty("parameter", parameter); label->setContextMenuPolicy(Qt::CustomContextMenu); connect(label, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(onParameterLabelContextMenuRequested(const QPoint&))); if ((param->minimum == 0.0) && (param->maximum == (param->minimum + param->step))) { /* option is basically a bool, so use a checkbox */ QCheckBox *checkBox = new QCheckBox(this); checkBox->setChecked(video_shader_param_get(param) == param->maximum ? true : false); checkBox->setProperty("param", parameter); connect(checkBox, SIGNAL(clicked()), this, SLOT(onShaderParamCheckBoxClicked())); form->addRow(label, checkBox); } else { QDoubleSpinBox *doubleSpinBox = NULL; QSpinBox *spinBox = NULL; QHBoxLayout *box = new QHBoxLayout(); QSlider *slider = new QSlider(Qt::Horizontal, this); double value = lerp( param->minimum, param->maximum, 0, 100, video_shader_param_get(param)); double intpart = 0; bool stepIsFractional = modf(param->step, &intpart); slider->setRange(0, 100); slider->setSingleStep(1); slider->setValue(value); slider->setProperty("param", parameter); connect(slider, SIGNAL(valueChanged(int)), this, SLOT(onShaderParamSliderValueChanged(int))); box->addWidget(slider); if (stepIsFractional) { doubleSpinBox = new QDoubleSpinBox(this); doubleSpinBox->setRange(param->minimum, param->maximum); doubleSpinBox->setSingleStep(param->step); doubleSpinBox->setValue(video_shader_param_get(param)); doubleSpinBox->setProperty("slider", QVariant::fromValue(slider)); slider->setProperty("doubleSpinBox", QVariant::fromValue(doubleSpinBox)); connect(doubleSpinBox, SIGNAL(valueChanged(double)), this, SLOT(onShaderParamDoubleSpinBoxValueChanged(double))); box->addWidget(doubleSpinBox); } else { spinBox = new QSpinBox(this); spinBox->setRange(param->minimum, param->maximum); spinBox->setSingleStep(param->step); spinBox->setValue(video_shader_param_get(param)); spinBox->setProperty("slider", QVariant::fromValue(slider)); slider->setProperty("spinBox", QVariant::fromValue(spinBox)); connect(spinBox, SIGNAL(valueChanged(int)), this, SLOT(onShaderParamSpinBoxValueChanged(int))); box->addWidget(spinBox); } form->addRow(label, box); } } void ShaderParamsDialog::onShaderParamCheckBoxClicked() { QVariant paramVariant; QCheckBox *checkBox = qobject_cast(sender()); struct video_shader *menu_shader = NULL; struct video_shader *video_shader = NULL; getShaders(&menu_shader, &video_shader); if (!checkBox) return; if (menu_shader && menu_shader->passes == 0) return; paramVariant = checkBox->property("param"); if (paramVariant.isValid()) { QString parameter = paramVariant.toString(); if (menu_shader) { int i; struct video_shader_parameter *param = NULL; for (i = 0; i < static_cast(menu_shader->num_parameters); i++) { QString id = menu_shader->parameters[i].id; if (id == parameter) param = &menu_shader->parameters[i]; } if (param) video_shader_param_set(param, (checkBox->isChecked() ? param->maximum : param->minimum)); } if (video_shader) { int i; struct video_shader_parameter *param = NULL; for (i = 0; i < static_cast(video_shader->num_parameters); i++) { QString id = video_shader->parameters[i].id; if (id == parameter) param = &video_shader->parameters[i]; } if (param) video_shader_param_set(param, (checkBox->isChecked() ? param->maximum : param->minimum)); video_shader->flags |= SHDR_FLAG_MODIFIED; } } } void ShaderParamsDialog::onShaderParamSliderValueChanged(int) { QVariant spinBoxVariant; QVariant paramVariant; QSlider *slider = qobject_cast(sender()); struct video_shader *menu_shader = NULL; struct video_shader *video_shader = NULL; double newValue = 0.0; getShaders(&menu_shader, &video_shader); if (!slider) return; spinBoxVariant = slider->property("spinBox"); paramVariant = slider->property("param"); if (paramVariant.isValid()) { QString parameter = paramVariant.toString(); if (menu_shader) { int i; struct video_shader_parameter *param = NULL; for (i = 0; i < static_cast(menu_shader->num_parameters); i++) { QString id = menu_shader->parameters[i].id; if (id == parameter) param = &menu_shader->parameters[i]; } if (param) { newValue = lerp(0, 100, param->minimum, param->maximum, slider->value()); newValue = round(newValue / param->step) * param->step; video_shader_param_set(param, newValue); } } if (video_shader) { int i; struct video_shader_parameter *param = NULL; for (i = 0; i < static_cast(video_shader->num_parameters); i++) { QString id = video_shader->parameters[i].id; if (id == parameter) param = &video_shader->parameters[i]; } if (param) { newValue = lerp(0, 100, param->minimum, param->maximum, slider->value()); newValue = round(newValue / param->step) * param->step; video_shader_param_set(param, newValue); } video_shader->flags |= SHDR_FLAG_MODIFIED; } } if (spinBoxVariant.isValid()) { QSpinBox *spinBox = spinBoxVariant.value(); if (!spinBox) return; spinBox->blockSignals(true); spinBox->setValue(newValue); spinBox->blockSignals(false); } else { QVariant doubleSpinBoxVariant = slider->property("doubleSpinBox"); QDoubleSpinBox *doubleSpinBox = doubleSpinBoxVariant.value(); if (!doubleSpinBox) return; doubleSpinBox->blockSignals(true); doubleSpinBox->setValue(newValue); doubleSpinBox->blockSignals(false); } } void ShaderParamsDialog::onShaderParamSpinBoxValueChanged(int value) { QVariant sliderVariant; QVariant paramVariant; QSpinBox *spinBox = qobject_cast(sender()); QSlider *slider = NULL; struct video_shader *menu_shader = NULL; struct video_shader *video_shader = NULL; getShaders(&menu_shader, &video_shader); if (!spinBox) return; sliderVariant = spinBox->property("slider"); if (!sliderVariant.isValid()) return; slider = sliderVariant.value(); if (!slider) return; paramVariant = slider->property("param"); if (paramVariant.isValid()) { QString parameter = paramVariant.toString(); double newValue = 0.0; if (menu_shader) { int i; struct video_shader_parameter *param = NULL; for (i = 0; i < static_cast(menu_shader->num_parameters); i++) { QString id = menu_shader->parameters[i].id; if (id == parameter) param = &menu_shader->parameters[i]; } if (param) { video_shader_param_set(param, value); newValue = lerp( param->minimum, param->maximum, 0, 100, video_shader_param_get(param)); slider->blockSignals(true); slider->setValue(newValue); slider->blockSignals(false); } } if (video_shader) { int i; struct video_shader_parameter *param = NULL; for (i = 0; i < static_cast(video_shader->num_parameters); i++) { QString id = video_shader->parameters[i].id; if (id == parameter) param = &video_shader->parameters[i]; } if (param) { video_shader_param_set(param, value); newValue = lerp( param->minimum, param->maximum, 0, 100, video_shader_param_get(param)); slider->blockSignals(true); slider->setValue(newValue); slider->blockSignals(false); } video_shader->flags |= SHDR_FLAG_MODIFIED; } } } void ShaderParamsDialog::onShaderParamDoubleSpinBoxValueChanged(double value) { QVariant sliderVariant; QVariant paramVariant; QSlider *slider = NULL; QDoubleSpinBox *doubleSpinBox = qobject_cast(sender()); struct video_shader *menu_shader = NULL; struct video_shader *video_shader = NULL; getShaders(&menu_shader, &video_shader); if (!doubleSpinBox) return; sliderVariant = doubleSpinBox->property("slider"); if (!sliderVariant.isValid()) return; slider = sliderVariant.value(); if (!slider) return; paramVariant = slider->property("param"); if (paramVariant.isValid()) { QString parameter = paramVariant.toString(); double newValue = 0.0; if (menu_shader) { int i; struct video_shader_parameter *param = NULL; for (i = 0; i < static_cast(menu_shader->num_parameters); i++) { QString id = menu_shader->parameters[i].id; if (id == parameter) param = &menu_shader->parameters[i]; } if (param) { video_shader_param_set(param, value); newValue = lerp( param->minimum, param->maximum, 0, 100, video_shader_param_get(param)); slider->blockSignals(true); slider->setValue(newValue); slider->blockSignals(false); } } if (video_shader) { int i; struct video_shader_parameter *param = NULL; for (i = 0; i < static_cast(video_shader->num_parameters); i++) { QString id = video_shader->parameters[i].id; if (id == parameter) param = &video_shader->parameters[i]; } if (param) { video_shader_param_set(param, value); newValue = lerp( param->minimum, param->maximum, 0, 100, video_shader_param_get(param)); slider->blockSignals(true); slider->setValue(newValue); slider->blockSignals(false); } video_shader->flags |= SHDR_FLAG_MODIFIED; } } } #endif #endif /* Thumbnail downloads. URLs, .partial handling, the pack extraction * and the file replacement rules are the companion core's * (companion_core_thumbnail_download / _pack_download); Qt keeps the * queues, counters and progress dialogs. Results arrive through the * driver's callback table as onCoreThumbnailDownloaded / * onCoreThumbnailPackFinished. */ /* ---- Thumbnail Pack Download ---- */ void MainWindow::onThumbnailPackDownloadCanceled() { companion_core_download_cancel(ui_companion_qt_core()); } void MainWindow::downloadAllThumbnails(QString system, QUrl url) { QByteArray systemArray = system.toUtf8(); (void)url; /* the server layout is the core's */ if (!companion_core_thumbnail_pack_download(ui_companion_qt_core(), systemArray.constData())) { RARCH_ERR("[Qt] Failed to start thumbnail pack download.\n"); return; } m_thumbnailPackDownloadProgressDialog->setWindowModality(Qt::NonModal); m_thumbnailPackDownloadProgressDialog->setMinimumDuration(0); m_thumbnailPackDownloadProgressDialog->setRange(0, 0); m_thumbnailPackDownloadProgressDialog->setAutoClose(true); m_thumbnailPackDownloadProgressDialog->setAutoReset(true); m_thumbnailPackDownloadProgressDialog->setValue(0); m_thumbnailPackDownloadProgressDialog->setLabelText( QString(msg_hash_to_str(MSG_DOWNLOADING)) + "..."); m_thumbnailPackDownloadProgressDialog->setCancelButtonText(tr("Cancel")); m_thumbnailPackDownloadProgressDialog->show(); } void MainWindow::onCoreThumbnailPackFinished(int result) { m_thumbnailPackDownloadProgressDialog->cancel(); switch ((enum companion_download_result)result) { case COMPANION_DL_OK: RARCH_LOG("[Qt] Thumbnail pack extracted successfully.\n"); emit showInfoMessageDeferred(msg_hash_to_str( MENU_ENUM_LABEL_VALUE_QT_THUMBNAIL_PACK_DOWNLOADED_SUCCESSFULLY)); updateVisibleItems(); emit itemChanged(); /* reload thumbnail image */ return; case COMPANION_DL_ERR_NETWORK: emit showErrorMessageDeferred(msg_hash_to_str( MENU_ENUM_LABEL_VALUE_QT_NETWORK_ERROR)); return; case COMPANION_DL_ERR_RENAME: emit showErrorMessageDeferred(msg_hash_to_str( MENU_ENUM_LABEL_VALUE_QT_COULD_NOT_RENAME_FILE)); return; case COMPANION_DL_ERR_DELETE: emit showErrorMessageDeferred(msg_hash_to_str( MENU_ENUM_LABEL_VALUE_QT_COULD_NOT_DELETE_FILE)); return; case COMPANION_DL_ERR_ARCHIVE_EMPTY: emit showErrorMessageDeferred("Error: Archive is empty."); return; case COMPANION_DL_ERR_EXTRACT: case COMPANION_DL_ERR_WRITE: default: emit showErrorMessageDeferred(msg_hash_to_str(MSG_DECOMPRESSION_FAILED)); return; } } /* ---- Single Thumbnail Download ---- */ void MainWindow::onThumbnailDownloadCanceled() { companion_core_download_cancel(ui_companion_qt_core()); m_pendingThumbnailDownloadTypes.clear(); } void MainWindow::onDownloadThumbnail(QString system, QString title) { downloadThumbnail(system, title); } /* companion core: a thumbnail transfer ended. */ void MainWindow::onCoreThumbnailDownloaded(QString system, QString title, QString path, bool success) { if (m_downloadingPlaylistThumbnails) onPlaylistThumbnailDownloadFinishedInternal(path, success); else onSingleThumbnailDownloadFinishedInternal(system, title, path, success); } void MainWindow::onSingleThumbnailDownloadFinishedInternal( QString system, QString title, QString path, bool success) { if (success && !path.isEmpty()) { /* Force reload of current item's thumbnail */ QModelIndex index = getCurrentContentIndex(); if (index.isValid()) { m_playlistModel->reloadThumbnail(index); onCurrentItemChanged(index); } updateVisibleItems(); } if (!m_pendingThumbnailDownloadTypes.isEmpty()) { /* Defer next download to let Qt event loop process */ QMetaObject::invokeMethod(this, "onDownloadThumbnail", Qt::QueuedConnection, Q_ARG(QString, system), Q_ARG(QString, title)); } else m_thumbnailDownloadProgressDialog->cancel(); } void MainWindow::downloadThumbnail(QString system, QString title, QUrl url) { QString downloadType; QByteArray systemArray, titleArray, typeArray; (void)url; if (m_pendingThumbnailDownloadTypes.isEmpty()) return; downloadType = m_pendingThumbnailDownloadTypes.takeFirst(); systemArray = system.toUtf8(); titleArray = title.toUtf8(); typeArray = downloadType.toUtf8(); m_downloadingPlaylistThumbnails = false; if (!companion_core_thumbnail_download(ui_companion_qt_core(), systemArray.constData(), titleArray.constData(), typeArray.constData())) { RARCH_ERR("[Qt] Failed to start thumbnail download.\n"); m_pendingThumbnailDownloadTypes.clear(); m_thumbnailDownloadProgressDialog->cancel(); return; } m_thumbnailDownloadProgressDialog->setWindowModality(Qt::NonModal); m_thumbnailDownloadProgressDialog->setMinimumDuration(0); m_thumbnailDownloadProgressDialog->setRange(0, 100); m_thumbnailDownloadProgressDialog->setAutoClose(true); m_thumbnailDownloadProgressDialog->setAutoReset(true); m_thumbnailDownloadProgressDialog->setValue(0); m_thumbnailDownloadProgressDialog->setLabelText( QString(msg_hash_to_str(MSG_DOWNLOADING)) + "..."); m_thumbnailDownloadProgressDialog->setCancelButtonText(tr("Cancel")); m_thumbnailDownloadProgressDialog->show(); } /* ---- Playlist Thumbnail Download ---- */ void MainWindow::onPlaylistThumbnailDownloadCanceled() { m_playlistThumbnailDownloadWasCanceled = true; m_downloadingPlaylistThumbnails = false; companion_core_download_cancel(ui_companion_qt_core()); m_pendingPlaylistThumbnails.clear(); } void MainWindow::onPlaylistThumbnailDownloadFinishedInternal( QString path, bool success) { if (success) { m_downloadedThumbnails++; if (!path.isEmpty()) m_playlistModel->reloadThumbnailPath(path); } else m_failedThumbnails++; if (m_playlistThumbnailDownloadWasCanceled) return; if (m_pendingPlaylistThumbnails.count() > 0) { QHash nextThumbnail = m_pendingPlaylistThumbnails.takeAt(0); m_playlistThumbnailDownloadProgressDialog->setValue( m_playlistThumbnailDownloadProgressDialog->maximum() - m_pendingPlaylistThumbnails.count()); { QString labelText = QString(msg_hash_to_str(MSG_DOWNLOADING)) + "...\n" + QString(msg_hash_to_str( MENU_ENUM_LABEL_VALUE_QT_DOWNLOAD_PLAYLIST_THUMBNAIL_PROGRESS)).arg( m_downloadedThumbnails).arg(m_failedThumbnails); m_playlistThumbnailDownloadProgressDialog->setLabelText(labelText); } downloadNextPlaylistThumbnail( nextThumbnail.value("db_name"), nextThumbnail.value("label_noext"), nextThumbnail.value("type")); } else { m_downloadingPlaylistThumbnails = false; m_playlistThumbnailDownloadProgressDialog->cancel(); /* Force reload of current item's thumbnail */ QModelIndex index = getCurrentContentIndex(); if (index.isValid()) { m_playlistModel->reloadThumbnail(index); onCurrentItemChanged(index); } updateVisibleItems(); } } void MainWindow::downloadNextPlaylistThumbnail( QString system, QString title, QString type, QUrl url) { QByteArray systemArray = system.toUtf8(); QByteArray titleArray = title.toUtf8(); QByteArray typeArray = type.toUtf8(); (void)url; /* Skip transfers that cannot start and move on down the queue; the * core reports every one it does start. */ while (!companion_core_thumbnail_download(ui_companion_qt_core(), systemArray.constData(), titleArray.constData(), typeArray.constData())) { m_failedThumbnails++; if (m_pendingPlaylistThumbnails.count() == 0) { m_downloadingPlaylistThumbnails = false; m_playlistThumbnailDownloadProgressDialog->cancel(); return; } { QHash next = m_pendingPlaylistThumbnails.takeAt(0); systemArray = next.value("db_name").toUtf8(); titleArray = next.value("label_noext").toUtf8(); typeArray = next.value("type").toUtf8(); } } } void MainWindow::downloadPlaylistThumbnails(QString playlistPath) { int i, count; QFile playlistFile(playlistPath); if (!playlistFile.exists()) return; m_pendingPlaylistThumbnails.clear(); m_downloadedThumbnails = 0; m_failedThumbnails = 0; m_playlistThumbnailDownloadWasCanceled = false; count = m_playlistModel->rowCount(); if (count == 0) return; for (i = 0; i < count; i++) { QHash hash; QHash hash2; QHash hash3; QHash hash4; const PlaylistEntry itemEntry = m_playlistModel->index(i, 0).data( PlaylistModel::ENTRY).value(); hash["db_name"] = itemEntry.dbName; hash["label_noext"] = itemEntry.labelNoExt; hash["type"] = THUMBNAIL_BOXART; hash2 = hash; hash3 = hash; hash4 = hash; hash2["type"] = THUMBNAIL_SCREENSHOT; hash3["type"] = THUMBNAIL_TITLE; hash4["type"] = THUMBNAIL_LOGO; m_pendingPlaylistThumbnails.append(hash); m_pendingPlaylistThumbnails.append(hash2); m_pendingPlaylistThumbnails.append(hash3); m_pendingPlaylistThumbnails.append(hash4); } m_playlistThumbnailDownloadProgressDialog->setWindowModality(Qt::NonModal); m_playlistThumbnailDownloadProgressDialog->setMinimumDuration(0); m_playlistThumbnailDownloadProgressDialog->setRange(0, m_pendingPlaylistThumbnails.count()); m_playlistThumbnailDownloadProgressDialog->setAutoClose(true); m_playlistThumbnailDownloadProgressDialog->setAutoReset(true); m_playlistThumbnailDownloadProgressDialog->setValue(0); m_playlistThumbnailDownloadProgressDialog->setLabelText( QString(msg_hash_to_str(MSG_DOWNLOADING)) + "..."); m_playlistThumbnailDownloadProgressDialog->setCancelButtonText(tr("Cancel")); m_playlistThumbnailDownloadProgressDialog->show(); m_downloadingPlaylistThumbnails = true; { QHash firstThumbnail = m_pendingPlaylistThumbnails.takeAt(0); downloadNextPlaylistThumbnail( firstThumbnail.value("db_name"), firstThumbnail.value("label_noext"), firstThumbnail.value("type")); } } /* All of the OptionsCategory/OptionsPage implementations below * build trees of the menu settings widgets (FormLayout, * SettingsGroup, CheckBox, etc.) and call into the menu code * (menu_displaylist_build_list, menu_setting_find_enum). Their * declarations are gated in ui_qt_widgets.h; the implementations * are gated to match. */ #ifdef HAVE_MENU AchievementsCategory::AchievementsCategory(QWidget *parent) : OptionsCategory(parent) { setDisplayName(MENU_ENUM_LABEL_VALUE_RETRO_ACHIEVEMENTS_SETTINGS); setCategoryIcon("menu_achievements"); } QVector AchievementsCategory::pages() { QVector pages; pages << new AchievementsPage(this); return pages; } AchievementsPage::AchievementsPage(QObject *parent) : OptionsPage(parent) { } QWidget *AchievementsPage::widget() { unsigned i; QWidget *widget = new QWidget; QVBoxLayout *layout = new QVBoxLayout; QHBoxLayout *columnsLayout = new QHBoxLayout; QVBoxLayout *leftColumn = new QVBoxLayout; QVBoxLayout *rightColumn = new QVBoxLayout; settings_t* settings = config_get_ptr(); CheckBox *enabledCheckBox = new CheckBox(MENU_ENUM_LABEL_CHEEVOS_ENABLE); file_list_t *generalList = (file_list_t*)calloc(1, sizeof(*generalList)); file_list_t *appearanceList = (file_list_t*)calloc(1, sizeof(*appearanceList)); file_list_t *visibilityList = (file_list_t*)calloc(1, sizeof(*visibilityList)); m_generalGroup = new SettingsGroup("General"); m_appearanceGroup = new SettingsGroup(msg_hash_to_str( MENU_ENUM_LABEL_VALUE_CHEEVOS_APPEARANCE_SETTINGS)); m_visibilityGroup = new SettingsGroup(msg_hash_to_str( MENU_ENUM_LABEL_VALUE_CHEEVOS_VISIBILITY_SETTINGS)); menu_displaylist_build_list(generalList, settings, DISPLAYLIST_RETRO_ACHIEVEMENTS_SETTINGS_LIST, true); for (i = 0; i < generalList->size; i++) { menu_file_list_cbs_t *cbs = (menu_file_list_cbs_t*) file_list_get_actiondata_at_offset(generalList, i); if (cbs->enum_idx == MENU_ENUM_LABEL_CHEEVOS_ENABLE) continue; m_generalGroup->add(cbs->enum_idx); } file_list_free(generalList); menu_displaylist_build_list(appearanceList, settings, DISPLAYLIST_CHEEVOS_APPEARANCE_SETTINGS_LIST, true); for (i = 0; i < appearanceList->size; i++) { menu_file_list_cbs_t* cbs = (menu_file_list_cbs_t*) file_list_get_actiondata_at_offset(appearanceList, i); m_appearanceGroup->add(cbs->enum_idx); } file_list_free(appearanceList); menu_displaylist_build_list(visibilityList, settings, DISPLAYLIST_CHEEVOS_VISIBILITY_SETTINGS_LIST, true); for (i = 0; i < visibilityList->size; i++) { menu_file_list_cbs_t* cbs = (menu_file_list_cbs_t*) file_list_get_actiondata_at_offset(visibilityList, i); m_visibilityGroup->add(cbs->enum_idx); } file_list_free(visibilityList); connect(enabledCheckBox, SIGNAL(stateChanged(int)), this, SLOT(onAchievementEnabledChanged(int))); onAchievementEnabledChanged(enabledCheckBox->checkState()); layout->addWidget(enabledCheckBox); leftColumn->addWidget(m_generalGroup); leftColumn->addWidget(m_appearanceGroup); rightColumn->addWidget(m_visibilityGroup); leftColumn->addStretch(); rightColumn->addStretch(); columnsLayout->addLayout(leftColumn, 1); columnsLayout->addLayout(rightColumn, 1); layout->addLayout(columnsLayout); layout->addStretch(); widget->setLayout(layout); return widget; } void AchievementsPage::onAchievementEnabledChanged(int state) { m_generalGroup->setDisabled(state == Qt::Unchecked); m_appearanceGroup->setDisabled(state == Qt::Unchecked); m_visibilityGroup->setDisabled(state == Qt::Unchecked); } static file_list_t *qt_displaylist_build( enum menu_displaylist_ctl_state state); static bool qt_list_has_entry(const file_list_t *list, enum msg_hash_enums entry); static void qt_settings_group_add_list(SettingsGroup *group, const file_list_t *list, const enum msg_hash_enums *skip_entries, size_t skip_count, const enum msg_hash_enums *only_entries, size_t only_count); static void qt_settings_group_add_displaylist(SettingsGroup *group, enum menu_displaylist_ctl_state state, const enum msg_hash_enums *skip_entries, size_t skip_count, const enum msg_hash_enums *only_entries, size_t only_count); AudioCategory::AudioCategory(QWidget *parent) : OptionsCategory(parent) { setDisplayName(MENU_ENUM_LABEL_VALUE_AUDIO_SETTINGS); setCategoryIcon("menu_audio"); } QVector AudioCategory::pages() { QVector pages; pages << new AudioPage(this); return pages; } AudioPage::AudioPage(QObject *parent) : OptionsPage(parent) { } QWidget *AudioPage::widget() { QWidget *widget = new QWidget; QVBoxLayout *layout = new QVBoxLayout; QHBoxLayout *columnsLayout = new QHBoxLayout; QVBoxLayout *leftColumn = new QVBoxLayout; QVBoxLayout *rightColumn = new QVBoxLayout; SettingsGroup *generalGroup = new SettingsGroup("General"); SettingsGroup *outputGroup = new SettingsGroup("Output"); SettingsGroup *syncGroup = new SettingsGroup(msg_hash_to_str( MENU_ENUM_LABEL_VALUE_AUDIO_SYNC)); SettingsGroup *resamplerGroup = new SettingsGroup("Resampler"); SettingsGroup *volumeGroup = new SettingsGroup("Volume"); SettingsGroup *menuSoundsGroup = new SettingsGroup(msg_hash_to_str( MENU_ENUM_LABEL_VALUE_MENU_SOUNDS)); SettingsGroup *midiGroup = new SettingsGroup( msg_hash_to_str(MENU_ENUM_LABEL_VALUE_MIDI_SETTINGS)); QGridLayout *volumeLayout = new QGridLayout; static const enum msg_hash_enums generalSkip[] = { MENU_ENUM_LABEL_AUDIO_VOLUME, MENU_ENUM_LABEL_AUDIO_MIXER_VOLUME, MENU_ENUM_LABEL_AUDIO_MUTE, MENU_ENUM_LABEL_AUDIO_MIXER_MUTE }; static const enum msg_hash_enums outputSkip[] = { MENU_ENUM_LABEL_AUDIO_OUTPUT_RATE, MENU_ENUM_LABEL_AUDIO_RESAMPLER_DRIVER, MENU_ENUM_LABEL_AUDIO_RESAMPLER_QUALITY, MENU_ENUM_LABEL_AUDIO_RESAMPLER_HQ_OVERSAMPLING, MENU_ENUM_LABEL_AUDIO_FASTPATH_S16, MENU_ENUM_LABEL_AUDIO_FORMAT_NEGOTIATION }; static const enum msg_hash_enums midiVolumeSkip[] = { MENU_ENUM_LABEL_MIDI_VOLUME }; static const enum msg_hash_enums resamplerEntries[] = { MENU_ENUM_LABEL_AUDIO_OUTPUT_RATE, MENU_ENUM_LABEL_AUDIO_RESAMPLER_DRIVER, MENU_ENUM_LABEL_AUDIO_RESAMPLER_QUALITY, MENU_ENUM_LABEL_AUDIO_RESAMPLER_HQ_OVERSAMPLING, MENU_ENUM_LABEL_AUDIO_FASTPATH_S16, MENU_ENUM_LABEL_AUDIO_FORMAT_NEGOTIATION }; /* Build the ordinary controls from the same lists used by the menu. * Action entries are ignored by the SettingsGroup helper. */ qt_settings_group_add_displaylist(generalGroup, DISPLAYLIST_AUDIO_SETTINGS_LIST, generalSkip, ARRAY_SIZE(generalSkip), NULL, 0); { file_list_t *outputList = qt_displaylist_build( DISPLAYLIST_AUDIO_OUTPUT_SETTINGS_LIST); qt_settings_group_add_list(outputGroup, outputList, outputSkip, ARRAY_SIZE(outputSkip), NULL, 0); qt_settings_group_add_list(resamplerGroup, outputList, NULL, 0, resamplerEntries, ARRAY_SIZE(resamplerEntries)); if (outputList) file_list_free(outputList); } qt_settings_group_add_displaylist(syncGroup, DISPLAYLIST_AUDIO_SYNCHRONIZATION_SETTINGS_LIST, NULL, 0, NULL, 0); qt_settings_group_add_displaylist(menuSoundsGroup, DISPLAYLIST_MENU_SOUNDS_LIST, NULL, 0, NULL, 0); qt_settings_group_add_displaylist(midiGroup, DISPLAYLIST_MIDI_SETTINGS_LIST, midiVolumeSkip, ARRAY_SIZE(midiVolumeSkip), NULL, 0); { rarch_setting_t *midiVolume = menu_setting_find_enum( MENU_ENUM_LABEL_MIDI_VOLUME); if (midiVolume && midiVolume->value.target.unsigned_integer) { QHBoxLayout *midiVolumeLayout = new QHBoxLayout; QSlider *slider = new QSlider(Qt::Horizontal); QSpinBox *spinBox = new QSpinBox; slider->setRange((int)midiVolume->min, (int)midiVolume->max); spinBox->setRange((int)midiVolume->min, (int)midiVolume->max); slider->setValue((int)*midiVolume->value.target.unsigned_integer); spinBox->setValue((int)*midiVolume->value.target.unsigned_integer); /* The spin box is the single writer: the slider only feeds * it, so each edit runs the change handler once (it ran twice * when both widgets wrote the setting and echoed each other). */ QObject::connect(slider, &QSlider::valueChanged, spinBox, &QSpinBox::setValue); QObject::connect(spinBox, static_cast(&QSpinBox::valueChanged), [midiVolume, slider](int value) { QSignalBlocker block(slider); *midiVolume->value.target.unsigned_integer = (unsigned)value; setting_generic_handle_change(midiVolume); slider->setValue(value); }); midiVolumeLayout->addWidget(slider, 1); midiVolumeLayout->addWidget(spinBox); midiGroup->addRow(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_MIDI_VOLUME), midiVolumeLayout); } } #ifdef HAVE_MICROPHONE { SettingsGroup *microphoneGroup = new SettingsGroup( msg_hash_to_str(MENU_ENUM_LABEL_VALUE_MICROPHONE_SETTINGS)); qt_settings_group_add_displaylist(microphoneGroup, DISPLAYLIST_MICROPHONE_SETTINGS_LIST, NULL, 0, NULL, 0); rightColumn->addWidget(microphoneGroup); } #endif /* Keep the two volume sliders and their mute buttons together. */ volumeLayout->addWidget(new QLabel( msg_hash_to_str(MENU_ENUM_LABEL_VALUE_AUDIO_VOLUME), widget), 0, 0); volumeLayout->addWidget(new CheckableIcon( MENU_ENUM_LABEL_AUDIO_MUTE, qApp->style()->standardIcon(QStyle::SP_MediaVolumeMuted)), 0, 1); volumeLayout->addLayout(new FloatSliderAndSpinBox( MENU_ENUM_LABEL_AUDIO_VOLUME), 0, 2); volumeLayout->addWidget(new QLabel( msg_hash_to_str(MENU_ENUM_LABEL_VALUE_AUDIO_MIXER_VOLUME), widget), 1, 0); volumeLayout->addWidget(new CheckableIcon( MENU_ENUM_LABEL_AUDIO_MIXER_MUTE, qApp->style()->standardIcon(QStyle::SP_MediaVolumeMuted)), 1, 1); volumeLayout->addLayout(new FloatSliderAndSpinBox( MENU_ENUM_LABEL_AUDIO_MIXER_VOLUME), 1, 2); volumeGroup->addRow(volumeLayout); leftColumn->addWidget(outputGroup); leftColumn->addWidget(syncGroup); leftColumn->addWidget(volumeGroup); leftColumn->addWidget(generalGroup); rightColumn->addWidget(resamplerGroup); rightColumn->addWidget(menuSoundsGroup); rightColumn->addWidget(midiGroup); leftColumn->addStretch(); rightColumn->addStretch(); columnsLayout->addLayout(leftColumn, 1); columnsLayout->addLayout(rightColumn, 1); layout->addLayout(columnsLayout); layout->addStretch(); widget->setLayout(layout); return widget; } InputCategory::InputCategory(QWidget *parent) : OptionsCategory(parent) { setDisplayName(MENU_ENUM_LABEL_VALUE_INPUT_SETTINGS); setCategoryIcon("core-input-remapping-options"); } QVector InputCategory::pages() { QVector pages; pages << new InputPage(this); pages << new HotkeyBindsPage(this); return pages; } InputPage::InputPage(QObject *parent) : OptionsPage(parent) { } QWidget *InputPage::widget() { QWidget *widget = new QWidget; QVBoxLayout *layout = new QVBoxLayout; QHBoxLayout *columnsLayout = new QHBoxLayout; QVBoxLayout *leftColumn = new QVBoxLayout; QVBoxLayout *rightColumn = new QVBoxLayout; SettingsGroup *generalGroup = new SettingsGroup("General"); SettingsGroup *menuGroup = new SettingsGroup( msg_hash_to_str(MENU_ENUM_LABEL_VALUE_INPUT_MENU_SETTINGS)); SettingsGroup *turboGroup = new SettingsGroup( msg_hash_to_str(MENU_ENUM_LABEL_VALUE_INPUT_TURBO_FIRE_SETTINGS)); SettingsGroup *sensorGroup = new SettingsGroup( msg_hash_to_str(MENU_ENUM_LABEL_VALUE_INPUT_SENSOR_SETTINGS)); SettingsGroup *hapticGroup = new SettingsGroup( msg_hash_to_str(MENU_ENUM_LABEL_VALUE_INPUT_HAPTIC_FEEDBACK_SETTINGS)); qt_settings_group_add_displaylist(generalGroup, DISPLAYLIST_INPUT_SETTINGS_LIST, NULL, 0, NULL, 0); qt_settings_group_add_displaylist(menuGroup, DISPLAYLIST_INPUT_MENU_SETTINGS_LIST, NULL, 0, NULL, 0); qt_settings_group_add_displaylist(turboGroup, DISPLAYLIST_INPUT_TURBO_FIRE_SETTINGS_LIST, NULL, 0, NULL, 0); qt_settings_group_add_displaylist(sensorGroup, DISPLAYLIST_INPUT_SENSOR_SETTINGS_LIST, NULL, 0, NULL, 0); qt_settings_group_add_displaylist(hapticGroup, DISPLAYLIST_INPUT_HAPTIC_FEEDBACK_SETTINGS_LIST, NULL, 0, NULL, 0); leftColumn->addWidget(generalGroup); rightColumn->addWidget(menuGroup); rightColumn->addWidget(turboGroup); rightColumn->addWidget(sensorGroup); rightColumn->addWidget(hapticGroup); leftColumn->addStretch(); rightColumn->addStretch(); columnsLayout->addLayout(leftColumn, 1); columnsLayout->addLayout(rightColumn, 1); layout->addLayout(columnsLayout); layout->addStretch(); widget->setLayout(layout); return widget; } HotkeyBindsPage::HotkeyBindsPage(QObject *parent) : OptionsPage(parent) { setDisplayName(MENU_ENUM_LABEL_VALUE_INPUT_HOTKEY_BINDS); } QWidget *HotkeyBindsPage::widget() { unsigned i; QWidget *widget = new QWidget; QHBoxLayout *layout = new QHBoxLayout; FormLayout *mainLayout = new FormLayout; settings_t *settings = config_get_ptr(); file_list_t *list = (file_list_t*)calloc(1, sizeof(*list)); menu_displaylist_build_list(list, settings, DISPLAYLIST_INPUT_HOTKEY_BINDS_LIST, true); for (i = 0; i < list->size; i++) { menu_file_list_cbs_t *cbs = (menu_file_list_cbs_t*) file_list_get_actiondata_at_offset(list, i); mainLayout->add(menu_setting_find_enum(cbs->enum_idx)); } file_list_free(list); layout->addLayout(mainLayout); widget->setLayout(layout); return widget; } UserBindsPage::UserBindsPage(QObject *parent) : OptionsPage(parent) { setDisplayName("User Binds"); } QWidget *UserBindsPage::widget() { unsigned p, retro_id; settings_t *settings = config_get_ptr(); unsigned max_users = settings->uints.input_max_users; QWidget *widget = new QWidget; QGridLayout *layout = new QGridLayout; QComboBox *userCombo = new QComboBox; QStackedWidget *stack = new QStackedWidget; for (p = 0; p < max_users; p++) { userCombo->addItem(QString::number(p)); QWidget *uWidget = new QWidget(); FormLayout *form = new FormLayout(); for (retro_id = 0; retro_id < RARCH_FIRST_CUSTOM_BIND + 20; retro_id++) { char descriptor[300]; const struct retro_keybind *keybind = input_config_bind(p, retro_id); const struct retro_keybind *auto_bind = (const struct retro_keybind*) input_config_get_bind_auto(p, retro_id); input_config_get_bind_string(settings, descriptor, keybind, auto_bind, input_config_bind_names(p, retro_id), input_autoconf_bind_names(p, retro_id), sizeof(descriptor)); QString label = msg_hash_to_str(input_config_bind_label(retro_id)); form->addRow(QString(msg_hash_to_str(input_config_bind_label(retro_id))), new QPushButton(QString(descriptor))); } uWidget->setLayout(form); stack->addWidget(uWidget); } connect(userCombo, SIGNAL(activated(int)), stack, SLOT(setCurrentIndex(int))); layout->addWidget(userCombo, 0, 0); layout->addWidget(stack, 1, 0); widget->setLayout(layout); return widget; } LatencyCategory::LatencyCategory(QWidget *parent) : OptionsCategory(parent) { setDisplayName(MENU_ENUM_LABEL_VALUE_LATENCY_SETTINGS); setCategoryIcon("menu_latency"); } QVector LatencyCategory::pages() { QVector pages; pages << new LatencyPage(this); return pages; } LatencyPage::LatencyPage(QObject *parent) : OptionsPage(parent) { } QWidget *LatencyPage::widget() { QWidget *widget = new QWidget; QVBoxLayout *layout = new QVBoxLayout; QHBoxLayout *contentLayout = new QHBoxLayout; QVBoxLayout *leftColumn = new QVBoxLayout; SettingsGroup *latencyGroup = new SettingsGroup("Latency"); SettingsGroup *runAheadGroup = new SettingsGroup( msg_hash_to_str(MENU_ENUM_LABEL_VALUE_RUNAHEAD_MODE)); rarch_setting_t *hardSyncSetting = menu_setting_find_enum( MENU_ENUM_LABEL_VIDEO_HARD_SYNC); static const enum msg_hash_enums latencySkip[] = { MENU_ENUM_LABEL_RUNAHEAD_MODE, MENU_ENUM_LABEL_RUN_AHEAD_FRAMES, MENU_ENUM_LABEL_PREEMPT_FRAMES, MENU_ENUM_LABEL_RUN_AHEAD_HIDE_WARNINGS, MENU_ENUM_LABEL_VIDEO_HARD_SYNC, MENU_ENUM_LABEL_VIDEO_HARD_SYNC_FRAMES }; static const enum msg_hash_enums runAheadEntries[] = { MENU_ENUM_LABEL_RUNAHEAD_MODE, MENU_ENUM_LABEL_RUN_AHEAD_FRAMES, MENU_ENUM_LABEL_PREEMPT_FRAMES, MENU_ENUM_LABEL_RUN_AHEAD_HIDE_WARNINGS }; { file_list_t *latencyList = qt_displaylist_build( DISPLAYLIST_LATENCY_SETTINGS_LIST); qt_settings_group_add_list(latencyGroup, latencyList, latencySkip, ARRAY_SIZE(latencySkip), NULL, 0); latencyGroup->add(MENU_ENUM_LABEL_INPUT_POLL_TYPE_BEHAVIOR); qt_settings_group_add_list(runAheadGroup, latencyList, NULL, 0, runAheadEntries, ARRAY_SIZE(runAheadEntries)); if (latencyList) file_list_free(latencyList); } leftColumn->addWidget(latencyGroup); if (hardSyncSetting) { CheckableSettingsGroup *hardSyncGroup = new CheckableSettingsGroup(hardSyncSetting); hardSyncGroup->add(MENU_ENUM_LABEL_VIDEO_HARD_SYNC_FRAMES); leftColumn->addWidget(hardSyncGroup); } leftColumn->addWidget(runAheadGroup); leftColumn->addStretch(); contentLayout->addLayout(leftColumn, 1); contentLayout->addStretch(1); layout->addLayout(contentLayout); layout->addStretch(); widget->setLayout(layout); return widget; } NetworkCategory::NetworkCategory(QWidget *parent) : OptionsCategory(parent) { setDisplayName(MENU_ENUM_LABEL_VALUE_NETWORK_SETTINGS); setCategoryIcon("menu_network"); } QVector NetworkCategory::pages() { QVector pages; pages << new NetplayPage(this); return pages; } NetplayPage::NetplayPage(QObject *parent) : OptionsPage(parent) { setDisplayName("General"); } QWidget *NetplayPage::widget() { QWidget *widget = new QWidget; QVBoxLayout *mainLayout = new QVBoxLayout; QHBoxLayout *columnsLayout = new QHBoxLayout; QVBoxLayout *leftColumn = new QVBoxLayout; QVBoxLayout *rightColumn = new QVBoxLayout; SettingsGroup *netplayGroup = new SettingsGroup("Netplay"); SettingsGroup *updaterGroup = new SettingsGroup( msg_hash_to_str(MENU_ENUM_LABEL_VALUE_UPDATER_SETTINGS)); QGridLayout *layout = new QGridLayout; FormLayout *checksLayout = new FormLayout; SettingsGroup *serverGroup = new SettingsGroup("Server"); SettingsGroup *syncGroup = new SettingsGroup("Synchronization"); SettingsGroup *slaveGroup = new SettingsGroup("Slave-Mode"); SettingsGroup *inputGroup = new SettingsGroup("Input Sharing"); SettingsGroup *deviceGroup = new SettingsGroup("Device Request"); SettingsGroup *networkGroup = new SettingsGroup("Network Services"); #ifdef HAVE_SMBCLIENT SettingsGroup *smbGroup = new SettingsGroup( msg_hash_to_str(MENU_ENUM_LABEL_VALUE_SMB_CLIENT_SETTINGS)); #endif #ifdef HAVE_NFSCLIENT SettingsGroup *nfsGroup = new SettingsGroup( msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NFS_CLIENT_SETTINGS)); #endif FormLayout *serverForm = new FormLayout; QGridLayout *requestGrid = new QGridLayout; unsigned i = 0; unsigned row = 0; unsigned column = 0; static const enum msg_hash_enums networkSkip[] = { MENU_ENUM_LABEL_NETPLAY_PUBLIC_ANNOUNCE, MENU_ENUM_LABEL_NETPLAY_USE_MITM_SERVER, MENU_ENUM_LABEL_NETPLAY_MITM_SERVER, MENU_ENUM_LABEL_NETPLAY_CUSTOM_MITM_SERVER, MENU_ENUM_LABEL_NETPLAY_IP_ADDRESS, MENU_ENUM_LABEL_NETPLAY_TCP_UDP_PORT, MENU_ENUM_LABEL_NETPLAY_MAX_CONNECTIONS, MENU_ENUM_LABEL_NETPLAY_MAX_PING, MENU_ENUM_LABEL_NETPLAY_PASSWORD, MENU_ENUM_LABEL_NETPLAY_SPECTATE_PASSWORD, MENU_ENUM_LABEL_NETPLAY_START_AS_SPECTATOR, MENU_ENUM_LABEL_NETPLAY_FADE_CHAT, MENU_ENUM_LABEL_NETPLAY_CHAT_COLOR_NAME, MENU_ENUM_LABEL_NETPLAY_CHAT_COLOR_MSG, MENU_ENUM_LABEL_NETPLAY_ALLOW_PAUSING, MENU_ENUM_LABEL_NETPLAY_ALLOW_SLAVES, MENU_ENUM_LABEL_NETPLAY_REQUIRE_SLAVES, MENU_ENUM_LABEL_NETPLAY_CHECK_FRAMES, MENU_ENUM_LABEL_NETPLAY_INPUT_LATENCY_FRAMES_MIN, MENU_ENUM_LABEL_NETPLAY_INPUT_LATENCY_FRAMES_RANGE, MENU_ENUM_LABEL_NETPLAY_NAT_TRAVERSAL, MENU_ENUM_LABEL_NETPLAY_SHARE_DIGITAL, MENU_ENUM_LABEL_NETPLAY_SHARE_ANALOG, MENU_ENUM_LABEL_NETWORK_ON_DEMAND_THUMBNAILS, MENU_ENUM_LABEL_NETPLAY_ANALOG_JOYPADS, MENU_ENUM_LABEL_NETPLAY_LOCKSTEP, MENU_ENUM_LABEL_NETPLAY_REQUEST_DEVICES, #ifdef HAVE_SMBCLIENT MENU_ENUM_LABEL_SMB_CLIENT_SETTINGS, #endif #ifdef HAVE_NFSCLIENT MENU_ENUM_LABEL_NFS_CLIENT_SETTINGS, #endif }; checksLayout->add(menu_setting_find_enum(MENU_ENUM_LABEL_NETPLAY_PUBLIC_ANNOUNCE)); checksLayout->add(menu_setting_find_enum(MENU_ENUM_LABEL_NETPLAY_START_AS_SPECTATOR)); checksLayout->add(menu_setting_find_enum(MENU_ENUM_LABEL_NETPLAY_FADE_CHAT)); checksLayout->add(menu_setting_find_enum(MENU_ENUM_LABEL_NETPLAY_ALLOW_PAUSING)); checksLayout->add(menu_setting_find_enum(MENU_ENUM_LABEL_NETPLAY_ANALOG_JOYPADS)); checksLayout->add(menu_setting_find_enum(MENU_ENUM_LABEL_NETPLAY_LOCKSTEP)); checksLayout->add(menu_setting_find_enum(MENU_ENUM_LABEL_NETWORK_ON_DEMAND_THUMBNAILS)); { const enum msg_hash_enums colorSettings[] = { MENU_ENUM_LABEL_NETPLAY_CHAT_COLOR_NAME, MENU_ENUM_LABEL_NETPLAY_CHAT_COLOR_MSG }; unsigned c; for (c = 0; c < ARRAY_SIZE(colorSettings); c++) { rarch_setting_t *colorSetting = menu_setting_find_enum(colorSettings[c]); if (colorSetting && colorSetting->value.target.unsigned_integer) { QPushButton *colorButton = new QPushButton; const auto updateColorButton = [colorSetting, colorButton]() { const unsigned color = *colorSetting->value.target.unsigned_integer & 0xFFFFFF; colorButton->setText(QString("#%1").arg(color, 6, 16, QChar('0')).toUpper()); colorButton->setStyleSheet(QString("background-color: #%1;").arg(color, 6, 16, QChar('0'))); }; updateColorButton(); QObject::connect(colorButton, &QPushButton::clicked, [colorSetting, updateColorButton]() { const QColor initial((int)((*colorSetting->value.target.unsigned_integer >> 16) & 0xFF), (int)((*colorSetting->value.target.unsigned_integer >> 8) & 0xFF), (int)(*colorSetting->value.target.unsigned_integer & 0xFF)); const QColor chosen = QColorDialog::getColor(initial, nullptr); if (chosen.isValid()) { *colorSetting->value.target.unsigned_integer = (unsigned)((chosen.red() << 16) | (chosen.green() << 8) | chosen.blue()); setting_generic_handle_change(colorSetting); updateColorButton(); } }); checksLayout->addRow(colorSetting->short_description ? colorSetting->short_description : "Chat Color", colorButton); } } } serverForm->add(menu_setting_find_enum(MENU_ENUM_LABEL_NETPLAY_IP_ADDRESS)); serverForm->add(menu_setting_find_enum(MENU_ENUM_LABEL_NETPLAY_TCP_UDP_PORT)); serverForm->add(menu_setting_find_enum(MENU_ENUM_LABEL_NETPLAY_MAX_CONNECTIONS)); serverForm->add(menu_setting_find_enum(MENU_ENUM_LABEL_NETPLAY_MAX_PING)); serverForm->add(menu_setting_find_enum(MENU_ENUM_LABEL_NETPLAY_PASSWORD)); serverForm->add(menu_setting_find_enum(MENU_ENUM_LABEL_NETPLAY_SPECTATE_PASSWORD)); serverForm->add(menu_setting_find_enum(MENU_ENUM_LABEL_NETPLAY_NAT_TRAVERSAL)); { QGroupBox *mitmGroup = createMitmServerGroup(); if (mitmGroup) serverGroup->addRow(mitmGroup); } /* Keep address/password fields at full width beneath the relay * selection controls; placing the two forms side-by-side squeezed * the editable fields into a narrow column. */ serverGroup->addRow(serverForm); slaveGroup->add(MENU_ENUM_LABEL_NETPLAY_ALLOW_SLAVES); slaveGroup->add(MENU_ENUM_LABEL_NETPLAY_REQUIRE_SLAVES); syncGroup->add(MENU_ENUM_LABEL_NETPLAY_CHECK_FRAMES); syncGroup->add(MENU_ENUM_LABEL_NETPLAY_INPUT_LATENCY_FRAMES_MIN); syncGroup->add(MENU_ENUM_LABEL_NETPLAY_INPUT_LATENCY_FRAMES_RANGE); inputGroup->add(MENU_ENUM_LABEL_NETPLAY_SHARE_DIGITAL); inputGroup->add(MENU_ENUM_LABEL_NETPLAY_SHARE_ANALOG); for (i = 0; i < MAX_USERS; i++) { if (column % 4 == 0) { column = 0; row++; } requestGrid->addWidget(new CheckBox((enum msg_hash_enums)( MENU_ENUM_LABEL_NETPLAY_REQUEST_DEVICE_1 + i)), row, column); column++; } deviceGroup->addRow(requestGrid); layout->addLayout(checksLayout, 0, 0, 1, 2); layout->addWidget(serverGroup, 1, 0, 1, 2); layout->addWidget(slaveGroup, 2, 0, 1, 1); layout->addWidget(syncGroup, 2, 1, 2, 1); layout->addWidget(inputGroup, 3, 0, 1, 1); layout->addWidget(deviceGroup, 4, 0, 1, 2); netplayGroup->addRow(layout); /* Keep the Network category in sync with the internal menu list. * The entries already represented by the custom Netplay controls above * are excluded; all remaining ordinary settings are added here. */ qt_settings_group_add_displaylist(networkGroup, DISPLAYLIST_NETWORK_SETTINGS_LIST, networkSkip, ARRAY_SIZE(networkSkip), NULL, 0); #ifdef HAVE_SMBCLIENT qt_settings_group_add_displaylist(smbGroup, DISPLAYLIST_SMB_CLIENT_SETTINGS_LIST, NULL, 0, NULL, 0); networkGroup->addRow(smbGroup); #endif #ifdef HAVE_NFSCLIENT qt_settings_group_add_displaylist(nfsGroup, DISPLAYLIST_NFS_CLIENT_SETTINGS_LIST, NULL, 0, NULL, 0); networkGroup->addRow(nfsGroup); #endif { static const enum msg_hash_enums updaterPathSkip[] = { MENU_ENUM_LABEL_CORE_UPDATER_BUILDBOT_URL, MENU_ENUM_LABEL_BUILDBOT_ASSETS_URL }; qt_settings_group_add_displaylist(updaterGroup, DISPLAYLIST_UPDATER_SETTINGS_LIST, updaterPathSkip, ARRAY_SIZE(updaterPathSkip), NULL, 0); qt_settings_group_add_compact_path(updaterGroup, MENU_ENUM_LABEL_CORE_UPDATER_BUILDBOT_URL, false); qt_settings_group_add_compact_path(updaterGroup, MENU_ENUM_LABEL_BUILDBOT_ASSETS_URL, false); } leftColumn->addWidget(netplayGroup); rightColumn->addWidget(networkGroup); rightColumn->addWidget(updaterGroup); leftColumn->addStretch(); rightColumn->addStretch(); columnsLayout->addLayout(leftColumn, 1); columnsLayout->addLayout(rightColumn, 1); mainLayout->addLayout(columnsLayout); widget->setLayout(mainLayout); return widget; } QGroupBox *NetplayPage::createMitmServerGroup() { #ifdef HAVE_NETWORKING size_t i; const char *netplay_mitm_server; CheckableSettingsGroup *groupBox = new CheckableSettingsGroup( MENU_ENUM_LABEL_NETPLAY_USE_MITM_SERVER); QButtonGroup *buttonGroup = new QButtonGroup(this); rarch_setting_t *setting = menu_setting_find_enum( MENU_ENUM_LABEL_NETPLAY_MITM_SERVER); if (!setting) return nullptr; netplay_mitm_server = setting->value.target.string; for (i = 0; i < ARRAY_SIZE(netplay_mitm_server_list); i++) { const mitm_server_t *server = &netplay_mitm_server_list[i]; QRadioButton *radioButton = new QRadioButton( msg_hash_to_str(server->description)); if (string_is_equal(server->name, netplay_mitm_server)) radioButton->setChecked(true); buttonGroup->addButton(radioButton, i); groupBox->addRow(radioButton); } groupBox->add(MENU_ENUM_LABEL_NETPLAY_CUSTOM_MITM_SERVER); #if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) connect(buttonGroup, &QButtonGroup::idClicked, this, &NetplayPage::onRadioButtonClicked); #else connect(buttonGroup, SIGNAL(buttonClicked(int)), this, SLOT(onRadioButtonClicked(int))); #endif return groupBox; #else return nullptr; #endif } void NetplayPage::onRadioButtonClicked(int id) { #ifdef HAVE_NETWORKING rarch_setting_t *setting = menu_setting_find_enum(MENU_ENUM_LABEL_NETPLAY_MITM_SERVER); if (!setting) return; strlcpy(setting->value.target.string, netplay_mitm_server_list[id].name, setting->size); #else (void)id; #endif } OnscreenDisplayCategory::OnscreenDisplayCategory(QWidget *parent) : OptionsCategory(parent) { setDisplayName(MENU_ENUM_LABEL_VALUE_ONSCREEN_DISPLAY_SETTINGS); setCategoryIcon("menu_osd"); } QVector OnscreenDisplayCategory::pages() { QVector pages; pages << new OverlayPage(this); return pages; } NotificationsPage::NotificationsPage(QObject *parent) : OptionsPage(parent) { setDisplayName(MENU_ENUM_LABEL_VALUE_ONSCREEN_NOTIFICATIONS_SETTINGS); } QWidget *NotificationsPage::widget() { QWidget *widget = new QWidget; QVBoxLayout *layout = new QVBoxLayout; CheckableSettingsGroup *notificationsGroup = new CheckableSettingsGroup( MENU_ENUM_LABEL_VIDEO_FONT_ENABLE); CheckableSettingsGroup *bgGroup = new CheckableSettingsGroup( MENU_ENUM_LABEL_VIDEO_MESSAGE_BGCOLOR_ENABLE); notificationsGroup->add(MENU_ENUM_LABEL_FPS_SHOW); notificationsGroup->add(MENU_ENUM_LABEL_FPS_UPDATE_INTERVAL); notificationsGroup->add(MENU_ENUM_LABEL_FRAMECOUNT_SHOW); notificationsGroup->add(MENU_ENUM_LABEL_MEMORY_SHOW); notificationsGroup->add(MENU_ENUM_LABEL_MEMORY_UPDATE_INTERVAL); notificationsGroup->add(MENU_ENUM_LABEL_TIME_SHOW); notificationsGroup->add(MENU_ENUM_LABEL_STATISTICS_SHOW); notificationsGroup->add(MENU_ENUM_LABEL_NETPLAY_PING_SHOW); notificationsGroup->add(MENU_ENUM_LABEL_VIDEO_FONT_PATH); notificationsGroup->add(MENU_ENUM_LABEL_VIDEO_FONT_SIZE); notificationsGroup->add(MENU_ENUM_LABEL_VIDEO_MESSAGE_POS_X); notificationsGroup->add(MENU_ENUM_LABEL_VIDEO_MESSAGE_POS_Y); /* TODO/FIXME - localize */ notificationsGroup->addRow("Notification Color: ", new FloatColorButton( MENU_ENUM_LABEL_VIDEO_MESSAGE_COLOR_RED, MENU_ENUM_LABEL_VIDEO_MESSAGE_COLOR_GREEN, MENU_ENUM_LABEL_VIDEO_MESSAGE_COLOR_BLUE)); /* TODO/FIXME - localize */ bgGroup->addRow("Notification Background Color: ", new UIntColorButton( MENU_ENUM_LABEL_VIDEO_MESSAGE_BGCOLOR_RED, MENU_ENUM_LABEL_VIDEO_MESSAGE_BGCOLOR_GREEN, MENU_ENUM_LABEL_VIDEO_MESSAGE_BGCOLOR_BLUE)); bgGroup->add(MENU_ENUM_LABEL_VIDEO_MESSAGE_BGCOLOR_OPACITY); notificationsGroup->addRow(bgGroup); notificationsGroup->add(MENU_ENUM_LABEL_MENU_WIDGETS_ENABLE); notificationsGroup->add(MENU_ENUM_LABEL_MENU_WIDGET_SCALE_AUTO); notificationsGroup->add(MENU_ENUM_LABEL_MENU_WIDGET_SCALE_FACTOR); #if !(defined(RARCH_CONSOLE) || defined(RARCH_MOBILE)) notificationsGroup->add(MENU_ENUM_LABEL_MENU_WIDGET_SCALE_FACTOR_WINDOWED); #endif notificationsGroup->add(MENU_ENUM_LABEL_MENU_SHOW_LOAD_CONTENT_ANIMATION); notificationsGroup->add(MENU_ENUM_LABEL_NOTIFICATION_SHOW_AUTOCONFIG); notificationsGroup->add(MENU_ENUM_LABEL_NOTIFICATION_SHOW_AUTOCONFIG_FAILS); notificationsGroup->add(MENU_ENUM_LABEL_NOTIFICATION_SHOW_REMAP_LOAD); #ifdef HAVE_CORE_SIGNING_TEST_KEY notificationsGroup->add(MENU_ENUM_LABEL_NOTIFICATION_SHOW_CORE_SIGNING_TEST_KEY); #endif notificationsGroup->add(MENU_ENUM_LABEL_NOTIFICATION_SHOW_CONFIG_OVERRIDE_LOAD); notificationsGroup->add(MENU_ENUM_LABEL_NOTIFICATION_SHOW_SET_INITIAL_DISK); notificationsGroup->add(MENU_ENUM_LABEL_NOTIFICATION_SHOW_SAVE_STATE); notificationsGroup->add(MENU_ENUM_LABEL_NOTIFICATION_SHOW_FAST_FORWARD); notificationsGroup->add(MENU_ENUM_LABEL_NOTIFICATION_SHOW_CHEATS_APPLIED); notificationsGroup->add(MENU_ENUM_LABEL_NOTIFICATION_SHOW_SCREENSHOT); notificationsGroup->add(MENU_ENUM_LABEL_NOTIFICATION_SHOW_SCREENSHOT_DURATION); notificationsGroup->add(MENU_ENUM_LABEL_NOTIFICATION_SHOW_SCREENSHOT_FLASH); notificationsGroup->add(MENU_ENUM_LABEL_NOTIFICATION_SHOW_REFRESH_RATE); notificationsGroup->add(MENU_ENUM_LABEL_NOTIFICATION_SHOW_NETPLAY_EXTRA); notificationsGroup->add(MENU_ENUM_LABEL_NOTIFICATION_SHOW_WHEN_MENU_IS_ALIVE); { SettingsGroup *notificationViewsGroup = new SettingsGroup("Additional Notification Options"); static const enum msg_hash_enums notificationViewsEntries[] = { MENU_ENUM_LABEL_STATISTICS_HIDE_IN_MENU, MENU_ENUM_LABEL_NOTIFICATION_SHOW_PATCH_APPLIED, MENU_ENUM_LABEL_NOTIFICATION_SHOW_DISK_CONTROL }; qt_settings_group_add_displaylist(notificationViewsGroup, DISPLAYLIST_ONSCREEN_NOTIFICATIONS_VIEWS_SETTINGS_LIST, NULL, 0, notificationViewsEntries, ARRAY_SIZE(notificationViewsEntries)); notificationsGroup->addRow(notificationViewsGroup); } layout->addWidget(notificationsGroup); layout->addStretch(); widget->setLayout(layout); return widget; } OverlayPage::OverlayPage(QObject *parent) : OptionsPage(parent) { setDisplayName("General"); } QWidget *OverlayPage::widget() { QWidget *widget = new QWidget; QVBoxLayout *layout = new QVBoxLayout; QHBoxLayout *columnsLayout = new QHBoxLayout; QVBoxLayout *leftColumn = new QVBoxLayout; QVBoxLayout *rightColumn = new QVBoxLayout; #if defined(HAVE_OVERLAY) { CheckableSettingsGroup *overlayGroup = new CheckableSettingsGroup( MENU_ENUM_LABEL_INPUT_OVERLAY_ENABLE); overlayGroup->add(MENU_ENUM_LABEL_OVERLAY_AUTOLOAD_PREFERRED); overlayGroup->add(MENU_ENUM_LABEL_INPUT_OVERLAY_AUTO_ROTATE); overlayGroup->add(MENU_ENUM_LABEL_INPUT_OVERLAY_HIDE_IN_MENU); overlayGroup->add(MENU_ENUM_LABEL_INPUT_OVERLAY_HIDE_WHEN_GAMEPAD_CONNECTED); overlayGroup->add(MENU_ENUM_LABEL_INPUT_OVERLAY_SHOW_MOUSE_CURSOR); overlayGroup->add(MENU_ENUM_LABEL_INPUT_OVERLAY_SHOW_INPUTS); overlayGroup->add(MENU_ENUM_LABEL_INPUT_OVERLAY_SHOW_INPUTS_PORT); overlayGroup->add(MENU_ENUM_LABEL_OVERLAY_PRESET); overlayGroup->add(MENU_ENUM_LABEL_OVERLAY_OPACITY); overlayGroup->add(MENU_ENUM_LABEL_OVERLAY_SCALE_LANDSCAPE); overlayGroup->add(MENU_ENUM_LABEL_OVERLAY_ASPECT_ADJUST_LANDSCAPE); overlayGroup->add(MENU_ENUM_LABEL_OVERLAY_X_SEPARATION_LANDSCAPE); overlayGroup->add(MENU_ENUM_LABEL_OVERLAY_Y_SEPARATION_LANDSCAPE); overlayGroup->add(MENU_ENUM_LABEL_OVERLAY_X_OFFSET_LANDSCAPE); overlayGroup->add(MENU_ENUM_LABEL_OVERLAY_Y_OFFSET_LANDSCAPE); overlayGroup->add(MENU_ENUM_LABEL_OVERLAY_SCALE_PORTRAIT); overlayGroup->add(MENU_ENUM_LABEL_OVERLAY_ASPECT_ADJUST_PORTRAIT); overlayGroup->add(MENU_ENUM_LABEL_OVERLAY_X_SEPARATION_PORTRAIT); overlayGroup->add(MENU_ENUM_LABEL_OVERLAY_X_OFFSET_PORTRAIT); overlayGroup->add(MENU_ENUM_LABEL_OVERLAY_Y_OFFSET_PORTRAIT); { static const enum msg_hash_enums overlayExtraEntries[] = { MENU_ENUM_LABEL_INPUT_OVERLAY_BEHIND_MENU, MENU_ENUM_LABEL_INPUT_OVERLAY_DPAD_DIAGONAL_SENSITIVITY, MENU_ENUM_LABEL_INPUT_OVERLAY_ABXY_DIAGONAL_SENSITIVITY, MENU_ENUM_LABEL_INPUT_OVERLAY_DPAD_METHOD, MENU_ENUM_LABEL_INPUT_OVERLAY_ABXY_METHOD, MENU_ENUM_LABEL_INPUT_OVERLAY_CONTACT_SCALE, MENU_ENUM_LABEL_INPUT_OVERLAY_ANALOG_RECENTER_ZONE, MENU_ENUM_LABEL_INPUT_OVERLAY_AUTO_SCALE, MENU_ENUM_LABEL_OVERLAY_Y_SEPARATION_PORTRAIT, MENU_ENUM_LABEL_INPUT_OVERLAY_POINTER_ENABLE }; qt_settings_group_add_displaylist(overlayGroup, DISPLAYLIST_ONSCREEN_OVERLAY_SETTINGS_LIST, NULL, 0, overlayExtraEntries, ARRAY_SIZE(overlayExtraEntries)); } { SettingsGroup *lightgunGroup = new SettingsGroup( msg_hash_to_str(MENU_ENUM_LABEL_VALUE_OVERLAY_LIGHTGUN_SETTINGS)); SettingsGroup *mouseGroup = new SettingsGroup( msg_hash_to_str(MENU_ENUM_LABEL_VALUE_OVERLAY_MOUSE_SETTINGS)); SettingsGroup *oskGroup = new SettingsGroup( msg_hash_to_str(MENU_ENUM_LABEL_VALUE_OSK_OVERLAY_SETTINGS)); qt_settings_group_add_displaylist(lightgunGroup, DISPLAYLIST_OVERLAY_LIGHTGUN_SETTINGS_LIST, NULL, 0, NULL, 0); qt_settings_group_add_displaylist(mouseGroup, DISPLAYLIST_OVERLAY_MOUSE_SETTINGS_LIST, NULL, 0, NULL, 0); qt_settings_group_add_displaylist(oskGroup, DISPLAYLIST_OSK_OVERLAY_SETTINGS_LIST, NULL, 0, NULL, 0); overlayGroup->addRow(lightgunGroup); overlayGroup->addRow(mouseGroup); overlayGroup->addRow(oskGroup); } rightColumn->addWidget(overlayGroup); } #endif { NotificationsPage *notificationsPage = new NotificationsPage(this); leftColumn->addWidget(notificationsPage->widget()); } leftColumn->addStretch(); rightColumn->addStretch(); columnsLayout->addLayout(leftColumn, 1); columnsLayout->addLayout(rightColumn, 1); layout->addLayout(columnsLayout); widget->setLayout(layout); return widget; } PlaylistsCategory::PlaylistsCategory(QWidget *parent) : OptionsCategory(parent) { setDisplayName(MENU_ENUM_LABEL_VALUE_PLAYLIST_SETTINGS); setCategoryIcon("menu_playlist"); } QVector PlaylistsCategory::pages() { QVector pages; pages << new PlaylistsPage(this); return pages; } PlaylistsPage::PlaylistsPage(QObject *parent) : OptionsPage(parent) { } QWidget *PlaylistsPage::widget() { QWidget *widget = new QWidget; QVBoxLayout *layout = new QVBoxLayout; QHBoxLayout *contentLayout = new QHBoxLayout; QVBoxLayout *leftColumn = new QVBoxLayout; CheckableSettingsGroup *historyGroup = new CheckableSettingsGroup( MENU_ENUM_LABEL_HISTORY_LIST_ENABLE); SettingsGroup *playlistGroup = new SettingsGroup("Playlist"); SettingsGroup *scanningGroup = new SettingsGroup("Scanning"); SettingsGroup *additionalGroup = new SettingsGroup("Additional Settings"); static const enum msg_hash_enums playlistSkip[] = { MENU_ENUM_LABEL_HISTORY_LIST_ENABLE, MENU_ENUM_LABEL_CONTENT_HISTORY_SIZE, MENU_ENUM_LABEL_PLAYLIST_ENTRY_RENAME, MENU_ENUM_LABEL_PLAYLIST_SORT_ALPHABETICAL, MENU_ENUM_LABEL_PLAYLIST_USE_OLD_FORMAT, MENU_ENUM_LABEL_PLAYLIST_COMPRESSION, MENU_ENUM_LABEL_PLAYLIST_SHOW_SUBLABELS, MENU_ENUM_LABEL_PLAYLIST_FUZZY_ARCHIVE_MATCH, MENU_ENUM_LABEL_SCAN_WITHOUT_CORE_MATCH }; historyGroup->add(MENU_ENUM_LABEL_CONTENT_HISTORY_SIZE); playlistGroup->add(MENU_ENUM_LABEL_PLAYLIST_ENTRY_RENAME); playlistGroup->add(MENU_ENUM_LABEL_PLAYLIST_SORT_ALPHABETICAL); playlistGroup->add(MENU_ENUM_LABEL_PLAYLIST_USE_OLD_FORMAT); playlistGroup->add(MENU_ENUM_LABEL_PLAYLIST_COMPRESSION); playlistGroup->add(MENU_ENUM_LABEL_PLAYLIST_SHOW_SUBLABELS); playlistGroup->add(MENU_ENUM_LABEL_PLAYLIST_FUZZY_ARCHIVE_MATCH); scanningGroup->add(MENU_ENUM_LABEL_SCAN_WITHOUT_CORE_MATCH); qt_settings_group_add_displaylist(additionalGroup, DISPLAYLIST_PLAYLIST_SETTINGS_LIST, playlistSkip, ARRAY_SIZE(playlistSkip), NULL, 0); leftColumn->addWidget(historyGroup); leftColumn->addWidget(playlistGroup); leftColumn->addWidget(scanningGroup); leftColumn->addWidget(additionalGroup); leftColumn->addStretch(); contentLayout->addLayout(leftColumn, 1); contentLayout->addStretch(1); layout->addLayout(contentLayout); layout->addStretch(); widget->setLayout(layout); return widget; } RecordingCategory::RecordingCategory(QWidget *parent) : OptionsCategory(parent) { setDisplayName(MENU_ENUM_LABEL_VALUE_RECORDING_SETTINGS); setCategoryIcon("menu_record"); } QVector RecordingCategory::pages() { QVector pages; pages << new RecordingPage(this); return pages; } RecordingPage::RecordingPage(QObject *parent) : OptionsPage(parent) { } QWidget *RecordingPage::widget() { QWidget *widget = new QWidget; QVBoxLayout *layout = new QVBoxLayout; QHBoxLayout *columnsLayout = new QHBoxLayout; QVBoxLayout *leftColumn = new QVBoxLayout; SettingsGroup *recordingGroup = new SettingsGroup("Recording"); SettingsGroup *streamingGroup = new SettingsGroup("Streaming"); QHBoxLayout *streamingModeLayout = new QHBoxLayout; static const enum msg_hash_enums recordingSkip[] = { MENU_ENUM_LABEL_STREAMING_MODE, MENU_ENUM_LABEL_VIDEO_STREAM_QUALITY, MENU_ENUM_LABEL_STREAM_CONFIG, MENU_ENUM_LABEL_STREAMING_TITLE, MENU_ENUM_LABEL_STREAMING_URL, MENU_ENUM_LABEL_UDP_STREAM_PORT, MENU_ENUM_LABEL_RECORDING_OUTPUT_DIRECTORY }; static const enum msg_hash_enums streamingEntries[] = { MENU_ENUM_LABEL_STREAM_CONFIG, MENU_ENUM_LABEL_STREAMING_TITLE, MENU_ENUM_LABEL_STREAMING_URL, MENU_ENUM_LABEL_UDP_STREAM_PORT }; file_list_t *recordingList = qt_displaylist_build( DISPLAYLIST_RECORDING_SETTINGS_LIST); qt_settings_group_add_list(recordingGroup, recordingList, recordingSkip, ARRAY_SIZE(recordingSkip), NULL, 0); qt_settings_group_add_compact_path(recordingGroup, MENU_ENUM_LABEL_RECORDING_OUTPUT_DIRECTORY, true); /* These compact radio controls are retained from the original page. */ streamingModeLayout->addWidget( new UIntRadioButtons(MENU_ENUM_LABEL_STREAMING_MODE)); streamingModeLayout->addWidget( new UIntRadioButtons(MENU_ENUM_LABEL_VIDEO_STREAM_QUALITY)); streamingGroup->addRow(streamingModeLayout); qt_settings_group_add_list(streamingGroup, recordingList, NULL, 0, streamingEntries, ARRAY_SIZE(streamingEntries)); if (recordingList) file_list_free(recordingList); leftColumn->addWidget(recordingGroup); leftColumn->addWidget(streamingGroup); leftColumn->addStretch(); columnsLayout->addLayout(leftColumn, 1); columnsLayout->addStretch(1); layout->addLayout(columnsLayout); layout->addStretch(); widget->setLayout(layout); return widget; } SavingCategory::SavingCategory(QWidget *parent) : OptionsCategory(parent) { setDisplayName(MENU_ENUM_LABEL_VALUE_SAVING_SETTINGS); setCategoryIcon("menu_saving"); } QVector SavingCategory::pages() { QVector pages; pages << new SavingPage(this); return pages; } SavingPage::SavingPage(QObject *parent) : OptionsPage(parent) { } QWidget *SavingPage::widget() { QWidget *widget = new QWidget; QVBoxLayout *layout = new QVBoxLayout; QHBoxLayout *columnsLayout = new QHBoxLayout; QVBoxLayout *leftColumn = new QVBoxLayout; QVBoxLayout *rightColumn = new QVBoxLayout; SettingsGroup *savesGroup = new SettingsGroup("Save Files"); SettingsGroup *saveRamGroup = new SettingsGroup("SaveRAM"); SettingsGroup *systemFilesDirGroup = new SettingsGroup("System Files"); SettingsGroup *screenshotsDirGroup = new SettingsGroup("Screenshots"); SettingsGroup *savestatesGroup = new SettingsGroup("Savestates"); SettingsGroup *replayGroup = new SettingsGroup("Replays"); SettingsGroup *runtimeLogGroup = new SettingsGroup("Runtime Log"); static const enum msg_hash_enums savesEntries[] = { MENU_ENUM_LABEL_SORT_SAVEFILES_ENABLE, MENU_ENUM_LABEL_SORT_SAVEFILES_BY_CONTENT_ENABLE, MENU_ENUM_LABEL_SAVEFILES_IN_CONTENT_DIR_ENABLE, MENU_ENUM_LABEL_SAVE_FILE_COMPRESSION, MENU_ENUM_LABEL_SAVE_COMPRESSION_CODEC }; static const enum msg_hash_enums saveRamEntries[] = { MENU_ENUM_LABEL_BLOCK_SRAM_OVERWRITE, MENU_ENUM_LABEL_AUTOSAVE_INTERVAL }; static const enum msg_hash_enums screenshotEntries[] = { MENU_ENUM_LABEL_VIDEO_GPU_SCREENSHOT, MENU_ENUM_LABEL_SORT_SCREENSHOTS_BY_CONTENT_ENABLE, MENU_ENUM_LABEL_SCREENSHOTS_IN_CONTENT_DIR_ENABLE }; static const enum msg_hash_enums savestateEntries[] = { MENU_ENUM_LABEL_SORT_SAVESTATES_ENABLE, MENU_ENUM_LABEL_SORT_SAVESTATES_BY_CONTENT_ENABLE, MENU_ENUM_LABEL_SAVESTATES_IN_CONTENT_DIR_ENABLE, MENU_ENUM_LABEL_SAVESTATE_AUTO_SAVE, MENU_ENUM_LABEL_SAVESTATE_AUTO_LOAD, MENU_ENUM_LABEL_SAVESTATE_THUMBNAIL_ENABLE, MENU_ENUM_LABEL_SAVESTATE_FILE_COMPRESSION, MENU_ENUM_LABEL_SAVESTATE_AUTOMATIC_INTERVAL, MENU_ENUM_LABEL_SAVESTATE_AUTO_INDEX, MENU_ENUM_LABEL_SAVESTATE_MAX_KEEP }; static const enum msg_hash_enums replayEntries[] = { MENU_ENUM_LABEL_REPLAY_AUTO_INDEX, MENU_ENUM_LABEL_REPLAY_MAX_KEEP, MENU_ENUM_LABEL_REPLAY_CHECKPOINT_INTERVAL, MENU_ENUM_LABEL_REPLAY_CHECKPOINT_DESERIALIZE }; static const enum msg_hash_enums runtimeEntries[] = { MENU_ENUM_LABEL_CONTENT_RUNTIME_LOG, MENU_ENUM_LABEL_CONTENT_RUNTIME_LOG_AGGREGATE }; file_list_t *savingList = qt_displaylist_build( DISPLAYLIST_SAVING_SETTINGS_LIST); qt_settings_group_add_list(savesGroup, savingList, NULL, 0, savesEntries, ARRAY_SIZE(savesEntries)); qt_settings_group_add_list(saveRamGroup, savingList, NULL, 0, saveRamEntries, ARRAY_SIZE(saveRamEntries)); systemFilesDirGroup->add(MENU_ENUM_LABEL_SYSTEMFILES_IN_CONTENT_DIR_ENABLE); qt_settings_group_add_list(screenshotsDirGroup, savingList, NULL, 0, screenshotEntries, ARRAY_SIZE(screenshotEntries)); qt_settings_group_add_list(savestatesGroup, savingList, NULL, 0, savestateEntries, ARRAY_SIZE(savestateEntries)); qt_settings_group_add_list(replayGroup, savingList, NULL, 0, replayEntries, ARRAY_SIZE(replayEntries)); qt_settings_group_add_list(runtimeLogGroup, savingList, NULL, 0, runtimeEntries, ARRAY_SIZE(runtimeEntries)); if (savingList) file_list_free(savingList); leftColumn->addWidget(savesGroup); leftColumn->addWidget(saveRamGroup); leftColumn->addWidget(systemFilesDirGroup); leftColumn->addWidget(screenshotsDirGroup); leftColumn->addWidget(replayGroup); rightColumn->addWidget(savestatesGroup); rightColumn->addWidget(runtimeLogGroup); #ifdef HAVE_CLOUDSYNC { SettingsGroup *cloudSyncGroup = new SettingsGroup( msg_hash_to_str(MENU_ENUM_LABEL_VALUE_CLOUD_SYNC_SETTINGS)); qt_settings_group_add_displaylist(cloudSyncGroup, DISPLAYLIST_CLOUD_SYNC_SETTINGS_LIST, NULL, 0, NULL, 0); rightColumn->addWidget(cloudSyncGroup); } #endif leftColumn->addStretch(); rightColumn->addStretch(); columnsLayout->addLayout(leftColumn, 1); columnsLayout->addLayout(rightColumn, 1); layout->addLayout(columnsLayout); layout->addStretch(); widget->setLayout(layout); return widget; } UserInterfaceCategory::UserInterfaceCategory(QWidget *parent) : OptionsCategory(parent) { setDisplayName(MENU_ENUM_LABEL_VALUE_USER_INTERFACE_SETTINGS); setCategoryIcon("menu_ui"); } UserInterfaceCategory::UserInterfaceCategory(MainWindow *mainwindow, QWidget *parent) : OptionsCategory(parent) ,m_mainwindow(mainwindow) { setDisplayName(MENU_ENUM_LABEL_VALUE_USER_INTERFACE_SETTINGS); setCategoryIcon("menu_ui"); m_pages << new UserInterfacePage(this); m_pages << new ViewsPage(this); m_pages << new AppearancePage(this); m_pages << new DesktopMenuPage(m_mainwindow, this); } QVector UserInterfaceCategory::pages() { return m_pages; } UserInterfacePage::UserInterfacePage(QObject *parent) : OptionsPage(parent) { } QWidget *UserInterfacePage::widget() { QWidget *widget = new QWidget; QVBoxLayout *layout = new QVBoxLayout; QHBoxLayout *columnsLayout = new QHBoxLayout; QVBoxLayout *leftColumn = new QVBoxLayout; QVBoxLayout *rightColumn = new QVBoxLayout; SettingsGroup *menuGroup = new SettingsGroup("Menu"); SettingsGroup *inputGroup = new SettingsGroup("Input"); SettingsGroup *miscGroup = new SettingsGroup("Miscellaneous"); SettingsGroup *behaviorGroup = new SettingsGroup("Behavior"); SettingsGroup *fileBrowserGroup = new SettingsGroup( msg_hash_to_str(MENU_ENUM_LABEL_VALUE_MENU_FILE_BROWSER_SETTINGS)); SettingsGroup *mediaPlayerGroup = new SettingsGroup( msg_hash_to_str(MENU_ENUM_LABEL_VALUE_MEDIA_PLAYER_SETTINGS)); CheckableSettingsGroup *desktopGroup = new CheckableSettingsGroup( MENU_ENUM_LABEL_DESKTOP_MENU_ENABLE); static const enum msg_hash_enums uiGeneralEntries[] = { MENU_ENUM_LABEL_PAUSE_ON_DISCONNECT, MENU_ENUM_LABEL_MENU_SAVESTATE_RESUME, MENU_ENUM_LABEL_MENU_INSERT_DISK_RESUME, MENU_ENUM_LABEL_QUIT_ON_CLOSE_CONTENT, MENU_ENUM_LABEL_MENU_REMEMBER_SELECTION, MENU_ENUM_LABEL_MENU_STARTUP_PAGE, MENU_ENUM_LABEL_CONFIRM_QUIT, MENU_ENUM_LABEL_CONFIRM_CLOSE, MENU_ENUM_LABEL_CONFIRM_RESET, MENU_ENUM_LABEL_THREAD_PREFER_FAST_CORES, MENU_ENUM_LABEL_VIDEO_THREAD_PRIORITY, MENU_ENUM_LABEL_MAIN_THREAD_PRIORITY, MENU_ENUM_LABEL_MENU_SCREENSAVER_TIMEOUT, MENU_ENUM_LABEL_MENU_SCREENSAVER_ANIMATION, MENU_ENUM_LABEL_MENU_SCREENSAVER_ANIMATION_SPEED, MENU_ENUM_LABEL_APPICON_SETTINGS }; rarch_setting_t *kioskMode = menu_setting_find_enum( MENU_ENUM_LABEL_MENU_ENABLE_KIOSK_MODE); menuGroup->add(MENU_ENUM_LABEL_SHOW_ADVANCED_SETTINGS); /* only on XMB and Ozone */ if (kioskMode) { CheckableSettingsGroup *kioskGroup = new CheckableSettingsGroup(kioskMode, widget); kioskGroup->add(MENU_ENUM_LABEL_MENU_KIOSK_MODE_PASSWORD); menuGroup->addRow(kioskGroup); } menuGroup->add(MENU_ENUM_LABEL_NAVIGATION_WRAPAROUND); menuGroup->add(MENU_ENUM_LABEL_PAUSE_LIBRETRO); menuGroup->add(MENU_ENUM_LABEL_THREADED_DATA_RUNLOOP_ENABLE); menuGroup->add(MENU_ENUM_LABEL_UI_COMPANION_ENABLE); menuGroup->add(MENU_ENUM_LABEL_UI_COMPANION_START_ON_BOOT); menuGroup->add(MENU_ENUM_LABEL_UI_MENUBAR_ENABLE); menuGroup->add(MENU_ENUM_LABEL_MENU_SCROLL_FAST); inputGroup->add(MENU_ENUM_LABEL_MOUSE_ENABLE); inputGroup->add(MENU_ENUM_LABEL_POINTER_ENABLE); menuGroup->addRow(inputGroup); miscGroup->add(MENU_ENUM_LABEL_PAUSE_NONACTIVE); miscGroup->add(MENU_ENUM_LABEL_VIDEO_DISABLE_COMPOSITION); desktopGroup->add(MENU_ENUM_LABEL_UI_COMPANION_TOGGLE); qt_settings_group_add_displaylist(behaviorGroup, DISPLAYLIST_USER_INTERFACE_SETTINGS_LIST, NULL, 0, uiGeneralEntries, ARRAY_SIZE(uiGeneralEntries)); qt_settings_group_add_displaylist(fileBrowserGroup, DISPLAYLIST_MENU_FILE_BROWSER_SETTINGS_LIST, NULL, 0, NULL, 0); qt_settings_group_add_displaylist(mediaPlayerGroup, DISPLAYLIST_MEDIA_PLAYER_SETTINGS_LIST, NULL, 0, NULL, 0); leftColumn->addWidget(menuGroup); leftColumn->addWidget(behaviorGroup); rightColumn->addWidget(fileBrowserGroup); rightColumn->addWidget(mediaPlayerGroup); rightColumn->addWidget(miscGroup); rightColumn->addWidget(desktopGroup); leftColumn->addStretch(); rightColumn->addStretch(); columnsLayout->addLayout(leftColumn, 1); columnsLayout->addLayout(rightColumn, 1); layout->addLayout(columnsLayout); widget->setLayout(layout); return widget; } ViewsPage::ViewsPage(QObject *parent) : OptionsPage(parent) { setDisplayName(MENU_ENUM_LABEL_VALUE_MENU_VIEWS_SETTINGS); } QWidget *ViewsPage::widget() { unsigned i; QWidget * widget = new QWidget(); QHBoxLayout *mainLayout = new QHBoxLayout; FormLayout *leftLayout = new FormLayout; QVBoxLayout *rightLayout = new QVBoxLayout; SettingsGroup *quickMenu = new SettingsGroup("Quick Menu"); OptionsPage *quickPage = new SimplePage( DISPLAYLIST_QUICK_MENU_VIEWS_SETTINGS_LIST, MENU_ENUM_LABEL_VALUE_QUICK_MENU_VIEWS_SETTINGS, this); QWidget *quickPageWidget; SettingsGroup *mainMenu = new SettingsGroup("Main Menu"); SettingsGroup *settings = new SettingsGroup("Settings"); SettingsGroup *tabs = new SettingsGroup("Tabs"); SettingsGroup *status = new SettingsGroup("Status"); SettingsGroup *startScreen = new SettingsGroup("StartScreen"); settings_t *_settings = config_get_ptr(); unsigned tabs_begin = 0; unsigned status_begin = 0; file_list_t *list = (file_list_t*)calloc(1, sizeof(*list)); { rarch_setting_t *kiosk_mode = NULL; menu_displaylist_build_list(list, _settings, DISPLAYLIST_MENU_VIEWS_SETTINGS_LIST, true); kiosk_mode = menu_setting_find_enum( MENU_ENUM_LABEL_MENU_ENABLE_KIOSK_MODE); for (i = 0; i < list->size; i++) { menu_file_list_cbs_t *cbs = (menu_file_list_cbs_t*) file_list_get_actiondata_at_offset(list, i); if (cbs->enum_idx == (kiosk_mode ? MENU_ENUM_LABEL_CONTENT_SHOW_SETTINGS : MENU_ENUM_LABEL_CONTENT_SHOW_EXPLORE)) { tabs_begin = i; break; } mainMenu->add(cbs->enum_idx); } for (i = tabs_begin; i < list->size; i++) { menu_file_list_cbs_t *cbs = (menu_file_list_cbs_t*) file_list_get_actiondata_at_offset(list, i); if (cbs->enum_idx == MENU_ENUM_LABEL_TIMEDATE_ENABLE) { status_begin = i; break; } tabs->add(cbs->enum_idx); } for (i = status_begin; i < list->size; i++) { menu_file_list_cbs_t *cbs = (menu_file_list_cbs_t*) file_list_get_actiondata_at_offset(list, i); if (cbs->enum_idx == MENU_ENUM_LABEL_MENU_SHOW_SUBLABELS) break; status->add(cbs->enum_idx); } file_list_free(list); } { unsigned i; file_list_t *list = (file_list_t*)calloc(1, sizeof(*list)); menu_displaylist_build_list(list, _settings, DISPLAYLIST_SETTINGS_VIEWS_SETTINGS_LIST, true); for (i = 0; i < list->size; i++) { menu_file_list_cbs_t *cbs = (menu_file_list_cbs_t*) file_list_get_actiondata_at_offset(list, i); settings->add(cbs->enum_idx); } file_list_free(list); } startScreen->add(MENU_ENUM_LABEL_RGUI_SHOW_START_SCREEN); quickMenu->layout()->setContentsMargins(0, 0, 0, 0); quickPageWidget = quickPage->widget(); quickPageWidget->setObjectName("quickMenuPage"); quickMenu->addRow(quickPageWidget); leftLayout->addRow(mainMenu); leftLayout->addRow(settings); leftLayout->addRow(startScreen); leftLayout->add(menu_setting_find_enum(MENU_ENUM_LABEL_MENU_SHOW_SUBLABELS)); rightLayout->addWidget(tabs); rightLayout->addWidget(quickMenu); rightLayout->addWidget(status); rightLayout->addStretch(); mainLayout->addLayout(leftLayout, 1); mainLayout->addLayout(rightLayout, 1); widget->setLayout(mainLayout); return widget; } AppearancePage::AppearancePage(QObject *parent) : OptionsPage(parent) { setDisplayName(MENU_ENUM_LABEL_VALUE_MENU_SETTINGS); } static bool qt_setting_list_contains(enum msg_hash_enums setting, const enum msg_hash_enums *entries, size_t count); QWidget *AppearancePage::widget() { unsigned i; QWidget *widget = new QWidget; QVBoxLayout *layout = new QVBoxLayout; QHBoxLayout *columnsLayout = new QHBoxLayout; QVBoxLayout *leftColumn = new QVBoxLayout; QVBoxLayout *rightColumn = new QVBoxLayout; SettingsGroup *appearanceGroup = new SettingsGroup("Appearance"); SettingsGroup *tickerGroup = new SettingsGroup("Ticker"); SettingsGroup *thumbnailGroup = new SettingsGroup("Thumbnails"); file_list_t *list = (file_list_t*)calloc(1, sizeof(*list)); settings_t *settings = config_get_ptr(); static const enum msg_hash_enums tickerEntries[] = { MENU_ENUM_LABEL_MENU_TICKER_TYPE, MENU_ENUM_LABEL_MENU_TICKER_SPEED, MENU_ENUM_LABEL_MENU_TICKER_SMOOTH }; static const enum msg_hash_enums thumbnailEntries[] = { MENU_ENUM_LABEL_MATERIALUI_MENU_THUMBNAIL_VIEW_PORTRAIT, MENU_ENUM_LABEL_MATERIALUI_MENU_THUMBNAIL_VIEW_LANDSCAPE, MENU_ENUM_LABEL_MATERIALUI_DUAL_THUMBNAIL_LIST_VIEW_ENABLE, MENU_ENUM_LABEL_MATERIALUI_THUMBNAIL_BACKGROUND_ENABLE, MENU_ENUM_LABEL_MENU_RGUI_INLINE_THUMBNAILS, MENU_ENUM_LABEL_THUMBNAILS, MENU_ENUM_LABEL_LEFT_THUMBNAILS, MENU_ENUM_LABEL_ICON_THUMBNAILS, MENU_ENUM_LABEL_XMB_VERTICAL_THUMBNAILS, MENU_ENUM_LABEL_MENU_XMB_THUMBNAIL_SCALE_FACTOR, MENU_ENUM_LABEL_OZONE_THUMBNAIL_SCALE_FACTOR, MENU_ENUM_LABEL_MENU_THUMBNAIL_UPSCALE_THRESHOLD, MENU_ENUM_LABEL_MENU_RGUI_SWAP_THUMBNAILS, MENU_ENUM_LABEL_MENU_RGUI_THUMBNAIL_DOWNSCALER, MENU_ENUM_LABEL_MENU_RGUI_THUMBNAIL_DITHER, MENU_ENUM_LABEL_MENU_RGUI_THUMBNAIL_DELAY, MENU_ENUM_LABEL_MENU_THUMBNAIL_BACKGROUND_ENABLE, MENU_ENUM_LABEL_MENU_THUMBNAIL_PREVIEW_AUDIO, MENU_ENUM_LABEL_MENU_THUMBNAIL_PREVIEW_THREADS }; menu_displaylist_build_list(list, settings, DISPLAYLIST_MENU_SETTINGS_LIST, true); for (i = 0; i < list->size; i++) { menu_file_list_cbs_t *cbs = (menu_file_list_cbs_t*) file_list_get_actiondata_at_offset(list, i); enum msg_hash_enums entry = cbs->enum_idx; if (qt_setting_list_contains(entry, tickerEntries, ARRAY_SIZE(tickerEntries))) tickerGroup->add(entry); else if (qt_setting_list_contains(entry, thumbnailEntries, ARRAY_SIZE(thumbnailEntries))) thumbnailGroup->add(entry); else { switch (entry) { case MENU_ENUM_LABEL_MENU_FONT_COLOR_RED: appearanceGroup->addUIntColorButton("Menu Font Color: ", MENU_ENUM_LABEL_MENU_FONT_COLOR_RED, MENU_ENUM_LABEL_MENU_FONT_COLOR_GREEN, MENU_ENUM_LABEL_MENU_FONT_COLOR_BLUE); break; case MENU_ENUM_LABEL_MENU_FONT_COLOR_GREEN: case MENU_ENUM_LABEL_MENU_FONT_COLOR_BLUE: break; default: appearanceGroup->add(entry); break; } } } file_list_free(list); leftColumn->addWidget(appearanceGroup); leftColumn->addWidget(tickerGroup); rightColumn->addWidget(thumbnailGroup); leftColumn->addStretch(); rightColumn->addStretch(); columnsLayout->addLayout(leftColumn, 1); columnsLayout->addLayout(rightColumn, 1); layout->addLayout(columnsLayout); widget->setLayout(layout); return widget; } DesktopMenuPage::DesktopMenuPage(MainWindow *mainwindow, QObject *parent) : OptionsPage(parent) ,m_widget(new ViewOptionsWidget(mainwindow)) { setDisplayName("Desktop Menu"); } void DesktopMenuPage::apply() { m_widget->saveViewOptions(); } void DesktopMenuPage::load() { m_widget->loadViewOptions(); } QWidget *DesktopMenuPage::widget() { QWidget *page = new QWidget; QGridLayout *layout = new QGridLayout; /* m_widget in the top-left cell; the stretch factors keep it at half * width and top-aligned, without nested column layouts. */ layout->addWidget(m_widget, 0, 0); layout->setColumnStretch(0, 1); layout->setColumnStretch(1, 1); layout->setRowStretch(1, 1); page->setLayout(layout); return page; } UserCategory::UserCategory(QWidget *parent) : OptionsCategory(parent) { setDisplayName(MENU_ENUM_LABEL_VALUE_USER_SETTINGS); setCategoryIcon("menu_user"); } QVector UserCategory::pages() { QVector pages; pages << new UserPage(this); return pages; } UserPage::UserPage(QObject *parent) : OptionsPage(parent) { } QWidget *UserPage::widget() { QWidget *widget = new QWidget; FormLayout *layout = new FormLayout; layout->add(menu_setting_find_enum(MENU_ENUM_LABEL_NETPLAY_NICKNAME)); layout->add(menu_setting_find_enum(MENU_ENUM_LABEL_USER_LANGUAGE)); layout->add(menu_setting_find_enum(MENU_ENUM_LABEL_KEYCHAIN_PASSPHRASE)); { SettingsGroup *privacyGroup = new SettingsGroup( msg_hash_to_str(MENU_ENUM_LABEL_VALUE_PRIVACY_SETTINGS)); qt_settings_group_add_displaylist(privacyGroup, DISPLAYLIST_PRIVACY_SETTINGS_LIST, NULL, 0, NULL, 0); layout->addRow(privacyGroup); } { SettingsGroup *accountsGroup = new SettingsGroup( msg_hash_to_str(MENU_ENUM_LABEL_VALUE_ACCOUNTS_LIST)); AccountsPage *accountsPage = new AccountsPage(this); accountsGroup->addRow(accountsPage->widget()); layout->addRow(accountsGroup); } widget->setLayout(layout); return widget; } AccountsPage::AccountsPage(QObject *parent) : OptionsPage(parent) { setDisplayName(MENU_ENUM_LABEL_VALUE_ACCOUNTS_LIST); } QWidget *AccountsPage::widget() { QWidget *widget = new QWidget; QVBoxLayout *layout = new QVBoxLayout; SettingsGroup *youtubeGroup = new SettingsGroup(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_ACCOUNTS_YOUTUBE)); SettingsGroup *twitchGroup = new SettingsGroup(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_ACCOUNTS_TWITCH)); SettingsGroup *facebookGroup = new SettingsGroup(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_ACCOUNTS_FACEBOOK)); SettingsGroup *kickGroup = new SettingsGroup(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_ACCOUNTS_KICK)); #ifdef HAVE_CHEEVOS SettingsGroup *cheevosGroup = new SettingsGroup(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_ACCOUNTS_RETRO_ACHIEVEMENTS)); cheevosGroup->add(MENU_ENUM_LABEL_CHEEVOS_USERNAME); cheevosGroup->add(MENU_ENUM_LABEL_CHEEVOS_PASSWORD); layout->addWidget(cheevosGroup); #endif youtubeGroup->add(MENU_ENUM_LABEL_YOUTUBE_STREAM_KEY); layout->addWidget(youtubeGroup); twitchGroup->add(MENU_ENUM_LABEL_TWITCH_STREAM_KEY); layout->addWidget(twitchGroup); facebookGroup->add(MENU_ENUM_LABEL_FACEBOOK_STREAM_KEY); layout->addWidget(facebookGroup); kickGroup->add(MENU_ENUM_LABEL_KICK_STREAM_KEY); layout->addWidget(kickGroup); layout->addStretch(); widget->setAttribute(Qt::WA_TranslucentBackground); widget->setAutoFillBackground(false); widget->setLayout(layout); return widget; } /* Populate a Qt SettingsGroup from an existing RetroArch menu display list. * This keeps the menu's conditional/platform-specific settings as the source * of truth while allowing the desktop UI to arrange them into groups. */ static bool qt_setting_list_contains(enum msg_hash_enums setting, const enum msg_hash_enums *entries, size_t count) { size_t i; for (i = 0; i < count; i++) if (entries[i] == setting) return true; return false; } /* Build a menu display list once; a page that splits one list into * several groups walks the same build for each group instead of * rebuilding (and re-copying every label of) the whole list per group. */ static file_list_t *qt_displaylist_build( enum menu_displaylist_ctl_state state) { file_list_t *list = (file_list_t*)calloc(1, sizeof(*list)); if (list) menu_displaylist_build_list(list, config_get_ptr(), state, true); return list; } static bool qt_list_has_entry(const file_list_t *list, enum msg_hash_enums entry) { size_t i; if (!list) return false; for (i = 0; i < list->size; i++) { const menu_file_list_cbs_t *cbs = (const menu_file_list_cbs_t*) list->list[i].actiondata; if (cbs && cbs->enum_idx == entry) return true; } return false; } static void qt_settings_group_add_list(SettingsGroup *group, const file_list_t *list, const enum msg_hash_enums *skip_entries, size_t skip_count, const enum msg_hash_enums *only_entries, size_t only_count) { size_t i; if (!list) return; for (i = 0; i < list->size; i++) { rarch_setting_t *setting; const menu_file_list_cbs_t *cbs = (const menu_file_list_cbs_t*) list->list[i].actiondata; if (!cbs) continue; if (only_count && !qt_setting_list_contains(cbs->enum_idx, only_entries, only_count)) continue; if (qt_setting_list_contains(cbs->enum_idx, skip_entries, skip_count)) continue; if ((setting = menu_setting_find_enum(cbs->enum_idx))) group->add(setting); } } static void qt_settings_group_add_displaylist(SettingsGroup *group, enum menu_displaylist_ctl_state state, const enum msg_hash_enums *skip_entries, size_t skip_count, const enum msg_hash_enums *only_entries, size_t only_count) { file_list_t *list = qt_displaylist_build(state); if (!list) return; qt_settings_group_add_list(group, list, skip_entries, skip_count, only_entries, only_count); file_list_free(list); } VideoCategory::VideoCategory(QWidget *parent) : OptionsCategory(parent) { setDisplayName(MENU_ENUM_LABEL_VALUE_VIDEO_SETTINGS); setCategoryIcon("menu_video"); } QVector VideoCategory::pages() { QVector pages; pages << new VideoPage(this); return pages; } VideoPage::VideoPage(QObject *parent) : OptionsPage(parent) ,m_resolutionCombo(new QComboBox()) ,m_crtSuperResolutionCombo(NULL) { } QWidget *VideoPage::widget() { QWidget *widget = new QWidget; QVBoxLayout *layout = new QVBoxLayout; QHBoxLayout *columnsLayout = new QHBoxLayout; QVBoxLayout *leftColumn = new QVBoxLayout; QVBoxLayout *rightColumn = new QVBoxLayout; SettingsGroup *outputGroup = new SettingsGroup("Output"); SettingsGroup *aspectGroup = new SettingsGroup("Scaling"); SettingsGroup *fullscreenGroup = new SettingsGroup("Fullscreen Mode"); SettingsGroup *windowedGroup = new SettingsGroup("Windowed Mode"); SettingsGroup *syncGroup = new SettingsGroup("Synchronization"); SettingsGroup *miscGroup = new SettingsGroup("Miscellaneous"); SettingsGroup *stereo3dGroup = new SettingsGroup("Stereo 3D and Screens"); CheckableSettingsGroup *vSyncGroup = new CheckableSettingsGroup(MENU_ENUM_LABEL_VIDEO_VSYNC); #if defined(_WIN32) && !defined(_XBOX) && !defined(__WINRT__) CheckableSettingsGroup *windowCustomSizeGroup = new CheckableSettingsGroup(MENU_ENUM_LABEL_VIDEO_WINDOW_SAVE_POSITION); #else CheckableSettingsGroup *windowCustomSizeGroup = new CheckableSettingsGroup(MENU_ENUM_LABEL_VIDEO_WINDOW_CUSTOM_SIZE_ENABLE); #endif QHBoxLayout *fullscreenSizeLayout = new QHBoxLayout; FormLayout *leftFullscreenSizeForm = new FormLayout; FormLayout *rightFullscreenSizeForm = new FormLayout; QHBoxLayout *windowedSizeLayout = new QHBoxLayout; FormLayout *leftWindowedSizeForm = new FormLayout; FormLayout *rightWindowedSizeForm = new FormLayout; QHBoxLayout *windowedCustomSizeLayout = new QHBoxLayout; FormLayout *leftWindowedCustomSizeForm = new FormLayout; FormLayout *rightWindowedCustomSizeForm = new FormLayout; unsigned i, size = 0; bool hasCrtSwitchres; /* One build of the top-level video list serves the CRT probe and the * Miscellaneous / Video Filter split (it was built three times). */ file_list_t *videoList = qt_displaylist_build( DISPLAYLIST_VIDEO_SETTINGS_LIST); struct video_display_config *resolutionList = (struct video_display_config*)video_display_server_get_resolution_list(&size); static const enum msg_hash_enums outputSkip[] = { MENU_ENUM_LABEL_SCREEN_RESOLUTION, MENU_ENUM_LABEL_VIDEO_REFRESH_RATE_AUTO, MENU_ENUM_LABEL_VIDEO_REFRESH_RATE_POLLED }; static const enum msg_hash_enums scalingSkip[] = { MENU_ENUM_LABEL_VIDEO_ASPECT_RATIO_INDEX, MENU_ENUM_LABEL_VIDEO_ASPECT_RATIO, MENU_ENUM_LABEL_VIDEO_VIEWPORT_CUSTOM_X, MENU_ENUM_LABEL_VIDEO_VIEWPORT_CUSTOM_Y, MENU_ENUM_LABEL_VIDEO_VIEWPORT_CUSTOM_WIDTH, MENU_ENUM_LABEL_VIDEO_VIEWPORT_CUSTOM_HEIGHT }; static const enum msg_hash_enums fullscreenSkip[] = { MENU_ENUM_LABEL_VIDEO_FULLSCREEN_X, MENU_ENUM_LABEL_VIDEO_FULLSCREEN_Y }; static const enum msg_hash_enums windowedSkip[] = { #if defined(_WIN32) && !defined(_XBOX) && !defined(__WINRT__) MENU_ENUM_LABEL_VIDEO_WINDOW_SAVE_POSITION, #else MENU_ENUM_LABEL_VIDEO_WINDOW_CUSTOM_SIZE_ENABLE, #endif MENU_ENUM_LABEL_VIDEO_SCALE, MENU_ENUM_LABEL_VIDEO_WINDOW_WIDTH, MENU_ENUM_LABEL_VIDEO_WINDOW_HEIGHT, MENU_ENUM_LABEL_VIDEO_WINDOW_AUTO_WIDTH_MAX, MENU_ENUM_LABEL_VIDEO_WINDOW_AUTO_HEIGHT_MAX, MENU_ENUM_LABEL_VIDEO_WINDOW_OPACITY }; static const enum msg_hash_enums syncSkip[] = { MENU_ENUM_LABEL_VIDEO_VSYNC, MENU_ENUM_LABEL_VIDEO_SWAP_INTERVAL, MENU_ENUM_LABEL_VIDEO_SHADER_SUBFRAMES, MENU_ENUM_LABEL_VIDEO_SCAN_SUBFRAMES, MENU_ENUM_LABEL_VIDEO_BLACK_FRAME_INSERTION, MENU_ENUM_LABEL_VIDEO_BFI_DARK_FRAMES, MENU_ENUM_LABEL_VIDEO_ADAPTIVE_VSYNC, MENU_ENUM_LABEL_VIDEO_HARD_SYNC, MENU_ENUM_LABEL_VIDEO_HARD_SYNC_FRAMES, MENU_ENUM_LABEL_VIDEO_FRAME_DELAY_AUTO, MENU_ENUM_LABEL_VIDEO_FRAME_DELAY }; static const enum msg_hash_enums crtSwitchresSkip[] = { MENU_ENUM_LABEL_CRT_SWITCH_RESOLUTION_SUPER }; static const enum msg_hash_enums filterEntries[] = { MENU_ENUM_LABEL_VIDEO_FILTER_ENABLE, MENU_ENUM_LABEL_VIDEO_FILTER_THREADS, MENU_ENUM_LABEL_VIDEO_FILTER, #if defined(DINGUX) MENU_ENUM_LABEL_VIDEO_DINGUX_IPU_FILTER_TYPE, #if defined(RS90) || defined(MIYOO) MENU_ENUM_LABEL_VIDEO_DINGUX_RS90_SOFTFILTER_TYPE, #endif #endif }; hasCrtSwitchres = qt_list_has_entry(videoList, MENU_ENUM_LABEL_CRT_SWITCHRES_SETTINGS); #ifdef HAVE_TEMPORAL_UPSCALER /* Only built where it can be shown: an unshown, unparented group * would leak. */ SettingsGroup *dlssNrGroup = new SettingsGroup("DLSS Noise Reduction"); /* Do not gate this group on the runtime-dependent display list. The * menu list is rebuilt only after a full restart when the DLSS runtime * becomes available, while Qt can expose the settings immediately. */ dlssNrGroup->add(MENU_ENUM_LABEL_VIDEO_DLSS_NR_ENABLE); dlssNrGroup->add(MENU_ENUM_LABEL_VIDEO_DLSS_NR_PRESET); dlssNrGroup->add(MENU_ENUM_LABEL_VIDEO_DLSS_NR_STYLE); dlssNrGroup->add(MENU_ENUM_LABEL_VIDEO_DLSS_NR_INTENSITY); dlssNrGroup->add(MENU_ENUM_LABEL_VIDEO_DLSS_NR_LOCAL_STRUCTURE); dlssNrGroup->add(MENU_ENUM_LABEL_VIDEO_DLSS_NR_LOCAL_TONE); { rarch_setting_t *skinStructure = menu_setting_find_enum( MENU_ENUM_LABEL_VIDEO_DLSS_NR_SKIN_STRUCTURE); if (skinStructure) dlssNrGroup->addRow(form_label(skinStructure), new IntSpinBox(skinStructure)); } dlssNrGroup->add(MENU_ENUM_LABEL_VIDEO_DLSS_NR_AUTO_MASK); #endif qt_settings_group_add_displaylist(outputGroup, DISPLAYLIST_VIDEO_OUTPUT_SETTINGS_LIST, outputSkip, ARRAY_SIZE(outputSkip), NULL, 0); if (resolutionList) { for (i = 0; i < size; i++) { /* Format straight into the QString the combo keeps, instead of * a stack buffer that addItem() then copies and converts. */ m_resolutionCombo->addItem(QString::asprintf("%dx%d (%d Hz)", VIDEO_SCALE_W(resolutionList[i].dims), VIDEO_SCALE_H(resolutionList[i].dims), resolutionList[i].refreshrate)); if (resolutionList[i].current) m_resolutionCombo->setCurrentIndex((int)i); } free(resolutionList); } if (m_resolutionCombo->count() > 0) outputGroup->addRow(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_SCREEN_RESOLUTION), m_resolutionCombo); { rarch_setting_t *refreshAction = menu_setting_find_enum( MENU_ENUM_LABEL_VIDEO_REFRESH_RATE_POLLED); if (refreshAction) { char refreshText[64] = {0}; QPushButton *refreshButton = new QPushButton; if (refreshAction->actions && refreshAction->actions->repr) refreshAction->actions->repr(refreshAction, refreshText, sizeof(refreshText)); refreshButton->setText(QString::fromUtf8(refreshText)); QObject::connect(refreshButton, &QPushButton::clicked, [refreshAction, refreshButton]() { if (refreshAction->actions && refreshAction->actions->ok) refreshAction->actions->ok(refreshAction, 0, false); char value[64] = {0}; if (refreshAction->actions && refreshAction->actions->repr) refreshAction->actions->repr(refreshAction, value, sizeof(value)); refreshButton->setText(QString::fromUtf8(value)); }); outputGroup->addRow(msg_hash_to_str( MENU_ENUM_LABEL_VALUE_VIDEO_REFRESH_RATE_POLLED), refreshButton); } } qt_settings_group_add_displaylist(aspectGroup, DISPLAYLIST_VIDEO_SCALING_SETTINGS_LIST, scalingSkip, ARRAY_SIZE(scalingSkip), NULL, 0); aspectGroup->addRow(new AspectRatioGroup("Aspect Ratio")); qt_settings_group_add_displaylist(fullscreenGroup, DISPLAYLIST_VIDEO_FULLSCREEN_MODE_SETTINGS_LIST, fullscreenSkip, ARRAY_SIZE(fullscreenSkip), NULL, 0); leftFullscreenSizeForm->addRow("Width:", new UIntSpinBox(MENU_ENUM_LABEL_VIDEO_FULLSCREEN_X)); rightFullscreenSizeForm->addRow("Height:", new UIntSpinBox(MENU_ENUM_LABEL_VIDEO_FULLSCREEN_Y)); fullscreenSizeLayout->addLayout(leftFullscreenSizeForm); fullscreenSizeLayout->addLayout(rightFullscreenSizeForm); fullscreenGroup->addRow(fullscreenSizeLayout); qt_settings_group_add_displaylist(windowedGroup, DISPLAYLIST_VIDEO_WINDOWED_MODE_SETTINGS_LIST, windowedSkip, ARRAY_SIZE(windowedSkip), NULL, 0); leftWindowedSizeForm->addRow("Scale:", new UIntSpinBox(MENU_ENUM_LABEL_VIDEO_SCALE)); leftWindowedSizeForm->addRow("Max Width:", new UIntSpinBox(MENU_ENUM_LABEL_VIDEO_WINDOW_AUTO_WIDTH_MAX)); rightWindowedSizeForm->addRow("Opacity:", new UIntSpinBox(MENU_ENUM_LABEL_VIDEO_WINDOW_OPACITY)); rightWindowedSizeForm->addRow("Max Height:", new UIntSpinBox(MENU_ENUM_LABEL_VIDEO_WINDOW_AUTO_HEIGHT_MAX)); windowedSizeLayout->addLayout(leftWindowedSizeForm); windowedSizeLayout->addLayout(rightWindowedSizeForm); windowedGroup->addRow(windowedSizeLayout); leftWindowedCustomSizeForm->addRow("Width:", new UIntSpinBox(MENU_ENUM_LABEL_VIDEO_WINDOW_WIDTH)); rightWindowedCustomSizeForm->addRow("Height:", new UIntSpinBox(MENU_ENUM_LABEL_VIDEO_WINDOW_HEIGHT)); windowedCustomSizeLayout->addLayout(leftWindowedCustomSizeForm); windowedCustomSizeLayout->addLayout(rightWindowedCustomSizeForm); windowCustomSizeGroup->addRow(windowedCustomSizeLayout); windowedGroup->addRow(windowCustomSizeGroup); /* Keep the dependent VSync and hard-sync controls grouped with their * master switches. The remaining synchronization settings come from the * live menu display list. */ vSyncGroup->add(MENU_ENUM_LABEL_VIDEO_SWAP_INTERVAL); vSyncGroup->add(MENU_ENUM_LABEL_VIDEO_SHADER_SUBFRAMES); vSyncGroup->add(MENU_ENUM_LABEL_VIDEO_SCAN_SUBFRAMES); vSyncGroup->add(MENU_ENUM_LABEL_VIDEO_BLACK_FRAME_INSERTION); vSyncGroup->add(MENU_ENUM_LABEL_VIDEO_BFI_DARK_FRAMES); vSyncGroup->add(MENU_ENUM_LABEL_VIDEO_ADAPTIVE_VSYNC); vSyncGroup->add(MENU_ENUM_LABEL_VIDEO_FRAME_DELAY); vSyncGroup->add(MENU_ENUM_LABEL_VIDEO_FRAME_DELAY_AUTO); syncGroup->addRow(vSyncGroup); { rarch_setting_t *hardSyncSetting = menu_setting_find_enum(MENU_ENUM_LABEL_VIDEO_HARD_SYNC); if (hardSyncSetting) { CheckableSettingsGroup *hardSyncGroup = new CheckableSettingsGroup(hardSyncSetting); hardSyncGroup->add(MENU_ENUM_LABEL_VIDEO_HARD_SYNC_FRAMES); syncGroup->addRow(hardSyncGroup); } } qt_settings_group_add_displaylist(syncGroup, DISPLAYLIST_VIDEO_SYNCHRONIZATION_SETTINGS_LIST, syncSkip, ARRAY_SIZE(syncSkip), NULL, 0); qt_settings_group_add_displaylist(stereo3dGroup, DISPLAYLIST_VIDEO_STEREO_SETTINGS_LIST, NULL, 0, NULL, 0); qt_settings_group_add_list(miscGroup, videoList, filterEntries, ARRAY_SIZE(filterEntries), NULL, 0); leftColumn->addWidget(outputGroup); leftColumn->addWidget(windowedGroup); leftColumn->addWidget(fullscreenGroup); leftColumn->addWidget(syncGroup); rightColumn->addWidget(aspectGroup); #ifdef HAVE_TEMPORAL_UPSCALER if (dlssNrGroup->layout()->count() > 0) rightColumn->addWidget(dlssNrGroup); else delete dlssNrGroup; #endif if (video_driver_get_disp_flags() & VIDEO_FLAG_HDR_SUPPORT) { SettingsGroup *hdrGroup = new SettingsGroup("HDR"); qt_settings_group_add_displaylist(hdrGroup, DISPLAYLIST_VIDEO_HDR_SETTINGS_LIST, NULL, 0, NULL, 0); rightColumn->addWidget(hdrGroup); } if (hasCrtSwitchres) { SettingsGroup *crtSwitchresGroup = new SettingsGroup( msg_hash_to_str(MENU_ENUM_LABEL_VALUE_CRT_SWITCHRES_SETTINGS)); m_crtSuperResolutionCombo = new QComboBox; qt_settings_group_add_displaylist(crtSwitchresGroup, DISPLAYLIST_CRT_SWITCHRES_SETTINGS_LIST, crtSwitchresSkip, ARRAY_SIZE(crtSwitchresSkip), NULL, 0); m_crtSuperResolutionCombo->addItem(msg_hash_to_str(MSG_NATIVE), 0); m_crtSuperResolutionCombo->addItem("1920", 1920); m_crtSuperResolutionCombo->addItem("2560", 2560); m_crtSuperResolutionCombo->addItem("3840", 3840); crtSwitchresGroup->addRow( msg_hash_to_str(MENU_ENUM_LABEL_VALUE_CRT_SWITCH_RESOLUTION_SUPER), m_crtSuperResolutionCombo); #if (QT_VERSION > QT_VERSION_CHECK(6, 0, 0)) connect(m_crtSuperResolutionCombo, &QComboBox::currentIndexChanged, this, &VideoPage::onCrtSuperResolutionComboIndexChanged); #else connect(m_crtSuperResolutionCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(onCrtSuperResolutionComboIndexChanged(int))); #endif rightColumn->addWidget(crtSwitchresGroup); } rightColumn->addWidget(miscGroup); #if defined(HAVE_VIDEO_FILTER) || defined(DINGUX) { SettingsGroup *filterGroup = new SettingsGroup("Video Filter"); qt_settings_group_add_list(filterGroup, videoList, NULL, 0, filterEntries, ARRAY_SIZE(filterEntries)); rightColumn->addWidget(filterGroup); } #endif rightColumn->addWidget(stereo3dGroup); if (videoList) file_list_free(videoList); leftColumn->addStretch(); rightColumn->addStretch(); columnsLayout->addLayout(leftColumn, 1); columnsLayout->addLayout(rightColumn, 1); layout->addLayout(columnsLayout); layout->addStretch(); #if (QT_VERSION > QT_VERSION_CHECK(6, 0, 0)) void (VideoPage::*cb)(int) = &VideoPage::onResolutionComboIndexChanged; connect(m_resolutionCombo, &QComboBox::currentIndexChanged, this, cb); #else connect(m_resolutionCombo, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(onResolutionComboIndexChanged(const QString&))); #endif widget->setLayout(layout); return widget; } AspectRatioGroup::AspectRatioGroup(const QString &title, QWidget *parent) : SettingsGroup(title, parent) ,m_radioButton(new AspectRatioRadioButton(ASPECT_RATIO_4_3, ASPECT_RATIO_32_9)) ,m_comboBox(new UIntComboBox(MENU_ENUM_LABEL_VIDEO_ASPECT_RATIO_INDEX, ASPECT_RATIO_4_3, ASPECT_RATIO_32_9)) { QHBoxLayout *aspectLayout = new QHBoxLayout; QHBoxLayout *preset = new QHBoxLayout; QHBoxLayout *custom = new QHBoxLayout; QVBoxLayout *customRadio = new QVBoxLayout; QHBoxLayout *config = new QHBoxLayout; QHBoxLayout *full = new QHBoxLayout; QHBoxLayout *aspectL = new QHBoxLayout; FormLayout *leftAspectForm = new FormLayout; FormLayout *rightAspectForm = new FormLayout; FormLayout *leftAspect = new FormLayout; FormLayout *rightAspect = new FormLayout; leftAspectForm->addRow("X Pos.:", new UIntSpinBox(MENU_ENUM_LABEL_VIDEO_VIEWPORT_CUSTOM_X)); leftAspectForm->addRow("Width:", new UIntSpinBox(MENU_ENUM_LABEL_VIDEO_VIEWPORT_CUSTOM_WIDTH)); rightAspectForm->addRow("Y Pos.:", new UIntSpinBox(MENU_ENUM_LABEL_VIDEO_VIEWPORT_CUSTOM_Y)); rightAspectForm->addRow("Height:", new UIntSpinBox(MENU_ENUM_LABEL_VIDEO_VIEWPORT_CUSTOM_HEIGHT)); aspectLayout->addLayout(leftAspectForm); aspectLayout->addLayout(rightAspectForm); preset->addWidget(m_radioButton); preset->addWidget(m_comboBox); preset->setStretch(1, 1); customRadio->addWidget(new UIntRadioButton(MENU_ENUM_LABEL_VIDEO_ASPECT_RATIO_INDEX, ASPECT_RATIO_CUSTOM), Qt::AlignTop); customRadio->addStretch(); custom->addLayout(customRadio); custom->addLayout(aspectLayout); custom->addStretch(); config->addWidget(new UIntRadioButton(MENU_ENUM_LABEL_VIDEO_ASPECT_RATIO_INDEX, ASPECT_RATIO_CONFIG)); config->addWidget(new FloatSpinBox(MENU_ENUM_LABEL_VIDEO_ASPECT_RATIO)); config->setStretch(1, 1); config->setSizeConstraint(QLayout::SetMinimumSize); full->addWidget(new UIntRadioButton(MENU_ENUM_LABEL_VIDEO_ASPECT_RATIO_INDEX, ASPECT_RATIO_FULL)); leftAspect->addRow(new UIntRadioButton(MENU_ENUM_LABEL_VIDEO_ASPECT_RATIO_INDEX, ASPECT_RATIO_CORE)); leftAspect->addRow(preset); rightAspect->addRow(config); rightAspect->addRow(new UIntRadioButton(MENU_ENUM_LABEL_VIDEO_ASPECT_RATIO_INDEX, ASPECT_RATIO_SQUARE)); aspectL->addLayout(leftAspect); aspectL->addStretch(); aspectL->addSpacing(30); aspectL->addLayout(rightAspect); addRow(aspectL); addRow(full); addRow(custom); connect(m_radioButton, SIGNAL(clicked(bool)), this, SLOT(onAspectRadioClicked(bool))); } void AspectRatioGroup::paintEvent(QPaintEvent *event) { settings_t *settings = config_get_ptr(); unsigned value = settings->uints.video_aspect_ratio_idx; if (ASPECT_RATIO_4_3 >= value || value <= ASPECT_RATIO_32_9) { m_comboBox->blockSignals(false); m_radioButton->setChecked(true); } else m_comboBox->blockSignals(true); SettingsGroup::paintEvent(event); } void AspectRatioGroup::onAspectRadioToggled(bool checked) { if (checked) m_comboBox->currentIndexChanged(m_comboBox->currentIndex()); else m_comboBox->blockSignals(true); } void AspectRatioGroup::onAspectRadioClicked(bool checked) { m_comboBox->blockSignals(false); m_comboBox->currentIndexChanged(m_comboBox->currentIndex()); setChecked(true); } void VideoPage::onCrtSuperResolutionComboIndexChanged(int index) { settings_t *settings = config_get_ptr(); (void)(index); if (m_crtSuperResolutionCombo) settings->uints.crt_switch_resolution_super = m_crtSuperResolutionCombo->currentData().value(); } void VideoPage::onResolutionComboIndexChanged(const QString &text) { const char *path = text.toUtf8().constData(); action_cb_push_dropdown_item_resolution(path, NULL, 0, 0, 0); } void VideoPage::onResolutionComboIndexChanged(int index) { const QString& text = m_resolutionCombo->itemText(index); const char *path = text.toUtf8().constData(); action_cb_push_dropdown_item_resolution(path, NULL, 0, 0, 0); } AspectRatioRadioButton::AspectRatioRadioButton(unsigned min, unsigned max, QWidget *parent) : QRadioButton(parent) ,m_min(min) ,m_max(max) { } /* DRIVERS */ DriversPage::DriversPage(QObject *parent) : OptionsPage(parent) { } QWidget *DriversPage::widget() { QWidget *widget = new QWidget; QVBoxLayout *layout = new QVBoxLayout; QHBoxLayout *contentLayout = new QHBoxLayout; QVBoxLayout *leftColumn = new QVBoxLayout; SettingsGroup *graphicsGroup = new SettingsGroup("Graphics & Menu"); SettingsGroup *inputGroup = new SettingsGroup("Input"); SettingsGroup *audioGroup = new SettingsGroup("Audio"); SettingsGroup *otherGroup = new SettingsGroup("Other Devices"); static const enum msg_hash_enums graphicsEntries[] = { MENU_ENUM_LABEL_MENU_DRIVER, MENU_ENUM_LABEL_VIDEO_DRIVER, #if defined(HAVE_RSLC) && defined(HAVE_GLSLANG) MENU_ENUM_LABEL_VIDEO_SHADER_COMPILER #endif }; static const enum msg_hash_enums inputEntries[] = { MENU_ENUM_LABEL_INPUT_DRIVER, MENU_ENUM_LABEL_JOYPAD_DRIVER }; static const enum msg_hash_enums audioEntries[] = { MENU_ENUM_LABEL_AUDIO_DRIVER, #ifdef HAVE_MICROPHONE MENU_ENUM_LABEL_MICROPHONE_DRIVER, #endif MENU_ENUM_LABEL_MIDI_DRIVER }; static const enum msg_hash_enums otherEntries[] = { MENU_ENUM_LABEL_RECORD_DRIVER, #ifdef HAVE_COMPANION_WIMP MENU_ENUM_LABEL_UI_COMPANION_DRIVER, #endif #ifdef HAVE_BLUETOOTH MENU_ENUM_LABEL_BLUETOOTH_DRIVER, #endif #if defined(HAVE_LAKKA) || defined(HAVE_WIFI) MENU_ENUM_LABEL_WIFI_DRIVER, #endif MENU_ENUM_LABEL_CAMERA_DRIVER, MENU_ENUM_LABEL_LOCATION_DRIVER }; file_list_t *driverList = qt_displaylist_build( DISPLAYLIST_DRIVER_SETTINGS_LIST); qt_settings_group_add_list(graphicsGroup, driverList, NULL, 0, graphicsEntries, ARRAY_SIZE(graphicsEntries)); qt_settings_group_add_list(inputGroup, driverList, NULL, 0, inputEntries, ARRAY_SIZE(inputEntries)); qt_settings_group_add_list(audioGroup, driverList, NULL, 0, audioEntries, ARRAY_SIZE(audioEntries)); qt_settings_group_add_list(otherGroup, driverList, NULL, 0, otherEntries, ARRAY_SIZE(otherEntries)); if (driverList) file_list_free(driverList); leftColumn->addWidget(graphicsGroup); leftColumn->addWidget(inputGroup); leftColumn->addWidget(audioGroup); leftColumn->addWidget(otherGroup); leftColumn->addStretch(); contentLayout->addLayout(leftColumn, 1); contentLayout->addStretch(1); layout->addLayout(contentLayout); layout->addStretch(); widget->setLayout(layout); return widget; } DriversCategory::DriversCategory(QWidget *parent) : OptionsCategory(parent) { setDisplayName(MENU_ENUM_LABEL_VALUE_DRIVER_SETTINGS); setCategoryIcon("menu_drivers"); } QVector DriversCategory::pages() { QVector pages; pages << new DriversPage(this); return pages; } /* DIRECTORY */ DirectoryCategory::DirectoryCategory(QWidget *parent) : OptionsCategory(parent) { setDisplayName(MENU_ENUM_LABEL_VALUE_DIRECTORY_SETTINGS); setCategoryIcon("folder"); } QVector DirectoryCategory::pages() { QVector pages; pages << new SimplePage(DISPLAYLIST_DIRECTORY_SETTINGS_LIST, this); return pages; } /* CONFIGURATION */ ConfigurationCategory::ConfigurationCategory(QWidget *parent) : OptionsCategory(parent) { setDisplayName(MENU_ENUM_LABEL_VALUE_CONFIGURATION_SETTINGS); setCategoryIcon("setting"); } QVector ConfigurationCategory::pages() { QVector pages; pages << new SimplePage(DISPLAYLIST_CONFIGURATION_SETTINGS_LIST, this); return pages; } /* CORE */ CoreCategory::CoreCategory(QWidget *parent) : OptionsCategory(parent) { setDisplayName(MENU_ENUM_LABEL_VALUE_CORE_SETTINGS); setCategoryIcon("core-options"); } QVector CoreCategory::pages() { QVector pages; pages << new SimplePage(DISPLAYLIST_CORE_SETTINGS_LIST, this); return pages; } /* LOGGING */ class QtDisplayListGroupPage : public OptionsPage { public: QtDisplayListGroupPage(enum menu_displaylist_ctl_state state, const QString &title, QObject *parent = 0, enum menu_displaylist_ctl_state secondState = DISPLAYLIST_NONE, const QString &secondTitle = QString(), enum menu_displaylist_ctl_state thirdState = DISPLAYLIST_NONE, const QString &thirdTitle = QString()) : OptionsPage(parent), m_state(state), m_title(title), m_secondState(secondState), m_secondTitle(secondTitle), m_thirdState(thirdState), m_thirdTitle(thirdTitle) { setDisplayName(title); } QWidget *widget() { QWidget *page = new QWidget; QHBoxLayout *columns = new QHBoxLayout; QVBoxLayout *left = new QVBoxLayout; SettingsGroup *first = new SettingsGroup(m_title); qt_settings_group_add_displaylist(first, m_state, NULL, 0, NULL, 0); left->addWidget(first); if (m_secondState != DISPLAYLIST_NONE) { SettingsGroup *second = new SettingsGroup(m_secondTitle); qt_settings_group_add_displaylist(second, m_secondState, NULL, 0, NULL, 0); left->addWidget(second); } if (m_thirdState != DISPLAYLIST_NONE) { SettingsGroup *third = new SettingsGroup(m_thirdTitle); qt_settings_group_add_displaylist(third, m_thirdState, NULL, 0, NULL, 0); left->addWidget(third); } left->addStretch(); columns->addLayout(left, 1); columns->addStretch(1); page->setLayout(columns); return page; } private: enum menu_displaylist_ctl_state m_state; QString m_title; enum menu_displaylist_ctl_state m_secondState; QString m_secondTitle; enum menu_displaylist_ctl_state m_thirdState; QString m_thirdTitle; }; LoggingCategory::LoggingCategory(QWidget *parent) : OptionsCategory(parent) { setDisplayName(MENU_ENUM_LABEL_VALUE_LOGGING_SETTINGS); setCategoryIcon("menu_log"); } QVector LoggingCategory::pages() { QVector pages; pages << new QtDisplayListGroupPage(DISPLAYLIST_LOGGING_SETTINGS_LIST, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_LOGGING_SETTINGS), this); return pages; } /* AI SERVICE */ AIServiceCategory::AIServiceCategory(QWidget *parent) : OptionsCategory(parent) { setDisplayName(MENU_ENUM_LABEL_VALUE_AI_SERVICE_SETTINGS); setCategoryIcon("menu_drivers"); } QVector AIServiceCategory::pages() { QVector pages; pages << new SimplePage(DISPLAYLIST_AI_SERVICE_SETTINGS_LIST, MENU_ENUM_LABEL_VALUE_AI_SERVICE_SETTINGS, this); return pages; } /* FRAME THROTTLE */ FrameThrottleCategory::FrameThrottleCategory(QWidget *parent) : OptionsCategory(parent) { setDisplayName(MENU_ENUM_LABEL_VALUE_FRAME_THROTTLE_SETTINGS); setCategoryIcon("menu_frameskip"); } QVector FrameThrottleCategory::pages() { QVector pages; pages << new QtDisplayListGroupPage(DISPLAYLIST_FRAME_THROTTLE_SETTINGS_LIST, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_FRAME_THROTTLE_SETTINGS), this, DISPLAYLIST_REWIND_SETTINGS_LIST, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_REWIND_SETTINGS), DISPLAYLIST_FRAME_TIME_COUNTER_SETTINGS_LIST, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_FRAME_TIME_COUNTER_SETTINGS)); return pages; } #endif /* HAVE_MENU - OptionsCategory/OptionsPage implementations */ PlaylistModel::PlaylistModel(QObject *parent) : QAbstractListModel(parent) { /* The shared companion thumbnail engine: threads sized to the * machine, cache budget from the view options. */ m_engine = companion_thumbs_new(0, 0); setThumbnailCacheLimit(500); /* Finished decodes are collected on the UI thread from a timer that * only runs while something is pending. */ m_pollTimer.setInterval(16); connect(&m_pollTimer, SIGNAL(timeout()), this, SLOT(pollThumbnails())); } PlaylistModel::~PlaylistModel() { if (m_engine) companion_thumbs_free(m_engine); /* joins the decode threads */ } int PlaylistModel::rowCount(const QModelIndex & /* parent */) const { return m_contents.count(); } int PlaylistModel::columnCount(const QModelIndex & /* parent */) const { return 1; } QVariant PlaylistModel::data(const QModelIndex &index, int role) const { if (index.column() == 0) { if (!index.isValid() || index.row() >= m_contents.size() || index.row() < 0) return QVariant(); switch (role) { case Qt::DisplayRole: case Qt::EditRole: case Qt::ToolTipRole: return m_contents.at(index.row()).labelNoExt; case ENTRY: return QVariant::fromValue(m_contents.at(index.row())); case THUMBNAIL: { /* The engine's pixels for this row at the grid's size, * converted to a QPixmap once and kept in m_cache. */ QPixmap *pm = pixmapFor(getCurrentTypeThumbnailPath(index), VIDEO_SCALE_PACK(m_thumbSize, m_thumbSize)); if (pm) return *pm; } break; } } return QVariant(); } Qt::ItemFlags PlaylistModel::flags(const QModelIndex &index) const { if (!index.isValid()) return Qt::ItemIsEnabled; return QAbstractListModel::flags(index) | Qt::ItemIsEditable; } bool PlaylistModel::setData(const QModelIndex &index, const QVariant &value, int role) { if (index.isValid() && role == Qt::EditRole) { PlaylistEntry rowEntry = m_contents.at(index.row()); rowEntry.label = value.toString(); rowEntry.labelNoExt = QFileInfo(value.toString()).completeBaseName(); m_contents.replace(index.row(), rowEntry); emit dataChanged(index, index, { role }); return true; } return false; } QVariant PlaylistModel::headerData(int section, Qt::Orientation orientation, int role) const { if (role != Qt::DisplayRole) return QVariant(); if (orientation == Qt::Horizontal) return msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_NAME); return section + 1; } void PlaylistModel::setThumbnailType(const ThumbnailType type) { m_thumbnailType = type; } void PlaylistModel::setThumbnailCacheLimit(int limit) { /* The setting is in MB: the engine holds the decoded pixels under * that budget; the QPixmap conversion cache mirrors it in KB. */ if (m_engine) companion_thumbs_set_budget(m_engine, (size_t)(limit > 0 ? limit : 64) * 1024 * 1024); m_cache.setMaxCost(limit * 1024); } void PlaylistModel::setThumbnailSize(int size) { if (size < 16) size = 16; if (size == m_thumbSize) return; m_thumbSize = size; /* Pixmaps at the old size are keyed by it and simply age out; what * was queued at the old size is dropped. */ if (m_engine) companion_thumbs_cancel(m_engine); m_pendingRows.clear(); } QString PlaylistModel::getThumbnailPath(const QModelIndex &index, QString type) const { return getThumbnailPath(m_contents.at(index.row()), type); } /* Thumbnail layout, name sanitising and extension probing live in the * companion core; these are the Qt string wrappers. */ QString PlaylistModel::getPlaylistThumbnailsDir( const QString playlistName, const QString type) const { char dir[PATH_MAX_LENGTH]; QByteArray dbArray = playlistName.toUtf8(); QByteArray typeArray = type.toUtf8(); companion_core_thumbnail_dir(ui_companion_qt_core(), dbArray.constData(), typeArray.constData(), dir, sizeof(dir)); return QString::fromUtf8(dir); } bool PlaylistModel::isSupportedImage(const QString path) const { QByteArray pathArray = path.toUtf8(); return image_texture_get_type(pathArray.constData()) != IMAGE_TYPE_NONE; } QString PlaylistModel::getRepositoryThumbnailPath(const QString playlistName, const QString labelNoExt, const QString type) const { char path[PATH_MAX_LENGTH]; QByteArray dbArray = playlistName.toUtf8(); QByteArray typeArray = type.toUtf8(); QByteArray labelArray = labelNoExt.toUtf8(); companion_core_thumbnail_path(ui_companion_qt_core(), dbArray.constData(), typeArray.constData(), labelArray.constData(), NULL, path, sizeof(path)); return QString::fromUtf8(path); } QString PlaylistModel::getThumbnailPath(const PlaylistEntry &entry, QString type) const { char path[PATH_MAX_LENGTH]; QByteArray dbArray = entry.dbName.toUtf8(); QByteArray typeArray = type.toUtf8(); QByteArray labelArray = entry.labelNoExt.toUtf8(); QByteArray pathArray = entry.path.toUtf8(); companion_core_thumbnail_path(ui_companion_qt_core(), dbArray.constData(), typeArray.constData(), labelArray.constData(), pathArray.constData(), path, sizeof(path)); return QString::fromUtf8(path); } QString PlaylistModel::getCurrentTypeThumbnailPath(const QModelIndex &index) const { switch (m_thumbnailType) { case THUMBNAIL_TYPE_BOXART: return getThumbnailPath(index, THUMBNAIL_BOXART); case THUMBNAIL_TYPE_SCREENSHOT: return getThumbnailPath(index, THUMBNAIL_SCREENSHOT); case THUMBNAIL_TYPE_TITLE_SCREEN: return getThumbnailPath(index, THUMBNAIL_TITLE); case THUMBNAIL_TYPE_LOGO: return getThumbnailPath(index, THUMBNAIL_LOGO); default: break; } return QString(); } void PlaylistModel::reloadThumbnail(const QModelIndex &index) { if (index.isValid()) { reloadThumbnailPath(getCurrentTypeThumbnailPath(index)); loadThumbnail(index); } } void PlaylistModel::reloadSystemThumbnails(const QString system) { int i = 0; settings_t *settings = config_get_ptr(); const char *path_dir_thumbnails = settings->paths.directory_thumbnails; QString path = QDir::cleanPath(QString(path_dir_thumbnails)) + QString("/") + system; QList keys = m_cache.keys(); for (i = 0; i < keys.size(); i++) { QString key = keys.at(i); if (key.startsWith(path)) { m_cache.remove(key); if (m_engine) companion_thumbs_forget(m_engine, key.left(key.lastIndexOf(QLatin1Char('@'))).toUtf8().constData()); } } } void PlaylistModel::reloadThumbnailPath(const QString path) { QList keys = m_cache.keys(); int i; for (i = 0; i < keys.size(); i++) if (keys.at(i).startsWith(path + QLatin1Char('@'))) m_cache.remove(keys.at(i)); if (m_engine) companion_thumbs_forget(m_engine, path.toUtf8().constData()); m_pendingRows.remove(path); } void PlaylistModel::loadThumbnail(const QModelIndex &index) { QString path = getCurrentTypeThumbnailPath(index); if (!m_engine || path.isEmpty()) return; if (companion_thumbs_get(m_engine, path.toUtf8().constData(), VIDEO_SCALE_PACK(m_thumbSize, m_thumbSize))) return; /* data() serves it from the cache */ if (m_pendingRows.contains(path)) return; m_pendingRows.insert(path, QPersistentModelIndex(index)); companion_thumbs_request(m_engine, path.toUtf8().constData(), VIDEO_SCALE_PACK(m_thumbSize, m_thumbSize), 0, true, 0x00000000u); if (!m_pollTimer.isActive()) m_pollTimer.start(); } #define QT_TAG_ANIM_FRAME ((uintptr_t)1 << (sizeof(uintptr_t) * 8 - 1)) void PlaylistModel::onEngineDone(void *ud, const char *path, unsigned dims, uintptr_t tag, const uint32_t *bits) { PlaylistModel *self = static_cast(ud); if (tag & QT_TAG_ANIM_FRAME) { /* An animation frame: not cached, shown at once. fromImage() * copies into the pixmap, so wrap the engine's buffer directly * rather than copying it once more first. */ if (bits) { int w = (int)VIDEO_SCALE_W(dims); QImage img((const uchar*)bits, w, (int)VIDEO_SCALE_H(dims), w * 4, QImage::Format_ARGB32); emit self->frameReady(QString::fromUtf8(path), QPixmap::fromImage(img)); } return; } self->thumbnailArrived(QString::fromUtf8(path)); } void PlaylistModel::animateImage(const QString &path, unsigned dims) { if ( !m_engine || path.isEmpty() || !VIDEO_SCALE_W(dims) || !VIDEO_SCALE_H(dims)) return; companion_thumbs_animate(m_engine, path.toUtf8().constData(), dims, QT_TAG_ANIM_FRAME, 0x00000000u); if (!m_pollTimer.isActive()) m_pollTimer.start(); } void PlaylistModel::stopAnimation() { if (m_engine) companion_thumbs_animate_stop(m_engine); } QPixmap *PlaylistModel::pixmapFor(const QString &path, unsigned dims) const { int w = (int)VIDEO_SCALE_W(dims); int h = (int)VIDEO_SCALE_H(dims); QString key = path + QLatin1Char('@') + QString::number(w) + QLatin1Char('x') + QString::number(h); QPixmap *pm = m_cache.object(key); const uint32_t *bits; if (pm) return pm; if (!m_engine || path.isEmpty()) return NULL; bits = companion_thumbs_get(m_engine, path.toUtf8().constData(), dims); if (!bits) return NULL; { /* copy(): the engine pointer is only valid until its next call */ QImage img((const uchar*)bits, w, h, w * 4, QImage::Format_ARGB32); int cost; pm = new QPixmap(QPixmap::fromImage(img.copy())); cost = pm->width() * pm->height() * pm->depth() / (8 * 1024); if (m_cache.maxCost() > 0 && cost > m_cache.maxCost()) cost = m_cache.maxCost(); m_cache.insert(key, pm, cost); } return pm; } bool PlaylistModel::imageAt(const QString &path, unsigned dims, QPixmap *out) const { QPixmap *pm = pixmapFor(path, dims); if (!pm) return false; if (out) *out = *pm; return true; } void PlaylistModel::abandonPending() { if (m_engine) companion_thumbs_cancel(m_engine); m_pendingRows.clear(); } void PlaylistModel::requestImage(const QString &path, unsigned dims) { if ( !m_engine || path.isEmpty() || !VIDEO_SCALE_W(dims) || !VIDEO_SCALE_H(dims)) return; companion_thumbs_request(m_engine, path.toUtf8().constData(), dims, 0, true, 0x00000000u); if (!m_pollTimer.isActive()) m_pollTimer.start(); } void PlaylistModel::thumbnailArrived(const QString &path) { QPersistentModelIndex index = m_pendingRows.take(path); emit thumbnailReady(path); /* index is persistent: it tracks the row across insertions / moves * and is invalid if that row was removed or the model reset while * the decode was in flight, so a stale row is never signalled. */ if (index.isValid()) { const QModelIndex modelIndex(index); emit dataChanged(modelIndex, modelIndex, { THUMBNAIL }); } } void PlaylistModel::pollThumbnails() { if (!m_engine) return; companion_thumbs_poll(m_engine, onEngineDone, this, 0, 4000); if (!companion_thumbs_pending(m_engine) && !companion_thumbs_animating(m_engine)) m_pollTimer.stop(); } static inline bool comp_hash_name_key_lower(const QHash &lhs, const QHash &rhs) { return lhs.value("name").toLower() < rhs.value("name").toLower(); } bool MainWindow::addDirectoryFilesToList(QProgressDialog *dialog, QStringList &list, QDir &dir, QStringList &extensions) { int i; PlaylistEntryDialog *playlistDialog = playlistEntryDialog(); QStringList dirList = dir.entryList(QStringList(), QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot | QDir::Hidden | QDir::System, QDir::Name); for (i = 0; i < dirList.count(); i++) { QString path(dir.path() + QString("/") + dirList.at(i)); QByteArray pathArray = path.toUtf8(); QFileInfo fileInfo(path); const char *pathData = pathArray.constData(); if (dialog->wasCanceled()) return false; /* Needed to update progress dialog while doing * a lot of stuff on the main thread. */ if (i % 25 == 0) qApp->processEvents(); if (fileInfo.isDir()) { QDir fileInfoDir(path); if (!addDirectoryFilesToList( dialog, list, fileInfoDir, extensions)) return false; continue; } if (fileInfo.isFile()) { bool add = false; if (extensions.isEmpty()) add = true; else { if (extensions.contains(fileInfo.suffix())) add = true; else { if (path_is_compressed_file(pathData)) { struct string_list *archive_list = file_archive_get_file_list(pathData, NULL); if (archive_list) { if (archive_list->size == 1) { /* Assume archives with one file should have * that file loaded directly. * Don't just extend this to add all files * in a ZIP, because we might hit something like * MAME/FBA where only the archives themselves * Only append inner file reference if filter * inside archives is enabled */ if (playlistDialog->filterInArchive()) { pathArray = (QString(pathData) + QString("#") + archive_list->elems[0].data).toUtf8(); pathData = pathArray.constData(); } if (!extensions.isEmpty() && playlistDialog->filterInArchive()) { /* If the user chose to filter extensions * inside archives, and this particular file * inside the archive * doesn't have one of the chosen extensions, * then we skip it. */ if (extensions.contains( QString::fromUtf8(path_get_extension(pathData)))) add = true; } { /* If the user chose to filter extensions * inside archives, and this particular file * inside the archive * doesn't have one of the chosen extensions, * then we skip it. */ if (extensions.contains( QString::fromUtf8(path_get_extension(pathData)))) add = true; } } string_list_free(archive_list); } } } } if (add) list.append(fileInfo.absoluteFilePath()); } } return true; } void MainWindow::onPlaylistFilesDropped(QStringList files) { addFilesToPlaylist(files); } /* Takes a list of files and folders and adds them to the * currently selected playlist. Folders will have their * contents added recursively. */ void MainWindow::addFilesToPlaylist(QStringList files) { int i; QStringList list; QString currentPlaylistPath; QByteArray currentPlaylistArray; QScopedPointer dialog(NULL); QHash selectedCore; PlaylistEntry itemToAdd; QString selectedDatabase; QString selectedName; QString selectedPath; QStringList selectedExtensions; QListWidgetItem *currentItem = m_listWidget->currentItem(); PlaylistEntryDialog *playlistDialog = playlistEntryDialog(); const char *currentPlaylistData = NULL; playlist_t *playlist = NULL; companion_core_t *core = ui_companion_qt_core(); /* Assume a blank list means we will manually enter in all fields. */ if (files.isEmpty()) { /* Leave fields default-empty: the dialog will offer the * "Multiple" placeholder when it sees an empty path. */ } else if (files.count() == 1) { QString path = files.at(0); QFileInfo info(path); if (info.isFile()) { itemToAdd.label = info.completeBaseName(); itemToAdd.path = path; } } if (currentItem) { currentPlaylistPath = currentItem->data(Qt::UserRole).toString(); if (!currentPlaylistPath.isEmpty()) { currentPlaylistArray = currentPlaylistPath.toUtf8(); currentPlaylistData = currentPlaylistArray.constData(); } } if (currentPlaylistPath == ALL_PLAYLISTS_TOKEN) { showMessageBox(msg_hash_to_str( MENU_ENUM_LABEL_VALUE_QT_CANNOT_ADD_TO_ALL_PLAYLISTS), MainWindow::MSGBOX_TYPE_ERROR, Qt::ApplicationModal, false); return; } /* a blank itemToAdd means there will be multiple */ if (!playlistDialog->showDialog(itemToAdd)) return; selectedName = m_playlistEntryDialog->getSelectedName(); selectedPath = m_playlistEntryDialog->getSelectedPath(); selectedCore = m_playlistEntryDialog->getSelectedCore(); selectedDatabase = m_playlistEntryDialog->getSelectedDatabase(); selectedExtensions = m_playlistEntryDialog->getSelectedExtensions(); if (!selectedExtensions.isEmpty()) selectedExtensions.replaceInStrings(QRegularExpression("^\\."), ""); if (selectedDatabase.isEmpty()) selectedDatabase = QFileInfo(currentPlaylistPath).fileName(); else selectedDatabase.append(".lpl"); dialog.reset(new QProgressDialog(msg_hash_to_str( MENU_ENUM_LABEL_VALUE_QT_GATHERING_LIST_OF_FILES), "Cancel", 0, 0, this)); dialog->setWindowModality(Qt::ApplicationModal); dialog->show(); qApp->processEvents(); if ( selectedName.isEmpty() || selectedPath.isEmpty() || selectedDatabase.isEmpty()) { showMessageBox(msg_hash_to_str( MENU_ENUM_LABEL_VALUE_QT_PLEASE_FILL_OUT_REQUIRED_FIELDS), MainWindow::MSGBOX_TYPE_ERROR, Qt::ApplicationModal, false); return; } if (files.isEmpty()) files.append(selectedPath); for (i = 0; i < files.count(); i++) { QString path(files.at(i)); QFileInfo fileInfo(path); if (dialog->wasCanceled()) return; /* Needed to update progress dialog while * doing a lot of stuff on the main thread. */ if (i % 25 == 0) qApp->processEvents(); if (fileInfo.isDir()) { QDir dir(path); if (!addDirectoryFilesToList( dialog.data(), list, dir, selectedExtensions)) return; continue; } if (fileInfo.isFile()) { bool add = false; if (selectedExtensions.isEmpty()) add = true; else { QByteArray pathArray = path.toUtf8(); const char *pathData = pathArray.constData(); if (selectedExtensions.contains(fileInfo.suffix())) add = true; else if (playlistDialog->filterInArchive() && path_is_compressed_file(pathData)) { /* We'll add it here, but really just delay * the check until later when the archive * contents are iterated. */ add = true; } } if (add) list.append(fileInfo.absoluteFilePath()); } else if (files.count() == 1) { /* If adding a single file, tell user that it doesn't exist. */ showMessageBox(msg_hash_to_str( MENU_ENUM_LABEL_VALUE_QT_FILE_DOES_NOT_EXIST), MainWindow::MSGBOX_TYPE_ERROR, Qt::ApplicationModal, false); return; } } dialog->setLabelText(msg_hash_to_str( MENU_ENUM_LABEL_VALUE_QT_ADDING_FILES_TO_PLAYLIST)); dialog->setMaximum(list.count()); /* Deliberately a private instance (unlike the other playlist * loads here): this is a bulk add whose cancel path discards * the half-modified playlist by freeing it unwritten, which a * borrowed cached instance cannot offer. The modal progress * dialog pumps events, so this is not a UI-thread freeze. */ playlist = companion_core_playlist_open_private(core, currentPlaylistData); if (!playlist) return; for (i = 0; i < list.count(); i++) { QFileInfo fileInfo; QByteArray fileBaseNameArray; QByteArray pathArray; QByteArray corePathArray; QByteArray coreNameArray; QByteArray databaseArray; char contentPath[PATH_MAX_LENGTH]; QString fileName = list.at(i); const char *pathData = NULL; const char *fileNameNoExten = NULL; const char *corePathData = NULL; const char *coreNameData = NULL; const char *databaseData = NULL; /* Cancel out of everything, the * current progress will not be written * to the playlist at all. */ if (dialog->wasCanceled()) { companion_core_playlist_release(core, playlist, true, false); return; } if (fileName.isEmpty()) continue; /* a modal QProgressDialog calls processEvents() * automatically in setValue() */ dialog->setValue(i + 1); fileInfo = QFileInfo(fileName); /* Make sure we're looking at a user-specified field * and not just "" * in case it was a folder with one file in it */ if ( files.count() == 1 && list.count() == 1 && i == 0 && playlistDialog->nameFieldEnabled()) { fileBaseNameArray = selectedName.toUtf8(); pathArray = QDir::toNativeSeparators(selectedPath).toUtf8(); } /* Otherwise just use the file name itself (minus extension) * for the playlist entry title */ else { fileBaseNameArray = fileInfo.completeBaseName().toUtf8(); pathArray = QDir::toNativeSeparators(fileName).toUtf8(); } fileNameNoExten = fileBaseNameArray.constData(); pathData = pathArray.constData(); if (!selectedCore.isEmpty()) { corePathArray = QDir::toNativeSeparators( selectedCore.value("core_path")).toUtf8(); coreNameArray = selectedCore.value("core_name").toUtf8(); corePathData = corePathArray.constData(); coreNameData = coreNameArray.constData(); } /* else NULL: the core substitutes "DETECT" */ databaseArray = selectedDatabase.toUtf8(); databaseData = databaseArray.constData(); /* A single-file archive resolves to "archive#file". */ companion_core_resolve_content_path(core, pathData, contentPath, sizeof(contentPath)); /* If the user chose to filter extensions inside archives, and * the resolved file inside the archive doesn't have one of the * chosen extensions, skip it. */ if ( strcmp(contentPath, pathData) != 0 && !selectedExtensions.isEmpty() && playlistDialog->filterInArchive() && !selectedExtensions.contains( QString::fromUtf8(path_get_extension(contentPath)))) continue; companion_core_playlist_push(core, playlist, contentPath, fileNameNoExten, corePathData, coreNameData, databaseData); } companion_core_playlist_release(core, playlist, true, true); reloadPlaylists(); } bool MainWindow::updateCurrentPlaylistEntry( const PlaylistEntry &contentEntry) { QByteArray playlistPathArray; QByteArray pathArray; QByteArray labelArray; QByteArray corePathArray; QByteArray coreNameArray; QByteArray dbNameArray; QByteArray crc32Array; char contentPath[PATH_MAX_LENGTH]; QString playlistPath = getCurrentPlaylistPath(); const char *playlistPathData = NULL; const char *pathData = NULL; const char *labelData = NULL; const char *corePathData = NULL; const char *coreNameData = NULL; const char *dbNameData = NULL; const char *crc32Data = NULL; if ( playlistPath.isEmpty() || contentEntry.path.isEmpty() || contentEntry.label.isEmpty() || contentEntry.coreName.isEmpty() || contentEntry.corePath.isEmpty()) return false; playlistPathArray = playlistPath.toUtf8(); pathArray = QDir::toNativeSeparators(contentEntry.path).toUtf8(); labelArray = contentEntry.label.toUtf8(); coreNameArray = contentEntry.coreName.toUtf8(); corePathArray = QDir::toNativeSeparators(contentEntry.corePath).toUtf8(); if (!contentEntry.dbName.isEmpty()) { dbNameArray = (contentEntry.dbName + ".lpl").toUtf8(); dbNameData = dbNameArray.constData(); } playlistPathData = playlistPathArray.constData(); pathData = pathArray.constData(); labelData = labelArray.constData(); coreNameData = coreNameArray.constData(); corePathData = corePathArray.constData(); if (!contentEntry.crc32.isEmpty()) { crc32Array = contentEntry.crc32.toUtf8(); crc32Data = crc32Array.constData(); } /* A single-file archive resolves to "archive#file". */ companion_core_resolve_content_path(ui_companion_qt_core(), pathData, contentPath, sizeof(contentPath)); pathData = contentPath; { struct playlist_entry entry = {0}; /* The update function reads our entry as const, * so these casts are safe */ entry.path = const_cast(pathData); entry.label = const_cast(labelData); entry.core_path = const_cast(corePathData); entry.core_name = const_cast(coreNameData); entry.crc32 = const_cast(crc32Data); entry.db_name = const_cast(dbNameData); if (!companion_core_playlist_update_entry(ui_companion_qt_core(), playlistPathData, contentEntry.index, &entry)) return false; } reloadPlaylists(); return true; } void MainWindow::onPlaylistWidgetContextMenuRequested(const QPoint&) { QString currentPlaylistDirPath; QString currentPlaylistPath; QString currentPlaylistFileName; QFile currentPlaylistFile; QFileInfo currentPlaylistFileInfo; QMap coreList; QScopedPointer menu; QScopedPointer associateMenu; QScopedPointer hiddenPlaylistsMenu; QScopedPointer downloadAllThumbnailsMenu; QScopedPointer hideAction; QScopedPointer newPlaylistAction; QScopedPointer deletePlaylistAction; QScopedPointer renamePlaylistAction; QScopedPointer downloadAllThumbnailsEntireSystemAction; QScopedPointer downloadAllThumbnailsThisPlaylistAction; QPointer selectedAction; QPoint cursorPos = QCursor::pos(); settings_t *settings = config_get_ptr(); const char *path_dir_playlist = settings->paths.directory_playlist; QDir playlistDir(path_dir_playlist); QListWidgetItem *selectedItem = m_listWidget->itemAt( m_listWidget->viewport()->mapFromGlobal(cursorPos)); QString playlistDirAbsPath = playlistDir.absolutePath(); core_info_list_t *core_info_list = NULL; unsigned i = 0; int j = 0; bool specialPlaylist = false; bool foundHiddenPlaylist = false; if (selectedItem) { currentPlaylistPath = selectedItem->data(Qt::UserRole).toString(); currentPlaylistFile.setFileName(currentPlaylistPath); currentPlaylistFileInfo = QFileInfo(currentPlaylistPath); currentPlaylistFileName = currentPlaylistFileInfo.fileName(); currentPlaylistDirPath = currentPlaylistFileInfo.absoluteDir().absolutePath(); } menu.reset(new QMenu(this)); menu->setObjectName("menu"); hiddenPlaylistsMenu.reset(new QMenu(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_HIDDEN_PLAYLISTS), this)); newPlaylistAction.reset(new QAction(QString( msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_NEW_PLAYLIST)) + QString("..."), this)); hiddenPlaylistsMenu->setObjectName("hiddenPlaylistsMenu"); menu->addAction(newPlaylistAction.data()); if (currentPlaylistFile.exists()) { deletePlaylistAction.reset(new QAction( QString(msg_hash_to_str( MENU_ENUM_LABEL_VALUE_QT_DELETE_PLAYLIST)) + QString("..."), this)); menu->addAction(deletePlaylistAction.data()); renamePlaylistAction.reset(new QAction(QString( msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_RENAME_PLAYLIST)) + QString("..."), this)); menu->addAction(renamePlaylistAction.data()); } if (selectedItem) { hideAction.reset(new QAction(msg_hash_to_str( MENU_ENUM_LABEL_VALUE_QT_HIDE), this)); menu->addAction(hideAction.data()); } for (j = 0; j < m_listWidget->count(); j++) { QListWidgetItem *item = m_listWidget->item(j); if (item->isHidden()) { QAction *action = hiddenPlaylistsMenu->addAction(item->text()); action->setProperty("row", j); action->setProperty("core_path", item->data(Qt::UserRole).toString()); foundHiddenPlaylist = true; } } if (!foundHiddenPlaylist) { QAction *action = hiddenPlaylistsMenu->addAction( msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NONE)); action->setProperty("row", -1); } menu->addMenu(hiddenPlaylistsMenu.data()); /* Don't just compare strings in case there are * case differences on Windows that should be ignored. * Special playlists like history etc. can't have an association */ if (QDir(currentPlaylistDirPath) != QDir(playlistDirAbsPath)) specialPlaylist = true; if (!specialPlaylist) { associateMenu.reset(new QMenu(msg_hash_to_str( MENU_ENUM_LABEL_VALUE_QT_ASSOCIATE_CORE), this)); associateMenu->setObjectName("associateMenu"); core_info_get_list(&core_info_list); for (i = 0; i < core_info_list->count && core_info_list->count > 0; i++) { const core_info_t *core = &core_info_list->list[i]; coreList[core->core_name] = core; } { QMapIterator coreListIterator(coreList); QVector > cores; while (coreListIterator.hasNext()) { QString key, name; const core_info_t *core = NULL; QHash hash; coreListIterator.next(); key = coreListIterator.key(); core = coreList.value(key); if (!core->core_name || !*core->core_name) name = core->display_name; else name = core->core_name; if (name.isEmpty()) continue; hash["name"] = name; hash["core_path"] = core->path; cores.append(hash); } std::sort(cores.begin(), cores.end(), comp_hash_name_key_lower); for (j = 0; j < cores.count(); j++) { const QHash &hash = cores.at(j); QAction *action = associateMenu->addAction(hash.value("name")); action->setProperty("core_path", hash.value("core_path")); } } menu->addMenu(associateMenu.data()); } if (!specialPlaylist) { downloadAllThumbnailsMenu.reset(new QMenu( msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_DOWNLOAD_ALL_THUMBNAILS), this)); downloadAllThumbnailsMenu->setObjectName("downloadAllThumbnailsMenu"); downloadAllThumbnailsThisPlaylistAction.reset( new QAction(msg_hash_to_str( MENU_ENUM_LABEL_VALUE_QT_DOWNLOAD_ALL_THUMBNAILS_THIS_PLAYLIST), downloadAllThumbnailsMenu.data())); downloadAllThumbnailsEntireSystemAction.reset( new QAction(msg_hash_to_str( MENU_ENUM_LABEL_VALUE_QT_DOWNLOAD_ALL_THUMBNAILS_ENTIRE_SYSTEM), downloadAllThumbnailsMenu.data())); downloadAllThumbnailsMenu->addAction( downloadAllThumbnailsThisPlaylistAction.data()); downloadAllThumbnailsMenu->addAction( downloadAllThumbnailsEntireSystemAction.data()); menu->addMenu(downloadAllThumbnailsMenu.data()); } selectedAction = menu->exec(cursorPos); if (!selectedAction) return; if (!specialPlaylist && selectedAction->parent() == associateMenu.data()) { QByteArray currentPlaylistPathByteArray = currentPlaylistPath.toUtf8(); QByteArray corePathByteArray = selectedAction->property("core_path").toString().toUtf8(); companion_core_playlist_set_default_core(ui_companion_qt_core(), currentPlaylistPathByteArray.constData(), corePathByteArray.constData()); } else if (selectedItem && selectedAction == deletePlaylistAction.data()) { if (currentPlaylistFile.exists()) { if (showMessageBox(QString(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_CONFIRM_DELETE_PLAYLIST)).arg(selectedItem->text()), MainWindow::MSGBOX_TYPE_QUESTION_YESNO, Qt::ApplicationModal, false)) { if (currentPlaylistFile.remove()) reloadPlaylists(); else showMessageBox(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_COULD_NOT_DELETE_FILE), MainWindow::MSGBOX_TYPE_ERROR, Qt::ApplicationModal, false); } } } else if (selectedItem && selectedAction == renamePlaylistAction.data()) { if (currentPlaylistFile.exists()) { QString oldName = selectedItem->text(); QString name = QInputDialog::getText(this, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_RENAME_PLAYLIST), msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_ENTER_NEW_PLAYLIST_NAME), QLineEdit::Normal, oldName); if (!name.isEmpty()) { renamePlaylistItem(selectedItem, name); reloadPlaylists(); } } } else if (selectedAction == newPlaylistAction.data()) { QString name = QInputDialog::getText(this, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_NEW_PLAYLIST), msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_ENTER_NEW_PLAYLIST_NAME)); QString newPlaylistPath = playlistDirAbsPath + "/" + name + ".lpl"; QFile file(newPlaylistPath); if (!name.isEmpty()) { if (file.open(QIODevice::WriteOnly)) file.close(); reloadPlaylists(); } } else if (selectedItem && selectedAction == hideAction.data()) { int row = m_listWidget->row(selectedItem); if (row >= 0) { qt_set_playlist_hidden(currentPlaylistFileName, true); m_listWidget->setRowHidden(row, true); } } else if (selectedAction->parent() == hiddenPlaylistsMenu.data()) { QVariant rowVariant = selectedAction->property("row"); if (rowVariant.isValid()) { int row = rowVariant.toInt(); if (row >= 0) { QString playlistPath = selectedAction->property("core_path").toString(); QFileInfo playlistFileInfo(playlistPath); QString playlistFileName = playlistFileInfo.fileName(); qt_set_playlist_hidden(playlistFileName, false); m_listWidget->setRowHidden(row, false); } } } else if (selectedItem && !specialPlaylist && selectedAction->parent() == downloadAllThumbnailsMenu.data()) { if (selectedAction == downloadAllThumbnailsEntireSystemAction.data()) { int row = m_listWidget->row(selectedItem); if (row >= 0) downloadAllThumbnails(currentPlaylistFileInfo.completeBaseName()); } else if (selectedAction == downloadAllThumbnailsThisPlaylistAction.data()) downloadPlaylistThumbnails(currentPlaylistPath); } setCoreActions(); } void MainWindow::deferReloadPlaylists() { emit gotReloadPlaylists(); } void MainWindow::onGotReloadPlaylists() { reloadPlaylists(); } void MainWindow::reloadPlaylists() { int i; QString currentPlaylistPath; QListWidgetItem *allPlaylistsItem = NULL; QListWidgetItem *favoritesPlaylistsItem = NULL; QListWidgetItem *imagePlaylistsItem = NULL; QListWidgetItem *musicPlaylistsItem = NULL; QListWidgetItem *videoPlaylistsItem = NULL; QListWidgetItem *firstItem = NULL; settings_t *settings = config_get_ptr(); const char *path_dir_playlist = settings->paths.directory_playlist; QDir playlistDir(path_dir_playlist); QListWidgetItem *currentItem = m_listWidget->currentItem(); if (currentItem) currentPlaylistPath = currentItem->data(Qt::UserRole).toString(); getPlaylistFiles(); m_listWidget->clear(); m_listWidget->setSelectionBehavior(QAbstractItemView::SelectRows); m_listWidget->setSelectionMode(QAbstractItemView::SingleSelection); m_listWidget->setEditTriggers(QAbstractItemView::SelectedClicked | QAbstractItemView::EditKeyPressed); allPlaylistsItem = new QListWidgetItem(m_folderIcon, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_ALL_PLAYLISTS)); allPlaylistsItem->setData(Qt::UserRole, ALL_PLAYLISTS_TOKEN); favoritesPlaylistsItem = new QListWidgetItem(m_folderIcon, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_FAVORITES_TAB)); favoritesPlaylistsItem->setData(Qt::UserRole, QString(settings->paths.path_content_favorites)); m_historyPlaylistsItem = new QListWidgetItem(m_folderIcon, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_HISTORY_TAB)); m_historyPlaylistsItem->setData(Qt::UserRole, QString(settings->paths.path_content_history)); imagePlaylistsItem = new QListWidgetItem(m_folderIcon, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_IMAGES_TAB)); imagePlaylistsItem->setData(Qt::UserRole, QString(settings->paths.path_content_image_history)); musicPlaylistsItem = new QListWidgetItem(m_folderIcon, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_MUSIC_TAB)); musicPlaylistsItem->setData(Qt::UserRole, QString(settings->paths.path_content_music_history)); videoPlaylistsItem = new QListWidgetItem(m_folderIcon, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_VIDEO_TAB)); videoPlaylistsItem->setData(Qt::UserRole, QString(settings->paths.path_content_video_history)); m_listWidget->addItem(allPlaylistsItem); m_listWidget->addItem(favoritesPlaylistsItem); m_listWidget->addItem(m_historyPlaylistsItem); m_listWidget->addItem(imagePlaylistsItem); m_listWidget->addItem(musicPlaylistsItem); m_listWidget->addItem(videoPlaylistsItem); if (qt_playlist_hidden(ALL_PLAYLISTS_TOKEN)) m_listWidget->setRowHidden(m_listWidget->row(allPlaylistsItem), true); if (qt_playlist_hidden(QFileInfo(settings->paths.path_content_favorites).fileName())) m_listWidget->setRowHidden(m_listWidget->row(favoritesPlaylistsItem), true); if (qt_playlist_hidden(QFileInfo(settings->paths.path_content_history).fileName())) m_listWidget->setRowHidden(m_listWidget->row(m_historyPlaylistsItem), true); if (qt_playlist_hidden(QFileInfo(settings->paths.path_content_image_history).fileName())) m_listWidget->setRowHidden(m_listWidget->row(imagePlaylistsItem), true); if (qt_playlist_hidden(QFileInfo(settings->paths.path_content_music_history).fileName())) m_listWidget->setRowHidden(m_listWidget->row(musicPlaylistsItem), true); if (qt_playlist_hidden(QFileInfo(settings->paths.path_content_video_history).fileName())) m_listWidget->setRowHidden(m_listWidget->row(videoPlaylistsItem), true); for (i = 0; i < m_playlistFiles.count(); i++) { QIcon icon; QString iconPath; QListWidgetItem *item = NULL; const QString &file = m_playlistFiles.at(i); /* don't show view files */ if (file.endsWith(".lvw", Qt::CaseInsensitive)) continue; QString fileDisplayName = file; QString fileName = file; bool hasIcon = false; fileDisplayName.remove(".lpl"); iconPath = QString( settings->paths.directory_assets) + ICON_PATH + fileDisplayName + ".png"; hasIcon = QFile::exists(iconPath); if (hasIcon) icon = QIcon(iconPath); else icon = m_folderIcon; item = new QListWidgetItem(icon, fileDisplayName); item->setFlags(item->flags() | Qt::ItemIsEditable); item->setData(Qt::UserRole, playlistDir.absoluteFilePath(file)); m_listWidget->addItem(item); if (qt_playlist_hidden(fileName)) { int row = m_listWidget->row(item); if (row >= 0) m_listWidget->setRowHidden(row, true); } } if (m_listWidget->count() > 0) { firstItem = m_listWidget->item(0); if (firstItem) { bool foundCurrent = false; bool foundInitial = false; QString initialPlaylist = string_is_empty(config_get_ptr()->paths.desktop_menu_initial_playlist) ? QString(ALL_PLAYLISTS_TOKEN) : QString::fromUtf8(config_get_ptr()->paths.desktop_menu_initial_playlist); QListWidgetItem *initialItem = NULL; for (i = 0; i < m_listWidget->count(); i++) { QString path; QListWidgetItem *item = m_listWidget->item(i); if (item) { path = item->data(Qt::UserRole).toString(); if (!path.isEmpty()) { /* don't break early here since we want * to make sure we've found both initial * and current items if they exist */ if (!foundInitial && path == initialPlaylist) { foundInitial = true; initialItem = item; } if ( !foundCurrent && !currentPlaylistPath.isEmpty() && path == currentPlaylistPath) { foundCurrent = true; m_listWidget->setCurrentItem(item); } } } } if (!foundCurrent) { if (foundInitial && initialItem) m_listWidget->setCurrentItem(initialItem); else { /* the previous playlist must be gone now, * just select the first one */ m_listWidget->setCurrentItem(firstItem); } } } } } QString MainWindow::getCurrentPlaylistPath() { QString playlistPath; QListWidgetItem *playlistItem = m_listWidget->currentItem(); if (!playlistItem) return playlistPath; playlistPath = playlistItem->data(Qt::UserRole).toString(); return playlistPath; } bool MainWindow::currentPlaylistIsSpecial() { QFileInfo currentPlaylistFileInfo; QString currentPlaylistPath; QString currentPlaylistDirPath; settings_t *settings = config_get_ptr(); QDir playlistDir(settings->paths.directory_playlist); QString playlistDirAbsPath = playlistDir.absolutePath(); QListWidgetItem *currentPlaylistItem = m_listWidget->currentItem(); if (!currentPlaylistItem) return false; currentPlaylistPath = currentPlaylistItem->data(Qt::UserRole).toString(); currentPlaylistFileInfo = QFileInfo(currentPlaylistPath); currentPlaylistDirPath = currentPlaylistFileInfo.absoluteDir().absolutePath(); /* Don't just compare strings in case there are * case differences on Windows that should be ignored. */ if (QDir(currentPlaylistDirPath) != QDir(playlistDirAbsPath)) return true; return false; } bool MainWindow::currentPlaylistIsAll() { QListWidgetItem *currentPlaylistItem = m_listWidget->currentItem(); if ( currentPlaylistItem && currentPlaylistItem->data(Qt::UserRole).toString() == ALL_PLAYLISTS_TOKEN) return true; return false; } void MainWindow::deleteCurrentPlaylistItem() { QByteArray playlistArray; QString playlistPath = getCurrentPlaylistPath(); PlaylistEntry contentEntry = getCurrentContentEntry(); const char *playlistData = NULL; bool isAllPlaylist = currentPlaylistIsAll(); if (isAllPlaylist) return; if (playlistPath.isEmpty()) return; if (contentEntry.path.isEmpty()) return; playlistArray = playlistPath.toUtf8(); playlistData = playlistArray.constData(); if (!showMessageBox(QString(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_CONFIRM_DELETE_PLAYLIST_ITEM)).arg(contentEntry.label), MainWindow::MSGBOX_TYPE_QUESTION_YESNO, Qt::ApplicationModal, false)) return; companion_core_playlist_delete_entry(ui_companion_qt_core(), playlistData, contentEntry.index); reloadPlaylists(); } QString MainWindow::getPlaylistDefaultCore(QString plName) { char core_path[PATH_MAX_LENGTH]; QByteArray plNameByteArray = plName.toUtf8(); if (companion_core_playlist_default_core(ui_companion_qt_core(), plNameByteArray.constData(), core_path, sizeof(core_path))) return QString::fromUtf8(core_path); return QString(); } void MainWindow::getPlaylistFiles() { settings_t *settings = config_get_ptr(); QDir playlistDir(settings->paths.directory_playlist); m_playlistFiles = playlistDir.entryList( QDir::NoDotAndDotDot | QDir::Readable | QDir::Files, QDir::Name); } /* Copy the companion core's currently loaded playlist into the pending * contents. Everything is deep-copied into QStrings, so nothing here * outlives the core's playlist object. */ void PlaylistModel::appendEntriesFromCore() { companion_core_t *core = ui_companion_qt_core(); const char *path = companion_core_selected_playlist_path(core); const char *playlistName = NULL; size_t playlistSize = companion_core_entry_count(core); size_t i; if (path && *path) playlistName = path_basename(path); for (i = 0; i < playlistSize; i++) { PlaylistEntry rowEntry; const struct playlist_entry *pl_row = companion_core_entry(core, i); if (!pl_row || !pl_row->path || !*pl_row->path) continue; rowEntry.path = pl_row->path; rowEntry.index = (unsigned)i; if (!pl_row->label || !*pl_row->label) { rowEntry.label = pl_row->path; rowEntry.labelNoExt = pl_row->path; } else { rowEntry.label = pl_row->label; rowEntry.labelNoExt = pl_row->label; } if (pl_row->core_path && *pl_row->core_path) rowEntry.corePath = pl_row->core_path; if (pl_row->core_name && *pl_row->core_name) rowEntry.coreName = pl_row->core_name; if (pl_row->crc32 && *pl_row->crc32) rowEntry.crc32 = pl_row->crc32; if (pl_row->db_name && *pl_row->db_name) { rowEntry.dbName = pl_row->db_name; rowEntry.dbName.remove(".lpl"); } if (playlistName && *playlistName) { rowEntry.plName = playlistName; rowEntry.plName.remove(".lpl"); } m_pendingContents.append(rowEntry); } } void PlaylistModel::startNextPendingPlaylist() { while (!m_pendingPaths.isEmpty()) { QByteArray pathArray = m_pendingPaths.takeFirst().toUtf8(); /* The parse is driven from the runloop by companion_core_iterate() * under a time budget; onCorePlaylistChanged() fires when it is * done. Nothing blocks here, however large the playlist. */ if (companion_core_select_playlist_path(ui_companion_qt_core(), pathArray.constData())) return; /* Unreadable path: skip it and try the next one. */ } /* All done: commit in a single model reset. */ beginResetModel(); m_contents = m_pendingContents; m_pendingContents.clear(); m_loadingPlaylists = false; endResetModel(); emit playlistsLoaded(); } void PlaylistModel::onCorePlaylistChanged() { if (!m_loadingPlaylists) return; appendEntriesFromCore(); startNextPendingPlaylist(); } bool PlaylistModel::isLoadingPlaylists() const { return m_loadingPlaylists; } void PlaylistModel::addPlaylistItems(const QStringList &paths, bool add) { if (paths.isEmpty()) return; /* Restarting supersedes any load still in flight: the core aborts * the pending parse when a new playlist is selected, and the * partially collected entries are dropped. */ m_pendingPaths = paths; m_pendingContents.clear(); m_loadingPlaylists = true; startNextPendingPlaylist(); } void PlaylistModel::addDir(QString path, QFlags showHidden) { int i; QDir dir = path; QStringList dirList = dir.entryList( QDir::NoDotAndDotDot | QDir::Readable | QDir::Files | showHidden, QDir::Name); if (dirList.count() == 0) return; beginResetModel(); m_contents.clear(); for (i = 0; i < dirList.count(); i++) { PlaylistEntry rowEntry; QString fileName = dirList.at(i); QString filePath( QDir::toNativeSeparators(dir.absoluteFilePath(fileName))); QFileInfo fileInfo(filePath); rowEntry.path = filePath; rowEntry.label = filePath; rowEntry.labelNoExt = fileInfo.completeBaseName(); rowEntry.dbName = fileInfo.dir().dirName(); m_contents.append(rowEntry); } endResetModel(); } void MainWindow::setAllPlaylistsListMaxCount(int count) { if (count < 1) count = 0; m_allPlaylistsListMaxCount = count; } void MainWindow::setAllPlaylistsGridMaxCount(int count) { if (count < 1) count = 0; m_allPlaylistsGridMaxCount = count; }