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

Correct formatting of preview widget fields #3727

Merged
merged 1 commit into from
Nov 9, 2019
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
59 changes: 30 additions & 29 deletions src/gui/EntryPreviewWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ EntryPreviewWidget::EntryPreviewWidget(QWidget* parent)
m_ui->entryAttachmentsWidget->setReadOnly(true);
m_ui->entryAttachmentsWidget->setButtonsVisible(false);

// Match background of read-only text edit fields with the window
m_ui->entryPasswordLabel->setBackgroundRole(QPalette::Window);
m_ui->entryUsernameLabel->setBackgroundRole(QPalette::Window);
m_ui->entryNotesTextEdit->setBackgroundRole(QPalette::Window);
m_ui->groupNotesTextEdit->setBackgroundRole(QPalette::Window);
// Align notes text with label text
m_ui->entryNotesTextEdit->document()->setDocumentMargin(0);
m_ui->groupNotesTextEdit->document()->setDocumentMargin(0);

connect(m_ui->entryUrlLabel, SIGNAL(linkActivated(QString)), SLOT(openEntryUrl()));

connect(m_ui->entryTotpButton, SIGNAL(toggled(bool)), m_ui->entryTotpLabel, SLOT(setVisible(bool)));
Expand Down Expand Up @@ -173,57 +182,49 @@ void EntryPreviewWidget::setPasswordVisible(bool state)
{
const QString password = m_currentEntry->resolveMultiplePlaceholders(m_currentEntry->password());
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(QTextEdit* notesWidget, const QString& notes, bool state)
{
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);
notesWidget->setPlainText(notes);
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);
}
}

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 +234,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 +330,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 QTextEdit;

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(QTextEdit* notesWidget, const QString& notes, bool state);

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