Commit 59e607a2 authored by Andrew den Exter's avatar Andrew den Exter Committed by Qt by Nokia

Add wrapMode and verticalAlignment properties to TextInput.

Wrap mode provides an alternative to horizontal scrolling when the width
of the text exceeds the width of the TextInput. With auto scroll
wrapping introdoces an implicit verticalAlignment so support setting it
explicitly as well.

Task-number: QTBUG-22305
Task-number: QTBUG-16203
Change-Id: I1bd3a5335edb3ac48df3d5ccd8ae7274caa91883
Reviewed-by: default avatarMartin Jones <martin.jones@nokia.com>
parent ac50bb1b
......@@ -127,6 +127,9 @@ Text improvements:
TextEdit:
- the default value of the textFormat property is now PlainText instead of AutoText.
TextInput has new wrapMode and verticalAlignment properties, and the positionAt function now takes
a y parameter.
PathView now has a \c currentItem property
ListView and GridView:
......
This diff is collapsed.
......@@ -44,6 +44,7 @@
#define QQUICKTEXTINPUT_P_H
#include "qquickimplicitsizeitem_p.h"
#include <QtGui/qtextoption.h>
#include <QtGui/qvalidator.h>
QT_BEGIN_HEADER
......@@ -56,8 +57,11 @@ class Q_AUTOTEST_EXPORT QQuickTextInput : public QQuickImplicitSizeItem
{
Q_OBJECT
Q_ENUMS(HAlignment)
Q_ENUMS(VAlignment)
Q_ENUMS(WrapMode)
Q_ENUMS(EchoMode)
Q_ENUMS(SelectionMode)
Q_ENUMS(CursorPosition)
Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
......@@ -66,6 +70,8 @@ class Q_AUTOTEST_EXPORT QQuickTextInput : public QQuickImplicitSizeItem
Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged)
Q_PROPERTY(HAlignment horizontalAlignment READ hAlign WRITE setHAlign RESET resetHAlign NOTIFY horizontalAlignmentChanged)
Q_PROPERTY(HAlignment effectiveHorizontalAlignment READ effectiveHAlign NOTIFY effectiveHorizontalAlignmentChanged)
Q_PROPERTY(VAlignment verticalAlignment READ vAlign WRITE setVAlign NOTIFY verticalAlignmentChanged)
Q_PROPERTY(WrapMode wrapMode READ wrapMode WRITE setWrapMode NOTIFY wrapModeChanged)
Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly NOTIFY readOnlyChanged)
Q_PROPERTY(bool cursorVisible READ isCursorVisible WRITE setCursorVisible NOTIFY cursorVisibleChanged)
......@@ -98,6 +104,8 @@ public:
QQuickTextInput(QQuickItem * parent=0);
~QQuickTextInput();
void componentComplete();
enum EchoMode {//To match QLineEdit::EchoMode
Normal,
NoEcho,
......@@ -111,6 +119,20 @@ public:
AlignHCenter = Qt::AlignHCenter
};
enum VAlignment {
AlignTop = Qt::AlignTop,
AlignBottom = Qt::AlignBottom,
AlignVCenter = Qt::AlignVCenter
};
enum WrapMode {
NoWrap = QTextOption::NoWrap,
WordWrap = QTextOption::WordWrap,
WrapAnywhere = QTextOption::WrapAnywhere,
WrapAtWordBoundaryOrAnywhere = QTextOption::WrapAtWordBoundaryOrAnywhere, // COMPAT
Wrap = QTextOption::WrapAtWordBoundaryOrAnywhere
};
enum SelectionMode {
SelectCharacters,
SelectWords
......@@ -121,9 +143,9 @@ public:
CursorOnCharacter
};
//Auxilliary functions needed to control the TextInput from QML
Q_INVOKABLE int positionAt(int x) const;
Q_INVOKABLE int positionAt(int x, CursorPosition position) const;
Q_INVOKABLE void positionAt(QDeclarativeV8Function *args) const;
Q_INVOKABLE QRectF positionToRectangle(int pos) const;
Q_INVOKABLE void moveCursorSelection(int pos);
Q_INVOKABLE void moveCursorSelection(int pos, SelectionMode mode);
......@@ -151,6 +173,12 @@ public:
void resetHAlign();
HAlignment effectiveHAlign() const;
VAlignment vAlign() const;
void setVAlign(VAlignment align);
WrapMode wrapMode() const;
void setWrapMode(WrapMode w);
bool isReadOnly() const;
void setReadOnly(bool);
......@@ -226,6 +254,8 @@ Q_SIGNALS:
void selectedTextColorChanged(const QColor &color);
void fontChanged(const QFont &font);
void horizontalAlignmentChanged(HAlignment alignment);
void verticalAlignmentChanged(VAlignment alignment);
void wrapModeChanged();
void readOnlyChanged(bool isReadOnly);
void cursorVisibleChanged(bool isCursorVisible);
void cursorDelegateChanged();
......@@ -273,8 +303,6 @@ public Q_SLOTS:
#endif
private Q_SLOTS:
void updateSize(bool needsRedraw = true);
void q_textChanged();
void selectionChanged();
void createCursor();
void updateCursorRectangle();
......
......@@ -81,7 +81,7 @@ public:
, textNode(0)
, m_maskData(0)
, hscroll(0)
, oldScroll(0)
, vscroll(0)
, m_cursor(0)
, m_preeditCursor(0)
, m_cursorWidth(1)
......@@ -97,6 +97,8 @@ public:
, m_selend(0)
, style(QQuickText::Normal)
, hAlign(QQuickTextInput::AlignLeft)
, vAlign(QQuickTextInput::AlignTop)
, wrapMode(QQuickTextInput::NoWrap)
, mouseSelectionMode(QQuickTextInput::SelectCharacters)
, inputMethodHints(Qt::ImhNone)
, m_layoutDirection(Qt::LayoutDirectionAuto)
......@@ -116,6 +118,7 @@ public:
, m_readOnly(0)
, m_echoMode(QQuickTextInput::Normal)
, m_textDirty(0)
, m_preeditDirty(0)
, m_selDirty(0)
, m_validInput(1)
, m_blinkStatus(0)
......@@ -130,6 +133,7 @@ public:
void init();
void startCreatingCursor();
void updateHorizontalScroll();
void updateVerticalScroll();
bool determineHorizontalAlignment();
bool setHAlign(QQuickTextInput::HAlignment, bool forceAlign = false);
void mirrorChange();
......@@ -186,13 +190,14 @@ public:
QPoint tripleClickStartPoint;
QList<int> m_transactions;
QVector<Command> m_history;
QRectF boundingRect;
int lastSelectionStart;
int lastSelectionEnd;
int oldHeight;
int oldWidth;
int hscroll;
int oldScroll;
int vscroll;
int m_cursor;
int m_preeditCursor;
int m_cursorWidth;
......@@ -209,6 +214,8 @@ public:
QQuickText::TextStyle style;
QQuickTextInput::HAlignment hAlign;
QQuickTextInput::VAlignment vAlign;
QQuickTextInput::WrapMode wrapMode;
QQuickTextInput::SelectionMode mouseSelectionMode;
Qt::InputMethodHints inputMethodHints;
Qt::LayoutDirection m_layoutDirection;
......@@ -232,6 +239,7 @@ public:
uint m_readOnly : 1;
uint m_echoMode : 2;
uint m_textDirty : 1;
uint m_preeditDirty : 1;
uint m_selDirty : 1;
uint m_validInput : 1;
uint m_blinkStatus : 1;
......@@ -269,10 +277,6 @@ public:
bool allSelected() const { return !m_text.isEmpty() && m_selstart == 0 && m_selend == (int)m_text.length(); }
bool hasSelectedText() const { return !m_text.isEmpty() && m_selend > m_selstart; }
int calculateTextHeight() const { return qRound(m_textLayout.lineAt(0).height()); }
int calculateTextWidth() const { return qRound(m_textLayout.lineAt(0).naturalTextWidth()); }
int ascent() const { return m_ascent; }
void setSelection(int start, int length);
inline QString selectedText() const { return hasSelectedText() ? m_text.mid(m_selstart, m_selend - m_selstart) : QString(); }
......@@ -281,12 +285,10 @@ public:
int selectionStart() const { return hasSelectedText() ? m_selstart : -1; }
int selectionEnd() const { return hasSelectedText() ? m_selend : -1; }
bool inSelection(int x) const
{
if (m_selstart >= m_selend)
return false;
int pos = xToPos(x, QTextLine::CursorOnCharacter);
return pos >= m_selstart && pos < m_selend;
int positionAt(int x, int y, QTextLine::CursorPosition position) const;
int positionAt(const QPointF &point, QTextLine::CursorPosition position = QTextLine::CursorBetweenCharacters) const {
return positionAt(point.x(), point.y(), position);
}
void removeSelection()
......@@ -333,17 +335,6 @@ public:
void home(bool mark) { moveCursor(0, mark); }
void end(bool mark) { moveCursor(q_func()->text().length(), mark); }
int xToPos(int x, QTextLine::CursorPosition = QTextLine::CursorBetweenCharacters) const;
qreal cursorToX(int cursor) const { return m_textLayout.lineAt(0).cursorToX(cursor); }
qreal cursorToX() const
{
int cursor = m_cursor;
if (m_preeditCursor != -1)
cursor += m_preeditCursor;
return cursorToX(cursor);
}
void backspace();
void del();
void deselect() { internalDeselect(); finishChange(); }
......@@ -398,6 +389,8 @@ public:
void setCursorBlinkPeriod(int msec);
void resetCursorBlinkTimer();
void updateLayout();
private:
void init(const QString &txt);
void removeSelectedText();
......@@ -425,7 +418,6 @@ private:
inline void separate() { m_separator = true; }
// masking
void parseInputMask(const QString &maskFields);
bool isValidInput(QChar key, QChar mask) const;
......
......@@ -10,10 +10,11 @@ Rectangle {
Rectangle {
anchors.centerIn: parent
width: 60
height: 20
height: 60
color: "green"
TextInput {
objectName: "text"
id: text
anchors.fill: parent
text: top.text
......
......@@ -4,5 +4,6 @@ TextInput{
focus: true
objectName: "myInput"
width: 50
height: 100
text: "AAAAAAAAAAAAAAAAAAAAAAAAAAAA"
}
......@@ -73,6 +73,8 @@ Rectangle {
font.pointSize: { pointvalue.model.get(pointvalue.currentIndex).value }
font.pixelSize: { pixelvalue.model.get(pixelvalue.currentIndex).value }
horizontalAlignment: { halignvalue.model.get(halignvalue.currentIndex).value }
verticalAlignment: { valignvalue.model.get(valignvalue.currentIndex).value }
wrapMode: { wrapvalue.model.get(wrapvalue.currentIndex).value }
smooth: { smoothvalue.model.get(smoothvalue.currentIndex).value }
selectByMouse: { mousevalue.model.get(mousevalue.currentIndex).value }
echoMode: { echovalue.model.get(echovalue.currentIndex).value }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment