mirror of https://github.com/procxx/kepka.git
Added background analysis in main menu for better readability.
This commit is contained in:
parent
08a3a5747a
commit
159f90a42c
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
Binary file not shown.
After Width: | Height: | Size: 1.6 KiB |
Binary file not shown.
After Width: | Height: | Size: 2.2 KiB |
|
@ -128,6 +128,7 @@ mainMenu: Menu(defaultMenu) {
|
||||||
}
|
}
|
||||||
itemToggleShift: 11px;
|
itemToggleShift: 11px;
|
||||||
}
|
}
|
||||||
|
mainMenuShadow: icon {{ "menu_shadow", windowShadowFg }};
|
||||||
mainMenuNewGroup: icon {{ "menu_new_group", menuIconFg }};
|
mainMenuNewGroup: icon {{ "menu_new_group", menuIconFg }};
|
||||||
mainMenuNewGroupOver: icon {{ "menu_new_group", menuIconFgOver }};
|
mainMenuNewGroupOver: icon {{ "menu_new_group", menuIconFgOver }};
|
||||||
mainMenuNewChannel: icon {{ "menu_new_channel", menuIconFg }};
|
mainMenuNewChannel: icon {{ "menu_new_channel", menuIconFg }};
|
||||||
|
|
|
@ -33,6 +33,30 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "styles/style_settings.h"
|
#include "styles/style_settings.h"
|
||||||
#include "styles/style_boxes.h"
|
#include "styles/style_boxes.h"
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
constexpr auto kMinDiffIntensity = 0.25;
|
||||||
|
|
||||||
|
float64 IntensityOfColor(QColor color) {
|
||||||
|
return (0.299 * color.red()
|
||||||
|
+ 0.587 * color.green()
|
||||||
|
+ 0.114 * color.blue()) / 255.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IsShadowShown(const QImage &img, const QRect r, float64 intensityText) {
|
||||||
|
for (auto x = r.x(); x < r.x() + r.width(); x++) {
|
||||||
|
for (auto y = r.y(); y < r.y() + r.height(); y++) {
|
||||||
|
const auto intensity = IntensityOfColor(QColor(img.pixel(x, y)));
|
||||||
|
if ((std::abs(intensity - intensityText)) < kMinDiffIntensity) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
namespace Window {
|
namespace Window {
|
||||||
|
|
||||||
class MainMenu::ResetScaleButton : public Ui::AbstractButton {
|
class MainMenu::ResetScaleButton : public Ui::AbstractButton {
|
||||||
|
@ -122,6 +146,7 @@ MainMenu::MainMenu(
|
||||||
Window::Theme::ToggleNightMode();
|
Window::Theme::ToggleNightMode();
|
||||||
Window::Theme::KeepApplied();
|
Window::Theme::KeepApplied();
|
||||||
}
|
}
|
||||||
|
refreshBackground();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -130,6 +155,7 @@ MainMenu::MainMenu(
|
||||||
emit action->triggered();
|
emit action->triggered();
|
||||||
});
|
});
|
||||||
refreshMenu();
|
refreshMenu();
|
||||||
|
refreshBackground();
|
||||||
|
|
||||||
_telegram->setRichText(textcmdLink(1, qsl("Telegram Desktop")));
|
_telegram->setRichText(textcmdLink(1, qsl("Telegram Desktop")));
|
||||||
_telegram->setLink(1, std::make_shared<UrlClickHandler>(qsl("https://desktop.telegram.org")));
|
_telegram->setLink(1, std::make_shared<UrlClickHandler>(qsl("https://desktop.telegram.org")));
|
||||||
|
@ -148,6 +174,7 @@ MainMenu::MainMenu(
|
||||||
subscribe(Window::Theme::Background(), [this](const Window::Theme::BackgroundUpdate &update) {
|
subscribe(Window::Theme::Background(), [this](const Window::Theme::BackgroundUpdate &update) {
|
||||||
if (update.type == Window::Theme::BackgroundUpdate::Type::ApplyingTheme) {
|
if (update.type == Window::Theme::BackgroundUpdate::Type::ApplyingTheme) {
|
||||||
refreshMenu();
|
refreshMenu();
|
||||||
|
refreshBackground();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
updatePhone();
|
updatePhone();
|
||||||
|
@ -220,6 +247,45 @@ void MainMenu::refreshMenu() {
|
||||||
updatePhone();
|
updatePhone();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainMenu::refreshBackground() {
|
||||||
|
const auto fill = QRect(0, 0, width(), st::mainMenuCoverHeight);
|
||||||
|
const auto intensityText = IntensityOfColor(st::mainMenuCoverFg->c);
|
||||||
|
QImage backgroundImage(
|
||||||
|
st::mainMenuWidth * cIntRetinaFactor(),
|
||||||
|
st::mainMenuCoverHeight * cIntRetinaFactor(),
|
||||||
|
QImage::Format_ARGB32_Premultiplied);
|
||||||
|
QPainter p(&backgroundImage);
|
||||||
|
|
||||||
|
// Solid color.
|
||||||
|
if (const auto color = Window::Theme::Background()->colorForFill()) {
|
||||||
|
const auto intensity = IntensityOfColor(*color);
|
||||||
|
_isShadowShown =
|
||||||
|
(std::abs(intensity - intensityText) < kMinDiffIntensity);
|
||||||
|
p.fillRect(fill, *color);
|
||||||
|
_background = backgroundImage;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Background image.
|
||||||
|
const auto &pixmap = Window::Theme::Background()->pixmap();
|
||||||
|
QRect to, from;
|
||||||
|
Window::Theme::ComputeBackgroundRects(fill, pixmap.size(), to, from);
|
||||||
|
|
||||||
|
p.drawPixmap(to, pixmap, from);
|
||||||
|
_background = backgroundImage;
|
||||||
|
|
||||||
|
// Cut off the part of the background that is under text.
|
||||||
|
const QRect underText(
|
||||||
|
st::mainMenuCoverTextLeft,
|
||||||
|
st::mainMenuCoverNameTop,
|
||||||
|
std::max(
|
||||||
|
st::semiboldFont->width(Auth().user()->nameText.toString()),
|
||||||
|
st::normalFont->width(_phoneText)),
|
||||||
|
st::semiboldFont->height * 2);
|
||||||
|
|
||||||
|
_isShadowShown = IsShadowShown(backgroundImage, underText, intensityText);
|
||||||
|
}
|
||||||
|
|
||||||
void MainMenu::resizeEvent(QResizeEvent *e) {
|
void MainMenu::resizeEvent(QResizeEvent *e) {
|
||||||
_menu->setForceWidth(width());
|
_menu->setForceWidth(width());
|
||||||
updateControlsGeometry();
|
updateControlsGeometry();
|
||||||
|
@ -248,25 +314,30 @@ void MainMenu::updatePhone() {
|
||||||
void MainMenu::paintEvent(QPaintEvent *e) {
|
void MainMenu::paintEvent(QPaintEvent *e) {
|
||||||
Painter p(this);
|
Painter p(this);
|
||||||
const auto clip = e->rect();
|
const auto clip = e->rect();
|
||||||
const auto fill = QRect(0, 0, width(), st::mainMenuCoverHeight);
|
const auto cover = QRect(0, 0, width(), st::mainMenuCoverHeight)
|
||||||
const auto cover = fill.intersected(clip);
|
.intersected(e->rect());
|
||||||
|
|
||||||
if (const auto color = Window::Theme::Background()->colorForFill()) {
|
if (!_background.isNull()) {
|
||||||
p.fillRect(fill, *color);
|
|
||||||
} else {
|
|
||||||
PainterHighQualityEnabler hq(p);
|
PainterHighQualityEnabler hq(p);
|
||||||
|
p.drawImage(0, 0, _background);
|
||||||
const auto &pix = Window::Theme::Background()->pixmap();
|
|
||||||
QRect to, from;
|
|
||||||
Window::Theme::ComputeBackgroundRects(fill, pix.size(), to, from);
|
|
||||||
p.drawPixmap(to, pix, from);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!cover.isEmpty()) {
|
if (!cover.isEmpty()) {
|
||||||
const auto widthText = _cloudButton
|
const auto widthText = _cloudButton
|
||||||
? _cloudButton->x() - st::mainMenuCloudSize
|
? _cloudButton->x() - st::mainMenuCloudSize
|
||||||
: width() - 2 * st::mainMenuCoverTextLeft;
|
: width() - 2 * st::mainMenuCoverTextLeft;
|
||||||
p.fillRect(cover, QColor(0, 0, 0, 51)); // 20% opacity.
|
|
||||||
|
if (_isShadowShown) {
|
||||||
|
st::mainMenuShadow.paint(
|
||||||
|
p,
|
||||||
|
0,
|
||||||
|
st::mainMenuCoverHeight - st::mainMenuShadow.height(),
|
||||||
|
st::mainMenuWidth,
|
||||||
|
IntensityOfColor(st::mainMenuCoverFg->c) < 0.5
|
||||||
|
? Qt::white
|
||||||
|
: Qt::black);
|
||||||
|
}
|
||||||
|
|
||||||
p.setPen(st::mainMenuCoverFg);
|
p.setPen(st::mainMenuCoverFg);
|
||||||
p.setFont(st::semiboldFont);
|
p.setFont(st::semiboldFont);
|
||||||
Auth().user()->nameText.drawLeftElided(
|
Auth().user()->nameText.drawLeftElided(
|
||||||
|
|
|
@ -38,6 +38,7 @@ private:
|
||||||
void updatePhone();
|
void updatePhone();
|
||||||
void initResetScaleButton();
|
void initResetScaleButton();
|
||||||
void refreshMenu();
|
void refreshMenu();
|
||||||
|
void refreshBackground();
|
||||||
|
|
||||||
class ResetScaleButton;
|
class ResetScaleButton;
|
||||||
not_null<Controller*> _controller;
|
not_null<Controller*> _controller;
|
||||||
|
@ -51,6 +52,8 @@ private:
|
||||||
base::Timer _nightThemeSwitch;
|
base::Timer _nightThemeSwitch;
|
||||||
|
|
||||||
QString _phoneText;
|
QString _phoneText;
|
||||||
|
QImage _background;
|
||||||
|
bool _isShadowShown = false;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue