fix: replace defines with constexpr/const and use more absolute paths for includes (#5527)

bye bye nuuls
This commit is contained in:
nerix 2024-08-03 12:00:58 +02:00 committed by GitHub
parent 5ee5abf5b2
commit aed55ac1ba
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
83 changed files with 386 additions and 380 deletions

View file

@ -58,6 +58,7 @@
- Dev: The running Qt version is now shown in the about page if it differs from the compiled version. (#5501) - Dev: The running Qt version is now shown in the about page if it differs from the compiled version. (#5501)
- Dev: `FlagsEnum` is now `constexpr`. (#5510) - Dev: `FlagsEnum` is now `constexpr`. (#5510)
- Dev: Documented and added tests to RTL handling. (#5473) - Dev: Documented and added tests to RTL handling. (#5473)
- Dev: Refactored a few `#define`s into `const(expr)` and cleaned includes. (#5527)
## 2.5.1 ## 2.5.1

View file

@ -1,4 +1,4 @@
#include "ChannelChatters.hpp" #include "common/ChannelChatters.hpp"
#include "common/Channel.hpp" #include "common/Channel.hpp"
#include "messages/Message.hpp" #include "messages/Message.hpp"

View file

@ -5,17 +5,17 @@
#include <QWidget> #include <QWidget>
#include <memory> #include <memory>
#include <optional>
#include <string>
#define LINK_CHATTERINO_WIKI "https://wiki.chatterino.com"
#define LINK_CHATTERINO_DISCORD "https://discord.gg/7Y5AYhAK4z"
#define LINK_CHATTERINO_SOURCE "https://github.com/Chatterino/chatterino2"
namespace chatterino { namespace chatterino {
const inline auto TWITCH_PLAYER_URL = constexpr QStringView LINK_CHATTERINO_WIKI = u"https://wiki.chatterino.com";
QStringLiteral("https://player.twitch.tv/?channel=%1&parent=twitch.tv"); constexpr QStringView LINK_CHATTERINO_DISCORD =
u"https://discord.gg/7Y5AYhAK4z";
constexpr QStringView LINK_CHATTERINO_SOURCE =
u"https://github.com/Chatterino/chatterino2";
constexpr QStringView TWITCH_PLAYER_URL =
u"https://player.twitch.tv/?channel=%1&parent=twitch.tv";
enum class HighlightState { enum class HighlightState {
None, None,
@ -23,21 +23,14 @@ enum class HighlightState {
NewMessage, NewMessage,
}; };
const Qt::KeyboardModifiers showSplitOverlayModifiers = constexpr Qt::KeyboardModifiers SHOW_SPLIT_OVERLAY_MODIFIERS =
Qt::ControlModifier | Qt::AltModifier; Qt::ControlModifier | Qt::AltModifier;
const Qt::KeyboardModifiers showAddSplitRegions = constexpr Qt::KeyboardModifiers SHOW_ADD_SPLIT_REGIONS =
Qt::ControlModifier | Qt::AltModifier; Qt::ControlModifier | Qt::AltModifier;
const Qt::KeyboardModifiers showResizeHandlesModifiers = Qt::ControlModifier; constexpr Qt::KeyboardModifiers SHOW_RESIZE_HANDLES_MODIFIERS =
Qt::ControlModifier;
#ifndef ATTR_UNUSED constexpr const char *ANONYMOUS_USERNAME_LABEL = " - anonymous - ";
# ifdef Q_OS_WIN
# define ATTR_UNUSED
# else
# define ATTR_UNUSED __attribute__((unused))
# endif
#endif
static const char *ANONYMOUS_USERNAME_LABEL ATTR_UNUSED = " - anonymous - ";
template <typename T> template <typename T>
std::weak_ptr<T> weakOf(T *element) std::weak_ptr<T> weakOf(T *element)

View file

@ -11,6 +11,7 @@
#include <QJsonDocument> #include <QJsonDocument>
#include <QJsonObject> #include <QJsonObject>
#include <QSaveFile> #include <QSaveFile>
#include <QStringBuilder>
#include <variant> #include <variant>
@ -26,16 +27,16 @@
# endif # endif
#endif #endif
#define FORMAT_NAME \
([&] { \
assert(!provider.contains(":")); \
return QString("chatterino:%1:%2").arg(provider).arg(name_); \
})()
namespace { namespace {
using namespace chatterino; using namespace chatterino;
QString formatName(const QString &provider, const QString &name)
{
assert(!provider.contains(":"));
return u"chatterino:" % provider % u':' % name;
}
bool useKeyring() bool useKeyring()
{ {
#ifdef NO_QTKEYCHAIN #ifdef NO_QTKEYCHAIN
@ -184,7 +185,7 @@ void Credentials::get(const QString &provider, const QString &name_,
{ {
assertInGuiThread(); assertInGuiThread();
auto name = FORMAT_NAME; auto name = formatName(provider, name_);
if (useKeyring()) if (useKeyring())
{ {
@ -219,7 +220,7 @@ void Credentials::set(const QString &provider, const QString &name_,
/// On linux, we try to use a keychain but show a message to disable it when it fails. /// On linux, we try to use a keychain but show a message to disable it when it fails.
/// XXX: add said message /// XXX: add said message
auto name = FORMAT_NAME; auto name = formatName(provider, name_);
if (useKeyring()) if (useKeyring())
{ {
@ -242,7 +243,7 @@ void Credentials::erase(const QString &provider, const QString &name_)
{ {
assertInGuiThread(); assertInGuiThread();
auto name = FORMAT_NAME; auto name = formatName(provider, name_);
if (useKeyring()) if (useKeyring())
{ {

View file

@ -1,4 +1,4 @@
#include "Modes.hpp" #include "common/Modes.hpp"
#include "util/CombinePath.hpp" #include "util/CombinePath.hpp"

View file

@ -1,7 +1,8 @@
#pragma once #pragma once
#include <QString> #include <QString>
#include <QtGlobal>
namespace chatterino {
/** /**
* Valid version formats, in order of latest to oldest * Valid version formats, in order of latest to oldest
@ -24,21 +25,7 @@
* - 2.4.0-alpha.2 * - 2.4.0-alpha.2
* - 2.4.0-alpha * - 2.4.0-alpha
**/ **/
#define CHATTERINO_VERSION "2.5.1" inline const QString CHATTERINO_VERSION = QStringLiteral("2.5.1");
#if defined(Q_OS_WIN)
# define CHATTERINO_OS "win"
#elif defined(Q_OS_MACOS)
# define CHATTERINO_OS "macos"
#elif defined(Q_OS_LINUX)
# define CHATTERINO_OS "linux"
#elif defined(Q_OS_FREEBSD)
# define CHATTERINO_OS "freebsd"
#else
# define CHATTERINO_OS "unknown"
#endif
namespace chatterino {
class Version class Version
{ {

View file

@ -1,4 +1,4 @@
#include "Account.hpp" #include "controllers/accounts/Account.hpp"
#include <tuple> #include <tuple>

View file

@ -1,4 +1,4 @@
#include "AccountModel.hpp" #include "controllers/accounts/AccountModel.hpp"
#include "controllers/accounts/Account.hpp" #include "controllers/accounts/Account.hpp"
#include "util/StandardItemHelper.hpp" #include "util/StandardItemHelper.hpp"

View file

@ -1,4 +1,4 @@
#include "Command.hpp" #include "controllers/commands/Command.hpp"
namespace chatterino { namespace chatterino {

View file

@ -1,4 +1,4 @@
#include "HighlightBadge.hpp" #include "controllers/highlights/HighlightBadge.hpp"
#include "messages/SharedMessageBuilder.hpp" #include "messages/SharedMessageBuilder.hpp"
#include "providers/twitch/TwitchBadge.hpp" #include "providers/twitch/TwitchBadge.hpp"

View file

@ -1,4 +1,4 @@
#include "NotificationModel.hpp" #include "controllers/notifications/NotificationModel.hpp"
#include "Application.hpp" #include "Application.hpp"
#include "singletons/Settings.hpp" #include "singletons/Settings.hpp"

View file

@ -1,4 +1,4 @@
#include "MutedChannelModel.hpp" #include "controllers/pings/MutedChannelModel.hpp"
#include "Application.hpp" #include "Application.hpp"
#include "singletons/Settings.hpp" #include "singletons/Settings.hpp"

View file

@ -1,4 +1,4 @@
#include "Benchmark.hpp" #include "debug/Benchmark.hpp"
#include "common/QLogging.hpp" #include "common/QLogging.hpp"

View file

@ -1,4 +1,4 @@
#include "Emote.hpp" #include "messages/Emote.hpp"
#include <unordered_map> #include <unordered_map>

View file

@ -1,4 +1,4 @@
#include "MessageBuilder.hpp" #include "messages/MessageBuilder.hpp"
#include "Application.hpp" #include "Application.hpp"
#include "common/IrcColors.hpp" #include "common/IrcColors.hpp"

View file

@ -1,4 +1,4 @@
#include "MessageColor.hpp" #include "messages/MessageColor.hpp"
#include "singletons/Theme.hpp" #include "singletons/Theme.hpp"

View file

@ -19,12 +19,6 @@
#include <QtGlobal> #include <QtGlobal>
#include <QThread> #include <QThread>
#define MARGIN_LEFT (int)(8 * this->scale)
#define MARGIN_RIGHT (int)(8 * this->scale)
#define MARGIN_TOP (int)(4 * this->scale)
#define MARGIN_BOTTOM (int)(4 * this->scale)
#define COMPACT_EMOTES_OFFSET 6
namespace chatterino { namespace chatterino {
namespace { namespace {

View file

@ -18,13 +18,17 @@
#include <optional> #include <optional>
#define COMPACT_EMOTES_OFFSET 4
#define MAX_UNCOLLAPSED_LINES \
(getSettings()->collpseMessagesMinLines.getValue())
namespace { namespace {
constexpr const QMargins MARGIN{8, 4, 8, 4}; using namespace chatterino;
constexpr QMargins MARGIN{8, 4, 8, 4};
constexpr int COMPACT_EMOTES_OFFSET = 4;
int maxUncollapsedLines()
{
return getSettings()->collpseMessagesMinLines.getValue();
}
} // namespace } // namespace
@ -208,7 +212,7 @@ void MessageLayoutContainer::breakLine()
this->lineStart_ = this->elements_.size(); this->lineStart_ = this->elements_.size();
// this->currentX = (int)(this->scale * 8); // this->currentX = (int)(this->scale * 8);
if (this->canCollapse() && this->line_ + 1 >= MAX_UNCOLLAPSED_LINES) if (this->canCollapse() && this->line_ + 1 >= maxUncollapsedLines())
{ {
this->canAddMessages_ = false; this->canAddMessages_ = false;
return; return;
@ -568,8 +572,9 @@ int MessageLayoutContainer::remainingWidth() const
{ {
return (this->width_ - int(MARGIN.left() * this->scale_) - return (this->width_ - int(MARGIN.left() * this->scale_) -
int(MARGIN.right() * this->scale_) - int(MARGIN.right() * this->scale_) -
(this->line_ + 1 == MAX_UNCOLLAPSED_LINES ? this->dotdotdotWidth_ (static_cast<int>(this->line_ + 1) == maxUncollapsedLines()
: 0)) - ? this->dotdotdotWidth_
: 0)) -
this->currentX_; this->currentX_;
} }

View file

@ -1,4 +1,4 @@
#include "RegexPredicate.hpp" #include "messages/search/RegexPredicate.hpp"
#include "messages/Message.hpp" #include "messages/Message.hpp"

View file

@ -1,8 +1,8 @@
#pragma once #pragma once
#include "messages/search/MessagePredicate.hpp" #include "messages/search/MessagePredicate.hpp"
#include "QRegularExpression"
#include <QRegularExpression>
#include <QString> #include <QString>
namespace chatterino { namespace chatterino {

View file

@ -1,4 +1,4 @@
#include "IvrApi.hpp" #include "providers/IvrApi.hpp"
#include "common/network/NetworkResult.hpp" #include "common/network/NetworkResult.hpp"
#include "common/QLogging.hpp" #include "common/QLogging.hpp"

View file

@ -64,9 +64,7 @@ struct IvrEmote {
: code(root.value("code").toString()) : code(root.value("code").toString())
, id(root.value("id").toString()) , id(root.value("id").toString())
, setId(root.value("setID").toString()) , setId(root.value("setID").toString())
, url(QString(TWITCH_EMOTE_TEMPLATE) , url(TWITCH_EMOTE_TEMPLATE.arg(this->id, u"3.0"))
.replace("{id}", this->id)
.replace("{scale}", "3.0"))
, emoteType(root.value("type").toString()) , emoteType(root.value("type").toString())
, imageType(root.value("assetType").toString()) , imageType(root.value("assetType").toString())
{ {

View file

@ -1,4 +1,4 @@
#include "AbstractIrcServer.hpp" #include "providers/irc/AbstractIrcServer.hpp"
#include "common/Channel.hpp" #include "common/Channel.hpp"
#include "common/QLogging.hpp" #include "common/QLogging.hpp"

View file

@ -1,4 +1,4 @@
#include "Irc2.hpp" #include "providers/irc/Irc2.hpp"
#include "Application.hpp" #include "Application.hpp"
#include "common/Credentials.hpp" #include "common/Credentials.hpp"

View file

@ -1,4 +1,4 @@
#include "IrcAccount.hpp" #include "providers/irc/IrcAccount.hpp"
// namespace chatterino { // namespace chatterino {
// //

View file

@ -1,4 +1,4 @@
#include "IrcChannel2.hpp" #include "providers/irc/IrcChannel2.hpp"
#include "common/Channel.hpp" #include "common/Channel.hpp"
#include "debug/AssertInGuiThread.hpp" #include "debug/AssertInGuiThread.hpp"

View file

@ -1,4 +1,4 @@
#include "IrcCommands.hpp" #include "providers/irc/IrcCommands.hpp"
#include "messages/MessageBuilder.hpp" #include "messages/MessageBuilder.hpp"
#include "providers/irc/IrcChannel2.hpp" #include "providers/irc/IrcChannel2.hpp"

View file

@ -1,4 +1,4 @@
#include "IrcConnection2.hpp" #include "providers/irc/IrcConnection2.hpp"
#include "common/QLogging.hpp" #include "common/QLogging.hpp"
#include "common/Version.hpp" #include "common/Version.hpp"
@ -11,7 +11,7 @@ namespace chatterino {
namespace { namespace {
const auto payload = QString("chatterino/" CHATTERINO_VERSION); const auto payload = "chatterino/" + CHATTERINO_VERSION;
} // namespace } // namespace

View file

@ -1,4 +1,4 @@
#include "IrcServer.hpp" #include "providers/irc/IrcServer.hpp"
#include "Application.hpp" #include "Application.hpp"
#include "common/QLogging.hpp" #include "common/QLogging.hpp"

View file

@ -1,8 +1,18 @@
#include "ChannelPointReward.hpp" #include "providers/twitch/ChannelPointReward.hpp"
#include "common/QLogging.hpp"
#include "messages/Image.hpp" #include "messages/Image.hpp"
#include <QStringBuilder>
namespace {
QString twitchChannelPointRewardUrl(const QString &file)
{
return u"https://static-cdn.jtvnw.net/custom-reward-images/default-" % file;
}
} // namespace
namespace chatterino { namespace chatterino {
ChannelPointReward::ChannelPointReward(const QJsonObject &redemption) ChannelPointReward::ChannelPointReward(const QJsonObject &redemption)
@ -94,11 +104,10 @@ ChannelPointReward::ChannelPointReward(const QJsonObject &redemption)
else else
{ {
static const ImageSet defaultImage{ static const ImageSet defaultImage{
Image::fromUrl({TWITCH_CHANNEL_POINT_REWARD_URL("1.png")}, 1, Image::fromUrl({twitchChannelPointRewardUrl("1.png")}, 1, baseSize),
baseSize), Image::fromUrl({twitchChannelPointRewardUrl("2.png")}, 0.5,
Image::fromUrl({TWITCH_CHANNEL_POINT_REWARD_URL("2.png")}, 0.5,
baseSize * 2), baseSize * 2),
Image::fromUrl({TWITCH_CHANNEL_POINT_REWARD_URL("4.png")}, 0.25, Image::fromUrl({twitchChannelPointRewardUrl("4.png")}, 0.25,
baseSize * 4)}; baseSize * 4)};
this->image = defaultImage; this->image = defaultImage;
} }

View file

@ -1,15 +1,11 @@
#pragma once #pragma once
#include "common/Aliases.hpp"
#include "messages/ImageSet.hpp" #include "messages/ImageSet.hpp"
#include <QJsonObject> #include <QJsonObject>
#define TWITCH_CHANNEL_POINT_REWARD_URL(x) \
QString("https://static-cdn.jtvnw.net/custom-reward-images/default-%1") \
.arg(x)
namespace chatterino { namespace chatterino {
struct ChannelPointReward { struct ChannelPointReward {
ChannelPointReward(const QJsonObject &redemption); ChannelPointReward(const QJsonObject &redemption);
ChannelPointReward() = delete; ChannelPointReward() = delete;

View file

@ -11,9 +11,7 @@ using namespace chatterino;
Url getEmoteLink(const EmoteId &id, const QString &emoteScale) Url getEmoteLink(const EmoteId &id, const QString &emoteScale)
{ {
return {QString(TWITCH_EMOTE_TEMPLATE) return {TWITCH_EMOTE_TEMPLATE.arg(id.string, emoteScale)};
.replace("{id}", id.string)
.replace("{scale}", emoteScale)};
} }
QSize getEmoteExpectedBaseSize(const EmoteId &id) QSize getEmoteExpectedBaseSize(const EmoteId &id)

View file

@ -10,12 +10,15 @@
#include <memory> #include <memory>
#include <unordered_map> #include <unordered_map>
namespace chatterino {
// NB: "default" can be replaced with "static" to always get a non-animated // NB: "default" can be replaced with "static" to always get a non-animated
// variant // variant
#define TWITCH_EMOTE_TEMPLATE \ /// %1 <-> {id}
"https://static-cdn.jtvnw.net/emoticons/v2/{id}/default/dark/{scale}" /// %2 <-> {scale} (1.0, 2.0, 3.0)
constexpr QStringView TWITCH_EMOTE_TEMPLATE =
u"https://static-cdn.jtvnw.net/emoticons/v2/%1/default/dark/%2";
namespace chatterino {
struct Emote; struct Emote;
using EmotePtr = std::shared_ptr<const Emote>; using EmotePtr = std::shared_ptr<const Emote>;

View file

@ -276,9 +276,7 @@ struct HelixChannelEmote {
, name(jsonObject.value("name").toString()) , name(jsonObject.value("name").toString())
, type(jsonObject.value("emote_type").toString()) , type(jsonObject.value("emote_type").toString())
, setId(jsonObject.value("emote_set_id").toString()) , setId(jsonObject.value("emote_set_id").toString())
, url(QString(TWITCH_EMOTE_TEMPLATE) , url(TWITCH_EMOTE_TEMPLATE.arg(this->emoteId, u"3.0"))
.replace("{id}", this->emoteId)
.replace("{scale}", "3.0"))
{ {
} }
}; };

View file

@ -24,11 +24,11 @@
#include <utility> #include <utility>
#define UPLOAD_DELAY 2000
// Delay between uploads in milliseconds
namespace { namespace {
// Delay between uploads in milliseconds
constexpr int UPLOAD_DELAY = 2000;
std::optional<QByteArray> convertToPng(const QImage &image) std::optional<QByteArray> convertToPng(const QImage &image)
{ {
QByteArray imageData; QByteArray imageData;

View file

@ -1,4 +1,3 @@
#include "singletons/Theme.hpp" #include "singletons/Theme.hpp"
#include "Application.hpp" #include "Application.hpp"

View file

@ -1,4 +1,4 @@
#include "Toasts.hpp" #include "singletons/Toasts.hpp"
#include "Application.hpp" #include "Application.hpp"
#include "common/Common.hpp" #include "common/Common.hpp"
@ -83,19 +83,17 @@ bool Toasts::isEnabled()
QString Toasts::findStringFromReaction(const ToastReaction &reaction) QString Toasts::findStringFromReaction(const ToastReaction &reaction)
{ {
// The constants are macros right now, but we want to avoid ASCII casts,
// so we're concatenating them with a QString literal - effectively making them part of it.
switch (reaction) switch (reaction)
{ {
case ToastReaction::OpenInBrowser: case ToastReaction::OpenInBrowser:
return OPEN_IN_BROWSER u""_s; return OPEN_IN_BROWSER;
case ToastReaction::OpenInPlayer: case ToastReaction::OpenInPlayer:
return OPEN_PLAYER_IN_BROWSER u""_s; return OPEN_PLAYER_IN_BROWSER;
case ToastReaction::OpenInStreamlink: case ToastReaction::OpenInStreamlink:
return OPEN_IN_STREAMLINK u""_s; return OPEN_IN_STREAMLINK;
case ToastReaction::DontOpen: case ToastReaction::DontOpen:
default: default:
return DONT_OPEN u""_s; return DONT_OPEN;
} }
} }

View file

@ -1,12 +1,13 @@
#include "Updates.hpp" #include "singletons/Updates.hpp"
#include "common/Literals.hpp"
#include "common/Modes.hpp" #include "common/Modes.hpp"
#include "common/network/NetworkRequest.hpp" #include "common/network/NetworkRequest.hpp"
#include "common/network/NetworkResult.hpp" #include "common/network/NetworkResult.hpp"
#include "common/QLogging.hpp" #include "common/QLogging.hpp"
#include "common/Version.hpp" #include "common/Version.hpp"
#include "Settings.hpp"
#include "singletons/Paths.hpp" #include "singletons/Paths.hpp"
#include "singletons/Settings.hpp"
#include "util/CombinePath.hpp" #include "util/CombinePath.hpp"
#include "util/PostToThread.hpp" #include "util/PostToThread.hpp"
@ -15,16 +16,34 @@
#include <QMessageBox> #include <QMessageBox>
#include <QProcess> #include <QProcess>
#include <QRegularExpression> #include <QRegularExpression>
#include <QStringBuilder>
#include <semver/semver.hpp> #include <semver/semver.hpp>
namespace chatterino {
namespace { namespace {
QString currentBranch()
{ using namespace chatterino;
return getSettings()->betaUpdates ? "beta" : "stable"; using namespace literals;
}
QString currentBranch()
{
return getSettings()->betaUpdates ? "beta" : "stable";
}
#if defined(Q_OS_WIN)
const QString CHATTERINO_OS = u"win"_s;
#elif defined(Q_OS_MACOS)
const QString CHATTERINO_OS = u"macos"_s;
#elif defined(Q_OS_LINUX)
const QString CHATTERINO_OS = u"linux"_s;
#elif defined(Q_OS_FREEBSD)
const QString CHATTERINO_OS = u"freebsd"_s;
#else
const QString CHATTERINO_OS = u"unknown"_s;
#endif
;
} // namespace } // namespace
namespace chatterino {
Updates::Updates(const Paths &paths_) Updates::Updates(const Paths &paths_)
: paths(paths_) : paths(paths_)
@ -262,9 +281,8 @@ void Updates::checkForUpdates()
return; return;
} }
QString url = QString url = "https://notitia.chatterino.com/version/chatterino/" %
"https://notitia.chatterino.com/version/chatterino/" CHATTERINO_OS "/" + CHATTERINO_OS % "/" % currentBranch();
currentBranch();
NetworkRequest(url) NetworkRequest(url)
.timeout(60000) .timeout(60000)

View file

@ -1,4 +1,4 @@
#include "DisplayBadge.hpp" #include "util/DisplayBadge.hpp"
namespace chatterino { namespace chatterino {
DisplayBadge::DisplayBadge(QString displayName, QString badgeName) DisplayBadge::DisplayBadge(QString displayName, QString badgeName)

View file

@ -1,4 +1,4 @@
#include "FunctionEventFilter.hpp" #include "util/FunctionEventFilter.hpp"
namespace chatterino { namespace chatterino {

View file

@ -1,4 +1,4 @@
#include "FuzzyConvert.hpp" #include "util/FuzzyConvert.hpp"
#include <QRegularExpression> #include <QRegularExpression>

View file

@ -1,4 +1,4 @@
#include "Helpers.hpp" #include "util/Helpers.hpp"
#include "providers/twitch/TwitchCommon.hpp" #include "providers/twitch/TwitchCommon.hpp"

View file

@ -1,4 +1,4 @@
#include "RatelimitBucket.hpp" #include "util/RatelimitBucket.hpp"
#include <QTimer> #include <QTimer>

View file

@ -1,4 +1,4 @@
#include "SampleData.hpp" #include "util/SampleData.hpp"
namespace chatterino { namespace chatterino {

View file

@ -1,4 +1,4 @@
#include "AccountSwitchWidget.hpp" #include "widgets/AccountSwitchWidget.hpp"
#include "Application.hpp" #include "Application.hpp"
#include "common/Common.hpp" #include "common/Common.hpp"

View file

@ -7,11 +7,11 @@
#include <QPainter> #include <QPainter>
// number of columns in grid mode
#define GRID_NUM_COLS 3
namespace { namespace {
// number of columns in grid mode
constexpr int GRID_NUM_COLS = 3;
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
template <typename T> template <typename T>
inline constexpr T *tooltipParentFor(T * /*desiredParent*/) inline constexpr T *tooltipParentFor(T * /*desiredParent*/)

View file

@ -737,19 +737,19 @@ void Window::addMenuBar()
// Help->Chatterino Wiki item // Help->Chatterino Wiki item
QAction *helpWiki = helpMenu->addAction(QString("Chatterino Wiki")); QAction *helpWiki = helpMenu->addAction(QString("Chatterino Wiki"));
connect(helpWiki, &QAction::triggered, this, []() { connect(helpWiki, &QAction::triggered, this, []() {
QDesktopServices::openUrl(QUrl(LINK_CHATTERINO_WIKI)); QDesktopServices::openUrl(QUrl(LINK_CHATTERINO_WIKI.toString()));
}); });
// Help->Chatterino Github // Help->Chatterino Github
QAction *helpGithub = helpMenu->addAction(QString("Chatterino GitHub")); QAction *helpGithub = helpMenu->addAction(QString("Chatterino GitHub"));
connect(helpGithub, &QAction::triggered, this, []() { connect(helpGithub, &QAction::triggered, this, []() {
QDesktopServices::openUrl(QUrl(LINK_CHATTERINO_SOURCE)); QDesktopServices::openUrl(QUrl(LINK_CHATTERINO_SOURCE.toString()));
}); });
// Help->Chatterino Discord // Help->Chatterino Discord
QAction *helpDiscord = helpMenu->addAction(QString("Chatterino Discord")); QAction *helpDiscord = helpMenu->addAction(QString("Chatterino Discord"));
connect(helpDiscord, &QAction::triggered, this, []() { connect(helpDiscord, &QAction::triggered, this, []() {
QDesktopServices::openUrl(QUrl(LINK_CHATTERINO_DISCORD)); QDesktopServices::openUrl(QUrl(LINK_CHATTERINO_DISCORD.toString()));
}); });
} }

View file

@ -1,4 +1,4 @@
#include "BadgePickerDialog.hpp" #include "widgets/dialogs/BadgePickerDialog.hpp"
#include "Application.hpp" #include "Application.hpp"
#include "providers/twitch/TwitchBadges.hpp" #include "providers/twitch/TwitchBadges.hpp"

View file

@ -1,4 +1,4 @@
#include "EmotePopup.hpp" #include "widgets/dialogs/EmotePopup.hpp"
#include "Application.hpp" #include "Application.hpp"
#include "common/QLogging.hpp" #include "common/QLogging.hpp"

View file

@ -1,4 +1,4 @@
#include "IrcConnectionEditor.hpp" #include "widgets/dialogs/IrcConnectionEditor.hpp"
#include "ui_IrcConnectionEditor.h" #include "ui_IrcConnectionEditor.h"

View file

@ -1,4 +1,4 @@
#include "QualityPopup.hpp" #include "widgets/dialogs/QualityPopup.hpp"
#include "Application.hpp" #include "Application.hpp"
#include "common/QLogging.hpp" #include "common/QLogging.hpp"

View file

@ -1,4 +1,4 @@
#include "SelectChannelDialog.hpp" #include "widgets/dialogs/SelectChannelDialog.hpp"
#include "Application.hpp" #include "Application.hpp"
#include "common/QLogging.hpp" #include "common/QLogging.hpp"
@ -25,11 +25,11 @@
#include <QTableView> #include <QTableView>
#include <QVBoxLayout> #include <QVBoxLayout>
#define TAB_TWITCH 0
#define TAB_IRC 1
namespace chatterino { namespace chatterino {
constexpr int TAB_TWITCH = 0;
constexpr int TAB_IRC = 1;
SelectChannelDialog::SelectChannelDialog(QWidget *parent) SelectChannelDialog::SelectChannelDialog(QWidget *parent)
: BaseWindow( : BaseWindow(
{ {

View file

@ -1,4 +1,4 @@
#include "SelectChannelFiltersDialog.hpp" #include "widgets/dialogs/SelectChannelFiltersDialog.hpp"
#include "controllers/filters/FilterRecord.hpp" #include "controllers/filters/FilterRecord.hpp"
#include "singletons/Settings.hpp" #include "singletons/Settings.hpp"

View file

@ -38,101 +38,104 @@
#include <QNetworkAccessManager> #include <QNetworkAccessManager>
#include <QNetworkReply> #include <QNetworkReply>
#include <QPointer> #include <QPointer>
#include <QStringBuilder>
const QString TEXT_FOLLOWERS("Followers: %1");
const QString TEXT_CREATED("Created: %1");
const QString TEXT_TITLE("%1's Usercard - #%2");
#define TEXT_USER_ID "ID: "
#define TEXT_UNAVAILABLE "(not available)"
namespace chatterino {
namespace { namespace {
Label *addCopyableLabel(LayoutCreator<QHBoxLayout> box, const char *tooltip,
Button **copyButton = nullptr) constexpr QStringView TEXT_FOLLOWERS = u"Followers: %1";
constexpr QStringView TEXT_CREATED = u"Created: %1";
constexpr QStringView TEXT_TITLE = u"%1's Usercard - #%2";
constexpr QStringView TEXT_USER_ID = u"ID: ";
constexpr QStringView TEXT_UNAVAILABLE = u"(not available)";
using namespace chatterino;
Label *addCopyableLabel(LayoutCreator<QHBoxLayout> box, const char *tooltip,
Button **copyButton = nullptr)
{
auto label = box.emplace<Label>();
auto button = box.emplace<Button>();
if (copyButton != nullptr)
{ {
auto label = box.emplace<Label>(); button.assign(copyButton);
auto button = box.emplace<Button>(); }
if (copyButton != nullptr) button->setPixmap(getApp()->getThemes()->buttons.copy);
{ button->setScaleIndependantSize(18, 18);
button.assign(copyButton); button->setDim(Button::Dim::Lots);
} button->setToolTip(tooltip);
button->setPixmap(getApp()->getThemes()->buttons.copy); QObject::connect(
button->setScaleIndependantSize(18, 18); button.getElement(), &Button::leftClicked,
button->setDim(Button::Dim::Lots); [label = label.getElement()] {
button->setToolTip(tooltip); auto copyText = label->property("copy-text").toString();
QObject::connect(
button.getElement(), &Button::leftClicked,
[label = label.getElement()] {
auto copyText = label->property("copy-text").toString();
crossPlatformCopy(copyText.isEmpty() ? label->getText() crossPlatformCopy(copyText.isEmpty() ? label->getText() : copyText);
: copyText); });
});
return label.getElement(); return label.getElement();
}; };
bool checkMessageUserName(const QString &userName, MessagePtr message) bool checkMessageUserName(const QString &userName, MessagePtr message)
{
if (message->flags.has(MessageFlag::Whisper))
{ {
if (message->flags.has(MessageFlag::Whisper)) return false;
{
return false;
}
bool isSubscription = message->flags.has(MessageFlag::Subscription) &&
message->loginName.isEmpty() &&
message->messageText.split(" ").at(0).compare(
userName, Qt::CaseInsensitive) == 0;
bool isModAction =
message->timeoutUser.compare(userName, Qt::CaseInsensitive) == 0;
bool isSelectedUser =
message->loginName.compare(userName, Qt::CaseInsensitive) == 0;
return (isSubscription || isModAction || isSelectedUser);
} }
ChannelPtr filterMessages(const QString &userName, ChannelPtr channel) bool isSubscription = message->flags.has(MessageFlag::Subscription) &&
message->loginName.isEmpty() &&
message->messageText.split(" ").at(0).compare(
userName, Qt::CaseInsensitive) == 0;
bool isModAction =
message->timeoutUser.compare(userName, Qt::CaseInsensitive) == 0;
bool isSelectedUser =
message->loginName.compare(userName, Qt::CaseInsensitive) == 0;
return (isSubscription || isModAction || isSelectedUser);
}
ChannelPtr filterMessages(const QString &userName, ChannelPtr channel)
{
LimitedQueueSnapshot<MessagePtr> snapshot = channel->getMessageSnapshot();
ChannelPtr channelPtr;
if (channel->isTwitchChannel())
{ {
LimitedQueueSnapshot<MessagePtr> snapshot = channelPtr = std::make_shared<TwitchChannel>(channel->getName());
channel->getMessageSnapshot();
ChannelPtr channelPtr;
if (channel->isTwitchChannel())
{
channelPtr = std::make_shared<TwitchChannel>(channel->getName());
}
else
{
channelPtr = std::make_shared<Channel>(channel->getName(),
Channel::Type::None);
}
for (size_t i = 0; i < snapshot.size(); i++)
{
MessagePtr message = snapshot[i];
if (checkMessageUserName(userName, message))
{
channelPtr->addMessage(message, MessageContext::Repost);
}
}
return channelPtr;
};
const auto borderColor = QColor(255, 255, 255, 80);
int calculateTimeoutDuration(TimeoutButton timeout)
{
static const QMap<QString, int> durations{
{"s", 1}, {"m", 60}, {"h", 3600}, {"d", 86400}, {"w", 604800},
};
return timeout.second * durations[timeout.first];
} }
else
{
channelPtr =
std::make_shared<Channel>(channel->getName(), Channel::Type::None);
}
for (size_t i = 0; i < snapshot.size(); i++)
{
MessagePtr message = snapshot[i];
if (checkMessageUserName(userName, message))
{
channelPtr->addMessage(message, MessageContext::Repost);
}
}
return channelPtr;
};
const auto borderColor = QColor(255, 255, 255, 80);
int calculateTimeoutDuration(TimeoutButton timeout)
{
static const QMap<QString, int> durations{
{"s", 1}, {"m", 60}, {"h", 3600}, {"d", 86400}, {"w", 604800},
};
return timeout.second * durations[timeout.first];
}
} // namespace } // namespace
namespace chatterino {
UserInfoPopup::UserInfoPopup(bool closeAutomatically, Split *split) UserInfoPopup::UserInfoPopup(bool closeAutomatically, Split *split)
: DraggablePopup(closeAutomatically, split) : DraggablePopup(closeAutomatically, split)
, split_(split) , split_(split)
@ -813,10 +816,9 @@ void UserInfoPopup::updateUserData()
this->ui_.nameLabel->setText(this->userName_); this->ui_.nameLabel->setText(this->userName_);
this->ui_.userIDLabel->setText(QString("ID ") + this->ui_.userIDLabel->setText(u"ID " % TEXT_UNAVAILABLE);
QString(TEXT_UNAVAILABLE));
this->ui_.userIDLabel->setProperty("copy-text", this->ui_.userIDLabel->setProperty("copy-text",
QString(TEXT_UNAVAILABLE)); TEXT_UNAVAILABLE.toString());
}; };
const auto onUserFetched = [this, hack, const auto onUserFetched = [this, hack,
currentUser](const HelixUser &user) { currentUser](const HelixUser &user) {
@ -855,7 +857,7 @@ void UserInfoPopup::updateUserData()
user.displayName, this->underlyingChannel_->getName())); user.displayName, this->underlyingChannel_->getName()));
this->ui_.createdDateLabel->setText( this->ui_.createdDateLabel->setText(
TEXT_CREATED.arg(user.createdAt.section("T", 0, 0))); TEXT_CREATED.arg(user.createdAt.section("T", 0, 0)));
this->ui_.userIDLabel->setText(TEXT_USER_ID + user.id); this->ui_.userIDLabel->setText(TEXT_USER_ID % user.id);
this->ui_.userIDLabel->setProperty("copy-text", user.id); this->ui_.userIDLabel->setProperty("copy-text", user.id);
if (getApp()->getStreamerMode()->isEnabled() && if (getApp()->getStreamerMode()->isEnabled() &&

View file

@ -1,4 +1,4 @@
#include "WelcomeDialog.hpp" #include "widgets/dialogs/WelcomeDialog.hpp"
namespace chatterino { namespace chatterino {

View file

@ -1,4 +1,4 @@
#include "Button.hpp" #include "widgets/helper/Button.hpp"
#include "singletons/Theme.hpp" #include "singletons/Theme.hpp"
#include "util/FunctionEventFilter.hpp" #include "util/FunctionEventFilter.hpp"

View file

@ -68,12 +68,10 @@
#include <functional> #include <functional>
#include <memory> #include <memory>
#define SELECTION_RESUME_SCROLLING_MSG_THRESHOLD 3
#define CHAT_HOVER_PAUSE_DURATION 1000
#define TOOLTIP_EMOTE_ENTRIES_LIMIT 7
namespace { namespace {
constexpr size_t TOOLTIP_EMOTE_ENTRIES_LIMIT = 7;
using namespace chatterino; using namespace chatterino;
constexpr int SCROLLBAR_PADDING = 8; constexpr int SCROLLBAR_PADDING = 8;

View file

@ -1,4 +1,4 @@
#include "ComboBoxItemDelegate.hpp" #include "widgets/helper/ComboBoxItemDelegate.hpp"
#include <QComboBox> #include <QComboBox>

View file

@ -1,8 +1,17 @@
#pragma once #pragma once
#define OPEN_IN_BROWSER "Open stream in browser" #include <QString>
#define OPEN_PLAYER_IN_BROWSER "Open player in browser"
#define OPEN_MOD_VIEW_IN_BROWSER "Open mod view in browser" namespace chatterino {
#define OPEN_IN_STREAMLINK "Open in streamlink"
#define DONT_OPEN "Don't open" inline const QString OPEN_IN_BROWSER = QStringLiteral("Open stream in browser");
#define OPEN_WHISPERS_IN_BROWSER "Open whispers in browser" inline const QString OPEN_PLAYER_IN_BROWSER =
QStringLiteral("Open player in browser");
inline const QString OPEN_MOD_VIEW_IN_BROWSER =
QStringLiteral("Open mod view in browser");
inline const QString OPEN_IN_STREAMLINK = QStringLiteral("Open in streamlink");
inline const QString DONT_OPEN = QStringLiteral("Don't open");
inline const QString OPEN_WHISPERS_IN_BROWSER =
QStringLiteral("Open whispers in browser");
} // namespace chatterino

View file

@ -1,4 +1,4 @@
#include "EditableModelView.hpp" #include "widgets/helper/EditableModelView.hpp"
#include "widgets/helper/RegExpItemDelegate.hpp" #include "widgets/helper/RegExpItemDelegate.hpp"
#include "widgets/helper/TableStyles.hpp" #include "widgets/helper/TableStyles.hpp"

View file

@ -14,8 +14,6 @@
#include <QPainterPath> #include <QPainterPath>
#include <QRadialGradient> #include <QRadialGradient>
#define nuuls nullptr
namespace chatterino { namespace chatterino {
NotebookButton::NotebookButton(Notebook *parent) NotebookButton::NotebookButton(Notebook *parent)

View file

@ -11,7 +11,7 @@
namespace chatterino { namespace chatterino {
#define NOTEBOOK_TAB_HEIGHT 28 constexpr int NOTEBOOK_TAB_HEIGHT = 28;
class SplitContainer; class SplitContainer;

View file

@ -1,4 +1,4 @@
#include "SearchPopup.hpp" #include "widgets/helper/SearchPopup.hpp"
#include "Application.hpp" #include "Application.hpp"
#include "common/Channel.hpp" #include "common/Channel.hpp"

View file

@ -1,4 +1,4 @@
#include "TitlebarButton.hpp" #include "widgets/helper/TitlebarButton.hpp"
#include "singletons/Theme.hpp" #include "singletons/Theme.hpp"

View file

@ -1,4 +1,4 @@
#include "GenericListItem.hpp" #include "widgets/listview/GenericListItem.hpp"
namespace chatterino { namespace chatterino {

View file

@ -1,4 +1,4 @@
#include "GenericListModel.hpp" #include "widgets/listview/GenericListModel.hpp"
namespace chatterino { namespace chatterino {

View file

@ -1,30 +1,29 @@
#include "AboutPage.hpp" #include "widgets/settingspages/AboutPage.hpp"
#include "common/Common.hpp" #include "common/Common.hpp"
#include "common/Modes.hpp"
#include "common/QLogging.hpp" #include "common/QLogging.hpp"
#include "common/Version.hpp" #include "common/Version.hpp"
#include "util/LayoutCreator.hpp" #include "util/LayoutCreator.hpp"
#include "util/RemoveScrollAreaBackground.hpp" #include "util/RemoveScrollAreaBackground.hpp"
#include "widgets/BasePopup.hpp" #include "widgets/BasePopup.hpp"
#include "widgets/helper/SignalLabel.hpp"
#include "widgets/layout/FlowLayout.hpp" #include "widgets/layout/FlowLayout.hpp"
#include <QFile> #include <QFile>
#include <QFormLayout> #include <QFormLayout>
#include <QGroupBox> #include <QGroupBox>
#include <QLabel> #include <QLabel>
#include <QStringBuilder>
#include <QTextEdit> #include <QTextEdit>
#include <QTextStream> #include <QTextStream>
#include <QVBoxLayout> #include <QVBoxLayout>
#define PIXMAP_WIDTH 500
#define LINK_DONATE "https://streamelements.com/fourtf/tip"
#define LINK_CHATTERINO_FEATURES "https://chatterino.com/#features"
namespace chatterino { namespace chatterino {
constexpr int PIXMAP_WIDTH = 500;
constexpr QStringView LINK_CHATTERINO_FEATURES =
u"https://chatterino.com/#features";
AboutPage::AboutPage() AboutPage::AboutPage()
{ {
LayoutCreator<AboutPage> layoutCreator(this); LayoutCreator<AboutPage> layoutCreator(this);
@ -66,9 +65,9 @@ AboutPage::AboutPage()
auto l = aboutChatterino.emplace<QVBoxLayout>(); auto l = aboutChatterino.emplace<QVBoxLayout>();
// clang-format off // clang-format off
l.emplace<QLabel>("Chatterino Wiki can be found <a href=\"" LINK_CHATTERINO_WIKI "\">here</a>")->setOpenExternalLinks(true); l.emplace<QLabel>("Chatterino Wiki can be found <a href=\"" % LINK_CHATTERINO_WIKI % "\">here</a>")->setOpenExternalLinks(true);
l.emplace<QLabel>("All about Chatterino's <a href=\"" LINK_CHATTERINO_FEATURES "\">features</a>")->setOpenExternalLinks(true); l.emplace<QLabel>("All about Chatterino's <a href=\"" % LINK_CHATTERINO_FEATURES % "\">features</a>")->setOpenExternalLinks(true);
l.emplace<QLabel>("Join the official Chatterino <a href=\"" LINK_CHATTERINO_DISCORD "\">Discord</a>")->setOpenExternalLinks(true); l.emplace<QLabel>("Join the official Chatterino <a href=\"" % LINK_CHATTERINO_DISCORD % "\">Discord</a>")->setOpenExternalLinks(true);
// clang-format on // clang-format on
} }

View file

@ -1,4 +1,4 @@
#include "AccountsPage.hpp" #include "widgets/settingspages/AccountsPage.hpp"
#include "Application.hpp" #include "Application.hpp"
#include "controllers/accounts/AccountController.hpp" #include "controllers/accounts/AccountController.hpp"

View file

@ -1,6 +1,7 @@
#include "CommandPage.hpp" #include "widgets/settingspages/CommandPage.hpp"
#include "Application.hpp" #include "Application.hpp"
#include "common/Literals.hpp"
#include "controllers/commands/Command.hpp" #include "controllers/commands/Command.hpp"
#include "controllers/commands/CommandController.hpp" #include "controllers/commands/CommandController.hpp"
#include "controllers/commands/CommandModel.hpp" #include "controllers/commands/CommandModel.hpp"
@ -18,13 +19,14 @@
#include <QTableView> #include <QTableView>
#include <QTextEdit> #include <QTextEdit>
// clang-format off
#define TEXT "{1} => first word &nbsp;&nbsp;&nbsp; {1+} => first word and after &nbsp;&nbsp;&nbsp; {{ => { &nbsp;&nbsp;&nbsp; <a href='https://chatterino.com/help/commands'>more info</a>"
// clang-format on
namespace { namespace {
using namespace chatterino; using namespace chatterino;
using namespace literals;
// clang-format off
inline const QString HELP_TEXT = u"{1} => first word &nbsp;&nbsp;&nbsp; {1+} => first word and after &nbsp;&nbsp;&nbsp; {{ => { &nbsp;&nbsp;&nbsp; <a href='https://chatterino.com/help/commands'>more info</a>"_s;
// clang-format on
QString c1settingsPath() QString c1settingsPath()
{ {
@ -106,7 +108,7 @@ CommandPage::CommandPage()
view->addCustomButton(button); view->addCustomButton(button);
QObject::connect(button, &QPushButton::clicked, this, [] { QObject::connect(button, &QPushButton::clicked, this, [] {
QFile c1settings = c1settingsPath(); QFile c1settings(c1settingsPath());
c1settings.open(QIODevice::ReadOnly); c1settings.open(QIODevice::ReadOnly);
for (auto line : for (auto line :
QString(c1settings.readAll()) QString(c1settings.readAll())
@ -125,7 +127,7 @@ CommandPage::CommandPage()
this->createCheckBox("Also match the trigger at the end of the message", this->createCheckBox("Also match the trigger at the end of the message",
getSettings()->allowCommandsAtEnd)); getSettings()->allowCommandsAtEnd));
QLabel *text = layout.emplace<QLabel>(TEXT).getElement(); QLabel *text = layout.emplace<QLabel>(HELP_TEXT).getElement();
text->setWordWrap(true); text->setWordWrap(true);
text->setStyleSheet("color: #bbb"); text->setStyleSheet("color: #bbb");
text->setOpenExternalLinks(true); text->setOpenExternalLinks(true);

View file

@ -10,11 +10,11 @@
#include <QGroupBox> #include <QGroupBox>
#include <QLabel> #include <QLabel>
#define STREAMLINK_QUALITY \
"Choose", "Source", "High", "Medium", "Low", "Audio only"
namespace chatterino { namespace chatterino {
inline const QStringList STREAMLINK_QUALITY = {
"Choose", "Source", "High", "Medium", "Low", "Audio only"};
ExternalToolsPage::ExternalToolsPage() ExternalToolsPage::ExternalToolsPage()
{ {
LayoutCreator<ExternalToolsPage> layoutCreator(this); LayoutCreator<ExternalToolsPage> layoutCreator(this);
@ -75,7 +75,7 @@ ExternalToolsPage::ExternalToolsPage()
groupLayout->addRow("Custom streamlink path:", customPath); groupLayout->addRow("Custom streamlink path:", customPath);
groupLayout->addRow( groupLayout->addRow(
"Preferred quality:", "Preferred quality:",
this->createComboBox({STREAMLINK_QUALITY}, this->createComboBox(STREAMLINK_QUALITY,
getSettings()->preferredQuality)); getSettings()->preferredQuality));
groupLayout->addRow( groupLayout->addRow(
"Additional options:", "Additional options:",

View file

@ -1,4 +1,4 @@
#include "FiltersPage.hpp" #include "widgets/settingspages/FiltersPage.hpp"
#include "Application.hpp" #include "Application.hpp"
#include "controllers/filters/FilterModel.hpp" #include "controllers/filters/FilterModel.hpp"
@ -8,15 +8,15 @@
#include "util/LayoutCreator.hpp" #include "util/LayoutCreator.hpp"
#include "widgets/dialogs/ChannelFilterEditorDialog.hpp" #include "widgets/dialogs/ChannelFilterEditorDialog.hpp"
#include "widgets/helper/EditableModelView.hpp" #include "widgets/helper/EditableModelView.hpp"
#include "widgets/Window.hpp"
#include <QHeaderView> #include <QHeaderView>
#include <QTableView> #include <QTableView>
#define FILTERS_DOCUMENTATION "https://wiki.chatterino.com/Filters"
namespace chatterino { namespace chatterino {
constexpr QStringView FILTERS_DOCUMENTATION =
u"https://wiki.chatterino.com/Filters";
FiltersPage::FiltersPage() FiltersPage::FiltersPage()
{ {
LayoutCreator<FiltersPage> layoutCreator(this); LayoutCreator<FiltersPage> layoutCreator(this);
@ -67,8 +67,8 @@ FiltersPage::FiltersPage()
}); });
auto *filterHelpLabel = auto *filterHelpLabel =
new QLabel(QString("<a href='%1'><span " new QLabel(QStringView(u"<a href='%1'><span "
"style='color:#99f'>filter info</span></a>") "style='color:#99f'>filter info</span></a>")
.arg(FILTERS_DOCUMENTATION)); .arg(FILTERS_DOCUMENTATION));
filterHelpLabel->setOpenExternalLinks(true); filterHelpLabel->setOpenExternalLinks(true);
view->addCustomButton(filterHelpLabel); view->addCustomButton(filterHelpLabel);

View file

@ -1,6 +1,7 @@
#include "widgets/settingspages/GeneralPage.hpp" #include "widgets/settingspages/GeneralPage.hpp"
#include "Application.hpp" #include "Application.hpp"
#include "common/Literals.hpp"
#include "common/QLogging.hpp" #include "common/QLogging.hpp"
#include "common/Version.hpp" #include "common/Version.hpp"
#include "controllers/hotkeys/HotkeyCategory.hpp" #include "controllers/hotkeys/HotkeyCategory.hpp"
@ -19,7 +20,6 @@
#include "util/IncognitoBrowser.hpp" #include "util/IncognitoBrowser.hpp"
#include "widgets/BaseWindow.hpp" #include "widgets/BaseWindow.hpp"
#include "widgets/settingspages/GeneralPageView.hpp" #include "widgets/settingspages/GeneralPageView.hpp"
#include "widgets/splits/SplitInput.hpp"
#include <magic_enum/magic_enum.hpp> #include <magic_enum/magic_enum.hpp>
#include <QDesktopServices> #include <QDesktopServices>
@ -28,64 +28,63 @@
#include <QLabel> #include <QLabel>
#include <QScrollArea> #include <QScrollArea>
#define CHROME_EXTENSION_LINK \ namespace {
"https://chrome.google.com/webstore/detail/chatterino-native-host/" \
"glknmaideaikkmemifbfkhnomoknepka"
#define FIREFOX_EXTENSION_LINK \
"https://addons.mozilla.org/en-US/firefox/addon/chatterino-native-host/"
// define to highlight sections in editor using namespace chatterino;
#define addTitle addTitle using namespace literals;
#define addSubtitle addSubtitle
const QString CHROME_EXTENSION_LINK =
u"https://chrome.google.com/webstore/detail/chatterino-native-host/glknmaideaikkmemifbfkhnomoknepka"_s;
const QString FIREFOX_EXTENSION_LINK =
u"https://addons.mozilla.org/en-US/firefox/addon/chatterino-native-host/"_s;
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
# define META_KEY "Windows" const QString META_KEY = u"Windows"_s;
#else #else
# define META_KEY "Meta" const QString META_KEY = u"Meta"_s;
#endif #endif
namespace chatterino { void addKeyboardModifierSetting(GeneralPageView &layout, const QString &title,
namespace { EnumSetting<Qt::KeyboardModifier> &setting)
void addKeyboardModifierSetting(GeneralPageView &layout, {
const QString &title, layout.addDropdown<std::underlying_type<Qt::KeyboardModifier>::type>(
EnumSetting<Qt::KeyboardModifier> &setting) title, {"None", "Shift", "Control", "Alt", META_KEY}, setting,
{ [](int index) {
layout.addDropdown<std::underlying_type<Qt::KeyboardModifier>::type>( switch (index)
title, {"None", "Shift", "Control", "Alt", META_KEY}, setting, {
[](int index) { case Qt::ShiftModifier:
switch (index) return 1;
{ case Qt::ControlModifier:
case Qt::ShiftModifier: return 2;
return 1; case Qt::AltModifier:
case Qt::ControlModifier: return 3;
return 2; case Qt::MetaModifier:
case Qt::AltModifier: return 4;
return 3; default:
case Qt::MetaModifier: return 0;
return 4; }
default: },
return 0; [](DropdownArgs args) {
} switch (args.index)
}, {
[](DropdownArgs args) { case 1:
switch (args.index) return Qt::ShiftModifier;
{ case 2:
case 1: return Qt::ControlModifier;
return Qt::ShiftModifier; case 3:
case 2: return Qt::AltModifier;
return Qt::ControlModifier; case 4:
case 3: return Qt::MetaModifier;
return Qt::AltModifier; default:
case 4: return Qt::NoModifier;
return Qt::MetaModifier; }
default: },
return Qt::NoModifier; false);
} }
},
false);
}
} // namespace } // namespace
namespace chatterino {
GeneralPage::GeneralPage() GeneralPage::GeneralPage()
{ {
auto *y = new QVBoxLayout; auto *y = new QVBoxLayout;

View file

@ -1,4 +1,4 @@
#include "HighlightingPage.hpp" #include "widgets/settingspages/HighlightingPage.hpp"
#include "Application.hpp" #include "Application.hpp"
#include "controllers/highlights/BadgeHighlightModel.hpp" #include "controllers/highlights/BadgeHighlightModel.hpp"
@ -10,7 +10,6 @@
#include "controllers/highlights/UserHighlightModel.hpp" #include "controllers/highlights/UserHighlightModel.hpp"
#include "providers/colors/ColorProvider.hpp" #include "providers/colors/ColorProvider.hpp"
#include "singletons/Settings.hpp" #include "singletons/Settings.hpp"
#include "singletons/Theme.hpp"
#include "util/Helpers.hpp" #include "util/Helpers.hpp"
#include "util/LayoutCreator.hpp" #include "util/LayoutCreator.hpp"
#include "widgets/dialogs/BadgePickerDialog.hpp" #include "widgets/dialogs/BadgePickerDialog.hpp"
@ -25,8 +24,6 @@
#include <QTableView> #include <QTableView>
#include <QTabWidget> #include <QTabWidget>
#define ALWAYS_PLAY "Play highlight sound even when Chatterino is focused"
namespace chatterino { namespace chatterino {
namespace { namespace {
@ -312,8 +309,9 @@ HighlightingPage::HighlightingPage()
this->managedConnections_); this->managedConnections_);
} }
layout.append(createCheckBox(ALWAYS_PLAY, layout.append(createCheckBox(
getSettings()->highlightAlwaysPlaySound)); "Play highlight sound even when Chatterino is focused",
getSettings()->highlightAlwaysPlaySound));
layout.append(createCheckBox( layout.append(createCheckBox(
"Flash taskbar only stops highlighting when Chatterino is focused", "Flash taskbar only stops highlighting when Chatterino is focused",
getSettings()->longAlerts)); getSettings()->longAlerts));

View file

@ -1,6 +1,7 @@
#include "widgets/settingspages/IgnoresPage.hpp" #include "widgets/settingspages/IgnoresPage.hpp"
#include "Application.hpp" #include "Application.hpp"
#include "common/Literals.hpp"
#include "controllers/accounts/AccountController.hpp" #include "controllers/accounts/AccountController.hpp"
#include "controllers/ignores/IgnoreModel.hpp" #include "controllers/ignores/IgnoreModel.hpp"
#include "controllers/ignores/IgnorePhrase.hpp" #include "controllers/ignores/IgnorePhrase.hpp"
@ -19,12 +20,10 @@
#include <QTableView> #include <QTableView>
#include <QVBoxLayout> #include <QVBoxLayout>
// clang-format off
#define INFO "/block <user> in chat blocks a user.\n/unblock <user> in chat unblocks a user.\nYou can also click on a user to open the usercard."
// clang-format on
namespace chatterino { namespace chatterino {
using namespace literals;
static void addPhrasesTab(LayoutCreator<QVBoxLayout> box); static void addPhrasesTab(LayoutCreator<QVBoxLayout> box);
static void addUsersTab(IgnoresPage &page, LayoutCreator<QVBoxLayout> box, static void addUsersTab(IgnoresPage &page, LayoutCreator<QVBoxLayout> box,
QStringListModel &model); QStringListModel &model);
@ -74,7 +73,8 @@ void addPhrasesTab(LayoutCreator<QVBoxLayout> layout)
void addUsersTab(IgnoresPage &page, LayoutCreator<QVBoxLayout> users, void addUsersTab(IgnoresPage &page, LayoutCreator<QVBoxLayout> users,
QStringListModel &userModel) QStringListModel &userModel)
{ {
auto label = users.emplace<QLabel>(INFO); auto label = users.emplace<QLabel>(
u"/block <user> in chat blocks a user.\n/unblock <user> in chat unblocks a user.\nYou can also click on a user to open the usercard."_s);
label->setWordWrap(true); label->setWordWrap(true);
users.append(page.createCheckBox("Enable Twitch blocked users", users.append(page.createCheckBox("Enable Twitch blocked users",
getSettings()->enableTwitchBlockedUsers)); getSettings()->enableTwitchBlockedUsers));

View file

@ -1,4 +1,4 @@
#include "ModerationPage.hpp" #include "widgets/settingspages/ModerationPage.hpp"
#include "Application.hpp" #include "Application.hpp"
#include "controllers/logging/ChannelLoggingModel.hpp" #include "controllers/logging/ChannelLoggingModel.hpp"

View file

@ -1,4 +1,4 @@
#include "NicknamesPage.hpp" #include "widgets/settingspages/NicknamesPage.hpp"
#include "controllers/nicknames/Nickname.hpp" #include "controllers/nicknames/Nickname.hpp"
#include "controllers/nicknames/NicknamesModel.hpp" #include "controllers/nicknames/NicknamesModel.hpp"

View file

@ -1,4 +1,4 @@
#include "NotificationPage.hpp" #include "widgets/settingspages/NotificationPage.hpp"
#include "Application.hpp" #include "Application.hpp"
#include "controllers/notifications/NotificationController.hpp" #include "controllers/notifications/NotificationController.hpp"

View file

@ -1,4 +1,4 @@
#include "SettingsPage.hpp" #include "widgets/settingspages/SettingsPage.hpp"
#include "Application.hpp" #include "Application.hpp"
#include "singletons/WindowManager.hpp" #include "singletons/WindowManager.hpp"

View file

@ -1,4 +1,4 @@
#include "ClosedSplits.hpp" #include "widgets/splits/ClosedSplits.hpp"
namespace chatterino { namespace chatterino {

View file

@ -343,29 +343,30 @@ Split::Split(QWidget *parent)
this->refreshModerationMode(); this->refreshModerationMode();
}); });
this->signalHolder_.managedConnect( this->signalHolder_.managedConnect(modifierStatusChanged, [this](
modifierStatusChanged, [this](Qt::KeyboardModifiers status) { Qt::KeyboardModifiers
if ((status == status) {
showSplitOverlayModifiers /*|| status == showAddSplitRegions*/) && if ((status ==
this->isMouseOver_) SHOW_SPLIT_OVERLAY_MODIFIERS /*|| status == showAddSplitRegions*/) &&
{ this->isMouseOver_)
this->overlay_->show(); {
} this->overlay_->show();
else }
{ else
this->overlay_->hide(); {
} this->overlay_->hide();
}
if (getSettings()->pauseChatModifier.getEnum() != Qt::NoModifier && if (getSettings()->pauseChatModifier.getEnum() != Qt::NoModifier &&
status == getSettings()->pauseChatModifier.getEnum()) status == getSettings()->pauseChatModifier.getEnum())
{ {
this->view_->pause(PauseReason::KeyboardModifier); this->view_->pause(PauseReason::KeyboardModifier);
} }
else else
{ {
this->view_->unpause(PauseReason::KeyboardModifier); this->view_->unpause(PauseReason::KeyboardModifier);
} }
}); });
this->signalHolder_.managedConnect(this->input_->ui_.textEdit->focused, this->signalHolder_.managedConnect(this->input_->ui_.textEdit->focused,
[this] { [this] {
@ -1019,7 +1020,7 @@ void Split::enterEvent(QEvent * /*event*/)
this->handleModifiers(QGuiApplication::queryKeyboardModifiers()); this->handleModifiers(QGuiApplication::queryKeyboardModifiers());
if (modifierStatus == if (modifierStatus ==
showSplitOverlayModifiers /*|| modifierStatus == showAddSplitRegions*/) SHOW_SPLIT_OVERLAY_MODIFIERS /*|| modifierStatus == showAddSplitRegions*/)
{ {
this->overlay_->show(); this->overlay_->show();
} }

View file

@ -41,7 +41,7 @@ SplitContainer::SplitContainer(Notebook *parent)
Split::modifierStatusChanged, [this](auto modifiers) { Split::modifierStatusChanged, [this](auto modifiers) {
this->layout(); this->layout();
if (modifiers == showResizeHandlesModifiers) if (modifiers == SHOW_RESIZE_HANDLES_MODIFIERS)
{ {
for (auto &handle : this->resizeHandles_) for (auto &handle : this->resizeHandles_)
{ {
@ -57,7 +57,7 @@ SplitContainer::SplitContainer(Notebook *parent)
} }
} }
if (modifiers == showSplitOverlayModifiers) if (modifiers == SHOW_SPLIT_OVERLAY_MODIFIERS)
{ {
this->setCursor(Qt::PointingHandCursor); this->setCursor(Qt::PointingHandCursor);
} }
@ -496,7 +496,7 @@ void SplitContainer::layout()
std::vector<ResizeRect> resizeRects; std::vector<ResizeRect> resizeRects;
const bool addSpacing = const bool addSpacing =
Split::modifierStatus == showAddSplitRegions || this->isDragging_; Split::modifierStatus == SHOW_ADD_SPLIT_REGIONS || this->isDragging_;
this->baseNode_.layout(addSpacing, this->scale(), dropRects, resizeRects); this->baseNode_.layout(addSpacing, this->scale(), dropRects, resizeRects);
this->dropRects_ = dropRects; this->dropRects_ = dropRects;
@ -559,7 +559,7 @@ void SplitContainer::layout()
handle->setVertical(resizeRect.vertical); handle->setVertical(resizeRect.vertical);
handle->node = resizeRect.node; handle->node = resizeRect.node;
if (Split::modifierStatus == showResizeHandlesModifiers) if (Split::modifierStatus == SHOW_RESIZE_HANDLES_MODIFIERS)
{ {
handle->show(); handle->show();
handle->raise(); handle->raise();
@ -720,7 +720,7 @@ void SplitContainer::dragEnterEvent(QDragEnterEvent *event)
void SplitContainer::mouseMoveEvent(QMouseEvent *event) void SplitContainer::mouseMoveEvent(QMouseEvent *event)
{ {
if (Split::modifierStatus == showSplitOverlayModifiers) if (Split::modifierStatus == SHOW_SPLIT_OVERLAY_MODIFIERS)
{ {
this->setCursor(Qt::PointingHandCursor); this->setCursor(Qt::PointingHandCursor);
} }

View file

@ -1,4 +1,4 @@
#include "SplitOverlay.hpp" #include "widgets/splits/SplitOverlay.hpp"
#include "Application.hpp" #include "Application.hpp"
#include "singletons/Resources.hpp" #include "singletons/Resources.hpp"

View file

@ -37,6 +37,8 @@ TEST(Updates, MustNotBeDowngrade)
TEST(Updates, ValidateCurrentVersion) TEST(Updates, ValidateCurrentVersion)
{ {
EXPECT_NO_THROW(auto v = semver::from_string(CHATTERINO_VERSION)) EXPECT_NO_THROW([[maybe_unused]] auto v = semver::from_string(
Version::instance().version().toStdString()))
<< "Current version must be valid semver"; << "Current version must be valid semver";
EXPECT_EQ(Version::instance().version(), CHATTERINO_VERSION);
} }