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