diff options
-rw-r--r-- | demos/declarative/samegame/SameGame.qml | 6 | ||||
-rw-r--r-- | demos/declarative/samegame/TODO | 6 | ||||
-rw-r--r-- | demos/declarative/samegame/content/BoomBlock.qml | 7 | ||||
-rw-r--r-- | demos/declarative/samegame/content/FastBlock.qml | 4 | ||||
-rw-r--r-- | demos/declarative/samegame/content/SameDialog.qml | 4 | ||||
-rw-r--r-- | demos/declarative/samegame/content/samegame.js | 29 | ||||
-rw-r--r-- | examples/declarative/minehunt/Explosion.qml | 15 | ||||
-rw-r--r-- | examples/declarative/minehunt/minehunt.qml | 7 | ||||
-rw-r--r-- | src/declarative/fx/qfxlineedit.cpp | 164 | ||||
-rw-r--r-- | src/declarative/fx/qfxlineedit.h | 39 | ||||
-rw-r--r-- | src/declarative/fx/qfxlineedit_p.h | 3 | ||||
-rw-r--r-- | src/declarative/util/qmlfollow.cpp | 1 | ||||
-rw-r--r-- | src/gui/widgets/qlinecontrol.cpp | 5 |
13 files changed, 155 insertions, 135 deletions
diff --git a/demos/declarative/samegame/SameGame.qml b/demos/declarative/samegame/SameGame.qml index 23a83b8..fd3ca88 100644 --- a/demos/declarative/samegame/SameGame.qml +++ b/demos/declarative/samegame/SameGame.qml @@ -29,13 +29,13 @@ Rect { anchors.topMargin: 10 anchors.horizontalCenter: parent.horizontalCenter MediaButton { id: btnA; text: "New Game"; onClicked: {initBoard();} } - MediaButton { id: btnB; text: "Swap Theme"; onClicked: {swapTileSrc(); dialog.opacity = 1;} - } + MediaButton { id: btnB; text: "Swap Theme"; onClicked: {swapTileSrc(); dialog.opacity = 1; + dialog.text="Takes effect next game.";} } Text{ text: "Score: " + gameCanvas.score; width:100 } } SameDialog { id: dialog anchors.centeredIn: parent - text: "Takes effect next game." + text: "Hello World" } } diff --git a/demos/declarative/samegame/TODO b/demos/declarative/samegame/TODO index b02ce54..bbe881f 100644 --- a/demos/declarative/samegame/TODO +++ b/demos/declarative/samegame/TODO @@ -1,5 +1,3 @@ Still to do before initial release --Garbage collect on click --Particles with count 0->50 should work properly --Particles are too slow to start --Everything is too slow, we should have four times the number of tiles there +-Garbage collect after click +-Second *good* theme diff --git a/demos/declarative/samegame/content/BoomBlock.qml b/demos/declarative/samegame/content/BoomBlock.qml index b7838dd..542e7bc 100644 --- a/demos/declarative/samegame/content/BoomBlock.qml +++ b/demos/declarative/samegame/content/BoomBlock.qml @@ -1,14 +1,13 @@ Item { id:block property bool dying: false - property bool spawning: false + property bool spawned: false property int type: 0 property int targetX: 0 property int targetY: 0 - x: Follow { source: targetX; spring: 2; damping: 0.2 } + x: Follow { enabled: spawned; source: targetX; spring: 2; damping: 0.2 } y: Follow { source: targetY; spring: 2; damping: 0.2 } - Image { id: img source: { if(type == 0){ @@ -41,7 +40,7 @@ Item { id:block states: [ - State{ name: "AliveState"; when: spawning == true && dying == false + State{ name: "AliveState"; when: spawned == true && dying == false SetProperties { target: img; opacity: 1 } }, State{ name: "DeathState"; when: dying == true diff --git a/demos/declarative/samegame/content/FastBlock.qml b/demos/declarative/samegame/content/FastBlock.qml index 04eb59b..c3e8829 100644 --- a/demos/declarative/samegame/content/FastBlock.qml +++ b/demos/declarative/samegame/content/FastBlock.qml @@ -1,7 +1,7 @@ Rect { id:block //Note: These properties are the interface used to control the blocks property bool dying: false - property bool spawning: false + property bool spawned: false property int type: 0 property int targetY: 0 property int targetX: 0 @@ -17,7 +17,7 @@ Rect { id:block states: [ - State{ name: "SpawnState"; when: spawning == true && dying == false + State{ name: "AliveState"; when: spawned == true && dying == false SetProperties { target: block; opacity: 1 } }, State{ name: "DeathState"; when: dying == true diff --git a/demos/declarative/samegame/content/SameDialog.qml b/demos/declarative/samegame/content/SameDialog.qml index eed52f0..a0718f2 100644 --- a/demos/declarative/samegame/content/SameDialog.qml +++ b/demos/declarative/samegame/content/SameDialog.qml @@ -5,8 +5,8 @@ Rect { opacity: 0 opacity: Behavior { SequentialAnimation { - NumberAnimation {property: "opacity"; duration: 1000 } - NumberAnimation {property: "opacity"; to: 0; duration: 1000 } + NumberAnimation {property: "opacity"; duration: 1500 } + NumberAnimation {property: "opacity"; to: 0; duration: 1500 } } } color: "white" diff --git a/demos/declarative/samegame/content/samegame.js b/demos/declarative/samegame/content/samegame.js index fe5ac87..d2a3cbc 100644 --- a/demos/declarative/samegame/content/samegame.js +++ b/demos/declarative/samegame/content/samegame.js @@ -145,13 +145,35 @@ function shuffleDown() function victoryCheck() { - //Only awards bonuses at the moment + //awards bonuses deservesBonus = true; for(xIdx=maxX-1; xIdx>=0; xIdx--) if(board[index(xIdx, maxY - 1)] != null) deservesBonus = false; if(deservesBonus) - gameCanvas.score += 250; + gameCanvas.score += 500; + //Checks for game over + if(deservesBonus || noMoreMoves()){ + dialog.text = "Game Over. Your score is " + gameCanvas.score; + dialog.opacity = 1; + } +} + +function noMoreMoves() +{ + return !floodMoveCheck(0, maxY-1, -1); +} + +function floodMoveCheck(xIdx, yIdx, type) +{ + if(xIdx >= maxX || xIdx < 0 || yIdx >= maxY || yIdx < 0) + return false; + if(board[index(xIdx, yIdx)] == null) + return false; + myType = board[index(xIdx, yIdx)].type; + if(type == myType) + return true; + return floodMoveCheck(xIdx + 1, yIdx, myType) || floodMoveCheck(xIdx, yIdx - 1, myType); } //Need a simpler method of doing this? @@ -177,11 +199,12 @@ function finishCreatingBlock(xIdx,yIdx){ } dynamicObject.type = Math.floor(Math.random() * 3); dynamicObject.parent = gameCanvas; + dynamicObject.x = xIdx*tileSize; dynamicObject.targetX = xIdx*tileSize; dynamicObject.targetY = yIdx*tileSize; dynamicObject.width = tileSize; dynamicObject.height = tileSize; - dynamicObject.spawning = true; + dynamicObject.spawned = true; board[index(xIdx,yIdx)] = dynamicObject; return true; }else if(component.isError()){ diff --git a/examples/declarative/minehunt/Explosion.qml b/examples/declarative/minehunt/Explosion.qml index 2886559..84e93d4 100644 --- a/examples/declarative/minehunt/Explosion.qml +++ b/examples/declarative/minehunt/Explosion.qml @@ -2,17 +2,26 @@ Item { property bool explode : false Particles { + id: particles width: 38 height: 21 - lifeSpan: 3600000 + lifeSpan: 1000 lifeSpanDeviation: 0 source: "pics/star.png" - count: 200 + count: 0 angle: 270 angleDeviation: 360 velocity: 100 velocityDeviation: 20 z: 100 - emitting: explode + opacity: 0 + streamIn: false } + states: [ State { name: "exploding"; when: explode == true + SetProperties { target: particles; count: 200 } + SetProperties { target: particles; opacity: 1 } + SetProperties { target: particles; emitting: false } // i.e. emit only once + } + ] + } diff --git a/examples/declarative/minehunt/minehunt.qml b/examples/declarative/minehunt/minehunt.qml index 286e485..3dc1da4 100644 --- a/examples/declarative/minehunt/minehunt.qml +++ b/examples/declarative/minehunt/minehunt.qml @@ -55,9 +55,10 @@ Item { opacity: modelData.hasMine } Explosion { + id: expl anchors.horizontalCenter: parent.horizontalCenter anchors.verticalCenter: parent.verticalCenter - explode: modelData.hasMine && modelData.flipped + //explode: modelData.hasMine && modelData.flipped//Doesn't wait for the pause } } states: [ @@ -89,6 +90,10 @@ Item { easing: "easeInOutQuad" properties: "rotation" } + RunScriptAction{ + script: if(modelData.hasMine && modelData.flipped) + {expl.explode = true;} + } } } ] diff --git a/src/declarative/fx/qfxlineedit.cpp b/src/declarative/fx/qfxlineedit.cpp index da79979..bafd782 100644 --- a/src/declarative/fx/qfxlineedit.cpp +++ b/src/declarative/fx/qfxlineedit.cpp @@ -104,32 +104,6 @@ void QFxLineEdit::setColor(const QColor &c) d->color = c; } -/* -QFxText::TextStyle QFxLineEdit::style() const -{ - Q_D(const QFxLineEdit); - return d->style; -} - -void QFxLineEdit::setStyle(QFxText::TextStyle style) -{ - Q_D(QFxLineEdit); - d->style = style; -} - -QColor QFxLineEdit::styleColor() const -{ - Q_D(const QFxLineEdit); - return d->styleColor; -} - -void QFxLineEdit::setStyleColor(const QColor &c) -{ - Q_D(QFxLineEdit); - d->styleColor = c; -} -*/ - QFxText::HAlignment QFxLineEdit::hAlign() const { Q_D(const QFxLineEdit); @@ -142,19 +116,6 @@ void QFxLineEdit::setHAlign(QFxText::HAlignment align) d->hAlign = align; } -QFxText::VAlignment QFxLineEdit::vAlign() const -{ - Q_D(const QFxLineEdit); - return d->vAlign; -} - -void QFxLineEdit::setVAlign(QFxText::VAlignment align) -{ - Q_D(QFxLineEdit); - d->vAlign = align; -} - -//### Should this also toggle cursor visibility? bool QFxLineEdit::isReadOnly() const { Q_D(const QFxLineEdit); @@ -190,16 +151,60 @@ void QFxLineEdit::setCursorPosition(int cp) d->control->moveCursor(cp); } -int QFxLineEdit::selectionLength() const +/*! + \qmlproperty int LineEdit::selectionStart + + The cursor position before the first character in the current selection. + Setting this and selectionEnd allows you to specify a selection in the + text edit. + + Note that if selectionStart == selectionEnd then there is no current + selection. If you attempt to set selectionStart to a value outside of + the current text, selectionStart will not be changed. + + \sa selectionEnd, cursorPosition, selectedText +*/ +int QFxLineEdit::selectionStart() const +{ + Q_D(const QFxLineEdit); + return d->lastSelectionStart; +} + +void QFxLineEdit::setSelectionStart(int s) +{ + Q_D(QFxLineEdit); + if(d->lastSelectionStart == s || s < 0 || s > text().length()) + return; + d->lastSelectionStart = s; + d->control->setSelection(s, d->lastSelectionEnd - s); +} + +/*! + \qmlproperty int LineEdit::selectionEnd + + The cursor position after the last character in the current selection. + Setting this and selectionStart allows you to specify a selection in the + text edit. + + Note that if selectionStart == selectionEnd then there is no current + selection. If you attempt to set selectionEnd to a value outside of + the current text, selectionEnd will not be changed. + + \sa selectionStart, cursorPosition, selectedText +*/ +int QFxLineEdit::selectionEnd() const { Q_D(const QFxLineEdit); - return d->control->selectionEnd() - d->control->selectionStart(); + return d->lastSelectionEnd; } -void QFxLineEdit::setSelectionLength(int len) +void QFxLineEdit::setSelectionEnd(int s) { Q_D(QFxLineEdit); - d->control->setSelection(d->control->cursor(), len); + if(d->lastSelectionEnd == s || s < 0 || s > text().length()) + return; + d->lastSelectionEnd = s; + d->control->setSelection(d->lastSelectionStart, s - d->lastSelectionStart); } QString QFxLineEdit::selectedText() const @@ -404,41 +409,8 @@ void QFxLineEdit::drawContents(QPainter *p, const QRect &r) if (d->control->hasSelectedText()) flags |= QLineControl::DrawSelections; - //TODO: Clean up this cut'n'pasted section from QLineEdit - QRect lineRect(r); - - int cix = qRound(d->control->cursorToX()); - - // horizontal scrolling. d->hscroll is the left indent from the beginning - // of the text line to the left edge of lineRect. we update this value - // depending on the delta from the last paint event; in effect this means - // the below code handles all scrolling based on the textline (widthUsed, - // minLB, minRB), the line edit rect (lineRect) and the cursor position - // (cix). - QFontMetrics fm = QApplication::fontMetrics(); - int minLB = qMax(0, -fm.minLeftBearing()); - int minRB = qMax(0, -fm.minRightBearing()); - int widthUsed = d->control->width() + minRB; - if ((minLB + widthUsed) <= lineRect.width()) { - // text fits in lineRect; use hscroll for alignment - d->hscroll = 0; - d->hscroll -= minLB; - } else if (cix - d->hscroll >= lineRect.width()) { - // text doesn't fit, cursor is to the right of lineRect (scroll right) - d->hscroll = cix - lineRect.width() + 1; - } else if (cix - d->hscroll < 0 && d->hscroll < widthUsed) { - // text doesn't fit, cursor is to the left of lineRect (scroll left) - d->hscroll = cix; - } - // the y offset is there to keep the baseline constant in case we have script changes in the text. - QPoint topLeft = lineRect.topLeft() - QPoint(d->hscroll, d->control->ascent() - fm.ascent()); + d->control->draw(p, QPoint(0,0), r, flags); - if(d->hscroll != d->oldScroll) - moveCursor(); - - d->control->draw(p, topLeft, r, flags); - - d->oldScroll = d->hscroll; p->restore(); } @@ -448,13 +420,12 @@ void QFxLineEditPrivate::init() control->setCursorWidth(1); control->setPasswordCharacter(QLatin1Char('*')); control->setLayoutDirection(Qt::LeftToRight); - control->setSelection(0,0); q->setSmooth(true); q->setAcceptedMouseButtons(Qt::LeftButton); q->setOptions(QFxLineEdit::AcceptsInputMethods | QFxLineEdit::SimpleItem | QFxLineEdit::HasContents | QFxLineEdit::MouseEvents); q->connect(control, SIGNAL(cursorPositionChanged(int,int)), - q, SIGNAL(cursorPositionChanged())); + q, SLOT(cursorPosChanged())); q->connect(control, SIGNAL(selectionChanged()), q, SLOT(selectionChanged())); q->connect(control, SIGNAL(textChanged(const QString &)), @@ -472,16 +443,43 @@ void QFxLineEditPrivate::init() font = new QmlFont(); q->updateSize(); oldValidity = control->hasAcceptableInput(); - oldSelectLength = q->selectionLength(); + lastSelectionStart = 0; + lastSelectionEnd = 0; +} + +void QFxLineEdit::cursorPosChanged() +{ + Q_D(QFxLineEdit); + emit cursorPositionChanged(); + + if(!d->control->hasSelectedText()){ + if(d->lastSelectionStart != d->control->cursor()){ + d->lastSelectionStart = d->control->cursor(); + emit selectionStartChanged(); + } + if(d->lastSelectionEnd != d->control->cursor()){ + d->lastSelectionEnd = d->control->cursor(); + emit selectionEndChanged(); + } + } } void QFxLineEdit::selectionChanged() { Q_D(QFxLineEdit); emit selectedTextChanged(); - if(selectionLength() != d->oldSelectLength){ - d->oldSelectLength = selectionLength(); - emit selectionLengthChanged(); + + if(d->lastSelectionStart != d->control->selectionStart()){ + d->lastSelectionStart = d->control->selectionStart(); + if(d->lastSelectionStart == -1) + d->lastSelectionStart = d->control->cursor(); + emit selectionStartChanged(); + } + if(d->lastSelectionEnd != d->control->selectionEnd()){ + d->lastSelectionEnd = d->control->selectionEnd(); + if(d->lastSelectionEnd == -1) + d->lastSelectionEnd = d->control->cursor(); + emit selectionEndChanged(); } } diff --git a/src/declarative/fx/qfxlineedit.h b/src/declarative/fx/qfxlineedit.h index e053c54..2c22d4b 100644 --- a/src/declarative/fx/qfxlineedit.h +++ b/src/declarative/fx/qfxlineedit.h @@ -62,17 +62,13 @@ class Q_DECLARATIVE_EXPORT QFxLineEdit : public QFxPaintedItem Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged) Q_PROPERTY(QmlFont *font READ font) Q_PROPERTY(QColor color READ color WRITE setColor) - /* - Q_PROPERTY(QFxText::TextStyle style READ style WRITE setStyle) - Q_PROPERTY(QColor styleColor READ styleColor WRITE setStyleColor) Q_PROPERTY(QFxText::HAlignment hAlign READ hAlign WRITE setHAlign) - Q_PROPERTY(QFxText::VAlignment vAlign READ vAlign WRITE setVAlign) - */ Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly); Q_PROPERTY(int maxLength READ maxLength WRITE setMaxLength); Q_PROPERTY(int cursorPosition READ cursorPosition WRITE setCursorPosition NOTIFY cursorPositionChanged); - Q_PROPERTY(int selectionLength READ selectionLength WRITE setSelectionLength NOTIFY selectionLengthChanged); + Q_PROPERTY(int selectionStart READ selectionStart WRITE setSelectionStart NOTIFY selectionStartChanged) + Q_PROPERTY(int selectionEnd READ selectionEnd WRITE setSelectionEnd NOTIFY selectionEndChanged) Q_PROPERTY(QString selectedText READ selectedText NOTIFY selectedTextChanged); Q_PROPERTY(QObject* validator READ validator WRITE setValidator); @@ -81,10 +77,6 @@ class Q_DECLARATIVE_EXPORT QFxLineEdit : public QFxPaintedItem Q_PROPERTY(uint echoMode READ echoMode WRITE setEchoMode); Q_PROPERTY(QmlComponent *cursorDelegate READ cursorDelegate WRITE setCursorDelegate); - /* - Q_PROPERTY(int scrollDuration READ scrollDuration SET setScrollDuration NOTIFY scrollDurationChanged); - */ - public: QFxLineEdit(QFxItem* parent=0); ~QFxLineEdit(); @@ -100,20 +92,9 @@ public: //### Should we have this function or x variants of properties? Q_INVOKABLE int xToPos(int x); - /* - QFxText::TextStyle style() const; - void setStyle(QFxText::TextStyle style); - - QColor styleColor() const; - void setStyleColor(const QColor &c); - */ - QFxText::HAlignment hAlign() const; void setHAlign(QFxText::HAlignment align); - QFxText::VAlignment vAlign() const; - void setVAlign(QFxText::VAlignment align); - bool isReadOnly() const; void setReadOnly(bool); @@ -123,8 +104,11 @@ public: int cursorPosition() const; void setCursorPosition(int cp); - int selectionLength() const; - void setSelectionLength(int len); + int selectionStart() const; + void setSelectionStart(int); + + int selectionEnd() const; + void setSelectionEnd(int); QString selectedText() const; @@ -140,18 +124,14 @@ public: QmlComponent* cursorDelegate() const; void setCursorDelegate(QmlComponent*); - /* - int scrollDuration() const; - void setScrollDuration(int); - */ - bool hasAcceptableInput() const; void drawContents(QPainter *p,const QRect &r); Q_SIGNALS: void textChanged(); void cursorPositionChanged(); - void selectionLengthChanged(); + void selectionStartChanged(); + void selectionEndChanged(); void selectedTextChanged(); void accepted(); void acceptableInputChanged(); @@ -174,6 +154,7 @@ private slots: void updateAll(); void createCursor(); void moveCursor(); + void cursorPosChanged(); private: Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr, QFxLineEdit); diff --git a/src/declarative/fx/qfxlineedit_p.h b/src/declarative/fx/qfxlineedit_p.h index a0ab19c..a18dea7 100644 --- a/src/declarative/fx/qfxlineedit_p.h +++ b/src/declarative/fx/qfxlineedit_p.h @@ -89,7 +89,8 @@ public: QPointer<QmlComponent> cursorComponent; QPointer<QFxItem> cursorItem; - int oldSelectLength; + int lastSelectionStart; + int lastSelectionEnd; int oldHeight; int oldWidth; bool oldValidity; diff --git a/src/declarative/util/qmlfollow.cpp b/src/declarative/util/qmlfollow.cpp index b8e6685..1e4468c 100644 --- a/src/declarative/util/qmlfollow.cpp +++ b/src/declarative/util/qmlfollow.cpp @@ -188,6 +188,7 @@ void QmlFollowPrivate::start() property.write(currentValue); } else if (sourceValue != currentValue && clock.state() != QAbstractAnimation::Running) { lastTime = 0; + currentValue = property.read().toDouble(); clock.start(); // infinity?? } } diff --git a/src/gui/widgets/qlinecontrol.cpp b/src/gui/widgets/qlinecontrol.cpp index 97f4a45..eec890b 100644 --- a/src/gui/widgets/qlinecontrol.cpp +++ b/src/gui/widgets/qlinecontrol.cpp @@ -244,14 +244,19 @@ void QLineControl::setSelection(int start, int length) } if (length > 0) { + if (start == m_selstart && start + length == m_selend) + return; m_selstart = start; m_selend = qMin(start + length, (int)m_text.length()); m_cursor = m_selend; } else { + if (start == m_selend && start + length == m_selstart) + return; m_selstart = qMax(start + length, 0); m_selend = start; m_cursor = m_selstart; } + emit selectionChanged(); } void QLineControl::_q_clipboardChanged() |