From c5369f7168a9e9309514aee9c39e9bfc6813694d Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Thu, 10 Sep 2009 10:59:22 +1000 Subject: API Changes Renaming stuff in TextEdit/Input --- src/declarative/QmlChanges.txt | 2 ++ src/declarative/fx/qfxtextedit.cpp | 26 +++++++-------- src/declarative/fx/qfxtextedit.h | 12 +++---- src/declarative/fx/qfxtextedit_p.h | 4 +-- src/declarative/fx/qfxtextinput.cpp | 63 ++++++++++++++++++++++++------------- src/declarative/fx/qfxtextinput.h | 30 ++++++++++++------ src/declarative/fx/qfxtextinput_p.h | 8 +++-- 7 files changed, 89 insertions(+), 56 deletions(-) diff --git a/src/declarative/QmlChanges.txt b/src/declarative/QmlChanges.txt index 87873f2..9c68d18 100644 --- a/src/declarative/QmlChanges.txt +++ b/src/declarative/QmlChanges.txt @@ -38,6 +38,8 @@ MouseRegion: ymin -> minimumY MouseRegion: ymin -> maximumY Text elements: hAlign -> horizontalAlignment Text elements: vAlign -> verticalAlignment +Text elements: highlightColor -> selectionColor +Text elements: highlightedTextColor -> selectedTextColor State: operations -> changes Transition: operations -> animations Transition: fromState -> from diff --git a/src/declarative/fx/qfxtextedit.cpp b/src/declarative/fx/qfxtextedit.cpp index c2c418e..72f12cc 100644 --- a/src/declarative/fx/qfxtextedit.cpp +++ b/src/declarative/fx/qfxtextedit.cpp @@ -271,24 +271,24 @@ void QFxTextEdit::setColor(const QColor &color) } /*! - \qmlproperty color TextEdit::highlightColor + \qmlproperty color TextEdit::selectionColor The text highlight color, used behind selections. */ -QColor QFxTextEdit::highlightColor() const +QColor QFxTextEdit::selectionColor() const { Q_D(const QFxTextEdit); - return d->highlightColor; + return d->selectionColor; } -void QFxTextEdit::setHighlightColor(const QColor &color) +void QFxTextEdit::setSelectionColor(const QColor &color) { Q_D(QFxTextEdit); - if (d->highlightColor == color) + if (d->selectionColor == color) return; clearCache(); - d->highlightColor = color; + d->selectionColor = color; QPalette pal = d->control->palette(); pal.setColor(QPalette::Highlight, color); d->control->setPalette(pal); @@ -296,24 +296,24 @@ void QFxTextEdit::setHighlightColor(const QColor &color) } /*! - \qmlproperty color TextEdit::highlightedTextColor + \qmlproperty color TextEdit::selectedTextColor - The highlighted text color, used in selections. + The selected text color, used in selections. */ -QColor QFxTextEdit::highlightedTextColor() const +QColor QFxTextEdit::selectedTextColor() const { Q_D(const QFxTextEdit); - return d->highlightedTextColor; + return d->selectedTextColor; } -void QFxTextEdit::setHighlightedTextColor(const QColor &color) +void QFxTextEdit::setSelectedTextColor(const QColor &color) { Q_D(QFxTextEdit); - if (d->highlightedTextColor == color) + if (d->selectedTextColor == color) return; clearCache(); - d->highlightedTextColor = color; + d->selectedTextColor = color; QPalette pal = d->control->palette(); pal.setColor(QPalette::HighlightedText, color); d->control->setPalette(pal); diff --git a/src/declarative/fx/qfxtextedit.h b/src/declarative/fx/qfxtextedit.h index 6a10e85..1a5d968 100644 --- a/src/declarative/fx/qfxtextedit.h +++ b/src/declarative/fx/qfxtextedit.h @@ -68,8 +68,8 @@ class Q_DECLARATIVE_EXPORT QFxTextEdit : public QFxPaintedItem Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged) Q_PROPERTY(QColor color READ color WRITE setColor) - Q_PROPERTY(QColor highlightColor READ highlightColor WRITE setHighlightColor) //### selectionColor - Q_PROPERTY(QColor highlightedTextColor READ highlightedTextColor WRITE setHighlightedTextColor) //### selectedTextColor + Q_PROPERTY(QColor selectionColor READ selectionColor WRITE setSelectionColor) + Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor) Q_PROPERTY(QFont font READ font WRITE setFont) Q_PROPERTY(HAlignment horizontalAlignment READ hAlign WRITE setHAlign) Q_PROPERTY(VAlignment verticalAlignment READ vAlign WRITE setVAlign) @@ -119,11 +119,11 @@ public: QColor color() const; void setColor(const QColor &c); - QColor highlightColor() const; - void setHighlightColor(const QColor &c); + QColor selectionColor() const; + void setSelectionColor(const QColor &c); - QColor highlightedTextColor() const; - void setHighlightedTextColor(const QColor &c); + QColor selectedTextColor() const; + void setSelectedTextColor(const QColor &c); HAlignment hAlign() const; void setHAlign(HAlignment align); diff --git a/src/declarative/fx/qfxtextedit_p.h b/src/declarative/fx/qfxtextedit_p.h index fb757de..9c73db9 100644 --- a/src/declarative/fx/qfxtextedit_p.h +++ b/src/declarative/fx/qfxtextedit_p.h @@ -84,8 +84,8 @@ public: QString text; QFont font; QColor color; - QColor highlightColor; - QColor highlightedTextColor; + QColor selectionColor; + QColor selectedTextColor; QString style; QColor styleColor; bool imgDirty; diff --git a/src/declarative/fx/qfxtextinput.cpp b/src/declarative/fx/qfxtextinput.cpp index 6bd793b..b6ec109 100644 --- a/src/declarative/fx/qfxtextinput.cpp +++ b/src/declarative/fx/qfxtextinput.cpp @@ -55,6 +55,12 @@ QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,QIntValidator,QIntValidator); /*! \qmlclass TextInput The TextInput item allows you to add an editable line of text to a scene. + + TextInput can only display a single line of text, and can only display + plain text. However it can provide addition input constraints on the text. + + Input constraints include setting a QValidator, an input mask, or a + maximum input length. */ QFxTextInput::QFxTextInput(QFxItem* parent) : QFxPaintedItem(*(new QFxTextInputPrivate), parent) @@ -148,44 +154,44 @@ void QFxTextInput::setColor(const QColor &c) /*! - \qmlproperty color TextInput::highlightColor + \qmlproperty color TextInput::selectionColor The text highlight color, used behind selections. */ -QColor QFxTextInput::highlightColor() const +QColor QFxTextInput::selectionColor() const { Q_D(const QFxTextInput); - return d->highlightColor; + return d->selectionColor; } -void QFxTextInput::setHighlightColor(const QColor &color) +void QFxTextInput::setSelectionColor(const QColor &color) { Q_D(QFxTextInput); - if (d->highlightColor == color) + if (d->selectionColor == color) return; - d->highlightColor = color; + d->selectionColor = color; //TODO: implement } /*! - \qmlproperty color TextInput::highlightedTextColor + \qmlproperty color TextInput::selectedTextColor The highlighted text color, used in selections. */ -QColor QFxTextInput::highlightedTextColor() const +QColor QFxTextInput::selectedTextColor() const { Q_D(const QFxTextInput); - return d->highlightedTextColor; + return d->selectedTextColor; } -void QFxTextInput::setHighlightedTextColor(const QColor &color) +void QFxTextInput::setSelectedTextColor(const QColor &color) { Q_D(QFxTextInput); - if (d->highlightedTextColor == color) + if (d->selectedTextColor == color) return; - d->highlightedTextColor = color; + d->selectedTextColor = color; //TODO: implement } @@ -340,6 +346,18 @@ QString QFxTextInput::selectedText() const return d->control->selectedText(); } +bool QFxTextInput::focusOnPress() const +{ + Q_D(const QFxTextInput); + return d->focusOnPress; +} + +void QFxTextInput::setFocusOnPress(bool b) +{ + Q_D(QFxTextInput); + d->focusOnPress = b; +} + QValidator* QFxTextInput::validator() const { Q_D(const QFxTextInput); @@ -375,16 +393,16 @@ bool QFxTextInput::hasAcceptableInput() const return d->control->hasAcceptableInput(); } -uint QFxTextInput::echoMode() const +QFxTextInput::EchoMode QFxTextInput::echoMode() const { Q_D(const QFxTextInput); - return d->control->echoMode(); + return (QFxTextInput::EchoMode)d->control->echoMode(); } -void QFxTextInput::setEchoMode(uint echo) +void QFxTextInput::setEchoMode(QFxTextInput::EchoMode echo) { Q_D(QFxTextInput); - d->control->setEchoMode(echo); + d->control->setEchoMode((uint)echo); } /*! @@ -431,7 +449,7 @@ void QFxTextInputPrivate::startCreatingCursor() q->connect(cursorComponent, SIGNAL(statusChanged(int)), q, SLOT(createCursor())); }else{//isError - qWarning() << "You could really use the error checking for QFxTextInput. We'll implement it soon."; + qWarning() << "You could really use the error checking for QFxTextInput. We'll implement it soon.";//TODO:better error handling } } @@ -446,7 +464,7 @@ void QFxTextInput::createCursor() delete d->cursorItem; d->cursorItem = qobject_cast(d->cursorComponent->create()); if(!d->cursorItem){ - qWarning() << "You could really use the error reporting for QFxTextInput. We'll implement it soon."; + qWarning() << "You could really use the error reporting for QFxTextInput. We'll implement it soon.";//TODO:better error handling return; } @@ -495,11 +513,12 @@ void QFxTextInput::keyPressEvent(QKeyEvent* ev) void QFxTextInput::mousePressEvent(QGraphicsSceneMouseEvent *event) { Q_D(QFxTextInput); - setFocus(true);//###Should we make 'focusOnPress' be optional like TextEdit? - setCursorVisible(true); - d->focused = true; + if(d->focusOnPress){ + setFocus(true); + setCursorVisible(true); + d->focused = true; + } d->control->processEvent(event); - //event->accept(); } bool QFxTextInput::event(QEvent* ev) diff --git a/src/declarative/fx/qfxtextinput.h b/src/declarative/fx/qfxtextinput.h index 1dca945..bc5bbf4 100644 --- a/src/declarative/fx/qfxtextinput.h +++ b/src/declarative/fx/qfxtextinput.h @@ -62,8 +62,8 @@ class Q_DECLARATIVE_EXPORT QFxTextInput : public QFxPaintedItem Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged) Q_PROPERTY(QColor color READ color WRITE setColor) - Q_PROPERTY(QColor highlightColor READ highlightColor WRITE setHighlightColor) //### selectionColor - Q_PROPERTY(QColor highlightedTextColor READ highlightedTextColor WRITE setHighlightedTextColor) //### selectedTextColor + Q_PROPERTY(QColor selectionColor READ selectionColor WRITE setSelectionColor) + Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor) Q_PROPERTY(QFont font READ font WRITE setFont) Q_PROPERTY(HAlignment horizontalAlignment READ hAlign WRITE setHAlign) @@ -79,13 +79,20 @@ class Q_DECLARATIVE_EXPORT QFxTextInput : public QFxPaintedItem Q_PROPERTY(QValidator* validator READ validator WRITE setValidator) Q_PROPERTY(QString inputMask READ inputMask WRITE setInputMask) Q_PROPERTY(bool acceptableInput READ hasAcceptableInput NOTIFY acceptableInputChanged) - Q_PROPERTY(uint echoMode READ echoMode WRITE setEchoMode) //### enum - //### Q_PROPERTY(bool focusOnPress READ focusOnPress WRITE setFocusOnPress) + Q_PROPERTY(EchoMode echoMode READ echoMode WRITE setEchoMode) + Q_PROPERTY(bool focusOnPress READ focusOnPress WRITE setFocusOnPress) public: QFxTextInput(QFxItem* parent=0); ~QFxTextInput(); + enum EchoMode {//To match QLineEdit::EchoMode + Normal, + NoEcho, + Password, + PasswordEchoOnEdit + }; + enum HAlignment { AlignLeft = Qt::AlignLeft, AlignRight = Qt::AlignRight, @@ -105,11 +112,11 @@ public: QColor color() const; void setColor(const QColor &c); - QColor highlightColor() const; - void setHighlightColor(const QColor &c); + QColor selectionColor() const; + void setSelectionColor(const QColor &c); - QColor highlightedTextColor() const; - void setHighlightedTextColor(const QColor &c); + QColor selectedTextColor() const; + void setSelectedTextColor(const QColor &c); HAlignment hAlign() const; void setHAlign(HAlignment align); @@ -140,12 +147,15 @@ public: QString inputMask() const; void setInputMask(const QString &im); - uint echoMode() const; - void setEchoMode(uint echo); + EchoMode echoMode() const; + void setEchoMode(EchoMode echo); QmlComponent* cursorDelegate() const; void setCursorDelegate(QmlComponent*); + bool focusOnPress() const; + void setFocusOnPress(bool); + bool hasAcceptableInput() const; void drawContents(QPainter *p,const QRect &r); diff --git a/src/declarative/fx/qfxtextinput_p.h b/src/declarative/fx/qfxtextinput_p.h index b533854..a2b45bb 100644 --- a/src/declarative/fx/qfxtextinput_p.h +++ b/src/declarative/fx/qfxtextinput_p.h @@ -66,7 +66,8 @@ public: QFxTextInputPrivate() : control(new QLineControl(QString())), color((QRgb)0), style(QFxText::Normal), styleColor((QRgb)0), hAlign(QFxTextInput::AlignLeft), - hscroll(0), oldScroll(0), focused(false), cursorVisible(false) + hscroll(0), oldScroll(0), focused(false), focusOnPress(true), + cursorVisible(false) { } @@ -82,8 +83,8 @@ public: QFont font; QColor color; - QColor highlightColor; - QColor highlightedTextColor; + QColor selectionColor; + QColor selectedTextColor; QFxText::TextStyle style; QColor styleColor; QFxTextInput::HAlignment hAlign; @@ -98,6 +99,7 @@ public: int hscroll; int oldScroll; bool focused; + bool focusOnPress; bool cursorVisible; }; -- cgit v0.12