Correct formatting of preview widget fields (#3727)

* Fix #3701 - replace QLabel with QTextEdit to enable scrolling of notes

* Notes are plain text. They will remain as plain text and hyperlinks will not be enabled in the notes. Until the notes editor is moved to a rich text / html editor this will remain the case.

* Convert username and password fields in preview pane to QLineEdit's to allow for full copying and viewing if larger than the field width.
This commit is contained in:
Jonathan White 2019-11-09 12:16:05 -05:00 committed by Janek Bevendorff
parent 29ca08f9ff
commit a07bae2530
3 changed files with 243 additions and 243 deletions

View File

@ -58,6 +58,15 @@ EntryPreviewWidget::EntryPreviewWidget(QWidget* parent)
m_ui->entryAttachmentsWidget->setReadOnly(true); m_ui->entryAttachmentsWidget->setReadOnly(true);
m_ui->entryAttachmentsWidget->setButtonsVisible(false); 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->entryUrlLabel, SIGNAL(linkActivated(QString)), SLOT(openEntryUrl()));
connect(m_ui->entryTotpButton, SIGNAL(toggled(bool)), m_ui->entryTotpLabel, SLOT(setVisible(bool))); connect(m_ui->entryTotpButton, SIGNAL(toggled(bool)), m_ui->entryTotpLabel, SLOT(setVisible(bool)));
@ -173,44 +182,35 @@ void EntryPreviewWidget::setPasswordVisible(bool state)
{ {
const QString password = m_currentEntry->resolveMultiplePlaceholders(m_currentEntry->password()); const QString password = m_currentEntry->resolveMultiplePlaceholders(m_currentEntry->password());
if (state) { if (state) {
m_ui->entryPasswordLabel->setRawText(password); m_ui->entryPasswordLabel->setText(password);
m_ui->entryPasswordLabel->setToolTip(password); m_ui->entryPasswordLabel->setCursorPosition(0);
m_ui->entryPasswordLabel->setTextInteractionFlags(Qt::TextSelectableByMouse); } else if (password.isEmpty() && config()->get("security/passwordemptynodots").toBool()) {
m_ui->entryPasswordLabel->setText("");
} else { } else {
m_ui->entryPasswordLabel->setTextInteractionFlags(Qt::NoTextInteraction); m_ui->entryPasswordLabel->setText(QString("\u25cf").repeated(6));
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));
}
} }
} }
void EntryPreviewWidget::setEntryNotesVisible(bool state) 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) 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) { if (state) {
// Add html hyperlinks to notes that start with XXXX:// notesWidget->setPlainText(notes);
QString hyperlinkNotes = notes; notesWidget->moveCursor(QTextCursor::Start);
notesLabel->setText(hyperlinkNotes.replace(QRegExp("(\\w+:\\/\\/\\S+)"), "<a href=\"\\1\">\\1</a>")); notesWidget->ensureCursorVisible();
notesLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
} else { } else {
if (notes.isEmpty()) { if (!notes.isEmpty()) {
notesLabel->setText(""); notesWidget->setPlainText(QString("\u25cf").repeated(6));
} else {
notesLabel->setText(QString("\u25cf").repeated(6));
} }
notesLabel->setTextInteractionFlags(Qt::NoTextInteraction);
} }
} }
@ -218,12 +218,13 @@ void EntryPreviewWidget::updateEntryGeneralTab()
{ {
Q_ASSERT(m_currentEntry); Q_ASSERT(m_currentEntry);
m_ui->entryUsernameLabel->setText(m_currentEntry->resolveMultiplePlaceholders(m_currentEntry->username())); m_ui->entryUsernameLabel->setText(m_currentEntry->resolveMultiplePlaceholders(m_currentEntry->username()));
m_ui->entryUsernameLabel->setCursorPosition(0);
if (config()->get("security/HidePasswordPreviewPanel").toBool()) { if (config()->get("security/HidePasswordPreviewPanel").toBool()) {
// Hide password // Hide password
setPasswordVisible(false); setPasswordVisible(false);
// Show the password toggle button if there are dots in the label // 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); m_ui->togglePasswordButton->setChecked(false);
} else { } else {
// Show password // Show password
@ -233,7 +234,7 @@ void EntryPreviewWidget::updateEntryGeneralTab()
if (config()->get("security/hidenotes").toBool()) { if (config()->get("security/hidenotes").toBool()) {
setEntryNotesVisible(false); 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); m_ui->toggleEntryNotesButton->setChecked(false);
} else { } else {
setEntryNotesVisible(true); setEntryNotesVisible(true);
@ -241,9 +242,9 @@ void EntryPreviewWidget::updateEntryGeneralTab()
} }
if (config()->get("GUI/MonospaceNotes", false).toBool()) { if (config()->get("GUI/MonospaceNotes", false).toBool()) {
m_ui->entryNotesLabel->setFont(Font::fixedFont()); m_ui->entryNotesTextEdit->setFont(Font::fixedFont());
} else { } else {
m_ui->entryNotesLabel->setFont(Font::defaultFont()); m_ui->entryNotesTextEdit->setFont(Font::defaultFont());
} }
m_ui->entryUrlLabel->setRawText(m_currentEntry->displayUrl()); m_ui->entryUrlLabel->setRawText(m_currentEntry->displayUrl());
@ -329,7 +330,7 @@ void EntryPreviewWidget::updateGroupGeneralTab()
if (config()->get("security/hidenotes").toBool()) { if (config()->get("security/hidenotes").toBool()) {
setGroupNotesVisible(false); 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); m_ui->toggleGroupNotesButton->setChecked(false);
} else { } else {
setGroupNotesVisible(true); setGroupNotesVisible(true);
@ -337,9 +338,9 @@ void EntryPreviewWidget::updateGroupGeneralTab()
} }
if (config()->get("GUI/MonospaceNotes", false).toBool()) { if (config()->get("GUI/MonospaceNotes", false).toBool()) {
m_ui->groupNotesLabel->setFont(Font::fixedFont()); m_ui->groupNotesTextEdit->setFont(Font::fixedFont());
} else { } else {
m_ui->groupNotesLabel->setFont(Font::defaultFont()); m_ui->groupNotesTextEdit->setFont(Font::defaultFont());
} }
} }

View File

@ -28,6 +28,8 @@ namespace Ui
class EntryPreviewWidget; class EntryPreviewWidget;
} }
class QTextEdit;
class EntryPreviewWidget : public QWidget class EntryPreviewWidget : public QWidget
{ {
Q_OBJECT Q_OBJECT
@ -54,7 +56,7 @@ private slots:
void setPasswordVisible(bool state); void setPasswordVisible(bool state);
void setEntryNotesVisible(bool state); void setEntryNotesVisible(bool state);
void setGroupNotesVisible(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 updateGroupHeaderLine();
void updateGroupGeneralTab(); void updateGroupGeneralTab();

View File

@ -159,7 +159,7 @@
<layout class="QVBoxLayout" name="verticalLayout_5"> <layout class="QVBoxLayout" name="verticalLayout_5">
<item> <item>
<widget class="QWidget" name="entryGeneralWidget" native="true"> <widget class="QWidget" name="entryGeneralWidget" native="true">
<layout class="QGridLayout" name="gridLayout" rowstretch="0,0,0" columnstretch="0,0,0,2,0,0,3"> <layout class="QGridLayout" name="gridLayout">
<property name="leftMargin"> <property name="leftMargin">
<number>0</number> <number>0</number>
</property> </property>
@ -172,151 +172,6 @@
<property name="bottomMargin"> <property name="bottomMargin">
<number>0</number> <number>0</number>
</property> </property>
<item row="0" column="0">
<spacer name="entryLeftHorizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="1">
<widget class="QLabel" name="entryUsernameTitleLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="text">
<string>Username</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QLabel" name="entryUsernameLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>100</width>
<height>0</height>
</size>
</property>
<property name="text">
<string notr="true">username</string>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>
<item row="0" column="4">
<spacer name="entryMiddleHorizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>10</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="5">
<widget class="QLabel" name="entryUrlTitleLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>URL</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="6">
<widget class="ElidedLabel" name="entryUrlLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>100</width>
<height>0</height>
</size>
</property>
<property name="cursor">
<cursorShape>PointingHandCursor</cursorShape>
</property>
<property name="focusPolicy">
<enum>Qt::ClickFocus</enum>
</property>
<property name="text">
<string notr="true">https://example.com</string>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse</set>
</property>
</widget>
</item>
<item row="1" column="0">
<spacer name="entryLeftHorizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>30</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="1"> <item row="1" column="1">
<widget class="QLabel" name="entryPasswordTitleLabel"> <widget class="QLabel" name="entryPasswordTitleLabel">
<property name="sizePolicy"> <property name="sizePolicy">
@ -339,6 +194,22 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="0">
<spacer name="entryLeftHorizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="2" colspan="2"> <item row="1" column="2" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_2" stretch="0,0"> <layout class="QHBoxLayout" name="horizontalLayout_2" stretch="0,0">
<property name="spacing"> <property name="spacing">
@ -358,28 +229,34 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="ElidedLabel" name="entryPasswordLabel"> <widget class="QLineEdit" name="entryPasswordLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>100</width> <width>150</width>
<height>0</height> <height>0</height>
</size> </size>
</property> </property>
<property name="focusPolicy">
<enum>Qt::ClickFocus</enum>
</property>
<property name="text"> <property name="text">
<string notr="true">password</string> <string notr="true">password</string>
</property> </property>
<property name="frame">
<bool>false</bool>
</property>
<property name="dragEnabled">
<bool>true</bool>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget> </widget>
</item> </item>
</layout> </layout>
</item> </item>
<item row="1" column="4"> <item row="0" column="4">
<spacer name="entryMiddleHorizontalSpacer_3"> <spacer name="entryMiddleHorizontalSpacer">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
@ -394,6 +271,56 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="0" column="6">
<widget class="ElidedLabel" name="entryUrlLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>150</width>
<height>0</height>
</size>
</property>
<property name="cursor">
<cursorShape>PointingHandCursor</cursorShape>
</property>
<property name="focusPolicy">
<enum>Qt::ClickFocus</enum>
</property>
<property name="text">
<string notr="true">https://example.com</string>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse</set>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="entryNotesTitleLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Notes</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTop|Qt::AlignTrailing</set>
</property>
</widget>
</item>
<item row="1" column="5"> <item row="1" column="5">
<widget class="QLabel" name="entryExpirationTitleLabel"> <widget class="QLabel" name="entryExpirationTitleLabel">
<property name="sizePolicy"> <property name="sizePolicy">
@ -445,27 +372,21 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="2" column="1"> <item row="1" column="0">
<widget class="QLabel" name="entryNotesTitleLabel"> <spacer name="entryLeftHorizontalSpacer_2">
<property name="sizePolicy"> <property name="orientation">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred"> <enum>Qt::Horizontal</enum>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property> </property>
<property name="font"> <property name="sizeType">
<font> <enum>QSizePolicy::Fixed</enum>
<weight>75</weight>
<bold>true</bold>
</font>
</property> </property>
<property name="text"> <property name="sizeHint" stdset="0">
<string>Notes</string> <size>
<width>20</width>
<height>30</height>
</size>
</property> </property>
<property name="alignment"> </spacer>
<set>Qt::AlignRight|Qt::AlignTop|Qt::AlignTrailing</set>
</property>
</widget>
</item> </item>
<item row="2" column="2" colspan="5"> <item row="2" column="2" colspan="5">
<layout class="QHBoxLayout" name="horizontalLayout_3" stretch="0,0"> <layout class="QHBoxLayout" name="horizontalLayout_3" stretch="0,0">
@ -486,41 +407,120 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLabel" name="entryNotesLabel"> <widget class="QTextEdit" name="entryNotesTextEdit">
<property name="sizePolicy"> <property name="focusPolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding"> <enum>Qt::ClickFocus</enum>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property> </property>
<property name="minimumSize"> <property name="frameShape">
<size> <enum>QFrame::NoFrame</enum>
<width>100</width>
<height>30</height>
</size>
</property> </property>
<property name="text"> <property name="frameShadow">
<string notr="true">notes</string> <enum>QFrame::Plain</enum>
</property> </property>
<property name="textFormat"> <property name="lineWidth">
<enum>Qt::RichText</enum> <number>0</number>
</property> </property>
<property name="alignment"> <property name="tabChangesFocus">
<set>Qt::AlignTop</set>
</property>
<property name="wordWrap">
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="openExternalLinks"> <property name="readOnly">
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="textInteractionFlags">
<set>Qt::NoTextInteraction</set>
</property>
</widget> </widget>
</item> </item>
</layout> </layout>
</item> </item>
<item row="0" column="1">
<widget class="QLabel" name="entryUsernameTitleLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="text">
<string>Username</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="4">
<spacer name="entryMiddleHorizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>10</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="5">
<widget class="QLabel" name="entryUrlTitleLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>URL</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLineEdit" name="entryUsernameLabel">
<property name="minimumSize">
<size>
<width>150</width>
<height>0</height>
</size>
</property>
<property name="focusPolicy">
<enum>Qt::ClickFocus</enum>
</property>
<property name="text">
<string notr="true">username</string>
</property>
<property name="frame">
<bool>false</bool>
</property>
<property name="cursorPosition">
<number>8</number>
</property>
<property name="dragEnabled">
<bool>true</bool>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>
@ -1003,26 +1003,23 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLabel" name="groupNotesLabel"> <widget class="QTextEdit" name="groupNotesTextEdit">
<property name="sizePolicy"> <property name="focusPolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding"> <enum>Qt::ClickFocus</enum>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property> </property>
<property name="minimumSize"> <property name="frameShape">
<size> <enum>QFrame::NoFrame</enum>
<width>100</width>
<height>30</height>
</size>
</property> </property>
<property name="text"> <property name="frameShadow">
<string notr="true">notes</string> <enum>QFrame::Plain</enum>
</property> </property>
<property name="alignment"> <property name="lineWidth">
<set>Qt::AlignTop</set> <number>0</number>
</property> </property>
<property name="wordWrap"> <property name="tabChangesFocus">
<bool>true</bool>
</property>
<property name="readOnly">
<bool>true</bool> <bool>true</bool>
</property> </property>
</widget> </widget>