Changeset View
Changeset View
Standalone View
Standalone View
src/include/ktexteditor/cursor.h
Context not available. | |||||
29 | 29 | | |||
---|---|---|---|---|---|
30 | #include <QDebug> | 30 | #include <QDebug> | ||
31 | #include <QtGlobal> | 31 | #include <QtGlobal> | ||
32 | #include <QObject> | ||||
33 | #include <QtQml/QJSEngine> | ||||
32 | 34 | | |||
33 | namespace KTextEditor | 35 | namespace KTextEditor | ||
34 | { | 36 | { | ||
Context not available. | |||||
81 | */ | 83 | */ | ||
82 | class KTEXTEDITOR_EXPORT Cursor | 84 | class KTEXTEDITOR_EXPORT Cursor | ||
83 | { | 85 | { | ||
86 | Q_GADGET | ||||
87 | Q_PROPERTY(int line READ line WRITE setLine) | ||||
88 | Q_PROPERTY(int column READ column WRITE setColumn) | ||||
84 | public: | 89 | public: | ||
85 | /** | 90 | /** | ||
86 | * The default constructor creates a cursor at position (0, 0). | 91 | * The default constructor creates a cursor at position (0, 0). | ||
Context not available. | |||||
96 | * \param line line for cursor | 101 | * \param line line for cursor | ||
97 | * \param column column for cursor | 102 | * \param column column for cursor | ||
98 | */ | 103 | */ | ||
99 | Q_DECL_CONSTEXPR Cursor(int line, int column) Q_DECL_NOEXCEPT | 104 | Q_INVOKABLE Q_DECL_CONSTEXPR Cursor(int line, int column) Q_DECL_NOEXCEPT | ||
100 | : m_line(line) | 105 | : m_line(line) | ||
101 | , m_column(column) { | 106 | , m_column(column) { | ||
102 | } | 107 | } | ||
Context not available. | |||||
109 | * \e text-position, use DocumentCursor::isValidTextPosition(), | 114 | * \e text-position, use DocumentCursor::isValidTextPosition(), | ||
110 | * or Document::isValidTextPosition(). | 115 | * or Document::isValidTextPosition(). | ||
111 | */ | 116 | */ | ||
112 | Q_DECL_CONSTEXPR inline bool isValid() const Q_DECL_NOEXCEPT { | 117 | Q_INVOKABLE Q_DECL_CONSTEXPR inline bool isValid() const Q_DECL_NOEXCEPT { | ||
113 | return m_line >= 0 && m_column >= 0; | 118 | return m_line >= 0 && m_column >= 0; | ||
114 | } | 119 | } | ||
115 | 120 | | |||
Context not available. | |||||
118 | * The returned cursor position is set to (-1, -1). | 123 | * The returned cursor position is set to (-1, -1). | ||
119 | * \see isValid() | 124 | * \see isValid() | ||
120 | */ | 125 | */ | ||
121 | Q_DECL_CONSTEXPR static Cursor invalid() Q_DECL_NOEXCEPT { | 126 | Q_INVOKABLE Q_DECL_CONSTEXPR static Cursor invalid() Q_DECL_NOEXCEPT { | ||
122 | return Cursor(-1, -1); | 127 | return Cursor(-1, -1); | ||
123 | } | 128 | } | ||
124 | 129 | | |||
Context not available. | |||||
381 | int m_column; | 386 | int m_column; | ||
382 | }; | 387 | }; | ||
383 | 388 | | |||
384 | } | 389 | } // namespace KTextEditor | ||
385 | 390 | | |||
386 | Q_DECLARE_TYPEINFO(KTextEditor::Cursor, Q_MOVABLE_TYPE); | 391 | Q_DECLARE_TYPEINFO(KTextEditor::Cursor, Q_MOVABLE_TYPE); | ||
387 | Q_DECLARE_METATYPE(KTextEditor::Cursor) | 392 | Q_DECLARE_METATYPE(KTextEditor::Cursor) | ||
Context not available. | |||||
407 | KTEXTEDITOR_EXPORT char *toString(const KTextEditor::Cursor &cursor); | 412 | KTEXTEDITOR_EXPORT char *toString(const KTextEditor::Cursor &cursor); | ||
408 | } | 413 | } | ||
409 | 414 | | |||
415 | inline QJSValue cursorToScriptValue(QJSEngine *engine, const KTextEditor::Cursor &cursor) | ||||
416 | { | ||||
417 | QString code = QStringLiteral("new Cursor(%1, %2);").arg(cursor.line()) | ||||
418 | .arg(cursor.column()); | ||||
419 | QJSValue result = engine->evaluate(code); | ||||
420 | Q_ASSERT(!result.isError()); | ||||
421 | return result; | ||||
422 | } | ||||
423 | | ||||
424 | inline void cursorFromScriptValue(const QJSValue &obj, KTextEditor::Cursor &cursor) | ||||
425 | { | ||||
426 | QJSValue line = obj.property(QStringLiteral("line")); | ||||
427 | QJSValue column = obj.property(QStringLiteral("column")); | ||||
428 | Q_ASSERT(!line.isError() && !column.isError()); | ||||
429 | cursor.setPosition(line.toInt(), column.toInt()); | ||||
430 | } | ||||
431 | | ||||
410 | #endif | 432 | #endif | ||
411 | 433 | | |||
Context not available. |