Allow ChannelViews without a Split (#4747)

This commit is contained in:
nerix 2023-12-17 21:49:37 +01:00 committed by GitHub
parent 269e7a07b4
commit d105a68dba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 69 additions and 9 deletions

View file

@ -97,6 +97,7 @@
- Dev: Load less message history upon reconnects. (#5001) - Dev: Load less message history upon reconnects. (#5001)
- Dev: BREAKING: Replace custom `import()` with normal Lua `require()`. (#5014) - Dev: BREAKING: Replace custom `import()` with normal Lua `require()`. (#5014)
- Dev: Fixed most compiler warnings. (#5028) - Dev: Fixed most compiler warnings. (#5028)
- Dev: Added the ability to show `ChannelView`s without a `Split`. (#4747)
## 2.4.6 ## 2.4.6

View file

@ -240,7 +240,7 @@ EmotePopup::EmotePopup(QWidget *parent)
}; };
auto makeView = [&](QString tabTitle, bool addToNotebook = true) { auto makeView = [&](QString tabTitle, bool addToNotebook = true) {
auto *view = new ChannelView(); auto *view = new ChannelView(nullptr);
view->setOverrideFlags(MessageElementFlags{ view->setOverrideFlags(MessageElementFlags{
MessageElementFlag::Default, MessageElementFlag::AlwaysShow, MessageElementFlag::Default, MessageElementFlag::AlwaysShow,

View file

@ -277,8 +277,22 @@ std::pair<int, int> getWordBounds(MessageLayout *layout,
namespace chatterino { namespace chatterino {
ChannelView::ChannelView(BaseWidget *parent, Split *split, Context context, ChannelView::ChannelView(QWidget *parent, Context context, size_t messagesLimit)
: ChannelView(InternalCtor{}, parent, nullptr, context, messagesLimit)
{
}
ChannelView::ChannelView(QWidget *parent, Split *split, Context context,
size_t messagesLimit) size_t messagesLimit)
: ChannelView(InternalCtor{}, parent, split, context, messagesLimit)
{
assert(parent != nullptr && split != nullptr &&
"This constructor should only be used with non-null values (see "
"documentation)");
}
ChannelView::ChannelView(InternalCtor /*tag*/, QWidget *parent, Split *split,
Context context, size_t messagesLimit)
: BaseWidget(parent) : BaseWidget(parent)
, split_(split) , split_(split)
, scrollBar_(new Scrollbar(messagesLimit, this)) , scrollBar_(new Scrollbar(messagesLimit, this))
@ -1347,7 +1361,10 @@ bool ChannelView::scrollToMessage(const MessagePtr &message)
} }
this->scrollToMessageLayout(messagesSnapshot[messageIdx].get(), messageIdx); this->scrollToMessageLayout(messagesSnapshot[messageIdx].get(), messageIdx);
getApp()->windows->select(this->split_); if (this->split_)
{
getApp()->windows->select(this->split_);
}
return true; return true;
} }
@ -1376,7 +1393,10 @@ bool ChannelView::scrollToMessageId(const QString &messageId)
} }
this->scrollToMessageLayout(messagesSnapshot[messageIdx].get(), messageIdx); this->scrollToMessageLayout(messagesSnapshot[messageIdx].get(), messageIdx);
getApp()->windows->select(this->split_); if (this->split_)
{
getApp()->windows->select(this->split_);
}
return true; return true;
} }
@ -2349,7 +2369,7 @@ void ChannelView::addMessageContextMenuItems(QMenu *menu,
bool isSearch = this->context_ == Context::Search; bool isSearch = this->context_ == Context::Search;
bool isReplyOrUserCard = (this->context_ == Context::ReplyThread || bool isReplyOrUserCard = (this->context_ == Context::ReplyThread ||
this->context_ == Context::UserCard) && this->context_ == Context::UserCard) &&
this->split_; this->split_ != nullptr;
bool isMentions = bool isMentions =
this->channel()->getType() == Channel::Type::TwitchMentions; this->channel()->getType() == Channel::Type::TwitchMentions;
bool isAutomod = this->channel()->getType() == Channel::Type::TwitchAutomod; bool isAutomod = this->channel()->getType() == Channel::Type::TwitchAutomod;
@ -2580,7 +2600,14 @@ void ChannelView::hideEvent(QHideEvent * /*event*/)
void ChannelView::showUserInfoPopup(const QString &userName, void ChannelView::showUserInfoPopup(const QString &userName,
QString alternativePopoutChannel) QString alternativePopoutChannel)
{ {
assert(this->split_ != nullptr); if (!this->split_)
{
qCWarning(chatterinoCommon)
<< "Tried to show user info for" << userName
<< "but the channel view doesn't belong to a split.";
return;
}
auto *userPopup = auto *userPopup =
new UserInfoPopup(getSettings()->autoCloseUserPopup, this->split_); new UserInfoPopup(getSettings()->autoCloseUserPopup, this->split_);
@ -2879,7 +2906,9 @@ void ChannelView::scrollUpdateRequested()
void ChannelView::setInputReply(const MessagePtr &message) void ChannelView::setInputReply(const MessagePtr &message)
{ {
if (message == nullptr) assertInGuiThread();
if (message == nullptr || this->split_ == nullptr)
{ {
return; return;
} }
@ -2917,6 +2946,14 @@ void ChannelView::showReplyThreadPopup(const MessagePtr &message)
return; return;
} }
if (!this->split_)
{
qCWarning(chatterinoCommon)
<< "Tried to show reply thread popup but the "
"channel view doesn't belong to a split.";
return;
}
auto *popup = auto *popup =
new ReplyThreadPopup(getSettings()->autoCloseThreadPopup, this->split_); new ReplyThreadPopup(getSettings()->autoCloseThreadPopup, this->split_);

View file

@ -75,7 +75,23 @@ public:
Search, Search,
}; };
explicit ChannelView(BaseWidget *parent = nullptr, Split *split = nullptr, /// Creates a channel view without a split.
/// In such a view, usercards and reply-threads can't be opened.
///
/// @param parent The parent of this widget. Can be `nullptr`.
/// @param context The context in which this view is shown (e.g. as a usercard).
/// @param messagesLimit The maximum amount of messages this view will display.
explicit ChannelView(QWidget *parent, Context context = Context::None,
size_t messagesLimit = 1000);
/// Creates a channel view in a split.
///
/// @param parent The parent of this widget.
/// @param split The split containing this widget.
/// @a split must be in the widget tree of @a parent.
/// @param context The context in which this view is shown (e.g. as a usercard).
/// @param messagesLimit The maximum amount of messages this view will display.
explicit ChannelView(QWidget *parent, Split *split,
Context context = Context::None, Context context = Context::None,
size_t messagesLimit = 1000); size_t messagesLimit = 1000);
@ -192,6 +208,12 @@ protected:
QPoint &relativePos, int &index); QPoint &relativePos, int &index);
private: private:
struct InternalCtor {
};
ChannelView(InternalCtor tag, QWidget *parent, Split *split,
Context context, size_t messagesLimit);
void initializeLayout(); void initializeLayout();
void initializeScrollbar(); void initializeScrollbar();
void initializeSignals(); void initializeSignals();
@ -270,7 +292,7 @@ private:
ChannelPtr channel_ = nullptr; ChannelPtr channel_ = nullptr;
ChannelPtr underlyingChannel_ = nullptr; ChannelPtr underlyingChannel_ = nullptr;
ChannelPtr sourceChannel_ = nullptr; ChannelPtr sourceChannel_ = nullptr;
Split *split_ = nullptr; Split *split_;
Scrollbar *scrollBar_; Scrollbar *scrollBar_;
EffectLabel *goToBottom_{}; EffectLabel *goToBottom_{};