FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
NetSpeed/WinDesktop.cpp at master · XMuli/NetSpeed · GitHub
XMuli
/
NetSpeed
Public
Notifications
You must be signed in to change notification settings
Fork
15
Star
70
Code
Issues
3
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
NetSpeed
/
WinDesktop.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
124 lines (103 loc) · 3.4 KB
Breadcrumbs
NetSpeed
/
WinDesktop.cpp
Copy path
File metadata and controls
124 lines (103 loc) · 3.4 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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
/
/ SPDX-SnippetCopyrightText: 2020-2025 Wengeng Zhan
g
//
SPDX-Author: Wengeng Zhang <xmulitech@gmail.com>
//
SPDX-License-Identifier: MIT
#
include
"
WinDesktop.h
"
#
include
<
QVBoxLayout
>
#
include
<
QHBoxLayout
>
#
include
<
QLabel
>
#
include
<
QDebug
>
#
include
<
QTimer
>
#
include
<
QWidget
>
#
include
<
QPushButton
>
#
include
"
ProgressLabel.h
"
/*
!
* \brief WinDesktop::WinDesktop
*
* \htmlonly
* <pre style="font-family: FreeMono, Consolas, Menlo, 'Noto Mono', 'Courier New', Courier, monospace;line-height: 100%;">
* ==============================
* || CPU 各核占用率 ||
* ==============================
* </pre>
* \endhtmlonly
* \param parent
*/
WinDesktop::WinDesktop
(QWidget *parent)
: WinTransparent(parent)
, m_mainLayout(
new
QVBoxLayout(
this
))
, m_info(
new
MonitorInfo_x11())
, m_timer(
new
QTimer())
{
init
();
}
void
WinDesktop::init
()
{
m_mainLayout->
setMargin
(
6
);
m_mainLayout->
setSpacing
(
10
);
m_info->
cpuInfo
(m_vec);
bool
isBegin =
true
;
for
(
auto
v : m_vec) {
QWidget *widget =
new
QWidget
();
widget->
setContentsMargins
(
0
,
0
,
0
,
0
);
widget->
setMaximumHeight
(
12
);
//
QPalette pal = widget->palette(); // Test
//
pal.setColor(QPalette::Background, Qt::green);
//
widget->setAutoFillBackground(true);
//
widget->setPalette(pal);
QHBoxLayout *hLayout =
new
QHBoxLayout
(widget);
hLayout->
setMargin
(
0
);
hLayout->
setSpacing
(
0
);
QString
text
(
"
"
);
if
(isBegin) {
text =
QString
(
"
CPU
"
) +
"
:
"
;
isBegin =
false
;
}
else
{
text =
QString
(
"
CPU
"
) +
QString::number
(v.
index
) +
"
:
"
;
}
QLabel *lab =
new
QLabel
(text);
lab->
setMargin
(
0
);
lab->
setMinimumWidth
(
50
);
ProgressLabel *progress =
new
ProgressLabel
();
//
QPalette pal2 = widget->palette(); // Test
//
pal2.setColor(QPalette::Background, Qt::gray);
//
progress->setAutoFillBackground(true);
//
progress->setPalette(pal2);
progress->
winDestktopPtr
(
this
);
progress->
m_val
= v.
cpuWork
;
progress->
m_all
= v.
cpuAll
;
QLabel *percentage =
new
QLabel
(
"
00.00%
"
);
percentage->
setMargin
(
0
);
percentage->
setMinimumWidth
(
55
);
percentage->
setAlignment
(Qt::AlignRight | Qt::AlignVCenter);
hLayout->
addWidget
(lab,
1
, Qt::AlignLeft);
hLayout->
addWidget
(progress,
9
);
//
不能加 Qt::AlignLeft
hLayout->
addWidget
(percentage,
1
, Qt::AlignRight);
m_mainLayout->
addWidget
(widget);
}
m_mainLayout->
addStretch
(
10
);
connect
(m_timer, &QTimer::timeout,
this
, &WinDesktop::onUpdate);
m_timer->
setInterval
(
1000
);
m_timer->
start
();
resize
(
300
,
400
);
}
QVBoxLayout*
WinDesktop::mainLayout
()
{
return
m_mainLayout;
}
void
WinDesktop::onUpdate
()
{
auto
list =
this
->
findChildren
<ProgressLabel *>();
QVector<CpuInfo> vec;
m_info->
cpuInfo
(vec);
for
(
int
i =
0
; i < list.
size
(); i +=
3
) {
int
num = i +
1
;
int
numNext = i +
2
;
int
index = i /
3
;
list[num]->
m_val
= vec[index].
cpuWork
- m_vec[index].
cpuWork
;
list[num]->
m_all
= vec[index].
cpuAll
- m_vec[index].
cpuAll
;
list[numNext]->
setText
(
QString::number
(list[num]->
m_val
*
100.0
/ list[num]->
m_all
,
'
f
'
,
2
) +
"
%
"
);
m_vec[index].
cpuWork
= vec[index].
cpuWork
;
m_vec[index].
cpuAll
= vec[index].
cpuAll
;
}
emit
sigValChange
();
}
Back
|
FazBrowse Home
|
New Git URL