diff options
| author | Anton <anton@picapica.im> | 2026-12-02 03:52:50 +0400 |
|---|---|---|
| committer | Anton <anton@picapica.im> | 2026-12-02 03:52:50 +0400 |
| commit | c3298beb0779a8cc09b6d4ea0d2132c0612ea776 (patch) | |
| tree | 910842506249d59a05cae4a72229b61049fcab19 /pica-client/dialogs/showpicaiddialog.cpp | |
| parent | 56863d74399c8d7354a00bc8ddc87b924ef870ab (diff) | |
| download | pica-pica-qr_codes.tar.gz pica-pica-qr_codes.zip | |
pica-client: show and scan contact ID as a QR codeqr_codes
Diffstat (limited to 'pica-client/dialogs/showpicaiddialog.cpp')
| -rw-r--r-- | pica-client/dialogs/showpicaiddialog.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/pica-client/dialogs/showpicaiddialog.cpp b/pica-client/dialogs/showpicaiddialog.cpp index cff91c0..e47e78a 100644 --- a/pica-client/dialogs/showpicaiddialog.cpp +++ b/pica-client/dialogs/showpicaiddialog.cpp @@ -18,6 +18,17 @@ #include <QVBoxLayout> #include <QFontMetrics> #include <QStyle> +#include <QPixmap> + +#ifdef HAVE_QRCODE +#include "../qrcode.h" + +// The QR code's side, in device independent pixels: large enough for a camera +// across a desk to resolve its modules, small enough for the dialog to stay a +// dialog. Rounded to a whole number of physical pixels per module, so that no +// module comes out a pixel narrower than its neighbour. +static const int kQrCodeSide = 300; +#endif ShowPicaIdDialog::ShowPicaIdDialog(QString name, QByteArray id, QString caption, QWidget *parent) : QDialog(parent) @@ -41,6 +52,27 @@ ShowPicaIdDialog::ShowPicaIdDialog(QString name, QByteArray id, QString caption, layout->addWidget(lbname_); layout->addWidget(picaid_); + +#ifdef HAVE_QRCODE + // The same text the line above shows, for another Pica Pica to read with + // "Contacts -> Scan the QR Code" - or any phone's scanner app. + const QImage code = picaQrCodeImage(picaid_->text()); + + if (!code.isNull()) + { + const qreal dpr = devicePixelRatioF(); + const int modulePixels = qMax(1, qRound(kQrCodeSide * dpr / code.width())); + QPixmap pixmap = QPixmap::fromImage(code.scaled(code.size() * modulePixels, + Qt::IgnoreAspectRatio, + Qt::FastTransformation)); + pixmap.setDevicePixelRatio(dpr); + + qrcode_ = new QLabel(); + qrcode_->setPixmap(pixmap); + qrcode_->setAlignment(Qt::AlignCenter); + layout->addWidget(qrcode_, 0, Qt::AlignHCenter); + } +#endif layout->addWidget(btok_, 0, Qt::AlignHCenter); connect(btok_, SIGNAL(clicked()), this, SLOT(Ok())); |
