/*
(c) Copyright 2012 - 2018 Anton Sviridenko
https://picapica.im
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, version 3.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
#include "showpicaiddialog.h"
#include
#include
#include
#include
#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)
{
setWindowTitle(caption);
QVBoxLayout *layout = new QVBoxLayout(this);
lbname_ = new QLabel(tr("Account: %1").arg(name.toHtmlEscaped()));
lbname_ ->setTextFormat(Qt::RichText);
picaid_ = new QLineEdit();
picaid_ ->setText(id.toBase64().constData());
picaid_->setReadOnly(true);
picaid_->setSelection(0, picaid_->text().size());
picaid_->setMinimumWidth(picaid_->fontMetrics().horizontalAdvance(picaid_->text()) + 16 + 2 * picaid_->style()->pixelMetric(QStyle::PM_DefaultFrameWidth));
btok_ = new QPushButton(tr("OK"));
btok_->setDefault(true);
btok_->setMaximumWidth(btok_->fontMetrics().horizontalAdvance(btok_->text()) * 3 / 2 + 2 * btok_->style()->pixelMetric(QStyle::PM_ButtonMargin));
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()));
}
void ShowPicaIdDialog::Ok()
{
done(0);
}