summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorQt Continuous Integration System <qt-info@nokia.com>2010-06-16 16:21:24 (GMT)
committerQt Continuous Integration System <qt-info@nokia.com>2010-06-16 16:21:24 (GMT)
commit7b30a66b2f16a8bf8828d26b7d0b193b5dffe713 (patch)
tree3ed1219e02bab53df871e7bf87bcf191c1a7534b /src
parent65b05e330640a5e1920c61a4735cbc27a5ca3fe2 (diff)
parent6d178306f71564471cc08eb7dc98743c3752cac4 (diff)
downloadQt-7b30a66b2f16a8bf8828d26b7d0b193b5dffe713.zip
Qt-7b30a66b2f16a8bf8828d26b7d0b193b5dffe713.tar.gz
Qt-7b30a66b2f16a8bf8828d26b7d0b193b5dffe713.tar.bz2
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/qt-qml into 4.7-integration
* '4.7' of scm.dev.nokia.troll.no:qt/qt-qml: Fix the N900 device orientation backend Micro cleanup Write TextInput.positionToRectangle docs. Minor demo fixes Fix autoScroll implementation Move knowledge of QGraphicsObject out of qml engine Stopping a flick resulted in the next click being consumed. Enhance docs Slight addition to the docs.
Diffstat (limited to 'src')
-rw-r--r--src/declarative/graphicsitems/qdeclarativeflickable.cpp1
-rw-r--r--src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp16
-rw-r--r--src/declarative/graphicsitems/qdeclarativetextinput.cpp100
-rw-r--r--src/declarative/graphicsitems/qdeclarativetextinput_p.h2
-rw-r--r--src/declarative/graphicsitems/qdeclarativetextinput_p_p.h1
-rw-r--r--src/declarative/qml/qdeclarativecomponent.cpp25
-rw-r--r--src/declarative/qml/qdeclarativeengine.cpp11
-rw-r--r--src/declarative/qml/qdeclarativemetatype.cpp19
-rw-r--r--src/declarative/qml/qdeclarativemetatype_p.h2
-rw-r--r--src/declarative/qml/qdeclarativeprivate.h4
10 files changed, 127 insertions, 54 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativeflickable.cpp b/src/declarative/graphicsitems/qdeclarativeflickable.cpp
index fdc1444..6dfd4d9 100644
--- a/src/declarative/graphicsitems/qdeclarativeflickable.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeflickable.cpp
@@ -1214,6 +1214,7 @@ bool QDeclarativeFlickable::sendMouseEvent(QGraphicsSceneMouseEvent *event)
default:
break;
}
+ stealThisEvent = d->stealMouse; // Update stealThisEvent and grabber in case changed by function calls above
grabber = qobject_cast<QDeclarativeItem*>(s->mouseGrabberItem());
if (grabber && stealThisEvent && !grabber->keepMouseGrab() && grabber != this) {
d->clearDelayedPress();
diff --git a/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp b/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp
index 0be8dac..b198077 100644
--- a/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp
@@ -79,8 +79,24 @@
#endif
#include "private/qdeclarativeanchors_p.h"
+static QDeclarativePrivate::AutoParentResult qgraphicsobject_autoParent(QObject *obj, QObject *parent)
+{
+ QGraphicsObject* gobj = qobject_cast<QGraphicsObject*>(obj);
+ if (!gobj)
+ return QDeclarativePrivate::IncompatibleObject;
+
+ QGraphicsObject* gparent = qobject_cast<QGraphicsObject*>(parent);
+ if (!gparent)
+ return QDeclarativePrivate::IncompatibleParent;
+
+ gobj->setParentItem(gparent);
+ return QDeclarativePrivate::Parented;
+}
+
void QDeclarativeItemModule::defineModule()
{
+ QDeclarativePrivate::registerAutoParentFunction(qgraphicsobject_autoParent);
+
#ifdef QT_NO_MOVIE
qmlRegisterTypeNotAvailable("Qt",4,7,"AnimatedImage",
qApp->translate("QDeclarativeAnimatedImage","Qt was built without support for QMovie"));
diff --git a/src/declarative/graphicsitems/qdeclarativetextinput.cpp b/src/declarative/graphicsitems/qdeclarativetextinput.cpp
index cba01ef..9e5dfb5 100644
--- a/src/declarative/graphicsitems/qdeclarativetextinput.cpp
+++ b/src/declarative/graphicsitems/qdeclarativetextinput.cpp
@@ -100,6 +100,7 @@ void QDeclarativeTextInput::setText(const QString &s)
if(s == text())
return;
d->control->setText(s);
+ d->updateHorizontalScroll();
//emit textChanged();
}
@@ -337,6 +338,7 @@ void QDeclarativeTextInput::setHAlign(HAlignment align)
return;
d->hAlign = align;
updateRect();
+ d->updateHorizontalScroll();
emit horizontalAlignmentChanged(d->hAlign);
}
@@ -554,7 +556,9 @@ void QDeclarativeTextInput::setAutoScroll(bool b)
return;
d->autoScroll = b;
-
+ d->updateHorizontalScroll();
+ //We need to repaint so that the scrolling is taking into account.
+ updateSize(true);
emit autoScrollChanged(d->autoScroll);
}
@@ -836,17 +840,23 @@ void QDeclarativeTextInput::moveCursor()
Q_D(QDeclarativeTextInput);
if(!d->cursorItem)
return;
+ d->updateHorizontalScroll();
d->cursorItem->setX(d->control->cursorToX() - d->hscroll);
}
/*!
- \qmlmethod rect TextInput::positionToRectangle(int x)
+ \qmlmethod rect TextInput::positionToRectangle(int pos)
+
+ This function takes a character position and returns the rectangle that the
+ cursor would occupy, if it was placed at that character position.
+
+ This is similar to setting the cursorPosition, and then querying the cursor
+ rectangle, but the cursorPosition is not changed.
*/
-QRectF QDeclarativeTextInput::positionToRectangle(int x) const
+QRectF QDeclarativeTextInput::positionToRectangle(int pos) const
{
Q_D(const QDeclarativeTextInput);
- QFontMetrics fm = QFontMetrics(d->font);
- return QRectF(d->control->cursorToX(x)-d->hscroll,
+ return QRectF(d->control->cursorToX(pos)-d->hscroll,
0.0,
d->control->cursorWidth(),
cursorRectangle().height());
@@ -1006,61 +1016,73 @@ void QDeclarativeTextInput::geometryChanged(const QRectF &newGeometry,
QDeclarativePaintedItem::geometryChanged(newGeometry, oldGeometry);
}
-void QDeclarativeTextInput::drawContents(QPainter *p, const QRect &r)
+void QDeclarativeTextInputPrivate::updateHorizontalScroll()
{
- Q_D(QDeclarativeTextInput);
- p->setRenderHint(QPainter::TextAntialiasing, true);
- p->save();
- p->setPen(QPen(d->color));
- int flags = QLineControl::DrawText;
- if(!isReadOnly() && d->cursorVisible && !d->cursorItem)
- flags |= QLineControl::DrawCursor;
- if (d->control->hasSelectedText())
- flags |= QLineControl::DrawSelections;
- QPoint offset = QPoint(0,0);
- QFontMetrics fm = QFontMetrics(d->font);
- int cix = qRound(d->control->cursorToX());
- QRect br(boundingRect().toRect());
+ Q_Q(QDeclarativeTextInput);
+ QFontMetrics fm = QFontMetrics(font);
+ int cix = qRound(control->cursorToX());
+ QRect br(q->boundingRect().toRect());
//###Is this using bearing appropriately?
int minLB = qMax(0, -fm.minLeftBearing());
int minRB = qMax(0, -fm.minRightBearing());
- int widthUsed = qRound(d->control->naturalTextWidth()) + 1 + minRB;
- if (d->autoScroll) {
+ int widthUsed = qRound(control->naturalTextWidth()) + 1 + minRB;
+ if (autoScroll) {
if ((minLB + widthUsed) <= br.width()) {
// text fits in br; use hscroll for alignment
- switch (d->hAlign & ~(Qt::AlignAbsolute|Qt::AlignVertical_Mask)) {
+ switch (hAlign & ~(Qt::AlignAbsolute|Qt::AlignVertical_Mask)) {
case Qt::AlignRight:
- d->hscroll = widthUsed - br.width() + 1;
+ hscroll = widthUsed - br.width() + 1;
break;
case Qt::AlignHCenter:
- d->hscroll = (widthUsed - br.width()) / 2;
+ hscroll = (widthUsed - br.width()) / 2;
break;
default:
// Left
- d->hscroll = 0;
+ hscroll = 0;
break;
}
- d->hscroll -= minLB;
- } else if (cix - d->hscroll >= br.width()) {
+ hscroll -= minLB;
+ } else if (cix - hscroll >= br.width()) {
// text doesn't fit, cursor is to the right of br (scroll right)
- d->hscroll = cix - br.width() + 1;
- } else if (cix - d->hscroll < 0 && d->hscroll < widthUsed) {
+ hscroll = cix - br.width() + 1;
+ } else if (cix - hscroll < 0 && hscroll < widthUsed) {
// text doesn't fit, cursor is to the left of br (scroll left)
- d->hscroll = cix;
- } else if (widthUsed - d->hscroll < br.width()) {
+ hscroll = cix;
+ } else if (widthUsed - hscroll < br.width()) {
// text doesn't fit, text document is to the left of br; align
// right
- d->hscroll = widthUsed - br.width() + 1;
+ hscroll = widthUsed - br.width() + 1;
+ }
+ } else {
+ if(hAlign == QDeclarativeTextInput::AlignRight){
+ hscroll = q->width() - widthUsed;
+ }else if(hAlign == QDeclarativeTextInput::AlignHCenter){
+ hscroll = (q->width() - widthUsed) / 2;
+ } else {
+ hscroll = 0;
}
+ hscroll -= minLB;
+ }
+}
+
+void QDeclarativeTextInput::drawContents(QPainter *p, const QRect &r)
+{
+ Q_D(QDeclarativeTextInput);
+ p->setRenderHint(QPainter::TextAntialiasing, true);
+ p->save();
+ p->setPen(QPen(d->color));
+ int flags = QLineControl::DrawText;
+ if(!isReadOnly() && d->cursorVisible && !d->cursorItem)
+ flags |= QLineControl::DrawCursor;
+ if (d->control->hasSelectedText())
+ flags |= QLineControl::DrawSelections;
+ QPoint offset = QPoint(0,0);
+ QFontMetrics fm = QFontMetrics(d->font);
+ QRect br(boundingRect().toRect());
+ if (d->autoScroll) {
// the y offset is there to keep the baseline constant in case we have script changes in the text.
offset = br.topLeft() - QPoint(d->hscroll, d->control->ascent() - fm.ascent());
} else {
- if(d->hAlign == AlignRight){
- d->hscroll = width() - widthUsed;
- }else if(d->hAlign == AlignHCenter){
- d->hscroll = (width() - widthUsed) / 2;
- }
- d->hscroll -= minLB;
offset = QPoint(d->hscroll, 0);
}
d->control->draw(p, offset, r, flags);
@@ -1230,6 +1252,7 @@ void QDeclarativeTextInput::moveCursorSelection(int position)
{
Q_D(QDeclarativeTextInput);
d->control->moveCursor(position, true);
+ d->updateHorizontalScroll();
}
/*!
@@ -1420,6 +1443,7 @@ void QDeclarativeTextInput::selectionChanged()
void QDeclarativeTextInput::q_textChanged()
{
Q_D(QDeclarativeTextInput);
+ d->updateHorizontalScroll();
updateSize();
emit textChanged();
if(hasAcceptableInput() != d->oldValidity){
diff --git a/src/declarative/graphicsitems/qdeclarativetextinput_p.h b/src/declarative/graphicsitems/qdeclarativetextinput_p.h
index c539bd3..03f55ae 100644
--- a/src/declarative/graphicsitems/qdeclarativetextinput_p.h
+++ b/src/declarative/graphicsitems/qdeclarativetextinput_p.h
@@ -112,7 +112,7 @@ public:
//Auxilliary functions needed to control the TextInput from QML
Q_INVOKABLE int positionAt(int x) const;
- Q_INVOKABLE QRectF positionToRectangle(int x) const;
+ Q_INVOKABLE QRectF positionToRectangle(int pos) const;
Q_INVOKABLE void moveCursorSelection(int pos);
Q_INVOKABLE void openSoftwareInputPanel();
diff --git a/src/declarative/graphicsitems/qdeclarativetextinput_p_p.h b/src/declarative/graphicsitems/qdeclarativetextinput_p_p.h
index 6865147..8b74bcc 100644
--- a/src/declarative/graphicsitems/qdeclarativetextinput_p_p.h
+++ b/src/declarative/graphicsitems/qdeclarativetextinput_p_p.h
@@ -99,6 +99,7 @@ public:
void init();
void startCreatingCursor();
void focusChanged(bool hasFocus);
+ void updateHorizontalScroll();
QLineControl* control;
diff --git a/src/declarative/qml/qdeclarativecomponent.cpp b/src/declarative/qml/qdeclarativecomponent.cpp
index 55ee783..b4919ff 100644
--- a/src/declarative/qml/qdeclarativecomponent.cpp
+++ b/src/declarative/qml/qdeclarativecomponent.cpp
@@ -60,7 +60,6 @@
#include <QFileInfo>
#include <QtCore/qdebug.h>
#include <QApplication>
-#include <QGraphicsObject>
QT_BEGIN_NAMESPACE
@@ -579,20 +578,26 @@ QScriptValue QDeclarativeComponent::createObject(QObject* parent)
if (!ret)
return QScriptValue(QScriptValue::NullValue);
- QGraphicsObject* gobj = qobject_cast<QGraphicsObject*>(ret);
- bool needParent = (gobj != 0);
- if(parent){
+
+ if (parent) {
ret->setParent(parent);
- if (gobj) {
- QGraphicsObject* gparent = qobject_cast<QGraphicsObject*>(parent);
- if(gparent){
- gobj->setParentItem(gparent);
+ QList<QDeclarativePrivate::AutoParentFunction> functions = QDeclarativeMetaType::parentFunctions();
+
+ bool needParent = false;
+
+ for (int ii = 0; ii < functions.count(); ++ii) {
+ QDeclarativePrivate::AutoParentResult res = functions.at(ii)(ret, parent);
+ if (res == QDeclarativePrivate::Parented) {
needParent = false;
+ break;
+ } else if (res == QDeclarativePrivate::IncompatibleParent) {
+ needParent = true;
}
}
+
+ if (needParent)
+ qWarning("QDeclarativeComponent: Created graphical object was not placed in the graphics scene.");
}
- if(needParent)
- qWarning("QDeclarativeComponent: Created graphical object was not placed in the graphics scene.");
QDeclarativeEnginePrivate *priv = QDeclarativeEnginePrivate::get(d->engine);
QDeclarativeData::get(ret, true)->setImplicitDestructible();
diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp
index 0715624..5c4d229 100644
--- a/src/declarative/qml/qdeclarativeengine.cpp
+++ b/src/declarative/qml/qdeclarativeengine.cpp
@@ -93,7 +93,6 @@
#include <QtGui/qcolor.h>
#include <QtGui/qvector3d.h>
#include <QtGui/qsound.h>
-#include <QGraphicsObject>
#include <QtCore/qcryptographichash.h>
#include <private/qobject_p.h>
@@ -1195,10 +1194,12 @@ QScriptValue QDeclarativeEnginePrivate::createQmlObject(QScriptContext *ctxt, QS
Q_ASSERT(obj);
obj->setParent(parentArg);
- QGraphicsObject* gobj = qobject_cast<QGraphicsObject*>(obj);
- QGraphicsObject* gparent = qobject_cast<QGraphicsObject*>(parentArg);
- if(gobj && gparent)
- gobj->setParentItem(gparent);
+
+ QList<QDeclarativePrivate::AutoParentFunction> functions = QDeclarativeMetaType::parentFunctions();
+ for (int ii = 0; ii < functions.count(); ++ii) {
+ if (QDeclarativePrivate::Parented == functions.at(ii)(obj, parentArg))
+ break;
+ }
QDeclarativeData::get(obj, true)->setImplicitDestructible();
return activeEnginePriv->objectClass->newQObject(obj, QMetaType::QObjectStar);
diff --git a/src/declarative/qml/qdeclarativemetatype.cpp b/src/declarative/qml/qdeclarativemetatype.cpp
index 5fcb7ee..c32cab6 100644
--- a/src/declarative/qml/qdeclarativemetatype.cpp
+++ b/src/declarative/qml/qdeclarativemetatype.cpp
@@ -112,6 +112,8 @@ struct QDeclarativeMetaTypeData
QBitArray objects;
QBitArray interfaces;
QBitArray lists;
+
+ QList<QDeclarativePrivate::AutoParentFunction> parentFunctions;
};
Q_GLOBAL_STATIC(QDeclarativeMetaTypeData, metaTypeData)
Q_GLOBAL_STATIC(QReadWriteLock, metaTypeDataLock)
@@ -483,6 +485,16 @@ int QDeclarativeType::index() const
return d->m_index;
}
+int QDeclarativePrivate::registerAutoParentFunction(AutoParentFunction function)
+{
+ QWriteLocker lock(metaTypeDataLock());
+ QDeclarativeMetaTypeData *data = metaTypeData();
+
+ data->parentFunctions.append(function);
+
+ return data->parentFunctions.count() - 1;
+}
+
int QDeclarativePrivate::registerType(const QDeclarativePrivate::RegisterInterface &interface)
{
if (interface.version > 0)
@@ -583,6 +595,13 @@ bool QDeclarativeMetaType::isModule(const QByteArray &module, int versionMajor,
((*it).vmajor_min == versionMajor && (*it).vminor_min <= versionMinor))));
}
+QList<QDeclarativePrivate::AutoParentFunction> QDeclarativeMetaType::parentFunctions()
+{
+ QReadLocker lock(metaTypeDataLock());
+ QDeclarativeMetaTypeData *data = metaTypeData();
+ return data->parentFunctions;
+}
+
QObject *QDeclarativeMetaType::toQObject(const QVariant &v, bool *ok)
{
if (!isQObject(v.userType())) {
diff --git a/src/declarative/qml/qdeclarativemetatype_p.h b/src/declarative/qml/qdeclarativemetatype_p.h
index bf6a700..4c98b6f 100644
--- a/src/declarative/qml/qdeclarativemetatype_p.h
+++ b/src/declarative/qml/qdeclarativemetatype_p.h
@@ -99,6 +99,8 @@ public:
static StringConverter customStringConverter(int);
static bool isModule(const QByteArray &module, int versionMajor, int versionMinor);
+
+ static QList<QDeclarativePrivate::AutoParentFunction> parentFunctions();
};
class QDeclarativeTypePrivate;
diff --git a/src/declarative/qml/qdeclarativeprivate.h b/src/declarative/qml/qdeclarativeprivate.h
index e657dd5..cd859fe 100644
--- a/src/declarative/qml/qdeclarativeprivate.h
+++ b/src/declarative/qml/qdeclarativeprivate.h
@@ -214,6 +214,10 @@ namespace QDeclarativePrivate
const char *iid;
};
+ enum AutoParentResult { Parented, IncompatibleObject, IncompatibleParent };
+ typedef AutoParentResult (*AutoParentFunction)(QObject *object, QObject *parent);
+
+ int Q_DECLARATIVE_EXPORT registerAutoParentFunction(AutoParentFunction);
int Q_DECLARATIVE_EXPORT registerType(const RegisterType &);
int Q_DECLARATIVE_EXPORT registerType(const RegisterInterface &);