NewNoteDialog.qml 6.14 KB
Newer Older
1 2 3
import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.0
Camilo Higuita's avatar
Camilo Higuita committed
4
import org.kde.mauikit 1.0 as Maui
5
import org.kde.kirigami 2.7 as Kirigami
6

7
Maui.Dialog
8
{
9
    id: control
10 11 12
    parent: parent
    heightHint: 0.95
    widthHint: 0.95
13
    maxWidth: 700*unit
14
    maxHeight: maxWidth
15

camilo higuita's avatar
camilo higuita committed
16
    property string selectedColor : "#ffffe6"
17
    property string fgColor: Qt.darker(selectedColor, 3)
18
    property bool showEditActions : false
19

Camilo higuita's avatar
Camilo higuita committed
20
    rejectButton.visible: false
21
    signal noteSaved(var note)
22
    page.padding: 0
23 24
    Kirigami.Theme.backgroundColor: selectedColor
     Kirigami.Theme.textColor: fgColor
25 26
    headBar.leftContent: [

27
        ToolButton
28
        {
29
            icon.name: "edit-undo"
30 31
            enabled: editor.body.canUndo
            onClicked: editor.body.undo()
32
            opacity: enabled ? 1 : 0.5
33
            icon.color: Kirigami.Theme.textColor
34 35
        },

36
        ToolButton
37
        {
38
            icon.name: "edit-redo"
39 40
            enabled: editor.body.canRedo
            onClicked: editor.body.redo()
41
            opacity: enabled ? 1 : 0.5
42
            icon.color: Kirigami.Theme.textColor
43 44
        },

45
        ToolButton
46
        {
47
            icon.name: "format-text-bold"
48
            focusPolicy: Qt.TabFocus
49
            icon.color: checked ? Kirigami.Theme.highlightColor :  Kirigami.Theme.textColor
50
            checkable: true
51 52
            checked: editor.document.bold
            onClicked: editor.document.bold = !editor.document.bold
53 54
        },

55
        ToolButton
56
        {
57
            icon.name: "format-text-italic"
58
            icon.color: checked ? Kirigami.Theme.highlightColor :  Kirigami.Theme.textColor
59 60
            focusPolicy: Qt.TabFocus
            checkable: true
61 62
            checked: editor.document.italic
            onClicked: editor.document.italic = !editor.document.italic
63 64
        },

65
        ToolButton
66
        {
67
            icon.name: "format-text-underline"
68
            icon.color: checked ? Kirigami.Theme.highlightColor :  Kirigami.Theme.textColor
69 70
            focusPolicy: Qt.TabFocus
            checkable: true
71 72
            checked: editor.document.underline
            onClicked: editor.document.underline = !editor.document.underline
73 74
        },

75
        ToolButton
76
        {
77
            icon.name: "format-text-uppercase"
78
            icon.color: checked ? Kirigami.Theme.highlightColor :  Kirigami.Theme.textColor
79 80
            focusPolicy: Qt.TabFocus
            checkable: true
81 82
            checked: editor.document.uppercase
            onClicked: editor.document.uppercase = !editor.document.uppercase
83
        },
84
        ToolButton
85
        {
86
            icon.name: "image"
87
            icon.color: control.Kirigami.Theme.textColor
88 89 90 91
        }
    ]

    headBar.rightContent: ColorsBar
92
    {
93 94 95 96
        onColorPicked: selectedColor = color
    }

    footBar.leftContent: [
97
        ToolButton
98 99
        {
            id: pinButton
100
            icon.name: "pin"
101
            checkable: true
102
            icon.color: checked ? highlightColor : Kirigami.Theme.textColor
103 104
            //                onClicked: checked = !checked
        },
105

106
        ToolButton
107
        {
108
            id: favButton
109
            icon.name: "love"
110
            checkable: true
111
            icon.color: checked ? "#ff007f" : Kirigami.Theme.textColor
112 113
        },

114
        ToolButton
115
        {
116
            icon.name: "document-share"
117 118
            onClicked: isAndroid ? Maui.Android.shareText(editor.body.text) :
                                   shareDialog.show(editor.body.text)
119
            icon.color: Kirigami.Theme.textColor
120

121 122
        },

123
        ToolButton
124
        {
125
            icon.name: "document-export"
126
            icon.color: Kirigami.Theme.textColor
127

128 129
        },

130
        ToolButton
131
        {
132
            icon.name: "entry-delete"
133
            icon.color: Kirigami.Theme.textColor
134

135
        }
136
    ]
137

138 139 140 141
    acceptText: qsTr("Save")
    rejectText:  qsTr("Discard")
    onAccepted:
    {
142
        if(editor.body.text.length > 0)
143 144 145
            packNote()
        clear()
    }
146

147
    onRejected: clear()
148

149 150 151
    ColumnLayout
    {
        anchors.fill: parent
152

153 154 155 156 157 158 159 160 161 162
        TextField
        {
            id: title
            Layout.fillWidth: true
            Layout.margins: space.medium
            height: 24
            placeholderText: qsTr("Title")
            font.weight: Font.Bold
            font.bold: true
            font.pointSize: fontSizes.large
163 164 165
//            Kirigami.Theme.backgroundColor: selectedColor
//            Kirigami.Theme.textColor: Qt.darker(selectedColor, 2.5)
//            color: fgColor
166
            background: Rectangle
167
            {
168
                color: "transparent"
169
            }
170
        }
camilo higuita's avatar
camilo higuita committed
171

172
        Maui.Editor
173
        {
174
            id: editor
175 176
            Layout.fillHeight: true
            Layout.fillWidth: true
177
            Kirigami.Theme.backgroundColor: selectedColor
178
            Kirigami.Theme.textColor: Qt.darker(selectedColor, 2.5)
179
            headBar.visible: false
180

181
        }
182

183
        Maui.TagsBar
Camilo Higuita's avatar
Camilo Higuita committed
184
        {
185 186 187
            id: tagBar
            Layout.fillWidth: true
            allowEditMode: true
188 189 190
            list.abstract: true
            list.key: "notes"
            onTagsEdited: list.updateToAbstract(tags)
191
            onTagRemovedClicked: list.removeFromAbstract(index)
192
             Kirigami.Theme.backgroundColor: "transparent"
193
             Kirigami.Theme.textColor: Kirigami.Theme.textColor
194

Camilo Higuita's avatar
Camilo Higuita committed
195
        }
196 197
    }

198
    onOpened: if(isMobile) editor.body.forceActiveFocus()
Camilo Higuita's avatar
Camilo Higuita committed
199

200

201
    function clear()
202 203
    {
        title.clear()
204
        editor.body.clear()
205
        close()
206
    }
207 208 209 210

    function fill(note)
    {
        title.text = note.title
211
        editor.body.text = note.body
Camilo Higuita's avatar
Camilo Higuita committed
212
        selectedColor =  note.color
213 214
        pinButton.checked = note.pin == 1
        favButton.checked = note.fav == 1
215 216

        tagBar.list.lot= note.id
217 218 219

        open()
    }
220 221 222 223 224 225

    function packNote()
    {
        noteSaved({
                      id: notesView.currentNote.id,
                      title: title.text.trim(),
226
                      body: editor.body.text,
227 228
                      color: selectedColor,
                      tag: tagBar.getTags(),
Camilo higuita's avatar
Camilo higuita committed
229 230
                      pin: pinButton.checked ? 1 : 0,
                      fav: favButton.checked ? 1 : 0,
Camilo higuita's avatar
Camilo higuita committed
231
                      updated: new Date()
232 233
                  })
    }
234
}