-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainwindow.cpp
220 lines (149 loc) · 5.88 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QPalette>
#include <QKeyEvent>
#include <QtWidgets>
Q_DECLARE_METATYPE(QCameraInfo)
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent), decoder(QZXing::DecoderFormat_QR_CODE),
camera(0),
imageCapture(0),
mediaRecorder(0),
isCapturingImage(false),
applicationExiting(false),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QActionGroup *videoDevicesGroup = new QActionGroup(this);
videoDevicesGroup->setExclusive(true);
// QMessageBox::information(this,"cameras",QString::number(QCameraInfo::availableCameras().size()));
foreach (const QCameraInfo &cameraInfo, QCameraInfo::availableCameras()) {
QAction *videoDeviceAction = new QAction(cameraInfo.description(), videoDevicesGroup);
videoDeviceAction->setCheckable(true);
videoDeviceAction->setData(QVariant::fromValue(cameraInfo));
if (cameraInfo == QCameraInfo::defaultCamera())
videoDeviceAction->setChecked(true);
ui->menuDevices->addAction(videoDeviceAction);
}
manager = new QNetworkAccessManager(this);
ui->pushButton->setText("ttyty");
connect(manager, SIGNAL(finished(QNetworkReply*)),
this, SLOT(replyFinished(QNetworkReply*)));
// decoder.DecoderFormat_QR_CODE;
connect(&decoder, SIGNAL(tagFound(QString)), this, SLOT(reportTagFound(QString)));
connect(videoDevicesGroup, SIGNAL(triggered(QAction*)), SLOT(updateCameraDevice(QAction*)));
//connect(ui->captureWidget, SIGNAL(currentChanged(int)), SLOT(updateCaptureMode()));
//setCamera(QCameraInfo::defaultCamera());
loginpass = new logindialog(this);
connect(loginpass,SIGNAL(MainShoww()),this,SLOT(Suclogin()));
loginpass->show();
}
MainWindow::~MainWindow()
{
delete ui;
delete mediaRecorder;
delete imageCapture;
delete camera;
}
void MainWindow::on_pushButton_2_clicked()
{
int Counts=0;
QString URLaddress ="http://"+ui->lineEdit->text();
ui->label->setText(URLaddress);
// manager->get(QNetworkRequest(QUrl(URLaddress)));
}
void MainWindow::replyFinished(QNetworkReply* reply)
{
QByteArray content = reply->readAll();
ui->textEdit->setPlainText(content.data());
qDebug() << "testing";
QMessageBox::information(this,"test",QString::number(content.length()));
// this->setWindowOpacity(0.75);
}
void MainWindow::RepeatGET()
{
}
void MainWindow::on_pushButton_3_clicked()
{
qDebug() << QR_Sample.load(":/image/qrtest2.png");
ui->label_2->setPixmap(QPixmap::fromImage(QR_Sample));
qDebug() << QR_Sample.size();
qDebug() << decoder.decodeImage(QR_Sample,1800,1800,false);
qDebug() << QR_Sample.size();
}
void MainWindow::reportTagFound(QString tag)
{
QMessageBox::information(this, QString("Decoding result") ,tag);
qDebug() << tag;
qDebug() << decoder.getProcessTimeOfLastDecoding();
QMessageBox::information(this,"test",QString::number(decoder.getProcessTimeOfLastDecoding()));
}
void MainWindow::on_pushButton_4_clicked()
{
// QList<QByteArray> cams = QCamera::availableDevices();
// m_defaultDevice = cams.at(2);
// m_camera = new QCamera( m_defaultDevice );
QImage QR_Sample2(800,600,QImage::Format_RGB32);
QR_Sample2 = ui->viewfinder->grab().toImage();
ui->label_2->setPixmap(QPixmap::fromImage(QR_Sample2));
qDebug() << QR_Sample2.size();
qDebug() << decoder.decodeImage(QR_Sample2,1800,1800,false);
qDebug() << QR_Sample2.size();
}
void MainWindow::Suclogin()
{
MainWindow::show();
loginpass->close();
delete loginpass;
}
void MainWindow::setCamera(const QCameraInfo &cameraInfo)
{
delete imageCapture;
delete mediaRecorder;
delete camera;
camera = new QCamera(cameraInfo);
//connect(camera, SIGNAL(stateChanged(QCamera::State)), this, SLOT(updateCameraState(QCamera::State)));
// connect(camera, SIGNAL(error(QCamera::Error)), this, SLOT(displayCameraError()));
mediaRecorder = new QMediaRecorder(camera);
// connect(mediaRecorder, SIGNAL(stateChanged(QMediaRecorder::State)), this, SLOT(updateRecorderState(QMediaRecorder::State)));
imageCapture = new QCameraImageCapture(camera);
// connect(mediaRecorder, SIGNAL(durationChanged(qint64)), this, SLOT(updateRecordTime()));
// connect(mediaRecorder, SIGNAL(error(QMediaRecorder::Error)), this, SLOT(displayRecorderError()));
mediaRecorder->setMetaData(QMediaMetaData::Title, QVariant(QLatin1String("Test Title")));
//connect(ui->exposureCompensation, SIGNAL(valueChanged(int)), SLOT(setExposureCompensation(int)));
camera->setViewfinder(ui->viewfinder);
//updateCameraState(camera->state());
// updateLockStatus(camera->lockStatus(), QCamera::UserRequest);
// updateRecorderState(mediaRecorder->state());
//ui->captureWidget->setTabEnabled(0, (camera->isCaptureModeSupported(QCamera::CaptureStillImage)));
//ui->captureWidget->setTabEnabled(1, (camera->isCaptureModeSupported(QCamera::CaptureVideo)));
//updateCaptureMode();
camera->start();
}
void MainWindow::updateCameraDevice(QAction *action)
{
setCamera(qvariant_cast<QCameraInfo>(action->data()));
}
void MainWindow::on_pushButton_clicked()
{
QByteArray requestString = "logn=222&prl=xml";
QString URLaddress ="http://"+ui->lineEdit->text();
ui->label->setText(URLaddress);
QNetworkRequest request(URLaddress);
manager->post(request,requestString);
}
void MainWindow::on_action_triggered()
{
QMessageBox* sure = new QMessageBox(this);
sure->setWindowTitle("Выход из программы");
sure->setText("Вы действительно хотите выйти?");
sure->setIcon(QMessageBox::Warning);
sure->setStandardButtons(QMessageBox::Yes | QMessageBox::No);
sure->setDefaultButton(QMessageBox::No);
int n = sure->exec();
delete sure;
if (n == QMessageBox::Yes)
{
qApp->quit();
}
}