diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-04-29 05:50:07 (GMT) |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-04-29 05:50:07 (GMT) |
commit | 27cce9ae6c889c1803e46e45375ffb411490989d (patch) | |
tree | b650a566b38cf7120c9375fb55c450f1a22ce214 /src/declarative | |
parent | 19c897d9fa2ee68aa0e8a5b3d1d12ad9cc431cba (diff) | |
parent | 012bf05b8c5e37bb102406d79023cb5d875deaac (diff) | |
download | Qt-27cce9ae6c889c1803e46e45375ffb411490989d.zip Qt-27cce9ae6c889c1803e46e45375ffb411490989d.tar.gz Qt-27cce9ae6c889c1803e46e45375ffb411490989d.tar.bz2 |
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
Diffstat (limited to 'src/declarative')
-rw-r--r-- | src/declarative/fx/qfxflipable.cpp | 133 | ||||
-rw-r--r-- | src/declarative/fx/qfxflipable.h | 10 | ||||
-rw-r--r-- | src/declarative/fx/qfxtransform.cpp | 25 | ||||
-rw-r--r-- | src/declarative/fx/qfxwebview.cpp | 83 | ||||
-rw-r--r-- | src/declarative/fx/qfxwebview.h | 3 |
5 files changed, 242 insertions, 12 deletions
diff --git a/src/declarative/fx/qfxflipable.cpp b/src/declarative/fx/qfxflipable.cpp index 9db0b57..1d15827 100644 --- a/src/declarative/fx/qfxflipable.cpp +++ b/src/declarative/fx/qfxflipable.cpp @@ -49,11 +49,17 @@ QML_DEFINE_TYPE(QFxFlipable,Flipable); class QFxFlipablePrivate : public QFxItemPrivate { public: - QFxFlipablePrivate() : current(QFxFlipable::Front), front(0), back(0) {} + QFxFlipablePrivate() : current(QFxFlipable::Front), front(0), back(0), axis(0), rotation(0) {} + + void setBackTransform(); + void _q_updateAxis(); QFxFlipable::Side current; QFxItem *front; QFxItem *back; + QFxAxis *axis; + QFxRotation axisRotation; + qreal rotation; }; /*! @@ -65,18 +71,18 @@ public: \code <Flipable id="flipable" width="40" height="40"> - <transform> - <Axis id="axis" xStart="20" xEnd="20" yStart="20" yEnd="0" /> - </transform> + <axis> + <Axis startX="20" startY="0" endX="20" endY="40" /> + </axis> <front> - <Image file="front.png"/> + <Image src="front.png"/> </front> <back> - <Image file="back.png"/> + <Image src="back.png"/> </back> <states> <State name="back"> - <SetProperty target="{axis}" property="rotation" value="180" /> + <SetProperty target="{flipable}" property="rotation" value="180" /> </State> </states> <transitions> @@ -153,6 +159,114 @@ void QFxFlipable::setBack(QFxItem *back) children()->append(d->back); if (Front == d->current) d->back->setOpacity(0.); + d->setBackTransform(); +} + +/*! + \qmlproperty Axis Flipable::axis + + The axis to flip around. See the \l Axis documentation for more + information on specifying an axis. +*/ + +QFxAxis *QFxFlipable::axis() +{ + Q_D(QFxFlipable); + return d->axis; +} + +void QFxFlipable::setAxis(QFxAxis *axis) +{ + Q_D(QFxFlipable); + //### disconnect if we are already connected? + if (d->axis) + disconnect(d->axis, SIGNAL(updated()), this, SLOT(_q_updateAxis())); + d->axis = axis; + connect(d->axis, SIGNAL(updated()), this, SLOT(_q_updateAxis())); + d->_q_updateAxis(); +} + +void QFxFlipablePrivate::_q_updateAxis() +{ + axisRotation.axis()->setStartX(axis->startX()); + axisRotation.axis()->setStartY(axis->startY()); + axisRotation.axis()->setEndX(axis->endX()); + axisRotation.axis()->setEndY(axis->endY()); + axisRotation.axis()->setEndZ(axis->endZ()); + + setBackTransform(); +} + +void QFxFlipablePrivate::setBackTransform() +{ + if (!back) + return; + + QPointF p1(0, 0); + QPointF p2(1, 0); + QPointF p3(1, 1); + + axisRotation.setAngle(180); + p1 = axisRotation.transform().map(p1); + p2 = axisRotation.transform().map(p2); + p3 = axisRotation.transform().map(p3); + axisRotation.setAngle(rotation); + + QSimpleCanvas::Matrix mat; +#ifdef QFX_RENDER_OPENGL + mat.translate(back->width()/2,back->height()/2, 0); + if (back->width() && p1.x() >= p2.x()) + mat.rotate(180, 0, 1, 0); + if (back->height() && p2.y() >= p3.y()) + mat.rotate(180, 1, 0, 0); + mat.translate(-back->width()/2,-back->height()/2, 0); +#else + mat.translate(back->width()/2,back->height()/2); + if (back->width() && p1.x() >= p2.x()) + mat.rotate(180, Qt::YAxis); + if (back->height() && p2.y() >= p3.y()) + mat.rotate(180, Qt::XAxis); + mat.translate(-back->width()/2,-back->height()/2); +#endif + back->setTransform(mat); +} + +/*! + \qmlproperty real Flipable::rotation + The angle to rotate the flipable. For example, to show the back side of the flipable + you can set the rotation to 180. +*/ +qreal QFxFlipable::rotation() const +{ + Q_D(const QFxFlipable); + return d->rotation; +} + +void QFxFlipable::setRotation(qreal angle) +{ + Q_D(QFxFlipable); + d->rotation = angle; + d->axisRotation.setAngle(angle); + setTransform(d->axisRotation.transform()); + + + int simpleAngle = int(angle) % 360; + + Side newSide; + if (simpleAngle < 91 || simpleAngle > 270) { + newSide = Front; + } else { + newSide = Back; + } + + if (newSide != d->current) { + d->current = newSide; + if (d->front) + d->front->setOpacity((d->current==Front)?1.:0.); + if (d->back) + d->back->setOpacity((d->current==Back)?1.:0.); + emit sideChanged(); + } } /*! @@ -167,6 +281,9 @@ QFxFlipable::Side QFxFlipable::side() const return d->current; } +//in some cases the user may want to specify a more complex transformation. +//in that case, we still allow the generic use of transform. +//(the logic here should be kept in sync with setBackTransform and setRotation) void QFxFlipable::transformChanged(const QSimpleCanvas::Matrix &trans) { Q_D(QFxFlipable); @@ -218,3 +335,5 @@ void QFxFlipable::transformChanged(const QSimpleCanvas::Matrix &trans) } QT_END_NAMESPACE + +#include "moc_qfxflipable.cpp" diff --git a/src/declarative/fx/qfxflipable.h b/src/declarative/fx/qfxflipable.h index 2c6c849..ef1832e 100644 --- a/src/declarative/fx/qfxflipable.h +++ b/src/declarative/fx/qfxflipable.h @@ -55,6 +55,7 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) +class QFxAxis; class QFxFlipablePrivate; class Q_DECLARATIVE_EXPORT QFxFlipable : public QFxItem { @@ -63,6 +64,8 @@ class Q_DECLARATIVE_EXPORT QFxFlipable : public QFxItem Q_ENUMS(Side); Q_PROPERTY(QFxItem *front READ front WRITE setFront) Q_PROPERTY(QFxItem *back READ back WRITE setBack) + Q_PROPERTY(QFxAxis *axis READ axis WRITE setAxis) + Q_PROPERTY(qreal rotation READ rotation WRITE setRotation) Q_PROPERTY(Side side READ side NOTIFY sideChanged) public: QFxFlipable(QFxItem *parent=0); @@ -74,6 +77,12 @@ public: QFxItem *back(); void setBack(QFxItem *); + QFxAxis *axis(); + void setAxis(QFxAxis *axis); + + qreal rotation() const; + void setRotation(qreal angle); + enum Side { Front, Back }; Side side() const; @@ -84,6 +93,7 @@ Q_SIGNALS: void sideChanged(); private: + Q_PRIVATE_SLOT(d_func(), void _q_updateAxis()) Q_DISABLE_COPY(QFxFlipable) Q_DECLARE_PRIVATE(QFxFlipable) }; diff --git a/src/declarative/fx/qfxtransform.cpp b/src/declarative/fx/qfxtransform.cpp index 9f18413..c355158 100644 --- a/src/declarative/fx/qfxtransform.cpp +++ b/src/declarative/fx/qfxtransform.cpp @@ -85,7 +85,16 @@ void QFxTransform::update() /*! \qmlclass Axis - \brief An axis that can be used for rotation or translation. + \brief The Axis element defines an axis that can be used for rotation or translation. + + An axis is specified by 2 points in 3D space: a start point and + an end point. While technically the axis is the line running through these two points + (and thus many different sets of two points could define the same axis), the distance + between the points does matter for translation along an axis. + + \code + <Axis startX="0" startY="0" endX="20" endY="30"/> + \endcode */ QML_DEFINE_TYPE(QFxAxis, Axis); @@ -99,6 +108,13 @@ QFxAxis::~QFxAxis() { } +/*! + \qmlproperty real Axis::startX + \qmlproperty real Axis::startY + + The start point of the axis. The z-position of the start point is assumed to be 0, and cannot + be changed. +*/ qreal QFxAxis::startX() const { return _startX; @@ -121,6 +137,13 @@ void QFxAxis::setStartY(qreal y) emit updated(); } +/*! + \qmlproperty real Axis::endX + \qmlproperty real Axis::endY + \qmlproperty real Axis::endZ + + The end point of the axis. +*/ qreal QFxAxis::endX() const { return _endX; diff --git a/src/declarative/fx/qfxwebview.cpp b/src/declarative/fx/qfxwebview.cpp index a6210e5..b2ad06c 100644 --- a/src/declarative/fx/qfxwebview.cpp +++ b/src/declarative/fx/qfxwebview.cpp @@ -75,6 +75,73 @@ QML_DEFINE_TYPE(QFxWebView,WebView); static const int MAX_DOUBLECLICK_TIME=500; // XXX need better gesture system +class QFxWebSettings : public QObject { + Q_OBJECT + /* + StandardFont, + FixedFont, + SerifFont, + SansSerifFont, + CursiveFont, + FantasyFont + + MinimumFontSize, + MinimumLogicalFontSize, + DefaultFontSize, + DefaultFixedFontSize + */ + + Q_PROPERTY(bool autoLoadImages READ autoLoadImages WRITE setAutoLoadImages) + Q_PROPERTY(bool javascriptEnabled READ javascriptEnabled WRITE setJavascriptEnabled) + Q_PROPERTY(bool javaEnabled READ javaEnabled WRITE setJavaEnabled) + Q_PROPERTY(bool pluginsEnabled READ pluginsEnabled WRITE setPluginsEnabled) + Q_PROPERTY(bool privateBrowsingEnabled READ privateBrowsingEnabled WRITE setPrivateBrowsingEnabled) + Q_PROPERTY(bool javascriptCanOpenWindows READ javascriptCanOpenWindows WRITE setJavascriptCanOpenWindows) + Q_PROPERTY(bool javascriptCanAccessClipboard READ javascriptCanAccessClipboard WRITE setJavascriptCanAccessClipboard) + Q_PROPERTY(bool developerExtrasEnabled READ developerExtrasEnabled WRITE setDeveloperExtrasEnabled) + Q_PROPERTY(bool linksIncludedInFocusChain READ linksIncludedInFocusChain WRITE setLinksIncludedInFocusChain) + Q_PROPERTY(bool zoomTextOnly READ zoomTextOnly WRITE setZoomTextOnly) + Q_PROPERTY(bool printElementBackgrounds READ printElementBackgrounds WRITE setPrintElementBackgrounds) + Q_PROPERTY(bool offlineStorageDatabaseEnabled READ offlineStorageDatabaseEnabled WRITE setOfflineStorageDatabaseEnabled) + Q_PROPERTY(bool offlineWebApplicationCacheEnabled READ offlineWebApplicationCacheEnabled WRITE setOfflineWebApplicationCacheEnabled) + Q_PROPERTY(bool localStorageDatabaseEnabled READ localStorageDatabaseEnabled WRITE setLocalStorageDatabaseEnabled) + +public: + QFxWebSettings() {} + + bool autoLoadImages() const { return s->testAttribute(QWebSettings::AutoLoadImages); } + void setAutoLoadImages(bool on) { s->setAttribute(QWebSettings::AutoLoadImages, on); } + bool javascriptEnabled() const { return s->testAttribute(QWebSettings::JavascriptEnabled); } + void setJavascriptEnabled(bool on) { s->setAttribute(QWebSettings::JavascriptEnabled, on); } + bool javaEnabled() const { return s->testAttribute(QWebSettings::JavaEnabled); } + void setJavaEnabled(bool on) { s->setAttribute(QWebSettings::JavaEnabled, on); } + bool pluginsEnabled() const { return s->testAttribute(QWebSettings::PluginsEnabled); } + void setPluginsEnabled(bool on) { s->setAttribute(QWebSettings::PluginsEnabled, on); } + bool privateBrowsingEnabled() const { return s->testAttribute(QWebSettings::PrivateBrowsingEnabled); } + void setPrivateBrowsingEnabled(bool on) { s->setAttribute(QWebSettings::PrivateBrowsingEnabled, on); } + bool javascriptCanOpenWindows() const { return s->testAttribute(QWebSettings::JavascriptCanOpenWindows); } + void setJavascriptCanOpenWindows(bool on) { s->setAttribute(QWebSettings::JavascriptCanOpenWindows, on); } + bool javascriptCanAccessClipboard() const { return s->testAttribute(QWebSettings::JavascriptCanAccessClipboard); } + void setJavascriptCanAccessClipboard(bool on) { s->setAttribute(QWebSettings::JavascriptCanAccessClipboard, on); } + bool developerExtrasEnabled() const { return s->testAttribute(QWebSettings::DeveloperExtrasEnabled); } + void setDeveloperExtrasEnabled(bool on) { s->setAttribute(QWebSettings::DeveloperExtrasEnabled, on); } + bool linksIncludedInFocusChain() const { return s->testAttribute(QWebSettings::LinksIncludedInFocusChain); } + void setLinksIncludedInFocusChain(bool on) { s->setAttribute(QWebSettings::LinksIncludedInFocusChain, on); } + bool zoomTextOnly() const { return s->testAttribute(QWebSettings::ZoomTextOnly); } + void setZoomTextOnly(bool on) { s->setAttribute(QWebSettings::ZoomTextOnly, on); } + bool printElementBackgrounds() const { return s->testAttribute(QWebSettings::PrintElementBackgrounds); } + void setPrintElementBackgrounds(bool on) { s->setAttribute(QWebSettings::PrintElementBackgrounds, on); } + bool offlineStorageDatabaseEnabled() const { return s->testAttribute(QWebSettings::OfflineStorageDatabaseEnabled); } + void setOfflineStorageDatabaseEnabled(bool on) { s->setAttribute(QWebSettings::OfflineStorageDatabaseEnabled, on); } + bool offlineWebApplicationCacheEnabled() const { return s->testAttribute(QWebSettings::OfflineWebApplicationCacheEnabled); } + void setOfflineWebApplicationCacheEnabled(bool on) { s->setAttribute(QWebSettings::OfflineWebApplicationCacheEnabled, on); } + bool localStorageDatabaseEnabled() const { return s->testAttribute(QWebSettings::LocalStorageDatabaseEnabled); } + void setLocalStorageDatabaseEnabled(bool on) { s->setAttribute(QWebSettings::LocalStorageDatabaseEnabled, on); } + + QWebSettings *s; +}; + + class QFxWebViewPrivate : public QFxItemPrivate { Q_DECLARE_PUBLIC(QFxWebView) @@ -131,6 +198,7 @@ public: QUrl pending_url; QString pending_string; QByteArray pending_data; + mutable QFxWebSettings settings; }; @@ -866,9 +934,6 @@ QWebPage *QFxWebView::page() const wp->setNetworkAccessManager(qmlEngine(this)->networkAccessManager()); - // XXX settable from QML? - wp->settings()->setAttribute(QWebSettings::PluginsEnabled, true); - self->setPage(wp); return wp; @@ -877,6 +942,13 @@ QWebPage *QFxWebView::page() const return d->page; } +// The QObject interface to settings(). +QObject *QFxWebView::settingsObject() const +{ + Q_D(const QFxWebView); + d->settings.s = page()->settings(); + return &d->settings; +} void QFxWebView::setPage(QWebPage *page) { @@ -1031,7 +1103,10 @@ public: QmlEngine *engine = qmlEngine(webview); component = new QmlComponent(engine, url, this); item = 0; - connect(engine, SIGNAL(statusChanged(Status)), this, SLOT(qmlLoaded())); + if (component->isReady()) + qmlLoaded(); + else + connect(component, SIGNAL(statusChanged(QmlComponent::Status)), this, SLOT(qmlLoaded())); } public Q_SLOTS: diff --git a/src/declarative/fx/qfxwebview.h b/src/declarative/fx/qfxwebview.h index 1eede52..6ba4601 100644 --- a/src/declarative/fx/qfxwebview.h +++ b/src/declarative/fx/qfxwebview.h @@ -103,6 +103,8 @@ class Q_DECLARATIVE_EXPORT QFxWebView : public QFxItem Q_PROPERTY(QObject* forward READ forwardAction) Q_PROPERTY(QObject* stop READ stopAction) + Q_PROPERTY(QObject* settings READ settingsObject) + public: QFxWebView(QFxItem *parent=0); ~QFxWebView(); @@ -164,6 +166,7 @@ public: QWebHistory *history() const; QWebSettings *settings() const; + QObject *settingsObject() const; QString status() const; |