Skip to content

Commit

Permalink
Correct formatting of entry and group notes in preview widget
Browse files Browse the repository at this point in the history
* Fix #3701 - replace QLabel with QPlainText to enable scrolling of notes

* Convert newlines to HTML breaks to ensure visible when displaying HTML content. This is necessary to also allow clickable links.

* Convert username and password fields in preview pane to QLineEdit's to allow for full copying and viewing if larger than the field width.
  • Loading branch information
droidmonkey committed Nov 9, 2019
1 parent f9d2696 commit a30c7a0
Show file tree
Hide file tree
Showing 3 changed files with 245 additions and 219 deletions.
56 changes: 28 additions & 28 deletions src/gui/EntryPreviewWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,58 +172,58 @@ void EntryPreviewWidget::updateEntryTotp()
void EntryPreviewWidget::setPasswordVisible(bool state)
{
const QString password = m_currentEntry->resolveMultiplePlaceholders(m_currentEntry->password());
m_ui->entryPasswordLabel->setEnabled(state);
if (state) {
m_ui->entryPasswordLabel->setRawText(password);
m_ui->entryPasswordLabel->setToolTip(password);
m_ui->entryPasswordLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
m_ui->entryPasswordLabel->setText(password);
m_ui->entryPasswordLabel->setCursorPosition(0);
} else if (password.isEmpty() && config()->get("security/passwordemptynodots").toBool()) {
m_ui->entryPasswordLabel->setText("");
} else {
m_ui->entryPasswordLabel->setTextInteractionFlags(Qt::NoTextInteraction);
m_ui->entryPasswordLabel->setToolTip({});
if (password.isEmpty() && config()->get("security/passwordemptynodots").toBool()) {
m_ui->entryPasswordLabel->setRawText("");
} else {
m_ui->entryPasswordLabel->setRawText(QString("\u25cf").repeated(6));
}
m_ui->entryPasswordLabel->setText(QString("\u25cf").repeated(6));
}
}

void EntryPreviewWidget::setEntryNotesVisible(bool state)
{
setNotesVisible(m_ui->entryNotesLabel, m_currentEntry->notes(), state);
setNotesVisible(m_ui->entryNotesTextEdit, m_currentEntry->notes(), state);
}

void EntryPreviewWidget::setGroupNotesVisible(bool state)
{
setNotesVisible(m_ui->groupNotesLabel, m_currentGroup->notes(), state);
setNotesVisible(m_ui->groupNotesTextEdit, m_currentGroup->notes(), state);
}

void EntryPreviewWidget::setNotesVisible(QLabel* notesLabel, const QString& notes, bool state)
void EntryPreviewWidget::setNotesVisible(QPlainTextEdit* notesWidget, const QString& notes, bool state)
{
notesWidget->clear();

if (state) {
// Add html hyperlinks to notes that start with XXXX://
QString hyperlinkNotes = notes;
notesLabel->setText(hyperlinkNotes.replace(QRegExp("(\\w+:\\/\\/\\S+)"), "<a href=\"\\1\">\\1</a>"));
notesLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
QString hyperlinkNotes = notes.toHtmlEscaped();
hyperlinkNotes.replace("\n", "<br/>");
notesWidget->appendHtml(hyperlinkNotes.replace(QRegExp("(\\w+:\\/\\/\\S+)"), "<a href=\"\\1\">\\1</a>"));
notesWidget->setTextInteractionFlags(Qt::TextBrowserInteraction);
notesWidget->moveCursor(QTextCursor::Start);
notesWidget->ensureCursorVisible();
} else {
if (notes.isEmpty()) {
notesLabel->setText("");
} else {
notesLabel->setText(QString("\u25cf").repeated(6));
if (!notes.isEmpty()) {
notesWidget->setPlainText(QString("\u25cf").repeated(6));
}
notesLabel->setTextInteractionFlags(Qt::NoTextInteraction);
notesWidget->setTextInteractionFlags(Qt::NoTextInteraction);
}
}

void EntryPreviewWidget::updateEntryGeneralTab()
{
Q_ASSERT(m_currentEntry);
m_ui->entryUsernameLabel->setText(m_currentEntry->resolveMultiplePlaceholders(m_currentEntry->username()));
m_ui->entryUsernameLabel->setCursorPosition(0);

if (config()->get("security/HidePasswordPreviewPanel").toBool()) {
// Hide password
setPasswordVisible(false);
// Show the password toggle button if there are dots in the label
m_ui->togglePasswordButton->setVisible(!m_ui->entryPasswordLabel->rawText().isEmpty());
m_ui->togglePasswordButton->setVisible(!m_ui->entryPasswordLabel->text().isEmpty());
m_ui->togglePasswordButton->setChecked(false);
} else {
// Show password
Expand All @@ -233,17 +233,17 @@ void EntryPreviewWidget::updateEntryGeneralTab()

if (config()->get("security/hidenotes").toBool()) {
setEntryNotesVisible(false);
m_ui->toggleEntryNotesButton->setVisible(!m_ui->entryNotesLabel->text().isEmpty());
m_ui->toggleEntryNotesButton->setVisible(!m_ui->entryNotesTextEdit->toPlainText().isEmpty());
m_ui->toggleEntryNotesButton->setChecked(false);
} else {
setEntryNotesVisible(true);
m_ui->toggleEntryNotesButton->setVisible(false);
}

if (config()->get("GUI/MonospaceNotes", false).toBool()) {
m_ui->entryNotesLabel->setFont(Font::fixedFont());
m_ui->entryNotesTextEdit->setFont(Font::fixedFont());
} else {
m_ui->entryNotesLabel->setFont(Font::defaultFont());
m_ui->entryNotesTextEdit->setFont(Font::defaultFont());
}

m_ui->entryUrlLabel->setRawText(m_currentEntry->displayUrl());
Expand Down Expand Up @@ -329,17 +329,17 @@ void EntryPreviewWidget::updateGroupGeneralTab()

if (config()->get("security/hidenotes").toBool()) {
setGroupNotesVisible(false);
m_ui->toggleGroupNotesButton->setVisible(!m_ui->groupNotesLabel->text().isEmpty());
m_ui->toggleGroupNotesButton->setVisible(!m_ui->groupNotesTextEdit->toPlainText().isEmpty());
m_ui->toggleGroupNotesButton->setChecked(false);
} else {
setGroupNotesVisible(true);
m_ui->toggleGroupNotesButton->setVisible(false);
}

if (config()->get("GUI/MonospaceNotes", false).toBool()) {
m_ui->groupNotesLabel->setFont(Font::fixedFont());
m_ui->groupNotesTextEdit->setFont(Font::fixedFont());
} else {
m_ui->groupNotesLabel->setFont(Font::defaultFont());
m_ui->groupNotesTextEdit->setFont(Font::defaultFont());
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/gui/EntryPreviewWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ namespace Ui
class EntryPreviewWidget;
}

class QPlainTextEdit;

class EntryPreviewWidget : public QWidget
{
Q_OBJECT
Expand All @@ -54,7 +56,7 @@ private slots:
void setPasswordVisible(bool state);
void setEntryNotesVisible(bool state);
void setGroupNotesVisible(bool state);
void setNotesVisible(QLabel* notesLabel, const QString& notes, bool state);
void setNotesVisible(QPlainTextEdit* notesWidget, const QString& notes, bool state);

void updateGroupHeaderLine();
void updateGroupGeneralTab();
Expand Down
Loading

0 comments on commit a30c7a0

Please sign in to comment.