summaryrefslogtreecommitdiffstats
path: root/pica-client/dialogs/showpicaiddialog.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'pica-client/dialogs/showpicaiddialog.cpp')
-rw-r--r--pica-client/dialogs/showpicaiddialog.cpp32
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()));