Skip to content

Commit

Permalink
Merge pull request #3349 from MerginMaps/rework-fix-colors
Browse files Browse the repository at this point in the history
Fix editor and input icon colours
  • Loading branch information
tomasMizera authored Apr 19, 2024
2 parents adf1b8c + 14d8e79 commit 56cddd0
Show file tree
Hide file tree
Showing 17 changed files with 83 additions and 32 deletions.
9 changes: 4 additions & 5 deletions app/qml/components/MMSwitch.qml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ import QtQuick.Controls
Switch {
id: root

property color checkedBgColor: enabled ? __style.grassColor : __style.mediumGreenColor
property color uncheckedBgColor: __style.polarColor
property color checkedBgColor: __style.grassColor
property color disabledFgColor: __style.mediumGreenColor
property color enabledFgColor: __style.forestColor
property color handleColor: enabled ? __style.forestColor : __style.mediumGreyColor

topPadding: 0
rightPadding: 0
Expand All @@ -26,7 +25,7 @@ Switch {
contentItem: Text {
text: root.text
font: __style.p5
color: root.enabled ? root.enabledFgColor : root.disabledFgColor
color: root.handleColor
verticalAlignment: Text.AlignVCenter
leftPadding: root.indicator.width + ( text ? root.spacing : 0 )
}
Expand All @@ -45,7 +44,7 @@ Switch {
width: 20 * __dp
height: width
radius: width / 2
color: root.enabled ? root.enabledFgColor : root.disabledFgColor
color: root.handleColor
anchors.verticalCenter: parent.verticalCenter
}
}
Expand Down
9 changes: 9 additions & 0 deletions app/qml/components/private/MMBaseSingleLineInput.qml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ MMBaseInput {
property bool rightContentVisible: rightContentGroup.children.length > 0
property bool leftContentVisible: leftContentGroup.children.length > 0

// IconColor is not used in this file directly, but derived components can use it
// as precalculated color for icons to avoid repeating the same text over and over.
property color iconColor: {
if ( root.editState !== "enabled" ) return __style.mediumGreyColor
if ( root.validationState === "error" ) return __style.grapeColor
if ( root.validationState === "warning" ) return __style.earthColor
return __style.forestColor
}

signal textEdited( string text )
signal textClicked()
signal leftContentClicked()
Expand Down
2 changes: 1 addition & 1 deletion app/qml/form/components/photo/MMPhotoPreview.qml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Popup {
contentItem: Item {
anchors.fill: parent

MMBusyIndicator {
MMComponents.MMBusyIndicator {
anchors.centerIn: parent
visible: true
}
Expand Down
2 changes: 1 addition & 1 deletion app/qml/form/editors/MMFormCalendarEditor.qml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ MMPrivateComponents.MMBaseSingleLineInput {

size: __style.icon24
source: __style.calendarIcon
color: root.editState === "enabled" ? __style.forestColor : __style.mediumGreenColor
color: root.iconColor
}

Loader {
Expand Down
2 changes: 1 addition & 1 deletion app/qml/form/editors/MMFormComboboxBaseEditor.qml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ MMPrivateComponents.MMBaseSingleLineInput {
rightContent: MMComponents.MMIcon {
size: __style.icon24
source: __style.arrowDownIcon
color: root.editState === "enabled" ? __style.forestColor : __style.mediumGreenColor
color: root.iconColor
}

onRightContentClicked: openDrawer()
Expand Down
28 changes: 26 additions & 2 deletions app/qml/form/editors/MMFormNumberEditor.qml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,19 @@ MMPrivateComponents.MMBaseSingleLineInput {

size: __style.icon24
source: __style.minusIcon
color: root.editState === "enabled" && internal.canSubtractStep ? __style.forestColor : __style.mediumGreenColor
color: {
if ( root.editState !== "enabled" ) return __style.mediumGreyColor
if ( internal.canSubtractStep ) {
if ( root.validationState === "error" ) return __style.grapeColor
if ( root.validationState === "warning" ) return __style.earthColor
return __style.forestColor
}
else {
if ( root.validationState === "error" ) return __style.negativeColor
if ( root.validationState === "warning" ) return __style.warningColor
return __style.mediumGreyColor
}
}
}

textField {
Expand Down Expand Up @@ -99,7 +111,19 @@ MMPrivateComponents.MMBaseSingleLineInput {

size: __style.icon24
source: __style.plusIcon
color: root.editState === "enabled" && internal.canAddStep ? __style.forestColor : __style.mediumGreenColor
color: {
if ( root.editState !== "enabled" ) return __style.mediumGreyColor
if ( internal.canAddStep ) {
if ( root.validationState === "error" ) return __style.grapeColor
if ( root.validationState === "warning" ) return __style.earthColor
return __style.forestColor
}
else {
if ( root.validationState === "error" ) return __style.negativeColor
if ( root.validationState === "warning" ) return __style.warningColor
return __style.mediumGreyColor
}
}
}

onLeftContentClicked: {
Expand Down
4 changes: 2 additions & 2 deletions app/qml/form/editors/MMFormRelationEditor.qml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ MMPrivateComponents.MMBaseInput {
signal openLinkedFeature( var linkedFeature )
signal createLinkedFeature( var parentFeature, var relation )

Component.onCompleted: root.recalculate()
onWidthChanged: root.recalculate()
Component.onCompleted: root.recalculateVisibleItems()
onWidthChanged: root.recalculateVisibleItems()

title: _fieldShouldShowTitle ? _fieldTitle : ""

Expand Down
2 changes: 1 addition & 1 deletion app/qml/form/editors/MMFormRelationReferenceEditor.qml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ MMPrivateComponents.MMBaseSingleLineInput {
rightContent: MMComponents.MMIcon {
size: __style.icon24
source: __style.linkIcon
color: root.editState === "enabled" ? __style.forestColor : __style.mediumGreyColor
color: root.iconColor
}

onRightContentClicked: {
Expand Down
2 changes: 1 addition & 1 deletion app/qml/form/editors/MMFormScannerEditor.qml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ MMPrivateComponents.MMBaseSingleLineInput {

size: __style.icon24
source: __style.qrCodeIcon
color: root.editState === "enabled" ? __style.forestColor : __style.mediumGreenColor
color: root.iconColor
}

onRightContentClicked: {
Expand Down
17 changes: 7 additions & 10 deletions app/qml/form/editors/MMFormSliderEditor.qml
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,18 @@ MMPrivateComponents.MMBaseSingleLineInput {
height: __style.row4
radius: __style.radius2

color: __style.lightGreenColor
color: {
if ( root.validationState === "error" ) return __style.negativeColor
if ( root.validationState === "warning" ) return __style.warningColor
return __style.lightGreenColor
}

Rectangle {
// fill indicator
height: parent.height
width: slider.visualPosition * parent.width

color: internal.indicatorColor
color: root.iconColor

radius: __style.radius2
}
Expand All @@ -104,7 +108,7 @@ MMPrivateComponents.MMBaseSingleLineInput {

radius: height / 2

color: internal.indicatorColor
color: root.iconColor
}
}

Expand All @@ -120,13 +124,6 @@ MMPrivateComponents.MMBaseSingleLineInput {
property real step: _fieldConfig["Step"] ? _fieldConfig["Step"] : 1
property string suffix: _fieldConfig["Suffix"] ? _fieldConfig["Suffix"] : ""

property color indicatorColor: {
if ( root.editState !== "enabled" ) return __style.mediumGreyColor
if ( root.validationState === "error" ) return __style.grapeColor
if ( root.validationState === "warning" ) return __style.earthColor
return __style.forestColor
}

readonly property int intMax: 2000000000 // https://doc.qt.io/qt-5/qml-int.html

function fixRange( rangeValue ) {
Expand Down
2 changes: 1 addition & 1 deletion app/qml/inputs/MMComboboxInput.qml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ MMPrivateComponents.MMBaseSingleLineInput {

size: __style.icon24
source: drawerLoader.active ? __style.arrowUpIcon : __style.arrowDownIcon
color: root.editState === "enabled" ? __style.forestColor : __style.mediumGreenColor
color: root.iconColor
}

Loader {
Expand Down
2 changes: 1 addition & 1 deletion app/qml/inputs/MMPasswordInput.qml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ MMPrivateComponents.MMBaseSingleLineInput {

size: __style.icon24
source: pressed ? __style.hideIcon : __style.showIcon
color: root.editState === "enabled" ? __style.forestColor : __style.mediumGreenColor
color: root.iconColor
}

onRightContentClicked: eyeButton.pressed = !eyeButton.pressed
Expand Down
9 changes: 7 additions & 2 deletions app/qml/inputs/MMSearchInput.qml
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,20 @@ MMPrivateComponents.MMBaseSingleLineInput {

size: __style.icon24
source: __style.searchIcon
color: root.enabled ? __style.nightColor : __style.mediumGreenColor
color: {
if ( root.editState === "disabled" ) return __style.mediumGreyColor
if ( root.validationState === "error" ) return __style.grapeColor
if ( root.validationState === "warning" ) return __style.earthColor
return __style.nightColor
}
}

rightContent: MMComponents.MMIcon {
id: rightIcon

size: __style.icon24
source: __style.closeIcon
color: root.enabled ? __style.forestColor : __style.mediumGreenColor
color: root.iconColor
}

rightContentVisible: root.showClearIcon && textField.activeFocus && root.text.length > 0
Expand Down
16 changes: 15 additions & 1 deletion app/qml/inputs/MMSwitchInput.qml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,21 @@ MMPrivateComponents.MMBaseSingleLineInput {
rightContent: MMComponents.MMSwitch {
id: switchComponent

uncheckedBgColor: __style.lightGreenColor
uncheckedBgColor: {
if ( root.editState !== "enabled" ) return __style.lightGreenColor
if ( root.validationState === "error" ) return __style.negativeLightColor
if ( root.validationState === "warning" ) return __style.sandColor
return __style.lightGreenColor
}

checkedBgColor: {
if ( root.editState !== "enabled" ) return __style.mediumGreenColor
if ( root.validationState === "error" ) return __style.negativeColor
if ( root.validationState === "warning" ) return __style.warningColor
return __style.grassColor
}

handleColor: root.iconColor
}

onTextClicked: toggleSwitchComponent()
Expand Down
2 changes: 1 addition & 1 deletion app/qml/inputs/MMTextInput.qml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ MMPrivateComponents.MMBaseSingleLineInput {
rightContent: MMComponents.MMIcon {
size: __style.icon24
source: __style.closeIcon
color: root.editState === "enabled" ? __style.forestColor : __style.mediumGreenColor
color: root.iconColor
}

rightContentVisible: root.showClearIcon && textField.activeFocus && textField.text.length > 0
Expand Down
5 changes: 5 additions & 0 deletions gallery/qml/pages/ChecksPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,11 @@ Column {
enabled: false
checked: false
}
MMComponents.MMSwitch {
text: "disabled"
enabled: false
checked: true
}
}
}
}
2 changes: 0 additions & 2 deletions gallery/qml/pages/EditorsPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,7 @@ ScrollView {
id: dateTimeCalendar

text: "yyyy-MM-dd hh:mm"
enabled: checkbox.checked
width: parent.width
warningMsg: text.length > 0 ? "" : "Press button to open Calendar"

fieldIsDate: false
includesTime: true
Expand Down

0 comments on commit 56cddd0

Please sign in to comment.