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: Debian / Ubuntu:
```bash ```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: Fedora:
```bash ```bash
yum groupinstall "Development Tools" 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: Slackware:

View File

@ -3,7 +3,8 @@
#include <QDebug> #include <QDebug>
#include <QBuffer> #include <QBuffer>
#include <QImage> #include <QImage>
#include "qrencode.h" #include <qrencode.h>
#include <sys/errno.h>
QRWidget::QRWidget(QWidget *parent) : QWidget(parent), data("0") QRWidget::QRWidget(QWidget *parent) : QWidget(parent), data("0")
//Note: The encoding fails with empty string so I just default to something else. //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); 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(); 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 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 //http://stackoverflow.com/questions/21400254/how-to-draw-a-qr-code-with-qt-in-native-c-c
void QRWidget::paintImage() void QRWidget::paintImage()
{ {
QPainter painter(image); QPainter painter(image);
//NOTE: I have hardcoded some parameters here that would make more sense as variables. //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 // 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 fg("black");
QColor bg("white"); QColor bg("white");
@ -99,5 +88,5 @@ void QRWidget::paintImage()
qDebug() << "QR FAIL: " << strerror(errno); qDebug() << "QR FAIL: " << strerror(errno);
} }
qr = 0; qr = nullptr;
} }

View File

@ -11,8 +11,7 @@ class QRWidget : public QWidget
public: public:
explicit QRWidget(QWidget *parent = 0); explicit QRWidget(QWidget *parent = 0);
void setQRData(QString data); void setQRData(const QString& data);
QString getImageAsText();
QImage* getImage(); QImage* getImage();
bool saveImage(QString path); bool saveImage(QString path);

View File

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