Commit c3a2cd19 authored by Thomas BOUTROUE's avatar Thomas BOUTROUE

Add basic support for QML2CSS code generation

parent 7b317393
Pipeline #586 passed with stage
in 6 seconds
......@@ -11,26 +11,32 @@ void QmlNoOutputScript::execute (void) {
emit execution ();
}
// EXPORTABLE OBJECT
// EXPORTABLE INTERFACE
QmlAbstractExportableObject::QmlAbstractExportableObject (QObject * parent)
QmlExportableInterface::QmlExportableInterface (QObject * parent)
: QObject (parent)
, m_others (this)
, m_children (this)
, m_active (true)
, m_activeChildren (true)
{ }
void QmlAbstractExportableObject::exportOutput (QString & output) const {
void QmlExportableInterface::exportOutput (QString & output) const {
if (m_active) {
outputContent (output);
}
}
// EXPORTABLE OBJECT
QmlAbstractExportableObject::QmlAbstractExportableObject (QObject * parent)
: QmlExportableInterface (parent)
, m_others (this)
, m_children (this)
, m_activeChildren (true)
{ }
void QmlAbstractExportableObject::exportChildrenOuput (QString & output) const {
if (m_activeChildren) {
const QVector<QmlAbstractExportableObject *> & list = m_children.items ();
for (QVector<QmlAbstractExportableObject *>::const_iterator it = list.constBegin (); it != list.constEnd (); it++) {
const QVector<QmlExportableInterface *> & list = m_children.items ();
for (QVector<QmlExportableInterface *>::const_iterator it = list.constBegin (); it != list.constEnd (); it++) {
(* it)->exportOutput (output);
}
}
......@@ -39,14 +45,9 @@ void QmlAbstractExportableObject::exportChildrenOuput (QString & output) const {
// REPEATER
QmlRepeater::QmlRepeater (QObject * parent)
: QmlAbstractExportableObject (parent)
: QmlExportableInterface (parent)
{ }
QByteArray QmlRepeater::outputMimeType (void) const {
static const QByteArray ret;
return ret;
}
void QmlRepeater::outputContent (QString & output) const {
static const QString MODEL_DATA = QS ("modelData");
if (m_delegate != Q_NULLPTR) {
......@@ -57,7 +58,7 @@ void QmlRepeater::outputContent (QString & output) const {
for (QVariantList::const_iterator it = m_model.constBegin (); it != m_model.constEnd (); it++) {
const QVariant modelData = (* it);
subContext.setContextProperty (MODEL_DATA, modelData);
QmlAbstractExportableObject * exportableObject = qmlCreateInstance<QmlAbstractExportableObject> (m_delegate, &subContext);
QmlExportableInterface * exportableObject = qmlCreateInstance<QmlExportableInterface> (m_delegate, &subContext);
if (exportableObject != Q_NULLPTR) {
exportableObject->exportOutput (output);
exportableObject->deleteLater ();
......
......@@ -15,11 +15,24 @@ signals:
void execution (void);
};
class QmlAbstractExportableObject : public QObject {
class QmlExportableInterface : public QObject {
Q_OBJECT
QML_LIST_PROPERTY (QObject, others)
QML_LIST_PROPERTY (QmlAbstractExportableObject, children)
QML_WRITABLE_VAR_PROPERTY (bool, active)
public:
explicit QmlExportableInterface (QObject * parent = Q_NULLPTR);
virtual ~QmlExportableInterface (void) { }
void exportOutput (QString & output) const;
protected:
virtual void outputContent (QString & output) const = 0;
};
class QmlAbstractExportableObject : public QmlExportableInterface {
Q_OBJECT
QML_LIST_PROPERTY (QObject, others)
QML_LIST_PROPERTY (QmlExportableInterface, children)
QML_WRITABLE_VAR_PROPERTY (bool, activeChildren)
public:
......@@ -28,18 +41,14 @@ public:
virtual QByteArray outputMimeType (void) const = 0;
void exportOutput (QString & output) const;
void exportChildrenOuput (QString & output) const;
signals:
void beforeExecution (void);
void afterExecution (void);
protected:
virtual void outputContent (QString & output) const = 0;
};
class QmlRepeater : public QmlAbstractExportableObject {
class QmlRepeater : public QmlExportableInterface {
Q_OBJECT
QML_DEFAULT_PROPERTY (delegate)
QML_WRITABLE_PTR_PROPERTY (QQmlComponent, delegate)
......@@ -48,8 +57,6 @@ class QmlRepeater : public QmlAbstractExportableObject {
public:
explicit QmlRepeater (QObject * parent = Q_NULLPTR);
QByteArray outputMimeType (void) const Q_DECL_OVERRIDE;
protected:
void outputContent (QString & output) const Q_DECL_OVERRIDE;
};
......
This diff is collapsed.
......@@ -22,7 +22,6 @@ public:
protected:
void outputContent (QString & output) const Q_DECL_OVERRIDE;
};
class QmlCssInlineStyle : public QmlAbstractCssObject {
......@@ -36,4 +35,333 @@ protected:
void outputContent (QString & output) const Q_DECL_OVERRIDE;
};
class QmlCssSingleton : public QObject {
Q_OBJECT
public:
explicit QmlCssSingleton (QObject * parent = Q_NULLPTR);
static QObject * singletonProvider (QQmlEngine * qmlEngine, QJSEngine * jsEngine);
enum Literals {
// misc
Inherit,
None,
Auto,
Both,
Normal,
Solid,
Hidden,
NoWrap,
// box
Block,
Inline,
InlineBlock,
// pos
Fixed,
Relative,
Absolute,
Top,
Left,
Right,
Bottom,
Center,
// font
Underline,
Italic,
Bold,
Justify,
};
Q_ENUMS (Literals)
Q_INVOKABLE QString literal (const int val) const;
Q_INVOKABLE QString px (const int val) const;
Q_INVOKABLE QString num (const int val) const;
Q_INVOKABLE QString percent (const int val) const;
Q_INVOKABLE QString rgba (const qreal r, const qreal g, const qreal b, const qreal a) const;
Q_INVOKABLE QString quote (const QString & str) const;
Q_INVOKABLE QString url (const QString & str) const;
Q_INVOKABLE QString format (const QString & fmt) const;
};
struct QmlCssProperty {
const QString key;
QString value;
explicit QmlCssProperty (const QString & cssKey);
void exportOutput (QString & output) const;
};
#define QML_CSS_PROPERTY(NAME) \
protected: Q_PROPERTY (QString NAME READ get_##NAME WRITE set_##NAME NOTIFY NAME##Changed) \
private: QmlCssProperty m_##NAME; \
Q_SIGNALS: void NAME##Changed (void); \
public: const QString & get_##NAME (void) const { return m_##NAME.value; } \
public: void set_##NAME (const QString & value) { if (m_##NAME.value != value) { m_##NAME.value = value; emit NAME##Changed (); } } \
private:
#define QML_CSS_GROUP(CLASS, NAME) \
protected: Q_PROPERTY (CLASS * NAME READ get_##NAME CONSTANT) \
private: CLASS m_##NAME; \
public: CLASS * get_##NAME (void) { return &m_##NAME; } \
private:
class QmlCssBackground : public QmlExportableInterface {
Q_OBJECT
QML_CSS_PROPERTY (color)
QML_CSS_PROPERTY (image)
QML_CSS_PROPERTY (position)
QML_CSS_PROPERTY (repeat)
QML_CSS_PROPERTY (clip)
QML_CSS_PROPERTY (origin)
QML_CSS_PROPERTY (size)
QML_CSS_PROPERTY (attachment)
public:
explicit QmlCssBackground (const QString & prefix, QObject * parent = Q_NULLPTR);
protected:
void outputContent (QString & output) const Q_DECL_OVERRIDE;
};
class QmlCssBorderSide : public QmlExportableInterface {
Q_OBJECT
QML_CSS_PROPERTY (width)
QML_CSS_PROPERTY (color)
QML_CSS_PROPERTY (style)
public:
explicit QmlCssBorderSide (const QString & prefix, QObject * parent = Q_NULLPTR);
protected:
void outputContent (QString & output) const Q_DECL_OVERRIDE;
};
class QmlCssBorder : public QmlExportableInterface {
Q_OBJECT
QML_CSS_GROUP (QmlCssBorderSide, all)
QML_CSS_GROUP (QmlCssBorderSide, top)
QML_CSS_GROUP (QmlCssBorderSide, left)
QML_CSS_GROUP (QmlCssBorderSide, right)
QML_CSS_GROUP (QmlCssBorderSide, bottom)
public:
explicit QmlCssBorder (const QString & prefix, QObject * parent = Q_NULLPTR);
protected:
void outputContent (QString & output) const Q_DECL_OVERRIDE;
};
class QmlCssBorderRadius : public QmlExportableInterface {
Q_OBJECT
QML_CSS_PROPERTY (all)
QML_CSS_PROPERTY (topLeft)
QML_CSS_PROPERTY (topRight)
QML_CSS_PROPERTY (bottomLeft)
QML_CSS_PROPERTY (bottomRight)
public:
explicit QmlCssBorderRadius (const QString & prefix, QObject * parent = Q_NULLPTR);
protected:
void outputContent (QString & output) const Q_DECL_OVERRIDE;
};
class QmlCssTextShadow : public QmlExportableInterface {
Q_OBJECT
QML_CSS_PROPERTY (vOffset)
QML_CSS_PROPERTY (hOffset)
QML_CSS_PROPERTY (color)
QML_CSS_PROPERTY (blur)
public:
explicit QmlCssTextShadow (const QString & prefix, QObject * parent = Q_NULLPTR);
protected:
void outputContent (QString & output) const Q_DECL_OVERRIDE;
};
class QmlCssBoxShadow : public QmlExportableInterface {
Q_OBJECT
QML_CSS_PROPERTY (vOffset)
QML_CSS_PROPERTY (hOffset)
QML_CSS_PROPERTY (color)
QML_CSS_PROPERTY (spread)
QML_CSS_PROPERTY (blur)
public:
explicit QmlCssBoxShadow (const QString & prefix, QObject * parent = Q_NULLPTR);
protected:
void outputContent (QString & output) const Q_DECL_OVERRIDE;
};
class QmlCssFont : public QmlExportableInterface {
Q_OBJECT
QML_CSS_PROPERTY (size)
QML_CSS_PROPERTY (weight)
QML_CSS_PROPERTY (style)
QML_CSS_PROPERTY (family)
public:
explicit QmlCssFont (const QString & prefix, QObject * parent = Q_NULLPTR);
protected:
void outputContent (QString & output) const Q_DECL_OVERRIDE;
};
class QmlCssDecoration : public QmlExportableInterface {
Q_OBJECT
QML_CSS_PROPERTY (color)
QML_CSS_PROPERTY (line)
QML_CSS_PROPERTY (style)
public:
explicit QmlCssDecoration (const QString & prefix, QObject * parent = Q_NULLPTR);
protected:
void outputContent (QString & output) const Q_DECL_OVERRIDE;
};
class QmlCssText : public QmlExportableInterface {
Q_OBJECT
QML_CSS_PROPERTY (decoration)
QML_CSS_PROPERTY (align)
QML_CSS_PROPERTY (indent)
public:
explicit QmlCssText (const QString & prefix, QObject * parent = Q_NULLPTR);
protected:
void outputContent (QString & output) const Q_DECL_OVERRIDE;
};
class QmlCssPosition : public QmlExportableInterface {
Q_OBJECT
QML_CSS_PROPERTY (type)
QML_CSS_PROPERTY (top)
QML_CSS_PROPERTY (left)
QML_CSS_PROPERTY (right)
QML_CSS_PROPERTY (bottom)
public:
explicit QmlCssPosition (const QString & prefix, QObject * parent = Q_NULLPTR);
protected:
void outputContent (QString & output) const Q_DECL_OVERRIDE;
};
class QmlCssPoint : public QmlExportableInterface {
Q_OBJECT
QML_CSS_PROPERTY (x)
QML_CSS_PROPERTY (y)
public:
explicit QmlCssPoint (const QString & prefix, QObject * parent = Q_NULLPTR);
protected:
void outputContent (QString & output) const Q_DECL_OVERRIDE;
};
class QmlCssSides : public QmlExportableInterface {
Q_OBJECT
QML_CSS_PROPERTY (all)
QML_CSS_PROPERTY (top)
QML_CSS_PROPERTY (left)
QML_CSS_PROPERTY (right)
QML_CSS_PROPERTY (bottom)
public:
explicit QmlCssSides (const QString & prefix, QObject * parent = Q_NULLPTR);
protected:
void outputContent (QString & output) const Q_DECL_OVERRIDE;
};
class QmlCssListStyle : public QmlExportableInterface {
Q_OBJECT
QML_CSS_PROPERTY (type)
QML_CSS_PROPERTY (image)
QML_CSS_PROPERTY (position)
public:
explicit QmlCssListStyle (const QString & prefix, QObject * parent = Q_NULLPTR);
protected:
void outputContent (QString & output) const Q_DECL_OVERRIDE;
};
class QmlCssCounter : public QmlExportableInterface {
Q_OBJECT
QML_CSS_PROPERTY (increment)
QML_CSS_PROPERTY (reset)
public:
explicit QmlCssCounter (const QString & prefix, QObject * parent = Q_NULLPTR);
protected:
void outputContent (QString & output) const Q_DECL_OVERRIDE;
};
class QmlCssRule : public QmlExportableInterface {
Q_OBJECT
QML_WRITABLE_CSTREF_PROPERTY (QString, selector)
QML_CSS_PROPERTY (x)
QML_CSS_PROPERTY (y)
QML_CSS_PROPERTY (zIndex)
QML_CSS_PROPERTY (width)
QML_CSS_PROPERTY (height)
QML_CSS_PROPERTY (minWidth)
QML_CSS_PROPERTY (minHeight)
QML_CSS_PROPERTY (maxWidth)
QML_CSS_PROPERTY (maxHeight)
QML_CSS_PROPERTY (color)
QML_CSS_PROPERTY (opacity)
QML_CSS_PROPERTY (display)
QML_CSS_PROPERTY (visibility)
QML_CSS_PROPERTY (clip)
QML_CSS_PROPERTY (floatSet)
QML_CSS_PROPERTY (floatClear)
QML_CSS_PROPERTY (whiteSpace)
QML_CSS_PROPERTY (wordWrap)
QML_CSS_PROPERTY (lineHeight)
QML_CSS_PROPERTY (verticalAlign)
QML_CSS_PROPERTY (src)
QML_CSS_PROPERTY (content)
QML_CSS_GROUP (QmlCssBackground, background)
QML_CSS_GROUP (QmlCssBorder, border)
QML_CSS_GROUP (QmlCssBorderRadius, borderRadius)
QML_CSS_GROUP (QmlCssTextShadow, textShadow)
QML_CSS_GROUP (QmlCssBoxShadow, boxShadow)
QML_CSS_GROUP (QmlCssFont, font)
QML_CSS_GROUP (QmlCssText, text)
QML_CSS_GROUP (QmlCssPosition, position)
QML_CSS_GROUP (QmlCssPoint, overflow)
QML_CSS_GROUP (QmlCssSides, padding)
QML_CSS_GROUP (QmlCssSides, margin)
QML_CSS_GROUP (QmlCssListStyle, listStyle)
QML_CSS_GROUP (QmlCssCounter, counter)
public:
explicit QmlCssRule (QObject * parent = Q_NULLPTR);
protected:
void outputContent (QString & output) const Q_DECL_OVERRIDE;
};
class QmlCssStylesheet : public QmlAbstractCssObject {
Q_OBJECT
QML_DEFAULT_PROPERTY (children)
public:
explicit QmlCssStylesheet (QObject * parent = Q_NULLPTR);
protected:
void outputContent (QString & output) const Q_DECL_OVERRIDE;
};
#endif // CSS_H
......@@ -85,11 +85,27 @@ void QmlHttpServer::registerQmlTypes (void) {
static const char * err ("!!!");
qmlRegisterSingletonType<QmlSqlSingleton> (uri, maj, min, "SQL", &QmlSqlSingleton::singletonProvider);
qmlRegisterSingletonType<QmlHtmlSingleton> (uri, maj, min, "HTML", &QmlHtmlSingleton::singletonProvider);
qmlRegisterSingletonType<QmlCssSingleton> (uri, maj, min, "CSS", &QmlCssSingleton::singletonProvider);
qmlRegisterUncreatableType<QmlExportableInterface> (uri, maj, min, "ExportableInterface", err);
qmlRegisterUncreatableType<QmlAbstractExportableObject> (uri, maj, min, "AbstractExportableObject", err);
qmlRegisterUncreatableType<QmlAbstractHtmlObject> (uri, maj, min, "AbstractHtmlObject", err);
qmlRegisterUncreatableType<QmlAbstractCssObject> (uri, maj, min, "AbstractCssObject", err);
qmlRegisterUncreatableType<QmlFileUpload> (uri, maj, min, "FileUpload", err);
qmlRegisterUncreatableType<QmlSqlQuery> (uri, maj, min, "SqlQuery", err);
qmlRegisterUncreatableType<QmlCssBackground> (uri, maj, min, "CssBackground", err);
qmlRegisterUncreatableType<QmlCssBorder> (uri, maj, min, "CssBorder", err);
qmlRegisterUncreatableType<QmlCssBorderRadius> (uri, maj, min, "CssBorderRadius", err);
qmlRegisterUncreatableType<QmlCssBorderSide> (uri, maj, min, "CssBorderSide", err);
qmlRegisterUncreatableType<QmlCssBoxShadow> (uri, maj, min, "CssBoxShadow", err);
qmlRegisterUncreatableType<QmlCssCounter> (uri, maj, min, "CssCounter", err);
qmlRegisterUncreatableType<QmlCssDecoration> (uri, maj, min, "CssDecoration", err);
qmlRegisterUncreatableType<QmlCssFont> (uri, maj, min, "CssFont", err);
qmlRegisterUncreatableType<QmlCssListStyle> (uri, maj, min, "CssListStyle", err);
qmlRegisterUncreatableType<QmlCssText> (uri, maj, min, "CssText", err);
qmlRegisterUncreatableType<QmlCssTextShadow> (uri, maj, min, "CssTextShadow", err);
qmlRegisterUncreatableType<QmlCssSides> (uri, maj, min, "CssSides", err);
qmlRegisterUncreatableType<QmlCssPosition> (uri, maj, min, "CssPosition", err);
qmlRegisterUncreatableType<QmlCssPoint> (uri, maj, min, "CssPoint", err);
qmlRegisterType<QObject> (uri, maj, min, "Object");
qmlRegisterType<QmlRepeater> (uri, maj, min, "Repeater");
qmlRegisterType<QmlHtmlPage> (uri, maj, min, "HtmlPage");
......@@ -100,6 +116,8 @@ void QmlHttpServer::registerQmlTypes (void) {
qmlRegisterType<QmlJsonDocument> (uri, maj, min, "JsonDocument");
qmlRegisterType<QmlCssFileReference> (uri, maj, min, "CssFileReference");
qmlRegisterType<QmlCssInlineStyle> (uri, maj, min, "CssInlineStyle");
qmlRegisterType<QmlCssRule> (uri, maj, min, "CssRule");
qmlRegisterType<QmlCssStylesheet> (uri, maj, min, "CssStylesheet");
}
void QmlHttpServer::initWebsite (void) {
......
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