-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainwindow.cpp
90 lines (79 loc) · 2.05 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
82
83
84
85
86
87
88
89
90
#include <chrono>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <functional>
#include <iostream>
#include <thread>
#include <QAudioOutput>
#include <QCheckBox>
#include <QCoreApplication>
#include <QMediaPlayer>
#include <QUrl>
#include "mainwindow.h"
#include "ui_mainwindow.h"
QCheckBox *boxes[18][24];
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
for (int i = 0; i < 18; i++) {
for (int j = 0; j < 24; j++) {
QCheckBox *c = new QCheckBox(ui->centralwidget);
c->setGeometry(j * 14, i * 14, 14, 14);
boxes[i][j] = c;
}
}
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_actionSelectAll_triggered()
{
for (int i = 0; i < 18; i++) {
for (int j = 0; j < 24; j++) {
boxes[i][j]->setChecked(true);
}
}
}
void MainWindow::on_actionUnselectAll_triggered()
{
for (int i = 0; i < 18; i++) {
for (int j = 0; j < 24; j++) {
boxes[i][j]->setChecked(false);
}
}
}
int fps = 15;
void MainWindow::play()
{
std::ifstream text("E:\\Qt\\badapple.txt");
std::string line;
while (std::getline(text, line)) {
for (int i = 0; i < 18; i++) {
for (int j = 0; j < 24; j++) {
boxes[i][j]->setChecked(line[i * 24 + j] - '0');
boxes[i][j]->update();
}
}
// QCoreApplication::processEvents();
std::this_thread::sleep_for(std::chrono::milliseconds(1000 / fps));
}
text.close();
}
void MainWindow::on_actionStart_triggered()
{
std::thread playThread([this]() {
this->play();
});
playThread.detach();
QMediaPlayer* player = new QMediaPlayer;
QAudioOutput* audioOutput = new QAudioOutput;
player->setAudioOutput(audioOutput);
connect(player, SIGNAL(positionChanged(qint64)), this, SLOT(positionChanged(qint64)));
player->setSource(QUrl::fromLocalFile("E:\\Qt\\BadApple.mp3"));
audioOutput->setVolume(50);
player->play();
}