diff --git a/share/translations/keepassxc_en.ts b/share/translations/keepassxc_en.ts index 6f625f943..4df6cef14 100644 --- a/share/translations/keepassxc_en.ts +++ b/share/translations/keepassxc_en.ts @@ -3890,6 +3890,10 @@ Error: %1 Disabled + + Double click to copy value + + EntryURLModel diff --git a/src/gui/DatabaseWidget.cpp b/src/gui/DatabaseWidget.cpp index 481040909..ebdca17bb 100644 --- a/src/gui/DatabaseWidget.cpp +++ b/src/gui/DatabaseWidget.cpp @@ -642,19 +642,19 @@ void DatabaseWidget::copyPassword() bool clearClipboard = config()->get(Config::Security_ClearClipboard).toBool(); auto plainTextEdit = qobject_cast(focusWidget()); - if (plainTextEdit) { + if (plainTextEdit && plainTextEdit->textCursor().hasSelection()) { clipboard()->setText(plainTextEdit->textCursor().selectedText(), clearClipboard); return; } auto label = qobject_cast(focusWidget()); - if (label) { + if (label && label->hasSelectedText()) { clipboard()->setText(label->selectedText(), clearClipboard); return; } auto textEdit = qobject_cast(focusWidget()); - if (textEdit) { + if (textEdit && textEdit->textCursor().hasSelection()) { clipboard()->setText(textEdit->textCursor().selectedText(), clearClipboard); return; } diff --git a/src/gui/EntryPreviewWidget.cpp b/src/gui/EntryPreviewWidget.cpp index 6fc6e1992..5fb3d3406 100644 --- a/src/gui/EntryPreviewWidget.cpp +++ b/src/gui/EntryPreviewWidget.cpp @@ -72,8 +72,17 @@ EntryPreviewWidget::EntryPreviewWidget(QWidget* parent) connect(m_ui->toggleEntryNotesButton, SIGNAL(clicked(bool)), SLOT(setEntryNotesVisible(bool))); connect(m_ui->toggleGroupNotesButton, SIGNAL(clicked(bool)), SLOT(setGroupNotesVisible(bool))); connect(m_ui->entryTabWidget, SIGNAL(tabBarClicked(int)), SLOT(updateTabIndexes()), Qt::QueuedConnection); + // Prevent the url from being focused after clicked to allow the Copy Password button to work properly + connect(m_ui->entryUrlLabel, &QLabel::linkActivated, this, [this] { m_ui->entryTabWidget->setFocus(); }); connect(&m_totpTimer, SIGNAL(timeout()), SLOT(updateTotpLabel())); + connect(m_ui->entryAttributesTable, &QTableWidget::itemDoubleClicked, this, [](QTableWidgetItem* item) { + auto userData = item->data(Qt::UserRole); + if (userData.isValid()) { + clipboard()->setText(userData.toString()); + } + }); + connect(config(), &Config::changed, this, [this](Config::ConfigKey key) { if (key == Config::GUI_HidePreviewPanel) { setVisible(!config()->get(Config::GUI_HidePreviewPanel).toBool()); @@ -256,7 +265,6 @@ void EntryPreviewWidget::updateEntryGeneralTab() auto hasNotes = !m_currentEntry->notes().isEmpty(); auto hideNotes = config()->get(Config::Security_HideNotes).toBool(); - m_ui->entryNotesTextEdit->setVisible(hasNotes); setEntryNotesVisible(hasNotes && !hideNotes); m_ui->toggleEntryNotesButton->setVisible(hasNotes && hideNotes && !m_ui->entryNotesTextEdit->toPlainText().isEmpty()); @@ -307,6 +315,8 @@ void EntryPreviewWidget::updateEntryAdvancedTab() font.setBold(true); for (const QString& key : customAttributes) { m_ui->entryAttributesTable->setItem(i, 0, new QTableWidgetItem(key)); + m_ui->entryAttributesTable->item(i, 0)->setFont(font); + m_ui->entryAttributesTable->item(i, 0)->setTextAlignment(Qt::AlignTop | Qt::AlignLeft); if (attributes->isProtected(key)) { // only show the reveal button on protected attributes @@ -314,40 +324,35 @@ void EntryPreviewWidget::updateEntryAdvancedTab() button->setCheckable(true); button->setChecked(false); button->setIcon(icons()->onOffIcon("password-show", false)); - button->setProperty("value", attributes->value(key)); button->setProperty("row", i); - m_ui->entryAttributesTable->setCellWidget(i, 1, button); - m_ui->entryAttributesTable->setItem(i, 2, new QTableWidgetItem(QString("\u25cf").repeated(6))); - + button->setIconSize({12, 12}); connect(button, &QToolButton::clicked, this, [this](bool state) { auto btn = qobject_cast(sender()); btn->setIcon(icons()->onOffIcon("password-show", state)); - auto row = btn->property("row").toInt(); + auto item = m_ui->entryAttributesTable->item(btn->property("row").toInt(), 2); if (state) { - m_ui->entryAttributesTable->item(row, 2)->setText(btn->property("value").toString()); + item->setText(item->data(Qt::UserRole).toString()); } else { - m_ui->entryAttributesTable->item(row, 2)->setText(QString("\u25cf").repeated(6)); + item->setText(QString("\u25cf").repeated(6)); } // Maintain button height while showing contents of cell auto size = btn->size(); - m_ui->entryAttributesTable->resizeRowToContents(row); + m_ui->entryAttributesTable->resizeRowToContents(item->row()); btn->setFixedSize(size); }); + + m_ui->entryAttributesTable->setCellWidget(i, 1, button); + m_ui->entryAttributesTable->setItem(i, 2, new QTableWidgetItem(QString("\u25cf").repeated(6))); } else { m_ui->entryAttributesTable->setItem(i, 2, new QTableWidgetItem(attributes->value(key))); } - m_ui->entryAttributesTable->item(i, 0)->setFont(font); - m_ui->entryAttributesTable->item(i, 0)->setTextAlignment(Qt::AlignTop | Qt::AlignLeft); + m_ui->entryAttributesTable->item(i, 2)->setData(Qt::UserRole, attributes->value(key)); + m_ui->entryAttributesTable->item(i, 2)->setToolTip(tr("Double click to copy value")); m_ui->entryAttributesTable->item(i, 2)->setTextAlignment(Qt::AlignTop | Qt::AlignLeft); ++i; } - connect(m_ui->entryAttributesTable, &QTableWidget::cellDoubleClicked, this, [this](int row, int column) { - if (column == 2) { - clipboard()->setText(m_ui->entryAttributesTable->item(row, column)->text()); - } - }); } m_ui->entryAttributesTable->horizontalHeader()->setStretchLastSection(true); diff --git a/src/gui/EntryPreviewWidget.ui b/src/gui/EntryPreviewWidget.ui index d97b23ab3..df7196a27 100644 --- a/src/gui/EntryPreviewWidget.ui +++ b/src/gui/EntryPreviewWidget.ui @@ -6,7 +6,7 @@ 0 0 - 481 + 508 257 @@ -195,7 +195,7 @@ - + 0 @@ -459,19 +459,6 @@ - - - - Qt::Vertical - - - - 20 - 40 - - - - @@ -751,7 +738,7 @@ - Qt::ClickFocus + Qt::NoFocus QFrame::Sunken @@ -759,6 +746,9 @@ true + + QAbstractItemView::NoSelection + true @@ -897,7 +887,7 @@ - + 0