Try to intelligently convert \n to <p> in song/artist info views
This commit is contained in:
parent
b97b2138fa
commit
c35ba55e75
@ -87,7 +87,7 @@ void EchoNestBiographies::RequestFinished() {
|
|||||||
data.icon_ = site_icons_[canonical_site];
|
data.icon_ = site_icons_[canonical_site];
|
||||||
|
|
||||||
SongInfoTextView* editor = new SongInfoTextView;
|
SongInfoTextView* editor = new SongInfoTextView;
|
||||||
editor->setHtml(bio.text());
|
editor->SetHtml(bio.text());
|
||||||
data.contents_ = editor;
|
data.contents_ = editor;
|
||||||
|
|
||||||
emit InfoReady(request->id_, data);
|
emit InfoReady(request->id_, data);
|
||||||
|
@ -122,7 +122,7 @@ void LastfmTrackInfoProvider::GetWiki(int id, const lastfm::XmlQuery& q) {
|
|||||||
SongInfoTextView* widget = new SongInfoTextView;
|
SongInfoTextView* widget = new SongInfoTextView;
|
||||||
data.contents_ = widget;
|
data.contents_ = widget;
|
||||||
|
|
||||||
widget->setHtml(content);
|
widget->SetHtml(content);
|
||||||
|
|
||||||
emit InfoReady(id, data);
|
emit InfoReady(id, data);
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QWheelEvent>
|
#include <QWheelEvent>
|
||||||
|
#include <QtDebug>
|
||||||
|
|
||||||
const qreal SongInfoTextView::kDefaultFontSize = 8.5;
|
const qreal SongInfoTextView::kDefaultFontSize = 8.5;
|
||||||
const char* SongInfoTextView::kSettingsGroup = "SongInfo";
|
const char* SongInfoTextView::kSettingsGroup = "SongInfo";
|
||||||
@ -73,3 +74,16 @@ void SongInfoTextView::contextMenuEvent(QContextMenuEvent* e) {
|
|||||||
|
|
||||||
menu->popup(e->globalPos());
|
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);
|
||||||
|
}
|
||||||
|
@ -32,6 +32,7 @@ public:
|
|||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void ReloadSettings();
|
void ReloadSettings();
|
||||||
|
void SetHtml(const QString& html);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void ShowSettingsDialog();
|
void ShowSettingsDialog();
|
||||||
|
@ -122,7 +122,7 @@ void UltimateLyricsProvider::LyricsFetched(quint64 id, QNetworkReply* reply) {
|
|||||||
data.relevance_ = relevance();
|
data.relevance_ = relevance();
|
||||||
|
|
||||||
SongInfoTextView* editor = new SongInfoTextView;
|
SongInfoTextView* editor = new SongInfoTextView;
|
||||||
editor->setHtml(lyrics);
|
editor->SetHtml(lyrics);
|
||||||
data.contents_ = editor;
|
data.contents_ = editor;
|
||||||
|
|
||||||
emit InfoReady(id, data);
|
emit InfoReady(id, data);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user