Show sub-text in search results
This commit is contained in:
committed by
craig.p.drummond
parent
0c47aa9d3e
commit
559ed9a64d
@@ -126,7 +126,7 @@ QVariant StreamSearchModel::data(const QModelIndex &index, int role) const
|
||||
#endif
|
||||
}
|
||||
} else {
|
||||
return QLatin1String("-");
|
||||
return item->subText.isEmpty() ? QLatin1String("-") : item->subText;
|
||||
}
|
||||
break;
|
||||
case ItemView::Role_Actions:
|
||||
@@ -291,7 +291,7 @@ void StreamSearchModel::jobFinished()
|
||||
|
||||
QModelIndex index=cat==root ? QModelIndex() : createIndex(cat->parent->children.indexOf(cat), 0, (void *)cat);
|
||||
if (QNetworkReply::NoError==job->error()) {
|
||||
QList<StreamsModel::Item *> newItems=StreamsModel::parseRadioTimeResponse(job, cat);
|
||||
QList<StreamsModel::Item *> newItems=StreamsModel::parseRadioTimeResponse(job, cat, true);
|
||||
if (!newItems.isEmpty()) {
|
||||
beginInsertRows(index, cat->children.count(), (cat->children.count()+newItems.count())-1);
|
||||
cat->children+=newItems;
|
||||
|
||||
@@ -801,14 +801,14 @@ void StreamsModel::persistFavourites()
|
||||
}
|
||||
}
|
||||
|
||||
QList<StreamsModel::Item *> StreamsModel::parseRadioTimeResponse(QIODevice *dev, CategoryItem *cat)
|
||||
QList<StreamsModel::Item *> StreamsModel::parseRadioTimeResponse(QIODevice *dev, CategoryItem *cat, bool parseSubText)
|
||||
{
|
||||
QList<Item *> newItems;
|
||||
QXmlStreamReader doc(dev);
|
||||
while (!doc.atEnd()) {
|
||||
doc.readNext();
|
||||
if (doc.isStartElement() && QLatin1String("outline")==doc.name()) {
|
||||
Item *item = parseRadioTimeEntry(doc, cat);
|
||||
Item *item = parseRadioTimeEntry(doc, cat, parseSubText);
|
||||
if (item) {
|
||||
newItems.append(item);
|
||||
}
|
||||
@@ -1282,7 +1282,7 @@ QList<StreamsModel::Item *> StreamsModel::parseShoutCastStations(QXmlStreamReade
|
||||
return newItems;
|
||||
}
|
||||
|
||||
StreamsModel::Item * StreamsModel::parseRadioTimeEntry(QXmlStreamReader &doc, CategoryItem *parent)
|
||||
StreamsModel::Item * StreamsModel::parseRadioTimeEntry(QXmlStreamReader &doc, CategoryItem *parent, bool parseSubText)
|
||||
{
|
||||
Item *item=0;
|
||||
CategoryItem *cat=0;
|
||||
@@ -1291,9 +1291,10 @@ StreamsModel::Item * StreamsModel::parseRadioTimeEntry(QXmlStreamReader &doc, Ca
|
||||
QString text=doc.attributes().value("text").toString();
|
||||
if (!text.isEmpty()) {
|
||||
QString url=doc.attributes().value("URL").toString();
|
||||
QString subText=parseSubText ? doc.attributes().value("subtext").toString() : QString();
|
||||
bool isStation=QLatin1String("audio")==doc.attributes().value("type").toString();
|
||||
if (isStation) {
|
||||
item=new Item(url, text, parent);
|
||||
item=new Item(url, text, parent, subText);
|
||||
} else {
|
||||
cat=new CategoryItem(url, text, parent);
|
||||
item=cat;
|
||||
|
||||
@@ -43,10 +43,11 @@ public:
|
||||
struct CategoryItem;
|
||||
struct Item
|
||||
{
|
||||
Item(const QString &u, const QString &n=QString(), CategoryItem *p=0) : url(u), name(n), parent(p) { }
|
||||
Item(const QString &u, const QString &n=QString(), CategoryItem *p=0, const QString &sub=QString()) : url(u), name(n), subText(sub), parent(p) { }
|
||||
virtual ~Item() { }
|
||||
QString url;
|
||||
QString name;
|
||||
QString subText;
|
||||
CategoryItem *parent;
|
||||
virtual bool isCategory() const { return false; }
|
||||
};
|
||||
@@ -132,7 +133,7 @@ Q_SIGNALS:
|
||||
void error(const QString &msg);
|
||||
|
||||
public:
|
||||
static QList<Item *> parseRadioTimeResponse(QIODevice *dev, CategoryItem *cat);
|
||||
static QList<Item *> parseRadioTimeResponse(QIODevice *dev, CategoryItem *cat, bool parseSubText=false);
|
||||
static QList<Item *> parseIceCastResponse(QIODevice *dev, CategoryItem *cat);
|
||||
static QList<Item *> parseSomaFmResponse(QIODevice *dev, CategoryItem *cat);
|
||||
static QList<Item *> parseDigitallyImportedResponse(QIODevice *dev, CategoryItem *cat);
|
||||
@@ -140,7 +141,7 @@ public:
|
||||
QList<Item *> parseShoutCastResponse(QIODevice *dev, CategoryItem *cat, const QString &origUrl);
|
||||
QList<Item *> parseShoutCastLinks(QXmlStreamReader &doc, CategoryItem *cat);
|
||||
QList<Item *> parseShoutCastStations(QXmlStreamReader &doc, CategoryItem *cat);
|
||||
static Item * parseRadioTimeEntry(QXmlStreamReader &doc, CategoryItem *parent);
|
||||
static Item * parseRadioTimeEntry(QXmlStreamReader &doc, CategoryItem *parent, bool parseSubText=false);
|
||||
static Item * parseSomaFmEntry(QXmlStreamReader &doc, CategoryItem *parent);
|
||||
|
||||
private Q_SLOTS:
|
||||
|
||||
@@ -166,9 +166,6 @@ public:
|
||||
QRect r(option.rect);
|
||||
QRect r2(r);
|
||||
QString childText = index.data(ItemView::Role_SubText).toString();
|
||||
if (childText==QLatin1String("-")) {
|
||||
childText.clear();
|
||||
}
|
||||
QVariant image = index.data(ItemView::Role_Image);
|
||||
if (image.isNull()) {
|
||||
image = index.data(Qt::DecorationRole);
|
||||
@@ -185,6 +182,10 @@ public:
|
||||
ActionPos actionPos = iconMode ? AP_VTop : AP_HMiddle;
|
||||
bool rtl = Qt::RightToLeft==QApplication::layoutDirection();
|
||||
|
||||
if (childText==QLatin1String("-")) {
|
||||
childText.clear();
|
||||
}
|
||||
|
||||
painter->save();
|
||||
painter->setClipRect(r);
|
||||
|
||||
@@ -278,11 +279,13 @@ public:
|
||||
painter->setFont(textFont);
|
||||
painter->drawText(textRect, text, textOpt);
|
||||
|
||||
childText = childMetrics.elidedText(childText, Qt::ElideRight, childRect.width(), QPalette::WindowText);
|
||||
color.setAlphaF(subTextAlpha(selected));
|
||||
painter->setPen(color);
|
||||
painter->setFont(childFont);
|
||||
painter->drawText(childRect, childText, textOpt);
|
||||
if (!childText.isEmpty()) {
|
||||
childText = childMetrics.elidedText(childText, Qt::ElideRight, childRect.width(), QPalette::WindowText);
|
||||
color.setAlphaF(subTextAlpha(selected));
|
||||
painter->setPen(color);
|
||||
painter->setFont(childFont);
|
||||
painter->drawText(childRect, childText, textOpt);
|
||||
}
|
||||
}
|
||||
|
||||
if (showCapacity) {
|
||||
|
||||
Reference in New Issue
Block a user