mirror-chatterino2/src/singletons/FontManager.hpp

86 lines
1.8 KiB
C++
Raw Normal View History

#pragma once
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-12-31 22:58:35 +01:00
namespace singletons {
2017-04-12 17:46:44 +02:00
2018-05-23 04:22:17 +02:00
class FontManager : boost::noncopyable
2017-04-12 17:46:44 +02:00
{
public:
FontManager();
2018-05-23 04:22:17 +02:00
// font data gets set in createFontData(...)
enum Type : uint8_t {
2018-01-17 14:14:31 +01:00
Tiny,
2018-05-23 04:22:17 +02:00
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,
};
2017-04-12 17:46:44 +02:00
2018-05-23 04:22:17 +02:00
QFont getFont(Type type, float scale);
QFontMetrics getFontMetrics(Type 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;
};
2018-05-23 04:22:17 +02:00
FontData &getOrCreateFontData(Type type, float scale);
FontData createFontData(Type type, float scale);
2018-05-23 04:22:17 +02:00
std::vector<std::unordered_map<float, FontData>> fontsByType;
2017-04-12 17:46:44 +02:00
};
2018-01-17 14:14:31 +01:00
} // namespace singletons
2017-04-12 17:46:44 +02:00
using FontStyle = singletons::FontManager::Type;
} // namespace chatterino