Browse Source

Add 3 variants of buttens

master
pouya 1 year ago
parent
commit
55ce41a9e3
  1. 23
      Page1.qml
  2. 4
      SepantaUiKit/Colors.qml
  3. 98
      SepantaUiKit/SKBtn/SKBtn.qml
  4. 11
      SepantaUiKit/Setting.qml

23
Page1.qml

@ -1,5 +1,6 @@
import QtQuick 2.13 import QtQuick 2.13
import "./SepantaUiKit/SKBtn" import "./SepantaUiKit/SKBtn"
import "./SepantaUiKit"
Item { Item {
anchors.fill: parent anchors.fill: parent
@ -8,11 +9,29 @@ Item {
anchors.margins: 20 anchors.margins: 20
anchors.fill: parent anchors.fill: parent
SKBtn { SKBtn {
text: "Enable" text: "Enable P"
} }
SKBtn { SKBtn {
text: "Disable" text: "Disable P"
isEnable: false isEnable: false
} }
SKBtn {
text: "Enable S"
buttonType: Setting.Secondary
}
SKBtn {
text: "Disable S"
isEnable: false
buttonType: Setting.Secondary
}
SKBtn {
text: "Enable T"
buttonType: Setting.Tertiary
}
SKBtn {
text: "Disable T"
isEnable: false
buttonType: Setting.Tertiary
}
} }
} }

4
SepantaUiKit/Colors.qml

@ -7,11 +7,11 @@ Item {
property string primaryEnable: "#B2F7EF" property string primaryEnable: "#B2F7EF"
property string primaryPressed: "#3CFCE6" property string primaryPressed: "#3CFCE6"
//Secondary //Secondary
property string secondaryEnable: "#007dff" property string secondaryEnable: "#D0D8D8"
property string secondaryPressed: "#abb5be" property string secondaryPressed: "#abb5be"
//Tertiary //Tertiary
property string tertiaryEnable: "#E9E8E8" property string tertiaryEnable: "#E9E8E8"
property string tertiaryPressed: "#D0D0d0" property string tertiaryPressed: "#E0E7E9"
//Other //Other
property string white: "#f8f8f8" property string white: "#f8f8f8"
property string balck: "#0b0b0b" property string balck: "#0b0b0b"

98
SepantaUiKit/SKBtn/SKBtn.qml

@ -7,18 +7,13 @@ Item {
width: 140 width: 140
height: 50 height: 50
property bool isEnable: true property bool isEnable: true
onIsEnableChanged: enableHandle() property var buttonType: Setting.Primary
function enableHandle() {
if (isEnable) {
stateOfComponent = Setting.Enable
} else {
stateOfComponent = Setting.Disabel
}
}
property var stateOfComponent: Setting.Enable property var stateOfComponent: Setting.Enable
onStateOfComponentChanged: stateChanged()
property alias text: idText.text property alias text: idText.text
onIsEnableChanged: enableHandle()
onStateOfComponentChanged: stateChanged()
//========================================================================
Rectangle { Rectangle {
id: idBackGround id: idBackGround
anchors.fill: parent anchors.fill: parent
@ -31,7 +26,11 @@ Item {
verticalAlignment: Text.AlignVCenter verticalAlignment: Text.AlignVCenter
color: Colors.balck color: Colors.balck
font: Fonts.h3 font: Fonts.h3
Component.onCompleted: console.log(JSON.stringify(idText.fontInfo)) Behavior on color {
ColorAnimation {
duration: Setting.animationDuration
}
}
} }
Behavior on color { Behavior on color {
ColorAnimation { ColorAnimation {
@ -62,21 +61,70 @@ Item {
} }
} }
} }
//========================================================================
function stateChanged() { function stateChanged() {
switch (stateOfComponent) { if (buttonType === Setting.Primary) {
case Setting.Enable: switch (stateOfComponent) {
idBackGround.color = Colors.primaryEnable case Setting.Enable:
break idBackGround.color = Colors.primaryEnable
case Setting.Pressed: break
idBackGround.color = Colors.primaryPressed case Setting.Pressed:
break idBackGround.color = Colors.primaryPressed
case Setting.Hoverd: break
idBackGround.color = Qt.lighter(Colors.primaryEnable, 1.07) case Setting.Hoverd:
break idBackGround.color = Qt.lighter(Colors.primaryEnable,
case Setting.Disabel: Setting.hoverCoeffecient)
idBackGround.color = Qt.darker(Colors.primaryEnable, 4) break
break case Setting.Disabel:
idBackGround.color = Qt.darker(Colors.primaryEnable,
Setting.disableCoeffecient)
break
}
} else if (buttonType === Setting.Secondary) {
switch (stateOfComponent) {
case Setting.Enable:
idBackGround.color = Colors.secondaryEnable
break
case Setting.Pressed:
idBackGround.color = Colors.secondaryPressed
break
case Setting.Hoverd:
idBackGround.color = Qt.lighter(Colors.secondaryEnable,
Setting.hoverCoeffecient)
break
case Setting.Disabel:
idBackGround.color = Qt.darker(Colors.secondaryEnable,
Setting.disableCoeffecient)
break
}
} else if (buttonType === Setting.Tertiary) {
idBackGround.color = Colors.balck
idBackGround.border.width = 1
idBackGround.border.color = Colors.tertiaryEnable
idText.color = Colors.white
switch (stateOfComponent) {
case Setting.Enable:
idBackGround.border.color = Colors.tertiaryEnable
break
case Setting.Pressed:
idBackGround.border.color = Colors.tertiaryPressed
break
case Setting.Hoverd:
idBackGround.border.color = Qt.lighter(Colors.tertiaryEnable,
Setting.hoverCoeffecient)
break
case Setting.Disabel:
idBackGround.border.color = Qt.darker(
Colors.tertiaryEnable, Setting.disableCoeffecient)
break
}
}
}
function enableHandle() {
if (isEnable) {
stateOfComponent = Setting.Enable
} else {
stateOfComponent = Setting.Disabel
} }
} }

11
SepantaUiKit/Setting.qml

@ -6,12 +6,19 @@ Item {
property int radius: 25 property int radius: 25
property real disableOpacity: 0.25 property real disableOpacity: 0.25
property real hoverOpacity: 0.20 property real hoverOpacity: 0.20
property int animationDuration: 200 property int animationDuration: 180
property real hoverCoeffecient: 1.07
property real disableCoeffecient: 4
enum State { enum State {
//status
Enable, Enable,
Pressed, Pressed,
Hoverd, Hoverd,
Disabel Disabel,
//button type
Primary,
Secondary,
Tertiary
} }
} }

Loading…
Cancel
Save