summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Alpert <alan.alpert@nokia.com>2009-09-02 06:36:49 (GMT)
committerAlan Alpert <alan.alpert@nokia.com>2009-09-02 06:36:49 (GMT)
commit9b1c76795b9982d3b63c300df6d3ae8354b21cf3 (patch)
treeed624d36e53f70548c729a3092e4f47d830b35b6
parent5994577c403d8622c535fa5d7fd3fd2d8b364043 (diff)
parentb6e26ee808ae3ffe1c4fba03cc89baf47d65d3a8 (diff)
downloadQt-9b1c76795b9982d3b63c300df6d3ae8354b21cf3.zip
Qt-9b1c76795b9982d3b63c300df6d3ae8354b21cf3.tar.gz
Qt-9b1c76795b9982d3b63c300df6d3ae8354b21cf3.tar.bz2
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
-rw-r--r--src/declarative/fx/qfxrect.cpp61
-rw-r--r--src/declarative/fx/qfxrect.h4
-rw-r--r--src/declarative/fx/qfxrect_p.h1
-rw-r--r--src/declarative/qml/qmldeclarativedata_p.h5
-rw-r--r--src/declarative/qml/qmlengine.cpp112
-rw-r--r--src/declarative/qml/qmlengine_p.h4
-rw-r--r--src/declarative/qml/qmlenginedebug.cpp11
-rw-r--r--src/declarative/qml/qmlinfo.cpp16
-rw-r--r--src/declarative/qml/qmlinstruction_p.h1
-rw-r--r--src/declarative/qml/qmlvme.cpp5
10 files changed, 153 insertions, 67 deletions
diff --git a/src/declarative/fx/qfxrect.cpp b/src/declarative/fx/qfxrect.cpp
index f8223f2..fbd7ee8 100644
--- a/src/declarative/fx/qfxrect.cpp
+++ b/src/declarative/fx/qfxrect.cpp
@@ -328,63 +328,6 @@ void QFxRect::setColor(const QColor &c)
update();
}
-/*!
- \qmlproperty color Rectangle::tintColor
- This property holds The color to tint the rectangle.
-
- This color will be drawn over the rectangle's color when the rectangle is painted. The tint color should usually be mostly transparent, or you will not be able to see the underlying color. The below example provides a slight red tint by having the tint color be pure red which is only 1/16th opaque.
-
- \qml
- Rectangle { x: 0; width: 80; height: 80; color: "lightsteelblue" }
- Rectangle { x: 100; width: 80; height: 80; color: "lightsteelblue"; tintColor: "#10FF0000" }
- \endqml
- \image declarative-rect_tint.png
-
- This attribute is not intended to be used with a single color over the lifetime of an user interface. It is most useful when a subtle change is intended to be conveyed due to some event; you can then use the tint color to more effectively tune the visible color.
-*/
-QColor QFxRect::tintColor() const
-{
- Q_D(const QFxRect);
- return d->tintColor;
-}
-
-void QFxRect::setTintColor(const QColor &c)
-{
- Q_D(QFxRect);
- if (d->tintColor == c)
- return;
-
- d->tintColor = c;
- update();
-}
-
-QColor QFxRectPrivate::getColor()
-{
- if (tintColor.isValid()) {
- int a = tintColor.alpha();
- if (a == 0xFF)
- return tintColor;
- else if (a == 0x00)
- return color;
- else {
- uint src = tintColor.rgba();
- uint dest = color.rgba();
-
- uint res = (((a * (src & 0xFF00FF)) +
- ((0xFF - a) * (dest & 0xFF00FF))) >> 8) & 0xFF00FF;
- res |= (((a * ((src >> 8) & 0xFF00FF)) +
- ((0xFF - a) * ((dest >> 8) & 0xFF00FF)))) & 0xFF00FF00;
- if ((src & 0xFF000000) == 0xFF000000)
- res |= 0xFF000000;
-
- return QColor::fromRgba(res);
- }
- } else {
- return color;
- }
-}
-
-
void QFxRect::generateRoundedRect()
{
Q_D(QFxRect);
@@ -443,7 +386,7 @@ void QFxRect::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *)
bool oldAA = p->testRenderHint(QPainter::Antialiasing);
if (d->smooth)
p->setRenderHints(QPainter::Antialiasing, true);
- p->fillRect(QRectF(0, 0, width(), height()), d->getColor());
+ p->fillRect(QRectF(0, 0, width(), height()), d->color);
if (d->smooth)
p->setRenderHint(QPainter::Antialiasing, oldAA);
}
@@ -527,7 +470,7 @@ void QFxRect::drawRect(QPainter &p)
// Middle
if (xMiddles && yMiddles)
// XXX paint errors in animation example
- //p.fillRect(xOffset-pw/2, yOffset-pw/2, width() - xSide + pw, height() - ySide + pw, d->getColor());
+ //p.fillRect(xOffset-pw/2, yOffset-pw/2, width() - xSide + pw, height() - ySide + pw, d->color);
p.drawPixmap(QRect(xOffset-pw/2, yOffset-pw/2, width() - xSide + pw, height() - ySide + pw), d->rectImage,
QRect(d->rectImage.width()/2, d->rectImage.height()/2, 1, 1));
// Middle right
diff --git a/src/declarative/fx/qfxrect.h b/src/declarative/fx/qfxrect.h
index 359e8fc..439cc65 100644
--- a/src/declarative/fx/qfxrect.h
+++ b/src/declarative/fx/qfxrect.h
@@ -136,7 +136,6 @@ class Q_DECLARATIVE_EXPORT QFxRect : public QFxItem
Q_OBJECT
Q_PROPERTY(QColor color READ color WRITE setColor)
- Q_PROPERTY(QColor tintColor READ tintColor WRITE setTintColor)
Q_PROPERTY(QFxGradient *gradient READ gradient WRITE setGradient)
Q_PROPERTY(QFxPen * border READ border)
Q_PROPERTY(qreal radius READ radius WRITE setRadius)
@@ -146,9 +145,6 @@ public:
QColor color() const;
void setColor(const QColor &);
- QColor tintColor() const;
- void setTintColor(const QColor &);
-
QFxPen *border();
QFxGradient *gradient() const;
diff --git a/src/declarative/fx/qfxrect_p.h b/src/declarative/fx/qfxrect_p.h
index 25fa38d..8eb074a 100644
--- a/src/declarative/fx/qfxrect_p.h
+++ b/src/declarative/fx/qfxrect_p.h
@@ -81,7 +81,6 @@ public:
QColor getColor();
QColor color;
QFxGradient *gradient;
- QColor tintColor;
QFxPen *getPen() {
if (!pen) {
Q_Q(QFxRect);
diff --git a/src/declarative/qml/qmldeclarativedata_p.h b/src/declarative/qml/qmldeclarativedata_p.h
index 5a51eb7..a316c0c 100644
--- a/src/declarative/qml/qmldeclarativedata_p.h
+++ b/src/declarative/qml/qmldeclarativedata_p.h
@@ -59,6 +59,7 @@ QT_BEGIN_NAMESPACE
class QmlCompiledData;
class QmlAbstractBinding;
+class QmlContext;
class QmlDeclarativeData : public QDeclarativeData
{
public:
@@ -69,6 +70,10 @@ public:
QmlContext *context;
QmlAbstractBinding *bindings;
+ QmlContext *outerContext; // Can't this be found from context?
+ ushort lineNumber;
+ ushort columnNumber;
+
QmlCompiledData *deferredComponent; // Can't this be found from the context?
unsigned int deferredIdx;
diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp
index 9a5efdb..e342d3f 100644
--- a/src/declarative/qml/qmlengine.cpp
+++ b/src/declarative/qml/qmlengine.cpp
@@ -80,6 +80,7 @@
#include <private/qmlbinding_p.h>
#include <private/qmlvme_p.h>
#include <private/qmlenginedebug_p.h>
+#include <private/qmlstringconverters_p.h>
#include <private/qmlxmlhttprequest_p.h>
Q_DECLARE_METATYPE(QmlMetaProperty)
@@ -121,12 +122,18 @@ QmlEnginePrivate::QmlEnginePrivate(QmlEngine *e)
qt_add_qmlxmlhttprequest(&scriptEngine);
+ //types
qtObject.setProperty(QLatin1String("rgba"), scriptEngine.newFunction(QmlEnginePrivate::rgba, 4));
qtObject.setProperty(QLatin1String("hsla"), scriptEngine.newFunction(QmlEnginePrivate::hsla, 4));
qtObject.setProperty(QLatin1String("rect"), scriptEngine.newFunction(QmlEnginePrivate::rect, 4));
qtObject.setProperty(QLatin1String("point"), scriptEngine.newFunction(QmlEnginePrivate::point, 2));
qtObject.setProperty(QLatin1String("size"), scriptEngine.newFunction(QmlEnginePrivate::size, 2));
qtObject.setProperty(QLatin1String("vector3d"), scriptEngine.newFunction(QmlEnginePrivate::vector, 3));
+
+ //color helpers
+ qtObject.setProperty(QLatin1String("lighter"), scriptEngine.newFunction(QmlEnginePrivate::lighter, 1));
+ qtObject.setProperty(QLatin1String("darker"), scriptEngine.newFunction(QmlEnginePrivate::darker, 1));
+ qtObject.setProperty(QLatin1String("tint"), scriptEngine.newFunction(QmlEnginePrivate::tint, 2));
}
QmlEnginePrivate::~QmlEnginePrivate()
@@ -802,6 +809,111 @@ QScriptValue QmlEnginePrivate::size(QScriptContext *ctxt, QScriptEngine *engine)
return qScriptValueFromValue(engine, qVariantFromValue(QSizeF(w, h)));
}
+QScriptValue QmlEnginePrivate::lighter(QScriptContext *ctxt, QScriptEngine *engine)
+{
+ if(ctxt->argumentCount() < 1)
+ return engine->nullValue();
+ QVariant v = ctxt->argument(0).toVariant();
+ QColor color;
+ if (v.type() == QVariant::Color)
+ color = v.value<QColor>();
+ else if (v.type() == QVariant::String) {
+ bool ok;
+ color = QmlStringConverters::colorFromString(v.toString(), &ok);
+ if (!ok)
+ return engine->nullValue();
+ } else
+ return engine->nullValue();
+ color = color.lighter();
+ return qScriptValueFromValue(engine, qVariantFromValue(color));
+}
+
+QScriptValue QmlEnginePrivate::darker(QScriptContext *ctxt, QScriptEngine *engine)
+{
+ if(ctxt->argumentCount() < 1)
+ return engine->nullValue();
+ QVariant v = ctxt->argument(0).toVariant();
+ QColor color;
+ if (v.type() == QVariant::Color)
+ color = v.value<QColor>();
+ else if (v.type() == QVariant::String) {
+ bool ok;
+ color = QmlStringConverters::colorFromString(v.toString(), &ok);
+ if (!ok)
+ return engine->nullValue();
+ } else
+ return engine->nullValue();
+ color = color.darker();
+ return qScriptValueFromValue(engine, qVariantFromValue(color));
+}
+
+/*!
+ This function allows tinting one color with another.
+
+ The tint color should usually be mostly transparent, or you will not be able to see the underlying color. The below example provides a slight red tint by having the tint color be pure red which is only 1/16th opaque.
+
+ \qml
+ Rectangle { x: 0; width: 80; height: 80; color: "lightsteelblue" }
+ Rectangle { x: 100; width: 80; height: 80; color: Qt.tint("lightsteelblue", "#10FF0000") }
+ \endqml
+ \image declarative-rect_tint.png
+
+ Tint is most useful when a subtle change is intended to be conveyed due to some event; you can then use tinting to more effectively tune the visible color.
+*/
+QScriptValue QmlEnginePrivate::tint(QScriptContext *ctxt, QScriptEngine *engine)
+{
+ if(ctxt->argumentCount() < 2)
+ return engine->nullValue();
+ //get color
+ QVariant v = ctxt->argument(0).toVariant();
+ QColor color;
+ if (v.type() == QVariant::Color)
+ color = v.value<QColor>();
+ else if (v.type() == QVariant::String) {
+ bool ok;
+ color = QmlStringConverters::colorFromString(v.toString(), &ok);
+ if (!ok)
+ return engine->nullValue();
+ } else
+ return engine->nullValue();
+
+ //get tint color
+ v = ctxt->argument(1).toVariant();
+ QColor tintColor;
+ if (v.type() == QVariant::Color)
+ tintColor = v.value<QColor>();
+ else if (v.type() == QVariant::String) {
+ bool ok;
+ tintColor = QmlStringConverters::colorFromString(v.toString(), &ok);
+ if (!ok)
+ return engine->nullValue();
+ } else
+ return engine->nullValue();
+
+ //tint
+ QColor finalColor;
+ int a = tintColor.alpha();
+ if (a == 0xFF)
+ finalColor = tintColor;
+ else if (a == 0x00)
+ finalColor = color;
+ else {
+ uint src = tintColor.rgba();
+ uint dest = color.rgba();
+
+ uint res = (((a * (src & 0xFF00FF)) +
+ ((0xFF - a) * (dest & 0xFF00FF))) >> 8) & 0xFF00FF;
+ res |= (((a * ((src >> 8) & 0xFF00FF)) +
+ ((0xFF - a) * ((dest >> 8) & 0xFF00FF)))) & 0xFF00FF00;
+ if ((src & 0xFF000000) == 0xFF000000)
+ res |= 0xFF000000;
+
+ finalColor = QColor::fromRgba(res);
+ }
+
+ return qScriptValueFromValue(engine, qVariantFromValue(finalColor));
+}
+
QmlScriptClass::QmlScriptClass(QmlEngine *bindengine)
: QScriptClass(QmlEnginePrivate::getScriptEngine(bindengine)),
engine(bindengine)
diff --git a/src/declarative/qml/qmlengine_p.h b/src/declarative/qml/qmlengine_p.h
index b595e7c..a33add3 100644
--- a/src/declarative/qml/qmlengine_p.h
+++ b/src/declarative/qml/qmlengine_p.h
@@ -219,6 +219,10 @@ public:
static QScriptValue size(QScriptContext*, QScriptEngine*);
static QScriptValue rect(QScriptContext*, QScriptEngine*);
+ static QScriptValue lighter(QScriptContext*, QScriptEngine*);
+ static QScriptValue darker(QScriptContext*, QScriptEngine*);
+ static QScriptValue tint(QScriptContext*, QScriptEngine*);
+
static QScriptEngine *getScriptEngine(QmlEngine *e) { return &e->d_func()->scriptEngine; }
static QmlEngine *getEngine(QScriptEngine *e) { return static_cast<QmlScriptEngine*>(e)->p->q_func(); }
static QmlEnginePrivate *get(QmlEngine *e) { return e->d_func(); }
diff --git a/src/declarative/qml/qmlenginedebug.cpp b/src/declarative/qml/qmlenginedebug.cpp
index 0e78cad..321fe74 100644
--- a/src/declarative/qml/qmlenginedebug.cpp
+++ b/src/declarative/qml/qmlenginedebug.cpp
@@ -181,9 +181,16 @@ void QmlEngineDebugServer::buildObjectList(QDataStream &message,
QmlEngineDebugServer::QmlObjectData
QmlEngineDebugServer::objectData(QObject *object)
{
+ QmlDeclarativeData *ddata = QmlDeclarativeData::get(object);
QmlObjectData rv;
- rv.lineNumber = -1;
- rv.columnNumber = -1;
+ if (ddata) {
+ rv.url = ddata->outerContext->baseUrl();
+ rv.lineNumber = ddata->lineNumber;
+ rv.columnNumber = ddata->columnNumber;
+ } else {
+ rv.lineNumber = -1;
+ rv.columnNumber = -1;
+ }
rv.objectName = object->objectName();
rv.objectType = object->metaObject()->className();
diff --git a/src/declarative/qml/qmlinfo.cpp b/src/declarative/qml/qmlinfo.cpp
index 65a4298..e47b4ab 100644
--- a/src/declarative/qml/qmlinfo.cpp
+++ b/src/declarative/qml/qmlinfo.cpp
@@ -40,6 +40,8 @@
****************************************************************************/
#include "qmlinfo.h"
+#include <private/qmldeclarativedata_p.h>
+#include <QtDeclarative/qmlcontext.h>
QT_BEGIN_NAMESPACE
@@ -80,7 +82,19 @@ QmlInfo::QmlInfo(QObject *object)
*this << "QML";
if (object)
*this << object->metaObject()->className();
- *this << "(unknown location):";
+ QmlDeclarativeData *ddata = QmlDeclarativeData::get(object);
+ if (ddata) {
+ QString location = QLatin1String("(");
+ location += ddata->outerContext->baseUrl().toString();
+ location += QLatin1String(":");
+ location += QString::number(ddata->lineNumber);
+ location += QLatin1String(":");
+ location += QString::number(ddata->columnNumber);
+ location += QLatin1String(")");
+ *this << location.toLatin1().constData();
+ } else {
+ *this << "(unknown location):";
+ }
}
/*!
diff --git a/src/declarative/qml/qmlinstruction_p.h b/src/declarative/qml/qmlinstruction_p.h
index 8861609a..ede06a2 100644
--- a/src/declarative/qml/qmlinstruction_p.h
+++ b/src/declarative/qml/qmlinstruction_p.h
@@ -170,6 +170,7 @@ public:
struct {
int type;
int data;
+ ushort column;
} create;
struct {
int data;
diff --git a/src/declarative/qml/qmlvme.cpp b/src/declarative/qml/qmlvme.cpp
index 930e6e4..7907195 100644
--- a/src/declarative/qml/qmlvme.cpp
+++ b/src/declarative/qml/qmlvme.cpp
@@ -174,6 +174,11 @@ QObject *QmlVME::run(QStack<QObject *> &stack, QmlContext *ctxt, QmlCompiledData
VME_EXCEPTION("Unable to create object of type" << types.at(instr.create.type).className);
}
+ QmlDeclarativeData *ddata = QmlDeclarativeData::get(o);
+ ddata->outerContext = ctxt;
+ ddata->lineNumber = instr.line;
+ ddata->columnNumber = instr.create.column;
+
if (instr.create.data != -1) {
QmlCustomParser *customParser =
types.at(instr.create.type).type->customParser();