Fix proxy icon on retina and on theme changes.

Fixes #4668.
This commit is contained in:
John Preston 2018-05-10 13:34:06 +03:00
parent 296e009808
commit 5c5bccae0b
1 changed files with 18 additions and 1 deletions

View File

@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/widgets/buttons.h"
#include "ui/effects/radial_animation.h"
#include "window/themes/window_theme.h"
#include "boxes/connection_box.h"
#include "lang/lang_keys.h"
#include "styles/style_window.h"
@ -65,7 +66,9 @@ void Progress::step(TimeMs ms, bool timer) {
} // namespace
class ConnectingWidget::ProxyIcon : public Ui::RpWidget {
class ConnectingWidget::ProxyIcon
: public Ui::RpWidget
, private base::Subscriber {
public:
ProxyIcon(QWidget *parent);
@ -76,6 +79,8 @@ protected:
void paintEvent(QPaintEvent *e) override;
private:
void refreshCacheImages();
float64 _opacity = 1.;
QPixmap _cacheOn;
QPixmap _cacheOff;
@ -92,10 +97,22 @@ ConnectingWidget::ProxyIcon::ProxyIcon(QWidget *parent) : RpWidget(parent) {
st::connectingRadial.size.height(),
st::connectingProxyOn.height()));
using namespace Window::Theme;
subscribe(Background(), [=](const BackgroundUpdate &update) {
if (update.paletteChanged()) {
refreshCacheImages();
}
});
refreshCacheImages();
}
void ConnectingWidget::ProxyIcon::refreshCacheImages() {
const auto prepareCache = [&](const style::icon &icon) {
auto image = QImage(
size() * cIntRetinaFactor(),
QImage::Format_ARGB32_Premultiplied);
image.setDevicePixelRatio(cRetinaFactor());
image.fill(st::windowBg->c);
{
Painter p(&image);