From 989a6e21ef4b10ad5a482c774a6d8e989a83e1d9 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Wed, 19 Aug 2009 11:53:26 +1000 Subject: Text-related API updates after review Rename LineEdit to TextInput; hAlign to horizontalAlignment; vAlign to verticalAlignment. Other assorted fixes. --- demos/declarative/contacts/FieldText.qml | 2 +- demos/declarative/contacts/RemoveButton.qml | 2 +- .../declarative/webbrowser/fieldtext/FieldText.qml | 2 +- demos/declarative/webbrowser/webbrowser.qml | 2 +- examples/declarative/listview/sections.qml | 2 +- examples/declarative/loader/Browser.qml | 4 +- .../1_Drawing_and_Animation/3/RemoveButton.qml | 2 +- .../1_Drawing_and_Animation/4/RemoveButton.qml | 2 +- .../1_Drawing_and_Animation/4a/RemoveButton.qml | 2 +- .../1_Drawing_and_Animation/5/RemoveButton.qml | 2 +- .../tutorials/contacts/2_Reuse/1/RemoveButton.qml | 2 +- .../tutorials/contacts/2_Reuse/1a/RemoveButton.qml | 2 +- .../contacts/2_Reuse/1b/lib/RemoveButton.qml | 2 +- .../tutorials/contacts/2_Reuse/2/RemoveButton.qml | 2 +- .../tutorials/contacts/2_Reuse/3/FieldText.qml | 2 +- .../tutorials/contacts/2_Reuse/3/RemoveButton.qml | 2 +- .../tutorials/contacts/2_Reuse/4/FieldText.qml | 2 +- .../tutorials/contacts/2_Reuse/4/RemoveButton.qml | 2 +- .../contacts/3_Collections/lib/FieldText.qml | 2 +- .../contacts/3_Collections/lib/RemoveButton.qml | 2 +- src/declarative/fx/fx.pri | 6 +- src/declarative/fx/qfxlineedit.cpp | 628 --------------------- src/declarative/fx/qfxlineedit.h | 192 ------- src/declarative/fx/qfxlineedit_p.h | 106 ---- src/declarative/fx/qfxtext.cpp | 8 +- src/declarative/fx/qfxtext.h | 4 +- src/declarative/fx/qfxtextedit.cpp | 8 +- src/declarative/fx/qfxtextedit.h | 4 +- src/declarative/fx/qfxtextinput.cpp | 626 ++++++++++++++++++++ src/declarative/fx/qfxtextinput.h | 193 +++++++ src/declarative/fx/qfxtextinput_p.h | 106 ++++ 31 files changed, 961 insertions(+), 962 deletions(-) delete mode 100644 src/declarative/fx/qfxlineedit.cpp delete mode 100644 src/declarative/fx/qfxlineedit.h delete mode 100644 src/declarative/fx/qfxlineedit_p.h create mode 100644 src/declarative/fx/qfxtextinput.cpp create mode 100644 src/declarative/fx/qfxtextinput.h create mode 100644 src/declarative/fx/qfxtextinput_p.h diff --git a/demos/declarative/contacts/FieldText.qml b/demos/declarative/contacts/FieldText.qml index a28fbbc..392d9aa 100644 --- a/demos/declarative/contacts/FieldText.qml +++ b/demos/declarative/contacts/FieldText.qml @@ -69,7 +69,7 @@ Rect { x: 5 width: parent.width-10 anchors.verticalCenter: parent.verticalCenter - hAlign: "AlignHCenter" + horizontalAlignment: "AlignHCenter" color: contactDetails.state == "editing" ? "#505050" : "#AAAAAA" font.italic: true font.bold: true diff --git a/demos/declarative/contacts/RemoveButton.qml b/demos/declarative/contacts/RemoveButton.qml index d42d359..c13b412 100644 --- a/demos/declarative/contacts/RemoveButton.qml +++ b/demos/declarative/contacts/RemoveButton.qml @@ -74,7 +74,7 @@ Rect { anchors.rightMargin: 4 font.bold: true color: "white" - hAlign: "AlignHCenter" + horizontalAlignment: "AlignHCenter" text: "Remove" opacity: 0 } diff --git a/demos/declarative/webbrowser/fieldtext/FieldText.qml b/demos/declarative/webbrowser/fieldtext/FieldText.qml index 3a9abdf..cbacfd8 100644 --- a/demos/declarative/webbrowser/fieldtext/FieldText.qml +++ b/demos/declarative/webbrowser/fieldtext/FieldText.qml @@ -82,7 +82,7 @@ Item { x: 5 width: parent.width-10 anchors.verticalCenter: parent.verticalCenter - hAlign: "AlignHCenter" + horizontalAlignment: "AlignHCenter" color: fieldText.state == "editing" ? "#505050" : "#AAAAAA" font.italic: true font.bold: true diff --git a/demos/declarative/webbrowser/webbrowser.qml b/demos/declarative/webbrowser/webbrowser.qml index c1de69b..8f1c00e 100644 --- a/demos/declarative/webbrowser/webbrowser.qml +++ b/demos/declarative/webbrowser/webbrowser.qml @@ -96,7 +96,7 @@ Item { anchors.rightMargin: 4 anchors.top: Header.top anchors.topMargin: 4 - hAlign: "AlignHCenter" + horizontalAlignment: "AlignHCenter" } Item { width: parent.width diff --git a/examples/declarative/listview/sections.qml b/examples/declarative/listview/sections.qml index ab9fbdf..41cc2e6 100644 --- a/examples/declarative/listview/sections.qml +++ b/examples/declarative/listview/sections.qml @@ -28,7 +28,7 @@ Rect { opacity: Wrapper.ListView.prevSection != Wrapper.ListView.section ? 1 : 0 Text { text: Wrapper.ListView.section; font.bold: true - x: 2; height: parent.height; vAlign: 'AlignVCenter' + x: 2; height: parent.height; verticalAlignment: 'AlignVCenter' } } Item { diff --git a/examples/declarative/loader/Browser.qml b/examples/declarative/loader/Browser.qml index d5887d7..78b26dc 100644 --- a/examples/declarative/loader/Browser.qml +++ b/examples/declarative/loader/Browser.qml @@ -41,7 +41,7 @@ Rect { } Text { id: NameText - anchors.fill: parent; vAlign: "AlignVCenter" + anchors.fill: parent; verticalAlignment: "AlignVCenter" text: fileName; anchors.leftMargin: 32 font.pointSize: 10 color: activePalette.windowText @@ -107,7 +107,7 @@ Rect { anchors.left: UpButton.right; anchors.right: parent.right; height: parent.height anchors.leftMargin: 4; anchors.rightMargin: 4 text: folders.folder; color: activePalette.buttonText - elide: "ElideLeft"; hAlign: "AlignRight"; vAlign: "AlignVCenter" + elide: "ElideLeft"; horizontalAlignment: "AlignRight"; verticalAlignment: "AlignVCenter" } } } diff --git a/examples/declarative/tutorials/contacts/1_Drawing_and_Animation/3/RemoveButton.qml b/examples/declarative/tutorials/contacts/1_Drawing_and_Animation/3/RemoveButton.qml index 6426457..f1b72ab 100644 --- a/examples/declarative/tutorials/contacts/1_Drawing_and_Animation/3/RemoveButton.qml +++ b/examples/declarative/tutorials/contacts/1_Drawing_and_Animation/3/RemoveButton.qml @@ -34,7 +34,7 @@ Rect { anchors.rightMargin: 4 font.bold: true color: "white" - hAlign: "AlignHCenter" + horizontalAlignment: "AlignHCenter" text: "Remove" } } diff --git a/examples/declarative/tutorials/contacts/1_Drawing_and_Animation/4/RemoveButton.qml b/examples/declarative/tutorials/contacts/1_Drawing_and_Animation/4/RemoveButton.qml index c97426c..dfb79a6 100644 --- a/examples/declarative/tutorials/contacts/1_Drawing_and_Animation/4/RemoveButton.qml +++ b/examples/declarative/tutorials/contacts/1_Drawing_and_Animation/4/RemoveButton.qml @@ -73,7 +73,7 @@ Rect { anchors.rightMargin: 4 font.bold: true color: "white" - hAlign: "AlignHCenter" + horizontalAlignment: "AlignHCenter" text: "Remove" opacity: 0 } diff --git a/examples/declarative/tutorials/contacts/1_Drawing_and_Animation/4a/RemoveButton.qml b/examples/declarative/tutorials/contacts/1_Drawing_and_Animation/4a/RemoveButton.qml index 712471f..d4f30eb 100644 --- a/examples/declarative/tutorials/contacts/1_Drawing_and_Animation/4a/RemoveButton.qml +++ b/examples/declarative/tutorials/contacts/1_Drawing_and_Animation/4a/RemoveButton.qml @@ -80,7 +80,7 @@ Rect { anchors.rightMargin: 4 font.bold: true color: "white" - hAlign: "AlignHCenter" + horizontalAlignment: "AlignHCenter" text: "Remove" opacity: 0 } diff --git a/examples/declarative/tutorials/contacts/1_Drawing_and_Animation/5/RemoveButton.qml b/examples/declarative/tutorials/contacts/1_Drawing_and_Animation/5/RemoveButton.qml index acc9896..292eb45 100644 --- a/examples/declarative/tutorials/contacts/1_Drawing_and_Animation/5/RemoveButton.qml +++ b/examples/declarative/tutorials/contacts/1_Drawing_and_Animation/5/RemoveButton.qml @@ -69,7 +69,7 @@ Rect { anchors.rightMargin: 4 font.bold: true color: "white" - hAlign: "AlignHCenter" + horizontalAlignment: "AlignHCenter" text: "Remove" opacity: 0 } diff --git a/examples/declarative/tutorials/contacts/2_Reuse/1/RemoveButton.qml b/examples/declarative/tutorials/contacts/2_Reuse/1/RemoveButton.qml index 5392154..f74ff99 100644 --- a/examples/declarative/tutorials/contacts/2_Reuse/1/RemoveButton.qml +++ b/examples/declarative/tutorials/contacts/2_Reuse/1/RemoveButton.qml @@ -69,7 +69,7 @@ Rect { anchors.rightMargin: 4 font.bold: true color: "white" - hAlign: "AlignHCenter" + horizontalAlignment: "AlignHCenter" text: "Remove" opacity: 0 } diff --git a/examples/declarative/tutorials/contacts/2_Reuse/1a/RemoveButton.qml b/examples/declarative/tutorials/contacts/2_Reuse/1a/RemoveButton.qml index 5392154..f74ff99 100644 --- a/examples/declarative/tutorials/contacts/2_Reuse/1a/RemoveButton.qml +++ b/examples/declarative/tutorials/contacts/2_Reuse/1a/RemoveButton.qml @@ -69,7 +69,7 @@ Rect { anchors.rightMargin: 4 font.bold: true color: "white" - hAlign: "AlignHCenter" + horizontalAlignment: "AlignHCenter" text: "Remove" opacity: 0 } diff --git a/examples/declarative/tutorials/contacts/2_Reuse/1b/lib/RemoveButton.qml b/examples/declarative/tutorials/contacts/2_Reuse/1b/lib/RemoveButton.qml index e47aff2..d21b297 100644 --- a/examples/declarative/tutorials/contacts/2_Reuse/1b/lib/RemoveButton.qml +++ b/examples/declarative/tutorials/contacts/2_Reuse/1b/lib/RemoveButton.qml @@ -71,7 +71,7 @@ Rect { anchors.rightMargin: 4 font.bold: true color: "white" - hAlign: "AlignHCenter" + horizontalAlignment: "AlignHCenter" text: "Remove" opacity: 0 } diff --git a/examples/declarative/tutorials/contacts/2_Reuse/2/RemoveButton.qml b/examples/declarative/tutorials/contacts/2_Reuse/2/RemoveButton.qml index 32e8ce0..9a7e0d7 100644 --- a/examples/declarative/tutorials/contacts/2_Reuse/2/RemoveButton.qml +++ b/examples/declarative/tutorials/contacts/2_Reuse/2/RemoveButton.qml @@ -75,7 +75,7 @@ Rect { anchors.rightMargin: 4 font.bold: true color: "white" - hAlign: "AlignHCenter" + horizontalAlignment: "AlignHCenter" text: "Remove" opacity: 0 } diff --git a/examples/declarative/tutorials/contacts/2_Reuse/3/FieldText.qml b/examples/declarative/tutorials/contacts/2_Reuse/3/FieldText.qml index e0651c8..3130bbe 100644 --- a/examples/declarative/tutorials/contacts/2_Reuse/3/FieldText.qml +++ b/examples/declarative/tutorials/contacts/2_Reuse/3/FieldText.qml @@ -67,7 +67,7 @@ Rect { x: 5 width: parent.width-10 anchors.verticalCenter: parent.verticalCenter - hAlign: "AlignHCenter" + horizontalAlignment: "AlignHCenter" color: "#505050" font.italic: true text: fieldText.label diff --git a/examples/declarative/tutorials/contacts/2_Reuse/3/RemoveButton.qml b/examples/declarative/tutorials/contacts/2_Reuse/3/RemoveButton.qml index 6280877..b99ab84 100644 --- a/examples/declarative/tutorials/contacts/2_Reuse/3/RemoveButton.qml +++ b/examples/declarative/tutorials/contacts/2_Reuse/3/RemoveButton.qml @@ -72,7 +72,7 @@ Rect { anchors.rightMargin: 4 font.bold: true color: "white" - hAlign: "AlignHCenter" + horizontalAlignment: "AlignHCenter" text: "Remove" opacity: 0 } diff --git a/examples/declarative/tutorials/contacts/2_Reuse/4/FieldText.qml b/examples/declarative/tutorials/contacts/2_Reuse/4/FieldText.qml index 21e3bf2..369d34d 100644 --- a/examples/declarative/tutorials/contacts/2_Reuse/4/FieldText.qml +++ b/examples/declarative/tutorials/contacts/2_Reuse/4/FieldText.qml @@ -69,7 +69,7 @@ Rect { x: 5 width: parent.width-10 anchors.verticalCenter: parent.verticalCenter - hAlign: "AlignHCenter" + horizontalAlignment: "AlignHCenter" color: "#505050" font.italic: true text: fieldText.label diff --git a/examples/declarative/tutorials/contacts/2_Reuse/4/RemoveButton.qml b/examples/declarative/tutorials/contacts/2_Reuse/4/RemoveButton.qml index 03b50eec..f4a55e1 100644 --- a/examples/declarative/tutorials/contacts/2_Reuse/4/RemoveButton.qml +++ b/examples/declarative/tutorials/contacts/2_Reuse/4/RemoveButton.qml @@ -77,7 +77,7 @@ Rect { anchors.rightMargin: 4 font.bold: true color: "white" - hAlign: "AlignHCenter" + horizontalAlignment: "AlignHCenter" text: "Remove" opacity: 0 } diff --git a/examples/declarative/tutorials/contacts/3_Collections/lib/FieldText.qml b/examples/declarative/tutorials/contacts/3_Collections/lib/FieldText.qml index 4506ec9..93ac0f8 100644 --- a/examples/declarative/tutorials/contacts/3_Collections/lib/FieldText.qml +++ b/examples/declarative/tutorials/contacts/3_Collections/lib/FieldText.qml @@ -69,7 +69,7 @@ Rect { x: 5 width: parent.width-10 anchors.verticalCenter: parent.verticalCenter - hAlign: "AlignHCenter" + horizontalAlignment: "AlignHCenter" color: "#505050" font.italic: true text: fieldText.label diff --git a/examples/declarative/tutorials/contacts/3_Collections/lib/RemoveButton.qml b/examples/declarative/tutorials/contacts/3_Collections/lib/RemoveButton.qml index 866a23f..d96a932 100644 --- a/examples/declarative/tutorials/contacts/3_Collections/lib/RemoveButton.qml +++ b/examples/declarative/tutorials/contacts/3_Collections/lib/RemoveButton.qml @@ -75,7 +75,7 @@ Rect { anchors.rightMargin: 4 font.bold: true color: "white" - hAlign: "AlignHCenter" + horizontalAlignment: "AlignHCenter" text: "Remove" opacity: 0 } diff --git a/src/declarative/fx/fx.pri b/src/declarative/fx/fx.pri index 48af58e..47cce95 100644 --- a/src/declarative/fx/fx.pri +++ b/src/declarative/fx/fx.pri @@ -35,8 +35,8 @@ HEADERS += \ fx/qfxrepeater.h \ fx/qfxrepeater_p.h \ fx/qfxscalegrid_p.h \ - fx/qfxlineedit.h \ - fx/qfxlineedit_p.h \ + fx/qfxtextinput.h \ + fx/qfxtextinput_p.h \ fx/qfxtextedit.h \ fx/qfxtextedit_p.h \ fx/qfxtext.h \ @@ -69,7 +69,7 @@ SOURCES += \ fx/qfxrect.cpp \ fx/qfxrepeater.cpp \ fx/qfxscalegrid.cpp \ - fx/qfxlineedit.cpp \ + fx/qfxtextinput.cpp \ fx/qfxtext.cpp \ fx/qfxtextedit.cpp \ fx/qfxpixmapcache.cpp \ diff --git a/src/declarative/fx/qfxlineedit.cpp b/src/declarative/fx/qfxlineedit.cpp deleted file mode 100644 index 6e93782..0000000 --- a/src/declarative/fx/qfxlineedit.cpp +++ /dev/null @@ -1,628 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (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 either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** 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.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qfxlineedit.h" -#include "qfxlineedit_p.h" -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,LineEdit,QFxLineEdit); -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,QIntValidator,QIntValidator); - -/*! - \qmlclass LineEdit - The LineEdit item allows you to add an editable line of text to a scene. -*/ -QFxLineEdit::QFxLineEdit(QFxItem* parent) - : QFxPaintedItem(*(new QFxLineEditPrivate), parent) -{ - Q_D(QFxLineEdit); - d->init(); -} - -/* - \internal -*/ -QFxLineEdit::QFxLineEdit(QFxLineEditPrivate &dd, QFxItem* parent) - : QFxPaintedItem(dd, parent) -{ - Q_D(QFxLineEdit); - d->init(); -} - -QFxLineEdit::~QFxLineEdit() -{ -} - -/*! - \qmlproperty string LineEdit::text - - The text in the LineEdit. -*/ - -QString QFxLineEdit::text() const -{ - Q_D(const QFxLineEdit); - return d->control->text(); -} - -void QFxLineEdit::setText(const QString &s) -{ - Q_D(QFxLineEdit); - if(s == text()) - return; - d->control->setText(s); - //emit textChanged(); -} - -/*! - \qmlproperty font LineEdit::font - - Set the LineEdit's font attributes. \c font.size sets the font's point size. -*/ -QFont QFxLineEdit::font() const -{ - Q_D(const QFxLineEdit); - return d->font; -} - -void QFxLineEdit::setFont(const QFont &font) -{ - Q_D(QFxLineEdit); - d->font = font; - - d->control->setFont(d->font); - if(d->cursorItem){ - d->cursorItem->setHeight(QFontMetrics(d->font).height()); - moveCursor(); - } - //updateSize(); - updateAll();//TODO: Only necessary updates - update(); -} - -/*! - \qmlproperty color LineEdit::color - - The text color. -*/ -QColor QFxLineEdit::color() const -{ - Q_D(const QFxLineEdit); - return d->color; -} - -void QFxLineEdit::setColor(const QColor &c) -{ - Q_D(QFxLineEdit); - d->color = c; -} - - -/*! - \qmlproperty color LineEdit::highlightColor - - The text highlight color, used behind selections. -*/ -QColor QFxLineEdit::highlightColor() const -{ - Q_D(const QFxLineEdit); - return d->highlightColor; -} - -void QFxLineEdit::setHighlightColor(const QColor &color) -{ - Q_D(QFxLineEdit); - if (d->highlightColor == color) - return; - - d->highlightColor = color; - //TODO: implement -} - -/*! - \qmlproperty color LineEdit::highlightedTextColor - - The highlighted text color, used in selections. -*/ -QColor QFxLineEdit::highlightedTextColor() const -{ - Q_D(const QFxLineEdit); - return d->highlightedTextColor; -} - -void QFxLineEdit::setHighlightedTextColor(const QColor &color) -{ - Q_D(QFxLineEdit); - if (d->highlightedTextColor == color) - return; - - d->highlightedTextColor = color; - //TODO: implement -} - -QFxLineEdit::HAlignment QFxLineEdit::hAlign() const -{ - Q_D(const QFxLineEdit); - return d->hAlign; -} - -void QFxLineEdit::setHAlign(HAlignment align) -{ - Q_D(QFxLineEdit); - d->hAlign = align; -} - -bool QFxLineEdit::isReadOnly() const -{ - Q_D(const QFxLineEdit); - return d->control->isReadOnly(); -} - -void QFxLineEdit::setReadOnly(bool ro) -{ - Q_D(QFxLineEdit); - d->control->setReadOnly(ro); -} - -int QFxLineEdit::maxLength() const -{ - Q_D(const QFxLineEdit); - return d->control->maxLength(); -} - -void QFxLineEdit::setMaxLength(int ml) -{ - Q_D(QFxLineEdit); - d->control->setMaxLength(ml); -} - -/*! - \qmlproperty bool LineEdit::cursorVisible - If true the text edit shows a cursor. - - This property is set and unset when the line edit gets focus, but it can also - be set directly (useful, for example, if a KeyProxy might forward keys to it). -*/ -bool QFxLineEdit::isCursorVisible() const -{ - Q_D(const QFxLineEdit); - return d->cursorVisible; -} - -void QFxLineEdit::setCursorVisible(bool on) -{ - Q_D(QFxLineEdit); - if (d->cursorVisible == on) - return; - d->cursorVisible = on; - d->control->setCursorBlinkPeriod(on?QApplication::cursorFlashTime():0); - updateAll();//TODO: Only update cursor rect -} - -/*! - \qmlproperty int LineEdit::cursorPosition - The position of the cursor in the LineEdit. -*/ -int QFxLineEdit::cursorPosition() const -{ - Q_D(const QFxLineEdit); - return d->control->cursor(); -} -void QFxLineEdit::setCursorPosition(int cp) -{ - Q_D(QFxLineEdit); - d->control->moveCursor(cp); -} - -/*! - \qmlproperty int LineEdit::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 QFxLineEdit::selectionStart() const -{ - Q_D(const QFxLineEdit); - return d->lastSelectionStart; -} - -void QFxLineEdit::setSelectionStart(int s) -{ - Q_D(QFxLineEdit); - if(d->lastSelectionStart == s || s < 0 || s > text().length()) - return; - d->lastSelectionStart = s; - d->control->setSelection(s, d->lastSelectionEnd - s); -} - -/*! - \qmlproperty int LineEdit::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 QFxLineEdit::selectionEnd() const -{ - Q_D(const QFxLineEdit); - return d->lastSelectionEnd; -} - -void QFxLineEdit::setSelectionEnd(int s) -{ - Q_D(QFxLineEdit); - if(d->lastSelectionEnd == s || s < 0 || s > text().length()) - return; - d->lastSelectionEnd = s; - d->control->setSelection(d->lastSelectionStart, s - d->lastSelectionStart); -} - -QString QFxLineEdit::selectedText() const -{ - Q_D(const QFxLineEdit); - return d->control->selectedText(); -} - -QObject* QFxLineEdit::validator() const -{ - Q_D(const QFxLineEdit); - //###const cast isn't good, but needed for property system? - //###same should be said about using QObject* as the property type - return const_cast(d->control->validator()); -} - -void QFxLineEdit::setValidator(QObject* v) -{ - Q_D(QFxLineEdit); - QValidator* valid = qobject_cast(v); - if(!valid) - return; - d->control->setValidator(valid); - if(!d->control->hasAcceptableInput()){ - d->oldValidity = false; - emit acceptableInputChanged(); - } -} - -QString QFxLineEdit::inputMask() const -{ - Q_D(const QFxLineEdit); - return d->control->inputMask(); -} - -void QFxLineEdit::setInputMask(const QString &im) -{ - Q_D(QFxLineEdit); - d->control->setInputMask(im); -} - -bool QFxLineEdit::hasAcceptableInput() const -{ - Q_D(const QFxLineEdit); - return d->control->hasAcceptableInput(); -} - -uint QFxLineEdit::echoMode() const -{ - Q_D(const QFxLineEdit); - return d->control->echoMode(); -} - -void QFxLineEdit::setEchoMode(uint echo) -{ - Q_D(QFxLineEdit); - d->control->setEchoMode(echo); -} - -/*! - \qmlproperty Component LineEdit::cursorDelegate - The delegate for the cursor in the LineEdit. - - If you set a cursorDelegate for a LineEdit, 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 LineEdit 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 QFxItem or - QFxItem derived item. -*/ -QmlComponent* QFxLineEdit::cursorDelegate() const -{ - Q_D(const QFxLineEdit); - return d->cursorComponent; -} - -void QFxLineEdit::setCursorDelegate(QmlComponent* c) -{ - Q_D(QFxLineEdit); - if(d->cursorComponent) - delete d->cursorComponent; - d->cursorComponent = c; - d->startCreatingCursor(); -} - -void QFxLineEditPrivate::startCreatingCursor() -{ - Q_Q(QFxLineEdit); - if(!cursorComponent){ - q->disconnect(control, SIGNAL(cursorPositionChanged(int, int)), - q, SLOT(moveCursor())); - return; - } - 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 - qWarning() << "You could really use the error checking for QFxLineEdit. We'll implement it soon."; - } -} - -void QFxLineEdit::createCursor() -{ - Q_D(QFxLineEdit); - //Handle isError too - if(!d->cursorComponent->isReady()) - return; - - if(d->cursorItem) - delete d->cursorItem; - d->cursorItem = qobject_cast(d->cursorComponent->create()); - if(!d->cursorItem){ - qWarning() << "You could really use the error reporting for QFxLineEdit. We'll implement it soon."; - return; - } - - d->cursorItem->setParentItem(this); - d->cursorItem->setX(d->control->cursorToX()); - d->cursorItem->setHeight(d->control->height()); -} - -void QFxLineEdit::moveCursor() -{ - Q_D(QFxLineEdit); - if(!d->cursorItem) - return; - d->cursorItem->setX(d->control->cursorToX() - d->hscroll); -} - -int QFxLineEdit::xToPos(int x) -{ - Q_D(const QFxLineEdit); - return d->control->xToPos(x - d->hscroll); -} - -void QFxLineEdit::focusChanged(bool hasFocus) -{ - Q_D(QFxLineEdit); - d->focused = hasFocus; - setCursorVisible(hasFocus); - QFxItem::focusChanged(hasFocus); -} - -void QFxLineEdit::keyPressEvent(QKeyEvent* ev) -{ - Q_D(QFxLineEdit); - d->control->processKeyEvent(ev); - if (!ev->isAccepted()) - QFxPaintedItem::keyPressEvent(ev); -} - -void QFxLineEdit::mousePressEvent(QGraphicsSceneMouseEvent *event) -{ - Q_D(QFxLineEdit); - setFocus(true);//###Should we make 'focusOnPress' be optional like TextEdit? - setCursorVisible(true); - d->focused = true; - d->control->processEvent(event); - //event->accept(); -} - -bool QFxLineEdit::event(QEvent* ev) -{ - Q_D(QFxLineEdit); - //Anything we don't deal with ourselves, pass to the control - switch(ev->type()){ - case QEvent::GraphicsSceneMousePress: - break; - default: - return d->control->processEvent(ev); - } - return false; -} - -void QFxLineEdit::geometryChanged(const QRectF &newGeometry, - const QRectF &oldGeometry) -{ - if (newGeometry.width() != oldGeometry.width()) - updateSize(); - QFxPaintedItem::geometryChanged(newGeometry, oldGeometry); -} - -void QFxLineEdit::drawContents(QPainter *p, const QRect &r) -{ - Q_D(QFxLineEdit); - 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; - - d->control->draw(p, QPoint(0,0), r, flags); - - p->restore(); -} - -/*! - \qmlproperty bool LineEdit::smooth - - Set this property if you want the text to be smoothly scaled or - transformed. Smooth filtering gives better visual quality, but is slower. If - the item is displayed at its natural size, this property has no visual or - performance effect. - - \note Generally scaling artifacts are only visible if the item is stationary on - the screen. A common pattern when animating an item is to disable smooth - filtering at the beginning of the animation and reenable it at the conclusion. -*/ - -void QFxLineEditPrivate::init() -{ - Q_Q(QFxLineEdit); - control->setCursorWidth(1); - control->setPasswordCharacter(QLatin1Char('*')); - control->setLayoutDirection(Qt::LeftToRight); - q->setSmoothTransform(smooth); - q->setAcceptedMouseButtons(Qt::LeftButton); - q->setFlag(QGraphicsItem::ItemHasNoContents, false); - q->setFlag(QGraphicsItem::ItemAcceptsInputMethod); - q->connect(control, SIGNAL(cursorPositionChanged(int,int)), - q, SLOT(cursorPosChanged())); - q->connect(control, SIGNAL(selectionChanged()), - q, SLOT(selectionChanged())); - q->connect(control, SIGNAL(textChanged(const QString &)), - 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(cursorPositionChanged(int,int)), - q, SLOT(updateAll())); - q->connect(control, SIGNAL(selectionChanged()), - q, SLOT(updateAll())); - q->updateSize(); - oldValidity = control->hasAcceptableInput(); - lastSelectionStart = 0; - lastSelectionEnd = 0; -} - -void QFxLineEdit::cursorPosChanged() -{ - Q_D(QFxLineEdit); - emit cursorPositionChanged(); - - if(!d->control->hasSelectedText()){ - if(d->lastSelectionStart != d->control->cursor()){ - d->lastSelectionStart = d->control->cursor(); - emit selectionStartChanged(); - } - if(d->lastSelectionEnd != d->control->cursor()){ - d->lastSelectionEnd = d->control->cursor(); - emit selectionEndChanged(); - } - } -} - -void QFxLineEdit::selectionChanged() -{ - Q_D(QFxLineEdit); - emit selectedTextChanged(); - - if(d->lastSelectionStart != d->control->selectionStart()){ - d->lastSelectionStart = d->control->selectionStart(); - if(d->lastSelectionStart == -1) - d->lastSelectionStart = d->control->cursor(); - emit selectionStartChanged(); - } - if(d->lastSelectionEnd != d->control->selectionEnd()){ - d->lastSelectionEnd = d->control->selectionEnd(); - if(d->lastSelectionEnd == -1) - d->lastSelectionEnd = d->control->cursor(); - emit selectionEndChanged(); - } -} - -void QFxLineEdit::q_textChanged() -{ - Q_D(QFxLineEdit); - updateAll(); - emit textChanged(); - if(hasAcceptableInput() != d->oldValidity){ - d->oldValidity = hasAcceptableInput(); - emit acceptableInputChanged(); - } -} - -//### Please replace this function with proper updating -void QFxLineEdit::updateAll() -{ - clearCache(); - updateSize(); - update(); -} - -void QFxLineEdit::updateSize() -{ - Q_D(QFxLineEdit); - setImplicitHeight(d->control->height()); - //d->control->width() is max width, not current width - QFontMetrics fm = QFontMetrics(d->font); - setImplicitWidth(fm.boundingRect(d->control->text()).width()+1); - setContentsSize(QSize(width(), height())); -} - -QT_END_NAMESPACE - diff --git a/src/declarative/fx/qfxlineedit.h b/src/declarative/fx/qfxlineedit.h deleted file mode 100644 index 1f4a5c6..0000000 --- a/src/declarative/fx/qfxlineedit.h +++ /dev/null @@ -1,192 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (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 either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** 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.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QFXLINEEDIT_H -#define QFXLINEEDIT_H - -#include "qfxtext.h" -#include "qfxpainteditem.h" -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QFxLineEditPrivate; -class QValidator; -//### class QFxTextInput?? -class Q_DECLARATIVE_EXPORT QFxLineEdit : public QFxPaintedItem -{ - Q_OBJECT - Q_ENUMS(HAlignment) - - Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged) - Q_PROPERTY(QColor color READ color WRITE setColor) - Q_PROPERTY(QColor highlightColor READ highlightColor WRITE setHighlightColor) //### selectionColor - Q_PROPERTY(QColor highlightedTextColor READ highlightedTextColor WRITE setHighlightedTextColor) //### selectedTextColor - Q_PROPERTY(QFont font READ font WRITE setFont) - Q_PROPERTY(HAlignment hAlign READ hAlign WRITE setHAlign) //### horizontalAlignment - - Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly) - Q_PROPERTY(bool cursorVisible READ isCursorVisible WRITE setCursorVisible) - Q_PROPERTY(int cursorPosition READ cursorPosition WRITE setCursorPosition NOTIFY cursorPositionChanged) - Q_PROPERTY(QmlComponent *cursorDelegate READ cursorDelegate WRITE setCursorDelegate) - Q_PROPERTY(int selectionStart READ selectionStart WRITE setSelectionStart NOTIFY selectionStartChanged) - Q_PROPERTY(int selectionEnd READ selectionEnd WRITE setSelectionEnd NOTIFY selectionEndChanged) - Q_PROPERTY(QString selectedText READ selectedText NOTIFY selectedTextChanged) - - Q_PROPERTY(int maxLength READ maxLength WRITE setMaxLength) //### maximumLength - Q_PROPERTY(QObject* validator READ validator WRITE setValidator) //### QValidator * - Q_PROPERTY(QString inputMask READ inputMask WRITE setInputMask) - Q_PROPERTY(bool acceptableInput READ hasAcceptableInput NOTIFY acceptableInputChanged) - Q_PROPERTY(uint echoMode READ echoMode WRITE setEchoMode) //### enum - //### Q_PROPERTY(bool focusOnPress READ focusOnPress WRITE setFocusOnPress) - -public: - QFxLineEdit(QFxItem* parent=0); - ~QFxLineEdit(); - - enum HAlignment { - AlignLeft = Qt::AlignLeft, - AlignRight = Qt::AlignRight, - AlignHCenter = Qt::AlignHCenter - }; - - //### Should we have this function, x based properties, - //### or copy TextEdit with x instead of QTextCursor? - Q_INVOKABLE int xToPos(int x); - - QString text() const; - void setText(const QString &); - - QFont font() const; - void setFont(const QFont &font); - - QColor color() const; - void setColor(const QColor &c); - - QColor highlightColor() const; - void setHighlightColor(const QColor &c); - - QColor highlightedTextColor() const; - void setHighlightedTextColor(const QColor &c); - - HAlignment hAlign() const; - void setHAlign(HAlignment align); - - bool isReadOnly() const; - void setReadOnly(bool); - - bool isCursorVisible() const; - void setCursorVisible(bool on); - - int cursorPosition() const; - void setCursorPosition(int cp); - - int selectionStart() const; - void setSelectionStart(int); - - int selectionEnd() const; - void setSelectionEnd(int); - - QString selectedText() const; - - int maxLength() const; - void setMaxLength(int ml); - - QObject * validator() const; - void setValidator(QObject* v); - - QString inputMask() const; - void setInputMask(const QString &im); - - uint echoMode() const; - void setEchoMode(uint echo); - - QmlComponent* cursorDelegate() const; - void setCursorDelegate(QmlComponent*); - - bool hasAcceptableInput() const; - - void drawContents(QPainter *p,const QRect &r); -Q_SIGNALS: - void textChanged(); - void cursorPositionChanged(); - void selectionStartChanged(); - void selectionEndChanged(); - void selectedTextChanged(); - void accepted(); - void acceptableInputChanged(); - -protected: - QFxLineEdit(QFxLineEditPrivate &dd, QFxItem *parent); - virtual void geometryChanged(const QRectF &newGeometry, - const QRectF &oldGeometry); - - void mousePressEvent(QGraphicsSceneMouseEvent *event); - void keyPressEvent(QKeyEvent* ev); - bool event(QEvent *e); - - void focusChanged(bool hasFocus); - -private Q_SLOTS: - void updateSize(); - void q_textChanged(); - void selectionChanged(); - void updateAll(); - void createCursor(); - void moveCursor(); - void cursorPosChanged(); - -private: - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr, QFxLineEdit); -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QFxLineEdit) -QML_DECLARE_TYPE(QIntValidator) - -QT_END_HEADER -#endif // QFXLINEEDIT_H diff --git a/src/declarative/fx/qfxlineedit_p.h b/src/declarative/fx/qfxlineedit_p.h deleted file mode 100644 index 369669f..0000000 --- a/src/declarative/fx/qfxlineedit_p.h +++ /dev/null @@ -1,106 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (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 either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** 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.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QFXLINEEDIT_P_H -#define QFXLINEEDIT_P_H - -#include "qfxlineedit.h" -#include "qml.h" -#include "qfxpainteditem_p.h" -#include "private/qlinecontrol_p.h" -#include -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. - -QT_BEGIN_NAMESPACE - -class QFxLineEditPrivate : public QFxPaintedItemPrivate -{ - Q_DECLARE_PUBLIC(QFxLineEdit); -public: - QFxLineEditPrivate() : control(new QLineControl(QString())), - color((QRgb)0), style(QFxText::Normal), - styleColor((QRgb)0), hAlign(QFxLineEdit::AlignLeft), - hscroll(0), oldScroll(0), focused(false), cursorVisible(false) - { - } - - ~QFxLineEditPrivate() - { - } - - void init(); - void startCreatingCursor(); - - QLineControl* control; - - QFont font; - QColor color; - QColor highlightColor; - QColor highlightedTextColor; - QFxText::TextStyle style; - QColor styleColor; - QFxLineEdit::HAlignment hAlign; - QPointer cursorComponent; - QPointer cursorItem; - - int lastSelectionStart; - int lastSelectionEnd; - int oldHeight; - int oldWidth; - bool oldValidity; - int hscroll; - int oldScroll; - bool focused; - bool cursorVisible; -}; - -QT_END_NAMESPACE - -#endif - diff --git a/src/declarative/fx/qfxtext.cpp b/src/declarative/fx/qfxtext.cpp index cd34aa0..43f2656 100644 --- a/src/declarative/fx/qfxtext.cpp +++ b/src/declarative/fx/qfxtext.cpp @@ -299,14 +299,14 @@ QColor QFxText::styleColor() const } /*! - \qmlproperty enumeration Text::hAlign - \qmlproperty enumeration Text::vAlign + \qmlproperty enumeration Text::horizontalAlignment + \qmlproperty enumeration Text::verticalAlignment Sets the horizontal and vertical alignment of the text within the Text items width and height. By default, the text is top-left aligned. - The valid values for \c hAlign are \c AlignLeft, \c AlignRight and - \c AlignHCenter. The valid values for \c vAlign are \c AlignTop, \c AlignBottom + The valid values for \c horizontalAlignment are \c AlignLeft, \c AlignRight and + \c AlignHCenter. The valid values for \c verticalAlignment are \c AlignTop, \c AlignBottom and \c AlignVCenter. */ diff --git a/src/declarative/fx/qfxtext.h b/src/declarative/fx/qfxtext.h index 63fb3e9..fcfe2b1 100644 --- a/src/declarative/fx/qfxtext.h +++ b/src/declarative/fx/qfxtext.h @@ -63,8 +63,8 @@ class Q_DECLARATIVE_EXPORT QFxText : public QFxItem Q_PROPERTY(QColor color READ color WRITE setColor) Q_PROPERTY(TextStyle style READ style WRITE setStyle) Q_PROPERTY(QColor styleColor READ styleColor WRITE setStyleColor) - Q_PROPERTY(HAlignment hAlign READ hAlign WRITE setHAlign) // ### horizontalAlignment? - Q_PROPERTY(VAlignment vAlign READ vAlign WRITE setVAlign) // ### verticalAlignment? + Q_PROPERTY(HAlignment horizontalAlignment READ hAlign WRITE setHAlign) + Q_PROPERTY(VAlignment verticalAlignment READ vAlign WRITE setVAlign) Q_PROPERTY(bool wrap READ wrap WRITE setWrap) //### there are several wrap modes in Qt Q_PROPERTY(TextFormat textFormat READ textFormat WRITE setTextFormat) Q_PROPERTY(Qt::TextElideMode elide READ elideMode WRITE setElideMode) //### elideMode? diff --git a/src/declarative/fx/qfxtextedit.cpp b/src/declarative/fx/qfxtextedit.cpp index 5014185..f7f5f0a 100644 --- a/src/declarative/fx/qfxtextedit.cpp +++ b/src/declarative/fx/qfxtextedit.cpp @@ -316,14 +316,14 @@ void QFxTextEdit::setHighlightedTextColor(const QColor &color) } /*! - \qmlproperty enumeration TextEdit::hAlign - \qmlproperty enumeration TextEdit::vAlign + \qmlproperty enumeration TextEdit::horizontalAlignment + \qmlproperty enumeration TextEdit::verticalAlignment Sets the horizontal and vertical alignment of the text within the TextEdit items width and height. By default, the text is top-left aligned. - The valid values for \c hAlign are \c AlignLeft, \c AlignRight and - \c AlignHCenter. The valid values for \c vAlign are \c AlignTop, \c AlignBottom + The valid values for \c horizontalAlignment are \c AlignLeft, \c AlignRight and + \c AlignHCenter. The valid values for \c verticalAlignment are \c AlignTop, \c AlignBottom and \c AlignVCenter. */ QFxTextEdit::HAlignment QFxTextEdit::hAlign() const diff --git a/src/declarative/fx/qfxtextedit.h b/src/declarative/fx/qfxtextedit.h index 8c402b0..f24faf9 100644 --- a/src/declarative/fx/qfxtextedit.h +++ b/src/declarative/fx/qfxtextedit.h @@ -71,8 +71,8 @@ class Q_DECLARATIVE_EXPORT QFxTextEdit : public QFxPaintedItem Q_PROPERTY(QColor highlightColor READ highlightColor WRITE setHighlightColor) //### selectionColor Q_PROPERTY(QColor highlightedTextColor READ highlightedTextColor WRITE setHighlightedTextColor) //### selectedTextColor Q_PROPERTY(QFont font READ font WRITE setFont) - Q_PROPERTY(HAlignment hAlign READ hAlign WRITE setHAlign) //### horizontalAlignment - Q_PROPERTY(VAlignment vAlign READ vAlign WRITE setVAlign) //### verticalAlignment + Q_PROPERTY(HAlignment horizontalAlignment READ hAlign WRITE setHAlign) + Q_PROPERTY(VAlignment verticalAlignment READ vAlign WRITE setVAlign) Q_PROPERTY(bool wrap READ wrap WRITE setWrap) //### other wrap modes Q_PROPERTY(TextFormat textFormat READ textFormat WRITE setTextFormat) Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly) diff --git a/src/declarative/fx/qfxtextinput.cpp b/src/declarative/fx/qfxtextinput.cpp new file mode 100644 index 0000000..1407a78 --- /dev/null +++ b/src/declarative/fx/qfxtextinput.cpp @@ -0,0 +1,626 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qfxtextinput.h" +#include "qfxtextinput_p.h" +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,TextInput,QFxTextInput); +QML_DEFINE_NOCREATE_TYPE(QValidator); +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,QIntValidator,QIntValidator); + +/*! + \qmlclass LineEdit + The LineEdit item allows you to add an editable line of text to a scene. +*/ +QFxTextInput::QFxTextInput(QFxItem* parent) + : QFxPaintedItem(*(new QFxTextInputPrivate), parent) +{ + Q_D(QFxTextInput); + d->init(); +} + +/* + \internal +*/ +QFxTextInput::QFxTextInput(QFxTextInputPrivate &dd, QFxItem* parent) + : QFxPaintedItem(dd, parent) +{ + Q_D(QFxTextInput); + d->init(); +} + +QFxTextInput::~QFxTextInput() +{ +} + +/*! + \qmlproperty string LineEdit::text + + The text in the LineEdit. +*/ + +QString QFxTextInput::text() const +{ + Q_D(const QFxTextInput); + return d->control->text(); +} + +void QFxTextInput::setText(const QString &s) +{ + Q_D(QFxTextInput); + if(s == text()) + return; + d->control->setText(s); + //emit textChanged(); +} + +/*! + \qmlproperty font LineEdit::font + + Set the LineEdit's font attributes. \c font.size sets the font's point size. +*/ +QFont QFxTextInput::font() const +{ + Q_D(const QFxTextInput); + return d->font; +} + +void QFxTextInput::setFont(const QFont &font) +{ + Q_D(QFxTextInput); + d->font = font; + + d->control->setFont(d->font); + if(d->cursorItem){ + d->cursorItem->setHeight(QFontMetrics(d->font).height()); + moveCursor(); + } + //updateSize(); + updateAll();//TODO: Only necessary updates + update(); +} + +/*! + \qmlproperty color LineEdit::color + + The text color. +*/ +QColor QFxTextInput::color() const +{ + Q_D(const QFxTextInput); + return d->color; +} + +void QFxTextInput::setColor(const QColor &c) +{ + Q_D(QFxTextInput); + d->color = c; +} + + +/*! + \qmlproperty color LineEdit::highlightColor + + The text highlight color, used behind selections. +*/ +QColor QFxTextInput::highlightColor() const +{ + Q_D(const QFxTextInput); + return d->highlightColor; +} + +void QFxTextInput::setHighlightColor(const QColor &color) +{ + Q_D(QFxTextInput); + if (d->highlightColor == color) + return; + + d->highlightColor = color; + //TODO: implement +} + +/*! + \qmlproperty color LineEdit::highlightedTextColor + + The highlighted text color, used in selections. +*/ +QColor QFxTextInput::highlightedTextColor() const +{ + Q_D(const QFxTextInput); + return d->highlightedTextColor; +} + +void QFxTextInput::setHighlightedTextColor(const QColor &color) +{ + Q_D(QFxTextInput); + if (d->highlightedTextColor == color) + return; + + d->highlightedTextColor = color; + //TODO: implement +} + +QFxTextInput::HAlignment QFxTextInput::hAlign() const +{ + Q_D(const QFxTextInput); + return d->hAlign; +} + +void QFxTextInput::setHAlign(HAlignment align) +{ + Q_D(QFxTextInput); + d->hAlign = align; +} + +bool QFxTextInput::isReadOnly() const +{ + Q_D(const QFxTextInput); + return d->control->isReadOnly(); +} + +void QFxTextInput::setReadOnly(bool ro) +{ + Q_D(QFxTextInput); + d->control->setReadOnly(ro); +} + +int QFxTextInput::maxLength() const +{ + Q_D(const QFxTextInput); + return d->control->maxLength(); +} + +void QFxTextInput::setMaxLength(int ml) +{ + Q_D(QFxTextInput); + d->control->setMaxLength(ml); +} + +/*! + \qmlproperty bool LineEdit::cursorVisible + If true the text edit shows a cursor. + + This property is set and unset when the line edit gets focus, but it can also + be set directly (useful, for example, if a KeyProxy might forward keys to it). +*/ +bool QFxTextInput::isCursorVisible() const +{ + Q_D(const QFxTextInput); + return d->cursorVisible; +} + +void QFxTextInput::setCursorVisible(bool on) +{ + Q_D(QFxTextInput); + if (d->cursorVisible == on) + return; + d->cursorVisible = on; + d->control->setCursorBlinkPeriod(on?QApplication::cursorFlashTime():0); + updateAll();//TODO: Only update cursor rect +} + +/*! + \qmlproperty int LineEdit::cursorPosition + The position of the cursor in the LineEdit. +*/ +int QFxTextInput::cursorPosition() const +{ + Q_D(const QFxTextInput); + return d->control->cursor(); +} +void QFxTextInput::setCursorPosition(int cp) +{ + Q_D(QFxTextInput); + d->control->moveCursor(cp); +} + +/*! + \qmlproperty int LineEdit::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 QFxTextInput::selectionStart() const +{ + Q_D(const QFxTextInput); + return d->lastSelectionStart; +} + +void QFxTextInput::setSelectionStart(int s) +{ + Q_D(QFxTextInput); + if(d->lastSelectionStart == s || s < 0 || s > text().length()) + return; + d->lastSelectionStart = s; + d->control->setSelection(s, d->lastSelectionEnd - s); +} + +/*! + \qmlproperty int LineEdit::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 QFxTextInput::selectionEnd() const +{ + Q_D(const QFxTextInput); + return d->lastSelectionEnd; +} + +void QFxTextInput::setSelectionEnd(int s) +{ + Q_D(QFxTextInput); + if(d->lastSelectionEnd == s || s < 0 || s > text().length()) + return; + d->lastSelectionEnd = s; + d->control->setSelection(d->lastSelectionStart, s - d->lastSelectionStart); +} + +QString QFxTextInput::selectedText() const +{ + Q_D(const QFxTextInput); + return d->control->selectedText(); +} + +QValidator* QFxTextInput::validator() const +{ + Q_D(const QFxTextInput); + //###const cast isn't good, but needed for property system? + return const_cast(d->control->validator()); +} + +void QFxTextInput::setValidator(QValidator* v) +{ + Q_D(QFxTextInput); + d->control->setValidator(v); + if(!d->control->hasAcceptableInput()){ + d->oldValidity = false; + emit acceptableInputChanged(); + } +} + +QString QFxTextInput::inputMask() const +{ + Q_D(const QFxTextInput); + return d->control->inputMask(); +} + +void QFxTextInput::setInputMask(const QString &im) +{ + Q_D(QFxTextInput); + d->control->setInputMask(im); +} + +bool QFxTextInput::hasAcceptableInput() const +{ + Q_D(const QFxTextInput); + return d->control->hasAcceptableInput(); +} + +uint QFxTextInput::echoMode() const +{ + Q_D(const QFxTextInput); + return d->control->echoMode(); +} + +void QFxTextInput::setEchoMode(uint echo) +{ + Q_D(QFxTextInput); + d->control->setEchoMode(echo); +} + +/*! + \qmlproperty Component LineEdit::cursorDelegate + The delegate for the cursor in the LineEdit. + + If you set a cursorDelegate for a LineEdit, 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 LineEdit 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 QFxItem or + QFxItem derived item. +*/ +QmlComponent* QFxTextInput::cursorDelegate() const +{ + Q_D(const QFxTextInput); + return d->cursorComponent; +} + +void QFxTextInput::setCursorDelegate(QmlComponent* c) +{ + Q_D(QFxTextInput); + if(d->cursorComponent) + delete d->cursorComponent; + d->cursorComponent = c; + d->startCreatingCursor(); +} + +void QFxTextInputPrivate::startCreatingCursor() +{ + Q_Q(QFxTextInput); + if(!cursorComponent){ + q->disconnect(control, SIGNAL(cursorPositionChanged(int, int)), + q, SLOT(moveCursor())); + return; + } + 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 + qWarning() << "You could really use the error checking for QFxTextInput. We'll implement it soon."; + } +} + +void QFxTextInput::createCursor() +{ + Q_D(QFxTextInput); + //Handle isError too + if(!d->cursorComponent->isReady()) + return; + + if(d->cursorItem) + delete d->cursorItem; + d->cursorItem = qobject_cast(d->cursorComponent->create()); + if(!d->cursorItem){ + qWarning() << "You could really use the error reporting for QFxTextInput. We'll implement it soon."; + return; + } + + d->cursorItem->setParentItem(this); + d->cursorItem->setX(d->control->cursorToX()); + d->cursorItem->setHeight(d->control->height()); +} + +void QFxTextInput::moveCursor() +{ + Q_D(QFxTextInput); + if(!d->cursorItem) + return; + d->cursorItem->setX(d->control->cursorToX() - d->hscroll); +} + +int QFxTextInput::xToPos(int x) +{ + Q_D(const QFxTextInput); + return d->control->xToPos(x - d->hscroll); +} + +void QFxTextInput::focusChanged(bool hasFocus) +{ + Q_D(QFxTextInput); + d->focused = hasFocus; + setCursorVisible(hasFocus); + QFxItem::focusChanged(hasFocus); +} + +void QFxTextInput::keyPressEvent(QKeyEvent* ev) +{ + Q_D(QFxTextInput); + d->control->processKeyEvent(ev); + if (!ev->isAccepted()) + QFxPaintedItem::keyPressEvent(ev); +} + +void QFxTextInput::mousePressEvent(QGraphicsSceneMouseEvent *event) +{ + Q_D(QFxTextInput); + setFocus(true);//###Should we make 'focusOnPress' be optional like TextEdit? + setCursorVisible(true); + d->focused = true; + d->control->processEvent(event); + //event->accept(); +} + +bool QFxTextInput::event(QEvent* ev) +{ + Q_D(QFxTextInput); + //Anything we don't deal with ourselves, pass to the control + switch(ev->type()){ + case QEvent::GraphicsSceneMousePress: + break; + default: + return d->control->processEvent(ev); + } + return false; +} + +void QFxTextInput::geometryChanged(const QRectF &newGeometry, + const QRectF &oldGeometry) +{ + if (newGeometry.width() != oldGeometry.width()) + updateSize(); + QFxPaintedItem::geometryChanged(newGeometry, oldGeometry); +} + +void QFxTextInput::drawContents(QPainter *p, const QRect &r) +{ + Q_D(QFxTextInput); + 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; + + d->control->draw(p, QPoint(0,0), r, flags); + + p->restore(); +} + +/*! + \qmlproperty bool LineEdit::smooth + + Set this property if you want the text to be smoothly scaled or + transformed. Smooth filtering gives better visual quality, but is slower. If + the item is displayed at its natural size, this property has no visual or + performance effect. + + \note Generally scaling artifacts are only visible if the item is stationary on + the screen. A common pattern when animating an item is to disable smooth + filtering at the beginning of the animation and reenable it at the conclusion. +*/ + +void QFxTextInputPrivate::init() +{ + Q_Q(QFxTextInput); + control->setCursorWidth(1); + control->setPasswordCharacter(QLatin1Char('*')); + control->setLayoutDirection(Qt::LeftToRight); + q->setSmoothTransform(smooth); + q->setAcceptedMouseButtons(Qt::LeftButton); + q->setFlag(QGraphicsItem::ItemHasNoContents, false); + q->setFlag(QGraphicsItem::ItemAcceptsInputMethod); + q->connect(control, SIGNAL(cursorPositionChanged(int,int)), + q, SLOT(cursorPosChanged())); + q->connect(control, SIGNAL(selectionChanged()), + q, SLOT(selectionChanged())); + q->connect(control, SIGNAL(textChanged(const QString &)), + 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(cursorPositionChanged(int,int)), + q, SLOT(updateAll())); + q->connect(control, SIGNAL(selectionChanged()), + q, SLOT(updateAll())); + q->updateSize(); + oldValidity = control->hasAcceptableInput(); + lastSelectionStart = 0; + lastSelectionEnd = 0; +} + +void QFxTextInput::cursorPosChanged() +{ + Q_D(QFxTextInput); + emit cursorPositionChanged(); + + if(!d->control->hasSelectedText()){ + if(d->lastSelectionStart != d->control->cursor()){ + d->lastSelectionStart = d->control->cursor(); + emit selectionStartChanged(); + } + if(d->lastSelectionEnd != d->control->cursor()){ + d->lastSelectionEnd = d->control->cursor(); + emit selectionEndChanged(); + } + } +} + +void QFxTextInput::selectionChanged() +{ + Q_D(QFxTextInput); + emit selectedTextChanged(); + + if(d->lastSelectionStart != d->control->selectionStart()){ + d->lastSelectionStart = d->control->selectionStart(); + if(d->lastSelectionStart == -1) + d->lastSelectionStart = d->control->cursor(); + emit selectionStartChanged(); + } + if(d->lastSelectionEnd != d->control->selectionEnd()){ + d->lastSelectionEnd = d->control->selectionEnd(); + if(d->lastSelectionEnd == -1) + d->lastSelectionEnd = d->control->cursor(); + emit selectionEndChanged(); + } +} + +void QFxTextInput::q_textChanged() +{ + Q_D(QFxTextInput); + updateAll(); + emit textChanged(); + if(hasAcceptableInput() != d->oldValidity){ + d->oldValidity = hasAcceptableInput(); + emit acceptableInputChanged(); + } +} + +//### Please replace this function with proper updating +void QFxTextInput::updateAll() +{ + clearCache(); + updateSize(); + update(); +} + +void QFxTextInput::updateSize() +{ + Q_D(QFxTextInput); + setImplicitHeight(d->control->height()); + //d->control->width() is max width, not current width + QFontMetrics fm = QFontMetrics(d->font); + setImplicitWidth(fm.boundingRect(d->control->text()).width()+1); + setContentsSize(QSize(width(), height())); +} + +QT_END_NAMESPACE + diff --git a/src/declarative/fx/qfxtextinput.h b/src/declarative/fx/qfxtextinput.h new file mode 100644 index 0000000..fe72f1e --- /dev/null +++ b/src/declarative/fx/qfxtextinput.h @@ -0,0 +1,193 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QFXTEXTINPUT_H +#define QFXTEXTINPUT_H + +#include "qfxtext.h" +#include "qfxpainteditem.h" +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QFxTextInputPrivate; +class QValidator; +class Q_DECLARATIVE_EXPORT QFxTextInput : public QFxPaintedItem +{ + Q_OBJECT + Q_ENUMS(HAlignment) + + Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged) + Q_PROPERTY(QColor color READ color WRITE setColor) + Q_PROPERTY(QColor highlightColor READ highlightColor WRITE setHighlightColor) //### selectionColor + Q_PROPERTY(QColor highlightedTextColor READ highlightedTextColor WRITE setHighlightedTextColor) //### selectedTextColor + Q_PROPERTY(QFont font READ font WRITE setFont) + Q_PROPERTY(HAlignment horizontalAlignment READ hAlign WRITE setHAlign) + + Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly) + Q_PROPERTY(bool cursorVisible READ isCursorVisible WRITE setCursorVisible) + Q_PROPERTY(int cursorPosition READ cursorPosition WRITE setCursorPosition NOTIFY cursorPositionChanged) + Q_PROPERTY(QmlComponent *cursorDelegate READ cursorDelegate WRITE setCursorDelegate) + Q_PROPERTY(int selectionStart READ selectionStart WRITE setSelectionStart NOTIFY selectionStartChanged) + Q_PROPERTY(int selectionEnd READ selectionEnd WRITE setSelectionEnd NOTIFY selectionEndChanged) + Q_PROPERTY(QString selectedText READ selectedText NOTIFY selectedTextChanged) + + Q_PROPERTY(int maximumLength READ maxLength WRITE setMaxLength) + Q_PROPERTY(QValidator* validator READ validator WRITE setValidator) + Q_PROPERTY(QString inputMask READ inputMask WRITE setInputMask) + Q_PROPERTY(bool acceptableInput READ hasAcceptableInput NOTIFY acceptableInputChanged) + Q_PROPERTY(uint echoMode READ echoMode WRITE setEchoMode) //### enum + //### Q_PROPERTY(bool focusOnPress READ focusOnPress WRITE setFocusOnPress) + +public: + QFxTextInput(QFxItem* parent=0); + ~QFxTextInput(); + + enum HAlignment { + AlignLeft = Qt::AlignLeft, + AlignRight = Qt::AlignRight, + AlignHCenter = Qt::AlignHCenter + }; + + //### Should we have this function, x based properties, + //### or copy TextEdit with x instead of QTextCursor? + Q_INVOKABLE int xToPos(int x); + + QString text() const; + void setText(const QString &); + + QFont font() const; + void setFont(const QFont &font); + + QColor color() const; + void setColor(const QColor &c); + + QColor highlightColor() const; + void setHighlightColor(const QColor &c); + + QColor highlightedTextColor() const; + void setHighlightedTextColor(const QColor &c); + + HAlignment hAlign() const; + void setHAlign(HAlignment align); + + bool isReadOnly() const; + void setReadOnly(bool); + + bool isCursorVisible() const; + void setCursorVisible(bool on); + + int cursorPosition() const; + void setCursorPosition(int cp); + + int selectionStart() const; + void setSelectionStart(int); + + int selectionEnd() const; + void setSelectionEnd(int); + + QString selectedText() const; + + int maxLength() const; + void setMaxLength(int ml); + + QValidator * validator() const; + void setValidator(QValidator* v); + + QString inputMask() const; + void setInputMask(const QString &im); + + uint echoMode() const; + void setEchoMode(uint echo); + + QmlComponent* cursorDelegate() const; + void setCursorDelegate(QmlComponent*); + + bool hasAcceptableInput() const; + + void drawContents(QPainter *p,const QRect &r); +Q_SIGNALS: + void textChanged(); + void cursorPositionChanged(); + void selectionStartChanged(); + void selectionEndChanged(); + void selectedTextChanged(); + void accepted(); + void acceptableInputChanged(); + +protected: + QFxTextInput(QFxTextInputPrivate &dd, QFxItem *parent); + virtual void geometryChanged(const QRectF &newGeometry, + const QRectF &oldGeometry); + + void mousePressEvent(QGraphicsSceneMouseEvent *event); + void keyPressEvent(QKeyEvent* ev); + bool event(QEvent *e); + + void focusChanged(bool hasFocus); + +private Q_SLOTS: + void updateSize(); + void q_textChanged(); + void selectionChanged(); + void updateAll(); + void createCursor(); + void moveCursor(); + void cursorPosChanged(); + +private: + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr, QFxTextInput); +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QFxTextInput) +QML_DECLARE_TYPE(QValidator) +QML_DECLARE_TYPE(QIntValidator) + +QT_END_HEADER + +#endif // QFXTEXTINPUT_H diff --git a/src/declarative/fx/qfxtextinput_p.h b/src/declarative/fx/qfxtextinput_p.h new file mode 100644 index 0000000..22a5306 --- /dev/null +++ b/src/declarative/fx/qfxtextinput_p.h @@ -0,0 +1,106 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QFXTEXTINPUT_P_H +#define QFXTEXTINPUT_P_H + +#include "qfxtextinput.h" +#include "qml.h" +#include "qfxpainteditem_p.h" +#include "private/qlinecontrol_p.h" +#include +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. + +QT_BEGIN_NAMESPACE + +class QFxTextInputPrivate : public QFxPaintedItemPrivate +{ + Q_DECLARE_PUBLIC(QFxTextInput); +public: + QFxTextInputPrivate() : control(new QLineControl(QString())), + color((QRgb)0), style(QFxText::Normal), + styleColor((QRgb)0), hAlign(QFxTextInput::AlignLeft), + hscroll(0), oldScroll(0), focused(false), cursorVisible(false) + { + } + + ~QFxTextInputPrivate() + { + } + + void init(); + void startCreatingCursor(); + + QLineControl* control; + + QFont font; + QColor color; + QColor highlightColor; + QColor highlightedTextColor; + QFxText::TextStyle style; + QColor styleColor; + QFxTextInput::HAlignment hAlign; + QPointer cursorComponent; + QPointer cursorItem; + + int lastSelectionStart; + int lastSelectionEnd; + int oldHeight; + int oldWidth; + bool oldValidity; + int hscroll; + int oldScroll; + bool focused; + bool cursorVisible; +}; + +QT_END_NAMESPACE + +#endif + -- cgit v0.12