Move QTextCursor::MoveStyle to Qt namespace

We cannot use QTextCursor::MoveStyle enums in QTextLine because
QTextCursor is not a QObject, while referring to that enum in
Q_PROPERTY requires it to be. That's why we need to move the
enums in Qt namespace.

Reviewed-by: David Boddie
(cherry picked from commit 5eba82b752e85a5d6cb3a893214ed2646d75f362)
This commit is contained in:
Jiang Jiang 2011-05-11 12:13:01 +02:00
parent 3032ba0f8e
commit 16628b76c0
17 changed files with 50 additions and 47 deletions

View File

@ -94,6 +94,7 @@ Qt {
Q_ENUMS(GestureState) Q_ENUMS(GestureState)
Q_ENUMS(GestureType) Q_ENUMS(GestureType)
#endif #endif
Q_ENUMS(CursorMoveStyle)
#endif // (defined(Q_MOC_RUN) || defined(QT_JAMBI_RUN)) #endif // (defined(Q_MOC_RUN) || defined(QT_JAMBI_RUN))
#if defined(Q_MOC_RUN) #if defined(Q_MOC_RUN)
@ -1784,6 +1785,11 @@ public:
NavigationModeCursorAuto, NavigationModeCursorAuto,
NavigationModeCursorForceVisible NavigationModeCursorForceVisible
}; };
enum CursorMoveStyle {
LogicalMoveStyle,
VisualMoveStyle
};
} }
#ifdef Q_MOC_RUN #ifdef Q_MOC_RUN
; ;

View File

@ -362,7 +362,7 @@ bool QTextCursorPrivate::movePosition(QTextCursor::MoveOperation op, QTextCursor
currentCharFormat = -1; currentCharFormat = -1;
bool adjustX = true; bool adjustX = true;
QTextBlock blockIt = block(); QTextBlock blockIt = block();
bool visualMovement = priv->defaultCursorMoveStyle == QTextCursor::Visual; bool visualMovement = priv->defaultCursorMoveStyle == Qt::VisualMoveStyle;
if (!blockIt.isValid()) if (!blockIt.isValid())
return false; return false;
@ -2568,18 +2568,18 @@ QTextDocument *QTextCursor::document() const
} }
/*! /*!
\enum QTextCursor::MoveStyle \enum Qt::CursorMoveStyle
This enum describes the movement style available to QTextCursor. The options This enum describes the movement style available to text cursors. The options
are: are:
\value Logical Within a left-to-right text block, increase cursor position \value LogicalMoveStyle Within a left-to-right text block, decrease cursor
when pressing left arrow key, decrease cursor position when pressing the position when pressing left arrow key, increase cursor position when pressing
right arrow key. If the text block is right-to-left, the opposite behavior the right arrow key. If the text block is right-to-left, the opposite behavior
applies. applies.
\value Visual Pressing the left arrow key will always cause the cursor to move \value VisualMoveStyle Pressing the left arrow key will always cause the cursor
left, regardless of the text's writing direction. The same behavior applies to to move left, regardless of the text's writing direction. Pressing the right
right arrow key. arrow key will always cause the cursor to move right.
*/ */
QT_END_NAMESPACE QT_END_NAMESPACE

View File

@ -86,10 +86,6 @@ public:
MoveAnchor, MoveAnchor,
KeepAnchor KeepAnchor
}; };
enum MoveStyle {
Logical,
Visual
};
void setPosition(int pos, MoveMode mode = MoveAnchor); void setPosition(int pos, MoveMode mode = MoveAnchor);
int position() const; int position() const;

View File

@ -589,9 +589,9 @@ void QTextDocument::setDefaultTextOption(const QTextOption &option)
\since 4.8 \since 4.8
The default cursor movement style is used by all QTextCursor objects The default cursor movement style is used by all QTextCursor objects
created from the document. The default is QTextCursor::Logical. created from the document. The default is Qt::LogicalMoveStyle.
*/ */
QTextCursor::MoveStyle QTextDocument::defaultCursorMoveStyle() const Qt::CursorMoveStyle QTextDocument::defaultCursorMoveStyle() const
{ {
Q_D(const QTextDocument); Q_D(const QTextDocument);
return d->defaultCursorMoveStyle; return d->defaultCursorMoveStyle;
@ -602,7 +602,7 @@ QTextCursor::MoveStyle QTextDocument::defaultCursorMoveStyle() const
Set the default cursor movement style. Set the default cursor movement style.
*/ */
void QTextDocument::setDefaultCursorMoveStyle(QTextCursor::MoveStyle style) void QTextDocument::setDefaultCursorMoveStyle(Qt::CursorMoveStyle style)
{ {
Q_D(QTextDocument); Q_D(QTextDocument);
d->defaultCursorMoveStyle = style; d->defaultCursorMoveStyle = style;

View File

@ -46,7 +46,6 @@
#include <QtCore/qsize.h> #include <QtCore/qsize.h>
#include <QtCore/qrect.h> #include <QtCore/qrect.h>
#include <QtGui/qfont.h> #include <QtGui/qfont.h>
#include <QtGui/qtextcursor.h>
QT_BEGIN_HEADER QT_BEGIN_HEADER
@ -70,6 +69,7 @@ class QUrl;
class QVariant; class QVariant;
class QRectF; class QRectF;
class QTextOption; class QTextOption;
class QTextCursor;
template<typename T> class QVector; template<typename T> class QVector;
@ -269,8 +269,8 @@ public:
QTextOption defaultTextOption() const; QTextOption defaultTextOption() const;
void setDefaultTextOption(const QTextOption &option); void setDefaultTextOption(const QTextOption &option);
QTextCursor::MoveStyle defaultCursorMoveStyle() const; Qt::CursorMoveStyle defaultCursorMoveStyle() const;
void setDefaultCursorMoveStyle(QTextCursor::MoveStyle style); void setDefaultCursorMoveStyle(Qt::CursorMoveStyle style);
Q_SIGNALS: Q_SIGNALS:
void contentsChange(int from, int charsRemoves, int charsAdded); void contentsChange(int from, int charsRemoves, int charsAdded);

View File

@ -209,7 +209,7 @@ QTextDocumentPrivate::QTextDocumentPrivate()
defaultTextOption.setTabStop(80); // same as in qtextengine.cpp defaultTextOption.setTabStop(80); // same as in qtextengine.cpp
defaultTextOption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere); defaultTextOption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
defaultCursorMoveStyle = QTextCursor::Logical; defaultCursorMoveStyle = Qt::LogicalMoveStyle;
indentWidth = 40; indentWidth = 40;
documentMargin = 4; documentMargin = 4;

View File

@ -342,7 +342,7 @@ private:
public: public:
QTextOption defaultTextOption; QTextOption defaultTextOption;
QTextCursor::MoveStyle defaultCursorMoveStyle; Qt::CursorMoveStyle defaultCursorMoveStyle;
#ifndef QT_NO_CSSPARSER #ifndef QT_NO_CSSPARSER
QCss::StyleSheet parsedDefaultStyleSheet; QCss::StyleSheet parsedDefaultStyleSheet;
#endif #endif

View File

@ -598,7 +598,7 @@ public:
inline bool visualCursorMovement() const inline bool visualCursorMovement() const
{ {
return (visualMovement || return (visualMovement ||
(block.docHandle() ? block.docHandle()->defaultCursorMoveStyle == QTextCursor::Visual : false)); (block.docHandle() ? block.docHandle()->defaultCursorMoveStyle == Qt::VisualMoveStyle : false));
} }
struct SpecialData { struct SpecialData {

View File

@ -579,27 +579,27 @@ bool QTextLayout::cacheEnabled() const
} }
/*! /*!
Set the visual cursor movement style. If the QTextLayout is backed by Set the cursor movement style. If the QTextLayout is backed by
a document, you can ignore this and use the option in QTextDocument, a document, you can ignore this and use the option in QTextDocument,
this option is for widgets like QLineEdit or custom widgets without this option is for widgets like QLineEdit or custom widgets without
a QTextDocument. Default value is QTextCursor::Logical. a QTextDocument. Default value is Qt::LogicalMoveStyle.
\sa setCursorMoveStyle() \sa setCursorMoveStyle()
*/ */
void QTextLayout::setCursorMoveStyle(QTextCursor::MoveStyle style) void QTextLayout::setCursorMoveStyle(Qt::CursorMoveStyle style)
{ {
d->visualMovement = style == QTextCursor::Visual ? true : false; d->visualMovement = style == Qt::VisualMoveStyle ? true : false;
} }
/*! /*!
The cursor movement style of this QTextLayout. The default is The cursor movement style of this QTextLayout. The default is
QTextCursor::Logical. Qt::LogicalMoveStyle.
\sa setCursorMoveStyle() \sa setCursorMoveStyle()
*/ */
QTextCursor::MoveStyle QTextLayout::cursorMoveStyle() const Qt::CursorMoveStyle QTextLayout::cursorMoveStyle() const
{ {
return d->visualMovement ? QTextCursor::Visual : QTextCursor::Logical; return d->visualMovement ? Qt::VisualMoveStyle : Qt::LogicalMoveStyle;
} }
/*! /*!

View File

@ -137,8 +137,8 @@ public:
void setCacheEnabled(bool enable); void setCacheEnabled(bool enable);
bool cacheEnabled() const; bool cacheEnabled() const;
void setCursorMoveStyle(QTextCursor::MoveStyle style); void setCursorMoveStyle(Qt::CursorMoveStyle style);
QTextCursor::MoveStyle cursorMoveStyle() const; Qt::CursorMoveStyle cursorMoveStyle() const;
void beginLayout(); void beginLayout();
void endLayout(); void endLayout();

View File

@ -1585,7 +1585,7 @@ void QLineControl::processKeyEvent(QKeyEvent* event)
} }
bool unknown = false; bool unknown = false;
bool visual = cursorMoveStyle() == QTextCursor::Visual; bool visual = cursorMoveStyle() == Qt::VisualMoveStyle;
if (false) { if (false) {
} }

View File

@ -160,8 +160,8 @@ public:
int cursorWidth() const { return m_cursorWidth; } int cursorWidth() const { return m_cursorWidth; }
void setCursorWidth(int value) { m_cursorWidth = value; } void setCursorWidth(int value) { m_cursorWidth = value; }
QTextCursor::MoveStyle cursorMoveStyle() const { return m_textLayout.cursorMoveStyle(); } Qt::CursorMoveStyle cursorMoveStyle() const { return m_textLayout.cursorMoveStyle(); }
void setCursorMoveStyle(QTextCursor::MoveStyle style) { m_textLayout.setCursorMoveStyle(style); } void setCursorMoveStyle(Qt::CursorMoveStyle style) { m_textLayout.setCursorMoveStyle(style); }
void moveCursor(int pos, bool mark = false); void moveCursor(int pos, bool mark = false);
void cursorForward(bool mark, int steps) void cursorForward(bool mark, int steps)
@ -169,11 +169,11 @@ public:
int c = m_cursor; int c = m_cursor;
if (steps > 0) { if (steps > 0) {
while (steps--) while (steps--)
c = cursorMoveStyle() == QTextCursor::Visual ? m_textLayout.rightCursorPosition(c) c = cursorMoveStyle() == Qt::VisualMoveStyle ? m_textLayout.rightCursorPosition(c)
: m_textLayout.nextCursorPosition(c); : m_textLayout.nextCursorPosition(c);
} else if (steps < 0) { } else if (steps < 0) {
while (steps++) while (steps++)
c = cursorMoveStyle() == QTextCursor::Visual ? m_textLayout.leftCursorPosition(c) c = cursorMoveStyle() == Qt::VisualMoveStyle ? m_textLayout.leftCursorPosition(c)
: m_textLayout.previousCursorPosition(c); : m_textLayout.previousCursorPosition(c);
} }
moveCursor(c, mark); moveCursor(c, mark);

View File

@ -1116,24 +1116,24 @@ void QLineEdit::setDragEnabled(bool b)
\brief the movement style of cursor in this line edit \brief the movement style of cursor in this line edit
\since 4.8 \since 4.8
When this property is set to QTextCursor::Visual, the line edit will use visual When this property is set to Qt::VisualMoveStyle, the line edit will use visual
movement style. Pressing the left arrow key will always cause the cursor to move movement style. Pressing the left arrow key will always cause the cursor to move
left, regardless of the text's writing direction. The same behavior applies to left, regardless of the text's writing direction. The same behavior applies to
right arrow key. right arrow key.
When the property is QTextCursor::Logical (the default), within a LTR text block, When the property is Qt::LogicalMoveStyle (the default), within a LTR text block,
increase cursor position when pressing left arrow key, decrease cursor position increase cursor position when pressing left arrow key, decrease cursor position
when pressing the right arrow key. If the text block is right to left, the opposite when pressing the right arrow key. If the text block is right to left, the opposite
behavior applies. behavior applies.
*/ */
QTextCursor::MoveStyle QLineEdit::cursorMoveStyle() const Qt::CursorMoveStyle QLineEdit::cursorMoveStyle() const
{ {
Q_D(const QLineEdit); Q_D(const QLineEdit);
return d->control->cursorMoveStyle(); return d->control->cursorMoveStyle();
} }
void QLineEdit::setCursorMoveStyle(QTextCursor::MoveStyle style) void QLineEdit::setCursorMoveStyle(Qt::CursorMoveStyle style)
{ {
Q_D(QLineEdit); Q_D(QLineEdit);
d->control->setCursorMoveStyle(style); d->control->setCursorMoveStyle(style);

View File

@ -85,6 +85,7 @@ class Q_GUI_EXPORT QLineEdit : public QWidget
Q_PROPERTY(bool redoAvailable READ isRedoAvailable) Q_PROPERTY(bool redoAvailable READ isRedoAvailable)
Q_PROPERTY(bool acceptableInput READ hasAcceptableInput) Q_PROPERTY(bool acceptableInput READ hasAcceptableInput)
Q_PROPERTY(QString placeholderText READ placeholderText WRITE setPlaceholderText) Q_PROPERTY(QString placeholderText READ placeholderText WRITE setPlaceholderText)
Q_PROPERTY(Qt::CursorMoveStyle cursorMoveStyle READ cursorMoveStyle WRITE setCursorMoveStyle)
public: public:
explicit QLineEdit(QWidget* parent=0); explicit QLineEdit(QWidget* parent=0);
@ -159,8 +160,8 @@ public:
void setDragEnabled(bool b); void setDragEnabled(bool b);
bool dragEnabled() const; bool dragEnabled() const;
void setCursorMoveStyle(QTextCursor::MoveStyle style); void setCursorMoveStyle(Qt::CursorMoveStyle style);
QTextCursor::MoveStyle cursorMoveStyle() const; Qt::CursorMoveStyle cursorMoveStyle() const;
QString inputMask() const; QString inputMask() const;
void setInputMask(const QString &inputMask); void setInputMask(const QString &inputMask);

View File

@ -214,7 +214,7 @@ void tst_QComplexText::bidiCursorMovement()
QTextOption option = layout.textOption(); QTextOption option = layout.textOption();
option.setTextDirection(basicDir == QChar::DirL ? Qt::LeftToRight : Qt::RightToLeft); option.setTextDirection(basicDir == QChar::DirL ? Qt::LeftToRight : Qt::RightToLeft);
layout.setTextOption(option); layout.setTextOption(option);
layout.setCursorMoveStyle(QTextCursor::Visual); layout.setCursorMoveStyle(Qt::VisualMoveStyle);
bool moved; bool moved;
int oldPos, newPos = 0; int oldPos, newPos = 0;
qreal x, newX; qreal x, newX;

View File

@ -3815,7 +3815,7 @@ void tst_QLineEdit::bidiVisualMovement()
QLineEdit le; QLineEdit le;
le.setText(logical); le.setText(logical);
le.setCursorMoveStyle(QTextCursor::Visual); le.setCursorMoveStyle(Qt::VisualMoveStyle);
le.setCursorPosition(0); le.setCursorPosition(0);
bool moved; bool moved;
@ -3863,7 +3863,7 @@ void tst_QLineEdit::bidiLogicalMovement()
QLineEdit le; QLineEdit le;
le.setText(logical); le.setText(logical);
le.setCursorMoveStyle(QTextCursor::Logical); le.setCursorMoveStyle(Qt::LogicalMoveStyle);
le.setCursorPosition(0); le.setCursorPosition(0);
bool moved; bool moved;

View File

@ -2292,7 +2292,7 @@ void tst_QTextEdit::bidiVisualMovement()
option.setTextDirection(basicDir == QChar::DirL ? Qt::LeftToRight : Qt::RightToLeft); option.setTextDirection(basicDir == QChar::DirL ? Qt::LeftToRight : Qt::RightToLeft);
ed->document()->setDefaultTextOption(option); ed->document()->setDefaultTextOption(option);
ed->document()->setDefaultCursorMoveStyle(QTextCursor::Visual); ed->document()->setDefaultCursorMoveStyle(Qt::VisualMoveStyle);
ed->moveCursor(QTextCursor::Start); ed->moveCursor(QTextCursor::Start);
ed->show(); ed->show();
@ -2346,7 +2346,7 @@ void tst_QTextEdit::bidiLogicalMovement()
option.setTextDirection(basicDir == QChar::DirL ? Qt::LeftToRight : Qt::RightToLeft); option.setTextDirection(basicDir == QChar::DirL ? Qt::LeftToRight : Qt::RightToLeft);
ed->document()->setDefaultTextOption(option); ed->document()->setDefaultTextOption(option);
ed->document()->setDefaultCursorMoveStyle(QTextCursor::Logical); ed->document()->setDefaultCursorMoveStyle(Qt::LogicalMoveStyle);
ed->moveCursor(QTextCursor::Start); ed->moveCursor(QTextCursor::Start);
ed->show(); ed->show();