Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve entry preview panel #7993

Merged
merged 1 commit into from
Jun 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions share/translations/keepassxc_en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
6 changes: 3 additions & 3 deletions src/gui/DatabaseWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
37 changes: 21 additions & 16 deletions src/gui/EntryPreviewWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(); });
droidmonkey marked this conversation as resolved.
Show resolved Hide resolved
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());
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -307,47 +315,44 @@ 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
auto button = new QToolButton();
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);
Expand Down
24 changes: 7 additions & 17 deletions src/gui/EntryPreviewWidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>481</width>
<width>508</width>
<height>257</height>
</rect>
</property>
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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">
Expand Down Expand Up @@ -751,14 +738,17 @@
<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>
</property>
<property name="showDropIndicator" stdset="0">
<bool>true</bool>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::NoSelection</enum>
</property>
<property name="rootIsDecorated">
<bool>true</bool>
</property>
Expand Down Expand Up @@ -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>
Expand Down