turning a lot of includes into forward declares

This commit is contained in:
fourtf
2018-08-11 22:23:06 +02:00
parent 63eaf3b94c
commit 44f5a15da3
117 changed files with 591 additions and 536 deletions
+21 -20
View File
@@ -2,6 +2,7 @@
#include "Application.hpp"
#include "debug/AssertInGuiThread.hpp"
#include "singletons/Settings.hpp"
#include "singletons/WindowManager.hpp"
#include <QDebug>
@@ -26,7 +27,7 @@ Fonts::Fonts()
: chatFontFamily("/appearance/currentFontFamily", DEFAULT_FONT_FAMILY)
, chatFontSize("/appearance/currentFontSize", DEFAULT_FONT_SIZE)
{
this->fontsByType_.resize(size_t(EndType));
this->fontsByType_.resize(size_t(FontStyle::EndType));
}
void Fonts::initialize(Settings &, Paths &)
@@ -61,21 +62,21 @@ void Fonts::initialize(Settings &, Paths &)
});
}
QFont Fonts::getFont(Fonts::Type type, float scale)
QFont Fonts::getFont(FontStyle type, float scale)
{
return this->getOrCreateFontData(type, scale).font;
}
QFontMetrics Fonts::getFontMetrics(Fonts::Type type, float scale)
QFontMetrics Fonts::getFontMetrics(FontStyle type, float scale)
{
return this->getOrCreateFontData(type, scale).metrics;
}
Fonts::FontData &Fonts::getOrCreateFontData(Type type, float scale)
Fonts::FontData &Fonts::getOrCreateFontData(FontStyle type, float scale)
{
assertInGuiThread();
assert(type >= 0 && type < EndType);
assert(type < FontStyle::EndType);
auto &map = this->fontsByType_[size_t(type)];
@@ -94,22 +95,22 @@ Fonts::FontData &Fonts::getOrCreateFontData(Type type, float scale)
return result.first->second;
}
Fonts::FontData Fonts::createFontData(Type type, float scale)
Fonts::FontData Fonts::createFontData(FontStyle type, float scale)
{
// check if it's a chat (scale the setting)
if (type >= ChatStart && type <= ChatEnd) {
static std::unordered_map<Type, ChatFontData> sizeScale{
{ChatSmall, {0.6f, false, QFont::Normal}},
{ChatMediumSmall, {0.8f, false, QFont::Normal}},
{ChatMedium, {1, false, QFont::Normal}},
{ChatMediumBold,
if (type >= FontStyle::ChatStart && type <= FontStyle::ChatEnd) {
static std::unordered_map<FontStyle, ChatFontData> sizeScale{
{FontStyle::ChatSmall, {0.6f, false, QFont::Normal}},
{FontStyle::ChatMediumSmall, {0.8f, false, QFont::Normal}},
{FontStyle::ChatMedium, {1, false, QFont::Normal}},
{FontStyle::ChatMediumBold,
{1, false,
QFont::Weight(getApp()->settings->boldScale.getValue())}},
{ChatMediumItalic, {1, true, QFont::Normal}},
{ChatLarge, {1.2f, false, QFont::Normal}},
{ChatVeryLarge, {1.4f, false, QFont::Normal}},
{FontStyle::ChatMediumItalic, {1, true, QFont::Normal}},
{FontStyle::ChatLarge, {1.2f, false, QFont::Normal}},
{FontStyle::ChatVeryLarge, {1.4f, false, QFont::Normal}},
};
sizeScale[ChatMediumBold] = {
sizeScale[FontStyle::ChatMediumBold] = {
1, false, QFont::Weight(getApp()->settings->boldScale.getValue())};
auto data = sizeScale[type];
return FontData(
@@ -126,11 +127,11 @@ Fonts::FontData Fonts::createFontData(Type type, float scale)
constexpr float multiplier = 1.f;
#endif
static std::unordered_map<Type, UiFontData> defaultSize{
{Tiny, {8, "Monospace", false, QFont::Normal}},
{UiMedium,
static std::unordered_map<FontStyle, UiFontData> defaultSize{
{FontStyle::Tiny, {8, "Monospace", false, QFont::Normal}},
{FontStyle::UiMedium,
{int(9 * multiplier), DEFAULT_FONT_FAMILY, false, QFont::Normal}},
{UiTabs,
{FontStyle::UiTabs,
{int(9 * multiplier), DEFAULT_FONT_FAMILY, false, QFont::Normal}},
};
+25 -26
View File
@@ -16,6 +16,27 @@ namespace chatterino {
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,
};
class Fonts final : public Singleton
{
public:
@@ -24,29 +45,9 @@ public:
virtual void initialize(Settings &settings, Paths &paths) override;
// font data gets set in createFontData(...)
enum Type : 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,
};
QFont getFont(Type type, float scale);
QFontMetrics getFontMetrics(Type type, float scale);
QFont getFont(FontStyle type, float scale);
QFontMetrics getFontMetrics(FontStyle type, float scale);
pajlada::Settings::Setting<std::string> chatFontFamily;
pajlada::Settings::Setting<int> chatFontSize;
@@ -78,12 +79,10 @@ private:
QFont::Weight weight;
};
FontData &getOrCreateFontData(Type type, float scale);
FontData createFontData(Type type, float scale);
FontData &getOrCreateFontData(FontStyle type, float scale);
FontData createFontData(FontStyle type, float scale);
std::vector<std::unordered_map<float, FontData>> fontsByType_;
};
using FontStyle = Fonts::Type;
} // namespace chatterino
-1
View File
@@ -5,7 +5,6 @@
#include "common/ChatterinoSetting.hpp"
#include "controllers/highlights/HighlightPhrase.hpp"
#include "controllers/moderationactions/ModerationAction.hpp"
#include "messages/MessageElement.hpp"
#include <pajlada/settings/setting.hpp>
#include <pajlada/settings/settinglistener.hpp>
+1
View File
@@ -1,6 +1,7 @@
#include "Updates.hpp"
#include "common/NetworkRequest.hpp"
#include "common/Outcome.hpp"
#include "common/Version.hpp"
#include "singletons/Paths.hpp"
#include "util/CombinePath.hpp"
+18 -11
View File
@@ -3,13 +3,20 @@
#include "Application.hpp"
#include "debug/AssertInGuiThread.hpp"
#include "debug/Log.hpp"
#include "messages/MessageElement.hpp"
#include "providers/twitch/TwitchServer.hpp"
#include "singletons/Fonts.hpp"
#include "singletons/Paths.hpp"
#include "singletons/Settings.hpp"
#include "singletons/Theme.hpp"
#include "util/Clamp.hpp"
#include "widgets/AccountSwitchPopupWidget.hpp"
#include "widgets/Notebook.hpp"
#include "widgets/Window.hpp"
#include "widgets/dialogs/SettingsDialog.hpp"
#include "widgets/helper/NotebookTab.hpp"
#include "widgets/splits/Split.hpp"
#include "widgets/splits/SplitContainer.hpp"
#include <QDebug>
#include <QJsonArray>
@@ -174,7 +181,7 @@ Window &WindowManager::getSelectedWindow()
return *this->selectedWindow_;
}
Window &WindowManager::createWindow(Window::Type type)
Window &WindowManager::createWindow(WindowType type)
{
assertInGuiThread();
@@ -182,7 +189,7 @@ Window &WindowManager::createWindow(Window::Type type)
this->windows_.push_back(window);
window->show();
if (type != Window::Type::Main) {
if (type != WindowType::Main) {
window->setAttribute(Qt::WA_DeleteOnClose);
QObject::connect(window, &QWidget::destroyed, [this, window] {
@@ -239,16 +246,16 @@ void WindowManager::initialize(Settings &settings, Paths &paths)
// get type
QString type_val = window_obj.value("type").toString();
Window::Type type =
type_val == "main" ? Window::Type::Main : Window::Type::Popup;
WindowType type =
type_val == "main" ? WindowType::Main : WindowType::Popup;
if (type == Window::Type::Main && mainWindow_ != nullptr) {
type = Window::Type::Popup;
if (type == WindowType::Main && mainWindow_ != nullptr) {
type = WindowType::Popup;
}
Window &window = createWindow(type);
if (type == Window::Type::Main) {
if (type == WindowType::Main) {
mainWindow_ = &window;
}
@@ -308,7 +315,7 @@ void WindowManager::initialize(Settings &settings, Paths &paths)
}
if (mainWindow_ == nullptr) {
mainWindow_ = &createWindow(Window::Type::Main);
mainWindow_ = &createWindow(WindowType::Main);
mainWindow_->getNotebook().addPage(true);
}
@@ -344,15 +351,15 @@ void WindowManager::save()
// window type
switch (window->getType()) {
case Window::Type::Main:
case WindowType::Main:
window_obj.insert("type", "main");
break;
case Window::Type::Popup:
case WindowType::Popup:
window_obj.insert("type", "popup");
break;
case Window::Type::Attached:;
case WindowType::Attached:;
}
// window geometry
+12 -5
View File
@@ -1,13 +1,20 @@
#pragma once
#include "common/Channel.hpp"
#include "common/FlagsEnum.hpp"
#include "common/Singleton.hpp"
#include "widgets/Window.hpp"
#include "widgets/splits/SplitContainer.hpp"
namespace chatterino {
class Settings;
class Paths;
class Window;
class SplitContainer;
enum class MessageElementFlag;
using MessageElementFlags = FlagsEnum<MessageElementFlag>;
enum class WindowType;
class WindowManager final : public Singleton
{
@@ -34,7 +41,7 @@ public:
Window &getMainWindow();
Window &getSelectedWindow();
Window &createWindow(Window::Type type);
Window &createWindow(WindowType type);
int windowCount();
Window *windowAt(int index);
@@ -63,10 +70,10 @@ private:
std::vector<Window *> windows_;
Window *mainWindow_ = nullptr;
Window *selectedWindow_ = nullptr;
Window *mainWindow_{};
Window *selectedWindow_{};
MessageElementFlags wordFlags_ = MessageElementFlag::Default;
MessageElementFlags wordFlags_{};
pajlada::Settings::SettingListener wordFlagsListener_;
};