src/declarative/util/qdeclarativestateoperations.cpp
changeset 33 3e2da88830cd
parent 30 5dc02b23752f
child 37 758a864f9613
equal deleted inserted replaced
30:5dc02b23752f 33:3e2da88830cd
   170     ParentChange can only preserve visual appearance if no complex transforms are involved.
   170     ParentChange can only preserve visual appearance if no complex transforms are involved.
   171     More specifically, it will not work if the transform property has been set for any
   171     More specifically, it will not work if the transform property has been set for any
   172     items involved in the reparenting (i.e. items in the common ancestor tree
   172     items involved in the reparenting (i.e. items in the common ancestor tree
   173     for the original and new parent).
   173     for the original and new parent).
   174 
   174 
       
   175     The example below displays a large red rectangle and a small blue rectangle, side by side. 
       
   176     When the \c blueRect is clicked, it changes to the "reparented" state: its parent is changed to \c redRect and it is 
       
   177     positioned at (10, 10) within the red rectangle, as specified in the ParentChange.
       
   178 
       
   179     \snippet doc/src/snippets/declarative/parentchange.qml 0
       
   180 
       
   181     \image parentchange.png
       
   182 
   175     You can specify at which point in a transition you want a ParentChange to occur by
   183     You can specify at which point in a transition you want a ParentChange to occur by
   176     using a ParentAnimation.
   184     using a ParentAnimation.
   177 */
   185 */
   178 
   186 
   179 
   187 
   581 
   589 
   582 /*!
   590 /*!
   583     \qmlclass StateChangeScript QDeclarativeStateChangeScript
   591     \qmlclass StateChangeScript QDeclarativeStateChangeScript
   584     \brief The StateChangeScript element allows you to run a script in a state.
   592     \brief The StateChangeScript element allows you to run a script in a state.
   585 
   593 
   586     StateChangeScripts are run when entering the state. You can use
   594     A StateChangeScript is run upon entering a state. You can optionally use
   587     ScriptAction to specify at which point in the transition
   595     ScriptAction to specify the point in the transition at which
   588     you want the StateChangeScript to be run.
   596     the StateChangeScript should to be run.
   589 
   597 
   590     \qml
   598     \qml
   591     State {
   599     State {
   592         name "state1"
   600         name "state1"
   593         StateChangeScript {
   601         StateChangeScript {
   685 
   693 
   686 /*!
   694 /*!
   687     \qmlclass AnchorChanges QDeclarativeAnchorChanges
   695     \qmlclass AnchorChanges QDeclarativeAnchorChanges
   688     \brief The AnchorChanges element allows you to change the anchors of an item in a state.
   696     \brief The AnchorChanges element allows you to change the anchors of an item in a state.
   689 
   697 
   690     In the following example we change the top and bottom anchors of an item:
   698     The AnchorChanges element is used to modify the anchors of an item in a \l State.
   691     \qml
   699 
   692     State {
   700     AnchorChanges cannot be used to modify the margins on an item. For this, use
   693         name: "reanchored"
   701     PropertyChanges intead.
   694         AnchorChanges {
   702 
   695             target: content;
   703     In the following example we change the top and bottom anchors of an item
   696             anchors.top: window.top;
   704     using AnchorChanges, and the top and bottom anchor margins using
   697             anchors.bottom: window.bottom
   705     PropertyChanges:
   698         }
   706 
   699         PropertyChanges {
   707     \snippet doc/src/snippets/declarative/anchorchanges.qml 0
   700             target: content;
   708 
   701             anchors.topMargin: 3
   709     \image anchorchanges.png
   702             anchors.bottomMargin: 3;
       
   703         }
       
   704     }
       
   705     \endqml
       
   706 
   710 
   707     AnchorChanges can be animated using AnchorAnimation.
   711     AnchorChanges can be animated using AnchorAnimation.
   708     \qml
   712     \qml
   709     //animate our anchor changes
   713     //animate our anchor changes
   710     Transition {
   714     Transition {
  1033     QDeclarativeProperty baselineProp;
  1037     QDeclarativeProperty baselineProp;
  1034 };
  1038 };
  1035 
  1039 
  1036 /*!
  1040 /*!
  1037     \qmlproperty Item AnchorChanges::target
  1041     \qmlproperty Item AnchorChanges::target
  1038     This property holds the Item whose anchors will change
  1042     This property holds the \l Item for which the anchor changes will be applied.
  1039 */
  1043 */
  1040 
  1044 
  1041 QDeclarativeAnchorChanges::QDeclarativeAnchorChanges(QObject *parent)
  1045 QDeclarativeAnchorChanges::QDeclarativeAnchorChanges(QObject *parent)
  1042  : QDeclarativeStateOperation(*(new QDeclarativeAnchorChangesPrivate), parent)
  1046  : QDeclarativeStateOperation(*(new QDeclarativeAnchorChangesPrivate), parent)
  1043 {
  1047 {
  1126 
  1130 
  1127     To reset an anchor you can assign \c undefined:
  1131     To reset an anchor you can assign \c undefined:
  1128     \qml
  1132     \qml
  1129     AnchorChanges {
  1133     AnchorChanges {
  1130         target: myItem
  1134         target: myItem
  1131         left: undefined          //remove myItem's left anchor
  1135         anchors.left: undefined          //remove myItem's left anchor
  1132         right: otherItem.right
  1136         anchors.right: otherItem.right
  1133     }
  1137     }
  1134     \endqml
  1138     \endqml
  1135 */
  1139 */
  1136 
  1140 
  1137 void QDeclarativeAnchorChanges::execute(Reason reason)
  1141 void QDeclarativeAnchorChanges::execute(Reason reason)
  1495     if (d->rewindBaseline.anchorLine != QDeclarativeAnchorLine::Invalid)
  1499     if (d->rewindBaseline.anchorLine != QDeclarativeAnchorLine::Invalid)
  1496         targetPrivate->anchors()->setBaseline(d->rewindBaseline);
  1500         targetPrivate->anchors()->setBaseline(d->rewindBaseline);
  1497 
  1501 
  1498     d->target->setX(d->rewindX);
  1502     d->target->setX(d->rewindX);
  1499     d->target->setY(d->rewindY);
  1503     d->target->setY(d->rewindY);
  1500     d->target->setWidth(d->rewindWidth);
  1504     if (targetPrivate->widthValid) {
  1501     d->target->setHeight(d->rewindHeight);
  1505         d->target->setWidth(d->rewindWidth);
       
  1506     }
       
  1507     if (targetPrivate->heightValid) {
       
  1508         d->target->setHeight(d->rewindHeight);
       
  1509     }
  1502 }
  1510 }
  1503 
  1511 
  1504 void QDeclarativeAnchorChanges::saveCurrentValues()
  1512 void QDeclarativeAnchorChanges::saveCurrentValues()
  1505 {
  1513 {
  1506     Q_D(QDeclarativeAnchorChanges);
  1514     Q_D(QDeclarativeAnchorChanges);