refactor: floatify messages (#6231)
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user