提交 a7edd8cb 编写于 作者: P peterq

add: 完成悬浮窗总速度显示

上级 1cbfce82
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1560514149653" class="icon" style="" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="6681" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><defs><style type="text/css"></style></defs><path d="M960.662463 796.610106m-58.798151 0a57.459 57.459 0 1 0 117.596302 0 57.459 57.459 0 1 0-117.596302 0Z" p-id="6682"></path><path d="M915.950122 649.613194c22.959921 22.965038 60.188824 22.970154 83.153862 0.010233 12.331863-12.32777 17.977443-28.768207 17.067724-44.908816l0.221034 0c1.081635-65.859987-23.436782-132.064828-73.687256-182.325535-51.372018-51.385321-119.401414-75.911924-186.700169-73.629951 2.009773-12.817933 3.062755-25.953092 3.062755-39.334867 0-139.172713-112.820532-251.992221-251.992221-251.992221S255.083629 170.252569 255.083629 309.424258c0 14.32731 1.213641 28.368094 3.510964 42.042535-1.169639-0.016373-2.337231-0.044002-3.510964-0.044002-121.852232 0-223.502353 86.488817-246.915599 201.425545-0.014326 0.068562-0.025583 0.137123-0.038886 0.204661-0.399089 1.969864-0.778736 3.946892-1.131777 5.932106-0.045025 0.25378-0.082888 0.511653-0.12689 0.765433-0.315178 1.805112-0.620124 3.615341-0.896416 5.433756-0.057305 0.37453-0.102331 0.753153-0.157589 1.127683-0.251733 1.702782-0.496304 3.40761-0.713244 5.120624-0.069585 0.553609-0.12382 1.111311-0.190335 1.665942-0.185218 1.542122-0.370437 3.084245-0.528026 4.634554-0.073678 0.730641-0.12689 1.466398-0.195451 2.198062-0.127913 1.38351-0.261966 2.76395-0.367367 4.1536-0.070608 0.930185-0.116657 1.866511-0.177032 2.798742-0.077771 1.199315-0.165776 2.394537-0.227174 3.597945-0.066515 1.316995-0.104377 2.642177-0.150426 3.964288-0.028653 0.826831-0.072655 1.64957-0.094144 2.477424-0.054235 2.156106-0.081864 4.320399-0.081864 6.489808 0 39.141462 8.924253 76.199473 24.848944 109.24817 40.696888 84.4596 127.114073 142.744052 227.143277 142.744052 0.356111 0 0.709151-0.01228 1.065262-0.013303 1.660826-0.007163 3.319605-0.023536 4.972245-0.062422 0.817622-0.019443 1.63115-0.054235 2.446725-0.080841 1.210571-0.039909 2.420119-0.080841 3.625574-0.138146 0.901533-0.042979 1.798972-0.097214 2.697435-0.149403 1.11438-0.064468 2.226714-0.132006 3.337002-0.211824 0.932232-0.066515 1.861394-0.140193 2.790556-0.215918 1.073448-0.088004 2.14485-0.184195 3.214205-0.285502 0.940418-0.089028 1.879813-0.181125 2.817162-0.280386 1.055029-0.112564 2.105964-0.23536 3.1569-0.361227 0.938372-0.11154 1.87879-0.221034 2.814092-0.343831 1.051959-0.137123 2.098801-0.289596 3.146667-0.440022 0.924045-0.132006 1.849114-0.257873 2.77009-0.400113 1.12359-0.173962 2.240017-0.367367 3.358491-0.556679 1.752924-0.295735 3.498684-0.60989 5.239328-0.941442 0.88516-0.168846 1.772366-0.330528 2.654456-0.508583 1.084705-0.218988 2.162246-0.455371 3.241834-0.687662 0.815575-0.176009 1.63115-0.347924 2.443655-0.532119 1.107217-0.25071 2.209318-0.5137 3.310396-0.778736 0.76748-0.184195 1.534959-0.369414 2.299369-0.560772 1.131777-0.283456 2.25946-0.575098 3.385097-0.873903 0.708128-0.188288 1.414209-0.379647 2.12029-0.574075 1.172709-0.322341 2.343371-0.649799 3.508917-0.98749 0.604774-0.176009 1.207501-0.358157 1.810229-0.538259 1.257643-0.375553 2.514263-0.754177 3.764744-1.14815 0.349971-0.110517 0.696872-0.227174 1.045819-0.339738 6.42534-2.060939 12.738116-4.372587 18.927071-6.92369 0.187265-0.076748 0.375553-0.152473 0.561795-0.229221 1.459235-0.605797 2.910283-1.227967 4.356214-1.860371 0.23536-0.103354 0.470721-0.204661 0.705058-0.309038 1.456165-0.642636 2.905166-1.298576 4.347005-1.966795 0.173962-0.080841 0.347924-0.162706 0.521886-0.243547 44.061518-20.568455 81.183997-53.500495 106.908892-94.343715l215.969796-244.87922c52.624545-39.156812 127.370923-34.876322 175.126576 12.889565 27.290553 27.29567 40.35101 63.409169 39.253002 99.16758l0.095167 0C897.979842 620.837824 903.622352 637.281331 915.950122 649.613194zM361.774557 685.10657l-10.718109 12.355399c-0.522909 0.533143-1.043772 1.067308-1.575892 1.592264l-0.001023-0.001023c-10.614755 10.478655-22.964014 19.205411-36.577057 25.708522-0.057305 0.027629-0.115634 0.051165-0.172939 0.078795-1.88493 0.89744-3.791349 1.753947-5.723352 2.565429-0.152473 0.064468-0.310062 0.118704-0.463558 0.182149-1.841951 0.76441-3.700275 1.49812-5.583159 2.182712-0.264013 0.096191-0.535189 0.176009-0.800225 0.271176-1.780553 0.63445-3.572362 1.24741-5.386684 1.808182-0.397043 0.122797-0.803295 0.222057-1.201361 0.341784-1.695618 0.506537-3.396353 1.000793-5.118578 1.441838-0.553609 0.141216-1.119497 0.252757-1.676176 0.38681-1.584078 0.38374-3.169179 0.766456-4.774747 1.092891-0.720408 0.146333-1.454118 0.25378-2.178619 0.388856-1.458211 0.272199-2.913353 0.553609-4.387937 0.777713-0.937348 0.14224-1.890047 0.237407-2.833535 0.360204-1.282203 0.166799-2.557242 0.355087-3.850701 0.485047-1.223874 0.12382-2.464121 0.190335-3.697205 0.281409-1.029446 0.075725-2.051729 0.181125-3.087315 0.233314-2.200108 0.110517-4.414543 0.163729-6.641257 0.167822-0.080841 0-0.159636 0.00614-0.240477 0.00614-74.224492 0-134.39592-60.171428-134.39592-134.39592 0-2.285043 0.059352-4.555759 0.171915-6.813173 0.031722-0.64059 0.099261-1.27197 0.140193-1.910513 0.102331-1.592264 0.204661-3.183506 0.36225-4.76042 0.096191-0.963954 0.23536-1.914606 0.352017-2.871397 0.149403-1.228991 0.285502-2.461051 0.467651-3.679809 0.172939-1.155313 0.38988-2.296299 0.592494-3.441379 0.174985-0.994654 0.335644-1.9934 0.532119-2.979868 0.25992-1.298576 0.562818-2.581802 0.859577-3.867074 0.186242-0.807389 0.358157-1.620917 0.558725-2.422166 0.356111-1.417279 0.75213-2.819209 1.153266-4.218068 0.183172-0.642636 0.354064-1.289366 0.547469-1.927909 0.461511-1.523703 0.961908-3.031033 1.474584-4.532223 0.166799-0.487094 0.323365-0.979304 0.49528-1.464351 0.575098-1.61887 1.187035-3.219321 1.821485-4.808516 0.137123-0.343831 0.268106-0.690732 0.407276-1.033539 0.695848-1.701758 1.428535-3.384074 2.191922-5.051039 0.096191-0.209778 0.188288-0.421602 0.285502-0.63138 0.823761-1.774413 1.684362-3.527336 2.581802-5.258771 0.045025-0.085958 0.088004-0.172939 0.13303-0.258896 5.770424-11.067057 13.033851-21.233604 21.523199-30.232558 1.036609-1.00284 2.023076-2.054799 2.983961-3.12927 24.299429-24.164353 57.783031-39.104623 94.760201-39.104623 74.224492 0 134.39592 60.171428 134.39592 134.39592C389.480572 634.154108 379.138016 662.463873 361.774557 685.10657zM507.076874 443.821201c-74.224492 0-134.39592-60.171428-134.39592-134.39592s60.171428-134.39592 134.39592-134.39592 134.39592 60.171428 134.39592 134.39592S581.301366 443.821201 507.076874 443.821201z" p-id="6683"></path></svg>
\ No newline at end of file
......@@ -2,165 +2,192 @@ import QtQuick 2.9
import QtQuick.Window 2.2
import QtQuick.Controls 1.4 as Controls
import Qt.labs.platform 1.0
import '../js/util.js' as Util
import QtGraphicalEffects 1.0
import "../js/util.js" as Util
import "../js/global.js" as G
import "../js/app.js" as App
//包含系统托盘的导包
Window {
id: mainWindow
//大小根据屏幕计算,宽高比为6:14
id: root
visible: true
minimumHeight: 50
minimumWidth: 120
width: Screen.desktopAvailableWidth / 14
height: width * 3 / 7
title: qsTr("tiny monitor")
x: 100
width: contentContainer.width + 20
height: contentContainer.height + 20
title: 'pan-light float'
x: Screen.desktopAvailableWidth - width
y: 100
//无边框的window flags
flags: Qt.WA_TranslucentBackground | Qt.WA_TransparentForMouseEvents| Qt.FramelessWindowHint
| Qt.WindowSystemMenuHint
| Qt.WindowStaysOnTopHint | Qt.X11BypassWindowManagerHint
//灰色0.9透明度
// color: Qt.rgba(0,0,0,0)
flags: Qt.WA_TranslucentBackground | Qt.WA_TransparentForMouseEvents
| Qt.FramelessWindowHint | Qt.WindowSystemMenuHint
| Qt.WindowStaysOnTopHint | Qt.X11BypassWindowManagerHint
color: 'transparent'
Component.onCompleted: {
Util.bridge.changeAttribute(mainWindow, Qt.WA_TranslucentBackground, true)
Util.bridge.changeAttribute(mainWindow, Qt.WA_TransparentForMouseEvents, true)
DataSaver {
$key: 'window.float'
property alias x: root.x
property alias y: root.y
}
Rectangle {
anchors.fill: parent
color: Qt.rgba(0,0,0,0)
border.color: 'red'
border.width: 2
}
Rectangle {
id: rectangle
x: 0
y: 0
width: mainWindow.height
height: width
color: Qt.rgba(0.2, 1.0, 0.0, 0.7)
Component.onCompleted: {
}
}
id: contentContainer
width: 130
height: 35
border.color: 'gray'
// radius: 5
clip: true
anchors.centerIn: parent
// 混合动画效果(这里混合x和y轴平移
ParallelAnimation {
id: moveAnimation
running: false
PropertyAnimation {
target: mainWindow
property: 'x'
easing.type: Easing.Linear
duration: 100
Rectangle {
id: logo
x: 1
height: parent.height - 2
anchors.verticalCenter: parent.verticalCenter
width: height * 1.1
color: '#38f'
IconFont {
type: 'baidu-cloud'
width: parent.height * 0.8
color: 'white'
anchors.centerIn: parent
}
}
PropertyAnimation {
target: mainWindow
property: 'y'
easing.type: Easing.Linear
duration: 100
Rectangle {
anchors.left: logo.right
anchors.verticalCenter: parent.verticalCenter
height: parent.height - 2
width: parent.width - 2 - logo.width
color: '#a2dcf4'
Text {
text: ''
color: '#34658a'
anchors.centerIn: parent
Timer {
interval: 1000
running: root.visible
triggeredOnStart: true
repeat: true
onTriggered: {
var data = {
"speed": 0
}
App.appState.transferComp.sumSpeed(data)
parent.text = Util.humanSize(data.speed) + '/s'
}
}
}
}
}
//鼠标可控制区域
MouseArea {
property point clickPos: "0,0"
id: dragRegion
anchors.fill: rectangle
drag.minimumX: 0
drag.maximumX: Screen.desktopAvailableWidth - mainWindow.width
drag.minimumY: 0
drag.maximumY: Screen.desktopAvailableHeight - mainWindow.heigh
onPressed: {
mainWindow.requestActivate()
clickPos = Qt.point(mouseX, mouseY)
OpacityMask {
anchors.fill: logo
source: logo
maskSource: contentContainer
visible: true
antialiasing: true
}
onPositionChanged: {
moveAnimation.stop()
//鼠标偏移量
var delta = Qt.point(mouse.x - clickPos.x, mouse.y - clickPos.y)
// console.log(delta.x + " " + delta.y)
mainWindow.x += delta.x
mainWindow.y += delta.y
moveAnimation.start()
}
//添加右键菜单
acceptedButtons: Qt.LeftButton | Qt.RightButton // 激活右键(别落下这个)
onClicked: {
if (mouse.button === Qt.RightButton) {
// 右键菜单
contentMenu.popup()
MouseArea {
property point clickPos: "0,0"
anchors.fill: parent
onPressed: {
root.requestActivate()
clickPos = Qt.point(mouseX, mouseY)
}
onPositionChanged: {
var delta = Qt.point(mouse.x - clickPos.x, mouse.y - clickPos.y)
root.x += delta.x
root.y += delta.y
}
acceptedButtons: Qt.LeftButton | Qt.RightButton
onClicked: {
if (mouse.button === Qt.RightButton) {
contentMenu.popup()
}
}
}
}
//不是托盘的菜单类
DropShadow {
anchors.fill: contentContainer
horizontalOffset: -5
verticalOffset: -5
radius: 12.0
samples: 25
color: "#20000000"
spread: 0.0
source: contentContainer
}
DropShadow {
anchors.fill: contentContainer
horizontalOffset: 5
verticalOffset: 5
radius: 12.0
samples: 25
color: "#20000000"
spread: 0.0
source: contentContainer
}
// 右键菜单
Controls.Menu {
id: contentMenu
// 右键菜单
Controls.MenuItem {
id:hideItem
text: qsTr("隐藏")
id: hideItem
text: '隐藏悬浮窗'
onTriggered: {
if(trayIcon==null){
console.log("系统托盘不存在");
contentMenu.removeItem(hideItem);
return;
}else{
if(trayIcon.available){
console.log("系统托盘存在");
}else{
console.log("系统托盘不存在");
contentMenu.removeItem(hideItem)
}
}
mainWindow.hide()
root.hide()
}
}
Controls.MenuItem {
text: qsTr("退出")
text: '显示主界面'
visible: !G.root.visible
onTriggered: {
G.root.show()
G.root.raise()
G.root.requestActivate()
}
}
Controls.MenuItem {
text: '退出程序'
onTriggered: Qt.quit()
}
}
//使用系统托盘的菜单组件
// 系统托盘菜单
Menu {
id: systemTrayMenu
// 右键菜单
MenuItem {
text: qsTr("隐藏")
shortcut: "Ctrl+z"
onTriggered: mainWindow.hide()
visible: root.visible
text: '隐藏悬浮窗'
onTriggered: root.hide()
}
MenuItem {
text: '显示悬浮窗'
visible: !root.visible
onTriggered: {
root.show()
}
}
MenuItem {
text: qsTr("显示")
text: '显示主界面'
onTriggered: {
mainWindow.show()
mainWindow.flags = Qt.WA_TranslucentBackground
| Qt.WA_TransparentForMouseEvents| Qt.FramelessWindowHint
| Qt.WindowSystemMenuHint
| Qt.WindowStaysOnTopHint | Qt.X11BypassWindowManagerHint
G.root.show()
G.root.raise()
G.root.requestActivate()
}
}
MenuItem {
text: qsTr("退出")
text: '退出程序'
onTriggered: Qt.quit()
}
}
//系统托盘
// 系统托盘
SystemTrayIcon {
id:trayIcon
id: trayIcon
visible: true
iconSource: "../assets/images/pan-light-1.png"
tooltip: "tiny-流量监控软件"
tooltip: "pan-light tray"
onActivated: {
mainWindow.show()
mainWindow.raise()
mainWindow.requestActivate()
root.show()
root.raise()
root.requestActivate()
}
menu: systemTrayMenu
}
......
......@@ -72,7 +72,12 @@ var hideDesktopWidget
ins = comp.createObject(null)
return
}
ins.visbal = true
ins.visible = true
}
hideDesktopWidget = function () {
if (ins) {
ins.visible = false
}
}
})()
......
......@@ -7,6 +7,7 @@ import "./layout"
import "./login"
import "./videoPlayer"
import "./widget"
import "./comps"
Window {
id: mainWindow
visible: true
......@@ -14,11 +15,20 @@ Window {
height: 680
minimumHeight: 600
minimumWidth: 900
title: "hello peterq2"
title: "pan-light"
signal customerEvent(string event, var data)
flags: Qt.WA_TranslucentBackground | Qt.WA_TransparentForMouseEvents| Qt.FramelessWindowHint
color: 'transparent'
visibility: Window.Windowed
DataSaver {
$key: 'window.main'
property alias x: mainWindow.x
property alias y: mainWindow.y
property alias width: mainWindow.width
property alias height: mainWindow.height
}
Component {
id: layoutComp
Layout {}
......
......@@ -163,5 +163,6 @@
<file>assets/images/icons/min.svg</file>
<file>assets/images/icons/more-down.svg</file>
<file>widget/Resize.qml</file>
<file>assets/images/icons/baidu-cloud.svg</file>
</qresource>
</RCC>
......@@ -22,6 +22,16 @@ Item {
signal taskEvent(string event, var data)
property string speed: ''
property int speedInt: 0
Connections {
target: App.appState.transferComp
onSumSpeed: {
if (isFinish)
return
data.speed += speedInt
}
}
DataSaver {
$key: 'download-item-' + root.downloadId
......@@ -65,6 +75,7 @@ Item {
interval: 1100
onTriggered: {
speed = ''
speedInt = 0
}
}
......@@ -72,6 +83,7 @@ Item {
// 更新下载速度
if (event === 'task.speed') {
speed = Util.humanSize(data.speed) + '/s'
speedInt = data.speed
speedClearTimer.restart()
progress = data.progress
return
......@@ -134,7 +146,8 @@ Item {
visible: !isFinish && meta.useVip
anchors.verticalCenter: parent.verticalCenter
anchors.left: fileNameText.left
anchors.leftMargin: 10 + Math.min(fileNameText.width, fileNameText.implicitWidth)
anchors.leftMargin: 10 + Math.min(fileNameText.width,
fileNameText.implicitWidth)
}
MouseArea {
......@@ -152,7 +165,7 @@ Item {
w: 500
h: 200
title: '确认删除'
onClickConfirm: function() {
onClickConfirm: function () {
result = checkBox.checked
return true
}
......
......@@ -4,6 +4,9 @@ import "../js/util.js" as Util
Item {
id: root
signal sumSpeed(var data)
HeaderBar {
id: headerBar
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册