summaryrefslogtreecommitdiff
path: root/src/urlbar
diff options
context:
space:
mode:
authorLionel Chauvin <megabigbug@yahoo.fr>2010-10-10 19:59:11 +0200
committerAndrea Diamantini <adjam7@gmail.com>2010-10-30 11:43:03 +0200
commitd3718562fa556d67f715f542034a5870eccb8c3f (patch)
tree6f6328208e1f866ff96d4f174b08d63bbc7eff32 /src/urlbar
parentImages in visual suggestion are now displayed !! (diff)
downloadrekonq-d3718562fa556d67f715f542034a5870eccb8c3f.tar.xz
improve layout of visual suggestions
Diffstat (limited to 'src/urlbar')
-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
4 files changed, 68 insertions, 28 deletions
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