I BROKE EVERYTHING
refactored the rendering process
This commit is contained in:
@@ -18,7 +18,7 @@
|
||||
namespace chatterino {
|
||||
namespace widgets {
|
||||
|
||||
AccountPopupWidget::AccountPopupWidget(std::shared_ptr<Channel> _channel)
|
||||
AccountPopupWidget::AccountPopupWidget(SharedChannel _channel)
|
||||
: BaseWidget()
|
||||
, ui(new Ui::AccountPopup)
|
||||
, channel(_channel)
|
||||
@@ -132,7 +132,7 @@ void AccountPopupWidget::setName(const QString &name)
|
||||
this->getUserId();
|
||||
}
|
||||
|
||||
void AccountPopupWidget::setChannel(std::shared_ptr<Channel> _channel)
|
||||
void AccountPopupWidget::setChannel(SharedChannel _channel)
|
||||
{
|
||||
this->channel = _channel;
|
||||
}
|
||||
|
||||
@@ -23,10 +23,10 @@ class AccountPopupWidget : public BaseWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
AccountPopupWidget(std::shared_ptr<Channel> _channel);
|
||||
AccountPopupWidget(SharedChannel _channel);
|
||||
|
||||
void setName(const QString &name);
|
||||
void setChannel(std::shared_ptr<Channel> _channel);
|
||||
void setChannel(SharedChannel _channel);
|
||||
|
||||
void updatePermissions();
|
||||
|
||||
@@ -47,7 +47,7 @@ private:
|
||||
enum class permissions { User, Mod, Owner };
|
||||
permissions permission;
|
||||
|
||||
std::shared_ptr<Channel> channel;
|
||||
SharedChannel channel;
|
||||
|
||||
QString userID;
|
||||
QPixmap avatar;
|
||||
|
||||
+17
-26
@@ -34,7 +34,7 @@ EmotePopup::EmotePopup(singletons::ThemeManager &themeManager)
|
||||
this->loadEmojis();
|
||||
}
|
||||
|
||||
void EmotePopup::loadChannel(std::shared_ptr<Channel> _channel)
|
||||
void EmotePopup::loadChannel(SharedChannel _channel)
|
||||
{
|
||||
TwitchChannel *channel = dynamic_cast<TwitchChannel *>(_channel.get());
|
||||
|
||||
@@ -42,29 +42,25 @@ void EmotePopup::loadChannel(std::shared_ptr<Channel> _channel)
|
||||
return;
|
||||
}
|
||||
|
||||
std::shared_ptr<Channel> emoteChannel(new Channel(""));
|
||||
SharedChannel emoteChannel(new Channel(""));
|
||||
|
||||
auto addEmotes = [&](util::EmoteMap &map, const QString &title, const QString &emoteDesc) {
|
||||
// TITLE
|
||||
messages::MessageBuilder builder1;
|
||||
|
||||
builder1.appendWord(Word(title, Word::Flags::Text, MessageColor(MessageColor::Text),
|
||||
singletons::FontManager::Medium, QString(), QString()));
|
||||
builder1.appendElement(new TextElement(title, MessageElement::Text));
|
||||
|
||||
builder1.getMessage()->centered = true;
|
||||
builder1.getMessage()->addFlags(Message::Centered);
|
||||
emoteChannel->addMessage(builder1.getMessage());
|
||||
|
||||
// EMOTES
|
||||
messages::MessageBuilder builder2;
|
||||
builder2.getMessage()->centered = true;
|
||||
builder2.getMessage()->setDisableCompactEmotes(true);
|
||||
|
||||
int preferredEmoteSize = singletons::SettingManager::getInstance().preferredEmoteQuality;
|
||||
builder2.getMessage()->addFlags(Message::Centered);
|
||||
builder2.getMessage()->addFlags(Message::DisableCompactEmotes);
|
||||
|
||||
map.each([&](const QString &key, const util::EmoteData &value) {
|
||||
builder2.appendWord(Word(value.getImageForSize(preferredEmoteSize),
|
||||
Word::Flags::AlwaysShow, key, emoteDesc,
|
||||
Link(Link::Type::InsertText, key)));
|
||||
builder2.appendElement((new EmoteElement(value, MessageElement::Flags::AlwaysShow)) //
|
||||
->setLink(Link(Link::InsertText, key)));
|
||||
});
|
||||
|
||||
emoteChannel->addMessage(builder2.getMessage());
|
||||
@@ -85,31 +81,26 @@ void EmotePopup::loadChannel(std::shared_ptr<Channel> _channel)
|
||||
|
||||
void EmotePopup::loadEmojis()
|
||||
{
|
||||
int preferredEmoteSize = singletons::SettingManager::getInstance().preferredEmoteQuality;
|
||||
util::EmoteMap &emojis = singletons::EmoteManager::getInstance().getEmojis();
|
||||
|
||||
std::shared_ptr<Channel> emojiChannel(new Channel(""));
|
||||
SharedChannel emojiChannel(new Channel(""));
|
||||
|
||||
// title
|
||||
messages::MessageBuilder builder1;
|
||||
|
||||
builder1.appendWord(Word("emojis", Word::Flags::Text, MessageColor(MessageColor::Text),
|
||||
singletons::FontManager::Medium, QString(), QString()));
|
||||
|
||||
builder1.getMessage()->centered = true;
|
||||
builder1.appendElement(new TextElement("emojis", MessageElement::Text));
|
||||
builder1.getMessage()->addFlags(Message::Centered);
|
||||
emojiChannel->addMessage(builder1.getMessage());
|
||||
|
||||
// emojis
|
||||
messages::MessageBuilder builder;
|
||||
builder.getMessage()->centered = true;
|
||||
builder.getMessage()->setDisableCompactEmotes(true);
|
||||
builder.getMessage()->addFlags(Message::Centered);
|
||||
builder.getMessage()->setFlags(Message::DisableCompactEmotes);
|
||||
|
||||
emojis.each(
|
||||
[this, &builder, preferredEmoteSize](const QString &key, const util::EmoteData &value) {
|
||||
auto emoteImage = value.getImageForSize(preferredEmoteSize);
|
||||
builder.appendWord(Word(emoteImage, Word::Flags::AlwaysShow, key, "emoji",
|
||||
Link(Link::Type::InsertText, key)));
|
||||
});
|
||||
emojis.each([this, &builder](const QString &key, const util::EmoteData &value) {
|
||||
builder.appendElement((new EmoteElement(value, MessageElement::Flags::AlwaysShow)) //
|
||||
->setLink(Link(Link::Type::InsertText, key)));
|
||||
});
|
||||
emojiChannel->addMessage(builder.getMessage());
|
||||
|
||||
this->viewEmojis->setChannel(emojiChannel);
|
||||
|
||||
@@ -12,7 +12,7 @@ class EmotePopup : public BaseWidget
|
||||
public:
|
||||
explicit EmotePopup(singletons::ThemeManager &);
|
||||
|
||||
void loadChannel(std::shared_ptr<Channel> channel);
|
||||
void loadChannel(SharedChannel channel);
|
||||
void loadEmojis();
|
||||
|
||||
private:
|
||||
|
||||
+282
-436
@@ -1,8 +1,8 @@
|
||||
#include "channelview.hpp"
|
||||
#include "debug/log.hpp"
|
||||
#include "messages/layouts/messagelayout.hpp"
|
||||
#include "messages/limitedqueuesnapshot.hpp"
|
||||
#include "messages/message.hpp"
|
||||
#include "messages/messageref.hpp"
|
||||
#include "singletons/channelmanager.hpp"
|
||||
#include "singletons/settingsmanager.hpp"
|
||||
#include "singletons/thememanager.hpp"
|
||||
@@ -57,8 +57,7 @@ ChannelView::ChannelView(BaseWidget *parent)
|
||||
|
||||
singletons::WindowManager &windowManager = singletons::WindowManager::getInstance();
|
||||
|
||||
this->repaintGifsConnection =
|
||||
windowManager.repaintGifs.connect([&] { this->updateGifEmotes(); });
|
||||
this->repaintGifsConnection = windowManager.repaintGifs.connect([&] { this->queueUpdate(); });
|
||||
this->layoutConnection = windowManager.layout.connect([&](Channel *channel) {
|
||||
if (channel == nullptr || this->channel.get() == channel) {
|
||||
this->layoutMessages();
|
||||
@@ -225,14 +224,6 @@ void ChannelView::clearMessages()
|
||||
this->queueUpdate();
|
||||
}
|
||||
|
||||
void ChannelView::updateGifEmotes()
|
||||
{
|
||||
if (!this->gifEmotes.empty()) {
|
||||
this->onlyUpdateEmotes = true;
|
||||
this->queueUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
Scrollbar &ChannelView::getScrollBar()
|
||||
{
|
||||
return this->scrollBar;
|
||||
@@ -240,103 +231,106 @@ Scrollbar &ChannelView::getScrollBar()
|
||||
|
||||
QString ChannelView::getSelectedText()
|
||||
{
|
||||
auto messagesSnapshot = this->getMessagesSnapshot();
|
||||
// fourtf: xD
|
||||
// auto messagesSnapshot = this->getMessagesSnapshot();
|
||||
|
||||
QString text;
|
||||
bool isSingleMessage = this->selection.isSingleMessage();
|
||||
// QString text;
|
||||
// bool isSingleMessage = this->selection.isSingleMessage();
|
||||
|
||||
size_t i = std::max(0, this->selection.min.messageIndex);
|
||||
// size_t i = std::max(0, this->selection.min.messageIndex);
|
||||
|
||||
int charIndex = 0;
|
||||
// int charIndex = 0;
|
||||
|
||||
bool first = true;
|
||||
// bool first = true;
|
||||
|
||||
auto addPart = [&](const WordPart &part, int from = 0, int to = -1) {
|
||||
if (part.getCopyText().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
// auto addPart = [&](const MessageLayoutElement &part, int from = 0, int to = -1) {
|
||||
// if (part.getCopyText().isEmpty()) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
if (part.getWord().isText()) {
|
||||
text += part.getText().mid(from, to);
|
||||
} else {
|
||||
text += part.getCopyText();
|
||||
}
|
||||
};
|
||||
// if (part.getWord().isText()) {
|
||||
// text += part.getText().mid(from, to);
|
||||
// } else {
|
||||
// text += part.getCopyText();
|
||||
// }
|
||||
// };
|
||||
|
||||
// first line
|
||||
for (const messages::WordPart &part : messagesSnapshot[i]->getWordParts()) {
|
||||
int charLength = part.getCharacterLength();
|
||||
// // first line
|
||||
// for (const messages::MessageLayoutElement &part : messagesSnapshot[i]->getWordParts()) {
|
||||
// int charLength = part.getCharacterLength();
|
||||
|
||||
if (charIndex + charLength < this->selection.min.charIndex) {
|
||||
charIndex += charLength;
|
||||
continue;
|
||||
}
|
||||
// if (charIndex + charLength < this->selection.min.charIndex) {
|
||||
// charIndex += charLength;
|
||||
// continue;
|
||||
// }
|
||||
|
||||
if (first) {
|
||||
first = false;
|
||||
bool isSingleWord =
|
||||
isSingleMessage &&
|
||||
this->selection.max.charIndex - charIndex < part.getCharacterLength();
|
||||
// if (first) {
|
||||
// first = false;
|
||||
// bool isSingleWord =
|
||||
// isSingleMessage &&
|
||||
// this->selection.max.charIndex - charIndex < part.getCharacterLength();
|
||||
|
||||
if (isSingleWord) {
|
||||
// return single word
|
||||
addPart(part, this->selection.min.charIndex - charIndex,
|
||||
this->selection.max.charIndex - this->selection.min.charIndex);
|
||||
return text;
|
||||
} else {
|
||||
// add first word of the selection
|
||||
addPart(part, this->selection.min.charIndex - charIndex);
|
||||
}
|
||||
} else if (isSingleMessage && charIndex + charLength >= selection.max.charIndex) {
|
||||
addPart(part, 0, this->selection.max.charIndex - charIndex);
|
||||
// if (isSingleWord) {
|
||||
// // return single word
|
||||
// addPart(part, this->selection.min.charIndex - charIndex,
|
||||
// this->selection.max.charIndex - this->selection.min.charIndex);
|
||||
// return text;
|
||||
// } else {
|
||||
// // add first word of the selection
|
||||
// addPart(part, this->selection.min.charIndex - charIndex);
|
||||
// }
|
||||
// } else if (isSingleMessage && charIndex + charLength >= selection.max.charIndex) {
|
||||
// addPart(part, 0, this->selection.max.charIndex - charIndex);
|
||||
|
||||
return text;
|
||||
} else {
|
||||
text += part.getCopyText() + (part.hasTrailingSpace() ? " " : "");
|
||||
}
|
||||
// return text;
|
||||
// } else {
|
||||
// text += part.getCopyText() + (part.hasTrailingSpace() ? " " : "");
|
||||
// }
|
||||
|
||||
charIndex += charLength;
|
||||
}
|
||||
// charIndex += charLength;
|
||||
// }
|
||||
|
||||
text += "\n";
|
||||
// text += "\n";
|
||||
|
||||
// middle lines
|
||||
for (i++; (int)i < this->selection.max.messageIndex; i++) {
|
||||
for (const messages::WordPart &part : messagesSnapshot[i]->getWordParts()) {
|
||||
if (!part.getCopyText().isEmpty()) {
|
||||
text += part.getCopyText();
|
||||
// // middle lines
|
||||
// for (i++; (int)i < this->selection.max.messageIndex; i++) {
|
||||
// for (const messages::MessageLayoutElement &part : messagesSnapshot[i]->getWordParts())
|
||||
// {
|
||||
// if (!part.getCopyText().isEmpty()) {
|
||||
// text += part.getCopyText();
|
||||
|
||||
if (part.hasTrailingSpace()) {
|
||||
text += " ";
|
||||
}
|
||||
}
|
||||
}
|
||||
text += "\n";
|
||||
}
|
||||
// if (part.hasTrailingSpace()) {
|
||||
// text += " ";
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// text += "\n";
|
||||
// }
|
||||
|
||||
// last line
|
||||
charIndex = 0;
|
||||
// // last line
|
||||
// charIndex = 0;
|
||||
|
||||
for (const messages::WordPart &part :
|
||||
messagesSnapshot[this->selection.max.messageIndex]->getWordParts()) {
|
||||
int charLength = part.getCharacterLength();
|
||||
// for (const messages::MessageLayoutElement &part :
|
||||
// messagesSnapshot[this->selection.max.messageIndex]->getWordParts()) {
|
||||
// int charLength = part.getCharacterLength();
|
||||
|
||||
if (charIndex + charLength >= this->selection.max.charIndex) {
|
||||
addPart(part, 0, this->selection.max.charIndex - charIndex);
|
||||
// if (charIndex + charLength >= this->selection.max.charIndex) {
|
||||
// addPart(part, 0, this->selection.max.charIndex - charIndex);
|
||||
|
||||
return text;
|
||||
}
|
||||
// return text;
|
||||
// }
|
||||
|
||||
text += part.getCopyText();
|
||||
// text += part.getCopyText();
|
||||
|
||||
if (part.hasTrailingSpace()) {
|
||||
text += " ";
|
||||
}
|
||||
// if (part.hasTrailingSpace()) {
|
||||
// text += " ";
|
||||
// }
|
||||
|
||||
charIndex += charLength;
|
||||
}
|
||||
// charIndex += charLength;
|
||||
// }
|
||||
|
||||
return text;
|
||||
// return text;
|
||||
return "";
|
||||
}
|
||||
|
||||
bool ChannelView::hasSelection()
|
||||
@@ -360,7 +354,7 @@ bool ChannelView::getEnableScrollingToBottom() const
|
||||
return this->enableScrollingToBottom;
|
||||
}
|
||||
|
||||
messages::LimitedQueueSnapshot<SharedMessageRef> ChannelView::getMessagesSnapshot()
|
||||
messages::LimitedQueueSnapshot<MessageLayoutPtr> ChannelView::getMessagesSnapshot()
|
||||
{
|
||||
if (!this->paused) {
|
||||
this->snapshot = this->messages.getSnapshot();
|
||||
@@ -369,7 +363,7 @@ messages::LimitedQueueSnapshot<SharedMessageRef> ChannelView::getMessagesSnapsho
|
||||
return this->snapshot;
|
||||
}
|
||||
|
||||
void ChannelView::setChannel(std::shared_ptr<Channel> newChannel)
|
||||
void ChannelView::setChannel(SharedChannel newChannel)
|
||||
{
|
||||
if (this->channel) {
|
||||
this->detachChannel();
|
||||
@@ -378,12 +372,12 @@ void ChannelView::setChannel(std::shared_ptr<Channel> newChannel)
|
||||
|
||||
// on new message
|
||||
this->messageAppendedConnection =
|
||||
newChannel->messageAppended.connect([this](SharedMessage &message) {
|
||||
SharedMessageRef deleted;
|
||||
newChannel->messageAppended.connect([this](MessagePtr &message) {
|
||||
MessageLayoutPtr deleted;
|
||||
|
||||
auto messageRef = new MessageRef(message);
|
||||
auto messageRef = new MessageLayout(message);
|
||||
|
||||
if (this->messages.pushBack(SharedMessageRef(messageRef), deleted)) {
|
||||
if (this->messages.pushBack(MessageLayoutPtr(messageRef), deleted)) {
|
||||
if (this->scrollBar.isAtBottom()) {
|
||||
this->scrollBar.scrollToBottom();
|
||||
} else {
|
||||
@@ -391,7 +385,7 @@ void ChannelView::setChannel(std::shared_ptr<Channel> newChannel)
|
||||
}
|
||||
}
|
||||
|
||||
if (message->containsHighlightedPhrase()) {
|
||||
if (!message->hasFlags(Message::DoNotTriggerNotification)) {
|
||||
this->highlightedMessageReceived.invoke();
|
||||
}
|
||||
|
||||
@@ -402,12 +396,12 @@ void ChannelView::setChannel(std::shared_ptr<Channel> newChannel)
|
||||
});
|
||||
|
||||
this->messageAddedAtStartConnection =
|
||||
newChannel->messagesAddedAtStart.connect([this](std::vector<SharedMessage> &messages) {
|
||||
std::vector<SharedMessageRef> messageRefs;
|
||||
newChannel->messagesAddedAtStart.connect([this](std::vector<MessagePtr> &messages) {
|
||||
std::vector<MessageLayoutPtr> messageRefs;
|
||||
messageRefs.resize(messages.size());
|
||||
qDebug() << messages.size();
|
||||
for (int i = 0; i < messages.size(); i++) {
|
||||
messageRefs.at(i) = SharedMessageRef(new MessageRef(messages.at(i)));
|
||||
for (size_t i = 0; i < messages.size(); i++) {
|
||||
messageRefs.at(i) = MessageLayoutPtr(new MessageLayout(messages.at(i)));
|
||||
}
|
||||
|
||||
if (this->messages.pushFront(messageRefs).size() > 0) {
|
||||
@@ -420,7 +414,7 @@ void ChannelView::setChannel(std::shared_ptr<Channel> newChannel)
|
||||
|
||||
std::vector<ScrollbarHighlight> highlights;
|
||||
highlights.reserve(messages.size());
|
||||
for (int i = 0; i < messages.size(); i++) {
|
||||
for (size_t i = 0; i < messages.size(); i++) {
|
||||
highlights.push_back(messages.at(i)->getScrollBarHighlight());
|
||||
}
|
||||
|
||||
@@ -432,7 +426,7 @@ void ChannelView::setChannel(std::shared_ptr<Channel> newChannel)
|
||||
|
||||
// on message removed
|
||||
this->messageRemovedConnection =
|
||||
newChannel->messageRemovedFromStart.connect([this](SharedMessage &) {
|
||||
newChannel->messageRemovedFromStart.connect([this](MessagePtr &) {
|
||||
this->selection.min.messageIndex--;
|
||||
this->selection.max.messageIndex--;
|
||||
this->selection.start.messageIndex--;
|
||||
@@ -443,8 +437,8 @@ void ChannelView::setChannel(std::shared_ptr<Channel> newChannel)
|
||||
|
||||
// on message replaced
|
||||
this->messageReplacedConnection =
|
||||
newChannel->messageReplaced.connect([this](size_t index, SharedMessage replacement) {
|
||||
SharedMessageRef newItem(new MessageRef(replacement));
|
||||
newChannel->messageReplaced.connect([this](size_t index, MessagePtr replacement) {
|
||||
MessageLayoutPtr newItem(new MessageLayout(replacement));
|
||||
|
||||
this->scrollBar.replaceHighlight(index, replacement->getScrollBarHighlight());
|
||||
|
||||
@@ -455,11 +449,11 @@ void ChannelView::setChannel(std::shared_ptr<Channel> newChannel)
|
||||
auto snapshot = newChannel->getMessageSnapshot();
|
||||
|
||||
for (size_t i = 0; i < snapshot.getLength(); i++) {
|
||||
SharedMessageRef deleted;
|
||||
MessageLayoutPtr deleted;
|
||||
|
||||
auto messageRef = new MessageRef(snapshot[i]);
|
||||
auto messageRef = new MessageLayout(snapshot[i]);
|
||||
|
||||
this->messages.pushBack(SharedMessageRef(messageRef), deleted);
|
||||
this->messages.pushBack(MessageLayoutPtr(messageRef), deleted);
|
||||
}
|
||||
|
||||
this->channel = newChannel;
|
||||
@@ -513,47 +507,20 @@ void ChannelView::setSelection(const SelectionItem &start, const SelectionItem &
|
||||
void ChannelView::paintEvent(QPaintEvent * /*event*/)
|
||||
{
|
||||
// BENCH(timer);
|
||||
|
||||
QPainter painter(this);
|
||||
|
||||
// only update gif emotes
|
||||
#ifndef Q_OS_MACOS
|
||||
// if (this->onlyUpdateEmotes) {
|
||||
// this->onlyUpdateEmotes = false;
|
||||
|
||||
// for (const GifEmoteData &item : this->gifEmotes) {
|
||||
// painter.fillRect(item.rect, this->themeManager.ChatBackground);
|
||||
|
||||
// painter.drawPixmap(item.rect, *item.image->getPixmap());
|
||||
// }
|
||||
|
||||
// return;
|
||||
// }
|
||||
#endif
|
||||
|
||||
// update all messages
|
||||
this->gifEmotes.clear();
|
||||
|
||||
painter.fillRect(rect(), this->themeManager.splits.background);
|
||||
|
||||
// draw messages
|
||||
this->drawMessages(painter, false);
|
||||
|
||||
painter.setRenderHint(QPainter::SmoothPixmapTransform);
|
||||
|
||||
// draw gif emotes
|
||||
for (GifEmoteData &item : this->gifEmotes) {
|
||||
painter.drawPixmap(item.rect, *item.image->getPixmap());
|
||||
}
|
||||
|
||||
// draw the overlays of the messages (such as disabled message blur-out)
|
||||
this->drawMessages(painter, true);
|
||||
this->drawMessages(painter);
|
||||
|
||||
// MARK(timer);
|
||||
}
|
||||
|
||||
// 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, bool overlays)
|
||||
void ChannelView::drawMessages(QPainter &painter)
|
||||
{
|
||||
auto messagesSnapshot = this->getMessagesSnapshot();
|
||||
|
||||
@@ -566,83 +533,16 @@ void ChannelView::drawMessages(QPainter &painter, bool overlays)
|
||||
int y = -(messagesSnapshot[start].get()->getHeight() *
|
||||
(fmod(this->scrollBar.getCurrentValue(), 1)));
|
||||
|
||||
messages::MessageRef *end = nullptr;
|
||||
messages::MessageLayout *end = nullptr;
|
||||
|
||||
for (size_t i = start; i < messagesSnapshot.getLength(); ++i) {
|
||||
messages::MessageRef *messageRef = messagesSnapshot[i].get();
|
||||
messages::MessageLayout *layout = messagesSnapshot[i].get();
|
||||
|
||||
if (overlays) {
|
||||
if (messageRef->isDisabled()) {
|
||||
painter.fillRect(0, y, this->width(), messageRef->getHeight(),
|
||||
this->themeManager.messages.disabled);
|
||||
}
|
||||
} else {
|
||||
std::shared_ptr<QPixmap> buffer = messageRef->buffer;
|
||||
layout->paint(painter, y, i, this->selection);
|
||||
|
||||
// bool updateBuffer = messageRef->updateBuffer;
|
||||
bool updateBuffer = false;
|
||||
y += layout->getHeight();
|
||||
|
||||
if (!buffer) {
|
||||
QPixmap *pixmap;
|
||||
|
||||
#ifdef Q_OS_MACOS
|
||||
|
||||
pixmap = new QPixmap(
|
||||
(int)(this->width() * painter.device()->devicePixelRatioF()),
|
||||
(int)(messageRef->getHeight() * painter.device()->devicePixelRatioF()));
|
||||
pixmap->setDevicePixelRatio(painter.device()->devicePixelRatioF());
|
||||
#else
|
||||
pixmap = new QPixmap(this->width(), messageRef->getHeight());
|
||||
#endif
|
||||
buffer = std::shared_ptr<QPixmap>(pixmap);
|
||||
updateBuffer = true;
|
||||
}
|
||||
|
||||
updateBuffer |= this->selecting;
|
||||
|
||||
// update messages that have been changed
|
||||
if (updateBuffer) {
|
||||
this->updateMessageBuffer(messageRef, buffer.get(), i);
|
||||
// qDebug() << "updating buffer xD";
|
||||
}
|
||||
|
||||
// get gif emotes
|
||||
for (messages::WordPart const &wordPart : messageRef->getWordParts()) {
|
||||
if (wordPart.getWord().isImage()) {
|
||||
messages::LazyLoadedImage &lli = wordPart.getWord().getImage();
|
||||
|
||||
if (lli.getAnimated()) {
|
||||
GifEmoteData gifEmoteData;
|
||||
gifEmoteData.image = &lli;
|
||||
QRect rect(wordPart.getX(), wordPart.getY() + y, wordPart.getWidth(),
|
||||
wordPart.getHeight());
|
||||
|
||||
gifEmoteData.rect = rect;
|
||||
|
||||
this->gifEmotes.push_back(gifEmoteData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
messageRef->buffer = buffer;
|
||||
|
||||
if (buffer) {
|
||||
//#ifdef Q_OS_MACOS
|
||||
// painter.setRenderHint(QPainter::SmoothPixmapTransform, false);
|
||||
// painter.drawPixmap(0, y,
|
||||
|
||||
// (int)(buffer->width() / painter.device()->devicePixelRatioF()),
|
||||
// (int)(buffer->height() / painter.device()->devicePixelRatioF()),
|
||||
// *buffer.get());
|
||||
//#else
|
||||
painter.drawPixmap(0, y, *buffer.get());
|
||||
//#endif
|
||||
}
|
||||
}
|
||||
|
||||
y += messageRef->getHeight();
|
||||
|
||||
end = messageRef;
|
||||
end = layout;
|
||||
if (y > height()) {
|
||||
break;
|
||||
}
|
||||
@@ -662,222 +562,168 @@ void ChannelView::drawMessages(QPainter &painter, bool overlays)
|
||||
}
|
||||
|
||||
// delete the message buffers that aren't on screen
|
||||
for (std::shared_ptr<messages::MessageRef> item : this->messagesOnScreen) {
|
||||
item->buffer.reset();
|
||||
for (const std::shared_ptr<messages::MessageLayout> &item : this->messagesOnScreen) {
|
||||
item->deleteBuffer();
|
||||
}
|
||||
|
||||
this->messagesOnScreen.clear();
|
||||
|
||||
// add all messages on screen to the map
|
||||
for (size_t i = start; i < messagesSnapshot.getLength(); ++i) {
|
||||
std::shared_ptr<messages::MessageRef> messageRef = messagesSnapshot[i];
|
||||
std::shared_ptr<messages::MessageLayout> layout = messagesSnapshot[i];
|
||||
|
||||
this->messagesOnScreen.insert(messageRef);
|
||||
this->messagesOnScreen.insert(layout);
|
||||
|
||||
if (messageRef.get() == end) {
|
||||
if (layout.get() == end) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ChannelView::updateMessageBuffer(messages::MessageRef *messageRef, QPixmap *buffer,
|
||||
int messageIndex)
|
||||
{
|
||||
QPainter painter(buffer);
|
||||
|
||||
painter.setRenderHint(QPainter::SmoothPixmapTransform);
|
||||
|
||||
// draw background
|
||||
// if (this->selectionMin.messageIndex <= messageIndex &&
|
||||
// this->selectionMax.messageIndex >= messageIndex) {
|
||||
// painter.fillRect(buffer->rect(), QColor(24, 55, 25));
|
||||
//} else {
|
||||
painter.fillRect(buffer->rect(),
|
||||
(messageRef->getMessage()->containsHighlightedPhrase())
|
||||
? this->themeManager.messages.backgrounds.highlighted
|
||||
: this->themeManager.messages.backgrounds.regular);
|
||||
//}
|
||||
|
||||
// draw selection
|
||||
if (!selection.isEmpty()) {
|
||||
drawMessageSelection(painter, messageRef, messageIndex, buffer->height());
|
||||
}
|
||||
|
||||
// draw message
|
||||
for (messages::WordPart const &wordPart : messageRef->getWordParts()) {
|
||||
// image
|
||||
if (wordPart.getWord().isImage()) {
|
||||
messages::LazyLoadedImage &lli = wordPart.getWord().getImage();
|
||||
|
||||
const QPixmap *image = lli.getPixmap();
|
||||
|
||||
if (image != nullptr && !lli.getAnimated()) {
|
||||
painter.drawPixmap(QRect(wordPart.getX(), wordPart.getY(), wordPart.getWidth(),
|
||||
wordPart.getHeight()),
|
||||
*image);
|
||||
}
|
||||
}
|
||||
// text
|
||||
else {
|
||||
QColor color = wordPart.getWord().getTextColor().getColor(this->themeManager);
|
||||
|
||||
this->themeManager.normalizeColor(color);
|
||||
|
||||
painter.setPen(color);
|
||||
painter.setFont(wordPart.getWord().getFont(this->getDpiMultiplier()));
|
||||
|
||||
painter.drawText(QRectF(wordPart.getX(), wordPart.getY(), 10000, 10000),
|
||||
wordPart.getText(), QTextOption(Qt::AlignLeft | Qt::AlignTop));
|
||||
}
|
||||
}
|
||||
|
||||
messageRef->updateBuffer = false;
|
||||
}
|
||||
|
||||
void ChannelView::drawMessageSelection(QPainter &painter, messages::MessageRef *messageRef,
|
||||
int messageIndex, int bufferHeight)
|
||||
{
|
||||
if (this->selection.min.messageIndex > messageIndex ||
|
||||
this->selection.max.messageIndex < messageIndex) {
|
||||
return;
|
||||
}
|
||||
|
||||
QColor selectionColor = this->themeManager.messages.selection;
|
||||
|
||||
int charIndex = 0;
|
||||
size_t i = 0;
|
||||
auto &parts = messageRef->getWordParts();
|
||||
|
||||
int currentLineNumber = 0;
|
||||
QRect rect;
|
||||
|
||||
if (parts.size() > 0) {
|
||||
if (selection.min.messageIndex == messageIndex) {
|
||||
rect.setTop(parts.at(0).getY());
|
||||
}
|
||||
rect.setLeft(parts.at(0).getX());
|
||||
}
|
||||
|
||||
// skip until selection start
|
||||
if (this->selection.min.messageIndex == messageIndex && this->selection.min.charIndex != 0) {
|
||||
for (; i < parts.size(); i++) {
|
||||
const messages::WordPart &part = parts.at(i);
|
||||
auto characterLength = part.getCharacterLength();
|
||||
|
||||
if (characterLength + charIndex > selection.min.charIndex) {
|
||||
break;
|
||||
}
|
||||
|
||||
charIndex += characterLength;
|
||||
currentLineNumber = part.getLineNumber();
|
||||
}
|
||||
|
||||
if (i >= parts.size()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// handle word that has a cut of selection
|
||||
const messages::WordPart &part = parts.at(i);
|
||||
|
||||
// check if selection if single word
|
||||
int characterLength = part.getCharacterLength();
|
||||
bool isSingleWord = charIndex + characterLength > this->selection.max.charIndex &&
|
||||
this->selection.max.messageIndex == messageIndex;
|
||||
|
||||
rect = part.getRect();
|
||||
currentLineNumber = part.getLineNumber();
|
||||
|
||||
if (part.getWord().isText()) {
|
||||
int offset = this->selection.min.charIndex - charIndex;
|
||||
|
||||
for (int j = 0; j < offset; j++) {
|
||||
rect.setLeft(rect.left() + part.getCharWidth(j, this->getDpiMultiplier()));
|
||||
}
|
||||
|
||||
if (isSingleWord) {
|
||||
int length = (this->selection.max.charIndex - charIndex) - offset;
|
||||
|
||||
rect.setRight(part.getX());
|
||||
|
||||
for (int j = 0; j < offset + length; j++) {
|
||||
rect.setRight(rect.right() + part.getCharWidth(j, this->getDpiMultiplier()));
|
||||
}
|
||||
|
||||
painter.fillRect(rect, selectionColor);
|
||||
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (isSingleWord) {
|
||||
if (charIndex + 1 != this->selection.max.charIndex) {
|
||||
rect.setRight(part.getX() + part.getWord().getImage().getScaledWidth());
|
||||
}
|
||||
painter.fillRect(rect, selectionColor);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (charIndex != this->selection.min.charIndex) {
|
||||
rect.setLeft(part.getX() + part.getWord().getImage().getScaledWidth());
|
||||
}
|
||||
}
|
||||
|
||||
i++;
|
||||
charIndex += characterLength;
|
||||
}
|
||||
|
||||
// go through lines and draw selection
|
||||
for (; i < parts.size(); i++) {
|
||||
const messages::WordPart &part = parts.at(i);
|
||||
|
||||
int charLength = part.getCharacterLength();
|
||||
|
||||
bool isLastSelectedWord = this->selection.max.messageIndex == messageIndex &&
|
||||
charIndex + charLength > this->selection.max.charIndex;
|
||||
|
||||
if (part.getLineNumber() == currentLineNumber) {
|
||||
rect.setLeft(std::min(rect.left(), part.getX()));
|
||||
rect.setTop(std::min(rect.top(), part.getY()));
|
||||
rect.setRight(std::max(rect.right(), part.getRight()));
|
||||
rect.setBottom(std::max(rect.bottom(), part.getBottom() - 1));
|
||||
} else {
|
||||
painter.fillRect(rect, selectionColor);
|
||||
|
||||
currentLineNumber = part.getLineNumber();
|
||||
|
||||
rect = part.getRect();
|
||||
}
|
||||
|
||||
if (isLastSelectedWord) {
|
||||
if (part.getWord().isText()) {
|
||||
int offset = this->selection.min.charIndex - charIndex;
|
||||
|
||||
int length = (this->selection.max.charIndex - charIndex) - offset;
|
||||
|
||||
rect.setRight(part.getX());
|
||||
|
||||
for (int j = 0; j < offset + length; j++) {
|
||||
rect.setRight(rect.right() + part.getCharWidth(j, this->getDpiMultiplier()));
|
||||
}
|
||||
} else {
|
||||
if (this->selection.max.charIndex == charIndex) {
|
||||
rect.setRight(part.getX());
|
||||
}
|
||||
}
|
||||
painter.fillRect(rect, selectionColor);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
charIndex += charLength;
|
||||
}
|
||||
|
||||
if (this->selection.max.messageIndex != messageIndex) {
|
||||
rect.setBottom(bufferHeight);
|
||||
}
|
||||
|
||||
painter.fillRect(rect, selectionColor);
|
||||
}
|
||||
// void ChannelView::drawMessageSelection(QPainter &painter, messages::MessageLayout *messageRef,
|
||||
// int messageIndex, int bufferHeight)
|
||||
//{
|
||||
// if (this->selection.min.messageIndex > messageIndex ||
|
||||
// this->selection.max.messageIndex < messageIndex) {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// QColor selectionColor = this->themeManager.messages.selection;
|
||||
//
|
||||
// int charIndex = 0;
|
||||
// size_t i = 0;
|
||||
// auto &parts = messageRef->getWordParts();
|
||||
//
|
||||
// int currentLineNumber = 0;
|
||||
// QRect rect;
|
||||
//
|
||||
// if (parts.size() > 0) {
|
||||
// if (selection.min.messageIndex == messageIndex) {
|
||||
// rect.setTop(parts.at(0).getY());
|
||||
// }
|
||||
// rect.setLeft(parts.at(0).getX());
|
||||
// }
|
||||
//
|
||||
// // skip until selection start
|
||||
// if (this->selection.min.messageIndex == messageIndex && this->selection.min.charIndex != 0) {
|
||||
// for (; i < parts.size(); i++) {
|
||||
// const messages::MessageLayoutElement &part = parts.at(i);
|
||||
// auto characterLength = part.getCharacterLength();
|
||||
//
|
||||
// if (characterLength + charIndex > selection.min.charIndex) {
|
||||
// break;
|
||||
// }
|
||||
//
|
||||
// charIndex += characterLength;
|
||||
// currentLineNumber = part.getLineNumber();
|
||||
// }
|
||||
//
|
||||
// if (i >= parts.size()) {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// // handle word that has a cut of selection
|
||||
// const messages::MessageLayoutElement &part = parts.at(i);
|
||||
//
|
||||
// // check if selection if single word
|
||||
// int characterLength = part.getCharacterLength();
|
||||
// bool isSingleWord = charIndex + characterLength > this->selection.max.charIndex &&
|
||||
// this->selection.max.messageIndex == messageIndex;
|
||||
//
|
||||
// rect = part.getRect();
|
||||
// currentLineNumber = part.getLineNumber();
|
||||
//
|
||||
// if (part.getWord().isText()) {
|
||||
// int offset = this->selection.min.charIndex - charIndex;
|
||||
//
|
||||
// for (int j = 0; j < offset; j++) {
|
||||
// rect.setLeft(rect.left() + part.getCharWidth(j, this->getDpiMultiplier()));
|
||||
// }
|
||||
//
|
||||
// if (isSingleWord) {
|
||||
// int length = (this->selection.max.charIndex - charIndex) - offset;
|
||||
//
|
||||
// rect.setRight(part.getX());
|
||||
//
|
||||
// for (int j = 0; j < offset + length; j++) {
|
||||
// rect.setRight(rect.right() + part.getCharWidth(j, this->getDpiMultiplier()));
|
||||
// }
|
||||
//
|
||||
// painter.fillRect(rect, selectionColor);
|
||||
//
|
||||
// return;
|
||||
// }
|
||||
// } else {
|
||||
// if (isSingleWord) {
|
||||
// if (charIndex + 1 != this->selection.max.charIndex) {
|
||||
// rect.setRight(part.getX() + part.getWord().getImage().getScaledWidth());
|
||||
// }
|
||||
// painter.fillRect(rect, selectionColor);
|
||||
//
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// if (charIndex != this->selection.min.charIndex) {
|
||||
// rect.setLeft(part.getX() + part.getWord().getImage().getScaledWidth());
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// i++;
|
||||
// charIndex += characterLength;
|
||||
// }
|
||||
//
|
||||
// // go through lines and draw selection
|
||||
// for (; i < parts.size(); i++) {
|
||||
// const messages::MessageLayoutElement &part = parts.at(i);
|
||||
//
|
||||
// int charLength = part.getCharacterLength();
|
||||
//
|
||||
// bool isLastSelectedWord = this->selection.max.messageIndex == messageIndex &&
|
||||
// charIndex + charLength > this->selection.max.charIndex;
|
||||
//
|
||||
// if (part.getLineNumber() == currentLineNumber) {
|
||||
// rect.setLeft(std::min(rect.left(), part.getX()));
|
||||
// rect.setTop(std::min(rect.top(), part.getY()));
|
||||
// rect.setRight(std::max(rect.right(), part.getRight()));
|
||||
// rect.setBottom(std::max(rect.bottom(), part.getBottom() - 1));
|
||||
// } else {
|
||||
// painter.fillRect(rect, selectionColor);
|
||||
//
|
||||
// currentLineNumber = part.getLineNumber();
|
||||
//
|
||||
// rect = part.getRect();
|
||||
// }
|
||||
//
|
||||
// if (isLastSelectedWord) {
|
||||
// if (part.getWord().isText()) {
|
||||
// int offset = this->selection.min.charIndex - charIndex;
|
||||
//
|
||||
// int length = (this->selection.max.charIndex - charIndex) - offset;
|
||||
//
|
||||
// rect.setRight(part.getX());
|
||||
//
|
||||
// for (int j = 0; j < offset + length; j++) {
|
||||
// rect.setRight(rect.right() + part.getCharWidth(j, this->getDpiMultiplier()));
|
||||
// }
|
||||
// } else {
|
||||
// if (this->selection.max.charIndex == charIndex) {
|
||||
// rect.setRight(part.getX());
|
||||
// }
|
||||
// }
|
||||
// painter.fillRect(rect, selectionColor);
|
||||
//
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// charIndex += charLength;
|
||||
// }
|
||||
//
|
||||
// if (this->selection.max.messageIndex != messageIndex) {
|
||||
// rect.setBottom(bufferHeight);
|
||||
// }
|
||||
//
|
||||
// painter.fillRect(rect, selectionColor);
|
||||
//}
|
||||
|
||||
void ChannelView::wheelEvent(QWheelEvent *event)
|
||||
{
|
||||
@@ -888,7 +734,8 @@ void ChannelView::wheelEvent(QWheelEvent *event)
|
||||
float delta = event->delta() * 1.5 * mouseMultiplier;
|
||||
|
||||
auto snapshot = this->getMessagesSnapshot();
|
||||
int i = std::min((int)desired, (int)snapshot.getLength());
|
||||
int snapshotLength = (int)snapshot.getLength();
|
||||
int i = std::min((int)desired, snapshotLength);
|
||||
|
||||
if (delta > 0) {
|
||||
float scrollFactor = fmod(desired, 1);
|
||||
@@ -916,7 +763,7 @@ void ChannelView::wheelEvent(QWheelEvent *event)
|
||||
float scrollFactor = 1 - fmod(desired, 1);
|
||||
float currentScrollLeft = (int)(scrollFactor * snapshot[i]->getHeight());
|
||||
|
||||
for (; i < snapshot.getLength(); i++) {
|
||||
for (; i < snapshotLength; i++) {
|
||||
if (delta < currentScrollLeft) {
|
||||
desired += scrollFactor * ((double)delta / currentScrollLeft);
|
||||
break;
|
||||
@@ -925,7 +772,7 @@ void ChannelView::wheelEvent(QWheelEvent *event)
|
||||
desired += scrollFactor;
|
||||
}
|
||||
|
||||
if (i == snapshot.getLength() - 1) {
|
||||
if (i == snapshotLength - 1) {
|
||||
desired = snapshot.getLength();
|
||||
} else {
|
||||
snapshot[i + 1]->layout(LAYOUT_WIDTH, this->getDpiMultiplier());
|
||||
@@ -957,12 +804,12 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event)
|
||||
}
|
||||
|
||||
auto tooltipWidget = TooltipWidget::getInstance();
|
||||
std::shared_ptr<messages::MessageRef> message;
|
||||
std::shared_ptr<messages::MessageLayout> layout;
|
||||
QPoint relativePos;
|
||||
int messageIndex;
|
||||
|
||||
// no message under cursor
|
||||
if (!tryGetMessageAt(event->pos(), message, relativePos, messageIndex)) {
|
||||
if (!tryGetMessageAt(event->pos(), layout, relativePos, messageIndex)) {
|
||||
this->setCursor(Qt::ArrowCursor);
|
||||
tooltipWidget->hide();
|
||||
return;
|
||||
@@ -971,7 +818,7 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event)
|
||||
// is selecting
|
||||
if (this->selecting) {
|
||||
this->pause(500);
|
||||
int index = message->getSelectionIndex(relativePos);
|
||||
int index = layout->getSelectionIndex(relativePos);
|
||||
|
||||
this->setSelection(this->selection.start, SelectionItem(messageIndex, index));
|
||||
|
||||
@@ -979,29 +826,28 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event)
|
||||
}
|
||||
|
||||
// message under cursor is collapsed
|
||||
if (message->isCollapsed()) {
|
||||
if (layout->getFlags() & MessageLayout::Collapsed) {
|
||||
this->setCursor(Qt::PointingHandCursor);
|
||||
tooltipWidget->hide();
|
||||
return;
|
||||
}
|
||||
|
||||
// check if word underneath cursor
|
||||
const messages::Word *hoverWord;
|
||||
if ((hoverWord = message->tryGetWordPart(relativePos)) == nullptr) {
|
||||
const messages::MessageLayoutElement *hoverLayoutElement = layout->getElementAt(relativePos);
|
||||
|
||||
if (hoverLayoutElement == nullptr) {
|
||||
this->setCursor(Qt::ArrowCursor);
|
||||
tooltipWidget->hide();
|
||||
return;
|
||||
}
|
||||
const auto &tooltip = hoverWord->getTooltip();
|
||||
const auto &tooltip = hoverLayoutElement->getCreator().getTooltip();
|
||||
|
||||
if (hoverWord->isImage()) {
|
||||
tooltipWidget->moveTo(event->globalPos());
|
||||
tooltipWidget->setText(tooltip);
|
||||
tooltipWidget->show();
|
||||
}
|
||||
tooltipWidget->moveTo(event->globalPos());
|
||||
tooltipWidget->setText(tooltip);
|
||||
tooltipWidget->show();
|
||||
|
||||
// check if word has a link
|
||||
if (hoverWord->getLink().isValid()) {
|
||||
if (hoverLayoutElement->getCreator().getLink().isValid()) {
|
||||
this->setCursor(Qt::PointingHandCursor);
|
||||
} else {
|
||||
this->setCursor(Qt::ArrowCursor);
|
||||
@@ -1018,13 +864,13 @@ void ChannelView::mousePressEvent(QMouseEvent *event)
|
||||
|
||||
this->lastPressPosition = event->screenPos();
|
||||
|
||||
std::shared_ptr<messages::MessageRef> message;
|
||||
std::shared_ptr<messages::MessageLayout> layout;
|
||||
QPoint relativePos;
|
||||
int messageIndex;
|
||||
|
||||
this->mouseDown(event);
|
||||
|
||||
if (!tryGetMessageAt(event->pos(), message, relativePos, messageIndex)) {
|
||||
if (!tryGetMessageAt(event->pos(), layout, relativePos, messageIndex)) {
|
||||
setCursor(Qt::ArrowCursor);
|
||||
|
||||
auto messagesSnapshot = this->getMessagesSnapshot();
|
||||
@@ -1045,11 +891,11 @@ void ChannelView::mousePressEvent(QMouseEvent *event)
|
||||
}
|
||||
|
||||
// check if message is collapsed
|
||||
if (message->isCollapsed()) {
|
||||
if (layout->getFlags() & MessageLayout::Collapsed) {
|
||||
return;
|
||||
}
|
||||
|
||||
int index = message->getSelectionIndex(relativePos);
|
||||
int index = layout->getSelectionIndex(relativePos);
|
||||
|
||||
auto selectionItem = SelectionItem(messageIndex, index);
|
||||
this->setSelection(selectionItem, selectionItem);
|
||||
@@ -1087,30 +933,30 @@ void ChannelView::mouseReleaseEvent(QMouseEvent *event)
|
||||
|
||||
// show user thing pajaW
|
||||
|
||||
std::shared_ptr<messages::MessageRef> message;
|
||||
std::shared_ptr<messages::MessageLayout> layout;
|
||||
QPoint relativePos;
|
||||
int messageIndex;
|
||||
|
||||
if (!tryGetMessageAt(event->pos(), message, relativePos, messageIndex)) {
|
||||
if (!tryGetMessageAt(event->pos(), layout, relativePos, messageIndex)) {
|
||||
// No message at clicked position
|
||||
this->userPopupWidget.hide();
|
||||
return;
|
||||
}
|
||||
|
||||
// message under cursor is collapsed
|
||||
if (message->isCollapsed()) {
|
||||
message->setCollapsed(false);
|
||||
if (layout->getFlags() & MessageLayout::Collapsed) {
|
||||
layout->addFlags(MessageLayout::Collapsed);
|
||||
this->layoutMessages();
|
||||
return;
|
||||
}
|
||||
|
||||
const messages::Word *hoverWord;
|
||||
const messages::MessageLayoutElement *hoverLayoutElement = layout->getElementAt(relativePos);
|
||||
|
||||
if ((hoverWord = message->tryGetWordPart(relativePos)) == nullptr) {
|
||||
if (hoverLayoutElement == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto &link = hoverWord->getLink();
|
||||
auto &link = hoverLayoutElement->getCreator().getLink();
|
||||
|
||||
switch (link.getType()) {
|
||||
case messages::Link::UserInfo: {
|
||||
@@ -1131,7 +977,7 @@ void ChannelView::mouseReleaseEvent(QMouseEvent *event)
|
||||
}
|
||||
}
|
||||
|
||||
bool ChannelView::tryGetMessageAt(QPoint p, std::shared_ptr<messages::MessageRef> &_message,
|
||||
bool ChannelView::tryGetMessageAt(QPoint p, std::shared_ptr<messages::MessageLayout> &_message,
|
||||
QPoint &relativePos, int &index)
|
||||
{
|
||||
auto messagesSnapshot = this->getMessagesSnapshot();
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include "channel.hpp"
|
||||
#include "messages/lazyloadedimage.hpp"
|
||||
#include "messages/image.hpp"
|
||||
#include "messages/layouts/messagelayout.hpp"
|
||||
#include "messages/limitedqueuesnapshot.hpp"
|
||||
#include "messages/messageref.hpp"
|
||||
#include "messages/messageelement.hpp"
|
||||
#include "messages/selection.hpp"
|
||||
#include "messages/word.hpp"
|
||||
#include "widgets/accountpopup.hpp"
|
||||
#include "widgets/basewidget.hpp"
|
||||
#include "widgets/helper/rippleeffectlabel.hpp"
|
||||
@@ -31,7 +31,6 @@ public:
|
||||
explicit ChannelView(BaseWidget *parent = 0);
|
||||
~ChannelView();
|
||||
|
||||
void updateGifEmotes();
|
||||
void queueUpdate();
|
||||
Scrollbar &getScrollBar();
|
||||
QString getSelectedText();
|
||||
@@ -41,8 +40,8 @@ public:
|
||||
bool getEnableScrollingToBottom() const;
|
||||
void pause(int msecTimeout);
|
||||
|
||||
void setChannel(std::shared_ptr<Channel> channel);
|
||||
messages::LimitedQueueSnapshot<messages::SharedMessageRef> getMessagesSnapshot();
|
||||
void setChannel(SharedChannel channel);
|
||||
messages::LimitedQueueSnapshot<messages::MessageLayoutPtr> getMessagesSnapshot();
|
||||
void layoutMessages();
|
||||
|
||||
void clearMessages();
|
||||
@@ -64,35 +63,25 @@ protected:
|
||||
virtual void mousePressEvent(QMouseEvent *event) override;
|
||||
virtual void mouseReleaseEvent(QMouseEvent *event) override;
|
||||
|
||||
bool tryGetMessageAt(QPoint p, std::shared_ptr<messages::MessageRef> &message,
|
||||
bool tryGetMessageAt(QPoint p, std::shared_ptr<messages::MessageLayout> &message,
|
||||
QPoint &relativePos, int &index);
|
||||
|
||||
private:
|
||||
struct GifEmoteData {
|
||||
messages::LazyLoadedImage *image;
|
||||
QRect rect;
|
||||
};
|
||||
|
||||
QTimer updateTimer;
|
||||
bool updateQueued = false;
|
||||
bool messageWasAdded = false;
|
||||
bool paused = false;
|
||||
QTimer pauseTimeout;
|
||||
|
||||
messages::LimitedQueueSnapshot<messages::SharedMessageRef> snapshot;
|
||||
messages::LimitedQueueSnapshot<messages::MessageLayoutPtr> snapshot;
|
||||
|
||||
void detachChannel();
|
||||
void actuallyLayoutMessages();
|
||||
|
||||
void drawMessages(QPainter &painter, bool overlays);
|
||||
void updateMessageBuffer(messages::MessageRef *messageRef, QPixmap *buffer, int messageIndex);
|
||||
void drawMessageSelection(QPainter &painter, messages::MessageRef *messageRef, int messageIndex,
|
||||
int bufferHeight);
|
||||
void drawMessages(QPainter &painter);
|
||||
void setSelection(const messages::SelectionItem &start, const messages::SelectionItem &end);
|
||||
|
||||
std::shared_ptr<Channel> channel;
|
||||
|
||||
std::vector<GifEmoteData> gifEmotes;
|
||||
SharedChannel channel;
|
||||
|
||||
Scrollbar scrollBar;
|
||||
RippleEffectLabel *goToBottom;
|
||||
@@ -112,7 +101,7 @@ private:
|
||||
messages::Selection selection;
|
||||
bool selecting = false;
|
||||
|
||||
messages::LimitedQueue<messages::SharedMessageRef> messages;
|
||||
messages::LimitedQueue<messages::MessageLayoutPtr> messages;
|
||||
|
||||
boost::signals2::connection messageAppendedConnection;
|
||||
boost::signals2::connection messageAddedAtStartConnection;
|
||||
@@ -123,7 +112,7 @@ private:
|
||||
|
||||
std::vector<pajlada::Signals::ScopedConnection> managedConnections;
|
||||
|
||||
std::unordered_set<std::shared_ptr<messages::MessageRef>> messagesOnScreen;
|
||||
std::unordered_set<std::shared_ptr<messages::MessageLayout>> messagesOnScreen;
|
||||
|
||||
private slots:
|
||||
void wordTypeMaskChanged()
|
||||
|
||||
@@ -59,7 +59,7 @@ void SearchPopup::initLayout()
|
||||
}
|
||||
}
|
||||
|
||||
void SearchPopup::setChannel(std::shared_ptr<Channel> channel)
|
||||
void SearchPopup::setChannel(SharedChannel channel)
|
||||
{
|
||||
this->snapshot = channel->getMessageSnapshot();
|
||||
this->performSearch();
|
||||
@@ -71,13 +71,13 @@ void SearchPopup::performSearch()
|
||||
{
|
||||
QString text = searchInput->text();
|
||||
|
||||
std::shared_ptr<Channel> channel(new Channel("search"));
|
||||
SharedChannel channel(new Channel("search"));
|
||||
|
||||
for (size_t i = 0; i < this->snapshot.getLength(); i++) {
|
||||
messages::SharedMessage message = this->snapshot[i];
|
||||
messages::MessagePtr message = this->snapshot[i];
|
||||
|
||||
if (text.isEmpty() ||
|
||||
message->getContent().indexOf(this->searchInput->text(), 0, Qt::CaseInsensitive) !=
|
||||
message->getSearchText().indexOf(this->searchInput->text(), 0, Qt::CaseInsensitive) !=
|
||||
-1) {
|
||||
channel->addMessage(message);
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ public:
|
||||
void setChannel(std::shared_ptr<Channel> channel);
|
||||
|
||||
private:
|
||||
messages::LimitedQueueSnapshot<messages::SharedMessage> snapshot;
|
||||
messages::LimitedQueueSnapshot<messages::MessagePtr> snapshot;
|
||||
QLineEdit *searchInput;
|
||||
ChannelView *channelView;
|
||||
|
||||
|
||||
@@ -48,9 +48,8 @@ SplitInput::SplitInput(Split *_chatWidget)
|
||||
this->textLengthLabel.setAlignment(Qt::AlignRight);
|
||||
|
||||
this->emotesLabel.getLabel().setTextFormat(Qt::RichText);
|
||||
this->emotesLabel.getLabel().setText(
|
||||
"<img src=':/images/emote.svg' width='12' height='12' "
|
||||
"/>");
|
||||
this->emotesLabel.getLabel().setText("<img src=':/images/emote.svg' width='12' height='12' "
|
||||
"/>");
|
||||
|
||||
connect(&this->emotesLabel, &RippleEffectLabel::clicked, [this] {
|
||||
if (this->emotePopup == nullptr) {
|
||||
@@ -86,16 +85,17 @@ SplitInput::SplitInput(Split *_chatWidget)
|
||||
sendMessage = sendMessage.replace('\n', ' ');
|
||||
|
||||
c->sendMessage(sendMessage);
|
||||
prevMsg.append(message);
|
||||
this->prevMsg.append(message);
|
||||
|
||||
event->accept();
|
||||
if (!(event->modifiers() == Qt::ControlModifier)) {
|
||||
textInput.setText(QString());
|
||||
prevIndex = 0;
|
||||
} else if (textInput.toPlainText() == prevMsg.at(prevMsg.size() - 1)) {
|
||||
prevMsg.removeLast();
|
||||
this->textInput.setText(QString());
|
||||
this->prevIndex = 0;
|
||||
} else if (this->textInput.toPlainText() ==
|
||||
this->prevMsg.at(this->prevMsg.size() - 1)) {
|
||||
this->prevMsg.removeLast();
|
||||
}
|
||||
prevIndex = prevMsg.size();
|
||||
this->prevIndex = this->prevMsg.size();
|
||||
} else if (event->key() == Qt::Key_Up) {
|
||||
if (event->modifiers() == Qt::AltModifier) {
|
||||
SplitContainer *page =
|
||||
@@ -108,9 +108,9 @@ SplitInput::SplitInput(Split *_chatWidget)
|
||||
|
||||
page->requestFocus(reqX, reqY);
|
||||
} else {
|
||||
if (prevMsg.size() && prevIndex) {
|
||||
prevIndex--;
|
||||
textInput.setText(prevMsg.at(prevIndex));
|
||||
if (this->prevMsg.size() && this->prevIndex) {
|
||||
this->prevIndex--;
|
||||
this->textInput.setText(this->prevMsg.at(this->prevIndex));
|
||||
}
|
||||
}
|
||||
} else if (event->key() == Qt::Key_Down) {
|
||||
@@ -125,12 +125,13 @@ SplitInput::SplitInput(Split *_chatWidget)
|
||||
|
||||
page->requestFocus(reqX, reqY);
|
||||
} else {
|
||||
if (prevIndex != (prevMsg.size() - 1) && prevIndex != prevMsg.size()) {
|
||||
prevIndex++;
|
||||
textInput.setText(prevMsg.at(prevIndex));
|
||||
if (this->prevIndex != (this->prevMsg.size() - 1) &&
|
||||
this->prevIndex != this->prevMsg.size()) {
|
||||
this->prevIndex++;
|
||||
this->textInput.setText(this->prevMsg.at(this->prevIndex));
|
||||
} else {
|
||||
prevIndex = prevMsg.size();
|
||||
textInput.setText(QString());
|
||||
this->prevIndex = this->prevMsg.size();
|
||||
this->textInput.setText(QString());
|
||||
}
|
||||
}
|
||||
} else if (event->key() == Qt::Key_Left) {
|
||||
|
||||
@@ -48,7 +48,7 @@ private:
|
||||
QLabel textLengthLabel;
|
||||
RippleEffectLabel emotesLabel;
|
||||
QStringList prevMsg;
|
||||
unsigned int prevIndex = 0;
|
||||
int prevIndex = 0;
|
||||
virtual void refreshTheme() override;
|
||||
|
||||
private slots:
|
||||
|
||||
@@ -126,9 +126,9 @@ void Notebook::select(SplitContainer *page)
|
||||
this->performLayout();
|
||||
}
|
||||
|
||||
void Notebook::selectIndex(unsigned index)
|
||||
void Notebook::selectIndex(int index)
|
||||
{
|
||||
if (index >= this->pages.size()) {
|
||||
if (index < 0 || index >= this->pages.size()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ public:
|
||||
void removePage(SplitContainer *page);
|
||||
void removeCurrentPage();
|
||||
void select(SplitContainer *page);
|
||||
void selectIndex(unsigned index);
|
||||
void selectIndex(int index);
|
||||
|
||||
SplitContainer *getSelectedPage() const
|
||||
{
|
||||
|
||||
@@ -297,7 +297,7 @@ QVBoxLayout *SettingsDialog::createAppearanceTab()
|
||||
|
||||
auto v = new QVBoxLayout();
|
||||
v->addWidget(createCheckbox("Show timestamp", settings.showTimestamps));
|
||||
v->addWidget(createCheckbox("Show seconds in timestamp", settings.showTimestampSeconds));
|
||||
// fourtf: add timestamp format
|
||||
v->addWidget(createCheckbox("Show badges", settings.showBadges));
|
||||
v->addWidget(createCheckbox("Allow sending duplicate messages (add a space at the end)",
|
||||
settings.allowDuplicateMessages));
|
||||
|
||||
@@ -121,17 +121,17 @@ const std::string &Split::getUUID() const
|
||||
return this->uuid;
|
||||
}
|
||||
|
||||
std::shared_ptr<Channel> Split::getChannel() const
|
||||
SharedChannel Split::getChannel() const
|
||||
{
|
||||
return this->channel;
|
||||
}
|
||||
|
||||
std::shared_ptr<Channel> &Split::getChannelRef()
|
||||
SharedChannel &Split::getChannelRef()
|
||||
{
|
||||
return this->channel;
|
||||
}
|
||||
|
||||
void Split::setChannel(std::shared_ptr<Channel> _newChannel)
|
||||
void Split::setChannel(SharedChannel _newChannel)
|
||||
{
|
||||
this->view.setChannel(_newChannel);
|
||||
|
||||
@@ -212,7 +212,8 @@ void Split::layoutMessages()
|
||||
|
||||
void Split::updateGifEmotes()
|
||||
{
|
||||
this->view.updateGifEmotes();
|
||||
qDebug() << "this shouldn't even exist";
|
||||
this->view.queueUpdate();
|
||||
}
|
||||
|
||||
void Split::giveFocus(Qt::FocusReason reason)
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include "channel.hpp"
|
||||
#include "messages/layouts/messagelayout.hpp"
|
||||
#include "messages/layouts/messagelayoutelement.hpp"
|
||||
#include "messages/limitedqueuesnapshot.hpp"
|
||||
#include "messages/messageref.hpp"
|
||||
#include "messages/word.hpp"
|
||||
#include "messages/wordpart.hpp"
|
||||
#include "messages/messageelement.hpp"
|
||||
#include "widgets/basewidget.hpp"
|
||||
#include "widgets/helper/channelview.hpp"
|
||||
#include "widgets/helper/rippleeffectlabel.hpp"
|
||||
@@ -55,8 +55,8 @@ public:
|
||||
}
|
||||
|
||||
const std::string &getUUID() const;
|
||||
std::shared_ptr<Channel> getChannel() const;
|
||||
std::shared_ptr<Channel> &getChannelRef();
|
||||
SharedChannel getChannel() const;
|
||||
SharedChannel &getChannelRef();
|
||||
void setFlexSizeX(double x);
|
||||
double getFlexSizeX();
|
||||
void setFlexSizeY(double y);
|
||||
@@ -73,7 +73,7 @@ protected:
|
||||
|
||||
private:
|
||||
SplitContainer &parentPage;
|
||||
std::shared_ptr<Channel> channel;
|
||||
SharedChannel channel;
|
||||
|
||||
QVBoxLayout vbox;
|
||||
SplitHeader header;
|
||||
@@ -84,7 +84,7 @@ private:
|
||||
|
||||
boost::signals2::connection channelIDChangedConnection;
|
||||
|
||||
void setChannel(std::shared_ptr<Channel> newChannel);
|
||||
void setChannel(SharedChannel newChannel);
|
||||
void doOpenAccountPopupWidget(AccountPopupWidget *widget, QString user);
|
||||
void channelNameUpdated(const std::string &newChannelName);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user