From 3a6d997fd146a499d2be374e9b7e52d256fc3880 Mon Sep 17 00:00:00 2001 From: peterq Date: Tue, 2 Jul 2019 14:28:59 +0800 Subject: [PATCH] fix pc: crash in mac --- pc/gui/qml/explore/Explore.qml | 135 +++++++++++++++++++++++++++++++ pc/gui/qml/pan/Pan.qml | 87 ++++++++++++++++++++ pc/gui/qml/transfer/Transfer.qml | 114 ++++++++++++++++++++++++++ 3 files changed, 336 insertions(+) create mode 100644 pc/gui/qml/explore/Explore.qml create mode 100644 pc/gui/qml/pan/Pan.qml create mode 100644 pc/gui/qml/transfer/Transfer.qml diff --git a/pc/gui/qml/explore/Explore.qml b/pc/gui/qml/explore/Explore.qml new file mode 100644 index 0000000..303c776 --- /dev/null +++ b/pc/gui/qml/explore/Explore.qml @@ -0,0 +1,135 @@ +import QtQuick 2.0 +import "../comps" + +Item { + id: root + property var tasbs: Object.keys(tasbsMap) + property var tasbsMap: { + "newest": '最新', + "hottest": '最热', + "official": '官方' + } + property string currentTab: 'newest' + + signal active + + onCurrentTabChanged: { + listRepeater.itemAt(tasbs.indexOf(currentTab)).active() + } + + + onActive: { + listRepeater.itemAt(tasbs.indexOf(currentTab)).active() + } + + DataSaver { + $key: 'page-explorer' + property alias showTip: tip.showTip + } + + Column { + anchors.fill: parent + Rectangle { + id: tip + property string showTip: 'show' + visible: showTip === 'show' + color: '#409EFF' + width: parent.width + height: visible ? textTip.implicitHeight + 20 : 0 + Text { + id: textTip + color: 'white' + width: parent.width - 40 + anchors.centerIn: parent + wrapMode: Text.WrapAnywhere + text: '开放型的资源广场, 突破版权文件分享限制(被和谐的违规文件除外).实验性功能, 暂只支持分享大于256k的文件.' + } + IconButton { + iconType: 'close' + color: 'red' + anchors.right: parent.right + anchors.rightMargin: 10 + anchors.verticalCenter: parent.verticalCenter + onClicked: { + tip.showTip = '' + } + } + } + + Rectangle { + id: tabsBar + width: parent.width + height: 60 + Rectangle { + width: parent.width + height: 1 + color: '#ddd' + anchors.bottom: parent.bottom + } + Item { + id: typeTab + property int padding: 4 + property int tabWidth: 80 + width: tabWidth * tabs.length + 2 * padding + height: parent.height * 0.7 + anchors.verticalCenter: parent.verticalCenter + x: 10 + Rectangle { + anchors.fill: parent + radius: 3 + color: '#eee' + } + + Rectangle { + radius: 3 + width: typeTab.tabWidth + height: typeTab.height - 2 * typeTab.padding + color: '#fff' + anchors.verticalCenter: parent.verticalCenter + x: typeTab.padding + root.tasbs.indexOf( + root.currentTab) * typeTab.tabWidth + Behavior on x { + PropertyAnimation { + duration: 400 + easing.type: Easing.OutCubic + } + } + } + + Repeater { + model: root.tasbs + delegate: Item { + width: typeTab.tabWidth + height: typeTab.height - 2 * typeTab.padding + anchors.verticalCenter: parent.verticalCenter + x: typeTab.padding + index * typeTab.tabWidth + Text { + text: root.tasbsMap[modelData] + anchors.centerIn: parent + } + MouseArea { + anchors.fill: parent + onClicked: { + root.currentTab = modelData + } + } + } + } + } + + + } + + Repeater { + id: listRepeater + model: root.tasbs + ShareList { + id: shareList + type: modelData + height: parent.height - tip.height - tabsBar.height + width: parent.width + visible: root.currentTab == type + } + } + } +} diff --git a/pc/gui/qml/pan/Pan.qml b/pc/gui/qml/pan/Pan.qml new file mode 100644 index 0000000..b1878e7 --- /dev/null +++ b/pc/gui/qml/pan/Pan.qml @@ -0,0 +1,87 @@ +import QtQuick 2.0 +import '../videoPlayer' +import '../js/app.js' as App +import '../js/util.js' as Util +import '../comps' +import './left-panel' +Rectangle { + id: root + + signal active + + // 左侧信息栏 + LeftPanel { + id: leftPanel + height: parent.height + width: 250 + // 右侧border + Rectangle { + color: 'gray' + width: 2 + height: parent.height + anchors.right: parent.right + } + } + // 头部加列表 + Rectangle { + anchors.left: leftPanel.right + width: root.width - leftPanel.width + height: parent.height + PathNav { + id: pathNav + width: parent.width + height: 40 + // 下侧border + Rectangle { + color: 'gray' + width: parent.width + height: 2 + anchors.bottom: parent.bottom + } + } + FileList { + width: parent.width + height: parent.height - pathNav.height + anchors.top: pathNav.bottom + color: "#fff" + + Rectangle { + id: loading + anchors.fill: parent + visible: false + color: Qt.rgba(1,1,1,.6) + Component { + id: iconComp + IconFont { + type: 'loading' + width: Math.min(loading.width, loading.height) * 0.3 + } + } + Loader { + id: iconLoader + focus: true + anchors.centerIn: parent + } + Component.onCompleted: { + // 监听进入path, 延时500ms显示加载动画 + App.appState.enterPathPromiseChanged.connect(function() { + if (!App.appState.enterPathPromise) { + loading.visible = false + iconLoader.sourceComponent = null + return + } + var p = App.appState.enterPathPromise + Util.sleep(500) + .then(function(){ + if (App.appState.enterPathPromise === p) { + iconLoader.sourceComponent = iconComp + loading.visible = true + } + }) + }) + } + } + LoadDirError{} + } + } +} diff --git a/pc/gui/qml/transfer/Transfer.qml b/pc/gui/qml/transfer/Transfer.qml new file mode 100644 index 0000000..17a0b22 --- /dev/null +++ b/pc/gui/qml/transfer/Transfer.qml @@ -0,0 +1,114 @@ +import QtQuick 2.0 +import "../js/app.js" as App +import "../js/util.js" as Util + +Item { + id: root + + signal sumSpeed(var data) + signal active + + HeaderBar { + id: headerBar + } + Rectangle { + width: parent.width + height: 2 + color: 'gray' + anchors.bottom: headerBar.bottom + } + DownloadList { + id: downloadingList + visible: headerBar.currentTab == '下载中' + isFinish: false + anchors.top: headerBar.bottom + width: parent.width + height: parent.height - headerBar.height + } + DownloadList { + id: downloadedList + visible: headerBar.currentTab == '已完成' + isFinish: true + anchors.top: headerBar.bottom + width: parent.width + height: parent.height - headerBar.height + } + Component.onCompleted: { + App.appState.transferComp = root + } + + function addDownload(meta, useVip) { + return Util.Promise.resolve().then(function () { + var evt = { + "fid": meta.fs_id + '', + "exist": false + } + downloadingList.checkFid(evt) + if (evt.exist) + return Util.confirm() + return true + }).then(function () { + if (App.appState.settings.defaultDownloadPath) + return App.appState.settings.defaultDownloadPath + return Util.pickSavePath({ + "fileName": meta.server_filename, + "defaultFolder": App.appState.settings.lastDownloadPath + }) + }).then(function (savePath) { + savePath = savePath.toString() + var newFid = (useVip ? 'vip' : 'direct') + '.' + meta.fs_id + var id = Util.callGoSync('download.new', { + "fid": newFid, + "savePath": savePath + }) + var obj = JSON.parse(JSON.stringify(meta)) + obj.downloadId = id + var sep = Qt.platform.os == "windows" ? '\\' : '/' + var t = String.prototype.split.call(savePath, sep) + obj.newFid = newFid + obj.saveName = t.pop() + obj.savePath = savePath + obj.useVip = !!useVip + downloadingList.add(obj) + }) + } + + function addDownloadShare(md5, sliceMd5, fileSize, fileName) { + var fid = ['share', md5, sliceMd5, fileSize].join('.') + return Util.Promise.resolve().then(function () { + return Util.pickSavePath({ + "fileName": fileName, + "defaultFolder": App.appState.settings.lastDownloadPath + }) + }).then(function (savePath) { + var id = Util.callGoSync('download.new', { + "fid": fid, + "savePath": savePath + }) + var obj = { + "size": fileSize, + "downloadId": id, + "newFid": fid, + "savePath": savePath, + "useVip": true, + "fileName": fileName, + "isShare": true + } + var sep = Qt.platform.os == "windows" ? '\\' : '/' + var t = String.prototype.split.call(savePath, sep) + obj.saveName = t.pop() + downloadingList.add(obj) + }) + } + + function deleteItem(idx, isFinish) { + var c = isFinish ? downloadedList : downloadingList + c.remove(idx) + } + + function itemCompleted(idx) { + var data = JSON.parse(JSON.stringify(downloadingList.get(idx))) + downloadingList.remove(idx) + downloadedList.add(data) + } +} -- GitLab