From 942c55b945443a2e6dd9a2d3660347fc2176630a Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Mon, 29 Mar 2010 11:47:42 +0200 Subject: This commit merge all our work about new UrlBar. DISCLAIMER: this is far from perfect, but we finally have a good starting point to work on.. :) Jonas Gastal started working on it in the 0.3 times, startin from CompletionBase code .. .. I did some work on another idea, proposing (in code) a new "suggest engine" created from scratch... Lionel Chauvin finally merged our ideas and implemented what you are seeing (and improved it, too!).. - New suggestion items (Firefox style) - a mockup on the known urls (rekonq style) - for now, automatic Google and Wikipedia searches (more coming).. - a beautiful animation :) - quite all rough edges smoothed -------------------------------------------------------- Squashed commit of the following: commit d9cf43da421c7f6c71f78444ff1935c414468b98 commit 9dcb6e18f8a3e9ae8ef1cd1299d47d37393aa6e5 commit 6c4bf2b2040ea20c78c5703f20c6bc88b7e40169 commit 8488df67115d186489f34210b638c150c66f62d3 commit 066ab907661282b1ffa4cf640739c20b4c7b6556 commit c23e23cbca7ab3197c570651a95d3f8fea270d78 commit 60655b0a8685a76e2b8b7a457bfded974bc98b4c commit 9a8817db124b55f501c9e5d3415a975ee6f92d68 commit 61312b6b577a535a4d56758b3bd3ea38812d5139 commit b6a3f4ea12423a063eafa641cedd13b890b9d392 commit 5e8e2f851edb42bc2deed296c26c58c3d7570381 commit 2904d828f71ac8ff46a53e58da8f45b5aa16e7ef --------------------------------------------------------- --- src/urlbar/listitem.cpp | 173 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 173 insertions(+) create mode 100644 src/urlbar/listitem.cpp (limited to 'src/urlbar/listitem.cpp') diff --git a/src/urlbar/listitem.cpp b/src/urlbar/listitem.cpp new file mode 100644 index 00000000..92951cb7 --- /dev/null +++ b/src/urlbar/listitem.cpp @@ -0,0 +1,173 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2009 by Andrea Diamantini +* +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; either version 2 of +* the License or (at your option) version 3 or any later version +* accepted by the membership of KDE e.V. (or its successor approved +* by the membership of KDE e.V.), which shall act as a proxy +* defined in Section 14 of version 3 of the license. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* +* ============================================================ */ + + +// Self Includes +#include "listitem.h" + +// Local Includes +#include "urlresolver.h" +#include "application.h" + +// KDE Includes +#include +#include +#include + +// Qt Includes +#include +#include +#include +#include +#include +#include +#include + +ListItem::ListItem(const UrlSearchItem &item, QWidget *parent) + : QWidget(parent), + m_option() +{ + QHBoxLayout *hLayout = new QHBoxLayout; + QVBoxLayout *vLayout = new QVBoxLayout; + + QLabel *previewLabel = new QLabel; + previewLabel->setFixedSize(40,30); + QPixmap preview; + QString path = KStandardDirs::locateLocal("cache", QString("thumbs/") + guessNameFromUrl(item.url) + ".png", true); + if(QFile::exists(path)) + { + preview.load(path); + previewLabel->setPixmap(preview.scaled(40,30)); + } + else + { + if(item.icon.startsWith( QLatin1String("http://") ) ) + preview = Application::icon( item.icon ).pixmap(22); + } + previewLabel->setSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum); + + hLayout->addWidget(previewLabel); + hLayout->addLayout(vLayout); + + QLabel *titleLabel = new QLabel("" + item.title + ""); + titleLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + + QLabel *urlLabel = new QLabel("" + item.url + ""); + urlLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + + vLayout->addWidget(titleLabel); + vLayout->addWidget(urlLabel); + + + 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); + + iconLabel->setPixmap(pixmap); + iconLabel->setSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum); + hLayout->addWidget(iconLabel); + + setLayout(hLayout); + + m_option.initFrom(this); + m_option.direction = Qt::LeftToRight; + + deactivate(); +} + +ListItem::~ListItem() +{ + disconnect(); +} + + +//TODO: REMOVE DUPLICATE CODE WITH PREVIEWIMAGE +QString ListItem::guessNameFromUrl(QUrl url) +{ + QString name = url.toString( QUrl::RemoveScheme | QUrl::RemoveUserInfo | QUrl::StripTrailingSlash ); + + // TODO learn Regular Expressions :) + // and implement something better here.. + name.remove('/'); + name.remove('&'); + name.remove('.'); + name.remove('-'); + name.remove('_'); + name.remove('?'); + name.remove('='); + name.remove('+'); + + return name; +} + + +void ListItem::activate() +{ + m_option.state |= QStyle::State_Selected; + repaint(); +} + + +void ListItem::deactivate() +{ + m_option.state &= ~QStyle::State_Selected; + repaint(); +} + +void ListItem::paintEvent(QPaintEvent *event) +{ + Q_UNUSED(event); + + if( m_option.state.testFlag(QStyle::State_Selected) || m_option.state.testFlag(QStyle::State_MouseOver)) + { + QPainter painter(this); + m_option.rect=QRect(QPoint(),size()); + style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &m_option, &painter, this); + } +} + +void ListItem::enterEvent(QEvent *e) +{ + m_option.state |= QStyle::State_MouseOver; + repaint(); + QWidget::enterEvent(e); +} + +void ListItem::leaveEvent(QEvent *e) +{ + m_option.state &= ~QStyle::State_MouseOver; + repaint(); + QWidget::enterEvent(e); +} + +void ListItem::mousePressEvent(QMouseEvent *e) +{ + emit itemClicked(this); + QWidget::mousePressEvent(e); +} + -- cgit v1.2.1 From c6e137acee1f707d33afd6bf5bbbe994167d6a2f Mon Sep 17 00:00:00 2001 From: Yoann Laissus Date: Mon, 29 Mar 2010 18:32:16 +0200 Subject: Add mid click support for the completition widget of the url bar --- src/urlbar/listitem.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/urlbar/listitem.cpp') diff --git a/src/urlbar/listitem.cpp b/src/urlbar/listitem.cpp index 92951cb7..d9837c7e 100644 --- a/src/urlbar/listitem.cpp +++ b/src/urlbar/listitem.cpp @@ -44,6 +44,7 @@ #include #include #include +#include ListItem::ListItem(const UrlSearchItem &item, QWidget *parent) : QWidget(parent), @@ -167,7 +168,7 @@ void ListItem::leaveEvent(QEvent *e) void ListItem::mousePressEvent(QMouseEvent *e) { - emit itemClicked(this); + emit itemClicked(this, e->button()); QWidget::mousePressEvent(e); } -- cgit v1.2.1 From b44a0fd574329a54a8377b5fe9e58748f846611f Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Thu, 1 Apr 2010 15:38:45 +0200 Subject: Cleaning awesome bar code a bit.. - update is better than repaint (this also probably solves the flickering results update) - right scope for some methods - removed KUrl use from there --- src/urlbar/listitem.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'src/urlbar/listitem.cpp') diff --git a/src/urlbar/listitem.cpp b/src/urlbar/listitem.cpp index d9837c7e..ee63a156 100644 --- a/src/urlbar/listitem.cpp +++ b/src/urlbar/listitem.cpp @@ -46,9 +46,10 @@ #include #include + ListItem::ListItem(const UrlSearchItem &item, QWidget *parent) - : QWidget(parent), - m_option() + : QWidget(parent) + , m_option() { QHBoxLayout *hLayout = new QHBoxLayout; QVBoxLayout *vLayout = new QVBoxLayout; @@ -101,6 +102,7 @@ ListItem::ListItem(const UrlSearchItem &item, QWidget *parent) deactivate(); } + ListItem::~ListItem() { disconnect(); @@ -130,16 +132,17 @@ QString ListItem::guessNameFromUrl(QUrl url) void ListItem::activate() { m_option.state |= QStyle::State_Selected; - repaint(); + update(); } void ListItem::deactivate() { m_option.state &= ~QStyle::State_Selected; - repaint(); + update(); } + void ListItem::paintEvent(QPaintEvent *event) { Q_UNUSED(event); @@ -152,23 +155,25 @@ void ListItem::paintEvent(QPaintEvent *event) } } + void ListItem::enterEvent(QEvent *e) { m_option.state |= QStyle::State_MouseOver; - repaint(); + update(); QWidget::enterEvent(e); } + void ListItem::leaveEvent(QEvent *e) { m_option.state &= ~QStyle::State_MouseOver; - repaint(); + update(); QWidget::enterEvent(e); } + void ListItem::mousePressEvent(QMouseEvent *e) { emit itemClicked(this, e->button()); QWidget::mousePressEvent(e); } - -- cgit v1.2.1 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 From d2b1a62a0ecdd286b9d83275170a3322ffafd32c Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Mon, 12 Apr 2010 02:00:13 +0200 Subject: URLBAR ANIMATION: implementation fix This commit follows the logic explained somewhere else, moving rekonq to a better management for urls from user input. 1) users type strings --> we store them in QStrings 2) app load urls --> we should ever work with KUrls, trying to guess users needs Here I also removed the unuseful QString icon from UrlSearchItem definition, as we just have a type (Search, Browse, History, Books..), a (k)url and an Application::icon method :) --- src/urlbar/listitem.cpp | 57 ++++++++++++++++++++----------------------------- 1 file changed, 23 insertions(+), 34 deletions(-) (limited to 'src/urlbar/listitem.cpp') diff --git a/src/urlbar/listitem.cpp b/src/urlbar/listitem.cpp index 959db360..91af352b 100644 --- a/src/urlbar/listitem.cpp +++ b/src/urlbar/listitem.cpp @@ -35,6 +35,7 @@ #include #include #include +#include // Qt Includes #include @@ -45,12 +46,10 @@ #include #include #include -#include ListItem::ListItem(const UrlSearchItem &item, QWidget *parent) : QWidget(parent) - , m_option() { //preview and icon @@ -60,7 +59,9 @@ ListItem::ListItem(const UrlSearchItem &item, QWidget *parent) previewLabelIcon->setFixedSize(45,33); hLayout->addWidget(previewLabelIcon); - QPixmap pixmapIcon = KIcon(QWebSettings::iconForUrl(item.url)).pixmap(16); + // pixmap should ever exists + QPixmap pixmapIcon = Application::icon(item.url).pixmap(16); + QString path = KStandardDirs::locateLocal("cache", QString("thumbs/") + guessNameFromUrl(item.url) + ".png", true); if(QFile::exists(path)) { @@ -68,35 +69,23 @@ ListItem::ListItem(const UrlSearchItem &item, QWidget *parent) previewLabel->setFrameStyle(QFrame::StyledPanel | QFrame::Raised); QPixmap preview; preview.load(path); - 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)); - } + + previewLabel->setFixedSize(38,29); + previewLabel->setPixmap(preview.scaled(38,29, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); } - if (!pixmapIcon.isNull()) - { - QLabel *iconLabel = new QLabel(previewLabelIcon); - iconLabel->setPixmap(pixmapIcon); - iconLabel->move(27, 16); - } - - //title and url + QLabel *iconLabel = new QLabel(previewLabelIcon); + iconLabel->setPixmap(pixmapIcon); + iconLabel->move(27, 16); + //title and url QVBoxLayout *vLayout = new QVBoxLayout; hLayout->addLayout(vLayout); QLabel *titleLabel = new QLabel("" + item.title + ""); titleLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - QLabel *urlLabel = new QLabel("" + item.url + ""); + QLabel *urlLabel = new QLabel("" + item.url.url() + ""); urlLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); vLayout->addWidget(titleLabel); @@ -126,8 +115,8 @@ ListItem::ListItem(const UrlSearchItem &item, QWidget *parent) setLayout(hLayout); - m_option.initFrom(this); - m_option.direction = Qt::LeftToRight; + _option.initFrom(this); + _option.direction = Qt::LeftToRight; deactivate(); } @@ -150,9 +139,9 @@ void ListItem::insertIcon(QLayout *layout, QString icon) //TODO: REMOVE DUPLICATE CODE WITH PREVIEWIMAGE -QString ListItem::guessNameFromUrl(QUrl url) +QString ListItem::guessNameFromUrl(KUrl url) { - QString name = url.toString( QUrl::RemoveScheme | QUrl::RemoveUserInfo | QUrl::StripTrailingSlash ); + QString name = url.url();// toString( QUrl::RemoveScheme | QUrl::RemoveUserInfo | QUrl::StripTrailingSlash ); // TODO learn Regular Expressions :) // and implement something better here.. @@ -171,14 +160,14 @@ QString ListItem::guessNameFromUrl(QUrl url) void ListItem::activate() { - m_option.state |= QStyle::State_Selected; + _option.state |= QStyle::State_Selected; update(); } void ListItem::deactivate() { - m_option.state &= ~QStyle::State_Selected; + _option.state &= ~QStyle::State_Selected; update(); } @@ -187,18 +176,18 @@ void ListItem::paintEvent(QPaintEvent *event) { Q_UNUSED(event); - if( m_option.state.testFlag(QStyle::State_Selected) || m_option.state.testFlag(QStyle::State_MouseOver)) + if( _option.state.testFlag(QStyle::State_Selected) || _option.state.testFlag(QStyle::State_MouseOver) ) { QPainter painter(this); - m_option.rect=QRect(QPoint(),size()); - style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &m_option, &painter, this); + _option.rect = QRect(QPoint(),size()); + style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &_option, &painter, this); } } void ListItem::enterEvent(QEvent *e) { - m_option.state |= QStyle::State_MouseOver; + _option.state |= QStyle::State_MouseOver; update(); QWidget::enterEvent(e); } @@ -206,7 +195,7 @@ void ListItem::enterEvent(QEvent *e) void ListItem::leaveEvent(QEvent *e) { - m_option.state &= ~QStyle::State_MouseOver; + _option.state &= ~QStyle::State_MouseOver; update(); QWidget::enterEvent(e); } -- cgit v1.2.1 From 493c497d23ccb2962880dd8746e4fac4c1788241 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Wed, 14 Apr 2010 02:33:49 +0200 Subject: Lionel's fixes to the UI. (at least the first bits, but they seems working really well :) ) --- src/urlbar/listitem.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/urlbar/listitem.cpp') diff --git a/src/urlbar/listitem.cpp b/src/urlbar/listitem.cpp index 91af352b..61a739f8 100644 --- a/src/urlbar/listitem.cpp +++ b/src/urlbar/listitem.cpp @@ -51,7 +51,14 @@ ListItem::ListItem(const UrlSearchItem &item, QWidget *parent) : QWidget(parent) { - //preview and icon + setAutoFillBackground(true); + + QPalette p = palette(); + p.setColor(QPalette::Base, Qt::white); // TODO: choose the correct color + p.setColor(QPalette::AlternateBase, QColor(247,247,247)); // TODO: choose the correct color + setPalette(p); + + // ---------------------------------------- QHBoxLayout *hLayout = new QHBoxLayout; -- cgit v1.2.1 From fa2287de034db6ce80dd1d966bde4844350f9e87 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Wed, 14 Apr 2010 16:19:35 +0200 Subject: moc fixes --- src/urlbar/listitem.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/urlbar/listitem.cpp') diff --git a/src/urlbar/listitem.cpp b/src/urlbar/listitem.cpp index 61a739f8..18e8352d 100644 --- a/src/urlbar/listitem.cpp +++ b/src/urlbar/listitem.cpp @@ -26,6 +26,7 @@ // Self Includes #include "listitem.h" +#include "listitem.moc" // Local Includes #include "urlresolver.h" -- cgit v1.2.1 From ee9fc135d6ee214e999aebebb59459fce9147b38 Mon Sep 17 00:00:00 2001 From: lionelc Date: Thu, 15 Apr 2010 18:36:07 +0200 Subject: introduce search listitem --- src/urlbar/listitem.cpp | 404 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 310 insertions(+), 94 deletions(-) (limited to 'src/urlbar/listitem.cpp') diff --git a/src/urlbar/listitem.cpp b/src/urlbar/listitem.cpp index 18e8352d..ef09d4f3 100644 --- a/src/urlbar/listitem.cpp +++ b/src/urlbar/listitem.cpp @@ -36,7 +36,10 @@ #include #include #include -#include +#include +#include +#include + // Qt Includes #include @@ -45,111 +48,203 @@ #include #include #include -#include #include +#include +#include ListItem::ListItem(const UrlSearchItem &item, QWidget *parent) : QWidget(parent) + , m_option() + , m_url(item.url) { setAutoFillBackground(true); + + m_option.initFrom(this); + m_option.direction = Qt::LeftToRight; + + QPalette p(palette()); + p.setColor(QPalette::Base, Qt::white); // TODO: choose the correct color - QPalette p = palette(); - p.setColor(QPalette::Base, Qt::white); // TODO: choose the correct color p.setColor(QPalette::AlternateBase, QColor(247,247,247)); // TODO: choose the correct color setPalette(p); - - // ---------------------------------------- - + QHBoxLayout *hLayout = new QHBoxLayout; - - QLabel *previewLabelIcon = new QLabel; - previewLabelIcon->setFixedSize(45,33); - hLayout->addWidget(previewLabelIcon); + hLayout->setSpacing(4); + setLayout(hLayout); - // pixmap should ever exists - QPixmap pixmapIcon = Application::icon(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->setFixedSize(38,29); - previewLabel->setPixmap(preview.scaled(38,29, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); - } + deactivate(); +} - QLabel *iconLabel = new QLabel(previewLabelIcon); - iconLabel->setPixmap(pixmapIcon); - iconLabel->move(27, 16); - - //title and url - QVBoxLayout *vLayout = new QVBoxLayout; - hLayout->addLayout(vLayout); - - QLabel *titleLabel = new QLabel("" + item.title + ""); - titleLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - - QLabel *urlLabel = new QLabel("" + item.url.url() + ""); - urlLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - - vLayout->addWidget(titleLabel); - vLayout->addWidget(urlLabel); - //type icon +ListItem::~ListItem() +{ + disconnect(); +} + - if (item.type & UrlSearchItem::Browse) - { - insertIcon(hLayout, "applications-internet"); - } + +void ListItem::activate() +{ + m_option.state |= QStyle::State_Selected; + update(); +} + + +void ListItem::deactivate() +{ + m_option.state &= ~QStyle::State_Selected; + update(); +} + + +void ListItem::paintEvent(QPaintEvent *event) +{ + Q_UNUSED(event); - if (item.type & UrlSearchItem::Search) - { - insertIcon(hLayout, "edit-find"); - } - - if (item.type & UrlSearchItem::Bookmark) + if( m_option.state.testFlag(QStyle::State_Selected) || m_option.state.testFlag(QStyle::State_MouseOver)) { - insertIcon(hLayout, "rating"); + QPainter painter(this); + m_option.rect=QRect(QPoint(),size()); + style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &m_option, &painter, this); } + + QWidget::paintEvent(event); +} - if (item.type & UrlSearchItem::History) - { - insertIcon(hLayout, "view-history"); - } - setLayout(hLayout); - - _option.initFrom(this); - _option.direction = Qt::LeftToRight; - - deactivate(); +void ListItem::enterEvent(QEvent *e) +{ + m_option.state |= QStyle::State_MouseOver; + update(); + QWidget::enterEvent(e); } -ListItem::~ListItem() +void ListItem::leaveEvent(QEvent *e) { - disconnect(); + m_option.state &= ~QStyle::State_MouseOver; + update(); + QWidget::enterEvent(e); +} + + +void ListItem::mousePressEvent(QMouseEvent *e) +{ + emit itemClicked(this, e->button()); + QWidget::mousePressEvent(e); +} + + +KUrl ListItem::url() +{ + return m_url; +} + +void ListItem::nextItemSubChoice() +{ + //will be override } -void ListItem::insertIcon(QLayout *layout, QString icon) +TypeIcon::TypeIcon(int type, QWidget *parent) +:QLabel(parent) +{ + setMinimumWidth(40); + QHBoxLayout *hLayout = new QHBoxLayout; + hLayout->setMargin(0); + hLayout->setAlignment(Qt::AlignRight); + setLayout(hLayout); + + if (type & UrlSearchItem::Search) hLayout->addWidget(getIcon("edit-find")); + if (type & UrlSearchItem::Browse) hLayout->addWidget(getIcon("applications-internet")); + if (type & UrlSearchItem::Bookmark) hLayout->addWidget(getIcon("rating")); + if (type & UrlSearchItem::History) hLayout->addWidget(getIcon("view-history")); +} + + +QLabel *TypeIcon::getIcon(QString icon) { QLabel *iconLabel = new QLabel; - QPixmap pixmap = KIcon(icon).pixmap(18); + iconLabel->setFixedSize(16,16); + QPixmap pixmap = KIcon(icon).pixmap(16); iconLabel->setPixmap(pixmap); - iconLabel->setSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum); - layout->addWidget(iconLabel); + return iconLabel; +} + + + +ItemIcon::ItemIcon(QString icon, QWidget *parent) +:QLabel(parent) +{ + QPixmap pixmapIcon = KIcon(QWebSettings::iconForUrl(icon)).pixmap(16); + if (pixmapIcon.isNull()) + { + pixmapIcon = KIcon("text-html").pixmap(16); + } + + setFixedSize(16,16); + setPixmap(pixmapIcon); +} + + +ItemText::ItemText(QString text, QString underlined, QWidget *parent) +:QLabel(underlineText(text,underlined), parent) +{ + setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); +} + + +QString ItemText::underlineText(QString text, QString textToUnderline) +{ + QString t = text; + t = t.replace(QRegExp("("+textToUnderline+")", Qt::CaseInsensitive), "\\1"); + return t; +} + + +//-------------------------------------------------------------------------------------------- + + +PreviewListItem::PreviewListItem(const UrlSearchItem &item, const QString &text, QWidget *parent) +:ListItem(item, parent) +{ + QLabel *previewLabelIcon = new QLabel; + previewLabelIcon->setFixedSize(45,33); + new ItemPreview(item.url.url(), 38, 29, previewLabelIcon); + ItemIcon* icon = new ItemIcon(item.url.url(), previewLabelIcon); + icon->move(27, 16); + layout()->addWidget(previewLabelIcon); + + QVBoxLayout *vLayout = new QVBoxLayout; + vLayout->setMargin(0); + ((QHBoxLayout *)layout())->addLayout(vLayout); + vLayout->addWidget(new ItemText(item.title, text)); + vLayout->addWidget(new ItemText("" + item.url.url() + "", text)); + layout()->addWidget(new TypeIcon(item.type)); +} + + +ItemPreview::ItemPreview(QString url, int width, int height, QWidget *parent) +:QLabel(parent) +{ + setFixedSize(width, height); + setFrameStyle(QFrame::StyledPanel | QFrame::Raised); + + QString path = KStandardDirs::locateLocal("cache", QString("thumbs/") + guessNameFromUrl(url) + ".png", true); + if(QFile::exists(path)) + { + QPixmap preview; + preview.load(path); + setPixmap(preview.scaled(width, height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); + } } //TODO: REMOVE DUPLICATE CODE WITH PREVIEWIMAGE -QString ListItem::guessNameFromUrl(KUrl url) +QString ItemPreview::guessNameFromUrl(QUrl url) { - QString name = url.url();// toString( QUrl::RemoveScheme | QUrl::RemoveUserInfo | QUrl::StripTrailingSlash ); + QString name = url.toString( QUrl::RemoveScheme | QUrl::RemoveUserInfo | QUrl::StripTrailingSlash ); // TODO learn Regular Expressions :) // and implement something better here.. @@ -165,52 +260,173 @@ QString ListItem::guessNameFromUrl(KUrl url) return name; } +//-------------------------------------------------------------------------------------------- +QString SearchListItem::m_currentEngine = ""; -void ListItem::activate() +SearchListItem::SearchListItem(const UrlSearchItem &item, const QString &text, QWidget *parent) + :ListItem(item, parent) + ,m_text(text) { - _option.state |= QStyle::State_Selected; - update(); + if (m_currentEngine == "") m_currentEngine = EngineBar::defaultEngine(); + + m_iconLabel = new ItemIcon("edit-find", this); //TODO: get the default engine icon + m_titleLabel = new ItemText(searchItemTitle(m_currentEngine, text), text); + m_engineBar = new EngineBar(text, m_currentEngine, this); + + layout()->addWidget(m_iconLabel); + layout()->addWidget(m_titleLabel); + layout()->addWidget(new QLabel("Engines: ")); + layout()->addWidget(m_engineBar); + layout()->addWidget(new TypeIcon(item.type)); + + connect(m_engineBar, SIGNAL(searchEngineChanged(QString, QString)), this, SLOT(changeSearchEngine(QString, QString))); } -void ListItem::deactivate() +QString SearchListItem::searchItemTitle(QString engine, QString text) { - _option.state &= ~QStyle::State_Selected; - update(); + return QString("Search "+ engine +" for "+text+""); } -void ListItem::paintEvent(QPaintEvent *event) +void SearchListItem::changeSearchEngine(QString url, QString engine) { - Q_UNUSED(event); + m_titleLabel->setText(searchItemTitle(engine,m_text)); + m_iconLabel->setPixmap(Application::icon(url).pixmap(16)); + m_url = KUrl(url); + m_currentEngine = engine; +} + + +void SearchListItem::nextItemSubChoice() +{ + m_engineBar->selectNextEngine(); +} + + +EngineBar::EngineBar(QString text, QString selectedEngine, QWidget *parent) +:KToolBar(parent) +{ + setIconSize(QSize(16,16)); + setToolButtonStyle(Qt::ToolButtonIconOnly); + + m_engineGroup = new QActionGroup(this); + m_engineGroup->setExclusive(true); + + KConfig config("kuriikwsfilterrc"); //Share with konqueror + KConfigGroup cg = config.group("General"); + QStringList favoriteEngines; + favoriteEngines << "wikipedia" << "google"; //defaults + favoriteEngines = cg.readEntry("FavoriteSearchEngines", favoriteEngines); + QString defaultEngine = cg.readEntry("DefaultSearchEngine", "google"); + KService::Ptr service; + + service = KService::serviceByDesktopPath(QString("searchproviders/%1.desktop").arg(defaultEngine)); + m_engineGroup->addAction(newEngineAction(service, selectedEngine, text)); - if( _option.state.testFlag(QStyle::State_Selected) || _option.state.testFlag(QStyle::State_MouseOver) ) + Q_FOREACH(const QString &engine, favoriteEngines) { - QPainter painter(this); - _option.rect = QRect(QPoint(),size()); - style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &_option, &painter, this); + if(!engine.isEmpty()) + { + service = KService::serviceByDesktopPath(QString("searchproviders/%1.desktop").arg(engine)); + if(service && service->desktopEntryName()!=defaultEngine) + { + m_engineGroup->addAction(newEngineAction(service, selectedEngine, text)); + } + } } + + addActions(m_engineGroup->actions()); } -void ListItem::enterEvent(QEvent *e) +QString EngineBar::defaultEngine() +{ + KConfig config("kuriikwsfilterrc"); //Share with konqueror + KConfigGroup cg = config.group("General"); + QString d = cg.readEntry("DefaultSearchEngine", "google"); + KService::Ptr service = KService::serviceByDesktopPath(QString("searchproviders/%1.desktop").arg(d)); + return service->name(); +} + + +KAction *EngineBar::newEngineAction(KService::Ptr service, QString selectedEngine, QString text) { - _option.state |= QStyle::State_MouseOver; - update(); - QWidget::enterEvent(e); + QString url = service->property("Query").toString(); + url = url.replace("\\{@}",text); + KAction *a = new KAction(Application::icon(url), service->name(), this); + a->setCheckable(true); + if (service->name()==selectedEngine) a->setChecked(true); + a->setData(QStringList() << url << service->name()); + connect(a, SIGNAL(triggered(bool)), this, SLOT(changeSearchEngine())); + + return a; } -void ListItem::leaveEvent(QEvent *e) +void EngineBar::changeSearchEngine() { - _option.state &= ~QStyle::State_MouseOver; - update(); - QWidget::enterEvent(e); + KAction *a = qobject_cast(sender()); + QStringList list = a->data().toStringList(); + emit searchEngineChanged(list.first(), list.last()); } -void ListItem::mousePressEvent(QMouseEvent *e) +void EngineBar::selectNextEngine() { - emit itemClicked(this, e->button()); - QWidget::mousePressEvent(e); + QList e = m_engineGroup->actions(); + int i = 0; + while(iisChecked()) + { + i++; + } + + if (i+1 == e.count()) + { + e.at(0)->setChecked(true); + e.at(0)->trigger(); + } + else + { + e.at(i+1)->setChecked(true); + e.at(i+1)->trigger(); + } } + + +//-------------------------------------------------------------------------------------------- + + +BrowseListItem::BrowseListItem(const UrlSearchItem &item, const QString &text, QWidget *parent) +:ListItem(item, parent) +{ + QString url = text; + layout()->addWidget(new ItemIcon(item.url.url())); + layout()->addWidget(new ItemText("Browse http://" + url.remove("http://") + "", text)); + layout()->addWidget(new TypeIcon(item.type)); +} + + +//-------------------------------------------------------------------------------------------- + + +ListItem *ListItemFactory::create(const UrlSearchItem &item, const QString &text, QWidget *parent) +{ + ListItem *newItem; + + if (item.type & UrlSearchItem::Browse) + { + newItem = new BrowseListItem(item, text, parent); + } + else if (item.type & UrlSearchItem::Search) + { + newItem = new SearchListItem(item, text, parent); + } + else + { + newItem = new PreviewListItem(item, text, parent); + } + + return newItem; +} + -- cgit v1.2.1 From 72e0446fbc7017e7703102f733568a4f2e3c5195 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Fri, 16 Apr 2010 03:14:48 +0200 Subject: Fixing Lionel's merge request: - clean/fix APIs - removed no more used methods/signals from CompletionWidget - use item->url() (as it has been defined) - Change the "pointing out text" from underline to bold (better, IMO) - QString --> Q/K url, as needed - Restore UrlFromUserInput engine: why it has been deleted? - Comment out the isHttp() check. That way I cannot in any way connect to localhost or to my home server. Apart from typing their IPs.. - Partially fixed the switch search engine implementation. Btw, I have to say I really don't like rekonq switch my default engine just because one time I decided to give a try to another... Not sure about. - Something more coming.. But tomorrow! Now it's 3:20 am here. Good night! --- src/urlbar/listitem.cpp | 86 ++++++++++++++++++++++++++++++------------------- 1 file changed, 52 insertions(+), 34 deletions(-) (limited to 'src/urlbar/listitem.cpp') diff --git a/src/urlbar/listitem.cpp b/src/urlbar/listitem.cpp index ef09d4f3..7d1d39b2 100644 --- a/src/urlbar/listitem.cpp +++ b/src/urlbar/listitem.cpp @@ -40,7 +40,6 @@ #include #include - // Qt Includes #include #include @@ -147,8 +146,11 @@ void ListItem::nextItemSubChoice() } +// --------------------------------------------------------------- + + TypeIcon::TypeIcon(int type, QWidget *parent) -:QLabel(parent) + : QLabel(parent) { setMinimumWidth(40); QHBoxLayout *hLayout = new QHBoxLayout; @@ -173,9 +175,11 @@ QLabel *TypeIcon::getIcon(QString icon) } +// --------------------------------------------------------------- + -ItemIcon::ItemIcon(QString icon, QWidget *parent) -:QLabel(parent) +ItemIcon::ItemIcon(const QString &icon, QWidget *parent) + : QLabel(parent) { QPixmap pixmapIcon = KIcon(QWebSettings::iconForUrl(icon)).pixmap(16); if (pixmapIcon.isNull()) @@ -188,18 +192,16 @@ ItemIcon::ItemIcon(QString icon, QWidget *parent) } -ItemText::ItemText(QString text, QString underlined, QWidget *parent) -:QLabel(underlineText(text,underlined), parent) -{ - setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); -} +// --------------------------------------------------------------- -QString ItemText::underlineText(QString text, QString textToUnderline) +ItemText::ItemText(const QString &text, const QString &textToPointOut, QWidget *parent) + : QLabel(parent) { QString t = text; - t = t.replace(QRegExp("("+textToUnderline+")", Qt::CaseInsensitive), "\\1"); - return t; + t = t.replace(QRegExp("(" + textToPointOut + ")", Qt::CaseInsensitive), "\\1"); + setText(t); + setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); } @@ -207,7 +209,7 @@ QString ItemText::underlineText(QString text, QString textToUnderline) PreviewListItem::PreviewListItem(const UrlSearchItem &item, const QString &text, QWidget *parent) -:ListItem(item, parent) + : ListItem(item, parent) { QLabel *previewLabelIcon = new QLabel; previewLabelIcon->setFixedSize(45,33); @@ -225,13 +227,16 @@ PreviewListItem::PreviewListItem(const UrlSearchItem &item, const QString &text, } -ItemPreview::ItemPreview(QString url, int width, int height, QWidget *parent) -:QLabel(parent) +// --------------------------------------------------------------- + + +ItemPreview::ItemPreview(const QString &url, int width, int height, QWidget *parent) + : QLabel(parent) { setFixedSize(width, height); setFrameStyle(QFrame::StyledPanel | QFrame::Raised); - QString path = KStandardDirs::locateLocal("cache", QString("thumbs/") + guessNameFromUrl(url) + ".png", true); + QString path = KStandardDirs::locateLocal("cache", QString("thumbs/") + guessNameFromUrl( QUrl(url) ) + ".png", true); if(QFile::exists(path)) { QPixmap preview; @@ -260,12 +265,16 @@ QString ItemPreview::guessNameFromUrl(QUrl url) return name; } -//-------------------------------------------------------------------------------------------- + +// --------------------------------------------------------------- + + QString SearchListItem::m_currentEngine = ""; + SearchListItem::SearchListItem(const UrlSearchItem &item, const QString &text, QWidget *parent) - :ListItem(item, parent) - ,m_text(text) + : ListItem(item, parent) + , m_text(text) { if (m_currentEngine == "") m_currentEngine = EngineBar::defaultEngine(); @@ -273,6 +282,9 @@ SearchListItem::SearchListItem(const UrlSearchItem &item, const QString &text, Q m_titleLabel = new ItemText(searchItemTitle(m_currentEngine, text), text); m_engineBar = new EngineBar(text, m_currentEngine, this); + // without this it will not work :) + m_url = m_engineBar->url(); + layout()->addWidget(m_iconLabel); layout()->addWidget(m_titleLabel); layout()->addWidget(new QLabel("Engines: ")); @@ -292,8 +304,9 @@ QString SearchListItem::searchItemTitle(QString engine, QString text) void SearchListItem::changeSearchEngine(QString url, QString engine) { m_titleLabel->setText(searchItemTitle(engine,m_text)); - m_iconLabel->setPixmap(Application::icon(url).pixmap(16)); - m_url = KUrl(url); + m_iconLabel->setPixmap(Application::icon( KUrl(url) ).pixmap(16)); + QString url2 = url.replace("\\{@}",m_text); + m_url = KUrl(url2); m_currentEngine = engine; } @@ -304,9 +317,9 @@ void SearchListItem::nextItemSubChoice() } -EngineBar::EngineBar(QString text, QString selectedEngine, QWidget *parent) -:KToolBar(parent) -{ +EngineBar::EngineBar(const QString &text, const QString &selectedEngine, QWidget *parent) + : KToolBar(parent) +{ setIconSize(QSize(16,16)); setToolButtonStyle(Qt::ToolButtonIconOnly); @@ -322,7 +335,12 @@ EngineBar::EngineBar(QString text, QString selectedEngine, QWidget *parent) KService::Ptr service; service = KService::serviceByDesktopPath(QString("searchproviders/%1.desktop").arg(defaultEngine)); - m_engineGroup->addAction(newEngineAction(service, selectedEngine, text)); + m_engineGroup->addAction(newEngineAction(service, selectedEngine)); + + // set url; + QString url = service->property("Query").toString(); + url = url.replace("\\{@}",text); + m_url = KUrl(url); Q_FOREACH(const QString &engine, favoriteEngines) { @@ -331,7 +349,7 @@ EngineBar::EngineBar(QString text, QString selectedEngine, QWidget *parent) service = KService::serviceByDesktopPath(QString("searchproviders/%1.desktop").arg(engine)); if(service && service->desktopEntryName()!=defaultEngine) { - m_engineGroup->addAction(newEngineAction(service, selectedEngine, text)); + m_engineGroup->addAction(newEngineAction(service, selectedEngine)); } } } @@ -350,13 +368,14 @@ QString EngineBar::defaultEngine() } -KAction *EngineBar::newEngineAction(KService::Ptr service, QString selectedEngine, QString text) +KAction *EngineBar::newEngineAction(KService::Ptr service, QString selectedEngine) { - QString url = service->property("Query").toString(); - url = url.replace("\\{@}",text); - KAction *a = new KAction(Application::icon(url), service->name(), this); + KAction *a = new KAction(Application::icon(m_url), service->name(), this); a->setCheckable(true); if (service->name()==selectedEngine) a->setChecked(true); + + QString url = service->property("Query").toString(); + a->setData(QStringList() << url << service->name()); connect(a, SIGNAL(triggered(bool)), this, SLOT(changeSearchEngine())); @@ -394,11 +413,11 @@ void EngineBar::selectNextEngine() } -//-------------------------------------------------------------------------------------------- +// --------------------------------------------------------------- BrowseListItem::BrowseListItem(const UrlSearchItem &item, const QString &text, QWidget *parent) -:ListItem(item, parent) + : ListItem(item, parent) { QString url = text; layout()->addWidget(new ItemIcon(item.url.url())); @@ -407,7 +426,7 @@ BrowseListItem::BrowseListItem(const UrlSearchItem &item, const QString &text, Q } -//-------------------------------------------------------------------------------------------- +// --------------------------------------------------------------- ListItem *ListItemFactory::create(const UrlSearchItem &item, const QString &text, QWidget *parent) @@ -429,4 +448,3 @@ ListItem *ListItemFactory::create(const UrlSearchItem &item, const QString &text return newItem; } - -- cgit v1.2.1 From 3f43542ea6857760d1da6b78ebc152ca4bfc286b Mon Sep 17 00:00:00 2001 From: megabigbug Date: Fri, 16 Apr 2010 22:14:38 +0200 Subject: fix text pointed in the search item --- src/urlbar/listitem.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/urlbar/listitem.cpp') diff --git a/src/urlbar/listitem.cpp b/src/urlbar/listitem.cpp index 7d1d39b2..6f91aabd 100644 --- a/src/urlbar/listitem.cpp +++ b/src/urlbar/listitem.cpp @@ -199,7 +199,9 @@ ItemText::ItemText(const QString &text, const QString &textToPointOut, QWidget * : QLabel(parent) { QString t = text; - t = t.replace(QRegExp("(" + textToPointOut + ")", Qt::CaseInsensitive), "\\1"); + if (!textToPointOut.isEmpty()) + t = t.replace(QRegExp("(" + textToPointOut + ")", Qt::CaseInsensitive), "\\1"); + setText(t); setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); } @@ -279,7 +281,7 @@ SearchListItem::SearchListItem(const UrlSearchItem &item, const QString &text, Q if (m_currentEngine == "") m_currentEngine = EngineBar::defaultEngine(); m_iconLabel = new ItemIcon("edit-find", this); //TODO: get the default engine icon - m_titleLabel = new ItemText(searchItemTitle(m_currentEngine, text), text); + m_titleLabel = new ItemText(searchItemTitle(m_currentEngine, text)); m_engineBar = new EngineBar(text, m_currentEngine, this); // without this it will not work :) @@ -297,7 +299,7 @@ SearchListItem::SearchListItem(const UrlSearchItem &item, const QString &text, Q QString SearchListItem::searchItemTitle(QString engine, QString text) { - return QString("Search "+ engine +" for "+text+""); + return QString("Search "+ engine +" for "+text+""); } -- cgit v1.2.1 From 8ef95ed5f65c07020a91b9fce306eacc0309794a Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Sat, 17 Apr 2010 18:27:40 +0200 Subject: Clean tab previews, not showing on loading removed a duplicated method and save one QPixmap in WebSnap class --- src/urlbar/listitem.cpp | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) (limited to 'src/urlbar/listitem.cpp') diff --git a/src/urlbar/listitem.cpp b/src/urlbar/listitem.cpp index 6f91aabd..229b43e9 100644 --- a/src/urlbar/listitem.cpp +++ b/src/urlbar/listitem.cpp @@ -31,6 +31,7 @@ // Local Includes #include "urlresolver.h" #include "application.h" +#include "websnap.h" // KDE Includes #include @@ -238,7 +239,8 @@ ItemPreview::ItemPreview(const QString &url, int width, int height, QWidget *par setFixedSize(width, height); setFrameStyle(QFrame::StyledPanel | QFrame::Raised); - QString path = KStandardDirs::locateLocal("cache", QString("thumbs/") + guessNameFromUrl( QUrl(url) ) + ".png", true); + KUrl u = WebSnap::fileForUrl( QUrl(url) ); + QString path = u.pathOrUrl(); if(QFile::exists(path)) { QPixmap preview; @@ -248,26 +250,6 @@ ItemPreview::ItemPreview(const QString &url, int width, int height, QWidget *par } -//TODO: REMOVE DUPLICATE CODE WITH PREVIEWIMAGE -QString ItemPreview::guessNameFromUrl(QUrl url) -{ - QString name = url.toString( QUrl::RemoveScheme | QUrl::RemoveUserInfo | QUrl::StripTrailingSlash ); - - // TODO learn Regular Expressions :) - // and implement something better here.. - name.remove('/'); - name.remove('&'); - name.remove('.'); - name.remove('-'); - name.remove('_'); - name.remove('?'); - name.remove('='); - name.remove('+'); - - return name; -} - - // --------------------------------------------------------------- -- cgit v1.2.1 From 254ea3a16b2e99502fd1e55318f7b3e2d683b3ee Mon Sep 17 00:00:00 2001 From: megabigbug Date: Sun, 18 Apr 2010 07:10:51 +0200 Subject: fix bold: "browse" was bold if the user type "browse" --- src/urlbar/listitem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/urlbar/listitem.cpp') diff --git a/src/urlbar/listitem.cpp b/src/urlbar/listitem.cpp index 229b43e9..4b9831b2 100644 --- a/src/urlbar/listitem.cpp +++ b/src/urlbar/listitem.cpp @@ -405,7 +405,7 @@ BrowseListItem::BrowseListItem(const UrlSearchItem &item, const QString &text, Q { QString url = text; layout()->addWidget(new ItemIcon(item.url.url())); - layout()->addWidget(new ItemText("Browse http://" + url.remove("http://") + "", text)); + layout()->addWidget(new ItemText("Browse http://" + url.remove("http://") + "")); layout()->addWidget(new TypeIcon(item.type)); } -- cgit v1.2.1 From 93ad10ce9a9e1f02f43837edafb83b08cc90f1d4 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Mon, 19 Apr 2010 11:17:57 +0200 Subject: Implementing a new default engine choice for rekonq --- src/urlbar/listitem.cpp | 45 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 9 deletions(-) (limited to 'src/urlbar/listitem.cpp') diff --git a/src/urlbar/listitem.cpp b/src/urlbar/listitem.cpp index 4b9831b2..d35da547 100644 --- a/src/urlbar/listitem.cpp +++ b/src/urlbar/listitem.cpp @@ -28,6 +28,9 @@ #include "listitem.h" #include "listitem.moc" +// Auto Includes +#include "rekonq.h" + // Local Includes #include "urlresolver.h" #include "application.h" @@ -52,6 +55,9 @@ #include #include +// Defines +#define QL1S(x) QLatin1String(x) + ListItem::ListItem(const UrlSearchItem &item, QWidget *parent) : QWidget(parent) @@ -260,7 +266,8 @@ SearchListItem::SearchListItem(const UrlSearchItem &item, const QString &text, Q : ListItem(item, parent) , m_text(text) { - if (m_currentEngine == "") m_currentEngine = EngineBar::defaultEngine(); + if (m_currentEngine == "") + m_currentEngine = EngineBar::defaultEngine(); m_iconLabel = new ItemIcon("edit-find", this); //TODO: get the default engine icon m_titleLabel = new ItemText(searchItemTitle(m_currentEngine, text)); @@ -315,10 +322,10 @@ EngineBar::EngineBar(const QString &text, const QString &selectedEngine, QWidget QStringList favoriteEngines; favoriteEngines << "wikipedia" << "google"; //defaults favoriteEngines = cg.readEntry("FavoriteSearchEngines", favoriteEngines); - QString defaultEngine = cg.readEntry("DefaultSearchEngine", "google"); - KService::Ptr service; - service = KService::serviceByDesktopPath(QString("searchproviders/%1.desktop").arg(defaultEngine)); + // default engine + QString defaultEngine = EngineBar::defaultEngine(); + KService::Ptr service = KService::serviceByDesktopPath(QString("searchproviders/%1.desktop").arg(defaultEngine)); m_engineGroup->addAction(newEngineAction(service, selectedEngine)); // set url; @@ -344,11 +351,31 @@ EngineBar::EngineBar(const QString &text, const QString &selectedEngine, QWidget QString EngineBar::defaultEngine() { - KConfig config("kuriikwsfilterrc"); //Share with konqueror - KConfigGroup cg = config.group("General"); - QString d = cg.readEntry("DefaultSearchEngine", "google"); - KService::Ptr service = KService::serviceByDesktopPath(QString("searchproviders/%1.desktop").arg(d)); - return service->name(); + int n = ReKonfig::searchEngine(); + QString engine; + switch(n) + { + case 0: + engine = QL1S("google"); + break; + case 1: + engine = QL1S("altavista"); + break; + case 2: + engine = QL1S("lycos"); + break; + case 3: + engine = QL1S("wikipedia"); + break; + case 4: + engine = QL1S("wolfram"); + break; + default: + engine = QL1S("google"); + break; + } + + return engine; } -- cgit v1.2.1 From f0b4144b957727a6031226a3ec84eabf53f0e0b9 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Mon, 19 Apr 2010 17:18:01 +0200 Subject: this commit renames Item classes with this logic - Listitem inherited classes are TYPE + "Listitem" - QLabel inherited classes are TYPE + Label --- src/urlbar/listitem.cpp | 47 +++++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 22 deletions(-) (limited to 'src/urlbar/listitem.cpp') diff --git a/src/urlbar/listitem.cpp b/src/urlbar/listitem.cpp index d35da547..0ecc56fe 100644 --- a/src/urlbar/listitem.cpp +++ b/src/urlbar/listitem.cpp @@ -75,7 +75,7 @@ ListItem::ListItem(const UrlSearchItem &item, QWidget *parent) p.setColor(QPalette::AlternateBase, QColor(247,247,247)); // TODO: choose the correct color setPalette(p); - QHBoxLayout *hLayout = new QHBoxLayout; + QHBoxLayout *hLayout = new QHBoxLayout(this); hLayout->setSpacing(4); setLayout(hLayout); @@ -156,11 +156,11 @@ void ListItem::nextItemSubChoice() // --------------------------------------------------------------- -TypeIcon::TypeIcon(int type, QWidget *parent) +TypeIconLabel::TypeIconLabel(int type, QWidget *parent) : QLabel(parent) { setMinimumWidth(40); - QHBoxLayout *hLayout = new QHBoxLayout; + QHBoxLayout *hLayout = new QHBoxLayout(this); hLayout->setMargin(0); hLayout->setAlignment(Qt::AlignRight); setLayout(hLayout); @@ -172,9 +172,9 @@ TypeIcon::TypeIcon(int type, QWidget *parent) } -QLabel *TypeIcon::getIcon(QString icon) +QLabel *TypeIconLabel::getIcon(QString icon) { - QLabel *iconLabel = new QLabel; + QLabel *iconLabel = new QLabel(this); iconLabel->setFixedSize(16,16); QPixmap pixmap = KIcon(icon).pixmap(16); iconLabel->setPixmap(pixmap); @@ -185,7 +185,7 @@ QLabel *TypeIcon::getIcon(QString icon) // --------------------------------------------------------------- -ItemIcon::ItemIcon(const QString &icon, QWidget *parent) +IconLabel::IconLabel(const QString &icon, QWidget *parent) : QLabel(parent) { QPixmap pixmapIcon = KIcon(QWebSettings::iconForUrl(icon)).pixmap(16); @@ -202,7 +202,7 @@ ItemIcon::ItemIcon(const QString &icon, QWidget *parent) // --------------------------------------------------------------- -ItemText::ItemText(const QString &text, const QString &textToPointOut, QWidget *parent) +TextLabel::TextLabel(const QString &text, const QString &textToPointOut, QWidget *parent) : QLabel(parent) { QString t = text; @@ -220,26 +220,26 @@ ItemText::ItemText(const QString &text, const QString &textToPointOut, QWidget * PreviewListItem::PreviewListItem(const UrlSearchItem &item, const QString &text, QWidget *parent) : ListItem(item, parent) { - QLabel *previewLabelIcon = new QLabel; + QLabel *previewLabelIcon = new QLabel(parent); previewLabelIcon->setFixedSize(45,33); - new ItemPreview(item.url.url(), 38, 29, previewLabelIcon); - ItemIcon* icon = new ItemIcon(item.url.url(), previewLabelIcon); + new PreviewLabel(item.url.url(), 38, 29, previewLabelIcon); + IconLabel* icon = new IconLabel(item.url.url(), previewLabelIcon); icon->move(27, 16); layout()->addWidget(previewLabelIcon); - QVBoxLayout *vLayout = new QVBoxLayout; + QVBoxLayout *vLayout = new QVBoxLayout(this); vLayout->setMargin(0); ((QHBoxLayout *)layout())->addLayout(vLayout); - vLayout->addWidget(new ItemText(item.title, text)); - vLayout->addWidget(new ItemText("" + item.url.url() + "", text)); - layout()->addWidget(new TypeIcon(item.type)); + vLayout->addWidget( new TextLabel(item.title, text, this) ); + vLayout->addWidget( new TextLabel("" + item.url.url() + "", text, this) ); + layout()->addWidget( new TypeIconLabel(item.type, this) ); } // --------------------------------------------------------------- -ItemPreview::ItemPreview(const QString &url, int width, int height, QWidget *parent) +PreviewLabel::PreviewLabel(const QString &url, int width, int height, QWidget *parent) : QLabel(parent) { setFixedSize(width, height); @@ -269,8 +269,8 @@ SearchListItem::SearchListItem(const UrlSearchItem &item, const QString &text, Q if (m_currentEngine == "") m_currentEngine = EngineBar::defaultEngine(); - m_iconLabel = new ItemIcon("edit-find", this); //TODO: get the default engine icon - m_titleLabel = new ItemText(searchItemTitle(m_currentEngine, text)); + m_iconLabel = new IconLabel("edit-find", this); //TODO: get the default engine icon + m_titleLabel = new TextLabel(searchItemTitle(m_currentEngine, text)); m_engineBar = new EngineBar(text, m_currentEngine, this); // without this it will not work :) @@ -278,9 +278,9 @@ SearchListItem::SearchListItem(const UrlSearchItem &item, const QString &text, Q layout()->addWidget(m_iconLabel); layout()->addWidget(m_titleLabel); - layout()->addWidget(new QLabel("Engines: ")); + layout()->addWidget( new QLabel( i18n("Engines: "), this ) ); layout()->addWidget(m_engineBar); - layout()->addWidget(new TypeIcon(item.type)); + layout()->addWidget( new TypeIconLabel(item.type, this) ); connect(m_engineBar, SIGNAL(searchEngineChanged(QString, QString)), this, SLOT(changeSearchEngine(QString, QString))); } @@ -308,6 +308,9 @@ void SearchListItem::nextItemSubChoice() } +// ----------------------------------------------------------------------------------------------- + + EngineBar::EngineBar(const QString &text, const QString &selectedEngine, QWidget *parent) : KToolBar(parent) { @@ -431,9 +434,9 @@ BrowseListItem::BrowseListItem(const UrlSearchItem &item, const QString &text, Q : ListItem(item, parent) { QString url = text; - layout()->addWidget(new ItemIcon(item.url.url())); - layout()->addWidget(new ItemText("Browse http://" + url.remove("http://") + "")); - layout()->addWidget(new TypeIcon(item.type)); + layout()->addWidget( new IconLabel(item.url.url(), this) ); + layout()->addWidget( new TextLabel( QL1S("Browse http://") + url.remove("http://") + QL1S(""), QString(), this) ); + layout()->addWidget( new TypeIconLabel(item.type, this) ); } -- cgit v1.2.1 From 7d11112b0c1836695dee398a5122051a0ec99585 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Tue, 20 Apr 2010 00:42:12 +0200 Subject: Fix default engine implementation and fix a bit code --- src/urlbar/listitem.cpp | 98 ++++++++++++++++++------------------------------- 1 file changed, 36 insertions(+), 62 deletions(-) (limited to 'src/urlbar/listitem.cpp') diff --git a/src/urlbar/listitem.cpp b/src/urlbar/listitem.cpp index 0ecc56fe..7dc22dda 100644 --- a/src/urlbar/listitem.cpp +++ b/src/urlbar/listitem.cpp @@ -35,6 +35,7 @@ #include "urlresolver.h" #include "application.h" #include "websnap.h" +#include "completionwidget.h" // KDE Includes #include @@ -188,12 +189,7 @@ QLabel *TypeIconLabel::getIcon(QString icon) IconLabel::IconLabel(const QString &icon, QWidget *parent) : QLabel(parent) { - QPixmap pixmapIcon = KIcon(QWebSettings::iconForUrl(icon)).pixmap(16); - if (pixmapIcon.isNull()) - { - pixmapIcon = KIcon("text-html").pixmap(16); - } - + QPixmap pixmapIcon = Application::icon( KUrl(icon) ).pixmap(16); setFixedSize(16,16); setPixmap(pixmapIcon); } @@ -220,7 +216,7 @@ TextLabel::TextLabel(const QString &text, const QString &textToPointOut, QWidget PreviewListItem::PreviewListItem(const UrlSearchItem &item, const QString &text, QWidget *parent) : ListItem(item, parent) { - QLabel *previewLabelIcon = new QLabel(parent); + QLabel *previewLabelIcon = new QLabel(this); previewLabelIcon->setFixedSize(45,33); new PreviewLabel(item.url.url(), 38, 29, previewLabelIcon); IconLabel* icon = new IconLabel(item.url.url(), previewLabelIcon); @@ -229,9 +225,10 @@ PreviewListItem::PreviewListItem(const UrlSearchItem &item, const QString &text, QVBoxLayout *vLayout = new QVBoxLayout(this); vLayout->setMargin(0); - ((QHBoxLayout *)layout())->addLayout(vLayout); vLayout->addWidget( new TextLabel(item.title, text, this) ); vLayout->addWidget( new TextLabel("" + item.url.url() + "", text, this) ); + ((QHBoxLayout *)layout())->addLayout(vLayout); + layout()->addWidget( new TypeIconLabel(item.type, this) ); } @@ -259,27 +256,25 @@ PreviewLabel::PreviewLabel(const QString &url, int width, int height, QWidget *p // --------------------------------------------------------------- -QString SearchListItem::m_currentEngine = ""; - - SearchListItem::SearchListItem(const UrlSearchItem &item, const QString &text, QWidget *parent) : ListItem(item, parent) , m_text(text) { - if (m_currentEngine == "") - m_currentEngine = EngineBar::defaultEngine(); + CompletionWidget *w = qobject_cast(parent); + QString currentEngine = w->searchEngine(); + kDebug() << currentEngine; m_iconLabel = new IconLabel("edit-find", this); //TODO: get the default engine icon - m_titleLabel = new TextLabel(searchItemTitle(m_currentEngine, text)); - m_engineBar = new EngineBar(text, m_currentEngine, this); + m_titleLabel = new TextLabel( searchItemTitle(currentEngine, text), QString(), this); + m_engineBar = new EngineBar(text, currentEngine, parent); // without this it will not work :) m_url = m_engineBar->url(); - layout()->addWidget(m_iconLabel); - layout()->addWidget(m_titleLabel); + layout()->addWidget( m_iconLabel ); + layout()->addWidget( m_titleLabel ); layout()->addWidget( new QLabel( i18n("Engines: "), this ) ); - layout()->addWidget(m_engineBar); + layout()->addWidget( m_engineBar ); layout()->addWidget( new TypeIconLabel(item.type, this) ); connect(m_engineBar, SIGNAL(searchEngineChanged(QString, QString)), this, SLOT(changeSearchEngine(QString, QString))); @@ -296,9 +291,11 @@ void SearchListItem::changeSearchEngine(QString url, QString engine) { m_titleLabel->setText(searchItemTitle(engine,m_text)); m_iconLabel->setPixmap(Application::icon( KUrl(url) ).pixmap(16)); - QString url2 = url.replace("\\{@}",m_text); + QString url2 = url.replace( QL1S("\\{@}"), m_text); m_url = KUrl(url2); - m_currentEngine = engine; + + CompletionWidget *w = qobject_cast(parent()); + w->setCurrentEngine( engine ); } @@ -327,8 +324,10 @@ EngineBar::EngineBar(const QString &text, const QString &selectedEngine, QWidget favoriteEngines = cg.readEntry("FavoriteSearchEngines", favoriteEngines); // default engine - QString defaultEngine = EngineBar::defaultEngine(); + CompletionWidget *w = qobject_cast(parent); + QString defaultEngine = w->searchEngine(); KService::Ptr service = KService::serviceByDesktopPath(QString("searchproviders/%1.desktop").arg(defaultEngine)); + m_engineGroup->addAction(newEngineAction(service, selectedEngine)); // set url; @@ -341,7 +340,7 @@ EngineBar::EngineBar(const QString &text, const QString &selectedEngine, QWidget if(!engine.isEmpty()) { service = KService::serviceByDesktopPath(QString("searchproviders/%1.desktop").arg(engine)); - if(service && service->desktopEntryName()!=defaultEngine) + if(service && service->desktopEntryName() != defaultEngine) { m_engineGroup->addAction(newEngineAction(service, selectedEngine)); } @@ -352,45 +351,16 @@ EngineBar::EngineBar(const QString &text, const QString &selectedEngine, QWidget } -QString EngineBar::defaultEngine() -{ - int n = ReKonfig::searchEngine(); - QString engine; - switch(n) - { - case 0: - engine = QL1S("google"); - break; - case 1: - engine = QL1S("altavista"); - break; - case 2: - engine = QL1S("lycos"); - break; - case 3: - engine = QL1S("wikipedia"); - break; - case 4: - engine = QL1S("wolfram"); - break; - default: - engine = QL1S("google"); - break; - } - - return engine; -} - - KAction *EngineBar::newEngineAction(KService::Ptr service, QString selectedEngine) { KAction *a = new KAction(Application::icon(m_url), service->name(), this); a->setCheckable(true); - if (service->name()==selectedEngine) a->setChecked(true); + if (service->name()==selectedEngine) + a->setChecked(true); QString url = service->property("Query").toString(); - a->setData(QStringList() << url << service->name()); + a->setData( QStringList() << url << service->desktopEntryName() ); connect(a, SIGNAL(triggered(bool)), this, SLOT(changeSearchEngine())); return a; @@ -447,18 +417,22 @@ ListItem *ListItemFactory::create(const UrlSearchItem &item, const QString &text { ListItem *newItem; - if (item.type & UrlSearchItem::Browse) + switch(item.type) { + case UrlSearchItem::Browse: newItem = new BrowseListItem(item, text, parent); - } - else if (item.type & UrlSearchItem::Search) - { + break; + + case UrlSearchItem::Search: newItem = new SearchListItem(item, text, parent); - } - else - { + break; + + case UrlSearchItem::History: + case UrlSearchItem::Bookmark: + default: newItem = new PreviewListItem(item, text, parent); + break; } - + return newItem; } -- cgit v1.2.1 From f68a57ae64887cc1d9c18efed629df3b1cc49bb8 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Tue, 20 Apr 2010 12:34:12 +0200 Subject: Reverting the switch case to an if-else one. I forgot t consider the particular condition in it. Sorry for the mistake. --- src/urlbar/listitem.cpp | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'src/urlbar/listitem.cpp') diff --git a/src/urlbar/listitem.cpp b/src/urlbar/listitem.cpp index 7dc22dda..a182c1a2 100644 --- a/src/urlbar/listitem.cpp +++ b/src/urlbar/listitem.cpp @@ -417,21 +417,20 @@ ListItem *ListItemFactory::create(const UrlSearchItem &item, const QString &text { ListItem *newItem; - switch(item.type) + if(item.type & UrlSearchItem::Browse) { - case UrlSearchItem::Browse: newItem = new BrowseListItem(item, text, parent); - break; - - case UrlSearchItem::Search: - newItem = new SearchListItem(item, text, parent); - break; - - case UrlSearchItem::History: - case UrlSearchItem::Bookmark: - default: - newItem = new PreviewListItem(item, text, parent); - break; + } + else + { + if(item.type & UrlSearchItem::Search) + { + newItem = new SearchListItem(item, text, parent); + } + else + { + newItem = new PreviewListItem(item, text, parent); + } } return newItem; -- cgit v1.2.1