summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/declarative/fx/qfxlineedit.cpp110
-rw-r--r--src/declarative/fx/qfxlineedit.h54
-rw-r--r--src/declarative/fx/qfxlineedit_p.h11
-rw-r--r--src/declarative/fx/qfxtextedit.cpp2
4 files changed, 127 insertions, 50 deletions
diff --git a/src/declarative/fx/qfxlineedit.cpp b/src/declarative/fx/qfxlineedit.cpp
index 760344d..f92a6fe 100644
--- a/src/declarative/fx/qfxlineedit.cpp
+++ b/src/declarative/fx/qfxlineedit.cpp
@@ -140,13 +140,66 @@ void QFxLineEdit::setColor(const QColor &c)
d->color = c;
}
-QFxText::HAlignment QFxLineEdit::hAlign() const
+
+/*!
+ \qmlproperty color LineEdit::highlightColor
+
+ The text highlight color, used behind selections.
+*/
+
+/*!
+ \property QFxLineEdit::highlightColor
+ \brief the line edit's default text highlight color
+*/
+QColor QFxLineEdit::highlightColor() const
+{
+ Q_D(const QFxLineEdit);
+ return d->highlightColor;
+}
+
+void QFxLineEdit::setHighlightColor(const QColor &color)
+{
+ Q_D(QFxLineEdit);
+ if (d->highlightColor == color)
+ return;
+
+ d->highlightColor = color;
+ //TODO: implement
+}
+
+/*!
+ \qmlproperty color LineEdit::highlightedTextColor
+
+ The highlighted text color, used in selections.
+*/
+
+/*!
+ \property QFxLineEdit::highlightedTextColor
+ \brief the line edit's default highlighted text color
+*/
+QColor QFxLineEdit::highlightedTextColor() const
+{
+ Q_D(const QFxLineEdit);
+ return d->highlightedTextColor;
+}
+
+void QFxLineEdit::setHighlightedTextColor(const QColor &color)
+{
+ Q_D(QFxLineEdit);
+ if (d->highlightedTextColor == color)
+ return;
+
+ d->highlightedTextColor = color;
+ //TODO: implement
+}
+
+QFxLineEdit::HAlignment QFxLineEdit::hAlign() const
{
Q_D(const QFxLineEdit);
return d->hAlign;
}
-void QFxLineEdit::setHAlign(QFxText::HAlignment align)
+void QFxLineEdit::setHAlign(HAlignment align)
{
Q_D(QFxLineEdit);
d->hAlign = align;
@@ -177,6 +230,29 @@ void QFxLineEdit::setMaxLength(int ml)
}
/*!
+ \qmlproperty LineEdit::cursorVisible
+ \brief If true the text edit shows a cursor.
+
+ This property is set and unset when the line edit gets focus, but it can also
+ be set directly (useful, for example, if a KeyProxy might forward keys to it).
+*/
+bool QFxLineEdit::isCursorVisible() const
+{
+ Q_D(const QFxLineEdit);
+ return d->cursorVisible;
+}
+
+void QFxLineEdit::setCursorVisible(bool on)
+{
+ Q_D(QFxLineEdit);
+ if (d->cursorVisible == on)
+ return;
+ d->cursorVisible = on;
+ d->control->setCursorBlinkPeriod(on?QApplication::cursorFlashTime():0);
+ updateAll();//TODO: Only update cursor rect
+}
+
+/*!
\qmlproperty LineEdit::cursorPosition
\brief The position of the cursor in the LineEdit.
*/
@@ -380,20 +456,6 @@ void QFxLineEdit::moveCursor()
d->cursorItem->setX(d->control->cursorToX() - d->hscroll);
}
-/*
-int QFxLineEdit::scrollDuration() const
-{
- Q_D(const QFxLineEdit);
- return d->scrollDur;
-}
-
-void QFxLineEdit::setScrollDuration(int s)
-{
- Q_D(QFxLineEdit);
- d->scrollDur = s;
- //Need to update cur anims as well
-}
-*/
int QFxLineEdit::xToPos(int x)
{
Q_D(const QFxLineEdit);
@@ -403,14 +465,8 @@ int QFxLineEdit::xToPos(int x)
void QFxLineEdit::focusChanged(bool hasFocus)
{
Q_D(QFxLineEdit);
- if(d->focused && !hasFocus){
- d->focused = false;
- d->control->setCursorBlinkPeriod(0);
- updateAll();//Only need the cursor rect
- }else{
- d->focused = hasFocus;
- updateAll();//Only need the cursor rect
- }
+ d->focused = hasFocus;
+ setCursorVisible(hasFocus);
}
void QFxLineEdit::keyPressEvent(QKeyEvent* ev)
@@ -422,8 +478,8 @@ void QFxLineEdit::keyPressEvent(QKeyEvent* ev)
void QFxLineEdit::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
Q_D(QFxLineEdit);
- setFocus(true);
- d->control->setCursorBlinkPeriod(QApplication::cursorFlashTime());
+ setFocus(true);//###Should we make 'focusOnPress' be optional like TextEdit?
+ setCursorVisible(true);
d->focused = true;
d->control->processEvent(event);
//event->accept();
@@ -457,7 +513,7 @@ void QFxLineEdit::drawContents(QPainter *p, const QRect &r)
p->save();
p->setPen(QPen(d->color));
int flags = QLineControl::DrawText;
- if(!isReadOnly() && d->focused && !d->cursorItem)
+ if(!isReadOnly() && d->cursorVisible && !d->cursorItem)
flags |= QLineControl::DrawCursor;
if (d->control->hasSelectedText())
flags |= QLineControl::DrawSelections;
diff --git a/src/declarative/fx/qfxlineedit.h b/src/declarative/fx/qfxlineedit.h
index 846ef52..f78dbfc 100644
--- a/src/declarative/fx/qfxlineedit.h
+++ b/src/declarative/fx/qfxlineedit.h
@@ -58,29 +58,43 @@ class QValidator;
class Q_DECLARATIVE_EXPORT QFxLineEdit : public QFxPaintedItem
{
Q_OBJECT
+ Q_ENUMS(HAlignment)
Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
- Q_PROPERTY(QmlFont *font READ font CONSTANT)
Q_PROPERTY(QColor color READ color WRITE setColor)
- Q_PROPERTY(QFxText::HAlignment hAlign READ hAlign WRITE setHAlign)
+ Q_PROPERTY(QColor highlightColor READ highlightColor WRITE setHighlightColor)
+ Q_PROPERTY(QColor highlightedTextColor READ highlightedTextColor WRITE setHighlightedTextColor)
+ Q_PROPERTY(QmlFont *font READ font CONSTANT)
+ Q_PROPERTY(HAlignment hAlign READ hAlign WRITE setHAlign)
- 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(bool readOnly READ isReadOnly WRITE setReadOnly)
+ Q_PROPERTY(bool cursorVisible READ isCursorVisible WRITE setCursorVisible)
+ Q_PROPERTY(int cursorPosition READ cursorPosition WRITE setCursorPosition NOTIFY cursorPositionChanged)
+ Q_PROPERTY(QmlComponent *cursorDelegate READ cursorDelegate WRITE setCursorDelegate)
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(QString selectedText READ selectedText NOTIFY selectedTextChanged)
- Q_PROPERTY(QObject* 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);
+ Q_PROPERTY(int maxLength READ maxLength WRITE setMaxLength)
+ Q_PROPERTY(QObject* 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)
- Q_PROPERTY(QmlComponent *cursorDelegate READ cursorDelegate WRITE setCursorDelegate);
public:
QFxLineEdit(QFxItem* parent=0);
~QFxLineEdit();
+ enum HAlignment {
+ AlignLeft = Qt::AlignLeft,
+ AlignRight = Qt::AlignRight,
+ AlignHCenter = Qt::AlignHCenter
+ };
+
+ //### Should we have this function, x based properties,
+ //### or copy TextEdit with x instead of QTextCursor?
+ Q_INVOKABLE int xToPos(int x);
+
QString text() const;
void setText(const QString &);
@@ -89,17 +103,20 @@ public:
QColor color() const;
void setColor(const QColor &c);
- //### Should we have this function or x variants of properties?
- Q_INVOKABLE int xToPos(int x);
+ QColor highlightColor() const;
+ void setHighlightColor(const QColor &c);
- QFxText::HAlignment hAlign() const;
- void setHAlign(QFxText::HAlignment align);
+ QColor highlightedTextColor() const;
+ void setHighlightedTextColor(const QColor &c);
+
+ HAlignment hAlign() const;
+ void setHAlign(HAlignment align);
bool isReadOnly() const;
void setReadOnly(bool);
- int maxLength() const;
- void setMaxLength(int ml);
+ bool isCursorVisible() const;
+ void setCursorVisible(bool on);
int cursorPosition() const;
void setCursorPosition(int cp);
@@ -112,6 +129,9 @@ public:
QString selectedText() const;
+ int maxLength() const;
+ void setMaxLength(int ml);
+
QObject * validator() const;
void setValidator(QObject* v);
diff --git a/src/declarative/fx/qfxlineedit_p.h b/src/declarative/fx/qfxlineedit_p.h
index a18dea7..a087a32 100644
--- a/src/declarative/fx/qfxlineedit_p.h
+++ b/src/declarative/fx/qfxlineedit_p.h
@@ -65,9 +65,8 @@ class QFxLineEditPrivate : public QFxPaintedItemPrivate
public:
QFxLineEditPrivate() : control(new QLineControl(QString())),
font(0), color((QRgb)0), style(QFxText::Normal),
- styleColor((QRgb)0),
- hAlign(QFxText::AlignLeft), vAlign(QFxText::AlignTop),
- hscroll(0), oldScroll(0), focused(false)
+ styleColor((QRgb)0), hAlign(QFxLineEdit::AlignLeft),
+ hscroll(0), oldScroll(0), focused(false), cursorVisible(false)
{
}
@@ -82,10 +81,11 @@ public:
QmlFont *font;
QColor color;
+ QColor highlightColor;
+ QColor highlightedTextColor;
QFxText::TextStyle style;
QColor styleColor;
- QFxText::HAlignment hAlign;
- QFxText::VAlignment vAlign;
+ QFxLineEdit::HAlignment hAlign;
QPointer<QmlComponent> cursorComponent;
QPointer<QFxItem> cursorItem;
@@ -97,6 +97,7 @@ public:
int hscroll;
int oldScroll;
bool focused;
+ bool cursorVisible;
};
QT_END_NAMESPACE
diff --git a/src/declarative/fx/qfxtextedit.cpp b/src/declarative/fx/qfxtextedit.cpp
index dbaba79..509b3da 100644
--- a/src/declarative/fx/qfxtextedit.cpp
+++ b/src/declarative/fx/qfxtextedit.cpp
@@ -329,7 +329,7 @@ void QFxTextEdit::setHighlightColor(const QColor &color)
QColor QFxTextEdit::highlightedTextColor() const
{
Q_D(const QFxTextEdit);
- return d->highlightColor;
+ return d->highlightedTextColor;
}
void QFxTextEdit::setHighlightedTextColor(const QColor &color)