├── README.md ├── green.png ├── main.cpp ├── monitorwindow.cpp ├── monitorwindow.h ├── monitorwindow.ui ├── monitot.cpp ├── monitot.h ├── monitot.ui ├── painter.pro ├── painter.pro.user ├── painter.pro.user.0512359 ├── painter.pro.user.6fdd718 ├── painter.pro.user.984e197 ├── painter.pro.user.d7bd2e8 ├── painter.pro.user.dc0572a ├── printcpu ├── manager.cpp ├── manager.h ├── manager.ui ├── printcpu.pro ├── printcpu.pro.user ├── printcpu.pro.user.984e197 ├── printcpu.pro.user.d7bd2e8 ├── widget.cpp ├── widget.h └── widget.ui ├── red.png ├── res.qrc ├── yellow.png └── 截图 ├── 截图_2017-12-04_11-37-58.png ├── 截图_2017-12-04_11-38-28.png ├── 截图_2017-12-04_11-38-39.png ├── 截图_2017-12-04_11-39-54.png └── 截图_2017-12-04_11-48-20.png /README.md: -------------------------------------------------------------------------------- 1 | 12.04更新 2 | 3 | ①加了CPU界面透明,并且能够自定义,Ctrl+鼠标滚动即可调节透明度 4 | 5 | ②任务界面点击CPU数值也可以弹出CPU界面。 6 | 7 | 12.02更新 8 | 9 | 增加cpu占用显示,右键可打开查看各cpu占用情况,俗称——数框框。 10 | 11 | 双击数框框界面可改变自由改变界面的大小,再次双击就能退出这个功能,暂时没做半透明,以后会设置一个小心的透明度,但不能自定义,毕竟只是小软件,尽量不做自定义功能。以后会增加 点击查看任务那个界面的CPU占用 能弹出数框框界面,之前一下子没想到,忘了做这个功能。 12 | 13 | 到此,这个软件基本就是这样了。 14 | 15 | 另外,以前fudeepinck-dock任务栏的插件已经不做,代码我也删除了。 16 | 17 | 一是因为不想在忍受fudeepinck的垃圾们了, 18 | 19 | 二是因为fudeepinck的垃圾api设计能力,毫无远见,想一点写一点,所以他们更新api后插件就废了。(呸,有那么多前人的经验给你参考还做不好,还好意思吐槽别人gnome的api多变?自大还是弱智啊。) 20 | 21 | ![截图](https://github.com/noahsai/monitor-desktop/raw/master/截图/截图_2017-12-04_11-37-58.png) 22 | ![截图](https://github.com/noahsai/monitor-desktop/raw/master/截图/截图_2017-12-04_11-38-28.png) 23 | ![截图](https://github.com/noahsai/monitor-desktop/raw/master/截图/截图_2017-12-04_11-38-39.png) 24 | ![截图](https://github.com/noahsai/monitor-desktop/raw/master/截图/截图_2017-12-04_11-39-54.png) 25 | ![截图](https://github.com/noahsai/monitor-desktop/raw/master/截图/截图_2017-12-04_11-48-20.png) 26 | 27 | 28 | -------------------------------------------------------------------------------- /green.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/noahsai/monitor-desktop/31f60350d16b71c377b2ec4a84138a6fa199a18a/green.png -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | #include "monitot.h" 2 | #include 3 | //---------------------- 4 | //测试monitorwindow用 5 | //#include"monitorwindow.h" 6 | 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | 11 | QApplication a(argc, argv); 12 | monitot w; 13 | w.show(); 14 | return a.exec(); 15 | 16 | } 17 | -------------------------------------------------------------------------------- /monitorwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "monitorwindow.h" 2 | #include "ui_monitorwindow.h" 3 | #include 4 | 5 | monitorwindow::monitorwindow(QWidget *parent) : 6 | QWidget(parent), 7 | ui(new Ui::monitorwindow) 8 | { 9 | ui->setupUi(this); 10 | this->setGeometry(QApplication::desktop()->width()-120,QApplication::desktop()->height()-120,86,32); 11 | setWindowFlags(Qt::FramelessWindowHint 12 | |Qt::WindowStaysOnTopHint 13 | |Qt::Tool 14 | );//去边框//最ding层显示//不在任务栏显示 15 | ui->tableWidget->setColumnCount(4); 16 | 17 | // QStringList header; 18 | // header<tableWidget->setHorizontalHeaderLabels(header); 20 | ui->tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows); 21 | ui->tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers); 22 | ui->tableWidget->horizontalHeader()->setStretchLastSection(true); 23 | ui->tableWidget->horizontalHeader()->resizeSection(0,120); 24 | ui->tableWidget->horizontalHeader()->resizeSection(1,40); 25 | ui->tableWidget->horizontalHeader()->resizeSection(2,40); 26 | ui->tableWidget->horizontalHeader()->resizeSection(3,30); 27 | ui->tableWidget->horizontalHeader()->setFixedHeight(20); 28 | ui->tableWidget->verticalHeader() ->setDefaultSectionSize(25); 29 | ui->tableWidget->setFrameShape(QFrame::NoFrame); 30 | //ui->tableWidget->setFixedSize(230,250); 31 | 32 | adjustSize(); 33 | setFixedSize(QSize(230,320));//10+30+10+20+250 34 | cmd = MEM_SORT; 35 | process = new QProcess(this); 36 | timer = new QTimer(this); 37 | timer->setInterval(3000); 38 | timer->setSingleShot(true);//手动开始/停止 39 | connect(timer,SIGNAL(timeout()),this,SLOT(getinfo())); 40 | //timer->start();// 41 | getinfo();//timer->start()在里面 42 | } 43 | 44 | monitorwindow::~monitorwindow() 45 | { 46 | delete ui; 47 | } 48 | 49 | void monitorwindow::stop_hide() 50 | { 51 | timer->stop(); 52 | hide(); 53 | } 54 | 55 | bool monitorwindow::getinfo() 56 | { 57 | timer->stop(); 58 | 59 | listupdate2freshselected.clear(); 60 | ui->pushButton_2->setEnabled(false); 61 | ui->pushButton_3->setEnabled(false); 62 | QRegularExpression reg; 63 | QStringList list; 64 | QTableWidgetItem *item; 65 | 66 | monitot *m = (monitot*)(this->parentWidget()); 67 | int memused = m->memusing(); 68 | QString color=BG_color; 69 | if(memused>=80)//内存大时的颜色!默认红色 70 | { 71 | color = color.arg(HIGH).arg(HIGH); 72 | } 73 | else if(memused>=65&&memused<80)//内存占用较多时的颜色!默认橙色 74 | { 75 | color = color.arg(MID).arg(MID); 76 | } 77 | else color = color.arg(LOW).arg(LOW); 78 | this->setStyleSheet(color); 79 | //======================== 80 | process->start("/bin/bash"); 81 | ui->tableWidget->clear(); 82 | if(process->waitForStarted(3000)) 83 | { 84 | process->write(cmd.toLatin1()); 85 | process->closeWriteChannel(); 86 | process->waitForFinished(3000); 87 | QString result = process->readAllStandardOutput(); 88 | reg.setPattern(" +"); 89 | result = result.replace(reg," "); 90 | //qDebug()<tableWidget->setRowCount(list.length()); 96 | for(int i=0;itableWidget->columnCount();j++) 106 | { 107 | 108 | item = new QTableWidgetItem; 109 | if(i%2!=0)item->setBackgroundColor(QColor("#f5f5f5")); 110 | else item->setBackgroundColor(QColor("#ffffff")); 111 | if(j==0) 112 | { 113 | item->setWhatsThis(pid); 114 | line = one.at(4); 115 | if((QString(one.at(0))=="root")) { 116 | root = true; 117 | 118 | line ="[Root] "+line; 119 | } 120 | item->setText(line); 121 | line = one.mid(5).join(" "); 122 | item->setToolTip(line); 123 | 124 | } 125 | else if(j==1) 126 | { 127 | item->setTextAlignment(Qt::AlignHCenter ); 128 | item->setText(one.at(2)); 129 | } 130 | else if(j==2) 131 | { 132 | line = one.at(3); 133 | item->setTextAlignment(Qt::AlignHCenter ); 134 | item->setText(line); 135 | } 136 | else if(j==3) 137 | { 138 | if(!root) 139 | { 140 | item->setCheckState(Qt::Unchecked); 141 | if(pidselected(pid)) { 142 | //item->setSelected(true); 143 | item->setCheckState(Qt::Checked); 144 | } 145 | } 146 | } 147 | ui->tableWidget->setItem(i,j,item); 148 | if(pid==pressed) ui->tableWidget->selectRow(i); 149 | } 150 | } 151 | //listupdate2freshselected 是刷新后的选择,selected应清空再赋值 152 | //主要是防止cpu和内存切换后,已选择的进程不在列表中了,误删看不见但在selected的进程 153 | selected.clear(); 154 | selected = listupdate2freshselected; 155 | listupdate2freshselected.clear(); 156 | 157 | } 158 | timer->start(); 159 | ui->pushButton_2->setEnabled(true); 160 | ui->pushButton_3->setEnabled(true); 161 | } 162 | 163 | 164 | 165 | void monitorwindow::on_pushButton_3_clicked() 166 | { 167 | listupdate2freshselected.clear(); 168 | if(cmd == MEM_SORT) return; 169 | cmd = MEM_SORT; 170 | getinfo(); 171 | } 172 | 173 | void monitorwindow::on_pushButton_2_clicked() 174 | { 175 | listupdate2freshselected.clear(); 176 | if(cmd == CPU_SORT) return; 177 | cmd = CPU_SORT; 178 | getinfo(); 179 | } 180 | 181 | void monitorwindow::on_tableWidget_itemSelectionChanged() 182 | { 183 | pressed = ui->tableWidget->item(ui->tableWidget->currentRow(),0)->whatsThis(); 184 | // qDebug()<<"clicked pid"<isActive()) return; 186 | // selected.clear(); 187 | // listupdate2freshselected.clear(); 188 | // qDebug()<<"selectionchaged"; 189 | // QList list = ui->tableWidget->selectedItems(); 190 | // for(int i=0;icolumn()==0) 193 | // { 194 | // selected.append(list.at(i)->whatsThis()); 195 | // } 196 | // } 197 | // qDebug()<stop(); 217 | this->hide(); 218 | } 219 | 220 | void monitorwindow::on_pushButton_clicked() 221 | { 222 | if(selected.isEmpty()) return; 223 | ui->pushButton->setEnabled(false); 224 | QProcess kill; 225 | QString cmd; 226 | cmd = "kill "+selected.join(" "); 227 | kill.start(cmd); 228 | if(kill.waitForStarted(3000)) 229 | if(kill.waitForFinished(3000)) 230 | { 231 | qDebug()<pushButton->setEnabled(true); 236 | } 237 | 238 | 239 | 240 | void monitorwindow::on_tableWidget_itemClicked(QTableWidgetItem *item) 241 | { 242 | if(item->column()!=3) return; 243 | //qDebug()<checkState(); 244 | if(item->checkState()==Qt::Checked) 245 | { 246 | selected.append(ui->tableWidget->item(item->row(),0)->whatsThis()); 247 | } 248 | else if(item->checkState()==Qt::Unchecked) selected.removeOne(ui->tableWidget->item(item->row(),0)->whatsThis()); 249 | //qDebug()<button()==Qt::LeftButton ) 255 | { 256 | oldpos=event->globalPos()-this->pos(); 257 | setCursor(Qt::ClosedHandCursor); 258 | } 259 | } 260 | 261 | void monitorwindow::mouseMoveEvent(QMouseEvent * event){ 262 | move(event->globalPos()-oldpos);//貌似linux要这样 263 | event->accept(); 264 | } 265 | 266 | void monitorwindow::mouseReleaseEvent(QMouseEvent * event){ 267 | setCursor(Qt::ArrowCursor); 268 | event->accept(); 269 | } 270 | 271 | bool monitorwindow::cpuchange(QString& value){ 272 | ui->cpuvalue->setText(value); 273 | } 274 | 275 | void monitorwindow::on_cpuvalue_clicked() 276 | { 277 | emit opencpu(); 278 | } 279 | -------------------------------------------------------------------------------- /monitorwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MONITORWINDOW_H 2 | #define MONITORWINDOW_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #define CPU_SORT "ps ax -o \"%u %p %C\" -o pmem -o \"%c %a\" --sort=-%cpu|head -16"//包含头 14 | #define MEM_SORT "ps ax -o \"%u %p %C\" -o pmem -o \"%c %a\" --sort=-pmem|head -16"//包含头 15 | #define BG_color "#monitorwindow{ background-color:%1; }\ 16 | #pushButton{ color:%2; }" 17 | #define LOW "rgb(50, 162, 106)" 18 | #define MID "rgb(233, 119, 57)" 19 | #define HIGH "rgb(179, 10, 13)" 20 | 21 | class monitot;//在cpp文件里包含h文件 22 | 23 | namespace Ui { 24 | class monitorwindow; 25 | } 26 | 27 | class monitorwindow : public QWidget 28 | { 29 | Q_OBJECT 30 | 31 | public: 32 | explicit monitorwindow(QWidget *parent = 0); 33 | void stop_hide(); 34 | ~monitorwindow(); 35 | 36 | signals: 37 | void opencpu(); 38 | 39 | public slots: 40 | bool getinfo(); 41 | bool cpuchange(QString&); 42 | 43 | private slots: 44 | void on_pushButton_2_clicked(); 45 | 46 | void on_pushButton_3_clicked(); 47 | 48 | void on_tableWidget_itemSelectionChanged(); 49 | 50 | 51 | void on_pushButton_4_clicked(); 52 | 53 | void on_pushButton_clicked(); 54 | 55 | void on_tableWidget_itemClicked(QTableWidgetItem *item); 56 | 57 | void on_cpuvalue_clicked(); 58 | 59 | private: 60 | Ui::monitorwindow *ui; 61 | void mousePressEvent(QMouseEvent* event); 62 | void mouseMoveEvent(QMouseEvent * event); 63 | void mouseReleaseEvent(QMouseEvent * event); 64 | QPoint oldpos; 65 | void makelist(); 66 | bool pidselected(const QString&); 67 | QTimer *timer; 68 | QProcess *process; 69 | QStringList selectedpid; 70 | QString cmd; 71 | QString pressed; 72 | QStringList selected; 73 | QStringList listupdate2freshselected; 74 | }; 75 | 76 | #endif // MONITORWINDOW_H 77 | -------------------------------------------------------------------------------- /monitorwindow.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | monitorwindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 216 10 | 315 11 | 12 | 13 | 14 | 15 | 50 16 | false 17 | 18 | 19 | 20 | 21 | 22 | 23 | #monitorwindow 24 | { 25 | background-color:rgb(50, 162, 106); 26 | } 27 | 28 | #pushButton 29 | { 30 | color:rgb(42, 140, 83); 31 | } 32 | #pushButton:hover 33 | { 34 | color:black; 35 | } 36 | 37 | 38 | 39 | 40 | 0 41 | 42 | 43 | 0 44 | 45 | 46 | 0 47 | 48 | 49 | 0 50 | 51 | 52 | 0 53 | 54 | 55 | 56 | 57 | 58 | 0 59 | 60 | 61 | 0 62 | 63 | 64 | 0 65 | 66 | 67 | 0 68 | 69 | 70 | 0 71 | 72 | 73 | 74 | 75 | 0 76 | 77 | 78 | 10 79 | 80 | 81 | 0 82 | 83 | 84 | 0 85 | 86 | 87 | 4 88 | 89 | 90 | 91 | 92 | 0 93 | 94 | 95 | 10 96 | 97 | 98 | 99 | 100 | 101 | 0 102 | 0 103 | 104 | 105 | 106 | 107 | 16777215 108 | 30 109 | 110 | 111 | 112 | 113 | 12 114 | 50 115 | false 116 | 117 | 118 | 119 | Qt::NoFocus 120 | 121 | 122 | 杀 死 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 0 131 | 0 132 | 133 | 134 | 135 | 136 | 55 137 | 0 138 | 139 | 140 | 141 | 142 | 16777215 143 | 30 144 | 145 | 146 | 147 | 148 | 12 149 | 150 | 151 | 152 | #cpulabel{ 153 | color: rgb(255, 255, 255); 154 | } 155 | 156 | 157 | CPU: 158 | 159 | 160 | Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 0 169 | 0 170 | 171 | 172 | 173 | 174 | 55 175 | 0 176 | 177 | 178 | 179 | 180 | 16777215 181 | 30 182 | 183 | 184 | 185 | 186 | 12 187 | false 188 | 189 | 190 | 191 | Qt::NoFocus 192 | 193 | 194 | #cpuvalue{ 195 | color: rgb(255, 255, 255); 196 | } 197 | #cpuvalue:hover{ 198 | color:rgb(255, 238, 0); 199 | background-color: rgba(0, 0 ,0, 140); 200 | } 201 | 202 | 203 | 0% 204 | 205 | 206 | true 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 0 216 | 217 | 218 | 219 | 220 | 221 | 0 222 | 0 223 | 224 | 225 | 226 | 227 | 20 228 | 20 229 | 230 | 231 | 232 | 233 | 14 234 | 235 | 236 | 237 | Qt::NoFocus 238 | 239 | 240 | #pushButton_4 241 | { 242 | color:#dddddd; 243 | } 244 | 245 | #pushButton_4:hover 246 | { 247 | color:white; 248 | } 249 | 250 | 251 | × 252 | 253 | 254 | true 255 | 256 | 257 | 258 | 259 | 260 | 261 | Qt::Vertical 262 | 263 | 264 | QSizePolicy::Ignored 265 | 266 | 267 | 268 | 20 269 | 10 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 0 282 | 283 | 284 | 4 285 | 286 | 287 | 0 288 | 289 | 290 | 0 291 | 292 | 293 | 294 | 295 | 296 | 116 297 | 20 298 | 299 | 300 | 301 | 302 | 116 303 | 20 304 | 305 | 306 | 307 | 308 | 10 309 | 50 310 | false 311 | false 312 | PreferAntialias 313 | 314 | 315 | 316 | QLabel{ 317 | color:white; 318 | } 319 | 320 | 321 | 进程-Top15 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 40 330 | 20 331 | 332 | 333 | 334 | 335 | 10 336 | 337 | 338 | 339 | Qt::NoFocus 340 | 341 | 342 | #pushButton_2 343 | { 344 | color:#eeeeee; 345 | } 346 | #pushButton_2:hover 347 | { 348 | color:white; 349 | } 350 | 351 | 352 | CPU% 353 | 354 | 355 | false 356 | 357 | 358 | true 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 40 367 | 20 368 | 369 | 370 | 371 | 372 | 10 373 | 374 | 375 | 376 | Qt::NoFocus 377 | 378 | 379 | #pushButton_3 380 | { 381 | color:#eeeeee; 382 | } 383 | #pushButton_3:hover 384 | { 385 | color:white; 386 | } 387 | 388 | 389 | 内存% 390 | 391 | 392 | false 393 | 394 | 395 | true 396 | 397 | 398 | 399 | 400 | 401 | 402 | Qt::Horizontal 403 | 404 | 405 | 406 | 30 407 | 20 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | QFrame::NoFrame 418 | 419 | 420 | Qt::ScrollBarAlwaysOff 421 | 422 | 423 | Qt::ScrollBarAlwaysOff 424 | 425 | 426 | QAbstractScrollArea::AdjustIgnored 427 | 428 | 429 | false 430 | 431 | 432 | 0 433 | 434 | 435 | QAbstractItemView::SingleSelection 436 | 437 | 438 | false 439 | 440 | 441 | Qt::NoPen 442 | 443 | 444 | false 445 | 446 | 447 | false 448 | 449 | 450 | false 451 | 452 | 453 | 0 454 | 455 | 456 | 1 457 | 458 | 459 | false 460 | 461 | 462 | 50 463 | 464 | 465 | false 466 | 467 | 468 | 25 469 | 470 | 471 | 20 472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 | 482 | 483 | 484 | -------------------------------------------------------------------------------- /monitot.cpp: -------------------------------------------------------------------------------- 1 | #include "monitot.h" 2 | #include "ui_monitot.h" 3 | #include "monitorwindow.h" 4 | #define BG_W 90 5 | // 2padding + 1反锯齿x2 + 86内容 6 | #define BG_H 36 7 | // 2padding + 1反锯齿x2 + 32内容 8 | #define BG_PADD 2 9 | //padding 10 | #define MEM_S 32 11 | //内存球绘图大小 = 1反锯齿x2 + 30内容 12 | 13 | monitot::monitot(QWidget *parent) : 14 | QWidget(parent), 15 | ui(new Ui::monitot) 16 | { 17 | ui->setupUi(this); 18 | setWindowFlags(Qt::FramelessWindowHint 19 | |Qt::WindowStaysOnTopHint 20 | |Qt::Tool 21 | );//去边框//最ding层显示//不在任务栏显示 22 | setAutoFillBackground(false); 23 | this->setAttribute(Qt::WA_TranslucentBackground, true); 24 | 25 | menu =new QMenu(this); 26 | QAction *tuichu = new QAction("退出",menu); 27 | QAction *moniter = new QAction("系统监视器",menu); 28 | QAction *cpu = new QAction("CUP图开/关",menu); 29 | connect(tuichu, SIGNAL(triggered(bool)), qApp, SLOT(quit()));//若触发了退出就退出程序 30 | connect(moniter,SIGNAL(triggered(bool)),this,SLOT(openmoniter())); 31 | connect(cpu,SIGNAL(triggered(bool)),this,SLOT(opencpu())); 32 | menu->addAction(cpu); //添加退出 33 | menu->addAction(moniter);//添加系统监视器 34 | menu->addAction(tuichu); //添加退出 35 | 36 | memused =0; 37 | upspeed = "↑0K"; 38 | downspeed = "↓0K"; 39 | 40 | 41 | mousepressed=false; 42 | oldpos.setX(0); 43 | oldpos.setY(0); 44 | oup=0; 45 | odown=0; 46 | side = -1; 47 | showall = true; 48 | animation = new QPropertyAnimation(this, "geometry"); 49 | connect(animation,SIGNAL(finished()),SLOT(animationfinished())); 50 | justpress = true; 51 | pro = new QProcess(this); 52 | killer = new monitorwindow(this); 53 | connect(killer , SIGNAL(opencpu()),this,SLOT(opencpu())); 54 | killer->hide(); 55 | cpumonitor = new manager(); 56 | connect(cpumonitor, SIGNAL(cpuchange(QString&)),killer,SLOT(cpuchange(QString&))); 57 | timer = new QTimer(this); 58 | timer->setInterval(1000); 59 | timer->setSingleShot(false); 60 | connect(timer,SIGNAL(timeout()),this,SLOT(timeout())); 61 | timer->start(); 62 | readset(); 63 | poscheck(); 64 | } 65 | 66 | monitot::~monitot() 67 | { 68 | saveset(); 69 | delete cpumonitor; 70 | delete ui; 71 | } 72 | 73 | void monitot::paintEvent(QPaintEvent *event) 74 | { 75 | QFont font; 76 | QPainter paint(this); 77 | paint.setRenderHint(QPainter::Antialiasing,true); 78 | //===============先画底============ 79 | QLinearGradient linearGradient(0,0,0,BG_H); 80 | //创建了一个QLinearGradient对象实例,参数为起点和终点坐标,可作为颜色渐变的方向 81 | //painter.setPen(Qt::NoPen); 82 | linearGradient.setColorAt(0.0,Qt::white); 83 | linearGradient.setColorAt(1.0,QColor(224, 224, 224)); 84 | paint.setBrush(QBrush(linearGradient)); 85 | paint.setPen(QPen(QColor(210, 210, 210), 1)); 86 | 87 | if(side==0&&(!showall)) paint.drawRoundedRect(0-BG_H/2+1 , 1 , BG_H - 2 , BG_H - 2 , BG_H/2,BG_H/2);//背景圆球 88 | else if(side == 1&&(!showall)) { 89 | //paint.translate(0,0-BG_H/2-1); 90 | paint.drawRoundedRect(1,0-BG_H/2+1,BG_H - 2 , BG_H - 2 , BG_H/2,BG_H/2);//背景圆球 91 | } 92 | else 93 | { 94 | // paint.setBrush(QBrush(Qt::white));//↓由于使用了反锯齿,四边都要多1像素,需要右下各移动1像素再绘图,确保边缘平滑显示。 95 | paint.drawRoundedRect(1,1,BG_W - 2 , BG_H - 2 , BG_H/2,BG_H/2); 96 | } 97 | if(showall) 98 | { 99 | //=========================再画网速数值================== 100 | font.setPixelSize(12); 101 | paint.setFont(font); 102 | paint.setPen(QPen(Qt::red, 1)); 103 | paint.drawText(QRectF(MEM_S ,BG_H/2-14,58,14),Qt::AlignLeft|Qt::AlignVCenter,upspeed); 104 | 105 | paint.setPen(QPen(QColor(60, 150, 21), 1)); 106 | paint.drawText(QRectF(MEM_S,BG_H/2,58,14),Qt::AlignLeft|Qt::AlignVCenter,downspeed); 107 | } 108 | 109 | 110 | //===================再画内存底========================= 111 | QString picture; 112 | if(memused>=80)//内存大时的颜色!默认红色 113 | { 114 | picture = RED; 115 | } 116 | else if(memused>=65&&memused<80)//内存占用较多时的颜色!默认橙色 117 | { 118 | picture = YELLOW; 119 | } 120 | else picture = GREEN; 121 | 122 | int mem = memused * 30 / 100; 123 | QPixmap pix = QPixmap(picture).copy(0,mem,30,30); 124 | paint.save();//保持(0,0)原点 125 | paint.translate(0, BG_PADD+1);//改变纵坐标原点,使填图案时不会发生错误 //由于反锯齿,还要+1 126 | paint.setBrush(QBrush(Qt::green,pix)); 127 | paint.setPen(QPen(QColor(210, 210, 210), 1)); 128 | if(side==0&&(!showall)) { 129 | paint.drawRoundedRect(0-BG_H/2+BG_PADD+1 , 0 ,30,30,15,15);//由于移坐标时y已经+1,此处y就不用+1了 130 | } 131 | else if(side == 1&&(!showall)) { 132 | paint.translate(0, 0-BG_H/2);//改变纵坐标原点,使填图案时不会发生错误 133 | paint.drawRoundedRect(BG_PADD+1 ,0 ,30,30,15,15);//由于移坐标时y已经+1,此处y就不用+1了 134 | } 135 | else paint.drawRoundedRect(BG_PADD+1 , 0 ,30,30,15,15);//由于移坐标时y已经+1,此处y就不用+1了 136 | paint.restore();//返回saved的0,0 137 | //==================再写内存数值============================== 138 | if(showall) 139 | { 140 | paint.setPen(QPen(QColor(BG_H/20, BG_H/20, BG_H/20), 1)); 141 | font.setPixelSize(16); 142 | paint.setFont(font); 143 | paint.drawText(QRectF(BG_PADD+1,1,30,BG_H-4),Qt::AlignCenter,QString().setNum( memused)); 144 | paint.setPen(QPen(QColor(255, 255, 255), 1)); 145 | paint.drawText(QRectF(BG_PADD+0,1,30,BG_H-4),Qt::AlignCenter,QString().setNum( memused)); 146 | } 147 | else { 148 | paint.setPen(QPen(QColor(150, 150, 150), 1)); 149 | font.setPixelSize(12); 150 | paint.setFont(font); 151 | if(side ==0) 152 | { 153 | paint.drawText(QRectF(0 , 0,MEM_S/2,BG_H),Qt::AlignCenter,QString().setNum( memused)); 154 | paint.setPen(QPen(QColor(255, 255, 255), 1)); 155 | paint.drawText(QRectF(-1 , 0,MEM_S/2,BG_H),Qt::AlignCenter,QString().setNum( memused)); 156 | } 157 | else if(side ==1) 158 | { 159 | paint.drawText(QRectF(0,0, BG_H , MEM_S/2),Qt::AlignCenter,QString().setNum( memused)); 160 | paint.setPen(QPen(QColor(255, 255, 255), 1)); 161 | paint.drawText(QRectF(0, -1 ,BG_H , MEM_S/2),Qt::AlignCenter,QString().setNum( memused)); 162 | } 163 | else 164 | { 165 | paint.drawText(QRectF(BG_PADD+2,0,MEM_S/2,BG_H),Qt::AlignCenter,QString().setNum( memused)); 166 | paint.setPen(QPen(QColor(255, 255, 255), 1)); 167 | paint.drawText(QRectF(BG_PADD+1,0,MEM_S/2,BG_H),Qt::AlignCenter,QString().setNum( memused)); 168 | } 169 | } 170 | //QWidget::paintEvent(event); 171 | event->accept(); 172 | } 173 | 174 | 175 | void monitot::timeout() 176 | { 177 | if(killer->isVisible()&&(!killer->isActiveWindow())) 178 | { 179 | killer->stop_hide(); 180 | } 181 | if(showall) { 182 | getnetspeed(); 183 | } 184 | else { 185 | oup = 0; 186 | odown = 0; 187 | } 188 | getmemused(); 189 | update(); 190 | 191 | } 192 | 193 | void monitot::getnetspeed() 194 | { 195 | QRegularExpressionMatchIterator matchs; 196 | QString result,tmp; 197 | qint64 up,down,t; 198 | upspeed = ""; 199 | upspeed = ""; 200 | up=0; 201 | down=0; 202 | pro->start("ip -s link"); 203 | if(pro->waitForStarted(2000)) 204 | { 205 | if(pro->waitForFinished(1000)) 206 | { 207 | result=pro->readAllStandardOutput(); 208 | // qDebug()<999) 227 | { 228 | t=t*100/1024; 229 | float f=t*1.0/100; 230 | upspeed="↑"+QString().setNum(f)+"M"; 231 | 232 | } 233 | else if(t>0) upspeed+="↑"+QString().setNum(t)+"K"; 234 | else upspeed="↑"+QString().setNum(up-oup)+"B"; 235 | 236 | if(oup == 0) upspeed ="↑0B";//没有基数,网速不正确,设为0B。 237 | oup=up; 238 | 239 | reg.setPattern("mcast[\\s\\S]+?\\d+"); 240 | matchs=reg.globalMatch(result); 241 | while(matchs.hasNext()) 242 | { 243 | tmp=matchs.next().captured(0); 244 | tmp.remove(QRegularExpression("[\\s\\S]+ ")); 245 | t=tmp.toLongLong(); 246 | down+=t; 247 | // qDebug()<<"got down"<999) 253 | { 254 | t=t*100/1024; 255 | float f=t*1.0/100; 256 | downspeed="↓"+QString().setNum(f)+"M"; 257 | 258 | } 259 | else if(t>0) downspeed="↓"+QString().setNum(t)+"K"; 260 | else downspeed="↓"+QString().setNum(down-odown)+"B"; 261 | 262 | // if(odown!=0) ui->down->setText(text); 263 | if(odown == 0) downspeed ="↓0B";//没有基数,网速不正确,设为0B。 264 | 265 | odown=down; 266 | } 267 | } 268 | } 269 | } 270 | 271 | void monitot::getmemused() 272 | { 273 | 274 | QString result,tmp; 275 | pro->start("free -m"); 276 | if(pro->waitForStarted(2000)) 277 | { 278 | if(pro->waitForFinished(1000)) 279 | { 280 | result=pro->readAllStandardOutput(); 281 | // qDebug()<mem->value();//先获取之前的数 287 | total=0; 288 | used=0; 289 | reg.setPattern("\\d+.+"); 290 | //reg.setPattern("Mem:.+"); 291 | tmp=reg.match(result).captured(0); 292 | // qDebug()<=5) memused+=1;//四舍五入 303 | } 304 | } 305 | } 306 | } 307 | 308 | void monitot::mousePressEvent(QMouseEvent* event) 309 | { 310 | if(event->button()==Qt::LeftButton ) 311 | { 312 | oldpos=event->globalPos()-this->pos(); 313 | setCursor(Qt::ClosedHandCursor); 314 | justpress = true; 315 | event->accept(); 316 | } 317 | else QWidget::mousePressEvent(event); 318 | } 319 | 320 | void monitot::mouseMoveEvent(QMouseEvent * event){ 321 | killer->stop_hide(); 322 | move(event->globalPos()-oldpos);//貌似linux要这样 323 | justpress = false; 324 | event->accept(); 325 | } 326 | 327 | void monitot::mouseReleaseEvent(QMouseEvent * event){ 328 | if(event->button()==Qt::LeftButton ) 329 | { 330 | setCursor(Qt::ArrowCursor); 331 | side = -1;//默认为不靠边 332 | //先判断y 333 | if(this->y()<=0) { 334 | side = 1; 335 | move(x(),0); 336 | } 337 | //后判断x,这样就左右优先,上其次 338 | if(this->x()<=0) { 339 | side = 0; 340 | move(0,y()); 341 | } 342 | else if(this->x()>=QApplication::desktop()->width()-BG_W) { 343 | move(QApplication::desktop()->width()-BG_W,y()); 344 | side = 2; 345 | } 346 | 347 | if(killer->isVisible()) { 348 | killer->stop_hide(); 349 | return; 350 | } 351 | if(justpress) 352 | { 353 | int x,y; 354 | x=this->x(); 355 | y=this->y()+BG_H+4; 356 | if(x > QApplication::desktop()->width()-killer->width()) x = QApplication::desktop()->width()-killer->width(); 357 | else if(x < 0) x=0; 358 | if(QApplication::desktop()->height()-this->y() < killer->height()){ 359 | y = this->y()-killer->height()-4; 360 | qDebug()<<"QApplication::desktop()->height()-this->y() < killer->height()"<move(x,y); 364 | killer->getinfo(); 365 | killer->show(); 366 | killer->activateWindow(); 367 | } 368 | // qDebug()<accept(); 372 | 373 | } 374 | else QWidget::mouseReleaseEvent(event); 375 | } 376 | 377 | void monitot::enterEvent(QEvent *event){ 378 | if(animation->state()==QAbstractAnimation::Running) { 379 | //qDebug()<<"animation running"; 380 | return; 381 | } 382 | showall =true;//立即开始画网速部分; 383 | int endx,endy,startw,starth;// 384 | startw = BG_H/2; 385 | starth = BG_H; 386 | switch(side) 387 | { 388 | case 0: 389 | endx = this->x(); 390 | endy = this->y(); 391 | break; 392 | case 1: 393 | endx = this->x(); 394 | endy = this->y(); 395 | startw = BG_H; 396 | starth = BG_H/2; 397 | break; 398 | case 2: 399 | endx = this->x()-(BG_W-BG_H/2); 400 | endy = this->y(); 401 | break; 402 | default: 403 | return; 404 | } 405 | //qDebug()<stop(); 408 | animation->setDuration(150); 409 | animation->setStartValue(QRect(this->x(), this->y(), startw, starth)); 410 | 411 | animation->setEndValue(QRect(endx, endy, BG_W, BG_H)); 412 | //qDebug()<<"enter"<geometry(); 413 | 414 | animation->start(); 415 | event->accept(); 416 | } 417 | void monitot::leaveEvent(QEvent *event){ 418 | int endx,endy,endw,endh; 419 | endw = BG_H/2; 420 | endh = BG_H; 421 | showall =true; 422 | switch(side) 423 | { 424 | case 0: 425 | endx = this->x(); 426 | endy = this->y(); 427 | break; 428 | case 1: 429 | endx = this->x(); 430 | endy = this->y(); 431 | endw = BG_H; 432 | endh = BG_H/2; 433 | break; 434 | case 2: 435 | endx = this->x()+(BG_W-BG_H/2); 436 | endy = this->y(); 437 | break; 438 | default: 439 | return; 440 | } 441 | animation->stop(); 442 | animation->setDuration(150); 443 | animation->setStartValue(QRect(this->x(), this->y(), this->width(), this->height())); 444 | animation->setEndValue(QRect(endx,endy, endw, endh)); 445 | //qDebug()<geometry(); 447 | animation->start(); 448 | event->accept(); 449 | } 450 | 451 | void monitot::contextMenuEvent(QContextMenuEvent * event) //右键菜单项编辑 452 | { 453 | if(menu) 454 | { 455 | QCursor cur=this->cursor(); 456 | menu->exec(cur.pos()); //关联到光标 457 | 458 | } 459 | event->accept(); 460 | } 461 | 462 | void monitot::openmoniter() 463 | { 464 | QProcess process; 465 | process.startDetached("gnome-system-monitor"); 466 | } 467 | 468 | void monitot::opencpu() 469 | { 470 | cpumonitor->setVisible(!cpumonitor->isVisible()); 471 | } 472 | 473 | void monitot::poscheck() 474 | { 475 | int x=this->x(); 476 | int y=this->y(); 477 | // qDebug()<pos().x()<0) x=0; 480 | else if(QApplication::desktop()->width()-xwidth()){ 481 | x=QApplication::desktop()->width()-this->width(); 482 | } 483 | 484 | if(this->pos().y()<0) y=0; 485 | else if(QApplication::desktop()->height()-yheight()) 486 | { 487 | y=QApplication::desktop()->height()-this->height(); 488 | } 489 | // qDebug()<width()geometry()); 503 | set.setValue("side", side); 504 | set.setValue("showall",showall); 505 | } 506 | void monitot::readset() 507 | { 508 | QSettings set("Noahsai","Monitor-desktop",this); 509 | QRect r = set.value("geometry",QVariant(QRect(QApplication::desktop()->width()-100,QApplication::desktop()->height()-100 , BG_W , BG_H))).toRect(); 510 | int rx = r.x(); 511 | int ry = r.y(); 512 | setGeometry(rx , ry , BG_W , BG_H ); 513 | side = set.value("side", -1).toInt(); 514 | showall = set.value("showall",true).toBool(); 515 | } 516 | 517 | int monitot::memusing(){ 518 | return memused; 519 | } 520 | -------------------------------------------------------------------------------- /monitot.h: -------------------------------------------------------------------------------- 1 | #ifndef MONITOT_H 2 | #define MONITOT_H 3 | 4 | #include 5 | #include 6 | //#include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include"printcpu/manager.h" 17 | 18 | 19 | 20 | #define RED ":/red.png" 21 | #define YELLOW ":/yellow.png" 22 | #define GREEN ":/green.png" 23 | 24 | class monitorwindow;//在cpp文件里包含h文件 25 | 26 | namespace Ui { 27 | class monitot; 28 | } 29 | 30 | class monitot : public QWidget 31 | { 32 | Q_OBJECT 33 | 34 | public: 35 | explicit monitot(QWidget *parent = 0); 36 | int memusing(); 37 | ~monitot(); 38 | 39 | private: 40 | Ui::monitot *ui; 41 | void paintEvent(QPaintEvent *); 42 | int memused; 43 | QString upspeed; 44 | QString downspeed; 45 | 46 | 47 | private slots: 48 | void animationfinished(); 49 | void timeout(); 50 | void openmoniter(); 51 | void opencpu(); 52 | private: 53 | void mousePressEvent(QMouseEvent* event); 54 | void mouseMoveEvent(QMouseEvent * event); 55 | void mouseReleaseEvent(QMouseEvent * event); 56 | void contextMenuEvent(QContextMenuEvent *); 57 | 58 | void enterEvent(QEvent *); 59 | void leaveEvent(QEvent *); 60 | int side;//左0,上1,右2,非贴边-1; 61 | bool showall; 62 | 63 | void saveset(); 64 | void readset(); 65 | 66 | 67 | void getnetspeed();//可独立使用,加返回值即可 68 | void getmemused();//同上 69 | void poscheck(); 70 | 71 | QProcess *pro; 72 | QTimer *timer; 73 | QRegularExpression reg; 74 | qint64 oup,odown; 75 | QPoint oldpos; 76 | bool mousepressed; 77 | // QSystemTrayIcon *trayIcon;//托盘图标 78 | QMenu *menu; 79 | // QAction *tuichu; 80 | // QAction *moniter; 81 | 82 | monitorwindow *killer; 83 | bool justpress; 84 | QPropertyAnimation *animation; 85 | manager *cpumonitor; 86 | }; 87 | 88 | #endif // MONITOT_H 89 | -------------------------------------------------------------------------------- /monitot.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | monitot 4 | 5 | 6 | 7 | 0 8 | 0 9 | 262 10 | 159 11 | 12 | 13 | 14 | monitot 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /painter.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2017-02-04T19:37:59 4 | # 5 | #------------------------------------------------- 6 | 7 | 8 | 9 | QT += core gui 10 | QT += network 11 | 12 | 13 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 14 | 15 | TARGET = painter 16 | TEMPLATE = app 17 | 18 | 19 | SOURCES += main.cpp\ 20 | monitot.cpp \ 21 | monitorwindow.cpp \ 22 | printcpu/manager.cpp \ 23 | printcpu/widget.cpp 24 | 25 | HEADERS += monitot.h \ 26 | monitorwindow.h \ 27 | printcpu/manager.h \ 28 | printcpu/widget.h 29 | 30 | FORMS += monitot.ui \ 31 | monitorwindow.ui \ 32 | printcpu/manager.ui \ 33 | printcpu/widget.ui 34 | 35 | RESOURCES += \ 36 | res.qrc 37 | 38 | SUBDIRS += \ 39 | printcpu/printcpu.pro 40 | 41 | -------------------------------------------------------------------------------- /painter.pro.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | EnvironmentId 7 | {984e1975-25d6-4251-9c56-aba9c75bc6f8} 8 | 9 | 10 | ProjectExplorer.Project.ActiveTarget 11 | 0 12 | 13 | 14 | ProjectExplorer.Project.EditorSettings 15 | 16 | true 17 | false 18 | true 19 | 20 | Cpp 21 | 22 | CppGlobal 23 | 24 | 25 | 26 | QmlJS 27 | 28 | QmlJSGlobal 29 | 30 | 31 | 2 32 | UTF-8 33 | false 34 | 4 35 | false 36 | 80 37 | true 38 | true 39 | 1 40 | true 41 | false 42 | 0 43 | true 44 | true 45 | 0 46 | 8 47 | true 48 | 1 49 | true 50 | true 51 | true 52 | false 53 | 54 | 55 | 56 | ProjectExplorer.Project.PluginSettings 57 | 58 | 59 | 60 | ProjectExplorer.Project.Target.0 61 | 62 | 桌面 63 | 桌面 64 | {d398a100-6dba-4a16-991d-884d0f99ea69} 65 | 1 66 | 0 67 | 0 68 | 69 | /home/sheng/QT_works/build-painter-unknown-Debug 70 | 71 | 72 | true 73 | qmake 74 | 75 | QtProjectManager.QMakeBuildStep 76 | true 77 | 78 | false 79 | false 80 | false 81 | 82 | 83 | true 84 | Make 85 | 86 | Qt4ProjectManager.MakeStep 87 | 88 | -w 89 | -r 90 | 91 | false 92 | 93 | 94 | 95 | 2 96 | 构建 97 | 98 | ProjectExplorer.BuildSteps.Build 99 | 100 | 101 | 102 | true 103 | Make 104 | 105 | Qt4ProjectManager.MakeStep 106 | 107 | -w 108 | -r 109 | 110 | true 111 | clean 112 | 113 | 114 | 1 115 | 清理 116 | 117 | ProjectExplorer.BuildSteps.Clean 118 | 119 | 2 120 | false 121 | 122 | Debug 123 | 124 | Qt4ProjectManager.Qt4BuildConfiguration 125 | 2 126 | true 127 | 128 | 129 | /home/sheng/QT_works/build-painter-unknown-Release 130 | 131 | 132 | true 133 | qmake 134 | 135 | QtProjectManager.QMakeBuildStep 136 | false 137 | 138 | false 139 | false 140 | false 141 | 142 | 143 | true 144 | Make 145 | 146 | Qt4ProjectManager.MakeStep 147 | 148 | -w 149 | -r 150 | 151 | false 152 | 153 | 154 | 155 | 2 156 | 构建 157 | 158 | ProjectExplorer.BuildSteps.Build 159 | 160 | 161 | 162 | true 163 | Make 164 | 165 | Qt4ProjectManager.MakeStep 166 | 167 | -w 168 | -r 169 | 170 | true 171 | clean 172 | 173 | 174 | 1 175 | 清理 176 | 177 | ProjectExplorer.BuildSteps.Clean 178 | 179 | 2 180 | false 181 | 182 | Release 183 | 184 | Qt4ProjectManager.Qt4BuildConfiguration 185 | 0 186 | true 187 | 188 | 189 | /home/sheng/QT_works/build-painter-unknown-Profile 190 | 191 | 192 | true 193 | qmake 194 | 195 | QtProjectManager.QMakeBuildStep 196 | true 197 | 198 | false 199 | true 200 | false 201 | 202 | 203 | true 204 | Make 205 | 206 | Qt4ProjectManager.MakeStep 207 | 208 | -w 209 | -r 210 | 211 | false 212 | 213 | 214 | 215 | 2 216 | 构建 217 | 218 | ProjectExplorer.BuildSteps.Build 219 | 220 | 221 | 222 | true 223 | Make 224 | 225 | Qt4ProjectManager.MakeStep 226 | 227 | -w 228 | -r 229 | 230 | true 231 | clean 232 | 233 | 234 | 1 235 | 清理 236 | 237 | ProjectExplorer.BuildSteps.Clean 238 | 239 | 2 240 | false 241 | 242 | Profile 243 | 244 | Qt4ProjectManager.Qt4BuildConfiguration 245 | 0 246 | true 247 | 248 | 3 249 | 250 | 251 | 0 252 | 部署 253 | 254 | ProjectExplorer.BuildSteps.Deploy 255 | 256 | 1 257 | 在本地部署 258 | 259 | ProjectExplorer.DefaultDeployConfiguration 260 | 261 | 1 262 | 263 | 264 | false 265 | false 266 | 1000 267 | 268 | true 269 | 270 | false 271 | false 272 | false 273 | false 274 | true 275 | 0.01 276 | 10 277 | true 278 | 1 279 | 25 280 | 281 | 1 282 | true 283 | false 284 | true 285 | valgrind 286 | 287 | 0 288 | 1 289 | 2 290 | 3 291 | 4 292 | 5 293 | 6 294 | 7 295 | 8 296 | 9 297 | 10 298 | 11 299 | 12 300 | 13 301 | 14 302 | 303 | 2 304 | 305 | painter 306 | 307 | Qt4ProjectManager.Qt4RunConfiguration:/home/sheng/QT_works/monitor-desktop/painter.pro 308 | true 309 | 310 | painter.pro 311 | false 312 | 313 | /home/sheng/QT_works/build-painter-unknown-Release 314 | 3768 315 | false 316 | true 317 | false 318 | false 319 | true 320 | 321 | 1 322 | 323 | 324 | 325 | ProjectExplorer.Project.TargetCount 326 | 1 327 | 328 | 329 | ProjectExplorer.Project.Updater.FileVersion 330 | 18 331 | 332 | 333 | Version 334 | 18 335 | 336 | 337 | -------------------------------------------------------------------------------- /painter.pro.user.0512359: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | EnvironmentId 7 | {0512359c-ebf5-4fbd-ab0d-a9a42feddd18} 8 | 9 | 10 | ProjectExplorer.Project.ActiveTarget 11 | 0 12 | 13 | 14 | ProjectExplorer.Project.EditorSettings 15 | 16 | true 17 | false 18 | true 19 | 20 | Cpp 21 | 22 | CppGlobal 23 | 24 | 25 | 26 | QmlJS 27 | 28 | QmlJSGlobal 29 | 30 | 31 | 2 32 | UTF-8 33 | false 34 | 4 35 | false 36 | 80 37 | true 38 | true 39 | 1 40 | true 41 | false 42 | 0 43 | true 44 | true 45 | 0 46 | 8 47 | true 48 | 1 49 | true 50 | true 51 | true 52 | false 53 | 54 | 55 | 56 | ProjectExplorer.Project.PluginSettings 57 | 58 | 59 | 60 | ProjectExplorer.Project.Target.0 61 | 62 | 桌面 63 | 桌面 64 | {129d8fc5-6e2b-44fa-aaa5-433694035958} 65 | 1 66 | 0 67 | 0 68 | 69 | /home/sheng/qtwork/build-painter-unknown-Debug 70 | 71 | 72 | true 73 | qmake 74 | 75 | QtProjectManager.QMakeBuildStep 76 | true 77 | 78 | false 79 | false 80 | false 81 | 82 | 83 | true 84 | Make 85 | 86 | Qt4ProjectManager.MakeStep 87 | 88 | -w 89 | -r 90 | 91 | false 92 | 93 | 94 | 95 | 2 96 | 构建 97 | 98 | ProjectExplorer.BuildSteps.Build 99 | 100 | 101 | 102 | true 103 | Make 104 | 105 | Qt4ProjectManager.MakeStep 106 | 107 | -w 108 | -r 109 | 110 | true 111 | clean 112 | 113 | 114 | 1 115 | 清理 116 | 117 | ProjectExplorer.BuildSteps.Clean 118 | 119 | 2 120 | false 121 | 122 | Debug 123 | 124 | Qt4ProjectManager.Qt4BuildConfiguration 125 | 2 126 | true 127 | 128 | 129 | /home/sheng/qtwork/build-painter-unknown-Release 130 | 131 | 132 | true 133 | qmake 134 | 135 | QtProjectManager.QMakeBuildStep 136 | false 137 | 138 | false 139 | false 140 | false 141 | 142 | 143 | true 144 | Make 145 | 146 | Qt4ProjectManager.MakeStep 147 | 148 | -w 149 | -r 150 | 151 | false 152 | 153 | 154 | 155 | 2 156 | 构建 157 | 158 | ProjectExplorer.BuildSteps.Build 159 | 160 | 161 | 162 | true 163 | Make 164 | 165 | Qt4ProjectManager.MakeStep 166 | 167 | -w 168 | -r 169 | 170 | true 171 | clean 172 | 173 | 174 | 1 175 | 清理 176 | 177 | ProjectExplorer.BuildSteps.Clean 178 | 179 | 2 180 | false 181 | 182 | Release 183 | 184 | Qt4ProjectManager.Qt4BuildConfiguration 185 | 0 186 | true 187 | 188 | 189 | /home/sheng/qtwork/build-painter-unknown-Profile 190 | 191 | 192 | true 193 | qmake 194 | 195 | QtProjectManager.QMakeBuildStep 196 | true 197 | 198 | false 199 | true 200 | false 201 | 202 | 203 | true 204 | Make 205 | 206 | Qt4ProjectManager.MakeStep 207 | 208 | -w 209 | -r 210 | 211 | false 212 | 213 | 214 | 215 | 2 216 | 构建 217 | 218 | ProjectExplorer.BuildSteps.Build 219 | 220 | 221 | 222 | true 223 | Make 224 | 225 | Qt4ProjectManager.MakeStep 226 | 227 | -w 228 | -r 229 | 230 | true 231 | clean 232 | 233 | 234 | 1 235 | 清理 236 | 237 | ProjectExplorer.BuildSteps.Clean 238 | 239 | 2 240 | false 241 | 242 | Profile 243 | 244 | Qt4ProjectManager.Qt4BuildConfiguration 245 | 0 246 | true 247 | 248 | 3 249 | 250 | 251 | 0 252 | 部署 253 | 254 | ProjectExplorer.BuildSteps.Deploy 255 | 256 | 1 257 | 在本地部署 258 | 259 | ProjectExplorer.DefaultDeployConfiguration 260 | 261 | 1 262 | 263 | 264 | false 265 | false 266 | 1000 267 | 268 | true 269 | 270 | false 271 | false 272 | false 273 | false 274 | true 275 | 0.01 276 | 10 277 | true 278 | 1 279 | 25 280 | 281 | 1 282 | true 283 | false 284 | true 285 | valgrind 286 | 287 | 0 288 | 1 289 | 2 290 | 3 291 | 4 292 | 5 293 | 6 294 | 7 295 | 8 296 | 9 297 | 10 298 | 11 299 | 12 300 | 13 301 | 14 302 | 303 | 2 304 | 305 | painter 306 | 307 | Qt4ProjectManager.Qt4RunConfiguration:/home/sheng/qtwork/monitor-desktop/painter.pro 308 | true 309 | 310 | painter.pro 311 | false 312 | 313 | /home/sheng/qtwork/build-painter-unknown-Release 314 | 3768 315 | false 316 | true 317 | false 318 | false 319 | true 320 | 321 | 1 322 | 323 | 324 | 325 | ProjectExplorer.Project.TargetCount 326 | 1 327 | 328 | 329 | ProjectExplorer.Project.Updater.FileVersion 330 | 18 331 | 332 | 333 | Version 334 | 18 335 | 336 | 337 | -------------------------------------------------------------------------------- /painter.pro.user.984e197: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | EnvironmentId 7 | {984e1975-25d6-4251-9c56-aba9c75bc6f8} 8 | 9 | 10 | ProjectExplorer.Project.ActiveTarget 11 | 0 12 | 13 | 14 | ProjectExplorer.Project.EditorSettings 15 | 16 | true 17 | false 18 | true 19 | 20 | Cpp 21 | 22 | CppGlobal 23 | 24 | 25 | 26 | QmlJS 27 | 28 | QmlJSGlobal 29 | 30 | 31 | 2 32 | UTF-8 33 | false 34 | 4 35 | false 36 | 80 37 | true 38 | true 39 | 1 40 | true 41 | false 42 | 0 43 | true 44 | true 45 | 0 46 | 8 47 | true 48 | 1 49 | true 50 | true 51 | true 52 | false 53 | 54 | 55 | 56 | ProjectExplorer.Project.PluginSettings 57 | 58 | 59 | 60 | ProjectExplorer.Project.Target.0 61 | 62 | 桌面 63 | 桌面 64 | {d398a100-6dba-4a16-991d-884d0f99ea69} 65 | 0 66 | 0 67 | 0 68 | 69 | /home/sheng/QT_works/build-painter-unknown-Debug 70 | 71 | 72 | true 73 | qmake 74 | 75 | QtProjectManager.QMakeBuildStep 76 | true 77 | 78 | false 79 | false 80 | false 81 | 82 | 83 | true 84 | Make 85 | 86 | Qt4ProjectManager.MakeStep 87 | 88 | -w 89 | -r 90 | 91 | false 92 | 93 | 94 | 95 | 2 96 | 构建 97 | 98 | ProjectExplorer.BuildSteps.Build 99 | 100 | 101 | 102 | true 103 | Make 104 | 105 | Qt4ProjectManager.MakeStep 106 | 107 | -w 108 | -r 109 | 110 | true 111 | clean 112 | 113 | 114 | 1 115 | 清理 116 | 117 | ProjectExplorer.BuildSteps.Clean 118 | 119 | 2 120 | false 121 | 122 | Debug 123 | 124 | Qt4ProjectManager.Qt4BuildConfiguration 125 | 2 126 | true 127 | 128 | 129 | /home/sheng/QT_works/build-painter-unknown-Release 130 | 131 | 132 | true 133 | qmake 134 | 135 | QtProjectManager.QMakeBuildStep 136 | false 137 | 138 | false 139 | false 140 | false 141 | 142 | 143 | true 144 | Make 145 | 146 | Qt4ProjectManager.MakeStep 147 | 148 | -w 149 | -r 150 | 151 | false 152 | 153 | 154 | 155 | 2 156 | 构建 157 | 158 | ProjectExplorer.BuildSteps.Build 159 | 160 | 161 | 162 | true 163 | Make 164 | 165 | Qt4ProjectManager.MakeStep 166 | 167 | -w 168 | -r 169 | 170 | true 171 | clean 172 | 173 | 174 | 1 175 | 清理 176 | 177 | ProjectExplorer.BuildSteps.Clean 178 | 179 | 2 180 | false 181 | 182 | Release 183 | 184 | Qt4ProjectManager.Qt4BuildConfiguration 185 | 0 186 | true 187 | 188 | 189 | /home/sheng/QT_works/build-painter-unknown-Profile 190 | 191 | 192 | true 193 | qmake 194 | 195 | QtProjectManager.QMakeBuildStep 196 | true 197 | 198 | false 199 | true 200 | false 201 | 202 | 203 | true 204 | Make 205 | 206 | Qt4ProjectManager.MakeStep 207 | 208 | -w 209 | -r 210 | 211 | false 212 | 213 | 214 | 215 | 2 216 | 构建 217 | 218 | ProjectExplorer.BuildSteps.Build 219 | 220 | 221 | 222 | true 223 | Make 224 | 225 | Qt4ProjectManager.MakeStep 226 | 227 | -w 228 | -r 229 | 230 | true 231 | clean 232 | 233 | 234 | 1 235 | 清理 236 | 237 | ProjectExplorer.BuildSteps.Clean 238 | 239 | 2 240 | false 241 | 242 | Profile 243 | 244 | Qt4ProjectManager.Qt4BuildConfiguration 245 | 0 246 | true 247 | 248 | 3 249 | 250 | 251 | 0 252 | 部署 253 | 254 | ProjectExplorer.BuildSteps.Deploy 255 | 256 | 1 257 | 在本地部署 258 | 259 | ProjectExplorer.DefaultDeployConfiguration 260 | 261 | 1 262 | 263 | 264 | false 265 | false 266 | 1000 267 | 268 | true 269 | 270 | false 271 | false 272 | false 273 | false 274 | true 275 | 0.01 276 | 10 277 | true 278 | 1 279 | 25 280 | 281 | 1 282 | true 283 | false 284 | true 285 | valgrind 286 | 287 | 0 288 | 1 289 | 2 290 | 3 291 | 4 292 | 5 293 | 6 294 | 7 295 | 8 296 | 9 297 | 10 298 | 11 299 | 12 300 | 13 301 | 14 302 | 303 | 2 304 | 305 | painter 306 | 307 | Qt4ProjectManager.Qt4RunConfiguration:/home/sheng/QT_works/monitor-desktop/painter.pro 308 | true 309 | 310 | painter.pro 311 | false 312 | 313 | /home/sheng/QT_works/build-painter-unknown-Debug 314 | 3768 315 | false 316 | true 317 | false 318 | false 319 | true 320 | 321 | 1 322 | 323 | 324 | 325 | ProjectExplorer.Project.TargetCount 326 | 1 327 | 328 | 329 | ProjectExplorer.Project.Updater.FileVersion 330 | 18 331 | 332 | 333 | Version 334 | 18 335 | 336 | 337 | -------------------------------------------------------------------------------- /painter.pro.user.d7bd2e8: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | EnvironmentId 7 | {d7bd2e88-b222-421c-9ea9-318a8761ed17} 8 | 9 | 10 | ProjectExplorer.Project.ActiveTarget 11 | 0 12 | 13 | 14 | ProjectExplorer.Project.EditorSettings 15 | 16 | true 17 | false 18 | true 19 | 20 | Cpp 21 | 22 | CppGlobal 23 | 24 | 25 | 26 | QmlJS 27 | 28 | QmlJSGlobal 29 | 30 | 31 | 2 32 | UTF-8 33 | false 34 | 4 35 | false 36 | 80 37 | true 38 | true 39 | 1 40 | true 41 | false 42 | 0 43 | true 44 | true 45 | 0 46 | 8 47 | true 48 | 1 49 | true 50 | true 51 | true 52 | false 53 | 54 | 55 | 56 | ProjectExplorer.Project.PluginSettings 57 | 58 | 59 | 60 | ProjectExplorer.Project.Target.0 61 | 62 | 桌面 63 | 桌面 64 | {48d66658-8c98-4dd7-87a4-d005f53fafa5} 65 | 1 66 | 0 67 | 0 68 | 69 | /home/sheng/QT_works/build-painter-unknown-Debug 70 | 71 | 72 | true 73 | qmake 74 | 75 | QtProjectManager.QMakeBuildStep 76 | true 77 | 78 | false 79 | false 80 | false 81 | 82 | 83 | true 84 | Make 85 | 86 | Qt4ProjectManager.MakeStep 87 | 88 | -w 89 | -r 90 | 91 | false 92 | 93 | 94 | 95 | 2 96 | 构建 97 | 98 | ProjectExplorer.BuildSteps.Build 99 | 100 | 101 | 102 | true 103 | Make 104 | 105 | Qt4ProjectManager.MakeStep 106 | 107 | -w 108 | -r 109 | 110 | true 111 | clean 112 | 113 | 114 | 1 115 | 清理 116 | 117 | ProjectExplorer.BuildSteps.Clean 118 | 119 | 2 120 | false 121 | 122 | Debug 123 | 124 | Qt4ProjectManager.Qt4BuildConfiguration 125 | 2 126 | true 127 | 128 | 129 | /home/sheng/QT_works/build-painter-unknown-Release 130 | 131 | 132 | true 133 | qmake 134 | 135 | QtProjectManager.QMakeBuildStep 136 | false 137 | 138 | false 139 | false 140 | false 141 | 142 | 143 | true 144 | Make 145 | 146 | Qt4ProjectManager.MakeStep 147 | 148 | -w 149 | -r 150 | 151 | false 152 | 153 | 154 | 155 | 2 156 | 构建 157 | 158 | ProjectExplorer.BuildSteps.Build 159 | 160 | 161 | 162 | true 163 | Make 164 | 165 | Qt4ProjectManager.MakeStep 166 | 167 | -w 168 | -r 169 | 170 | true 171 | clean 172 | 173 | 174 | 1 175 | 清理 176 | 177 | ProjectExplorer.BuildSteps.Clean 178 | 179 | 2 180 | false 181 | 182 | Release 183 | 184 | Qt4ProjectManager.Qt4BuildConfiguration 185 | 0 186 | true 187 | 188 | 189 | /home/sheng/QT_works/build-painter-unknown-Profile 190 | 191 | 192 | true 193 | qmake 194 | 195 | QtProjectManager.QMakeBuildStep 196 | true 197 | 198 | false 199 | true 200 | false 201 | 202 | 203 | true 204 | Make 205 | 206 | Qt4ProjectManager.MakeStep 207 | 208 | -w 209 | -r 210 | 211 | false 212 | 213 | 214 | 215 | 2 216 | 构建 217 | 218 | ProjectExplorer.BuildSteps.Build 219 | 220 | 221 | 222 | true 223 | Make 224 | 225 | Qt4ProjectManager.MakeStep 226 | 227 | -w 228 | -r 229 | 230 | true 231 | clean 232 | 233 | 234 | 1 235 | 清理 236 | 237 | ProjectExplorer.BuildSteps.Clean 238 | 239 | 2 240 | false 241 | 242 | Profile 243 | 244 | Qt4ProjectManager.Qt4BuildConfiguration 245 | 0 246 | true 247 | 248 | 3 249 | 250 | 251 | 0 252 | 部署 253 | 254 | ProjectExplorer.BuildSteps.Deploy 255 | 256 | 1 257 | 在本地部署 258 | 259 | ProjectExplorer.DefaultDeployConfiguration 260 | 261 | 1 262 | 263 | 264 | false 265 | false 266 | 1000 267 | 268 | true 269 | 270 | false 271 | false 272 | false 273 | false 274 | true 275 | 0.01 276 | 10 277 | true 278 | 1 279 | 25 280 | 281 | 1 282 | true 283 | false 284 | true 285 | valgrind 286 | 287 | 0 288 | 1 289 | 2 290 | 3 291 | 4 292 | 5 293 | 6 294 | 7 295 | 8 296 | 9 297 | 10 298 | 11 299 | 12 300 | 13 301 | 14 302 | 303 | 2 304 | 305 | painter 306 | 307 | Qt4ProjectManager.Qt4RunConfiguration:/home/sheng/QT_works/monitor-desktop/painter.pro 308 | true 309 | 310 | painter.pro 311 | false 312 | 313 | /home/sheng/QT_works/build-painter-unknown-Release 314 | 3768 315 | false 316 | true 317 | false 318 | false 319 | true 320 | 321 | 1 322 | 323 | 324 | 325 | ProjectExplorer.Project.TargetCount 326 | 1 327 | 328 | 329 | ProjectExplorer.Project.Updater.FileVersion 330 | 18 331 | 332 | 333 | Version 334 | 18 335 | 336 | 337 | -------------------------------------------------------------------------------- /painter.pro.user.dc0572a: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | EnvironmentId 7 | {dc0572a7-b8af-47cb-ad72-f08b84807601} 8 | 9 | 10 | ProjectExplorer.Project.ActiveTarget 11 | 0 12 | 13 | 14 | ProjectExplorer.Project.EditorSettings 15 | 16 | true 17 | false 18 | true 19 | 20 | Cpp 21 | 22 | CppGlobal 23 | 24 | 25 | 26 | QmlJS 27 | 28 | QmlJSGlobal 29 | 30 | 31 | 2 32 | UTF-8 33 | false 34 | 4 35 | false 36 | 80 37 | true 38 | true 39 | 1 40 | true 41 | false 42 | 0 43 | true 44 | true 45 | 0 46 | 8 47 | true 48 | 1 49 | true 50 | true 51 | true 52 | false 53 | 54 | 55 | 56 | ProjectExplorer.Project.PluginSettings 57 | 58 | 59 | 60 | ProjectExplorer.Project.Target.0 61 | 62 | 桌面 63 | 桌面 64 | {fe68303e-2394-4dd7-a78c-25fb852d2868} 65 | 1 66 | 0 67 | 0 68 | 69 | /home/sheng/QT_works/build-painter-unknown-Debug 70 | 71 | 72 | true 73 | qmake 74 | 75 | QtProjectManager.QMakeBuildStep 76 | true 77 | 78 | false 79 | false 80 | false 81 | 82 | 83 | true 84 | Make 85 | 86 | Qt4ProjectManager.MakeStep 87 | 88 | -w 89 | -r 90 | 91 | false 92 | 93 | 94 | 95 | 2 96 | 构建 97 | 98 | ProjectExplorer.BuildSteps.Build 99 | 100 | 101 | 102 | true 103 | Make 104 | 105 | Qt4ProjectManager.MakeStep 106 | 107 | -w 108 | -r 109 | 110 | true 111 | clean 112 | 113 | 114 | 1 115 | 清理 116 | 117 | ProjectExplorer.BuildSteps.Clean 118 | 119 | 2 120 | false 121 | 122 | Debug 123 | 124 | Qt4ProjectManager.Qt4BuildConfiguration 125 | 2 126 | true 127 | 128 | 129 | /home/sheng/QT_works/build-painter-unknown-Release 130 | 131 | 132 | true 133 | qmake 134 | 135 | QtProjectManager.QMakeBuildStep 136 | false 137 | 138 | false 139 | false 140 | false 141 | 142 | 143 | true 144 | Make 145 | 146 | Qt4ProjectManager.MakeStep 147 | 148 | -w 149 | -r 150 | 151 | false 152 | 153 | 154 | 155 | 2 156 | 构建 157 | 158 | ProjectExplorer.BuildSteps.Build 159 | 160 | 161 | 162 | true 163 | Make 164 | 165 | Qt4ProjectManager.MakeStep 166 | 167 | -w 168 | -r 169 | 170 | true 171 | clean 172 | 173 | 174 | 1 175 | 清理 176 | 177 | ProjectExplorer.BuildSteps.Clean 178 | 179 | 2 180 | false 181 | 182 | Release 183 | 184 | Qt4ProjectManager.Qt4BuildConfiguration 185 | 0 186 | true 187 | 188 | 189 | /home/sheng/QT_works/build-painter-unknown-Profile 190 | 191 | 192 | true 193 | qmake 194 | 195 | QtProjectManager.QMakeBuildStep 196 | true 197 | 198 | false 199 | true 200 | false 201 | 202 | 203 | true 204 | Make 205 | 206 | Qt4ProjectManager.MakeStep 207 | 208 | -w 209 | -r 210 | 211 | false 212 | 213 | 214 | 215 | 2 216 | 构建 217 | 218 | ProjectExplorer.BuildSteps.Build 219 | 220 | 221 | 222 | true 223 | Make 224 | 225 | Qt4ProjectManager.MakeStep 226 | 227 | -w 228 | -r 229 | 230 | true 231 | clean 232 | 233 | 234 | 1 235 | 清理 236 | 237 | ProjectExplorer.BuildSteps.Clean 238 | 239 | 2 240 | false 241 | 242 | Profile 243 | 244 | Qt4ProjectManager.Qt4BuildConfiguration 245 | 0 246 | true 247 | 248 | 3 249 | 250 | 251 | 0 252 | 部署 253 | 254 | ProjectExplorer.BuildSteps.Deploy 255 | 256 | 1 257 | 在本地部署 258 | 259 | ProjectExplorer.DefaultDeployConfiguration 260 | 261 | 1 262 | 263 | 264 | false 265 | false 266 | 1000 267 | 268 | true 269 | 270 | false 271 | false 272 | false 273 | false 274 | true 275 | 0.01 276 | 10 277 | true 278 | 1 279 | 25 280 | 281 | 1 282 | true 283 | false 284 | true 285 | valgrind 286 | 287 | 0 288 | 1 289 | 2 290 | 3 291 | 4 292 | 5 293 | 6 294 | 7 295 | 8 296 | 9 297 | 10 298 | 11 299 | 12 300 | 13 301 | 14 302 | 303 | 2 304 | 305 | painter 306 | 307 | Qt4ProjectManager.Qt4RunConfiguration:/home/sheng/QT_works/painter/painter.pro 308 | true 309 | 310 | painter.pro 311 | false 312 | 313 | /home/sheng/QT_works/build-painter-unknown-Release 314 | 3768 315 | false 316 | true 317 | false 318 | false 319 | true 320 | 321 | 1 322 | 323 | 324 | 325 | ProjectExplorer.Project.TargetCount 326 | 1 327 | 328 | 329 | ProjectExplorer.Project.Updater.FileVersion 330 | 18 331 | 332 | 333 | Version 334 | 18 335 | 336 | 337 | -------------------------------------------------------------------------------- /printcpu/manager.cpp: -------------------------------------------------------------------------------- 1 | #include "manager.h" 2 | #include "ui_manager.h" 3 | 4 | manager::manager(QScrollArea *parent) : 5 | QScrollArea(parent), 6 | ui(new Ui::manager) 7 | { 8 | ui->setupUi(this); 9 | setWindowFlags(Qt::FramelessWindowHint 10 | |Qt::Tool 11 | );//去边框//最ding层显示//不在任务栏显示 12 | 13 | this->setAttribute(Qt::WA_TranslucentBackground, true); 14 | isone = true; 15 | row =0; 16 | col =0; 17 | time = 0; 18 | times_1s = 10; 19 | timer = new QTimer; 20 | initui(); 21 | timer->setInterval(100); 22 | connect(timer,SIGNAL(timeout()),this,SLOT(timeout())); 23 | timer->start(); 24 | readset(); 25 | setalpha( alpha ); 26 | // getcpu(); 27 | } 28 | 29 | manager::~manager() 30 | { 31 | saveset(); 32 | delete ui; 33 | } 34 | 35 | void manager::getcpu() 36 | { 37 | //qDebug()<<"getcpu start"; 38 | QStringList* l; 39 | if(isone) 40 | { 41 | l=&list; 42 | isone = false; 43 | } 44 | else { 45 | l = &list2; 46 | isone = true; 47 | } 48 | l->clear(); 49 | 50 | file.setFileName("/proc/stat"); 51 | QTextStream in; 52 | in.setDevice(&file); 53 | if( file.open(QIODevice::ReadOnly)) 54 | { 55 | QString data = in.readAll(); 56 | //qDebug()<append(matchs.next().captured()); 62 | } 63 | //qDebug()<<(*l); 64 | if(list.isEmpty()||list2.isEmpty()) { 65 | file.close(); 66 | return; 67 | } 68 | else { 69 | result=getresult(list,list2); 70 | } 71 | } 72 | else { 73 | //qDebug()<<"file open error!"; 74 | } 75 | file.close(); 76 | QString info = QString().setNum( result.at(0)*100,'f',2)+"%"; 77 | emit cpuchange(info); 78 | //qDebug()<<"getcpu ed"; 79 | 80 | } 81 | 82 | void manager::timeout() 83 | { 84 | timer->stop(); 85 | time++; 86 | if(time>=times_1s) { 87 | time =0;//放在后面可以在停止后保存time值,绘图就不会变 88 | getcpu(); 89 | if(!result.isEmpty()) refresh(); 90 | } 91 | if(!result.isEmpty()) smallrefresh(); 92 | timer->start(); 93 | } 94 | 95 | QList manager::getresult(QStringList& l1,QStringList&l2){ 96 | QList result; 97 | QString one,two; 98 | float res; 99 | for(int i=0;i intlist; 119 | list = one.split(QRegularExpression(" +")); 120 | for(int i=0;isetObjectName("cpumonitor");//给qss用的 162 | cpu->set1s_times(times_1s); 163 | cpu->setcpunum(i); 164 | cpulist.append(cpu); 165 | if(i==0) ui->horizontalLayout->addWidget(cpu); 166 | //cpu->show(); 167 | i++; 168 | matchs.next(); 169 | } 170 | int n = i-1; //CPU数量 171 | //n=128;测试超多核 172 | if(n>8) 173 | { 174 | // int tmp =3; 175 | for(int i=(int)(qSqrt(n)+1);i>3;i--){ 176 | if(n%i==0){ 177 | col = n/i; 178 | row = n/col; 179 | break; 180 | } 181 | } 182 | if(col == 0) 183 | { 184 | col = 3; 185 | row = n/col+1; 186 | } 187 | } 188 | else if(n>3){ 189 | col =2; 190 | row =n/2; 191 | if(n%2!=0) n = n+1; 192 | } 193 | else { 194 | col = 1; 195 | row = n; 196 | } 197 | for(int i=0;igridLayout->addWidget(cpu,i,j); 203 | } 204 | } 205 | //qDebug()<adddata(result.at(0));//总的 224 | for(int i=0;iadddata(result.at(n+1)); 229 | } 230 | } 231 | //qDebug()<<"refresh ed"; 232 | 233 | } 234 | 235 | void manager::smallrefresh() 236 | { 237 | //qDebug()<<"refresh start"; 238 | Widget* cpu; 239 | cpu = cpulist.at(0); 240 | cpu->timechange(time); 241 | for(int i=0;itimechange(time); 246 | } 247 | } 248 | //qDebug()<<"refresh ed"; 249 | 250 | } 251 | 252 | 253 | void manager::mousePressEvent(QMouseEvent* event) 254 | { 255 | if(event->button()==Qt::LeftButton ) 256 | { 257 | oldpos=event->globalPos()-this->pos(); 258 | setCursor(Qt::ClosedHandCursor); 259 | event->accept(); 260 | } 261 | else QWidget::mousePressEvent(event); 262 | } 263 | 264 | void manager::mouseMoveEvent(QMouseEvent * event){ 265 | move(event->globalPos()-oldpos);//貌似linux要这样 266 | event->accept(); 267 | } 268 | 269 | void manager::mouseReleaseEvent(QMouseEvent * event){ 270 | if(event->button()==Qt::LeftButton ) 271 | { 272 | setCursor(Qt::ArrowCursor); 273 | //先判断y 274 | if(this->y()<=0) { 275 | move(x(),0); 276 | } 277 | else if(this->y()>QApplication::desktop()->height()-this->height()) 278 | move(x(),QApplication::desktop()->height()-this->height()); 279 | //后判断x,这样就左右优先,上其次 280 | if(this->x()<=0) { 281 | move(0,y()); 282 | } 283 | else if(this->x()>=QApplication::desktop()->width()-this->width()) { 284 | move(QApplication::desktop()->width()-this->width(),y()); 285 | } 286 | saveset(); 287 | event->accept(); 288 | 289 | } 290 | else QWidget::mouseReleaseEvent(event); 291 | } 292 | 293 | void manager::saveset() 294 | { 295 | QSettings set("Noahsai","Cpu-Monitor",this); 296 | set.setValue("geometry", this->geometry()); 297 | set.setValue("visible", this->isVisible()); 298 | set.setValue("alpha", alpha); 299 | //qDebug()<width()-this->width(),QApplication::desktop()->height()-this->height() , this->width() , this->height()))).toRect(); 308 | this->setGeometry(r); 309 | this->setVisible(set.value("visible",true).toBool()); 310 | alpha = set.value("alpha" , 230).toInt(); 311 | //qDebug()<button()==Qt::LeftButton ) 316 | { 317 | // qDebug()<show(); 322 | } 323 | else { 324 | setWindowFlags((Qt::Window|Qt::WindowTitleHint|Qt::WindowSystemMenuHint|Qt::WindowCloseButtonHint)); 325 | this->showNormal(); 326 | } 327 | 328 | event->accept(); 329 | 330 | } 331 | else QWidget::mouseReleaseEvent(event); 332 | } 333 | void manager::closeEvent(QCloseEvent *event){ 334 | hide(); 335 | event->accept(); 336 | } 337 | 338 | void manager::wheelEvent(QWheelEvent *event){ 339 | if(QApplication::keyboardModifiers() == Qt::ControlModifier) 340 | { 341 | QWheelEvent *e = static_cast(event); 342 | int degrees = e->delta();//上为正,下为负 343 | if(degrees > 0) 344 | { 345 | alpha +=10; 346 | if(alpha > 255) alpha = 255; 347 | } 348 | else{ 349 | alpha -=10; 350 | if(alpha < 0) alpha = 0; 351 | } 352 | setalpha(alpha); 353 | event->accept(); 354 | } 355 | else QWidget::wheelEvent(event); 356 | } 357 | 358 | void manager::setalpha(int a) 359 | { 360 | //qDebug()< 5 | #include "QTimer" 6 | #include "QFile" 7 | #include "QTextStream" 8 | #include"QDebug" 9 | #include"QRegularExpression" 10 | #include 11 | #include"printcpu/widget.h" 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | namespace Ui { 18 | class manager; 19 | } 20 | 21 | class manager : public QScrollArea 22 | { 23 | Q_OBJECT 24 | 25 | public: 26 | explicit manager(QScrollArea *parent = 0); 27 | ~manager(); 28 | 29 | private slots: 30 | void timeout(); 31 | 32 | signals: 33 | void cpuchange(QString&); 34 | private: 35 | Ui::manager *ui; 36 | void mousePressEvent(QMouseEvent* event); 37 | void mouseMoveEvent(QMouseEvent * event); 38 | void mouseReleaseEvent(QMouseEvent * event); 39 | void mouseDoubleClickEvent(QMouseEvent *event); 40 | void closeEvent(QCloseEvent *event); 41 | void wheelEvent(QWheelEvent *); 42 | QList getresult(QStringList&,QStringList&); 43 | float colculate(QString& one,QString& two);void initui(); 44 | void getcpu(); 45 | void refresh(); 46 | void smallrefresh(); 47 | void saveset(); 48 | void readset(); 49 | void setalpha(int ); 50 | QTimer *timer; 51 | QFile file; 52 | QStringList list; 53 | QStringList list2; 54 | QRegularExpression reg; 55 | QRegularExpressionMatchIterator matchs; 56 | bool isone; 57 | int row; 58 | int col; 59 | int time; 60 | int times_1s; 61 | int alpha; 62 | QList result; 63 | QList cpulist; 64 | QPoint oldpos; 65 | }; 66 | 67 | #endif // manager_H 68 | -------------------------------------------------------------------------------- /printcpu/manager.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | manager 4 | 5 | 6 | 7 | 0 8 | 0 9 | 224 10 | 203 11 | 12 | 13 | 14 | ScrollArea 15 | 16 | 17 | 18 | 19 | 20 | QFrame::NoFrame 21 | 22 | 23 | Qt::ScrollBarAlwaysOff 24 | 25 | 26 | true 27 | 28 | 29 | 30 | 31 | 0 32 | 0 33 | 224 34 | 203 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 2 43 | 44 | 45 | 2 46 | 47 | 48 | 2 49 | 50 | 51 | 2 52 | 53 | 54 | 2 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 2 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /printcpu/printcpu.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2017-10-16T22:18:45 4 | # 5 | #------------------------------------------------- 6 | 7 | QT += core gui 8 | 9 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 10 | 11 | TARGET = printcpu 12 | TEMPLATE = app 13 | 14 | # The following define makes your compiler emit warnings if you use 15 | # any feature of Qt which as been marked as deprecated (the exact warnings 16 | # depend on your compiler). Please consult the documentation of the 17 | # deprecated API in order to know how to port your code away from it. 18 | DEFINES += QT_DEPRECATED_WARNINGS 19 | 20 | # You can also make your code fail to compile if you use deprecated APIs. 21 | # In order to do so, uncomment the following line. 22 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 23 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 24 | 25 | 26 | SOURCES += \ 27 | main.cpp \ 28 | widget.cpp \ 29 | manager.cpp 30 | 31 | HEADERS += \ 32 | widget.h \ 33 | manager.h 34 | 35 | FORMS += \ 36 | widget.ui \ 37 | manager.ui 38 | -------------------------------------------------------------------------------- /printcpu/printcpu.pro.user.984e197: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | EnvironmentId 7 | {984e1975-25d6-4251-9c56-aba9c75bc6f8} 8 | 9 | 10 | ProjectExplorer.Project.ActiveTarget 11 | 0 12 | 13 | 14 | ProjectExplorer.Project.EditorSettings 15 | 16 | true 17 | false 18 | true 19 | 20 | Cpp 21 | 22 | CppGlobal 23 | 24 | 25 | 26 | QmlJS 27 | 28 | QmlJSGlobal 29 | 30 | 31 | 2 32 | UTF-8 33 | false 34 | 4 35 | false 36 | 80 37 | true 38 | true 39 | 1 40 | true 41 | false 42 | 0 43 | true 44 | true 45 | 0 46 | 8 47 | true 48 | 1 49 | true 50 | true 51 | true 52 | false 53 | 54 | 55 | 56 | ProjectExplorer.Project.PluginSettings 57 | 58 | 59 | 60 | ProjectExplorer.Project.Target.0 61 | 62 | 桌面 63 | 桌面 64 | {d398a100-6dba-4a16-991d-884d0f99ea69} 65 | 0 66 | 0 67 | 0 68 | 69 | /home/sheng/QT_works/build-printcpu-unknown-Debug 70 | 71 | 72 | true 73 | qmake 74 | 75 | QtProjectManager.QMakeBuildStep 76 | true 77 | 78 | false 79 | false 80 | false 81 | 82 | 83 | true 84 | Make 85 | 86 | Qt4ProjectManager.MakeStep 87 | 88 | -w 89 | -r 90 | 91 | false 92 | 93 | 94 | 95 | 2 96 | 构建 97 | 98 | ProjectExplorer.BuildSteps.Build 99 | 100 | 101 | 102 | true 103 | Make 104 | 105 | Qt4ProjectManager.MakeStep 106 | 107 | -w 108 | -r 109 | 110 | true 111 | clean 112 | 113 | 114 | 1 115 | 清理 116 | 117 | ProjectExplorer.BuildSteps.Clean 118 | 119 | 2 120 | false 121 | 122 | Debug 123 | 124 | Qt4ProjectManager.Qt4BuildConfiguration 125 | 2 126 | true 127 | 128 | 129 | /home/sheng/QT_works/build-printcpu-unknown-Release 130 | 131 | 132 | true 133 | qmake 134 | 135 | QtProjectManager.QMakeBuildStep 136 | false 137 | 138 | false 139 | false 140 | false 141 | 142 | 143 | true 144 | Make 145 | 146 | Qt4ProjectManager.MakeStep 147 | 148 | -w 149 | -r 150 | 151 | false 152 | 153 | 154 | 155 | 2 156 | 构建 157 | 158 | ProjectExplorer.BuildSteps.Build 159 | 160 | 161 | 162 | true 163 | Make 164 | 165 | Qt4ProjectManager.MakeStep 166 | 167 | -w 168 | -r 169 | 170 | true 171 | clean 172 | 173 | 174 | 1 175 | 清理 176 | 177 | ProjectExplorer.BuildSteps.Clean 178 | 179 | 2 180 | false 181 | 182 | Release 183 | 184 | Qt4ProjectManager.Qt4BuildConfiguration 185 | 0 186 | true 187 | 188 | 189 | /home/sheng/QT_works/build-printcpu-unknown-Profile 190 | 191 | 192 | true 193 | qmake 194 | 195 | QtProjectManager.QMakeBuildStep 196 | true 197 | 198 | false 199 | true 200 | false 201 | 202 | 203 | true 204 | Make 205 | 206 | Qt4ProjectManager.MakeStep 207 | 208 | -w 209 | -r 210 | 211 | false 212 | 213 | 214 | 215 | 2 216 | 构建 217 | 218 | ProjectExplorer.BuildSteps.Build 219 | 220 | 221 | 222 | true 223 | Make 224 | 225 | Qt4ProjectManager.MakeStep 226 | 227 | -w 228 | -r 229 | 230 | true 231 | clean 232 | 233 | 234 | 1 235 | 清理 236 | 237 | ProjectExplorer.BuildSteps.Clean 238 | 239 | 2 240 | false 241 | 242 | Profile 243 | 244 | Qt4ProjectManager.Qt4BuildConfiguration 245 | 0 246 | true 247 | 248 | 3 249 | 250 | 251 | 0 252 | 部署 253 | 254 | ProjectExplorer.BuildSteps.Deploy 255 | 256 | 1 257 | 在本地部署 258 | 259 | ProjectExplorer.DefaultDeployConfiguration 260 | 261 | 1 262 | 263 | 264 | false 265 | false 266 | 1000 267 | 268 | true 269 | 270 | false 271 | false 272 | false 273 | false 274 | true 275 | 0.01 276 | 10 277 | true 278 | 1 279 | 25 280 | 281 | 1 282 | true 283 | false 284 | true 285 | valgrind 286 | 287 | 0 288 | 1 289 | 2 290 | 3 291 | 4 292 | 5 293 | 6 294 | 7 295 | 8 296 | 9 297 | 10 298 | 11 299 | 12 300 | 13 301 | 14 302 | 303 | 2 304 | 305 | printcpu 306 | 307 | Qt4ProjectManager.Qt4RunConfiguration:/home/sheng/QT_works/printcpu/printcpu.pro 308 | true 309 | 310 | printcpu.pro 311 | false 312 | 313 | /home/sheng/QT_works/build-printcpu-unknown-Debug 314 | 3768 315 | false 316 | true 317 | false 318 | false 319 | true 320 | 321 | 1 322 | 323 | 324 | 325 | ProjectExplorer.Project.TargetCount 326 | 1 327 | 328 | 329 | ProjectExplorer.Project.Updater.FileVersion 330 | 18 331 | 332 | 333 | Version 334 | 18 335 | 336 | 337 | -------------------------------------------------------------------------------- /printcpu/widget.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | #include "ui_widget.h" 3 | 4 | //float a[31] = {0.0,0.3,0.0,0.201,0.10,0.609,0.1,0.40,1,0.4,0.0,0.3,0.0,0.201,0.10,0.609,0.1,0.40,1,0.4,0.0,0.3,0.0,0.201,0.10,0.609,0.1,0.40,1,0.4,0.2}; 5 | Widget::Widget(QWidget *parent) : 6 | QWidget(parent), 7 | ui(new Ui::Widget) 8 | { 9 | ui->setupUi(this); 10 | setAutoFillBackground(true); 11 | //this->setAttribute(Qt::WA_TranslucentBackground, true); 12 | howlong_fresh = 100;//多少毫秒刷新一次; 13 | show_second = 30;//显示框中头-尾总共show_second+1秒,因为1-show_second+1之间有10个间隔,10比较好算数 14 | times_1s = 1000/howlong_fresh;//1秒内几次 15 | time = 0; 16 | cpunum=0; 17 | // now = 0; 18 | initlist();//放在show_second后面 19 | // timer.setSingleShot(false); 20 | // timer.setInterval(howlong_fresh); 21 | // connect(&timer ,SIGNAL(timeout()),this,SLOT(timeout())); 22 | // //adddata(a[now]); 23 | // timer.start(); 24 | //resize(100,30); 25 | setMinimumSize(70,30); 26 | 27 | } 28 | 29 | Widget::~Widget() 30 | { 31 | delete ui; 32 | } 33 | 34 | 35 | QSize Widget:: sizeHint() 36 | { 37 | return QSize(100,30); 38 | } 39 | 40 | 41 | 42 | void Widget::initlist(){ 43 | datalist.clear(); 44 | for(int i =0;iwidth()/6; 58 | p.drawLine(pre*i,0,pre*i,this->height()); 59 | } 60 | for(int i =1;i<=3;i++){ 61 | qreal pre = this->height()/4; 62 | p.drawLine(0,pre*i,this->width(),pre*i); 63 | } 64 | p.setRenderHint(QPainter::Antialiasing,true); 65 | QPainterPath path; 66 | bool start = false; 67 | qreal x=-1.0; 68 | qreal y=-1.0; 69 | // p.translate(0-this->width()/show_second,0); 70 | for (int i=0;iheight()); 78 | path.lineTo(x,y); 79 | } 80 | else path.lineTo(x,y); 81 | // qDebug()<<"x,y"<height()); 84 | // qDebug()<height()/3); 90 | // fon.setBold(true); 91 | p.setFont(fon); 92 | //p.drawText(this->rect(),QString().setNum(cpunum),QTextOption(Qt::AlignTop|Qt::AlignLeft)); 93 | p.drawText(this->rect()," "+QString().setNum(cpunum)); 94 | } 95 | //画曲线 96 | p.setBrush(QBrush(QColor("#99ddeeff"))); 97 | p.setPen(QColor("#8cc8ff")); 98 | p.drawPath(path); 99 | //画边框 100 | p.setBrush(Qt::transparent); 101 | p.setPen(QPen(QColor("gray"),1)); 102 | p.drawRect(this->rect()); 103 | //写数字 104 | QFont fon; 105 | p.setPen(QColor("#222222")); 106 | int s = this->height()/3; 107 | if(s<10) s =10; 108 | fon.setPixelSize(s); 109 | p.setFont(fon); 110 | float n = datalist.last()*100; 111 | if(datalist.last()<=0) n = 0.0; 112 | p.drawText(this->rect(),QString().setNum(n,'f',1)+"%",QTextOption(Qt::AlignHCenter|Qt::AlignTop)); 113 | // qDebug()<<"paint"; 114 | 115 | } 116 | 117 | 118 | //void Widget::timeout() 119 | //{ 120 | // time++; 121 | // if(time>=times_1s) { 122 | // if(now>show_second) {timer.stop();return;} 123 | // time =0;//放在后面可以在停止后保存time值,绘图就不会变 124 | // adddata(a[now]); 125 | // now ++; 126 | // } 127 | // update(); 128 | 129 | //} 130 | 131 | void Widget::adddata(float pre){ 132 | datalist.takeFirst(); 133 | datalist.append(pre);//写到此处 134 | if(isVisible()) update(); 135 | } 136 | 137 | void Widget::timechange(int time){ 138 | this->time = time ; 139 | update(); 140 | } 141 | 142 | void Widget:: set1s_times(int times){ 143 | times_1s = times; 144 | } 145 | 146 | 147 | void Widget:: setcpunum(int n){ 148 | cpunum = n; 149 | } 150 | 151 | 152 | qreal Widget::lms(int show_second , int times_1s){ 153 | qreal w = this->width(); 154 | qreal l = w/show_second/times_1s;// 宽度/10s/10次=100ms的长度 155 | // qDebug()<<"lms"<height()-20)*(1.0-per)+10;//上下边距10 166 | qreal y = (this->height())*(1.0-per); 167 | // qDebug()<<"y"<height()< 5 | #include"QPainter" 6 | #include"QTimer" 7 | #include"QPainterPath" 8 | #include"QDebug" 9 | #include"QPixmap" 10 | #include"QLabel" 11 | namespace Ui { 12 | class Widget; 13 | } 14 | 15 | class Widget : public QWidget 16 | { 17 | Q_OBJECT 18 | 19 | public: 20 | explicit Widget(QWidget *parent = 0); 21 | void adddata(float pre); 22 | 23 | void set1s_times(int times); 24 | void timechange( int time); 25 | void setcpunum(int n); 26 | ~Widget(); 27 | 28 | private slots: 29 | // void timeout(); 30 | 31 | private: 32 | QSize sizeHint(); 33 | void paintEvent(QPaintEvent *event); 34 | Ui::Widget *ui; 35 | void initlist(); 36 | qreal lms(int alls , int prems); 37 | qreal getx(int ms); 38 | qreal gety(float per); 39 | int posx; 40 | int posy; 41 | QList datalist; 42 | //QTimer timer; 43 | int times_1s,time; 44 | QPixmap *pix; 45 | int show_second; 46 | int howlong_fresh; 47 | int cpunum; 48 | //int now; 49 | }; 50 | 51 | #endif // WIDGET_H 52 | -------------------------------------------------------------------------------- /printcpu/widget.ui: -------------------------------------------------------------------------------- 1 | 2 | Widget 3 | 4 | 5 | 6 | 0 7 | 0 8 | 400 9 | 300 10 | 11 | 12 | 13 | Widget 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /red.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/noahsai/monitor-desktop/31f60350d16b71c377b2ec4a84138a6fa199a18a/red.png -------------------------------------------------------------------------------- /res.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | green.png 4 | yellow.png 5 | red.png 6 | 7 | 8 | -------------------------------------------------------------------------------- /yellow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/noahsai/monitor-desktop/31f60350d16b71c377b2ec4a84138a6fa199a18a/yellow.png -------------------------------------------------------------------------------- /截图/截图_2017-12-04_11-37-58.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/noahsai/monitor-desktop/31f60350d16b71c377b2ec4a84138a6fa199a18a/截图/截图_2017-12-04_11-37-58.png -------------------------------------------------------------------------------- /截图/截图_2017-12-04_11-38-28.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/noahsai/monitor-desktop/31f60350d16b71c377b2ec4a84138a6fa199a18a/截图/截图_2017-12-04_11-38-28.png -------------------------------------------------------------------------------- /截图/截图_2017-12-04_11-38-39.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/noahsai/monitor-desktop/31f60350d16b71c377b2ec4a84138a6fa199a18a/截图/截图_2017-12-04_11-38-39.png -------------------------------------------------------------------------------- /截图/截图_2017-12-04_11-39-54.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/noahsai/monitor-desktop/31f60350d16b71c377b2ec4a84138a6fa199a18a/截图/截图_2017-12-04_11-39-54.png -------------------------------------------------------------------------------- /截图/截图_2017-12-04_11-48-20.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/noahsai/monitor-desktop/31f60350d16b71c377b2ec4a84138a6fa199a18a/截图/截图_2017-12-04_11-48-20.png --------------------------------------------------------------------------------