refactor: floatify messages (#6231)

This commit is contained in:
nerix
2025-05-24 11:40:11 +02:00
committed by GitHub
parent 8782533457
commit b78e1ed0a7
18 changed files with 303 additions and 255 deletions
+1
View File
@@ -33,6 +33,7 @@
- Bugfix: Fixed a crash that could occur an eventsub connection's keepalive timer would run after the connection was dead, causing the keepalive timer to use-itself-after-free. (#6204)
- Bugfix: Fixed a crash that could occur when an image started loading mid app shutdown. (#6213)
- Bugfix: Fixed some minor typos. (#6196)
- Bugfix: Fixed inconsistent spaces in messages when using fractional scaling. (#6231)
- Dev: Mini refactor of Split. (#6148)
- Dev: Conan will no longer generate a `CMakeUserPresets.json` file. (#6117)
- Dev: Pass `--force-openssl` when installing from CMake in Qt 6.8+. (#6129)
+13
View File
@@ -484,6 +484,19 @@ int Image::height() const
return static_cast<int>(this->expectedSize_.height() * this->scale_);
}
QSizeF Image::size() const
{
assertInGuiThread();
if (auto pixmap = this->frames_->first())
{
return pixmap->size().toSizeF() * this->scale_;
}
// No frames loaded, use the expected size
return this->expectedSize_.toSizeF() * this->scale_;
}
void Image::actuallyLoad()
{
auto weak = weakOf(this);
+1
View File
@@ -98,6 +98,7 @@ public:
bool isEmpty() const;
int width() const;
int height() const;
QSizeF size() const;
bool animated() const;
bool operator==(const Image &image) = delete;
+39 -47
View File
@@ -27,17 +27,18 @@ using namespace literals;
namespace {
// Computes the bounding box for the given vector of images
QSize getBoundingBoxSize(const std::vector<ImagePtr> &images)
QSizeF getBoundingBoxSize(const std::vector<ImagePtr> &images)
{
int width = 0;
int height = 0;
qreal width = 0;
qreal height = 0;
for (const auto &img : images)
{
width = std::max(width, img->width());
height = std::max(height, img->height());
QSizeF s = img->size();
width = std::max(width, s.width());
height = std::max(height, s.height());
}
return QSize(width, height);
return {width, height};
}
} // namespace
@@ -124,11 +125,8 @@ void ImageElement::addToContainer(MessageLayoutContainer &container,
{
if (ctx.flags.hasAny(this->getFlags()))
{
auto size = QSize(this->image_->width() * container.getScale(),
this->image_->height() * container.getScale());
container.addElement(
(new ImageLayoutElement(*this, this->image_, size)));
container.addElement(new ImageLayoutElement(
*this, this->image_, this->image_->size() * container.getScale()));
}
}
@@ -208,9 +206,7 @@ void EmoteElement::addToContainer(MessageLayoutContainer &container,
auto emoteScale = getSettings()->emoteScale.getValue();
auto size =
QSize(int(container.getScale() * image->width() * emoteScale),
int(container.getScale() * image->height() * emoteScale));
auto size = image->size() * container.getScale() * emoteScale;
container.addElement(this->makeImageLayoutElement(image, size));
}
@@ -227,7 +223,7 @@ void EmoteElement::addToContainer(MessageLayoutContainer &container,
}
MessageLayoutElement *EmoteElement::makeImageLayoutElement(
const ImagePtr &image, const QSize &size)
const ImagePtr &image, QSizeF size)
{
return new ImageLayoutElement(*this, image, size);
}
@@ -278,12 +274,11 @@ void LayeredEmoteElement::addToContainer(MessageLayoutContainer &container,
float overallScale = emoteScale * container.getScale();
auto largestSize = getBoundingBoxSize(images) * overallScale;
std::vector<QSize> individualSizes;
std::vector<QSizeF> individualSizes;
individualSizes.reserve(this->emotes_.size());
for (auto img : images)
for (const auto &img : images)
{
individualSizes.push_back(QSize(img->width(), img->height()) *
overallScale);
individualSizes.push_back(img->size() * overallScale);
}
container.addElement(this->makeImageLayoutElement(
@@ -319,8 +314,8 @@ std::vector<ImagePtr> LayeredEmoteElement::getLoadedImages(float scale)
}
MessageLayoutElement *LayeredEmoteElement::makeImageLayoutElement(
const std::vector<ImagePtr> &images, const std::vector<QSize> &sizes,
QSize largestSize)
const std::vector<ImagePtr> &images, const std::vector<QSizeF> &sizes,
QSizeF largestSize)
{
return new LayeredImageLayoutElement(*this, images, sizes, largestSize);
}
@@ -461,10 +456,8 @@ void BadgeElement::addToContainer(MessageLayoutContainer &container,
return;
}
auto size = QSize(int(container.getScale() * image->width()),
int(container.getScale() * image->height()));
container.addElement(this->makeImageLayoutElement(image, size));
container.addElement(this->makeImageLayoutElement(
image, image->size() * container.getScale()));
}
}
@@ -474,7 +467,7 @@ EmotePtr BadgeElement::getEmote() const
}
MessageLayoutElement *BadgeElement::makeImageLayoutElement(
const ImagePtr &image, const QSize &size)
const ImagePtr &image, QSizeF size)
{
auto *element = new ImageLayoutElement(*this, image, size);
@@ -498,7 +491,7 @@ ModBadgeElement::ModBadgeElement(const EmotePtr &data,
}
MessageLayoutElement *ModBadgeElement::makeImageLayoutElement(
const ImagePtr &image, const QSize &size)
const ImagePtr &image, QSizeF size)
{
static const QColor modBadgeBackgroundColor("#34AE0A");
@@ -524,7 +517,7 @@ VipBadgeElement::VipBadgeElement(const EmotePtr &data,
}
MessageLayoutElement *VipBadgeElement::makeImageLayoutElement(
const ImagePtr &image, const QSize &size)
const ImagePtr &image, QSizeF size)
{
auto *element = new ImageLayoutElement(*this, image, size);
@@ -548,7 +541,7 @@ FfzBadgeElement::FfzBadgeElement(const EmotePtr &data,
}
MessageLayoutElement *FfzBadgeElement::makeImageLayoutElement(
const ImagePtr &image, const QSize &size)
const ImagePtr &image, QSizeF size)
{
auto *element =
new ImageWithBackgroundLayoutElement(*this, image, size, this->color);
@@ -583,20 +576,20 @@ void TextElement::addToContainer(MessageLayoutContainer &container,
if (ctx.flags.hasAny(this->getFlags()))
{
QFontMetrics metrics =
auto metrics =
app->getFonts()->getFontMetrics(this->style_, container.getScale());
for (const auto &word : this->words_)
{
auto wordId = container.nextWordId();
auto getTextLayoutElement = [&](QString text, int width,
auto getTextLayoutElement = [&](QString text, qreal width,
bool hasTrailingSpace) {
auto color = this->color_.getColor(ctx.messageColors);
app->getThemes()->normalizeColor(color);
auto *e = new TextLayoutElement(
*this, text, QSize(width, metrics.height()), color,
*this, text, QSizeF(width, metrics.height()), color,
this->style_, container.getScale());
e->setTrailingSpace(hasTrailingSpace);
e->setText(text);
@@ -749,16 +742,16 @@ void SingleLineTextElement::addToContainer(MessageLayoutContainer &container,
if (ctx.flags.hasAny(this->getFlags()))
{
QFontMetrics metrics =
auto metrics =
app->getFonts()->getFontMetrics(this->style_, container.getScale());
auto getTextLayoutElement = [&](QString text, int width,
auto getTextLayoutElement = [&](QString text, qreal width,
bool hasTrailingSpace) {
auto color = this->color_.getColor(ctx.messageColors);
app->getThemes()->normalizeColor(color);
auto *e = new TextLayoutElement(
*this, text, QSize(width, metrics.height()), color,
*this, text, QSizeF(width, metrics.height()), color,
this->style_, container.getScale());
e->setTrailingSpace(hasTrailingSpace);
e->setText(text);
@@ -811,11 +804,10 @@ void SingleLineTextElement::addToContainer(MessageLayoutContainer &container,
{
auto emoteScale = getSettings()->emoteScale.getValue();
int currentWidth =
auto currentWidth =
metrics.horizontalAdvance(currentText);
auto emoteSize =
QSize(image->width(), image->height()) *
(emoteScale * container.getScale());
image->size() * emoteScale * container.getScale();
if (!container.fitsInLine(currentWidth +
emoteSize.width()))
@@ -847,7 +839,7 @@ void SingleLineTextElement::addToContainer(MessageLayoutContainer &container,
// Add the last of the pending message text to the container.
if (!currentText.isEmpty())
{
int width = metrics.horizontalAdvance(currentText);
auto width = metrics.horizontalAdvance(currentText);
container.addElementNoLineBreak(
getTextLayoutElement(currentText, width, false));
}
@@ -1051,12 +1043,14 @@ void TwitchModerationElement::addToContainer(MessageLayoutContainer &container,
{
if (ctx.flags.has(MessageElementFlag::ModeratorTools))
{
QSize size(int(container.getScale() * 16),
int(container.getScale() * 16));
QSizeF size{
container.getScale() * 16,
container.getScale() * 16,
};
auto actions = getSettings()->moderationActions.readOnly();
for (const auto &action : *actions)
{
if (auto image = action.getImage())
if (const auto &image = action.getImage())
{
container.addElement(
(new ImageLayoutElement(*this, *image, size))
@@ -1123,10 +1117,8 @@ void ScalingImageElement::addToContainer(MessageLayoutContainer &container,
return;
}
auto size = QSize(image->width() * container.getScale(),
image->height() * container.getScale());
container.addElement(new ImageLayoutElement(*this, image, size));
container.addElement(new ImageLayoutElement(
*this, image, image->size() * container.getScale()));
}
}
@@ -1147,7 +1139,7 @@ ReplyCurveElement::ReplyCurveElement()
void ReplyCurveElement::addToContainer(MessageLayoutContainer &container,
const MessageLayoutContext &ctx)
{
static const int width = 18; // Overall width
static const qreal width = 18; // Overall width
static const float thickness = 1.5; // Pen width
static const int radius = 6; // Radius of the top left corner
static const int margin = 2; // Top/Left/Bottom margin
+7 -7
View File
@@ -394,7 +394,7 @@ public:
protected:
virtual MessageLayoutElement *makeImageLayoutElement(const ImagePtr &image,
const QSize &size);
QSizeF size);
private:
std::unique_ptr<TextElement> textElement_;
@@ -431,8 +431,8 @@ public:
private:
MessageLayoutElement *makeImageLayoutElement(
const std::vector<ImagePtr> &image, const std::vector<QSize> &sizes,
QSize largestSize);
const std::vector<ImagePtr> &image, const std::vector<QSizeF> &sizes,
QSizeF largestSize);
QString getCopyString() const;
void updateTooltips();
@@ -459,7 +459,7 @@ public:
protected:
virtual MessageLayoutElement *makeImageLayoutElement(const ImagePtr &image,
const QSize &size);
QSizeF size);
private:
EmotePtr emote_;
@@ -474,7 +474,7 @@ public:
protected:
MessageLayoutElement *makeImageLayoutElement(const ImagePtr &image,
const QSize &size) override;
QSizeF size) override;
};
class VipBadgeElement : public BadgeElement
@@ -486,7 +486,7 @@ public:
protected:
MessageLayoutElement *makeImageLayoutElement(const ImagePtr &image,
const QSize &size) override;
QSizeF size) override;
};
class FfzBadgeElement : public BadgeElement
@@ -499,7 +499,7 @@ public:
protected:
MessageLayoutElement *makeImageLayoutElement(const ImagePtr &image,
const QSize &size) override;
QSizeF size) override;
const QColor color;
};
+49 -20
View File
@@ -56,12 +56,12 @@ const MessagePtr &MessageLayout::getMessagePtr() const
}
// Height
int MessageLayout::getHeight() const
qreal MessageLayout::getHeight() const
{
return this->container_.getHeight();
}
int MessageLayout::getWidth() const
qreal MessageLayout::getWidth() const
{
return this->container_.getWidth();
}
@@ -113,7 +113,7 @@ bool MessageLayout::layout(const MessageLayoutContext &ctx,
return false;
}
int oldHeight = this->container_.getHeight();
qreal oldHeight = this->container_.getHeight();
this->actuallyLayout(ctx);
if (widthChanged || this->container_.getHeight() != oldHeight)
{
@@ -236,7 +236,7 @@ MessagePaintResult MessageLayout::paint(const MessagePaintContext &ctx)
}
// draw on buffer
ctx.painter.drawPixmap(0, ctx.y, *pixmap);
ctx.painter.drawPixmap(QPointF{0, ctx.y}, *pixmap);
// draw gif emotes
result.hasAnimatedElements =
@@ -245,15 +245,27 @@ MessagePaintResult MessageLayout::paint(const MessagePaintContext &ctx)
// draw disabled
if (this->message_->flags.has(MessageFlag::Disabled))
{
ctx.painter.fillRect(0, ctx.y, pixmap->width(), pixmap->height(),
ctx.messageColors.disabled);
ctx.painter.fillRect(
QRectF{
0,
ctx.y,
static_cast<qreal>(pixmap->width()),
static_cast<qreal>(pixmap->height()),
},
ctx.messageColors.disabled);
}
if (this->message_->flags.has(MessageFlag::RecentMessage) &&
ctx.preferences.fadeMessageHistory)
{
ctx.painter.fillRect(0, ctx.y, pixmap->width(), pixmap->height(),
ctx.messageColors.disabled);
ctx.painter.fillRect(
QRectF{
0,
ctx.y,
static_cast<qreal>(pixmap->width()),
static_cast<qreal>(pixmap->height()),
},
ctx.messageColors.disabled);
}
if (!ctx.isMentions &&
@@ -262,7 +274,12 @@ MessagePaintResult MessageLayout::paint(const MessagePaintContext &ctx)
ctx.preferences.enableRedeemedHighlight)
{
ctx.painter.fillRect(
0, ctx.y, int(this->scale_ * 4), pixmap->height(),
QRectF{
0,
ctx.y,
this->scale_ * 4,
static_cast<qreal>(pixmap->height()),
},
*ColorProvider::instance().color(ColorType::RedeemedHighlight));
}
@@ -276,8 +293,14 @@ MessagePaintResult MessageLayout::paint(const MessagePaintContext &ctx)
// draw message seperation line
if (ctx.preferences.separateMessages)
{
ctx.painter.fillRect(0, ctx.y, this->container_.getWidth() + 64, 1,
ctx.messageColors.messageSeperator);
ctx.painter.fillRect(
QRectF{
0.0,
static_cast<qreal>(ctx.y),
this->container_.getWidth() + 64,
1.0,
},
ctx.messageColors.messageSeperator);
}
// draw last read message line
@@ -297,8 +320,14 @@ MessagePaintResult MessageLayout::paint(const MessagePaintContext &ctx)
QBrush brush(color, ctx.preferences.lastMessagePattern);
ctx.painter.fillRect(0, ctx.y + this->container_.getHeight() - 1,
pixmap->width(), 1, brush);
ctx.painter.fillRect(
QRectF{
0,
ctx.y + this->container_.getHeight() - 1,
static_cast<qreal>(pixmap->width()),
1,
},
brush);
}
this->bufferValid_ = true;
@@ -306,7 +335,7 @@ MessagePaintResult MessageLayout::paint(const MessagePaintContext &ctx)
return result;
}
QPixmap *MessageLayout::ensureBuffer(QPainter &painter, int width, bool clear)
QPixmap *MessageLayout::ensureBuffer(QPainter &painter, qreal width, bool clear)
{
if (this->buffer_ != nullptr)
{
@@ -315,9 +344,9 @@ QPixmap *MessageLayout::ensureBuffer(QPainter &painter, int width, bool clear)
// Create new buffer
this->buffer_ = std::make_unique<QPixmap>(
int(width * painter.device()->devicePixelRatioF()),
int(this->container_.getHeight() *
painter.device()->devicePixelRatioF()));
static_cast<int>(width * painter.device()->devicePixelRatioF()),
static_cast<int>(this->container_.getHeight() *
painter.device()->devicePixelRatioF()));
this->buffer_->setDevicePixelRatio(painter.device()->devicePixelRatioF());
if (clear)
@@ -469,14 +498,14 @@ void MessageLayout::deleteCache()
// returns nullptr if none was found
// fourtf: this should return a MessageLayoutItem
const MessageLayoutElement *MessageLayout::getElementAt(QPoint point) const
const MessageLayoutElement *MessageLayout::getElementAt(QPointF point) const
{
// go through all words and return the first one that contains the point.
return this->container_.getElementAt(point);
}
std::pair<int, int> MessageLayout::getWordBounds(
const MessageLayoutElement *hoveredElement, QPoint relativePos) const
const MessageLayoutElement *hoveredElement, QPointF relativePos) const
{
// An element with wordId != -1 can be multiline, so we need to check all
// elements in the container
@@ -504,7 +533,7 @@ size_t MessageLayout::getFirstMessageCharacterIndex() const
return this->container_.getFirstMessageCharacterIndex();
}
size_t MessageLayout::getSelectionIndex(QPoint position) const
size_t MessageLayout::getSelectionIndex(QPointF position) const
{
return this->container_.getSelectionIndex(position);
}
+7 -7
View File
@@ -52,8 +52,8 @@ public:
const Message *getMessage();
const MessagePtr &getMessagePtr() const;
int getHeight() const;
int getWidth() const;
qreal getHeight() const;
qreal getWidth() const;
MessageLayoutFlags flags;
@@ -70,7 +70,7 @@ public:
*
* If no element is found at the given point, this returns a null pointer
*/
const MessageLayoutElement *getElementAt(QPoint point) const;
const MessageLayoutElement *getElementAt(QPointF point) const;
/**
* @brief Returns the word bounds of the given element
@@ -84,7 +84,7 @@ public:
* "abc "
*/
std::pair<int, int> getWordBounds(
const MessageLayoutElement *hoveredElement, QPoint relativePos) const;
const MessageLayoutElement *hoveredElement, QPointF relativePos) const;
/**
* Get the index of the last character in this message's container
@@ -101,7 +101,7 @@ public:
/**
* Get the character index at the given position, in the context of selections
*/
size_t getSelectionIndex(QPoint position) const;
size_t getSelectionIndex(QPointF position) const;
void addSelectionText(QString &str, uint32_t from = 0,
uint32_t to = UINT32_MAX,
CopyMode copymode = CopyMode::Everything);
@@ -116,7 +116,7 @@ private:
void updateBuffer(QPixmap *buffer, const MessagePaintContext &ctx);
// Create new buffer if required, returning the buffer
QPixmap *ensureBuffer(QPainter &painter, int width, bool clear);
QPixmap *ensureBuffer(QPainter &painter, qreal width, bool clear);
// variables
const MessagePtr message_;
@@ -124,7 +124,7 @@ private:
std::unique_ptr<QPixmap> buffer_;
bool bufferValid_ = false;
int height_ = 0;
qreal height_ = 0;
int currentLayoutWidth_ = -1;
int layoutState_ = -1;
float scale_ = -1;
+38 -38
View File
@@ -23,7 +23,7 @@ namespace {
using namespace chatterino;
constexpr QMargins MARGIN{8, 4, 8, 4};
constexpr int COMPACT_EMOTES_OFFSET = 4;
constexpr qreal COMPACT_EMOTES_OFFSET = 4;
int maxUncollapsedLines()
{
@@ -34,7 +34,7 @@ int maxUncollapsedLines()
namespace chatterino {
void MessageLayoutContainer::beginLayout(int width, float scale,
void MessageLayoutContainer::beginLayout(qreal width, float scale,
float imageScale, MessageFlags flags)
{
this->elements_.clear();
@@ -74,7 +74,7 @@ void MessageLayoutContainer::endLayout()
auto *element = new TextLayoutElement(
dotdotdot, dotdotdotText,
QSize(this->dotdotdotWidth_, this->textLineHeight_),
QSizeF(this->dotdotdotWidth_, this->textLineHeight_),
QColor("#00D80A"), FontStyle::ChatMediumBold, this->scale_);
if (this->isRTL())
@@ -83,9 +83,11 @@ void MessageLayoutContainer::endLayout()
for (auto i = this->lines_.back().startIndex;
i < this->elements_.size(); i++)
{
QPoint prevPos = this->elements_[i]->getRect().topLeft();
this->elements_[i]->setPosition(
QPoint(prevPos.x() + this->dotdotdotWidth_, prevPos.y()));
QPointF prevPos = this->elements_[i]->getRect().topLeft();
this->elements_[i]->setPosition(QPointF{
prevPos.x() + this->dotdotdotWidth_,
prevPos.y(),
});
}
}
this->addElement(element, true, -2);
@@ -157,7 +159,7 @@ void MessageLayoutContainer::breakLine()
this->anyReorderingDone_ = true;
}
int xOffset = 0;
qreal xOffset = 0;
if (this->flags_.has(MessageFlag::Centered) && this->elements_.size() > 0)
{
@@ -179,16 +181,16 @@ void MessageLayoutContainer::breakLine()
element->getCreator().getFlags().has(
MessageElementFlag::EmoteImages);
int yExtra = 0;
qreal yExtra = 0;
if (isCompactEmote)
{
yExtra = (COMPACT_EMOTES_OFFSET / 2) * this->scale_;
}
element->setPosition(
QPoint(element->getRect().x() + xOffset +
int(MARGIN.left() * this->scale_),
element->getRect().y() + this->lineHeight_ + yExtra));
element->setPosition(QPointF{
element->getRect().x() + xOffset + (MARGIN.left() * this->scale_),
element->getRect().y() + this->lineHeight_ + yExtra,
});
}
if (!this->lines_.empty())
@@ -201,7 +203,7 @@ void MessageLayoutContainer::breakLine()
.endIndex = 0,
.startCharIndex = this->charIndex_,
.endCharIndex = 0,
.rect = QRect(-100000, this->currentY_, 200000, lineHeight_),
.rect = QRectF(-100000, this->currentY_, 200000, lineHeight_),
});
for (auto i = this->lineStart_; i < this->elements_.size(); i++)
@@ -260,7 +262,7 @@ void MessageLayoutContainer::paintElements(QPainter &painter,
}
bool MessageLayoutContainer::paintAnimatedElements(QPainter &painter,
int yOffset) const
qreal yOffset) const
{
bool anyAnimatedElement = false;
for (const auto &element : this->elements_)
@@ -273,7 +275,7 @@ bool MessageLayoutContainer::paintAnimatedElements(QPainter &painter,
void MessageLayoutContainer::paintSelection(QPainter &painter,
const size_t messageIndex,
const Selection &selection,
const int yOffset) const
const qreal yOffset) const
{
if (selection.selectionMin.messageIndex > messageIndex ||
selection.selectionMax.messageIndex < messageIndex)
@@ -383,7 +385,7 @@ void MessageLayoutContainer::addSelectionText(QString &str, uint32_t from,
}
}
MessageLayoutElement *MessageLayoutContainer::getElementAt(QPoint point) const
MessageLayoutElement *MessageLayoutContainer::getElementAt(QPointF point) const
{
for (const auto &element : this->elements_)
{
@@ -396,7 +398,7 @@ MessageLayoutElement *MessageLayoutContainer::getElementAt(QPoint point) const
return nullptr;
}
size_t MessageLayoutContainer::getSelectionIndex(QPoint point) const
size_t MessageLayoutContainer::getSelectionIndex(QPointF point) const
{
if (this->elements_.empty())
{
@@ -534,12 +536,12 @@ size_t MessageLayoutContainer::getLastCharacterIndex() const
return this->lines_.back().endCharIndex;
}
int MessageLayoutContainer::getWidth() const
qreal MessageLayoutContainer::getWidth() const
{
return this->width_;
}
int MessageLayoutContainer::getHeight() const
qreal MessageLayoutContainer::getHeight() const
{
return this->height_;
}
@@ -564,12 +566,12 @@ bool MessageLayoutContainer::atStartOfLine() const
return this->lineStart_ == this->elements_.size();
}
bool MessageLayoutContainer::fitsInLine(int width) const
bool MessageLayoutContainer::fitsInLine(qreal width) const
{
return width <= this->remainingWidth();
}
int MessageLayoutContainer::remainingWidth() const
qreal MessageLayoutContainer::remainingWidth() const
{
return (this->width_ - int(MARGIN.left() * this->scale_) -
int(MARGIN.right() * this->scale_) -
@@ -663,7 +665,7 @@ void MessageLayoutContainer::addElement(MessageLayoutElement *element,
this->currentY_ = int(MARGIN.top() * this->scale_);
}
int elementLineHeight = element->getRect().height();
qreal elementLineHeight = element->getRect().height();
// compact emote offset
bool isCompactEmote =
@@ -678,8 +680,8 @@ void MessageLayoutContainer::addElement(MessageLayoutElement *element,
// update line height
this->lineHeight_ = std::max(this->lineHeight_, elementLineHeight);
auto xOffset = 0;
auto yOffset = 0;
qreal xOffset = 0;
qreal yOffset = 0;
if (element->getCreator().getFlags().has(
MessageElementFlag::ChannelPointReward) &&
@@ -713,8 +715,8 @@ void MessageLayoutContainer::addElement(MessageLayoutElement *element,
// set move element
element->setPosition(
QPoint(this->currentX_ + xOffset,
this->currentY_ - element->getRect().height() + yOffset));
QPointF(this->currentX_ + xOffset,
this->currentY_ - element->getRect().height() + yOffset));
element->setLine(this->line_);
@@ -832,15 +834,13 @@ void MessageLayoutContainer::reorderRTL(size_t firstTextIndex)
}
}
void MessageLayoutContainer::paintSelectionRect(QPainter &painter,
const Line &line,
const int left, const int right,
const int yOffset,
const QColor &color) const
void MessageLayoutContainer::paintSelectionRect(
QPainter &painter, const Line &line, const qreal left, const qreal right,
const qreal yOffset, const QColor &color) const
{
QRect rect = line.rect;
QRectF rect = line.rect;
rect.setTop(std::max(0, rect.top()) + yOffset);
rect.setTop(std::max(rect.top(), 0.0) + yOffset);
rect.setBottom(std::min(this->height_, rect.bottom()) + yOffset);
rect.setLeft(left);
rect.setRight(right);
@@ -850,7 +850,7 @@ void MessageLayoutContainer::paintSelectionRect(QPainter &painter,
std::optional<size_t> MessageLayoutContainer::paintSelectionStart(
QPainter &painter, const size_t messageIndex, const Selection &selection,
const int yOffset) const
const qreal yOffset) const
{
const auto selectionColor = getTheme()->messages.selection;
@@ -899,8 +899,8 @@ std::optional<size_t> MessageLayoutContainer::paintSelectionStart(
return {lineIndex + 1};
}
int x = this->elements_[line.startIndex]->getRect().left();
int r = this->elements_[line.endIndex - 1]->getRect().right();
qreal x = this->elements_[line.startIndex]->getRect().left();
qreal r = this->elements_[line.endIndex - 1]->getRect().right();
auto index = line.startCharIndex;
for (auto i = line.startIndex; i < line.endIndex; i++)
@@ -966,7 +966,7 @@ std::optional<size_t> MessageLayoutContainer::paintSelectionStart(
void MessageLayoutContainer::paintSelectionEnd(QPainter &painter,
size_t lineIndex,
const Selection &selection,
const int yOffset) const
const qreal yOffset) const
{
const auto selectionColor = getTheme()->messages.selection;
// [2] selection contains or ends in this message (starts before our message or line)
@@ -986,7 +986,7 @@ void MessageLayoutContainer::paintSelectionEnd(QPainter &painter,
}
// find the right end of the selection
int r = this->elements_[line.endIndex - 1]->getRect().right();
qreal r = this->elements_[line.endIndex - 1]->getRect().right();
for (auto i = line.startIndex; i < line.endIndex; i++)
{
+23 -22
View File
@@ -38,7 +38,7 @@ struct MessageLayoutContainer {
* This will reset all line calculations, and will be considered incomplete
* until the accompanying end function has been called
*/
void beginLayout(int width, float scale, float imageScale,
void beginLayout(qreal width, float scale, float imageScale,
MessageFlags flags);
/**
@@ -73,7 +73,7 @@ struct MessageLayoutContainer {
* Paint the animated elements in this message
* @returns true if this container contains at least one animated element
*/
bool paintAnimatedElements(QPainter &painter, int yOffset) const;
bool paintAnimatedElements(QPainter &painter, qreal yOffset) const;
/**
* Paint the selection for this container
@@ -86,7 +86,7 @@ struct MessageLayoutContainer {
* @param yOffset The extra offset added to Y for everything that's painted
*/
void paintSelection(QPainter &painter, size_t messageIndex,
const Selection &selection, int yOffset) const;
const Selection &selection, qreal yOffset) const;
/**
* Add text from this message into the `str` parameter
@@ -104,12 +104,12 @@ struct MessageLayoutContainer {
*
* If no element is found at the given point, this returns a null pointer
*/
MessageLayoutElement *getElementAt(QPoint point) const;
MessageLayoutElement *getElementAt(QPointF point) const;
/**
* Get the character index at the given point, in the context of selections
*/
size_t getSelectionIndex(QPoint point) const;
size_t getSelectionIndex(QPointF point) const;
/**
* Get the index of the first visible character in this message
@@ -141,12 +141,12 @@ struct MessageLayoutContainer {
/**
* Returns the width of this message
*/
int getWidth() const;
qreal getWidth() const;
/**
* Returns the height of this message
*/
int getHeight() const;
qreal getHeight() const;
/**
* Returns the scale of this message
@@ -173,12 +173,12 @@ struct MessageLayoutContainer {
*
* Returns true if it does fit, false if not
*/
bool fitsInLine(int width) const;
bool fitsInLine(qreal width) const;
/**
* Returns the remaining width of this line until we will need to start a new line
*/
int remainingWidth() const;
qreal remainingWidth() const;
/**
* Returns the id of the next word that can be added to this container
@@ -215,7 +215,7 @@ private:
* The rectangle that covers all elements on this line
* This rectangle will always take up 100% of the view's width
*/
QRect rect;
QRectF rect;
};
/// @brief Attempts to add @a element to this container
@@ -277,8 +277,9 @@ private:
* @param yOffset Extra offset for line's top & bottom
* @param color Color of the selection
**/
void paintSelectionRect(QPainter &painter, const Line &line, int left,
int right, int yOffset, const QColor &color) const;
void paintSelectionRect(QPainter &painter, const Line &line, qreal left,
qreal right, qreal yOffset,
const QColor &color) const;
/**
* Paint the selection start
@@ -293,7 +294,7 @@ private:
std::optional<size_t> paintSelectionStart(QPainter &painter,
size_t messageIndex,
const Selection &selection,
int yOffset) const;
qreal yOffset) const;
/**
* Paint the selection end
@@ -301,7 +302,7 @@ private:
* @param lineIndex The index of the line to start painting at
*/
void paintSelectionEnd(QPainter &painter, size_t lineIndex,
const Selection &selection, int yOffset) const;
const Selection &selection, qreal yOffset) const;
/**
* canAddElements returns true if it's possible to add more elements to this message
@@ -330,7 +331,7 @@ private:
* Scale factor for images
*/
float imageScale_ = 1.F;
int width_ = 0;
qreal width_ = 0;
MessageFlags flags_{};
/**
* line_ is the current line index we are adding
@@ -338,19 +339,19 @@ private:
* incrementing if the message is collapsed
*/
size_t line_{};
int height_ = 0;
int currentX_ = 0;
int currentY_ = 0;
qreal height_ = 0;
qreal currentX_ = 0;
qreal currentY_ = 0;
/**
* charIndex_ is the selection-contexted index of where we currently are in our message
* At the end, this will always be equal to the sum of `elements_` getSelectionIndexCount()
*/
size_t charIndex_ = 0;
size_t lineStart_ = 0;
int lineHeight_ = 0;
int spaceWidth_ = 4;
int textLineHeight_ = 0;
int dotdotdotWidth_ = 0;
qreal lineHeight_ = 0;
qreal spaceWidth_ = 4;
qreal textLineHeight_ = 0;
qreal dotdotdotWidth_ = 0;
int currentWordId_ = 0;
bool canAddMessages_ = true;
bool isCollapsed_ = false;
@@ -76,7 +76,7 @@ struct MessagePaintContext {
const bool isMentions{};
// y coordinate we're currently painting at
int y{};
qreal y{};
// Index of the message that is currently being painted
// This index refers to the snapshot being used in the painting
+42 -40
View File
@@ -27,16 +27,15 @@ void alignRectBottomCenter(QRectF &rect, const QRectF &reference)
namespace chatterino {
const QRect &MessageLayoutElement::getRect() const
const QRectF &MessageLayoutElement::getRect() const
{
return this->rect_;
}
MessageLayoutElement::MessageLayoutElement(MessageElement &creator,
const QSize &size)
: creator_(creator)
MessageLayoutElement::MessageLayoutElement(MessageElement &creator, QSizeF size)
: rect_(QPointF{}, size)
, creator_(creator)
{
this->rect_.setSize(size);
DebugCount::increase("message layout elements");
}
@@ -50,7 +49,7 @@ MessageElement &MessageLayoutElement::getCreator() const
return this->creator_;
}
void MessageLayoutElement::setPosition(QPoint point)
void MessageLayoutElement::setPosition(QPointF point)
{
this->rect_.moveTopLeft(point);
}
@@ -123,7 +122,7 @@ void MessageLayoutElement::setWordId(int wordId)
//
ImageLayoutElement::ImageLayoutElement(MessageElement &creator, ImagePtr image,
const QSize &size)
QSizeF size)
: MessageLayoutElement(creator, size)
, image_(std::move(image))
{
@@ -167,7 +166,7 @@ void ImageLayoutElement::paint(QPainter &painter,
}
}
bool ImageLayoutElement::paintAnimated(QPainter &painter, int yOffset)
bool ImageLayoutElement::paintAnimated(QPainter &painter, qreal yOffset)
{
if (this->image_ == nullptr)
{
@@ -187,12 +186,12 @@ bool ImageLayoutElement::paintAnimated(QPainter &painter, int yOffset)
return false;
}
int ImageLayoutElement::getMouseOverIndex(const QPoint &abs) const
int ImageLayoutElement::getMouseOverIndex(QPointF /*abs*/) const
{
return 0;
}
int ImageLayoutElement::getXFromIndex(size_t index)
qreal ImageLayoutElement::getXFromIndex(size_t index)
{
if (index <= 0)
{
@@ -215,7 +214,7 @@ int ImageLayoutElement::getXFromIndex(size_t index)
LayeredImageLayoutElement::LayeredImageLayoutElement(
MessageElement &creator, std::vector<ImagePtr> images,
std::vector<QSize> sizes, QSize largestSize)
std::vector<QSizeF> sizes, QSizeF largestSize)
: MessageLayoutElement(creator, largestSize)
, images_(std::move(images))
, sizes_(std::move(sizes))
@@ -281,7 +280,7 @@ void LayeredImageLayoutElement::paint(QPainter &painter,
}
}
bool LayeredImageLayoutElement::paintAnimated(QPainter &painter, int yOffset)
bool LayeredImageLayoutElement::paintAnimated(QPainter &painter, qreal yOffset)
{
auto fullRect = QRectF(this->getRect());
fullRect.moveTop(fullRect.y() + yOffset);
@@ -316,12 +315,12 @@ bool LayeredImageLayoutElement::paintAnimated(QPainter &painter, int yOffset)
return animatedFlag;
}
int LayeredImageLayoutElement::getMouseOverIndex(const QPoint &abs) const
int LayeredImageLayoutElement::getMouseOverIndex(QPointF /*abs*/) const
{
return 0;
}
int LayeredImageLayoutElement::getXFromIndex(size_t index)
qreal LayeredImageLayoutElement::getXFromIndex(size_t index)
{
if (index <= 0)
{
@@ -342,8 +341,8 @@ int LayeredImageLayoutElement::getXFromIndex(size_t index)
// IMAGE WITH BACKGROUND
//
ImageWithBackgroundLayoutElement::ImageWithBackgroundLayoutElement(
MessageElement &creator, ImagePtr image, const QSize &size, QColor color)
: ImageLayoutElement(creator, image, size)
MessageElement &creator, ImagePtr image, QSizeF size, QColor color)
: ImageLayoutElement(creator, std::move(image), size)
, color_(color)
{
}
@@ -411,9 +410,9 @@ void ImageWithCircleBackgroundLayoutElement::paint(
//
TextLayoutElement::TextLayoutElement(MessageElement &_creator, QString &_text,
const QSize &_size, QColor _color,
QSizeF size, QColor _color,
FontStyle _style, float _scale)
: MessageLayoutElement(_creator, _size)
: MessageLayoutElement(_creator, size)
, color_(_color)
, style_(_style)
, scale_(_scale)
@@ -456,12 +455,12 @@ void TextLayoutElement::paint(QPainter &painter,
QTextOption(Qt::AlignLeft | Qt::AlignTop));
}
bool TextLayoutElement::paintAnimated(QPainter & /*painter*/, int /*yOffset*/)
bool TextLayoutElement::paintAnimated(QPainter & /*painter*/, qreal /*yOffset*/)
{
return false;
}
int TextLayoutElement::getMouseOverIndex(const QPoint &abs) const
int TextLayoutElement::getMouseOverIndex(QPointF abs) const
{
if (abs.x() < this->getRect().left())
{
@@ -500,12 +499,11 @@ int TextLayoutElement::getMouseOverIndex(const QPoint &abs) const
return this->getSelectionIndexCount() - (this->hasTrailingSpace() ? 1 : 0);
}
int TextLayoutElement::getXFromIndex(size_t index)
qreal TextLayoutElement::getXFromIndex(size_t index)
{
auto *app = getApp();
QFontMetrics metrics =
app->getFonts()->getFontMetrics(this->style_, this->scale_);
auto metrics = app->getFonts()->getFontMetrics(this->style_, this->scale_);
if (index <= 0)
{
@@ -513,7 +511,7 @@ int TextLayoutElement::getXFromIndex(size_t index)
}
else if (index < static_cast<size_t>(this->getText().size()))
{
int x = 0;
qreal x = 0;
for (size_t i = 0; i < index; i++)
{
x += metrics.horizontalAdvance(
@@ -531,7 +529,7 @@ int TextLayoutElement::getXFromIndex(size_t index)
TextIconLayoutElement::TextIconLayoutElement(MessageElement &creator,
const QString &_line1,
const QString &_line2,
float _scale, const QSize &size)
float _scale, QSizeF size)
: MessageLayoutElement(creator, size)
, scale(_scale)
, line1(_line1)
@@ -564,33 +562,37 @@ void TextIconLayoutElement::paint(QPainter &painter,
if (this->line2.isEmpty())
{
QRect _rect(this->getRect());
painter.drawText(_rect, this->line1, option);
painter.drawText(this->getRect(), this->line1, option);
}
else
{
painter.drawText(
QPoint(this->getRect().x(),
this->getRect().y() + this->getRect().height() / 2),
QPointF{
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(
QPointF{
this->getRect().x(),
this->getRect().y() + this->getRect().height(),
},
this->line2);
}
}
bool TextIconLayoutElement::paintAnimated(QPainter & /*painter*/,
int /*yOffset*/)
qreal /*yOffset*/)
{
return false;
}
int TextIconLayoutElement::getMouseOverIndex(const QPoint &abs) const
int TextIconLayoutElement::getMouseOverIndex(QPointF /*abs*/) const
{
return 0;
}
int TextIconLayoutElement::getXFromIndex(size_t index)
qreal TextIconLayoutElement::getXFromIndex(size_t index)
{
if (index <= 0)
{
@@ -608,10 +610,10 @@ int TextIconLayoutElement::getXFromIndex(size_t index)
}
ReplyCurveLayoutElement::ReplyCurveLayoutElement(MessageElement &creator,
int width, float thickness,
qreal width, float thickness,
float radius,
float neededMargin)
: MessageLayoutElement(creator, QSize(width, 0))
: MessageLayoutElement(creator, QSizeF(width, 0))
, pen_(QColor("#888"), thickness, Qt::SolidLine, Qt::RoundCap)
, radius_(radius)
, neededMargin_(neededMargin)
@@ -655,17 +657,17 @@ void ReplyCurveLayoutElement::paint(QPainter &painter,
}
bool ReplyCurveLayoutElement::paintAnimated(QPainter & /*painter*/,
int /*yOffset*/)
qreal /*yOffset*/)
{
return false;
}
int ReplyCurveLayoutElement::getMouseOverIndex(const QPoint &abs) const
int ReplyCurveLayoutElement::getMouseOverIndex(QPointF /*abs*/) const
{
return 0;
}
int ReplyCurveLayoutElement::getXFromIndex(size_t index)
qreal ReplyCurveLayoutElement::getXFromIndex(size_t index)
{
if (index <= 0)
{
+31 -33
View File
@@ -25,7 +25,7 @@ struct MessageColors;
class MessageLayoutElement
{
public:
MessageLayoutElement(MessageElement &creator_, const QSize &size);
MessageLayoutElement(MessageElement &creator_, QSizeF size);
virtual ~MessageLayoutElement();
MessageLayoutElement(const MessageLayoutElement &) = delete;
@@ -36,9 +36,9 @@ public:
bool reversedNeutral = false;
const QRect &getRect() const;
const QRectF &getRect() const;
MessageElement &getCreator() const;
void setPosition(QPoint point);
void setPosition(QPointF point);
bool hasTrailingSpace() const;
size_t getLine() const;
void setLine(size_t line);
@@ -58,9 +58,9 @@ public:
virtual void paint(QPainter &painter,
const MessageColors &messageColors) = 0;
/// @returns true if anything was painted
virtual bool paintAnimated(QPainter &painter, int yOffset) = 0;
virtual int getMouseOverIndex(const QPoint &abs) const = 0;
virtual int getXFromIndex(size_t index) = 0;
virtual bool paintAnimated(QPainter &painter, qreal yOffset) = 0;
virtual int getMouseOverIndex(QPointF abs) const = 0;
virtual qreal getXFromIndex(size_t index) = 0;
/// @brief Returns the link this layout element has
///
@@ -79,7 +79,7 @@ protected:
private:
QString text_;
QRect rect_;
QRectF rect_;
std::optional<Link> link_;
MessageElement &creator_;
/**
@@ -99,17 +99,16 @@ private:
class ImageLayoutElement : public MessageLayoutElement
{
public:
ImageLayoutElement(MessageElement &creator, ImagePtr image,
const QSize &size);
ImageLayoutElement(MessageElement &creator, ImagePtr image, QSizeF size);
protected:
void addCopyTextToString(QString &str, uint32_t from = 0,
uint32_t to = UINT32_MAX) const override;
size_t getSelectionIndexCount() const override;
void paint(QPainter &painter, const MessageColors &messageColors) override;
bool paintAnimated(QPainter &painter, int yOffset) override;
int getMouseOverIndex(const QPoint &abs) const override;
int getXFromIndex(size_t index) override;
bool paintAnimated(QPainter &painter, qreal yOffset) override;
int getMouseOverIndex(QPointF abs) const override;
qreal getXFromIndex(size_t index) override;
ImagePtr image_;
};
@@ -119,26 +118,26 @@ class LayeredImageLayoutElement : public MessageLayoutElement
public:
LayeredImageLayoutElement(MessageElement &creator,
std::vector<ImagePtr> images,
std::vector<QSize> sizes, QSize largestSize);
std::vector<QSizeF> sizes, QSizeF largestSize);
protected:
void addCopyTextToString(QString &str, uint32_t from = 0,
uint32_t to = UINT32_MAX) const override;
size_t getSelectionIndexCount() const override;
void paint(QPainter &painter, const MessageColors &messageColors) override;
bool paintAnimated(QPainter &painter, int yOffset) override;
int getMouseOverIndex(const QPoint &abs) const override;
int getXFromIndex(size_t index) override;
bool paintAnimated(QPainter &painter, qreal yOffset) override;
int getMouseOverIndex(QPointF abs) const override;
qreal getXFromIndex(size_t index) override;
std::vector<ImagePtr> images_;
std::vector<QSize> sizes_;
std::vector<QSizeF> sizes_;
};
class ImageWithBackgroundLayoutElement : public ImageLayoutElement
{
public:
ImageWithBackgroundLayoutElement(MessageElement &creator, ImagePtr image,
const QSize &size, QColor color);
QSizeF size, QColor color);
protected:
void paint(QPainter &painter, const MessageColors &messageColors) override;
@@ -168,18 +167,17 @@ 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, QSizeF size,
QColor color_, FontStyle style_, float scale_);
protected:
void addCopyTextToString(QString &str, uint32_t from = 0,
uint32_t to = UINT32_MAX) const override;
size_t getSelectionIndexCount() const override;
void paint(QPainter &painter, const MessageColors &messageColors) override;
bool paintAnimated(QPainter &painter, int yOffset) override;
int getMouseOverIndex(const QPoint &abs) const override;
int getXFromIndex(size_t index) override;
bool paintAnimated(QPainter &painter, qreal yOffset) override;
int getMouseOverIndex(QPointF abs) const override;
qreal getXFromIndex(size_t index) override;
QColor color_;
FontStyle style_;
@@ -192,16 +190,16 @@ class TextIconLayoutElement : public MessageLayoutElement
{
public:
TextIconLayoutElement(MessageElement &creator_, const QString &line1,
const QString &line2, float scale, const QSize &size);
const QString &line2, float scale, QSizeF size);
protected:
void addCopyTextToString(QString &str, uint32_t from = 0,
uint32_t to = UINT32_MAX) const override;
size_t getSelectionIndexCount() const override;
void paint(QPainter &painter, const MessageColors &messageColors) override;
bool paintAnimated(QPainter &painter, int yOffset) override;
int getMouseOverIndex(const QPoint &abs) const override;
int getXFromIndex(size_t index) override;
bool paintAnimated(QPainter &painter, qreal yOffset) override;
int getMouseOverIndex(QPointF abs) const override;
qreal getXFromIndex(size_t index) override;
private:
float scale;
@@ -212,14 +210,14 @@ private:
class ReplyCurveLayoutElement : public MessageLayoutElement
{
public:
ReplyCurveLayoutElement(MessageElement &creator, int width, float thickness,
float radius, float neededMargin);
ReplyCurveLayoutElement(MessageElement &creator, qreal width,
float thickness, float radius, float neededMargin);
protected:
void paint(QPainter &painter, const MessageColors &messageColors) override;
bool paintAnimated(QPainter &painter, int yOffset) override;
int getMouseOverIndex(const QPoint &abs) const override;
int getXFromIndex(size_t index) override;
bool paintAnimated(QPainter &painter, qreal yOffset) override;
int getMouseOverIndex(QPointF abs) const override;
qreal getXFromIndex(size_t index) override;
void addCopyTextToString(QString &str, uint32_t from = 0,
uint32_t to = UINT32_MAX) const override;
size_t getSelectionIndexCount() const override;
+1 -1
View File
@@ -202,7 +202,7 @@ QFont Fonts::getFont(FontStyle type, float scale)
return this->getOrCreateFontData(type, scale).font;
}
QFontMetrics Fonts::getFontMetrics(FontStyle type, float scale)
QFontMetricsF Fonts::getFontMetrics(FontStyle type, float scale)
{
return this->getOrCreateFontData(type, scale).metrics;
}
+2 -2
View File
@@ -46,7 +46,7 @@ public:
// font data gets set in createFontData(...)
QFont getFont(FontStyle type, float scale);
QFontMetrics getFontMetrics(FontStyle type, float scale);
QFontMetricsF getFontMetrics(FontStyle type, float scale);
pajlada::Signals::NoArgSignal fontChanged;
@@ -59,7 +59,7 @@ private:
}
const QFont font;
const QFontMetrics metrics;
const QFontMetricsF metrics;
};
struct ChatFontData {
+7 -7
View File
@@ -101,8 +101,8 @@ void Label::paintEvent(QPaintEvent *)
{
QPainter painter(this);
QFontMetrics metrics = getApp()->getFonts()->getFontMetrics(
this->getFontStyle(), this->scale());
auto metrics = getApp()->getFonts()->getFontMetrics(this->getFontStyle(),
this->scale());
painter.setFont(
getApp()->getFonts()->getFont(this->getFontStyle(), this->scale()));
@@ -111,7 +111,7 @@ void Label::paintEvent(QPaintEvent *)
// draw text
QRect textRect(offset, 0, this->width() - offset - offset, this->height());
int width = metrics.horizontalAdvance(this->text_);
int width = static_cast<int>(metrics.horizontalAdvance(this->text_));
Qt::Alignment alignment = !this->centered_ || width > textRect.width()
? Qt::AlignLeft | Qt::AlignVCenter
: Qt::AlignCenter;
@@ -137,13 +137,13 @@ void Label::paintEvent(QPaintEvent *)
void Label::updateSize()
{
QFontMetrics metrics =
auto metrics =
getApp()->getFonts()->getFontMetrics(this->fontStyle_, this->scale());
int width =
auto width =
metrics.horizontalAdvance(this->text_) + (2 * this->getOffset());
int height = metrics.height();
this->preferedSize_ = QSize(width, height);
auto height = metrics.height();
this->preferedSize_ = QSizeF(width, height).toSize();
this->updateGeometry();
}
+33 -21
View File
@@ -699,8 +699,8 @@ void ChannelView::layoutVisibleMessages(
if (messages.size() > start)
{
auto y = int(-(messages[start]->getHeight() *
(fmod(this->scrollBar_->getRelativeCurrentValue(), 1))));
auto y = -(messages[start]->getHeight() *
(fmod(this->scrollBar_->getRelativeCurrentValue(), 1)));
for (auto i = start; i < messages.size() && y <= this->height(); i++)
{
@@ -739,7 +739,7 @@ void ChannelView::updateScrollbar(
}
/// Layout the messages at the bottom
auto h = this->height() - 8;
qreal h = this->height() - 8;
auto flags = this->getFlags();
auto layoutWidth = this->getLayoutWidth();
auto showScrollbar = false;
@@ -765,8 +765,8 @@ void ChannelView::updateScrollbar(
if (h < 0) // break condition
{
this->scrollBar_->setPageSize(
(messages.size() - i) +
qreal(h) / std::max<int>(1, message->getHeight()));
static_cast<qreal>(messages.size() - i) +
(h / std::max(1.0, message->getHeight())));
showScrollbar = true;
break;
@@ -1610,14 +1610,15 @@ void ChannelView::drawMessages(QPainter &painter, const QRect &area)
.isMentions = this->underlyingChannel_ ==
getApp()->getTwitch()->getMentionsChannel(),
.y = int(-(messagesSnapshot[start]->getHeight() *
(fmod(this->scrollBar_->getRelativeCurrentValue(), 1)))),
.y = -(messagesSnapshot[start]->getHeight() *
(fmod(this->scrollBar_->getRelativeCurrentValue(), 1))),
.messageIndex = start,
.isLastReadMessage = false,
};
bool showLastMessageIndicator = getSettings()->showLastMessageIndicator;
// using QRect here, because we can only request updates with a rect
QRect animationArea;
auto areaContainsY = [&area](auto y) {
return y >= area.y() && y < area.y() + area.height();
@@ -1645,21 +1646,32 @@ void ChannelView::drawMessages(QPainter &painter, const QRect &area)
{
if (animationArea.isNull())
{
animationArea = QRect{0, ctx.y, layout->getWidth(),
layout->getHeight()};
animationArea = QRect{
0,
static_cast<int>(ctx.y),
static_cast<int>(layout->getWidth()),
static_cast<int>(layout->getHeight()),
};
}
else
{
animationArea.setBottom(ctx.y + layout->getHeight());
animationArea.setBottom(
static_cast<int>(ctx.y + layout->getHeight()));
animationArea.setWidth(
std::max(layout->getWidth(), animationArea.width()));
std::max(static_cast<int>(layout->getWidth()),
animationArea.width()));
}
}
if (this->highlightedMessage_ == layout)
{
painter.fillRect(
0, ctx.y, layout->getWidth(), layout->getHeight(),
QRectF{
0,
ctx.y,
layout->getWidth(),
layout->getHeight(),
},
this->highlightAnimation_.currentValue().value<QColor>());
if (this->highlightAnimation_.state() ==
QVariantAnimation::Stopped)
@@ -1944,7 +1956,7 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event)
}
std::shared_ptr<MessageLayout> layout;
QPoint relativePos;
QPointF relativePos;
int messageIndex;
// no message under cursor
@@ -2138,7 +2150,7 @@ void ChannelView::mousePressEvent(QMouseEvent *event)
this->mouseDown.invoke(event);
std::shared_ptr<MessageLayout> layout;
QPoint relativePos;
QPointF relativePos;
int messageIndex;
if (!tryGetMessageAt(event->pos(), layout, relativePos, messageIndex))
@@ -2244,7 +2256,7 @@ void ChannelView::mouseReleaseEvent(QMouseEvent *event)
this->queueLayout();
std::shared_ptr<MessageLayout> layout;
QPoint relativePos;
QPointF relativePos;
int messageIndex;
bool foundElement =
@@ -2801,7 +2813,7 @@ void ChannelView::mouseDoubleClickEvent(QMouseEvent *event)
}
std::shared_ptr<MessageLayout> layout;
QPoint relativePos;
QPointF relativePos;
int messageIndex;
if (!tryGetMessageAt(event->pos(), layout, relativePos, messageIndex))
@@ -3053,9 +3065,9 @@ void ChannelView::handleLinkClick(QMouseEvent *event, const Link &link,
}
}
bool ChannelView::tryGetMessageAt(QPoint p,
bool ChannelView::tryGetMessageAt(QPointF p,
std::shared_ptr<MessageLayout> &_message,
QPoint &relativePos, int &index)
QPointF &relativePos, int &index)
{
auto &messagesSnapshot = this->getMessagesSnapshot();
@@ -3066,8 +3078,8 @@ bool ChannelView::tryGetMessageAt(QPoint p,
return false;
}
int y = -(messagesSnapshot[start]->getHeight() *
(fmod(this->scrollBar_->getRelativeCurrentValue(), 1)));
qreal y = -(messagesSnapshot[start]->getHeight() *
(fmod(this->scrollBar_->getRelativeCurrentValue(), 1)));
for (size_t i = start; i < messagesSnapshot.size(); ++i)
{
@@ -3075,7 +3087,7 @@ bool ChannelView::tryGetMessageAt(QPoint p,
if (p.y() < y + message->getHeight())
{
relativePos = QPoint(p.x(), p.y() - y);
relativePos = QPointF(p.x(), p.y() - y);
_message = message;
index = i;
return true;
+2 -2
View File
@@ -258,8 +258,8 @@ protected:
void handleLinkClick(QMouseEvent *event, const Link &link,
MessageLayout *layout);
bool tryGetMessageAt(QPoint p, std::shared_ptr<MessageLayout> &message,
QPoint &relativePos, int &index);
bool tryGetMessageAt(QPointF p, std::shared_ptr<MessageLayout> &message,
QPointF &relativePos, int &index);
private:
struct InternalCtor {
+6 -7
View File
@@ -232,19 +232,19 @@ int NotebookTab::normalTabWidthForHeight(int height) const
float scale = this->scale();
int width = 0;
QFontMetrics metrics =
auto metrics =
getApp()->getFonts()->getFontMetrics(FontStyle::UiTabs, scale);
float compactDivider = getCompactDivider(getSettings()->tabStyle);
if (this->hasXButton())
{
width = (metrics.horizontalAdvance(this->getTitle()) +
int(32 / compactDivider * scale));
width = static_cast<int>(metrics.horizontalAdvance(this->getTitle()) +
(32 / compactDivider * scale));
}
else
{
width = (metrics.horizontalAdvance(this->getTitle()) +
int(16 / compactDivider * scale));
width = static_cast<int>(metrics.horizontalAdvance(this->getTitle()) +
(16 / compactDivider * scale));
}
if (static_cast<float>(height) > 150 * scale)
@@ -679,8 +679,7 @@ void NotebookTab::paintEvent(QPaintEvent *)
float scale = this->scale();
painter.setFont(app->getFonts()->getFont(FontStyle::UiTabs, scale));
QFontMetrics metrics =
app->getFonts()->getFontMetrics(FontStyle::UiTabs, scale);
auto metrics = app->getFonts()->getFontMetrics(FontStyle::UiTabs, scale);
int height = int(scale * NOTEBOOK_TAB_HEIGHT);