mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
Compare commits
5 commits
cc0820c2a4
...
7b5e33de69
Author | SHA1 | Date | |
---|---|---|---|
7b5e33de69 | |||
18c4815ad7 | |||
f54bdf939a | |||
adf124c11b | |||
74101d40f5 |
|
@ -7,7 +7,7 @@
|
|||
- Major: Improve high-DPI support on Windows. (#4868, #5391, #5664, #5666)
|
||||
- Major: Added transparent overlay window (default keybind: <kbd>CTRL</kbd> + <kbd>ALT</kbd> + <kbd>N</kbd>). (#4746, #5643, #5659)
|
||||
- Minor: Removed the Ctrl+Shift+L hotkey for toggling the "live only" tab visibility state. (#5530)
|
||||
- Minor: Add support for Shared Chat messages. Shared chat messages can be filtered with the `flags.shared` filter variable, or with search using `is:shared`. Some messages like subscriptions are filtered on purpose to avoid confusion for the broadcaster. If you have both channels participating in Shared Chat open, only one of the message triggering your highlight will trigger. (#5606, #5625)
|
||||
- Minor: Add support for Shared Chat messages. Shared chat messages can be filtered with the `flags.shared` filter variable, or with search using `is:shared`. Some messages like subscriptions are filtered on purpose to avoid confusion for the broadcaster. If you have both channels participating in Shared Chat open, only one of the message triggering your highlight will trigger. (#5606, #5625, #5661)
|
||||
- Minor: Moved tab visibility control to a submenu, without any toggle actions. (#5530)
|
||||
- Minor: Add option to customise Moderation buttons with images. (#5369)
|
||||
- Minor: Colored usernames now update on the fly when changing the "Color @usernames" setting. (#5300)
|
||||
|
@ -70,6 +70,7 @@
|
|||
- Dev: Refactor and document `Scrollbar`. (#5334, #5393)
|
||||
- Dev: Refactor `TwitchIrcServer`, making it abstracted. (#5421, #5435)
|
||||
- Dev: Reduced the amount of scale events. (#5404, #5406)
|
||||
- Dev: Refactored settings widget creation. (#5585)
|
||||
- Dev: Removed unused timegate settings. (#5361)
|
||||
- Dev: Add `Channel::addSystemMessage` helper function, allowing us to avoid the common `channel->addMessage(makeSystemMessage(...));` pattern. (#5500)
|
||||
- Dev: Unsingletonize `Resources2`. (#5460)
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include "common/Args.hpp"
|
||||
#include "mocks/DisabledStreamerMode.hpp"
|
||||
#include "mocks/EmptyApplication.hpp"
|
||||
#include "mocks/TwitchUsers.hpp"
|
||||
#include "providers/bttv/BttvLiveUpdates.hpp"
|
||||
#include "singletons/Fonts.hpp"
|
||||
#include "singletons/Settings.hpp"
|
||||
|
@ -55,6 +56,11 @@ public:
|
|||
return &this->fonts;
|
||||
}
|
||||
|
||||
ITwitchUsers *getTwitchUsers() override
|
||||
{
|
||||
return &this->twitchUsers;
|
||||
}
|
||||
|
||||
BttvLiveUpdates *getBttvLiveUpdates() override
|
||||
{
|
||||
return nullptr;
|
||||
|
@ -71,6 +77,7 @@ public:
|
|||
DisabledStreamerMode streamerMode;
|
||||
Theme theme;
|
||||
Fonts fonts;
|
||||
TwitchUsers twitchUsers;
|
||||
};
|
||||
|
||||
} // namespace chatterino::mock
|
||||
|
|
24
mocks/include/mocks/TwitchUsers.hpp
Normal file
24
mocks/include/mocks/TwitchUsers.hpp
Normal file
|
@ -0,0 +1,24 @@
|
|||
#pragma once
|
||||
|
||||
#include "providers/twitch/TwitchUser.hpp"
|
||||
#include "providers/twitch/TwitchUsers.hpp"
|
||||
|
||||
namespace chatterino::mock {
|
||||
|
||||
class TwitchUsers : public ITwitchUsers
|
||||
{
|
||||
public:
|
||||
TwitchUsers() = default;
|
||||
|
||||
std::shared_ptr<TwitchUser> resolveID(const UserId &id)
|
||||
{
|
||||
TwitchUser u = {
|
||||
.id = id.string,
|
||||
.name = {},
|
||||
.displayName = {},
|
||||
};
|
||||
return std::make_shared<TwitchUser>(u);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace chatterino::mock
|
|
@ -61,6 +61,11 @@ chatterino--DescriptionLabel {
|
|||
color: #999;
|
||||
}
|
||||
|
||||
QLabel#description {
|
||||
color: #999;
|
||||
padding-left: 10px;
|
||||
}
|
||||
|
||||
chatterino--NavigationLabel {
|
||||
font-family: "Segoe UI light";
|
||||
font-size: 15px;
|
||||
|
|
BIN
resources/twitch/sharedChat.png
Normal file
BIN
resources/twitch/sharedChat.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1 KiB |
|
@ -713,6 +713,8 @@ set(SOURCE_FILES
|
|||
widgets/settingspages/PluginsPage.hpp
|
||||
widgets/settingspages/SettingsPage.cpp
|
||||
widgets/settingspages/SettingsPage.hpp
|
||||
widgets/settingspages/SettingWidget.cpp
|
||||
widgets/settingspages/SettingWidget.hpp
|
||||
|
||||
widgets/splits/ClosedSplits.cpp
|
||||
widgets/splits/ClosedSplits.hpp
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include "providers/twitch/TwitchChannel.hpp"
|
||||
#include "providers/twitch/TwitchIrc.hpp"
|
||||
#include "providers/twitch/TwitchIrcServer.hpp"
|
||||
#include "providers/twitch/TwitchUsers.hpp"
|
||||
#include "singletons/Emotes.hpp"
|
||||
#include "singletons/Resources.hpp"
|
||||
#include "singletons/Settings.hpp"
|
||||
|
@ -380,6 +381,18 @@ EmotePtr makeAutoModBadge()
|
|||
Url{"https://dashboard.twitch.tv/settings/moderation/automod"}});
|
||||
}
|
||||
|
||||
EmotePtr makeSharedChatBadge(const QString &sourceName)
|
||||
{
|
||||
return std::make_shared<Emote>(Emote{
|
||||
.name = EmoteName{},
|
||||
.images = ImageSet{Image::fromResourcePixmap(
|
||||
getResources().twitch.sharedChat, 0.25)},
|
||||
.tooltip = Tooltip{"Shared Message" +
|
||||
(sourceName.isEmpty() ? "" : " from " + sourceName)},
|
||||
.homePage = Url{"https://link.twitch.tv/SharedChatViewer"},
|
||||
});
|
||||
}
|
||||
|
||||
std::tuple<std::optional<EmotePtr>, MessageElementFlags, bool> parseEmote(
|
||||
TwitchChannel *twitchChannel, const EmoteName &name)
|
||||
{
|
||||
|
@ -2751,6 +2764,28 @@ void MessageBuilder::appendTwitchBadges(const QVariantMap &tags,
|
|||
return;
|
||||
}
|
||||
|
||||
if (this->message().flags.has(MessageFlag::SharedMessage))
|
||||
{
|
||||
const QString sourceId = tags["source-room-id"].toString();
|
||||
QString sourceName;
|
||||
if (sourceId.isEmpty())
|
||||
{
|
||||
sourceName = "";
|
||||
}
|
||||
else if (twitchChannel->roomId() == sourceId)
|
||||
{
|
||||
sourceName = twitchChannel->getName();
|
||||
}
|
||||
else
|
||||
{
|
||||
sourceName =
|
||||
getApp()->getTwitchUsers()->resolveID({sourceId})->displayName;
|
||||
}
|
||||
|
||||
this->emplace<BadgeElement>(makeSharedChatBadge(sourceName),
|
||||
MessageElementFlag::BadgeSharedChannel);
|
||||
}
|
||||
|
||||
auto badgeInfos = parseBadgeInfoTag(tags);
|
||||
auto badges = parseBadgeTag(tags);
|
||||
appendBadges(this, badges, badgeInfos, twitchChannel);
|
||||
|
|
|
@ -66,6 +66,10 @@ enum class MessageElementFlag : int64_t {
|
|||
BitsStatic = (1LL << 11),
|
||||
BitsAnimated = (1LL << 12),
|
||||
|
||||
// Slot 0: Twitch
|
||||
// - Shared Channel indicator badge
|
||||
BadgeSharedChannel = (1LL << 37),
|
||||
|
||||
// Slot 1: Twitch
|
||||
// - Staff badge
|
||||
// - Admin badge
|
||||
|
@ -119,7 +123,7 @@ enum class MessageElementFlag : int64_t {
|
|||
|
||||
Badges = BadgeGlobalAuthority | BadgePredictions | BadgeChannelAuthority |
|
||||
BadgeSubscription | BadgeVanity | BadgeChatterino | BadgeSevenTV |
|
||||
BadgeFfz,
|
||||
BadgeFfz | BadgeSharedChannel,
|
||||
|
||||
ChannelName = (1LL << 20),
|
||||
|
||||
|
|
|
@ -195,6 +195,7 @@ void WindowManager::updateWordTypeMask()
|
|||
flags.set(settings->animateEmotes ? MEF::BitsAnimated : MEF::BitsStatic);
|
||||
|
||||
// badges
|
||||
flags.set(MEF::BadgeSharedChannel);
|
||||
flags.set(settings->showBadgesGlobalAuthority ? MEF::BadgeGlobalAuthority
|
||||
: MEF::None);
|
||||
flags.set(settings->showBadgesPredictions ? MEF::BadgePredictions
|
||||
|
|
|
@ -2408,6 +2408,11 @@ void ChannelView::handleMouseClick(QMouseEvent *event,
|
|||
return;
|
||||
}
|
||||
|
||||
if (link.value.startsWith("id:"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Insert @username into split input
|
||||
const bool commaMention =
|
||||
getSettings()->mentionUsersWithComma;
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "util/IncognitoBrowser.hpp"
|
||||
#include "widgets/BaseWindow.hpp"
|
||||
#include "widgets/settingspages/GeneralPageView.hpp"
|
||||
#include "widgets/settingspages/SettingWidget.hpp"
|
||||
|
||||
#include <magic_enum/magic_enum.hpp>
|
||||
#include <QDesktopServices>
|
||||
|
@ -265,10 +266,13 @@ void GeneralPage::initLayout(GeneralPageView &layout)
|
|||
},
|
||||
false, "Choose which tabs are visible in the notebook");
|
||||
|
||||
layout.addCheckbox(
|
||||
"Show message reply context", s.hideReplyContext, true,
|
||||
"This setting will only affect how messages are shown. You can reply "
|
||||
"to a message regardless of this setting.");
|
||||
SettingWidget::inverseCheckbox("Show message reply context",
|
||||
s.hideReplyContext)
|
||||
->setTooltip(
|
||||
"This setting will only affect how messages are shown. You can "
|
||||
"reply to a message regardless of this setting.")
|
||||
->addTo(layout);
|
||||
|
||||
layout.addCheckbox("Show message reply button", s.showReplyButton, false,
|
||||
"Show a reply button next to every chat message");
|
||||
|
||||
|
@ -614,10 +618,19 @@ void GeneralPage::initLayout(GeneralPageView &layout)
|
|||
"Google",
|
||||
},
|
||||
s.emojiSet);
|
||||
layout.addCheckbox("Show BTTV global emotes", s.enableBTTVGlobalEmotes);
|
||||
layout.addCheckbox("Show BTTV channel emotes", s.enableBTTVChannelEmotes);
|
||||
layout.addCheckbox("Enable BTTV live emote updates (requires restart)",
|
||||
s.enableBTTVLiveUpdates);
|
||||
SettingWidget::checkbox("Show BetterTTV global emotes",
|
||||
s.enableBTTVGlobalEmotes)
|
||||
->addKeywords({"bttv"})
|
||||
->addTo(layout);
|
||||
SettingWidget::checkbox("Show BetterTTV channel emotes",
|
||||
s.enableBTTVChannelEmotes)
|
||||
->addKeywords({"bttv"})
|
||||
->addTo(layout);
|
||||
SettingWidget::checkbox(
|
||||
"Enable BetterTTV live emote updates (requires restart)",
|
||||
s.enableBTTVLiveUpdates)
|
||||
->addKeywords({"bttv"})
|
||||
->addTo(layout);
|
||||
layout.addCheckbox("Show FFZ global emotes", s.enableFFZGlobalEmotes);
|
||||
layout.addCheckbox("Show FFZ channel emotes", s.enableFFZChannelEmotes);
|
||||
layout.addCheckbox("Show 7TV global emotes", s.enableSevenTVGlobalEmotes);
|
||||
|
@ -1063,10 +1076,11 @@ void GeneralPage::initLayout(GeneralPageView &layout)
|
|||
false,
|
||||
"Make all clickable links lowercase to deter "
|
||||
"phishing attempts.");
|
||||
layout.addCheckbox(
|
||||
"Show user's pronouns in user card", s.showPronouns, false,
|
||||
"Shows users' pronouns in their user card. "
|
||||
"Pronouns are retrieved from alejo.io when the user card is opened.");
|
||||
SettingWidget::checkbox("Show user's pronouns in user card", s.showPronouns)
|
||||
->setDescription(
|
||||
R"(Pronouns are retrieved from <a href="https://pr.alejo.io">pr.alejo.io</a> when a user card is opened.)")
|
||||
->addTo(layout);
|
||||
|
||||
layout.addCheckbox("Bold @usernames", s.boldUsernames, false,
|
||||
"Bold @mentions to make them more noticable.");
|
||||
layout.addCheckbox("Color @usernames", s.colorUsernames, false,
|
||||
|
@ -1191,25 +1205,20 @@ void GeneralPage::initLayout(GeneralPageView &layout)
|
|||
"@mention for the related thread. If the reply context is hidden, "
|
||||
"these mentions will never be stripped.");
|
||||
|
||||
layout.addDropdownEnumClass<ChatSendProtocol>(
|
||||
"Chat send protocol", qmagicenum::enumNames<ChatSendProtocol>(),
|
||||
s.chatSendProtocol,
|
||||
"'Helix' will use Twitch's Helix API to send message. 'IRC' will use "
|
||||
"IRC to send messages.",
|
||||
{});
|
||||
SettingWidget::dropdown("Chat send protocol", s.chatSendProtocol)
|
||||
->setTooltip("'Helix' will use Twitch's Helix API to send message. "
|
||||
"'IRC' will use IRC to send messages.")
|
||||
->addTo(layout);
|
||||
|
||||
layout.addCheckbox(
|
||||
"Show send message button", s.showSendButton, false,
|
||||
"Show a Send button next to each split input that can be "
|
||||
"clicked to send the message");
|
||||
SettingWidget::checkbox("Show send message button", s.showSendButton)
|
||||
->setTooltip("Show a Send button next to each split input that can be "
|
||||
"clicked to send the message")
|
||||
->addTo(layout);
|
||||
|
||||
auto *soundBackend = layout.addDropdownEnumClass<SoundBackend>(
|
||||
"Sound backend (requires restart)",
|
||||
qmagicenum::enumNames<SoundBackend>(), s.soundBackend,
|
||||
"Change this only if you're noticing issues with sound playback on "
|
||||
"your system",
|
||||
{});
|
||||
soundBackend->setMinimumWidth(soundBackend->minimumSizeHint().width());
|
||||
SettingWidget::dropdown("Sound backend (requires restart)", s.soundBackend)
|
||||
->setTooltip("Change this only if you're noticing issues "
|
||||
"with sound playback on your system")
|
||||
->addTo(layout);
|
||||
|
||||
layout.addStretch();
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include "widgets/dialogs/ColorPickerDialog.hpp"
|
||||
#include "widgets/helper/color/ColorButton.hpp"
|
||||
#include "widgets/helper/Line.hpp"
|
||||
#include "widgets/settingspages/SettingWidget.hpp"
|
||||
|
||||
#include <QRegularExpression>
|
||||
#include <QScrollArea>
|
||||
|
@ -44,9 +45,16 @@ GeneralPageView::GeneralPageView(QWidget *parent)
|
|||
});
|
||||
}
|
||||
|
||||
void GeneralPageView::addWidget(QWidget *widget)
|
||||
void GeneralPageView::addWidget(QWidget *widget, QStringList keywords)
|
||||
{
|
||||
this->contentLayout_->addWidget(widget);
|
||||
if (!keywords.isEmpty())
|
||||
{
|
||||
this->groups_.back().widgets.push_back({
|
||||
.element = widget,
|
||||
.keywords = keywords,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void GeneralPageView::addLayout(QLayout *layout)
|
||||
|
@ -376,11 +384,10 @@ bool GeneralPageView::filterElements(const QString &query)
|
|||
currentSubtitleVisible = true;
|
||||
widget.element->show();
|
||||
groupAny = true;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
widget.element->hide();
|
||||
}
|
||||
|
||||
widget.element->hide();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ class QScrollArea;
|
|||
namespace chatterino {
|
||||
|
||||
class ColorButton;
|
||||
class SettingWidget;
|
||||
|
||||
class Space : public QLabel
|
||||
{
|
||||
|
@ -95,7 +96,7 @@ class GeneralPageView : public QWidget
|
|||
public:
|
||||
GeneralPageView(QWidget *parent = nullptr);
|
||||
|
||||
void addWidget(QWidget *widget);
|
||||
void addWidget(QWidget *widget, QStringList keywords = {});
|
||||
void addLayout(QLayout *layout);
|
||||
void addStretch();
|
||||
|
||||
|
@ -274,50 +275,6 @@ public:
|
|||
return combo;
|
||||
}
|
||||
|
||||
template <typename T, std::size_t N>
|
||||
ComboBox *addDropdownEnumClass(const QString &text,
|
||||
const std::array<QStringView, N> &items,
|
||||
EnumStringSetting<T> &setting,
|
||||
QString toolTipText,
|
||||
const QString &defaultValueText)
|
||||
{
|
||||
auto *combo = this->addDropdown(text, {}, std::move(toolTipText));
|
||||
|
||||
for (const auto &item : items)
|
||||
{
|
||||
combo->addItem(item.toString());
|
||||
}
|
||||
|
||||
if (!defaultValueText.isEmpty())
|
||||
{
|
||||
combo->setCurrentText(defaultValueText);
|
||||
}
|
||||
|
||||
setting.connect(
|
||||
[&setting, combo](const QString &value) {
|
||||
auto enumValue =
|
||||
qmagicenum::enumCast<T>(value, qmagicenum::CASE_INSENSITIVE)
|
||||
.value_or(setting.defaultValue);
|
||||
|
||||
auto i = magic_enum::enum_integer(enumValue);
|
||||
|
||||
combo->setCurrentIndex(i);
|
||||
},
|
||||
this->managedConnections_);
|
||||
|
||||
QObject::connect(
|
||||
combo, &QComboBox::currentTextChanged,
|
||||
[&setting](const auto &newText) {
|
||||
// The setter for EnumStringSetting does not check that this value is valid
|
||||
// Instead, it's up to the getters to make sure that the setting is legic - see the enum_cast above
|
||||
// You could also use the settings `getEnum` function
|
||||
setting = newText;
|
||||
getApp()->getWindows()->forceLayoutChannelViews();
|
||||
});
|
||||
|
||||
return combo;
|
||||
}
|
||||
|
||||
void enableIf(QComboBox *widget, auto &setting, auto cb)
|
||||
{
|
||||
auto updateVisibility = [cb = std::move(cb), &setting, widget]() {
|
||||
|
|
144
src/widgets/settingspages/SettingWidget.cpp
Normal file
144
src/widgets/settingspages/SettingWidget.cpp
Normal file
|
@ -0,0 +1,144 @@
|
|||
#include "widgets/settingspages/SettingWidget.hpp"
|
||||
|
||||
#include "widgets/settingspages/GeneralPageView.hpp"
|
||||
|
||||
#include <QBoxLayout>
|
||||
#include <QCheckBox>
|
||||
#include <QLabel>
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr int MAX_TOOLTIP_LINE_LENGTH = 50;
|
||||
const auto MAX_TOOLTIP_LINE_LENGTH_PATTERN =
|
||||
QStringLiteral(R"(.{%1}\S*\K(\s+))").arg(MAX_TOOLTIP_LINE_LENGTH);
|
||||
const QRegularExpression MAX_TOOLTIP_LINE_LENGTH_REGEX(
|
||||
MAX_TOOLTIP_LINE_LENGTH_PATTERN);
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
SettingWidget::SettingWidget(const QString &mainKeyword)
|
||||
: vLayout(new QVBoxLayout(this))
|
||||
, hLayout(new QHBoxLayout)
|
||||
{
|
||||
this->vLayout->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
this->hLayout->setContentsMargins(0, 0, 0, 0);
|
||||
this->vLayout->addLayout(hLayout);
|
||||
|
||||
this->keywords.append(mainKeyword);
|
||||
}
|
||||
|
||||
SettingWidget *SettingWidget::checkbox(const QString &label,
|
||||
BoolSetting &setting)
|
||||
{
|
||||
auto *widget = new SettingWidget(label);
|
||||
|
||||
auto *check = new QCheckBox(label);
|
||||
|
||||
widget->hLayout->addWidget(check);
|
||||
|
||||
// update when setting changes
|
||||
setting.connect(
|
||||
[check](const bool &value, auto) {
|
||||
check->setChecked(value);
|
||||
},
|
||||
widget->managedConnections);
|
||||
|
||||
// update setting on toggle
|
||||
QObject::connect(check, &QCheckBox::toggled, widget,
|
||||
[&setting](bool state) {
|
||||
setting = state;
|
||||
});
|
||||
|
||||
widget->actionWidget = check;
|
||||
widget->label = check;
|
||||
|
||||
return widget;
|
||||
}
|
||||
|
||||
SettingWidget *SettingWidget::inverseCheckbox(const QString &label,
|
||||
BoolSetting &setting)
|
||||
{
|
||||
auto *widget = new SettingWidget(label);
|
||||
|
||||
auto *check = new QCheckBox(label);
|
||||
|
||||
widget->hLayout->addWidget(check);
|
||||
|
||||
// update when setting changes
|
||||
setting.connect(
|
||||
[check](const bool &value, auto) {
|
||||
check->setChecked(!value);
|
||||
},
|
||||
widget->managedConnections);
|
||||
|
||||
// update setting on toggle
|
||||
QObject::connect(check, &QCheckBox::toggled, widget,
|
||||
[&setting](bool state) {
|
||||
setting = !state;
|
||||
});
|
||||
|
||||
widget->actionWidget = check;
|
||||
widget->label = check;
|
||||
|
||||
return widget;
|
||||
}
|
||||
|
||||
SettingWidget *SettingWidget::setTooltip(QString tooltip)
|
||||
{
|
||||
assert(!tooltip.isEmpty());
|
||||
|
||||
if (tooltip.length() > MAX_TOOLTIP_LINE_LENGTH)
|
||||
{
|
||||
// match MAX_TOOLTIP_LINE_LENGTH characters, any remaining
|
||||
// non-space, and then capture the following space for
|
||||
// replacement with newline
|
||||
tooltip.replace(MAX_TOOLTIP_LINE_LENGTH_REGEX, "\n");
|
||||
}
|
||||
|
||||
if (this->label != nullptr)
|
||||
{
|
||||
this->label->setToolTip(tooltip);
|
||||
}
|
||||
|
||||
if (this->actionWidget != nullptr)
|
||||
{
|
||||
this->actionWidget->setToolTip(tooltip);
|
||||
}
|
||||
|
||||
this->keywords.append(tooltip);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
SettingWidget *SettingWidget::setDescription(const QString &text)
|
||||
{
|
||||
auto *lbl = new QLabel(text);
|
||||
lbl->setTextInteractionFlags(Qt::TextBrowserInteraction |
|
||||
Qt::LinksAccessibleByKeyboard);
|
||||
lbl->setOpenExternalLinks(true);
|
||||
lbl->setWordWrap(true);
|
||||
lbl->setObjectName("description");
|
||||
|
||||
this->vLayout->insertWidget(0, lbl);
|
||||
|
||||
this->keywords.append(text);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
SettingWidget *SettingWidget::addKeywords(const QStringList &newKeywords)
|
||||
{
|
||||
this->keywords.append(newKeywords);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
void SettingWidget::addTo(GeneralPageView &view)
|
||||
{
|
||||
view.addWidget(this, this->keywords);
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
106
src/widgets/settingspages/SettingWidget.hpp
Normal file
106
src/widgets/settingspages/SettingWidget.hpp
Normal file
|
@ -0,0 +1,106 @@
|
|||
#pragma once
|
||||
|
||||
#include "common/ChatterinoSetting.hpp"
|
||||
#include "util/QMagicEnum.hpp"
|
||||
#include "widgets/settingspages/GeneralPageView.hpp"
|
||||
|
||||
#include <pajlada/signals/signalholder.hpp>
|
||||
#include <QBoxLayout>
|
||||
#include <QComboBox>
|
||||
#include <QLabel>
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QtContainerFwd>
|
||||
#include <QWidget>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class GeneralPageView;
|
||||
|
||||
class SettingWidget : QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
explicit SettingWidget(const QString &mainKeyword);
|
||||
|
||||
public:
|
||||
~SettingWidget() override = default;
|
||||
SettingWidget &operator=(const SettingWidget &) = delete;
|
||||
SettingWidget &operator=(SettingWidget &&) = delete;
|
||||
SettingWidget(const SettingWidget &other) = delete;
|
||||
SettingWidget(SettingWidget &&other) = delete;
|
||||
|
||||
static SettingWidget *checkbox(const QString &label, BoolSetting &setting);
|
||||
static SettingWidget *inverseCheckbox(const QString &label,
|
||||
BoolSetting &setting);
|
||||
template <typename T>
|
||||
static SettingWidget *dropdown(const QString &label,
|
||||
EnumStringSetting<T> &setting)
|
||||
{
|
||||
auto *widget = new SettingWidget(label);
|
||||
|
||||
auto *lbl = new QLabel(label % ":");
|
||||
auto *combo = new ComboBox;
|
||||
combo->setFocusPolicy(Qt::StrongFocus);
|
||||
for (const auto &item : qmagicenum::enumNames<T>())
|
||||
{
|
||||
combo->addItem(item.toString());
|
||||
}
|
||||
// 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(
|
||||
[&setting, combo](const QString &value) {
|
||||
auto enumValue =
|
||||
qmagicenum::enumCast<T>(value, qmagicenum::CASE_INSENSITIVE)
|
||||
.value_or(setting.defaultValue);
|
||||
|
||||
auto i = magic_enum::enum_integer(enumValue);
|
||||
|
||||
combo->setCurrentIndex(i);
|
||||
},
|
||||
widget->managedConnections);
|
||||
|
||||
QObject::connect(
|
||||
combo, &QComboBox::currentTextChanged,
|
||||
[&setting](const auto &newText) {
|
||||
// The setter for EnumStringSetting does not check that this value is valid
|
||||
// Instead, it's up to the getters to make sure that the setting is legic - see the enum_cast above
|
||||
// You could also use the settings `getEnum` function
|
||||
setting = newText;
|
||||
});
|
||||
|
||||
return widget;
|
||||
}
|
||||
|
||||
SettingWidget *setTooltip(QString tooltip);
|
||||
SettingWidget *setDescription(const QString &text);
|
||||
|
||||
/// Add extra keywords to the widget
|
||||
///
|
||||
/// All text from the tooltip, description, and label are already keywords
|
||||
SettingWidget *addKeywords(const QStringList &newKeywords);
|
||||
|
||||
void addTo(GeneralPageView &view);
|
||||
|
||||
private:
|
||||
QWidget *label = nullptr;
|
||||
QWidget *actionWidget = nullptr;
|
||||
|
||||
QVBoxLayout *vLayout;
|
||||
QHBoxLayout *hLayout;
|
||||
|
||||
pajlada::Signals::SignalHolder managedConnections;
|
||||
|
||||
QStringList keywords;
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
|
@ -64,6 +64,24 @@
|
|||
"trailingSpace": true,
|
||||
"type": "TwitchModerationElement"
|
||||
},
|
||||
{
|
||||
"emote": {
|
||||
"homePage": "https://link.twitch.tv/SharedChatViewer",
|
||||
"images": {
|
||||
"1x": ""
|
||||
},
|
||||
"name": "",
|
||||
"tooltip": "Shared Message"
|
||||
},
|
||||
"flags": "BadgeSharedChannel",
|
||||
"link": {
|
||||
"type": "None",
|
||||
"value": ""
|
||||
},
|
||||
"tooltip": "Shared Message",
|
||||
"trailingSpace": true,
|
||||
"type": "BadgeElement"
|
||||
},
|
||||
{
|
||||
"emote": {
|
||||
"homePage": "https://www.twitch.tv/jobs?ref=chat_badge",
|
||||
|
|
|
@ -64,6 +64,24 @@
|
|||
"trailingSpace": true,
|
||||
"type": "TwitchModerationElement"
|
||||
},
|
||||
{
|
||||
"emote": {
|
||||
"homePage": "https://link.twitch.tv/SharedChatViewer",
|
||||
"images": {
|
||||
"1x": ""
|
||||
},
|
||||
"name": "",
|
||||
"tooltip": "Shared Message from twitchdev"
|
||||
},
|
||||
"flags": "BadgeSharedChannel",
|
||||
"link": {
|
||||
"type": "None",
|
||||
"value": ""
|
||||
},
|
||||
"tooltip": "Shared Message from twitchdev",
|
||||
"trailingSpace": true,
|
||||
"type": "BadgeElement"
|
||||
},
|
||||
{
|
||||
"color": "#ffff0000",
|
||||
"flags": "Username",
|
||||
|
|
|
@ -64,6 +64,24 @@
|
|||
"trailingSpace": true,
|
||||
"type": "TwitchModerationElement"
|
||||
},
|
||||
{
|
||||
"emote": {
|
||||
"homePage": "https://link.twitch.tv/SharedChatViewer",
|
||||
"images": {
|
||||
"1x": ""
|
||||
},
|
||||
"name": "",
|
||||
"tooltip": "Shared Message from twitchdev"
|
||||
},
|
||||
"flags": "BadgeSharedChannel",
|
||||
"link": {
|
||||
"type": "None",
|
||||
"value": ""
|
||||
},
|
||||
"tooltip": "Shared Message from twitchdev",
|
||||
"trailingSpace": true,
|
||||
"type": "BadgeElement"
|
||||
},
|
||||
{
|
||||
"emote": {
|
||||
"homePage": "https://www.twitch.tv/jobs?ref=chat_badge",
|
||||
|
|
|
@ -64,6 +64,24 @@
|
|||
"trailingSpace": true,
|
||||
"type": "TwitchModerationElement"
|
||||
},
|
||||
{
|
||||
"emote": {
|
||||
"homePage": "https://link.twitch.tv/SharedChatViewer",
|
||||
"images": {
|
||||
"1x": ""
|
||||
},
|
||||
"name": "",
|
||||
"tooltip": "Shared Message"
|
||||
},
|
||||
"flags": "BadgeSharedChannel",
|
||||
"link": {
|
||||
"type": "None",
|
||||
"value": ""
|
||||
},
|
||||
"tooltip": "Shared Message",
|
||||
"trailingSpace": true,
|
||||
"type": "BadgeElement"
|
||||
},
|
||||
{
|
||||
"emote": {
|
||||
"homePage": "https://www.twitch.tv/jobs?ref=chat_badge",
|
||||
|
|
Loading…
Reference in a new issue