diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-10-22 21:37:11 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-10-22 21:37:11 +0200 |
commit | b89f64cb55507b466f95a27898f94fc64ec5fd29 (patch) | |
tree | c0dfba7ec533b51804978a91d88ce6f8c558220d | |
parent | 2638a94094f50ced165ec3d24e73f59f8d3d1ea8 (diff) | |
download | serenity-b89f64cb55507b466f95a27898f94fc64ec5fd29.zip |
LibGUI: Make it possible to wrap a Font in a GVariant
-rw-r--r-- | Libraries/LibGUI/GVariant.cpp | 17 | ||||
-rw-r--r-- | Libraries/LibGUI/GVariant.h | 13 |
2 files changed, 29 insertions, 1 deletions
diff --git a/Libraries/LibGUI/GVariant.cpp b/Libraries/LibGUI/GVariant.cpp index 632ea93145..87f9b3a4fd 100644 --- a/Libraries/LibGUI/GVariant.cpp +++ b/Libraries/LibGUI/GVariant.cpp @@ -16,6 +16,7 @@ const char* to_string(GVariant::Type type) case GVariant::Type::Point: return "Point"; case GVariant::Type::Size: return "Size"; case GVariant::Type::Rect: return "Rect"; + case GVariant::Type::Font: return "Font"; } ASSERT_NOT_REACHED(); } @@ -134,6 +135,13 @@ GVariant::GVariant(const GIcon& value) AK::ref_if_not_null(m_value.as_icon); } +GVariant::GVariant(const Font& value) + : m_type(Type::Font) +{ + m_value.as_font = &const_cast<Font&>(value); + AK::ref_if_not_null(m_value.as_font); +} + GVariant::GVariant(Color color) : m_type(Type::Color) { @@ -212,6 +220,10 @@ void GVariant::copy_from(const GVariant& other) m_value.as_icon = other.m_value.as_icon; AK::ref_if_not_null(m_value.as_icon); break; + case Type::Font: + m_value.as_font = other.m_value.as_font; + AK::ref_if_not_null(m_value.as_font); + break; case Type::Color: m_value.as_color = other.m_value.as_color; break; @@ -256,6 +268,8 @@ bool GVariant::operator==(const GVariant& other) const return as_size() == other.as_size(); case Type::Rect: return as_rect() == other.as_rect(); + case Type::Font: + return &as_font() == &other.as_font(); case Type::Invalid: return true; } @@ -288,6 +302,7 @@ bool GVariant::operator<(const GVariant& other) const case Type::Point: case Type::Size: case Type::Rect: + case Type::Font: // FIXME: Figure out how to compare these. ASSERT_NOT_REACHED(); case Type::Invalid: @@ -321,6 +336,8 @@ String GVariant::to_string() const return as_size().to_string(); case Type::Rect: return as_rect().to_string(); + case Type::Font: + return String::format("[Font: %s]", as_font().name().characters()); case Type::Invalid: return "[null]"; break; diff --git a/Libraries/LibGUI/GVariant.h b/Libraries/LibGUI/GVariant.h index 168f5c1fca..bd008fdab0 100644 --- a/Libraries/LibGUI/GVariant.h +++ b/Libraries/LibGUI/GVariant.h @@ -1,8 +1,9 @@ #pragma once #include <AK/String.h> -#include <LibGUI/GIcon.h> +#include <LibDraw/Font.h> #include <LibDraw/GraphicsBitmap.h> +#include <LibGUI/GIcon.h> namespace AK { class JsonValue; @@ -22,6 +23,7 @@ public: GVariant(const Point&); GVariant(const Size&); GVariant(const Rect&); + GVariant(const Font&); GVariant(const AK::JsonValue&); GVariant(Color); @@ -47,6 +49,7 @@ public: Point, Size, Rect, + Font, }; bool is_valid() const { return m_type != Type::Invalid; } @@ -61,6 +64,7 @@ public: bool is_point() const { return m_type == Type::Point; } bool is_size() const { return m_type == Type::Size; } bool is_rect() const { return m_type == Type::Rect; } + bool is_font() const { return m_type == Type::Font; } Type type() const { return m_type; } bool as_bool() const @@ -167,6 +171,12 @@ public: return Color::from_rgba(m_value.as_color); } + const Font& as_font() const + { + ASSERT(type() == Type::Font); + return *m_value.as_font; + } + Color to_color(Color default_value = {}) const { if (type() == Type::Color) @@ -206,6 +216,7 @@ private: StringImpl* as_string; GraphicsBitmap* as_bitmap; GIconImpl* as_icon; + Font* as_font; bool as_bool; int as_int; unsigned as_uint; |