diff --git a/src/plugins/qmldesigner/designercore/include/stylesheetmerger.h b/src/plugins/qmldesigner/designercore/include/stylesheetmerger.h index d6a27d2af7e..8a4b3bec30c 100644 --- a/src/plugins/qmldesigner/designercore/include/stylesheetmerger.h +++ b/src/plugins/qmldesigner/designercore/include/stylesheetmerger.h @@ -70,7 +70,10 @@ private: struct Options { bool preserveTextAlignment; - Options() : preserveTextAlignment(false) + bool useStyleSheetPositions; + Options() + : preserveTextAlignment(false) + , useStyleSheetPositions(false) {} }; diff --git a/src/plugins/qmldesigner/designercore/model/modeltotextmerger.cpp b/src/plugins/qmldesigner/designercore/model/modeltotextmerger.cpp index bc6824e3ab3..18bea1990cb 100644 --- a/src/plugins/qmldesigner/designercore/model/modeltotextmerger.cpp +++ b/src/plugins/qmldesigner/designercore/model/modeltotextmerger.cpp @@ -383,6 +383,9 @@ PropertyNameList ModelToTextMerger::propertyOrder() PropertyName("horizontalAlignment"), PropertyName("verticalAlignment"), PropertyName("source"), + PropertyName("lineHeight"), + PropertyName("lineHeightMode"), + PropertyName("wrapMode"), PropertyName(), PropertyName("states"), PropertyName("transitions") diff --git a/src/plugins/qmldesigner/designercore/model/stylesheetmerger.cpp b/src/plugins/qmldesigner/designercore/model/stylesheetmerger.cpp index 9c08053fdda..b54d39ef066 100644 --- a/src/plugins/qmldesigner/designercore/model/stylesheetmerger.cpp +++ b/src/plugins/qmldesigner/designercore/model/stylesheetmerger.cpp @@ -391,6 +391,9 @@ void StylesheetMerger::parseTemplateOptions() if (optionsNode.hasVariantProperty("preserveTextAlignment")) { m_options.preserveTextAlignment = optionsNode.variantProperty("preserveTextAlignment").value().toBool(); } + if (optionsNode.hasVariantProperty("useStyleSheetPositions")) { + m_options.useStyleSheetPositions = optionsNode.variantProperty("useStyleSheetPositions").value().toBool(); + } try { RewriterTransaction transaction(m_templateView, "remove-options-node"); optionsNode.destroy(); @@ -490,7 +493,7 @@ void StylesheetMerger::merge() if (!currentNode.hasParentProperty() || !m_templateView->modelNodeForId(currentNode.parentProperty().parentModelNode().id()).isValid()) { - if (!hasPos) { //If template had postition retain it + if (!hasPos && !m_options.useStyleSheetPositions) { //If template had postition retain it removePropertyIfExists(templateNode, "x"); removePropertyIfExists(templateNode, "y"); } diff --git a/tests/auto/qml/qmldesigner/coretests/tst_testcore.cpp b/tests/auto/qml/qmldesigner/coretests/tst_testcore.cpp index c99805152ca..52fa6f519f8 100644 --- a/tests/auto/qml/qmldesigner/coretests/tst_testcore.cpp +++ b/tests/auto/qml/qmldesigner/coretests/tst_testcore.cpp @@ -3762,6 +3762,11 @@ void tst_TestCore::testMergeModelRewriter1_data() QString buttonAbsoluteTemplateWithOptionsQmlContents = readQmlFromFile(QString(TESTSRCDIR) + "/../data/merging/ButtonAbsoluteTemplateWithOptions.qml"); QString buttonStyleUiWithOptionsExpectedQmlContents = readQmlFromFile(QString(TESTSRCDIR) + "/../data/merging/ButtonStyleWithOptions.ui.Expected.qml"); + QString testExportButtonTemplateQmlContents = readQmlFromFile(QString(TESTSRCDIR) + "/../data/merging//test_export_button_template.ui.qml"); + QString testExportButtonStylesheetQmlContents = readQmlFromFile(QString(TESTSRCDIR) + "/../data/merging//test_export_button_stylesheet.ui.qml"); + QString testExportButtonExpectedQmlContents = readQmlFromFile(QString(TESTSRCDIR) + "/../data/merging//test_export_button_expected.ui.qml"); + + QTest::newRow("Simple style replacement") << simpleTemplateQmlContents << simpleStyleQmlContents << simpleExpectedQmlContents; QTest::newRow("Complex style replacement") << complexTemplateQmlContents << complexStyleQmlContents << complexExpectedQmlContents; QTest::newRow("Empty stylesheet") << emptyTemplateQmlContents << emptyStyleQmlContents << emptyExpectedQmlContents; @@ -3775,6 +3780,7 @@ void tst_TestCore::testMergeModelRewriter1_data() QTest::newRow("Button Designer styling") << buttonAbsoluteTemplateQmlContents << buttonStyleUiQmlContents << buttonStyleUiExpectedQmlContents; QTest::newRow("Button Designer styling with options") << buttonAbsoluteTemplateWithOptionsQmlContents << buttonStyleUiQmlContents << buttonStyleUiWithOptionsExpectedQmlContents; + QTest::newRow("Button styling with info screen test case ") << testExportButtonTemplateQmlContents << testExportButtonStylesheetQmlContents << testExportButtonExpectedQmlContents; } diff --git a/tests/auto/qml/qmldesigner/data/merging/test_export_button_expected.ui.qml b/tests/auto/qml/qmldesigner/data/merging/test_export_button_expected.ui.qml new file mode 100644 index 00000000000..976431b8cd8 --- /dev/null +++ b/tests/auto/qml/qmldesigner/data/merging/test_export_button_expected.ui.qml @@ -0,0 +1,279 @@ +import QtQuick 2.10 +import QtQuick.Templates 2.1 as T +import Home 1.0 + +T.Button { + id: control + width: 296 + height: 538 + + font: Constants.font + implicitWidth: Math.max( + background ? background.implicitWidth : 0, + contentItem.implicitWidth + leftPadding + rightPadding) + implicitHeight: Math.max( + background ? background.implicitHeight : 0, + contentItem.implicitHeight + topPadding + bottomPadding) + leftPadding: 4 + rightPadding: 4 + + background: normalBG + contentItem: normalContent + Item { + id: normalBG + x: 0 + y: 0 + width: 296 + height: 538 + + Image { + id: normalBGAsset + x: 0 + y: 0 + source: "assets/normalBG.png" + } + } + + Item { + id: normalContent + x: 0 + y: 42 + width: 296 + height: 428 + + Image { + id: normalContentAsset + x: 115 + y: 40 + source: "assets/normalContent.png" + } + + Text { + id: normal_button_text + x: 59 + y: 353 + width: 241 + height: 75 + color: "#c1c1c1" + text: "Normal button text" + font.pixelSize: 30 + lineHeight: 44 + lineHeightMode: Text.FixedHeight + wrapMode: Text.WordWrap + } + + Text { + id: normal_button_label + x: 113 + y: 203 + color: "#c1c1c1" + text: "Normal Button label" + font.pixelSize: 36 + } + } + Item { + id: focusedBG + x: 0 + y: 0 + width: 296 + height: 538 + + Image { + id: focusedBGAsset + x: 0 + y: 0 + source: "assets/focusedBG.png" + } + + Item { + id: highlight_item_focused_1 + x: 0 + y: 0 + width: 296 + height: 196 + } + + Item { + id: highlight_item_focused_2 + x: 39 + y: 0 + width: 197 + height: 99 + } + + Image { + id: rectangle_focusedBG_1 + x: 0 + y: 0 + source: "assets/rectangle_focusedBG_1.png" + } + + Image { + id: highlight_img_focusedBG_1 + x: 0 + y: 0 + source: "assets/highlight_img_focusedBG_1.png" + } + + Image { + id: highlight_img_focused_1 + x: 291 + y: 7 + source: "assets/highlight_img_focused_1.png" + } + } + Item { + id: focusedContent + x: 0 + y: 42 + width: 296 + height: 428 + + Image { + id: focusedContentAsset + x: 115 + y: 40 + source: "assets/focusedContent.png" + } + + Text { + id: focus_button_text + x: 59 + y: 353 + width: 241 + height: 75 + color: "#ffffff" + text: "Focus button text" + font.pixelSize: 30 + lineHeight: 44 + lineHeightMode: Text.FixedHeight + wrapMode: Text.WordWrap + } + + Text { + id: focus_button_label + x: 113 + y: 203 + color: "#ba544d" + text: "Button label focus" + font.pixelSize: 36 + } + } + + Item { + id: pressedBG + x: 0 + y: 0 + width: 296 + height: 538 + + Image { + id: pressedBGAsset + x: 0 + y: 0 + source: "assets/pressedBG.png" + } + + Item { + id: highlight_item_pressed_1 + x: 0 + y: 0 + width: 296 + height: 196 + } + + Item { + id: highlight_item_pressed_2 + x: 39 + y: 0 + width: 197 + height: 99 + } + + Image { + id: rectangle_pressedBG_1 + x: 0 + y: 0 + source: "assets/rectangle_pressedBG_1.png" + } + + Image { + id: highlight_img_pressed_1 + x: 0 + y: 0 + source: "assets/highlight_img_pressed_1.png" + } + + Image { + id: highlight_img_pressed_2 + x: 291 + y: 7 + source: "assets/highlight_img_pressed_2.png" + } + } + + Image { + id: defaultBG + x: 35 + y: 339 + source: "assets/defaultBG.png" + } + + + + + + + states: [ + State { + name: "normal" + when: !control.down && !control.focus + + PropertyChanges { + target: focusedBG + visible: false + } + PropertyChanges { + target: focusedContent + visible: false + } + PropertyChanges { + target: pressedBG + visible: false + } + }, + State { + name: "press" + when: control.down && control.focus + PropertyChanges { + target: control + contentItem: focusedContent + } + + PropertyChanges { + target: normalBG + visible: false + } + + PropertyChanges { + target: normalContent + visible: false + } + + PropertyChanges { + target: pressedBG + visible: true + } + + PropertyChanges { + target: focusedContent + visible: true + } + + PropertyChanges { + target: control + background: pressedBG + } + } + ] +} diff --git a/tests/auto/qml/qmldesigner/data/merging/test_export_button_stylesheet.ui.qml b/tests/auto/qml/qmldesigner/data/merging/test_export_button_stylesheet.ui.qml new file mode 100644 index 00000000000..75c8653b39d --- /dev/null +++ b/tests/auto/qml/qmldesigner/data/merging/test_export_button_stylesheet.ui.qml @@ -0,0 +1,255 @@ +import QtQuick 2.10 + +Item { + id: info_screen + width: 296 + height: 538 + + Item { + id: normalBG + x: 0 + y: 0 + width: 296 + height: 538 + Image { + id: normalBGAsset + x: 0 + y: 0 + source: "assets/normalBG.png" + } + } + + Item { + id: normalContent + x: 0 + y: 42 + width: 296 + height: 428 + Image { + id: normalContentAsset + x: 115 + y: 40 + source: "assets/normalContent.png" + } + + Text { + id: normal_button_text + x: 59 + y: 353 + width: 241 + height: 75 + color: "#C1C1C1" + text: "Normal button text" + font.pixelSize: 30 + lineHeightMode: Text.FixedHeight + lineHeight: 44 + wrapMode: Text.WordWrap + } + + Text { + id: normal_button_label + x: 113 + y: 203 + color: "#C1C1C1" + text: "Normal Button label" + font.pixelSize: 36 + } + } + + Item { + id: pressedBG + x: 0 + y: 0 + width: 296 + height: 538 + Image { + id: pressedBGAsset + x: 0 + y: 0 + source: "assets/pressedBG.png" + } + + Item { + id: highlight_item_pressed_1 + x: 0 + y: 0 + width: 296 + height: 196 + } + + Item { + id: highlight_item_pressed_2 + x: 39 + y: 0 + width: 197 + height: 99 + } + + Image { + id: rectangle_pressedBG_1 + x: 0 + y: 0 + source: "assets/rectangle_pressedBG_1.png" + } + + Image { + id: highlight_img_pressed_1 + x: 0 + y: 0 + source: "assets/highlight_img_pressed_1.png" + } + + Image { + id: highlight_img_pressed_2 + x: 291 + y: 7 + source: "assets/highlight_img_pressed_2.png" + } + } + + Item { + id: focusedBG + x: 0 + y: 0 + width: 296 + height: 538 + Image { + id: focusedBGAsset + x: 0 + y: 0 + source: "assets/focusedBG.png" + } + + Item { + id: highlight_item_focused_1 + x: 0 + y: 0 + width: 296 + height: 196 + } + + Item { + id: highlight_item_focused_2 + x: 39 + y: 0 + width: 197 + height: 99 + } + + Image { + id: rectangle_focusedBG_1 + x: 0 + y: 0 + source: "assets/rectangle_focusedBG_1.png" + } + + Image { + id: highlight_img_focusedBG_1 + x: 0 + y: 0 + source: "assets/highlight_img_focusedBG_1.png" + } + + Image { + id: highlight_img_focused_1 + x: 291 + y: 7 + source: "assets/highlight_img_focused_1.png" + } + } + + Item { + id: focusedContent + x: 0 + y: 42 + width: 296 + height: 428 + Image { + id: focusedContentAsset + x: 115 + y: 40 + source: "assets/focusedContent.png" + } + + Text { + id: focus_button_text + x: 59 + y: 353 + width: 241 + height: 75 + color: "#FFFFFF" + text: "Focus button text" + font.pixelSize: 30 + lineHeightMode: Text.FixedHeight + lineHeight: 44 + wrapMode: Text.WordWrap + } + + Text { + id: focus_button_label + x: 113 + y: 203 + color: "#BA544D" + text: "Button label focus" + font.pixelSize: 36 + } + } + + Item { + id: disabledBG + x: 0 + y: 0 + width: 296 + height: 533 + Image { + id: disabledBGAsset + x: 0 + y: 0 + source: "assets/disabledBG.png" + } + } + + Item { + id: disabledContent + x: 0 + y: 0 + width: 296 + height: 538 + Image { + id: disabledContentAsset + x: 115 + y: 82 + source: "assets/disabledContent.png" + } + + Text { + id: disabled_button_text + x: 59 + y: 395 + width: 241 + height: 75 + color: "#413E3C" + text: "Disabled button text" + font.pixelSize: 30 + lineHeightMode: Text.FixedHeight + lineHeight: 44 + wrapMode: Text.WordWrap + } + + Text { + id: disabled_button_label + x: 109 + y: 242 + color: "#413E3C" + text: "Disabled button label" + font.pixelSize: 40 + } + } + + Image { + id: defaultBG + x: 35 + y: 339 + source: "assets/defaultBG.png" + } +} diff --git a/tests/auto/qml/qmldesigner/data/merging/test_export_button_template.ui.qml b/tests/auto/qml/qmldesigner/data/merging/test_export_button_template.ui.qml new file mode 100644 index 00000000000..ac96a076f9a --- /dev/null +++ b/tests/auto/qml/qmldesigner/data/merging/test_export_button_template.ui.qml @@ -0,0 +1,99 @@ +import QtQuick 2.10 +import QtQuick.Templates 2.1 as T +import Home 1.0 + +T.Button { + id: control + width: 296 + height: 538 + + font: Constants.font + implicitWidth: Math.max( + background ? background.implicitWidth : 0, + contentItem.implicitWidth + leftPadding + rightPadding) + implicitHeight: Math.max( + background ? background.implicitHeight : 0, + contentItem.implicitHeight + topPadding + bottomPadding) + leftPadding: 4 + rightPadding: 4 + + background: normalBG + contentItem: normalContent + + Item { + id: normalBG + } + Item { + id: normalContent + } + + Item { + id: focusedBG + } + Item { + id: focusedContent + } + Item { + id: pressedBG + } + Item { + id: defaultBG + } + + states: [ + State { + name: "normal" + when: !control.down && !control.focus + + PropertyChanges { + target: focusedBG + visible: false + } + PropertyChanges { + target: focusedContent + visible: false + } + PropertyChanges { + target: pressedBG + visible: false + } + }, + State { + name: "press" + when: control.down && control.focus + PropertyChanges { + target: control + contentItem: focusedContent + } + + PropertyChanges { + target: normalBG + visible: false + } + + PropertyChanges { + target: normalContent + visible: false + } + + PropertyChanges { + target: pressedBG + visible: true + } + + PropertyChanges { + target: focusedContent + visible: true + } + + PropertyChanges { + target: control + background: pressedBG + } + } + ] + QtObject { + id: qds_stylesheet_merger_options + property bool useStyleSheetPositions: true + } +}