8#include "basictheme_p.h"
9#include "styleselector.h"
12#include <QGuiApplication>
14#include "kirigamiplatform_logging.h"
21BasicThemeDefinition::BasicThemeDefinition(QObject *parent)
24 defaultFont = qGuiApp->font();
26 smallFont = qGuiApp->font();
27 smallFont.setPointSize(smallFont.pointSize() - 2);
30void BasicThemeDefinition::syncToQml(PlatformTheme *
object)
32 auto item = qobject_cast<QQuickItem *>(object->parent());
33 if (item && qmlAttachedPropertiesObject<PlatformTheme>(item,
false) ==
object) {
38BasicThemeInstance::BasicThemeInstance(
QObject *parent)
43BasicThemeDefinition &BasicThemeInstance::themeDefinition(
QQmlEngine *engine)
45 if (m_themeDefinition) {
46 return *m_themeDefinition;
50 qCWarning(KirigamiPlatform) <<
"No QML engine found, using default Basic theme.";
51 m_themeDefinition = std::make_unique<BasicThemeDefinition>();
53 auto themeUrl = StyleSelector::componentUrl(QStringLiteral(
"Theme.qml"));
55 component.loadUrl(themeUrl);
57 if (
auto themeDefinition = qobject_cast<BasicThemeDefinition *>(component.create())) {
58 m_themeDefinition.reset(themeDefinition);
60 const auto errors = component.errors();
61 for (
auto error : errors) {
62 qCWarning(KirigamiPlatform) <<
error.toString();
65 qCWarning(KirigamiPlatform) <<
"Invalid Theme file, using default Basic theme.";
66 m_themeDefinition = std::make_unique<BasicThemeDefinition>();
70 connect(m_themeDefinition.get(), &BasicThemeDefinition::changed,
this, &BasicThemeInstance::onDefinitionChanged);
72 return *m_themeDefinition;
75void BasicThemeInstance::onDefinitionChanged()
77 for (
auto watcher : std::as_const(watchers)) {
82Q_GLOBAL_STATIC(BasicThemeInstance, basicThemeInstance)
84BasicTheme::BasicTheme(
QObject *parent)
85 : PlatformTheme(parent)
87 basicThemeInstance()->watchers.append(
this);
92BasicTheme::~BasicTheme()
94 basicThemeInstance()->watchers.removeOne(
this);
97void BasicTheme::sync()
99 PlatformThemeChangeTracker tracker{
this};
101 auto &definition = basicThemeInstance()->themeDefinition(qmlEngine(parent()));
103 switch (colorSet()) {
104 case BasicTheme::Button:
105 setTextColor(
tint(definition.buttonTextColor));
106 setBackgroundColor(
tint(definition.buttonBackgroundColor));
107 setAlternateBackgroundColor(
tint(definition.buttonAlternateBackgroundColor));
108 setHoverColor(
tint(definition.buttonHoverColor));
109 setFocusColor(
tint(definition.buttonFocusColor));
111 case BasicTheme::View:
112 setTextColor(
tint(definition.viewTextColor));
113 setBackgroundColor(
tint(definition.viewBackgroundColor));
114 setAlternateBackgroundColor(
tint(definition.viewAlternateBackgroundColor));
115 setHoverColor(
tint(definition.viewHoverColor));
116 setFocusColor(
tint(definition.viewFocusColor));
118 case BasicTheme::Selection:
119 setTextColor(
tint(definition.selectionTextColor));
120 setBackgroundColor(
tint(definition.selectionBackgroundColor));
121 setAlternateBackgroundColor(
tint(definition.selectionAlternateBackgroundColor));
122 setHoverColor(
tint(definition.selectionHoverColor));
123 setFocusColor(
tint(definition.selectionFocusColor));
125 case BasicTheme::Tooltip:
126 setTextColor(
tint(definition.tooltipTextColor));
127 setBackgroundColor(
tint(definition.tooltipBackgroundColor));
128 setAlternateBackgroundColor(
tint(definition.tooltipAlternateBackgroundColor));
129 setHoverColor(
tint(definition.tooltipHoverColor));
130 setFocusColor(
tint(definition.tooltipFocusColor));
132 case BasicTheme::Complementary:
133 setTextColor(
tint(definition.complementaryTextColor));
134 setBackgroundColor(
tint(definition.complementaryBackgroundColor));
135 setAlternateBackgroundColor(
tint(definition.complementaryAlternateBackgroundColor));
136 setHoverColor(
tint(definition.complementaryHoverColor));
137 setFocusColor(
tint(definition.complementaryFocusColor));
139 case BasicTheme::Window:
141 setTextColor(
tint(definition.textColor));
142 setBackgroundColor(
tint(definition.backgroundColor));
143 setAlternateBackgroundColor(
tint(definition.alternateBackgroundColor));
144 setHoverColor(
tint(definition.hoverColor));
145 setFocusColor(
tint(definition.focusColor));
149 setDisabledTextColor(
tint(definition.disabledTextColor));
150 setHighlightColor(
tint(definition.highlightColor));
151 setHighlightedTextColor(
tint(definition.highlightedTextColor));
152 setActiveTextColor(
tint(definition.activeTextColor));
153 setActiveBackgroundColor(
tint(definition.activeBackgroundColor));
154 setLinkColor(
tint(definition.linkColor));
155 setLinkBackgroundColor(
tint(definition.linkBackgroundColor));
156 setVisitedLinkColor(
tint(definition.visitedLinkColor));
157 setVisitedLinkBackgroundColor(
tint(definition.visitedLinkBackgroundColor));
158 setNegativeTextColor(
tint(definition.negativeTextColor));
159 setNegativeBackgroundColor(
tint(definition.negativeBackgroundColor));
160 setNeutralTextColor(
tint(definition.neutralTextColor));
161 setNeutralBackgroundColor(
tint(definition.neutralBackgroundColor));
162 setPositiveTextColor(
tint(definition.positiveTextColor));
163 setPositiveBackgroundColor(
tint(definition.positiveBackgroundColor));
165 setDefaultFont(definition.defaultFont);
166 setSmallFont(definition.smallFont);
169bool BasicTheme::event(
QEvent *event)
171 if (
event->type() == PlatformThemeEvents::DataChangedEvent::type) {
175 if (
event->type() == PlatformThemeEvents::ColorSetChangedEvent::type) {
179 if (
event->type() == PlatformThemeEvents::ColorGroupChangedEvent::type) {
183 if (
event->type() == PlatformThemeEvents::ColorChangedEvent::type) {
184 basicThemeInstance()->themeDefinition(qmlEngine(parent())).syncToQml(
this);
187 if (
event->type() == PlatformThemeEvents::FontChangedEvent::type) {
188 basicThemeInstance()->themeDefinition(qmlEngine(parent())).syncToQml(
this);
191 return PlatformTheme::event(event);
199 switch (colorGroup()) {
200 case PlatformTheme::Inactive:
202 case PlatformTheme::Disabled:
212#include "moc_basictheme_p.cpp"
AKONADI_CALENDAR_EXPORT KCalendarCore::Event::Ptr event(const Akonadi::Item &item)
KGUIADDONS_EXPORT QColor tint(const QColor &base, const QColor &color, qreal amount=0.3)
void error(QWidget *parent, const QString &text, const QString &title, const KGuiItem &buttonOk, Options options=Notify)
QColor fromHsvF(float h, float s, float v, float a)
float saturationF() const const
float valueF() const const
bool isEnabled() const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)