diff options
Diffstat (limited to 'src/imports/nativestyle/controls')
-rw-r--r-- | src/imports/nativestyle/controls/DefaultButton.qml | 88 | ||||
-rw-r--r-- | src/imports/nativestyle/controls/DefaultCheckBox.qml | 96 | ||||
-rw-r--r-- | src/imports/nativestyle/controls/DefaultGroupBox.qml | 83 | ||||
-rw-r--r-- | src/imports/nativestyle/controls/DefaultRadioButton.qml | 101 | ||||
-rw-r--r-- | src/imports/nativestyle/controls/DefaultSlider.qml | 78 | ||||
-rw-r--r-- | src/imports/nativestyle/controls/DefaultSpinBox.qml | 109 | ||||
-rw-r--r-- | src/imports/nativestyle/controls/DefaultTextField.qml | 90 | ||||
-rw-r--r-- | src/imports/nativestyle/controls/controls.pri | 8 |
8 files changed, 653 insertions, 0 deletions
diff --git a/src/imports/nativestyle/controls/DefaultButton.qml b/src/imports/nativestyle/controls/DefaultButton.qml new file mode 100644 index 00000000..3cbc2567 --- /dev/null +++ b/src/imports/nativestyle/controls/DefaultButton.qml @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** Copyright (C) 2020 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 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.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 later 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 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.12 +import QtQuick.Controls 2.12 +import QtQuick.Controls.impl 2.12 +import QtQuick.Templates 2.12 as T +import QtQuick.NativeStyle 6.0 as NativeStyle + +T.Button { + id: control + + property bool nativeBackground: background instanceof NativeStyle.StyleItem + + // Since QQuickControl will subtract the insets from the control size to + // figure out the background size, we need to reverse that here, otherwise + // the control ends up too big. + implicitWidth: implicitBackgroundWidth + leftInset + rightInset + implicitHeight: implicitBackgroundHeight + topInset + bottomInset + + font.pixelSize: nativeBackground ? background.styleFont(control).pixelSize : undefined + + leftPadding: nativeBackground ? background.contentPadding.left + leftInset: 5 + rightPadding: nativeBackground ? background.contentPadding.right + rightInset: 5 + topPadding: nativeBackground ? background.contentPadding.top + topInset: 5 + bottomPadding: nativeBackground ? background.contentPadding.bottom + bottomInset : 5 + + topInset: nativeBackground ? background.insets.top : 0 + bottomInset: nativeBackground ? background.insets.bottom : 0 + leftInset: nativeBackground ? background.insets.left : 0 + rightInset: nativeBackground ? background.insets.right : 0 + + background: NativeStyle.Button { + control: control + contentWidth: contentItem.implicitWidth + contentHeight: contentItem.implicitHeight + } + + icon.width: 24 + icon.height: 24 + icon.color: control.checked || control.highlighted ? control.palette.brightText : + control.flat && !control.down ? (control.visualFocus ? control.palette.highlight : control.palette.windowText) : control.palette.buttonText + + contentItem: IconLabel { + spacing: control.spacing + mirrored: control.mirrored + display: control.display + + icon: control.icon + text: control.text + font: control.font + color: control.checked || control.highlighted ? control.palette.brightText : + control.flat && !control.down ? (control.visualFocus ? control.palette.highlight : control.palette.windowText) : control.palette.buttonText + } +} diff --git a/src/imports/nativestyle/controls/DefaultCheckBox.qml b/src/imports/nativestyle/controls/DefaultCheckBox.qml new file mode 100644 index 00000000..d3b599ba --- /dev/null +++ b/src/imports/nativestyle/controls/DefaultCheckBox.qml @@ -0,0 +1,96 @@ +/**************************************************************************** +** +** Copyright (C) 2020 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 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.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 later 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 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.12 +import QtQuick.Templates 2.12 as T +import QtQuick.Controls 2.12 +import QtQuick.Controls.impl 2.12 +import QtQuick.NativeStyle 6.0 as NativeStyle + +T.CheckBox { + id: control + + property bool nativeIndicator: indicator instanceof NativeStyle.StyleItem + + implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset, + implicitContentWidth + leftPadding + rightPadding) + implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset, + implicitContentHeight + topPadding + bottomPadding, + implicitIndicatorHeight + topPadding + bottomPadding) + + font.pixelSize: nativeIndicator ? indicator.styleFont(control).pixelSize : undefined + + spacing: nativeIndicator ? 0 : 6 + padding: nativeIndicator ? 0 : 6 + + topInset: nativeIndicator ? indicator.insets.top : 0 + bottomInset: nativeIndicator ? indicator.insets.bottom : 0 + leftInset: nativeIndicator ? indicator.insets.left : 0 + rightInset: nativeIndicator ? indicator.insets.right : 0 + + indicator: NativeStyle.CheckBox { + control: control + contentWidth: contentItem.implicitWidth + contentHeight: contentItem.implicitHeight + useNinePatchImage: false + } + + contentItem: CheckLabel { + text: control.text + font: control.font + color: control.palette.windowText + + // For some reason, the other styles set padding here (in the delegate), instead of in + // the control above. And they also adjust the indicator position by setting x and y + // explicitly (instead of using insets). So we follow the same pattern to ensure that + // setting a custom contentItem delegate from the app will end up looking the same for + // all styles. But this should probably be fixed for all styles (to make them work the + // same way as e.g Buttons). + leftPadding: { + if (nativeIndicator) + indicator.contentPadding.left + else + indicator && !mirrored ? indicator.width + spacing : 0 + } + + rightPadding: { + if (nativeIndicator) + indicator.contentPadding.right + else + indicator && mirrored ? indicator.width + spacing : 0 + } + } +} diff --git a/src/imports/nativestyle/controls/DefaultGroupBox.qml b/src/imports/nativestyle/controls/DefaultGroupBox.qml new file mode 100644 index 00000000..d7de7e6e --- /dev/null +++ b/src/imports/nativestyle/controls/DefaultGroupBox.qml @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** Copyright (C) 2020 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 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.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 later 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 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.12 +import QtQuick.Controls 2.12 +import QtQuick.Controls.impl 2.12 +import QtQuick.Templates 2.12 as T +import QtQuick.NativeStyle 6.0 as NativeStyle + +T.GroupBox { + id: control + + property bool nativeBackground: background instanceof NativeStyle.StyleItem + + implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset, + contentWidth + leftPadding + rightPadding, + implicitLabelWidth + leftPadding + rightPadding) + implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset, + contentHeight + topPadding + bottomPadding) + + font.pixelSize: nativeBackground ? background.styleFont(control).pixelSize : undefined + + label: Text { + x: control.leftPadding + width: control.availableWidth + + text: control.title + font: control.font + color: control.palette.windowText + elide: Text.ElideRight + verticalAlignment: Text.AlignVCenter + } + + leftPadding: nativeBackground ? background.contentPadding.left : 0 + rightPadding: nativeBackground ? background.contentPadding.right : 0 + topPadding: nativeBackground ? background.contentPadding.top : 0 + bottomPadding: nativeBackground ? background.contentPadding.bottom : 0 + + background: NativeStyle.GroupBox { + control: control + + x: groupBoxPadding.left + y: groupBoxPadding.top + width: contentItem.width + control.leftPadding + control.rightPadding - groupBoxPadding.left - groupBoxPadding.right + height: contentItem.height + control.topPadding + control.bottomPadding - groupBoxPadding.top - groupBoxPadding.bottom + + contentWidth: contentItem.implicitWidth + contentHeight: contentItem.implicitHeight + } +} diff --git a/src/imports/nativestyle/controls/DefaultRadioButton.qml b/src/imports/nativestyle/controls/DefaultRadioButton.qml new file mode 100644 index 00000000..dc4b1218 --- /dev/null +++ b/src/imports/nativestyle/controls/DefaultRadioButton.qml @@ -0,0 +1,101 @@ +/**************************************************************************** +** +** Copyright (C) 2020 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 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.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 later 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 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.12 +import QtQuick.Templates 2.12 as T +import QtQuick.Controls 2.12 +import QtQuick.Controls.impl 2.12 +import QtQuick.NativeStyle 6.0 as NativeStyle + +T.RadioButton { + id: control + + property bool nativeIndicator: indicator instanceof NativeStyle.StyleItem + + implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset, + implicitContentWidth + leftPadding + rightPadding) + implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset, + implicitContentHeight + topPadding + bottomPadding, + implicitIndicatorHeight + topPadding + bottomPadding) + + font.pixelSize: nativeIndicator ? indicator.styleFont(control).pixelSize : undefined + + spacing: nativeIndicator ? 0 : 6 + padding: nativeIndicator ? 0 : 6 + + topInset: nativeIndicator ? indicator.insets.top : 0 + bottomInset: nativeIndicator ? indicator.insets.bottom : 0 + leftInset: nativeIndicator ? indicator.insets.left : 0 + rightInset: nativeIndicator ? indicator.insets.right : 0 + + indicator: NativeStyle.RadioButton { + control: control + contentWidth: contentItem.implicitWidth + contentHeight: contentItem.implicitHeight + useNinePatchImage: false +// Component.onCompleted: { +// var f = indicator.font(control) +// control.font.pixelSize = f.pixelSize +// print(f) +// } + } + + contentItem: CheckLabel { + text: control.text + font: control.font + color: control.palette.windowText + + // For some reason, the other styles set padding here (in the delegate), instead of in + // the control above. And they also adjust the indicator position by setting x and y + // explicitly (instead of using insets). So we follow the same pattern to ensure that + // setting a custom contentItem delegate from the app will end up looking the same for + // all styles. But this should probably be fixed for all styles (to make them work the + // same way as e.g Buttons). + leftPadding: { + if (nativeIndicator) + indicator.contentPadding.left + else + indicator && !mirrored ? indicator.width + spacing : 0 + } + + rightPadding: { + if (nativeIndicator) + indicator.contentPadding.right + else + indicator && mirrored ? indicator.width + spacing : 0 + } + } +} diff --git a/src/imports/nativestyle/controls/DefaultSlider.qml b/src/imports/nativestyle/controls/DefaultSlider.qml new file mode 100644 index 00000000..45a01ac4 --- /dev/null +++ b/src/imports/nativestyle/controls/DefaultSlider.qml @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2020 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 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.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 later 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 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.12 +import QtQuick.Controls 2.12 +import QtQuick.Controls.impl 2.12 +import QtQuick.Templates 2.12 as T +import QtQuick.NativeStyle 6.0 as NativeStyle + +T.Slider { + id: control + + property bool nativeBackground: background instanceof NativeStyle.StyleItem + + implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset, + implicitHandleWidth + leftPadding + rightPadding) + implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset, + implicitHandleHeight + topPadding + bottomPadding) + + font.pixelSize: nativeBackground ? background.styleFont(control).pixelSize : undefined + + topInset: nativeBackground ? background.insets.top : 0 + bottomInset: nativeBackground ? background.insets.bottom : 0 + leftInset: nativeBackground ? background.insets.left : 0 + rightInset: nativeBackground ? background.insets.right : 0 + + background: NativeStyle.Slider { + control: control + subControl: NativeStyle.Slider.Groove + // We normally cannot use a nine patch image for the + // groove if we draw tickmarks (since then the scaling + // would scale the tickmarks too). The groove might + // also use a different background color before, and + // after, the handle. + useNinePatchImage: false + } + + handle: NativeStyle.Slider { + control: control + subControl: NativeStyle.Slider.Handle + x: control.leftPadding + (control.horizontal ? control.visualPosition * (control.availableWidth - width) : (control.availableWidth - width) / 2) + y: control.topPadding + (control.horizontal ? (control.availableHeight - height) / 2 : control.visualPosition * (control.availableHeight - height)) + useNinePatchImage: false + } +} diff --git a/src/imports/nativestyle/controls/DefaultSpinBox.qml b/src/imports/nativestyle/controls/DefaultSpinBox.qml new file mode 100644 index 00000000..816f78a9 --- /dev/null +++ b/src/imports/nativestyle/controls/DefaultSpinBox.qml @@ -0,0 +1,109 @@ +/**************************************************************************** +** +** Copyright (C) 2020 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 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.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 later 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 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.12 +import QtQuick.Controls 2.12 +import QtQuick.Controls.impl 2.12 +import QtQuick.Templates 2.12 as T +import QtQuick.NativeStyle 6.0 as NativeStyle + +T.SpinBox { + id: control + + property bool nativeBackground: background instanceof NativeStyle.StyleItem + + implicitWidth: implicitBackgroundWidth + spacing + up.implicitIndicatorWidth + + leftInset + rightInset + implicitHeight: Math.max(implicitBackgroundHeight, up.implicitIndicatorHeight + down.implicitIndicatorHeight + + (spacing * 3)) + topInset + bottomInset + + font.pixelSize: nativeBackground ? background.styleFont(control).pixelSize : undefined + + spacing: 2 + + leftPadding: (nativeBackground ? background.contentPadding.left: 0) + topPadding: (nativeBackground ? background.contentPadding.top: 0) + rightPadding: (nativeBackground ? background.contentPadding.right : 0) + up.implicitIndicatorWidth + spacing + bottomPadding: (nativeBackground ? background.contentPadding.bottom: 0) + spacing + + validator: IntValidator { + locale: control.locale.name + bottom: Math.min(control.from, control.to) + top: Math.max(control.from, control.to) + } + + contentItem: TextInput { + text: control.displayText + font: font.font + color: control.palette.text + selectionColor: control.palette.highlight + selectedTextColor: control.palette.highlightedText + horizontalAlignment: Qt.AlignLeft + verticalAlignment: Qt.AlignVCenter + + topPadding: 2 + bottomPadding: 2 + leftPadding: 10 + rightPadding: 10 + + readOnly: !control.editable + validator: control.validator + inputMethodHints: control.inputMethodHints + } + + up.indicator: NativeStyle.SpinBox { + control: control + subControl: NativeStyle.SpinBox.Up + x: parent.width - width - spacing + y: (parent.height / 2) - height + useNinePatchImage: false + } + + down.indicator: NativeStyle.SpinBox { + control: control + subControl: NativeStyle.SpinBox.Down + x: up.indicator.x + y: up.indicator.y + up.indicator.height + useNinePatchImage: false + } + + background: NativeStyle.SpinBox { + control: control + subControl: NativeStyle.SpinBox.Frame + contentWidth: contentItem.implicitWidth + contentHeight: contentItem.implicitHeight + } +} diff --git a/src/imports/nativestyle/controls/DefaultTextField.qml b/src/imports/nativestyle/controls/DefaultTextField.qml new file mode 100644 index 00000000..e2901028 --- /dev/null +++ b/src/imports/nativestyle/controls/DefaultTextField.qml @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** Copyright (C) 2020 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 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.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 later 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 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.12 +import QtQuick.Controls 2.12 +import QtQuick.Controls.impl 2.12 +import QtQuick.Templates 2.12 as T +import QtQuick.NativeStyle 6.0 as NativeStyle + +T.TextField { + id: control + + property bool nativeBackground: background instanceof NativeStyle.StyleItem + + implicitWidth: Math.max(96, background.implicitWidth + leftPadding + rightPadding + leftInset + rightInset) + implicitHeight: background.implicitHeight + topPadding + bottomPadding + topInset + bottomInset + + font.pixelSize: nativeBackground ? background.styleFont(control).pixelSize : undefined + + leftPadding: nativeBackground ? background.contentPadding.left: 7 + rightPadding: nativeBackground ? background.contentPadding.right: 7 + topPadding: nativeBackground ? background.contentPadding.top: 3 + bottomPadding: nativeBackground ? background.contentPadding.bottom: 3 + + topInset: nativeBackground ? background.insets.top : 0 + bottomInset: nativeBackground ? background.insets.bottom : 0 + leftInset: nativeBackground ? background.insets.left : 0 + rightInset: nativeBackground ? background.insets.right : 0 + + color: control.palette.text + selectionColor: control.palette.highlight + selectedTextColor: control.palette.highlightedText + placeholderTextColor: Color.transparent(control.color, 0.5) + verticalAlignment: TextInput.AlignTop + + PlaceholderText { + id: placeholder + height: control.height + topPadding: control.topPadding + bottomPadding: control.bottomPadding + leftPadding: control.leftPadding + rightPadding: control.rightPadding + 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: NativeStyle.TextField { + control: control + contentWidth: Math.max(control.contentWidth, placeholder.implicitWidth) + contentHeight: control.contentHeight + } +} diff --git a/src/imports/nativestyle/controls/controls.pri b/src/imports/nativestyle/controls/controls.pri new file mode 100644 index 00000000..16031f3d --- /dev/null +++ b/src/imports/nativestyle/controls/controls.pri @@ -0,0 +1,8 @@ +QML_FILES += \ + $$PWD/DefaultButton.qml \ + $$PWD/DefaultSlider.qml \ + $$PWD/DefaultGroupBox.qml \ + $$PWD/DefaultCheckBox.qml \ + $$PWD/DefaultRadioButton.qml \ + $$PWD/DefaultSpinBox.qml \ + $$PWD/DefaultTextField.qml \ |