mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2026-07-25 15:04:57 +00:00
Added support of profile color to top bar for gradient backgrounds.
This commit is contained in:
@@ -369,7 +369,8 @@ void TopBar::updateCollectibleStatus() {
|
||||
const auto collectible = _peer->emojiStatusId().collectible;
|
||||
const auto colorProfile
|
||||
= _peer->session().api().peerColors().colorProfileFor(_peer);
|
||||
_hasCollectible = collectible != nullptr;
|
||||
_hasGradientBg = (collectible != nullptr)
|
||||
|| (colorProfile && colorProfile->bg.size() > 1);
|
||||
_solidBg = (colorProfile && colorProfile->bg.size() == 1)
|
||||
? std::make_optional(colorProfile->bg.front())
|
||||
: std::nullopt;
|
||||
@@ -394,7 +395,7 @@ void TopBar::updateCollectibleStatus() {
|
||||
update();
|
||||
adjustColors(collectible
|
||||
? std::optional<QColor>(collectible->edgeColor)
|
||||
: colorProfile
|
||||
: (colorProfile && !colorProfile->bg.empty())
|
||||
? std::optional<QColor>(colorProfile->bg.front())
|
||||
: std::nullopt);
|
||||
}
|
||||
@@ -941,10 +942,10 @@ void TopBar::updateLabelsPosition() {
|
||||
|
||||
void TopBar::resizeEvent(QResizeEvent *e) {
|
||||
_cachedClipPath = QPainterPath();
|
||||
if (_hasCollectible && !_animatedPoints.empty()) {
|
||||
if (_peer->emojiStatusId().collectible && !_animatedPoints.empty()) {
|
||||
setupAnimatedPattern();
|
||||
}
|
||||
if (_hasCollectible && e->oldSize().width() != e->size().width()) {
|
||||
if (_hasGradientBg && e->oldSize().width() != e->size().width()) {
|
||||
_cachedClipPath = QPainterPath();
|
||||
_cachedGradient = QImage();
|
||||
}
|
||||
@@ -1040,7 +1041,7 @@ void TopBar::paintEvent(QPaintEvent *e) {
|
||||
auto p = QPainter(this);
|
||||
const auto geometry = userpicGeometry();
|
||||
|
||||
if (_hasCollectible && _cachedGradient.isNull()) {
|
||||
if (_hasGradientBg && _cachedGradient.isNull()) {
|
||||
_cachedGradient = Ui::CreateTopBgGradient(
|
||||
QSize(width(), maximumHeight()),
|
||||
_peer,
|
||||
@@ -1050,7 +1051,7 @@ void TopBar::paintEvent(QPaintEvent *e) {
|
||||
? -st::infoProfileTopBarPhotoBgShift
|
||||
: -st::infoProfileTopBarPhotoBgNoActionsShift));
|
||||
}
|
||||
if (!_hasCollectible) {
|
||||
if (!_hasGradientBg) {
|
||||
paintEdges(p);
|
||||
} else {
|
||||
const auto x = (width()
|
||||
|
||||
@@ -200,8 +200,7 @@ private:
|
||||
bool _roundEdges = true;
|
||||
|
||||
rpl::variable<std::optional<QColor>> _edgeColor;
|
||||
bool _hasBackground = false;
|
||||
bool _hasCollectible = false;
|
||||
bool _hasGradientBg = false;
|
||||
std::optional<QColor> _solidBg;
|
||||
QImage _cachedGradient;
|
||||
QPainterPath _cachedClipPath;
|
||||
|
||||
@@ -7,11 +7,14 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#include "ui/top_background_gradient.h"
|
||||
|
||||
#include "apiwrap.h"
|
||||
#include "api/api_peer_colors.h"
|
||||
#include "data/data_emoji_statuses.h"
|
||||
#include "data/data_credits.h"
|
||||
#include "data/data_peer.h"
|
||||
#include "data/data_star_gift.h"
|
||||
#include "data/stickers/data_custom_emoji.h"
|
||||
#include "main/main_session.h"
|
||||
#include "ui/image/image_prepare.h"
|
||||
#include "ui/painter.h"
|
||||
#include "ui/rect.h"
|
||||
@@ -106,9 +109,19 @@ QImage CreateTopBgGradient(
|
||||
collectible->edgeColor,
|
||||
false,
|
||||
offset);
|
||||
} else {
|
||||
return QImage();
|
||||
}
|
||||
if (const auto color = peer->session().api().peerColors().colorProfileFor(
|
||||
peer)) {
|
||||
if (color->bg.size() > 1) {
|
||||
return CreateTopBgGradient(
|
||||
size,
|
||||
color->bg[1],
|
||||
color->bg[0],
|
||||
false,
|
||||
offset);
|
||||
}
|
||||
}
|
||||
return QImage();
|
||||
}
|
||||
|
||||
const std::vector<PatternPoint> &PatternBgPoints() {
|
||||
|
||||
Reference in New Issue
Block a user