mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
6ea3a1df08
cstdint) Make MessageElement to a class to fit better with the derived classes. Make MessageLayoutElement to a class to fit better with the derived classes. Remove virtual from override functions Replace all instances of boost::signals2 with pajlada::Signals. This lets us properly use clang code model to check for issues. Add missing virtual destructor to AbstractIrcServer Add missing virtual destructor to MessageLayoutElement Remove unused "connectedConnection" connection in TwitchChannel Fix typo in TrimChannelName function Fix typo in MessageParseArgs Replace some raw pointers with unique pointers where it made more sense. This allowed us to remove some manually written destructors whose only purpose was to delete that raw pointer. Reformat: Add namespace comments Reformat: Add empty empty lines between main namespace beginning and end Reformat: Re-order includes Reformat: Fix some includes that used quotes where they should use angle brackets Reformat: Replace some typedef's with using's Filter out more useless warnings
111 lines
3 KiB
C++
111 lines
3 KiB
C++
#include "singletons/fontmanager.hpp"
|
|
|
|
#include <QDebug>
|
|
#include <QtGlobal>
|
|
|
|
#ifdef Q_OS_WIN32
|
|
#define DEFAULT_FONT_FAMILY "Segoe UI"
|
|
#define DEFAULT_FONT_SIZE 10
|
|
#else
|
|
#ifdef Q_OS_MACOS
|
|
#define DEFAULT_FONT_FAMILY "Helvetica Neue"
|
|
#define DEFAULT_FONT_SIZE 12
|
|
#else
|
|
#define DEFAULT_FONT_FAMILY "Arial"
|
|
#define DEFAULT_FONT_SIZE 11
|
|
#endif
|
|
#endif
|
|
|
|
namespace chatterino {
|
|
namespace singletons {
|
|
|
|
FontManager::FontManager()
|
|
: currentFontFamily("/appearance/currentFontFamily", DEFAULT_FONT_FAMILY)
|
|
, currentFontSize("/appearance/currentFontSize", DEFAULT_FONT_SIZE)
|
|
// , currentFont(this->currentFontFamily.getValue().c_str(), currentFontSize.getValue())
|
|
{
|
|
this->currentFontFamily.connect([this](const std::string &newValue, auto) {
|
|
this->incGeneration();
|
|
// this->currentFont.setFamily(newValue.c_str());
|
|
this->currentFontByScale.clear();
|
|
this->fontChanged.invoke();
|
|
});
|
|
this->currentFontSize.connect([this](const int &newValue, auto) {
|
|
this->incGeneration();
|
|
// this->currentFont.setSize(newValue);
|
|
this->currentFontByScale.clear();
|
|
this->fontChanged.invoke();
|
|
});
|
|
}
|
|
|
|
FontManager &FontManager::getInstance()
|
|
{
|
|
static FontManager instance;
|
|
|
|
return instance;
|
|
}
|
|
|
|
QFont &FontManager::getFont(FontManager::Type type, float scale)
|
|
{
|
|
// return this->currentFont.getFont(type);
|
|
return this->getCurrentFont(scale).getFont(type);
|
|
}
|
|
|
|
QFontMetrics &FontManager::getFontMetrics(FontManager::Type type, float scale)
|
|
{
|
|
// return this->currentFont.getFontMetrics(type);
|
|
return this->getCurrentFont(scale).getFontMetrics(type);
|
|
}
|
|
|
|
FontManager::FontData &FontManager::Font::getFontData(FontManager::Type type)
|
|
{
|
|
switch (type) {
|
|
case Tiny:
|
|
return this->tiny;
|
|
case Small:
|
|
return this->small;
|
|
case MediumSmall:
|
|
return this->mediumSmall;
|
|
case Medium:
|
|
return this->medium;
|
|
case MediumBold:
|
|
return this->mediumBold;
|
|
case MediumItalic:
|
|
return this->mediumItalic;
|
|
case Large:
|
|
return this->large;
|
|
case VeryLarge:
|
|
return this->veryLarge;
|
|
default:
|
|
qDebug() << "Unknown font type:" << type << ", defaulting to medium";
|
|
return this->medium;
|
|
}
|
|
}
|
|
|
|
QFont &FontManager::Font::getFont(Type type)
|
|
{
|
|
return this->getFontData(type).font;
|
|
}
|
|
|
|
QFontMetrics &FontManager::Font::getFontMetrics(Type type)
|
|
{
|
|
return this->getFontData(type).metrics;
|
|
}
|
|
|
|
FontManager::Font &FontManager::getCurrentFont(float scale)
|
|
{
|
|
for (auto it = this->currentFontByScale.begin(); it != this->currentFontByScale.end(); it++) {
|
|
if (it->first == scale) {
|
|
return it->second;
|
|
}
|
|
}
|
|
this->currentFontByScale.push_back(
|
|
std::make_pair(scale, Font(this->currentFontFamily.getValue().c_str(),
|
|
this->currentFontSize.getValue() * scale)));
|
|
|
|
return this->currentFontByScale.back().second;
|
|
}
|
|
|
|
} // namespace singletons
|
|
} // namespace chatterino
|