diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -372,12 +373,12 @@ } else if (!Settings::isDisplayAsIs()) { if (!password.isEmpty()) { // set the password, it is hidden if needed in addToGridLayout - addToGridLayout(i18n("Password"), password); + addToGridLayout(i18n("Password:"), password); } const NamedValues namedValues = fileContent.getNamedValues(); for (const auto& nv : namedValues) { - addToGridLayout(nv.name, nv.value); + addToGridLayout(i18nc("Field label", "%1:", nv.name), nv.value); } output = fileContent.getRemainingDataForDisplay(); @@ -906,18 +907,42 @@ QString trimmedValue = value.trimmed(); // Combine the Copy button and the line edit in one widget - QFrame *frame = new QFrame(); - QLayout *ly = new QHBoxLayout(); - ly->setContentsMargins(5, 2, 2, 2); - ly->setSpacing(0); - frame->setLayout(ly); - auto fieldLabel = createPushButton(QIcon::fromTheme(QStringLiteral("edit-copy")), i18n("Copy '%1' to clipboard", trimmedField), m_clipboardHelper, [this, trimmedValue] { + auto rowLayout = new QHBoxLayout(); + rowLayout->setContentsMargins(0, 2, 0, 2); + + if (trimmedField == i18n("Password:")) { + auto *line = new KPasswordLineEdit(); + line->setRevealPasswordMode(KPassword::RevealMode::Always); + line->setObjectName(trimmedField); + line->setPassword(trimmedValue); + line->setReadOnly(true); + line->setContentsMargins(0, 0, 0, 0); + line->setEchoMode(QLineEdit::Password); + auto icon = QIcon::fromTheme(QStringLiteral("password-show-on")); + icon.addFile(QStringLiteral("password-show-off"), QSize(), QIcon::Normal, QIcon::Off); + rowLayout->addWidget(line); + } else { + auto *line = new QLabel(); + line->setOpenExternalLinks(true); + line->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::LinksAccessibleByMouse | Qt::LinksAccessibleByKeyboard); + line->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum)); + line->setObjectName(trimmedField); + trimmedValue.replace(Util::protocolRegex(), QStringLiteral(R"(\1)")); + line->setText(trimmedValue); + line->setContentsMargins(5, 0, 0, 0); + rowLayout->addWidget(line); + } + + auto fieldName = trimmedField; + fieldName.removeLast(); // remove ':' from the end of the label + + auto fieldLabel = createPushButton(QIcon::fromTheme(QStringLiteral("edit-copy")), i18n("Copy '%1' to clipboard", fieldName), m_clipboardHelper, [this, trimmedValue] { m_clipboardHelper->copyTextToClipboard(trimmedValue); }); - frame->layout()->addWidget(fieldLabel.release()); + rowLayout->addWidget(fieldLabel.release()); - auto qrButton = createPushButton(QIcon::fromTheme(QStringLiteral("view-barcode-qr")), i18n("View '%1' QR Code", trimmedField), m_clipboardHelper, [this, trimmedValue]() { + auto qrButton = createPushButton(QIcon::fromTheme(QStringLiteral("view-barcode-qr")), i18n("View '%1' QR Code", fieldName), m_clipboardHelper, [this, trimmedValue]() { auto barcode = Prison::Barcode::create(Prison::QRCode); if (!barcode) { return; @@ -936,42 +961,10 @@ popup.move(QCursor::pos()); popup.exec(); }); - frame->layout()->addWidget(qrButton.release()); - - if (trimmedField == i18n("Password")) { - auto *line = new QLineEdit(); - line->setObjectName(trimmedField); - line->setText(trimmedValue); - line->setReadOnly(true); - line->setContentsMargins(0, 0, 0, 0); - line->setEchoMode(QLineEdit::Password); - auto icon = QIcon::fromTheme(QStringLiteral("password-show-on")); - icon.addFile(QStringLiteral("password-show-off"), QSize(), QIcon::Normal, QIcon::Off); - auto showButton = createPushButton(icon, i18n("Toggle password visibility"), line, [line]() { - if (line->echoMode() == QLineEdit::Password) { - line->setEchoMode(QLineEdit::Normal); - } else { - line->setEchoMode(QLineEdit::Password); - } - }); - showButton->setCheckable(true); - showButton->setContentsMargins(0, 0, 0, 0); - frame->layout()->addWidget(showButton.release()); - frame->layout()->addWidget(line); - } else { - auto *line = new QLabel(); - line->setOpenExternalLinks(true); - line->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::LinksAccessibleByMouse | Qt::LinksAccessibleByKeyboard); - line->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum)); - line->setObjectName(trimmedField); - trimmedValue.replace(Util::protocolRegex(), QStringLiteral(R"(\1)")); - line->setText(trimmedValue); - line->setContentsMargins(5, 0, 0, 0); - frame->layout()->addWidget(line); - } + rowLayout->addWidget(qrButton.release()); // set into the layout - ui->contentLayout->addRow(trimmedField, frame); + ui->contentLayout->addRow(trimmedField, rowLayout); } /**