diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-05-08 03:05:20 (GMT) |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-05-08 03:05:20 (GMT) |
commit | 674f6502671e969264bb7450a507ca04ab149b6a (patch) | |
tree | ae9a25517cdb7c000993128501d83d2f1655946a | |
parent | e4fb4f78ae18e3b5a538ce47b43136b4c666674e (diff) | |
parent | 6597cb980c484c11554314d8db63c6dd4edcd887 (diff) | |
download | Qt-674f6502671e969264bb7450a507ca04ab149b6a.zip Qt-674f6502671e969264bb7450a507ca04ab149b6a.tar.gz Qt-674f6502671e969264bb7450a507ca04ab149b6a.tar.bz2 |
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
-rw-r--r-- | demos/declarative/flickr/content/MediaLineEdit.qml | 108 | ||||
-rw-r--r-- | demos/declarative/flickr/content/pics/button-pressed.sci | 5 | ||||
-rw-r--r-- | demos/declarative/flickr/content/pics/button.sci | 5 | ||||
-rw-r--r-- | demos/declarative/flickr/flickr.qml | 18 | ||||
-rw-r--r-- | src/declarative/fx/qfxtextedit.cpp | 42 | ||||
-rw-r--r-- | src/declarative/fx/qfxtextedit.h | 8 | ||||
-rw-r--r-- | src/declarative/fx/qfxtextedit_p.h | 3 |
7 files changed, 177 insertions, 12 deletions
diff --git a/demos/declarative/flickr/content/MediaLineEdit.qml b/demos/declarative/flickr/content/MediaLineEdit.qml new file mode 100644 index 0000000..37caf24 --- /dev/null +++ b/demos/declarative/flickr/content/MediaLineEdit.qml @@ -0,0 +1,108 @@ +Item { + id: Container + + property string label + property string text + + width: Math.max(94,Label.width + Editor.width + 20) + height: Image.height + + states: [ + State { + name: "Edit" + SetProperties { + target: Label + text: Container.label + ": " + } + SetProperty { + target: Label + property: "x" + binding: 10 + } + SetProperties { + target: Editor + cursorVisible: true + width: 100 + } + SetProperties { + target: Proxy + focus: true + } + RunScript { + script:"Editor.selectAll()" + } + }, + State { + // When returning to default state, typed text is propagated + RunScript { + script: "Container.text = Editor.text" + } + } + ] + transitions: [ + Transition { + NumericAnimation { properties: "x,width"; duration: 500; easing: "easeInOutQuad" } + } + ] + + + Image { + id: Image + source: "pics/button.sci" + anchors.left: Container.left + anchors.right: Container.right + } + + Image { + id: Pressed + source: "pics/button-pressed.sci" + opacity: 0 + anchors.left: Container.left + anchors.right: Container.right + } + + MouseRegion { + id: MouseRegion + anchors.fill: Image + onClicked: { Container.state = Container.state=="Edit" ? "" : "Edit" } + states: [ + State { + when: MouseRegion.pressed == true + SetProperties { + target: Pressed + opacity: 1 + } + } + ] + } + + Text { + id: Label + font.bold: true + color: "white" + anchors.verticalCenter: Container.verticalCenter + x: (Container.width - width)/2 + text: Container.label + "..." + } + + TextEdit { + id: Editor + font.bold: true + color: "white" + width: 0 + clip: true + anchors.left: Label.right + anchors.verticalCenter: Container.verticalCenter + } + KeyProxy { + id: Proxy + anchors.left: Container.left + anchors.fill: Container + focusable: true + targets: [(ReturnKey), (Editor)] + } + KeyActions { + id: ReturnKey + return: "Container.state = ''" + } +} diff --git a/demos/declarative/flickr/content/pics/button-pressed.sci b/demos/declarative/flickr/content/pics/button-pressed.sci new file mode 100644 index 0000000..d3b16e2 --- /dev/null +++ b/demos/declarative/flickr/content/pics/button-pressed.sci @@ -0,0 +1,5 @@ +gridLeft: 8 +gridTop: 4 +gridBottom: 4 +gridRight: 8 +imageFile: button.png diff --git a/demos/declarative/flickr/content/pics/button.sci b/demos/declarative/flickr/content/pics/button.sci new file mode 100644 index 0000000..d3b16e2 --- /dev/null +++ b/demos/declarative/flickr/content/pics/button.sci @@ -0,0 +1,5 @@ +gridLeft: 8 +gridTop: 4 +gridBottom: 4 +gridRight: 8 +imageFile: button.png diff --git a/demos/declarative/flickr/flickr.qml b/demos/declarative/flickr/flickr.qml index dc150cb..092aef6 100644 --- a/demos/declarative/flickr/flickr.qml +++ b/demos/declarative/flickr/flickr.qml @@ -8,7 +8,7 @@ Item { resources: [ XmlListModel { id: FeedModel - property string tags : "" + property string tags : TagsEdit.text source: "http://api.flickr.com/services/feeds/photos_public.gne?"+(tags ? "tags="+tags+"&" : "")+"format=rss2" query: "doc($src)/rss/channel/item" namespaceDeclarations: "declare namespace media=\"http://search.yahoo.com/mrss/\";" @@ -90,7 +90,8 @@ Item { SetProperties { target: ImageDetails; y: 20 } SetProperties { target: PhotoGridView; y: "-480" } SetProperties { target: PhotoPathView; y: "-480" } - SetProperties { target: CloseButton; opacity: 0 } + SetProperties { target: ViewModeButton; opacity: 0 } + SetProperties { target: TagsEdit; opacity: 0 } SetProperties { target: FetchButton; opacity: 0 } SetProperties { target: CategoryText; y: "-50" } } @@ -160,18 +161,25 @@ Item { ImageDetails { id: ImageDetails; width: 750; x: 25; y: 500; height: 410 } MediaButton { - id: CloseButton; x: 680; y: 410; text: "View Mode" + id: ViewModeButton; x: 680; y: 410; text: "View Mode" onClicked: { if (MainWindow.showPathView == true) MainWindow.showPathView = false; else MainWindow.showPathView = true } } MediaButton { id: FetchButton text: "Update" - anchors.right: CloseButton.left; anchors.rightMargin: 5 - anchors.top: CloseButton.top + anchors.right: ViewModeButton.left; anchors.rightMargin: 5 + anchors.top: ViewModeButton.top onClicked: { FeedModel.reload(); } } + MediaLineEdit { + id: TagsEdit; + label: "Tags" + anchors.right: FetchButton.left; anchors.rightMargin: 5 + anchors.top: ViewModeButton.top + } + states: [ State { name: "PathView" diff --git a/src/declarative/fx/qfxtextedit.cpp b/src/declarative/fx/qfxtextedit.cpp index bf7a16d..3bc9696 100644 --- a/src/declarative/fx/qfxtextedit.cpp +++ b/src/declarative/fx/qfxtextedit.cpp @@ -377,6 +377,28 @@ void QFxTextEdit::setWrap(bool w) updateSize(); } +/*! + \property QFxTextEdit::cursorVisible + \brief If true the text edit shows a cursor. + + This property is set and unset when the text edit gets focus, but it can also + be set directly (useful, for example, if a KeyProxy might forward keys to it). +*/ +bool QFxTextEdit::isCursorVisible() const +{ + Q_D(const QFxTextEdit); + return d->cursorVisible; +} + +void QFxTextEdit::setCursorVisible(bool on) +{ + Q_D(QFxTextEdit); + if (d->cursorVisible == on) + return; + d->cursorVisible = on; + QFocusEvent focusEvent(on ? QEvent::FocusIn : QEvent::FocusOut); + d->control->processEvent(&focusEvent, QPointF(0, 0)); +} void QFxTextEdit::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) @@ -591,8 +613,15 @@ void QFxTextEdit::keyReleaseEvent(QKeyEvent *event) void QFxTextEdit::focusChanged(bool hasFocus) { Q_D(QFxTextEdit); - QFocusEvent focusEvent(hasFocus ? QEvent::FocusIn : QEvent::FocusOut); - d->control->processEvent(&focusEvent, QPointF(0, 0)); +} + +/*! + Causes all text to be selected. +*/ +void QFxTextEdit::selectAll() +{ + Q_D(QFxTextEdit); + d->control->selectAll(); } static QMouseEvent *sceneMouseEventToMouseEvent(QGraphicsSceneMouseEvent *e) @@ -737,6 +766,7 @@ void QFxTextEditPrivate::init() document->setDocumentMargin(0); document->setUndoRedoEnabled(false); // flush undo buffer. document->setUndoRedoEnabled(true); + updateDefaultTextOption(); } void QFxTextEdit::q_textChanged() @@ -785,14 +815,13 @@ void QFxTextEdit::updateSize() void QFxTextEditPrivate::updateDefaultTextOption() { - QTextDocument *doc = control->document(); - - QTextOption opt = doc->defaultTextOption(); + QTextOption opt = document->defaultTextOption(); int oldAlignment = opt.alignment(); opt.setAlignment((Qt::Alignment)(int)(hAlign | vAlign)); QTextOption::WrapMode oldWrapMode = opt.wrapMode(); +qDebug() << "wrap mode is" << opt.wrapMode(); if (wrap) opt.setWrapMode(QTextOption::WordWrap); else @@ -800,7 +829,8 @@ void QFxTextEditPrivate::updateDefaultTextOption() if (oldWrapMode == opt.wrapMode() && oldAlignment == opt.alignment()) return; - doc->setDefaultTextOption(opt); +qDebug() << "wrap mode set to" << opt.wrapMode(); + document->setDefaultTextOption(opt); } QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxtextedit.h b/src/declarative/fx/qfxtextedit.h index e5e9421..068a25a 100644 --- a/src/declarative/fx/qfxtextedit.h +++ b/src/declarative/fx/qfxtextedit.h @@ -75,7 +75,9 @@ class Q_DECLARATIVE_EXPORT QFxTextEdit : public QFxPaintedItem Q_PROPERTY(bool wrap READ wrap WRITE setWrap) Q_PROPERTY(TextFormat textFormat READ textFormat WRITE setTextFormat) Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly) + Q_PROPERTY(bool cursorVisible READ isCursorVisible WRITE setCursorVisible) Q_CLASSINFO("DefaultProperty", "text") + public: QFxTextEdit(QFxItem *parent=0); @@ -118,6 +120,9 @@ public: bool wrap() const; void setWrap(bool w); + bool isCursorVisible() const; + void setCursorVisible(bool on); + virtual void dump(int depth); virtual QString propertyInfo() const; @@ -145,6 +150,9 @@ Q_SIGNALS: void textChanged(const QString &); void cursorPositionChanged(); +public Q_SLOTS: + void selectAll(); + private Q_SLOTS: void fontChanged(); void updateImgCache(const QRectF &rect); diff --git a/src/declarative/fx/qfxtextedit_p.h b/src/declarative/fx/qfxtextedit_p.h index b583dbe..f4591f5 100644 --- a/src/declarative/fx/qfxtextedit_p.h +++ b/src/declarative/fx/qfxtextedit_p.h @@ -68,7 +68,7 @@ class QFxTextEditPrivate : public QFxPaintedItemPrivate public: QFxTextEditPrivate() - : font(0), color("black"), imgDirty(true), hAlign(QFxTextEdit::AlignLeft), vAlign(QFxTextEdit::AlignTop), dirty(false), wrap(false), richText(false), format(QFxTextEdit::AutoText), document(0) + : font(0), color("black"), imgDirty(true), hAlign(QFxTextEdit::AlignLeft), vAlign(QFxTextEdit::AlignTop), dirty(false), wrap(false), richText(false), cursorVisible(false), format(QFxTextEdit::AutoText), document(0) { } @@ -93,6 +93,7 @@ public: bool dirty; bool wrap; bool richText; + bool cursorVisible; QFxTextEdit::TextFormat format; QTextDocument *document; QTextControl *control; |