2017-06-07 10:09:24 +02:00
|
|
|
#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>
|
2017-06-17 11:37:13 +02:00
|
|
|
#include <pajlada/settings/setting.hpp>
|
2017-10-27 21:02:58 +02:00
|
|
|
#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
|
|
|
{
|
2018-04-28 15:20:18 +02:00
|
|
|
public:
|
|
|
|
FontManager();
|
|
|
|
|
2018-05-23 04:22:17 +02:00
|
|
|
// font data gets set in createFontData(...)
|
2017-06-17 11:37:13 +02:00
|
|
|
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-06-17 11:37:13 +02:00
|
|
|
};
|
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
|
|
|
|
2017-10-27 21:02:58 +02:00
|
|
|
pajlada::Signals::NoArgSignal fontChanged;
|
|
|
|
|
2017-06-17 11:37:13 +02:00
|
|
|
private:
|
|
|
|
struct FontData {
|
2018-05-23 04:22:17 +02:00
|
|
|
FontData(const QFont &_font)
|
2017-06-17 11:37:13 +02:00
|
|
|
: font(_font)
|
2018-05-23 04:22:17 +02:00
|
|
|
, metrics(_font)
|
2017-06-17 11:37:13 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-05-23 04:22:17 +02:00
|
|
|
const QFont font;
|
|
|
|
const QFontMetrics metrics;
|
2017-06-17 11:37:13 +02:00
|
|
|
};
|
|
|
|
|
2018-05-23 04:22:17 +02:00
|
|
|
struct ChatFontData {
|
|
|
|
float scale;
|
|
|
|
bool italic;
|
|
|
|
QFont::Weight weight;
|
2017-06-17 11:37:13 +02:00
|
|
|
};
|
|
|
|
|
2018-05-23 04:22:17 +02:00
|
|
|
struct UiFontData {
|
|
|
|
float size;
|
|
|
|
const char *name;
|
|
|
|
bool italic;
|
|
|
|
QFont::Weight weight;
|
|
|
|
};
|
2017-12-23 21:18:13 +01:00
|
|
|
|
2018-05-23 04:22:17 +02:00
|
|
|
FontData &getOrCreateFontData(Type type, float scale);
|
|
|
|
FontData createFontData(Type type, float scale);
|
2017-06-17 11:37:13 +02:00
|
|
|
|
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-04-03 02:55:32 +02:00
|
|
|
|
2018-01-17 14:14:31 +01:00
|
|
|
} // namespace singletons
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2018-04-03 02:55:32 +02:00
|
|
|
using FontStyle = singletons::FontManager::Type;
|
|
|
|
|
2017-06-07 10:09:24 +02:00
|
|
|
} // namespace chatterino
|