From b18f2e5dfcc17615d73fdbd20cb4e312ea83dfaf Mon Sep 17 00:00:00 2001 From: lionelc Date: Thu, 1 Apr 2010 19:53:18 +0200 Subject: multiple icons for type of items display icon of website --- src/urlbar/listitem.cpp | 80 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 60 insertions(+), 20 deletions(-) (limited to 'src/urlbar/listitem.cpp') 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 #include #include +#include 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("" + item.title + ""); @@ -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) { -- cgit v1.2.1