-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainwindow.cpp
81 lines (70 loc) · 2.08 KB
/
mainwindow.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 "mainwindow.h"
#include "ui_mainwindow.h"
#include "worker.h"
#include <QTime>
#include <QThread>
#include <QDebug>
#include <QPainter>
#include <QFile>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
startFlag = 0;
lapCounter = 0;
Worker *lobWorker = new Worker;
lobWorker->moveToThread(&workerThread);
connect(lobWorker,SIGNAL(resultReady(QString)),this,SLOT(workerFinish(QString)));
connect(this,SIGNAL(startChrono()),lobWorker,SLOT(launchChrono()));
connect(this, SIGNAL(resetChrono()), lobWorker, SLOT(resetChrono()));
connect(&workerThread, SIGNAL (finished()), &workerThread, SLOT (deleteLater()));
workerThread.start();
this->statusBar()->showMessage(tr("www.gtronick.com"));
QFile styleFile("style.qss");
styleFile.open(QFile::ReadOnly);
QString StyleSheet = QLatin1String(styleFile.readAll());
this->setStyleSheet(StyleSheet);
this->setWindowFlags(Qt::WindowStaysOnTopHint);
}
MainWindow::~MainWindow()
{
workerThread.quit();
workerThread.wait();
delete ui;
}
void MainWindow::on_startButton_clicked()
{
if(startFlag == 0){
ui->startButton->setIcon(QIcon(":/img/img/Stop.png"));
ui->startButton->setText("Stop");
emit(startChrono());
startFlag = 1;
stopFlag = 1;
}else{
ui->startButton->setIcon(QIcon(":/img/img/Go.png"));
ui->startButton->setText("Start");
startFlag = 0;
stopFlag = 0;
}
}
void MainWindow::on_resetButton_clicked()
{
ui->gobLCD->setText("00:00:00");
emit(resetChrono());
}
void MainWindow::on_flagButton_clicked()
{
lapCounter ++;
ui->gobLapTextArea->appendPlainText(QString("%1) %2 ").arg(lapCounter).arg(ui->gobLCD->text()));
}
void MainWindow::workerFinish(QString data)
{
ui->gobLCD->setText(data);
if(startFlag == 1)emit(startChrono());
}
void MainWindow::on_clearLapsButton_clicked()
{
ui->gobLapTextArea->clear();
lapCounter = 0;
}