Use black icon for support mode (support).
This commit is contained in:
		
							parent
							
								
									6ba0755e15
								
							
						
					
					
						commit
						a27e9ad734
					
				
					 5 changed files with 91 additions and 11 deletions
				
			
		| 
						 | 
					@ -19,8 +19,7 @@ PreLaunchWindow *PreLaunchWindowInstance = nullptr;
 | 
				
			||||||
PreLaunchWindow::PreLaunchWindow(QString title) {
 | 
					PreLaunchWindow::PreLaunchWindow(QString title) {
 | 
				
			||||||
	Fonts::Start();
 | 
						Fonts::Start();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	auto icon = Window::CreateIcon();
 | 
						setWindowIcon(Window::CreateIcon());
 | 
				
			||||||
	setWindowIcon(icon);
 | 
					 | 
				
			||||||
	setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint);
 | 
						setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	setWindowTitle(title.isEmpty() ? qsl("Telegram") : title);
 | 
						setWindowTitle(title.isEmpty() ? qsl("Telegram") : title);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -874,6 +874,9 @@ QImage MainWindow::iconWithCounter(int size, int count, style::color bg, style::
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	QImage img(smallIcon ? ((size == 16) ? iconbig16 : (size == 32 ? iconbig32 : iconbig64)) : ((size == 16) ? icon16 : (size == 32 ? icon32 : icon64)));
 | 
						QImage img(smallIcon ? ((size == 16) ? iconbig16 : (size == 32 ? iconbig32 : iconbig64)) : ((size == 16) ? icon16 : (size == 32 ? icon32 : icon64)));
 | 
				
			||||||
 | 
						if (AuthSession::Exists() && Auth().supportMode()) {
 | 
				
			||||||
 | 
							Window::ConvertIconToBlack(img);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	if (!count) return img;
 | 
						if (!count) return img;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (smallIcon) {
 | 
						if (smallIcon) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -573,8 +573,8 @@ void Messenger::startLocalStorage() {
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
	subscribe(authSessionChanged(), [this] {
 | 
						subscribe(authSessionChanged(), [=] {
 | 
				
			||||||
		InvokeQueued(this, [this] {
 | 
							InvokeQueued(this, [=] {
 | 
				
			||||||
			const auto phone = AuthSession::Exists()
 | 
								const auto phone = AuthSession::Exists()
 | 
				
			||||||
				? Auth().user()->phone()
 | 
									? Auth().user()->phone()
 | 
				
			||||||
				: QString();
 | 
									: QString();
 | 
				
			||||||
| 
						 | 
					@ -588,6 +588,7 @@ void Messenger::startLocalStorage() {
 | 
				
			||||||
			if (_mtproto) {
 | 
								if (_mtproto) {
 | 
				
			||||||
				_mtproto->requestConfig();
 | 
									_mtproto->requestConfig();
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
								qApp->setWindowIcon(Window::CreateIcon());
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -24,6 +24,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 | 
				
			||||||
#include "styles/style_window.h"
 | 
					#include "styles/style_window.h"
 | 
				
			||||||
#include "styles/style_boxes.h"
 | 
					#include "styles/style_boxes.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef small
 | 
				
			||||||
 | 
					#undef small
 | 
				
			||||||
 | 
					#endif // small
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace Window {
 | 
					namespace Window {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
constexpr auto kInactivePressTimeout = TimeMs(200);
 | 
					constexpr auto kInactivePressTimeout = TimeMs(200);
 | 
				
			||||||
| 
						 | 
					@ -37,12 +41,70 @@ QImage LoadLogoNoMargin() {
 | 
				
			||||||
	return QImage(qsl(":/gui/art/logo_256_no_margin.png"));
 | 
						return QImage(qsl(":/gui/art/logo_256_no_margin.png"));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void ConvertIconToBlack(QImage &image) {
 | 
				
			||||||
 | 
						if (image.format() != QImage::Format_ARGB32_Premultiplied) {
 | 
				
			||||||
 | 
							image = std::move(image).convertToFormat(
 | 
				
			||||||
 | 
								QImage::Format_ARGB32_Premultiplied);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						//const auto gray = red * 0.299 + green * 0.587 + blue * 0.114;
 | 
				
			||||||
 | 
						//const auto result = (gray - 100 < 0) ? 0 : (gray - 100) * 255 / 155;
 | 
				
			||||||
 | 
						constexpr auto scale = 255 / 155.;
 | 
				
			||||||
 | 
						constexpr auto red = 0.299;
 | 
				
			||||||
 | 
						constexpr auto green = 0.587;
 | 
				
			||||||
 | 
						constexpr auto blue = 0.114;
 | 
				
			||||||
 | 
						static constexpr auto shift = (1 << 24);
 | 
				
			||||||
 | 
						auto shifter = [](double value) {
 | 
				
			||||||
 | 
							return uint32(value * shift);
 | 
				
			||||||
 | 
						};
 | 
				
			||||||
 | 
						constexpr auto iscale = shifter(scale);
 | 
				
			||||||
 | 
						constexpr auto ired = shifter(red);
 | 
				
			||||||
 | 
						constexpr auto igreen = shifter(green);
 | 
				
			||||||
 | 
						constexpr auto iblue = shifter(blue);
 | 
				
			||||||
 | 
						constexpr auto threshold = 100;
 | 
				
			||||||
 | 
						constexpr auto ithreshold = shifter(threshold);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						const auto width = image.width();
 | 
				
			||||||
 | 
						const auto height = image.height();
 | 
				
			||||||
 | 
						const auto data = reinterpret_cast<uint32*>(image.bits());
 | 
				
			||||||
 | 
						const auto intsPerLine = image.bytesPerLine() / 4;
 | 
				
			||||||
 | 
						const auto intsPerLineAdded = intsPerLine - width;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						auto pixel = data;
 | 
				
			||||||
 | 
						for (auto j = 0; j != height; ++j) {
 | 
				
			||||||
 | 
							for (auto i = 0; i != width; ++i) {
 | 
				
			||||||
 | 
								const auto value = *pixel;
 | 
				
			||||||
 | 
								const auto gray = (((value >> 16) & 0xFF) * ired
 | 
				
			||||||
 | 
									+ ((value >> 8) & 0xFF) * igreen
 | 
				
			||||||
 | 
									+ (value & 0xFF) * iblue) >> 24;
 | 
				
			||||||
 | 
								const auto small = gray - threshold;
 | 
				
			||||||
 | 
								const auto test = ~small;
 | 
				
			||||||
 | 
								const auto result = (test >> 31) * small * iscale;
 | 
				
			||||||
 | 
								const auto component = (result >> 24) & 0xFF;
 | 
				
			||||||
 | 
								*pixel++ = (value & 0xFF000000U)
 | 
				
			||||||
 | 
									| (component << 16)
 | 
				
			||||||
 | 
									| (component << 8)
 | 
				
			||||||
 | 
									| component;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							pixel += intsPerLineAdded;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
QIcon CreateOfficialIcon() {
 | 
					QIcon CreateOfficialIcon() {
 | 
				
			||||||
	auto useNoMarginLogo = (cPlatform() == dbipMac);
 | 
						auto useNoMarginLogo = (cPlatform() == dbipMac);
 | 
				
			||||||
	if (auto messenger = Messenger::InstancePointer()) {
 | 
						auto image = [&] {
 | 
				
			||||||
		return QIcon(App::pixmapFromImageInPlace(useNoMarginLogo ? messenger->logoNoMargin() : messenger->logo()));
 | 
							if (const auto messenger = Messenger::InstancePointer()) {
 | 
				
			||||||
 | 
								return useNoMarginLogo
 | 
				
			||||||
 | 
									? messenger->logoNoMargin()
 | 
				
			||||||
 | 
									: messenger->logo();
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							return useNoMarginLogo
 | 
				
			||||||
 | 
								? LoadLogoNoMargin()
 | 
				
			||||||
 | 
								: LoadLogo();
 | 
				
			||||||
 | 
						}();
 | 
				
			||||||
 | 
						if (AuthSession::Exists() && Auth().supportMode()) {
 | 
				
			||||||
 | 
							ConvertIconToBlack(image);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return QIcon(App::pixmapFromImageInPlace(useNoMarginLogo ? LoadLogoNoMargin() : LoadLogo()));
 | 
						return QIcon(App::pixmapFromImageInPlace(std::move(image)));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
QIcon CreateIcon() {
 | 
					QIcon CreateIcon() {
 | 
				
			||||||
| 
						 | 
					@ -58,14 +120,22 @@ MainWindow::MainWindow()
 | 
				
			||||||
, _body(this)
 | 
					, _body(this)
 | 
				
			||||||
, _icon(CreateIcon())
 | 
					, _icon(CreateIcon())
 | 
				
			||||||
, _titleText(qsl("Telegram")) {
 | 
					, _titleText(qsl("Telegram")) {
 | 
				
			||||||
	subscribe(Theme::Background(), [this](const Theme::BackgroundUpdate &data) {
 | 
						subscribe(Theme::Background(), [=](
 | 
				
			||||||
 | 
								const Theme::BackgroundUpdate &data) {
 | 
				
			||||||
		if (data.paletteChanged()) {
 | 
							if (data.paletteChanged()) {
 | 
				
			||||||
			updatePalette();
 | 
								updatePalette();
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
	subscribe(Global::RefUnreadCounterUpdate(), [this] { updateUnreadCounter(); });
 | 
						subscribe(Global::RefUnreadCounterUpdate(), [=] {
 | 
				
			||||||
	subscribe(Global::RefWorkMode(), [this](DBIWorkMode mode) { workmodeUpdated(mode); });
 | 
							updateUnreadCounter();
 | 
				
			||||||
	subscribe(Messenger::Instance().authSessionChanged(), [this] { checkAuthSession(); });
 | 
						});
 | 
				
			||||||
 | 
						subscribe(Global::RefWorkMode(), [=](DBIWorkMode mode) {
 | 
				
			||||||
 | 
							workmodeUpdated(mode);
 | 
				
			||||||
 | 
						});
 | 
				
			||||||
 | 
						subscribe(Messenger::Instance().authSessionChanged(), [=] {
 | 
				
			||||||
 | 
							checkAuthSession();
 | 
				
			||||||
 | 
							updateWindowIcon();
 | 
				
			||||||
 | 
						});
 | 
				
			||||||
	checkAuthSession();
 | 
						checkAuthSession();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	Messenger::Instance().termsLockValue(
 | 
						Messenger::Instance().termsLockValue(
 | 
				
			||||||
| 
						 | 
					@ -194,6 +264,11 @@ bool MainWindow::computeIsActive() const {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void MainWindow::updateWindowIcon() {
 | 
					void MainWindow::updateWindowIcon() {
 | 
				
			||||||
 | 
						const auto supportIcon = AuthSession::Exists() && Auth().supportMode();
 | 
				
			||||||
 | 
						if (supportIcon != _usingSupportIcon) {
 | 
				
			||||||
 | 
							_icon = CreateIcon();
 | 
				
			||||||
 | 
							_usingSupportIcon = supportIcon;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	setWindowIcon(_icon);
 | 
						setWindowIcon(_icon);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -23,6 +23,7 @@ struct TermsLock;
 | 
				
			||||||
QImage LoadLogo();
 | 
					QImage LoadLogo();
 | 
				
			||||||
QImage LoadLogoNoMargin();
 | 
					QImage LoadLogoNoMargin();
 | 
				
			||||||
QIcon CreateIcon();
 | 
					QIcon CreateIcon();
 | 
				
			||||||
 | 
					void ConvertIconToBlack(QImage &image);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class MainWindow : public Ui::RpWidget, protected base::Subscriber {
 | 
					class MainWindow : public Ui::RpWidget, protected base::Subscriber {
 | 
				
			||||||
	Q_OBJECT
 | 
						Q_OBJECT
 | 
				
			||||||
| 
						 | 
					@ -165,6 +166,7 @@ private:
 | 
				
			||||||
	QPointer<BoxContent> _termsBox;
 | 
						QPointer<BoxContent> _termsBox;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	QIcon _icon;
 | 
						QIcon _icon;
 | 
				
			||||||
 | 
						bool _usingSupportIcon = false;
 | 
				
			||||||
	QString _titleText;
 | 
						QString _titleText;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	bool _isActive = false;
 | 
						bool _isActive = false;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue