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;
49 auto themeUrl = StyleSelector::componentUrl(QStringLiteral(
"Theme.qml"));
51 component.loadUrl(themeUrl);
53 if (
auto themeDefinition = qobject_cast<BasicThemeDefinition *>(component.create())) {
54 m_themeDefinition.reset(themeDefinition);
56 const auto errors = component.errors();
57 for (
auto error : errors) {
58 qCWarning(KirigamiPlatform) <<
error.toString();
61 qCWarning(KirigamiPlatform) <<
"Invalid Theme file, using default Basic theme.";
62 m_themeDefinition = std::make_unique<BasicThemeDefinition>();
65 connect(m_themeDefinition.get(), &BasicThemeDefinition::changed,
this, &BasicThemeInstance::onDefinitionChanged);
67 return *m_themeDefinition;
70void BasicThemeInstance::onDefinitionChanged()
72 for (
auto watcher : std::as_const(watchers)) {
77Q_GLOBAL_STATIC(BasicThemeInstance, basicThemeInstance)
79BasicTheme::BasicTheme(
QObject *parent)
80 : PlatformTheme(parent)
82 basicThemeInstance()->watchers.append(
this);
87BasicTheme::~BasicTheme()
89 basicThemeInstance()->watchers.removeOne(
this);
92void BasicTheme::sync()
94 PlatformThemeChangeTracker tracker{
this};
96 auto &definition = basicThemeInstance()->themeDefinition(qmlEngine(parent()));
99 case BasicTheme::Button:
100 setTextColor(
tint(definition.buttonTextColor));
101 setBackgroundColor(
tint(definition.buttonBackgroundColor));
102 setAlternateBackgroundColor(
tint(definition.buttonAlternateBackgroundColor));
103 setHoverColor(
tint(definition.buttonHoverColor));
104 setFocusColor(
tint(definition.buttonFocusColor));
106 case BasicTheme::View:
107 setTextColor(
tint(definition.viewTextColor));
108 setBackgroundColor(
tint(definition.viewBackgroundColor));
109 setAlternateBackgroundColor(
tint(definition.viewAlternateBackgroundColor));
110 setHoverColor(
tint(definition.viewHoverColor));
111 setFocusColor(
tint(definition.viewFocusColor));
113 case BasicTheme::Selection:
114 setTextColor(
tint(definition.selectionTextColor));
115 setBackgroundColor(
tint(definition.selectionBackgroundColor));
116 setAlternateBackgroundColor(
tint(definition.selectionAlternateBackgroundColor));
117 setHoverColor(
tint(definition.selectionHoverColor));
118 setFocusColor(
tint(definition.selectionFocusColor));
120 case BasicTheme::Tooltip:
121 setTextColor(
tint(definition.tooltipTextColor));
122 setBackgroundColor(
tint(definition.tooltipBackgroundColor));
123 setAlternateBackgroundColor(
tint(definition.tooltipAlternateBackgroundColor));
124 setHoverColor(
tint(definition.tooltipHoverColor));
125 setFocusColor(
tint(definition.tooltipFocusColor));
127 case BasicTheme::Complementary:
128 setTextColor(
tint(definition.complementaryTextColor));
129 setBackgroundColor(
tint(definition.complementaryBackgroundColor));
130 setAlternateBackgroundColor(
tint(definition.complementaryAlternateBackgroundColor));
131 setHoverColor(
tint(definition.complementaryHoverColor));
132 setFocusColor(
tint(definition.complementaryFocusColor));
134 case BasicTheme::Window:
136 setTextColor(
tint(definition.textColor));
137 setBackgroundColor(
tint(definition.backgroundColor));
138 setAlternateBackgroundColor(
tint(definition.alternateBackgroundColor));
139 setHoverColor(
tint(definition.hoverColor));
140 setFocusColor(
tint(definition.focusColor));
144 setDisabledTextColor(
tint(definition.disabledTextColor));
145 setHighlightColor(
tint(definition.highlightColor));
146 setHighlightedTextColor(
tint(definition.highlightedTextColor));
147 setActiveTextColor(
tint(definition.activeTextColor));
148 setActiveBackgroundColor(
tint(definition.activeBackgroundColor));
149 setLinkColor(
tint(definition.linkColor));
150 setLinkBackgroundColor(
tint(definition.linkBackgroundColor));
151 setVisitedLinkColor(
tint(definition.visitedLinkColor));
152 setVisitedLinkBackgroundColor(
tint(definition.visitedLinkBackgroundColor));
153 setNegativeTextColor(
tint(definition.negativeTextColor));
154 setNegativeBackgroundColor(
tint(definition.negativeBackgroundColor));
155 setNeutralTextColor(
tint(definition.neutralTextColor));
156 setNeutralBackgroundColor(
tint(definition.neutralBackgroundColor));
157 setPositiveTextColor(
tint(definition.positiveTextColor));
158 setPositiveBackgroundColor(
tint(definition.positiveBackgroundColor));
160 setDefaultFont(definition.defaultFont);
161 setSmallFont(definition.smallFont);
164bool BasicTheme::event(
QEvent *event)
166 if (
event->type() == PlatformThemeEvents::DataChangedEvent::type) {
170 if (
event->type() == PlatformThemeEvents::ColorSetChangedEvent::type) {
174 if (
event->type() == PlatformThemeEvents::ColorGroupChangedEvent::type) {
178 if (
event->type() == PlatformThemeEvents::ColorChangedEvent::type) {
179 basicThemeInstance()->themeDefinition(qmlEngine(parent())).syncToQml(
this);
182 if (
event->type() == PlatformThemeEvents::FontChangedEvent::type) {
183 basicThemeInstance()->themeDefinition(qmlEngine(parent())).syncToQml(
this);
186 return PlatformTheme::event(event);
194 switch (colorGroup()) {
195 case PlatformTheme::Inactive:
197 case PlatformTheme::Disabled:
207#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)