From dd2dcc4147256746e71e05cfbfd83d148238abaa Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Mon, 7 Mar 2016 12:22:18 +0800 Subject: [PATCH] Fix additional space in comment label --- src/gui/addnewtorrentdialog.cpp | 15 +++++++++++++-- src/gui/addnewtorrentdialog.h | 1 + src/gui/addnewtorrentdialog.ui | 2 +- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/gui/addnewtorrentdialog.cpp b/src/gui/addnewtorrentdialog.cpp index caa757144..e61557b62 100644 --- a/src/gui/addnewtorrentdialog.cpp +++ b/src/gui/addnewtorrentdialog.cpp @@ -689,7 +689,7 @@ void AddNewTorrentDialog::setMetadataProgressIndicator(bool visibleIndicator, co void AddNewTorrentDialog::setupTreeview() { if (!m_hasMetadata) { - ui->comment_lbl->setText(tr("Not Available", "This comment is unavailable")); + setCommentText(tr("Not Available", "This comment is unavailable")); ui->date_lbl->setText(tr("Not Available", "This date is unavailable")); } else { @@ -697,7 +697,7 @@ void AddNewTorrentDialog::setupTreeview() setWindowTitle(m_torrentInfo.name()); // Set torrent information - ui->comment_lbl->setText(Utils::Misc::parseHtmlLinks(m_torrentInfo.comment())); + setCommentText(Utils::Misc::parseHtmlLinks(m_torrentInfo.comment())); ui->date_lbl->setText(!m_torrentInfo.creationDate().isNull() ? m_torrentInfo.creationDate().toString(Qt::DefaultLocaleShortDate) : tr("Not available")); // Prepare content tree @@ -777,3 +777,14 @@ void AddNewTorrentDialog::savingModeChanged(bool enabled) ui->defaultSavePathCheckBox->setVisible(false); } } + +void AddNewTorrentDialog::setCommentText(const QString &str) const +{ + ui->commentLabel->setText(str); + + // workaround for the additional space introduced by QScrollArea + int lineHeight = ui->commentLabel->fontMetrics().lineSpacing(); + int lines = 1 + str.count("\n"); + int height = lineHeight * lines; + ui->scrollArea->setMaximumHeight(height); +} diff --git a/src/gui/addnewtorrentdialog.h b/src/gui/addnewtorrentdialog.h index a67f239f5..f7fb9383d 100644 --- a/src/gui/addnewtorrentdialog.h +++ b/src/gui/addnewtorrentdialog.h @@ -95,6 +95,7 @@ private: void setMetadataProgressIndicator(bool visibleIndicator, const QString &labelText = QString()); void setupTreeview(); QString defaultSavePath() const; + void setCommentText(const QString &str) const; void showEvent(QShowEvent *event) override; diff --git a/src/gui/addnewtorrentdialog.ui b/src/gui/addnewtorrentdialog.ui index 78f27f9e5..8c15a435d 100644 --- a/src/gui/addnewtorrentdialog.ui +++ b/src/gui/addnewtorrentdialog.ui @@ -287,7 +287,7 @@ 0 - + Qt::RichText