feat: add SettingWidget::dropdown support for int style enums (#6303)
This commit is contained in:
@@ -2046,7 +2046,7 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event)
|
||||
if (badgeElement || emoteElement || layeredEmoteElement)
|
||||
{
|
||||
auto showThumbnailSetting =
|
||||
getSettings()->emotesTooltipPreview.getValue();
|
||||
getSettings()->emotesTooltipPreview.getEnum();
|
||||
|
||||
bool showThumbnail =
|
||||
showThumbnailSetting == ThumbnailPreviewMode::AlwaysShow ||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "Application.hpp"
|
||||
#include "common/Literals.hpp"
|
||||
#include "common/QLogging.hpp"
|
||||
#include "common/ThumbnailPreviewMode.hpp"
|
||||
#include "common/Version.hpp"
|
||||
#include "controllers/hotkeys/HotkeyCategory.hpp"
|
||||
#include "controllers/hotkeys/HotkeyController.hpp"
|
||||
@@ -552,29 +553,8 @@ void GeneralPage::initLayout(GeneralPageView &layout)
|
||||
s.showLastMessageIndicator, false,
|
||||
"Adds an underline below the most recent message "
|
||||
"sent before you tabbed out of Chatterino.");
|
||||
layout.addDropdown<std::underlying_type_t<Qt::BrushStyle>>(
|
||||
"Line style", {"Dotted", "Solid"}, s.lastMessagePattern,
|
||||
[](int value) {
|
||||
switch (value)
|
||||
{
|
||||
case Qt::VerPattern:
|
||||
return 0;
|
||||
case Qt::SolidPattern:
|
||||
default:
|
||||
return 1;
|
||||
}
|
||||
},
|
||||
[](DropdownArgs args) {
|
||||
switch (args.index)
|
||||
{
|
||||
case 0:
|
||||
return Qt::VerPattern;
|
||||
case 1:
|
||||
default:
|
||||
return Qt::SolidPattern;
|
||||
}
|
||||
},
|
||||
false);
|
||||
|
||||
SettingWidget::dropdown("Line style", s.lastMessagePattern)->addTo(layout);
|
||||
|
||||
SettingWidget::colorButton("Line color", s.lastMessageColor)->addTo(layout);
|
||||
|
||||
@@ -634,30 +614,11 @@ void GeneralPage::initLayout(GeneralPageView &layout)
|
||||
});
|
||||
},
|
||||
false);
|
||||
layout.addDropdown<std::underlying_type_t<ThumbnailPreviewMode>>(
|
||||
"Show emote & badge thumbnail on hover",
|
||||
{
|
||||
"Don't show",
|
||||
"Always show",
|
||||
"Hold shift",
|
||||
},
|
||||
s.emotesTooltipPreview,
|
||||
[](auto val) {
|
||||
switch (val)
|
||||
{
|
||||
case ThumbnailPreviewMode::DontShow:
|
||||
return "Don't show";
|
||||
case ThumbnailPreviewMode::AlwaysShow:
|
||||
return "Always show";
|
||||
case ThumbnailPreviewMode::ShowOnShift:
|
||||
return "Hold shift";
|
||||
}
|
||||
return "";
|
||||
},
|
||||
[](auto args) {
|
||||
return args.index;
|
||||
},
|
||||
false);
|
||||
|
||||
SettingWidget::dropdown("Show emote & badge thumbnail on hover",
|
||||
s.emotesTooltipPreview)
|
||||
->addTo(layout);
|
||||
|
||||
SettingWidget::dropdown("Emote & badge thumbnail size on hover",
|
||||
s.emoteTooltipScale)
|
||||
->addTo(layout);
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#include "widgets/settingspages/SettingWidget.hpp"
|
||||
|
||||
#include "singletons/Settings.hpp"
|
||||
#include "common/QLogging.hpp"
|
||||
#include "singletons/Settings.hpp" // IWYU pragma: keep
|
||||
#include "util/QMagicEnumTagged.hpp"
|
||||
#include "util/RapidJsonSerializeQString.hpp" // IWYU pragma: keep
|
||||
#include "widgets/dialogs/ColorPickerDialog.hpp"
|
||||
#include "widgets/helper/color/ColorButton.hpp"
|
||||
@@ -230,6 +232,83 @@ template SettingWidget *SettingWidget::dropdown<ShowModerationState>(
|
||||
template SettingWidget *SettingWidget::dropdown<EmojiStyle>(
|
||||
const QString &label, EnumStringSetting<EmojiStyle> &setting);
|
||||
|
||||
template <typename T>
|
||||
SettingWidget *SettingWidget::dropdown(const QString &label,
|
||||
EnumSetting<T> &setting)
|
||||
{
|
||||
auto *widget = new SettingWidget(label);
|
||||
|
||||
auto *lbl = new QLabel(label % ":");
|
||||
auto *combo = new ComboBox;
|
||||
combo->setFocusPolicy(Qt::StrongFocus);
|
||||
|
||||
for (const auto value : magic_enum::enum_values<T>())
|
||||
{
|
||||
combo->addItem(qmagicenum::enumDisplayNameString(value),
|
||||
QVariant(static_cast<std::underlying_type_t<T>>(value)));
|
||||
}
|
||||
|
||||
// TODO: this can probably use some other size hint/size strategy
|
||||
combo->setMinimumWidth(combo->minimumSizeHint().width());
|
||||
|
||||
widget->actionWidget = combo;
|
||||
widget->label = lbl;
|
||||
|
||||
widget->hLayout->addWidget(lbl);
|
||||
widget->hLayout->addStretch(1);
|
||||
widget->hLayout->addWidget(combo);
|
||||
|
||||
setting.connect(
|
||||
[combo, label](const auto &value) {
|
||||
std::optional<int> foundRow;
|
||||
|
||||
for (auto row = 0; row < combo->model()->rowCount(); ++row)
|
||||
{
|
||||
auto index = combo->model()->index(row, 0);
|
||||
auto rowEnumValue = index.data(Qt::UserRole);
|
||||
if (rowEnumValue == value)
|
||||
{
|
||||
foundRow = row;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (foundRow)
|
||||
{
|
||||
combo->setCurrentIndex(*foundRow);
|
||||
}
|
||||
else
|
||||
{
|
||||
qCWarning(chatterinoWidget)
|
||||
<< "Did not find a correct combo box row for" << label
|
||||
<< " with value" << value;
|
||||
}
|
||||
},
|
||||
widget->managedConnections);
|
||||
|
||||
QObject::connect(combo, &QComboBox::currentTextChanged,
|
||||
[label, combo, &setting](const auto &newText) {
|
||||
bool ok = true;
|
||||
auto enumValue = combo->currentData().toInt(&ok);
|
||||
if (!ok)
|
||||
{
|
||||
qCWarning(chatterinoWidget)
|
||||
<< "Combo" << label << " with value" << newText
|
||||
<< "did not contain an intable UserRole data";
|
||||
return;
|
||||
}
|
||||
|
||||
setting.setValue(enumValue);
|
||||
});
|
||||
|
||||
return widget;
|
||||
}
|
||||
|
||||
template SettingWidget *SettingWidget::dropdown<LastMessageLineStyle>(
|
||||
const QString &label, EnumSetting<LastMessageLineStyle> &setting);
|
||||
template SettingWidget *SettingWidget::dropdown<ThumbnailPreviewMode>(
|
||||
const QString &label, EnumSetting<ThumbnailPreviewMode> &setting);
|
||||
|
||||
SettingWidget *SettingWidget::colorButton(const QString &label,
|
||||
QStringSetting &setting)
|
||||
{
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "common/ChatterinoSetting.hpp"
|
||||
#include "common/QLogging.hpp"
|
||||
#include "util/QMagicEnum.hpp"
|
||||
#include "util/QMagicEnumTagged.hpp"
|
||||
#include "widgets/settingspages/GeneralPageView.hpp"
|
||||
|
||||
#include <pajlada/signals/signalholder.hpp>
|
||||
#include <QBoxLayout>
|
||||
@@ -18,6 +14,9 @@
|
||||
#include <QtContainerFwd>
|
||||
#include <QWidget>
|
||||
|
||||
#include <functional>
|
||||
#include <optional>
|
||||
|
||||
class QFormLayout;
|
||||
|
||||
namespace chatterino {
|
||||
@@ -57,6 +56,10 @@ public:
|
||||
static SettingWidget *dropdown(const QString &label,
|
||||
EnumStringSetting<T> &setting);
|
||||
|
||||
template <typename T>
|
||||
static SettingWidget *dropdown(const QString &label,
|
||||
EnumSetting<T> &setting);
|
||||
|
||||
static SettingWidget *colorButton(const QString &label,
|
||||
QStringSetting &setting);
|
||||
static SettingWidget *lineEdit(const QString &label,
|
||||
|
||||
Reference in New Issue
Block a user