summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Brasser <michael.brasser@nokia.com>2009-11-05 03:56:56 (GMT)
committerMichael Brasser <michael.brasser@nokia.com>2009-11-05 04:48:03 (GMT)
commit656870157932a0b44de69927faa003c71eeb2a47 (patch)
tree569c205b62aca853b5f24118f1384a748b7efc84
parentd39ec85b7e5d8702c2888cdad4ccdae72531c199 (diff)
downloadQt-656870157932a0b44de69927faa003c71eeb2a47.zip
Qt-656870157932a0b44de69927faa003c71eeb2a47.tar.gz
Qt-656870157932a0b44de69927faa003c71eeb2a47.tar.bz2
Fix signal overriding.
-rw-r--r--src/declarative/util/qmlpropertychanges.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/declarative/util/qmlpropertychanges.cpp b/src/declarative/util/qmlpropertychanges.cpp
index dbf2bc4..3cc6ca9 100644
--- a/src/declarative/util/qmlpropertychanges.cpp
+++ b/src/declarative/util/qmlpropertychanges.cpp
@@ -307,7 +307,7 @@ QmlPropertyChangesPrivate::property(const QByteArray &property)
if (!prop.isValid()) {
qmlInfo(QmlPropertyChanges::tr("Cannot assign to non-existant property \"%1\"").arg(QString::fromUtf8(property)), q);
return QmlMetaProperty();
- } else if (!prop.isWritable()) {
+ } else if (prop.type() != QmlMetaProperty::SignalProperty && !prop.isWritable()) {
qmlInfo(QmlPropertyChanges::tr("Cannot assign to read-only property \"%1\"").arg(QString::fromUtf8(property)), q);
return QmlMetaProperty();
}
a> 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtDeclarative module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights.  These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include "qmlgraphicstextinput_p.h"
#include "qmlgraphicstextinput_p_p.h"

#include <qmlinfo.h>

#include <QValidator>
#include <QApplication>
#include <QFontMetrics>
#include <QPainter>

QT_BEGIN_NAMESPACE

/*!
    \qmlclass TextInput QmlGraphicsTextInput
  \since 4.7
    The TextInput item allows you to add an editable line of text to a scene.

    TextInput can only display a single line of text, and can only display
    plain text. However it can provide addition input constraints on the text.

    Input constraints include setting a QValidator, an input mask, or a
    maximum input length.
*/
QmlGraphicsTextInput::QmlGraphicsTextInput(QmlGraphicsItem* parent)
    : QmlGraphicsPaintedItem(*(new QmlGraphicsTextInputPrivate), parent)
{
    Q_D(QmlGraphicsTextInput);
    d->init();
}

QmlGraphicsTextInput::~QmlGraphicsTextInput()
{
}

/*!
    \qmlproperty string TextInput::text

    The text in the TextInput.
*/

QString QmlGraphicsTextInput::text() const
{
    Q_D(const QmlGraphicsTextInput);
    return d->control->text();
}

void QmlGraphicsTextInput::setText(const QString &s)
{
    Q_D(QmlGraphicsTextInput);
    if(s == text())
        return;
    d->control->setText(s);
    //emit textChanged();
}

/*!
    \qmlproperty string TextInput::font.family
    \qmlproperty bool TextInput::font.bold
    \qmlproperty bool TextInput::font.italic
    \qmlproperty bool TextInput::font.underline
    \qmlproperty real TextInput::font.pointSize
    \qmlproperty int TextInput::font.pixelSize

    Set the TextInput's font attributes.
*/
QFont QmlGraphicsTextInput::font() const
{
    Q_D(const QmlGraphicsTextInput);
    return d->font;
}

void QmlGraphicsTextInput::setFont(const QFont &font)
{
    Q_D(QmlGraphicsTextInput);
    if (d->font == font)
        return;

    d->font = font;

    d->control->setFont(d->font);
    if(d->cursorItem){
        d->cursorItem->setHeight(QFontMetrics(d->font).height());
        moveCursor();
    }
    updateSize();
    emit fontChanged(d->font);
}

/*!
    \qmlproperty color TextInput::color

    The text color.
*/
QColor QmlGraphicsTextInput::color() const
{
    Q_D(const QmlGraphicsTextInput);
    return d->color;
}

void QmlGraphicsTextInput::setColor(const QColor &c)
{
    Q_D(QmlGraphicsTextInput);
    d->color = c;
}


/*!
    \qmlproperty color TextInput::selectionColor

    The text highlight color, used behind selections.
*/
QColor QmlGraphicsTextInput::selectionColor() const
{
    Q_D(const QmlGraphicsTextInput);
    return d->selectionColor;
}

void QmlGraphicsTextInput::setSelectionColor(const QColor &color)
{
    Q_D(QmlGraphicsTextInput);
    if (d->selectionColor == color)
        return;

    d->selectionColor = color;
    QPalette p = d->control->palette();
    p.setColor(QPalette::Highlight, d->selectionColor);
    d->control->setPalette(p);
    emit selectionColorChanged(color);
}

/*!
    \qmlproperty color TextInput::selectedTextColor

    The highlighted text color, used in selections.
*/
QColor QmlGraphicsTextInput::selectedTextColor() const
{
    Q_D(const QmlGraphicsTextInput);
    return d->selectedTextColor;
}

void QmlGraphicsTextInput::setSelectedTextColor(const QColor &color)
{
    Q_D(QmlGraphicsTextInput);
    if (d->selectedTextColor == color)
        return;

    d->selectedTextColor = color;
    QPalette p = d->control->palette();
    p.setColor(QPalette::HighlightedText, d->selectedTextColor);
    d->control->setPalette(p);
    emit selectedTextColorChanged(color);
}

/*!
    \qmlproperty enumeration TextInput::horizontalAlignment

    Sets the horizontal alignment of the text within the TextInput item's
    width and height.  By default, the text is left aligned.

    TextInput does not have vertical alignment, as the natural height is
    exactly the height of the single line of text. If you set the height
    manually to something larger, TextInput will always be top aligned
    vertically. You can use anchors to align it however you want within
    another item.

    The valid values for \c horizontalAlignment are \c AlignLeft, \c AlignRight and
    \c AlignHCenter.
*/
QmlGraphicsTextInput::HAlignment QmlGraphicsTextInput::hAlign() const
{
    Q_D(const QmlGraphicsTextInput);
    return d->hAlign;
}

void QmlGraphicsTextInput::setHAlign(HAlignment align)
{
    Q_D(QmlGraphicsTextInput);
    if(align == d->hAlign)
        return;
    d->hAlign = align;
    emit horizontalAlignmentChanged(d->hAlign);
}

bool QmlGraphicsTextInput::isReadOnly() const
{
    Q_D(const QmlGraphicsTextInput);
    return d->control->isReadOnly();
}

void QmlGraphicsTextInput::setReadOnly(bool ro)
{
    Q_D(QmlGraphicsTextInput);
    if (d->control->isReadOnly() == ro)
        return;

    d->control->setReadOnly(ro);

    emit readOnlyChanged(ro);
}

int QmlGraphicsTextInput::maxLength() const
{
    Q_D(const QmlGraphicsTextInput);
    return d->control->maxLength();
}

void QmlGraphicsTextInput::setMaxLength(int ml)
{
    Q_D(QmlGraphicsTextInput);
    if (d->control->maxLength() == ml)
        return;

    d->control->setMaxLength(ml);

    emit maximumLengthChanged(ml);
}

/*!
    \qmlproperty bool TextInput::cursorVisible
    Set to true when the TextInput shows a cursor.

    This property is set and unset when the TextInput gets focus, so that other
    properties can be bound to whether the cursor is currently showing. As it
    gets set and unset automatically, when you set the value yourself you must
    keep in mind that your value may be overwritten.

    It can be set directly in script, for example if a KeyProxy might
    forward keys to it and you desire it to look active when this happens
    (but without actually giving it the focus).

    It should not be set directly on the element, like in the below QML,
    as the specified value will be overridden an lost on focus changes.

    \code
    TextInput {
        text: "Text"
        cursorVisible: false
    }
    \endcode

    In the above snippet the cursor will still become visible when the
    TextInput gains focus.
*/
bool QmlGraphicsTextInput::isCursorVisible() const
{
    Q_D(const QmlGraphicsTextInput);
    return d->cursorVisible;
}

void QmlGraphicsTextInput::setCursorVisible(bool on)
{
    Q_D(QmlGraphicsTextInput);
    if (d->cursorVisible == on)
        return;
    d->cursorVisible = on;
    d->control->setCursorBlinkPeriod(on?QApplication::cursorFlashTime():0);
    //d->control should emit the cursor update regions
    emit cursorVisibleChanged(d->cursorVisible);
}

/*!
    \qmlproperty int TextInput::cursorPosition
    The position of the cursor in the TextInput.
*/
int QmlGraphicsTextInput::cursorPosition() const
{
    Q_D(const QmlGraphicsTextInput);
    return d->control->cursor();
}
void QmlGraphicsTextInput::setCursorPosition(int cp)
{
    Q_D(QmlGraphicsTextInput);
    d->control->moveCursor(cp);
}

/*!
  \internal

  Returns a Rect which encompasses the cursor, but which may be larger than is
  required. Ignores custom cursor delegates.
*/
QRect QmlGraphicsTextInput::cursorRect() const
{
    Q_D(const QmlGraphicsTextInput);
    return d->control->cursorRect();
}

/*!
    \qmlproperty int TextInput::selectionStart

    The cursor position before the first character in the current selection.
    Setting this and selectionEnd allows you to specify a selection in the
    text edit.

    Note that if selectionStart == selectionEnd then there is no current
    selection. If you attempt to set selectionStart to a value outside of
    the current text, selectionStart will not be changed.

    \sa selectionEnd, cursorPosition, selectedText
*/
int QmlGraphicsTextInput::selectionStart() const
{
    Q_D(const QmlGraphicsTextInput);
    return d->lastSelectionStart;
}

void QmlGraphicsTextInput::setSelectionStart(int s)
{
    Q_D(QmlGraphicsTextInput);
    if(d->lastSelectionStart == s || s < 0 || s > text().length())
        return;
    d->lastSelectionStart = s;
    d->control->setSelection(s, d->lastSelectionEnd - s);
}

/*!
    \qmlproperty int TextInput::selectionEnd

    The cursor position after the last character in the current selection.
    Setting this and selectionStart allows you to specify a selection in the
    text edit.

    Note that if selectionStart == selectionEnd then there is no current
    selection. If you attempt to set selectionEnd to a value outside of
    the current text, selectionEnd will not be changed.

    \sa selectionStart, cursorPosition, selectedText
*/
int QmlGraphicsTextInput::selectionEnd() const
{
    Q_D(const QmlGraphicsTextInput);
    return d->lastSelectionEnd;
}

void QmlGraphicsTextInput::setSelectionEnd(int s)
{
    Q_D(QmlGraphicsTextInput);
    if(d->lastSelectionEnd == s || s < 0 || s > text().length())
        return;
    d->lastSelectionEnd = s;
    d->control->setSelection(d->lastSelectionStart, s - d->lastSelectionStart);
}

/*!
    \qmlproperty string TextInput::selectedText

    This read-only property provides the text currently selected in the
    text input.

    It is equivalent to the following snippet, but is faster and easier
    to use.

    \qml
    myTextInput.text.toString().substring(myTextInput.selectionStart,
        myTextInput.selectionEnd);
    \endqml
*/
QString QmlGraphicsTextInput::selectedText() const
{
    Q_D(const QmlGraphicsTextInput);
    return d->control->selectedText();
}

/*!
    \qmlproperty bool TextInput::focusOnPress

    Whether the TextInput should gain focus on a mouse press. By default this is
    set to true.
*/
bool QmlGraphicsTextInput::focusOnPress() const
{
    Q_D(const QmlGraphicsTextInput);
    return d->focusOnPress;
}

void QmlGraphicsTextInput::setFocusOnPress(bool b)
{
    Q_D(QmlGraphicsTextInput);
    if (d->focusOnPress == b)
        return;

    d->focusOnPress = b;

    emit focusOnPressChanged(d->focusOnPress);
}

/*!
    \qmlproperty QValidator* TextInput::validator

    Allows you to set a QValidator on the TextInput. When a validator is set
    the TextInput will only accept input which leaves the text property in
    an acceptable or intermediate state. The accepted signal will only be sent
    if the text is in an acceptable state when enter is pressed.

    Currently supported validators are QIntValidator, QDoubleValidator and
    QRegExpValidator. For details, refer to their C++ documentation and remember
    that all Q_PROPERTIES are accessible from Qml. A brief usage guide follows:

    QIntValidator and QDoubleValidator both are controllable through two properties,
    top and bottom. The difference is that for QIntValidator the top and bottom properties
    should be integers, and for QDoubleValidator they should be doubles. QRegExpValidator
    has a single string property, regExp, which should be set to the regular expression to
    be used for validation. An example of using validators is shown below, which allows
    input of integers between 11 and 31 into the text input:

    \code
    import Qt 4.6
    TextInput{
        validator: QIntValidator{bottom: 11; top: 31;}
        focus: true
    }
    \endcode

    \sa acceptableInput, inputMask
*/
QValidator* QmlGraphicsTextInput::validator() const
{
    Q_D(const QmlGraphicsTextInput);
    //###const cast isn't good, but needed for property system?
    return const_cast<QValidator*>(d->control->validator());
}

void QmlGraphicsTextInput::setValidator(QValidator* v)
{
    Q_D(QmlGraphicsTextInput);
    if (d->control->validator() == v)
        return;

    d->control->setValidator(v);
    if(!d->control->hasAcceptableInput()){
        d->oldValidity = false;
        emit acceptableInputChanged();
    }

    emit validatorChanged();
}

/*!
    \qmlproperty string TextInput::inputMask

    Allows you to set an input mask on the TextInput, restricting the allowable
    text inputs. See QLineEdit::inputMask for further details, as the exact
    same mask strings are used by TextInput.

    \sa acceptableInput, validator
*/
QString QmlGraphicsTextInput::inputMask() const
{
    Q_D(const QmlGraphicsTextInput);
    return d->control->inputMask();
}

void QmlGraphicsTextInput::setInputMask(const QString &im)
{
    Q_D(QmlGraphicsTextInput);
    if (d->control->inputMask() == im)
        return;

    d->control->setInputMask(im);
    emit inputMaskChanged(d->control->inputMask());
}

/*!
    \qmlproperty bool TextInput::acceptableInput

    This property is always true unless a validator or input mask has been set.
    If a validator or input mask has been set, this property will only be true
    if the current text is acceptable to the validator or input mask as a final
    string (not as an intermediate string).
*/
bool QmlGraphicsTextInput::hasAcceptableInput() const
{
    Q_D(const QmlGraphicsTextInput);
    return d->control->hasAcceptableInput();
}

/*!
    \qmlproperty TextInput.EchoMode TextInput::echoMode

    Specifies how the text should be displayed in the TextInput.
    The default is Normal, which displays the text as it is. Other values
    are Password, which displays asterixes instead of characters, NoEcho,
    which displays nothing, and PasswordEchoOnEdit, which displays all but the
    current character as asterixes.

*/
QmlGraphicsTextInput::EchoMode QmlGraphicsTextInput::echoMode() const
{
    Q_D(const QmlGraphicsTextInput);
    return (QmlGraphicsTextInput::EchoMode)d->control->echoMode();
}

void QmlGraphicsTextInput::setEchoMode(QmlGraphicsTextInput::EchoMode echo)
{
    Q_D(QmlGraphicsTextInput);
    if (echoMode() == echo)
        return;

    d->control->setEchoMode((uint)echo);
    emit echoModeChanged(echoMode());
}

/*!
    \qmlproperty Component TextInput::cursorDelegate
    The delegate for the cursor in the TextInput.

    If you set a cursorDelegate for a TextInput, this delegate will be used for
    drawing the cursor instead of the standard cursor. An instance of the
    delegate will be created and managed by the TextInput when a cursor is
    needed, and the x property of delegate instance will be set so as
    to be one pixel before the top left of the current character.

    Note that the root item of the delegate component must be a QmlGraphicsItem or
    QmlGraphicsItem derived item.
*/
QmlComponent* QmlGraphicsTextInput::cursorDelegate() const
{
    Q_D(const QmlGraphicsTextInput);
    return d->cursorComponent;
}

void QmlGraphicsTextInput::setCursorDelegate(QmlComponent* c)
{
    Q_D(QmlGraphicsTextInput);
    if (d->cursorComponent == c)
        return;

    d->cursorComponent = c;
    if(!c){
        //note that the components are owned by something else
        disconnect(d->control, SIGNAL(cursorPositionChanged(int, int)),
                this, SLOT(moveCursor()));
        delete d->cursorItem;
    }else{
        d->startCreatingCursor();
    }

    emit cursorDelegateChanged();
}

void QmlGraphicsTextInputPrivate::startCreatingCursor()
{
    Q_Q(QmlGraphicsTextInput);
    q->connect(control, SIGNAL(cursorPositionChanged(int, int)),
            q, SLOT(moveCursor()));
    if(cursorComponent->isReady()){
        q->createCursor();
    }else if(cursorComponent->isLoading()){
        q->connect(cursorComponent, SIGNAL(statusChanged(int)),
                q, SLOT(createCursor()));
    }else{//isError
        qmlInfo(q) << QmlGraphicsTextInput::tr("Could not load cursor delegate");
        qWarning() << cursorComponent->errors();
    }
}

void QmlGraphicsTextInput::createCursor()
{
    Q_D(QmlGraphicsTextInput);
    if(d->cursorComponent->isError()){
        qmlInfo(this) << tr("Could not load cursor delegate");
        qWarning() << d->cursorComponent->errors();
        return;
    }

    if(!d->cursorComponent->isReady())
        return;

    if(d->cursorItem)
        delete d->cursorItem;
    d->cursorItem = qobject_cast<QmlGraphicsItem*>(d->cursorComponent->create());
    if(!d->cursorItem){
        qmlInfo(this) << tr("Could not instantiate cursor delegate");
        //The failed instantiation should print its own error messages
        return;
    }

    d->cursorItem->setParentItem(this);
    d->cursorItem->setX(d->control->cursorToX());
    d->cursorItem->setHeight(d->control->height());
}

void QmlGraphicsTextInput::moveCursor()
{
    Q_D(QmlGraphicsTextInput);
    if(!d->cursorItem)
        return;
    d->cursorItem->setX(d->control->cursorToX() - d->hscroll);
}

int QmlGraphicsTextInput::xToPos(int x)
{
    Q_D(const QmlGraphicsTextInput);
    return d->control->xToPos(x - d->hscroll);
}

void QmlGraphicsTextInput::focusChanged(bool hasFocus)
{
    Q_D(QmlGraphicsTextInput);
    d->focused = hasFocus;
    setCursorVisible(hasFocus);
    QmlGraphicsItem::focusChanged(hasFocus);
}

void QmlGraphicsTextInput::keyPressEvent(QKeyEvent* ev)
{
    Q_D(QmlGraphicsTextInput);
    if(((d->control->cursor() == 0 && ev->key() == Qt::Key_Left)
            || (d->control->cursor() == d->control->text().length()
                && ev->key() == Qt::Key_Right))
            && (d->lastSelectionStart == d->lastSelectionEnd)){
        //ignore when moving off the end
        //unless there is a selection, because then moving will do something (deselect)
        ev->ignore();
    }else{
        d->control->processKeyEvent(ev);
    }
    if (!ev->isAccepted())
        QmlGraphicsPaintedItem::keyPressEvent(ev);
}

void QmlGraphicsTextInput::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
    Q_D(QmlGraphicsTextInput);
    if(d->focusOnPress){
        QGraphicsItem *p = parentItem();//###Is there a better way to find my focus scope?
        while(p) {
            if(p->flags() & QGraphicsItem::ItemIsFocusScope){
                p->setFocus();
                break;
            }
            p = p->parentItem();
        }
        setFocus(true);
    }
    d->control->processEvent(event);
}

/*!
\overload
Handles the given mouse \a event.
*/
void QmlGraphicsTextInput::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
    Q_D(QmlGraphicsTextInput);
    QWidget *widget = event->widget();
    if (widget && !d->control->isReadOnly() && boundingRect().contains(event->pos()))
        qt_widget_private(widget)->handleSoftwareInputPanel(event->button(), d->focusOnPress);
    d->control->processEvent(event);
}

bool QmlGraphicsTextInput::event(QEvent* ev)
{
    Q_D(QmlGraphicsTextInput);
    //Anything we don't deal with ourselves, pass to the control
    bool handled = false;
    switch(ev->type()){
        case QEvent::KeyPress:
        case QEvent::KeyRelease://###Should the control be doing anything with release?
        case QEvent::GraphicsSceneMousePress:
        case QEvent::GraphicsSceneMouseRelease:
            break;
        default:
            handled = d->control->processEvent(ev);
    }
    if(!handled)
        return QmlGraphicsPaintedItem::event(ev);
    return true;
}

void QmlGraphicsTextInput::geometryChanged(const QRectF &newGeometry,
                                  const QRectF &oldGeometry)
{
    if (newGeometry.width() != oldGeometry.width())
        updateSize();
    QmlGraphicsPaintedItem::geometryChanged(newGeometry, oldGeometry);
}

void QmlGraphicsTextInput::drawContents(QPainter *p, const QRect &r)
{
    Q_D(QmlGraphicsTextInput);
    p->setRenderHint(QPainter::TextAntialiasing, true);
    p->save();
    p->setPen(QPen(d->color));
    int flags = QLineControl::DrawText;
    if(!isReadOnly() && d->cursorVisible && !d->cursorItem)
        flags |= QLineControl::DrawCursor;
    if (d->control->hasSelectedText()){
            flags |= QLineControl::DrawSelections;
    }

    QPoint offset = QPoint(0,0);
    if(d->hAlign != AlignLeft){