diff options
author | Michael Brasser <michael.brasser@nokia.com> | 2009-06-01 03:25:08 (GMT) |
---|---|---|
committer | Michael Brasser <michael.brasser@nokia.com> | 2009-06-01 03:25:08 (GMT) |
commit | b9f484ae5d415d95df897e18059c054527111374 (patch) | |
tree | 48e5c68e87125b657203ed00e6021bc14b4c6672 | |
parent | e4ea96a48bd6d4c8b96859fc0364a5d9c7c686d6 (diff) | |
download | Qt-b9f484ae5d415d95df897e18059c054527111374.zip Qt-b9f484ae5d415d95df897e18059c054527111374.tar.gz Qt-b9f484ae5d415d95df897e18059c054527111374.tar.bz2 |
Add textMargin property and more flexible key handling to TextEdit
-rw-r--r-- | src/declarative/fx/qfxtextedit.cpp | 34 | ||||
-rw-r--r-- | src/declarative/fx/qfxtextedit.h | 5 | ||||
-rw-r--r-- | src/declarative/fx/qfxtextedit_p.h | 3 |
3 files changed, 38 insertions, 4 deletions
diff --git a/src/declarative/fx/qfxtextedit.cpp b/src/declarative/fx/qfxtextedit.cpp index 1c70abf..c7a7700 100644 --- a/src/declarative/fx/qfxtextedit.cpp +++ b/src/declarative/fx/qfxtextedit.cpp @@ -49,6 +49,7 @@ #endif #include <qfxperf.h> +#include "qfxevents_p.h" #include <QTextLayout> #include <QTextLine> #include <QTextDocument> @@ -474,6 +475,21 @@ void QFxTextEdit::setPreserveSelection(bool on) d->preserveSelection = on; } +qreal QFxTextEdit::textMargin() const +{ + Q_D(const QFxTextEdit); + return d->textMargin; +} + +void QFxTextEdit::setTextMargin(qreal margin) +{ + Q_D(QFxTextEdit); + if (d->textMargin == margin) + return; + d->textMargin = margin; + d->document->setDocumentMargin(d->textMargin); +} + void QFxTextEdit::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) { @@ -659,6 +675,13 @@ Handles the given key \a event. void QFxTextEdit::keyPressEvent(QKeyEvent *event) { Q_D(QFxTextEdit); + //### experiment with allowing 'overrides' to key events + QFxKeyEvent ke(*event); + emit keyPress(&ke); + event->setAccepted(ke.isAccepted()); + if (event->isAccepted()) + return; + QTextCursor c = textCursor(); QTextCursor::MoveOperation op = QTextCursor::NoMove; if (event == QKeySequence::MoveToNextChar) { @@ -688,6 +711,13 @@ Handles the given key \a event. void QFxTextEdit::keyReleaseEvent(QKeyEvent *event) { Q_D(QFxTextEdit); + //### experiment with allowing 'overrides' to key events + QFxKeyEvent ke(*event); + emit keyRelease(&ke); + event->setAccepted(ke.isAccepted()); + if (event->isAccepted()) + return; + d->control->processEvent(event, QPointF(0, 0)); } @@ -821,7 +851,7 @@ void QFxTextEditPrivate::init() document = control->document(); document->setDefaultFont(font.font()); - document->setDocumentMargin(0); + document->setDocumentMargin(textMargin); document->setUndoRedoEnabled(false); // flush undo buffer. document->setUndoRedoEnabled(true); updateDefaultTextOption(); @@ -851,7 +881,7 @@ void QFxTextEdit::updateSize() else if (d->vAlign == AlignVCenter) yoff = dy/2; } - setBaselineOffset(fm.ascent() + yoff); + setBaselineOffset(fm.ascent() + yoff + d->textMargin); if (!widthValid()) { int newWidth = (int)d->document->idealWidth(); d->document->setTextWidth(newWidth); // ### QTextDoc> Alignment will not work unless textWidth is set diff --git a/src/declarative/fx/qfxtextedit.h b/src/declarative/fx/qfxtextedit.h index 37bc327..e30b9ed 100644 --- a/src/declarative/fx/qfxtextedit.h +++ b/src/declarative/fx/qfxtextedit.h @@ -79,7 +79,7 @@ class Q_DECLARATIVE_EXPORT QFxTextEdit : public QFxPaintedItem Q_PROPERTY(bool cursorVisible READ isCursorVisible WRITE setCursorVisible) Q_PROPERTY(bool focusOnPress READ focusOnPress WRITE setFocusOnPress) Q_PROPERTY(bool preserveSelection READ preserveSelection WRITE setPreserveSelection) - Q_CLASSINFO("DefaultProperty", "text") + Q_PROPERTY(qreal textMargin READ textMargin WRITE setTextMargin) public: QFxTextEdit(QFxItem *parent=0); @@ -135,6 +135,9 @@ public: bool preserveSelection() const; void setPreserveSelection(bool on); + qreal textMargin() const; + void setTextMargin(qreal margin); + virtual void dump(int depth); virtual QString propertyInfo() const; diff --git a/src/declarative/fx/qfxtextedit_p.h b/src/declarative/fx/qfxtextedit_p.h index 9f26b10..f733a4c 100644 --- a/src/declarative/fx/qfxtextedit_p.h +++ b/src/declarative/fx/qfxtextedit_p.h @@ -70,7 +70,7 @@ public: QFxTextEditPrivate() : font(0), color("black"), imgDirty(true), hAlign(QFxTextEdit::AlignLeft), vAlign(QFxTextEdit::AlignTop), dirty(false), wrap(false), richText(false), cursorVisible(false), focusOnPress(false), preserveSelection(true), - format(QFxTextEdit::AutoText), document(0) + textMargin(0.0), format(QFxTextEdit::AutoText), document(0) { } @@ -99,6 +99,7 @@ public: bool cursorVisible; bool focusOnPress; bool preserveSelection; + qreal textMargin; QFxTextEdit::TextFormat format; QTextDocument *document; QTextControl *control; |