This commit is contained in:
fourtf 2018-08-16 00:16:33 +02:00
parent 5068c9a64e
commit 8bcc9c487b
7 changed files with 42 additions and 26 deletions

View file

@ -41,4 +41,9 @@ std::weak_ptr<T> weakOf(T *element)
struct Message; struct Message;
using MessagePtr = std::shared_ptr<const Message>; using MessagePtr = std::shared_ptr<const Message>;
enum class CopyMode {
Everything,
OnlyTextAndEmotes,
};
} // namespace chatterino } // namespace chatterino

View file

@ -284,9 +284,10 @@ int MessageLayout::getSelectionIndex(QPoint position)
return this->container_->getSelectionIndex(position); return this->container_->getSelectionIndex(position);
} }
void MessageLayout::addSelectionText(QString &str, int from, int to) void MessageLayout::addSelectionText(QString &str, int from, int to,
CopyMode copymode)
{ {
this->container_->addSelectionText(str, from, to); this->container_->addSelectionText(str, from, to, copymode);
} }
} // namespace chatterino } // namespace chatterino

View file

@ -1,5 +1,6 @@
#pragma once #pragma once
#include "common/Common.hpp"
#include "common/FlagsEnum.hpp" #include "common/FlagsEnum.hpp"
#include <QPixmap> #include <QPixmap>
@ -54,7 +55,8 @@ public:
const MessageLayoutElement *getElementAt(QPoint point); const MessageLayoutElement *getElementAt(QPoint point);
int getLastCharacterIndex() const; int getLastCharacterIndex() const;
int getSelectionIndex(QPoint position); int getSelectionIndex(QPoint position);
void addSelectionText(QString &str, int from = 0, int to = INT_MAX); void addSelectionText(QString &str, int from = 0, int to = INT_MAX,
CopyMode copymode = CopyMode::Everything);
// Misc // Misc
bool isDisabled() const; bool isDisabled() const;

View file

@ -505,33 +505,41 @@ int MessageLayoutContainer::getLastCharacterIndex() const
return this->lines_.back().endCharIndex; return this->lines_.back().endCharIndex;
} }
void MessageLayoutContainer::addSelectionText(QString &str, int from, int to) void MessageLayoutContainer::addSelectionText(QString &str, int from, int to,
CopyMode copymode)
{ {
int index = 0; int index = 0;
bool first = true; bool first = true;
for (std::unique_ptr<MessageLayoutElement> &ele : this->elements_) { for (auto &element : this->elements_) {
int c = ele->getSelectionIndexCount(); if (copymode == CopyMode::OnlyTextAndEmotes) {
if (element->getCreator().getFlags().hasAny(
{MessageElementFlag::Timestamp,
MessageElementFlag::Username, MessageElementFlag::Badges}))
continue;
}
auto indexCount = element->getSelectionIndexCount();
if (first) { if (first) {
if (index + c > from) { if (index + indexCount > from) {
ele->addCopyTextToString(str, from - index, to - index); element->addCopyTextToString(str, from - index, to - index);
first = false; first = false;
if (index + c > to) { if (index + indexCount > to) {
break; break;
} }
} }
} else { } else {
if (index + c > to) { if (index + indexCount > to) {
ele->addCopyTextToString(str, 0, to - index); element->addCopyTextToString(str, 0, to - index);
break; break;
} else { } else {
ele->addCopyTextToString(str); element->addCopyTextToString(str);
} }
} }
index += c; index += indexCount;
} }
} }

View file

@ -5,6 +5,7 @@
#include <memory> #include <memory>
#include <vector> #include <vector>
#include "common/Common.hpp"
#include "common/FlagsEnum.hpp" #include "common/FlagsEnum.hpp"
#include "messages/Selection.hpp" #include "messages/Selection.hpp"
#include "messages/layouts/MessageLayoutElement.hpp" #include "messages/layouts/MessageLayoutElement.hpp"
@ -74,7 +75,7 @@ struct MessageLayoutContainer {
// selection // selection
int getSelectionIndex(QPoint point); int getSelectionIndex(QPoint point);
int getLastCharacterIndex() const; int getLastCharacterIndex() const;
void addSelectionText(QString &str, int from, int to); void addSelectionText(QString &str, int from, int to, CopyMode copymode);
bool isCollapsed(); bool isCollapsed();

View file

@ -83,8 +83,6 @@ bool TwitchMessageBuilder::isIgnored() const
MessagePtr TwitchMessageBuilder::build() MessagePtr TwitchMessageBuilder::build()
{ {
auto app = getApp();
// PARSING // PARSING
this->parseUsername(); this->parseUsername();
@ -437,7 +435,7 @@ void TwitchMessageBuilder::appendUsername()
// IrcManager::getInstance().getUser().getUserName(); // IrcManager::getInstance().getUser().getUserName();
} else if (this->args.isReceivedWhisper) { } else if (this->args.isReceivedWhisper) {
// Sender username // Sender username
this->emplace<TextElement>(usernameText, MessageElementFlag::Text, this->emplace<TextElement>(usernameText, MessageElementFlag::Username,
this->usernameColor_, this->usernameColor_,
FontStyle::ChatMediumBold) FontStyle::ChatMediumBold)
->setLink({Link::UserInfo, this->userName}); ->setLink({Link::UserInfo, this->userName});
@ -445,7 +443,7 @@ void TwitchMessageBuilder::appendUsername()
auto currentUser = app->accounts->twitch.getCurrent(); auto currentUser = app->accounts->twitch.getCurrent();
// Separator // Separator
this->emplace<TextElement>("->", MessageElementFlag::Text, this->emplace<TextElement>("->", MessageElementFlag::Username,
app->themes->messages.textColors.system, app->themes->messages.textColors.system,
FontStyle::ChatMedium); FontStyle::ChatMedium);
@ -456,14 +454,14 @@ void TwitchMessageBuilder::appendUsername()
// Your own username // Your own username
this->emplace<TextElement>(currentUser->getUserName() + ":", this->emplace<TextElement>(currentUser->getUserName() + ":",
MessageElementFlag::Text, selfColor, MessageElementFlag::Username, selfColor,
FontStyle::ChatMediumBold); FontStyle::ChatMediumBold);
} else { } else {
if (!this->action_) { if (!this->action_) {
usernameText += ":"; usernameText += ":";
} }
this->emplace<TextElement>(usernameText, MessageElementFlag::Text, this->emplace<TextElement>(usernameText, MessageElementFlag::Username,
this->usernameColor_, this->usernameColor_,
FontStyle::ChatMediumBold) FontStyle::ChatMediumBold)
->setLink({Link::UserInfo, this->userName}); ->setLink({Link::UserInfo, this->userName});

View file

@ -1088,17 +1088,18 @@ void ChannelView::addContextMenuItems(
menu->addAction("Copy message", [layout] { menu->addAction("Copy message", [layout] {
QString copyString; QString copyString;
layout->addSelectionText(copyString); layout->addSelectionText(copyString, 0, INT_MAX,
CopyMode::OnlyTextAndEmotes);
QGuiApplication::clipboard()->setText(copyString); QGuiApplication::clipboard()->setText(copyString);
}); });
// menu->addAction("Quote message", [layout] { menu->addAction("Copy full message", [layout] {
// QString copyString; QString copyString;
// layout->addSelectionText(copyString); layout->addSelectionText(copyString);
// // insert into input QGuiApplication::clipboard()->setText(copyString);
// }); });
menu->popup(QCursor::pos()); menu->popup(QCursor::pos());
menu->raise(); menu->raise();