-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
71 lines (59 loc) · 1.9 KB
/
mainwindow.cpp
File metadata and controls
71 lines (59 loc) · 1.9 KB
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
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QProcess>
#include <QClipboard>
#include "qqrencode.h"
#include <dmtx.h>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
this->setWindowFlags(Qt::WindowStaysOnTopHint/*|Qt::X11BypassWindowManagerHint|Qt::FramelessWindowHint*/);
/*this->setWindowState(Qt::WindowFullScreen);*/
// the text that I want encoded
QString inputText;
if (QApplication::arguments().length() > 1) {
inputText = QApplication::arguments().last();
} else {
inputText = QGuiApplication::clipboard()->text();
}
// DATAMATRIX STUFF START
DmtxEncode *enc;
int err = 0;
int len = inputText.length();
// segfault for text longer than this. so dont bother
if (len > 1595) {
// err = 1596;
} else {
enc = dmtxEncodeCreate();
/* Read input data into buffer */
err = dmtxEncodeDataMatrix(enc, len, (unsigned char*)inputText.toLocal8Bit().data());
QImage dmatrix(enc->image->pxl, enc->image->width, enc->image->height, QImage::Format_RGB888);
ui->label->setPixmap(QPixmap::fromImage(dmatrix).scaled(240,240));
dmtxEncodeDestroy(&enc);
}
// DATAMATRIX STUFF END
// QRCODE STUFF START
QQREncode encoder;
encoder.encode(inputText);
QImage qrcode = encoder.toQImage().scaled(240,240);
ui->label_2->setPixmap(QPixmap::fromImage(qrcode));
// QRCODE STUFF END
// COMPENSATE FOR DMATRIX FAILURE USING INVERTED QRCODE START
if (err == 0) {
qrcode.invertPixels();
ui->label->setPixmap(QPixmap::fromImage(qrcode));
}
// COMPENSATE FOR DMATRIX FAILURE USING INVERTED QRCODE END
this->updateGeometry();
}
void MainWindow::mousePressEvent ( QMouseEvent * event )
{
Q_UNUSED(event);
QApplication::quit();
}
MainWindow::~MainWindow()
{
delete ui;
}