diff options
-rw-r--r-- | src/imports/controls/AbstractButton.qml | 48 | ||||
-rw-r--r-- | src/imports/controls/controls.pri | 1 | ||||
-rw-r--r-- | src/imports/controls/qtquickcontrols2plugin.cpp | 3 | ||||
-rw-r--r-- | tests/auto/controls/data/tst_abstractbutton.qml | 36 |
4 files changed, 86 insertions, 2 deletions
diff --git a/src/imports/controls/AbstractButton.qml b/src/imports/controls/AbstractButton.qml new file mode 100644 index 00000000..487b452b --- /dev/null +++ b/src/imports/controls/AbstractButton.qml @@ -0,0 +1,48 @@ +/**************************************************************************** +** +** Copyright (C) 2016 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.6 +import QtQuick.Templates 2.0 as T + +T.AbstractButton { + id: control + + implicitWidth: Math.max(background ? background.implicitWidth : 0, + (contentItem ? contentItem.implicitWidth : 0) + leftPadding + rightPadding) + implicitHeight: Math.max(background ? background.implicitHeight : 0, + (contentItem ? contentItem.implicitHeight : 0) + topPadding + bottomPadding) + baselineOffset: contentItem ? contentItem.y + contentItem.baselineOffset : 0 +} diff --git a/src/imports/controls/controls.pri b/src/imports/controls/controls.pri index 788bfe27..dcbcf8e1 100644 --- a/src/imports/controls/controls.pri +++ b/src/imports/controls/controls.pri @@ -9,6 +9,7 @@ SOURCES += \ $$PWD/qquickdialring.cpp QML_CONTROLS = \ + AbstractButton.qml \ ApplicationWindow.qml \ BusyIndicator.qml \ Button.qml \ diff --git a/src/imports/controls/qtquickcontrols2plugin.cpp b/src/imports/controls/qtquickcontrols2plugin.cpp index 541d18d6..153d61f7 100644 --- a/src/imports/controls/qtquickcontrols2plugin.cpp +++ b/src/imports/controls/qtquickcontrols2plugin.cpp @@ -41,7 +41,6 @@ #include <QtCore/private/qfileselector_p.h> #include <QtQuickControls2/qquickstyle.h> -#include <QtQuickTemplates2/private/qquickabstractbutton_p.h> #include <QtQuickTemplates2/private/qquickbuttongroup_p.h> #include <QtQuickTemplates2/private/qquickcontainer_p.h> #include <QtQuickTemplates2/private/qquickcontrol_p.h> @@ -82,7 +81,6 @@ QtQuickControls2Plugin::QtQuickControls2Plugin(QObject *parent) : QQuickStylePlu void QtQuickControls2Plugin::registerTypes(const char *uri) { - qmlRegisterType<QQuickAbstractButton>(uri, 2, 0, "AbstractButton"); qmlRegisterType<QQuickButtonGroup>(uri, 2, 0, "ButtonGroup"); qmlRegisterType<QQuickButtonGroupAttached>(); @@ -93,6 +91,7 @@ void QtQuickControls2Plugin::registerTypes(const char *uri) if (!style.isEmpty()) QFileSelectorPrivate::addStatics(QStringList() << style.toLower()); + qmlRegisterType(selector.select(QStringLiteral("AbstractButton.qml")), uri, 2, 0, "AbstractButton"); qmlRegisterType(selector.select(QStringLiteral("ApplicationWindow.qml")), uri, 2, 0, "ApplicationWindow"); qmlRegisterType(selector.select(QStringLiteral("BusyIndicator.qml")), uri, 2, 0, "BusyIndicator"); qmlRegisterType(selector.select(QStringLiteral("Button.qml")), uri, 2, 0, "Button"); diff --git a/tests/auto/controls/data/tst_abstractbutton.qml b/tests/auto/controls/data/tst_abstractbutton.qml index c94653d9..ba5ee94c 100644 --- a/tests/auto/controls/data/tst_abstractbutton.qml +++ b/tests/auto/controls/data/tst_abstractbutton.qml @@ -55,6 +55,11 @@ TestCase { AbstractButton {} } + Component { + id: item + Item { } + } + function test_text() { var control = button.createObject(testCase); verify(control); @@ -67,4 +72,35 @@ TestCase { control.destroy(); } + + function test_baseline() { + var control = button.createObject(testCase, {padding: 6}) + verify(control) + compare(control.baselineOffset, 0) + control.contentItem = item.createObject(control, {baselineOffset: 12}) + compare(control.baselineOffset, 18) + control.destroy() + } + + function test_implicitSize() { + var control = button.createObject(testCase) + verify(control) + + compare(control.implicitWidth, 0) + compare(control.implicitHeight, 0) + + control.contentItem = item.createObject(control, {implicitWidth: 10, implicitHeight: 20}) + compare(control.implicitWidth, 10) + compare(control.implicitHeight, 20) + + control.background = item.createObject(control, {implicitWidth: 20, implicitHeight: 30}) + compare(control.implicitWidth, 20) + compare(control.implicitHeight, 30) + + control.padding = 100 + compare(control.implicitWidth, 210) + compare(control.implicitHeight, 220) + + control.destroy() + } } |