NewLinkDialog.qml 6.83 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.buho.editor 1.0
6
import org.kde.kirigami 2.2 as Kirigami
7

8
Maui.Popup
9
{
10 11 12 13 14
    parent: parent
    heightHint: 0.95
    widthHint: 0.95
    maxHeight: previewReady ? unit * 800 : contentLayout.implicitHeight
    maxWidth: unit *700
15

Camilo Higuita's avatar
Camilo Higuita committed
16
    signal linkSaved(var link)
17 18
    property string selectedColor : "#ffffe6"
    property string fgColor: Qt.darker(selectedColor, 2.5)
19 20 21 22

    property bool previewReady : false
    x: (parent.width / 2) - (width / 2)
    y: (parent.height /2 ) - (height / 2)
23
    modal: true
24
    padding: isAndroid ? 1 : undefined
25

26 27 28 29 30 31 32 33 34 35
    Connections
    {
        target: linker
        onPreviewReady:
        {
            previewReady = true
            fill(link)
        }
    }

36
    Maui.Page
37 38
    {
        id: content
39
        margins: 0
40
        anchors.fill: parent
41 42 43 44 45 46 47
        Rectangle
        {
            id: bg
            color: selectedColor
            z: -1
            anchors.fill: parent
        }
48

Camilo Higuita's avatar
Camilo Higuita committed
49
        headBarExit: false
50 51
        headBarVisible: previewReady
        footBarVisible: previewReady
Camilo Higuita's avatar
Camilo Higuita committed
52 53 54 55 56 57 58 59 60 61

        headBar.leftContent: Maui.ToolButton
        {
            id: pinButton
            iconName: "window-pin"
            checkable: true
            iconColor: checked ? highlightColor : textColor
            //                onClicked: checked = !checked
        }

62
        headBar.rightContent: ColorsBar
63
        {
64
            onColorPicked: selectedColor = color
65 66
        }

67
        ColumnLayout
68
        {
69 70
            id: contentLayout
            anchors.fill: parent
Camilo Higuita's avatar
Camilo Higuita committed
71

72
            TextField
73
            {
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
                id: link
                Layout.fillWidth: true
                Layout.margins: space.medium
                height: rowHeight
                verticalAlignment: Qt.AlignVCenter
                placeholderText: qsTr("URL")
                font.weight: Font.Bold
                font.bold: true
                font.pointSize: fontSizes.large
                color: fgColor
                Layout.alignment: Qt.AlignCenter

                background: Rectangle
                {
                    color: "transparent"
                }

                onAccepted: linker.extract(link.text)
92 93
            }

94
            TextField
95
            {
96 97 98 99 100 101 102 103 104 105 106 107
                id: title
                visible: previewReady
                Layout.fillWidth: true
                Layout.margins: space.medium
                height: 24
                placeholderText: qsTr("Title")
                font.weight: Font.Bold
                font.bold: true
                font.pointSize: fontSizes.large
                color: fgColor

                background: Rectangle
108
                {
109
                    color: "transparent"
110
                }
111 112 113 114 115 116 117
            }

            Item
            {
                Layout.fillWidth: true
                Layout.fillHeight: true
                visible: previewReady
118

119 120 121 122 123
                ListView
                {
                    id: previewList
                    anchors.fill: parent
                    anchors.centerIn: parent
124
                    visible: count > 0
125 126 127 128 129 130 131
                    clip: true
                    snapMode: ListView.SnapOneItem
                    orientation: ListView.Horizontal
                    interactive: count > 1
                    highlightFollowsCurrentItem: true
                    model: ListModel{}
                    onMovementEnded:
132
                    {
133 134
                        var index = indexAt(contentX, contentY)
                        currentIndex = index
135
                    }
136
                    delegate: ItemDelegate
137
                    {
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
                        height: previewList.height
                        width: previewList.width

                        background: Rectangle
                        {
                            color: "transparent"
                        }

                        Image
                        {
                            id: img
                            source: model.url
                            fillMode: Image.PreserveAspectFit
                            asynchronous: true
                            width: parent.width
                            height: parent.height
                            sourceSize.height: height
                            horizontalAlignment: Qt.AlignHCenter
                            verticalAlignment: Qt.AlignVCenter
                        }
158
                    }
159 160
                }
            }
161 162 163 164 165 166 167 168 169 170 171 172 173 174

            Maui.TagsBar
            {
                id: tagBar
                visible: previewReady
                Layout.fillWidth: true
                allowEditMode: true

                onTagsEdited:
                {
                    for(var i in tags)
                        append({tag : tags[i]})
                }
            }
175 176
        }

Camilo Higuita's avatar
Camilo Higuita committed
177
        footBar.leftContent: [
178

Camilo Higuita's avatar
Camilo Higuita committed
179
            Maui.ToolButton
180
            {
Camilo Higuita's avatar
Camilo Higuita committed
181 182 183 184 185 186 187 188 189 190 191
                id: favButton
                iconName: "love"
                checkable: true
                iconColor: checked ? "#ff007f" : textColor
            },

            Maui.ToolButton
            {
                iconName: "document-share"
                onClicked: isAndroid ? Maui.Android.shareText(link.text) :
                                       shareDialog.show(link.text)
192
            },
193

Camilo Higuita's avatar
Camilo Higuita committed
194 195 196 197 198 199 200 201 202 203
            Maui.ToolButton
            {
                iconName: "document-export"
            }
        ]

        footBar.rightContent: Row
        {
            spacing: space.medium

204
            Maui.Button
205 206 207
            {
                id: discard
                text: qsTr("Discard")
Camilo Higuita's avatar
Camilo Higuita committed
208
                onClicked:  clear()
209
            }
Camilo Higuita's avatar
Camilo Higuita committed
210

211
            Maui.Button
Camilo Higuita's avatar
Camilo Higuita committed
212 213 214 215 216 217 218 219 220 221
            {
                id: save
                text: qsTr("Save")
                onClicked:
                {
                    packLink()
                    clear()
                }
            }
        }
222 223 224
    }


Camilo Higuita's avatar
Camilo Higuita committed
225
    function clear()
226 227
    {
        title.clear()
228 229
        link.clear()
        previewList.model.clear()
Camilo Higuita's avatar
Camilo Higuita committed
230
        tagBar.clear()
231
        previewReady = false
Camilo Higuita's avatar
Camilo Higuita committed
232 233
        close()

234 235
    }

236
    function fill(link)
237
    {
238
        title.text = link.title
239
        populatePreviews(link.image)
240 241 242

        open()
    }
243 244 245 246

    function populatePreviews(imgs)
    {
        for(var i in imgs)
247 248
        {
            console.log("PREVIEW:", imgs[i])
249
            previewList.model.append({url : imgs[i]})
250
        }
251
    }
Camilo Higuita's avatar
Camilo Higuita committed
252 253 254 255 256

    function packLink()
    {
        var data = ({
                        link : link.text,
257 258
                        title: title.text,
                        preview: previewList.count > 0 ? previewList.model.get(previewList.currentIndex).url :  "",
Camilo Higuita's avatar
Camilo Higuita committed
259 260 261 262 263 264 265
                        color: selectedColor,
                        tag: tagBar.getTags(),
                        pin: pinButton.checked,
                        fav: favButton.checked
                    })
        linkSaved(data)
    }
266
}