diff options
author | Richard Moe Gustavsen <richardg@live.no> | 2020-01-20 15:43:39 +0100 |
---|---|---|
committer | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2020-05-25 11:25:38 +0000 |
commit | bf42c8689b312383f4cf18ab6a11f90fb0a956bb (patch) | |
tree | 99548fe28f145485ef2652d3d40a0bfa0cc67200 /src/imports/nativestyle/controls/DefaultGroupBox.qml | |
parent | 1f4f547a070356dda459a45b9f1c17fd4995d793 (diff) |
Native style: copy QStyle from widgets, and implement ground work for creating native styles
This is the initial patch for adding native style support to controls2.
The gist of the patch is that it copies QStyle from widgets (including the
mac plugin style), remove all notions of widgets, tweak it as needed, and
make it compile inside the qtquickcontrols2 repository as a separate
QML plugin (QtQuick.NativeStyle).
The "new" QStyle is then used to draw primitives onto nine-patch-images that can
be rendered by the scene graph. Each such primitive/image will be wrapped by a
QQuickStyleItem (which is a subclass of QQuickItem). E.g a button background will
be implemented by QQuickStyleItemButton.cpp. This item can then be placed anywhere
in the QML code to draw a native-looking button background.
Controls2 has its own styling API, where a style consist of a set of QML files
that extend template controls written in C++. To enable native styling, we simply
follow the exact same approach; We create a style folder per platform alongside
the other styles in controls2. Each style will contain a set of qml files for the
controls (Button.qml, Slider.qml, etc), and inside each control, the style items
will be used to draw the default delegates. Since it's likely that each such
qml file will be implemented equal in all the desktop styles (but not always), the
native style plugin contains a set of default controls (e.g DefaultButton.qml) that
a platform style can choose to inherit from and extend as needed.
Included is also an example called "DesktopGallery" that can be used to
test and view the controls.
Change-Id: I8b45aa7d493930f552d3ad2e3e3e7184129a9d6c
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src/imports/nativestyle/controls/DefaultGroupBox.qml')
-rw-r--r-- | src/imports/nativestyle/controls/DefaultGroupBox.qml | 83 |
1 files changed, 83 insertions, 0 deletions
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 + } +} |