mirror-chatterino2/src/singletons/Fonts.hpp

89 lines
1.8 KiB
C++
Raw Normal View History

#pragma once
2017-04-12 17:46:44 +02:00
2018-07-07 11:41:01 +02:00
#include "common/Singleton.hpp"
2017-04-12 17:46:44 +02:00
#include <QFont>
2018-01-17 14:14:31 +01:00
#include <QFontDatabase>
2017-04-12 17:46:44 +02:00
#include <QFontMetrics>
2018-05-23 04:22:17 +02:00
#include <array>
#include <boost/noncopyable.hpp>
#include <pajlada/settings/setting.hpp>
#include <pajlada/signals/signal.hpp>
2018-05-23 04:22:17 +02:00
#include <unordered_map>
2017-04-12 17:46:44 +02:00
2017-04-14 17:52:22 +02:00
namespace chatterino {
2017-04-12 17:46:44 +02:00
2018-08-02 14:23:27 +02:00
class Settings;
class Paths;
enum class FontStyle : uint8_t {
Tiny,
ChatSmall,
ChatMediumSmall,
ChatMedium,
ChatMediumBold,
ChatMediumItalic,
ChatLarge,
ChatVeryLarge,
UiMedium,
UiTabs,
// don't remove this value
EndType,
// make sure to update these values accordingly!
ChatStart = ChatSmall,
ChatEnd = ChatVeryLarge,
};
2018-07-07 11:41:01 +02:00
class Fonts final : public Singleton
2017-04-12 17:46:44 +02:00
{
public:
2018-06-28 19:51:07 +02:00
Fonts();
2018-08-02 14:23:27 +02:00
virtual void initialize(Settings &settings, Paths &paths) override;
2018-07-07 11:41:01 +02:00
2018-05-23 04:22:17 +02:00
// font data gets set in createFontData(...)
2017-04-12 17:46:44 +02:00
QFont getFont(FontStyle type, float scale);
QFontMetrics getFontMetrics(FontStyle type, float scale);
2017-04-12 17:46:44 +02:00
2018-05-23 04:22:17 +02:00
pajlada::Settings::Setting<std::string> chatFontFamily;
pajlada::Settings::Setting<int> chatFontSize;
2017-04-12 17:46:44 +02:00
pajlada::Signals::NoArgSignal fontChanged;
private:
struct FontData {
2018-05-23 04:22:17 +02:00
FontData(const QFont &_font)
: font(_font)
2018-05-23 04:22:17 +02:00
, metrics(_font)
{
}
2018-05-23 04:22:17 +02:00
const QFont font;
const QFontMetrics metrics;
};
2018-05-23 04:22:17 +02:00
struct ChatFontData {
float scale;
bool italic;
QFont::Weight weight;
};
2018-05-23 04:22:17 +02:00
struct UiFontData {
float size;
const char *name;
bool italic;
QFont::Weight weight;
};
FontData &getOrCreateFontData(FontStyle type, float scale);
FontData createFontData(FontStyle type, float scale);
2018-07-06 19:23:47 +02:00
std::vector<std::unordered_map<float, FontData>> fontsByType_;
2017-04-12 17:46:44 +02:00
};
} // namespace chatterino