summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/opensearch/suggestionparser.cpp15
-rw-r--r--src/opensearch/suggestionparser.h42
-rw-r--r--src/urlbar/listitem.cpp55
-rw-r--r--src/urlbar/listitem.h11
-rw-r--r--src/urlbar/urlresolver.cpp10
-rw-r--r--src/urlbar/urlresolver.h20
6 files changed, 106 insertions, 47 deletions
diff --git a/src/opensearch/suggestionparser.cpp b/src/opensearch/suggestionparser.cpp
index 02f99644..8f0e7ba2 100644
--- a/src/opensearch/suggestionparser.cpp
+++ b/src/opensearch/suggestionparser.cpp
@@ -63,9 +63,11 @@ ResponseList XMLParser::parse(const QByteArray &resp)
if (m_reader.isStartElement() && m_reader.name() == QL1S("Item"))
{
QString title;
+ QString description;
QString url;
QString image;
- QString description;
+ int image_width=0;
+ int image_height=0;
m_reader.readNext();
@@ -75,13 +77,18 @@ ResponseList XMLParser::parse(const QByteArray &resp)
{
if (m_reader.name() == QL1S("Text")) title = m_reader.readElementText();
if (m_reader.name() == QL1S("Url")) url = m_reader.readElementText();
- if (m_reader.name() == QL1S("Image")) image = m_reader.attributes().value("source").toString();
+ if (m_reader.name() == QL1S("Image"))
+ {
+ image = m_reader.attributes().value("source").toString();
+ image_width = m_reader.attributes().value("width").toString().toInt();
+ image_height = m_reader.attributes().value("height").toString().toInt();
+ }
if (m_reader.name() == QL1S("Description")) description = m_reader.readElementText();
}
m_reader.readNext();
}
- rlist << Response(url, title, image, description);
+ rlist << Response(title, description, url, image, image_width, image_height);
}
m_reader.readNext();
@@ -127,7 +134,7 @@ ResponseList JSONParser::parse(const QByteArray &resp)
foreach(QString s, responsePartsList)
{
- rlist << Response(QString(), s, QString());
+ rlist << Response(s);
}
return rlist;
diff --git a/src/opensearch/suggestionparser.h b/src/opensearch/suggestionparser.h
index e59a092c..59c788b1 100644
--- a/src/opensearch/suggestionparser.h
+++ b/src/opensearch/suggestionparser.h
@@ -41,30 +41,42 @@
class Response
{
public:
- QString url;
QString title;
- QString image;
QString description;
-
- Response(const Response &item) : url(item.url),
- title(item.title),
+ QString url;
+ QString image;
+ int image_width;
+ int image_height;
+
+ Response(const Response &item) : title(item.title),
+ description(item.description),
+ url(item.url),
image(item.image),
- description(item.description)
+ image_width(item.image_width),
+ image_height(item.image_height)
+
{};
- Response() : url(QString()),
- title(QString()),
+ Response() : title(QString()),
+ description(QString()),
+ url(QString()),
image(QString()),
- description(QString())
+ image_width(0),
+ image_height(0)
+
{};
- Response(const QString &_url,
- const QString &_title = QString(),
+ Response(const QString &_title = QString(),
+ const QString &_description = QString(),
+ const QString &_url = QString(),
const QString &_image = QString(),
- const QString &description = QString()) : url(_url),
- title(_title),
- image(_image),
- description(description)
+ const int &_image_width = 0,
+ const int &_image_height = 0) : title(_title),
+ description(_description),
+ url(_url),
+ image(_image),
+ image_width(_image_width),
+ image_height(_image_height)
{};
};
diff --git a/src/urlbar/listitem.cpp b/src/urlbar/listitem.cpp
index 219c7072..a73ec66b 100644
--- a/src/urlbar/listitem.cpp
+++ b/src/urlbar/listitem.cpp
@@ -265,7 +265,7 @@ TextLabel::TextLabel(QWidget *parent)
{
setTextFormat(Qt::RichText);
setMouseTracking(false);
- setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
+ setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
}
@@ -274,6 +274,25 @@ void TextLabel::setEngineText(const QString &engine, const QString &text)
setText( i18nc("%1=search engine, e.g. Google, Wikipedia %2=text to search for", "Search %1 for <b>%2</b>", engine, Qt::escape(text) ) );
}
+// ---------------------------------------------------------------
+
+
+DescriptionLabel::DescriptionLabel(const QString &text, const QString &textToPointOut, QWidget *parent)
+ : QLabel(parent)
+{
+ QString t = text;
+ const bool wasItalic = t.startsWith(QL1S("<i>"));
+ if (wasItalic)
+ t.remove(QRegExp("<[/ib]*>"));
+
+ if (wasItalic)
+ t = QL1S("<i>") + t + QL1S("</i>");
+
+ setWordWrap(false); //TODO: why setWordWrap(true) make items have a strange behavior ?
+ setText(t);
+ setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
+}
+
//--------------------------------------------------------------------------------------------
@@ -354,12 +373,13 @@ void ImageLabel::slotData(KIO::Job *job, const QByteArray &data)
m_data.append(data);
}
+
void ImageLabel::slotResult(KJob *job)
{
QPixmap pix;
if (!pix.loadFromData(m_data))
kDebug() << "error while loading image: ";
- setPixmap(pix.scaled(m_width, m_height, Qt::KeepAspectRatio, Qt::SmoothTransformation));
+ setPixmap(pix);
}
// ---------------------------------------------------------------
@@ -520,26 +540,34 @@ VisualSuggestionListItem::VisualSuggestionListItem(const UrlSearchItem &item, co
QHBoxLayout *hLayout = new QHBoxLayout;
hLayout->setSpacing(4);
-
QLabel *previewLabelIcon = new QLabel(this);
- previewLabelIcon->setFixedSize(45, 33);
- new ImageLabel(item.image, 38, 29, previewLabelIcon);
- IconLabel* icon = new IconLabel(item.url, previewLabelIcon);
- icon->move(27, 16);
- hLayout->addWidget(previewLabelIcon);
+ if (!item.image.isEmpty())
+ {
+ previewLabelIcon->setFixedSize(item.image_width+10, item.image_height+10);
+ new ImageLabel(item.image, item.image_width, item.image_height, previewLabelIcon);
+ IconLabel* icon = new IconLabel(item.url, previewLabelIcon);
+ icon->move(item.image_width - 10, item.image_height -10);
+ }
+ else
+ {
+ previewLabelIcon->setFixedSize(18, 18);
+ new IconLabel(item.url, previewLabelIcon);
+ }
+
+ hLayout->addWidget(previewLabelIcon);
QVBoxLayout *vLayout = new QVBoxLayout;
vLayout->setMargin(0);
-
+ vLayout->addItem(new QSpacerItem(0,0,QSizePolicy::Expanding,QSizePolicy::MinimumExpanding));
QString query = SearchEngine::extractQuery(text);
vLayout->addWidget(new TextLabel(item.title, query, this));
- vLayout->addWidget(new TextLabel("<i>"+item.description+"</i>", query, this));
-
+ DescriptionLabel *d = new DescriptionLabel("", query, this);
+ vLayout->addWidget(d);
+ vLayout->addItem(new QSpacerItem(0,0,QSizePolicy::Expanding,QSizePolicy::MinimumExpanding));
hLayout->addLayout(vLayout);
-
hLayout->addWidget(new TypeIconLabel(item.type, this));
-
setLayout(hLayout);
+ d->setText("<i>"+item.description+"</i>");
}
@@ -574,7 +602,6 @@ BrowseListItem::BrowseListItem(const UrlSearchItem &item, const QString &text, Q
ListItem *ListItemFactory::create(const UrlSearchItem &item, const QString &text, QWidget *parent)
{
-
if (item.type & UrlSearchItem::Search)
{
kDebug() << "Search";
diff --git a/src/urlbar/listitem.h b/src/urlbar/listitem.h
index ab12917a..615958db 100644
--- a/src/urlbar/listitem.h
+++ b/src/urlbar/listitem.h
@@ -126,6 +126,17 @@ public:
void setEngineText(const QString &engine, const QString &text);
};
+// -------------------------------------------------------------------------
+
+
+class DescriptionLabel : public QLabel
+{
+ Q_OBJECT
+
+public:
+ explicit DescriptionLabel(const QString &text, const QString &textToPointOut = QString(), QWidget *parent = 0);
+};
+
// -------------------------------------------------------------------------
diff --git a/src/urlbar/urlresolver.cpp b/src/urlbar/urlresolver.cpp
index 7429adce..75349407 100644
--- a/src/urlbar/urlresolver.cpp
+++ b/src/urlbar/urlresolver.cpp
@@ -408,15 +408,7 @@ void UrlResolver::suggestionsReceived(const QString &text, const ResponseList &s
Q_FOREACH(const Response &i, suggestions)
{
-<<<<<<< HEAD
-<<<<<<< HEAD
- UrlSearchItem gItem(UrlSearchItem::Suggestion, SearchEngine::buildQuery(UrlResolver::searchEngine(), s), s);
-=======
- UrlSearchItem gItem(UrlSearchItem::Suggestion, i.title, i.title);
->>>>>>> add an xml parser to the opensearch engine.
-=======
- UrlSearchItem gItem(UrlSearchItem::Suggestion, i.url, i.title, i.image, i.description);
->>>>>>> Images in visual suggestion are now displayed !!
+ UrlSearchItem gItem(UrlSearchItem::Suggestion, i.url, i.title, i.description, i.image, i.image_width, i.image_height);
sugList << gItem;
}
emit suggestionsReady(sugList, _typedString);
diff --git a/src/urlbar/urlresolver.h b/src/urlbar/urlresolver.h
index 020b3407..3e8e4fce 100644
--- a/src/urlbar/urlresolver.h
+++ b/src/urlbar/urlresolver.h
@@ -60,35 +60,45 @@ public:
int type;
QString url;
QString title;
- QString image;
QString description;
+ QString image;
+ int image_width;
+ int image_height;
QString bookmarkPath;
UrlSearchItem(const UrlSearchItem &item) : type(item.type),
url(item.url),
title(item.title),
+ description(item.description),
image(item.image),
- description(item.description)
+ image_width(item.image_width),
+ image_height(item.image_height)
{};
UrlSearchItem() : type(UrlSearchItem::Undefined),
url(QString()),
title(QString()),
+ description(QString()),
image(QString()),
- description(QString())
+ image_width(0),
+ image_height(0)
{};
UrlSearchItem(const int &_type,
const QString &_url,
const QString &_title = QString(),
+ const QString &_description = QString(),
const QString &_image = QString(),
- const QString &description = QString()
+ const int &_image_width = 0,
+ const int &_image_height = 0
)
: type(_type),
url(_url),
title(_title),
+ description(_description),
image(_image),
- description(description)
+ image_width(_image_width),
+ image_height(_image_height)
{};
inline bool operator==(const UrlSearchItem &i) const