-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_window.cpp
81 lines (65 loc) · 2.14 KB
/
main_window.cpp
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
#include "main_window.h"
#include "utils.h"
#include <QApplication>
#include <QMouseEvent>
#include <QPainter>
#include <QThread>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
mainWidget = new QWidget();
layout = new QHBoxLayout();
networkLayout = new QVBoxLayout();
memoryMonitor = new MemoryMonitor();
downloadLabel = new QLabel("↓0.0K");
uploadLabel = new QLabel("↑0.0K");
thread = new Thread();
QAction *quitAction = new QAction("退出", this);
menu = new QMenu;
menu->addAction(quitAction);
downloadLabel->setStyleSheet("QLabel { font-size: 13px; color: #2E6843; }");
uploadLabel->setStyleSheet("QLabel { font-size: 13px; color: #FF0000; }");
setWindowFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint);
networkLayout->setMargin(0);
networkLayout->setSpacing(0);
networkLayout->addStretch();
networkLayout->addWidget(uploadLabel);
networkLayout->addWidget(downloadLabel);
networkLayout->addStretch();
layout->setMargin(0);
layout->addWidget(memoryMonitor);
layout->addLayout(networkLayout);
mainWidget->setLayout(layout);
setCentralWidget(mainWidget);
connect(quitAction, &QAction::triggered, this, &QApplication::quit);
connect(thread, &Thread::updateNetworkSpeed, this, &MainWindow::updateNetworkSpeed);
thread->start();
}
MainWindow::~MainWindow()
{
}
void MainWindow::paintEvent(QPaintEvent *e)
{
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing, true);
painter.setPen(Qt::NoPen);
painter.setBrush(QColor("#F1F1F1"));
painter.drawRect(rect());
}
void MainWindow::mouseMoveEvent(QMouseEvent *e)
{
if (e->buttons() & Qt::LeftButton)
move(e->globalPos() - p);
}
void MainWindow::mousePressEvent(QMouseEvent *e)
{
if (e->button() == Qt::LeftButton) {
p = e->globalPos() - frameGeometry().topLeft();
}else if (e->button() == Qt::RightButton)
menu->exec(QCursor::pos());
}
void MainWindow::updateNetworkSpeed(QString upload, QString download)
{
uploadLabel->setText(upload);
downloadLabel->setText(download);
}