1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Cleanup QR PR

Fix coding style, #include "" -> #include <>
Remove tooltip
Move "tox:" addition out of qr-related code

Conflicts:
	src/misc/qrwidget.cpp
This commit is contained in:
Dubslow 2015-03-16 14:53:35 -05:00
parent 01a4cdd07e
commit b908852e3b
No known key found for this signature in database
GPG Key ID: 3DB8E05315C220AA
4 changed files with 28 additions and 41 deletions

View File

@ -68,13 +68,13 @@ sudo pacman -S --needed base-devel qt5 opencv openal libxss qrencode
Debian / Ubuntu:
```bash
sudo apt-get install build-essential qt5-qmake qt5-default qttools5-dev-tools libqt5opengl5-dev libqt5svg5-dev libopenal-dev libopencv-dev libxss-dev qrencode
sudo apt-get install build-essential qt5-qmake qt5-default qttools5-dev-tools libqt5opengl5-dev libqt5svg5-dev libopenal-dev libopencv-dev libxss-dev qrencode libqrencode-dev
```
Fedora:
```bash
yum groupinstall "Development Tools"
yum install qt-devel qt-doc qt-creator qt5-qtsvg opencv-devel openal-soft-devel libXScrnSaver-devel qrencode
yum install qt-devel qt-doc qt-creator qt5-qtsvg opencv-devel openal-soft-devel libXScrnSaver-devel qrencode-devel
```
Slackware:

View File

@ -3,7 +3,8 @@
#include <QDebug>
#include <QBuffer>
#include <QImage>
#include "qrencode.h"
#include <qrencode.h>
#include <sys/errno.h>
QRWidget::QRWidget(QWidget *parent) : QWidget(parent), data("0")
//Note: The encoding fails with empty string so I just default to something else.
@ -15,9 +16,9 @@ QRWidget::QRWidget(QWidget *parent) : QWidget(parent), data("0")
image = new QImage(size, QImage::Format_RGB32);
}
void QRWidget::setQRData(QString data)
void QRWidget::setQRData(const QString& data)
{
this->data = "tox:" + data;
this->data = data;
paintImage();
}
@ -36,29 +37,17 @@ bool QRWidget::saveImage(QString path)
return image->save(path, 0, 75); //0 - image format same as file extension, 75-quality, png file is ~6.3kb
}
QString QRWidget::getImageAsText()
{
paintImage();
QByteArray ba;
QBuffer buffer(&ba);
buffer.open(QIODevice::WriteOnly);
image->save(&buffer, "PNG"); // writes the image in PNG format inside the buffer
QString iconBase64 = QString::fromLatin1(ba.toBase64().data());
QString base64Image = "<img width=\"300\" heigth=\"300\" src=\"data:image/png;base64," + iconBase64 +"\" />";
return QString(base64Image);
}
//http://stackoverflow.com/questions/21400254/how-to-draw-a-qr-code-with-qt-in-native-c-c
void QRWidget::paintImage()
{
QPainter painter(image);
//NOTE: I have hardcoded some parameters here that would make more sense as variables.
// ECLEVEL_M is much faster recognizable by barcodescanner any any other type
QRcode *qr = QRcode_encodeString(data.toStdString().c_str(), 1, QR_ECLEVEL_M, QR_MODE_8, 0);
// https://fukuchi.org/works/qrencode/manual/qrencode_8h.html#a4cebc3c670efe1b8866b14c42737fc8f
// any mode other than QR_MODE_8 or QR_MODE_KANJI results in EINVAL. First 1 is version, second is case sensitivity
QRcode* qr = QRcode_encodeString(data.toStdString().c_str(), 1, QR_ECLEVEL_M, QR_MODE_8, 1);
if(0 != qr)
if (qr != nullptr)
{
QColor fg("black");
QColor bg("white");
@ -72,14 +61,14 @@ void QRWidget::paintImage()
const double aspect = w / h;
const double scale = ((aspect > 1.0) ? h : w) / s;
for(int y = 0; y < s; y++)
for (int y = 0; y < s; y++)
{
const int yy = y * s;
for(int x = 0; x < s; x++)
for (int x = 0; x < s; x++)
{
const int xx = yy + x;
const unsigned char b = qr->data[xx];
if(b & 0x01)
if (b & 0x01)
{
const double rx1 = x * scale,
ry1 = y * scale;
@ -99,5 +88,5 @@ void QRWidget::paintImage()
qDebug() << "QR FAIL: " << strerror(errno);
}
qr = 0;
qr = nullptr;
}

View File

@ -11,15 +11,14 @@ class QRWidget : public QWidget
public:
explicit QRWidget(QWidget *parent = 0);
void setQRData(QString data);
QString getImageAsText();
void setQRData(const QString& data);
QImage* getImage();
bool saveImage(QString path);
private:
QString data;
void paintImage();
QImage *image;
QImage* image;
QSize size;
};

View File

@ -172,9 +172,8 @@ void ProfileForm::setToxId(const QString& id)
toxId->setCursorPosition(0);
qr = new QRWidget();
qr->setQRData(id);
qr->setQRData("tox:"+id);
bodyUI->qrCode->setPixmap(QPixmap::fromImage(qr->getImage()->scaledToWidth(150)));
bodyUI->qrCode->setToolTip(qr->getImageAsText());
}
void ProfileForm::onAvatarClicked()