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 "lang_auto.h"
#include "ayu/libs/json.hpp" #include "ayu/libs/json.hpp"
#include "ayu/libs/json_ext.hpp" #include "ayu/libs/json_ext.hpp"
#include "ayu/ui/ayu_assets.h"
#include "rpl/producer.h" #include "rpl/producer.h"
namespace AyuSettings 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 class AyuGramSettings
{ {
public: public:
@ -56,12 +41,15 @@ public:
disableStories = false; disableStories = false;
collapseSimilarChannels = true; collapseSimilarChannels = true;
hideSimilarChannels = false; hideSimilarChannels = false;
uploadSpeedBoost = false;
disableNotificationsDelay = false; disableNotificationsDelay = false;
localPremium = false; localPremium = false;
copyUsernameAsLink = true; copyUsernameAsLink = true;
// ~ Customization // ~ Customization
appIcon = DEFAULT_ICON; appIcon = AyuAssets::DEFAULT_ICON;
simpleQuotesAndReplies = true; simpleQuotesAndReplies = true;
deletedMark = "🧹"; deletedMark = "🧹";
editedMark = tr::lng_edited(tr::now); editedMark = tr::lng_edited(tr::now);

View file

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

View file

@ -6,6 +6,27 @@
// Copyright @Radolyn, 2023 // Copyright @Radolyn, 2023
#pragma once #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(); void loadAppIco();
QImage loadPreview(QString name); QImage loadPreview(QString name);
@ -13,3 +34,5 @@ QImage loadPreview(QString name);
QString currentAppLogoName(); QString currentAppLogoName();
QImage currentAppLogo(); QImage currentAppLogo();
QImage currentAppLogoNoMargin(); QImage currentAppLogoNoMargin();
}

View file

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

View file

@ -450,7 +450,7 @@ void Step::paintCover(QPainter &p, int top) {
planeLeft += deltaLeft; planeLeft += deltaLeft;
// planeTop += top; // 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())); 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 ScaledLogoNoMargin = base::flat_map<int, QImage>();
static auto ScaledLogoDark = base::flat_map<int, QImage>(); static auto ScaledLogoDark = base::flat_map<int, QImage>();
static auto ScaledLogoLight = 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>(); ScaledLogo = base::flat_map<int, QImage>();
ScaledLogoNoMargin = base::flat_map<int, QImage>(); ScaledLogoNoMargin = base::flat_map<int, QImage>();
ScaledLogoDark = 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"; const char kOptionNewWindowsSizeAsFirst[] = "new-windows-size-as-first";
QImage Logo() { QImage Logo() {
return currentAppLogo(); return AyuAssets::currentAppLogo();
} }
QImage LogoNoMargin() { QImage LogoNoMargin() {
return currentAppLogoNoMargin(); return AyuAssets::currentAppLogoNoMargin();
} }
void ConvertIconToBlack(QImage &image) { void ConvertIconToBlack(QImage &image) {
@ -141,7 +141,7 @@ void OverrideApplicationIcon(QImage image) {
} }
QIcon CreateOfficialIcon(Main::Session *session) { QIcon CreateOfficialIcon(Main::Session *session) {
return QIcon(Ui::PixmapFromImage(currentAppLogo())); return QIcon(Ui::PixmapFromImage(AyuAssets::currentAppLogo()));
} }
QIcon CreateIcon(Main::Session *session, bool returnNullIfDefault) { QIcon CreateIcon(Main::Session *session, bool returnNullIfDefault) {