first commit
This commit is contained in:
97
modern-qt/widget/cards/basic-card.hh
Normal file
97
modern-qt/widget/cards/basic-card.hh
Normal file
@@ -0,0 +1,97 @@
|
||||
#pragma once
|
||||
#include "modern-qt/utility/theme/theme.hh"
|
||||
#include "modern-qt/widget/shape/rounded-rect.hh"
|
||||
|
||||
namespace creeper::card::internal {
|
||||
|
||||
constexpr auto kCardRadius = double { 12 };
|
||||
|
||||
constexpr auto kElevatedShadowOpacity = double { 0.4 };
|
||||
constexpr auto kElevatedShadowBlurRadius = double { 10 };
|
||||
constexpr auto kElevatedShadowOffsetX = double { 0 };
|
||||
constexpr auto kElevatedShadowOffsetY = double { 2 };
|
||||
|
||||
constexpr auto kOutlinedWidth = double { 1.5 };
|
||||
|
||||
class Card : public RoundedRect {
|
||||
public:
|
||||
enum class Level {
|
||||
LOWEST,
|
||||
LOW,
|
||||
DEFAULT,
|
||||
HIGH,
|
||||
HIGHEST,
|
||||
};
|
||||
|
||||
Level level = Level::DEFAULT;
|
||||
|
||||
public:
|
||||
explicit Card() noexcept
|
||||
: Declarative {
|
||||
rounded_rect::pro::BorderWidth { 0 },
|
||||
rounded_rect::pro::BorderColor { Qt::transparent },
|
||||
rounded_rect::pro::Radius { kCardRadius },
|
||||
} { }
|
||||
|
||||
auto set_level(Level level) noexcept {
|
||||
this->level = level;
|
||||
update();
|
||||
}
|
||||
|
||||
void set_color_scheme(const ColorScheme& scheme) {
|
||||
switch (level) {
|
||||
case card::internal::Card::Level::LOWEST:
|
||||
set_background(scheme.surface_container_lowest);
|
||||
break;
|
||||
case card::internal::Card::Level::LOW:
|
||||
set_background(scheme.surface_container_low);
|
||||
break;
|
||||
case card::internal::Card::Level::DEFAULT:
|
||||
set_background(scheme.surface_container);
|
||||
break;
|
||||
case card::internal::Card::Level::HIGH:
|
||||
set_background(scheme.surface_container_high);
|
||||
break;
|
||||
case card::internal::Card::Level::HIGHEST:
|
||||
set_background(scheme.surface_container_highest);
|
||||
break;
|
||||
}
|
||||
update();
|
||||
}
|
||||
|
||||
void load_theme_manager(ThemeManager& manager) {
|
||||
manager.append_handler(this,
|
||||
[this](const ThemeManager& manager) { set_color_scheme(manager.color_scheme()); });
|
||||
}
|
||||
};
|
||||
}
|
||||
namespace creeper::card::pro {
|
||||
|
||||
using Token = common::Token<internal::Card>;
|
||||
|
||||
using Level =
|
||||
SetterProp<Token, internal::Card::Level, [](auto& self, const auto& v) { self.set_level(v); }>;
|
||||
|
||||
constexpr auto LevelDefault = Level { internal::Card::Level::DEFAULT };
|
||||
constexpr auto LevelHigh = Level { internal::Card::Level::HIGH };
|
||||
constexpr auto LevelHighest = Level { internal::Card::Level::HIGHEST };
|
||||
constexpr auto LevelLow = Level { internal::Card::Level::LOW };
|
||||
constexpr auto LevelLowest = Level { internal::Card::Level::LOWEST };
|
||||
|
||||
template <class Card>
|
||||
concept trait = std::derived_from<Card, Token>;
|
||||
|
||||
CREEPER_DEFINE_CHECKER(trait);
|
||||
|
||||
using namespace rounded_rect::pro;
|
||||
using namespace theme::pro;
|
||||
}
|
||||
namespace creeper {
|
||||
|
||||
using CardLevel = card::internal::Card::Level;
|
||||
|
||||
using BasicCard = Declarative<card::internal::Card,
|
||||
CheckerOr<card::pro::checker, rounded_rect::pro::checker, theme::pro::checker,
|
||||
widget::pro::checker>>;
|
||||
|
||||
}
|
||||
39
modern-qt/widget/cards/elevated-card.hh
Normal file
39
modern-qt/widget/cards/elevated-card.hh
Normal file
@@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
#include "basic-card.hh"
|
||||
|
||||
namespace creeper {
|
||||
namespace elevated_card::internal {
|
||||
class ElevatedCard : public BasicCard {
|
||||
public:
|
||||
explicit ElevatedCard() {
|
||||
using namespace card::internal;
|
||||
shadow_effect.setBlurRadius(kElevatedShadowBlurRadius);
|
||||
shadow_effect.setOffset(kElevatedShadowOffsetX, kElevatedShadowOffsetY);
|
||||
setGraphicsEffect(&shadow_effect);
|
||||
}
|
||||
|
||||
void set_color_scheme(const ColorScheme& scheme) {
|
||||
using namespace card::internal;
|
||||
|
||||
auto shadow_color = scheme.shadow;
|
||||
shadow_color.setAlphaF(kElevatedShadowOpacity);
|
||||
|
||||
shadow_effect.setColor(shadow_color);
|
||||
Card::set_color_scheme(scheme);
|
||||
}
|
||||
|
||||
void load_theme_manager(ThemeManager& manager) {
|
||||
manager.append_handler(this,
|
||||
[this](const ThemeManager& manager) { set_color_scheme(manager.color_scheme()); });
|
||||
}
|
||||
|
||||
private:
|
||||
QGraphicsDropShadowEffect shadow_effect {};
|
||||
};
|
||||
|
||||
}
|
||||
namespace elevated_card::pro {
|
||||
using namespace card::pro;
|
||||
}
|
||||
using ElevatedCard = Declarative<elevated_card::internal::ElevatedCard, BasicCard::Checker>;
|
||||
}
|
||||
9
modern-qt/widget/cards/filled-card.hh
Normal file
9
modern-qt/widget/cards/filled-card.hh
Normal file
@@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
#include "basic-card.hh"
|
||||
|
||||
namespace creeper {
|
||||
namespace filled_card::pro {
|
||||
using namespace card::pro;
|
||||
}
|
||||
using FilledCard = Declarative<BasicCard, BasicCard::Checker>;
|
||||
}
|
||||
29
modern-qt/widget/cards/outlined-card.hh
Normal file
29
modern-qt/widget/cards/outlined-card.hh
Normal file
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
#include "basic-card.hh"
|
||||
|
||||
namespace creeper {
|
||||
namespace outlined_card::internal {
|
||||
class OutlinedCard : public BasicCard {
|
||||
public:
|
||||
explicit OutlinedCard() {
|
||||
using namespace card::internal;
|
||||
set_border_width(kOutlinedWidth);
|
||||
}
|
||||
|
||||
void set_color_scheme(const ColorScheme& scheme) {
|
||||
set_border_color(scheme.outline_variant);
|
||||
Card::set_color_scheme(scheme);
|
||||
}
|
||||
|
||||
void load_theme_manager(ThemeManager& manager) {
|
||||
manager.append_handler(this,
|
||||
[this](const ThemeManager& manager) { set_color_scheme(manager.color_scheme()); });
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
namespace outlined_card::pro {
|
||||
using namespace card::pro;
|
||||
}
|
||||
using OutlinedCard = Declarative<outlined_card::internal::OutlinedCard, BasicCard::Checker>;
|
||||
}
|
||||
Reference in New Issue
Block a user