diff options
Diffstat (limited to 'src/declarative')
-rw-r--r-- | src/declarative/fx/qfxpainteditem.cpp | 3 | ||||
-rw-r--r-- | src/declarative/fx/qfxtextedit.cpp | 5 | ||||
-rw-r--r-- | src/declarative/fx/qfxtextinput.cpp | 56 | ||||
-rw-r--r-- | src/declarative/fx/qfxtextinput.h | 4 |
4 files changed, 44 insertions, 24 deletions
diff --git a/src/declarative/fx/qfxpainteditem.cpp b/src/declarative/fx/qfxpainteditem.cpp index 1ed44a9..27f3ca6 100644 --- a/src/declarative/fx/qfxpainteditem.cpp +++ b/src/declarative/fx/qfxpainteditem.cpp @@ -101,7 +101,7 @@ void QFxPaintedItem::dirtyCache(const QRect& rect) QFxPaintedItemPrivate::ImageCacheItem *c = d->imagecache[i]; QRect isect = (c->area & rect) | c->dirty; if (isect == c->area && !inpaint) { - d->imagecache.removeAt(i); + delete d->imagecache.takeAt(i); } else { c->dirty = isect; ++i; @@ -231,6 +231,7 @@ void QFxPaintedItem::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidge QPainter qp(&d->imagecache[i]->image); qp.setRenderHints(QPainter::HighQualityAntialiasing | QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform, d->smooth); qp.translate(-area.x(), -area.y()); + qp.eraseRect(d->imagecache[i]->dirty); if (d->fillColor.isValid()) qp.fillRect(d->imagecache[i]->dirty,d->fillColor); qp.setClipRect(d->imagecache[i]->dirty); diff --git a/src/declarative/fx/qfxtextedit.cpp b/src/declarative/fx/qfxtextedit.cpp index 8094d32..f7b92a4 100644 --- a/src/declarative/fx/qfxtextedit.cpp +++ b/src/declarative/fx/qfxtextedit.cpp @@ -1047,6 +1047,11 @@ void QFxTextEdit::updateSize() //### need to comfirm cost of always setting these int newWidth = (int)d->document->idealWidth(); d->document->setTextWidth(newWidth); // ### QTextDoc> Alignment will not work unless textWidth is set. Does Text need this line as well? + int cursorWidth = 1; + if(d->cursor) + cursorWidth = d->cursor->width(); + newWidth += cursorWidth; + newWidth += 3;// ### Need a better way of ensuring cursor is in width setImplicitWidth(newWidth); setImplicitHeight(d->text.isEmpty() ? fm.height() : (int)d->document->size().height()); diff --git a/src/declarative/fx/qfxtextinput.cpp b/src/declarative/fx/qfxtextinput.cpp index f38a551..b7b155a 100644 --- a/src/declarative/fx/qfxtextinput.cpp +++ b/src/declarative/fx/qfxtextinput.cpp @@ -131,9 +131,7 @@ void QFxTextInput::setFont(const QFont &font) d->cursorItem->setHeight(QFontMetrics(d->font).height()); moveCursor(); } - //updateSize(); - updateAll();//TODO: Only necessary updates - update(); + updateSize(); } /*! @@ -272,7 +270,7 @@ void QFxTextInput::setCursorVisible(bool on) return; d->cursorVisible = on; d->control->setCursorBlinkPeriod(on?QApplication::cursorFlashTime():0); - updateAll();//TODO: Only update cursor rect + //d->control should emit the cursor update regions } /*! @@ -593,14 +591,17 @@ bool QFxTextInput::event(QEvent* ev) { Q_D(QFxTextInput); //Anything we don't deal with ourselves, pass to the control + bool handled = false; switch(ev->type()){ case QEvent::KeyPress: case QEvent::GraphicsSceneMousePress: break; default: - return d->control->processEvent(ev); + handled = d->control->processEvent(ev); } - return false; + if(!handled) + return QFxPaintedItem::event(ev); + return true; } void QFxTextInput::geometryChanged(const QRectF &newGeometry, @@ -624,7 +625,9 @@ void QFxTextInput::drawContents(QPainter *p, const QRect &r) flags |= QLineControl::DrawSelections; } - d->control->draw(p, QPoint(0,0), r, flags); + QPoint offset = QPoint(0,0); + QRect clipRect = r; + d->control->draw(p, offset, clipRect, flags); p->restore(); } @@ -667,13 +670,13 @@ void QFxTextInputPrivate::init() q, SLOT(q_textChanged())); q->connect(control, SIGNAL(accepted()), q, SIGNAL(accepted())); - q->connect(control, SIGNAL(updateNeeded(const QRect &)), - // q, SLOT(dirtyCache(const QRect &))); - q, SLOT(updateAll())); + q->connect(control, SIGNAL(updateNeeded(QRect)), + q, SLOT(updateRect(QRect))); q->connect(control, SIGNAL(cursorPositionChanged(int,int)), - q, SLOT(updateAll())); + q, SLOT(updateRect()));//TODO: Only update rect between pos's q->connect(control, SIGNAL(selectionChanged()), - q, SLOT(updateAll())); + q, SLOT(updateRect()));//TODO: Only update rect in selection + //Note that above TODOs probably aren't that big a savings q->updateSize(); oldValidity = control->hasAcceptableInput(); lastSelectionStart = 0; @@ -719,7 +722,7 @@ void QFxTextInput::selectionChanged() void QFxTextInput::q_textChanged() { Q_D(QFxTextInput); - updateAll(); + updateSize(); emit textChanged(); if(hasAcceptableInput() != d->oldValidity){ d->oldValidity = hasAcceptableInput(); @@ -727,21 +730,32 @@ void QFxTextInput::q_textChanged() } } -//### Please replace this function with proper updating -void QFxTextInput::updateAll() +void QFxTextInput::updateRect(const QRect &r) { - clearCache(); - updateSize(); + if(r == QRect()) + clearCache(); + else + dirtyCache(r); update(); } -void QFxTextInput::updateSize() +void QFxTextInput::updateSize(bool needsRedraw) { Q_D(QFxTextInput); + int w = width(); + int h = height(); setImplicitHeight(d->control->height()); - //d->control->width() is width of the line, not of the text - setImplicitWidth(d->control->naturalTextWidth()+2); - setContentsSize(QSize(width(), height())); + int cursorWidth = d->control->cursorWidth(); + if(d->cursorItem) + cursorWidth = d->cursorItem->width(); + //### Is QFontMetrics too slow? + QFontMetricsF fm(d->font); + setImplicitWidth(fm.width(d->control->displayText())+cursorWidth); + setContentsSize(QSize(width(), height()));//Repaints if changed + if(w==width() && h==height() && needsRedraw){ + clearCache(); + update(); + } } QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxtextinput.h b/src/declarative/fx/qfxtextinput.h index 4fa4100..b1e8b14 100644 --- a/src/declarative/fx/qfxtextinput.h +++ b/src/declarative/fx/qfxtextinput.h @@ -184,13 +184,13 @@ public Q_SLOTS: void selectAll(); private Q_SLOTS: - void updateSize(); + void updateSize(bool needsRedraw = true); void q_textChanged(); void selectionChanged(); - void updateAll(); void createCursor(); void moveCursor(); void cursorPosChanged(); + void updateRect(const QRect &r = QRect()); private: Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QFxTextInput); |