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:
parent
01a4cdd07e
commit
b908852e3b
|
@ -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:
|
||||
|
|
|
@ -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);
|
||||
|
||||
if(0 != qr)
|
||||
// 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 (qr != nullptr)
|
||||
{
|
||||
QColor fg("black");
|
||||
QColor bg("white");
|
||||
|
@ -71,15 +60,15 @@ void QRWidget::paintImage()
|
|||
const double h = height();
|
||||
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;
|
||||
|
@ -98,6 +87,6 @@ void QRWidget::paintImage()
|
|||
painter.drawRect(0, 0, width(), height());
|
||||
qDebug() << "QR FAIL: " << strerror(errno);
|
||||
}
|
||||
|
||||
qr = 0;
|
||||
|
||||
qr = nullptr;
|
||||
}
|
||||
|
|
|
@ -8,18 +8,17 @@
|
|||
class QRWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
public:
|
||||
explicit QRWidget(QWidget *parent = 0);
|
||||
void setQRData(QString data);
|
||||
QString getImageAsText();
|
||||
void setQRData(const QString& data);
|
||||
QImage* getImage();
|
||||
bool saveImage(QString path);
|
||||
|
||||
bool saveImage(QString path);
|
||||
|
||||
private:
|
||||
QString data;
|
||||
void paintImage();
|
||||
QImage *image;
|
||||
QImage* image;
|
||||
QSize size;
|
||||
};
|
||||
|
||||
|
|
|
@ -75,11 +75,11 @@ ProfileForm::ProfileForm(QWidget *parent) :
|
|||
toxId->setReadOnly(true);
|
||||
toxId->setFrame(false);
|
||||
toxId->setFont(Style::getFont(Style::Small));
|
||||
|
||||
|
||||
QVBoxLayout *toxIdGroup = qobject_cast<QVBoxLayout*>(bodyUI->toxGroup->layout());
|
||||
toxIdGroup->replaceWidget(bodyUI->toxId, toxId);
|
||||
bodyUI->toxId->hide();
|
||||
|
||||
|
||||
profilePicture = new MaskablePixmapWidget(this, QSize(64, 64), ":/img/avatar_mask.png");
|
||||
profilePicture->setPixmap(QPixmap(":/img/contact_dark.png"));
|
||||
profilePicture->setClickable(true);
|
||||
|
@ -91,7 +91,7 @@ ProfileForm::ProfileForm(QWidget *parent) :
|
|||
timer.setInterval(750);
|
||||
timer.setSingleShot(true);
|
||||
connect(&timer, &QTimer::timeout, this, [=]() {bodyUI->toxIdLabel->setText(bodyUI->toxIdLabel->text().replace(" ✔", "")); hasCheck = false;});
|
||||
|
||||
|
||||
connect(bodyUI->toxIdLabel, SIGNAL(clicked()), this, SLOT(copyIdClicked()));
|
||||
connect(toxId, SIGNAL(clicked()), this, SLOT(copyIdClicked()));
|
||||
connect(core, &Core::idSet, this, &ProfileForm::setToxId);
|
||||
|
@ -170,11 +170,10 @@ void ProfileForm::setToxId(const QString& id)
|
|||
{
|
||||
toxId->setText(id);
|
||||
toxId->setCursorPosition(0);
|
||||
|
||||
qr = new QRWidget();
|
||||
qr->setQRData(id);
|
||||
|
||||
qr = new QRWidget();
|
||||
qr->setQRData("tox:"+id);
|
||||
bodyUI->qrCode->setPixmap(QPixmap::fromImage(qr->getImage()->scaledToWidth(150)));
|
||||
bodyUI->qrCode->setToolTip(qr->getImageAsText());
|
||||
}
|
||||
|
||||
void ProfileForm::onAvatarClicked()
|
||||
|
|
Loading…
Reference in New Issue
Block a user