Improve entry preview panel

* Fix #7811 - Notes height no longer truncated
* Fix #7949 - Improve copying attribute value to clipboard in entry preview
* Fix #7898 - Prevent copying url when copy password selected after clicking url in preview pane
* Fix #7982 - Double clicking hidden attributes in preview pane copies the value instead of ●●●●●●
This commit is contained in:
Jonathan White 2022-05-01 15:43:39 -04:00
parent bc0a5a9440
commit b1f4e12d34
4 changed files with 35 additions and 36 deletions

View File

@ -3890,6 +3890,10 @@ Error: %1</source>
<source>Disabled</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Double click to copy value</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>EntryURLModel</name>

View File

@ -642,19 +642,19 @@ void DatabaseWidget::copyPassword()
bool clearClipboard = config()->get(Config::Security_ClearClipboard).toBool();
auto plainTextEdit = qobject_cast<QPlainTextEdit*>(focusWidget());
if (plainTextEdit) {
if (plainTextEdit && plainTextEdit->textCursor().hasSelection()) {
clipboard()->setText(plainTextEdit->textCursor().selectedText(), clearClipboard);
return;
}
auto label = qobject_cast<QLabel*>(focusWidget());
if (label) {
if (label && label->hasSelectedText()) {
clipboard()->setText(label->selectedText(), clearClipboard);
return;
}
auto textEdit = qobject_cast<QTextEdit*>(focusWidget());
if (textEdit) {
if (textEdit && textEdit->textCursor().hasSelection()) {
clipboard()->setText(textEdit->textCursor().selectedText(), clearClipboard);
return;
}

View File

@ -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<QToolButton*>(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);

View File

@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>481</width>
<width>508</width>
<height>257</height>
</rect>
</property>
@ -195,7 +195,7 @@
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<widget class="QWidget" name="entryGeneralWidget" native="true">
<layout class="QGridLayout" name="gridLayout">
<layout class="QGridLayout" name="gridLayout" rowstretch="0,0,0,1">
<property name="leftMargin">
<number>0</number>
</property>
@ -459,19 +459,6 @@
</property>
</spacer>
</item>
<item row="4" column="0">
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="5">
<widget class="ElidedLabel" name="entryUrlLabel">
<property name="sizePolicy">
@ -751,7 +738,7 @@
<item>
<widget class="QTreeWidget" name="entryAutotypeTree">
<property name="focusPolicy">
<enum>Qt::ClickFocus</enum>
<enum>Qt::NoFocus</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
@ -759,6 +746,9 @@
<property name="showDropIndicator" stdset="0">
<bool>true</bool>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::NoSelection</enum>
</property>
<property name="rootIsDecorated">
<bool>true</bool>
</property>
@ -897,7 +887,7 @@
<layout class="QVBoxLayout" name="verticalLayout_8">
<item>
<widget class="QWidget" name="groupGeneralWidget" native="true">
<layout class="QGridLayout" name="gridLayout_2" columnstretch="0,0,0">
<layout class="QGridLayout" name="gridLayout_2" rowstretch="0,0,0,1">
<property name="leftMargin">
<number>0</number>
</property>