Merge branch 'replace_controls_1_for_controls_2' into CURA-8687_dialogs

# Conflicts:
#	resources/qml/Account/SyncState.qml
#	resources/qml/Preferences/ReadOnlySpinBox.qml
This commit is contained in:
casper 2022-02-11 10:44:52 +01:00
commit 1c711129e2
9 changed files with 132 additions and 121 deletions

View File

@ -44,7 +44,7 @@ Item
text: printJob ? Math.round(printJob.progress * 100) + "%" : "0%" text: printJob ? Math.round(printJob.progress * 100) + "%" : "0%"
color: printJob && printJob.isActive ? UM.Theme.getColor("text") : UM.Theme.getColor("monitor_text_disabled") color: printJob && printJob.isActive ? UM.Theme.getColor("text") : UM.Theme.getColor("monitor_text_disabled")
width: contentWidth width: contentWidth
wrapMode: Text.NoWrap
// FIXED-LINE-HEIGHT: // FIXED-LINE-HEIGHT:
height: UM.Theme.getSize("monitor_text_line").height height: UM.Theme.getSize("monitor_text_line").height
} }
@ -57,6 +57,7 @@ Item
leftMargin: UM.Theme.getSize("monitor_margin").width leftMargin: UM.Theme.getSize("monitor_margin").width
verticalCenter: parent.verticalCenter verticalCenter: parent.verticalCenter
} }
wrapMode: Text.NoWrap
text: text:
{ {
if (!printJob) if (!printJob)

View File

@ -84,6 +84,8 @@ Row // Sync state icon + message
font: UM.Theme.getFont("medium") font: UM.Theme.getFont("medium")
anchors.leftMargin: UM.Theme.getSize("default_margin").width anchors.leftMargin: UM.Theme.getSize("default_margin").width
anchors.rightMargin: UM.Theme.getSize("default_margin").width anchors.rightMargin: UM.Theme.getSize("default_margin").width
wrapMode: Text.NoWrap
height: contentHeight
visible: !Cura.API.account.manualSyncEnabled && !Cura.API.account.updatePackagesEnabled visible: !Cura.API.account.manualSyncEnabled && !Cura.API.account.updatePackagesEnabled
} }
@ -94,6 +96,7 @@ Row // Sync state icon + message
color: UM.Theme.getColor("text_link") color: UM.Theme.getColor("text_link")
font: UM.Theme.getFont("medium") font: UM.Theme.getFont("medium")
height: contentHeight height: contentHeight
wrapMode: Text.NoWrap
width: contentWidth + UM.Theme.getSize("default_margin").height width: contentWidth + UM.Theme.getSize("default_margin").height
visible: Cura.API.account.updatePackagesEnabled visible: Cura.API.account.updatePackagesEnabled
@ -113,6 +116,7 @@ Row // Sync state icon + message
text: catalog.i18nc("@button", "Check for account updates") text: catalog.i18nc("@button", "Check for account updates")
color: UM.Theme.getColor("text_link") color: UM.Theme.getColor("text_link")
font: UM.Theme.getFont("medium") font: UM.Theme.getFont("medium")
wrapMode: Text.NoWrap
height: contentHeight height: contentHeight
width: contentWidth + UM.Theme.getSize("default_margin").height width: contentWidth + UM.Theme.getSize("default_margin").height
visible: Cura.API.account.manualSyncEnabled visible: Cura.API.account.manualSyncEnabled

View File

@ -195,6 +195,7 @@ Cura.ExpandablePopup
text: model.material_brand + " " + model.material_name text: model.material_brand + " " + model.material_name
elide: Text.ElideRight elide: Text.ElideRight
wrapMode: Text.NoWrap
width: parent.width width: parent.width
visible: !truncated visible: !truncated
} }

View File

@ -1,4 +1,4 @@
// Copyright (c) 2016 Ultimaker B.V. // Copyright (c) 2022 Ultimaker B.V.
// Cura is released under the terms of the LGPLv3 or higher. // Cura is released under the terms of the LGPLv3 or higher.
import QtQuick 2.2 import QtQuick 2.2
@ -118,15 +118,18 @@ Menu
{ {
spacing: UM.Theme.getSize("default_margin").width spacing: UM.Theme.getSize("default_margin").width
Label UM.Label
{ {
text: catalog.i18nc("@label", "Number of Copies") text: catalog.i18nc("@label", "Number of Copies")
anchors.verticalCenter: copiesField.verticalCenter anchors.verticalCenter: copiesField.verticalCenter
width: contentWidth
wrapMode: Text.NoWrap
} }
SpinBox Cura.SpinBox
{ {
id: copiesField id: copiesField
editable: true
focus: true focus: true
from: 1 from: 1
to: 99 to: 99

View File

@ -19,7 +19,7 @@ Cura.Menu
{ {
id: extruderInstantiator id: extruderInstantiator
model: activeMachine == null ? null : activeMachine.extruderList model: activeMachine == null ? null : activeMachine.extruderList
Menu Cura.Menu
{ {
title: modelData.name title: modelData.name
property var extruder: (base.activeMachine === null) ? null : activeMachine.extruderList[model.index] property var extruder: (base.activeMachine === null) ? null : activeMachine.extruderList[model.index]

View File

@ -230,30 +230,31 @@ Item
Label { width: parent.width; height: parent.rowHeight; font.bold: true; verticalAlignment: Qt.AlignVCenter; text: catalog.i18nc("@label", "Properties") } Label { width: parent.width; height: parent.rowHeight; font.bold: true; verticalAlignment: Qt.AlignVCenter; text: catalog.i18nc("@label", "Properties") }
Label { width: informationPage.columnWidth; height: parent.rowHeight; verticalAlignment: Qt.AlignVCenter; text: catalog.i18nc("@label", "Density") } Label { width: informationPage.columnWidth; height: parent.rowHeight; verticalAlignment: Qt.AlignVCenter; text: catalog.i18nc("@label", "Density") }
ReadOnlySpinBox
Cura.SpinBox
{ {
enabled: base.editingEnabled
id: densitySpinBox id: densitySpinBox
width: informationPage.columnWidth width: informationPage.columnWidth
value: properties.density value: properties.density
decimals: 2 decimals: 2
suffix: " g/cm³" suffix: " g/cm³"
stepSize: 0.01 stepSize: 0.01
readOnly: !base.editingEnabled
onEditingFinished: base.setMetaDataEntry("properties/density", properties.density, value) onEditingFinished: base.setMetaDataEntry("properties/density", properties.density, value)
onValueChanged: updateCostPerMeter() onValueChanged: updateCostPerMeter()
} }
Label { width: informationPage.columnWidth; height: parent.rowHeight; verticalAlignment: Qt.AlignVCenter; text: catalog.i18nc("@label", "Diameter") } Label { width: informationPage.columnWidth; height: parent.rowHeight; verticalAlignment: Qt.AlignVCenter; text: catalog.i18nc("@label", "Diameter") }
ReadOnlySpinBox Cura.SpinBox
{ {
enabled: base.editingEnabled
id: diameterSpinBox id: diameterSpinBox
width: informationPage.columnWidth width: informationPage.columnWidth
value: properties.diameter value: properties.diameter
decimals: 2 decimals: 2
suffix: " mm" suffix: " mm"
stepSize: 0.01 stepSize: 0.01
readOnly: !base.editingEnabled
onEditingFinished: onEditingFinished:
{ {
@ -279,44 +280,26 @@ Item
} }
Label { width: informationPage.columnWidth; height: parent.rowHeight; verticalAlignment: Qt.AlignVCenter; text: catalog.i18nc("@label", "Filament Cost") } Label { width: informationPage.columnWidth; height: parent.rowHeight; verticalAlignment: Qt.AlignVCenter; text: catalog.i18nc("@label", "Filament Cost") }
SpinBox
Cura.SpinBox
{ {
id: spoolCostSpinBox id: spoolCostSpinBox
width: informationPage.columnWidth width: informationPage.columnWidth
value: base.getMaterialPreferenceValue(properties.guid, "spool_cost") value: base.getMaterialPreferenceValue(properties.guid, "spool_cost")
to: 100000000 to: 100000000
editable: true editable: true
prefix: base.currency + " "
contentItem: TextField decimals: 2
{
text: spoolCostSpinBox.textFromValue(spoolCostSpinBox.value, spoolCostSpinBox.locale)
selectByMouse: true
background: Item {}
validator: RegExpValidator { regExp: new RegExp("^" + base.currency + " ([0-9]+[.]?[0-9]*)?$") }
}
property int decimals: 2
valueFromText: function(text) {
// remove all non-number tokens from input string so value can be parsed correctly
var value = Number(text.replace(",", ".").replace(/[^0-9.]+/g, ""));
var precision = Math.pow(10, spoolCostSpinBox.decimals);
return Math.round(value * precision) / precision;
}
textFromValue: function(value) {
return base.currency + " " + value.toFixed(spoolCostSpinBox.decimals)
}
onValueChanged: onValueChanged:
{ {
base.setMaterialPreferenceValue(properties.guid, "spool_cost", parseFloat(value, decimals)) base.setMaterialPreferenceValue(properties.guid, "spool_cost", parseFloat(value))
updateCostPerMeter() updateCostPerMeter()
} }
} }
Label { width: informationPage.columnWidth; height: parent.rowHeight; verticalAlignment: Qt.AlignVCenter; text: catalog.i18nc("@label", "Filament weight") } Label { width: informationPage.columnWidth; height: parent.rowHeight; verticalAlignment: Qt.AlignVCenter; text: catalog.i18nc("@label", "Filament weight") }
SpinBox Cura.SpinBox
{ {
id: spoolWeightSpinBox id: spoolWeightSpinBox
width: informationPage.columnWidth width: informationPage.columnWidth
@ -324,24 +307,7 @@ Item
stepSize: 100 stepSize: 100
to: 10000 to: 10000
editable: true editable: true
suffix: " g"
contentItem: TextField
{
text: spoolWeightSpinBox.textFromValue(spoolWeightSpinBox.value, spoolWeightSpinBox.locale)
selectByMouse: true
background: Item {}
validator: RegExpValidator { regExp: new RegExp("^([0-9]+[.]?[0-9]*)? g$") }
}
valueFromText: function(text, locale) {
// remove all non-number tokens from input string so value can be parsed correctly
var value = Number(text.replace(",", ".").replace(/[^0-9.]+/g, ""));
return Math.round(value);
}
textFromValue: function(value, locale) {
return value + " g"
}
onValueChanged: onValueChanged:
{ {
@ -455,7 +421,7 @@ Item
elide: Text.ElideRight elide: Text.ElideRight
verticalAlignment: Qt.AlignVCenter verticalAlignment: Qt.AlignVCenter
} }
ReadOnlySpinBox Cura.SpinBox
{ {
id: spinBox id: spinBox
anchors.left: label.right anchors.left: label.right
@ -479,9 +445,8 @@ Item
return 0; return 0;
} }
width: base.secondColumnWidth width: base.secondColumnWidth
readOnly: !base.editingEnabled
suffix: " " + model.unit suffix: " " + model.unit
maximumValue: 99999 to: 99999
decimals: model.unit == "mm" ? 2 : 0 decimals: model.unit == "mm" ? 2 : 0
onEditingFinished: materialPropertyProvider.setPropertyValue("value", value) onEditingFinished: materialPropertyProvider.setPropertyValue("value", value)
@ -637,4 +602,10 @@ Item
base.setMetaDataEntry("brand", old_brand, new_brand) base.setMetaDataEntry("brand", old_brand, new_brand)
properties.brand = new_brand properties.brand = new_brand
} }
function updateCostPerMeter()
{
base.spoolLength = calculateSpoolLength(diameterSpinBox.value, densitySpinBox.value, spoolWeightSpinBox.value);
base.costPerMeter = calculateCostPerMeter(spoolCostSpinBox.value);
}
} }

View File

@ -1,53 +0,0 @@
// Copyright (c) 2016 Ultimaker B.V.
// Cura is released under the terms of the LGPLv3 or higher.
import QtQuick 2.1
import QtQuick.Controls 1.1
Item
{
id: base
property alias value: spinBox.value
property alias minimumValue: spinBox.minimumValue
property alias maximumValue: spinBox.maximumValue
property alias stepSize: spinBox.stepSize
property alias prefix: spinBox.prefix
property alias suffix: spinBox.suffix
property alias decimals: spinBox.decimals
signal editingFinished();
property bool readOnly: false
width: spinBox.width
height: spinBox.height
SpinBox
{
id: spinBox
enabled: !base.readOnly
opacity: base.readOnly ? 0.5 : 1.0
anchors.fill: parent
onEditingFinished: base.editingFinished()
Keys.onEnterPressed: spinBox.focus = false
Keys.onReturnPressed: spinBox.focus = false
}
Label
{
visible: base.readOnly
text: base.prefix + base.value.toFixed(spinBox.decimals) + base.suffix
anchors.verticalCenter: parent.verticalCenter
anchors.left: parent.left
anchors.leftMargin: spinBox.__style ? spinBox.__style.padding.left : 0
color: palette.buttonText
}
SystemPalette { id: palette }
}

View File

@ -11,7 +11,7 @@ import Cura 1.0 as Cura
UM.PreferencesPage UM.PreferencesPage
{ {
title: catalog.i18nc("@title:tab", "Setting Visibility"); title: catalog.i18nc("@title:tab", "Setting Visibility")
property QtObject settingVisibilityPresetsModel: CuraApplication.getSettingVisibilityPresetsModel() property QtObject settingVisibilityPresetsModel: CuraApplication.getSettingVisibilityPresetsModel()
@ -31,16 +31,16 @@ UM.PreferencesPage
Item Item
{ {
id: base; id: base
anchors.fill: parent; anchors.fill: parent
OldControls.CheckBox OldControls.CheckBox
{ {
id: toggleVisibleSettings id: toggleVisibleSettings
anchors anchors
{ {
verticalCenter: filter.verticalCenter; verticalCenter: filter.verticalCenter
left: parent.left; left: parent.left
leftMargin: UM.Theme.getSize("default_margin").width leftMargin: UM.Theme.getSize("default_margin").width
} }
text: catalog.i18nc("@label:textbox", "Check all") text: catalog.i18nc("@label:textbox", "Check all")
@ -80,7 +80,7 @@ UM.PreferencesPage
TextField TextField
{ {
id: filter; id: filter
anchors anchors
{ {
@ -96,7 +96,7 @@ UM.PreferencesPage
onTextChanged: definitionsModel.filter = {"i18n_label|i18n_description": "*" + text} onTextChanged: definitionsModel.filter = {"i18n_label|i18n_description": "*" + text}
} }
ComboBox Cura.ComboBox
{ {
id: visibilityPreset id: visibilityPreset
width: 150 * screenScaleFactor width: 150 * screenScaleFactor
@ -104,7 +104,7 @@ UM.PreferencesPage
{ {
top: parent.top top: parent.top
right: parent.right right: parent.right
bottom: settingsListView.top verticalCenter: filter.verticalCenter
} }
model: settingVisibilityPresetsModel.items model: settingVisibilityPresetsModel.items
@ -136,11 +136,11 @@ UM.PreferencesPage
id: settingsListView id: settingsListView
anchors anchors
{ {
top: filter.bottom; top: filter.bottom
topMargin: UM.Theme.getSize("default_margin").height topMargin: UM.Theme.getSize("default_margin").height
left: parent.left; left: parent.left
right: parent.right; right: parent.right
bottom: parent.bottom; bottom: parent.bottom
} }
clip: true clip: true
@ -182,8 +182,8 @@ UM.PreferencesPage
} }
} }
UM.I18nCatalog { name: "cura"; } UM.I18nCatalog { name: "cura" }
SystemPalette { id: palette; } SystemPalette { id: palette }
Component Component
{ {

84
resources/qml/SpinBox.qml Normal file
View File

@ -0,0 +1,84 @@
// Copyright (c) 2022 Ultimaker B.V.
// Cura is released under the terms of the LGPLv3 or higher.
import QtQuick 2.2
import QtQuick.Controls 2.15
// This component extends the funtionality of QtControls 2.x Spinboxes to
// - be able to contain fractional values
// - hava a "prefix" and a "suffix". A validator is added that recognizes this pre-, suf-fix combo. When adding a custom
// validator the pre-, suf-fix should be added (e.g. new RegExp("^" + prefix + \regex\ + suffix + "$")
Item
{
id: base
property string prefix: ""
property string suffix: ""
property int decimals: 0
property real stepSize: 1
property real value: 0
property real from: 0
property real to: 99
property alias wrap: spinBox.wrap
property bool editable: true
property var validator: RegExpValidator
{
regExp: new RegExp("^" + prefix + "([0-9]+[.|,]?[0-9]*)?" + suffix + "$")
}
signal editingFinished()
implicitWidth: spinBox.implicitWidth
implicitHeight: spinBox.implicitHeight
SpinBox
{
id: spinBox
anchors.fill: base
editable: base.editable
// The stepSize of the SpinBox is intentionally set to be always `1`
// As SpinBoxes can only contain integer values the `base.stepSize` is concidered the precision/resolution
// increasing the spinBox.value by one increases the actual/real value of the component by `base.stepSize`
// as such spinBox.value * base.stepSizes produces the real value of the component
stepSize: 1
value: Math.floor(base.value / base.stepSize)
from: Math.floor(base.from / base.stepSize)
to: Math.floor(base.to / base.stepSize)
valueFromText: function(text)
{
return parseFloat(text.substring(prefix.length, text.length - suffix.length).replace(",", ".")) / base.stepSize;
}
textFromValue: function(value)
{
return prefix + (value * base.stepSize).toFixed(decimals) + suffix;
}
validator: base.validator
onValueModified:
{
base.value = value * base.stepSize;
}
contentItem: TextField
{
text: spinBox.textFromValue(spinBox.value, spinBox.locale)
selectByMouse: base.editable
background: Item {}
validator: base.validator
onActiveFocusChanged:
{
if(!activeFocus)
{
base.editingFinished();
}
}
}
}
}