feat: add SettingWidget::dropdown support for int style enums (#6303)
This commit is contained in:
@@ -31,6 +31,7 @@ set(SOURCE_FILES
|
|||||||
common/Credentials.hpp
|
common/Credentials.hpp
|
||||||
common/Env.cpp
|
common/Env.cpp
|
||||||
common/Env.hpp
|
common/Env.hpp
|
||||||
|
common/LastMessageLineStyle.hpp
|
||||||
common/LinkParser.cpp
|
common/LinkParser.cpp
|
||||||
common/LinkParser.hpp
|
common/LinkParser.hpp
|
||||||
common/Literals.hpp
|
common/Literals.hpp
|
||||||
@@ -38,6 +39,7 @@ set(SOURCE_FILES
|
|||||||
common/Modes.hpp
|
common/Modes.hpp
|
||||||
common/QLogging.cpp
|
common/QLogging.cpp
|
||||||
common/QLogging.hpp
|
common/QLogging.hpp
|
||||||
|
common/ThumbnailPreviewMode.hpp
|
||||||
common/TimeoutStackStyle.hpp
|
common/TimeoutStackStyle.hpp
|
||||||
common/WindowDescriptors.cpp
|
common/WindowDescriptors.cpp
|
||||||
common/WindowDescriptors.hpp
|
common/WindowDescriptors.hpp
|
||||||
|
|||||||
@@ -62,6 +62,9 @@ using StringSetting = ChatterinoSetting<std::string>;
|
|||||||
using QStringSetting = ChatterinoSetting<QString>;
|
using QStringSetting = ChatterinoSetting<QString>;
|
||||||
using QSizeSetting = ChatterinoSetting<QSize>;
|
using QSizeSetting = ChatterinoSetting<QSize>;
|
||||||
|
|
||||||
|
/// Accepts any enum and saves the enum value as an integer
|
||||||
|
///
|
||||||
|
/// e.g. for enum class {Foo = 2, Bar = 6}, Foo would be saved as 2 and Bar would be saved as 6
|
||||||
template <typename Enum>
|
template <typename Enum>
|
||||||
class EnumSetting : public ChatterinoSetting<std::underlying_type_t<Enum>>
|
class EnumSetting : public ChatterinoSetting<std::underlying_type_t<Enum>>
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QBrush>
|
||||||
|
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
|
namespace chatterino {
|
||||||
|
|
||||||
|
/// The values must always be castable to a Qt::BrushStyle
|
||||||
|
// NOLINTNEXTLINE(performance-enum-size)
|
||||||
|
enum class LastMessageLineStyle : std::underlying_type_t<Qt::BrushStyle> {
|
||||||
|
Solid = Qt::SolidPattern,
|
||||||
|
Dotted = Qt::VerPattern,
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace chatterino
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <optional>
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
|
namespace chatterino {
|
||||||
|
|
||||||
|
enum class ThumbnailPreviewMode : std::uint8_t {
|
||||||
|
DontShow,
|
||||||
|
|
||||||
|
AlwaysShow,
|
||||||
|
|
||||||
|
ShowOnShift,
|
||||||
|
};
|
||||||
|
|
||||||
|
constexpr std::optional<std::string_view> qmagicenumDisplayName(
|
||||||
|
ThumbnailPreviewMode value) noexcept
|
||||||
|
{
|
||||||
|
switch (value)
|
||||||
|
{
|
||||||
|
case ThumbnailPreviewMode::DontShow:
|
||||||
|
return "Don't show";
|
||||||
|
case ThumbnailPreviewMode::AlwaysShow:
|
||||||
|
return "Always show";
|
||||||
|
case ThumbnailPreviewMode::ShowOnShift:
|
||||||
|
return "Hold shift";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace chatterino
|
||||||
+10
-12
@@ -2,8 +2,10 @@
|
|||||||
|
|
||||||
#include "common/ChatterinoSetting.hpp"
|
#include "common/ChatterinoSetting.hpp"
|
||||||
#include "common/enums/MessageOverflow.hpp"
|
#include "common/enums/MessageOverflow.hpp"
|
||||||
|
#include "common/LastMessageLineStyle.hpp"
|
||||||
#include "common/Modes.hpp"
|
#include "common/Modes.hpp"
|
||||||
#include "common/SignalVector.hpp"
|
#include "common/SignalVector.hpp"
|
||||||
|
#include "common/ThumbnailPreviewMode.hpp"
|
||||||
#include "common/TimeoutStackStyle.hpp"
|
#include "common/TimeoutStackStyle.hpp"
|
||||||
#include "controllers/filters/FilterRecord.hpp"
|
#include "controllers/filters/FilterRecord.hpp"
|
||||||
#include "controllers/highlights/HighlightBadge.hpp"
|
#include "controllers/highlights/HighlightBadge.hpp"
|
||||||
@@ -16,7 +18,6 @@
|
|||||||
#include "controllers/sound/ISoundController.hpp"
|
#include "controllers/sound/ISoundController.hpp"
|
||||||
#include "providers/emoji/EmojiStyle.hpp"
|
#include "providers/emoji/EmojiStyle.hpp"
|
||||||
#include "singletons/Toasts.hpp"
|
#include "singletons/Toasts.hpp"
|
||||||
#include "util/QMagicEnumTagged.hpp"
|
|
||||||
#include "util/RapidJsonSerializeQString.hpp" // IWYU pragma: keep
|
#include "util/RapidJsonSerializeQString.hpp" // IWYU pragma: keep
|
||||||
#include "widgets/NotebookEnums.hpp"
|
#include "widgets/NotebookEnums.hpp"
|
||||||
|
|
||||||
@@ -24,6 +25,9 @@
|
|||||||
#include <pajlada/settings/settinglistener.hpp>
|
#include <pajlada/settings/settinglistener.hpp>
|
||||||
#include <pajlada/signals/signalholder.hpp>
|
#include <pajlada/signals/signalholder.hpp>
|
||||||
|
|
||||||
|
#include <optional>
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
using TimeoutButton = std::pair<QString, int>;
|
using TimeoutButton = std::pair<QString, int>;
|
||||||
|
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
@@ -52,14 +56,6 @@ enum UsernameDisplayMode : int {
|
|||||||
UsernameAndLocalizedName = 3, // Username (Localized name)
|
UsernameAndLocalizedName = 3, // Username (Localized name)
|
||||||
};
|
};
|
||||||
|
|
||||||
enum ThumbnailPreviewMode : int {
|
|
||||||
DontShow = 0,
|
|
||||||
|
|
||||||
AlwaysShow = 1,
|
|
||||||
|
|
||||||
ShowOnShift = 2,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum UsernameRightClickBehavior : int {
|
enum UsernameRightClickBehavior : int {
|
||||||
Reply = 0,
|
Reply = 0,
|
||||||
Mention = 1,
|
Mention = 1,
|
||||||
@@ -106,7 +102,7 @@ enum class EmoteTooltipScale : std::uint8_t {
|
|||||||
Huge,
|
Huge,
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr qmagicenum::customize_t qmagicenumDisplayName(
|
constexpr std::optional<std::string_view> qmagicenumDisplayName(
|
||||||
EmoteTooltipScale value) noexcept
|
EmoteTooltipScale value) noexcept
|
||||||
{
|
{
|
||||||
switch (value)
|
switch (value)
|
||||||
@@ -163,8 +159,10 @@ public:
|
|||||||
"h:mm"};
|
"h:mm"};
|
||||||
BoolSetting showLastMessageIndicator = {
|
BoolSetting showLastMessageIndicator = {
|
||||||
"/appearance/messages/showLastMessageIndicator", false};
|
"/appearance/messages/showLastMessageIndicator", false};
|
||||||
EnumSetting<Qt::BrushStyle> lastMessagePattern = {
|
EnumSetting<LastMessageLineStyle> lastMessagePattern = {
|
||||||
"/appearance/messages/lastMessagePattern", Qt::SolidPattern};
|
"/appearance/messages/lastMessagePattern",
|
||||||
|
LastMessageLineStyle::Solid,
|
||||||
|
};
|
||||||
QStringSetting lastMessageColor = {"/appearance/messages/lastMessageColor",
|
QStringSetting lastMessageColor = {"/appearance/messages/lastMessageColor",
|
||||||
"#7f2026"};
|
"#7f2026"};
|
||||||
BoolSetting showEmptyInput = {"/appearance/showEmptyInputBox", true};
|
BoolSetting showEmptyInput = {"/appearance/showEmptyInputBox", true};
|
||||||
|
|||||||
@@ -2046,7 +2046,7 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event)
|
|||||||
if (badgeElement || emoteElement || layeredEmoteElement)
|
if (badgeElement || emoteElement || layeredEmoteElement)
|
||||||
{
|
{
|
||||||
auto showThumbnailSetting =
|
auto showThumbnailSetting =
|
||||||
getSettings()->emotesTooltipPreview.getValue();
|
getSettings()->emotesTooltipPreview.getEnum();
|
||||||
|
|
||||||
bool showThumbnail =
|
bool showThumbnail =
|
||||||
showThumbnailSetting == ThumbnailPreviewMode::AlwaysShow ||
|
showThumbnailSetting == ThumbnailPreviewMode::AlwaysShow ||
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include "Application.hpp"
|
#include "Application.hpp"
|
||||||
#include "common/Literals.hpp"
|
#include "common/Literals.hpp"
|
||||||
#include "common/QLogging.hpp"
|
#include "common/QLogging.hpp"
|
||||||
|
#include "common/ThumbnailPreviewMode.hpp"
|
||||||
#include "common/Version.hpp"
|
#include "common/Version.hpp"
|
||||||
#include "controllers/hotkeys/HotkeyCategory.hpp"
|
#include "controllers/hotkeys/HotkeyCategory.hpp"
|
||||||
#include "controllers/hotkeys/HotkeyController.hpp"
|
#include "controllers/hotkeys/HotkeyController.hpp"
|
||||||
@@ -552,29 +553,8 @@ void GeneralPage::initLayout(GeneralPageView &layout)
|
|||||||
s.showLastMessageIndicator, false,
|
s.showLastMessageIndicator, false,
|
||||||
"Adds an underline below the most recent message "
|
"Adds an underline below the most recent message "
|
||||||
"sent before you tabbed out of Chatterino.");
|
"sent before you tabbed out of Chatterino.");
|
||||||
layout.addDropdown<std::underlying_type_t<Qt::BrushStyle>>(
|
|
||||||
"Line style", {"Dotted", "Solid"}, s.lastMessagePattern,
|
SettingWidget::dropdown("Line style", s.lastMessagePattern)->addTo(layout);
|
||||||
[](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::colorButton("Line color", s.lastMessageColor)->addTo(layout);
|
SettingWidget::colorButton("Line color", s.lastMessageColor)->addTo(layout);
|
||||||
|
|
||||||
@@ -634,30 +614,11 @@ void GeneralPage::initLayout(GeneralPageView &layout)
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
false);
|
false);
|
||||||
layout.addDropdown<std::underlying_type_t<ThumbnailPreviewMode>>(
|
|
||||||
"Show emote & badge thumbnail on hover",
|
SettingWidget::dropdown("Show emote & badge thumbnail on hover",
|
||||||
{
|
s.emotesTooltipPreview)
|
||||||
"Don't show",
|
->addTo(layout);
|
||||||
"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("Emote & badge thumbnail size on hover",
|
SettingWidget::dropdown("Emote & badge thumbnail size on hover",
|
||||||
s.emoteTooltipScale)
|
s.emoteTooltipScale)
|
||||||
->addTo(layout);
|
->addTo(layout);
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
#include "widgets/settingspages/SettingWidget.hpp"
|
#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 "util/RapidJsonSerializeQString.hpp" // IWYU pragma: keep
|
||||||
#include "widgets/dialogs/ColorPickerDialog.hpp"
|
#include "widgets/dialogs/ColorPickerDialog.hpp"
|
||||||
#include "widgets/helper/color/ColorButton.hpp"
|
#include "widgets/helper/color/ColorButton.hpp"
|
||||||
@@ -230,6 +232,83 @@ template SettingWidget *SettingWidget::dropdown<ShowModerationState>(
|
|||||||
template SettingWidget *SettingWidget::dropdown<EmojiStyle>(
|
template SettingWidget *SettingWidget::dropdown<EmojiStyle>(
|
||||||
const QString &label, EnumStringSetting<EmojiStyle> &setting);
|
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,
|
SettingWidget *SettingWidget::colorButton(const QString &label,
|
||||||
QStringSetting &setting)
|
QStringSetting &setting)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,10 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "common/ChatterinoSetting.hpp"
|
#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 <pajlada/signals/signalholder.hpp>
|
||||||
#include <QBoxLayout>
|
#include <QBoxLayout>
|
||||||
@@ -18,6 +14,9 @@
|
|||||||
#include <QtContainerFwd>
|
#include <QtContainerFwd>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
class QFormLayout;
|
class QFormLayout;
|
||||||
|
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
@@ -57,6 +56,10 @@ public:
|
|||||||
static SettingWidget *dropdown(const QString &label,
|
static SettingWidget *dropdown(const QString &label,
|
||||||
EnumStringSetting<T> &setting);
|
EnumStringSetting<T> &setting);
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
static SettingWidget *dropdown(const QString &label,
|
||||||
|
EnumSetting<T> &setting);
|
||||||
|
|
||||||
static SettingWidget *colorButton(const QString &label,
|
static SettingWidget *colorButton(const QString &label,
|
||||||
QStringSetting &setting);
|
QStringSetting &setting);
|
||||||
static SettingWidget *lineEdit(const QString &label,
|
static SettingWidget *lineEdit(const QString &label,
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include "common/FlagsEnum.hpp"
|
#include "common/FlagsEnum.hpp"
|
||||||
#include "common/Literals.hpp"
|
#include "common/Literals.hpp"
|
||||||
|
#include "common/ThumbnailPreviewMode.hpp"
|
||||||
#include "Test.hpp"
|
#include "Test.hpp"
|
||||||
#include "util/QMagicEnumTagged.hpp"
|
#include "util/QMagicEnumTagged.hpp"
|
||||||
|
|
||||||
@@ -257,4 +258,8 @@ TEST(QMagicEnumTagged, enumDisplayNameString)
|
|||||||
|
|
||||||
auto secondWithSpec = enumName<MyCustom::Second>();
|
auto secondWithSpec = enumName<MyCustom::Second>();
|
||||||
ASSERT_EQ(secondWithSpec, u"mysecond.*");
|
ASSERT_EQ(secondWithSpec, u"mysecond.*");
|
||||||
|
|
||||||
|
ASSERT_EQ(
|
||||||
|
qmagicenum::enumDisplayNameString<ThumbnailPreviewMode::DontShow>(),
|
||||||
|
u"Don't show");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user