diff options
author | J-P Nurmi <jpnurmi@digia.com> | 2013-10-22 15:23:56 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-10-23 20:53:25 +0200 |
commit | 860dd2acb930d87a4a7ec47cdd8bca9d7a113c77 (patch) | |
tree | d3f96ac68872a37fce9dd81bb79f0625baeb18ed /src | |
parent | fb99780dbae5b5f1bc972db83f612e9d3fafa75a (diff) | |
download | qtquickcontrols-860dd2acb930d87a4a7ec47cdd8bca9d7a113c77.tar.gz |
Add TextAreaStyle
Task-number: QTBUG-33266
Change-Id: I7bcd45469e757f7bde25b62e2324833b85a0ee7f
Reviewed-by: Caroline Chao <caroline.chao@digia.com>
Reviewed-by: Jens Bache-Wiig <jens.bache-wiig@digia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/controls/Styles/Base/TextAreaStyle.qml | 99 | ||||
-rw-r--r-- | src/controls/Styles/Desktop/TextAreaStyle.qml | 60 | ||||
-rw-r--r-- | src/controls/Styles/qmldir | 1 | ||||
-rw-r--r-- | src/controls/Styles/styles.pri | 2 | ||||
-rw-r--r-- | src/controls/TextArea.qml | 22 |
5 files changed, 173 insertions, 11 deletions
diff --git a/src/controls/Styles/Base/TextAreaStyle.qml b/src/controls/Styles/Base/TextAreaStyle.qml new file mode 100644 index 00000000..c974c01d --- /dev/null +++ b/src/controls/Styles/Base/TextAreaStyle.qml @@ -0,0 +1,99 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.1 +import QtQuick.Controls 1.1 +import QtQuick.Controls.Private 1.0 + +/*! + \qmltype TextAreaStyle + \inqmlmodule QtQuick.Controls.Styles + \since 5.2 + \ingroup controlsstyling + \brief Provides custom styling for TextArea. + + Example: + \qml + TextArea { + style: TextAreaStyle { + textColor: "#333" + selectionColor: "steelblue" + selectedTextColor: "#eee" + backgroundColor: "#eee" + } + } + \endqml +*/ + +ScrollViewStyle { + id: style + + /*! The \l TextArea attached to this style. */ + readonly property TextArea control: __control + + /*! The current font. */ + property font font + + /*! The text color. */ + property color textColor: __syspal.text + + /*! The text highlight color, used behind selections. */ + property color selectionColor: __syspal.highlight + + /*! The highlighted text color, used in selections. */ + property color selectedTextColor: __syspal.highlightedText + + /*! The background color. */ + property color backgroundColor: control.backgroundVisible ? __syspal.base : "transparent" + + /*! + \qmlproperty enumeration renderType + + Override the default rendering type for the control. + + Supported render types are: + \list + \li Text.QtRendering + \li Text.NativeRendering - the default + \endlist + + \sa Text::renderType + */ + property int renderType: Text.NativeRendering +} diff --git a/src/controls/Styles/Desktop/TextAreaStyle.qml b/src/controls/Styles/Desktop/TextAreaStyle.qml new file mode 100644 index 00000000..3f2904a3 --- /dev/null +++ b/src/controls/Styles/Desktop/TextAreaStyle.qml @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.1 +import QtQuick.Controls 1.1 +import QtQuick.Controls.Private 1.0 + +ScrollViewStyle { + property font font: __styleitem.font + property color textColor: __styleitem.textColor + property color selectionColor: __syspal.highlight + property color selectedTextColor: __syspal.highlightedText + property color backgroundColor: control.backgroundVisible ? __syspal.base : "transparent" + + property StyleItem __styleitem: StyleItem{ + property color textColor: styleHint("textColor") + elementType: "edit" + visible: false + active: control.activeFocus + onActiveChanged: textColor = styleHint("textColor") + } + + property int renderType: Text.NativeRendering +} diff --git a/src/controls/Styles/qmldir b/src/controls/Styles/qmldir index 1688f662..8e53b6ba 100644 --- a/src/controls/Styles/qmldir +++ b/src/controls/Styles/qmldir @@ -11,4 +11,5 @@ SpinBoxStyle 1.1 Base/SpinBoxStyle.qml SwitchStyle 1.1 Base/SwitchStyle.qml TabViewStyle 1.0 Base/TabViewStyle.qml TableViewStyle 1.0 Base/TableViewStyle.qml +TextAreaStyle 1.1 Base/TextAreaStyle.qml TextFieldStyle 1.0 Base/TextFieldStyle.qml diff --git a/src/controls/Styles/styles.pri b/src/controls/Styles/styles.pri index 05a53619..4c57944c 100644 --- a/src/controls/Styles/styles.pri +++ b/src/controls/Styles/styles.pri @@ -18,6 +18,7 @@ STYLES_QML_FILES = \ $$PWD/Base/StatusBarStyle.qml \ $$PWD/Base/TableViewStyle.qml \ $$PWD/Base/TabViewStyle.qml \ + $$PWD/Base/TextAreaStyle.qml \ $$PWD/Base/TextFieldStyle.qml \ $$PWD/Base/ToolBarStyle.qml \ $$PWD/Base/ToolButtonStyle.qml @@ -41,6 +42,7 @@ STYLES_QML_FILES += \ $$PWD/Desktop/StatusBarStyle.qml\ $$PWD/Desktop/TabViewStyle.qml \ $$PWD/Desktop/TableViewStyle.qml \ + $$PWD/Desktop/TextAreaStyle.qml \ $$PWD/Desktop/TextFieldStyle.qml \ $$PWD/Desktop/ToolBarStyle.qml \ $$PWD/Desktop/ToolButtonStyle.qml diff --git a/src/controls/TextArea.qml b/src/controls/TextArea.qml index 9083a2aa..72697919 100644 --- a/src/controls/TextArea.qml +++ b/src/controls/TextArea.qml @@ -64,6 +64,9 @@ import QtQuick.Controls.Private 1.0 You can translate between cursor positions (characters from the start of the document) and pixel points using positionAt() and positionToRectangle(). + You can create a custom appearance for a TextArea by + assigning a \l{QtQuick.Controls.Styles::TextAreaStyle}{TextAreaStyle}. + \sa TextField, TextEdit */ @@ -645,6 +648,8 @@ ScrollView { Accessible.role: Accessible.EditableText + style: Qt.createComponent(Settings.style + "/TextAreaStyle.qml", area) + /*! \qmlproperty TextDocument TextArea::textDocument @@ -663,16 +668,11 @@ ScrollView { id: edit focus: true - SystemPalette { - id: palette - colorGroup: enabled ? SystemPalette.Active : SystemPalette.Disabled - } - Rectangle { id: colorRect parent: viewport anchors.fill: parent - color: palette.base + color: __style ? __style.backgroundColor : "white" z: -1 } @@ -709,11 +709,11 @@ ScrollView { onContentHeightChanged: edit.doLayout() onWrapModeChanged: edit.doLayout() - renderType: Text.NativeRendering - - color: palette.text - selectionColor: palette.highlight - selectedTextColor: palette.highlightedText + renderType: __style ? __style.renderType : Text.NativeRendering + font: __style ? __style.font : font + color: __style ? __style.textColor : "darkgray" + selectionColor: __style ? __style.selectionColor : "darkred" + selectedTextColor: __style ? __style.selectedTextColor : "white" wrapMode: TextEdit.WordWrap textMargin: 4 |