changed to 80 max column
This commit is contained in:
+158
-104
@@ -33,7 +33,8 @@
|
||||
|
||||
namespace chatterino {
|
||||
namespace {
|
||||
void addEmoteContextMenuItems(const Emote &emote, MessageElement::Flags creatorFlags, QMenu &menu)
|
||||
void addEmoteContextMenuItems(const Emote &emote,
|
||||
MessageElement::Flags creatorFlags, QMenu &menu)
|
||||
{
|
||||
auto openAction = menu.addAction("Open");
|
||||
auto openMenu = new QMenu;
|
||||
@@ -45,18 +46,21 @@ void addEmoteContextMenuItems(const Emote &emote, MessageElement::Flags creatorF
|
||||
|
||||
// see if the QMenu actually gets destroyed
|
||||
QObject::connect(openMenu, &QMenu::destroyed, [] {
|
||||
QMessageBox(QMessageBox::Information, "xD", "the menu got deleted").exec();
|
||||
QMessageBox(QMessageBox::Information, "xD", "the menu got deleted")
|
||||
.exec();
|
||||
});
|
||||
|
||||
// Add copy and open links for 1x, 2x, 3x
|
||||
auto addImageLink = [&](const ImagePtr &image, char scale) {
|
||||
if (!image->empty()) {
|
||||
copyMenu->addAction(QString(scale) + "x link", [url = image->url()] {
|
||||
QApplication::clipboard()->setText(url.string);
|
||||
});
|
||||
openMenu->addAction(QString(scale) + "x link", [url = image->url()] {
|
||||
QDesktopServices::openUrl(QUrl(url.string));
|
||||
});
|
||||
copyMenu->addAction(
|
||||
QString(scale) + "x link", [url = image->url()] {
|
||||
QApplication::clipboard()->setText(url.string);
|
||||
});
|
||||
openMenu->addAction(QString(scale) + "x link",
|
||||
[url = image->url()] {
|
||||
QDesktopServices::openUrl(QUrl(url.string));
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -69,12 +73,14 @@ void addEmoteContextMenuItems(const Emote &emote, MessageElement::Flags creatorF
|
||||
copyMenu->addSeparator();
|
||||
openMenu->addSeparator();
|
||||
|
||||
copyMenu->addAction("Copy " + name + " emote link", [url = emote.homePage] {
|
||||
QApplication::clipboard()->setText(url.string); //
|
||||
});
|
||||
openMenu->addAction("Open " + name + " emote link", [url = emote.homePage] {
|
||||
QDesktopServices::openUrl(QUrl(url.string)); //
|
||||
});
|
||||
copyMenu->addAction(
|
||||
"Copy " + name + " emote link", [url = emote.homePage] {
|
||||
QApplication::clipboard()->setText(url.string); //
|
||||
});
|
||||
openMenu->addAction("Open " + name + " emote link",
|
||||
[url = emote.homePage] {
|
||||
QDesktopServices::openUrl(QUrl(url.string)); //
|
||||
});
|
||||
};
|
||||
|
||||
if (creatorFlags & MessageElement::Flags::BttvEmote) {
|
||||
@@ -99,7 +105,8 @@ ChannelView::ChannelView(BaseWidget *parent)
|
||||
}));
|
||||
|
||||
this->scrollBar_.getCurrentValueChanged().connect([this] {
|
||||
// Whenever the scrollbar value has been changed, re-render the ChatWidgetView
|
||||
// Whenever the scrollbar value has been changed, re-render the
|
||||
// ChatWidgetView
|
||||
this->actuallyLayoutMessages(true);
|
||||
|
||||
// if (!this->isPaused()) {
|
||||
@@ -111,21 +118,24 @@ ChannelView::ChannelView(BaseWidget *parent)
|
||||
this->queueUpdate();
|
||||
});
|
||||
|
||||
this->scrollBar_.getDesiredValueChanged().connect(
|
||||
[this] { this->pausedByScrollingUp_ = !this->scrollBar_.isAtBottom(); });
|
||||
this->scrollBar_.getDesiredValueChanged().connect([this] {
|
||||
this->pausedByScrollingUp_ = !this->scrollBar_.isAtBottom();
|
||||
});
|
||||
|
||||
this->connections_.push_back(app->windows->repaintGifs.connect([&] {
|
||||
this->queueUpdate(); //
|
||||
}));
|
||||
|
||||
this->connections_.push_back(app->windows->layout.connect([&](Channel *channel) {
|
||||
if (channel == nullptr || this->channel_.get() == channel) {
|
||||
this->layoutMessages();
|
||||
}
|
||||
}));
|
||||
this->connections_.push_back(
|
||||
app->windows->layout.connect([&](Channel *channel) {
|
||||
if (channel == nullptr || this->channel_.get() == channel) {
|
||||
this->layoutMessages();
|
||||
}
|
||||
}));
|
||||
|
||||
this->goToBottom_ = new RippleEffectLabel(this, 0);
|
||||
this->goToBottom_->setStyleSheet("background-color: rgba(0,0,0,0.66); color: #FFF;");
|
||||
this->goToBottom_->setStyleSheet(
|
||||
"background-color: rgba(0,0,0,0.66); color: #FFF;");
|
||||
this->goToBottom_->getLabel().setText("More messages below");
|
||||
this->goToBottom_->setVisible(false);
|
||||
|
||||
@@ -175,8 +185,9 @@ ChannelView::ChannelView(BaseWidget *parent)
|
||||
});
|
||||
|
||||
QShortcut *shortcut = new QShortcut(QKeySequence("Ctrl+C"), this);
|
||||
QObject::connect(shortcut, &QShortcut::activated,
|
||||
[this] { QGuiApplication::clipboard()->setText(this->getSelectedText()); });
|
||||
QObject::connect(shortcut, &QShortcut::activated, [this] {
|
||||
QGuiApplication::clipboard()->setText(this->getSelectedText());
|
||||
});
|
||||
}
|
||||
|
||||
ChannelView::~ChannelView()
|
||||
@@ -235,7 +246,8 @@ void ChannelView::actuallyLayoutMessages(bool causedByScrollbar)
|
||||
// True if one of the following statements are true:
|
||||
// The scrollbar was not visible
|
||||
// The scrollbar was visible and at the bottom
|
||||
this->showingLatestMessages_ = this->scrollBar_.isAtBottom() || !this->scrollBar_.isVisible();
|
||||
this->showingLatestMessages_ =
|
||||
this->scrollBar_.isAtBottom() || !this->scrollBar_.isVisible();
|
||||
|
||||
size_t start = size_t(this->scrollBar_.getCurrentValue());
|
||||
int layoutWidth = this->getLayoutWidth();
|
||||
@@ -250,7 +262,8 @@ void ChannelView::actuallyLayoutMessages(bool causedByScrollbar)
|
||||
for (size_t i = start; i < messagesSnapshot.getLength(); ++i) {
|
||||
auto message = messagesSnapshot[i];
|
||||
|
||||
redrawRequired |= message->layout(layoutWidth, this->getScale(), flags);
|
||||
redrawRequired |=
|
||||
message->layout(layoutWidth, this->getScale(), flags);
|
||||
|
||||
y += message->getHeight();
|
||||
|
||||
@@ -288,9 +301,10 @@ void ChannelView::actuallyLayoutMessages(bool causedByScrollbar)
|
||||
|
||||
this->scrollBar_.setMaximum(messagesSnapshot.getLength());
|
||||
|
||||
// If we were showing the latest messages and the scrollbar now wants to be rendered, scroll
|
||||
// to bottom
|
||||
if (this->enableScrollingToBottom_ && this->showingLatestMessages_ && showScrollbar) {
|
||||
// If we were showing the latest messages and the scrollbar now wants to be
|
||||
// rendered, scroll to bottom
|
||||
if (this->enableScrollingToBottom_ && this->showingLatestMessages_ &&
|
||||
showScrollbar) {
|
||||
if (!this->isPaused()) {
|
||||
this->scrollBar_.scrollToBottom(
|
||||
// this->messageWasAdded &&
|
||||
@@ -309,7 +323,8 @@ void ChannelView::clearMessages()
|
||||
// Clear all stored messages in this chat widget
|
||||
this->messages.clear();
|
||||
|
||||
// Layout chat widget messages, and force an update regardless if there are no messages
|
||||
// Layout chat widget messages, and force an update regardless if there are
|
||||
// no messages
|
||||
this->layoutMessages();
|
||||
this->queueUpdate();
|
||||
}
|
||||
@@ -323,7 +338,8 @@ QString ChannelView::getSelectedText()
|
||||
{
|
||||
QString result = "";
|
||||
|
||||
LimitedQueueSnapshot<MessageLayoutPtr> messagesSnapshot = this->getMessagesSnapshot();
|
||||
LimitedQueueSnapshot<MessageLayoutPtr> messagesSnapshot =
|
||||
this->getMessagesSnapshot();
|
||||
|
||||
Selection _selection = this->selection_;
|
||||
|
||||
@@ -334,10 +350,12 @@ QString ChannelView::getSelectedText()
|
||||
for (int msg = _selection.selectionMin.messageIndex;
|
||||
msg <= _selection.selectionMax.messageIndex; msg++) {
|
||||
MessageLayoutPtr layout = messagesSnapshot[msg];
|
||||
int from =
|
||||
msg == _selection.selectionMin.messageIndex ? _selection.selectionMin.charIndex : 0;
|
||||
int to = msg == _selection.selectionMax.messageIndex ? _selection.selectionMax.charIndex
|
||||
: layout->getLastCharacterIndex() + 1;
|
||||
int from = msg == _selection.selectionMin.messageIndex
|
||||
? _selection.selectionMin.charIndex
|
||||
: 0;
|
||||
int to = msg == _selection.selectionMax.messageIndex
|
||||
? _selection.selectionMax.charIndex
|
||||
: layout->getLastCharacterIndex() + 1;
|
||||
|
||||
qDebug() << "from:" << from << ", to:" << to;
|
||||
|
||||
@@ -374,7 +392,8 @@ void ChannelView::setOverrideFlags(boost::optional<MessageElement::Flags> value)
|
||||
this->overrideFlags_ = value;
|
||||
}
|
||||
|
||||
const boost::optional<MessageElement::Flags> &ChannelView::getOverrideFlags() const
|
||||
const boost::optional<MessageElement::Flags> &ChannelView::getOverrideFlags()
|
||||
const
|
||||
{
|
||||
return this->overrideFlags_;
|
||||
}
|
||||
@@ -406,13 +425,15 @@ void ChannelView::setChannel(ChannelPtr newChannel)
|
||||
if (this->lastMessageHasAlternateBackground_) {
|
||||
messageRef->flags |= MessageLayout::AlternateBackground;
|
||||
}
|
||||
this->lastMessageHasAlternateBackground_ = !this->lastMessageHasAlternateBackground_;
|
||||
this->lastMessageHasAlternateBackground_ =
|
||||
!this->lastMessageHasAlternateBackground_;
|
||||
|
||||
if (this->isPaused()) {
|
||||
this->messagesAddedSinceSelectionPause_++;
|
||||
}
|
||||
|
||||
if (this->messages.pushBack(MessageLayoutPtr(messageRef), deleted)) {
|
||||
if (this->messages.pushBack(MessageLayoutPtr(messageRef),
|
||||
deleted)) {
|
||||
// if (!this->isPaused()) {
|
||||
if (this->scrollBar_.isAtBottom()) {
|
||||
this->scrollBar_.scrollToBottom();
|
||||
@@ -424,9 +445,11 @@ void ChannelView::setChannel(ChannelPtr newChannel)
|
||||
|
||||
if (!(message->flags & Message::DoNotTriggerNotification)) {
|
||||
if (message->flags & Message::Highlighted) {
|
||||
this->tabHighlightRequested.invoke(HighlightState::Highlighted);
|
||||
this->tabHighlightRequested.invoke(
|
||||
HighlightState::Highlighted);
|
||||
} else {
|
||||
this->tabHighlightRequested.invoke(HighlightState::NewMessage);
|
||||
this->tabHighlightRequested.invoke(
|
||||
HighlightState::NewMessage);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -437,34 +460,37 @@ void ChannelView::setChannel(ChannelPtr newChannel)
|
||||
}));
|
||||
|
||||
this->channelConnections_.push_back(
|
||||
newChannel->messagesAddedAtStart.connect([this](std::vector<MessagePtr> &messages) {
|
||||
std::vector<MessageLayoutPtr> messageRefs;
|
||||
messageRefs.resize(messages.size());
|
||||
for (size_t i = 0; i < messages.size(); i++) {
|
||||
messageRefs.at(i) = MessageLayoutPtr(new MessageLayout(messages.at(i)));
|
||||
}
|
||||
newChannel->messagesAddedAtStart.connect(
|
||||
[this](std::vector<MessagePtr> &messages) {
|
||||
std::vector<MessageLayoutPtr> messageRefs;
|
||||
messageRefs.resize(messages.size());
|
||||
for (size_t i = 0; i < messages.size(); i++) {
|
||||
messageRefs.at(i) =
|
||||
MessageLayoutPtr(new MessageLayout(messages.at(i)));
|
||||
}
|
||||
|
||||
if (!this->isPaused()) {
|
||||
if (this->messages.pushFront(messageRefs).size() > 0) {
|
||||
if (this->scrollBar_.isAtBottom()) {
|
||||
this->scrollBar_.scrollToBottom();
|
||||
} else {
|
||||
this->scrollBar_.offset(qreal(messages.size()));
|
||||
if (!this->isPaused()) {
|
||||
if (this->messages.pushFront(messageRefs).size() > 0) {
|
||||
if (this->scrollBar_.isAtBottom()) {
|
||||
this->scrollBar_.scrollToBottom();
|
||||
} else {
|
||||
this->scrollBar_.offset(qreal(messages.size()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<ScrollbarHighlight> highlights;
|
||||
highlights.reserve(messages.size());
|
||||
for (size_t i = 0; i < messages.size(); i++) {
|
||||
highlights.push_back(messages.at(i)->getScrollBarHighlight());
|
||||
}
|
||||
std::vector<ScrollbarHighlight> highlights;
|
||||
highlights.reserve(messages.size());
|
||||
for (size_t i = 0; i < messages.size(); i++) {
|
||||
highlights.push_back(
|
||||
messages.at(i)->getScrollBarHighlight());
|
||||
}
|
||||
|
||||
this->scrollBar_.addHighlightsAtStart(highlights);
|
||||
this->scrollBar_.addHighlightsAtStart(highlights);
|
||||
|
||||
this->messageWasAdded_ = true;
|
||||
this->layoutMessages();
|
||||
}));
|
||||
this->messageWasAdded_ = true;
|
||||
this->layoutMessages();
|
||||
}));
|
||||
|
||||
// on message removed
|
||||
this->channelConnections_.push_back(
|
||||
@@ -478,17 +504,19 @@ void ChannelView::setChannel(ChannelPtr newChannel)
|
||||
}));
|
||||
|
||||
// on message replaced
|
||||
this->channelConnections_.push_back(
|
||||
newChannel->messageReplaced.connect([this](size_t index, MessagePtr replacement) {
|
||||
if (index >= this->messages.getSnapshot().getLength() || index < 0) {
|
||||
this->channelConnections_.push_back(newChannel->messageReplaced.connect(
|
||||
[this](size_t index, MessagePtr replacement) {
|
||||
if (index >= this->messages.getSnapshot().getLength() ||
|
||||
index < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
MessageLayoutPtr newItem(new MessageLayout(replacement));
|
||||
auto snapshot = this->messages.getSnapshot();
|
||||
if (index >= snapshot.getLength()) {
|
||||
Log("Tried to replace out of bounds message. Index: {}. Length: {}", index,
|
||||
snapshot.getLength());
|
||||
Log("Tried to replace out of bounds message. Index: {}. "
|
||||
"Length: {}",
|
||||
index, snapshot.getLength());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -497,7 +525,8 @@ void ChannelView::setChannel(ChannelPtr newChannel)
|
||||
newItem->flags |= MessageLayout::AlternateBackground;
|
||||
}
|
||||
|
||||
this->scrollBar_.replaceHighlight(index, replacement->getScrollBarHighlight());
|
||||
this->scrollBar_.replaceHighlight(
|
||||
index, replacement->getScrollBarHighlight());
|
||||
|
||||
this->messages.replaceItem(message, newItem);
|
||||
this->layoutMessages();
|
||||
@@ -513,7 +542,8 @@ void ChannelView::setChannel(ChannelPtr newChannel)
|
||||
if (this->lastMessageHasAlternateBackground_) {
|
||||
messageRef->flags |= MessageLayout::AlternateBackground;
|
||||
}
|
||||
this->lastMessageHasAlternateBackground_ = !this->lastMessageHasAlternateBackground_;
|
||||
this->lastMessageHasAlternateBackground_ =
|
||||
!this->lastMessageHasAlternateBackground_;
|
||||
|
||||
this->messages.pushBack(MessageLayoutPtr(messageRef), deleted);
|
||||
}
|
||||
@@ -567,7 +597,8 @@ void ChannelView::resizeEvent(QResizeEvent *)
|
||||
this->update();
|
||||
}
|
||||
|
||||
void ChannelView::setSelection(const SelectionItem &start, const SelectionItem &end)
|
||||
void ChannelView::setSelection(const SelectionItem &start,
|
||||
const SelectionItem &end)
|
||||
{
|
||||
// selections
|
||||
if (!this->selecting_ && start != end) {
|
||||
@@ -596,7 +627,8 @@ MessageElement::Flags ChannelView::getFlags() const
|
||||
|
||||
if (split != nullptr) {
|
||||
if (split->getModerationMode()) {
|
||||
flags = MessageElement::Flags(flags | MessageElement::ModeratorTools);
|
||||
flags =
|
||||
MessageElement::Flags(flags | MessageElement::ModeratorTools);
|
||||
}
|
||||
if (this->channel_ == app->twitch.server->mentionsChannel) {
|
||||
flags = MessageElement::Flags(flags | MessageElement::ChannelName);
|
||||
@@ -609,7 +641,8 @@ MessageElement::Flags ChannelView::getFlags() const
|
||||
bool ChannelView::isPaused()
|
||||
{
|
||||
return false;
|
||||
// return this->pausedTemporarily_ || this->pausedBySelection_ || this->pausedByScrollingUp_;
|
||||
// return this->pausedTemporarily_ || this->pausedBySelection_ ||
|
||||
// this->pausedByScrollingUp_;
|
||||
}
|
||||
|
||||
void ChannelView::updatePauseStatus()
|
||||
@@ -633,8 +666,8 @@ void ChannelView::paintEvent(QPaintEvent * /*event*/)
|
||||
this->drawMessages(painter);
|
||||
}
|
||||
|
||||
// if overlays is false then it draws the message, if true then it draws things such as the grey
|
||||
// overlay when a message is disabled
|
||||
// if overlays is false then it draws the message, if true then it draws things
|
||||
// such as the grey overlay when a message is disabled
|
||||
void ChannelView::drawMessages(QPainter &painter)
|
||||
{
|
||||
auto app = getApp();
|
||||
@@ -661,7 +694,8 @@ void ChannelView::drawMessages(QPainter &painter)
|
||||
isLastMessage = this->lastReadMessage_.get() == layout;
|
||||
}
|
||||
|
||||
layout->paint(painter, DRAW_WIDTH, y, i, this->selection_, isLastMessage, windowFocused);
|
||||
layout->paint(painter, DRAW_WIDTH, y, i, this->selection_,
|
||||
isLastMessage, windowFocused);
|
||||
|
||||
y += layout->getHeight();
|
||||
|
||||
@@ -732,7 +766,8 @@ void ChannelView::wheelEvent(QWheelEvent *event)
|
||||
|
||||
if (delta > 0) {
|
||||
qreal scrollFactor = fmod(desired, 1);
|
||||
qreal currentScrollLeft = int(scrollFactor * snapshot[i]->getHeight());
|
||||
qreal currentScrollLeft =
|
||||
int(scrollFactor * snapshot[i]->getHeight());
|
||||
|
||||
for (; i >= 0; i--) {
|
||||
if (delta < currentScrollLeft) {
|
||||
@@ -746,8 +781,8 @@ void ChannelView::wheelEvent(QWheelEvent *event)
|
||||
if (i == 0) {
|
||||
desired = 0;
|
||||
} else {
|
||||
snapshot[i - 1]->layout(this->getLayoutWidth(), this->getScale(),
|
||||
this->getFlags());
|
||||
snapshot[i - 1]->layout(this->getLayoutWidth(),
|
||||
this->getScale(), this->getFlags());
|
||||
scrollFactor = 1;
|
||||
currentScrollLeft = snapshot[i - 1]->getHeight();
|
||||
}
|
||||
@@ -755,11 +790,13 @@ void ChannelView::wheelEvent(QWheelEvent *event)
|
||||
} else {
|
||||
delta = -delta;
|
||||
qreal scrollFactor = 1 - fmod(desired, 1);
|
||||
qreal currentScrollLeft = int(scrollFactor * snapshot[i]->getHeight());
|
||||
qreal currentScrollLeft =
|
||||
int(scrollFactor * snapshot[i]->getHeight());
|
||||
|
||||
for (; i < snapshotLength; i++) {
|
||||
if (delta < currentScrollLeft) {
|
||||
desired += scrollFactor * (qreal(delta) / currentScrollLeft);
|
||||
desired +=
|
||||
scrollFactor * (qreal(delta) / currentScrollLeft);
|
||||
break;
|
||||
} else {
|
||||
delta -= currentScrollLeft;
|
||||
@@ -769,8 +806,8 @@ void ChannelView::wheelEvent(QWheelEvent *event)
|
||||
if (i == snapshotLength - 1) {
|
||||
desired = snapshot.getLength();
|
||||
} else {
|
||||
snapshot[i + 1]->layout(this->getLayoutWidth(), this->getScale(),
|
||||
this->getFlags());
|
||||
snapshot[i + 1]->layout(this->getLayoutWidth(),
|
||||
this->getScale(), this->getFlags());
|
||||
|
||||
scrollFactor = 1;
|
||||
currentScrollLeft = snapshot[i + 1]->getHeight();
|
||||
@@ -826,7 +863,8 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event)
|
||||
this->pause(300);
|
||||
int index = layout->getSelectionIndex(relativePos);
|
||||
|
||||
this->setSelection(this->selection_.start, SelectionItem(messageIndex, index));
|
||||
this->setSelection(this->selection_.start,
|
||||
SelectionItem(messageIndex, index));
|
||||
|
||||
this->queueUpdate();
|
||||
}
|
||||
@@ -839,7 +877,8 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event)
|
||||
}
|
||||
|
||||
// check if word underneath cursor
|
||||
const MessageLayoutElement *hoverLayoutElement = layout->getElementAt(relativePos);
|
||||
const MessageLayoutElement *hoverLayoutElement =
|
||||
layout->getElementAt(relativePos);
|
||||
|
||||
if (hoverLayoutElement == nullptr) {
|
||||
this->setCursor(Qt::ArrowCursor);
|
||||
@@ -934,7 +973,8 @@ void ChannelView::mouseReleaseEvent(QMouseEvent *event)
|
||||
if (this->isMouseDown_) {
|
||||
this->isMouseDown_ = false;
|
||||
|
||||
if (fabsf(distanceBetweenPoints(this->lastPressPosition_, event->screenPos())) > 15.f) {
|
||||
if (fabsf(distanceBetweenPoints(this->lastPressPosition_,
|
||||
event->screenPos())) > 15.f) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
@@ -944,8 +984,8 @@ void ChannelView::mouseReleaseEvent(QMouseEvent *event)
|
||||
if (this->isRightMouseDown_) {
|
||||
this->isRightMouseDown_ = false;
|
||||
|
||||
if (fabsf(distanceBetweenPoints(this->lastRightPressPosition_, event->screenPos())) >
|
||||
15.f) {
|
||||
if (fabsf(distanceBetweenPoints(this->lastRightPressPosition_,
|
||||
event->screenPos())) > 15.f) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
@@ -978,7 +1018,8 @@ void ChannelView::mouseReleaseEvent(QMouseEvent *event)
|
||||
return;
|
||||
}
|
||||
|
||||
const MessageLayoutElement *hoverLayoutElement = layout->getElementAt(relativePos);
|
||||
const MessageLayoutElement *hoverLayoutElement =
|
||||
layout->getElementAt(relativePos);
|
||||
|
||||
if (hoverLayoutElement == nullptr) {
|
||||
return;
|
||||
@@ -988,7 +1029,8 @@ void ChannelView::mouseReleaseEvent(QMouseEvent *event)
|
||||
this->handleMouseClick(event, hoverLayoutElement, layout.get());
|
||||
}
|
||||
|
||||
void ChannelView::handleMouseClick(QMouseEvent *event, const MessageLayoutElement *hoveredElement,
|
||||
void ChannelView::handleMouseClick(QMouseEvent *event,
|
||||
const MessageLayoutElement *hoveredElement,
|
||||
MessageLayout *layout)
|
||||
{
|
||||
switch (event->button()) {
|
||||
@@ -1029,8 +1071,8 @@ void ChannelView::handleMouseClick(QMouseEvent *event, const MessageLayoutElemen
|
||||
}
|
||||
}
|
||||
|
||||
void ChannelView::addContextMenuItems(const MessageLayoutElement *hoveredElement,
|
||||
MessageLayout *layout)
|
||||
void ChannelView::addContextMenuItems(
|
||||
const MessageLayoutElement *hoveredElement, MessageLayout *layout)
|
||||
{
|
||||
const auto &creator = hoveredElement->getCreator();
|
||||
auto creatorFlags = creator.getFlags();
|
||||
@@ -1039,9 +1081,12 @@ void ChannelView::addContextMenuItems(const MessageLayoutElement *hoveredElement
|
||||
menu->clear();
|
||||
|
||||
// Emote actions
|
||||
if (creatorFlags & (MessageElement::Flags::EmoteImages | MessageElement::Flags::EmojiImage)) {
|
||||
if (creatorFlags & (MessageElement::Flags::EmoteImages |
|
||||
MessageElement::Flags::EmojiImage)) {
|
||||
const auto emoteElement = dynamic_cast<const EmoteElement *>(&creator);
|
||||
if (emoteElement) addEmoteContextMenuItems(*emoteElement->getEmote(), creatorFlags, *menu);
|
||||
if (emoteElement)
|
||||
addEmoteContextMenuItems(*emoteElement->getEmote(), creatorFlags,
|
||||
*menu);
|
||||
}
|
||||
|
||||
// add seperator
|
||||
@@ -1053,16 +1098,19 @@ void ChannelView::addContextMenuItems(const MessageLayoutElement *hoveredElement
|
||||
if (hoveredElement->getLink().type == Link::Url) {
|
||||
QString url = hoveredElement->getLink().value;
|
||||
|
||||
menu->addAction("Open link", [url] { QDesktopServices::openUrl(QUrl(url)); });
|
||||
menu->addAction("Copy link", [url] { QApplication::clipboard()->setText(url); });
|
||||
menu->addAction("Open link",
|
||||
[url] { QDesktopServices::openUrl(QUrl(url)); });
|
||||
menu->addAction("Copy link",
|
||||
[url] { QApplication::clipboard()->setText(url); });
|
||||
|
||||
menu->addSeparator();
|
||||
}
|
||||
|
||||
// Copy actions
|
||||
if (!this->selection_.isEmpty()) {
|
||||
menu->addAction("Copy selection",
|
||||
[this] { QGuiApplication::clipboard()->setText(this->getSelectedText()); });
|
||||
menu->addAction("Copy selection", [this] {
|
||||
QGuiApplication::clipboard()->setText(this->getSelectedText());
|
||||
});
|
||||
}
|
||||
|
||||
menu->addAction("Copy message", [layout] {
|
||||
@@ -1103,7 +1151,8 @@ void ChannelView::mouseDoubleClickEvent(QMouseEvent *event)
|
||||
return;
|
||||
}
|
||||
|
||||
const MessageLayoutElement *hoverLayoutElement = layout->getElementAt(relativePos);
|
||||
const MessageLayoutElement *hoverLayoutElement =
|
||||
layout->getElementAt(relativePos);
|
||||
|
||||
if (hoverLayoutElement == nullptr) {
|
||||
return;
|
||||
@@ -1123,7 +1172,8 @@ void ChannelView::hideEvent(QHideEvent *)
|
||||
this->messagesOnScreen_.clear();
|
||||
}
|
||||
|
||||
void ChannelView::handleLinkClick(QMouseEvent *event, const Link &link, MessageLayout *layout)
|
||||
void ChannelView::handleLinkClick(QMouseEvent *event, const Link &link,
|
||||
MessageLayout *layout)
|
||||
{
|
||||
if (event->button() != Qt::LeftButton) {
|
||||
return;
|
||||
@@ -1136,7 +1186,8 @@ void ChannelView::handleLinkClick(QMouseEvent *event, const Link &link, MessageL
|
||||
auto *userPopup = new UserInfoPopup;
|
||||
userPopup->setData(user, this->channel_);
|
||||
userPopup->setActionOnFocusLoss(BaseWindow::Delete);
|
||||
QPoint offset(int(150 * this->getScale()), int(70 * this->getScale()));
|
||||
QPoint offset(int(150 * this->getScale()),
|
||||
int(70 * this->getScale()));
|
||||
userPopup->move(QCursor::pos() - offset);
|
||||
userPopup->show();
|
||||
|
||||
@@ -1159,7 +1210,8 @@ void ChannelView::handleLinkClick(QMouseEvent *event, const Link &link, MessageL
|
||||
}
|
||||
}
|
||||
|
||||
bool ChannelView::tryGetMessageAt(QPoint p, std::shared_ptr<MessageLayout> &_message,
|
||||
bool ChannelView::tryGetMessageAt(QPoint p,
|
||||
std::shared_ptr<MessageLayout> &_message,
|
||||
QPoint &relativePos, int &index)
|
||||
{
|
||||
auto messagesSnapshot = this->getMessagesSnapshot();
|
||||
@@ -1170,7 +1222,8 @@ bool ChannelView::tryGetMessageAt(QPoint p, std::shared_ptr<MessageLayout> &_mes
|
||||
return false;
|
||||
}
|
||||
|
||||
int y = -(messagesSnapshot[start]->getHeight() * (fmod(this->scrollBar_.getCurrentValue(), 1)));
|
||||
int y = -(messagesSnapshot[start]->getHeight() *
|
||||
(fmod(this->scrollBar_.getCurrentValue(), 1)));
|
||||
|
||||
for (size_t i = start; i < messagesSnapshot.getLength(); ++i) {
|
||||
auto message = messagesSnapshot[i];
|
||||
@@ -1190,7 +1243,8 @@ bool ChannelView::tryGetMessageAt(QPoint p, std::shared_ptr<MessageLayout> &_mes
|
||||
|
||||
int ChannelView::getLayoutWidth() const
|
||||
{
|
||||
if (this->scrollBar_.isVisible()) return int(this->width() - 8 * this->getScale());
|
||||
if (this->scrollBar_.isVisible())
|
||||
return int(this->width() - 8 * this->getScale());
|
||||
|
||||
return this->width();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user