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.
  • Loading branch information
droidmonkey committed Oct 30, 2019
1 parent 178bea6 commit 2ed5879
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 55 deletions.
35 changes: 19 additions & 16 deletions src/gui/EntryPreviewWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,28 +189,31 @@ void EntryPreviewWidget::setPasswordVisible(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)
{
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);
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);
}
}

Expand All @@ -233,17 +236,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 +332,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
67 changes: 29 additions & 38 deletions src/gui/EntryPreviewWidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -486,36 +486,27 @@
</widget>
</item>
<item>
<widget class="QLabel" name="entryNotesLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
<widget class="QPlainTextEdit" name="entryNotesTextEdit">
<property name="focusPolicy">
<enum>Qt::ClickFocus</enum>
</property>
<property name="minimumSize">
<size>
<width>100</width>
<height>30</height>
</size>
</property>
<property name="text">
<string notr="true">notes</string>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="textFormat">
<enum>Qt::RichText</enum>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="alignment">
<set>Qt::AlignTop</set>
</property>
<property name="wordWrap">
<property name="tabChangesFocus">
<bool>true</bool>
</property>
<property name="openExternalLinks">
<property name="undoRedoEnabled">
<bool>false</bool>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
<property name="textInteractionFlags">
<set>Qt::NoTextInteraction</set>
<set>Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse|Qt::TextBrowserInteraction|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>
Expand Down Expand Up @@ -1003,28 +994,28 @@
</widget>
</item>
<item>
<widget class="QLabel" name="groupNotesLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
<widget class="QPlainTextEdit" name="groupNotesTextEdit">
<property name="focusPolicy">
<enum>Qt::ClickFocus</enum>
</property>
<property name="minimumSize">
<size>
<width>100</width>
<height>30</height>
</size>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="text">
<string notr="true">notes</string>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="tabChangesFocus">
<bool>true</bool>
</property>
<property name="alignment">
<set>Qt::AlignTop</set>
<property name="undoRedoEnabled">
<bool>false</bool>
</property>
<property name="wordWrap">
<property name="readOnly">
<bool>true</bool>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse|Qt::TextBrowserInteraction|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>
</layout>
Expand Down

0 comments on commit 2ed5879

Please sign in to comment.