Returned render color theme in main menu when background is filled.

This commit is contained in:
23rd 2019-05-31 20:53:00 +03:00
parent 9871184953
commit b45705f39d
3 changed files with 36 additions and 3 deletions

View file

@ -49,6 +49,20 @@ inline bool AreTestingTheme() {
return !GlobalApplying.paletteForRevert.isEmpty();
};
bool CalculateIsMonoColorImage(const QImage &image) {
if (!image.isNull()) {
const auto bits = reinterpret_cast<const uint32*>(image.constBits());
const auto first = bits[0];
for (auto i = 0; i < image.width() * image.height(); i++) {
if (first != bits[i]) {
return false;
}
}
return true;
}
return false;
}
QByteArray readThemeContent(const QString &path) {
QFile file(path);
if (!file.exists()) {
@ -580,6 +594,7 @@ void ChatBackground::preparePixmaps(QImage image) {
}
_pixmapForTiled = App::pixmapFromImageInPlace(std::move(imageForTiled));
}
_isMonoColorImage = CalculateIsMonoColorImage(image);
_pixmap = App::pixmapFromImageInPlace(std::move(image));
if (!isSmallForTiled) {
_pixmapForTiled = _pixmap;
@ -671,6 +686,10 @@ bool ChatBackground::tileNight() const {
return _tileNightValue;
}
bool ChatBackground::isMonoColorImage() const {
return _isMonoColorImage;
}
void ChatBackground::ensureStarted() {
if (_pixmap.isNull() && !_paper.backgroundColor()) {
// We should start first, otherwise the default call

View file

@ -126,6 +126,7 @@ public:
[[nodiscard]] bool tile() const;
[[nodiscard]] bool tileDay() const;
[[nodiscard]] bool tileNight() const;
[[nodiscard]] bool isMonoColorImage() const;
private:
struct AdjustableColor {
@ -174,6 +175,8 @@ private:
bool _tileDayValue = false;
bool _tileNightValue = true;
bool _isMonoColorImage = false;
QString _themeAbsolutePath;
QImage _themeImage;
bool _themeTile = false;

View file

@ -331,7 +331,14 @@ void MainMenu::paintEvent(QPaintEvent *e) {
const auto cover = QRect(0, 0, width(), st::mainMenuCoverHeight)
.intersected(e->rect());
if (!_background.isNull()) {
const auto background = Window::Theme::Background();
const auto isFill = background->tile()
|| background->colorForFill().has_value()
|| background->isMonoColorImage()
|| background->paper().isPattern()
|| Data::IsLegacy1DefaultWallPaper(background->paper());
if (!isFill && !_background.isNull()) {
PainterHighQualityEnabler hq(p);
p.drawImage(0, 0, _background);
}
@ -340,6 +347,10 @@ void MainMenu::paintEvent(QPaintEvent *e) {
const auto widthText = _cloudButton
? _cloudButton->x() - st::mainMenuCloudSize
: width() - 2 * st::mainMenuCoverTextLeft;
if (isFill) {
p.fillRect(cover, st::mainMenuCoverBg);
}
p.setPen(st::mainMenuCoverFg);
p.setFont(st::semiboldFont);
Auth().user()->nameText.drawLeftElided(
@ -357,8 +368,8 @@ void MainMenu::paintEvent(QPaintEvent *e) {
_cloudButton->y() + (_cloudButton->height() - st::mainMenuCloudSize) / 2,
width(),
st::mainMenuCloudSize,
st::msgServiceBg,
st::mainMenuCloudFg);
isFill ? st::mainMenuCloudBg : st::msgServiceBg,
isFill ? st::mainMenuCloudFg : st::msgServiceFg);
}
}
auto other = QRect(0, st::mainMenuCoverHeight, width(), height() - st::mainMenuCoverHeight).intersected(clip);