Fix weather widget in stories.

This commit is contained in:
John Preston 2025-02-04 21:46:26 +04:00
parent 7ac849ab12
commit 8912d4d55a
2 changed files with 12 additions and 11 deletions

View file

@ -576,9 +576,10 @@ void WeatherView::setAreaGeometry(QRect geometry, float64 radius) {
const auto diagxdiag = (geometry.width() * geometry.width()) const auto diagxdiag = (geometry.width() * geometry.width())
+ (geometry.height() * geometry.height()); + (geometry.height() * geometry.height());
const auto diag = std::sqrt(diagxdiag); const auto diag = std::sqrt(diagxdiag);
const auto shift = diag * 2 / 3.;
const auto topleft = QRectF(geometry).center() const auto topleft = QRectF(geometry).center()
- QPointF(diag / 2., diag / 2.); - QPointF(shift, shift);
const auto bottomright = topleft + QPointF(diag, diag); const auto bottomright = topleft + QPointF(shift, shift) * 2;
const auto left = int(std::floor(topleft.x())); const auto left = int(std::floor(topleft.x()));
const auto top = int(std::floor(topleft.y())); const auto top = int(std::floor(topleft.y()));
const auto right = int(std::ceil(bottomright.x())); const auto right = int(std::ceil(bottomright.x()));
@ -701,7 +702,7 @@ void WeatherView::cacheBackground() {
p.translate(-center); p.translate(-center);
const auto format = [](float64 value) { const auto format = [](float64 value) {
return QString::number(int(base::SafeRound(value * 10)) / 10.); return QString::number(int(base::SafeRound(value)));
}; };
const auto text = [&] { const auto text = [&] {
const auto celsius = _data.millicelsius / 1000.; const auto celsius = _data.millicelsius / 1000.;
@ -712,11 +713,11 @@ void WeatherView::cacheBackground() {
return format(fahrenheit); return format(fahrenheit);
}().append(QChar(0xb0)).append(_celsius ? "C" : "F"); }().append(QChar(0xb0)).append(_celsius ? "C" : "F");
const auto metrics = QFontMetrics(_font); const auto metrics = QFontMetrics(_font);
const auto textWidth = metrics.horizontalAdvance(text); const auto textWidth = qCeil(metrics.horizontalAdvance(text));
_padding = int(_rect.height() / 6); _padding = int(_rect.height() / 5);
const auto fullWidth = (_emoji ? _emojiSize : 0) const auto fullWidth = (_emoji ? (_emojiSize - _padding) : 0)
+ textWidth + textWidth
+ (2 * _padding); + (4 * _padding);
const auto left = _rect.x() + (_rect.width() - fullWidth) / 2; const auto left = _rect.x() + (_rect.width() - fullWidth) / 2;
_wrapped = QRect(left, _rect.y(), fullWidth, _rect.height()); _wrapped = QRect(left, _rect.y(), fullWidth, _rect.height());
@ -725,7 +726,7 @@ void WeatherView::cacheBackground() {
p.setPen(_fg); p.setPen(_fg);
p.setFont(_font); p.setFont(_font);
p.drawText(_wrapped.marginsRemoved( p.drawText(_wrapped.marginsRemoved(
{ _padding + (_emoji ? _emojiSize : 0), 0, _padding, 0 }), { 2 * _padding + (_emoji ? (_emojiSize - _padding) : 0), 0, 2 * _padding, 0 }),
text, text,
style::al_center); style::al_center);
} }

View file

@ -24,10 +24,10 @@ std::optional<QColor> MaybeColorFromSerialized(quint32 serialized) {
QColor Color32FromSerialized(quint32 serialized) { QColor Color32FromSerialized(quint32 serialized) {
return QColor( return QColor(
int((serialized >> 24) & 0xFFU), int(serialized & 0xFFU),
int((serialized >> 16) & 0xFFU),
int((serialized >> 8) & 0xFFU), int((serialized >> 8) & 0xFFU),
int(serialized & 0xFFU)); int((serialized >> 16) & 0xFFU),
int((serialized >> 24) & 0xFFU));
} }
} // namespace Ui } // namespace Ui