changed to 80 max column
This commit is contained in:
@@ -85,7 +85,8 @@ std::vector<Frame> readFrames(QImageReader &reader, const Url &url)
|
||||
std::vector<Frame> frames;
|
||||
|
||||
if (reader.imageCount() <= 0) {
|
||||
Log("Error while reading image {}: '{}'", url.string, reader.errorString());
|
||||
Log("Error while reading image {}: '{}'", url.string,
|
||||
reader.errorString());
|
||||
return frames;
|
||||
}
|
||||
|
||||
@@ -100,7 +101,8 @@ std::vector<Frame> readFrames(QImageReader &reader, const Url &url)
|
||||
}
|
||||
|
||||
if (frames.size() != 0) {
|
||||
Log("Error while reading image {}: '{}'", url.string, reader.errorString());
|
||||
Log("Error while reading image {}: '{}'", url.string,
|
||||
reader.errorString());
|
||||
}
|
||||
|
||||
return frames;
|
||||
|
||||
@@ -47,7 +47,8 @@ class Image : public std::enable_shared_from_this<Image>, boost::noncopyable
|
||||
{
|
||||
public:
|
||||
static ImagePtr fromUrl(const Url &url, qreal scale = 1);
|
||||
static ImagePtr fromOwningPixmap(std::unique_ptr<QPixmap> pixmap, qreal scale = 1);
|
||||
static ImagePtr fromOwningPixmap(std::unique_ptr<QPixmap> pixmap,
|
||||
qreal scale = 1);
|
||||
static ImagePtr fromNonOwningPixmap(QPixmap *pixmap, qreal scale = 1);
|
||||
static ImagePtr getEmpty();
|
||||
|
||||
|
||||
@@ -13,7 +13,8 @@ ImageSet::ImageSet()
|
||||
{
|
||||
}
|
||||
|
||||
ImageSet::ImageSet(const ImagePtr &image1, const ImagePtr &image2, const ImagePtr &image3)
|
||||
ImageSet::ImageSet(const ImagePtr &image1, const ImagePtr &image2,
|
||||
const ImagePtr &image3)
|
||||
: imageX1_(image1)
|
||||
, imageX2_(image2)
|
||||
, imageX3_(image3)
|
||||
|
||||
@@ -16,7 +16,8 @@ namespace chatterino {
|
||||
//
|
||||
// Explanation:
|
||||
// - messages can be appended until 'limit' is reached
|
||||
// - when the limit is reached for every message added one will be removed at the start
|
||||
// - when the limit is reached for every message added one will be removed at
|
||||
// the start
|
||||
// - messages can only be added to the start when there is space for them,
|
||||
// trying to add messages to the start when it's full will not add them
|
||||
// - you are able to get a "Snapshot" which captures the state of this object
|
||||
@@ -41,7 +42,8 @@ public:
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(this->mutex_);
|
||||
|
||||
this->chunks_ = std::make_shared<std::vector<std::shared_ptr<std::vector<T>>>>();
|
||||
this->chunks_ =
|
||||
std::make_shared<std::vector<std::shared_ptr<std::vector<T>>>>();
|
||||
Chunk chunk = std::make_shared<std::vector<T>>();
|
||||
chunk->resize(this->chunkSize_);
|
||||
this->chunks_->push_back(chunk);
|
||||
@@ -60,8 +62,8 @@ public:
|
||||
// still space in the last chunk
|
||||
if (lastChunk->size() <= this->lastChunkEnd_) {
|
||||
// create new chunk vector
|
||||
ChunkVector newVector =
|
||||
std::make_shared<std::vector<std::shared_ptr<std::vector<T>>>>();
|
||||
ChunkVector newVector = std::make_shared<
|
||||
std::vector<std::shared_ptr<std::vector<T>>>>();
|
||||
|
||||
// copy chunks
|
||||
for (Chunk &chunk : *this->chunks_) {
|
||||
@@ -93,8 +95,8 @@ public:
|
||||
std::lock_guard<std::mutex> lock(this->mutex_);
|
||||
|
||||
// create new vector to clone chunks into
|
||||
ChunkVector newChunks =
|
||||
std::make_shared<std::vector<std::shared_ptr<std::vector<T>>>>();
|
||||
ChunkVector newChunks = std::make_shared<
|
||||
std::vector<std::shared_ptr<std::vector<T>>>>();
|
||||
|
||||
newChunks->resize(this->chunks_->size());
|
||||
|
||||
@@ -142,7 +144,8 @@ public:
|
||||
Chunk &chunk = this->chunks_->at(i);
|
||||
|
||||
size_t start = i == 0 ? this->firstChunkOffset_ : 0;
|
||||
size_t end = i == chunk->size() - 1 ? this->lastChunkEnd_ : chunk->size();
|
||||
size_t end =
|
||||
i == chunk->size() - 1 ? this->lastChunkEnd_ : chunk->size();
|
||||
|
||||
for (size_t j = start; j < end; j++) {
|
||||
if (chunk->at(j) == item) {
|
||||
@@ -176,7 +179,8 @@ public:
|
||||
Chunk &chunk = this->chunks_->at(i);
|
||||
|
||||
size_t start = i == 0 ? this->firstChunkOffset_ : 0;
|
||||
size_t end = i == chunk->size() - 1 ? this->lastChunkEnd_ : chunk->size();
|
||||
size_t end =
|
||||
i == chunk->size() - 1 ? this->lastChunkEnd_ : chunk->size();
|
||||
|
||||
for (size_t j = start; j < end; j++) {
|
||||
if (x == index) {
|
||||
@@ -204,8 +208,9 @@ public:
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(this->mutex_);
|
||||
|
||||
return LimitedQueueSnapshot<T>(this->chunks_, this->limit_ - this->space(),
|
||||
this->firstChunkOffset_, this->lastChunkEnd_);
|
||||
return LimitedQueueSnapshot<T>(
|
||||
this->chunks_, this->limit_ - this->space(),
|
||||
this->firstChunkOffset_, this->lastChunkEnd_);
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -238,8 +243,8 @@ private:
|
||||
// need to delete the first chunk
|
||||
if (this->firstChunkOffset_ == this->chunks_->front()->size() - 1) {
|
||||
// copy the chunk vector
|
||||
ChunkVector newVector =
|
||||
std::make_shared<std::vector<std::shared_ptr<std::vector<T>>>>();
|
||||
ChunkVector newVector = std::make_shared<
|
||||
std::vector<std::shared_ptr<std::vector<T>>>>();
|
||||
|
||||
// delete first chunk
|
||||
bool first = true;
|
||||
|
||||
@@ -12,8 +12,9 @@ class LimitedQueueSnapshot
|
||||
public:
|
||||
LimitedQueueSnapshot() = default;
|
||||
|
||||
LimitedQueueSnapshot(std::shared_ptr<std::vector<std::shared_ptr<std::vector<T>>>> chunks,
|
||||
size_t length, size_t firstChunkOffset, size_t lastChunkEnd)
|
||||
LimitedQueueSnapshot(
|
||||
std::shared_ptr<std::vector<std::shared_ptr<std::vector<T>>>> chunks,
|
||||
size_t length, size_t firstChunkOffset, size_t lastChunkEnd)
|
||||
: chunks_(chunks)
|
||||
, length_(length)
|
||||
, firstChunkOffset_(firstChunkOffset)
|
||||
|
||||
@@ -33,7 +33,8 @@ MessagePtr Message::createSystemMessage(const QString &text)
|
||||
MessagePtr message(new Message);
|
||||
|
||||
message->addElement(new TimestampElement(QTime::currentTime()));
|
||||
message->addElement(new TextElement(text, MessageElement::Text, MessageColor::System));
|
||||
message->addElement(
|
||||
new TextElement(text, MessageElement::Text, MessageColor::System));
|
||||
message->flags |= MessageFlags::System;
|
||||
message->flags |= MessageFlags::DoNotTriggerNotification;
|
||||
message->searchText = text;
|
||||
@@ -46,7 +47,8 @@ MessagePtr Message::createMessage(const QString &text)
|
||||
MessagePtr message(new Message);
|
||||
|
||||
message->addElement(new TimestampElement(QTime::currentTime()));
|
||||
message->addElement(new TextElement(text, MessageElement::Text, MessageColor::Text));
|
||||
message->addElement(
|
||||
new TextElement(text, MessageElement::Text, MessageColor::Text));
|
||||
message->searchText = text;
|
||||
|
||||
return message;
|
||||
@@ -96,8 +98,10 @@ QString makeDuration(int timeoutSeconds)
|
||||
|
||||
} // namespace
|
||||
|
||||
MessagePtr Message::createTimeoutMessage(const QString &username, const QString &durationInSeconds,
|
||||
const QString &reason, bool multipleTimes)
|
||||
MessagePtr Message::createTimeoutMessage(const QString &username,
|
||||
const QString &durationInSeconds,
|
||||
const QString &reason,
|
||||
bool multipleTimes)
|
||||
{
|
||||
QString text;
|
||||
|
||||
@@ -135,7 +139,8 @@ MessagePtr Message::createTimeoutMessage(const QString &username, const QString
|
||||
return message;
|
||||
}
|
||||
|
||||
MessagePtr Message::createTimeoutMessage(const BanAction &action, uint32_t count)
|
||||
MessagePtr Message::createTimeoutMessage(const BanAction &action,
|
||||
uint32_t count)
|
||||
{
|
||||
MessagePtr msg(new Message);
|
||||
|
||||
@@ -178,7 +183,8 @@ MessagePtr Message::createTimeoutMessage(const BanAction &action, uint32_t count
|
||||
}
|
||||
}
|
||||
|
||||
msg->addElement(new TextElement(text, MessageElement::Text, MessageColor::System));
|
||||
msg->addElement(
|
||||
new TextElement(text, MessageElement::Text, MessageColor::System));
|
||||
msg->searchText = text;
|
||||
|
||||
return msg;
|
||||
@@ -206,7 +212,8 @@ MessagePtr Message::createUntimeoutMessage(const UnbanAction &action)
|
||||
.arg(action.target.name);
|
||||
}
|
||||
|
||||
msg->addElement(new TextElement(text, MessageElement::Text, MessageColor::System));
|
||||
msg->addElement(
|
||||
new TextElement(text, MessageElement::Text, MessageColor::System));
|
||||
msg->searchText = text;
|
||||
|
||||
return msg;
|
||||
|
||||
@@ -68,13 +68,14 @@ public:
|
||||
static std::shared_ptr<Message> createSystemMessage(const QString &text);
|
||||
static std::shared_ptr<Message> createMessage(const QString &text);
|
||||
|
||||
static std::shared_ptr<Message> createTimeoutMessage(const QString &username,
|
||||
const QString &durationInSeconds,
|
||||
const QString &reason, bool multipleTimes);
|
||||
static std::shared_ptr<Message> createTimeoutMessage(
|
||||
const QString &username, const QString &durationInSeconds,
|
||||
const QString &reason, bool multipleTimes);
|
||||
|
||||
static std::shared_ptr<Message> createTimeoutMessage(const BanAction &action,
|
||||
uint32_t count = 1);
|
||||
static std::shared_ptr<Message> createUntimeoutMessage(const UnbanAction &action);
|
||||
static std::shared_ptr<Message> createTimeoutMessage(
|
||||
const BanAction &action, uint32_t count = 1);
|
||||
static std::shared_ptr<Message> createUntimeoutMessage(
|
||||
const UnbanAction &action);
|
||||
};
|
||||
|
||||
using MessagePtr = std::shared_ptr<Message>;
|
||||
|
||||
@@ -47,9 +47,12 @@ QString MessageBuilder::matchLink(const QString &string)
|
||||
{
|
||||
LinkParser linkParser(string);
|
||||
|
||||
static QRegularExpression httpRegex("\\bhttps?://", QRegularExpression::CaseInsensitiveOption);
|
||||
static QRegularExpression ftpRegex("\\bftps?://", QRegularExpression::CaseInsensitiveOption);
|
||||
static QRegularExpression spotifyRegex("\\bspotify:", QRegularExpression::CaseInsensitiveOption);
|
||||
static QRegularExpression httpRegex(
|
||||
"\\bhttps?://", QRegularExpression::CaseInsensitiveOption);
|
||||
static QRegularExpression ftpRegex(
|
||||
"\\bftps?://", QRegularExpression::CaseInsensitiveOption);
|
||||
static QRegularExpression spotifyRegex(
|
||||
"\\bspotify:", QRegularExpression::CaseInsensitiveOption);
|
||||
|
||||
if (!linkParser.hasMatch()) {
|
||||
return QString();
|
||||
@@ -57,7 +60,8 @@ QString MessageBuilder::matchLink(const QString &string)
|
||||
|
||||
QString captured = linkParser.getCaptured();
|
||||
|
||||
if (!captured.contains(httpRegex) && !captured.contains(ftpRegex) && !captured.contains(spotifyRegex)) {
|
||||
if (!captured.contains(httpRegex) && !captured.contains(ftpRegex) &&
|
||||
!captured.contains(spotifyRegex)) {
|
||||
captured.insert(0, "http://");
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,8 @@ public:
|
||||
template <typename T, typename... Args>
|
||||
T *emplace(Args &&... args)
|
||||
{
|
||||
static_assert(std::is_base_of<MessageElement, T>::value, "T must extend MessageElement");
|
||||
static_assert(std::is_base_of<MessageElement, T>::value,
|
||||
"T must extend MessageElement");
|
||||
|
||||
T *element = new T(std::forward<Args>(args)...);
|
||||
this->append(element);
|
||||
|
||||
@@ -67,14 +67,15 @@ ImageElement::ImageElement(ImagePtr image, MessageElement::Flags flags)
|
||||
// this->setTooltip(image->getTooltip());
|
||||
}
|
||||
|
||||
void ImageElement::addToContainer(MessageLayoutContainer &container, MessageElement::Flags flags)
|
||||
void ImageElement::addToContainer(MessageLayoutContainer &container,
|
||||
MessageElement::Flags flags)
|
||||
{
|
||||
if (flags & this->getFlags()) {
|
||||
auto size = QSize(this->image_->width() * container.getScale(),
|
||||
this->image_->height() * container.getScale());
|
||||
|
||||
container.addElement(
|
||||
(new ImageLayoutElement(*this, this->image_, size))->setLink(this->getLink()));
|
||||
container.addElement((new ImageLayoutElement(*this, this->image_, size))
|
||||
->setLink(this->getLink()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,7 +84,8 @@ EmoteElement::EmoteElement(const EmotePtr &emote, MessageElement::Flags flags)
|
||||
: MessageElement(flags)
|
||||
, emote_(emote)
|
||||
{
|
||||
this->textElement_.reset(new TextElement(emote->getCopyString(), MessageElement::Misc));
|
||||
this->textElement_.reset(
|
||||
new TextElement(emote->getCopyString(), MessageElement::Misc));
|
||||
|
||||
this->setTooltip(emote->tooltip.string);
|
||||
}
|
||||
@@ -93,7 +95,8 @@ EmotePtr EmoteElement::getEmote() const
|
||||
return this->emote_;
|
||||
}
|
||||
|
||||
void EmoteElement::addToContainer(MessageLayoutContainer &container, MessageElement::Flags flags)
|
||||
void EmoteElement::addToContainer(MessageLayoutContainer &container,
|
||||
MessageElement::Flags flags)
|
||||
{
|
||||
if (flags & this->getFlags()) {
|
||||
if (flags & MessageElement::EmoteImages) {
|
||||
@@ -103,11 +106,12 @@ void EmoteElement::addToContainer(MessageLayoutContainer &container, MessageElem
|
||||
auto size = QSize(int(container.getScale() * image->width()),
|
||||
int(container.getScale() * image->height()));
|
||||
|
||||
container.addElement(
|
||||
(new ImageLayoutElement(*this, image, size))->setLink(this->getLink()));
|
||||
container.addElement((new ImageLayoutElement(*this, image, size))
|
||||
->setLink(this->getLink()));
|
||||
} else {
|
||||
if (this->textElement_) {
|
||||
this->textElement_->addToContainer(container, MessageElement::Misc);
|
||||
this->textElement_->addToContainer(container,
|
||||
MessageElement::Misc);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -126,20 +130,24 @@ TextElement::TextElement(const QString &text, MessageElement::Flags flags,
|
||||
}
|
||||
}
|
||||
|
||||
void TextElement::addToContainer(MessageLayoutContainer &container, MessageElement::Flags flags)
|
||||
void TextElement::addToContainer(MessageLayoutContainer &container,
|
||||
MessageElement::Flags flags)
|
||||
{
|
||||
auto app = getApp();
|
||||
|
||||
if (flags & this->getFlags()) {
|
||||
QFontMetrics metrics = app->fonts->getFontMetrics(this->style_, container.getScale());
|
||||
QFontMetrics metrics =
|
||||
app->fonts->getFontMetrics(this->style_, container.getScale());
|
||||
|
||||
for (Word &word : this->words_) {
|
||||
auto getTextLayoutElement = [&](QString text, int width, bool trailingSpace) {
|
||||
auto getTextLayoutElement = [&](QString text, int width,
|
||||
bool trailingSpace) {
|
||||
QColor color = this->color_.getColor(*app->themes);
|
||||
app->themes->normalizeColor(color);
|
||||
|
||||
auto e = (new TextLayoutElement(*this, text, QSize(width, metrics.height()), color,
|
||||
this->style_, container.getScale()))
|
||||
auto e = (new TextLayoutElement(
|
||||
*this, text, QSize(width, metrics.height()),
|
||||
color, this->style_, container.getScale()))
|
||||
->setLink(this->getLink());
|
||||
e->setTrailingSpace(trailingSpace);
|
||||
return e;
|
||||
@@ -152,8 +160,8 @@ void TextElement::addToContainer(MessageLayoutContainer &container, MessageEleme
|
||||
|
||||
// see if the text fits in the current line
|
||||
if (container.fitsInLine(word.width)) {
|
||||
container.addElementNoLineBreak(
|
||||
getTextLayoutElement(word.text, word.width, this->hasTrailingSpace()));
|
||||
container.addElementNoLineBreak(getTextLayoutElement(
|
||||
word.text, word.width, this->hasTrailingSpace()));
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -162,8 +170,8 @@ void TextElement::addToContainer(MessageLayoutContainer &container, MessageEleme
|
||||
container.breakLine();
|
||||
|
||||
if (container.fitsInLine(word.width)) {
|
||||
container.addElementNoLineBreak(
|
||||
getTextLayoutElement(word.text, word.width, this->hasTrailingSpace()));
|
||||
container.addElementNoLineBreak(getTextLayoutElement(
|
||||
word.text, word.width, this->hasTrailingSpace()));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -178,8 +186,8 @@ void TextElement::addToContainer(MessageLayoutContainer &container, MessageEleme
|
||||
int charWidth = metrics.width(text[i]);
|
||||
|
||||
if (!container.fitsInLine(width + charWidth)) {
|
||||
container.addElementNoLineBreak(
|
||||
getTextLayoutElement(text.mid(wordStart, i - wordStart), width, false));
|
||||
container.addElementNoLineBreak(getTextLayoutElement(
|
||||
text.mid(wordStart, i - wordStart), width, false));
|
||||
container.breakLine();
|
||||
|
||||
wordStart = i;
|
||||
@@ -194,8 +202,8 @@ void TextElement::addToContainer(MessageLayoutContainer &container, MessageEleme
|
||||
width += charWidth;
|
||||
}
|
||||
|
||||
container.addElement(
|
||||
getTextLayoutElement(text.mid(wordStart), width, this->hasTrailingSpace()));
|
||||
container.addElement(getTextLayoutElement(
|
||||
text.mid(wordStart), width, this->hasTrailingSpace()));
|
||||
container.breakLine();
|
||||
}
|
||||
}
|
||||
@@ -230,7 +238,8 @@ TextElement *TimestampElement::formatTime(const QTime &time)
|
||||
|
||||
QString format = locale.toString(time, getApp()->settings->timestampFormat);
|
||||
|
||||
return new TextElement(format, Flags::Timestamp, MessageColor::System, FontStyle::ChatMedium);
|
||||
return new TextElement(format, Flags::Timestamp, MessageColor::System,
|
||||
FontStyle::ChatMedium);
|
||||
}
|
||||
|
||||
// TWITCH MODERATION
|
||||
@@ -243,15 +252,19 @@ void TwitchModerationElement::addToContainer(MessageLayoutContainer &container,
|
||||
MessageElement::Flags flags)
|
||||
{
|
||||
if (flags & MessageElement::ModeratorTools) {
|
||||
QSize size(int(container.getScale() * 16), int(container.getScale() * 16));
|
||||
QSize size(int(container.getScale() * 16),
|
||||
int(container.getScale() * 16));
|
||||
|
||||
for (const auto &action : getApp()->moderationActions->items.getVector()) {
|
||||
for (const auto &action :
|
||||
getApp()->moderationActions->items.getVector()) {
|
||||
if (auto image = action.getImage()) {
|
||||
container.addElement((new ImageLayoutElement(*this, image.get(), size))
|
||||
->setLink(Link(Link::UserAction, action.getAction())));
|
||||
container.addElement(
|
||||
(new ImageLayoutElement(*this, image.get(), size))
|
||||
->setLink(Link(Link::UserAction, action.getAction())));
|
||||
} else {
|
||||
container.addElement(
|
||||
(new TextIconLayoutElement(*this, action.getLine1(), action.getLine2(),
|
||||
(new TextIconLayoutElement(*this, action.getLine1(),
|
||||
action.getLine2(),
|
||||
container.getScale(), size))
|
||||
->setLink(Link(Link::UserAction, action.getAction())));
|
||||
}
|
||||
|
||||
@@ -72,10 +72,11 @@ public:
|
||||
// - Chatterino top donator badge
|
||||
BadgeChatterino = (1 << 18),
|
||||
|
||||
// Rest of slots: ffz custom badge? bttv custom badge? mywaifu (puke) custom badge?
|
||||
// Rest of slots: ffz custom badge? bttv custom badge? mywaifu (puke)
|
||||
// custom badge?
|
||||
|
||||
Badges = BadgeGlobalAuthority | BadgeChannelAuthority | BadgeSubscription | BadgeVanity |
|
||||
BadgeChatterino,
|
||||
Badges = BadgeGlobalAuthority | BadgeChannelAuthority |
|
||||
BadgeSubscription | BadgeVanity | BadgeChatterino,
|
||||
|
||||
ChannelName = (1 << 19),
|
||||
|
||||
@@ -89,7 +90,8 @@ public:
|
||||
|
||||
AlwaysShow = (1 << 25),
|
||||
|
||||
// used in the ChannelView class to make the collapse buttons visible if needed
|
||||
// used in the ChannelView class to make the collapse buttons visible if
|
||||
// needed
|
||||
Collapsed = (1 << 26),
|
||||
|
||||
// used for dynamic bold usernames
|
||||
@@ -100,8 +102,9 @@ public:
|
||||
LowercaseLink = (1 << 29),
|
||||
OriginalLink = (1 << 30),
|
||||
|
||||
Default = Timestamp | Badges | Username | BitsStatic | FfzEmoteImage | BttvEmoteImage |
|
||||
TwitchEmoteImage | BitsAmount | Text | AlwaysShow,
|
||||
Default = Timestamp | Badges | Username | BitsStatic | FfzEmoteImage |
|
||||
BttvEmoteImage | TwitchEmoteImage | BitsAmount | Text |
|
||||
AlwaysShow,
|
||||
};
|
||||
|
||||
enum UpdateFlags : char {
|
||||
@@ -121,7 +124,8 @@ public:
|
||||
bool hasTrailingSpace() const;
|
||||
Flags getFlags() const;
|
||||
|
||||
virtual void addToContainer(MessageLayoutContainer &container, MessageElement::Flags flags) = 0;
|
||||
virtual void addToContainer(MessageLayoutContainer &container,
|
||||
MessageElement::Flags flags) = 0;
|
||||
|
||||
protected:
|
||||
MessageElement(Flags flags);
|
||||
@@ -139,7 +143,8 @@ class ImageElement : public MessageElement
|
||||
public:
|
||||
ImageElement(ImagePtr image, MessageElement::Flags flags);
|
||||
|
||||
void addToContainer(MessageLayoutContainer &container, MessageElement::Flags flags) override;
|
||||
void addToContainer(MessageLayoutContainer &container,
|
||||
MessageElement::Flags flags) override;
|
||||
|
||||
private:
|
||||
ImagePtr image_;
|
||||
@@ -154,7 +159,8 @@ public:
|
||||
FontStyle style = FontStyle::ChatMedium);
|
||||
~TextElement() override = default;
|
||||
|
||||
void addToContainer(MessageLayoutContainer &container, MessageElement::Flags flags) override;
|
||||
void addToContainer(MessageLayoutContainer &container,
|
||||
MessageElement::Flags flags) override;
|
||||
|
||||
private:
|
||||
MessageColor color_;
|
||||
@@ -175,7 +181,8 @@ class EmoteElement : public MessageElement
|
||||
public:
|
||||
EmoteElement(const EmotePtr &data, MessageElement::Flags flags_);
|
||||
|
||||
void addToContainer(MessageLayoutContainer &container, MessageElement::Flags flags_) override;
|
||||
void addToContainer(MessageLayoutContainer &container,
|
||||
MessageElement::Flags flags_) override;
|
||||
EmotePtr getEmote() const;
|
||||
|
||||
private:
|
||||
@@ -190,7 +197,8 @@ public:
|
||||
TimestampElement(QTime time_ = QTime::currentTime());
|
||||
~TimestampElement() override = default;
|
||||
|
||||
void addToContainer(MessageLayoutContainer &container, MessageElement::Flags flags) override;
|
||||
void addToContainer(MessageLayoutContainer &container,
|
||||
MessageElement::Flags flags) override;
|
||||
|
||||
TextElement *formatTime(const QTime &time);
|
||||
|
||||
@@ -200,14 +208,15 @@ private:
|
||||
QString format_;
|
||||
};
|
||||
|
||||
// adds all the custom moderation buttons, adds a variable amount of items depending on settings
|
||||
// fourtf: implement
|
||||
// adds all the custom moderation buttons, adds a variable amount of items
|
||||
// depending on settings fourtf: implement
|
||||
class TwitchModerationElement : public MessageElement
|
||||
{
|
||||
public:
|
||||
TwitchModerationElement();
|
||||
|
||||
void addToContainer(MessageLayoutContainer &container, MessageElement::Flags flags) override;
|
||||
void addToContainer(MessageLayoutContainer &container,
|
||||
MessageElement::Flags flags) override;
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -26,7 +26,8 @@ struct SelectionItem {
|
||||
if (this->messageIndex < b.messageIndex) {
|
||||
return true;
|
||||
}
|
||||
if (this->messageIndex == b.messageIndex && this->charIndex < b.charIndex) {
|
||||
if (this->messageIndex == b.messageIndex &&
|
||||
this->charIndex < b.charIndex) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -39,7 +40,8 @@ struct SelectionItem {
|
||||
|
||||
bool operator==(const SelectionItem &b) const
|
||||
{
|
||||
return this->messageIndex == b.messageIndex && this->charIndex == b.charIndex;
|
||||
return this->messageIndex == b.messageIndex &&
|
||||
this->charIndex == b.charIndex;
|
||||
}
|
||||
|
||||
bool operator!=(const SelectionItem &b) const
|
||||
@@ -74,7 +76,8 @@ struct Selection {
|
||||
|
||||
bool isSingleMessage() const
|
||||
{
|
||||
return this->selectionMin.messageIndex == this->selectionMax.messageIndex;
|
||||
return this->selectionMin.messageIndex ==
|
||||
this->selectionMax.messageIndex;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -98,12 +98,14 @@ void MessageLayout::actuallyLayout(int width, MessageElement::Flags _flags)
|
||||
if (this->flags & MessageLayout::Expanded ||
|
||||
(_flags & MessageElement::ModeratorTools &&
|
||||
!(this->message_->flags & Message::MessageFlags::Disabled))) {
|
||||
messageFlags = Message::MessageFlags(messageFlags & ~Message::MessageFlags::Collapsed);
|
||||
messageFlags = Message::MessageFlags(messageFlags &
|
||||
~Message::MessageFlags::Collapsed);
|
||||
}
|
||||
|
||||
this->container_.begin(width, this->scale_, messageFlags);
|
||||
|
||||
for (const std::unique_ptr<MessageElement> &element : this->message_->getElements()) {
|
||||
for (const std::unique_ptr<MessageElement> &element :
|
||||
this->message_->getElements()) {
|
||||
element->addToContainer(this->container_, _flags);
|
||||
}
|
||||
|
||||
@@ -123,7 +125,8 @@ void MessageLayout::actuallyLayout(int width, MessageElement::Flags _flags)
|
||||
|
||||
// Painting
|
||||
void MessageLayout::paint(QPainter &painter, int width, int y, int messageIndex,
|
||||
Selection &selection, bool isLastReadMessage, bool isWindowFocused)
|
||||
Selection &selection, bool isLastReadMessage,
|
||||
bool isWindowFocused)
|
||||
{
|
||||
auto app = getApp();
|
||||
QPixmap *pixmap = this->buffer_.get();
|
||||
@@ -132,7 +135,8 @@ void MessageLayout::paint(QPainter &painter, int width, int y, int messageIndex,
|
||||
if (!pixmap) {
|
||||
#ifdef Q_OS_MACOS
|
||||
pixmap = new QPixmap(int(width * painter.device()->devicePixelRatioF()),
|
||||
int(container_.getHeight() * painter.device()->devicePixelRatioF()));
|
||||
int(container_.getHeight() *
|
||||
painter.device()->devicePixelRatioF()));
|
||||
pixmap->setDevicePixelRatio(painter.device()->devicePixelRatioF());
|
||||
#else
|
||||
pixmap = new QPixmap(width, std::max(16, this->container_.getHeight()));
|
||||
@@ -149,14 +153,16 @@ void MessageLayout::paint(QPainter &painter, int width, int y, int messageIndex,
|
||||
|
||||
// draw on buffer
|
||||
painter.drawPixmap(0, y, *pixmap);
|
||||
// painter.drawPixmap(0, y, this->container.width, this->container.getHeight(), *pixmap);
|
||||
// painter.drawPixmap(0, y, this->container.width,
|
||||
// this->container.getHeight(), *pixmap);
|
||||
|
||||
// draw gif emotes
|
||||
this->container_.paintAnimatedElements(painter, y);
|
||||
|
||||
// draw disabled
|
||||
if (this->message_->flags.HasFlag(Message::Disabled)) {
|
||||
painter.fillRect(0, y, pixmap->width(), pixmap->height(), app->themes->messages.disabled);
|
||||
painter.fillRect(0, y, pixmap->width(), pixmap->height(),
|
||||
app->themes->messages.disabled);
|
||||
}
|
||||
|
||||
// draw selection
|
||||
@@ -172,19 +178,23 @@ void MessageLayout::paint(QPainter &painter, int width, int y, int messageIndex,
|
||||
|
||||
// draw last read message line
|
||||
if (isLastReadMessage) {
|
||||
QColor color = isWindowFocused ? app->themes->tabs.selected.backgrounds.regular.color()
|
||||
: app->themes->tabs.selected.backgrounds.unfocused.color();
|
||||
QColor color =
|
||||
isWindowFocused
|
||||
? app->themes->tabs.selected.backgrounds.regular.color()
|
||||
: app->themes->tabs.selected.backgrounds.unfocused.color();
|
||||
|
||||
QBrush brush(color,
|
||||
static_cast<Qt::BrushStyle>(app->settings->lastMessagePattern.getValue()));
|
||||
QBrush brush(color, static_cast<Qt::BrushStyle>(
|
||||
app->settings->lastMessagePattern.getValue()));
|
||||
|
||||
painter.fillRect(0, y + this->container_.getHeight() - 1, pixmap->width(), 1, brush);
|
||||
painter.fillRect(0, y + this->container_.getHeight() - 1,
|
||||
pixmap->width(), 1, brush);
|
||||
}
|
||||
|
||||
this->bufferValid_ = true;
|
||||
}
|
||||
|
||||
void MessageLayout::updateBuffer(QPixmap *buffer, int /*messageIndex*/, Selection & /*selection*/)
|
||||
void MessageLayout::updateBuffer(QPixmap *buffer, int /*messageIndex*/,
|
||||
Selection & /*selection*/)
|
||||
{
|
||||
auto app = getApp();
|
||||
|
||||
@@ -212,8 +222,8 @@ void MessageLayout::updateBuffer(QPixmap *buffer, int /*messageIndex*/, Selectio
|
||||
#ifdef FOURTF
|
||||
// debug
|
||||
painter.setPen(QColor(255, 0, 0));
|
||||
painter.drawRect(buffer->rect().x(), buffer->rect().y(), buffer->rect().width() - 1,
|
||||
buffer->rect().height() - 1);
|
||||
painter.drawRect(buffer->rect().x(), buffer->rect().y(),
|
||||
buffer->rect().width() - 1, buffer->rect().height() - 1);
|
||||
|
||||
QTextOption option;
|
||||
option.setAlignment(Qt::AlignRight | Qt::AlignTop);
|
||||
|
||||
@@ -40,8 +40,9 @@ public:
|
||||
bool layout(int width, float scale_, MessageElement::Flags flags);
|
||||
|
||||
// Painting
|
||||
void paint(QPainter &painter, int width, int y, int messageIndex, Selection &selection,
|
||||
bool isLastReadMessage, bool isWindowFocused);
|
||||
void paint(QPainter &painter, int width, int y, int messageIndex,
|
||||
Selection &selection, bool isLastReadMessage,
|
||||
bool isWindowFocused);
|
||||
void invalidateBuffer();
|
||||
void deleteBuffer();
|
||||
void deleteCache();
|
||||
|
||||
@@ -9,7 +9,8 @@
|
||||
#include <QPainter>
|
||||
|
||||
#define COMPACT_EMOTES_OFFSET 6
|
||||
#define MAX_UNCOLLAPSED_LINES (getApp()->settings->collpseMessagesMinLines.getValue())
|
||||
#define MAX_UNCOLLAPSED_LINES \
|
||||
(getApp()->settings->collpseMessagesMinLines.getValue())
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
@@ -29,13 +30,15 @@ float MessageLayoutContainer::getScale() const
|
||||
}
|
||||
|
||||
// methods
|
||||
void MessageLayoutContainer::begin(int width, float scale, Message::MessageFlags flags)
|
||||
void MessageLayoutContainer::begin(int width, float scale,
|
||||
Message::MessageFlags flags)
|
||||
{
|
||||
this->clear();
|
||||
this->width_ = width;
|
||||
this->scale_ = scale;
|
||||
this->flags_ = flags;
|
||||
auto mediumFontMetrics = getApp()->fonts->getFontMetrics(FontStyle::ChatMedium, scale);
|
||||
auto mediumFontMetrics =
|
||||
getApp()->fonts->getFontMetrics(FontStyle::ChatMedium, scale);
|
||||
this->textLineHeight_ = mediumFontMetrics.height();
|
||||
this->spaceWidth_ = mediumFontMetrics.width(' ');
|
||||
this->dotdotdotWidth_ = mediumFontMetrics.width("...");
|
||||
@@ -66,7 +69,8 @@ void MessageLayoutContainer::addElement(MessageLayoutElement *element)
|
||||
this->_addElement(element);
|
||||
}
|
||||
|
||||
void MessageLayoutContainer::addElementNoLineBreak(MessageLayoutElement *element)
|
||||
void MessageLayoutContainer::addElementNoLineBreak(
|
||||
MessageLayoutElement *element)
|
||||
{
|
||||
this->_addElement(element);
|
||||
}
|
||||
@@ -76,7 +80,8 @@ bool MessageLayoutContainer::canAddElements()
|
||||
return this->canAddMessages_;
|
||||
}
|
||||
|
||||
void MessageLayoutContainer::_addElement(MessageLayoutElement *element, bool forceAdd)
|
||||
void MessageLayoutContainer::_addElement(MessageLayoutElement *element,
|
||||
bool forceAdd)
|
||||
{
|
||||
if (!this->canAddElements() && !forceAdd) {
|
||||
delete element;
|
||||
@@ -91,8 +96,9 @@ void MessageLayoutContainer::_addElement(MessageLayoutElement *element, bool for
|
||||
int newLineHeight = element->getRect().height();
|
||||
|
||||
// compact emote offset
|
||||
bool isCompactEmote = !(this->flags_ & Message::DisableCompactEmotes) &&
|
||||
element->getCreator().getFlags() & MessageElement::EmoteImages;
|
||||
bool isCompactEmote =
|
||||
!(this->flags_ & Message::DisableCompactEmotes) &&
|
||||
element->getCreator().getFlags() & MessageElement::EmoteImages;
|
||||
|
||||
if (isCompactEmote) {
|
||||
newLineHeight -= COMPACT_EMOTES_OFFSET * this->scale_;
|
||||
@@ -102,7 +108,8 @@ void MessageLayoutContainer::_addElement(MessageLayoutElement *element, bool for
|
||||
this->lineHeight_ = std::max(this->lineHeight_, newLineHeight);
|
||||
|
||||
// set move element
|
||||
element->setPosition(QPoint(this->currentX_, this->currentY_ - element->getRect().height()));
|
||||
element->setPosition(
|
||||
QPoint(this->currentX_, this->currentY_ - element->getRect().height()));
|
||||
|
||||
// add element
|
||||
this->elements_.push_back(std::unique_ptr<MessageLayoutElement>(element));
|
||||
@@ -120,35 +127,42 @@ void MessageLayoutContainer::breakLine()
|
||||
int xOffset = 0;
|
||||
|
||||
if (this->flags_ & Message::Centered && this->elements_.size() > 0) {
|
||||
xOffset = (width_ - this->elements_.at(this->elements_.size() - 1)->getRect().right()) / 2;
|
||||
xOffset = (width_ - this->elements_.at(this->elements_.size() - 1)
|
||||
->getRect()
|
||||
.right()) /
|
||||
2;
|
||||
}
|
||||
|
||||
for (size_t i = lineStart_; i < this->elements_.size(); i++) {
|
||||
MessageLayoutElement *element = this->elements_.at(i).get();
|
||||
|
||||
bool isCompactEmote = !(this->flags_ & Message::DisableCompactEmotes) &&
|
||||
element->getCreator().getFlags() & MessageElement::EmoteImages;
|
||||
bool isCompactEmote =
|
||||
!(this->flags_ & Message::DisableCompactEmotes) &&
|
||||
element->getCreator().getFlags() & MessageElement::EmoteImages;
|
||||
|
||||
int yExtra = 0;
|
||||
if (isCompactEmote) {
|
||||
yExtra = (COMPACT_EMOTES_OFFSET / 2) * this->scale_;
|
||||
}
|
||||
|
||||
// if (element->getCreator().getFlags() & MessageElement::Badges) {
|
||||
// if (element->getCreator().getFlags() & MessageElement::Badges)
|
||||
// {
|
||||
if (element->getRect().height() < this->textLineHeight_) {
|
||||
yExtra -= (this->textLineHeight_ - element->getRect().height()) / 2;
|
||||
}
|
||||
|
||||
element->setPosition(QPoint(element->getRect().x() + xOffset + this->margin.left,
|
||||
element->getRect().y() + this->lineHeight_ + yExtra));
|
||||
element->setPosition(
|
||||
QPoint(element->getRect().x() + xOffset + this->margin.left,
|
||||
element->getRect().y() + this->lineHeight_ + yExtra));
|
||||
}
|
||||
|
||||
if (this->lines_.size() != 0) {
|
||||
this->lines_.back().endIndex = this->lineStart_;
|
||||
this->lines_.back().endCharIndex = this->charIndex_;
|
||||
}
|
||||
this->lines_.push_back({(int)lineStart_, 0, this->charIndex_, 0,
|
||||
QRect(-100000, this->currentY_, 200000, lineHeight_)});
|
||||
this->lines_.push_back(
|
||||
{(int)lineStart_, 0, this->charIndex_, 0,
|
||||
QRect(-100000, this->currentY_, 200000, lineHeight_)});
|
||||
|
||||
for (int i = this->lineStart_; i < this->elements_.size(); i++) {
|
||||
this->charIndex_ += this->elements_[i]->getSelectionIndexCount();
|
||||
@@ -178,17 +192,20 @@ bool MessageLayoutContainer::fitsInLine(int _width)
|
||||
{
|
||||
return this->currentX_ + _width <=
|
||||
(this->width_ - this->margin.left - this->margin.right -
|
||||
(this->line_ + 1 == MAX_UNCOLLAPSED_LINES ? this->dotdotdotWidth_ : 0));
|
||||
(this->line_ + 1 == MAX_UNCOLLAPSED_LINES ? this->dotdotdotWidth_
|
||||
: 0));
|
||||
}
|
||||
|
||||
void MessageLayoutContainer::end()
|
||||
{
|
||||
if (!this->canAddElements()) {
|
||||
static TextElement dotdotdot("...", MessageElement::Collapsed, MessageColor::Link);
|
||||
static TextElement dotdotdot("...", MessageElement::Collapsed,
|
||||
MessageColor::Link);
|
||||
static QString dotdotdotText("...");
|
||||
|
||||
auto *element = new TextLayoutElement(
|
||||
dotdotdot, dotdotdotText, QSize(this->dotdotdotWidth_, this->textLineHeight_),
|
||||
dotdotdot, dotdotdotText,
|
||||
QSize(this->dotdotdotWidth_, this->textLineHeight_),
|
||||
QColor("#00D80A"), FontStyle::ChatMediumBold, this->scale_);
|
||||
|
||||
// getApp()->themes->messages.textColors.system
|
||||
@@ -235,7 +252,8 @@ MessageLayoutElement *MessageLayoutContainer::getElementAt(QPoint point)
|
||||
// painting
|
||||
void MessageLayoutContainer::paintElements(QPainter &painter)
|
||||
{
|
||||
for (const std::unique_ptr<MessageLayoutElement> &element : this->elements_) {
|
||||
for (const std::unique_ptr<MessageLayoutElement> &element :
|
||||
this->elements_) {
|
||||
#ifdef FOURTF
|
||||
painter.setPen(QColor(0, 255, 0));
|
||||
painter.drawRect(element->getRect());
|
||||
@@ -245,9 +263,11 @@ void MessageLayoutContainer::paintElements(QPainter &painter)
|
||||
}
|
||||
}
|
||||
|
||||
void MessageLayoutContainer::paintAnimatedElements(QPainter &painter, int yOffset)
|
||||
void MessageLayoutContainer::paintAnimatedElements(QPainter &painter,
|
||||
int yOffset)
|
||||
{
|
||||
for (const std::unique_ptr<MessageLayoutElement> &element : this->elements_) {
|
||||
for (const std::unique_ptr<MessageLayoutElement> &element :
|
||||
this->elements_) {
|
||||
element->paintAnimated(painter, yOffset);
|
||||
}
|
||||
}
|
||||
@@ -273,7 +293,8 @@ void MessageLayoutContainer::paintSelection(QPainter &painter, int messageIndex,
|
||||
rect.setTop(std::max(0, rect.top()) + yOffset);
|
||||
rect.setBottom(std::min(this->height_, rect.bottom()) + yOffset);
|
||||
rect.setLeft(this->elements_[line.startIndex]->getRect().left());
|
||||
rect.setRight(this->elements_[line.endIndex - 1]->getRect().right());
|
||||
rect.setRight(
|
||||
this->elements_[line.endIndex - 1]->getRect().right());
|
||||
|
||||
painter.fillRect(rect, selectionColor);
|
||||
}
|
||||
@@ -302,16 +323,19 @@ void MessageLayoutContainer::paintSelection(QPainter &painter, int messageIndex,
|
||||
int c = this->elements_[i]->getSelectionIndexCount();
|
||||
|
||||
if (index + c > selection.selectionMin.charIndex) {
|
||||
x = this->elements_[i]->getXFromIndex(selection.selectionMin.charIndex - index);
|
||||
x = this->elements_[i]->getXFromIndex(
|
||||
selection.selectionMin.charIndex - index);
|
||||
|
||||
// ends in same line
|
||||
if (selection.selectionMax.messageIndex == messageIndex &&
|
||||
line.endCharIndex > /*=*/selection.selectionMax.charIndex) //
|
||||
line.endCharIndex >
|
||||
/*=*/selection.selectionMax.charIndex) //
|
||||
{
|
||||
returnAfter = true;
|
||||
index = line.startCharIndex;
|
||||
for (int i = line.startIndex; i < line.endIndex; i++) {
|
||||
int c = this->elements_[i]->getSelectionIndexCount();
|
||||
int c =
|
||||
this->elements_[i]->getSelectionIndexCount();
|
||||
|
||||
if (index + c > selection.selectionMax.charIndex) {
|
||||
r = this->elements_[i]->getXFromIndex(
|
||||
@@ -330,9 +354,15 @@ void MessageLayoutContainer::paintSelection(QPainter &painter, int messageIndex,
|
||||
QRect rect = line.rect;
|
||||
|
||||
rect.setTop(std::max(0, rect.top()) + yOffset);
|
||||
rect.setBottom(std::min(this->height_, rect.bottom()) + yOffset);
|
||||
rect.setLeft(this->elements_[line.startIndex]->getRect().left());
|
||||
rect.setRight(this->elements_[line.endIndex - 1]->getRect().right());
|
||||
rect.setBottom(
|
||||
std::min(this->height_, rect.bottom()) +
|
||||
yOffset);
|
||||
rect.setLeft(this->elements_[line.startIndex]
|
||||
->getRect()
|
||||
.left());
|
||||
rect.setRight(this->elements_[line.endIndex - 1]
|
||||
->getRect()
|
||||
.right());
|
||||
|
||||
painter.fillRect(rect, selectionColor);
|
||||
}
|
||||
@@ -378,7 +408,8 @@ void MessageLayoutContainer::paintSelection(QPainter &painter, int messageIndex,
|
||||
rect.setTop(std::max(0, rect.top()) + yOffset);
|
||||
rect.setBottom(std::min(this->height_, rect.bottom()) + yOffset);
|
||||
rect.setLeft(this->elements_[line.startIndex]->getRect().left());
|
||||
rect.setRight(this->elements_[line.endIndex - 1]->getRect().right());
|
||||
rect.setRight(
|
||||
this->elements_[line.endIndex - 1]->getRect().right());
|
||||
|
||||
painter.fillRect(rect, selectionColor);
|
||||
continue;
|
||||
@@ -390,7 +421,8 @@ void MessageLayoutContainer::paintSelection(QPainter &painter, int messageIndex,
|
||||
int c = this->elements_[i]->getSelectionIndexCount();
|
||||
|
||||
if (index + c > selection.selectionMax.charIndex) {
|
||||
r = this->elements_[i]->getXFromIndex(selection.selectionMax.charIndex - index);
|
||||
r = this->elements_[i]->getXFromIndex(
|
||||
selection.selectionMax.charIndex - index);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -424,11 +456,13 @@ int MessageLayoutContainer::getSelectionIndex(QPoint point)
|
||||
}
|
||||
}
|
||||
|
||||
int lineStart = line == this->lines_.end() ? this->lines_.back().startIndex : line->startIndex;
|
||||
int lineStart = line == this->lines_.end() ? this->lines_.back().startIndex
|
||||
: line->startIndex;
|
||||
if (line != this->lines_.end()) {
|
||||
line++;
|
||||
}
|
||||
int lineEnd = line == this->lines_.end() ? this->elements_.size() : line->startIndex;
|
||||
int lineEnd =
|
||||
line == this->lines_.end() ? this->elements_.size() : line->startIndex;
|
||||
|
||||
int index = 0;
|
||||
|
||||
|
||||
@@ -66,7 +66,8 @@ struct MessageLayoutContainer {
|
||||
// painting
|
||||
void paintElements(QPainter &painter);
|
||||
void paintAnimatedElements(QPainter &painter, int yOffset);
|
||||
void paintSelection(QPainter &painter, int messageIndex, Selection &selection, int yOffset);
|
||||
void paintSelection(QPainter &painter, int messageIndex,
|
||||
Selection &selection, int yOffset);
|
||||
|
||||
// selection
|
||||
int getSelectionIndex(QPoint point);
|
||||
|
||||
@@ -14,7 +14,8 @@ const QRect &MessageLayoutElement::getRect() const
|
||||
return this->rect_;
|
||||
}
|
||||
|
||||
MessageLayoutElement::MessageLayoutElement(MessageElement &creator, const QSize &size)
|
||||
MessageLayoutElement::MessageLayoutElement(MessageElement &creator,
|
||||
const QSize &size)
|
||||
: creator_(creator)
|
||||
{
|
||||
this->rect_.setSize(size);
|
||||
@@ -63,14 +64,16 @@ const Link &MessageLayoutElement::getLink() const
|
||||
// IMAGE
|
||||
//
|
||||
|
||||
ImageLayoutElement::ImageLayoutElement(MessageElement &creator, ImagePtr image, const QSize &size)
|
||||
ImageLayoutElement::ImageLayoutElement(MessageElement &creator, ImagePtr image,
|
||||
const QSize &size)
|
||||
: MessageLayoutElement(creator, size)
|
||||
, image_(image)
|
||||
{
|
||||
this->trailingSpace = creator.hasTrailingSpace();
|
||||
}
|
||||
|
||||
void ImageLayoutElement::addCopyTextToString(QString &str, int from, int to) const
|
||||
void ImageLayoutElement::addCopyTextToString(QString &str, int from,
|
||||
int to) const
|
||||
{
|
||||
// str += this->image_->getCopyString();
|
||||
str += "not implemented";
|
||||
@@ -134,8 +137,9 @@ int ImageLayoutElement::getXFromIndex(int index)
|
||||
// TEXT
|
||||
//
|
||||
|
||||
TextLayoutElement::TextLayoutElement(MessageElement &_creator, QString &_text, const QSize &_size,
|
||||
QColor _color, FontStyle _style, float _scale)
|
||||
TextLayoutElement::TextLayoutElement(MessageElement &_creator, QString &_text,
|
||||
const QSize &_size, QColor _color,
|
||||
FontStyle _style, float _scale)
|
||||
: MessageLayoutElement(_creator, _size)
|
||||
, text(_text)
|
||||
, color(_color)
|
||||
@@ -144,7 +148,8 @@ TextLayoutElement::TextLayoutElement(MessageElement &_creator, QString &_text, c
|
||||
{
|
||||
}
|
||||
|
||||
void TextLayoutElement::addCopyTextToString(QString &str, int from, int to) const
|
||||
void TextLayoutElement::addCopyTextToString(QString &str, int from,
|
||||
int to) const
|
||||
{
|
||||
str += this->text.mid(from, to - from);
|
||||
|
||||
@@ -166,8 +171,9 @@ void TextLayoutElement::paint(QPainter &painter)
|
||||
|
||||
painter.setFont(app->fonts->getFont(this->style, this->scale));
|
||||
|
||||
painter.drawText(QRectF(this->getRect().x(), this->getRect().y(), 10000, 10000), this->text,
|
||||
QTextOption(Qt::AlignLeft | Qt::AlignTop));
|
||||
painter.drawText(
|
||||
QRectF(this->getRect().x(), this->getRect().y(), 10000, 10000),
|
||||
this->text, QTextOption(Qt::AlignLeft | Qt::AlignTop));
|
||||
}
|
||||
|
||||
void TextLayoutElement::paintAnimated(QPainter &, int)
|
||||
@@ -219,8 +225,10 @@ int TextLayoutElement::getXFromIndex(int index)
|
||||
}
|
||||
|
||||
// TEXT ICON
|
||||
TextIconLayoutElement::TextIconLayoutElement(MessageElement &creator, const QString &_line1,
|
||||
const QString &_line2, float _scale, const QSize &size)
|
||||
TextIconLayoutElement::TextIconLayoutElement(MessageElement &creator,
|
||||
const QString &_line1,
|
||||
const QString &_line2,
|
||||
float _scale, const QSize &size)
|
||||
: MessageLayoutElement(creator, size)
|
||||
, scale(_scale)
|
||||
, line1(_line1)
|
||||
@@ -228,7 +236,8 @@ TextIconLayoutElement::TextIconLayoutElement(MessageElement &creator, const QStr
|
||||
{
|
||||
}
|
||||
|
||||
void TextIconLayoutElement::addCopyTextToString(QString &str, int from, int to) const
|
||||
void TextIconLayoutElement::addCopyTextToString(QString &str, int from,
|
||||
int to) const
|
||||
{
|
||||
}
|
||||
|
||||
@@ -254,11 +263,12 @@ void TextIconLayoutElement::paint(QPainter &painter)
|
||||
painter.drawText(_rect, this->line1, option);
|
||||
} else {
|
||||
painter.drawText(
|
||||
QPoint(this->getRect().x(), this->getRect().y() + this->getRect().height() / 2),
|
||||
QPoint(this->getRect().x(),
|
||||
this->getRect().y() + this->getRect().height() / 2),
|
||||
this->line1);
|
||||
painter.drawText(
|
||||
QPoint(this->getRect().x(), this->getRect().y() + this->getRect().height()),
|
||||
this->line2);
|
||||
painter.drawText(QPoint(this->getRect().x(),
|
||||
this->getRect().y() + this->getRect().height()),
|
||||
this->line2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,8 @@ public:
|
||||
MessageLayoutElement *setTrailingSpace(bool value);
|
||||
MessageLayoutElement *setLink(const Link &link_);
|
||||
|
||||
virtual void addCopyTextToString(QString &str, int from = 0, int to = INT_MAX) const = 0;
|
||||
virtual void addCopyTextToString(QString &str, int from = 0,
|
||||
int to = INT_MAX) const = 0;
|
||||
virtual int getSelectionIndexCount() = 0;
|
||||
virtual void paint(QPainter &painter) = 0;
|
||||
virtual void paintAnimated(QPainter &painter, int yOffset) = 0;
|
||||
@@ -52,10 +53,12 @@ private:
|
||||
class ImageLayoutElement : public MessageLayoutElement
|
||||
{
|
||||
public:
|
||||
ImageLayoutElement(MessageElement &creator, ImagePtr image, const QSize &size);
|
||||
ImageLayoutElement(MessageElement &creator, ImagePtr image,
|
||||
const QSize &size);
|
||||
|
||||
protected:
|
||||
void addCopyTextToString(QString &str, int from = 0, int to = INT_MAX) const override;
|
||||
void addCopyTextToString(QString &str, int from = 0,
|
||||
int to = INT_MAX) const override;
|
||||
int getSelectionIndexCount() override;
|
||||
void paint(QPainter &painter) override;
|
||||
void paintAnimated(QPainter &painter, int yOffset) override;
|
||||
@@ -70,11 +73,13 @@ private:
|
||||
class TextLayoutElement : public MessageLayoutElement
|
||||
{
|
||||
public:
|
||||
TextLayoutElement(MessageElement &creator_, QString &text, const QSize &size, QColor color,
|
||||
FontStyle style, float scale);
|
||||
TextLayoutElement(MessageElement &creator_, QString &text,
|
||||
const QSize &size, QColor color, FontStyle style,
|
||||
float scale);
|
||||
|
||||
protected:
|
||||
void addCopyTextToString(QString &str, int from = 0, int to = INT_MAX) const override;
|
||||
void addCopyTextToString(QString &str, int from = 0,
|
||||
int to = INT_MAX) const override;
|
||||
int getSelectionIndexCount() override;
|
||||
void paint(QPainter &painter) override;
|
||||
void paintAnimated(QPainter &painter, int yOffset) override;
|
||||
@@ -93,11 +98,12 @@ private:
|
||||
class TextIconLayoutElement : public MessageLayoutElement
|
||||
{
|
||||
public:
|
||||
TextIconLayoutElement(MessageElement &creator_, const QString &line1, const QString &line2,
|
||||
float scale, const QSize &size);
|
||||
TextIconLayoutElement(MessageElement &creator_, const QString &line1,
|
||||
const QString &line2, float scale, const QSize &size);
|
||||
|
||||
protected:
|
||||
void addCopyTextToString(QString &str, int from = 0, int to = INT_MAX) const override;
|
||||
void addCopyTextToString(QString &str, int from = 0,
|
||||
int to = INT_MAX) const override;
|
||||
int getSelectionIndexCount() override;
|
||||
void paint(QPainter &painter) override;
|
||||
void paintAnimated(QPainter &painter, int yOffset) override;
|
||||
|
||||
Reference in New Issue
Block a user