Browse Source

Добавил кнопку с градиентом

Denis V. Dedkov 7 years ago
parent
commit
f6a03e1565
5 changed files with 73 additions and 10 deletions
  1. 32 0
      GradientButton.qml
  2. 2 0
      HomeForm.qml
  3. 36 8
      LightGroup.qml
  4. 1 0
      qml.qrc
  5. 2 2
      qtquickcontrols2.conf

+ 32 - 0
GradientButton.qml

@@ -0,0 +1,32 @@
+import QtQuick 2.0
+import QtQuick.Controls.Material 2.2
+
+Rectangle {
+    id: root
+
+    signal clicked()
+
+    Gradient {
+        id: pressedGradient
+
+        GradientStop {position: 0.0; color: Material.color(Material.Grey, Material.Shade300)}
+        GradientStop {position: 0.5; color: Material.color(Material.BlueGrey, Material.Shade300)}
+        GradientStop {position: 1.0; color: Material.color(Material.Brown, Material.Shade300)}
+    }
+
+    Gradient {
+        id: normalGradient
+
+        GradientStop {position: 0.0; color: Material.color(Material.Grey)}
+        GradientStop {position: 0.5; color: Material.color(Material.BlueGrey)}
+        GradientStop {position: 1.0; color: Material.color(Material.Brown)}
+    }
+
+    MouseArea {
+        id: ma
+
+        anchors.fill: parent
+    }
+
+    gradient: ma.pressed ? pressedGradient : normalGradient
+}

+ 2 - 0
HomeForm.qml

@@ -14,6 +14,7 @@ Page {
 
     ListView {
         anchors.fill: parent
+        anchors.margins: 5
 
         model: lightsModel
         spacing: 5
@@ -23,6 +24,7 @@ Page {
             height: childrenRect.height
 
             title: groupName || ""
+            lights: channels
         }
     }
 }

+ 36 - 8
LightGroup.qml

@@ -5,17 +5,45 @@ Item {
     id: root
 
     property string title: ""
-    property var lights: []
+    property QtObject lights: undefined
 
-    Rectangle {
-        width: parent.width
-        height: 20
+    Column {
+        width: root.width
 
-        color: "green"
+        spacing: 5
 
-        Label {
-            text: root.title
-            anchors.centerIn: parent
+        GradientButton {
+            width: root.width
+            height: 40
+
+            visible: Boolean(root.title)
+            radius: 5
+
+            Label {
+                text: root.title
+                anchors.centerIn: parent
+            }
+        }
+
+        Row {
+            id: buttonsRow
+
+            width: root.width
+            height: childrenRect.height
+
+            spacing: 5
+
+            Repeater {
+                model: root.lights
+
+                width: root.width
+
+                GradientButton {
+                    width: (root.width - buttonsRow.spacing * (root.lights.count - 1)) / root.lights.count
+                    height: width / 2
+                    radius: 5
+                }
+            }
         }
     }
 }

+ 1 - 0
qml.qrc

@@ -8,5 +8,6 @@
         <file>SubtitledItemDelegate.qml</file>
         <file>LightsModel.qml</file>
         <file>LightGroup.qml</file>
+        <file>GradientButton.qml</file>
     </qresource>
 </RCC>

+ 2 - 2
qtquickcontrols2.conf

@@ -7,7 +7,7 @@ Style=Material
 
 [Material]
 Theme=Dark
-Primary=#3C3C3C
-Accent=BlueGrey
+Primary=BlueGrey
+Accent=Grey
 ;Foreground=Brown
 ;Background=Steel