Layout.qml 5.7 KB
Newer Older
P
peterq 已提交
1 2 3 4 5 6 7
import QtQuick 2.4
import "../js/util.js" as Util
Item {
    id: mainLayout
    property var tabsUrl: {'我的网盘': 'pan', '传输列表': 'transfer', '探索': 'explore'}
    property var tabs: ['我的网盘', '传输列表', '探索']
    property var colors: ['blue', 'red', 'green']
P
peterq 已提交
8
    property string activeTab: '我的网盘'
9
    anchors.fill: parent
P
peterq 已提交
10 11 12 13 14 15 16 17 18
    Header {
        id: header
        tabs: mainLayout.tabs
        activeTab: mainLayout.activeTab
        onActiveChange: {
            tabsCon.doSlideAnimation(tab)
            mainLayout.activeTab = tab
        }
    }
P
peterq 已提交
19 20 21 22 23 24 25 26 27 28
    function notiActive() {
        var idx = mainLayout.tabs.findIndex(function (tab) {
            return tab === mainLayout.activeTab
        })
        tabRepeater.itemAt(idx).active()
    }
    onActiveTabChanged: {
        notiActive()
    }

P
peterq 已提交
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
    Rectangle {
        id: tabsViewport
        width: parent.width
        height: parent.height - header.height
        y: header.height
        clip: true
        color: '#eaeaea'
        Text {
            id: tabBgAppName
            text: "pan-light"
            font.pointSize: 40
            anchors.centerIn: parent
        }
        Text {
            font.pointSize: 20
            color: 'red'
            text: "by PeterQ"
            anchors.left: tabBgAppName.right
            anchors.bottom: tabBgAppName.bottom
            anchors.leftMargin: 10
        }
        Row {
            id: tabsCon
            width: parent.width * tabs.length
            height: parent.height
            spacing: 0.2 * tabsViewport.width
            x: {
                if (slideChangeAnimation.doing) return x
                var idx = mainLayout.tabs.findIndex(function (tab) {
                    return tab === mainLayout.activeTab
                })
                return -(tabsViewport.width + tabsCon.spacing) * idx
            }
            function doSlideAnimation(newTab) {
                var idx = mainLayout.tabs.findIndex(function (tab) {
                    return tab === newTab
                })
                var newX = -(tabsViewport.width + tabsCon.spacing) * idx
                slideChangeAnimation.stop()
                tabSlideAnimation.from = x
                tabSlideAnimation.to = newX
                slideChangeAnimation.start()
            }

            SequentialAnimation {
                id: slideChangeAnimation
                property real speed: 1
                property bool doing: false
                onStarted: {
                    doing = true
                }
                onStopped: {
                    if (tabsConScale.scale === 1) doing = false
                }
                PropertyAnimation {
                   id: tabScalAnimation
                   target: tabsConScale
                   property: 'scale'
                   from: tabsConScale.scale
                   to: 0.5
                   duration: Math.abs(from - to) / 0.5 * 200 * slideChangeAnimation.speed
                }
                PauseAnimation {
                    duration: 150 * slideChangeAnimation.speed
                }
                PropertyAnimation {
                   id: tabSlideAnimation
                   target: tabsCon
                   property: 'x'
                   from: 0
                   to: 0
                   duration: Math.abs(from - to) / (tabsViewport.width + tabsCon.spacing) * 200 * slideChangeAnimation.speed || 1
                }
                PauseAnimation {
                    duration: 150 * slideChangeAnimation.speed
                }
                PropertyAnimation {
                   id: tabScalAnimation2
                   target: tabsConScale
                   property: 'scale'
                   from: 0.5
                   to: 1
                   duration: 200 * slideChangeAnimation.speed
                }
            }


            transform: Scale {
                id: tabsConScale
                property real scale: 1
                xScale: scale
                yScale: scale
                origin.x: -tabsCon.x + tabsViewport.width / 2
//                origin.x: tabsCon.width / 2
                origin.y: parent.height /2
            }

            Repeater {
P
peterq 已提交
127
                id: tabRepeater
P
peterq 已提交
128 129 130 131 132
                model: tabs
                Rectangle {
                    id: tabWapper
                    width: tabsViewport.width
                    height: tabsViewport.height
P
peterq 已提交
133
                    signal active
P
peterq 已提交
134 135 136 137 138 139 140 141 142 143 144 145 146 147

//                    color: mainLayout.colors[index]
                    Rectangle {
                       visible: false
                       property real borderWidth: 10
                       width: parent.width + 2 * borderWidth
                       height: parent.height + 2 * borderWidth
                       x: -borderWidth
                       y: -borderWidth
                       border.color: 'red'
                       border.width: borderWidth
                    }
                    Loader {
                        id: tabLoader
148
                        focus: true
P
peterq 已提交
149 150
                        width: tabWapper.width
                        height: tabWapper.height
P
peterq 已提交
151 152 153
                        Component.onCompleted: {
                            tabLoader.setSource('../' + tabsUrl[modelData] + '/' + tabsUrl[modelData] + '.qml', {tabWapper: tabWapper})
                        }
P
peterq 已提交
154 155 156 157 158 159 160
                    }
                }
            }
        }
    }

    Component.onCompleted: {
P
peterq 已提交
161
        notiActive()
P
peterq 已提交
162
        console.log(Util.callGoSync('time'))
163
        Util.openDesktopWidget()
P
peterq 已提交
164 165 166 167 168 169 170 171 172 173
        Util.callGoAsync('wait', {time: 1})
            .then(function(data) {
                console.log('reslove', data)
            }, function(data) {
                console.log('reject', data)
            }, function(data) {
                console.log('progress', data)
            })
    }
}