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 (!component.isError()) {
54 auto result = component.create();
55 if (
auto themeDefinition = qobject_cast<BasicThemeDefinition *>(result)) {
56 m_themeDefinition.reset(themeDefinition);
58 const auto errors = component.errors();
59 for (
auto error : errors) {
60 qCWarning(KirigamiPlatform) <<
error.toString();
63 qCWarning(KirigamiPlatform) <<
"Invalid Theme file, using default Basic theme.";
64 m_themeDefinition = std::make_unique<BasicThemeDefinition>();
67 qCDebug(KirigamiPlatform) <<
"No Theme file found, using default Basic theme";
68 m_themeDefinition = std::make_unique<BasicThemeDefinition>();
71 connect(m_themeDefinition.get(), &BasicThemeDefinition::changed,
this, &BasicThemeInstance::onDefinitionChanged);
73 return *m_themeDefinition;
76void BasicThemeInstance::onDefinitionChanged()
78 for (
auto watcher :
std::as_const(watchers)) {
83Q_GLOBAL_STATIC(BasicThemeInstance, basicThemeInstance)
85BasicTheme::BasicTheme(
QObject *parent)
86 : PlatformTheme(parent)
88 basicThemeInstance()->watchers.append(
this);
93BasicTheme::~BasicTheme()
95 basicThemeInstance()->watchers.removeOne(
this);
98void BasicTheme::sync()
100 auto &definition = basicThemeInstance()->themeDefinition(qmlEngine(parent()));
102 switch (colorSet()) {
103 case BasicTheme::Button:
104 setTextColor(
tint(definition.buttonTextColor));
105 setBackgroundColor(
tint(definition.buttonBackgroundColor));
106 setAlternateBackgroundColor(
tint(definition.buttonAlternateBackgroundColor));
107 setHoverColor(
tint(definition.buttonHoverColor));
108 setFocusColor(
tint(definition.buttonFocusColor));
110 case BasicTheme::View:
111 setTextColor(
tint(definition.viewTextColor));
112 setBackgroundColor(
tint(definition.viewBackgroundColor));
113 setAlternateBackgroundColor(
tint(definition.viewAlternateBackgroundColor));
114 setHoverColor(
tint(definition.viewHoverColor));
115 setFocusColor(
tint(definition.viewFocusColor));
117 case BasicTheme::Selection:
118 setTextColor(
tint(definition.selectionTextColor));
119 setBackgroundColor(
tint(definition.selectionBackgroundColor));
120 setAlternateBackgroundColor(
tint(definition.selectionAlternateBackgroundColor));
121 setHoverColor(
tint(definition.selectionHoverColor));
122 setFocusColor(
tint(definition.selectionFocusColor));
124 case BasicTheme::Tooltip:
125 setTextColor(
tint(definition.tooltipTextColor));
126 setBackgroundColor(
tint(definition.tooltipBackgroundColor));
127 setAlternateBackgroundColor(
tint(definition.tooltipAlternateBackgroundColor));
128 setHoverColor(
tint(definition.tooltipHoverColor));
129 setFocusColor(
tint(definition.tooltipFocusColor));
131 case BasicTheme::Complementary:
132 setTextColor(
tint(definition.complementaryTextColor));
133 setBackgroundColor(
tint(definition.complementaryBackgroundColor));
134 setAlternateBackgroundColor(
tint(definition.complementaryAlternateBackgroundColor));
135 setHoverColor(
tint(definition.complementaryHoverColor));
136 setFocusColor(
tint(definition.complementaryFocusColor));
138 case BasicTheme::Window:
140 setTextColor(
tint(definition.textColor));
141 setBackgroundColor(
tint(definition.backgroundColor));
142 setAlternateBackgroundColor(
tint(definition.alternateBackgroundColor));
143 setHoverColor(
tint(definition.hoverColor));
144 setFocusColor(
tint(definition.focusColor));
148 setDisabledTextColor(
tint(definition.disabledTextColor));
149 setHighlightColor(
tint(definition.highlightColor));
150 setHighlightedTextColor(
tint(definition.highlightedTextColor));
151 setActiveTextColor(
tint(definition.activeTextColor));
152 setActiveBackgroundColor(
tint(definition.activeBackgroundColor));
153 setLinkColor(
tint(definition.linkColor));
154 setLinkBackgroundColor(
tint(definition.linkBackgroundColor));
155 setVisitedLinkColor(
tint(definition.visitedLinkColor));
156 setVisitedLinkBackgroundColor(
tint(definition.visitedLinkBackgroundColor));
157 setNegativeTextColor(
tint(definition.negativeTextColor));
158 setNegativeBackgroundColor(
tint(definition.negativeBackgroundColor));
159 setNeutralTextColor(
tint(definition.neutralTextColor));
160 setNeutralBackgroundColor(
tint(definition.neutralBackgroundColor));
161 setPositiveTextColor(
tint(definition.positiveTextColor));
162 setPositiveBackgroundColor(
tint(definition.positiveBackgroundColor));
164 setDefaultFont(definition.defaultFont);
165 setSmallFont(definition.smallFont);
168bool BasicTheme::event(
QEvent *event)
170 if (
event->type() == PlatformThemeEvents::DataChangedEvent::type) {
174 if (
event->type() == PlatformThemeEvents::ColorSetChangedEvent::type) {
178 if (
event->type() == PlatformThemeEvents::ColorGroupChangedEvent::type) {
182 if (
event->type() == PlatformThemeEvents::ColorChangedEvent::type) {
183 basicThemeInstance()->themeDefinition(qmlEngine(parent())).syncToQml(
this);
186 if (
event->type() == PlatformThemeEvents::FontChangedEvent::type) {
187 basicThemeInstance()->themeDefinition(qmlEngine(parent())).syncToQml(
this);
190 return PlatformTheme::event(event);
195 switch (colorGroup()) {
196 case PlatformTheme::Inactive:
198 case PlatformTheme::Disabled:
208#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
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)