feat: refactor a bit

This commit is contained in:
ZavaruKitsu 2024-01-03 16:56:32 +03:00
parent 74196732ac
commit fba53e1ec8
7 changed files with 63 additions and 43 deletions

View file

@ -9,27 +9,12 @@
#include "lang_auto.h"
#include "ayu/libs/json.hpp"
#include "ayu/libs/json_ext.hpp"
#include "ayu/ui/ayu_assets.h"
#include "rpl/producer.h"
namespace AyuSettings
{
const auto DEFAULT_ICON = QString("default");
const auto ALT_ICON = QString("alt");
const auto DISCORD_ICON = QString("discord");
const auto SPOTIFY_ICON = QString("spotify");
const auto EXTERA_ICON = QString("extera");
const auto NOTHING_ICON = QString("nothing");
const auto BARD_ICON = QString("bard");
const auto YAPLUS_ICON = QString("yaplus");
class AyuGramSettings
{
public:
@ -56,12 +41,15 @@ public:
disableStories = false;
collapseSimilarChannels = true;
hideSimilarChannels = false;
uploadSpeedBoost = false;
disableNotificationsDelay = false;
localPremium = false;
copyUsernameAsLink = true;
// ~ Customization
appIcon = DEFAULT_ICON;
appIcon = AyuAssets::DEFAULT_ICON;
simpleQuotesAndReplies = true;
deletedMark = "🧹";
editedMark = tr::lng_edited(tr::now);

View file

@ -13,6 +13,9 @@ static QImage LAST_LOADED;
static QImage LAST_LOADED_NO_MARGIN;
namespace AyuAssets
{
void loadAppIco()
{
auto settings = &AyuSettings::getInstance();
@ -62,3 +65,5 @@ QImage currentAppLogoNoMargin()
loadIcons();
return LAST_LOADED_NO_MARGIN;
}
}

View file

@ -6,6 +6,27 @@
// Copyright @Radolyn, 2023
#pragma once
#define ICON(name, value) const auto name##_ICON = QStringLiteral(value)
namespace AyuAssets
{
ICON(DEFAULT, "default");
ICON(ALT, "alt");
ICON(DISCORD, "discord");
ICON(SPOTIFY, "spotify");
ICON(EXTERA, "extera");
ICON(NOTHING, "nothing");
ICON(BARD, "bard");
ICON(YAPLUS, "yaplus");
void loadAppIco();
QImage loadPreview(QString name);
@ -13,3 +34,5 @@ QImage loadPreview(QString name);
QString currentAppLogoName();
QImage currentAppLogo();
QImage currentAppLogoNoMargin();
}

View file

@ -21,14 +21,14 @@
#endif
const QVector<QString> icons{
AyuSettings::DEFAULT_ICON,
AyuSettings::ALT_ICON,
AyuSettings::DISCORD_ICON,
AyuSettings::SPOTIFY_ICON,
AyuSettings::EXTERA_ICON,
AyuSettings::NOTHING_ICON,
AyuSettings::BARD_ICON,
AyuSettings::YAPLUS_ICON
AyuAssets::DEFAULT_ICON,
AyuAssets::ALT_ICON,
AyuAssets::DISCORD_ICON,
AyuAssets::SPOTIFY_ICON,
AyuAssets::EXTERA_ICON,
AyuAssets::NOTHING_ICON,
AyuAssets::BARD_ICON,
AyuAssets::YAPLUS_ICON
};
const auto rows = static_cast<int>(icons.size()) / 4 + std::min(1, static_cast<int>(icons.size()) % 4);
@ -51,6 +51,19 @@ void drawIcon(QPainter &p, const QImage &icon, int xOffset, int yOffset, bool se
p.drawImage(rect, icon);
}
void applyIcon()
{
#ifdef Q_OS_WIN
AyuAssets::loadAppIco();
reloadAppIconFromTaskBar();
#endif
Window::OverrideApplicationIcon(AyuAssets::currentAppLogo());
Core::App().refreshApplicationIcon();
Core::App().tray().updateIconCounters();
Core::App().domain().notifyUnreadBadgeChanged();
}
IconPicker::IconPicker(QWidget *parent)
: RpWidget(parent)
{
@ -70,13 +83,13 @@ void IconPicker::paintEvent(QPaintEvent *e)
auto const idx = i + row * 4;
const auto &iconName = icons[idx];
auto icon = loadPreview(iconName)
auto icon = AyuAssets::loadPreview(iconName)
.scaled(st::cpIconSize, st::cpIconSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
drawIcon(p,
icon,
(st::cpIconSize + st::cpSpacingX) * i + offset,
row * (st::cpIconSize + st::cpSpacingY),
currentAppLogoName() == iconName);
AyuAssets::currentAppLogoName() == iconName);
}
}
}
@ -108,16 +121,7 @@ void IconPicker::mousePressEvent(QMouseEvent *e)
if (changed) {
AyuSettings::save();
#ifdef Q_OS_WIN
loadAppIco();
reloadAppIconFromTaskBar();
#endif
Window::OverrideApplicationIcon(currentAppLogo());
Core::App().refreshApplicationIcon();
Core::App().tray().updateIconCounters();
Core::App().domain().notifyUnreadBadgeChanged();
applyIcon();
repaint();
}

View file

@ -450,7 +450,7 @@ void Step::paintCover(QPainter &p, int top) {
planeLeft += deltaLeft;
// planeTop += top;
}
const auto ayuGramIcon = Ui::PixmapFromImage(currentAppLogo());
const auto ayuGramIcon = Ui::PixmapFromImage(AyuAssets::currentAppLogo());
QIcon(ayuGramIcon).paint(&p, QRect(width() / 2 - ayuGramIcon.width() / 2, planeTop - 16, ayuGramIcon.width(), st::introCoverIcon.height()));
}

View file

@ -121,9 +121,9 @@ constexpr auto kTooltipDelay = crl::time(10000);
static auto ScaledLogoNoMargin = base::flat_map<int, QImage>();
static auto ScaledLogoDark = base::flat_map<int, QImage>();
static auto ScaledLogoLight = base::flat_map<int, QImage>();
static auto lastUsedIcon = currentAppLogoName();
static auto lastUsedIcon = AyuAssets::currentAppLogoName();
if (lastUsedIcon != currentAppLogoName()) {
if (lastUsedIcon != AyuAssets::currentAppLogoName()) {
ScaledLogo = base::flat_map<int, QImage>();
ScaledLogoNoMargin = base::flat_map<int, QImage>();
ScaledLogoDark = base::flat_map<int, QImage>();

View file

@ -82,11 +82,11 @@ base::options::toggle OptionNewWindowsSizeAsFirst({
const char kOptionNewWindowsSizeAsFirst[] = "new-windows-size-as-first";
QImage Logo() {
return currentAppLogo();
return AyuAssets::currentAppLogo();
}
QImage LogoNoMargin() {
return currentAppLogoNoMargin();
return AyuAssets::currentAppLogoNoMargin();
}
void ConvertIconToBlack(QImage &image) {
@ -141,7 +141,7 @@ void OverrideApplicationIcon(QImage image) {
}
QIcon CreateOfficialIcon(Main::Session *session) {
return QIcon(Ui::PixmapFromImage(currentAppLogo()));
return QIcon(Ui::PixmapFromImage(AyuAssets::currentAppLogo()));
}
QIcon CreateIcon(Main::Session *session, bool returnNullIfDefault) {