2018-06-26 14:09:39 +02:00
|
|
|
#include "ChannelView.hpp"
|
|
|
|
|
|
|
|
#include "Application.hpp"
|
|
|
|
#include "debug/Log.hpp"
|
|
|
|
#include "messages/layouts/MessageLayout.hpp"
|
|
|
|
#include "messages/LimitedQueueSnapshot.hpp"
|
|
|
|
#include "messages/Message.hpp"
|
|
|
|
#include "providers/twitch/TwitchServer.hpp"
|
|
|
|
#include "singletons/SettingsManager.hpp"
|
|
|
|
#include "singletons/ThemeManager.hpp"
|
|
|
|
#include "singletons/WindowManager.hpp"
|
|
|
|
#include "util/Benchmark.hpp"
|
|
|
|
#include "util/DistanceBetweenPoints.hpp"
|
2018-06-26 14:39:22 +02:00
|
|
|
#include "widgets/splits/Split.hpp"
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "widgets/TooltipWidget.hpp"
|
|
|
|
#include "widgets/UserInfoPopup.hpp"
|
2017-01-11 01:08:20 +01:00
|
|
|
|
2018-01-24 21:16:00 +01:00
|
|
|
#include <QClipboard>
|
2017-02-01 16:28:28 +01:00
|
|
|
#include <QDebug>
|
2017-07-26 09:08:19 +02:00
|
|
|
#include <QDesktopServices>
|
2017-02-07 00:03:15 +01:00
|
|
|
#include <QGraphicsBlurEffect>
|
2017-01-11 01:08:20 +01:00
|
|
|
#include <QPainter>
|
2017-06-06 17:18:23 +02:00
|
|
|
|
2017-09-12 19:06:16 +02:00
|
|
|
#include <algorithm>
|
2017-02-07 00:03:15 +01:00
|
|
|
#include <chrono>
|
2018-04-03 02:55:32 +02:00
|
|
|
#include <cmath>
|
2017-01-18 01:04:54 +01:00
|
|
|
#include <functional>
|
2017-09-12 19:06:16 +02:00
|
|
|
#include <memory>
|
2017-01-01 02:30:42 +01:00
|
|
|
|
2018-05-31 12:59:43 +02:00
|
|
|
#define DRAW_WIDTH (this->width())
|
2018-05-17 12:16:13 +02:00
|
|
|
#define SELECTION_RESUME_SCROLLING_MSG_THRESHOLD 3
|
2018-06-13 13:27:10 +02:00
|
|
|
#define CHAT_HOVER_PAUSE_DURATION 1000
|
2018-01-05 10:41:21 +01:00
|
|
|
|
2017-09-16 00:05:06 +02:00
|
|
|
using namespace chatterino::messages;
|
2018-02-05 15:11:50 +01:00
|
|
|
using namespace chatterino::providers::twitch;
|
2017-09-16 00:05:06 +02:00
|
|
|
|
2017-01-18 21:30:23 +01:00
|
|
|
namespace chatterino {
|
|
|
|
namespace widgets {
|
|
|
|
|
2017-12-17 02:18:13 +01:00
|
|
|
ChannelView::ChannelView(BaseWidget *parent)
|
2017-09-16 00:05:06 +02:00
|
|
|
: BaseWidget(parent)
|
2018-06-13 13:27:10 +02:00
|
|
|
, scrollBar_(this)
|
2017-01-01 02:30:42 +01:00
|
|
|
{
|
2018-04-27 22:11:19 +02:00
|
|
|
auto app = getApp();
|
|
|
|
|
2017-06-11 11:36:42 +02:00
|
|
|
this->setMouseTracking(true);
|
2017-01-22 12:46:35 +01:00
|
|
|
|
2018-06-13 13:29:11 +02:00
|
|
|
this->connections_.push_back(app->settings->wordFlagsChanged.connect([this] {
|
2018-04-27 22:11:19 +02:00
|
|
|
this->layoutMessages();
|
|
|
|
this->update();
|
|
|
|
}));
|
2017-01-26 04:26:40 +01:00
|
|
|
|
2018-06-13 13:27:10 +02:00
|
|
|
this->scrollBar_.getCurrentValueChanged().connect([this] {
|
2017-06-06 17:18:23 +02:00
|
|
|
// Whenever the scrollbar value has been changed, re-render the ChatWidgetView
|
2018-05-06 16:12:21 +02:00
|
|
|
this->actuallyLayoutMessages(true);
|
2018-05-17 17:27:20 +02:00
|
|
|
|
2018-06-13 13:27:10 +02:00
|
|
|
// if (!this->isPaused()) {
|
|
|
|
this->goToBottom_->setVisible(this->enableScrollingToBottom_ &&
|
|
|
|
this->scrollBar_.isVisible() &&
|
|
|
|
!this->scrollBar_.isAtBottom());
|
|
|
|
// }
|
2017-09-21 17:34:41 +02:00
|
|
|
|
2017-10-11 10:34:04 +02:00
|
|
|
this->queueUpdate();
|
2017-06-06 17:18:23 +02:00
|
|
|
});
|
2017-09-17 02:13:57 +02:00
|
|
|
|
2018-06-13 03:58:52 +02:00
|
|
|
this->scrollBar_.getDesiredValueChanged().connect(
|
|
|
|
[this] { this->pausedByScrollingUp_ = !this->scrollBar_.isAtBottom(); });
|
|
|
|
|
2018-06-13 03:58:52 +02:00
|
|
|
this->connections_.push_back(app->windows->repaintGifs.connect([&] {
|
2018-04-27 22:11:19 +02:00
|
|
|
this->queueUpdate(); //
|
2018-06-13 03:58:52 +02:00
|
|
|
}));
|
|
|
|
|
|
|
|
this->connections_.push_back(app->windows->layout.connect([&](Channel *channel) {
|
2018-06-13 03:58:52 +02:00
|
|
|
if (channel == nullptr || this->channel_.get() == channel) {
|
2018-01-01 23:29:54 +01:00
|
|
|
this->layoutMessages();
|
|
|
|
}
|
2018-06-13 03:58:52 +02:00
|
|
|
}));
|
2017-09-21 17:34:41 +02:00
|
|
|
|
2018-06-13 13:27:10 +02:00
|
|
|
this->goToBottom_ = new RippleEffectLabel(this, 0);
|
|
|
|
this->goToBottom_->setStyleSheet("background-color: rgba(0,0,0,0.66); color: #FFF;");
|
|
|
|
this->goToBottom_->getLabel().setText("More messages below");
|
|
|
|
this->goToBottom_->setVisible(false);
|
2017-09-21 17:34:41 +02:00
|
|
|
|
2018-06-13 03:58:52 +02:00
|
|
|
this->connections_.emplace_back(app->fonts->fontChanged.connect([this] {
|
2018-04-28 15:20:18 +02:00
|
|
|
this->layoutMessages(); //
|
|
|
|
}));
|
2017-12-17 03:26:23 +01:00
|
|
|
|
2018-06-13 03:58:52 +02:00
|
|
|
QObject::connect(this->goToBottom_, &RippleEffectLabel::clicked, this, [=] {
|
2018-04-27 22:11:19 +02:00
|
|
|
QTimer::singleShot(180, [=] {
|
2018-06-13 13:27:10 +02:00
|
|
|
this->scrollBar_.scrollToBottom(
|
2018-04-27 22:11:19 +02:00
|
|
|
app->settings->enableSmoothScrollingNewMessages.getValue());
|
2018-01-05 03:14:46 +01:00
|
|
|
});
|
|
|
|
});
|
2017-10-11 10:34:04 +02:00
|
|
|
|
2018-04-06 18:27:49 +02:00
|
|
|
// this->updateTimer.setInterval(1000 / 60);
|
|
|
|
// this->updateTimer.setSingleShot(true);
|
|
|
|
// connect(&this->updateTimer, &QTimer::timeout, this, [this] {
|
|
|
|
// if (this->updateQueued) {
|
|
|
|
// this->updateQueued = false;
|
|
|
|
// this->repaint();
|
|
|
|
// this->updateTimer.start();
|
|
|
|
// }
|
|
|
|
// });
|
2018-01-05 11:22:51 +01:00
|
|
|
|
2018-06-13 13:27:10 +02:00
|
|
|
this->pauseTimeout_.setSingleShot(true);
|
|
|
|
QObject::connect(&this->pauseTimeout_, &QTimer::timeout, [this] {
|
|
|
|
this->pausedTemporarily_ = false;
|
|
|
|
this->updatePauseStatus();
|
2018-05-17 17:27:20 +02:00
|
|
|
this->layoutMessages();
|
2018-05-17 12:16:13 +02:00
|
|
|
});
|
2018-01-16 01:40:52 +01:00
|
|
|
|
2018-04-27 22:11:19 +02:00
|
|
|
app->settings->showLastMessageIndicator.connect(
|
|
|
|
[this](auto, auto) {
|
|
|
|
this->update(); //
|
|
|
|
},
|
2018-06-13 03:58:52 +02:00
|
|
|
this->connections_);
|
2018-04-06 18:27:49 +02:00
|
|
|
|
2018-06-13 13:27:10 +02:00
|
|
|
this->layoutCooldown_ = new QTimer(this);
|
|
|
|
this->layoutCooldown_->setSingleShot(true);
|
|
|
|
this->layoutCooldown_->setInterval(66);
|
2018-04-06 18:27:49 +02:00
|
|
|
|
2018-06-13 13:27:10 +02:00
|
|
|
QObject::connect(this->layoutCooldown_, &QTimer::timeout, [this] {
|
|
|
|
if (this->layoutQueued_) {
|
2018-04-06 18:27:49 +02:00
|
|
|
this->layoutMessages();
|
2018-06-13 13:27:10 +02:00
|
|
|
this->layoutQueued_ = false;
|
2018-04-06 18:27:49 +02:00
|
|
|
}
|
|
|
|
});
|
2018-05-17 12:16:13 +02:00
|
|
|
|
2018-05-23 13:54:42 +02:00
|
|
|
QShortcut *shortcut = new QShortcut(QKeySequence("Ctrl+C"), this);
|
|
|
|
QObject::connect(shortcut, &QShortcut::activated,
|
|
|
|
[this] { QGuiApplication::clipboard()->setText(this->getSelectedText()); });
|
|
|
|
}
|
2017-01-22 12:46:35 +01:00
|
|
|
|
2017-09-16 00:05:06 +02:00
|
|
|
ChannelView::~ChannelView()
|
2017-01-22 12:46:35 +01:00
|
|
|
{
|
2017-01-01 02:30:42 +01:00
|
|
|
}
|
2017-01-03 21:19:33 +01:00
|
|
|
|
2018-01-25 20:49:49 +01:00
|
|
|
void ChannelView::themeRefreshEvent()
|
2018-01-24 20:35:26 +01:00
|
|
|
{
|
2018-01-25 20:49:49 +01:00
|
|
|
BaseWidget::themeRefreshEvent();
|
2018-01-24 20:35:26 +01:00
|
|
|
|
|
|
|
this->layoutMessages();
|
|
|
|
}
|
|
|
|
|
2017-10-11 10:34:04 +02:00
|
|
|
void ChannelView::queueUpdate()
|
2017-01-03 21:19:33 +01:00
|
|
|
{
|
2018-04-06 23:31:34 +02:00
|
|
|
// if (this->updateTimer.isActive()) {
|
|
|
|
// this->updateQueued = true;
|
|
|
|
// return;
|
|
|
|
// }
|
2017-10-11 10:34:04 +02:00
|
|
|
|
2018-01-19 23:41:02 +01:00
|
|
|
// this->repaint();
|
|
|
|
this->update();
|
2017-10-11 10:34:04 +02:00
|
|
|
|
2018-04-06 23:31:34 +02:00
|
|
|
// this->updateTimer.start();
|
2017-10-11 10:34:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ChannelView::layoutMessages()
|
|
|
|
{
|
2018-04-10 02:07:25 +02:00
|
|
|
// if (!this->layoutCooldown->isActive()) {
|
|
|
|
this->actuallyLayoutMessages();
|
2018-04-06 18:27:49 +02:00
|
|
|
|
2018-04-10 02:07:25 +02:00
|
|
|
// this->layoutCooldown->start();
|
|
|
|
// } else {
|
|
|
|
// this->layoutQueued = true;
|
|
|
|
// }
|
2017-10-11 10:34:04 +02:00
|
|
|
}
|
|
|
|
|
2018-05-06 16:12:21 +02:00
|
|
|
void ChannelView::actuallyLayoutMessages(bool causedByScrollbar)
|
2017-10-11 10:34:04 +02:00
|
|
|
{
|
2018-05-26 16:31:43 +02:00
|
|
|
// BenchmarkGuard benchmark("layout messages");
|
2018-05-25 12:45:18 +02:00
|
|
|
|
2018-04-27 22:11:19 +02:00
|
|
|
auto app = getApp();
|
|
|
|
|
2017-12-22 15:13:42 +01:00
|
|
|
auto messagesSnapshot = this->getMessagesSnapshot();
|
2017-01-11 01:08:20 +01:00
|
|
|
|
2017-12-22 15:13:42 +01:00
|
|
|
if (messagesSnapshot.getLength() == 0) {
|
2018-06-13 13:27:10 +02:00
|
|
|
this->scrollBar_.setVisible(false);
|
2017-10-11 10:34:04 +02:00
|
|
|
|
|
|
|
return;
|
2017-02-03 19:31:51 +01:00
|
|
|
}
|
|
|
|
|
2017-10-11 10:34:04 +02:00
|
|
|
bool redrawRequired = false;
|
2017-06-11 11:36:42 +02:00
|
|
|
bool showScrollbar = false;
|
2017-02-03 19:31:51 +01:00
|
|
|
|
2017-06-06 17:18:23 +02:00
|
|
|
// Bool indicating whether or not we were showing all messages
|
|
|
|
// True if one of the following statements are true:
|
|
|
|
// The scrollbar was not visible
|
|
|
|
// The scrollbar was visible and at the bottom
|
2018-06-13 13:27:10 +02:00
|
|
|
this->showingLatestMessages_ = this->scrollBar_.isAtBottom() || !this->scrollBar_.isVisible();
|
2017-06-06 17:18:23 +02:00
|
|
|
|
2018-06-13 13:27:10 +02:00
|
|
|
size_t start = size_t(this->scrollBar_.getCurrentValue());
|
2018-06-13 03:58:52 +02:00
|
|
|
int layoutWidth = this->getLayoutWidth();
|
2017-02-03 19:31:51 +01:00
|
|
|
|
2018-01-17 16:52:51 +01:00
|
|
|
MessageElement::Flags flags = this->getFlags();
|
|
|
|
|
2017-02-06 18:31:25 +01:00
|
|
|
// layout the visible messages in the view
|
2017-12-22 15:13:42 +01:00
|
|
|
if (messagesSnapshot.getLength() > start) {
|
2018-06-13 13:27:10 +02:00
|
|
|
int y = int(-(messagesSnapshot[start]->getHeight() *
|
|
|
|
(fmod(this->scrollBar_.getCurrentValue(), 1))));
|
2017-02-06 11:38:26 +01:00
|
|
|
|
2017-12-22 15:13:42 +01:00
|
|
|
for (size_t i = start; i < messagesSnapshot.getLength(); ++i) {
|
|
|
|
auto message = messagesSnapshot[i];
|
2017-01-16 03:15:07 +01:00
|
|
|
|
2018-01-25 20:49:49 +01:00
|
|
|
redrawRequired |= message->layout(layoutWidth, this->getScale(), flags);
|
2017-02-02 20:35:12 +01:00
|
|
|
|
2017-02-06 18:31:25 +01:00
|
|
|
y += message->getHeight();
|
2017-02-03 19:31:51 +01:00
|
|
|
|
2018-04-25 14:49:30 +02:00
|
|
|
if (y >= this->height()) {
|
2017-02-06 18:31:25 +01:00
|
|
|
break;
|
|
|
|
}
|
2017-02-03 19:31:51 +01:00
|
|
|
}
|
|
|
|
}
|
2017-01-16 03:15:07 +01:00
|
|
|
|
2017-02-06 18:31:25 +01:00
|
|
|
// layout the messages at the bottom to determine the scrollbar thumb size
|
2018-04-25 14:49:30 +02:00
|
|
|
int h = this->height() - 8;
|
2017-01-26 04:26:40 +01:00
|
|
|
|
2018-06-13 13:27:10 +02:00
|
|
|
for (int i = int(messagesSnapshot.getLength()) - 1; i >= 0; i--) {
|
2017-12-22 15:13:42 +01:00
|
|
|
auto *message = messagesSnapshot[i].get();
|
2017-01-16 03:15:07 +01:00
|
|
|
|
2018-01-25 20:49:49 +01:00
|
|
|
message->layout(layoutWidth, this->getScale(), flags);
|
2017-01-26 04:26:40 +01:00
|
|
|
|
2017-01-26 07:10:46 +01:00
|
|
|
h -= message->getHeight();
|
|
|
|
|
|
|
|
if (h < 0) {
|
2018-06-13 13:27:10 +02:00
|
|
|
this->scrollBar_.setLargeChange((messagesSnapshot.getLength() - i) +
|
|
|
|
qreal(h) / message->getHeight());
|
2017-12-18 20:18:20 +01:00
|
|
|
// this->scrollBar.setDesiredValue(this->scrollBar.getDesiredValue());
|
2017-01-26 07:10:46 +01:00
|
|
|
|
|
|
|
showScrollbar = true;
|
2017-02-01 16:28:28 +01:00
|
|
|
break;
|
2017-01-26 07:10:46 +01:00
|
|
|
}
|
2017-01-26 04:26:40 +01:00
|
|
|
}
|
|
|
|
|
2018-06-13 13:27:10 +02:00
|
|
|
this->scrollBar_.setVisible(showScrollbar);
|
2017-01-26 07:10:46 +01:00
|
|
|
|
2018-06-13 13:27:10 +02:00
|
|
|
if (!showScrollbar && !causedByScrollbar) {
|
|
|
|
this->scrollBar_.setDesiredValue(0);
|
2017-02-07 00:03:15 +01:00
|
|
|
}
|
|
|
|
|
2018-06-13 13:27:10 +02:00
|
|
|
this->scrollBar_.setMaximum(messagesSnapshot.getLength());
|
2017-01-26 07:10:46 +01:00
|
|
|
|
2018-01-05 03:14:46 +01:00
|
|
|
// If we were showing the latest messages and the scrollbar now wants to be rendered, scroll
|
|
|
|
// to bottom
|
2018-06-13 13:27:10 +02:00
|
|
|
if (this->enableScrollingToBottom_ && this->showingLatestMessages_ && showScrollbar) {
|
2018-05-17 17:27:20 +02:00
|
|
|
if (!this->isPaused()) {
|
2018-06-13 13:27:10 +02:00
|
|
|
this->scrollBar_.scrollToBottom(
|
2018-05-23 20:22:41 +02:00
|
|
|
// this->messageWasAdded &&
|
2018-05-17 17:27:20 +02:00
|
|
|
app->settings->enableSmoothScrollingNewMessages.getValue());
|
|
|
|
}
|
2018-06-13 13:27:10 +02:00
|
|
|
this->messageWasAdded_ = false;
|
2017-06-06 17:18:23 +02:00
|
|
|
}
|
|
|
|
|
2017-10-11 10:34:04 +02:00
|
|
|
if (redrawRequired) {
|
|
|
|
this->queueUpdate();
|
|
|
|
}
|
2017-01-26 04:26:40 +01:00
|
|
|
}
|
|
|
|
|
2017-09-16 00:05:06 +02:00
|
|
|
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
|
|
|
|
this->layoutMessages();
|
2017-10-11 10:34:04 +02:00
|
|
|
this->queueUpdate();
|
2017-09-16 00:05:06 +02:00
|
|
|
}
|
|
|
|
|
2018-01-06 03:48:56 +01:00
|
|
|
Scrollbar &ChannelView::getScrollBar()
|
2017-04-12 17:46:44 +02:00
|
|
|
{
|
2018-06-13 13:27:10 +02:00
|
|
|
return this->scrollBar_;
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
|
|
|
|
2017-09-16 00:05:06 +02:00
|
|
|
QString ChannelView::getSelectedText()
|
2017-09-12 19:06:16 +02:00
|
|
|
{
|
2018-01-16 02:39:31 +01:00
|
|
|
QString result = "";
|
2017-09-12 19:06:16 +02:00
|
|
|
|
2018-01-16 02:39:31 +01:00
|
|
|
messages::LimitedQueueSnapshot<MessageLayoutPtr> messagesSnapshot = this->getMessagesSnapshot();
|
2017-09-12 19:06:16 +02:00
|
|
|
|
2018-06-13 13:27:10 +02:00
|
|
|
Selection _selection = this->selection_;
|
2017-09-12 19:06:16 +02:00
|
|
|
|
2018-05-06 14:57:57 +02:00
|
|
|
if (_selection.isEmpty()) {
|
2018-01-16 02:39:31 +01:00
|
|
|
return result;
|
|
|
|
}
|
2017-09-12 19:06:16 +02:00
|
|
|
|
2018-05-06 14:57:57 +02:00
|
|
|
for (int msg = _selection.selectionMin.messageIndex;
|
|
|
|
msg <= _selection.selectionMax.messageIndex; msg++) {
|
2018-01-16 02:39:31 +01:00
|
|
|
MessageLayoutPtr layout = messagesSnapshot[msg];
|
2018-04-15 15:09:31 +02:00
|
|
|
int from =
|
2018-05-06 14:57:57 +02:00
|
|
|
msg == _selection.selectionMin.messageIndex ? _selection.selectionMin.charIndex : 0;
|
|
|
|
int to = msg == _selection.selectionMax.messageIndex ? _selection.selectionMax.charIndex
|
|
|
|
: layout->getLastCharacterIndex() + 1;
|
2018-04-10 15:48:56 +02:00
|
|
|
|
|
|
|
qDebug() << "from:" << from << ", to:" << to;
|
2017-09-12 19:06:16 +02:00
|
|
|
|
2018-01-16 02:39:31 +01:00
|
|
|
layout->addSelectionText(result, from, to);
|
|
|
|
}
|
2018-05-06 14:57:57 +02:00
|
|
|
qDebug() << "xd <";
|
2017-09-12 19:06:16 +02:00
|
|
|
|
2018-01-16 02:39:31 +01:00
|
|
|
return result;
|
2017-09-12 19:06:16 +02:00
|
|
|
}
|
|
|
|
|
2017-09-21 02:20:02 +02:00
|
|
|
bool ChannelView::hasSelection()
|
|
|
|
{
|
2018-06-13 13:27:10 +02:00
|
|
|
return !this->selection_.isEmpty();
|
2017-09-21 02:20:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ChannelView::clearSelection()
|
|
|
|
{
|
2018-06-13 13:27:10 +02:00
|
|
|
this->selection_ = Selection();
|
2017-09-21 02:20:02 +02:00
|
|
|
layoutMessages();
|
|
|
|
}
|
|
|
|
|
2017-12-28 00:48:21 +01:00
|
|
|
void ChannelView::setEnableScrollingToBottom(bool value)
|
|
|
|
{
|
2018-06-13 13:27:10 +02:00
|
|
|
this->enableScrollingToBottom_ = value;
|
2017-12-28 00:48:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ChannelView::getEnableScrollingToBottom() const
|
|
|
|
{
|
2018-06-13 13:27:10 +02:00
|
|
|
return this->enableScrollingToBottom_;
|
2017-12-28 00:48:21 +01:00
|
|
|
}
|
|
|
|
|
2018-01-27 21:13:22 +01:00
|
|
|
void ChannelView::setOverrideFlags(boost::optional<messages::MessageElement::Flags> value)
|
|
|
|
{
|
2018-06-13 13:27:10 +02:00
|
|
|
this->overrideFlags_ = value;
|
2018-01-27 21:13:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const boost::optional<messages::MessageElement::Flags> &ChannelView::getOverrideFlags() const
|
|
|
|
{
|
2018-06-13 13:27:10 +02:00
|
|
|
return this->overrideFlags_;
|
2018-01-27 21:13:22 +01:00
|
|
|
}
|
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
messages::LimitedQueueSnapshot<MessageLayoutPtr> ChannelView::getMessagesSnapshot()
|
2017-09-16 00:05:06 +02:00
|
|
|
{
|
2018-06-13 13:27:10 +02:00
|
|
|
if (!this->isPaused() /*|| this->scrollBar_.isVisible()*/) {
|
|
|
|
this->snapshot_ = this->messages.getSnapshot();
|
|
|
|
}
|
2018-01-05 11:22:51 +01:00
|
|
|
|
2018-06-13 13:27:10 +02:00
|
|
|
return this->snapshot_;
|
2017-09-16 00:05:06 +02:00
|
|
|
}
|
|
|
|
|
2018-01-24 13:15:41 +01:00
|
|
|
void ChannelView::setChannel(ChannelPtr newChannel)
|
2017-09-16 00:05:06 +02:00
|
|
|
{
|
2018-06-13 13:27:10 +02:00
|
|
|
if (this->channel_) {
|
2017-09-16 00:05:06 +02:00
|
|
|
this->detachChannel();
|
|
|
|
}
|
2018-04-20 19:54:45 +02:00
|
|
|
|
2017-09-16 00:05:06 +02:00
|
|
|
this->messages.clear();
|
|
|
|
|
|
|
|
// on new message
|
2018-06-13 03:58:52 +02:00
|
|
|
this->channelConnections_.push_back(
|
2018-01-11 20:16:25 +01:00
|
|
|
newChannel->messageAppended.connect([this](MessagePtr &message) {
|
|
|
|
MessageLayoutPtr deleted;
|
2017-09-16 00:05:06 +02:00
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
auto messageRef = new MessageLayout(message);
|
2017-09-16 00:05:06 +02:00
|
|
|
|
2018-06-13 13:27:10 +02:00
|
|
|
if (this->lastMessageHasAlternateBackground_) {
|
2018-05-06 14:38:23 +02:00
|
|
|
messageRef->flags |= MessageLayout::AlternateBackground;
|
|
|
|
}
|
2018-06-13 13:27:10 +02:00
|
|
|
this->lastMessageHasAlternateBackground_ = !this->lastMessageHasAlternateBackground_;
|
2018-05-06 14:38:23 +02:00
|
|
|
|
2018-05-17 12:16:13 +02:00
|
|
|
if (this->isPaused()) {
|
2018-06-13 13:27:10 +02:00
|
|
|
this->messagesAddedSinceSelectionPause_++;
|
2018-05-17 12:16:13 +02:00
|
|
|
}
|
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
if (this->messages.pushBack(MessageLayoutPtr(messageRef), deleted)) {
|
2018-05-17 12:16:13 +02:00
|
|
|
// if (!this->isPaused()) {
|
2018-06-13 13:27:10 +02:00
|
|
|
if (this->scrollBar_.isAtBottom()) {
|
|
|
|
this->scrollBar_.scrollToBottom();
|
2018-05-17 12:16:13 +02:00
|
|
|
} else {
|
2018-06-13 13:27:10 +02:00
|
|
|
this->scrollBar_.offset(-1);
|
2017-12-18 22:13:46 +01:00
|
|
|
}
|
2018-05-17 12:16:13 +02:00
|
|
|
// }
|
2017-09-16 00:05:06 +02:00
|
|
|
}
|
|
|
|
|
2018-04-10 16:53:40 +02:00
|
|
|
if (!(message->flags & Message::DoNotTriggerNotification)) {
|
|
|
|
if (message->flags & Message::Highlighted) {
|
|
|
|
this->tabHighlightRequested.invoke(HighlightState::Highlighted);
|
|
|
|
} else {
|
|
|
|
this->tabHighlightRequested.invoke(HighlightState::NewMessage);
|
|
|
|
}
|
2017-12-26 12:32:24 +01:00
|
|
|
}
|
|
|
|
|
2018-06-13 13:27:10 +02:00
|
|
|
this->scrollBar_.addHighlight(message->getScrollBarHighlight());
|
2018-01-06 03:48:56 +01:00
|
|
|
|
2018-06-13 13:27:10 +02:00
|
|
|
this->messageWasAdded_ = true;
|
2018-01-05 03:14:46 +01:00
|
|
|
this->layoutMessages();
|
2018-06-13 03:58:52 +02:00
|
|
|
}));
|
2018-01-01 22:29:21 +01:00
|
|
|
|
2018-06-13 03:58:52 +02:00
|
|
|
this->channelConnections_.push_back(
|
2018-01-11 20:16:25 +01:00
|
|
|
newChannel->messagesAddedAtStart.connect([this](std::vector<MessagePtr> &messages) {
|
|
|
|
std::vector<MessageLayoutPtr> messageRefs;
|
2018-01-01 22:29:21 +01:00
|
|
|
messageRefs.resize(messages.size());
|
2018-01-11 20:16:25 +01:00
|
|
|
for (size_t i = 0; i < messages.size(); i++) {
|
|
|
|
messageRefs.at(i) = MessageLayoutPtr(new MessageLayout(messages.at(i)));
|
2018-01-01 22:29:21 +01:00
|
|
|
}
|
|
|
|
|
2018-05-17 12:16:13 +02:00
|
|
|
if (!this->isPaused()) {
|
2018-01-11 21:03:40 +01:00
|
|
|
if (this->messages.pushFront(messageRefs).size() > 0) {
|
2018-06-13 13:27:10 +02:00
|
|
|
if (this->scrollBar_.isAtBottom()) {
|
|
|
|
this->scrollBar_.scrollToBottom();
|
2018-01-11 21:03:40 +01:00
|
|
|
} else {
|
2018-06-13 13:27:10 +02:00
|
|
|
this->scrollBar_.offset(qreal(messages.size()));
|
2018-01-11 21:03:40 +01:00
|
|
|
}
|
2018-01-01 22:29:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-06 03:48:56 +01:00
|
|
|
std::vector<ScrollbarHighlight> highlights;
|
|
|
|
highlights.reserve(messages.size());
|
2018-01-11 20:16:25 +01:00
|
|
|
for (size_t i = 0; i < messages.size(); i++) {
|
2018-01-06 03:48:56 +01:00
|
|
|
highlights.push_back(messages.at(i)->getScrollBarHighlight());
|
|
|
|
}
|
|
|
|
|
2018-06-13 13:27:10 +02:00
|
|
|
this->scrollBar_.addHighlightsAtStart(highlights);
|
2018-01-06 03:48:56 +01:00
|
|
|
|
2018-06-13 13:27:10 +02:00
|
|
|
this->messageWasAdded_ = true;
|
2018-01-05 03:14:46 +01:00
|
|
|
this->layoutMessages();
|
2018-06-13 03:58:52 +02:00
|
|
|
}));
|
2017-09-16 00:05:06 +02:00
|
|
|
|
|
|
|
// on message removed
|
2018-06-13 03:58:52 +02:00
|
|
|
this->channelConnections_.push_back(
|
2018-01-11 20:16:25 +01:00
|
|
|
newChannel->messageRemovedFromStart.connect([this](MessagePtr &) {
|
2018-06-13 13:27:10 +02:00
|
|
|
this->selection_.selectionMin.messageIndex--;
|
|
|
|
this->selection_.selectionMax.messageIndex--;
|
|
|
|
this->selection_.start.messageIndex--;
|
|
|
|
this->selection_.end.messageIndex--;
|
2017-09-16 00:05:06 +02:00
|
|
|
|
2017-10-11 10:34:04 +02:00
|
|
|
this->layoutMessages();
|
2018-06-13 03:58:52 +02:00
|
|
|
}));
|
2017-09-16 00:05:06 +02:00
|
|
|
|
2018-01-05 23:14:55 +01:00
|
|
|
// on message replaced
|
2018-06-13 03:58:52 +02:00
|
|
|
this->channelConnections_.push_back(
|
2018-01-11 20:16:25 +01:00
|
|
|
newChannel->messageReplaced.connect([this](size_t index, MessagePtr replacement) {
|
2018-06-19 20:19:43 +02:00
|
|
|
if (index >= this->messages.getSnapshot().getLength() || index < 0) {
|
2018-06-13 13:27:10 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
MessageLayoutPtr newItem(new MessageLayout(replacement));
|
2018-06-18 20:03:09 +02:00
|
|
|
auto snapshot = this->messages.getSnapshot();
|
|
|
|
if (index >= snapshot.getLength()) {
|
|
|
|
debug::Log("Tried to replace out of bounds message. Index: {}. Length: {}", index,
|
|
|
|
snapshot.getLength());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto &message = snapshot[index];
|
|
|
|
if (message->flags & MessageLayout::AlternateBackground) {
|
2018-05-06 14:57:57 +02:00
|
|
|
newItem->flags |= MessageLayout::AlternateBackground;
|
|
|
|
}
|
2018-01-05 23:14:55 +01:00
|
|
|
|
2018-06-13 13:27:10 +02:00
|
|
|
this->scrollBar_.replaceHighlight(index, replacement->getScrollBarHighlight());
|
2018-01-06 03:48:56 +01:00
|
|
|
|
2018-06-18 20:03:09 +02:00
|
|
|
this->messages.replaceItem(message, newItem);
|
2018-01-05 23:14:55 +01:00
|
|
|
this->layoutMessages();
|
2018-06-13 03:58:52 +02:00
|
|
|
}));
|
2018-01-05 23:14:55 +01:00
|
|
|
|
2017-12-22 15:13:42 +01:00
|
|
|
auto snapshot = newChannel->getMessageSnapshot();
|
2017-09-16 00:05:06 +02:00
|
|
|
|
|
|
|
for (size_t i = 0; i < snapshot.getLength(); i++) {
|
2018-01-11 20:16:25 +01:00
|
|
|
MessageLayoutPtr deleted;
|
2017-09-16 00:05:06 +02:00
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
auto messageRef = new MessageLayout(snapshot[i]);
|
2017-09-16 00:05:06 +02:00
|
|
|
|
2018-06-13 13:27:10 +02:00
|
|
|
if (this->lastMessageHasAlternateBackground_) {
|
2018-05-06 14:57:57 +02:00
|
|
|
messageRef->flags |= MessageLayout::AlternateBackground;
|
|
|
|
}
|
2018-06-13 13:27:10 +02:00
|
|
|
this->lastMessageHasAlternateBackground_ = !this->lastMessageHasAlternateBackground_;
|
2018-05-06 14:57:57 +02:00
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
this->messages.pushBack(MessageLayoutPtr(messageRef), deleted);
|
2017-09-16 00:05:06 +02:00
|
|
|
}
|
|
|
|
|
2018-06-13 13:27:10 +02:00
|
|
|
this->channel_ = newChannel;
|
2017-09-16 00:05:06 +02:00
|
|
|
|
2018-01-05 13:42:23 +01:00
|
|
|
this->layoutMessages();
|
2018-01-07 00:05:32 +01:00
|
|
|
this->queueUpdate();
|
2017-09-16 00:05:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ChannelView::detachChannel()
|
|
|
|
{
|
2018-06-13 03:58:52 +02:00
|
|
|
this->channelConnections_.clear();
|
2017-09-16 00:05:06 +02:00
|
|
|
}
|
|
|
|
|
2018-01-05 11:22:51 +01:00
|
|
|
void ChannelView::pause(int msecTimeout)
|
|
|
|
{
|
2018-06-13 13:27:10 +02:00
|
|
|
this->pausedTemporarily_ = true;
|
|
|
|
this->updatePauseStatus();
|
2018-01-05 11:22:51 +01:00
|
|
|
|
2018-06-13 13:27:10 +02:00
|
|
|
if (this->pauseTimeout_.remainingTime() < msecTimeout) {
|
|
|
|
this->pauseTimeout_.stop();
|
|
|
|
this->pauseTimeout_.start(msecTimeout);
|
|
|
|
|
2018-06-19 20:34:50 +02:00
|
|
|
// qDebug() << "pause" << msecTimeout;
|
2018-06-13 13:27:10 +02:00
|
|
|
}
|
2018-01-05 11:22:51 +01:00
|
|
|
}
|
|
|
|
|
2018-01-23 22:48:33 +01:00
|
|
|
void ChannelView::updateLastReadMessage()
|
|
|
|
{
|
|
|
|
auto _snapshot = this->getMessagesSnapshot();
|
|
|
|
|
|
|
|
if (_snapshot.getLength() > 0) {
|
2018-06-13 13:27:10 +02:00
|
|
|
this->lastReadMessage_ = _snapshot[_snapshot.getLength() - 1];
|
2018-01-23 22:48:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
this->update();
|
|
|
|
}
|
|
|
|
|
2017-09-16 00:05:06 +02:00
|
|
|
void ChannelView::resizeEvent(QResizeEvent *)
|
2017-04-12 17:46:44 +02:00
|
|
|
{
|
2018-06-13 13:27:10 +02:00
|
|
|
this->scrollBar_.setGeometry(this->width() - this->scrollBar_.width(), 0,
|
|
|
|
this->scrollBar_.width(), this->height());
|
2017-01-16 03:15:07 +01:00
|
|
|
|
2018-06-13 13:27:10 +02:00
|
|
|
this->goToBottom_->setGeometry(0, this->height() - 32, this->width(), 32);
|
2017-09-21 17:34:41 +02:00
|
|
|
|
2018-06-13 13:27:10 +02:00
|
|
|
this->scrollBar_.raise();
|
2017-09-21 17:34:41 +02:00
|
|
|
|
2018-01-05 10:41:21 +01:00
|
|
|
this->layoutMessages();
|
2017-02-07 00:03:15 +01:00
|
|
|
|
2017-06-06 17:18:23 +02:00
|
|
|
this->update();
|
2017-01-03 21:19:33 +01:00
|
|
|
}
|
2017-01-05 16:07:20 +01:00
|
|
|
|
2017-09-16 00:05:06 +02:00
|
|
|
void ChannelView::setSelection(const SelectionItem &start, const SelectionItem &end)
|
2017-08-18 15:12:07 +02:00
|
|
|
{
|
|
|
|
// selections
|
2018-06-13 13:27:10 +02:00
|
|
|
if (!this->selecting_ && start != end) {
|
|
|
|
this->messagesAddedSinceSelectionPause_ = 0;
|
2018-05-17 12:16:13 +02:00
|
|
|
|
2018-06-13 13:27:10 +02:00
|
|
|
this->selecting_ = true;
|
|
|
|
this->pausedBySelection_ = true;
|
2018-05-17 12:16:13 +02:00
|
|
|
}
|
|
|
|
|
2018-06-13 13:27:10 +02:00
|
|
|
this->selection_ = Selection(start, end);
|
2017-08-18 15:12:07 +02:00
|
|
|
|
2018-04-03 02:55:32 +02:00
|
|
|
this->selectionChanged.invoke();
|
2017-08-18 15:12:07 +02:00
|
|
|
}
|
|
|
|
|
2018-01-17 16:52:51 +01:00
|
|
|
messages::MessageElement::Flags ChannelView::getFlags() const
|
|
|
|
{
|
2018-04-27 22:11:19 +02:00
|
|
|
auto app = getApp();
|
|
|
|
|
2018-06-13 13:27:10 +02:00
|
|
|
if (this->overrideFlags_) {
|
|
|
|
return this->overrideFlags_.get();
|
2018-01-27 21:13:22 +01:00
|
|
|
}
|
|
|
|
|
2018-04-27 22:11:19 +02:00
|
|
|
MessageElement::Flags flags = app->settings->getWordFlags();
|
2018-01-17 16:52:51 +01:00
|
|
|
|
|
|
|
Split *split = dynamic_cast<Split *>(this->parentWidget());
|
|
|
|
|
|
|
|
if (split != nullptr) {
|
|
|
|
if (split->getModerationMode()) {
|
2018-06-13 13:27:10 +02:00
|
|
|
flags = MessageElement::Flags(flags | MessageElement::ModeratorTools);
|
2018-01-17 16:52:51 +01:00
|
|
|
}
|
2018-06-13 13:27:10 +02:00
|
|
|
if (this->channel_ == app->twitch.server->mentionsChannel) {
|
|
|
|
flags = MessageElement::Flags(flags | MessageElement::ChannelName);
|
2018-01-23 23:28:06 +01:00
|
|
|
}
|
2018-01-17 16:52:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
2018-05-17 12:16:13 +02:00
|
|
|
bool ChannelView::isPaused()
|
|
|
|
{
|
2018-06-19 18:55:45 +02:00
|
|
|
return false;
|
|
|
|
// return this->pausedTemporarily_ || this->pausedBySelection_ || this->pausedByScrollingUp_;
|
2018-05-17 12:16:13 +02:00
|
|
|
}
|
|
|
|
|
2018-06-13 13:27:10 +02:00
|
|
|
void ChannelView::updatePauseStatus()
|
|
|
|
{
|
|
|
|
if (this->isPaused()) {
|
|
|
|
this->scrollBar_.pauseHighlights();
|
|
|
|
} else {
|
|
|
|
this->scrollBar_.unpauseHighlights();
|
|
|
|
}
|
|
|
|
}
|
2018-05-17 12:16:13 +02:00
|
|
|
|
2017-09-16 00:05:06 +02:00
|
|
|
void ChannelView::paintEvent(QPaintEvent * /*event*/)
|
2017-01-05 16:07:20 +01:00
|
|
|
{
|
2018-05-28 08:34:54 +02:00
|
|
|
// BenchmarkGuard benchmark("paint event");
|
2017-02-07 00:03:15 +01:00
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
QPainter painter(this);
|
2017-02-07 00:03:15 +01:00
|
|
|
|
2018-04-27 22:11:19 +02:00
|
|
|
painter.fillRect(rect(), this->themeManager->splits.background);
|
2017-08-18 15:12:07 +02:00
|
|
|
|
|
|
|
// draw messages
|
2018-01-11 20:16:25 +01:00
|
|
|
this->drawMessages(painter);
|
2017-08-18 15:12:07 +02:00
|
|
|
}
|
|
|
|
|
2018-01-01 23:29:54 +01:00
|
|
|
// 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
|
2018-01-11 20:16:25 +01:00
|
|
|
void ChannelView::drawMessages(QPainter &painter)
|
2017-08-18 15:12:07 +02:00
|
|
|
{
|
2018-04-27 22:11:19 +02:00
|
|
|
auto app = getApp();
|
|
|
|
|
2017-12-22 15:13:42 +01:00
|
|
|
auto messagesSnapshot = this->getMessagesSnapshot();
|
2017-01-11 01:08:20 +01:00
|
|
|
|
2018-06-13 13:27:10 +02:00
|
|
|
size_t start = size_t(this->scrollBar_.getCurrentValue());
|
2017-01-11 01:08:20 +01:00
|
|
|
|
2017-12-22 15:13:42 +01:00
|
|
|
if (start >= messagesSnapshot.getLength()) {
|
2017-01-18 04:33:30 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-05-25 12:45:18 +02:00
|
|
|
int y = int(-(messagesSnapshot[start].get()->getHeight() *
|
2018-06-13 13:27:10 +02:00
|
|
|
(fmod(this->scrollBar_.getCurrentValue(), 1))));
|
2017-01-18 04:33:30 +01:00
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
messages::MessageLayout *end = nullptr;
|
2018-01-23 22:48:33 +01:00
|
|
|
bool windowFocused = this->window() == QApplication::activeWindow();
|
2017-12-26 18:24:02 +01:00
|
|
|
|
2017-12-22 15:13:42 +01:00
|
|
|
for (size_t i = start; i < messagesSnapshot.getLength(); ++i) {
|
2018-01-11 20:16:25 +01:00
|
|
|
messages::MessageLayout *layout = messagesSnapshot[i].get();
|
2017-02-07 00:03:15 +01:00
|
|
|
|
2018-01-23 22:48:33 +01:00
|
|
|
bool isLastMessage = false;
|
2018-04-27 22:11:19 +02:00
|
|
|
if (app->settings->showLastMessageIndicator) {
|
2018-06-13 13:27:10 +02:00
|
|
|
isLastMessage = this->lastReadMessage_.get() == layout;
|
2018-01-23 22:48:33 +01:00
|
|
|
}
|
|
|
|
|
2018-06-13 13:27:10 +02:00
|
|
|
layout->paint(painter, DRAW_WIDTH, y, i, this->selection_, isLastMessage, windowFocused);
|
2017-02-03 19:31:51 +01:00
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
y += layout->getHeight();
|
2017-01-20 06:10:28 +01:00
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
end = layout;
|
2018-04-25 14:49:30 +02:00
|
|
|
if (y > this->height()) {
|
2017-01-20 06:10:28 +01:00
|
|
|
break;
|
|
|
|
}
|
2017-01-11 01:08:20 +01:00
|
|
|
}
|
2017-12-26 18:24:02 +01:00
|
|
|
|
|
|
|
if (end == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove messages that are on screen
|
|
|
|
// the messages that are left at the end get their buffers reset
|
|
|
|
for (size_t i = start; i < messagesSnapshot.getLength(); ++i) {
|
2018-06-13 13:27:10 +02:00
|
|
|
auto it = this->messagesOnScreen_.find(messagesSnapshot[i]);
|
|
|
|
if (it != this->messagesOnScreen_.end()) {
|
|
|
|
this->messagesOnScreen_.erase(it);
|
2017-12-26 18:24:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// delete the message buffers that aren't on screen
|
2018-06-13 13:27:10 +02:00
|
|
|
for (const std::shared_ptr<messages::MessageLayout> &item : this->messagesOnScreen_) {
|
2018-01-11 20:16:25 +01:00
|
|
|
item->deleteBuffer();
|
2017-12-26 18:24:02 +01:00
|
|
|
}
|
|
|
|
|
2018-06-13 13:27:10 +02:00
|
|
|
this->messagesOnScreen_.clear();
|
2017-12-26 18:24:02 +01:00
|
|
|
|
|
|
|
// add all messages on screen to the map
|
|
|
|
for (size_t i = start; i < messagesSnapshot.getLength(); ++i) {
|
2018-01-11 20:16:25 +01:00
|
|
|
std::shared_ptr<messages::MessageLayout> layout = messagesSnapshot[i];
|
2017-12-26 18:24:02 +01:00
|
|
|
|
2018-06-13 13:27:10 +02:00
|
|
|
this->messagesOnScreen_.insert(layout);
|
2017-12-26 18:24:02 +01:00
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
if (layout.get() == end) {
|
2017-12-26 18:24:02 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-08-18 15:12:07 +02:00
|
|
|
}
|
2017-02-07 00:03:15 +01:00
|
|
|
|
2017-09-16 00:05:06 +02:00
|
|
|
void ChannelView::wheelEvent(QWheelEvent *event)
|
2017-01-26 04:26:40 +01:00
|
|
|
{
|
2018-06-19 18:55:45 +02:00
|
|
|
if (event->orientation() != Qt::Vertical) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-06-13 13:27:10 +02:00
|
|
|
this->pausedBySelection_ = false;
|
|
|
|
this->pausedTemporarily_ = false;
|
|
|
|
this->updatePauseStatus();
|
2018-05-17 17:27:20 +02:00
|
|
|
|
2018-06-11 15:04:54 +02:00
|
|
|
if (event->modifiers() & Qt::ControlModifier) {
|
|
|
|
event->ignore();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-06-13 13:27:10 +02:00
|
|
|
if (this->scrollBar_.isVisible()) {
|
2018-04-27 22:11:19 +02:00
|
|
|
auto app = getApp();
|
|
|
|
|
|
|
|
float mouseMultiplier = app->settings->mouseScrollMultiplier;
|
2017-04-14 17:47:28 +02:00
|
|
|
|
2018-06-13 13:27:10 +02:00
|
|
|
qreal desired = this->scrollBar_.getDesiredValue();
|
|
|
|
qreal delta = event->delta() * qreal(1.5) * mouseMultiplier;
|
2018-01-05 02:55:24 +01:00
|
|
|
|
|
|
|
auto snapshot = this->getMessagesSnapshot();
|
2018-06-13 13:27:10 +02:00
|
|
|
int snapshotLength = int(snapshot.getLength());
|
|
|
|
int i = std::min(int(desired), snapshotLength);
|
2018-01-05 02:55:24 +01:00
|
|
|
|
|
|
|
if (delta > 0) {
|
2018-06-13 13:27:10 +02:00
|
|
|
qreal scrollFactor = fmod(desired, 1);
|
|
|
|
qreal currentScrollLeft = int(scrollFactor * snapshot[i]->getHeight());
|
2018-01-05 02:55:24 +01:00
|
|
|
|
|
|
|
for (; i >= 0; i--) {
|
|
|
|
if (delta < currentScrollLeft) {
|
|
|
|
desired -= scrollFactor * (delta / currentScrollLeft);
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
delta -= currentScrollLeft;
|
|
|
|
desired -= scrollFactor;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == 0) {
|
|
|
|
desired = 0;
|
|
|
|
} else {
|
2018-06-13 03:58:52 +02:00
|
|
|
snapshot[i - 1]->layout(this->getLayoutWidth(), this->getScale(),
|
|
|
|
this->getFlags());
|
2018-01-05 02:55:24 +01:00
|
|
|
scrollFactor = 1;
|
|
|
|
currentScrollLeft = snapshot[i - 1]->getHeight();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
delta = -delta;
|
2018-06-13 13:27:10 +02:00
|
|
|
qreal scrollFactor = 1 - fmod(desired, 1);
|
|
|
|
qreal currentScrollLeft = int(scrollFactor * snapshot[i]->getHeight());
|
2018-01-05 02:55:24 +01:00
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
for (; i < snapshotLength; i++) {
|
2018-01-05 02:55:24 +01:00
|
|
|
if (delta < currentScrollLeft) {
|
2018-06-13 13:27:10 +02:00
|
|
|
desired += scrollFactor * (qreal(delta) / currentScrollLeft);
|
2018-01-05 02:55:24 +01:00
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
delta -= currentScrollLeft;
|
|
|
|
desired += scrollFactor;
|
|
|
|
}
|
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
if (i == snapshotLength - 1) {
|
2018-01-05 02:55:24 +01:00
|
|
|
desired = snapshot.getLength();
|
|
|
|
} else {
|
2018-06-13 03:58:52 +02:00
|
|
|
snapshot[i + 1]->layout(this->getLayoutWidth(), this->getScale(),
|
|
|
|
this->getFlags());
|
2018-01-05 02:55:24 +01:00
|
|
|
|
|
|
|
scrollFactor = 1;
|
|
|
|
currentScrollLeft = snapshot[i + 1]->getHeight();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-13 13:27:10 +02:00
|
|
|
this->scrollBar_.setDesiredValue(desired, true);
|
2017-02-06 18:31:25 +01:00
|
|
|
}
|
2017-01-26 04:26:40 +01:00
|
|
|
}
|
2017-02-17 23:51:35 +01:00
|
|
|
|
2018-01-05 11:22:51 +01:00
|
|
|
void ChannelView::enterEvent(QEvent *)
|
|
|
|
{
|
|
|
|
// this->pause(PAUSE_TIME);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChannelView::leaveEvent(QEvent *)
|
|
|
|
{
|
2018-06-13 13:27:10 +02:00
|
|
|
this->pausedTemporarily_ = false;
|
|
|
|
this->updatePauseStatus();
|
2018-05-17 17:27:20 +02:00
|
|
|
this->layoutMessages();
|
2018-01-05 11:22:51 +01:00
|
|
|
}
|
|
|
|
|
2017-09-16 00:05:06 +02:00
|
|
|
void ChannelView::mouseMoveEvent(QMouseEvent *event)
|
2017-02-17 23:51:35 +01:00
|
|
|
{
|
2018-01-17 01:19:42 +01:00
|
|
|
if (event->modifiers() & (Qt::AltModifier | Qt::ControlModifier)) {
|
|
|
|
this->unsetCursor();
|
|
|
|
|
|
|
|
event->ignore();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-27 22:11:19 +02:00
|
|
|
auto app = getApp();
|
|
|
|
|
|
|
|
if (app->settings->pauseChatHover.getValue()) {
|
2018-05-17 12:16:13 +02:00
|
|
|
this->pause(CHAT_HOVER_PAUSE_DURATION);
|
2018-01-05 11:22:51 +01:00
|
|
|
}
|
|
|
|
|
2017-12-23 22:17:38 +01:00
|
|
|
auto tooltipWidget = TooltipWidget::getInstance();
|
2018-01-11 20:16:25 +01:00
|
|
|
std::shared_ptr<messages::MessageLayout> layout;
|
2017-02-17 23:51:35 +01:00
|
|
|
QPoint relativePos;
|
2017-08-18 15:12:07 +02:00
|
|
|
int messageIndex;
|
2017-02-17 23:51:35 +01:00
|
|
|
|
2017-12-19 00:09:38 +01:00
|
|
|
// no message under cursor
|
2018-01-11 20:16:25 +01:00
|
|
|
if (!tryGetMessageAt(event->pos(), layout, relativePos, messageIndex)) {
|
2017-12-19 00:09:38 +01:00
|
|
|
this->setCursor(Qt::ArrowCursor);
|
2017-12-23 22:17:38 +01:00
|
|
|
tooltipWidget->hide();
|
2017-12-19 00:09:38 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// is selecting
|
2018-06-13 13:27:10 +02:00
|
|
|
if (this->isMouseDown_) {
|
2018-05-17 12:16:13 +02:00
|
|
|
this->pause(300);
|
2018-01-11 20:16:25 +01:00
|
|
|
int index = layout->getSelectionIndex(relativePos);
|
2017-08-18 15:12:07 +02:00
|
|
|
|
2018-06-13 13:27:10 +02:00
|
|
|
this->setSelection(this->selection_.start, SelectionItem(messageIndex, index));
|
2017-08-18 15:12:07 +02:00
|
|
|
|
2018-01-05 11:22:51 +01:00
|
|
|
this->queueUpdate();
|
|
|
|
}
|
|
|
|
|
|
|
|
// message under cursor is collapsed
|
2018-05-24 11:35:50 +02:00
|
|
|
if (layout->flags & MessageLayout::Collapsed) {
|
2018-01-05 11:22:51 +01:00
|
|
|
this->setCursor(Qt::PointingHandCursor);
|
|
|
|
tooltipWidget->hide();
|
|
|
|
return;
|
2017-08-18 15:12:07 +02:00
|
|
|
}
|
2017-04-24 23:00:26 +02:00
|
|
|
|
2017-12-19 00:09:38 +01:00
|
|
|
// check if word underneath cursor
|
2018-01-11 20:16:25 +01:00
|
|
|
const messages::MessageLayoutElement *hoverLayoutElement = layout->getElementAt(relativePos);
|
|
|
|
|
|
|
|
if (hoverLayoutElement == nullptr) {
|
2017-12-19 00:09:38 +01:00
|
|
|
this->setCursor(Qt::ArrowCursor);
|
2017-12-23 22:17:38 +01:00
|
|
|
tooltipWidget->hide();
|
2017-02-17 23:51:35 +01:00
|
|
|
return;
|
|
|
|
}
|
2018-01-11 20:16:25 +01:00
|
|
|
const auto &tooltip = hoverLayoutElement->getCreator().getTooltip();
|
2017-12-19 03:36:05 +01:00
|
|
|
|
2018-01-17 03:26:32 +01:00
|
|
|
if (tooltip.isEmpty()) {
|
|
|
|
tooltipWidget->hide();
|
|
|
|
} else {
|
2018-01-22 15:06:36 +01:00
|
|
|
tooltipWidget->moveTo(this, event->globalPos());
|
2018-01-17 03:26:32 +01:00
|
|
|
tooltipWidget->setText(tooltip);
|
2018-06-22 17:45:11 +02:00
|
|
|
tooltipWidget->adjustSize();
|
2018-01-17 03:26:32 +01:00
|
|
|
tooltipWidget->show();
|
2018-05-24 10:03:07 +02:00
|
|
|
tooltipWidget->raise();
|
2018-01-17 03:26:32 +01:00
|
|
|
}
|
2017-12-19 03:36:05 +01:00
|
|
|
|
2017-12-19 00:09:38 +01:00
|
|
|
// check if word has a link
|
2018-01-17 14:14:31 +01:00
|
|
|
if (hoverLayoutElement->getLink().isValid()) {
|
2017-12-19 00:09:38 +01:00
|
|
|
this->setCursor(Qt::PointingHandCursor);
|
2017-02-17 23:51:35 +01:00
|
|
|
} else {
|
2017-12-19 00:09:38 +01:00
|
|
|
this->setCursor(Qt::ArrowCursor);
|
2017-02-17 23:51:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-16 00:05:06 +02:00
|
|
|
void ChannelView::mousePressEvent(QMouseEvent *event)
|
2017-04-12 17:46:44 +02:00
|
|
|
{
|
2018-04-27 22:11:19 +02:00
|
|
|
auto app = getApp();
|
|
|
|
|
2018-06-04 21:44:03 +02:00
|
|
|
this->mouseDown.invoke(event);
|
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
std::shared_ptr<messages::MessageLayout> layout;
|
2017-08-18 15:12:07 +02:00
|
|
|
QPoint relativePos;
|
|
|
|
int messageIndex;
|
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
if (!tryGetMessageAt(event->pos(), layout, relativePos, messageIndex)) {
|
2017-08-18 15:12:07 +02:00
|
|
|
setCursor(Qt::ArrowCursor);
|
|
|
|
|
2017-12-22 15:13:42 +01:00
|
|
|
auto messagesSnapshot = this->getMessagesSnapshot();
|
|
|
|
if (messagesSnapshot.getLength() == 0) {
|
2017-11-04 13:17:35 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start selection at the last message at its last index
|
2018-06-04 14:39:26 +02:00
|
|
|
if (event->button() == Qt::LeftButton) {
|
|
|
|
auto lastMessageIndex = messagesSnapshot.getLength() - 1;
|
|
|
|
auto lastMessage = messagesSnapshot[lastMessageIndex];
|
|
|
|
auto lastCharacterIndex = lastMessage->getLastCharacterIndex();
|
2017-11-04 13:17:35 +01:00
|
|
|
|
2018-06-04 14:39:26 +02:00
|
|
|
SelectionItem selectionItem(lastMessageIndex, lastCharacterIndex);
|
|
|
|
this->setSelection(selectionItem, selectionItem);
|
|
|
|
}
|
2018-06-05 15:01:40 +02:00
|
|
|
return;
|
2017-08-18 15:12:07 +02:00
|
|
|
}
|
|
|
|
|
2017-12-19 00:09:38 +01:00
|
|
|
// check if message is collapsed
|
2018-06-04 14:39:26 +02:00
|
|
|
switch (event->button()) {
|
|
|
|
case Qt::LeftButton: {
|
2018-06-13 13:27:10 +02:00
|
|
|
this->lastPressPosition_ = event->screenPos();
|
|
|
|
this->isMouseDown_ = true;
|
2018-06-05 14:24:01 +02:00
|
|
|
|
|
|
|
if (layout->flags & MessageLayout::Collapsed) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-06-04 14:39:26 +02:00
|
|
|
if (app->settings->linksDoubleClickOnly.getValue()) {
|
|
|
|
this->pause(200);
|
|
|
|
}
|
2018-01-17 01:19:42 +01:00
|
|
|
|
2018-06-04 14:39:26 +02:00
|
|
|
int index = layout->getSelectionIndex(relativePos);
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2018-06-04 14:39:26 +02:00
|
|
|
auto selectionItem = SelectionItem(messageIndex, index);
|
|
|
|
this->setSelection(selectionItem, selectionItem);
|
|
|
|
} break;
|
2018-05-17 12:16:13 +02:00
|
|
|
|
2018-06-04 14:39:26 +02:00
|
|
|
case Qt::RightButton: {
|
2018-06-13 13:27:10 +02:00
|
|
|
this->lastRightPressPosition_ = event->screenPos();
|
|
|
|
this->isRightMouseDown_ = true;
|
2018-06-04 14:39:26 +02:00
|
|
|
} break;
|
2018-05-17 12:16:13 +02:00
|
|
|
|
2018-06-04 14:39:26 +02:00
|
|
|
default:;
|
2018-01-05 11:22:51 +01:00
|
|
|
}
|
|
|
|
|
2018-06-04 14:39:26 +02:00
|
|
|
this->update();
|
|
|
|
}
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2018-06-04 14:39:26 +02:00
|
|
|
void ChannelView::mouseReleaseEvent(QMouseEvent *event)
|
|
|
|
{
|
|
|
|
// check if mouse was pressed
|
|
|
|
if (event->button() == Qt::LeftButton) {
|
2018-06-13 13:27:10 +02:00
|
|
|
if (this->isMouseDown_) {
|
|
|
|
this->isMouseDown_ = false;
|
2018-06-04 14:39:26 +02:00
|
|
|
|
2018-06-13 13:27:10 +02:00
|
|
|
if (fabsf(util::distanceBetweenPoints(this->lastPressPosition_, event->screenPos())) >
|
2018-06-04 14:39:26 +02:00
|
|
|
15.f) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else if (event->button() == Qt::RightButton) {
|
2018-06-13 13:27:10 +02:00
|
|
|
if (this->isRightMouseDown_) {
|
|
|
|
this->isRightMouseDown_ = false;
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2018-06-13 13:27:10 +02:00
|
|
|
if (fabsf(util::distanceBetweenPoints(this->lastRightPressPosition_,
|
2018-06-04 14:39:26 +02:00
|
|
|
event->screenPos())) > 15.f) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// not left or right button
|
2017-04-12 17:46:44 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-06-04 14:39:26 +02:00
|
|
|
// find message
|
2018-02-06 00:10:30 +01:00
|
|
|
this->layoutMessages();
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
std::shared_ptr<messages::MessageLayout> layout;
|
2017-04-12 17:46:44 +02:00
|
|
|
QPoint relativePos;
|
2017-08-18 15:12:07 +02:00
|
|
|
int messageIndex;
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2018-06-04 14:39:26 +02:00
|
|
|
// no message found
|
2018-01-11 20:16:25 +01:00
|
|
|
if (!tryGetMessageAt(event->pos(), layout, relativePos, messageIndex)) {
|
2017-04-12 17:46:44 +02:00
|
|
|
// No message at clicked position
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-19 00:09:38 +01:00
|
|
|
// message under cursor is collapsed
|
2018-05-24 11:35:50 +02:00
|
|
|
if (layout->flags & MessageLayout::Collapsed) {
|
|
|
|
layout->flags |= MessageLayout::Expanded;
|
2018-05-25 12:45:18 +02:00
|
|
|
layout->flags |= MessageLayout::RequiresLayout;
|
2018-04-18 09:12:29 +02:00
|
|
|
|
|
|
|
this->layoutMessages();
|
2017-12-19 00:09:38 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
const messages::MessageLayoutElement *hoverLayoutElement = layout->getElementAt(relativePos);
|
2017-04-24 23:00:26 +02:00
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
if (hoverLayoutElement == nullptr) {
|
2017-04-24 23:00:26 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-06-04 14:39:26 +02:00
|
|
|
// handle the click
|
|
|
|
this->handleMouseClick(event, hoverLayoutElement, layout.get());
|
|
|
|
}
|
2018-05-16 03:55:56 +02:00
|
|
|
|
2018-06-04 14:39:26 +02:00
|
|
|
void ChannelView::handleMouseClick(QMouseEvent *event,
|
|
|
|
const messages::MessageLayoutElement *hoveredElement,
|
|
|
|
messages::MessageLayout *layout)
|
|
|
|
{
|
|
|
|
switch (event->button()) {
|
|
|
|
case Qt::LeftButton: {
|
2018-06-13 13:27:10 +02:00
|
|
|
if (this->selecting_) {
|
|
|
|
if (this->messagesAddedSinceSelectionPause_ >
|
2018-06-04 14:39:26 +02:00
|
|
|
SELECTION_RESUME_SCROLLING_MSG_THRESHOLD) {
|
2018-06-13 13:27:10 +02:00
|
|
|
this->showingLatestMessages_ = false;
|
2018-06-04 14:39:26 +02:00
|
|
|
}
|
2018-05-16 03:55:56 +02:00
|
|
|
|
2018-06-13 13:27:10 +02:00
|
|
|
// this->pausedBySelection = false;
|
|
|
|
this->selecting_ = false;
|
|
|
|
// this->pauseTimeout.stop();
|
|
|
|
// this->pausedTemporarily = false;
|
2018-05-16 03:55:56 +02:00
|
|
|
|
2018-06-04 14:39:26 +02:00
|
|
|
this->layoutMessages();
|
2018-05-16 03:55:56 +02:00
|
|
|
}
|
|
|
|
|
2018-06-04 14:39:26 +02:00
|
|
|
auto &link = hoveredElement->getLink();
|
|
|
|
if (!getApp()->settings->linksDoubleClickOnly) {
|
|
|
|
this->handleLinkClick(event, link, layout);
|
|
|
|
|
|
|
|
this->linkClicked.invoke(link);
|
2018-05-16 03:55:56 +02:00
|
|
|
}
|
2018-06-04 14:39:26 +02:00
|
|
|
} break;
|
|
|
|
case Qt::RightButton: {
|
|
|
|
this->addContextMenuItems(hoveredElement, layout);
|
|
|
|
} break;
|
|
|
|
default:;
|
|
|
|
}
|
|
|
|
}
|
2018-05-16 03:55:56 +02:00
|
|
|
|
2018-06-04 14:39:26 +02:00
|
|
|
void ChannelView::addContextMenuItems(const messages::MessageLayoutElement *hoveredElement,
|
|
|
|
messages::MessageLayout *layout)
|
|
|
|
{
|
|
|
|
const auto &creator = hoveredElement->getCreator();
|
|
|
|
auto creatorFlags = creator.getFlags();
|
2018-05-16 03:55:56 +02:00
|
|
|
|
2018-06-04 14:39:26 +02:00
|
|
|
static QMenu *menu = new QMenu;
|
|
|
|
menu->clear();
|
2018-05-23 21:16:34 +02:00
|
|
|
|
2018-06-04 14:39:26 +02:00
|
|
|
// Emote actions
|
|
|
|
if (creatorFlags & (MessageElement::Flags::EmoteImages | MessageElement::Flags::EmojiImage)) {
|
|
|
|
const auto &emoteElement = static_cast<const messages::EmoteElement &>(creator);
|
2018-05-23 21:16:34 +02:00
|
|
|
|
2018-06-04 14:39:26 +02:00
|
|
|
// TODO: We might want to add direct "Open image" variants alongside the Copy
|
|
|
|
// actions
|
|
|
|
if (emoteElement.data.image1x != nullptr) {
|
2018-06-13 03:58:52 +02:00
|
|
|
QAction *addEntry = menu->addAction("Copy emote link...");
|
2018-06-09 18:59:08 +02:00
|
|
|
|
2018-06-13 03:58:52 +02:00
|
|
|
QMenu *procmenu = new QMenu;
|
2018-06-09 18:59:08 +02:00
|
|
|
addEntry->setMenu(procmenu);
|
|
|
|
procmenu->addAction("Copy 1x link", [url = emoteElement.data.image1x->getUrl()] {
|
2018-06-04 14:39:26 +02:00
|
|
|
QApplication::clipboard()->setText(url); //
|
|
|
|
});
|
2018-06-09 18:59:08 +02:00
|
|
|
if (emoteElement.data.image2x != nullptr) {
|
|
|
|
procmenu->addAction("Copy 2x link", [url = emoteElement.data.image2x->getUrl()] {
|
|
|
|
QApplication::clipboard()->setText(url); //
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (emoteElement.data.image3x != nullptr) {
|
|
|
|
procmenu->addAction("Copy 3x link", [url = emoteElement.data.image3x->getUrl()] {
|
|
|
|
QApplication::clipboard()->setText(url); //
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if ((creatorFlags & MessageElement::Flags::BttvEmote) != 0) {
|
|
|
|
procmenu->addSeparator();
|
|
|
|
QString emotePageLink = emoteElement.data.pageLink;
|
|
|
|
procmenu->addAction("Copy BTTV emote link", [emotePageLink] {
|
|
|
|
QApplication::clipboard()->setText(emotePageLink); //
|
|
|
|
});
|
|
|
|
} else if ((creatorFlags & MessageElement::Flags::FfzEmote) != 0) {
|
|
|
|
procmenu->addSeparator();
|
|
|
|
QString emotePageLink = emoteElement.data.pageLink;
|
|
|
|
procmenu->addAction("Copy FFZ emote link", [emotePageLink] {
|
|
|
|
QApplication::clipboard()->setText(emotePageLink); //
|
|
|
|
});
|
|
|
|
}
|
2018-06-04 14:39:26 +02:00
|
|
|
}
|
2018-06-09 18:59:08 +02:00
|
|
|
if (emoteElement.data.image1x != nullptr) {
|
2018-06-13 03:58:52 +02:00
|
|
|
QAction *addEntry = menu->addAction("Open emote link...");
|
2018-06-04 14:39:26 +02:00
|
|
|
|
2018-06-13 03:58:52 +02:00
|
|
|
QMenu *procmenu = new QMenu;
|
2018-06-09 18:59:08 +02:00
|
|
|
addEntry->setMenu(procmenu);
|
|
|
|
procmenu->addAction("Open 1x link", [url = emoteElement.data.image1x->getUrl()] {
|
|
|
|
QDesktopServices::openUrl(QUrl(url)); //
|
2018-06-04 14:39:26 +02:00
|
|
|
});
|
2018-06-09 18:59:08 +02:00
|
|
|
if (emoteElement.data.image2x != nullptr) {
|
|
|
|
procmenu->addAction("Open 2x link", [url = emoteElement.data.image2x->getUrl()] {
|
|
|
|
QDesktopServices::openUrl(QUrl(url)); //
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (emoteElement.data.image3x != nullptr) {
|
|
|
|
procmenu->addAction("Open 3x link", [url = emoteElement.data.image3x->getUrl()] {
|
|
|
|
QDesktopServices::openUrl(QUrl(url)); //
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if ((creatorFlags & MessageElement::Flags::BttvEmote) != 0) {
|
|
|
|
procmenu->addSeparator();
|
|
|
|
QString emotePageLink = emoteElement.data.pageLink;
|
|
|
|
procmenu->addAction("Open BTTV emote link", [emotePageLink] {
|
|
|
|
QDesktopServices::openUrl(QUrl(emotePageLink)); //
|
|
|
|
});
|
|
|
|
} else if ((creatorFlags & MessageElement::Flags::FfzEmote) != 0) {
|
|
|
|
procmenu->addSeparator();
|
|
|
|
QString emotePageLink = emoteElement.data.pageLink;
|
|
|
|
procmenu->addAction("Open FFZ emote link", [emotePageLink] {
|
|
|
|
QDesktopServices::openUrl(QUrl(emotePageLink)); //
|
|
|
|
});
|
|
|
|
}
|
2018-05-23 21:16:34 +02:00
|
|
|
}
|
2018-06-04 14:39:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// add seperator
|
|
|
|
if (!menu->actions().empty()) {
|
|
|
|
menu->addSeparator();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Link copy
|
|
|
|
if (hoveredElement->getLink().type == Link::Url) {
|
|
|
|
QString url = hoveredElement->getLink().value;
|
2018-05-23 21:16:34 +02:00
|
|
|
|
2018-06-04 14:39:26 +02:00
|
|
|
menu->addAction("Open link in browser", [url] { QDesktopServices::openUrl(QUrl(url)); });
|
|
|
|
menu->addAction("Copy link", [url] { QApplication::clipboard()->setText(url); });
|
|
|
|
|
|
|
|
menu->addSeparator();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy actions
|
2018-06-13 13:27:10 +02:00
|
|
|
if (!this->selection_.isEmpty()) {
|
2018-06-05 14:24:54 +02:00
|
|
|
menu->addAction("Copy selection",
|
|
|
|
[this] { QGuiApplication::clipboard()->setText(this->getSelectedText()); });
|
2018-06-04 14:39:26 +02:00
|
|
|
}
|
2018-05-23 20:34:37 +02:00
|
|
|
|
2018-06-05 14:24:54 +02:00
|
|
|
menu->addAction("Copy message", [layout] {
|
|
|
|
QString copyString;
|
|
|
|
layout->addSelectionText(copyString);
|
|
|
|
|
|
|
|
QGuiApplication::clipboard()->setText(copyString);
|
|
|
|
});
|
|
|
|
|
2018-06-04 14:39:26 +02:00
|
|
|
// menu->addAction("Quote message", [layout] {
|
|
|
|
// QString copyString;
|
|
|
|
// layout->addSelectionText(copyString);
|
2018-05-23 20:34:37 +02:00
|
|
|
|
2018-06-04 14:39:26 +02:00
|
|
|
// // insert into input
|
|
|
|
// });
|
2018-05-16 03:55:56 +02:00
|
|
|
|
2018-06-04 14:39:26 +02:00
|
|
|
menu->move(QCursor::pos());
|
|
|
|
menu->show();
|
2018-06-09 18:59:08 +02:00
|
|
|
menu->raise();
|
2018-01-24 21:44:31 +01:00
|
|
|
|
2018-06-04 14:39:26 +02:00
|
|
|
return;
|
2018-01-24 21:44:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ChannelView::mouseDoubleClickEvent(QMouseEvent *event)
|
|
|
|
{
|
2018-04-27 22:11:19 +02:00
|
|
|
auto app = getApp();
|
|
|
|
|
|
|
|
if (app->settings->linksDoubleClickOnly) {
|
2018-01-24 21:44:31 +01:00
|
|
|
std::shared_ptr<messages::MessageLayout> layout;
|
|
|
|
QPoint relativePos;
|
|
|
|
int messageIndex;
|
|
|
|
|
|
|
|
if (!tryGetMessageAt(event->pos(), layout, relativePos, messageIndex)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// message under cursor is collapsed
|
2018-05-24 11:35:50 +02:00
|
|
|
if (layout->flags & MessageLayout::Collapsed) {
|
2018-01-24 21:44:31 +01:00
|
|
|
return;
|
|
|
|
}
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2018-01-24 21:44:31 +01:00
|
|
|
const messages::MessageLayoutElement *hoverLayoutElement =
|
|
|
|
layout->getElementAt(relativePos);
|
|
|
|
|
|
|
|
if (hoverLayoutElement == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2018-01-24 21:44:31 +01:00
|
|
|
auto &link = hoverLayoutElement->getLink();
|
|
|
|
this->handleLinkClick(event, link, layout.get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-18 09:12:29 +02:00
|
|
|
void ChannelView::hideEvent(QHideEvent *)
|
|
|
|
{
|
2018-06-13 13:27:10 +02:00
|
|
|
for (auto &layout : this->messagesOnScreen_) {
|
2018-04-18 09:12:29 +02:00
|
|
|
layout->deleteBuffer();
|
|
|
|
}
|
|
|
|
|
2018-06-13 13:27:10 +02:00
|
|
|
this->messagesOnScreen_.clear();
|
2018-04-18 09:12:29 +02:00
|
|
|
}
|
|
|
|
|
2018-01-24 21:44:31 +01:00
|
|
|
void ChannelView::handleLinkClick(QMouseEvent *event, const messages::Link &link,
|
|
|
|
messages::MessageLayout *layout)
|
|
|
|
{
|
2018-05-23 21:16:34 +02:00
|
|
|
if (event->button() != Qt::LeftButton) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-01-28 03:52:52 +01:00
|
|
|
switch (link.type) {
|
2017-07-31 00:57:42 +02:00
|
|
|
case messages::Link::UserInfo: {
|
2018-01-28 03:52:52 +01:00
|
|
|
auto user = link.value;
|
2018-06-19 19:51:08 +02:00
|
|
|
|
2018-06-06 13:35:06 +02:00
|
|
|
auto *userPopup = new UserInfoPopup;
|
2018-06-13 13:27:10 +02:00
|
|
|
userPopup->setData(user, this->channel_);
|
2018-06-06 10:46:23 +02:00
|
|
|
userPopup->setAttribute(Qt::WA_DeleteOnClose);
|
2018-06-19 22:29:58 +02:00
|
|
|
QPoint offset(int(150 * this->getScale()), int(70 * this->getScale()));
|
|
|
|
userPopup->move(QCursor::pos() - offset);
|
2018-06-06 10:46:23 +02:00
|
|
|
userPopup->show();
|
|
|
|
|
2017-04-24 23:00:26 +02:00
|
|
|
qDebug() << "Clicked " << user << "s message";
|
|
|
|
break;
|
2017-07-26 09:08:19 +02:00
|
|
|
}
|
2018-06-06 15:54:14 +02:00
|
|
|
|
2017-07-31 00:57:42 +02:00
|
|
|
case messages::Link::Url: {
|
2018-05-23 21:16:34 +02:00
|
|
|
QDesktopServices::openUrl(QUrl(link.value));
|
2017-07-26 09:08:19 +02:00
|
|
|
break;
|
|
|
|
}
|
2018-06-06 15:54:14 +02:00
|
|
|
|
2018-01-17 14:14:31 +01:00
|
|
|
case messages::Link::UserAction: {
|
2018-01-28 03:52:52 +01:00
|
|
|
QString value = link.value;
|
2018-01-17 14:14:31 +01:00
|
|
|
value.replace("{user}", layout->getMessage()->loginName);
|
2018-06-13 13:27:10 +02:00
|
|
|
this->channel_->sendMessage(value);
|
2018-01-17 14:14:31 +01:00
|
|
|
}
|
2018-06-06 15:54:14 +02:00
|
|
|
|
|
|
|
default:;
|
2017-04-24 23:00:26 +02:00
|
|
|
}
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
bool ChannelView::tryGetMessageAt(QPoint p, std::shared_ptr<messages::MessageLayout> &_message,
|
2017-09-16 00:05:06 +02:00
|
|
|
QPoint &relativePos, int &index)
|
2017-02-17 23:51:35 +01:00
|
|
|
{
|
2017-12-22 15:13:42 +01:00
|
|
|
auto messagesSnapshot = this->getMessagesSnapshot();
|
2017-02-17 23:51:35 +01:00
|
|
|
|
2018-06-13 13:27:10 +02:00
|
|
|
size_t start = this->scrollBar_.getCurrentValue();
|
2017-02-17 23:51:35 +01:00
|
|
|
|
2017-12-22 15:13:42 +01:00
|
|
|
if (start >= messagesSnapshot.getLength()) {
|
2017-02-17 23:51:35 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-06-13 13:27:10 +02:00
|
|
|
int y = -(messagesSnapshot[start]->getHeight() * (fmod(this->scrollBar_.getCurrentValue(), 1)));
|
2017-02-17 23:51:35 +01:00
|
|
|
|
2017-12-22 15:13:42 +01:00
|
|
|
for (size_t i = start; i < messagesSnapshot.getLength(); ++i) {
|
|
|
|
auto message = messagesSnapshot[i];
|
2017-02-17 23:51:35 +01:00
|
|
|
|
2017-04-24 23:00:26 +02:00
|
|
|
if (p.y() < y + message->getHeight()) {
|
|
|
|
relativePos = QPoint(p.x(), p.y() - y);
|
2017-02-17 23:51:35 +01:00
|
|
|
_message = message;
|
2017-08-18 15:12:07 +02:00
|
|
|
index = i;
|
2017-02-17 23:51:35 +01:00
|
|
|
return true;
|
|
|
|
}
|
2017-04-24 23:00:26 +02:00
|
|
|
|
|
|
|
y += message->getHeight();
|
2017-02-17 23:51:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2017-06-06 17:18:23 +02:00
|
|
|
|
2018-06-13 03:58:52 +02:00
|
|
|
int ChannelView::getLayoutWidth() const
|
|
|
|
{
|
2018-06-13 03:58:52 +02:00
|
|
|
if (this->scrollBar_.isVisible())
|
2018-06-13 03:58:52 +02:00
|
|
|
return int(this->width() - 8 * this->getScale());
|
|
|
|
|
|
|
|
return this->width();
|
|
|
|
}
|
|
|
|
|
2017-04-14 17:52:22 +02:00
|
|
|
} // namespace widgets
|
|
|
|
} // namespace chatterino
|