Commit e9073375 authored by Lucien XU's avatar Lucien XU

Comments and cleanups

parent aafd0897
......@@ -56,10 +56,6 @@ Item {
text: isGlacier ? "Set Ugly Theme" : "Set Nice Theme"
onClicked: isGlacier ? Theme.loadFromFile("ugly.json")
: Theme.loadFromFile("glacier.json")
// NemoControls.setTheme((Theme.themeName == NemoControls.themes[0]) ? NemoControls.themes[1]
// : NemoControls.themes[0])
}
Button {
......
......@@ -58,7 +58,7 @@ QString NemoTheme::name() const
return m_name;
}
void NemoTheme::setName(QString name)
void NemoTheme::setName(const QString &name)
{
if (m_name != name) {
m_name = name;
......@@ -71,7 +71,7 @@ QString NemoTheme::description() const
return m_description;
}
void NemoTheme::setDescription(QString description)
void NemoTheme::setDescription(const QString &description)
{
if (m_description != description) {
m_description = description;
......@@ -109,9 +109,9 @@ static inline QJsonValue jsonValue(const QJsonObject &object, const QString &key
{
if (!object.contains(key)) {
if (objectName.isEmpty()) {
qWarning() << "W" << "Root JSON object do not have value" << key;
qWarning() << "W" << "Root JSON object does not have value" << key;
} else {
qWarning() << "W" << "JSON Object" << objectName << "do not have value" << key;
qWarning() << "W" << "JSON Object" << objectName << "does not have value" << key;
}
return QJsonValue();
}
......@@ -137,7 +137,9 @@ static inline QColor jsonToColor(const QJsonValue &value,
color = defines.value(color).toString();
}
if (!QColor::isValidColor(color)) {
// We need to skip the warning caused by a null value,
// so we check if the color is not empty
if (!QColor::isValidColor(color) && !color.isEmpty()) {
qWarning() << "W" << color << "is not a valid color";
return QColor();
}
......
......@@ -42,9 +42,9 @@ class NemoTheme: public QObject
public:
explicit NemoTheme(QObject *parent = 0);
QString name() const;
void setName(QString name);
void setName(const QString &name);
QString description() const;
void setDescription(QString description);
void setDescription(const QString &description);
NemoThemeButton * button() const;
NemoThemeButton * primaryButton() const;
NemoThemeGroove * groove() const;
......
......@@ -34,7 +34,7 @@ QColor NemoThemeButton::background() const
return m_background;
}
void NemoThemeButton::setBackground(QColor background)
void NemoThemeButton::setBackground(const QColor &background)
{
if (m_background != background) {
m_background = background;
......
......@@ -37,7 +37,7 @@ class NemoThemeButton: public QObject
public:
explicit NemoThemeButton(QObject *parent = 0);
QColor background() const;
void setBackground(QColor background);
void setBackground(const QColor &background);
NemoThemeButtonText * text() const;
NemoThemeButtonPressedGradient * pressedGradient() const;
Q_SIGNALS:
......
......@@ -36,7 +36,7 @@ QColor NemoThemeButtonPressedGradient::centerColor() const
return m_centerColor;
}
void NemoThemeButtonPressedGradient::setCenterColor(QColor centerColor)
void NemoThemeButtonPressedGradient::setCenterColor(const QColor &centerColor)
{
if (m_centerColor != centerColor) {
m_centerColor = centerColor;
......@@ -49,7 +49,7 @@ QColor NemoThemeButtonPressedGradient::edgeColor() const
return m_edgeColor;
}
void NemoThemeButtonPressedGradient::setEdgeColor(QColor edgeColor)
void NemoThemeButtonPressedGradient::setEdgeColor(const QColor &edgeColor)
{
if (m_edgeColor != edgeColor) {
m_edgeColor = edgeColor;
......@@ -62,7 +62,7 @@ int NemoThemeButtonPressedGradient::width() const
return m_width;
}
void NemoThemeButtonPressedGradient::setWidth(const int &width)
void NemoThemeButtonPressedGradient::setWidth(int width)
{
if (m_width != width) {
m_width = width;
......@@ -75,7 +75,7 @@ int NemoThemeButtonPressedGradient::height() const
return m_height;
}
void NemoThemeButtonPressedGradient::setHeight(const int &height)
void NemoThemeButtonPressedGradient::setHeight(int height)
{
if (m_height != height) {
m_height = height;
......@@ -88,7 +88,7 @@ double NemoThemeButtonPressedGradient::center() const
return m_center;
}
void NemoThemeButtonPressedGradient::setCenter(const double &center)
void NemoThemeButtonPressedGradient::setCenter(double center)
{
if (m_center != center) {
m_center = center;
......@@ -101,7 +101,7 @@ double NemoThemeButtonPressedGradient::edge() const
return m_edge;
}
void NemoThemeButtonPressedGradient::setEdge(const double &edge)
void NemoThemeButtonPressedGradient::setEdge(double edge)
{
if (m_edge != edge) {
m_edge = edge;
......
......@@ -38,17 +38,17 @@ class NemoThemeButtonPressedGradient: public QObject
public:
explicit NemoThemeButtonPressedGradient(QObject *parent = 0);
QColor centerColor() const;
void setCenterColor(QColor centerColor);
void setCenterColor(const QColor &centerColor);
QColor edgeColor() const;
void setEdgeColor(QColor edgeColor);
void setEdgeColor(const QColor &edgeColor);
int width() const;
void setWidth(const int &width);
void setWidth(int width);
int height() const;
void setHeight(const int &height);
void setHeight(int height);
double center() const;
void setCenter(const double &center);
void setCenter(double center);
double edge() const;
void setEdge(const double &edge);
void setEdge(double edge);
Q_SIGNALS:
void centerColorChanged();
void edgeColorChanged();
......
......@@ -33,7 +33,7 @@ QColor NemoThemeButtonText::color() const
return m_color;
}
void NemoThemeButtonText::setColor(QColor color)
void NemoThemeButtonText::setColor(const QColor &color)
{
if (m_color != color) {
m_color = color;
......
......@@ -35,7 +35,7 @@ class NemoThemeButtonText: public QObject
public:
explicit NemoThemeButtonText(QObject *parent = 0);
QColor color() const;
void setColor(QColor color);
void setColor(const QColor &color);
NemoThemeFont * font() const;
Q_SIGNALS:
void colorChanged();
......
......@@ -34,7 +34,7 @@ int NemoThemeFont::pointSize() const
return m_pointSize;
}
void NemoThemeFont::setPointSize(const int &pointSize)
void NemoThemeFont::setPointSize(int pointSize)
{
if (m_pointSize != pointSize) {
m_pointSize = pointSize;
......@@ -47,7 +47,7 @@ int NemoThemeFont::weight() const
return m_weight;
}
void NemoThemeFont::setWeight(const int &weight)
void NemoThemeFont::setWeight(int weight)
{
if (m_weight != weight) {
m_weight = weight;
......
......@@ -33,9 +33,9 @@ class NemoThemeFont: public QObject
public:
explicit NemoThemeFont(QObject *parent = 0);
int pointSize() const;
void setPointSize(const int &pointSize);
void setPointSize(int pointSize);
int weight() const;
void setWeight(const int &weight);
void setWeight(int weight);
Q_SIGNALS:
void pointSizeChanged();
void weightChanged();
......
......@@ -32,7 +32,7 @@ QColor NemoThemeGroove::background() const
return m_background;
}
void NemoThemeGroove::setBackground(QColor background)
void NemoThemeGroove::setBackground(const QColor &background)
{
if (m_background != background) {
m_background = background;
......@@ -45,7 +45,7 @@ QColor NemoThemeGroove::foreground() const
return m_foreground;
}
void NemoThemeGroove::setForeground(QColor foreground)
void NemoThemeGroove::setForeground(const QColor &foreground)
{
if (m_foreground != foreground) {
m_foreground = foreground;
......
......@@ -34,9 +34,9 @@ class NemoThemeGroove: public QObject
public:
explicit NemoThemeGroove(QObject *parent = 0);
QColor background() const;
void setBackground(QColor background);
void setBackground(const QColor &background);
QColor foreground() const;
void setForeground(QColor foreground);
void setForeground(const QColor &foreground);
Q_SIGNALS:
void backgroundChanged();
void foregroundChanged();
......
......@@ -32,7 +32,7 @@ QColor NemoThemeTextField::selectedTextColor() const
return m_selectedTextColor;
}
void NemoThemeTextField::setSelectedTextColor(QColor selectedTextColor)
void NemoThemeTextField::setSelectedTextColor(const QColor &selectedTextColor)
{
if (m_selectedTextColor != selectedTextColor) {
m_selectedTextColor = selectedTextColor;
......@@ -45,7 +45,7 @@ QColor NemoThemeTextField::selectionColor() const
return m_selectionColor;
}
void NemoThemeTextField::setSelectionColor(QColor selectionColor)
void NemoThemeTextField::setSelectionColor(const QColor &selectionColor)
{
if (m_selectionColor != selectionColor) {
m_selectionColor = selectionColor;
......
......@@ -34,9 +34,9 @@ class NemoThemeTextField: public QObject
public:
explicit NemoThemeTextField(QObject *parent = 0);
QColor selectedTextColor() const;
void setSelectedTextColor(QColor selectedTextColor);
void setSelectedTextColor(const QColor &selectedTextColor);
QColor selectionColor() const;
void setSelectionColor(QColor selectionColor);
void setSelectionColor(const QColor &selectionColor);
Q_SIGNALS:
void selectedTextColorChanged();
void selectionColorChanged();
......
/*
* Copyright (C) 2013 Tomasz Olszak <olszak.tomasz@gmail.com>
* Copyright (C) 2013 Andrea Bernabei <and.bernabei@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
import QtQuick 2.1
import QtQuick.Controls.Nemo 1.0
QtObject {
readonly property string fontFamily: fontLoader.name
property QtObject fontLoader: FontLoader {
source: "/usr/share/fonts/google-opensans/OpenSans-Regular.ttf"
}
// The binding updates this var when NemoControls.setTheme succeeds
readonly property var themeConfig: NemoControls.currentThemeConfig
readonly property string themeName: themeConfig.themeName
onThemeNameChanged: console.log("Theme successfully updated to " + themeName)
// ({ }) is QML notation for assigning JS object to a var property
// Automagically updated when themeConfig is updated
property var button :
({
backgroundColor: themeConfig.button.background,
text: {
color: themeConfig.button.text,
font: {
pointSize: 24,
weight: 25 //Font.Light
}
},
pressedGradient: {
width: 240,
height: 240,
center: 0.29,
edge: 0.5,
centerColor: themeConfig.button.pressedGradient.centerColor,
edgeColor: themeConfig.button.pressedGradient.edgeColor
}
})
// Only holds special styling for the primary button, the rest is in button
property var primaryButton:
({
backgroundColor: themeConfig.primaryButton.background,
text: {
font: {
weight: 63 //Font.DemiBold
}
},
pressedGradient: {
centerColor: themeConfig.primaryButton.pressedGradient.centerColor,
edgeColor: themeConfig.primaryButton.pressedGradient.edgeColor
}
})
property var groove:
({
foregroundColor: themeConfig.groove.foreground,
backgroundColor: themeConfig.groove.background,
})
property var textField:
({
selectionColor: themeConfig.textField.selectionColor,
selectedTextColor: themeConfig.textField.selectedTextColor,
})
}
......@@ -20,7 +20,7 @@
#include "qquicknemostyleextensionplugin.h"
#include <QtQml>
#include "nemotheme.h"
#include "autogenerated/nemotheme.h"
QQuickNemoStyleExtensionPlugin::QQuickNemoStyleExtensionPlugin(QObject *parent) :
QQmlExtensionPlugin(parent)
......
......@@ -78,23 +78,23 @@ images.path = $$[QT_INSTALL_QML]/$$PLUGIN_IMPORT_PATH
HEADERS += \
qquicknemostyleextensionplugin.h \
nemothemebutton.h \
nemothemebuttonpressedgradient.h \
nemothemebuttontext.h \
nemothemefont.h \
nemothemegroove.h \
nemothemetextfield.h \
nemotheme.h
autogenerated/nemotheme.h \
autogenerated/nemothemebutton.h \
autogenerated/nemothemebuttonpressedgradient.h \
autogenerated/nemothemebuttontext.h \
autogenerated/nemothemefont.h \
autogenerated/nemothemegroove.h \
autogenerated/nemothemetextfield.h
SOURCES += \
qquicknemostyleextensionplugin.cpp \
nemothemebutton.cpp \
nemothemebuttonpressedgradient.cpp \
nemothemebuttontext.cpp \
nemothemefont.cpp \
nemothemegroove.cpp \
nemothemetextfield.cpp \
nemotheme.cpp
autogenerated/nemotheme.cpp \
autogenerated/nemothemebutton.cpp \
autogenerated/nemothemebuttonpressedgradient.cpp \
autogenerated/nemothemebuttontext.cpp \
autogenerated/nemothemefont.cpp \
autogenerated/nemothemegroove.cpp \
autogenerated/nemothemetextfield.cpp
INSTALLS += target images qmlfiles themes
......
How to use the components generator
1. Have python 2 installed (the script don't work with Python 3 yet)
2. Add the components in "components.json"
3. call "./themehelper.py components.json"
4. copy all the generated files to the style folder in src
5. qmlRegisterUncreatableType the new created components in qquicknemostyleextensionplugin.cpp and
adds them in the style.pro file
6. update theme files if needed
......@@ -53,8 +53,11 @@ license = """/*
// Any modification done in this file will be overridden
"""
# Used by formatting functions
basicTypes = ["int", "float", "double"]
# Formatting functions
def _getType(property):
if "type" in property:
return property["type"]
......@@ -64,7 +67,7 @@ def _getType(property):
def _getArgumentType(property):
if "type" in property:
type = property["type"]
if type in basicTypes:
if type not in basicTypes:
return "const " + type + " &"
return type + " "
if "object" in property:
......@@ -73,6 +76,8 @@ def _getArgumentType(property):
def _getUpper(name):
return name[0].upper() + name[1:]
# Generates some basic entries
# (includes, Q_PROPERTY macro, getter or setters etc)
def _getInclude(property):
if "type" in property:
type = property["type"]
......@@ -136,9 +141,9 @@ static inline QJsonValue jsonValue(const QJsonObject &object, const QString &key
{
if (!object.contains(key)) {
if (objectName.isEmpty()) {
qWarning() << "W" << "Root JSON object do not have value" << key;
qWarning() << "W" << "Root JSON object does not have value" << key;
} else {
qWarning() << "W" << "JSON Object" << objectName << "do not have value" << key;
qWarning() << "W" << "JSON Object" << objectName << "does not have value" << key;
}
return QJsonValue();
}
......@@ -164,7 +169,9 @@ static inline QColor jsonToColor(const QJsonValue &value,
color = defines.value(color).toString();
}
if (!QColor::isValidColor(color)) {
// We need to skip the warning caused by a null value,
// so we check if the color is not empty
if (!QColor::isValidColor(color) && !color.isEmpty()) {
qWarning() << "W" << color << "is not a valid color";
return QColor();
}
......@@ -203,6 +210,7 @@ static inline int jsonToDouble(const QJsonValue &value,
"""
# Generate the method that loads from file
source += "void " + name + "::loadFromFile(const QString &fileName)\n"
source += """{
QDir dir (THEME_DIR);
......@@ -263,7 +271,8 @@ static inline int jsonToDouble(const QJsonValue &value,
return;
}
"""
# We create a map of components
# We create a map of components that can be used
# to quickly retrieve a component based on the name
components = {}
for component in data["components"]:
components[component["name"]] = component["properties"]
......@@ -312,6 +321,10 @@ def _getCasted(property, jsonObject, name, cppObject):
return data
# This method is used to generate the tree of components and set calls
# it will start with a root component property, try to load all properties
# from theme file (and ignore those already defined), and continue
# with children components.
def _getSetObject(jsonObject, cppObject, name, properties, components):
data = " // Setting properties for " + name + "\n"
data += " QJsonObject " + jsonObject + _getUpper(name) + " = " + jsonObject
......
......@@ -17,6 +17,39 @@
}
]
},
{
"name": "Groove",
"properties": [
{
"name": "background",
"type": "QColor"
},
{
"name": "foreground",
"type": "QColor"
}
]
},
{
"name": "TextField",
"properties": [
{
"name": "selectedTextColor",
"type": "QColor"
},
{
"name": "selectionColor",
"type": "QColor"
}
]
},
{
"name": "ButtonPressedGradient",
"properties": [
......@@ -78,33 +111,6 @@
}
]
},
{
"name": "Groove",
"properties": [
{
"name": "background",
"type": "QColor"
},
{
"name": "foreground",
"type": "QColor"
}
]
},
{
"name": "TextField",
"properties": [
{
"name": "selectedTextColor",
"type": "QColor"
},
{
"name": "selectionColor",
"type": "QColor"
}
]
}
],
"properties": [
{
......
#!/bin/bash
# Copyright (C) 2013 Lucien Xu <sfietkonstantin@free.fr>
#
# You may use this file under the terms of the BSD license as follows:
#
# "Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Nemo Mobile nor the names of its contributors
# may be used to endorse or promote products derived from this
# software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
themehelper.py components.json
\ No newline at end of file
......@@ -28,6 +28,51 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
# Generates components from a JSON description file
#
# This script generates components from a JSON description file.
# The JSON description file have the following organization
# {
# "components": [
# list of components
# ],
# "properties": [ list of properties ],
# "font": "/path/to/some_font.ttf"
# }
#
# The "components" is the list of components that should be generated.
# Each component have a "name", and a list of "properties". A property
# is a list of objects defined this way:
# {
# "name": "someName",
# "type": "some_type",
# ["default": some_value]
# }
# or
# {
# "name": "someName",
# "object": "some_object"
# }
#
# The first variation defines a simple property. "type" field should
# contain the name of either a basic type, like int, or float, or
# a Qt object, like QColor and QString. The optional "default" field
# contains a default value that is embedded in the component.
# Properties with default values don't need to be defined in the
# theme file.
#
# The second variation contains an object definition. Usually, an
# object defines a complex type, that needs several basic types to be
# defined, like a gradient, that needs 2 colors, and maybe a radius.
#
# The "properties" field of the root object behave the same, and
# describes the properties that the Theme object have. Note that
# "name" and "description" are automatically provided by the
# script, and don't need to be defined in the properties.
#
# The last field is the font. It provides the default font that
# is available from the Theme object.
import json
import classgenerator
import argparse
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment