2
* Copyright (C) 2013 National University of Defense Technology(NUDT) & Kylin Ltd.
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; version 3.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
#include "progressdialog.h"
17
#include "ui_progressdialog.h"
19
#include <QMouseEvent>
21
extern bool progress_flag;
22
ProgressDialog::ProgressDialog(QWidget *parent) :
24
ui(new Ui::ProgressDialog)
27
progress_flag = false;
28
this->setAttribute(Qt::WA_DeleteOnClose);
29
this->setWindowFlags(Qt::ToolTip | Qt::FramelessWindowHint);
30
this->setAttribute(Qt::WA_TranslucentBackground);
31
ui->label->setStyleSheet("QLabel {color: green; font-size: 12px}");
32
// ui->label_2->setStyleSheet("QLabel {color: black; font-size: 12px}");
33
// ui->progressBar->setStyleSheet("QProgressBar {border: 1px solid grey;border-radius: 2px;text-align: center;}"
34
// "QProgressBar::chunk {background-color: #6be2fa;width: 10px;}");
35
QDesktopWidget* desktop = QApplication::desktop();
37
move((desktop->width() - this->width())/2, (desktop->height() - this->height())/2);
40
ProgressDialog::~ProgressDialog() {
44
void ProgressDialog::reset_status() {
46
ui->label_2->setText(tr("%1").arg(ratio_sus)+"%");
48
ui->label->setText("开始");
52
void ProgressDialog::setDynamicSoftwareProgress(QString type, QString msg) {
53
if(this->isHidden()) {
56
if(type == "down_start") {
57
ui->label->setText("开始下载");
58
// ui->progressBar->setValue(0);
59
ui->label_2->setText(tr("%1").arg(ratio_sus)+"%");
62
else if(type == "down_pulse"){
64
if(msg.contains("download_bytes") && msg.contains("total_bytes")) {
65
QStringList process_value = msg.split(",");
66
if (process_value.size() == 4) {
67
QStringList download_bytes = process_value.at(0).split(":");
68
double download_bytes_value = download_bytes.at(1).toDouble();
69
QStringList total_bytes = process_value.at(1).split(":");
70
double total_bytes_value = total_bytes.at(1).toDouble();
71
double percent = download_bytes_value / total_bytes_value;
72
QString ratio = QString::number(percent, 'f', 2);
73
double trans = ratio.toDouble() * 100;
74
ratio = QString::number(trans,'f',0);
75
// ui->progressBar->setValue(ratio.toInt());
76
ratio_sus=ratio.toInt();
79
softwareSourceUpdateProgressToSudoDispather(ratio);
82
ui->label->setText("正在下载安装包...");
83
ui->label_2->setText(tr("%1").arg(ratio_sus)+"%");
89
else if(type == "down_stop") {
94
ui->label->setText("下载完成");
96
ui->label_2->setText(tr("%1").arg(ratio_sus)+"%");
99
else if(type == "apt_start"){
100
if(this->isHidden()) {
103
ui->label->setText("开始");
104
// ui->progressBar->setValue(0);
105
ui->label_2->setText(tr("%1").arg(ratio_sus)+"%");
109
else if(type == "apt_pulse"){
111
if(msg.contains(",")) {
112
QStringList process_value = msg.split(",");
113
if (process_value.size() == 2) {
114
QStringList status_value = process_value.at(0).split(":");
115
int value = status_value.at(1).toInt();
116
QStringList action_value = process_value.at(1).split(":");
117
QString act = action_value.at(1);
118
ui->label->setText("正在进行:" + act);
119
// ui->progressBar->setValue(value);
121
ui->label_2->setText(tr("%1").arg(ratio_sus)+"%");
126
else if(type == "apt_stop") {
127
ui->label->setText("完成");
128
// ui->progressBar->setValue(0);
130
ui->label_2->setText(tr("%1").arg(ratio_sus)+"%");
133
QTimer *timer = new QTimer(this);
134
timer->setInterval(2000);
135
connect(timer,SIGNAL(timeout()),this,SLOT(reset_status()));
144
void ProgressDialog::mousePressEvent(QMouseEvent *event) {
145
if (event->button() == Qt::LeftButton) {
146
dragPos = event->globalPos() - frameGeometry().topLeft();
151
void ProgressDialog::mouseMoveEvent(QMouseEvent *event) {
152
if (event->buttons() & Qt::LeftButton ) {
153
move(event->globalPos() - dragPos);
154
setWindowOpacity(0.5);
159
void ProgressDialog::mouseReleaseEvent(QMouseEvent *event) {
160
if (event->button() == Qt::LeftButton) {
167
QSize ProgressDialog::sizeHint()const {
168
return QSize(height(),height());
171
void ProgressDialog::resizeEvent(QResizeEvent *) {
175
void ProgressDialog::paintEvent(QPaintEvent *) {
176
QPainter painter(this);
178
QPixmap progress_bar1;
179
QPixmap progress_bar2;
181
background.load(":/pixmap/image/progress-bg.png");
182
progress_bar1.load(":/pixmap/image/progress-bar1.png");
183
progress_bar2.load(":/pixmap/image/progress-bar2.png");
184
painter.drawPixmap(0,0, background);
185
painter.setPen(Qt::transparent);
187
painter.drawPixmap(10,30,progress_bar1);
188
// painter.drawPixmap(10,30,progress_bar2,0,0,progress_bar2.width()*(ratio_sus*0.01),progress_bar2.height());
189
painter.drawPixmap(10,30,progress_bar2.width()*(ratio_sus*0.01),progress_bar2.height(),progress_bar2);
190
style()->drawPrimitive(QStyle::PE_Widget,&opt,&painter,this);