You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
2.1 KiB
64 lines
2.1 KiB
#include "invitedialog.h" |
|
#include "qrcode_utils.h" |
|
#include <QVBoxLayout> |
|
#include <QHBoxLayout> |
|
#include <QLineEdit> |
|
#include <QPushButton> |
|
#include <QLabel> |
|
#include <QClipboard> |
|
#include <QApplication> |
|
#include <QTimer> |
|
|
|
InviteDialog::InviteDialog(const QString& link, QWidget* parent) |
|
: QDialog(parent), m_link(link) |
|
{ |
|
setWindowTitle("Пригласительная ссылка"); |
|
setMinimumWidth(420); |
|
setModal(true); |
|
|
|
auto *layout = new QVBoxLayout(this); |
|
layout->setSpacing(12); |
|
|
|
auto *linkEdit = new QLineEdit(m_link, this); |
|
linkEdit->setReadOnly(true); |
|
linkEdit->setStyleSheet("padding: 6px; font-family: monospace;"); |
|
layout->addWidget(linkEdit); |
|
|
|
auto *btnLayout = new QHBoxLayout(); |
|
auto *copyBtn = new QPushButton("Скопировать", this); |
|
connect(copyBtn, &QPushButton::clicked, this, [this, linkEdit]() { |
|
QClipboard* cb = QApplication::clipboard(); |
|
cb->clear(QClipboard::Clipboard); |
|
cb->setText(m_link, QClipboard::Clipboard); |
|
if (cb->supportsSelection()) { |
|
cb->clear(QClipboard::Selection); |
|
cb->setText(m_link, QClipboard::Selection); |
|
} |
|
linkEdit->setFocus(); |
|
}); |
|
btnLayout->addWidget(copyBtn); |
|
btnLayout->addStretch(); |
|
layout->addLayout(btnLayout); |
|
|
|
auto *qrLabel = new QLabel(this); |
|
QImage qrImage = generateQRCode(m_link); |
|
if (!qrImage.isNull()) |
|
qrLabel->setPixmap(QPixmap::fromImage(qrImage).scaled( |
|
180, 180, Qt::KeepAspectRatio, Qt::SmoothTransformation)); |
|
qrLabel->setAlignment(Qt::AlignCenter); |
|
layout->addWidget(qrLabel, 0, Qt::AlignCenter); |
|
|
|
auto *closeBtn = new QPushButton("OK", this); |
|
connect(closeBtn, &QPushButton::clicked, this, &QDialog::accept); |
|
layout->addWidget(closeBtn, 0, Qt::AlignRight); |
|
|
|
QTimer::singleShot(0, this, [this]() { |
|
QClipboard* cb = QApplication::clipboard(); |
|
cb->clear(QClipboard::Clipboard); |
|
cb->setText(m_link, QClipboard::Clipboard); |
|
if (cb->supportsSelection()) { |
|
cb->clear(QClipboard::Selection); |
|
cb->setText(m_link, QClipboard::Selection); |
|
} |
|
}); |
|
}
|
|
|