Try to intelligently convert \n to <p> in song/artist info views

This commit is contained in:
David Sansome 2010-10-16 16:16:22 +00:00
parent b97b2138fa
commit c35ba55e75
5 changed files with 18 additions and 3 deletions

View File

@ -87,7 +87,7 @@ void EchoNestBiographies::RequestFinished() {
data.icon_ = site_icons_[canonical_site];
SongInfoTextView* editor = new SongInfoTextView;
editor->setHtml(bio.text());
editor->SetHtml(bio.text());
data.contents_ = editor;
emit InfoReady(request->id_, data);

View File

@ -122,7 +122,7 @@ void LastfmTrackInfoProvider::GetWiki(int id, const lastfm::XmlQuery& q) {
SongInfoTextView* widget = new SongInfoTextView;
data.contents_ = widget;
widget->setHtml(content);
widget->SetHtml(content);
emit InfoReady(id, data);
}

View File

@ -20,6 +20,7 @@
#include <QMenu>
#include <QSettings>
#include <QWheelEvent>
#include <QtDebug>
const qreal SongInfoTextView::kDefaultFontSize = 8.5;
const char* SongInfoTextView::kSettingsGroup = "SongInfo";
@ -73,3 +74,16 @@ void SongInfoTextView::contextMenuEvent(QContextMenuEvent* e) {
menu->popup(e->globalPos());
}
void SongInfoTextView::SetHtml(const QString& html) {
QString copy(html.trimmed());
// Simplify newlines, and convert them to <p>
copy.replace(QRegExp("[\\r\\n]+"), "\n");
copy.replace(QRegExp("([^>])[\\t ]*\\n"), "\\1<p>");
// Strip any newlines from the end
copy.replace(QRegExp("((<\\s*br\\s*/?\\s*>)|(<\\s*/?\\s*p\\s*/?\\s*>))+$"), "");
setHtml(copy);
}

View File

@ -32,6 +32,7 @@ public:
public slots:
void ReloadSettings();
void SetHtml(const QString& html);
signals:
void ShowSettingsDialog();

View File

@ -122,7 +122,7 @@ void UltimateLyricsProvider::LyricsFetched(quint64 id, QNetworkReply* reply) {
data.relevance_ = relevance();
SongInfoTextView* editor = new SongInfoTextView;
editor->setHtml(lyrics);
editor->SetHtml(lyrics);
data.contents_ = editor;
emit InfoReady(id, data);