diff options
author | Doris Verria <doris.verria@qt.io> | 2022-04-27 11:42:53 +0200 |
---|---|---|
committer | Doris Verria <doris.verria@qt.io> | 2022-05-20 16:10:30 +0200 |
commit | 41e96a7490f563449cfd32a89cdbf8d43c62f83b (patch) | |
tree | 7bb5f6be5f9d963232a447c28f918c76a3c53195 | |
parent | 369c45beb5002e4e90e2fb3e3fe6fe0194307dad (diff) |
iOS Style: Add TextField control
Change-Id: I4fac16331bd2e2a171f30e6f840661c24a0e445c
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
-rw-r--r-- | src/quickcontrols2/ios/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/quickcontrols2/ios/TextField.qml | 91 | ||||
-rw-r--r-- | src/quickcontrols2/ios/qquickiostheme.mm | 9 |
3 files changed, 99 insertions, 2 deletions
diff --git a/src/quickcontrols2/ios/CMakeLists.txt b/src/quickcontrols2/ios/CMakeLists.txt index 29d4c69ec2..e80709f42d 100644 --- a/src/quickcontrols2/ios/CMakeLists.txt +++ b/src/quickcontrols2/ios/CMakeLists.txt @@ -14,6 +14,7 @@ set(qml_files "Dial.qml" "PageIndicator.qml" "TextArea.qml" + "TextField.qml" ) set_source_files_properties(Slider.qml PROPERTIES QT_QML_SOURCE_VERSIONS "2.2;6.0" diff --git a/src/quickcontrols2/ios/TextField.qml b/src/quickcontrols2/ios/TextField.qml new file mode 100644 index 0000000000..d5940348f8 --- /dev/null +++ b/src/quickcontrols2/ios/TextField.qml @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** Copyright (C) 2022 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick +import QtQuick.Templates as T +import QtQuick.Controls.impl +import QtQuick.Controls.iOS +import QtQuick.Controls.iOS.impl + + +T.TextField { + id: control + + implicitWidth: implicitBackgroundWidth + leftInset + rightInset + || Math.max(contentWidth, placeholder.implicitWidth) + leftPadding + rightPadding + implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset, + contentHeight + topPadding + bottomPadding, + placeholder.implicitHeight + topPadding + bottomPadding) + + leftPadding: 6 + rightPadding: 8 + + color: control.palette.text + selectionColor: control.palette.highlight + selectedTextColor: control.palette.highlightedText + placeholderTextColor: control.palette.placeholderText + verticalAlignment: Qt.AlignVCenter + cursorDelegate: CursorDelegate {} + + PlaceholderText { + id: placeholder + x: control.leftPadding + y: control.topPadding + width: control.width - (control.leftPadding + control.rightPadding) + height: control.height - (control.topPadding + control.bottomPadding) + + text: control.placeholderText + font: control.font + color: control.placeholderTextColor + verticalAlignment: control.verticalAlignment + visible: !control.length && !control.preeditText && (!control.activeFocus || control.horizontalAlignment !== Qt.AlignHCenter) + elide: Text.ElideRight + renderType: control.renderType + } + + background: Rectangle { + implicitHeight: 34 + implicitWidth: 97 + radius: 4 + + border.width: 1 + border.color: control.palette.mid + color: control.palette.base + } +} diff --git a/src/quickcontrols2/ios/qquickiostheme.mm b/src/quickcontrols2/ios/qquickiostheme.mm index 10025a9328..05a7bde24b 100644 --- a/src/quickcontrols2/ios/qquickiostheme.mm +++ b/src/quickcontrols2/ios/qquickiostheme.mm @@ -55,18 +55,21 @@ void QQuickIOSTheme::initialize(QQuickTheme *theme) QPalette systemPalette; QColor background; + QColor placeholderText; QColor blue; QColor white; QColor disabled; QColor grey; #ifdef Q_OS_IOS + background = qt_mac_toQColor(UIColor.systemBackgroundColor.CGColor); + placeholderText = qt_mac_toQColor(UIColor.placeholderTextColor.CGColor); blue = qt_mac_toQColor(UIColor.systemBlueColor.CGColor); disabled = qt_mac_toQColor(UIColor.tertiarySystemFillColor.CGColor); white = qt_mac_toQColor(UIColor.whiteColor.CGColor); - grey = qt_mac_toQColor(UIColor.systemFillColor.CGColor); - background = qt_mac_toQColor(UIColor.systemBackgroundColor.CGColor); + grey = qt_mac_toQColor(UIColor.opaqueSeparatorColor.CGColor); #else background = QQuickStylePrivate::isDarkSystemTheme() ? QColor(Qt::black) : QColor(Qt::white); + placeholderText = QColor(qRgba(60, 60, 67, 77)); blue = QColor(qRgba(0, 122, 255, 255)); white = QColor(qRgba(255, 255, 255, 255)); disabled = QColor(qRgba(118, 118, 128, 31)); @@ -75,6 +78,8 @@ void QQuickIOSTheme::initialize(QQuickTheme *theme) systemPalette.setColor(QPalette::Window, background); systemPalette.setColor(QPalette::Base, background); + systemPalette.setColor(QPalette::PlaceholderText, placeholderText); + systemPalette.setColor(QPalette::Button, blue); systemPalette.setColor(QPalette::Disabled, QPalette::Button, disabled); |