2
* Copyright 2015 Canonical Ltd.
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU Lesser General Public License as published by
6
* the Free Software Foundation; version 3.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU Lesser General Public License for more details.
13
* You should have received a copy of the GNU Lesser General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Authors: Zsombor Egri <zsombor.egri@canonical.com>
19
#include "ucnamespace.h"
20
#include "ucdeprecatedtheme.h"
23
#include <QtQml/QQmlComponent>
24
#include <QtQml/QQmlContext>
25
#include <QtQml/QQmlInfo>
26
#include <QtQml/QQmlEngine>
31
\inqmlmodule Ubuntu.Components 1.1
33
\brief The Theme class provides facilities to interact with the current theme.
35
A global instance is exposed as the \b Theme context property.
37
The theme defines the visual aspect of the Ubuntu components.
39
Example changing the current theme:
43
import Ubuntu.Components 1.2
47
onClicked: Theme.name = "Ubuntu.Components.Themes.Ambiance"
52
Example creating a style component:
56
import Ubuntu.Components 1.2
60
style: Theme.createStyleComponent("MyItemStyle.qml", myItem)
66
UCDeprecatedTheme::UCDeprecatedTheme(QObject *parent)
69
m_notes = QHash<QString, bool>();
70
connect(&UCTheme::defaultTheme(), &UCTheme::nameChanged,
71
this, &UCDeprecatedTheme::nameChanged);
72
connect(&UCTheme::defaultTheme(), &UCTheme::paletteChanged,
73
this, &UCDeprecatedTheme::paletteChanged);
76
void UCDeprecatedTheme::showDeprecatedNote(QObject *onItem, const char *note)
78
QQmlContext ctx(QQmlEngine::contextForObject(onItem));
79
// No warnings due to deprecated code used in the components themselves
80
if (ctx.baseUrl().toString().contains("/Ubuntu/Components/"))
82
// Warnings without a filename are not helpful
83
if (ctx.baseUrl().isEmpty())
86
QString noteId(QString("%1.%2").arg(note).arg(onItem->metaObject()->className()));
87
if (m_notes.contains(noteId))
89
QByteArray suppressNote = qgetenv("SUPPRESS_DEPRECATED_NOTE");
90
if (suppressNote.isEmpty() || suppressNote != "yes") {
91
qmlInfo(onItem) << note;
92
m_notes.insert(noteId, true);
97
\qmlproperty string Theme::name
99
The name of the current theme.
101
QString UCDeprecatedTheme::name()
103
showDeprecatedNote(this, "Theme.name is deprecated. Use ThemeSettings instead.");
104
return UCTheme::defaultTheme().name();
106
void UCDeprecatedTheme::setName(const QString& name)
108
showDeprecatedNote(this, "Theme.name is deprecated. Use ThemeSettings instead.");
109
UCTheme::defaultTheme().setName(name);
111
void UCDeprecatedTheme::resetName()
113
showDeprecatedNote(this, "Theme.name is deprecated. Use ThemeSettings instead.");
114
UCTheme::defaultTheme().resetName();
118
\qmlproperty Palette Theme::palette
120
The palette of the current theme.
122
QObject* UCDeprecatedTheme::palette()
124
showDeprecatedNote(this, "Theme.palette is deprecated. Use ThemeSettings instead.");
125
return UCTheme::defaultTheme().palette();
129
\qmlmethod Component Theme::createStyleComponent(string styleName, object parent)
131
Returns an instance of the style component named \a styleName.
133
QQmlComponent* UCDeprecatedTheme::createStyleComponent(const QString& styleName, QObject* parent)
135
showDeprecatedNote(parent, "Theme.createStyleComponent() is deprecated. Use ThemeSettings instead.");
136
return UCTheme::defaultTheme().createStyleComponent(styleName, parent, BUILD_VERSION(1, 2));
139
void UCDeprecatedTheme::registerToContext(QQmlContext* context)
141
UCTheme::defaultTheme().m_engine = context->engine();
142
UCTheme::defaultTheme().updateEnginePaths();
143
// register deprecated Theme property
144
context->setContextProperty("Theme", this);
146
ContextPropertyChangeListener *themeChangeListener =
147
new ContextPropertyChangeListener(context, "Theme");
148
QObject::connect(this, SIGNAL(nameChanged()),
149
themeChangeListener, SLOT(updateContextProperty()));