Page Menu
Home
Phabricator (Chris)
Search
Configure Global Search
Log In
Files
F132291
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
19 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/3rdparty/qqrencode/libqtqrencode_global.h b/3rdparty/qqrencode/libqtqrencode_global.h
new file mode 100644
index 0000000..9ec2bc5
--- /dev/null
+++ b/3rdparty/qqrencode/libqtqrencode_global.h
@@ -0,0 +1,12 @@
+#ifndef LIBQTQRENCODE_GLOBAL_H
+#define LIBQTQRENCODE_GLOBAL_H
+
+#include <QtCore/qglobal.h>
+
+#if defined(LIBQTQRENCODE_LIBRARY)
+# define LIBQTQRENCODESHARED_EXPORT Q_DECL_EXPORT
+#else
+# define LIBQTQRENCODESHARED_EXPORT Q_DECL_IMPORT
+#endif
+
+#endif // LIBQTQRENCODE_GLOBAL_H
diff --git a/3rdparty/qqrencode/qqrencode.cpp b/3rdparty/qqrencode/qqrencode.cpp
new file mode 100644
index 0000000..b85d3b1
--- /dev/null
+++ b/3rdparty/qqrencode/qqrencode.cpp
@@ -0,0 +1,268 @@
+#include "qqrencode.h"
+#include "qqrencode_p.h"
+
+#include <QDateTime>
+#include <QSvgGenerator>
+
+#define INCHES_PER_METER (100.0/2.54)
+
+QQREncodePrivate::~QQREncodePrivate()
+{
+ QRcode_free(m_code);
+}
+
+void QQREncodePrivate::paint(QPainter &painter)
+{
+ unsigned char *row, *p;
+ int x, y;
+
+ int symwidth = m_code->width + m_margin * 2;
+ painter.setClipRect(QRect(0,0,symwidth, symwidth));
+ painter.setPen(m_pen);
+ painter.setBrush(m_fg);
+
+ /* Make solid background */
+ painter.fillRect(QRect(0, 0, symwidth, symwidth), m_bg);
+
+ /* Write data */
+ p = m_code->data;
+ for(y=0; y<m_code->width; y++) {
+ row = (p+(y*m_code->width));
+ /* no RLE */
+ for(x=0; x<m_code->width; x++) {
+ if(*(row+x)&0x1) {
+ painter.drawRect(m_margin + x, m_margin + y, 1, 1);
+ }
+ }
+
+ }
+}
+
+QQREncode::QQREncode()
+ : d_ptr(new QQREncodePrivate(this))
+{
+}
+
+QQREncode::~QQREncode()
+{
+}
+
+void QQREncode::setLevel(QQREncode::ErrorCorrectionLevel value)
+{
+ Q_D(QQREncode);
+ switch (value) {
+ case LOW:
+ d->m_level = QR_ECLEVEL_L;
+ break;
+ case MEDIUM:
+ d->m_level = QR_ECLEVEL_M;
+ break;
+ case QUARTILE:
+ d->m_level = QR_ECLEVEL_Q;
+ break;
+ case HIGH:
+ d->m_level = QR_ECLEVEL_H;
+ break;
+ }
+}
+
+QQREncode::ErrorCorrectionLevel QQREncode::getLevel() const
+{
+ Q_D(const QQREncode);
+ switch (d->m_level) {
+ case QR_ECLEVEL_L:
+ return LOW;
+ case QR_ECLEVEL_M:
+ return MEDIUM;
+ case QR_ECLEVEL_Q:
+ return QUARTILE;
+ case QR_ECLEVEL_H:
+ return HIGH;
+ }
+ return LOW;
+}
+
+//bool QQREncode::encode(QString code, QString output)
+//{
+// if (code.isEmpty() || output.isEmpty()) {
+// return false;
+// }
+// QString program = "./qrencode.exe";
+// QStringList arguments;
+// arguments << "-t" << "PNG";
+// arguments << "-o" << output;
+// arguments << code;
+
+// QProcess *myProcess = new QProcess(this);
+// myProcess->start(program, arguments);
+// return myProcess->waitForFinished();
+//}
+
+
+void QQREncode::setVersion(int version)
+{
+ Q_D(QQREncode);
+ // 1 - 40
+ if (version > 0 && version <= 40)
+ d->m_version = version;
+}
+
+int QQREncode::version() const
+{
+ Q_D(const QQREncode);
+ return d->m_version;
+}
+
+void QQREncode::setMargin(int value)
+{
+ Q_D(QQREncode);
+ if (value > -1)
+ d->m_margin = value;
+}
+
+int QQREncode::margin() const
+{
+ Q_D(const QQREncode);
+ return d->m_margin;
+}
+
+void QQREncode::setMicro(bool value)
+{
+ Q_D(QQREncode);
+ d->m_micro = (value) ? 1 : 0;
+}
+
+bool QQREncode::isMicro() const
+{
+ Q_D(const QQREncode);
+ return (d->m_micro == 1) ? true : false;
+}
+
+void QQREncode::setBackground(QColor color)
+{
+ Q_D(QQREncode);
+ d->m_bg.setColor(color);
+}
+
+void QQREncode::setForeground(QColor color)
+{
+ Q_D(QQREncode);
+ d->m_fg.setColor(color);
+ d->m_pen.setColor(color);
+}
+
+bool QQREncode::encode(QByteArray input)
+{
+ Q_D(QQREncode);
+ QRcode *c = NULL;
+ if (input.isEmpty()) return false;
+ if (d->m_micro) {
+ c = QRcode_encodeDataMQR(input.size(), (const unsigned char*)input.constData(),
+ d->m_version, d->m_level);
+ } else {
+ c = QRcode_encodeData(input.size(), (const unsigned char*)input.constData(),
+ d->m_version, d->m_level);
+ }
+ if (c == NULL) {
+ return false;
+ }
+ if (d->m_code) QRcode_free(d->m_code);
+ d->m_code = c;
+ return true;
+}
+
+bool QQREncode::encode(QString input, bool caseSensitive)
+{
+ Q_D(QQREncode);
+ if (input.isEmpty()) return false;
+ QRcode *c = NULL;
+ if (d->m_micro) {
+ c = QRcode_encodeStringMQR(input.toStdString().c_str(),
+ d->m_version,
+ d->m_level,
+ QR_MODE_8,
+ (caseSensitive) ? 1 : 0);
+ } else {
+ c = QRcode_encodeString(input.toStdString().c_str(),
+ d->m_version,
+ d->m_level,
+ QR_MODE_8,
+ (caseSensitive) ? 1 : 0);
+ }
+ if (c == NULL) {
+ return false;
+ }
+ if (d->m_code) QRcode_free(d->m_code);
+ d->m_code = c;
+ return true;
+}
+
+bool QQREncode::encodeKanji(QByteArray input, bool caseSensitive)
+{
+ Q_D(QQREncode);
+ if (input.isEmpty()) return false;
+ QRcode *c = NULL;
+ if (d->m_micro) {
+ c = QRcode_encodeStringMQR(input.constData(),
+ d->m_version,
+ d->m_level,
+ QR_MODE_KANJI,
+ (caseSensitive) ? 1 : 0);
+ } else {
+ c = QRcode_encodeString(input.constData(),
+ d->m_version,
+ d->m_level,
+ QR_MODE_KANJI,
+ (caseSensitive) ? 1 : 0);
+ }
+ if (c == NULL) {
+ return false;
+ }
+ if (d->m_code) QRcode_free(d->m_code);
+ d->m_code = c;
+ return true;
+}
+
+bool QQREncode::toSVG(QString output, int size)
+{
+ Q_D(QQREncode);
+ if (output.isEmpty() || d->m_code == NULL) {
+ return false;
+ }
+
+ QSvgGenerator generator;
+ generator.setFileName(output);
+ generator.setSize(QSize(size, size));
+ int symwidth = d->m_code->width + d->m_margin * 2;
+ generator.setViewBox(QRect(0, 0, symwidth, symwidth));
+
+ QPainter painter;
+ painter.begin(&generator);
+ d->paint(painter);
+ painter.end();
+
+ return true;
+}
+
+QImage QQREncode::toQImage(int size)
+{
+ Q_D(QQREncode);
+ if (size < 0) throw std::invalid_argument("Invalid size");
+
+ if (d->m_code == NULL) {
+ std::logic_error("No qr code to convert");
+ }
+
+ int symwidth = d->m_code->width + d->m_margin * 2;
+ QImage result(QSize(symwidth, symwidth), QImage::Format_Mono);
+ result.fill(Qt::white);
+
+ QPainter painter;
+ painter.begin(&result);
+ d->paint(painter);
+ painter.end();
+
+ if (size > 0)
+ return result.scaled(size, size);
+ return result;
+}
diff --git a/3rdparty/qqrencode/qqrencode.h b/3rdparty/qqrencode/qqrencode.h
new file mode 100644
index 0000000..4ebf668
--- /dev/null
+++ b/3rdparty/qqrencode/qqrencode.h
@@ -0,0 +1,52 @@
+#ifndef QQRENCODE_H
+#define QQRENCODE_H
+
+#include <QtCore>
+
+#include "libqtqrencode_global.h"
+
+class QQREncodePrivate;
+
+class LIBQTQRENCODESHARED_EXPORT QQREncode
+{
+ Q_GADGET
+ Q_ENUMS(ErrorCorrectionLevel)
+
+public:
+ enum ErrorCorrectionLevel {
+ LOW,
+ MEDIUM,
+ QUARTILE,
+ HIGH
+ };
+
+ QQREncode();
+ ~QQREncode();
+
+ void setLevel(ErrorCorrectionLevel value);
+ ErrorCorrectionLevel getLevel() const;
+ void setVersion(int version);
+ int version() const;
+ void setMargin(int value);
+ int margin() const;
+ void setMicro(bool value);
+ bool isMicro() const;
+ void setBackground(QColor color);
+ void setForeground(QColor color);
+
+ bool encode(QByteArray input);
+ bool encode(QString input, bool caseSensitive=true);
+ bool encodeKanji(QByteArray input, bool caseSensitive=true);
+
+ bool toSVG(QString output, int size);
+ QImage toQImage(int size=0);
+
+ // ToDo: encode structured, rle
+
+private:
+ Q_DISABLE_COPY(QQREncode)
+ QScopedPointer<QQREncodePrivate> d_ptr;
+ Q_DECLARE_PRIVATE(QQREncode)
+};
+
+#endif // QQRENCODE_H
diff --git a/3rdparty/qqrencode/qqrencode.pro b/3rdparty/qqrencode/qqrencode.pro
new file mode 100644
index 0000000..d4534ab
--- /dev/null
+++ b/3rdparty/qqrencode/qqrencode.pro
@@ -0,0 +1,37 @@
+QT += core gui svg
+
+!win32-msvc2010 {
+ QMAKE_CXXFLAGS_DEBUG += -std=c++11 -Wno-write-strings
+ QMAKE_CXXFLAGS_RELEASE += -std=c++11 -Wno-write-strings
+}
+
+TARGET = qtqrencode
+TEMPLATE = lib
+
+DEFINES += LIBQTQRENCODE_LIBRARY
+
+SOURCES += qqrencode.cpp
+
+HEADERS += qqrencode.h \
+ libqtqrencode_global.h \
+ qqrencode_p.h
+
+header_files.files = qqrencode.h \
+ libqtqrencode_global.h
+header_files.path = /usr/include
+INSTALLS += header_files
+
+win32 {
+ LIBS += -L$$PWD/../lib/qrencode -lqrencode
+} else {
+ target.path = /usr/lib
+ INSTALLS += target
+ macx {
+ LIBS += -L/usr/local/lib -lqrencode
+ } else {
+ LIBS += -lqrencode
+ }
+}
+
+INCLUDEPATH += $$PWD/../lib/qrencode/include
+DEPENDPATH += $$PWD/../lib/qrencode/include
diff --git a/3rdparty/qqrencode/qqrencode_p.h b/3rdparty/qqrencode/qqrencode_p.h
new file mode 100644
index 0000000..1a41e8d
--- /dev/null
+++ b/3rdparty/qqrencode/qqrencode_p.h
@@ -0,0 +1,42 @@
+#ifndef QQRENCODE_P_H
+#define QQRENCODE_P_H
+
+#include "qqrencode.h"
+
+#include <qrencode.h>
+#include <QPainter>
+
+class QQREncodePrivate
+{
+ Q_DECLARE_PUBLIC(QQREncode)
+
+public:
+ QQREncodePrivate(QQREncode *qqrencode)
+ : q_ptr(qqrencode), m_code(NULL), m_level(QR_ECLEVEL_L),m_version(1), m_margin(4), m_micro(0),
+ m_pen(Qt::black, 0.1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin), m_bg(Qt::white),
+ m_fg(Qt::black)
+ {
+ }
+
+ ~QQREncodePrivate();
+
+ void paint(QPainter &painter);
+
+ QQREncode *q_ptr;
+ QRcode *m_code;
+ QRecLevel m_level;
+ int m_version;
+ int m_margin;
+ int m_micro;
+ QPen m_pen;
+ QBrush m_bg;
+ QBrush m_fg;
+
+ // ToDo: Corrupted SVG when setting the resolution
+// int m_dpi = 72;
+ // ToDo: structured and rle features
+// int m_structured = 0;
+// int m_rle = 0;
+};
+
+#endif // QQRENCODE_P_H
diff --git a/barcoder.pro b/barcoder.pro
index 0240f48..5cb5b2b 100644
--- a/barcoder.pro
+++ b/barcoder.pro
@@ -1,31 +1,35 @@
#-------------------------------------------------
#
# Project created by QtCreator 2017-02-16T22:41:52
#
#-------------------------------------------------
-QT += core gui
+QT += core gui svg
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = barcoder
TEMPLATE = app
# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
+INCLUDEPATH += 3rdparty/qqrencode
+LIBS += -lqrencode -lpng -ldmtx
SOURCES += main.cpp\
- mainwindow.cpp
+ mainwindow.cpp\
+ 3rdparty/qqrencode/qqrencode.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
+
diff --git a/mainwindow.cpp b/mainwindow.cpp
index 52bfb06..c5529c1 100644
--- a/mainwindow.cpp
+++ b/mainwindow.cpp
@@ -1,79 +1,64 @@
#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);
- QPixmap p;
- // if more than one argument, assume last argument is a string to encode
- //!! NOTE this may not work in Windows depending how app is started!
- if (QApplication::arguments().length() > 1) {
- // qDebug() << QApplication::arguments().last();
- QProcess dmtx;
- dmtx.start("dmtxwrite", QStringList() << "-s" << "40x40");
- dmtx.waitForStarted();
-
- dmtx.write(QApplication::arguments().last().toUtf8());
- dmtx.closeWriteChannel();
- dmtx.waitForFinished();
-
- QByteArray result = dmtx.readAll();
- p.loadFromData(result,"PNG");
- ui->label->setPixmap(p);
-
- ////////////////////////////////////////////////////
- dmtx.start("qrencode", QStringList() << "-o" << "-");
- dmtx.waitForStarted();
+ this->setWindowFlags(Qt::WindowStaysOnTopHint/*|Qt::X11BypassWindowManagerHint|Qt::FramelessWindowHint*/);
+ /*this->setWindowState(Qt::WindowFullScreen);*/
- dmtx.write(QApplication::arguments().last().toUtf8());
- dmtx.closeWriteChannel();
- dmtx.waitForFinished();
-
- result = dmtx.readAll();
- p.loadFromData(result,"PNG");
- ui->label_2->setPixmap(p);
-// ui->label->setPixmap();
+ // the text that I want encoded
+ QString inputText;
+ if (QApplication::arguments().length() > 1) {
+ inputText = QApplication::arguments().last();
} else {
- QClipboard *clipboard = QGuiApplication::clipboard();
- // qDebug() << clipboard->text();
- QProcess dmtx;
- dmtx.start("dmtxwrite", QStringList() << "-s" << "40x40");
- dmtx.waitForStarted();
+ inputText = QGuiApplication::clipboard()->text();
+ }
- dmtx.write(clipboard->text().toUtf8());
- dmtx.closeWriteChannel();
- dmtx.waitForFinished();
+ // DATAMATRIX STUFF START
+ DmtxEncode *enc;
+ int err = 0;
- QByteArray result = dmtx.readAll();
- p.loadFromData(result,"PNG");
- ui->label->setPixmap(p);
+ enc = dmtxEncodeCreate();
+ /* Read input data into buffer */
+ err = dmtxEncodeDataMatrix(enc, inputText.length(), (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
- ////////////////////////////////////////////////////
- dmtx.start("qrencode", QStringList() << "-o" << "-");
- dmtx.waitForStarted();
- dmtx.write(clipboard->text().toUtf8());
- dmtx.closeWriteChannel();
- dmtx.waitForFinished();
+ // 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
- result = dmtx.readAll();
- p.loadFromData(result,"PNG");
- ui->label_2->setPixmap(p);
+ // 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();
- //connect(ui->centralWidget, SIGNAL(clicked()), qApp, SLOT(quit()));
}
-void MainWindow::mousePressEvent (QMouseEvent * event)
+void MainWindow::mousePressEvent ( QMouseEvent * event )
{
QApplication::quit();
}
MainWindow::~MainWindow()
{
delete ui;
}
diff --git a/mainwindow.h b/mainwindow.h
index e07018d..ebed0c3 100644
--- a/mainwindow.h
+++ b/mainwindow.h
@@ -1,23 +1,41 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
+typedef struct {
+ char *inputPath;
+ char *outputPath;
+ char *format;
+ int codewords;
+ int marginSize;
+ int moduleSize;
+ int scheme;
+ int preview;
+ int rotate;
+ int sizeIdx;
+ int color[3];
+ int bgColor[3];
+ int mosaic;
+ int dpi;
+ int verbose;
+} UserOptions;
+
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
void mousePressEvent(QMouseEvent *);
~MainWindow();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
diff --git a/mainwindow.ui b/mainwindow.ui
index 0da9927..59a1abd 100644
--- a/mainwindow.ui
+++ b/mainwindow.ui
@@ -1,90 +1,90 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
- <width>640</width>
- <height>300</height>
+ <width>638</width>
+ <height>298</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>barcoder</string>
</property>
<widget class="QWidget" name="centralWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<widget class="QWidget" name="horizontalLayoutWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>276</width>
<height>80</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>100</number>
</property>
<property name="sizeConstraint">
<enum>QLayout::SetMinimumSize</enum>
</property>
<property name="leftMargin">
<number>30</number>
</property>
<property name="topMargin">
<number>30</number>
</property>
<property name="rightMargin">
<number>30</number>
</property>
<property name="bottomMargin">
<number>30</number>
</property>
<item>
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Tue, Jun 16, 12:40 AM (2 w, 1 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
72433
Default Alt Text
(19 KB)
Attached To
Mode
R4 barcoder
Attached
Detach File
Event Timeline