Merge branch 'qtquick2' of scm.dev.nokia.troll.no:qt/qtdeclarative-staging into qtquick2

This commit is contained in:
Alan Alpert 2011-05-11 19:11:51 +10:00
commit ad5aeed367
26 changed files with 550 additions and 171 deletions

View File

@ -439,7 +439,20 @@
} }
\endqml \endqml
The \c variant type can also hold: A \c variant type property can also hold an image or pixmap.
A \c variant which contains a QPixmap or QImage is known as a
"scarce resource" and the declarative engine will attempt to
automatically release such resources after evaluation of any JavaScript
expression which requires one to be copied has completed.
Clients may explicitly release such a scarce resource by calling the
"destroy" method on the \c variant property from within JavaScript. They
may also explicitly preserve the scarce resource by calling the
"preserve" method on the \c variant property from within JavaScript.
For more information regarding the usage of a scarce resource, please
see \l{Scarce Resources in JavaScript}.
Finally, the \c variant type can also hold:
\list \list
\o An array of \l {QML Basic Types}{basic type} values \o An array of \l {QML Basic Types}{basic type} values

View File

@ -168,6 +168,44 @@ Notice that calling \l {QML:Qt::include()}{Qt.include()} imports all functions f
\c factorial.js into the \c MyScript namespace, which means the QML component can also \c factorial.js into the \c MyScript namespace, which means the QML component can also
access \c factorial() directly as \c MyScript.factorial(). access \c factorial() directly as \c MyScript.factorial().
In QtQuick 2.0, support has been added to allow JavaScript files to import other
JavaScript files and also QML modules using a variation of the standard QML import
syntax (where all of the previously described rules and qualifications apply).
A JavaScript file may import another in the following fashion:
\code
.import "filename.js" as UniqueQualifier
\endcode
For example:
\code
.import "factorial.js" as MathFunctions
\endcode
A JavaScript file may import a QML module in the following fashion:
\code
.import Module.Name MajorVersion.MinorVersion as UniqueQualifier
\endcode
For example:
\code
.import Qt.test 1.0 as JsQtTest
\endcode
In particular, this may be useful in order to access functionality provided
via a module API; see qmlRegisterModuleApi() for more information.
Due to the ability of a JavaScript file to import another script or QML module in
this fashion in QtQuick 2.0, some extra semantics are defined:
\list
\o a script with imports will not inherit imports from the QML file which imported it (so accessing Component.error will fail, for example)
\o a script without imports will inherit imports from the QML file which imported it (so accessing Component.error will succeed, for example)
\o a shared script (i.e., defined as .pragma library) does not inherit imports from any QML file even if it imports no other scripts
\endlist
The first semantic is conceptually correct, given that a particular script
might be imported by any number of QML files. The second semantic is retained
for the purposes of backwards-compatibility. The third semantic remains
unchanged from the current semantics for shared scripts, but is clarified here
in respect to the newly possible case (where the script imports other scripts
or modules).
\section1 Running JavaScript at Startup \section1 Running JavaScript at Startup
@ -321,4 +359,195 @@ Item {
\endlist \endlist
\section1 Scarce Resources in JavaScript
As described in the documentation for \l{QML Basic Types}, a \c variant type
property may hold a "scarce resource" (image or pixmap). There are several
important semantics of scarce resources which should be noted:
\list
\o By default, a scarce resource is automatically released by the declarative engine as soon as evaluation of the expression in which the scarce resource is allocated is complete if there are no other references to the resource
\o A client may explicitly preserve a scarce resource, which will ensure that the resource will not be released until all references to the resource are released and the JavaScript engine runs its garbage collector
\o A client may explicitly destroy a scarce resource, which will immediately release the resource
\endlist
In most cases, allowing the engine to automatically release the resource is
the correct choice. In some cases, however, this may result in an invalid
variant being returned from a function in JavaScript, and in those cases it
may be necessary for clients to manually preserve or destroy resources for
themselves.
For the following examples, imagine that we have defined the following class:
\code
class AvatarExample : public QObject
{
Q_OBJECT
Q_PROPERTY(QPixmap avatar READ avatar WRITE setAvatar NOTIFY avatarChanged)
public:
AvatarExample(QObject *parent = 0) : QObject(parent), m_value(100, 100) { m_value.fill(Qt::blue); }
~AvatarExample() {}
QPixmap avatar() const { return m_value; }
void setAvatar(QPixmap v) { m_value = v; emit avatarChanged(); }
signals:
void avatarChanged();
private:
QPixmap m_value;
};
\endcode
and that we have registered it with the QML type-system as follows:
\code
qmlRegisterType<AvatarExample>("Qt.example", 1, 0, "AvatarExample");
\endcode
The AvatarExample class has a property which is a pixmap. When the property
is accessed in JavaScript scope, a copy of the resource will be created and
stored in a JavaScript object which can then be used within JavaScript. This
copy will take up valuable system resources, and so by default the scarce
resource copy in the JavaScript object will be released automatically by the
declarative engine once evaluation of the JavaScript expression is complete,
unless the client explicitly preserves it.
\section2 Example One: Automatic Release
In this example, the resource will be automatically
released after the binding expression evaluation is
complete.
\qml
// exampleOne.qml
import QtQuick 1.0
import Qt.example 1.0
QtObject {
property AvatarExample a;
a: AvatarExample { id: example }
property variant avatar: example.avatar
}
\endqml
\code
QDeclarativeComponent component(&engine, "exampleOne.qml");
QObject *object = component.create();
// The scarce resource will have been released automatically
// after the binding expression was evaluated.
// Since the scarce resource was not released explicitly prior
// to the binding expression being evaluated, we get the
// expected result:
//object->property("scarceResourceCopy").isValid() == true
delete object;
\endcode
\section2 Example Two: Explicit Preservation
In this example, the resource must be explicitly preserved in order
to prevent the declarative engine from automatically releasing the
resource after evaluation of the imported script.
\code
// exampleTwo.js
.import Qt.example 1.0 as QtExample
var component = Qt.createComponent("exampleOne.qml");
var exampleOneElement = component.createObject(null);
var avatarExample = exampleOneElement.a;
var retn = avatarExample.avatar;
// without the following call, the scarce resource held
// by retn would be automatically released by the engine
// after the import statement in exampleTwo.qml, prior
// to the variable assignment.
retn.preserve();
function importAvatar() {
return retn;
}
\endcode
\qml
// exampleTwo.qml
import QtQuick 1.0
import Qt.example 1.0
import "exampleTwo.js" as ExampleTwoJs
QtObject {
property variant avatar: ExampleTwoJs.importAvatar()
}
\endqml
\code
QDeclarativeComponent component(&engine, "exampleTwo.qml");
QObject *object = component.create();
// The resource was preserved explicitly during evaluation of the
// JavaScript expression. Thus, during property assignment, the
// scarce resource was still valid, and so we get the expected result:
//object->property("avatar").isValid() == true
// The scarce resource may not have been cleaned up by the JS GC yet;
// it will continue to consume system resources until the JS GC runs.
delete object;
\endcode
\section2 Example Three: Explicit Destruction
In the following example, we release (via destroy()) an explicitly preserved
scarce resource variant. This example shows how a client may free system
resources by releasing the scarce resource held in a JavaScript object, if
required, during evaluation of a JavaScript expression.
\code
// exampleThree.js
.import Qt.example 1.0 as QtExample
var component = Qt.createComponent("exampleOne.qml");
var exampleOneElement = component.createObject(null);
var avatarExample = exampleOneElement.a;
var retn = avatarExample.avatar;
retn.preserve();
function importAvatar() {
return retn;
}
function releaseAvatar() {
retn.destroy();
}
\endcode
\qml
// exampleThree.qml
import QtQuick 1.0
import Qt.example 1.0
import "exampleThree.js" as ExampleThreeJs
QtObject {
property variant avatarOne
property variant avatarTwo
Component.onCompleted: {
avatarOne = ExampleThreeJs.importAvatar(); // valid at this stage
ExampleThreeJs.releaseAvatar(); // explicit release
avatarTwo = ExampleThreeJs.importAvatar(); // invalid at this stage
}
}
\endqml
\code
QDeclarativeComponent component(&engine, "exampleThree.qml");
QObject *object = component.create();
// The scarce resource was explicitly preserved by the client during
// the evaluation of the imported script, and so the scarce resource
// remains valid until the explicit call to releaseAvatar(). As such,
// we get the expected results:
//object->property("avatarOne").isValid() == true
//object->property("avatarTwo").isValid() == false
// Because the scarce resource was released explicitly, it will no longer
// be consuming any system resources (beyond what a normal JS Object would;
// that small overhead will exist until the JS GC runs, as per any other
// JavaScript object).
delete object;
\endcode
*/ */

View File

@ -103,6 +103,8 @@ QSGPaintedItemPrivate::QSGPaintedItemPrivate()
, geometryDirty(false) , geometryDirty(false)
, contentsDirty(false) , contentsDirty(false)
, opaquePainting(false) , opaquePainting(false)
, antialiasing(false)
, mipmap(false)
{ {
} }
@ -225,6 +227,40 @@ void QSGPaintedItem::setAntialiasing(bool enable)
update(); update();
} }
/*!
Returns true if mipmaps are enabled; otherwise, false is returned.
By default, mipmapping is not enabled.
\sa setMipmap()
*/
bool QSGPaintedItem::mipmap() const
{
Q_D(const QSGPaintedItem);
return d->mipmap;
}
/*!
If \a enable is true, mipmapping is enabled on the associated texture.
Mipmapping increases rendering speed and reduces aliasing artifacts when the item is
scaled down.
By default, mipmapping is not enabled.
\sa mipmap()
*/
void QSGPaintedItem::setMipmap(bool enable)
{
Q_D(QSGPaintedItem);
if (d->mipmap == enable)
return;
d->mipmap = enable;
update();
}
/*! /*!
This function returns the outer bounds of the item as a rectangle; all painting must be This function returns the outer bounds of the item as a rectangle; all painting must be
restricted to inside an item's bounding rect. restricted to inside an item's bounding rect.
@ -379,6 +415,11 @@ void QSGPaintedItem::setRenderTarget(RenderTarget target)
Reimplement this function in a QSGPaintedItem subclass to provide the Reimplement this function in a QSGPaintedItem subclass to provide the
item's painting implementation, using \a painter. item's painting implementation, using \a painter.
\note The QML Scene Graph uses two separate threads, the main thread does things such as
processing events or updating animations while a second thread does the actual OpenGL rendering.
As a consequence, paint() is not called from the main GUI thread but from the GL enabled
renderer thread.
*/ */
/*! /*!
@ -416,7 +457,7 @@ QSGNode *QSGPaintedItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *
node->setSize(QSize(qRound(br.width()), qRound(br.height()))); node->setSize(QSize(qRound(br.width()), qRound(br.height())));
node->setSmoothPainting(d->antialiasing); node->setSmoothPainting(d->antialiasing);
node->setLinearFiltering(d->smooth); node->setLinearFiltering(d->smooth);
node->setMipmapping(d->smooth); node->setMipmapping(d->mipmap);
node->setOpaquePainting(d->opaquePainting); node->setOpaquePainting(d->opaquePainting);
node->setFillColor(d->fillColor); node->setFillColor(d->fillColor);
node->setContentsScale(d->contentsScale); node->setContentsScale(d->contentsScale);

View File

@ -75,6 +75,9 @@ public:
bool antialiasing() const; bool antialiasing() const;
void setAntialiasing(bool enable); void setAntialiasing(bool enable);
bool mipmap() const;
void setMipmap(bool enable);
QRectF contentsBoundingRect() const; QRectF contentsBoundingRect() const;
QSize contentsSize() const; QSize contentsSize() const;

View File

@ -63,6 +63,7 @@ public:
bool contentsDirty : 1; bool contentsDirty : 1;
bool opaquePainting: 1; bool opaquePainting: 1;
bool antialiasing: 1; bool antialiasing: 1;
bool mipmap: 1;
}; };
QT_END_NAMESPACE QT_END_NAMESPACE

View File

@ -82,6 +82,7 @@ QSGShaderEffectTexture::QSGShaderEffectTexture(QSGItem *shaderSource)
, m_dirtyTexture(true) , m_dirtyTexture(true)
, m_multisamplingSupportChecked(false) , m_multisamplingSupportChecked(false)
, m_multisampling(false) , m_multisampling(false)
, m_grab(false)
{ {
} }
@ -124,8 +125,9 @@ void QSGShaderEffectTexture::bind()
bool QSGShaderEffectTexture::updateTexture() bool QSGShaderEffectTexture::updateTexture()
{ {
if (m_dirtyTexture) { if ((m_live || m_grab) && m_dirtyTexture) {
grab(); grab();
m_grab = false;
return true; return true;
} }
return false; return false;
@ -181,6 +183,15 @@ void QSGShaderEffectTexture::setLive(bool live)
markDirtyTexture(); markDirtyTexture();
} }
void QSGShaderEffectTexture::scheduleUpdate()
{
if (m_grab)
return;
m_grab = true;
if (m_dirtyTexture)
emit textureChanged();
}
void QSGShaderEffectTexture::setRecursive(bool recursive) void QSGShaderEffectTexture::setRecursive(bool recursive)
{ {
m_recursive = recursive; m_recursive = recursive;
@ -188,10 +199,9 @@ void QSGShaderEffectTexture::setRecursive(bool recursive)
void QSGShaderEffectTexture::markDirtyTexture() void QSGShaderEffectTexture::markDirtyTexture()
{ {
if (m_live) { m_dirtyTexture = true;
m_dirtyTexture = true; if (m_live || m_grab)
emit textureChanged(); emit textureChanged();
}
} }
void QSGShaderEffectTexture::grab() void QSGShaderEffectTexture::grab()
@ -360,6 +370,7 @@ QSGShaderEffectSource::QSGShaderEffectSource(QSGItem *parent)
, m_hideSource(false) , m_hideSource(false)
, m_mipmap(false) , m_mipmap(false)
, m_recursive(false) , m_recursive(false)
, m_grab(true)
{ {
setFlag(ItemHasContents); setFlag(ItemHasContents);
m_texture = new QSGShaderEffectTexture(this); m_texture = new QSGShaderEffectTexture(this);
@ -516,17 +527,12 @@ void QSGShaderEffectSource::setRecursive(bool enabled)
emit recursiveChanged(); emit recursiveChanged();
} }
void QSGShaderEffectSource::grab() void QSGShaderEffectSource::scheduleUpdate()
{ {
if (!m_sourceItem) if (m_grab)
return; return;
QSGCanvas *canvas = m_sourceItem->canvas(); m_grab = true;
if (!canvas) update();
return;
QSGCanvasPrivate::get(canvas)->updateDirtyNodes();
QGLContext *glctx = const_cast<QGLContext *>(canvas->context());
glctx->makeCurrent();
qobject_cast<QSGShaderEffectTexture *>(m_texture)->grab();
} }
static void get_wrap_mode(QSGShaderEffectSource::WrapMode mode, QSGTexture::WrapMode *hWrap, QSGTexture::WrapMode *vWrap) static void get_wrap_mode(QSGShaderEffectSource::WrapMode mode, QSGTexture::WrapMode *hWrap, QSGTexture::WrapMode *vWrap)
@ -582,6 +588,7 @@ QSGNode *QSGShaderEffectSource::updatePaintNode(QSGNode *oldNode, UpdatePaintNod
QSGShaderEffectTexture *tex = qobject_cast<QSGShaderEffectTexture *>(m_texture); QSGShaderEffectTexture *tex = qobject_cast<QSGShaderEffectTexture *>(m_texture);
tex->setLive(m_live);
tex->setItem(QSGItemPrivate::get(m_sourceItem)->itemNode()); tex->setItem(QSGItemPrivate::get(m_sourceItem)->itemNode());
QRectF sourceRect = m_sourceRect.isNull() QRectF sourceRect = m_sourceRect.isNull()
? QRectF(0, 0, m_sourceItem->width(), m_sourceItem->height()) ? QRectF(0, 0, m_sourceItem->width(), m_sourceItem->height())
@ -591,11 +598,14 @@ QSGNode *QSGShaderEffectSource::updatePaintNode(QSGNode *oldNode, UpdatePaintNod
? QSize(qCeil(qAbs(sourceRect.width())), qCeil(qAbs(sourceRect.height()))) ? QSize(qCeil(qAbs(sourceRect.width())), qCeil(qAbs(sourceRect.height())))
: m_textureSize; : m_textureSize;
tex->setSize(textureSize); tex->setSize(textureSize);
tex->setLive(m_live);
tex->setRecursive(m_recursive); tex->setRecursive(m_recursive);
tex->setFormat(GLenum(m_format)); tex->setFormat(GLenum(m_format));
tex->setHasMipmaps(m_mipmap); tex->setHasMipmaps(m_mipmap);
if (m_grab)
tex->scheduleUpdate();
m_grab = false;
QSGTexture::Filtering filtering = QSGItemPrivate::get(this)->smooth QSGTexture::Filtering filtering = QSGItemPrivate::get(this)->smooth
? QSGTexture::Linear ? QSGTexture::Linear
: QSGTexture::Nearest; : QSGTexture::Nearest;

View File

@ -112,7 +112,7 @@ public:
bool recursive() const { return bool(m_recursive); } bool recursive() const { return bool(m_recursive); }
void setRecursive(bool recursive); void setRecursive(bool recursive);
void grab(); void scheduleUpdate();
Q_SIGNALS: Q_SIGNALS:
void textureChanged(); void textureChanged();
@ -121,6 +121,8 @@ public Q_SLOTS:
void markDirtyTexture(); void markDirtyTexture();
private: private:
void grab();
QSGNode *m_item; QSGNode *m_item;
QRectF m_rect; QRectF m_rect;
QSize m_size; QSize m_size;
@ -141,6 +143,7 @@ private:
uint m_dirtyTexture : 1; uint m_dirtyTexture : 1;
uint m_multisamplingSupportChecked : 1; uint m_multisamplingSupportChecked : 1;
uint m_multisampling : 1; uint m_multisampling : 1;
uint m_grab : 1;
}; };
class QSGShaderEffectSource : public QSGItem, public QSGTextureProvider class QSGShaderEffectSource : public QSGItem, public QSGTextureProvider
@ -204,7 +207,7 @@ public:
QSGTexture *texture() const; QSGTexture *texture() const;
const char *textureChangedSignal() const { return SIGNAL(textureChanged()); } const char *textureChangedSignal() const { return SIGNAL(textureChanged()); }
Q_INVOKABLE void grab(); Q_INVOKABLE void scheduleUpdate();
Q_SIGNALS: Q_SIGNALS:
void wrapModeChanged(); void wrapModeChanged();
@ -233,6 +236,7 @@ private:
uint m_hideSource : 1; uint m_hideSource : 1;
uint m_mipmap : 1; uint m_mipmap : 1;
uint m_recursive : 1; uint m_recursive : 1;
uint m_grab : 1;
}; };
QT_END_NAMESPACE QT_END_NAMESPACE

View File

@ -153,7 +153,7 @@ void QSGTextNode::addTextDecorations(const QPointF &position, const QRawFont &fo
} }
} }
QSGGlyphNode *QSGTextNode::addGlyphs(const QPointF &position, const QGlyphs &glyphs, const QColor &color, QSGGlyphNode *QSGTextNode::addGlyphs(const QPointF &position, const QGlyphRun &glyphs, const QColor &color,
QSGText::TextStyle style, const QColor &styleColor) QSGText::TextStyle style, const QColor &styleColor)
{ {
QSGGlyphNode *node = m_context->createGlyphNode(); QSGGlyphNode *node = m_context->createGlyphNode();
@ -187,10 +187,10 @@ void QSGTextNode::addTextDocument(const QPointF &position, QTextDocument *textDo
void QSGTextNode::addTextLayout(const QPointF &position, QTextLayout *textLayout, const QColor &color, void QSGTextNode::addTextLayout(const QPointF &position, QTextLayout *textLayout, const QColor &color,
QSGText::TextStyle style, const QColor &styleColor) QSGText::TextStyle style, const QColor &styleColor)
{ {
QList<QGlyphs> glyphsList(textLayout->glyphs()); QList<QGlyphRun> glyphsList(textLayout->glyphRuns());
for (int i=0; i<glyphsList.size(); ++i) { for (int i=0; i<glyphsList.size(); ++i) {
QGlyphs glyphs = glyphsList.at(i); QGlyphRun glyphs = glyphsList.at(i);
QRawFont font = glyphs.font(); QRawFont font = glyphs.rawFont();
addGlyphs(position + QPointF(0, font.ascent()), glyphs, color, style, styleColor); addGlyphs(position + QPointF(0, font.ascent()), glyphs, color, style, styleColor);
} }
@ -356,10 +356,10 @@ void QSGTextNode::addTextBlock(const QPointF &position, QTextDocument *textDocum
? overrideColor ? overrideColor
: charFormat.foreground().color(); : charFormat.foreground().color();
QList<QGlyphs> glyphsList = fragment.glyphs(); QList<QGlyphRun> glyphsList = fragment.glyphRuns();
for (int i=0; i<glyphsList.size(); ++i) { for (int i=0; i<glyphsList.size(); ++i) {
QGlyphs glyphs = glyphsList.at(i); QGlyphRun glyphs = glyphsList.at(i);
QRawFont font = glyphs.font(); QRawFont font = glyphs.rawFont();
QSGGlyphNode *glyphNode = addGlyphs(position + blockPosition + QPointF(0, font.ascent()), QSGGlyphNode *glyphNode = addGlyphs(position + blockPosition + QPointF(0, font.ascent()),
glyphs, color, style, styleColor); glyphs, color, style, styleColor);

View File

@ -72,7 +72,7 @@ public:
private: private:
void addTextBlock(const QPointF &position, QTextDocument *textDocument, const QTextBlock &block, void addTextBlock(const QPointF &position, QTextDocument *textDocument, const QTextBlock &block,
const QColor &overrideColor, QSGText::TextStyle style = QSGText::Normal, const QColor &styleColor = QColor()); const QColor &overrideColor, QSGText::TextStyle style = QSGText::Normal, const QColor &styleColor = QColor());
QSGGlyphNode *addGlyphs(const QPointF &position, const QGlyphs &glyphs, const QColor &color, QSGGlyphNode *addGlyphs(const QPointF &position, const QGlyphRun &glyphs, const QColor &color,
QSGText::TextStyle style = QSGText::Normal, const QColor &styleColor = QColor()); QSGText::TextStyle style = QSGText::Normal, const QColor &styleColor = QColor());
void addTextDecorations(const QPointF &position, const QRawFont &font, const QColor &color, void addTextDecorations(const QPointF &position, const QRawFont &font, const QColor &color,
qreal width, bool hasOverline, bool hasStrikeOut, bool hasUnderline); qreal width, bool hasOverline, bool hasStrikeOut, bool hasUnderline);

View File

@ -144,9 +144,22 @@ QDeclarativeScarceResourceScriptClass::property(Object *object, const Identifier
} }
/* /*
The user explicitly wants to preserve the resource. This method is called when the user explicitly calls the "preserve" method of a scarce resource in JavaScript
We remove the scarce resource from the engine's linked list within the specified evaluation context \a context of the script engine \a engine.
of resources to release after evaluation completes. Calling this function signifies that the user explicitly wants to preserve the resource rather than let it
be automatically released once evaluation of the expression is complete.
This function removes the internal scarce resource from the declarative engine's linked list of scarce resources
to release after evaluation of the expression completes. This means that the resource will only be truly
released when the JavaScript engine's garbage collector is run.
Example:
\qml
function getIcon(model) {
var icon = model.avatar; // a pixmap property
icon.preserve(); // explicitly preserves the resource
return icon; // a valid variant will be returned
}
\endqml
*/ */
QScriptValue QDeclarativeScarceResourceScriptClass::preserve(QScriptContext *context, QScriptEngine *engine) QScriptValue QDeclarativeScarceResourceScriptClass::preserve(QScriptContext *context, QScriptEngine *engine)
{ {
@ -168,8 +181,21 @@ QScriptValue QDeclarativeScarceResourceScriptClass::preserve(QScriptContext *con
} }
/* /*
The user explicitly wants to release the resource. This method is called when the user explicitly calls the "destroy" method of a scarce resource in JavaScript
We set the internal scarce resource variant to the invalid variant. within the specified evaluation context \a context of the script engine \a engine.
Calling this function signifies that the user explicitly wants to release the resource.
This function sets the internal scarce resource variant to the invalid variant, in order to release the original resource,
and then removes the resource from the declarative engine's linked-list of scarce resources to
to release after evaluation of the expression completes, as it has already been released.
Example:
\qml
function getIcon(model) {
var icon = model.avatar; // a pixmap property
icon.destroy(); // explicitly releases the resource
return icon; // an invalid variant will be returned
}
\endqml
*/ */
QScriptValue QDeclarativeScarceResourceScriptClass::destroy(QScriptContext *context, QScriptEngine *engine) QScriptValue QDeclarativeScarceResourceScriptClass::destroy(QScriptContext *context, QScriptEngine *engine)
{ {

View File

@ -49,7 +49,7 @@
#include <QtCore/qrect.h> #include <QtCore/qrect.h>
#include <QtGui/qcolor.h> #include <QtGui/qcolor.h>
#include <QtCore/qsharedpointer.h> #include <QtCore/qsharedpointer.h>
#include <QtGui/qglyphs.h> #include <QtGui/qglyphrun.h>
#include <QtCore/qurl.h> #include <QtCore/qurl.h>
QT_BEGIN_HEADER QT_BEGIN_HEADER
@ -103,7 +103,7 @@ public:
SubPixelAntialiasing SubPixelAntialiasing
}; };
virtual void setGlyphs(const QPointF &position, const QGlyphs &glyphs) = 0; virtual void setGlyphs(const QPointF &position, const QGlyphRun &glyphs) = 0;
virtual void setColor(const QColor &color) = 0; virtual void setColor(const QColor &color) = 0;
virtual QPointF baseLine() const = 0; virtual QPointF baseLine() const = 0;

View File

@ -69,12 +69,12 @@ void QSGDefaultGlyphNode::setColor(const QColor &color)
} }
} }
void QSGDefaultGlyphNode::setGlyphs(const QPointF &position, const QGlyphs &glyphs) void QSGDefaultGlyphNode::setGlyphs(const QPointF &position, const QGlyphRun &glyphs)
{ {
if (m_material != 0) if (m_material != 0)
delete m_material; delete m_material;
QRawFont font = glyphs.font(); QRawFont font = glyphs.rawFont();
m_material = new QSGTextMaskMaterial(font); m_material = new QSGTextMaskMaterial(font);
m_material->setColor(m_color); m_material->setColor(m_color);

View File

@ -60,13 +60,13 @@ public:
~QSGDefaultGlyphNode(); ~QSGDefaultGlyphNode();
virtual QPointF baseLine() const { return m_baseLine; } virtual QPointF baseLine() const { return m_baseLine; }
virtual void setGlyphs(const QPointF &position, const QGlyphs &glyphs); virtual void setGlyphs(const QPointF &position, const QGlyphRun &glyphs);
virtual void setColor(const QColor &color); virtual void setColor(const QColor &color);
virtual void setPreferredAntialiasingMode(AntialiasingMode) { } virtual void setPreferredAntialiasingMode(AntialiasingMode) { }
private: private:
QGlyphs m_glyphs; QGlyphRun m_glyphs;
QPointF m_position; QPointF m_position;
QColor m_color; QColor m_color;

View File

@ -49,7 +49,7 @@
#include <private/qsgcontext_p.h> #include <private/qsgcontext_p.h>
#include <private/qrawfont_p.h> #include <private/qrawfont_p.h>
#include <qglfunctions.h> #include <qglfunctions.h>
#include <qglyphs.h> #include <qglyphrun.h>
#include <qrawfont.h> #include <qrawfont.h>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE

View File

@ -87,9 +87,9 @@ void QSGDistanceFieldGlyphNode::setPreferredAntialiasingMode(AntialiasingMode mo
updateMaterial(); updateMaterial();
} }
void QSGDistanceFieldGlyphNode::setGlyphs(const QPointF &position, const QGlyphs &glyphs) void QSGDistanceFieldGlyphNode::setGlyphs(const QPointF &position, const QGlyphRun &glyphs)
{ {
QRawFont font = glyphs.font(); QRawFont font = glyphs.rawFont();
m_position = QPointF(position.x(), position.y() - font.ascent()); m_position = QPointF(position.x(), position.y() - font.ascent());
m_glyphs = glyphs; m_glyphs = glyphs;
@ -187,7 +187,7 @@ void QSGDistanceFieldGlyphNode::updateGeometry()
void QSGDistanceFieldGlyphNode::updateFont() void QSGDistanceFieldGlyphNode::updateFont()
{ {
m_glyph_cache = QSGDistanceFieldGlyphCache::get(QGLContext::currentContext(), m_glyphs.font()); m_glyph_cache = QSGDistanceFieldGlyphCache::get(QGLContext::currentContext(), m_glyphs.rawFont());
} }
void QSGDistanceFieldGlyphNode::updateMaterial() void QSGDistanceFieldGlyphNode::updateMaterial()

View File

@ -61,7 +61,7 @@ public:
~QSGDistanceFieldGlyphNode(); ~QSGDistanceFieldGlyphNode();
virtual QPointF baseLine() const { return m_baseLine; } virtual QPointF baseLine() const { return m_baseLine; }
virtual void setGlyphs(const QPointF &position, const QGlyphs &glyphs); virtual void setGlyphs(const QPointF &position, const QGlyphRun &glyphs);
virtual void setColor(const QColor &color); virtual void setColor(const QColor &color);
virtual void setPreferredAntialiasingMode(AntialiasingMode mode); virtual void setPreferredAntialiasingMode(AntialiasingMode mode);
@ -78,7 +78,7 @@ private:
QPointF m_baseLine; QPointF m_baseLine;
QSGDistanceFieldTextMaterial *m_material; QSGDistanceFieldTextMaterial *m_material;
QPointF m_position; QPointF m_position;
QGlyphs m_glyphs; QGlyphRun m_glyphs;
QSGDistanceFieldGlyphCache *m_glyph_cache; QSGDistanceFieldGlyphCache *m_glyph_cache;
QSGGeometry m_geometry; QSGGeometry m_geometry;
QSGText::TextStyle m_style; QSGText::TextStyle m_style;

View File

@ -0,0 +1,9 @@
import Test 1.0
MyQmlObject {
id: myObject
property int myValue: 1
object: myObject
result: ###
}

View File

@ -2,6 +2,7 @@ import Test 1.0
MyQmlObject { MyQmlObject {
id: myObject id: myObject
object: myObject
result: ### result: ###
} }

View File

@ -41,6 +41,7 @@
#include <qtest.h> #include <qtest.h>
#include <QDeclarativeEngine> #include <QDeclarativeEngine>
#include <QDeclarativeContext>
#include <QDeclarativeComponent> #include <QDeclarativeComponent>
#include <QFile> #include <QFile>
#include <QDebug> #include <QDebug>
@ -70,9 +71,12 @@ private slots:
void objectproperty(); void objectproperty();
void basicproperty_data(); void basicproperty_data();
void basicproperty(); void basicproperty();
void creation_data();
void creation();
private: private:
QDeclarativeEngine engine; QDeclarativeEngine engine;
MyQmlObject tstObject;
}; };
tst_binding::tst_binding() tst_binding::tst_binding()
@ -86,6 +90,7 @@ tst_binding::~tst_binding()
void tst_binding::initTestCase() void tst_binding::initTestCase()
{ {
registerTypes(); registerTypes();
engine.rootContext()->setContextProperty("tstObject", &tstObject);
} }
void tst_binding::cleanupTestCase() void tst_binding::cleanupTestCase()
@ -162,5 +167,28 @@ void tst_binding::basicproperty()
} }
} }
void tst_binding::creation_data()
{
QTest::addColumn<QString>("file");
QTest::addColumn<QString>("binding");
QTest::newRow("constant") << SRCDIR "/data/creation.txt" << "10";
QTest::newRow("ownProperty") << SRCDIR "/data/creation.txt" << "myObject.value";
QTest::newRow("declaredProperty") << SRCDIR "/data/creation.txt" << "myObject.myValue";
QTest::newRow("contextProperty") << SRCDIR "/data/creation.txt" << "tstObject.value";
}
void tst_binding::creation()
{
QFETCH(QString, file);
QFETCH(QString, binding);
COMPONENT(file, binding);
QBENCHMARK {
c.create();
}
}
QTEST_MAIN(tst_binding) QTEST_MAIN(tst_binding)
#include "tst_binding.moc" #include "tst_binding.moc"

View File

@ -139,10 +139,10 @@ QAction *LoggerWidget::showAction()
void LoggerWidget::readSettings() void LoggerWidget::readSettings()
{ {
QSettings settings; QSettings settings;
QString warningsPreferences = settings.value("warnings", "hide").toString(); QString warningsPreferences = settings.value(QLatin1String("warnings"), QLatin1String("hide")).toString();
if (warningsPreferences == "show") { if (warningsPreferences == QLatin1String("show")) {
m_visibility = ShowWarnings; m_visibility = ShowWarnings;
} else if (warningsPreferences == "hide") { } else if (warningsPreferences == QLatin1String("hide")) {
m_visibility = HideWarnings; m_visibility = HideWarnings;
} else { } else {
m_visibility = AutoShowWarnings; m_visibility = AutoShowWarnings;
@ -154,15 +154,15 @@ void LoggerWidget::saveSettings()
if (m_visibilityOrigin != SettingsOrigin) if (m_visibilityOrigin != SettingsOrigin)
return; return;
QString value = "autoShow"; QString value = QLatin1String("autoShow");
if (defaultVisibility() == ShowWarnings) { if (defaultVisibility() == ShowWarnings) {
value = "show"; value = QLatin1String("show");
} else if (defaultVisibility() == HideWarnings) { } else if (defaultVisibility() == HideWarnings) {
value = "hide"; value = QLatin1String("hide");
} }
QSettings settings; QSettings settings;
settings.setValue("warnings", value); settings.setValue(QLatin1String("warnings"), value);
} }
void LoggerWidget::warningsPreferenceChanged(QAction *action) void LoggerWidget::warningsPreferenceChanged(QAction *action)

View File

@ -50,6 +50,7 @@
#include <QDebug> #include <QDebug>
#include <QMessageBox> #include <QMessageBox>
#include <QAtomicInt> #include <QAtomicInt>
#include <QLibraryInfo>
#include "qdeclarativetester.h" #include "qdeclarativetester.h"
#include <private/qdeclarativedebughelper_p.h> #include <private/qdeclarativedebughelper_p.h>
@ -67,7 +68,7 @@ void exitApp(int i)
// Debugging output is not visible by default on Windows - // Debugging output is not visible by default on Windows -
// therefore show modal dialog with errors instead. // therefore show modal dialog with errors instead.
if (!warnings.isEmpty()) { if (!warnings.isEmpty()) {
QMessageBox::warning(0, QApplication::tr("Qt QML Viewer"), warnings); QMessageBox::warning(0, QApplication::translate("QDeclarativeViewer", "Qt QML Viewer"), warnings);
} }
#endif #endif
exit(i); exit(i);
@ -123,7 +124,7 @@ void myMessageOutput(QtMsgType type, const char *msg)
static QDeclarativeViewer* globalViewer = 0; static QDeclarativeViewer* globalViewer = 0;
// The qml file that is shown if the user didn't specify a QML file // The qml file that is shown if the user didn't specify a QML file
QString initialFile = "qrc:/startup/startup.qml"; QString initialFile = QLatin1String("qrc:/startup/startup.qml");
void usage() void usage()
{ {
@ -199,7 +200,7 @@ struct ViewerOptions
fps(0.0), fps(0.0),
autorecord_from(0), autorecord_from(0),
autorecord_to(0), autorecord_to(0),
dither("none"), dither(QLatin1String("none")),
runScript(false), runScript(false),
devkeys(false), devkeys(false),
cache(0), cache(0),
@ -336,54 +337,54 @@ static void parseCommandLineOptions(const QStringList &arguments)
for (int i = 1; i < arguments.count(); ++i) { for (int i = 1; i < arguments.count(); ++i) {
bool lastArg = (i == arguments.count() - 1); bool lastArg = (i == arguments.count() - 1);
QString arg = arguments.at(i); QString arg = arguments.at(i);
if (arg == "-frameless") { if (arg == QLatin1String("-frameless")) {
opts.frameless = true; opts.frameless = true;
} else if (arg == "-maximized") { } else if (arg == QLatin1String("-maximized")) {
opts.maximized = true; opts.maximized = true;
} else if (arg == "-fullscreen") { } else if (arg == QLatin1String("-fullscreen")) {
opts.fullScreen = true; opts.fullScreen = true;
} else if (arg == "-stayontop") { } else if (arg == QLatin1String("-stayontop")) {
opts.stayOnTop = true; opts.stayOnTop = true;
} else if (arg == "-netcache") { } else if (arg == QLatin1String("-netcache")) {
if (lastArg) usage(); if (lastArg) usage();
opts.cache = arguments.at(++i).toInt(); opts.cache = arguments.at(++i).toInt();
} else if (arg == "-recordrate") { } else if (arg == QLatin1String("-recordrate")) {
if (lastArg) usage(); if (lastArg) usage();
opts.fps = arguments.at(++i).toDouble(); opts.fps = arguments.at(++i).toDouble();
} else if (arg == "-recordfile") { } else if (arg == QLatin1String("-recordfile")) {
if (lastArg) usage(); if (lastArg) usage();
opts.recordfile = arguments.at(++i); opts.recordfile = arguments.at(++i);
} else if (arg == "-record") { } else if (arg == QLatin1String("-record")) {
if (lastArg) usage(); if (lastArg) usage();
opts.recordargs << arguments.at(++i); opts.recordargs << arguments.at(++i);
} else if (arg == "-recorddither") { } else if (arg == QLatin1String("-recorddither")) {
if (lastArg) usage(); if (lastArg) usage();
opts.dither = arguments.at(++i); opts.dither = arguments.at(++i);
} else if (arg == "-autorecord") { } else if (arg == QLatin1String("-autorecord")) {
if (lastArg) usage(); if (lastArg) usage();
QString range = arguments.at(++i); QString range = arguments.at(++i);
int dash = range.indexOf('-'); int dash = range.indexOf(QLatin1Char('-'));
if (dash > 0) if (dash > 0)
opts.autorecord_from = range.left(dash).toInt(); opts.autorecord_from = range.left(dash).toInt();
opts.autorecord_to = range.mid(dash+1).toInt(); opts.autorecord_to = range.mid(dash+1).toInt();
} else if (arg == "-devicekeys") { } else if (arg == QLatin1String("-devicekeys")) {
opts.devkeys = true; opts.devkeys = true;
} else if (arg == "-dragthreshold") { } else if (arg == QLatin1String("-dragthreshold")) {
if (lastArg) usage(); if (lastArg) usage();
qApp->setStartDragDistance(arguments.at(++i).toInt()); qApp->setStartDragDistance(arguments.at(++i).toInt());
} else if (arg == QLatin1String("-v") || arg == QLatin1String("-version")) { } else if (arg == QLatin1String("-v") || arg == QLatin1String("-version")) {
qWarning("Qt QML Viewer version %s", QT_VERSION_STR); qWarning("Qt QML Viewer version %s", QT_VERSION_STR);
exitApp(0); exitApp(0);
} else if (arg == "-translation") { } else if (arg == QLatin1String("-translation")) {
if (lastArg) usage(); if (lastArg) usage();
opts.translationFile = arguments.at(++i); opts.translationFile = arguments.at(++i);
} else if (arg == "-no-opengl") { } else if (arg == QLatin1String("-no-opengl")) {
opts.useGL = false; opts.useGL = false;
} else if (arg == "-opengl") { } else if (arg == QLatin1String("-opengl")) {
opts.useGL = true; opts.useGL = true;
} else if (arg == "-qmlbrowser") { } else if (arg == QLatin1String("-qmlbrowser")) {
opts.useNativeFileBrowser = false; opts.useNativeFileBrowser = false;
} else if (arg == "-warnings") { } else if (arg == QLatin1String("-warnings")) {
if (lastArg) usage(); if (lastArg) usage();
QString warningsStr = arguments.at(++i); QString warningsStr = arguments.at(++i);
if (warningsStr == QLatin1String("show")) { if (warningsStr == QLatin1String("show")) {
@ -393,8 +394,8 @@ static void parseCommandLineOptions(const QStringList &arguments)
} else { } else {
usage(); usage();
} }
} else if (arg == "-I" || arg == "-L") { } else if (arg == QLatin1String("-I") || arg == QLatin1String("-L")) {
if (arg == "-L") if (arg == QLatin1String("-L"))
qWarning("-L option provided for compatibility only, use -I instead"); qWarning("-L option provided for compatibility only, use -I instead");
if (lastArg) { if (lastArg) {
QDeclarativeEngine tmpEngine; QDeclarativeEngine tmpEngine;
@ -403,32 +404,32 @@ static void parseCommandLineOptions(const QStringList &arguments)
exitApp(0); exitApp(0);
} }
opts.imports << arguments.at(++i); opts.imports << arguments.at(++i);
} else if (arg == "-P") { } else if (arg == QLatin1String("-P")) {
if (lastArg) usage(); if (lastArg) usage();
opts.plugins << arguments.at(++i); opts.plugins << arguments.at(++i);
} else if (arg == "-script") { } else if (arg == QLatin1String("-script")) {
if (lastArg) usage(); if (lastArg) usage();
opts.script = arguments.at(++i); opts.script = arguments.at(++i);
} else if (arg == "-scriptopts") { } else if (arg == QLatin1String("-scriptopts")) {
if (lastArg) usage(); if (lastArg) usage();
opts.scriptopts = arguments.at(++i); opts.scriptopts = arguments.at(++i);
} else if (arg == "-savescript") { } else if (arg == QLatin1String("-savescript")) {
if (lastArg) usage(); if (lastArg) usage();
opts.script = arguments.at(++i); opts.script = arguments.at(++i);
opts.runScript = false; opts.runScript = false;
} else if (arg == "-playscript") { } else if (arg == QLatin1String("-playscript")) {
if (lastArg) usage(); if (lastArg) usage();
opts.script = arguments.at(++i); opts.script = arguments.at(++i);
opts.runScript = true; opts.runScript = true;
} else if (arg == "-sizeviewtorootobject") { } else if (arg == QLatin1String("-sizeviewtorootobject")) {
opts.sizeToView = false; opts.sizeToView = false;
} else if (arg == "-sizerootobjecttoview") { } else if (arg == QLatin1String("-sizerootobjecttoview")) {
opts.sizeToView = true; opts.sizeToView = true;
} else if (arg == "-experimentalgestures") { } else if (arg == QLatin1String("-experimentalgestures")) {
opts.experimentalGestures = true; opts.experimentalGestures = true;
} else if (!arg.startsWith('-')) { } else if (!arg.startsWith(QLatin1Char('-'))) {
fileNames.append(arg); fileNames.append(arg);
} else if (true || arg == "-help") { } else if (true || arg == QLatin1String("-help")) {
usage(); usage();
} }
} }
@ -521,37 +522,47 @@ QDeclarativeViewer *openFile(const QString &fileName)
int main(int argc, char ** argv) int main(int argc, char ** argv)
{ {
QDeclarativeDebugHelper::enableDebugging();
systemMsgOutput = qInstallMsgHandler(myMessageOutput); systemMsgOutput = qInstallMsgHandler(myMessageOutput);
#if defined (Q_WS_X11) || defined (Q_WS_MAC) #if defined (Q_WS_X11) || defined (Q_WS_MAC)
//### default to using raster graphics backend for now //### default to using raster graphics backend for now
bool gsSpecified = false; bool gsSpecified = false;
for (int i = 0; i < argc; ++i) { for (int i = 0; i < argc; ++i) {
QString arg = argv[i]; QString arg = QString::fromAscii(argv[i]);
if (arg == "-graphicssystem") { if (arg == QLatin1String("-graphicssystem")) {
gsSpecified = true; gsSpecified = true;
break; break;
} }
} }
if (!gsSpecified) if (!gsSpecified)
QApplication::setGraphicsSystem("raster"); QApplication::setGraphicsSystem(QLatin1String("raster"));
#endif #endif
QDeclarativeDebugHelper::enableDebugging(); QDeclarativeDebugHelper::enableDebugging();
Application app(argc, argv); Application app(argc, argv);
app.setApplicationName("QtQmlViewer"); app.setApplicationName(QLatin1String("QtQmlViewer"));
app.setOrganizationName("Nokia"); app.setOrganizationName(QLatin1String("Nokia"));
app.setOrganizationDomain("nokia.com"); app.setOrganizationDomain(QLatin1String("nokia.com"));
QDeclarativeViewer::registerTypes(); QDeclarativeViewer::registerTypes();
QDeclarativeTester::registerTypes(); QDeclarativeTester::registerTypes();
parseCommandLineOptions(app.arguments()); parseCommandLineOptions(app.arguments());
QTranslator translator;
QTranslator qtTranslator;
QString sysLocale = QLocale::system().name();
if (translator.load(QLatin1String("qmlviewer_") + sysLocale, QLibraryInfo::location(QLibraryInfo::TranslationsPath))) {
app.installTranslator(&translator);
if (qtTranslator.load(QLatin1String("qt_") + sysLocale, QLibraryInfo::location(QLibraryInfo::TranslationsPath))) {
app.installTranslator(&qtTranslator);
} else {
app.removeTranslator(&translator);
}
}
QTranslator qmlTranslator; QTranslator qmlTranslator;
if (!opts.translationFile.isEmpty()) { if (!opts.translationFile.isEmpty()) {
if (qmlTranslator.load(opts.translationFile)) { if (qmlTranslator.load(opts.translationFile)) {

View File

@ -54,17 +54,17 @@ ProxySettings::ProxySettings (QWidget * parent)
#if !defined Q_WS_MAEMO_5 #if !defined Q_WS_MAEMO_5
// the onscreen keyboard can't cope with masks // the onscreen keyboard can't cope with masks
proxyServerEdit->setInputMask ("000.000.000.000;_"); proxyServerEdit->setInputMask(QLatin1String("000.000.000.000;_"));
#endif #endif
QIntValidator *validator = new QIntValidator (0, 9999, this); QIntValidator *validator = new QIntValidator (0, 9999, this);
proxyPortEdit->setValidator (validator); proxyPortEdit->setValidator(validator);
QSettings settings; QSettings settings;
proxyCheckBox->setChecked (settings.value ("http_proxy/use", 0).toBool ()); proxyCheckBox->setChecked(settings.value(QLatin1String("http_proxy/use"), 0).toBool());
proxyServerEdit->insert (settings.value ("http_proxy/hostname", "").toString ()); proxyServerEdit->insert(settings.value(QLatin1String("http_proxy/hostname")).toString());
proxyPortEdit->insert (settings.value ("http_proxy/port", "80").toString ()); proxyPortEdit->insert(settings.value(QLatin1String("http_proxy/port"), QLatin1String("80")).toString ());
usernameEdit->insert (settings.value ("http_proxy/username", "").toString ()); usernameEdit->insert(settings.value(QLatin1String("http_proxy/username")).toString ());
passwordEdit->insert (settings.value ("http_proxy/password", "").toString ()); passwordEdit->insert(settings.value(QLatin1String("http_proxy/password")).toString ());
} }
ProxySettings::~ProxySettings() ProxySettings::~ProxySettings()
@ -75,11 +75,11 @@ void ProxySettings::accept ()
{ {
QSettings settings; QSettings settings;
settings.setValue ("http_proxy/use", proxyCheckBox->isChecked ()); settings.setValue(QLatin1String("http_proxy/use"), proxyCheckBox->isChecked());
settings.setValue ("http_proxy/hostname", proxyServerEdit->text ()); settings.setValue(QLatin1String("http_proxy/hostname"), proxyServerEdit->text());
settings.setValue ("http_proxy/port", proxyPortEdit->text ()); settings.setValue(QLatin1String("http_proxy/port"), proxyPortEdit->text());
settings.setValue ("http_proxy/username", usernameEdit->text ()); settings.setValue(QLatin1String("http_proxy/username"), usernameEdit->text());
settings.setValue ("http_proxy/password", passwordEdit->text ()); settings.setValue(QLatin1String("http_proxy/password"), passwordEdit->text());
QDialog::accept (); QDialog::accept ();
} }
@ -89,13 +89,13 @@ QNetworkProxy ProxySettings::httpProxy ()
QSettings settings; QSettings settings;
QNetworkProxy proxy; QNetworkProxy proxy;
bool proxyInUse = settings.value ("http_proxy/use", 0).toBool (); bool proxyInUse = settings.value(QLatin1String("http_proxy/use"), 0).toBool();
if (proxyInUse) { if (proxyInUse) {
proxy.setType (QNetworkProxy::HttpProxy); proxy.setType (QNetworkProxy::HttpProxy);
proxy.setHostName (settings.value ("http_proxy/hostname", "").toString ());// "192.168.220.5" proxy.setHostName (settings.value(QLatin1String("http_proxy/hostname")).toString());// "192.168.220.5"
proxy.setPort (settings.value ("http_proxy/port", 80).toInt ()); // 8080 proxy.setPort (settings.value(QLatin1String("http_proxy/port"), 80).toInt()); // 8080
proxy.setUser (settings.value ("http_proxy/username", "").toString ()); proxy.setUser (settings.value(QLatin1String("http_proxy/username")).toString());
proxy.setPassword (settings.value ("http_proxy/password", "").toString ()); proxy.setPassword (settings.value(QLatin1String("http_proxy/password")).toString());
//QNetworkProxy::setApplicationProxy (proxy); //QNetworkProxy::setApplicationProxy (proxy);
} }
else { else {
@ -107,7 +107,7 @@ QNetworkProxy ProxySettings::httpProxy ()
bool ProxySettings::httpProxyInUse() bool ProxySettings::httpProxyInUse()
{ {
QSettings settings; QSettings settings;
return settings.value ("http_proxy/use", 0).toBool (); return settings.value(QLatin1String("http_proxy/use"), 0).toBool();
} }
QT_END_NAMESPACE QT_END_NAMESPACE

View File

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>449</width> <width>447</width>
<height>164</height> <height>162</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -88,7 +88,7 @@
<item row="1" column="1"> <item row="1" column="1">
<widget class="QLineEdit" name="proxyPortEdit"> <widget class="QLineEdit" name="proxyPortEdit">
<property name="text"> <property name="text">
<string>8080</string> <string notr="true">8080</string>
</property> </property>
</widget> </widget>
</item> </item>

View File

@ -205,7 +205,7 @@ void QDeclarativeTester::save()
QString filename = m_script + QLatin1String(".qml"); QString filename = m_script + QLatin1String(".qml");
QFileInfo filenameInfo(filename); QFileInfo filenameInfo(filename);
QDir saveDir = filenameInfo.absoluteDir(); QDir saveDir = filenameInfo.absoluteDir();
saveDir.mkpath("."); saveDir.mkpath(QLatin1String("."));
QFile file(filename); QFile file(filename);
file.open(QIODevice::WriteOnly); file.open(QIODevice::WriteOnly);
@ -224,8 +224,8 @@ void QDeclarativeTester::save()
if (!fe.hash.isEmpty()) { if (!fe.hash.isEmpty()) {
ts << " hash: \"" << fe.hash.toHex() << "\"\n"; ts << " hash: \"" << fe.hash.toHex() << "\"\n";
} else if (!fe.image.isNull()) { } else if (!fe.image.isNull()) {
QString filename = filenameInfo.baseName() + "." + QString::number(imgCount) + ".png"; QString filename = filenameInfo.baseName() + QLatin1String(".") + QString::number(imgCount) + QLatin1String(".png");
fe.image.save(m_script + "." + QString::number(imgCount) + ".png"); fe.image.save(m_script + QLatin1String(".") + QString::number(imgCount) + QLatin1String(".png"));
imgCount++; imgCount++;
ts << " image: \"" << filename << "\"\n"; ts << " image: \"" << filename << "\"\n";
} }
@ -375,7 +375,7 @@ void QDeclarativeTester::updateCurrentTime(int msec)
imagefailure(); imagefailure();
} }
if (goodImage != img) { if (goodImage != img) {
QString reject(frame->image().toLocalFile() + ".reject.png"); QString reject(frame->image().toLocalFile() + QLatin1String(".reject.png"));
qWarning() << "QDeclarativeTester(" << m_script << "): Image mismatch. Reject saved to:" qWarning() << "QDeclarativeTester(" << m_script << "): Image mismatch. Reject saved to:"
<< reject; << reject;
img.save(reject); img.save(reject);
@ -393,7 +393,7 @@ void QDeclarativeTester::updateCurrentTime(int msec)
} }
} }
} }
QString diff(frame->image().toLocalFile() + ".diff.png"); QString diff(frame->image().toLocalFile() + QLatin1String(".diff.png"));
diffimg.save(diff); diffimg.save(diff);
qWarning().nospace() << " Diff (" << diffCount << " pixels differed) saved to: " << diff; qWarning().nospace() << " Diff (" << diffCount << " pixels differed) saved to: " << diff;
} }

View File

@ -265,7 +265,7 @@ public:
hz->setValidator(new QDoubleValidator(hz)); hz->setValidator(new QDoubleValidator(hz));
#endif #endif
for (int i=0; ffmpegprofiles[i].name; ++i) { for (int i=0; ffmpegprofiles[i].name; ++i) {
profile->addItem(ffmpegprofiles[i].name); profile->addItem(QString::fromAscii(ffmpegprofiles[i].name));
} }
} }
@ -273,9 +273,9 @@ public:
{ {
int i; int i;
for (i=0; ffmpegprofiles[i].args[0]; ++i) { for (i=0; ffmpegprofiles[i].args[0]; ++i) {
if (ffmpegprofiles[i].args == a) { if (QString::fromAscii(ffmpegprofiles[i].args) == a) {
profile->setCurrentIndex(i); profile->setCurrentIndex(i);
args->setText(QLatin1String(ffmpegprofiles[i].args)); args->setText(QString::fromAscii(ffmpegprofiles[i].args));
return; return;
} }
} }
@ -465,14 +465,14 @@ private:
} }
} }
QSettings settings; QSettings settings;
settings.setValue("Cookies",data); settings.setValue(QLatin1String("Cookies"), data);
} }
void load() void load()
{ {
QMutexLocker lock(&mutex); QMutexLocker lock(&mutex);
QSettings settings; QSettings settings;
QByteArray data = settings.value("Cookies").toByteArray(); QByteArray data = settings.value(QLatin1String("Cookies")).toByteArray();
setAllCookies(QNetworkCookie::parseCookies(data)); setAllCookies(QNetworkCookie::parseCookies(data));
} }
@ -490,7 +490,7 @@ public:
if (proxyDirty) if (proxyDirty)
setupProxy(); setupProxy();
QString protocolTag = query.protocolTag(); QString protocolTag = query.protocolTag();
if (httpProxyInUse && (protocolTag == "http" || protocolTag == "https")) { if (httpProxyInUse && (protocolTag == QLatin1String("http") || protocolTag == QLatin1String("https"))) {
QList<QNetworkProxy> ret; QList<QNetworkProxy> ret;
ret << httpProxy; ret << httpProxy;
return ret; return ret;
@ -597,7 +597,7 @@ QString QDeclarativeViewer::getVideoFileName()
if (convertAvailable) types += tr("GIF Animation")+QLatin1String(" (*.gif)"); if (convertAvailable) types += tr("GIF Animation")+QLatin1String(" (*.gif)");
types += tr("Individual PNG frames")+QLatin1String(" (*.png)"); types += tr("Individual PNG frames")+QLatin1String(" (*.png)");
if (ffmpegAvailable) types += tr("All ffmpeg formats (*.*)"); if (ffmpegAvailable) types += tr("All ffmpeg formats (*.*)");
return QFileDialog::getSaveFileName(this, title, "", types.join(";; ")); return QFileDialog::getSaveFileName(this, title, QString(), types.join(QLatin1String(";; ")));
} }
QDeclarativeViewer::QDeclarativeViewer(QWidget *parent, Qt::WindowFlags flags) QDeclarativeViewer::QDeclarativeViewer(QWidget *parent, Qt::WindowFlags flags)
@ -725,18 +725,18 @@ void QDeclarativeViewer::createMenu()
connect(reloadAction, SIGNAL(triggered()), this, SLOT(reload())); connect(reloadAction, SIGNAL(triggered()), this, SLOT(reload()));
QAction *snapshotAction = new QAction(tr("&Take Snapshot"), this); QAction *snapshotAction = new QAction(tr("&Take Snapshot"), this);
snapshotAction->setShortcut(QKeySequence("F3")); snapshotAction->setShortcut(QKeySequence(tr("F3")));
connect(snapshotAction, SIGNAL(triggered()), this, SLOT(takeSnapShot())); connect(snapshotAction, SIGNAL(triggered()), this, SLOT(takeSnapShot()));
recordAction = new QAction(tr("Start Recording &Video"), this); recordAction = new QAction(tr("Start Recording &Video"), this);
recordAction->setShortcut(QKeySequence("F9")); recordAction->setShortcut(QKeySequence(tr("F9")));
connect(recordAction, SIGNAL(triggered()), this, SLOT(toggleRecordingWithSelection())); connect(recordAction, SIGNAL(triggered()), this, SLOT(toggleRecordingWithSelection()));
QAction *recordOptions = new QAction(tr("Video &Options..."), this); QAction *recordOptions = new QAction(tr("Video &Options..."), this);
connect(recordOptions, SIGNAL(triggered()), this, SLOT(chooseRecordingOptions())); connect(recordOptions, SIGNAL(triggered()), this, SLOT(chooseRecordingOptions()));
QAction *slowAction = new QAction(tr("&Slow Down Animations"), this); QAction *slowAction = new QAction(tr("&Slow Down Animations"), this);
slowAction->setShortcut(QKeySequence("Ctrl+.")); slowAction->setShortcut(QKeySequence(tr("Ctrl+.")));
slowAction->setCheckable(true); slowAction->setCheckable(true);
connect(slowAction, SIGNAL(triggered(bool)), this, SLOT(setSlowMode(bool))); connect(slowAction, SIGNAL(triggered(bool)), this, SLOT(setSlowMode(bool)));
@ -755,7 +755,7 @@ void QDeclarativeViewer::createMenu()
connect(fullscreenAction, SIGNAL(triggered()), this, SLOT(toggleFullScreen())); connect(fullscreenAction, SIGNAL(triggered()), this, SLOT(toggleFullScreen()));
rotateAction = new QAction(tr("Rotate orientation"), this); rotateAction = new QAction(tr("Rotate orientation"), this);
rotateAction->setShortcut(QKeySequence("Ctrl+T")); rotateAction->setShortcut(QKeySequence(tr("Ctrl+T")));
connect(rotateAction, SIGNAL(triggered()), this, SLOT(rotateOrientation())); connect(rotateAction, SIGNAL(triggered()), this, SLOT(rotateOrientation()));
orientation = new QActionGroup(this); orientation = new QActionGroup(this);
@ -963,7 +963,7 @@ void QDeclarativeViewer::chooseRecordingOptions()
// Profile // Profile
recdlg->setArguments(record_args.join(" ")); recdlg->setArguments(record_args.join(QLatin1String(" ")));
if (recdlg->exec()) { if (recdlg->exec()) {
// File // File
record_file = recdlg->file->text(); record_file = recdlg->file->text();
@ -972,7 +972,7 @@ void QDeclarativeViewer::chooseRecordingOptions()
// Rate // Rate
record_rate = recdlg->videoRate(); record_rate = recdlg->videoRate();
// Profile // Profile
record_args = recdlg->arguments().split(" ",QString::SkipEmptyParts); record_args = recdlg->arguments().split(QLatin1Char(' '),QString::SkipEmptyParts);
} }
} }
@ -983,8 +983,8 @@ void QDeclarativeViewer::toggleRecordingWithSelection()
QString fileName = getVideoFileName(); QString fileName = getVideoFileName();
if (fileName.isEmpty()) if (fileName.isEmpty())
return; return;
if (!fileName.contains(QRegExp(".[^\\/]*$"))) if (!fileName.contains(QRegExp(QLatin1String(".[^\\/]*$"))))
fileName += ".avi"; fileName += QLatin1String(".avi");
setRecordFile(fileName); setRecordFile(fileName);
} }
} }
@ -1026,7 +1026,7 @@ void QDeclarativeViewer::openFile()
{ {
QString cur = canvas->source().toLocalFile(); QString cur = canvas->source().toLocalFile();
if (useQmlFileBrowser) { if (useQmlFileBrowser) {
open("qrc:/browser/Browser.qml"); open(QLatin1String("qrc:/browser/Browser.qml"));
} else { } else {
QString fileName = QFileDialog::getOpenFileName(this, tr("Open QML file"), cur, tr("QML Files (*.qml)")); QString fileName = QFileDialog::getOpenFileName(this, tr("Open QML file"), cur, tr("QML Files (*.qml)"));
if (!fileName.isEmpty()) { if (!fileName.isEmpty()) {
@ -1072,7 +1072,7 @@ void QDeclarativeViewer::loadTranslationFile(const QString& directory)
void QDeclarativeViewer::loadDummyDataFiles(const QString& directory) void QDeclarativeViewer::loadDummyDataFiles(const QString& directory)
{ {
QDir dir(directory+"/dummydata", "*.qml"); QDir dir(directory + QLatin1String("/dummydata"), QLatin1String("*.qml"));
QStringList list = dir.entryList(); QStringList list = dir.entryList();
for (int i = 0; i < list.size(); ++i) { for (int i = 0; i < list.size(); ++i) {
QString qml = list.at(i); QString qml = list.at(i);
@ -1114,14 +1114,14 @@ bool QDeclarativeViewer::open(const QString& file_or_url)
delete canvas->rootObject(); delete canvas->rootObject();
canvas->engine()->clearComponentCache(); canvas->engine()->clearComponentCache();
QDeclarativeContext *ctxt = canvas->rootContext(); QDeclarativeContext *ctxt = canvas->rootContext();
ctxt->setContextProperty("qmlViewer", this); ctxt->setContextProperty(QLatin1String("qmlViewer"), this);
#ifdef Q_OS_SYMBIAN #ifdef Q_OS_SYMBIAN
ctxt->setContextProperty("qmlViewerFolder", "E:\\"); // Documents on your S60 phone ctxt->setContextProperty(QLatin1String("qmlViewerFolder"), QLatin1String("E:\\")); // Documents on your S60 phone
#else #else
ctxt->setContextProperty("qmlViewerFolder", QDir::currentPath()); ctxt->setContextProperty(QLatin1String("qmlViewerFolder"), QDir::currentPath());
#endif #endif
ctxt->setContextProperty("runtime", Runtime::instance()); ctxt->setContextProperty(QLatin1String("runtime"), Runtime::instance());
QString fileName = url.toLocalFile(); QString fileName = url.toLocalFile();
if (!fileName.isEmpty()) { if (!fileName.isEmpty()) {
@ -1224,26 +1224,26 @@ bool QDeclarativeViewer::event(QEvent *event)
void QDeclarativeViewer::senseImageMagick() void QDeclarativeViewer::senseImageMagick()
{ {
QProcess proc; QProcess proc;
proc.start("convert", QStringList() << "-h"); proc.start(QLatin1String("convert"), QStringList() << QLatin1String("-h"));
proc.waitForFinished(2000); proc.waitForFinished(2000);
QString help = proc.readAllStandardOutput(); QString help = QString::fromAscii(proc.readAllStandardOutput());
convertAvailable = help.contains("ImageMagick"); convertAvailable = help.contains(QLatin1String("ImageMagick"));
} }
void QDeclarativeViewer::senseFfmpeg() void QDeclarativeViewer::senseFfmpeg()
{ {
QProcess proc; QProcess proc;
proc.start("ffmpeg", QStringList() << "-h"); proc.start(QLatin1String("ffmpeg"), QStringList() << QLatin1String("-h"));
proc.waitForFinished(2000); proc.waitForFinished(2000);
QString ffmpegHelp = proc.readAllStandardOutput(); QString ffmpegHelp = QString::fromAscii(proc.readAllStandardOutput());
ffmpegAvailable = ffmpegHelp.contains("-s "); ffmpegAvailable = ffmpegHelp.contains(QLatin1String("-s "));
ffmpegHelp = tr("Video recording uses ffmpeg:")+"\n\n"+ffmpegHelp; ffmpegHelp = tr("Video recording uses ffmpeg:") + QLatin1String("\n\n") + ffmpegHelp;
QDialog *d = new QDialog(recdlg); QDialog *d = new QDialog(recdlg);
QVBoxLayout *l = new QVBoxLayout(d); QVBoxLayout *l = new QVBoxLayout(d);
QTextBrowser *b = new QTextBrowser(d); QTextBrowser *b = new QTextBrowser(d);
QFont f = b->font(); QFont f = b->font();
f.setFamily("courier"); f.setFamily(QLatin1String("courier"));
b->setFont(f); b->setFont(f);
b->setText(ffmpegHelp); b->setText(ffmpegHelp);
l->addWidget(b); l->addWidget(b);
@ -1266,7 +1266,7 @@ void QDeclarativeViewer::setRecording(bool on)
recordTimer.start(); recordTimer.start();
frame_fmt = record_file.right(4).toLower(); frame_fmt = record_file.right(4).toLower();
frame = QImage(canvas->width(),canvas->height(),QImage::Format_RGB32); frame = QImage(canvas->width(),canvas->height(),QImage::Format_RGB32);
if (frame_fmt != ".png" && (!convertAvailable || frame_fmt != ".gif")) { if (frame_fmt != QLatin1String(".png") && (!convertAvailable || frame_fmt != QLatin1String(".gif"))) {
// Stream video to ffmpeg // Stream video to ffmpeg
QProcess *proc = new QProcess(this); QProcess *proc = new QProcess(this);
@ -1274,19 +1274,19 @@ void QDeclarativeViewer::setRecording(bool on)
frame_stream = proc; frame_stream = proc;
QStringList args; QStringList args;
args << "-y"; args << QLatin1String("-y");
args << "-r" << QString::number(record_rate); args << QLatin1String("-r") << QString::number(record_rate);
args << "-f" << "rawvideo"; args << QLatin1String("-f") << QLatin1String("rawvideo");
args << "-pix_fmt" << (frame_fmt == ".gif" ? "rgb24" : "rgb32"); args << QLatin1String("-pix_fmt") << (frame_fmt == QLatin1String(".gif") ? QLatin1String("rgb24") : QLatin1String("rgb32"));
args << "-s" << QString("%1x%2").arg(canvas->width()).arg(canvas->height()); args << QLatin1String("-s") << QString::fromAscii("%1x%2").arg(canvas->width()).arg(canvas->height());
args << "-i" << "-"; args << QLatin1String("-i") << QLatin1String("-");
if (record_outsize.isValid()) { if (record_outsize.isValid()) {
args << "-s" << QString("%1x%2").arg(record_outsize.width()).arg(record_outsize.height()); args << QLatin1String("-s") << QString::fromAscii("%1x%2").arg(record_outsize.width()).arg(record_outsize.height());
args << "-aspect" << QString::number(double(canvas->width())/canvas->height()); args << QLatin1String("-aspect") << QString::number(double(canvas->width())/canvas->height());
} }
args += record_args; args += record_args;
args << record_file; args << record_file;
proc->start("ffmpeg",args); proc->start(QLatin1String("ffmpeg"), args);
} else { } else {
// Store frames, save to GIF/PNG // Store frames, save to GIF/PNG
@ -1309,14 +1309,14 @@ void QDeclarativeViewer::setRecording(bool on)
QString framename; QString framename;
bool png_output = false; bool png_output = false;
if (record_file.right(4).toLower()==".png") { if (record_file.right(4).toLower() == QLatin1String(".png")) {
if (record_file.contains('%')) if (record_file.contains(QLatin1Char('%')))
framename = record_file; framename = record_file;
else else
framename = record_file.left(record_file.length()-4)+"%04d"+record_file.right(4); framename = record_file.left(record_file.length()-4) + QLatin1String("%04d") + record_file.right(4);
png_output = true; png_output = true;
} else { } else {
framename = "tmp-frame%04d.png"; framename = QLatin1String("tmp-frame%04d.png");
png_output = false; png_output = false;
} }
foreach (QImage* img, frames) { foreach (QImage* img, frames) {
@ -1327,11 +1327,11 @@ void QDeclarativeViewer::setRecording(bool on)
name.sprintf(framename.toLocal8Bit(),frame++); name.sprintf(framename.toLocal8Bit(),frame++);
if (record_outsize.isValid()) if (record_outsize.isValid())
*img = img->scaled(record_outsize,Qt::IgnoreAspectRatio,Qt::SmoothTransformation); *img = img->scaled(record_outsize,Qt::IgnoreAspectRatio,Qt::SmoothTransformation);
if (record_dither=="ordered") if (record_dither==QLatin1String("ordered"))
img->convertToFormat(QImage::Format_Indexed8,Qt::PreferDither|Qt::OrderedDither).save(name); img->convertToFormat(QImage::Format_Indexed8,Qt::PreferDither|Qt::OrderedDither).save(name);
else if (record_dither=="threshold") else if (record_dither==QLatin1String("threshold"))
img->convertToFormat(QImage::Format_Indexed8,Qt::PreferDither|Qt::ThresholdDither).save(name); img->convertToFormat(QImage::Format_Indexed8,Qt::PreferDither|Qt::ThresholdDither).save(name);
else if (record_dither=="floyd") else if (record_dither==QLatin1String("floyd"))
img->convertToFormat(QImage::Format_Indexed8,Qt::PreferDither).save(name); img->convertToFormat(QImage::Format_Indexed8,Qt::PreferDither).save(name);
else else
img->save(name); img->save(name);
@ -1341,25 +1341,26 @@ void QDeclarativeViewer::setRecording(bool on)
if (!progress.wasCanceled()) { if (!progress.wasCanceled()) {
if (png_output) { if (png_output) {
framename.replace(QRegExp("%\\d*."),"*"); framename.replace(QRegExp(QLatin1String("%\\d*.")), QLatin1String("*"));
qDebug() << "Wrote frames" << framename; qDebug() << "Wrote frames" << framename;
inputs.clear(); // don't remove them inputs.clear(); // don't remove them
} else { } else {
// ImageMagick and gifsicle for GIF encoding // ImageMagick and gifsicle for GIF encoding
progress.setLabelText(tr("Converting frames to GIF file...")); progress.setLabelText(tr("Converting frames to GIF file..."));
QStringList args; QStringList args;
args << "-delay" << QString::number(period/10); args << QLatin1String("-delay") << QString::number(period/10);
args << inputs; args << inputs;
args << record_file; args << record_file;
qDebug() << "Converting..." << record_file << "(this may take a while)"; qDebug() << "Converting..." << record_file << "(this may take a while)";
if (0!=QProcess::execute("convert", args)) { if (0!=QProcess::execute(QLatin1String("convert"), args)) {
qWarning() << "Cannot run ImageMagick 'convert' - recorded frames not converted"; qWarning() << "Cannot run ImageMagick 'convert' - recorded frames not converted";
inputs.clear(); // don't remove them inputs.clear(); // don't remove them
qDebug() << "Wrote frames tmp-frame*.png"; qDebug() << "Wrote frames tmp-frame*.png";
} else { } else {
if (record_file.right(4).toLower() == ".gif") { if (record_file.right(4).toLower() == QLatin1String(".gif")) {
qDebug() << "Compressing..." << record_file; qDebug() << "Compressing..." << record_file;
if (0!=QProcess::execute("gifsicle", QStringList() << "-O2" << "-o" << record_file << record_file)) if (0!=QProcess::execute(QLatin1String("gifsicle"), QStringList() << QLatin1String("-O2")
<< QLatin1String("-o") << record_file << record_file))
qWarning() << "Cannot run 'gifsicle' - not compressed"; qWarning() << "Cannot run 'gifsicle' - not compressed";
} }
qDebug() << "Wrote" << record_file; qDebug() << "Wrote" << record_file;
@ -1410,7 +1411,7 @@ void QDeclarativeViewer::recordFrame()
{ {
canvas->QWidget::render(&frame); canvas->QWidget::render(&frame);
if (frame_stream) { if (frame_stream) {
if (frame_fmt == ".gif") { if (frame_fmt == QLatin1String(".gif")) {
// ffmpeg can't do 32bpp with gif // ffmpeg can't do 32bpp with gif
QImage rgb24 = frame.convertToFormat(QImage::Format_RGB888); QImage rgb24 = frame.convertToFormat(QImage::Format_RGB888);
frame_stream->write((char*)rgb24.bits(),rgb24.numBytes()); frame_stream->write((char*)rgb24.bits(),rgb24.numBytes());
@ -1542,8 +1543,8 @@ void QDeclarativeViewer::registerTypes()
if (!registered) { if (!registered) {
// registering only for exposing the DeviceOrientation::Orientation enum // registering only for exposing the DeviceOrientation::Orientation enum
qmlRegisterUncreatableType<DeviceOrientation>("Qt",4,7,"Orientation",""); qmlRegisterUncreatableType<DeviceOrientation>("Qt", 4, 7, "Orientation", QString());
qmlRegisterUncreatableType<DeviceOrientation>("QtQuick",1,0,"Orientation",""); qmlRegisterUncreatableType<DeviceOrientation>("QtQuick", 1, 0, "Orientation", QString());
registered = true; registered = true;
} }
} }

View File

@ -10,6 +10,8 @@ INCLUDEPATH += ../../include/QtDeclarative
INCLUDEPATH += ../../src/declarative/util INCLUDEPATH += ../../src/declarative/util
INCLUDEPATH += ../../src/declarative/graphicsitems INCLUDEPATH += ../../src/declarative/graphicsitems
DEFINES += QT_NO_CAST_FROM_ASCII QT_NO_CAST_TO_ASCII
target.path = $$[QT_INSTALL_BINS] target.path = $$[QT_INSTALL_BINS]
INSTALLS += target INSTALLS += target