mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-14 13:17:08 +02:00
feat: refactor a bit
This commit is contained in:
parent
74196732ac
commit
fba53e1ec8
7 changed files with 63 additions and 43 deletions
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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()));
|
||||
}
|
||||
|
||||
|
|
|
@ -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>();
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Add table
Reference in a new issue