feat: add font builder
This commit is contained in:
parent
7cb3944af7
commit
1f2913f90c
3 changed files with 70 additions and 0 deletions
|
|
@ -6,6 +6,7 @@ qml_module(caelestia-config
|
|||
configobject.cpp
|
||||
rootconfig.cpp
|
||||
appearanceconfig.cpp
|
||||
fontbuilder.cpp
|
||||
tokens.cpp
|
||||
tokensattached.cpp
|
||||
anim.cpp
|
||||
|
|
|
|||
42
plugin/src/Caelestia/Config/fontbuilder.cpp
Normal file
42
plugin/src/Caelestia/Config/fontbuilder.cpp
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
#include "fontbuilder.hpp"
|
||||
|
||||
#include <qcoreapplication.h>
|
||||
#include <qmetatype.h>
|
||||
|
||||
namespace caelestia::config {
|
||||
|
||||
FontBuilder::FontBuilder(QFont font)
|
||||
: m_font(std::move(font)) {}
|
||||
|
||||
FontBuilder FontBuilder::family(const QString& family) {
|
||||
m_font.setFamily(family);
|
||||
return *this;
|
||||
}
|
||||
|
||||
FontBuilder FontBuilder::size(int pointSize) {
|
||||
m_font.setPointSize(pointSize);
|
||||
m_font.setVariableAxis("opsz", static_cast<float>(pointSize));
|
||||
return *this;
|
||||
}
|
||||
|
||||
FontBuilder FontBuilder::weight(QFont::Weight weight) {
|
||||
m_font.setWeight(weight);
|
||||
m_font.setVariableAxis("wght", weight);
|
||||
return *this;
|
||||
}
|
||||
|
||||
FontBuilder FontBuilder::italic(bool on) {
|
||||
m_font.setItalic(on);
|
||||
return *this;
|
||||
}
|
||||
|
||||
FontBuilder FontBuilder::vaxis(QFont::Tag tag, float value) {
|
||||
m_font.setVariableAxis(tag, value);
|
||||
return *this;
|
||||
}
|
||||
|
||||
QFont FontBuilder::build() const {
|
||||
return m_font;
|
||||
}
|
||||
|
||||
} // namespace caelestia::config
|
||||
27
plugin/src/Caelestia/Config/fontbuilder.hpp
Normal file
27
plugin/src/Caelestia/Config/fontbuilder.hpp
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
#pragma once
|
||||
|
||||
#include <qfont.h>
|
||||
#include <qqmlintegration.h>
|
||||
|
||||
namespace caelestia::config {
|
||||
|
||||
class FontBuilder {
|
||||
Q_GADGET
|
||||
QML_ANONYMOUS
|
||||
|
||||
public:
|
||||
FontBuilder() = default;
|
||||
explicit FontBuilder(QFont font);
|
||||
|
||||
[[nodiscard]] Q_INVOKABLE FontBuilder family(const QString& family);
|
||||
[[nodiscard]] Q_INVOKABLE FontBuilder size(int pointSize);
|
||||
[[nodiscard]] Q_INVOKABLE FontBuilder weight(QFont::Weight weight);
|
||||
[[nodiscard]] Q_INVOKABLE FontBuilder italic(bool on = true);
|
||||
[[nodiscard]] Q_INVOKABLE FontBuilder vaxis(QFont::Tag tag, float value);
|
||||
[[nodiscard]] Q_INVOKABLE QFont build() const;
|
||||
|
||||
private:
|
||||
QFont m_font;
|
||||
};
|
||||
|
||||
} // namespace caelestia::config
|
||||
Loading…
Add table
Reference in a new issue