mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
c08059c6a8
Delete copy/move constructor of FontManager :kkona: Fix places that were using the copy constructor of the FontManager
134 lines
3.5 KiB
C++
134 lines
3.5 KiB
C++
#pragma once
|
|
|
|
#include <QFont>
|
|
#include <QFontMetrics>
|
|
#include <pajlada/settings/setting.hpp>
|
|
#include <pajlada/signals/signal.hpp>
|
|
|
|
namespace chatterino {
|
|
|
|
class FontManager
|
|
{
|
|
FontManager(const FontManager &) = delete;
|
|
FontManager(FontManager &&) = delete;
|
|
|
|
public:
|
|
enum Type : uint8_t {
|
|
Small,
|
|
Medium,
|
|
MediumBold,
|
|
MediumItalic,
|
|
Large,
|
|
VeryLarge,
|
|
};
|
|
|
|
// FontManager is initialized only once, on first use
|
|
static FontManager &getInstance()
|
|
{
|
|
static FontManager instance;
|
|
|
|
return instance;
|
|
}
|
|
|
|
QFont &getFont(Type type);
|
|
QFontMetrics &getFontMetrics(Type type);
|
|
|
|
int getGeneration() const
|
|
{
|
|
return this->generation;
|
|
}
|
|
|
|
void incGeneration()
|
|
{
|
|
this->generation++;
|
|
}
|
|
|
|
pajlada::Settings::Setting<std::string> currentFontFamily;
|
|
pajlada::Settings::Setting<int> currentFontSize;
|
|
|
|
pajlada::Signals::NoArgSignal fontChanged;
|
|
|
|
private:
|
|
FontManager();
|
|
|
|
struct FontData {
|
|
FontData(QFont &&_font)
|
|
: font(_font)
|
|
, metrics(this->font)
|
|
{
|
|
}
|
|
|
|
QFont font;
|
|
QFontMetrics metrics;
|
|
};
|
|
|
|
struct Font {
|
|
Font() = delete;
|
|
|
|
explicit Font(const char *fontFamilyName, int mediumSize)
|
|
: small(QFont(fontFamilyName, mediumSize - 4))
|
|
, medium(QFont(fontFamilyName, mediumSize))
|
|
, mediumBold(QFont(fontFamilyName, mediumSize, 50))
|
|
, mediumItalic(QFont(fontFamilyName, mediumSize, -1, true))
|
|
, large(QFont(fontFamilyName, mediumSize))
|
|
, veryLarge(QFont(fontFamilyName, mediumSize))
|
|
{
|
|
}
|
|
|
|
void setFamily(const char *newFamily)
|
|
{
|
|
this->small.font.setFamily(newFamily);
|
|
this->medium.font.setFamily(newFamily);
|
|
this->mediumBold.font.setFamily(newFamily);
|
|
this->mediumItalic.font.setFamily(newFamily);
|
|
this->large.font.setFamily(newFamily);
|
|
this->veryLarge.font.setFamily(newFamily);
|
|
|
|
this->updateMetrics();
|
|
}
|
|
|
|
void setSize(int newMediumSize)
|
|
{
|
|
this->small.font.setPointSize(newMediumSize - 4);
|
|
this->medium.font.setPointSize(newMediumSize);
|
|
this->mediumBold.font.setPointSize(newMediumSize);
|
|
this->mediumItalic.font.setPointSize(newMediumSize);
|
|
this->large.font.setPointSize(newMediumSize + 2);
|
|
this->veryLarge.font.setPointSize(newMediumSize + 4);
|
|
|
|
this->updateMetrics();
|
|
}
|
|
|
|
void updateMetrics()
|
|
{
|
|
this->small.metrics = QFontMetrics(this->small.font);
|
|
this->medium.metrics = QFontMetrics(this->medium.font);
|
|
this->mediumBold.metrics = QFontMetrics(this->mediumBold.font);
|
|
this->mediumItalic.metrics = QFontMetrics(this->mediumItalic.font);
|
|
this->large.metrics = QFontMetrics(this->large.font);
|
|
this->veryLarge.metrics = QFontMetrics(this->veryLarge.font);
|
|
}
|
|
|
|
FontData &getFontData(Type type);
|
|
|
|
QFont &getFont(Type type);
|
|
QFontMetrics &getFontMetrics(Type type);
|
|
|
|
FontData small;
|
|
FontData medium;
|
|
FontData mediumBold;
|
|
FontData mediumItalic;
|
|
FontData large;
|
|
FontData veryLarge;
|
|
};
|
|
|
|
// Future plans:
|
|
// Could have multiple fonts in here, such as "Menu font", "Application font", "Chat font"
|
|
|
|
Font currentFont;
|
|
|
|
int generation = 0;
|
|
};
|
|
|
|
} // namespace chatterino
|