-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
121 lines (98 loc) · 2.99 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "about.h"
#include "ui_about.h"
#include <QDir>
#include <QFileInfoList>
#include <QString>
#include <QDebug>
#include <vector>
#include <random>
#include <time.h>
using namespace std;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->pushButton->setEnabled(false);
ui->pushButton_2->setEnabled(false);
}
void MainWindow::traverse(const QString &pattern, const QString &dirname, int level)
{
QDir dir(dirname);
dir.setFilter(QDir::Dirs | QDir::Files | QDir::NoSymLinks | QDir::NoDot | QDir::NoDotDot);
static const QStringList stringList = pattern.split('/');
foreach (QFileInfo fileInfo, dir.entryInfoList(stringList.mid(level, 1))) {
if (fileInfo.isDir() && fileInfo.isReadable())
traverse(pattern, fileInfo.filePath(), level+1);
else if (stringList.size() == (level + 1)) {
// pth
pth.push_back(fileInfo.filePath());
// qDebug() << fileInfo.filePath();
}
}
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
ui->lbl_descr->clear();
//qsrand(qrand());
srand (time(NULL));
MyRand = rand() % ((pth.size() - 1));
//qDebug() << pth.at(MyRand) << " - " << MyRand;
QImage *img;
img = new QImage();
img->load(pth.at(MyRand));
ui->ImgLabel->setPixmap(QPixmap::fromImage(img->scaled(
ui->ImgLabel->geometry().width(),
ui->ImgLabel->geometry().height(), Qt::IgnoreAspectRatio)));
delete img;
ui->pushButton_2->setEnabled(true);
}
unsigned int MainWindow::getNumberFPath(unsigned int V)
{
QString str = pth.at(V);
return str.split('/').at(1).toInt();
}
void MainWindow::on_pushButton_2_clicked()
{
unsigned int var = getNumberFPath(MyRand);
unsigned int rb;
if (ui->radioButton->isChecked()) {
rb = 1;
} else if (ui->radioButton_2->isChecked()) {
rb =2;
} else {
rb = 3;
}
if (rb == var) {
cinTrue+=1;
ui->lbl_true->setText("Правильных ответов - " + QString::number(cinTrue));
} else {
cinFalse +=1;
ui->lbl_false->setText("Неправильных ответов - " + QString::number(cinFalse));
}
ui->lbl_descr->setText("<<<----- это CIN"+QString::number(var));
ui->pushButton_2->setEnabled(false);
}
void MainWindow::on_pushButton_3_clicked()
{
pth.clear();
traverse("*/*", "cin", 0);
ui->pushButton->setEnabled(true);
ui->pushButton->click();
ui->pushButton_3->setEnabled(false);
ui->pushButton_2->setEnabled(true);
cinTrue = 0;
cinFalse = 0;
cnt=0;
}
void MainWindow::on_pushButton_4_clicked()
{
About* ab = new About();
ab->show();
}