summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlionelc <lionelc@lionelc.(none)>2010-04-01 19:53:18 +0200
committerAndrea Diamantini <adjam7@gmail.com>2010-04-02 22:01:33 +0200
commitb18f2e5dfcc17615d73fdbd20cb4e312ea83dfaf (patch)
tree00fb0c3437445658a7eec270b0d5c24ff8e1e22a
parentmanage common item of bookmarks and history (diff)
downloadrekonq-b18f2e5dfcc17615d73fdbd20cb4e312ea83dfaf.tar.xz
multiple icons for type of items
display icon of website
-rw-r--r--src/urlbar/completionwidget.cpp13
-rw-r--r--src/urlbar/listitem.cpp80
-rw-r--r--src/urlbar/listitem.h2
-rw-r--r--src/urlbar/urlresolver.cpp16
-rw-r--r--src/urlbar/urlresolver.h20
5 files changed, 92 insertions, 39 deletions
diff --git a/src/urlbar/completionwidget.cpp b/src/urlbar/completionwidget.cpp
index 27fcfbad..740f1471 100644
--- a/src/urlbar/completionwidget.cpp
+++ b/src/urlbar/completionwidget.cpp
@@ -44,9 +44,6 @@
#include <QEvent>
#include <QKeyEvent>
-// Defines
-#define MAX_ELEMENTS 9
-
CompletionWidget::CompletionWidget( QWidget *parent)
:QFrame( parent, Qt::ToolTip)
@@ -68,16 +65,12 @@ CompletionWidget::CompletionWidget( QWidget *parent)
void CompletionWidget::insertSearchList(const UrlSearchList &list)
{
_list = list;
- int min = MAX_ELEMENTS;
- if(list.count() < min)
- min = list.count();
-
- for(int i = 0; i<min ; ++i)
+ int i=0;
+ foreach(UrlSearchItem item, _list)
{
- UrlSearchItem item = list.at(i);
ListItem *suggestion = new ListItem(item);
connect(suggestion, SIGNAL(itemClicked(ListItem *, Qt::MouseButton)), this, SLOT(itemChosen(ListItem *, Qt::MouseButton)));
- suggestion->setObjectName( QString::number(i) );
+ suggestion->setObjectName( QString::number(i++) );
layout()->addWidget( suggestion );
}
}
diff --git a/src/urlbar/listitem.cpp b/src/urlbar/listitem.cpp
index ee63a156..959db360 100644
--- a/src/urlbar/listitem.cpp
+++ b/src/urlbar/listitem.cpp
@@ -45,32 +45,52 @@
#include <QStylePainter>
#include <QFile>
#include <QMouseEvent>
+#include <QWebSettings>
ListItem::ListItem(const UrlSearchItem &item, QWidget *parent)
: QWidget(parent)
, m_option()
{
+ //preview and icon
+
QHBoxLayout *hLayout = new QHBoxLayout;
- QVBoxLayout *vLayout = new QVBoxLayout;
+
+ QLabel *previewLabelIcon = new QLabel;
+ previewLabelIcon->setFixedSize(45,33);
+ hLayout->addWidget(previewLabelIcon);
- QLabel *previewLabel = new QLabel;
- previewLabel->setFixedSize(40,30);
- QPixmap preview;
+ QPixmap pixmapIcon = KIcon(QWebSettings::iconForUrl(item.url)).pixmap(16);
QString path = KStandardDirs::locateLocal("cache", QString("thumbs/") + guessNameFromUrl(item.url) + ".png", true);
if(QFile::exists(path))
{
+ QLabel *previewLabel = new QLabel(previewLabelIcon);
+ previewLabel->setFrameStyle(QFrame::StyledPanel | QFrame::Raised);
+ QPixmap preview;
preview.load(path);
- previewLabel->setPixmap(preview.scaled(40,30));
- }
- else
+ if (!pixmapIcon.isNull())
+ {
+ previewLabel->setFixedSize(38,29);
+ previewLabel->setPixmap(preview.scaled(38,29, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
+ }
+ else
+ {
+ previewLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+ previewLabel->setFixedSize(45,33);
+ previewLabel->setPixmap(preview.scaled(45,33, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
+ }
+ }
+
+ if (!pixmapIcon.isNull())
{
- if(item.icon.startsWith( QLatin1String("http://") ) )
- preview = Application::icon( item.icon ).pixmap(22);
+ QLabel *iconLabel = new QLabel(previewLabelIcon);
+ iconLabel->setPixmap(pixmapIcon);
+ iconLabel->move(27, 16);
}
- previewLabel->setSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum);
- hLayout->addWidget(previewLabel);
+ //title and url
+
+ QVBoxLayout *vLayout = new QVBoxLayout;
hLayout->addLayout(vLayout);
QLabel *titleLabel = new QLabel("<b>" + item.title + "</b>");
@@ -82,17 +102,27 @@ ListItem::ListItem(const UrlSearchItem &item, QWidget *parent)
vLayout->addWidget(titleLabel);
vLayout->addWidget(urlLabel);
+ //type icon
- QLabel *iconLabel = new QLabel;
- QPixmap pixmap;
- if(item.icon.startsWith( QLatin1String("http://") ) )
- pixmap = Application::icon( item.icon ).pixmap(18);
- else
- pixmap = KIcon(item.icon).pixmap(18);
+ if (item.type & UrlSearchItem::Browse)
+ {
+ insertIcon(hLayout, "applications-internet");
+ }
+
+ if (item.type & UrlSearchItem::Search)
+ {
+ insertIcon(hLayout, "edit-find");
+ }
+
+ if (item.type & UrlSearchItem::Bookmark)
+ {
+ insertIcon(hLayout, "rating");
+ }
- iconLabel->setPixmap(pixmap);
- iconLabel->setSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum);
- hLayout->addWidget(iconLabel);
+ if (item.type & UrlSearchItem::History)
+ {
+ insertIcon(hLayout, "view-history");
+ }
setLayout(hLayout);
@@ -109,6 +139,16 @@ ListItem::~ListItem()
}
+void ListItem::insertIcon(QLayout *layout, QString icon)
+{
+ QLabel *iconLabel = new QLabel;
+ QPixmap pixmap = KIcon(icon).pixmap(18);
+ iconLabel->setPixmap(pixmap);
+ iconLabel->setSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum);
+ layout->addWidget(iconLabel);
+}
+
+
//TODO: REMOVE DUPLICATE CODE WITH PREVIEWIMAGE
QString ListItem::guessNameFromUrl(QUrl url)
{
diff --git a/src/urlbar/listitem.h b/src/urlbar/listitem.h
index 1e7b0805..de22d739 100644
--- a/src/urlbar/listitem.h
+++ b/src/urlbar/listitem.h
@@ -26,6 +26,7 @@
// Qt Includes
#include <QWidget>
+#include <QLayout>
#include <QStyleOptionViewItemV4>
// Forward Declarations
@@ -55,4 +56,5 @@ protected:
private:
QStyleOptionViewItemV4 m_option;
QString guessNameFromUrl(QUrl url);
+ void insertIcon(QLayout *layout, QString icon);
};
diff --git a/src/urlbar/urlresolver.cpp b/src/urlbar/urlresolver.cpp
index ef071c30..ff90ce14 100644
--- a/src/urlbar/urlresolver.cpp
+++ b/src/urlbar/urlresolver.cpp
@@ -45,6 +45,7 @@
#include <QByteArray>
#include <QUrl>
+#define MAX_ELEMENTS 9
// NOTE default kurifilter plugin list (at least in my box)
// 1. "kshorturifilter"
@@ -106,10 +107,15 @@ UrlSearchList UrlResolver::orderedSearchItems()
foreach (UrlSearchItem i, historyList)
{
- if (!bookmarksList.contains(i))
+ if (!bookmarksList.contains(i))
+ {
list << i;
+ }
else
+ {
+ i.type |= UrlSearchItem::Bookmark;
common << i;
+ }
}
foreach (UrlSearchItem i, common)
@@ -161,7 +167,7 @@ UrlSearchList UrlResolver::qurlFromUserInputResolution()
{
QString gUrl = QString(ba);
QString gTitle = i18n("Browse");
- UrlSearchItem gItem(gUrl, gTitle, QString("") );
+ UrlSearchItem gItem(UrlSearchItem::Browse, gUrl, gTitle, QString("") );
list << gItem;
}
@@ -182,7 +188,7 @@ UrlSearchList UrlResolver::webSearchesResolution()
// KUriFilter has the worst performance possible here and let this trick unusable
QString gUrl = QString("http://www.google.com/search?q=%1&ie=UTF-8&oe=UTF-8").arg(url1);
QString gTitle = i18n("Search Google for ") + url1;
- UrlSearchItem gItem(gUrl, gTitle, QString("http://www.google.com") );
+ UrlSearchItem gItem(UrlSearchItem::Search, gUrl, gTitle, QString("http://www.google.com") );
list << gItem;
// QString wUrl = QString("http://en.wikipedia.org/wiki/Special:Search?search=%1&go=Go").arg(url1);
@@ -204,7 +210,7 @@ UrlSearchList UrlResolver::historyResolution()
QStringList historyResults = historyCompletion->substringCompletion(_urlString);
Q_FOREACH(const QString &s, historyResults)
{
- UrlSearchItem it(s, Application::historyManager()->titleForHistoryUrl(s), QString("view-history"));
+ UrlSearchItem it(UrlSearchItem::History, s, Application::historyManager()->titleForHistoryUrl(s), QString("view-history"));
list << it;
}
@@ -221,7 +227,7 @@ UrlSearchList UrlResolver::bookmarksResolution()
QStringList bookmarkResults = bookmarkCompletion->substringCompletion(_urlString);
Q_FOREACH(const QString &s, bookmarkResults)
{
- UrlSearchItem it( s, Application::bookmarkProvider()->titleForBookmarkUrl(s), QString("rating") );
+ UrlSearchItem it(UrlSearchItem::Bookmark, s, Application::bookmarkProvider()->titleForBookmarkUrl(s), QString("rating") );
list << it;
}
diff --git a/src/urlbar/urlresolver.h b/src/urlbar/urlresolver.h
index 54b96d63..489a5a79 100644
--- a/src/urlbar/urlresolver.h
+++ b/src/urlbar/urlresolver.h
@@ -35,13 +35,25 @@
class UrlSearchItem
{
-public:
+
+ public:
+
+ enum types
+ {
+ Search = 0x00000001,
+ Browse = 0x00000010,
+ History = 0x00000100,
+ Bookmark = 0x00001000,
+ Suggestion = 0x00010000,
+ };
+
+ int type;
QString url;
QString title;
QString icon;
-
- UrlSearchItem(const QString &_url, const QString &_title = QString(), const QString &_icon = QString())
- : url(_url), title(_title), icon(_icon)
+
+ UrlSearchItem(const int &_type, const QString &_url, const QString &_title = QString(), const QString &_icon = QString())
+ : type(_type), url(_url), title(_title), icon(_icon)
{};
bool operator==(UrlSearchItem i);