~majster-pl/+junk/uShopper

« back to all changes in this revision

Viewing changes to components/EditListItelComponent.qml

  • Committer: Szymon Waliczek
  • Date: 2015-11-23 21:27:03 UTC
  • Revision ID: majsterrr@gmail.com-20151123212703-2kl0wxd7kojpowfx
initial release, still long way to go... ;)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2015 Szymon Waliczek.
 
3
 *
 
4
 * Authors:
 
5
 *  Szymon Waliczek <majsterrr@gmail.com>
 
6
 *
 
7
 * This file is part of SocketWorld app for Ubuntu Touch
 
8
 *
 
9
 * This program is free software; you can redistribute it and/or modify
 
10
 * it under the terms of the GNU Lesser General Public License as published by
 
11
 * the Free Software Foundation; version 3.
 
12
 *
 
13
 * This program is distributed in the hope that it will be useful,
 
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
 * GNU Lesser General Public License for more details.
 
17
 *
 
18
 * You should have received a copy of the GNU Lesser General Public License
 
19
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
20
 */
 
21
 
 
22
 
 
23
import QtQuick 2.4
 
24
import Ubuntu.Components 1.2
 
25
//import Ubuntu.Components.ListItems 1.0 as ListItem
 
26
import Ubuntu.Components.Popups 1.0
 
27
 
 
28
//import "../components"
 
29
import "../backEnd/utils.js" as Utils
 
30
 
 
31
// EDIT LIST NAME DIALOG
 
32
Component {
 
33
    id: editMainListDialog
 
34
    Dialog {
 
35
        id: dialogue
 
36
        title: i18n.tr("Edit") + " <b>" + main_shopping_list_MODEL.get(editListIndex).name
 
37
        TextField {
 
38
            id: newListNameTextField
 
39
            placeholderText: i18n.tr("eg. 'Weekend Shopping'")
 
40
            inputMethodHints: Qt.ImhNoPredictiveText
 
41
            text: main_shopping_list_MODEL.get(editListIndex).name
 
42
            onAccepted: {
 
43
                if(newListNameTextField.text.length > 0) {
 
44
                    if (main_shopping_list_MODEL.listNameValidator(text)) {
 
45
                        console.log("[LOG]: Editing list named: " + newListNameTextField.text )
 
46
                        main_shopping_list_MODEL.editListNameAndColor(editListIndex, newListNameTextField.text, colorPreview.backgroundColor.toString())
 
47
                        PopupUtils.close(dialogue)
 
48
                    } else {
 
49
                        if(text.toLowerCase() === main_shopping_list_MODEL.get(editListIndex).name.toLowerCase()) {
 
50
                            console.log("[LOG]: Editing list named: " + newListNameTextField.text )
 
51
                            main_shopping_list_MODEL.editListNameAndColor(editListIndex, newListNameTextField.text, colorPreview.backgroundColor.toString())
 
52
                            PopupUtils.close(dialogue)
 
53
                        }
 
54
 
 
55
                    }
 
56
 
 
57
                }
 
58
 
 
59
            }
 
60
            Component.onCompleted: {
 
61
                forceActiveFocus()
 
62
                cursorPosition = text.length
 
63
            }
 
64
        }
 
65
 
 
66
        Label {
 
67
            text: i18n.tr('Name already exists')
 
68
            color: "red"
 
69
            opacity: (main_shopping_list_MODEL.listNameValidator(newListNameTextField.text)) || (main_shopping_list_MODEL.get(editListIndex).name === newListNameTextField.text) ? 0 : 1
 
70
            Behavior on opacity {
 
71
                UbuntuNumberAnimation {
 
72
 
 
73
                }
 
74
            }
 
75
        }
 
76
 
 
77
 
 
78
        Column {
 
79
            width: parent.width
 
80
            spacing: units.gu(1)
 
81
            Label {
 
82
                text: i18n.tr('Color')
 
83
            }
 
84
            Item {
 
85
                width: parent.width
 
86
                height: units.gu(4)
 
87
 
 
88
                Rectangle {
 
89
                    id: colorPicker
 
90
                    width: units.gu(3)
 
91
                    height: parent.width
 
92
                    rotation: 270
 
93
                    border.width: units.gu(0.1)
 
94
                    border.color: "black"
 
95
                    anchors.centerIn: parent
 
96
                    gradient: Gradient {
 
97
                        GradientStop { position: 1*(1/8); color: "#FFFFFF" }
 
98
                        GradientStop { position: 2*(1/8); color: "#000000" }
 
99
                        GradientStop { position: 3*(1/8); color: "#FF0000" }
 
100
                        GradientStop { position: 4*(1/8); color: "#FFFF00" }
 
101
                        GradientStop { position: 5*(1/8); color: "#00FF00" }
 
102
                        GradientStop { position: 6*(1/8); color: "#00FFFF" }
 
103
                        GradientStop { position: 7*(1/8); color: "#0000FF" }
 
104
                        GradientStop { position: 8*(1/8); color: "#FF00FF" }
 
105
                    }
 
106
                }
 
107
                UbuntuShape {
 
108
                    height: parent.height+units.gu(1)
 
109
                    width: units.gu(3)
 
110
                    anchors.verticalCenter: parent.verticalCenter
 
111
                    backgroundColor: "#38a8ff"
 
112
                    onXChanged: {
 
113
                            print(x)
 
114
//                            print('X: '+ 7 / colorPreview.width)
 
115
                        if(x <= 2*(colorPicker.width/1)) {
 
116
                            colorPreview.backgroundColor = "#FFFFFF"
 
117
                        } else if(x < 3*(colorPicker.width / 1)){
 
118
                            colorPreview.backgroundColor = "#000000"
 
119
                        } else if(x < 4*(colorPicker.width / 1)){
 
120
                            colorPreview.backgroundColor = "#FF0000"
 
121
                        } else if(x < 5*(colorPicker.width / 1)){
 
122
                            colorPreview.backgroundColor = "#FFFF00"
 
123
                        } else if(x < 6*(colorPicker.width / 1)){
 
124
                            colorPreview.backgroundColor = "#00FF00"
 
125
                        } else if(x < 7*(colorPicker.width / 1)){
 
126
                            colorPreview.backgroundColor = "#00FFFF"
 
127
                        } else if(x < 8*(colorPicker.width / 1)){
 
128
                            colorPreview.backgroundColor = "#0000FF"
 
129
                        } else if(x <= 9*(colorPicker.width / 1)){
 
130
                            colorPreview.backgroundColor = "#FF00FF"
 
131
                        }
 
132
 
 
133
//                                if(x) {
 
134
//                                } else if (1*(1/9) < x && x < 2*(1/9)) {
 
135
//                                    colorPreview.color = "#000000"
 
136
//                                }
 
137
                    }
 
138
 
 
139
                    MouseArea {
 
140
                        id: dragArea
 
141
                        anchors.fill: parent
 
142
                        drag.target: parent
 
143
                        drag.maximumX: colorPicker.height - parent.width
 
144
                        drag.minimumX: 0
 
145
 
 
146
                        onPressed: {
 
147
                            colorPreview.opacity = 1
 
148
                        }
 
149
 
 
150
                        onReleased: {
 
151
                            colorPreview.opacity = 0
 
152
                        }
 
153
 
 
154
                    }
 
155
                    UbuntuShape {
 
156
                        id: colorPreview
 
157
                        width: units.gu(4)
 
158
                        height: units.gu(4)
 
159
                        backgroundColor: main_shopping_list_MODEL.get(editListIndex).def_color
 
160
                        opacity: 0
 
161
                        anchors.bottom: parent.top;
 
162
                        anchors.bottomMargin: units.gu(2)
 
163
                        anchors.horizontalCenter: parent.horizontalCenter
 
164
                        Behavior on opacity {
 
165
                            UbuntuNumberAnimation {}
 
166
                        }
 
167
                    }
 
168
 
 
169
                }
 
170
 
 
171
 
 
172
//                    MouseArea {
 
173
//                        anchors.fill: parent
 
174
//                        onPressed: forceActiveFocus()
 
175
//                    }
 
176
            }
 
177
 
 
178
        }
 
179
 
 
180
 
 
181
 
 
182
 
 
183
 
 
184
 
 
185
        Item {
 
186
            width: parent.width
 
187
            height: units.gu(3)
 
188
        }
 
189
 
 
190
        Row {
 
191
            width: parent.width
 
192
            spacing: units.gu(2)
 
193
            // cancel button
 
194
            Button {
 
195
                width: parent.width / 2 - units.gu(1)
 
196
                text: i18n.tr("Cancel")
 
197
                color: UbuntuColors.red
 
198
                onClicked: PopupUtils.close(dialogue)
 
199
            }
 
200
            // add button
 
201
            Button {
 
202
                id: addButton
 
203
                width: parent.width / 2 - units.gu(1)
 
204
                text: i18n.tr("Save")
 
205
                enabled: (newListNameTextField.text !== "" && main_shopping_list_MODEL.listNameValidator(newListNameTextField.text)) || (main_shopping_list_MODEL.get(editListIndex).name === newListNameTextField.text) ? true : false
 
206
                font.bold: true
 
207
                color: UbuntuColors.green
 
208
                onClicked: {
 
209
                    console.log("[LOG]: Editing list named: " + newListNameTextField.text )
 
210
                    main_shopping_list_MODEL.editListNameAndColor(editListIndex, newListNameTextField.text, colorPreview.backgroundColor.toString())
 
211
//                        Utils.addMainList(newListNameTextField.text, "#" + Math.random().toString(16).slice(2, 8))
 
212
                    PopupUtils.close(dialogue)
 
213
                }
 
214
            }
 
215
 
 
216
        }
 
217
 
 
218
    }
 
219
 
 
220
}