From 40a13302af46792cb139d59d7f66e12b46644392 Mon Sep 17 00:00:00 2001 From: matgic78 Date: Sun, 31 Jan 2010 11:28:31 +0100 Subject: Last bugs : layout fixes and empty urlbar when going back to homepage --- src/urlbar/urlbar.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/urlbar') diff --git a/src/urlbar/urlbar.cpp b/src/urlbar/urlbar.cpp index adeba6ae..4d9765a2 100644 --- a/src/urlbar/urlbar.cpp +++ b/src/urlbar/urlbar.cpp @@ -148,7 +148,6 @@ void UrlBar::setUrl(const QUrl& url) m_currentUrl = KUrl(url); updateUrl(); } - } -- cgit v1.2.1 From 067b99a053b6f8b1ccab507be8e828b2f72a1e43 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Wed, 10 Feb 2010 10:57:57 +0100 Subject: Fix copyright for 0.4 beta release --- src/urlbar/lineedit.cpp | 4 ++-- src/urlbar/lineedit.h | 4 ++-- src/urlbar/urlbar.cpp | 4 ++-- src/urlbar/urlbar.h | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) (limited to 'src/urlbar') diff --git a/src/urlbar/lineedit.cpp b/src/urlbar/lineedit.cpp index f3c93e8e..db36bd0c 100644 --- a/src/urlbar/lineedit.cpp +++ b/src/urlbar/lineedit.cpp @@ -2,9 +2,9 @@ * * This file is a part of the rekonq project * -* Copyright (C) 2009 by Andrea Diamantini +* Copyright (C) 2009-2010 by Andrea Diamantini * Copyright (C) 2009 by Paweł Prażak -* Copyright (C) 2009 by Lionel Chauvin +* Copyright (C) 2009-2010 by Lionel Chauvin * * * This program is free software; you can redistribute it and/or diff --git a/src/urlbar/lineedit.h b/src/urlbar/lineedit.h index 67ded052..0fca21d4 100644 --- a/src/urlbar/lineedit.h +++ b/src/urlbar/lineedit.h @@ -2,9 +2,9 @@ * * This file is a part of the rekonq project * -* Copyright (C) 2009 by Andrea Diamantini +* Copyright (C) 2009-2010 by Andrea Diamantini * Copyright (C) 2009 by Paweł Prażak -* Copyright (C) 2009 by Lionel Chauvin +* Copyright (C) 2009-2010 by Lionel Chauvin * * * This program is free software; you can redistribute it and/or diff --git a/src/urlbar/urlbar.cpp b/src/urlbar/urlbar.cpp index 4d9765a2..1b6ebca8 100644 --- a/src/urlbar/urlbar.cpp +++ b/src/urlbar/urlbar.cpp @@ -2,10 +2,10 @@ * * This file is a part of the rekonq project * -* Copyright (C) 2008-2009 by Andrea Diamantini +* Copyright (C) 2008-2010 by Andrea Diamantini * Copyright (C) 2009 by Domrachev Alexandr * Copyright (C) 2009 by Paweł Prażak -* Copyright (C) 2009 by Lionel Chauvin +* Copyright (C) 2009-2010 by Lionel Chauvin * * * This program is free software; you can redistribute it and/or diff --git a/src/urlbar/urlbar.h b/src/urlbar/urlbar.h index 8d267b2c..6d24e599 100644 --- a/src/urlbar/urlbar.h +++ b/src/urlbar/urlbar.h @@ -2,10 +2,10 @@ * * This file is a part of the rekonq project * -* Copyright (C) 2008-2009 by Andrea Diamantini +* Copyright (C) 2008-2010 by Andrea Diamantini * Copyright (C) 2009 by Domrachev Alexandr * Copyright (C) 2009 by Paweł Prażak -* Copyright (C) 2009 by Lionel Chauvin +* Copyright (C) 2009-2010 by Lionel Chauvin * * * This program is free software; you can redistribute it and/or -- cgit v1.2.1 From 3064ebbde6453b900572806eaf8d78c207293100 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Sun, 14 Feb 2010 11:49:31 +0100 Subject: this fix urlbar behaviour, removing focus from there and enabling loading animation. Temporary fix?? --- src/urlbar/urlbar.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/urlbar') diff --git a/src/urlbar/urlbar.cpp b/src/urlbar/urlbar.cpp index 1b6ebca8..290ac034 100644 --- a/src/urlbar/urlbar.cpp +++ b/src/urlbar/urlbar.cpp @@ -37,6 +37,7 @@ #include "mainwindow.h" #include "webview.h" #include "historymanager.h" +#include "webtab.h" // KDE Includes #include @@ -204,6 +205,9 @@ void UrlBar::activated(const QString& urlString) if (urlString.isEmpty()) return; + // this fix urlbar behaviour, removing focus from there and enabling + // loading animation. Temporary fix?? + Application::instance()->mainWindow()->currentTab()->setFocus(); setUrl(urlString); emit activated(m_currentUrl); } -- cgit v1.2.1 From f364b998624e403a33dd1b79983f80b2d058da26 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Tue, 16 Feb 2010 02:12:45 +0100 Subject: Fixes focus && let Protocol handler to just load on demand the KDirLister class (and delete on finish) --- src/urlbar/urlbar.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/urlbar') diff --git a/src/urlbar/urlbar.cpp b/src/urlbar/urlbar.cpp index 290ac034..8cb17b17 100644 --- a/src/urlbar/urlbar.cpp +++ b/src/urlbar/urlbar.cpp @@ -161,13 +161,13 @@ void UrlBar::setProgress(int progress) void UrlBar::updateUrl() { - // Don't change my typed url... - // FIXME this is not a proper solution (also if it works...) - if(hasFocus()) - { - kDebug() << "Don't change my typed url..."; - return; - } +// // Don't change my typed url... +// // FIXME this is not a proper solution (also if it works...) +// if(hasFocus()) +// { +// kDebug() << "Don't change my typed url..."; +// return; +// } KIcon icon; if(m_currentUrl.isEmpty()) -- cgit v1.2.1 From 4dcd02b5317896be0adbe479a4594dac4f048286 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Thu, 18 Feb 2010 02:10:51 +0100 Subject: Working around about: protocol.. - honor rekonq settings on about:home page - loads about:blank :) pages --- src/urlbar/urlbar.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/urlbar') diff --git a/src/urlbar/urlbar.cpp b/src/urlbar/urlbar.cpp index 8cb17b17..3ddadf6b 100644 --- a/src/urlbar/urlbar.cpp +++ b/src/urlbar/urlbar.cpp @@ -208,8 +208,9 @@ void UrlBar::activated(const QString& urlString) // this fix urlbar behaviour, removing focus from there and enabling // loading animation. Temporary fix?? Application::instance()->mainWindow()->currentTab()->setFocus(); - setUrl(urlString); - emit activated(m_currentUrl); + + setUrl( KUrl(urlString) ); + emit activated( KUrl(urlString) ); } -- cgit v1.2.1 From 8dda858403d283f1850c0298aac0fb5212a27952 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Fri, 26 Feb 2010 11:37:11 +0100 Subject: tests support for every Qt derived rekonq class --- src/urlbar/lineedit.h | 5 ++++- src/urlbar/urlbar.h | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'src/urlbar') diff --git a/src/urlbar/lineedit.h b/src/urlbar/lineedit.h index 0fca21d4..1ac3af2e 100644 --- a/src/urlbar/lineedit.h +++ b/src/urlbar/lineedit.h @@ -30,6 +30,9 @@ #define LINEEDIT_H +// Local Includes +#include "rekonqprivate_export.h" + // KDE Includes #include @@ -39,7 +42,7 @@ class QFocusEvent; class QKeyEvent; -class LineEdit : public KLineEdit +class REKONQ_TESTS_EXPORT LineEdit : public KLineEdit { Q_OBJECT diff --git a/src/urlbar/urlbar.h b/src/urlbar/urlbar.h index 6d24e599..39911bb2 100644 --- a/src/urlbar/urlbar.h +++ b/src/urlbar/urlbar.h @@ -32,6 +32,7 @@ // Local Includes +#include "rekonqprivate_export.h" #include "lineedit.h" // KDE Includes @@ -47,7 +48,7 @@ class QWidget; class KCompletion; -class UrlBar : public KHistoryComboBox +class REKONQ_TESTS_EXPORT UrlBar : public KHistoryComboBox { Q_OBJECT -- cgit v1.2.1 From 51bc713428c8c23f9b3f614c756a1bc3e239c586 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Tue, 2 Mar 2010 01:22:13 +0100 Subject: Reenabled urlbar hack BUG:228606 --- src/urlbar/urlbar.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/urlbar') diff --git a/src/urlbar/urlbar.cpp b/src/urlbar/urlbar.cpp index 3ddadf6b..718d9f67 100644 --- a/src/urlbar/urlbar.cpp +++ b/src/urlbar/urlbar.cpp @@ -161,13 +161,13 @@ void UrlBar::setProgress(int progress) void UrlBar::updateUrl() { -// // Don't change my typed url... -// // FIXME this is not a proper solution (also if it works...) -// if(hasFocus()) -// { -// kDebug() << "Don't change my typed url..."; -// return; -// } + // Don't change my typed url... + // FIXME this is not a proper solution (also if it works...) + if(hasFocus()) + { + kDebug() << "Don't change my typed url..."; + return; + } KIcon icon; if(m_currentUrl.isEmpty()) -- cgit v1.2.1 From 64408ad486db25f0124f934aed55af72f2cd6d39 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Sun, 28 Mar 2010 10:12:45 +0200 Subject: update is better than repaint :) --- src/urlbar/urlbar.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/urlbar') diff --git a/src/urlbar/urlbar.cpp b/src/urlbar/urlbar.cpp index 718d9f67..189d19fe 100644 --- a/src/urlbar/urlbar.cpp +++ b/src/urlbar/urlbar.cpp @@ -155,7 +155,7 @@ void UrlBar::setUrl(const QUrl& url) void UrlBar::setProgress(int progress) { m_progress = progress; - repaint(); + update(); } @@ -225,14 +225,14 @@ void UrlBar::loadFinished(bool) { // reset progress bar after small delay m_progress = 0; - QTimer::singleShot(200, this, SLOT(repaint())); + QTimer::singleShot(200, this, SLOT(update())); } void UrlBar::updateProgress(int progress) { m_progress = progress; - repaint(); + update(); } @@ -295,7 +295,7 @@ QLinearGradient UrlBar::generateGradient(const QColor &color, int height) void UrlBar::setBackgroundColor(QColor c) { s_defaultBaseColor = c; - repaint(); + update(); } -- cgit v1.2.1 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/completionwidget.cpp | 242 ++++++++++++++++++++++++++++++++++++++++ src/urlbar/completionwidget.h | 77 +++++++++++++ src/urlbar/lineedit.cpp | 4 +- src/urlbar/lineedit.h | 12 +- src/urlbar/listitem.cpp | 173 ++++++++++++++++++++++++++++ src/urlbar/listitem.h | 59 ++++++++++ src/urlbar/urlbar.cpp | 200 ++++++++++++++++----------------- src/urlbar/urlbar.h | 28 ++--- src/urlbar/urlresolver.cpp | 177 +++++++++++++++++++++++++++++ src/urlbar/urlresolver.h | 72 ++++++++++++ 10 files changed, 915 insertions(+), 129 deletions(-) create mode 100644 src/urlbar/completionwidget.cpp create mode 100644 src/urlbar/completionwidget.h create mode 100644 src/urlbar/listitem.cpp create mode 100644 src/urlbar/listitem.h create mode 100644 src/urlbar/urlresolver.cpp create mode 100644 src/urlbar/urlresolver.h (limited to 'src/urlbar') diff --git a/src/urlbar/completionwidget.cpp b/src/urlbar/completionwidget.cpp new file mode 100644 index 00000000..42abcb73 --- /dev/null +++ b/src/urlbar/completionwidget.cpp @@ -0,0 +1,242 @@ +/* ============================================================ +* +* 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 "completionwidget.h" +#include "completionwidget.moc" + +// KDE Includes +#include +#include +#include + +// Qt Includes +#include +#include +#include +#include +#include +#include + +#define MAX_ELEMENTS 9 +#include "application.h" + +CompletionWidget::CompletionWidget( QWidget *parent) +:QFrame( parent, Qt::ToolTip) + , _parent(parent) + , _currentIndex(-1) +{ + QPalette p(palette()); + p.setColor(QPalette::Background, Qt::white); //todo: choose the correct color + setPalette(p); + setFrameStyle(QFrame::Panel); + setLayoutDirection(Qt::LeftToRight); + QVBoxLayout *layout = new QVBoxLayout; + layout->setMargin(0); + setLayout(layout); + +} + + +void CompletionWidget::insertSearchList(const UrlSearchList &list) +{ + _list = list; + int min = MAX_ELEMENTS; + if(list.count() < min) + min = list.count(); + + for(int i = 0; isetObjectName( QString::number(i) ); + layout()->addWidget( suggestion ); + } +} + + +void CompletionWidget::sizeAndPosition() +{ + // size + setFixedHeight(layout()->count() * 44 ); + setFixedWidth( _parent->width() ); + + // position + QPoint p = _parent->mapToGlobal( QPoint(0,0) ); + move(p.x(), p.y() + _parent->height()); +} + + +void CompletionWidget::popup() +{ + down(); + sizeAndPosition(); + if (!isVisible()) + show(); +} + + +void CompletionWidget::up() +{ + // deactivate previous + if(_currentIndex != -1) + { + ListItem *widget = findChild( QString::number(_currentIndex) ); + widget->deactivate(); + } + + if(_currentIndex > 0) + _currentIndex--; + else + _currentIndex=layout()->count()-1; + + // activate "new" current + ListItem *widget = findChild( QString::number(_currentIndex) ); + widget->activate(); +} + +KUrl CompletionWidget::currentUrl() +{ + return _list.at(_currentIndex).url; +} + +void CompletionWidget::down() +{ + // deactivate previous + if(_currentIndex != -1) + { + ListItem *widget = findChild( QString::number(_currentIndex) ); + widget->deactivate(); + } + + if(_currentIndex < _list.count() -1) + _currentIndex++; + else + _currentIndex=0; + + // activate "new" current + ListItem *widget = findChild( QString::number(_currentIndex) ); + widget->activate(); +} + +void CompletionWidget::clear() +{ + QLayoutItem *child; + while ((child = layout()->takeAt(0)) != 0) + { + delete child->widget(); + delete child; + } + _currentIndex = -1; +} + + +bool CompletionWidget::eventFilter( QObject *o, QEvent *e ) +{ + int type = e->type(); + QWidget *wid = qobject_cast(o); + + if (o == this) + { + return false; + } + + //hide conditions of the CompletionWidget + if (wid + && ((wid == _parent && (type == QEvent::Move || type == QEvent::Resize)) + || ((wid->windowFlags() & Qt::Window) + && (type == QEvent::Move || type == QEvent::Hide || type == QEvent::WindowDeactivate) + && wid == _parent->window()) + || (type == QEvent::MouseButtonPress && !isAncestorOf(wid))) + ) + { + hide(); + return false; + } + + //actions on the CompletionWidget + if (wid && wid->isAncestorOf(_parent) && isVisible()) + { + if ( type == QEvent::KeyPress ) + { + QKeyEvent *ev = static_cast( e ); + switch ( ev->key() ) + { + case Qt::Key_Up: + case Qt::Key_Backtab: + if (ev->modifiers() == Qt::NoButton || (ev->modifiers() & Qt::ShiftModifier)) + { + up(); + ev->accept(); + return true; + } + break; + + case Qt::Key_Down: + case Qt::Key_Tab: + if (ev->modifiers() == Qt::NoButton) + { + down(); + ev->accept(); + return true; + } + break; + + case Qt::Key_Return: + hide(); + emit chosenUrl(currentUrl().url()); + ev->accept(); + return true; + break; + } + } + } + + return QFrame::eventFilter(o,e); +} + + +void CompletionWidget::setVisible( bool visible ) +{ + if (visible) + { + Application::instance()->installEventFilter(this); + } + else + { + Application::instance()->removeEventFilter(this); + } + + QFrame::setVisible(visible); +} + + +void CompletionWidget::itemChosen(ListItem *item) +{ + emit chosenUrl(_list.at(layout()->indexOf(item)).url); + hide(); +} \ No newline at end of file diff --git a/src/urlbar/completionwidget.h b/src/urlbar/completionwidget.h new file mode 100644 index 00000000..7b474bd8 --- /dev/null +++ b/src/urlbar/completionwidget.h @@ -0,0 +1,77 @@ +/* ============================================================ +* +* 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 . +* +* ============================================================ */ + + +#ifndef COMPLETION_WIDGET_H +#define COMPLETION_WIDGET_H + + +// Local Includes +#include "urlresolver.h" +#include "listitem.h" + +// Qt Includes +#include + +// KDE Includes +#include + +// Forward Declarations +class KUrl; + + +class CompletionWidget : public QFrame +{ +Q_OBJECT + +public: + CompletionWidget(QWidget *parent); + + void insertSearchList(const UrlSearchList &list); + void popup(); + + void up(); + void down(); + void clear(); + virtual bool eventFilter(QObject *obj, QEvent *ev); + void setVisible(bool visible); + KUrl currentUrl(); + +private slots: + void itemChosen(ListItem *item); + +signals: + void chosenUrl(const QString&); + +private: + void sizeAndPosition(); + + QWidget *_parent; + + UrlSearchList _list; + int _currentIndex; +}; + +#endif // COMPLETION_WIDGET_H diff --git a/src/urlbar/lineedit.cpp b/src/urlbar/lineedit.cpp index db36bd0c..f3c93e8e 100644 --- a/src/urlbar/lineedit.cpp +++ b/src/urlbar/lineedit.cpp @@ -2,9 +2,9 @@ * * This file is a part of the rekonq project * -* Copyright (C) 2009-2010 by Andrea Diamantini +* Copyright (C) 2009 by Andrea Diamantini * Copyright (C) 2009 by Paweł Prażak -* Copyright (C) 2009-2010 by Lionel Chauvin +* Copyright (C) 2009 by Lionel Chauvin * * * This program is free software; you can redistribute it and/or diff --git a/src/urlbar/lineedit.h b/src/urlbar/lineedit.h index 1ac3af2e..d76a5fcb 100644 --- a/src/urlbar/lineedit.h +++ b/src/urlbar/lineedit.h @@ -2,9 +2,9 @@ * * This file is a part of the rekonq project * -* Copyright (C) 2009-2010 by Andrea Diamantini +* Copyright (C) 2009 by Andrea Diamantini * Copyright (C) 2009 by Paweł Prażak -* Copyright (C) 2009-2010 by Lionel Chauvin +* Copyright (C) 2009 by Lionel Chauvin * * * This program is free software; you can redistribute it and/or @@ -30,9 +30,6 @@ #define LINEEDIT_H -// Local Includes -#include "rekonqprivate_export.h" - // KDE Includes #include @@ -42,7 +39,7 @@ class QFocusEvent; class QKeyEvent; -class REKONQ_TESTS_EXPORT LineEdit : public KLineEdit +class LineEdit : public KLineEdit { Q_OBJECT @@ -50,9 +47,12 @@ public: explicit LineEdit(QWidget *parent = 0); virtual ~LineEdit(); + protected: virtual void keyPressEvent(QKeyEvent*); virtual void mouseDoubleClickEvent(QMouseEvent *); + + }; #endif // LINEEDIT_H 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); +} + diff --git a/src/urlbar/listitem.h b/src/urlbar/listitem.h new file mode 100644 index 00000000..6aa3f1e9 --- /dev/null +++ b/src/urlbar/listitem.h @@ -0,0 +1,59 @@ +/* ============================================================ +* +* 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 . +* +* ============================================================ */ + + +// Qt Includes +#include +#include + +// Forward Declarations +class UrlSearchItem; + + +class ListItem : public QWidget +{ +Q_OBJECT + +public: + ListItem(const UrlSearchItem &item, QWidget *parent = 0); + ~ListItem(); + + void activate(); + void deactivate(); + +signals: + void itemClicked(ListItem *item); + +protected: + virtual void paintEvent(QPaintEvent *event); + virtual void enterEvent(QEvent *); + virtual void leaveEvent(QEvent *); + virtual void mousePressEvent(QMouseEvent *e); + +private: + QStyleOptionViewItemV4 m_option; + QString guessNameFromUrl(QUrl url); + +}; diff --git a/src/urlbar/urlbar.cpp b/src/urlbar/urlbar.cpp index 189d19fe..54a0a02d 100644 --- a/src/urlbar/urlbar.cpp +++ b/src/urlbar/urlbar.cpp @@ -2,10 +2,10 @@ * * This file is a part of the rekonq project * -* Copyright (C) 2008-2010 by Andrea Diamantini +* Copyright (C) 2008-2009 by Andrea Diamantini * Copyright (C) 2009 by Domrachev Alexandr * Copyright (C) 2009 by Paweł Prażak -* Copyright (C) 2009-2010 by Lionel Chauvin +* Copyright (C) 2009 by Lionel Chauvin * * * This program is free software; you can redistribute it and/or @@ -36,8 +36,7 @@ #include "lineedit.h" #include "mainwindow.h" #include "webview.h" -#include "historymanager.h" -#include "webtab.h" +#include "urlresolver.h" // KDE Includes #include @@ -49,43 +48,44 @@ #include #include #include - +#include QColor UrlBar::s_defaultBaseColor; UrlBar::UrlBar(QWidget *parent) - : KHistoryComboBox(true, parent) - , m_lineEdit(new LineEdit) - , m_progress(0) + : KComboBox(true, parent) + , m_lineEdit(new LineEdit) + , m_progress(0) + , m_box(new CompletionWidget(this)) { - setUrlDropsEnabled(true); - setAutoDeleteCompletionObject(true); - //cosmetic setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); setMinimumWidth(180); - - setTrapReturnKey(true); - - setupLineEdit(); - // add every item to history - connect(this, SIGNAL(returnPressed(const QString&)), SLOT(activated(const QString&))); - connect(completionBox(), SIGNAL(activated(const QString&)), SLOT(activated(const QString&))); + // signal handlings + setTrapReturnKey(true); + setUrlDropsEnabled(true); + + // Make m_lineEdit background transparent + QPalette p = m_lineEdit->palette(); + p.setColor(QPalette::Base, Qt::transparent); + m_lineEdit->setPalette(p); - connect(this, SIGNAL(cleared()), SLOT(cleared())); + if (!s_defaultBaseColor.isValid()) + { + s_defaultBaseColor = palette().color(QPalette::Base); + } - // setup completion box - setCompletionObject( Application::historyManager()->completionObject() ); - - // set dropdown list background - QPalette p = view()->palette(); - p.setColor(QPalette::Base, palette().color(QPalette::Base)); - view()->setPalette(p); + setLineEdit(m_lineEdit); + // clear the URL bar + m_lineEdit->clear(); // load urls on activated urlbar signal - connect(this, SIGNAL(activated(const KUrl&)), Application::instance(), SLOT(loadUrl(const KUrl&))); + connect(this, SIGNAL(returnPressed(const QString&)), SLOT(activated(const QString&))); + + installEventFilter(m_box); + connect(m_box, SIGNAL(chosenUrl(const QString&)), SLOT(activated(const QString&))); } @@ -96,7 +96,7 @@ UrlBar::~UrlBar() void UrlBar::selectAll() const { - lineEdit()->selectAll(); + m_lineEdit->selectAll(); } @@ -106,42 +106,12 @@ KUrl UrlBar::url() const } -KLineEdit *UrlBar::lineEdit() const -{ - return m_lineEdit; -} - - -void UrlBar::setupLineEdit() -{ - // Make m_lineEdit background transparent - QPalette p = m_lineEdit->palette(); - p.setColor(QPalette::Base, Qt::transparent); - m_lineEdit->setPalette(p); - - if (!s_defaultBaseColor.isValid()) - { - s_defaultBaseColor = palette().color(QPalette::Base); - } - - setLineEdit(m_lineEdit); - - // Make the lineedit consume the Qt::Key_Enter event... - lineEdit()->setTrapReturnKey(true); - - lineEdit()->setHandleSignals(true); - - // clear the URL bar - lineEdit()->clear(); -} - - void UrlBar::setUrl(const QUrl& url) { if(url.scheme() == "about") { m_currentUrl = KUrl(); - updateUrl(); // updateUrl before setFocus + updateUrl(); setFocus(); } else @@ -149,6 +119,7 @@ void UrlBar::setUrl(const QUrl& url) m_currentUrl = KUrl(url); updateUrl(); } + } @@ -195,29 +166,21 @@ void UrlBar::updateUrl() // Must be AFTER setCurrentIndex if (!hasFocus()) { - lineEdit()->setCursorPosition(0); + m_lineEdit->setCursorPosition(0); } } void UrlBar::activated(const QString& urlString) { + disconnect(this, SIGNAL(editTextChanged(const QString &)), this, SLOT(suggestUrls(const QString &))); + if (urlString.isEmpty()) return; - // this fix urlbar behaviour, removing focus from there and enabling - // loading animation. Temporary fix?? - Application::instance()->mainWindow()->currentTab()->setFocus(); - - setUrl( KUrl(urlString) ); - emit activated( KUrl(urlString) ); -} - - -void UrlBar::cleared() -{ - // clear the history on user's request from context menu - clear(); + clearFocus(); + setUrl(urlString); + Application::instance()->loadUrl(m_currentUrl); } @@ -243,7 +206,7 @@ void UrlBar::paintEvent(QPaintEvent *event) p.setColor(QPalette::Base, s_defaultBaseColor); setPalette(p); - KHistoryComboBox::paintEvent(event); + KComboBox::paintEvent(event); if (!hasFocus()) { @@ -261,7 +224,7 @@ void UrlBar::paintEvent(QPaintEvent *event) painter.setBrush(generateGradient(loadingColor, height())); painter.setPen(Qt::transparent); - QRect backgroundRect = lineEdit()->frameGeometry(); + QRect backgroundRect = m_lineEdit->frameGeometry(); int mid = backgroundRect.width() * m_progress / 100; QRect progressRect(backgroundRect.x(), backgroundRect.y(), mid, backgroundRect.height()); painter.drawRect(progressRect); @@ -272,7 +235,7 @@ void UrlBar::paintEvent(QPaintEvent *event) QSize UrlBar::sizeHint() const { - return lineEdit()->sizeHint(); + return m_lineEdit->sizeHint(); } @@ -308,43 +271,70 @@ bool UrlBar::isLoading() return true; } - void UrlBar::keyPressEvent(QKeyEvent *event) { + + // this handles the Modifiers + Return key combinations QString currentText = m_lineEdit->text().trimmed(); - if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) + if ((event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) + && !currentText.startsWith(QLatin1String("http://"), Qt::CaseInsensitive)) { - if( !currentText.startsWith(QLatin1String("http://"), Qt::CaseInsensitive) ) + QString append; + if (event->modifiers() == Qt::ControlModifier) { - QString append; - if (event->modifiers() == Qt::ControlModifier) - { - append = QLatin1String(".com"); - } - else if (event->modifiers() == (Qt::ControlModifier | Qt::ShiftModifier)) - { - append = QLatin1String(".org"); - } - else if (event->modifiers() == Qt::ShiftModifier) - { - append = QLatin1String(".net"); - } - - QUrl url(QLatin1String("http://www.") + currentText); - QString host = url.host(); - if (!host.endsWith(append, Qt::CaseInsensitive)) - { - host += append; - url.setHost(host); - m_lineEdit->setText(url.toString()); - } + append = QLatin1String(".com"); } - else + else if (event->modifiers() == (Qt::ControlModifier | Qt::ShiftModifier)) + { + append = QLatin1String(".org"); + } + else if (event->modifiers() == Qt::ShiftModifier) + { + append = QLatin1String(".net"); + } + + QUrl url(QLatin1String("http://www.") + currentText); + QString host = url.host(); + if (!host.endsWith(append, Qt::CaseInsensitive)) { - // fill lineEdit with its stripped contents to remove trailing spaces - m_lineEdit->setText(currentText); + host += append; + url.setHost(host); + m_lineEdit->setText(url.toString()); } } + + KComboBox::keyPressEvent(event); +} + + +void UrlBar::suggestUrls(const QString &text) +{ + if (!hasFocus()) + { + return; + } + + if(text.isEmpty()) + { + m_box->hide(); + return; + } + + UrlResolver res(text); + UrlSearchList list = res.orderedSearchItems(); + + if(list.count() > 0) + { + m_box->clear(); + m_box->insertSearchList(list); + m_box->popup(); + } +} - KHistoryComboBox::keyPressEvent(event); +void UrlBar::focusInEvent(QFocusEvent *event) +{ + // activate suggestions on edit text + connect(this, SIGNAL(editTextChanged(const QString &)), this, SLOT(suggestUrls(const QString &))); + + KComboBox::focusInEvent(event); } diff --git a/src/urlbar/urlbar.h b/src/urlbar/urlbar.h index 39911bb2..ef53d63a 100644 --- a/src/urlbar/urlbar.h +++ b/src/urlbar/urlbar.h @@ -2,10 +2,10 @@ * * This file is a part of the rekonq project * -* Copyright (C) 2008-2010 by Andrea Diamantini +* Copyright (C) 2008-2009 by Andrea Diamantini * Copyright (C) 2009 by Domrachev Alexandr * Copyright (C) 2009 by Paweł Prażak -* Copyright (C) 2009-2010 by Lionel Chauvin +* Copyright (C) 2009 by Lionel Chauvin * * * This program is free software; you can redistribute it and/or @@ -32,23 +32,23 @@ // Local Includes -#include "rekonqprivate_export.h" #include "lineedit.h" +#include "completionwidget.h" // KDE Includes #include -#include +#include // Qt Includes #include +#include // Forward Declarations class QLinearGradient; class QWidget; -class KCompletion; -class REKONQ_TESTS_EXPORT UrlBar : public KHistoryComboBox +class UrlBar : public KComboBox { Q_OBJECT @@ -61,31 +61,24 @@ public: QSize sizeHint() const; void setBackgroundColor(QColor); bool isLoading(); - void setProgress(int progress); -signals: - void activated(const KUrl&); - public slots: void setUrl(const QUrl &url); void updateProgress(int progress); void updateUrl(); - + private slots: void activated(const QString& url); void loadFinished(bool); - void cleared(); + void suggestUrls(const QString &editedText); protected: virtual void paintEvent(QPaintEvent *event); virtual void keyPressEvent(QKeyEvent *event); + virtual void focusInEvent(QFocusEvent *event); private: - void setupLineEdit(); - - KLineEdit *lineEdit() const; - static QLinearGradient generateGradient(const QColor &color, int height); static QColor s_defaultBaseColor; @@ -94,6 +87,9 @@ private: KUrl m_currentUrl; int m_progress; + + CompletionWidget *m_box; + KUrl m_suggestedUrl; }; #endif diff --git a/src/urlbar/urlresolver.cpp b/src/urlbar/urlresolver.cpp new file mode 100644 index 00000000..b2bf50af --- /dev/null +++ b/src/urlbar/urlresolver.cpp @@ -0,0 +1,177 @@ +/* ============================================================ +* +* 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 "urlresolver.h" + +// Local Includes +#include "application.h" +#include "historymanager.h" +#include "bookmarksmanager.h" + +// KDE Includes +#include +#include +#include +#include +#include +#include + +// Qt Includes +#include +#include +#include + + +// NOTE default kurifilter plugin list (at least in my box) +// 1. "kshorturifilter" +// 2. "kurisearchfilter" +// 3. "localdomainurifilter" +// 4 ."kuriikwsfilter" +// 5. "fixhosturifilter" + + +UrlResolver::UrlResolver(const QString &typedUrl) + : _urlString(typedUrl) +{ +} + + +UrlSearchList UrlResolver::orderedSearchItems() +{ + // NOTE: the logic here is : "we wanna suggest (at least) 9 elements" + // so we have (more or less) 3 from first results (1 from QUrl Resolutions, 2 from + // default search engines). + // There are 6 remaining: if bookmarkResults + historyResults <= 6, catch all, else + // catch first 3 results from the two resulting lists :) + + UrlSearchList list; + + list << qurlFromUserInputResolution(); + list << webSearchesResolution(); + int firstResults = list.count(); + int checkPoint = 9 - firstResults; + + UrlSearchList historyList = historyResolution(); + int historyResults = historyList.count(); + + UrlSearchList bookmarksList = bookmarksResolution(); + int bookmarkResults = bookmarksList.count(); + + if(historyResults + bookmarkResults > checkPoint) + { + historyList = historyList.mid(0,3); + bookmarksList = bookmarksList.mid(0,3); + } + list << historyList; + list << bookmarksList; + + return list; +} + + +////////////////////////////////////////////////////////////////////////// +// PRIVATE ENGINES + + +// STEP 1 = QUrl from User Input (easily the best solution... ) +UrlSearchList UrlResolver::qurlFromUserInputResolution() +{ + UrlSearchList list; + + QString url2 = _urlString; + QUrl urlFromUserInput = QUrl::fromUserInput(url2); + if(urlFromUserInput.isValid()) + { + QByteArray ba = urlFromUserInput.toEncoded(); + if(!ba.isEmpty()) + { + QString str(ba); + UrlSearchItem it(str); + list << it; + } + } + + return list; +} + + +// STEP 2 = Web Searches +UrlSearchList UrlResolver::webSearchesResolution() +{ + UrlSearchList list; + + QString url1 = _urlString; + if(KUrl(url1).isRelative() && !url1.contains('.')) + { + // 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") ); + list << gItem; + + QString wUrl = QString("http://en.wikipedia.org/wiki/Special:Search?search=%1&go=Go").arg(url1); + QString wTitle = i18n("Search Wikipedia for ") + url1; + UrlSearchItem wItem(wUrl, wTitle, QString("http://wikipedia.org") ); + list << wItem; + } + + return list; +} + + +// STEP 3 = history completion +UrlSearchList UrlResolver::historyResolution() +{ + UrlSearchList list; + + KCompletion *historyCompletion = Application::historyManager()->completionObject(); + QStringList historyResults = historyCompletion->substringCompletion(_urlString); + Q_FOREACH(const QString &s, historyResults) + { + UrlSearchItem it(s, s, QString("view-history")); + list << it; + } + + return list; +} + + +// STEP 4 = bookmarks completion +UrlSearchList UrlResolver::bookmarksResolution() +{ + UrlSearchList list; + + KCompletion *bookmarkCompletion = Application::bookmarkProvider()->completionObject(); + QStringList bookmarkResults = bookmarkCompletion->substringCompletion(_urlString); + Q_FOREACH(const QString &s, bookmarkResults) + { + UrlSearchItem it( s, QString(), QString("rating") ); + list << it; + } + + return list; +} diff --git a/src/urlbar/urlresolver.h b/src/urlbar/urlresolver.h new file mode 100644 index 00000000..0a880150 --- /dev/null +++ b/src/urlbar/urlresolver.h @@ -0,0 +1,72 @@ +/* ============================================================ +* +* 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 . +* +* ============================================================ */ + + +#ifndef URL_RESOLVER_H +#define URL_RESOLVER_H + + +// Qt Includes +#include +#include + +// Forward Declarations +class KUrl; + +class UrlSearchItem +{ +public: + QString url; + QString title; + QString icon; + + UrlSearchItem(const QString &_url, const QString &_title = QString(), const QString &_icon = QString()) + : url(_url), title(_title), icon(_icon) + {}; +}; + +typedef QList UrlSearchList; + + +// ---------------------------------------------------------------------- + + +class UrlResolver +{ +public: + UrlResolver(const QString &typedUrl); + + UrlSearchList orderedSearchItems(); + +private: + QString _urlString; + + UrlSearchList webSearchesResolution(); + UrlSearchList historyResolution(); + UrlSearchList qurlFromUserInputResolution(); + UrlSearchList bookmarksResolution(); +}; + +#endif // URL_RESOLVER_H -- 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/completionwidget.cpp | 13 ++++++++----- src/urlbar/completionwidget.h | 5 +++-- src/urlbar/listitem.cpp | 3 ++- src/urlbar/listitem.h | 2 +- src/urlbar/urlbar.cpp | 6 +++--- src/urlbar/urlbar.h | 2 +- 6 files changed, 18 insertions(+), 13 deletions(-) (limited to 'src/urlbar') diff --git a/src/urlbar/completionwidget.cpp b/src/urlbar/completionwidget.cpp index 42abcb73..3ea35a0b 100644 --- a/src/urlbar/completionwidget.cpp +++ b/src/urlbar/completionwidget.cpp @@ -72,7 +72,7 @@ void CompletionWidget::insertSearchList(const UrlSearchList &list) { UrlSearchItem item = list.at(i); ListItem *suggestion = new ListItem(item); - connect(suggestion, SIGNAL(itemClicked(ListItem *)), this, SLOT(itemChosen(ListItem *))); + connect(suggestion, SIGNAL(itemClicked(ListItem *, Qt::MouseButton)), this, SLOT(itemChosen(ListItem *, Qt::MouseButton))); suggestion->setObjectName( QString::number(i) ); layout()->addWidget( suggestion ); } @@ -208,7 +208,7 @@ bool CompletionWidget::eventFilter( QObject *o, QEvent *e ) case Qt::Key_Return: hide(); - emit chosenUrl(currentUrl().url()); + emit chosenUrl(currentUrl().url(), Rekonq::CurrentTab); ev->accept(); return true; break; @@ -235,8 +235,11 @@ void CompletionWidget::setVisible( bool visible ) } -void CompletionWidget::itemChosen(ListItem *item) +void CompletionWidget::itemChosen(ListItem *item, Qt::MouseButton button) { - emit chosenUrl(_list.at(layout()->indexOf(item)).url); + if(button == Qt::MidButton) + emit chosenUrl(_list.at(layout()->indexOf(item)).url, Rekonq::NewCurrentTab); + else + emit chosenUrl(_list.at(layout()->indexOf(item)).url, Rekonq::CurrentTab); hide(); -} \ No newline at end of file +} diff --git a/src/urlbar/completionwidget.h b/src/urlbar/completionwidget.h index 7b474bd8..64d33189 100644 --- a/src/urlbar/completionwidget.h +++ b/src/urlbar/completionwidget.h @@ -29,6 +29,7 @@ // Local Includes +#include "application.h" #include "urlresolver.h" #include "listitem.h" @@ -60,10 +61,10 @@ public: KUrl currentUrl(); private slots: - void itemChosen(ListItem *item); + void itemChosen(ListItem *item, Qt::MouseButton = Qt::LeftButton); signals: - void chosenUrl(const QString&); + void chosenUrl(const QString&, Rekonq::OpenType); private: void sizeAndPosition(); 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); } diff --git a/src/urlbar/listitem.h b/src/urlbar/listitem.h index 6aa3f1e9..ac476d4b 100644 --- a/src/urlbar/listitem.h +++ b/src/urlbar/listitem.h @@ -44,7 +44,7 @@ public: void deactivate(); signals: - void itemClicked(ListItem *item); + void itemClicked(ListItem *item, Qt::MouseButton); protected: virtual void paintEvent(QPaintEvent *event); diff --git a/src/urlbar/urlbar.cpp b/src/urlbar/urlbar.cpp index 54a0a02d..57108d29 100644 --- a/src/urlbar/urlbar.cpp +++ b/src/urlbar/urlbar.cpp @@ -85,7 +85,7 @@ UrlBar::UrlBar(QWidget *parent) connect(this, SIGNAL(returnPressed(const QString&)), SLOT(activated(const QString&))); installEventFilter(m_box); - connect(m_box, SIGNAL(chosenUrl(const QString&)), SLOT(activated(const QString&))); + connect(m_box, SIGNAL(chosenUrl(const QString&, Rekonq::OpenType)), SLOT(activated(const QString&, Rekonq::OpenType))); } @@ -171,7 +171,7 @@ void UrlBar::updateUrl() } -void UrlBar::activated(const QString& urlString) +void UrlBar::activated(const QString& urlString, Rekonq::OpenType type) { disconnect(this, SIGNAL(editTextChanged(const QString &)), this, SLOT(suggestUrls(const QString &))); @@ -180,7 +180,7 @@ void UrlBar::activated(const QString& urlString) clearFocus(); setUrl(urlString); - Application::instance()->loadUrl(m_currentUrl); + Application::instance()->loadUrl(m_currentUrl, type); } diff --git a/src/urlbar/urlbar.h b/src/urlbar/urlbar.h index ef53d63a..552d1ee0 100644 --- a/src/urlbar/urlbar.h +++ b/src/urlbar/urlbar.h @@ -69,7 +69,7 @@ public slots: void updateUrl(); private slots: - void activated(const QString& url); + void activated(const QString& url, Rekonq::OpenType = Rekonq::CurrentTab); void loadFinished(bool); void suggestUrls(const QString &editedText); -- cgit v1.2.1 From 0daaf2f04b4e2be4c8a63f6008b4653ea08e1054 Mon Sep 17 00:00:00 2001 From: megabigbug Date: Mon, 29 Mar 2010 21:33:44 +0200 Subject: detect if user type an url and order the results accordingly --- src/urlbar/urlresolver.cpp | 48 +++++++++++++++++++++++++++++++++++----------- src/urlbar/urlresolver.h | 1 + 2 files changed, 38 insertions(+), 11 deletions(-) (limited to 'src/urlbar') diff --git a/src/urlbar/urlresolver.cpp b/src/urlbar/urlresolver.cpp index b2bf50af..3f87b989 100644 --- a/src/urlbar/urlresolver.cpp +++ b/src/urlbar/urlresolver.cpp @@ -70,8 +70,17 @@ UrlSearchList UrlResolver::orderedSearchItems() UrlSearchList list; - list << qurlFromUserInputResolution(); - list << webSearchesResolution(); + if(isHttp()) + { + list << qurlFromUserInputResolution(); + list << webSearchesResolution(); + } + else + { + list << webSearchesResolution(); + list << qurlFromUserInputResolution(); + } + int firstResults = list.count(); int checkPoint = 9 - firstResults; @@ -93,6 +102,21 @@ UrlSearchList UrlResolver::orderedSearchItems() } +bool UrlResolver::isHttp() +{ + QString r = "[\\d\\w-.]+\\.(a[cdefgilmnoqrstuwz]|b[abdefghijmnorstvwyz]|"\ + "c[acdfghiklmnoruvxyz]|d[ejkmnoz]|e[ceghrst]|f[ijkmnor]|g[abdefghilmnpqrstuwy]|"\ + "h[kmnrtu]|i[delmnoqrst]|j[emop]|k[eghimnprwyz]|l[abcikrstuvy]|"\ + "m[acdghklmnopqrstuvwxyz]|n[acefgilopruz]|om|p[aefghklmnrstwy]|qa|r[eouw]|"\ + "s[abcdeghijklmnortuvyz]|t[cdfghjkmnoprtvwz]|u[augkmsyz]|v[aceginu]|w[fs]|"\ + "y[etu]|z[amw]|aero|arpa|biz|com|coop|edu|info|int|gov|mil|museum|name|net|org|"\ + "pro)"; + + return (QRegExp(r, Qt::CaseInsensitive).indexIn(_urlString) != -1) + || _urlString.startsWith("http:") + || _urlString.startsWith("https:"); +} + ////////////////////////////////////////////////////////////////////////// // PRIVATE ENGINES @@ -108,10 +132,12 @@ UrlSearchList UrlResolver::qurlFromUserInputResolution() { QByteArray ba = urlFromUserInput.toEncoded(); if(!ba.isEmpty()) - { - QString str(ba); - UrlSearchItem it(str); - list << it; + { + QString gUrl = QString(ba); + QString gTitle = i18n("Browse"); + UrlSearchItem gItem(gUrl, gTitle, QString("") ); + list << gItem; + } } @@ -125,7 +151,7 @@ UrlSearchList UrlResolver::webSearchesResolution() UrlSearchList list; QString url1 = _urlString; - if(KUrl(url1).isRelative() && !url1.contains('.')) + if(KUrl(url1).isRelative()) { // 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); @@ -133,10 +159,10 @@ UrlSearchList UrlResolver::webSearchesResolution() UrlSearchItem gItem(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); - QString wTitle = i18n("Search Wikipedia for ") + url1; - UrlSearchItem wItem(wUrl, wTitle, QString("http://wikipedia.org") ); - list << wItem; +// QString wUrl = QString("http://en.wikipedia.org/wiki/Special:Search?search=%1&go=Go").arg(url1); +// QString wTitle = i18n("Search Wikipedia for ") + url1; +// UrlSearchItem wItem(wUrl, wTitle, QString("http://wikipedia.org") ); +// list << wItem; } return list; diff --git a/src/urlbar/urlresolver.h b/src/urlbar/urlresolver.h index 0a880150..4231aaab 100644 --- a/src/urlbar/urlresolver.h +++ b/src/urlbar/urlresolver.h @@ -67,6 +67,7 @@ private: UrlSearchList historyResolution(); UrlSearchList qurlFromUserInputResolution(); UrlSearchList bookmarksResolution(); + bool isHttp(); }; #endif // URL_RESOLVER_H -- cgit v1.2.1 From b1f39e13b1d2199b2f8a9bef3c213715a36dd146 Mon Sep 17 00:00:00 2001 From: megabigbug Date: Mon, 29 Mar 2010 23:20:37 +0200 Subject: add title for bookmarks in the list --- src/urlbar/urlresolver.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/urlbar') diff --git a/src/urlbar/urlresolver.cpp b/src/urlbar/urlresolver.cpp index 3f87b989..cb61ad95 100644 --- a/src/urlbar/urlresolver.cpp +++ b/src/urlbar/urlresolver.cpp @@ -195,9 +195,10 @@ UrlSearchList UrlResolver::bookmarksResolution() QStringList bookmarkResults = bookmarkCompletion->substringCompletion(_urlString); Q_FOREACH(const QString &s, bookmarkResults) { - UrlSearchItem it( s, QString(), QString("rating") ); + UrlSearchItem it( s, Application::bookmarkProvider()->titleForBookmarkUrl(s), QString("rating") ); list << it; } + return list; } -- cgit v1.2.1 From 80b37fa28d6c4e148ac0c69e91e07c1679866c54 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Tue, 30 Mar 2010 11:26:07 +0200 Subject: Cleaning urlbar API and improving animation WARNING: This is the best animation I could provide with the KComboBox class. In the KLineEdit derived it works perfectly. In the Combos there are some shadows on top :( Squashed commit of the following: commit 01e72a1996161028f8dbdc4e355daf00f954eace commit 8bc032d98a4987d3b01566ac520f5e8a1a095dd0 commit bc5cfd9f7d1b34f5af06dd7af6de8d3b2edb277b commit 73b4deac84d91fece407b9c700dcc61e36a34327 commit c55b753913b2619607c6aa11cabbf77ca3c84e3e commit b901fbe71b7539f65260c4fa9bbfb22f4ea997b9 commit 1de363d9614c1309ac1ac4a8eea7e70be7f2f3ed commit 76d6373f8b6c41f5c27b8404db2074f9bfc309c9 commit d741aa7109db016abc292d49fb45d15bb09e6c01 --- src/urlbar/lineedit.cpp | 2 +- src/urlbar/urlbar.cpp | 109 +++++++++++++++++++----------------------------- src/urlbar/urlbar.h | 17 +++----- 3 files changed, 50 insertions(+), 78 deletions(-) (limited to 'src/urlbar') diff --git a/src/urlbar/lineedit.cpp b/src/urlbar/lineedit.cpp index f3c93e8e..ac92b858 100644 --- a/src/urlbar/lineedit.cpp +++ b/src/urlbar/lineedit.cpp @@ -42,7 +42,7 @@ LineEdit::LineEdit(QWidget* parent) setMinimumWidth(200); setFocusPolicy(Qt::WheelFocus); setHandleSignals(true); - setClearButtonShown(true); + setClearButtonShown(false); } diff --git a/src/urlbar/urlbar.cpp b/src/urlbar/urlbar.cpp index 57108d29..a04d6534 100644 --- a/src/urlbar/urlbar.cpp +++ b/src/urlbar/urlbar.cpp @@ -50,14 +50,13 @@ #include #include -QColor UrlBar::s_defaultBaseColor; - UrlBar::UrlBar(QWidget *parent) : KComboBox(true, parent) , m_lineEdit(new LineEdit) - , m_progress(0) , m_box(new CompletionWidget(this)) + , _tab(0) + , _privateMode(false) { //cosmetic setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); @@ -72,11 +71,6 @@ UrlBar::UrlBar(QWidget *parent) p.setColor(QPalette::Base, Qt::transparent); m_lineEdit->setPalette(p); - if (!s_defaultBaseColor.isValid()) - { - s_defaultBaseColor = palette().color(QPalette::Base); - } - setLineEdit(m_lineEdit); // clear the URL bar @@ -123,13 +117,6 @@ void UrlBar::setUrl(const QUrl& url) } -void UrlBar::setProgress(int progress) -{ - m_progress = progress; - update(); -} - - void UrlBar::updateUrl() { // Don't change my typed url... @@ -184,26 +171,21 @@ void UrlBar::activated(const QString& urlString, Rekonq::OpenType type) } -void UrlBar::loadFinished(bool) -{ - // reset progress bar after small delay - m_progress = 0; - QTimer::singleShot(200, this, SLOT(update())); -} - - -void UrlBar::updateProgress(int progress) -{ - m_progress = progress; - update(); -} - - void UrlBar::paintEvent(QPaintEvent *event) { + QColor backgroundColor; + if( _privateMode ) + { + backgroundColor = QColor(192, 192, 192); // gray + } + else + { + backgroundColor = Application::palette().color(QPalette::Base); + } + // set background color of UrlBar QPalette p = palette(); - p.setColor(QPalette::Base, s_defaultBaseColor); + p.setColor(QPalette::Base, backgroundColor); setPalette(p); KComboBox::paintEvent(event); @@ -221,11 +203,20 @@ void UrlBar::paintEvent(QPaintEvent *event) { loadingColor = QColor(116, 192, 250); } - painter.setBrush(generateGradient(loadingColor, height())); + int progr = _tab->progress(); + + backgroundColor.setAlpha(0); + backgroundColor.setAlpha(200); + QLinearGradient gradient(0, 0, width(), height() ); + gradient.setColorAt(0, loadingColor); + gradient.setColorAt(((double)progr)/100, backgroundColor); + + painter.setBrush( gradient ); painter.setPen(Qt::transparent); + QRect backgroundRect = m_lineEdit->frameGeometry(); - int mid = backgroundRect.width() * m_progress / 100; + int mid = backgroundRect.width() * progr / 100; QRect progressRect(backgroundRect.x(), backgroundRect.y(), mid, backgroundRect.height()); painter.drawRect(progressRect); painter.end(); @@ -239,41 +230,8 @@ QSize UrlBar::sizeHint() const } -QLinearGradient UrlBar::generateGradient(const QColor &color, int height) -{ - QColor base = s_defaultBaseColor; - base.setAlpha(0); - QColor barColor = color; - barColor.setAlpha(200); - QLinearGradient gradient(0, 0, 0, height); - gradient.setColorAt(0, base); - gradient.setColorAt(0.25, barColor.lighter(120)); - gradient.setColorAt(0.5, barColor); - gradient.setColorAt(0.75, barColor.lighter(120)); - gradient.setColorAt(1, base); - return gradient; -} - - -void UrlBar::setBackgroundColor(QColor c) -{ - s_defaultBaseColor = c; - update(); -} - - -bool UrlBar::isLoading() -{ - if(m_progress == 0) - { - return false; - } - return true; -} - void UrlBar::keyPressEvent(QKeyEvent *event) { - // this handles the Modifiers + Return key combinations QString currentText = m_lineEdit->text().trimmed(); if ((event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) @@ -338,3 +296,22 @@ void UrlBar::focusInEvent(QFocusEvent *event) KComboBox::focusInEvent(event); } + + +void UrlBar::setCurrentTab(WebTab *tab) +{ + if(_tab) + disconnect(_tab->view(), SIGNAL(urlChanged(const QUrl &)), this, SLOT(setUrl(const QUrl &))); + _tab = tab; + connect(_tab->view(), SIGNAL(urlChanged(const QUrl &)), this, SLOT(setUrl(const QUrl &))); + + // update it now (the first time) + setUrl( _tab->url() ); + update(); +} + + +void UrlBar::setPrivateMode(bool on) +{ + _privateMode = on; +} diff --git a/src/urlbar/urlbar.h b/src/urlbar/urlbar.h index 552d1ee0..991b9038 100644 --- a/src/urlbar/urlbar.h +++ b/src/urlbar/urlbar.h @@ -34,6 +34,7 @@ // Local Includes #include "lineedit.h" #include "completionwidget.h" +#include "webtab.h" // KDE Includes #include @@ -59,18 +60,16 @@ public: void selectAll() const; KUrl url() const; QSize sizeHint() const; - void setBackgroundColor(QColor); - bool isLoading(); - void setProgress(int progress); + void setCurrentTab(WebTab *); + void setPrivateMode(bool on); + public slots: void setUrl(const QUrl &url); - void updateProgress(int progress); void updateUrl(); private slots: void activated(const QString& url, Rekonq::OpenType = Rekonq::CurrentTab); - void loadFinished(bool); void suggestUrls(const QString &editedText); protected: @@ -79,17 +78,13 @@ protected: virtual void focusInEvent(QFocusEvent *event); private: - static QLinearGradient generateGradient(const QColor &color, int height); - - static QColor s_defaultBaseColor; - LineEdit *m_lineEdit; KUrl m_currentUrl; - int m_progress; CompletionWidget *m_box; - KUrl m_suggestedUrl; + WebTab *_tab; + bool _privateMode; }; #endif -- cgit v1.2.1 From 5b4569933c22f85835a7605bd1d59df849b4f36a Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Wed, 31 Mar 2010 09:41:10 +0200 Subject: This patch solves some problems of clipped text I cannot value this is completely safe, but sizeAndPosition() slot is surely something to take care.. Courtesy patch from Peter Hedlund. Thanks :) CCMAIL:peter@peterandlinda.com CCMAIL:rekonq@kde.org --- src/urlbar/completionwidget.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/urlbar') diff --git a/src/urlbar/completionwidget.cpp b/src/urlbar/completionwidget.cpp index 3ea35a0b..3a54f890 100644 --- a/src/urlbar/completionwidget.cpp +++ b/src/urlbar/completionwidget.cpp @@ -82,7 +82,14 @@ void CompletionWidget::insertSearchList(const UrlSearchList &list) void CompletionWidget::sizeAndPosition() { // size - setFixedHeight(layout()->count() * 44 ); + int h = 34; + ListItem *widget; + for(int i = 0; i < layout()->count(); ++i) + { + widget = findChild( QString::number(i) ); + h = qMax(widget->sizeHint().height(), h); + } + setFixedHeight(layout()->count() * (h + 10) ); setFixedWidth( _parent->width() ); // position @@ -206,6 +213,7 @@ bool CompletionWidget::eventFilter( QObject *o, QEvent *e ) } break; + case Qt::Key_Enter: case Qt::Key_Return: hide(); emit chosenUrl(currentUrl().url(), Rekonq::CurrentTab); -- 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/completionwidget.cpp | 17 +++++++++-------- src/urlbar/completionwidget.h | 18 +++++++----------- src/urlbar/lineedit.h | 3 --- src/urlbar/listitem.cpp | 19 ++++++++++++------- src/urlbar/listitem.h | 3 +-- src/urlbar/urlresolver.h | 2 -- 6 files changed, 29 insertions(+), 33 deletions(-) (limited to 'src/urlbar') diff --git a/src/urlbar/completionwidget.cpp b/src/urlbar/completionwidget.cpp index 3a54f890..27fcfbad 100644 --- a/src/urlbar/completionwidget.cpp +++ b/src/urlbar/completionwidget.cpp @@ -28,6 +28,9 @@ #include "completionwidget.h" #include "completionwidget.moc" +// Local Includes +#include "application.h" + // KDE Includes #include #include @@ -41,16 +44,17 @@ #include #include +// Defines #define MAX_ELEMENTS 9 -#include "application.h" + CompletionWidget::CompletionWidget( QWidget *parent) -:QFrame( parent, Qt::ToolTip) + :QFrame( parent, Qt::ToolTip) , _parent(parent) , _currentIndex(-1) { QPalette p(palette()); - p.setColor(QPalette::Background, Qt::white); //todo: choose the correct color + p.setColor(QPalette::Background, Qt::white); // TODO: choose the correct color setPalette(p); setFrameStyle(QFrame::Panel); setLayoutDirection(Qt::LeftToRight); @@ -126,10 +130,6 @@ void CompletionWidget::up() widget->activate(); } -KUrl CompletionWidget::currentUrl() -{ - return _list.at(_currentIndex).url; -} void CompletionWidget::down() { @@ -150,6 +150,7 @@ void CompletionWidget::down() widget->activate(); } + void CompletionWidget::clear() { QLayoutItem *child; @@ -216,7 +217,7 @@ bool CompletionWidget::eventFilter( QObject *o, QEvent *e ) case Qt::Key_Enter: case Qt::Key_Return: hide(); - emit chosenUrl(currentUrl().url(), Rekonq::CurrentTab); + emit chosenUrl(_list.at(_currentIndex).url, Rekonq::CurrentTab); ev->accept(); return true; break; diff --git a/src/urlbar/completionwidget.h b/src/urlbar/completionwidget.h index 64d33189..a714bb17 100644 --- a/src/urlbar/completionwidget.h +++ b/src/urlbar/completionwidget.h @@ -33,32 +33,26 @@ #include "urlresolver.h" #include "listitem.h" -// Qt Includes -#include - // KDE Includes #include -// Forward Declarations -class KUrl; +// Qt Includes +#include class CompletionWidget : public QFrame { -Q_OBJECT + Q_OBJECT public: CompletionWidget(QWidget *parent); void insertSearchList(const UrlSearchList &list); void popup(); - - void up(); - void down(); void clear(); + virtual bool eventFilter(QObject *obj, QEvent *ev); void setVisible(bool visible); - KUrl currentUrl(); private slots: void itemChosen(ListItem *item, Qt::MouseButton = Qt::LeftButton); @@ -68,7 +62,9 @@ signals: private: void sizeAndPosition(); - + void up(); + void down(); + QWidget *_parent; UrlSearchList _list; diff --git a/src/urlbar/lineedit.h b/src/urlbar/lineedit.h index d76a5fcb..67ded052 100644 --- a/src/urlbar/lineedit.h +++ b/src/urlbar/lineedit.h @@ -47,12 +47,9 @@ public: explicit LineEdit(QWidget *parent = 0); virtual ~LineEdit(); - protected: virtual void keyPressEvent(QKeyEvent*); virtual void mouseDoubleClickEvent(QMouseEvent *); - - }; #endif // LINEEDIT_H 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); } - diff --git a/src/urlbar/listitem.h b/src/urlbar/listitem.h index ac476d4b..1e7b0805 100644 --- a/src/urlbar/listitem.h +++ b/src/urlbar/listitem.h @@ -34,7 +34,7 @@ class UrlSearchItem; class ListItem : public QWidget { -Q_OBJECT + Q_OBJECT public: ListItem(const UrlSearchItem &item, QWidget *parent = 0); @@ -55,5 +55,4 @@ protected: private: QStyleOptionViewItemV4 m_option; QString guessNameFromUrl(QUrl url); - }; diff --git a/src/urlbar/urlresolver.h b/src/urlbar/urlresolver.h index 4231aaab..3033fc38 100644 --- a/src/urlbar/urlresolver.h +++ b/src/urlbar/urlresolver.h @@ -32,8 +32,6 @@ #include #include -// Forward Declarations -class KUrl; class UrlSearchItem { -- cgit v1.2.1 From 45acb07245d52a51e5b486eaab3c4fdddc2ccbad Mon Sep 17 00:00:00 2001 From: lionelc Date: Tue, 30 Mar 2010 11:01:44 +0200 Subject: display bookmark and history item only if string typed is longer than 3 chars --- src/urlbar/urlresolver.cpp | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) (limited to 'src/urlbar') diff --git a/src/urlbar/urlresolver.cpp b/src/urlbar/urlresolver.cpp index cb61ad95..5593f566 100644 --- a/src/urlbar/urlresolver.cpp +++ b/src/urlbar/urlresolver.cpp @@ -81,23 +81,26 @@ UrlSearchList UrlResolver::orderedSearchItems() list << qurlFromUserInputResolution(); } - int firstResults = list.count(); - int checkPoint = 9 - firstResults; - - UrlSearchList historyList = historyResolution(); - int historyResults = historyList.count(); - - UrlSearchList bookmarksList = bookmarksResolution(); - int bookmarkResults = bookmarksList.count(); - - if(historyResults + bookmarkResults > checkPoint) + if (_urlString.length()>2) { - historyList = historyList.mid(0,3); - bookmarksList = bookmarksList.mid(0,3); + int firstResults = list.count(); + int checkPoint = 9 - firstResults; + + UrlSearchList historyList = historyResolution(); + int historyResults = historyList.count(); + + UrlSearchList bookmarksList = bookmarksResolution(); + int bookmarkResults = bookmarksList.count(); + + if(historyResults + bookmarkResults > checkPoint) + { + historyList = historyList.mid(0,3); + bookmarksList = bookmarksList.mid(0,3); + } + list << historyList; + list << bookmarksList; } - list << historyList; - list << bookmarksList; - + return list; } -- cgit v1.2.1 From a2cb9efc54c78c47e41196f0121ca00255a4a7ab Mon Sep 17 00:00:00 2001 From: lionelc Date: Tue, 30 Mar 2010 11:37:25 +0200 Subject: add title for history items --- src/urlbar/urlresolver.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/urlbar') diff --git a/src/urlbar/urlresolver.cpp b/src/urlbar/urlresolver.cpp index 5593f566..3877a6c2 100644 --- a/src/urlbar/urlresolver.cpp +++ b/src/urlbar/urlresolver.cpp @@ -181,7 +181,7 @@ UrlSearchList UrlResolver::historyResolution() QStringList historyResults = historyCompletion->substringCompletion(_urlString); Q_FOREACH(const QString &s, historyResults) { - UrlSearchItem it(s, s, QString("view-history")); + UrlSearchItem it(s, Application::historyManager()->titleForHistoryUrl(s), QString("view-history")); list << it; } -- cgit v1.2.1 From a2aa033e21d1746b5479836e8d8363dcb4654d8a Mon Sep 17 00:00:00 2001 From: lionelc Date: Tue, 30 Mar 2010 19:45:27 +0200 Subject: manage common item of bookmarks and history --- src/urlbar/urlresolver.cpp | 27 +++++++++++++++++++++++++-- src/urlbar/urlresolver.h | 2 ++ 2 files changed, 27 insertions(+), 2 deletions(-) (limited to 'src/urlbar') diff --git a/src/urlbar/urlresolver.cpp b/src/urlbar/urlresolver.cpp index 3877a6c2..ef071c30 100644 --- a/src/urlbar/urlresolver.cpp +++ b/src/urlbar/urlresolver.cpp @@ -53,6 +53,10 @@ // 4 ."kuriikwsfilter" // 5. "fixhosturifilter" +bool UrlSearchItem::operator==(UrlSearchItem i) +{ + return url==i.url; +} UrlResolver::UrlResolver(const QString &typedUrl) : _urlString(typedUrl) @@ -97,8 +101,27 @@ UrlSearchList UrlResolver::orderedSearchItems() historyList = historyList.mid(0,3); bookmarksList = bookmarksList.mid(0,3); } - list << historyList; - list << bookmarksList; + + QList common; + + foreach (UrlSearchItem i, historyList) + { + if (!bookmarksList.contains(i)) + list << i; + else + common << i; + } + + foreach (UrlSearchItem i, common) + { + list << i; + } + + foreach (UrlSearchItem i, bookmarksList) + { + if (!common.contains(i)) + list << i; + } } return list; diff --git a/src/urlbar/urlresolver.h b/src/urlbar/urlresolver.h index 3033fc38..54b96d63 100644 --- a/src/urlbar/urlresolver.h +++ b/src/urlbar/urlresolver.h @@ -43,6 +43,8 @@ public: UrlSearchItem(const QString &_url, const QString &_title = QString(), const QString &_icon = QString()) : url(_url), title(_title), icon(_icon) {}; + + bool operator==(UrlSearchItem i); }; typedef QList UrlSearchList; -- 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/completionwidget.cpp | 13 ++----- src/urlbar/listitem.cpp | 80 ++++++++++++++++++++++++++++++----------- src/urlbar/listitem.h | 2 ++ src/urlbar/urlresolver.cpp | 16 ++++++--- src/urlbar/urlresolver.h | 20 ++++++++--- 5 files changed, 92 insertions(+), 39 deletions(-) (limited to 'src/urlbar') 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 #include -// 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; isetObjectName( 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 #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) { 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 +#include #include // 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 #include +#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); -- cgit v1.2.1 From ce03d5d4687f7d789ddfacdd51c4281eb9193487 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Fri, 2 Apr 2010 22:10:24 +0200 Subject: hide suggestions on ESC key --- src/urlbar/urlbar.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/urlbar') diff --git a/src/urlbar/urlbar.cpp b/src/urlbar/urlbar.cpp index a04d6534..0dc91a1e 100644 --- a/src/urlbar/urlbar.cpp +++ b/src/urlbar/urlbar.cpp @@ -232,6 +232,12 @@ QSize UrlBar::sizeHint() const void UrlBar::keyPressEvent(QKeyEvent *event) { + if(event->key() == Qt::Key_Escape) + { + m_box->hide(); + return; + } + // this handles the Modifiers + Return key combinations QString currentText = m_lineEdit->text().trimmed(); if ((event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) -- cgit v1.2.1 From 352168759ea96b35296eaf33790fbe073b69f69b Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Mon, 5 Apr 2010 01:31:13 +0200 Subject: This commit is the first implementation of a new new new urlbar Here are its features: - KLineEdit based - ability to easily add "icons" :) - SSL informations shown (a-la firefox) - smoother animation - cleaner code - data QString, not KUrl based (Users type string, not urls!!!) --- src/urlbar/iconbutton.cpp | 76 +++++++++++++++++ src/urlbar/iconbutton.h | 51 ++++++++++++ src/urlbar/lineedit.cpp | 71 +++++++++++++++- src/urlbar/lineedit.h | 19 ++++- src/urlbar/urlbar.cpp | 208 +++++++++++++++++----------------------------- src/urlbar/urlbar.h | 20 ++--- 6 files changed, 296 insertions(+), 149 deletions(-) create mode 100644 src/urlbar/iconbutton.cpp create mode 100644 src/urlbar/iconbutton.h (limited to 'src/urlbar') diff --git a/src/urlbar/iconbutton.cpp b/src/urlbar/iconbutton.cpp new file mode 100644 index 00000000..60008993 --- /dev/null +++ b/src/urlbar/iconbutton.cpp @@ -0,0 +1,76 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2010 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 "iconbutton.h" +#include "iconbutton.moc" + +// Local Includes +#include "application.h" + +// KDE Includes +#include + + +IconButton::IconButton(QWidget *parent) + : QToolButton(parent) +{ + QPalette p = palette(); + p.setColor( QPalette::Button, Qt::transparent ); + setPalette(p); + + setCursor(Qt::ArrowCursor); + setStyleSheet("IconButton { border: none; padding: 0px}"); +} + + +void IconButton::setIconUrl(const KUrl &url, bool trusted) +{ + setToolButtonStyle(Qt::ToolButtonTextBesideIcon); + setIcon( Application::icon(url) ); + setText( url.host() ); + + if(trusted) + { + setStyleSheet("IconButton { background-color:#0F0; padding: 2px }"); + } + else + { + setStyleSheet("IconButton { background-color:#F00; padding: 2px}"); + } + + adjustSize(); +} + + +void IconButton::updateIcon(KIcon icon) +{ + setToolButtonStyle(Qt::ToolButtonIconOnly); + setIcon( icon ); + + setStyleSheet("IconButton { background-color:transparent; border: none; padding: 0px}"); + adjustSize(); +} diff --git a/src/urlbar/iconbutton.h b/src/urlbar/iconbutton.h new file mode 100644 index 00000000..b66e212b --- /dev/null +++ b/src/urlbar/iconbutton.h @@ -0,0 +1,51 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2010 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 . +* +* ============================================================ */ + + + +#ifndef ICON_BUTTON_H +#define ICON_BUTTON_H + + +// KDE Includes +#include +#include + +// Qt Includes +#include + + +class IconButton : public QToolButton +{ + Q_OBJECT + +public: + IconButton(QWidget *parent = 0); + + void setIconUrl(const KUrl &url, bool trusted); + void updateIcon(KIcon icon); +}; + +#endif // ICON_BUTTON_H diff --git a/src/urlbar/lineedit.cpp b/src/urlbar/lineedit.cpp index ac92b858..f7af1f61 100644 --- a/src/urlbar/lineedit.cpp +++ b/src/urlbar/lineedit.cpp @@ -30,24 +30,64 @@ #include "lineedit.h" #include "lineedit.moc" +// KDE Includes +#include +#include + // Qt Includes #include #include #include +#include +#include LineEdit::LineEdit(QWidget* parent) - : KLineEdit(parent) + : KLineEdit(parent) + , _icon( new IconButton(this) ) { + // cosmetic + setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); setMinimumWidth(200); - setFocusPolicy(Qt::WheelFocus); - setHandleSignals(true); + setMinimumHeight(26); + updateStyles(); + + // doesn't show the clear button setClearButtonShown(false); + + // trap Key_Enter & Key_Return events, while emitting the returnPressed signal + setTrapReturnKey(true); + + // insert decoded URLs + setUrlDropsEnabled(true); + + // accept focus, via tabbing, clicking & wheeling + setFocusPolicy(Qt::WheelFocus); + + // disable completion object (we have our own :) ) + setCompletionObject(0); } LineEdit::~LineEdit() { + delete _icon; +} + + +void LineEdit::updateStyles() +{ + adjustSize(); + _icon->adjustSize(); + if(_icon->toolButtonStyle() == Qt::ToolButtonIconOnly) + _icon->move( 4, 3); + else + _icon->move( 2, 1); + + int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth); + setStyleSheet(QString("LineEdit { padding-left: %1px; } ").arg(_icon->sizeHint().width() + frameWidth + 1)); + + update(); } @@ -67,3 +107,28 @@ void LineEdit::mouseDoubleClickEvent(QMouseEvent *) { selectAll(); } + + +IconButton *LineEdit::iconButton() const +{ + return _icon; +} + + +void LineEdit::paintEvent(QPaintEvent *event) +{ + KLineEdit::paintEvent(event); + + if (text().isEmpty() && !hasFocus()) + { + QStyleOptionFrame option; + initStyleOption(&option); + QRect textRect = style()->subElementRect(QStyle::SE_LineEditContents, &option, this); + QPainter painter(this); + painter.setPen(Qt::gray); + painter.drawText( textRect, + Qt::AlignLeft | Qt::AlignVCenter, + i18n("Search Bookmarks, History, Google.. and the Kitchen Sink!") + ); + } +} diff --git a/src/urlbar/lineedit.h b/src/urlbar/lineedit.h index 67ded052..96f25918 100644 --- a/src/urlbar/lineedit.h +++ b/src/urlbar/lineedit.h @@ -30,13 +30,20 @@ #define LINEEDIT_H +// Local Includes +#include "iconbutton.h" + // KDE Includes #include +#include + +#include // Forward Declarations class QContextMenuEvent; class QFocusEvent; class QKeyEvent; +class QStyleOptionFrameV2; class LineEdit : public KLineEdit @@ -46,10 +53,18 @@ class LineEdit : public KLineEdit public: explicit LineEdit(QWidget *parent = 0); virtual ~LineEdit(); - + + IconButton *iconButton() const; + + void updateStyles(); + protected: - virtual void keyPressEvent(QKeyEvent*); + virtual void keyPressEvent(QKeyEvent *); virtual void mouseDoubleClickEvent(QMouseEvent *); + virtual void paintEvent(QPaintEvent *); + +private: + IconButton *_icon; }; #endif // LINEEDIT_H diff --git a/src/urlbar/urlbar.cpp b/src/urlbar/urlbar.cpp index 0dc91a1e..dd14a4a3 100644 --- a/src/urlbar/urlbar.cpp +++ b/src/urlbar/urlbar.cpp @@ -50,124 +50,59 @@ #include #include +// Defines +#define QL1S(x) QLatin1String(x) + UrlBar::UrlBar(QWidget *parent) - : KComboBox(true, parent) - , m_lineEdit(new LineEdit) - , m_box(new CompletionWidget(this)) + : LineEdit(parent) + , _box(new CompletionWidget(this)) , _tab(0) , _privateMode(false) { - //cosmetic - setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); - setMinimumWidth(180); - - // signal handlings - setTrapReturnKey(true); - setUrlDropsEnabled(true); - - // Make m_lineEdit background transparent - QPalette p = m_lineEdit->palette(); - p.setColor(QPalette::Base, Qt::transparent); - m_lineEdit->setPalette(p); - - setLineEdit(m_lineEdit); - - // clear the URL bar - m_lineEdit->clear(); // load urls on activated urlbar signal - connect(this, SIGNAL(returnPressed(const QString&)), SLOT(activated(const QString&))); - - installEventFilter(m_box); - connect(m_box, SIGNAL(chosenUrl(const QString&, Rekonq::OpenType)), SLOT(activated(const QString&, Rekonq::OpenType))); -} - - -UrlBar::~UrlBar() -{ -} + connect(this, SIGNAL(returnPressed(const QString&)), this, SLOT(activated(const QString&))); - -void UrlBar::selectAll() const -{ - m_lineEdit->selectAll(); + // suggestions + installEventFilter(_box); + connect(_box, SIGNAL(chosenUrl(const QString&, Rekonq::OpenType)), SLOT(activated(const QString&, Rekonq::OpenType))); } -KUrl UrlBar::url() const +UrlBar::~UrlBar() { - return m_currentUrl; + delete _box; } -void UrlBar::setUrl(const QUrl& url) +void UrlBar::setQUrl(const QUrl& url) { - if(url.scheme() == "about") + if(url.scheme() == QL1S("about") ) { - m_currentUrl = KUrl(); - updateUrl(); + iconButton()->updateIcon( KIcon("arrow-right") ); setFocus(); } else { - m_currentUrl = KUrl(url); - updateUrl(); + LineEdit::setUrl(url); + setCursorPosition(0); + iconButton()->updateIcon( Application::icon(url) ); } -} - - -void UrlBar::updateUrl() -{ - // Don't change my typed url... - // FIXME this is not a proper solution (also if it works...) - if(hasFocus()) - { - kDebug() << "Don't change my typed url..."; - return; - } - - KIcon icon; - if(m_currentUrl.isEmpty()) - { - icon = KIcon("arrow-right"); - } - else - { - icon = Application::icon(m_currentUrl); - } - - if (count()) - { - changeUrl(0, icon, m_currentUrl); - } - else - { - insertUrl(0, icon, m_currentUrl); - } - - setCurrentIndex(0); - - // important security consideration: always display the beginning - // of the url rather than its end to prevent spoofing attempts. - // Must be AFTER setCurrentIndex - if (!hasFocus()) - { - m_lineEdit->setCursorPosition(0); - } + updateStyles(); } void UrlBar::activated(const QString& urlString, Rekonq::OpenType type) { - disconnect(this, SIGNAL(editTextChanged(const QString &)), this, SLOT(suggestUrls(const QString &))); + disconnect(this, SIGNAL(textChanged(const QString &)), this, SLOT(suggestUrls(const QString &))); if (urlString.isEmpty()) return; clearFocus(); - setUrl(urlString); - Application::instance()->loadUrl(m_currentUrl, type); + setText(urlString); + Application::instance()->loadUrl(urlString, type); } @@ -185,17 +120,16 @@ void UrlBar::paintEvent(QPaintEvent *event) // set background color of UrlBar QPalette p = palette(); - p.setColor(QPalette::Base, backgroundColor); - setPalette(p); - KComboBox::paintEvent(event); - - if (!hasFocus()) + int progr = _tab->progress(); + if (progr == 0) + { + p.setBrush(QPalette::Base, backgroundColor); + } + else { - QPainter painter(this); - QColor loadingColor; - if (m_currentUrl.scheme() == QLatin1String("https")) + if ( _tab->url().scheme() == QLatin1String("https")) { loadingColor = QColor(248, 248, 100); } @@ -203,30 +137,16 @@ void UrlBar::paintEvent(QPaintEvent *event) { loadingColor = QColor(116, 192, 250); } - int progr = _tab->progress(); - - backgroundColor.setAlpha(0); - backgroundColor.setAlpha(200); - QLinearGradient gradient(0, 0, width(), height() ); + + + QLinearGradient gradient(0, 0, width(), 0); gradient.setColorAt(0, loadingColor); gradient.setColorAt(((double)progr)/100, backgroundColor); - - painter.setBrush( gradient ); - painter.setPen(Qt::transparent); - - - QRect backgroundRect = m_lineEdit->frameGeometry(); - int mid = backgroundRect.width() * progr / 100; - QRect progressRect(backgroundRect.x(), backgroundRect.y(), mid, backgroundRect.height()); - painter.drawRect(progressRect); - painter.end(); + p.setBrush(QPalette::Base, gradient); } -} - - -QSize UrlBar::sizeHint() const -{ - return m_lineEdit->sizeHint(); + setPalette(p); + + LineEdit::paintEvent(event); } @@ -234,12 +154,12 @@ void UrlBar::keyPressEvent(QKeyEvent *event) { if(event->key() == Qt::Key_Escape) { - m_box->hide(); + _box->hide(); return; } // this handles the Modifiers + Return key combinations - QString currentText = m_lineEdit->text().trimmed(); + QString currentText = text().trimmed(); if ((event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) && !currentText.startsWith(QLatin1String("http://"), Qt::CaseInsensitive)) { @@ -263,11 +183,11 @@ void UrlBar::keyPressEvent(QKeyEvent *event) { host += append; url.setHost(host); - m_lineEdit->setText(url.toString()); + setText(url.toString()); } } - KComboBox::keyPressEvent(event); + LineEdit::keyPressEvent(event); } @@ -280,7 +200,7 @@ void UrlBar::suggestUrls(const QString &text) if(text.isEmpty()) { - m_box->hide(); + _box->hide(); return; } @@ -289,31 +209,41 @@ void UrlBar::suggestUrls(const QString &text) if(list.count() > 0) { - m_box->clear(); - m_box->insertSearchList(list); - m_box->popup(); + _box->clear(); + _box->insertSearchList(list); + _box->popup(); } } + void UrlBar::focusInEvent(QFocusEvent *event) { // activate suggestions on edit text - connect(this, SIGNAL(editTextChanged(const QString &)), this, SLOT(suggestUrls(const QString &))); + connect(this, SIGNAL(textChanged(const QString &)), this, SLOT(suggestUrls(const QString &))); - KComboBox::focusInEvent(event); + LineEdit::focusInEvent(event); } void UrlBar::setCurrentTab(WebTab *tab) { if(_tab) - disconnect(_tab->view(), SIGNAL(urlChanged(const QUrl &)), this, SLOT(setUrl(const QUrl &))); + { + disconnect(_tab->view(), SIGNAL(urlChanged(const QUrl &)), this, SLOT(setQUrl(const QUrl &))); + disconnect(_tab->view(), SIGNAL(loadFinished(bool)), this, SLOT(loadFinished())); + disconnect(_tab->page(), SIGNAL(validSSLInfo(bool)), this, SLOT(setTrustedHost(bool))); + disconnect(iconButton(), SIGNAL(clicked()), _tab->page(), SLOT(showSSLInfo())); + } _tab = tab; - connect(_tab->view(), SIGNAL(urlChanged(const QUrl &)), this, SLOT(setUrl(const QUrl &))); - + connect(_tab->view(), SIGNAL(urlChanged(const QUrl &)), this, SLOT(setQUrl(const QUrl &))); + connect(_tab->view(), SIGNAL(loadFinished(bool)), this, SLOT(loadFinished())); + connect(_tab->page(), SIGNAL(validSSLInfo(bool)), this, SLOT(setTrustedHost(bool))); + connect(iconButton(), SIGNAL(clicked()), _tab->page(), SLOT(showSSLInfo())); + // update it now (the first time) - setUrl( _tab->url() ); - update(); + updateStyles(); + _tab->view()->setFocus(); + setQUrl( _tab->url() ); } @@ -321,3 +251,21 @@ void UrlBar::setPrivateMode(bool on) { _privateMode = on; } + + +void UrlBar::loadFinished() +{ + // show RSS + + // show KGet downloads?? + + // last, but not least + updateStyles(); +} + + +void UrlBar::setTrustedHost(bool on) +{ + kDebug() << "SET TRUSTED HOST.."; + iconButton()->setIconUrl( _tab->url() , on ); +} diff --git a/src/urlbar/urlbar.h b/src/urlbar/urlbar.h index 991b9038..848073db 100644 --- a/src/urlbar/urlbar.h +++ b/src/urlbar/urlbar.h @@ -49,7 +49,7 @@ class QLinearGradient; class QWidget; -class UrlBar : public KComboBox +class UrlBar : public LineEdit { Q_OBJECT @@ -57,32 +57,24 @@ public: UrlBar(QWidget *parent = 0); ~UrlBar(); - void selectAll() const; - KUrl url() const; - QSize sizeHint() const; - void setCurrentTab(WebTab *); void setPrivateMode(bool on); - -public slots: - void setUrl(const QUrl &url); - void updateUrl(); private slots: void activated(const QString& url, Rekonq::OpenType = Rekonq::CurrentTab); void suggestUrls(const QString &editedText); + void setQUrl(const QUrl &url); + void loadFinished(); + void setTrustedHost(bool on); + protected: virtual void paintEvent(QPaintEvent *event); virtual void keyPressEvent(QKeyEvent *event); virtual void focusInEvent(QFocusEvent *event); private: - LineEdit *m_lineEdit; - - KUrl m_currentUrl; - - CompletionWidget *m_box; + CompletionWidget *_box; WebTab *_tab; bool _privateMode; }; -- cgit v1.2.1 From 817500ffb63a26e534edff7524e8c2988e851506 Mon Sep 17 00:00:00 2001 From: Yoann Laissus Date: Mon, 5 Apr 2010 13:46:34 +0200 Subject: Load the url when an url is dropped onto the urlbar --- src/urlbar/urlbar.cpp | 7 +++++++ src/urlbar/urlbar.h | 1 + 2 files changed, 8 insertions(+) (limited to 'src/urlbar') diff --git a/src/urlbar/urlbar.cpp b/src/urlbar/urlbar.cpp index dd14a4a3..35934bf4 100644 --- a/src/urlbar/urlbar.cpp +++ b/src/urlbar/urlbar.cpp @@ -269,3 +269,10 @@ void UrlBar::setTrustedHost(bool on) kDebug() << "SET TRUSTED HOST.."; iconButton()->setIconUrl( _tab->url() , on ); } + + +void UrlBar::dropEvent(QDropEvent *event) +{ + LineEdit::dropEvent(event); + activated(text()); +} diff --git a/src/urlbar/urlbar.h b/src/urlbar/urlbar.h index 848073db..3b28fb3a 100644 --- a/src/urlbar/urlbar.h +++ b/src/urlbar/urlbar.h @@ -72,6 +72,7 @@ protected: virtual void paintEvent(QPaintEvent *event); virtual void keyPressEvent(QKeyEvent *event); virtual void focusInEvent(QFocusEvent *event); + virtual void dropEvent(QDropEvent *event); private: CompletionWidget *_box; -- cgit v1.2.1 From 43dc2695d62fd2e4fc01aff608bb2af3e8335040 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Thu, 8 Apr 2010 02:53:38 +0200 Subject: This is a really big commit, implementing the new urlbar - removed previous SSL animation, we have now a nice yellow lock :) - faster and cleaner animations - reenabled the old stacked widget, to avoid stupid refreshes and fix some regressions - implemented some "right icons": KGet, SSL, RSS. For now, just SSL is full featured - clean up the box :) Some old & unuseful files removed, some icons added - Pano's request: grey text shown everytime in the empty bar Again and again: this is not the first, but the second implementation of the new urlbar UI. About me this is clearly better than the first or the previous. But it needs love :D BUG: 230125 BUG: 231015 CCBUG: 228040 BUG: 227272 --- src/urlbar/iconbutton.cpp | 76 --------------------------------- src/urlbar/iconbutton.h | 51 ----------------------- src/urlbar/lineedit.cpp | 97 ++++++++++++++++++++++++++++++++---------- src/urlbar/lineedit.h | 36 +++++++++++++--- src/urlbar/urlbar.cpp | 104 +++++++++++++++++++++++----------------------- src/urlbar/urlbar.h | 2 - 6 files changed, 157 insertions(+), 209 deletions(-) delete mode 100644 src/urlbar/iconbutton.cpp delete mode 100644 src/urlbar/iconbutton.h (limited to 'src/urlbar') diff --git a/src/urlbar/iconbutton.cpp b/src/urlbar/iconbutton.cpp deleted file mode 100644 index 60008993..00000000 --- a/src/urlbar/iconbutton.cpp +++ /dev/null @@ -1,76 +0,0 @@ -/* ============================================================ -* -* This file is a part of the rekonq project -* -* Copyright (C) 2010 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 "iconbutton.h" -#include "iconbutton.moc" - -// Local Includes -#include "application.h" - -// KDE Includes -#include - - -IconButton::IconButton(QWidget *parent) - : QToolButton(parent) -{ - QPalette p = palette(); - p.setColor( QPalette::Button, Qt::transparent ); - setPalette(p); - - setCursor(Qt::ArrowCursor); - setStyleSheet("IconButton { border: none; padding: 0px}"); -} - - -void IconButton::setIconUrl(const KUrl &url, bool trusted) -{ - setToolButtonStyle(Qt::ToolButtonTextBesideIcon); - setIcon( Application::icon(url) ); - setText( url.host() ); - - if(trusted) - { - setStyleSheet("IconButton { background-color:#0F0; padding: 2px }"); - } - else - { - setStyleSheet("IconButton { background-color:#F00; padding: 2px}"); - } - - adjustSize(); -} - - -void IconButton::updateIcon(KIcon icon) -{ - setToolButtonStyle(Qt::ToolButtonIconOnly); - setIcon( icon ); - - setStyleSheet("IconButton { background-color:transparent; border: none; padding: 0px}"); - adjustSize(); -} diff --git a/src/urlbar/iconbutton.h b/src/urlbar/iconbutton.h deleted file mode 100644 index b66e212b..00000000 --- a/src/urlbar/iconbutton.h +++ /dev/null @@ -1,51 +0,0 @@ -/* ============================================================ -* -* This file is a part of the rekonq project -* -* Copyright (C) 2010 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 . -* -* ============================================================ */ - - - -#ifndef ICON_BUTTON_H -#define ICON_BUTTON_H - - -// KDE Includes -#include -#include - -// Qt Includes -#include - - -class IconButton : public QToolButton -{ - Q_OBJECT - -public: - IconButton(QWidget *parent = 0); - - void setIconUrl(const KUrl &url, bool trusted); - void updateIcon(KIcon icon); -}; - -#endif // ICON_BUTTON_H diff --git a/src/urlbar/lineedit.cpp b/src/urlbar/lineedit.cpp index f7af1f61..8e689a46 100644 --- a/src/urlbar/lineedit.cpp +++ b/src/urlbar/lineedit.cpp @@ -33,6 +33,8 @@ // KDE Includes #include #include +#include +#include // Qt Includes #include @@ -42,6 +44,18 @@ #include +IconButton::IconButton(QWidget *parent) + : QToolButton(parent) +{ + setToolButtonStyle(Qt::ToolButtonIconOnly); + setStyleSheet("IconButton { background-color:transparent; border: none; padding: 0px}"); + setCursor(Qt::ArrowCursor); +} + + +// ----------------------------------------------------------------------------------------------------------- + + LineEdit::LineEdit(QWidget* parent) : KLineEdit(parent) , _icon( new IconButton(this) ) @@ -49,8 +63,11 @@ LineEdit::LineEdit(QWidget* parent) // cosmetic setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); setMinimumWidth(200); - setMinimumHeight(26); - updateStyles(); + setMinimumHeight(20); + + // initial style + _icon->move(4,6); + setStyleSheet( QString("LineEdit { padding: 0 0 0 %1px;} ").arg(_icon->sizeHint().width()) ); // doesn't show the clear button setClearButtonShown(false); @@ -75,22 +92,6 @@ LineEdit::~LineEdit() } -void LineEdit::updateStyles() -{ - adjustSize(); - _icon->adjustSize(); - if(_icon->toolButtonStyle() == Qt::ToolButtonIconOnly) - _icon->move( 4, 3); - else - _icon->move( 2, 1); - - int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth); - setStyleSheet(QString("LineEdit { padding-left: %1px; } ").arg(_icon->sizeHint().width() + frameWidth + 1)); - - update(); -} - - void LineEdit::keyPressEvent(QKeyEvent *event) { if (event->key() == Qt::Key_Escape) @@ -117,18 +118,70 @@ IconButton *LineEdit::iconButton() const void LineEdit::paintEvent(QPaintEvent *event) { + // you need this before our code to draw inside the line edit.. KLineEdit::paintEvent(event); - if (text().isEmpty() && !hasFocus()) - { + if (text().isEmpty()) + { QStyleOptionFrame option; initStyleOption(&option); QRect textRect = style()->subElementRect(QStyle::SE_LineEditContents, &option, this); QPainter painter(this); painter.setPen(Qt::gray); painter.drawText( textRect, - Qt::AlignLeft | Qt::AlignVCenter, - i18n("Search Bookmarks, History, Google.. and the Kitchen Sink!") + Qt::AlignCenter, + i18n("Search Bookmarks, History, Google.. just start typing here!") ); } } + + +IconButton *LineEdit::addRightIcon(LineEdit::icon ic) +{ + IconButton *rightIcon = new IconButton(this); + + switch(ic) + { + case LineEdit::KGet: + rightIcon->setIcon( QIcon(KStandardDirs::locate("data", "rekonq/pics/kget-icon.png")) ); + break; + case LineEdit::RSS: + rightIcon->setIcon( QIcon(KStandardDirs::locate("data", "rekonq/pics/rss-icon.png")) ); + break; + case LineEdit::SSL: + rightIcon->setIcon( QIcon(KStandardDirs::locate("data", "rekonq/pics/ssl-icon.png")) ); + break; + default: + kDebug() << "ERROR.. default non extant case!!"; + break; + } + + _rightIconsList << rightIcon; + int iconsCount = _rightIconsList.count(); + rightIcon->move( width() - 23*iconsCount, 6); + rightIcon->show(); + + return rightIcon; +} + + +void LineEdit::clearRightIcons() +{ + qDeleteAll(_rightIconsList); + _rightIconsList.clear(); +} + + +void LineEdit::resizeEvent(QResizeEvent *event) +{ + KLineEdit::resizeEvent(event); + + int iconsCount = _rightIconsList.count(); + int w = width(); + + for(int i = 0; i < iconsCount; ++i) + { + IconButton *bt = _rightIconsList.at(i); + bt->move( w - 23*(i+1), 6); + } +} diff --git a/src/urlbar/lineedit.h b/src/urlbar/lineedit.h index 96f25918..5b8ff2a3 100644 --- a/src/urlbar/lineedit.h +++ b/src/urlbar/lineedit.h @@ -30,13 +30,11 @@ #define LINEEDIT_H -// Local Includes -#include "iconbutton.h" - // KDE Includes #include #include +// Qt Includes #include // Forward Declarations @@ -46,25 +44,53 @@ class QKeyEvent; class QStyleOptionFrameV2; +class IconButton : public QToolButton +{ + Q_OBJECT + +public: + IconButton(QWidget *parent = 0); +}; + + +// ------------------------------------------------------------------------------------ + + +// Definitions +typedef QList IconButtonPointerList; + + class LineEdit : public KLineEdit { Q_OBJECT public: + + enum icon + { + KGet = 0x00000001, + RSS = 0x00000010, + SSL = 0x00000100, + }; + explicit LineEdit(QWidget *parent = 0); virtual ~LineEdit(); IconButton *iconButton() const; - void updateStyles(); + void clearRightIcons(); protected: virtual void keyPressEvent(QKeyEvent *); virtual void mouseDoubleClickEvent(QMouseEvent *); virtual void paintEvent(QPaintEvent *); + virtual void resizeEvent(QResizeEvent *); + IconButton *addRightIcon(LineEdit::icon ); + private: - IconButton *_icon; + IconButton *_icon; + IconButtonPointerList _rightIconsList; }; #endif // LINEEDIT_H diff --git a/src/urlbar/urlbar.cpp b/src/urlbar/urlbar.cpp index 35934bf4..c5201a1c 100644 --- a/src/urlbar/urlbar.cpp +++ b/src/urlbar/urlbar.cpp @@ -31,6 +31,9 @@ #include "urlbar.h" #include "urlbar.moc" +// Auto Includes +#include "rekonq.h" + // Local Includes #include "application.h" #include "lineedit.h" @@ -60,6 +63,11 @@ UrlBar::UrlBar(QWidget *parent) , _tab(0) , _privateMode(false) { + _tab = qobject_cast(parent); + + connect(_tab->view(), SIGNAL(urlChanged(const QUrl &)), this, SLOT(setQUrl(const QUrl &))); + connect(_tab->view(), SIGNAL(loadFinished(bool)), this, SLOT(loadFinished())); + // load urls on activated urlbar signal connect(this, SIGNAL(returnPressed(const QString&)), this, SLOT(activated(const QString&))); @@ -77,19 +85,21 @@ UrlBar::~UrlBar() void UrlBar::setQUrl(const QUrl& url) { + // find a better place? Ideally a loadStarted connected slot.. + clearRightIcons(); + if(url.scheme() == QL1S("about") ) { - iconButton()->updateIcon( KIcon("arrow-right") ); + iconButton()->setIcon( KIcon("arrow-right") ); + clear(); setFocus(); } else { LineEdit::setUrl(url); setCursorPosition(0); - iconButton()->updateIcon( Application::icon(url) ); + iconButton()->setIcon( Application::icon(url) ); } - - updateStyles(); } @@ -111,7 +121,7 @@ void UrlBar::paintEvent(QPaintEvent *event) QColor backgroundColor; if( _privateMode ) { - backgroundColor = QColor(192, 192, 192); // gray + backgroundColor = QColor(220, 220, 220); // light gray } else { @@ -124,21 +134,16 @@ void UrlBar::paintEvent(QPaintEvent *event) int progr = _tab->progress(); if (progr == 0) { + if( _tab->url().scheme() == QL1S("https") ) + { + backgroundColor = QColor(255, 255, 171); // light yellow + } p.setBrush(QPalette::Base, backgroundColor); } else { - QColor loadingColor; - if ( _tab->url().scheme() == QLatin1String("https")) - { - loadingColor = QColor(248, 248, 100); - } - else - { - loadingColor = QColor(116, 192, 250); - } - - + QColor loadingColor = QColor(116, 192, 250); + QLinearGradient gradient(0, 0, width(), 0); gradient.setColorAt(0, loadingColor); gradient.setColorAt(((double)progr)/100, backgroundColor); @@ -225,54 +230,47 @@ void UrlBar::focusInEvent(QFocusEvent *event) } -void UrlBar::setCurrentTab(WebTab *tab) +void UrlBar::setPrivateMode(bool on) { - if(_tab) - { - disconnect(_tab->view(), SIGNAL(urlChanged(const QUrl &)), this, SLOT(setQUrl(const QUrl &))); - disconnect(_tab->view(), SIGNAL(loadFinished(bool)), this, SLOT(loadFinished())); - disconnect(_tab->page(), SIGNAL(validSSLInfo(bool)), this, SLOT(setTrustedHost(bool))); - disconnect(iconButton(), SIGNAL(clicked()), _tab->page(), SLOT(showSSLInfo())); - } - _tab = tab; - connect(_tab->view(), SIGNAL(urlChanged(const QUrl &)), this, SLOT(setQUrl(const QUrl &))); - connect(_tab->view(), SIGNAL(loadFinished(bool)), this, SLOT(loadFinished())); - connect(_tab->page(), SIGNAL(validSSLInfo(bool)), this, SLOT(setTrustedHost(bool))); - connect(iconButton(), SIGNAL(clicked()), _tab->page(), SLOT(showSSLInfo())); - - // update it now (the first time) - updateStyles(); - _tab->view()->setFocus(); - setQUrl( _tab->url() ); + _privateMode = on; } -void UrlBar::setPrivateMode(bool on) +void UrlBar::dropEvent(QDropEvent *event) { - _privateMode = on; + LineEdit::dropEvent(event); + activated(text()); } void UrlBar::loadFinished() { - // show RSS + if(_tab->progress() != 0) + return; + + if(_tab->url().scheme() == QL1S("about") ) + return; // show KGet downloads?? + if(ReKonfig::kgetList()) + { + IconButton *bt = addRightIcon(LineEdit::KGet); + connect(bt, SIGNAL(clicked()), _tab->page(), SLOT(downloadAllContentsWithKGet())); + } - // last, but not least - updateStyles(); -} - - -void UrlBar::setTrustedHost(bool on) -{ - kDebug() << "SET TRUSTED HOST.."; - iconButton()->setIconUrl( _tab->url() , on ); -} - - -void UrlBar::dropEvent(QDropEvent *event) -{ - LineEdit::dropEvent(event); - activated(text()); + // show RSS + if(_tab->hasRSSInfo()) + { + IconButton *bt = addRightIcon(LineEdit::RSS); + connect(bt, SIGNAL(clicked()), _tab, SLOT(showRSSInfo())); + } + + // show SSL + if(_tab->url().scheme() == QL1S("https") ) + { + IconButton *bt = addRightIcon(LineEdit::SSL); + connect(bt, SIGNAL(clicked()), _tab->page(), SLOT(showSSLInfo())); + } + + update(); } diff --git a/src/urlbar/urlbar.h b/src/urlbar/urlbar.h index 3b28fb3a..2536c27b 100644 --- a/src/urlbar/urlbar.h +++ b/src/urlbar/urlbar.h @@ -57,7 +57,6 @@ public: UrlBar(QWidget *parent = 0); ~UrlBar(); - void setCurrentTab(WebTab *); void setPrivateMode(bool on); private slots: @@ -66,7 +65,6 @@ private slots: void setQUrl(const QUrl &url); void loadFinished(); - void setTrustedHost(bool on); protected: virtual void paintEvent(QPaintEvent *event); -- cgit v1.2.1 From 49faf17ac19b0ff351f7c7812e8d1f85d7cf82fc Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Fri, 9 Apr 2010 01:09:17 +0200 Subject: Using oxygen icons, removing the other ones and adding some tooltips there :) --- src/urlbar/lineedit.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/urlbar') diff --git a/src/urlbar/lineedit.cpp b/src/urlbar/lineedit.cpp index 8e689a46..059a0178 100644 --- a/src/urlbar/lineedit.cpp +++ b/src/urlbar/lineedit.cpp @@ -143,13 +143,16 @@ IconButton *LineEdit::addRightIcon(LineEdit::icon ic) switch(ic) { case LineEdit::KGet: - rightIcon->setIcon( QIcon(KStandardDirs::locate("data", "rekonq/pics/kget-icon.png")) ); + rightIcon->setIcon( KIcon("download") ); + rightIcon->setToolTip( i18n("List all links with KGet") ); break; case LineEdit::RSS: - rightIcon->setIcon( QIcon(KStandardDirs::locate("data", "rekonq/pics/rss-icon.png")) ); + rightIcon->setIcon( KIcon("application-rss+xml") ); + rightIcon->setToolTip( i18n("List all available RSS feeds") ); break; case LineEdit::SSL: - rightIcon->setIcon( QIcon(KStandardDirs::locate("data", "rekonq/pics/ssl-icon.png")) ); + rightIcon->setIcon( KIcon("object-locked") ); + rightIcon->setToolTip( i18n("Show SSL Infos") ); break; default: kDebug() << "ERROR.. default non extant case!!"; -- cgit v1.2.1 From 7fedb0bcaf32ca5cb1de9e4815de08df7098426b Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Fri, 9 Apr 2010 02:06:33 +0200 Subject: Fixing icons position and saving a couple of moveEvents --- src/urlbar/lineedit.cpp | 11 +++++++---- src/urlbar/urlbar.cpp | 3 +++ 2 files changed, 10 insertions(+), 4 deletions(-) (limited to 'src/urlbar') diff --git a/src/urlbar/lineedit.cpp b/src/urlbar/lineedit.cpp index 059a0178..09c158fa 100644 --- a/src/urlbar/lineedit.cpp +++ b/src/urlbar/lineedit.cpp @@ -63,10 +63,9 @@ LineEdit::LineEdit(QWidget* parent) // cosmetic setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); setMinimumWidth(200); - setMinimumHeight(20); + setMinimumHeight(26); // initial style - _icon->move(4,6); setStyleSheet( QString("LineEdit { padding: 0 0 0 %1px;} ").arg(_icon->sizeHint().width()) ); // doesn't show the clear button @@ -177,7 +176,8 @@ void LineEdit::clearRightIcons() void LineEdit::resizeEvent(QResizeEvent *event) { - KLineEdit::resizeEvent(event); + int newHeight = ( height() - 19 )/2; + _icon->move(4, newHeight ); int iconsCount = _rightIconsList.count(); int w = width(); @@ -185,6 +185,9 @@ void LineEdit::resizeEvent(QResizeEvent *event) for(int i = 0; i < iconsCount; ++i) { IconButton *bt = _rightIconsList.at(i); - bt->move( w - 23*(i+1), 6); + bt->move( w - 25*(i+1), newHeight ); } + + KLineEdit::resizeEvent(event); + } diff --git a/src/urlbar/urlbar.cpp b/src/urlbar/urlbar.cpp index c5201a1c..adc011f0 100644 --- a/src/urlbar/urlbar.cpp +++ b/src/urlbar/urlbar.cpp @@ -249,7 +249,10 @@ void UrlBar::loadFinished() return; if(_tab->url().scheme() == QL1S("about") ) + { + update(); return; + } // show KGet downloads?? if(ReKonfig::kgetList()) -- cgit v1.2.1 From 23d65a3a5c1e6c0e2501d41ae0660c89085dbb84 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Sat, 10 Apr 2010 00:35:01 +0200 Subject: Fix focus problems and trim search strings (fix encodings problems, step 1) --- src/urlbar/urlbar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/urlbar') diff --git a/src/urlbar/urlbar.cpp b/src/urlbar/urlbar.cpp index adc011f0..6f916482 100644 --- a/src/urlbar/urlbar.cpp +++ b/src/urlbar/urlbar.cpp @@ -112,7 +112,7 @@ void UrlBar::activated(const QString& urlString, Rekonq::OpenType type) clearFocus(); setText(urlString); - Application::instance()->loadUrl(urlString, type); + Application::instance()->loadUrl(urlString.trimmed(), type); } -- cgit v1.2.1 From 138801dfa40b1bbbbbf0ce6a5bd8e04977b9ccdc Mon Sep 17 00:00:00 2001 From: pano Date: Sun, 11 Apr 2010 12:55:15 +0200 Subject: fix strings --- src/urlbar/urlresolver.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/urlbar') diff --git a/src/urlbar/urlresolver.cpp b/src/urlbar/urlresolver.cpp index ff90ce14..5f025cb5 100644 --- a/src/urlbar/urlresolver.cpp +++ b/src/urlbar/urlresolver.cpp @@ -187,12 +187,12 @@ 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; + QString gTitle = i18n("Search Google for %1", url1); 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); -// QString wTitle = i18n("Search Wikipedia for ") + url1; +// QString wTitle = i18n("Search Wikipedia for %1", url1); // UrlSearchItem wItem(wUrl, wTitle, QString("http://wikipedia.org") ); // list << wItem; } -- 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/completionwidget.h | 2 +- src/urlbar/listitem.cpp | 57 +++++++++++++++++-------------------------- src/urlbar/listitem.h | 6 +++-- src/urlbar/urlbar.cpp | 11 +++------ src/urlbar/urlbar.h | 2 +- src/urlbar/urlresolver.cpp | 34 +++++++++----------------- src/urlbar/urlresolver.h | 10 +++++--- 7 files changed, 51 insertions(+), 71 deletions(-) (limited to 'src/urlbar') diff --git a/src/urlbar/completionwidget.h b/src/urlbar/completionwidget.h index a714bb17..ab78e489 100644 --- a/src/urlbar/completionwidget.h +++ b/src/urlbar/completionwidget.h @@ -58,7 +58,7 @@ private slots: void itemChosen(ListItem *item, Qt::MouseButton = Qt::LeftButton); signals: - void chosenUrl(const QString&, Rekonq::OpenType); + void chosenUrl(const KUrl &, Rekonq::OpenType); private: void sizeAndPosition(); 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); } diff --git a/src/urlbar/listitem.h b/src/urlbar/listitem.h index de22d739..1b594115 100644 --- a/src/urlbar/listitem.h +++ b/src/urlbar/listitem.h @@ -31,6 +31,7 @@ // Forward Declarations class UrlSearchItem; +class KUrl; class ListItem : public QWidget @@ -54,7 +55,8 @@ protected: virtual void mousePressEvent(QMouseEvent *e); private: - QStyleOptionViewItemV4 m_option; - QString guessNameFromUrl(QUrl url); + QString guessNameFromUrl(KUrl url); void insertIcon(QLayout *layout, QString icon); + + QStyleOptionViewItemV4 _option; }; diff --git a/src/urlbar/urlbar.cpp b/src/urlbar/urlbar.cpp index 6f916482..3b79b06b 100644 --- a/src/urlbar/urlbar.cpp +++ b/src/urlbar/urlbar.cpp @@ -73,7 +73,7 @@ UrlBar::UrlBar(QWidget *parent) // suggestions installEventFilter(_box); - connect(_box, SIGNAL(chosenUrl(const QString&, Rekonq::OpenType)), SLOT(activated(const QString&, Rekonq::OpenType))); + connect(_box, SIGNAL(chosenUrl(const KUrl &, Rekonq::OpenType)), SLOT(activated(const KUrl &, Rekonq::OpenType))); } @@ -103,16 +103,13 @@ void UrlBar::setQUrl(const QUrl& url) } -void UrlBar::activated(const QString& urlString, Rekonq::OpenType type) +void UrlBar::activated(const KUrl& url, Rekonq::OpenType type) { disconnect(this, SIGNAL(textChanged(const QString &)), this, SLOT(suggestUrls(const QString &))); - if (urlString.isEmpty()) - return; - clearFocus(); - setText(urlString); - Application::instance()->loadUrl(urlString.trimmed(), type); + setUrl(url); + Application::instance()->loadUrl(url, type); } diff --git a/src/urlbar/urlbar.h b/src/urlbar/urlbar.h index 2536c27b..a473638b 100644 --- a/src/urlbar/urlbar.h +++ b/src/urlbar/urlbar.h @@ -60,7 +60,7 @@ public: void setPrivateMode(bool on); private slots: - void activated(const QString& url, Rekonq::OpenType = Rekonq::CurrentTab); + void activated(const KUrl& url, Rekonq::OpenType = Rekonq::CurrentTab); void suggestUrls(const QString &editedText); void setQUrl(const QUrl &url); diff --git a/src/urlbar/urlresolver.cpp b/src/urlbar/urlresolver.cpp index 5f025cb5..4ff6b461 100644 --- a/src/urlbar/urlresolver.cpp +++ b/src/urlbar/urlresolver.cpp @@ -60,7 +60,7 @@ bool UrlSearchItem::operator==(UrlSearchItem i) } UrlResolver::UrlResolver(const QString &typedUrl) - : _urlString(typedUrl) + : _urlString( typedUrl.trimmed() ) { } @@ -162,15 +162,10 @@ UrlSearchList UrlResolver::qurlFromUserInputResolution() QUrl urlFromUserInput = QUrl::fromUserInput(url2); if(urlFromUserInput.isValid()) { - QByteArray ba = urlFromUserInput.toEncoded(); - if(!ba.isEmpty()) - { - QString gUrl = QString(ba); - QString gTitle = i18n("Browse"); - UrlSearchItem gItem(UrlSearchItem::Browse, gUrl, gTitle, QString("") ); - list << gItem; - - } + KUrl gUrl(urlFromUserInput); + QString gTitle = i18n("Browse"); + UrlSearchItem gItem(UrlSearchItem::Browse, gUrl, gTitle); + list << gItem; } return list; @@ -182,19 +177,14 @@ UrlSearchList UrlResolver::webSearchesResolution() { UrlSearchList list; - QString url1 = _urlString; - if(KUrl(url1).isRelative()) + KUrl url1(_urlString); + if(url1.isRelative()) { // 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 %1", url1); - UrlSearchItem gItem(UrlSearchItem::Search, gUrl, gTitle, QString("http://www.google.com") ); + KUrl gUrl( QString("gg:") + _urlString ); + QString gTitle = i18n("Search Google for %1", _urlString); + UrlSearchItem gItem(UrlSearchItem::Search, gUrl, gTitle ); list << gItem; - -// QString wUrl = QString("http://en.wikipedia.org/wiki/Special:Search?search=%1&go=Go").arg(url1); -// QString wTitle = i18n("Search Wikipedia for %1", url1); -// UrlSearchItem wItem(wUrl, wTitle, QString("http://wikipedia.org") ); -// list << wItem; } return list; @@ -210,7 +200,7 @@ UrlSearchList UrlResolver::historyResolution() QStringList historyResults = historyCompletion->substringCompletion(_urlString); Q_FOREACH(const QString &s, historyResults) { - UrlSearchItem it(UrlSearchItem::History, s, Application::historyManager()->titleForHistoryUrl(s), QString("view-history")); + UrlSearchItem it(UrlSearchItem::History, KUrl(s), Application::historyManager()->titleForHistoryUrl(s) ); //, QString("view-history")); list << it; } @@ -227,7 +217,7 @@ UrlSearchList UrlResolver::bookmarksResolution() QStringList bookmarkResults = bookmarkCompletion->substringCompletion(_urlString); Q_FOREACH(const QString &s, bookmarkResults) { - UrlSearchItem it(UrlSearchItem::Bookmark, s, Application::bookmarkProvider()->titleForBookmarkUrl(s), QString("rating") ); + UrlSearchItem it(UrlSearchItem::Bookmark, KUrl(s), Application::bookmarkProvider()->titleForBookmarkUrl(s) ); //, QString("rating") ); list << it; } diff --git a/src/urlbar/urlresolver.h b/src/urlbar/urlresolver.h index 489a5a79..3c082e00 100644 --- a/src/urlbar/urlresolver.h +++ b/src/urlbar/urlresolver.h @@ -28,6 +28,9 @@ #define URL_RESOLVER_H +// KDE Includes +#include + // Qt Includes #include #include @@ -48,12 +51,11 @@ class UrlSearchItem }; int type; - QString url; + KUrl url; QString title; - QString icon; - UrlSearchItem(const int &_type, const QString &_url, const QString &_title = QString(), const QString &_icon = QString()) - : type(_type), url(_url), title(_title), icon(_icon) + UrlSearchItem(const int &_type, const KUrl &_url, const QString &_title = QString()) + : type(_type), url(_url), title(_title) {}; bool operator==(UrlSearchItem i); -- cgit v1.2.1 From eb52521b43669aab1c38ab9872a53386b776662d Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Tue, 13 Apr 2010 03:01:42 +0200 Subject: This commit is (quite) last in the urlbar encodings fix series. It fixes: BUG: 233159 BUG: 234168 Moreover it "cleans" road to fix (not yet, but we are near..) another bug CCBUG: 230771 at least from the rekonq side. Changes in there - cleaning and fixing filterurljob class (responsible for the encodings) - using urls instead of strings in the resolver class (work with right data..) - letting first box appearance without item selection and adding one signal to use the filterurljob class directly. --- src/urlbar/completionwidget.cpp | 6 ++++-- src/urlbar/completionwidget.h | 3 ++- src/urlbar/urlbar.cpp | 13 +++++++++++-- src/urlbar/urlbar.h | 2 +- 4 files changed, 18 insertions(+), 6 deletions(-) (limited to 'src/urlbar') diff --git a/src/urlbar/completionwidget.cpp b/src/urlbar/completionwidget.cpp index 740f1471..0733b1f0 100644 --- a/src/urlbar/completionwidget.cpp +++ b/src/urlbar/completionwidget.cpp @@ -97,7 +97,6 @@ void CompletionWidget::sizeAndPosition() void CompletionWidget::popup() { - down(); sizeAndPosition(); if (!isVisible()) show(); @@ -210,7 +209,10 @@ bool CompletionWidget::eventFilter( QObject *o, QEvent *e ) case Qt::Key_Enter: case Qt::Key_Return: hide(); - emit chosenUrl(_list.at(_currentIndex).url, Rekonq::CurrentTab); + if(_currentIndex >= 0) + emit chosenUrl(_list.at(_currentIndex).url, Rekonq::CurrentTab); + else + emit loadTypedUrl(); ev->accept(); return true; break; diff --git a/src/urlbar/completionwidget.h b/src/urlbar/completionwidget.h index ab78e489..57a8bed0 100644 --- a/src/urlbar/completionwidget.h +++ b/src/urlbar/completionwidget.h @@ -59,7 +59,8 @@ private slots: signals: void chosenUrl(const KUrl &, Rekonq::OpenType); - + void loadTypedUrl(); + private: void sizeAndPosition(); void up(); diff --git a/src/urlbar/urlbar.cpp b/src/urlbar/urlbar.cpp index 3b79b06b..5423e5d0 100644 --- a/src/urlbar/urlbar.cpp +++ b/src/urlbar/urlbar.cpp @@ -74,6 +74,7 @@ UrlBar::UrlBar(QWidget *parent) // suggestions installEventFilter(_box); connect(_box, SIGNAL(chosenUrl(const KUrl &, Rekonq::OpenType)), SLOT(activated(const KUrl &, Rekonq::OpenType))); + connect(_box, SIGNAL(loadTypedUrl()), this, SLOT(activated())); } @@ -108,8 +109,16 @@ void UrlBar::activated(const KUrl& url, Rekonq::OpenType type) disconnect(this, SIGNAL(textChanged(const QString &)), this, SLOT(suggestUrls(const QString &))); clearFocus(); - setUrl(url); - Application::instance()->loadUrl(url, type); + KUrl loadingUrl; + + if(url.isEmpty()) + loadingUrl = KUrl(text()); + else + loadingUrl = url; + + setUrl(loadingUrl); + + Application::instance()->loadUrl(loadingUrl, type); } diff --git a/src/urlbar/urlbar.h b/src/urlbar/urlbar.h index a473638b..684a205e 100644 --- a/src/urlbar/urlbar.h +++ b/src/urlbar/urlbar.h @@ -60,7 +60,7 @@ public: void setPrivateMode(bool on); private slots: - void activated(const KUrl& url, Rekonq::OpenType = Rekonq::CurrentTab); + void activated(const KUrl& url = KUrl(), Rekonq::OpenType = Rekonq::CurrentTab); void suggestUrls(const QString &editedText); void setQUrl(const QUrl &url); -- cgit v1.2.1 From b7deeaf321b9f145018811eb4ce78776c06d9832 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Tue, 13 Apr 2010 11:11:05 +0200 Subject: oops :) QT_FATAL_WARNINGS=1 rekonq --> crash Fixed --- src/urlbar/urlbar.cpp | 3 --- 1 file changed, 3 deletions(-) (limited to 'src/urlbar') diff --git a/src/urlbar/urlbar.cpp b/src/urlbar/urlbar.cpp index 5423e5d0..dcdda533 100644 --- a/src/urlbar/urlbar.cpp +++ b/src/urlbar/urlbar.cpp @@ -68,9 +68,6 @@ UrlBar::UrlBar(QWidget *parent) connect(_tab->view(), SIGNAL(urlChanged(const QUrl &)), this, SLOT(setQUrl(const QUrl &))); connect(_tab->view(), SIGNAL(loadFinished(bool)), this, SLOT(loadFinished())); - // load urls on activated urlbar signal - connect(this, SIGNAL(returnPressed(const QString&)), this, SLOT(activated(const QString&))); - // suggestions installEventFilter(_box); connect(_box, SIGNAL(chosenUrl(const KUrl &, Rekonq::OpenType)), SLOT(activated(const KUrl &, Rekonq::OpenType))); -- 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/completionwidget.cpp | 23 +++++++---------------- src/urlbar/listitem.cpp | 9 ++++++++- 2 files changed, 15 insertions(+), 17 deletions(-) (limited to 'src/urlbar') diff --git a/src/urlbar/completionwidget.cpp b/src/urlbar/completionwidget.cpp index 0733b1f0..311694b3 100644 --- a/src/urlbar/completionwidget.cpp +++ b/src/urlbar/completionwidget.cpp @@ -50,45 +50,36 @@ CompletionWidget::CompletionWidget( QWidget *parent) , _parent(parent) , _currentIndex(-1) { - QPalette p(palette()); - p.setColor(QPalette::Background, Qt::white); // TODO: choose the correct color - setPalette(p); setFrameStyle(QFrame::Panel); setLayoutDirection(Qt::LeftToRight); QVBoxLayout *layout = new QVBoxLayout; layout->setMargin(0); + layout->setSpacing(0); setLayout(layout); - } void CompletionWidget::insertSearchList(const UrlSearchList &list) { _list = list; - int i=0; + int i = 0; foreach(UrlSearchItem item, _list) { ListItem *suggestion = new ListItem(item); + suggestion->setBackgroundRole(i%2 ? QPalette::AlternateBase : QPalette::Base); 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 ); + i++; } } void CompletionWidget::sizeAndPosition() { - // size - int h = 34; - ListItem *widget; - for(int i = 0; i < layout()->count(); ++i) - { - widget = findChild( QString::number(i) ); - h = qMax(widget->sizeHint().height(), h); - } - setFixedHeight(layout()->count() * (h + 10) ); setFixedWidth( _parent->width() ); - + adjustSize(); + // position QPoint p = _parent->mapToGlobal( QPoint(0,0) ); move(p.x(), p.y() + _parent->height()); 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 c05b14ad0f8358171f4dc199e61dc0a259d0aa65 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Wed, 14 Apr 2010 11:59:43 +0200 Subject: Proper solutions are always the best ones :) Fix duplicated right icons. CCBUG: 234320 --- src/urlbar/lineedit.h | 7 ++++--- src/urlbar/urlbar.cpp | 6 ++---- 2 files changed, 6 insertions(+), 7 deletions(-) (limited to 'src/urlbar') diff --git a/src/urlbar/lineedit.h b/src/urlbar/lineedit.h index 5b8ff2a3..68cdc7d1 100644 --- a/src/urlbar/lineedit.h +++ b/src/urlbar/lineedit.h @@ -77,9 +77,7 @@ public: virtual ~LineEdit(); IconButton *iconButton() const; - - void clearRightIcons(); - + protected: virtual void keyPressEvent(QKeyEvent *); virtual void mouseDoubleClickEvent(QMouseEvent *); @@ -88,6 +86,9 @@ protected: IconButton *addRightIcon(LineEdit::icon ); +private slots: + void clearRightIcons(); + private: IconButton *_icon; IconButtonPointerList _rightIconsList; diff --git a/src/urlbar/urlbar.cpp b/src/urlbar/urlbar.cpp index dcdda533..051277e2 100644 --- a/src/urlbar/urlbar.cpp +++ b/src/urlbar/urlbar.cpp @@ -67,7 +67,8 @@ UrlBar::UrlBar(QWidget *parent) connect(_tab->view(), SIGNAL(urlChanged(const QUrl &)), this, SLOT(setQUrl(const QUrl &))); connect(_tab->view(), SIGNAL(loadFinished(bool)), this, SLOT(loadFinished())); - + connect(_tab->view(), SIGNAL(loadStarted()), this, SLOT(clearRightIcons())); + // suggestions installEventFilter(_box); connect(_box, SIGNAL(chosenUrl(const KUrl &, Rekonq::OpenType)), SLOT(activated(const KUrl &, Rekonq::OpenType))); @@ -83,9 +84,6 @@ UrlBar::~UrlBar() void UrlBar::setQUrl(const QUrl& url) { - // find a better place? Ideally a loadStarted connected slot.. - clearRightIcons(); - if(url.scheme() == QL1S("about") ) { iconButton()->setIcon( KIcon("arrow-right") ); -- 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 + src/urlbar/listitem.h | 7 +++++++ 2 files changed, 8 insertions(+) (limited to 'src/urlbar') 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" diff --git a/src/urlbar/listitem.h b/src/urlbar/listitem.h index 1b594115..18ec8a33 100644 --- a/src/urlbar/listitem.h +++ b/src/urlbar/listitem.h @@ -24,6 +24,10 @@ * ============================================================ */ +#ifndef LISTITEM_H +#define LISTITEM_H + + // Qt Includes #include #include @@ -60,3 +64,6 @@ private: QStyleOptionViewItemV4 _option; }; + + +#endif // LISTITEM_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/completionwidget.cpp | 35 ++-- src/urlbar/completionwidget.h | 4 +- src/urlbar/listitem.cpp | 404 ++++++++++++++++++++++++++++++---------- src/urlbar/listitem.h | 149 ++++++++++++++- src/urlbar/urlbar.cpp | 2 +- src/urlbar/urlresolver.cpp | 58 +++--- src/urlbar/urlresolver.h | 19 +- 7 files changed, 510 insertions(+), 161 deletions(-) (limited to 'src/urlbar') diff --git a/src/urlbar/completionwidget.cpp b/src/urlbar/completionwidget.cpp index 311694b3..42824af9 100644 --- a/src/urlbar/completionwidget.cpp +++ b/src/urlbar/completionwidget.cpp @@ -59,18 +59,18 @@ CompletionWidget::CompletionWidget( QWidget *parent) } -void CompletionWidget::insertSearchList(const UrlSearchList &list) +void CompletionWidget::insertSearchList(const UrlSearchList &list, const QString& text) { _list = list; int i = 0; foreach(UrlSearchItem item, _list) { - ListItem *suggestion = new ListItem(item); - suggestion->setBackgroundRole(i%2 ? QPalette::AlternateBase : QPalette::Base); + ListItem *suggestion = ListItemFactory::create(item, text); + suggestion->setBackgroundRole(i%2 ? QPalette::AlternateBase: QPalette::Base); connect(suggestion, SIGNAL(itemClicked(ListItem *, Qt::MouseButton)), this, SLOT(itemChosen(ListItem *, Qt::MouseButton))); - suggestion->setObjectName( QString::number(i) ); + connect(this, SIGNAL(nextItemSubChoice()), suggestion, SLOT(nextItemSubChoice())); + suggestion->setObjectName( QString::number(i++) ); layout()->addWidget( suggestion ); - i++; } } @@ -88,8 +88,9 @@ void CompletionWidget::sizeAndPosition() void CompletionWidget::popup() { + down(); sizeAndPosition(); - if (!isVisible()) + if (!isVisible()) show(); } @@ -195,17 +196,23 @@ bool CompletionWidget::eventFilter( QObject *o, QEvent *e ) ev->accept(); return true; } + else if (ev->modifiers() & Qt::ControlModifier) + { + emit nextItemSubChoice(); + ev->accept(); + return true; + } break; - + case Qt::Key_Enter: case Qt::Key_Return: - hide(); - if(_currentIndex >= 0) - emit chosenUrl(_list.at(_currentIndex).url, Rekonq::CurrentTab); - else - emit loadTypedUrl(); - ev->accept(); - return true; + hide(); + if(_currentIndex >= 0) + emit chosenUrl(_list.at(_currentIndex).url, Rekonq::CurrentTab); + else + emit loadTypedUrl(); + ev->accept(); + return true; break; } } diff --git a/src/urlbar/completionwidget.h b/src/urlbar/completionwidget.h index 57a8bed0..25b6f5eb 100644 --- a/src/urlbar/completionwidget.h +++ b/src/urlbar/completionwidget.h @@ -47,7 +47,7 @@ class CompletionWidget : public QFrame public: CompletionWidget(QWidget *parent); - void insertSearchList(const UrlSearchList &list); + void insertSearchList(const UrlSearchList &list, const QString& text); void popup(); void clear(); @@ -59,6 +59,7 @@ private slots: signals: void chosenUrl(const KUrl &, Rekonq::OpenType); + void nextItemSubChoice(); void loadTypedUrl(); private: @@ -70,6 +71,7 @@ private: UrlSearchList _list; int _currentIndex; + QString *_searchEngine; }; #endif // COMPLETION_WIDGET_H 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; +} + diff --git a/src/urlbar/listitem.h b/src/urlbar/listitem.h index 18ec8a33..6a6c433f 100644 --- a/src/urlbar/listitem.h +++ b/src/urlbar/listitem.h @@ -23,19 +23,25 @@ * * ============================================================ */ - #ifndef LISTITEM_H #define LISTITEM_H +// KDE Includes +#include +#include +#include + +// Local Includes +#include "urlresolver.h" // Qt Includes #include #include #include +#include // Forward Declarations class UrlSearchItem; -class KUrl; class ListItem : public QWidget @@ -44,11 +50,16 @@ class ListItem : public QWidget public: ListItem(const UrlSearchItem &item, QWidget *parent = 0); - ~ListItem(); + virtual ~ListItem(); void activate(); void deactivate(); + KUrl url(); + +public slots: + virtual void nextItemSubChoice(); + signals: void itemClicked(ListItem *item, Qt::MouseButton); @@ -59,11 +70,135 @@ protected: virtual void mousePressEvent(QMouseEvent *e); private: - QString guessNameFromUrl(KUrl url); - void insertIcon(QLayout *layout, QString icon); + QStyleOptionViewItemV4 m_option; + +protected: + KUrl m_url; +}; + + +class TypeIcon : public QLabel +{ + Q_OBJECT + + public: + TypeIcon(int type, QWidget *parent = 0); + private: + QLabel *getIcon(QString icon); +}; + + +class ItemIcon : public QLabel +{ + Q_OBJECT + + public: + ItemIcon(QString icon, QWidget *parent = 0); +}; + + +class ItemText : public QLabel +{ + Q_OBJECT + + public: + ItemText(QString text, QString underlined, QWidget *parent = 0); + QString underlineText(QString text, QString textToUnderline); +}; + + +//------------------------------------------------------------------------------------------------- + +class EngineBar : public KToolBar +{ + Q_OBJECT + + public: + EngineBar(QString text, QString selectedEngine, QWidget *parent = 0); + static QString defaultEngine(); + void selectNextEngine(); + + signals: + void searchEngineChanged(QString url, QString engine); + + private slots: + void changeSearchEngine(); + + private: + KAction *newEngineAction(KService::Ptr service, QString selectedEngine, QString text); + + QActionGroup *m_engineGroup; +}; + + +class SearchListItem : public ListItem +{ + Q_OBJECT + + public: + SearchListItem(const UrlSearchItem &item, const QString &text, QWidget *parent = 0); + + public slots: + virtual void nextItemSubChoice(); + + protected: + + + private slots: + void changeSearchEngine(QString url, QString engine); + + private: + QString searchItemTitle(QString engine, QString text); + ItemText* m_titleLabel; + ItemIcon* m_iconLabel; + EngineBar* m_engineBar; + QString m_text; + static QString m_currentEngine; +}; + + +//------------------------------------------------------------------------------------------------- + +class PreviewListItem : public ListItem +{ + Q_OBJECT + + public: + PreviewListItem(const UrlSearchItem &item, const QString &text, QWidget *parent = 0); +}; + + +class ItemPreview : public QLabel +{ + Q_OBJECT + + public: + ItemPreview(QString url,int width, int height, QWidget *parent = 0); + + private: + static QString guessNameFromUrl(QUrl url); +}; + +//------------------------------------------------------------------------------------------------- + +class BrowseListItem : public ListItem +{ + Q_OBJECT - QStyleOptionViewItemV4 _option; + public: + BrowseListItem(const UrlSearchItem &item, const QString &text, QWidget *parent = 0); + protected: + +}; + +//------------------------------------------------------------------------------------------------- + +class ListItemFactory +{ + public: + static ListItem *create(const UrlSearchItem &item, const QString &text, QWidget *parent = 0); + }; -#endif // LISTITEM_H +#endif \ No newline at end of file diff --git a/src/urlbar/urlbar.cpp b/src/urlbar/urlbar.cpp index 051277e2..4abd4622 100644 --- a/src/urlbar/urlbar.cpp +++ b/src/urlbar/urlbar.cpp @@ -216,7 +216,7 @@ void UrlBar::suggestUrls(const QString &text) if(list.count() > 0) { _box->clear(); - _box->insertSearchList(list); + _box->insertSearchList(list, text); _box->popup(); } } diff --git a/src/urlbar/urlresolver.cpp b/src/urlbar/urlresolver.cpp index 4ff6b461..fd4cdfcb 100644 --- a/src/urlbar/urlresolver.cpp +++ b/src/urlbar/urlresolver.cpp @@ -60,7 +60,7 @@ bool UrlSearchItem::operator==(UrlSearchItem i) } UrlResolver::UrlResolver(const QString &typedUrl) - : _urlString( typedUrl.trimmed() ) + : _urlString(typedUrl.trimmed()) { } @@ -78,19 +78,15 @@ UrlSearchList UrlResolver::orderedSearchItems() if(isHttp()) { list << qurlFromUserInputResolution(); - list << webSearchesResolution(); - } - else - { - list << webSearchesResolution(); - list << qurlFromUserInputResolution(); } + + list << webSearchesResolution(); if (_urlString.length()>2) { int firstResults = list.count(); int checkPoint = 9 - firstResults; - + UrlSearchList historyList = historyResolution(); int historyResults = historyList.count(); @@ -136,7 +132,12 @@ UrlSearchList UrlResolver::orderedSearchItems() bool UrlResolver::isHttp() { - QString r = "[\\d\\w-.]+\\.(a[cdefgilmnoqrstuwz]|b[abdefghijmnorstvwyz]|"\ + QString ipv4 = "^0*([1-9]?\\d|1\\d\\d|2[0-4]\\d|25[0-5])\\.0*([1-9]?\\d|1\\d\\d|2[0-4]\\d|25[0-5])"\ + "\\.0*([1-9]?\\d|1\\d\\d|2[0-4]\\d|25[0-5])\\.0*([1-9]?\\d|1\\d\\d|2[0-4]\\d|25[0-5])"; + + QString ipv6 = "^([0-9a-fA-F]{4}|0)(\\:([0-9a-fA-F]{4}|0)){7}"; + + QString address = "[\\d\\w-.]+\\.(a[cdefgilmnoqrstuwz]|b[abdefghijmnorstvwyz]|"\ "c[acdfghiklmnoruvxyz]|d[ejkmnoz]|e[ceghrst]|f[ijkmnor]|g[abdefghilmnpqrstuwy]|"\ "h[kmnrtu]|i[delmnoqrst]|j[emop]|k[eghimnprwyz]|l[abcikrstuvy]|"\ "m[acdghklmnopqrstuvwxyz]|n[acefgilopruz]|om|p[aefghklmnrstwy]|qa|r[eouw]|"\ @@ -144,9 +145,11 @@ bool UrlResolver::isHttp() "y[etu]|z[amw]|aero|arpa|biz|com|coop|edu|info|int|gov|mil|museum|name|net|org|"\ "pro)"; - return (QRegExp(r, Qt::CaseInsensitive).indexIn(_urlString) != -1) - || _urlString.startsWith("http:") - || _urlString.startsWith("https:"); + return _urlString.startsWith("http://") + || _urlString.startsWith("https://") + || (QRegExp(address, Qt::CaseInsensitive).indexIn(_urlString) != -1) + || (QRegExp(ipv4, Qt::CaseInsensitive).indexIn(_urlString) != -1) + || (QRegExp(ipv6, Qt::CaseInsensitive).indexIn(_urlString) != -1); } ////////////////////////////////////////////////////////////////////////// @@ -156,19 +159,8 @@ bool UrlResolver::isHttp() // STEP 1 = QUrl from User Input (easily the best solution... ) UrlSearchList UrlResolver::qurlFromUserInputResolution() { - UrlSearchList list; - - QString url2 = _urlString; - QUrl urlFromUserInput = QUrl::fromUserInput(url2); - if(urlFromUserInput.isValid()) - { - KUrl gUrl(urlFromUserInput); - QString gTitle = i18n("Browse"); - UrlSearchItem gItem(UrlSearchItem::Browse, gUrl, gTitle); - list << gItem; - } - - return list; + UrlSearchItem gItem(UrlSearchItem::Browse, KUrl(_urlString), QString()); + return UrlSearchList() << gItem; } @@ -176,14 +168,12 @@ UrlSearchList UrlResolver::qurlFromUserInputResolution() UrlSearchList UrlResolver::webSearchesResolution() { UrlSearchList list; - - KUrl url1(_urlString); - if(url1.isRelative()) + + if(KUrl(_urlString).isRelative()) { - // KUriFilter has the worst performance possible here and let this trick unusable - KUrl gUrl( QString("gg:") + _urlString ); - QString gTitle = i18n("Search Google for %1", _urlString); - UrlSearchItem gItem(UrlSearchItem::Search, gUrl, gTitle ); + QString gUrl = QString("http://www.google.com/search?q=%1&ie=UTF-8&oe=UTF-8").arg(_urlString); + QString gTitle = i18n("Search Google for ") + _urlString; + UrlSearchItem gItem(UrlSearchItem::Search, KUrl(), gTitle); list << gItem; } @@ -200,7 +190,7 @@ UrlSearchList UrlResolver::historyResolution() QStringList historyResults = historyCompletion->substringCompletion(_urlString); Q_FOREACH(const QString &s, historyResults) { - UrlSearchItem it(UrlSearchItem::History, KUrl(s), Application::historyManager()->titleForHistoryUrl(s) ); //, QString("view-history")); + UrlSearchItem it(UrlSearchItem::History, KUrl(s), Application::historyManager()->titleForHistoryUrl(s)); list << it; } @@ -217,7 +207,7 @@ UrlSearchList UrlResolver::bookmarksResolution() QStringList bookmarkResults = bookmarkCompletion->substringCompletion(_urlString); Q_FOREACH(const QString &s, bookmarkResults) { - UrlSearchItem it(UrlSearchItem::Bookmark, KUrl(s), Application::bookmarkProvider()->titleForBookmarkUrl(s) ); //, QString("rating") ); + UrlSearchItem it(UrlSearchItem::Bookmark, KUrl(s), Application::bookmarkProvider()->titleForBookmarkUrl(s)); list << it; } diff --git a/src/urlbar/urlresolver.h b/src/urlbar/urlresolver.h index 3c082e00..610b1fd0 100644 --- a/src/urlbar/urlresolver.h +++ b/src/urlbar/urlresolver.h @@ -27,7 +27,6 @@ #ifndef URL_RESOLVER_H #define URL_RESOLVER_H - // KDE Includes #include @@ -43,21 +42,21 @@ class UrlSearchItem enum types { - Search = 0x00000001, - Browse = 0x00000010, - History = 0x00000100, - Bookmark = 0x00001000, - Suggestion = 0x00010000, + Search = 0x00000001, + Browse = 0x00000010, + History = 0x00000100, + Bookmark = 0x00001000, }; int type; KUrl url; QString title; + QString icon; - UrlSearchItem(const int &_type, const KUrl &_url, const QString &_title = QString()) - : type(_type), url(_url), title(_title) + UrlSearchItem(const int &_type, const KUrl &_url, const QString &_title = QString(), const QString &_icon = QString()) + : type(_type), url(_url), title(_title), icon(_icon) {}; - + bool operator==(UrlSearchItem i); }; @@ -75,7 +74,7 @@ public: UrlSearchList orderedSearchItems(); private: - QString _urlString; + QString _urlString; //TODO: give a better name UrlSearchList webSearchesResolution(); UrlSearchList historyResolution(); -- 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/completionwidget.cpp | 19 +++--- src/urlbar/completionwidget.h | 1 - src/urlbar/listitem.cpp | 86 ++++++++++++++---------- src/urlbar/listitem.h | 142 +++++++++++++++++++++++----------------- src/urlbar/urlbar.cpp | 22 +++---- src/urlbar/urlbar.h | 3 +- src/urlbar/urlresolver.cpp | 56 ++++++++++------ src/urlbar/urlresolver.h | 7 +- 8 files changed, 194 insertions(+), 142 deletions(-) (limited to 'src/urlbar') diff --git a/src/urlbar/completionwidget.cpp b/src/urlbar/completionwidget.cpp index 42824af9..83e99f9d 100644 --- a/src/urlbar/completionwidget.cpp +++ b/src/urlbar/completionwidget.cpp @@ -45,8 +45,8 @@ #include -CompletionWidget::CompletionWidget( QWidget *parent) - :QFrame( parent, Qt::ToolTip) +CompletionWidget::CompletionWidget(QWidget *parent) + : QFrame( parent, Qt::ToolTip) , _parent(parent) , _currentIndex(-1) { @@ -206,12 +206,12 @@ bool CompletionWidget::eventFilter( QObject *o, QEvent *e ) case Qt::Key_Enter: case Qt::Key_Return: - hide(); - if(_currentIndex >= 0) - emit chosenUrl(_list.at(_currentIndex).url, Rekonq::CurrentTab); - else - emit loadTypedUrl(); + + // need this to let ListItem magic work.. + ListItem *child = findChild( QString::number(_currentIndex) ); + emit chosenUrl( child->url(), Rekonq::CurrentTab); ev->accept(); + hide(); return true; break; } @@ -233,6 +233,7 @@ void CompletionWidget::setVisible( bool visible ) Application::instance()->removeEventFilter(this); } + QFrame::setVisible(visible); } @@ -240,8 +241,8 @@ void CompletionWidget::setVisible( bool visible ) void CompletionWidget::itemChosen(ListItem *item, Qt::MouseButton button) { if(button == Qt::MidButton) - emit chosenUrl(_list.at(layout()->indexOf(item)).url, Rekonq::NewCurrentTab); + emit chosenUrl( item->url(), Rekonq::NewCurrentTab); else - emit chosenUrl(_list.at(layout()->indexOf(item)).url, Rekonq::CurrentTab); + emit chosenUrl( item->url(), Rekonq::CurrentTab); hide(); } diff --git a/src/urlbar/completionwidget.h b/src/urlbar/completionwidget.h index 25b6f5eb..125e186a 100644 --- a/src/urlbar/completionwidget.h +++ b/src/urlbar/completionwidget.h @@ -60,7 +60,6 @@ private slots: signals: void chosenUrl(const KUrl &, Rekonq::OpenType); void nextItemSubChoice(); - void loadTypedUrl(); private: void sizeAndPosition(); 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; } - diff --git a/src/urlbar/listitem.h b/src/urlbar/listitem.h index 6a6c433f..e355160a 100644 --- a/src/urlbar/listitem.h +++ b/src/urlbar/listitem.h @@ -23,17 +23,19 @@ * * ============================================================ */ + #ifndef LISTITEM_H #define LISTITEM_H + +// Local Includes +#include "urlresolver.h" + // KDE Includes #include #include #include -// Local Includes -#include "urlresolver.h" - // Qt Includes #include #include @@ -77,128 +79,146 @@ protected: }; +// ------------------------------------------------------------------------- + + class TypeIcon : public QLabel { Q_OBJECT - public: - TypeIcon(int type, QWidget *parent = 0); - private: - QLabel *getIcon(QString icon); +public: + TypeIcon(int type, QWidget *parent = 0); + +private: + QLabel *getIcon(QString icon); }; +// ------------------------------------------------------------------------- + + class ItemIcon : public QLabel { Q_OBJECT - public: - ItemIcon(QString icon, QWidget *parent = 0); +public: + ItemIcon(const QString &icon, QWidget *parent = 0); }; +// ------------------------------------------------------------------------- + + class ItemText : public QLabel { Q_OBJECT - public: - ItemText(QString text, QString underlined, QWidget *parent = 0); - QString underlineText(QString text, QString textToUnderline); +public: + ItemText(const QString &text, const QString &textToPointOut, QWidget *parent = 0); }; -//------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------- + class EngineBar : public KToolBar { Q_OBJECT - public: - EngineBar(QString text, QString selectedEngine, QWidget *parent = 0); - static QString defaultEngine(); - void selectNextEngine(); - - signals: - void searchEngineChanged(QString url, QString engine); - - private slots: - void changeSearchEngine(); +public: + EngineBar(const QString &text, const QString &selectedEngine, QWidget *parent = 0); + static QString defaultEngine(); + void selectNextEngine(); + KUrl url() { return m_url; }; - private: - KAction *newEngineAction(KService::Ptr service, QString selectedEngine, QString text); +signals: + void searchEngineChanged(QString url, QString engine); + +private slots: + void changeSearchEngine(); + +private: + KAction *newEngineAction(KService::Ptr service, QString selectedEngine); - QActionGroup *m_engineGroup; + QActionGroup *m_engineGroup; + KUrl m_url; }; +// ------------------------------------------------------------------------- + + class SearchListItem : public ListItem { Q_OBJECT - public: - SearchListItem(const UrlSearchItem &item, const QString &text, QWidget *parent = 0); - - public slots: - virtual void nextItemSubChoice(); - - protected: - - - private slots: - void changeSearchEngine(QString url, QString engine); - - private: - QString searchItemTitle(QString engine, QString text); - ItemText* m_titleLabel; - ItemIcon* m_iconLabel; - EngineBar* m_engineBar; - QString m_text; - static QString m_currentEngine; +public: + SearchListItem(const UrlSearchItem &item, const QString &text, QWidget *parent = 0); + +public slots: + virtual void nextItemSubChoice(); + +private slots: + void changeSearchEngine(QString url, QString engine); + +private: + QString searchItemTitle(QString engine, QString text); + ItemText* m_titleLabel; + ItemIcon* m_iconLabel; + EngineBar* m_engineBar; + QString m_text; + + static QString m_currentEngine; }; -//------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------- + class PreviewListItem : public ListItem { Q_OBJECT - public: - PreviewListItem(const UrlSearchItem &item, const QString &text, QWidget *parent = 0); +public: + PreviewListItem(const UrlSearchItem &item, const QString &text, QWidget *parent = 0); }; +// ------------------------------------------------------------------------- + + class ItemPreview : public QLabel { Q_OBJECT - public: - ItemPreview(QString url,int width, int height, QWidget *parent = 0); +public: + ItemPreview(const QString &url, int width, int height, QWidget *parent = 0); - private: - static QString guessNameFromUrl(QUrl url); +private: + static QString guessNameFromUrl(QUrl url); }; -//------------------------------------------------------------------------------------------------- + +// ------------------------------------------------------------------------- + class BrowseListItem : public ListItem { Q_OBJECT - public: - BrowseListItem(const UrlSearchItem &item, const QString &text, QWidget *parent = 0); - protected: - +public: + BrowseListItem(const UrlSearchItem &item, const QString &text, QWidget *parent = 0); }; + //------------------------------------------------------------------------------------------------- + class ListItemFactory { - public: - static ListItem *create(const UrlSearchItem &item, const QString &text, QWidget *parent = 0); - +public: + static ListItem *create(const UrlSearchItem &item, const QString &text, QWidget *parent = 0); }; -#endif \ No newline at end of file +#endif diff --git a/src/urlbar/urlbar.cpp b/src/urlbar/urlbar.cpp index 4abd4622..4e7310bf 100644 --- a/src/urlbar/urlbar.cpp +++ b/src/urlbar/urlbar.cpp @@ -72,7 +72,9 @@ UrlBar::UrlBar(QWidget *parent) // suggestions installEventFilter(_box); connect(_box, SIGNAL(chosenUrl(const KUrl &, Rekonq::OpenType)), SLOT(activated(const KUrl &, Rekonq::OpenType))); - connect(_box, SIGNAL(loadTypedUrl()), this, SLOT(activated())); + + // load typed urls + connect(this, SIGNAL(returnPressed(const QString &)), this, SLOT(loadTyped(const QString &))); } @@ -104,16 +106,8 @@ void UrlBar::activated(const KUrl& url, Rekonq::OpenType type) disconnect(this, SIGNAL(textChanged(const QString &)), this, SLOT(suggestUrls(const QString &))); clearFocus(); - KUrl loadingUrl; - - if(url.isEmpty()) - loadingUrl = KUrl(text()); - else - loadingUrl = url; - - setUrl(loadingUrl); - - Application::instance()->loadUrl(loadingUrl, type); + setUrl(url); + Application::instance()->loadUrl(url, type); } @@ -278,3 +272,9 @@ void UrlBar::loadFinished() update(); } + + +void UrlBar::loadTyped(const QString &text) +{ + activated(KUrl(text)); +} diff --git a/src/urlbar/urlbar.h b/src/urlbar/urlbar.h index 684a205e..804188f7 100644 --- a/src/urlbar/urlbar.h +++ b/src/urlbar/urlbar.h @@ -60,11 +60,12 @@ public: void setPrivateMode(bool on); private slots: - void activated(const KUrl& url = KUrl(), Rekonq::OpenType = Rekonq::CurrentTab); + void activated(const KUrl& url, Rekonq::OpenType = Rekonq::CurrentTab); void suggestUrls(const QString &editedText); void setQUrl(const QUrl &url); void loadFinished(); + void loadTyped(const QString &); protected: virtual void paintEvent(QPaintEvent *event); diff --git a/src/urlbar/urlresolver.cpp b/src/urlbar/urlresolver.cpp index fd4cdfcb..5b4b1625 100644 --- a/src/urlbar/urlresolver.cpp +++ b/src/urlbar/urlresolver.cpp @@ -45,8 +45,10 @@ #include #include +// defines #define MAX_ELEMENTS 9 + // NOTE default kurifilter plugin list (at least in my box) // 1. "kshorturifilter" // 2. "kurisearchfilter" @@ -54,13 +56,15 @@ // 4 ."kuriikwsfilter" // 5. "fixhosturifilter" + bool UrlSearchItem::operator==(UrlSearchItem i) { return url==i.url; } + UrlResolver::UrlResolver(const QString &typedUrl) - : _urlString(typedUrl.trimmed()) + : _typedString(typedUrl.trimmed()) { } @@ -75,15 +79,17 @@ UrlSearchList UrlResolver::orderedSearchItems() UrlSearchList list; - if(isHttp()) - { - list << qurlFromUserInputResolution(); - } +// if(isHttp()) +// { +// list << qurlFromUserInputResolution(); +// } list << webSearchesResolution(); - if (_urlString.length()>2) + if (_typedString.length() >= 2) { + list << qurlFromUserInputResolution(); + int firstResults = list.count(); int checkPoint = 9 - firstResults; @@ -145,13 +151,14 @@ bool UrlResolver::isHttp() "y[etu]|z[amw]|aero|arpa|biz|com|coop|edu|info|int|gov|mil|museum|name|net|org|"\ "pro)"; - return _urlString.startsWith("http://") - || _urlString.startsWith("https://") - || (QRegExp(address, Qt::CaseInsensitive).indexIn(_urlString) != -1) - || (QRegExp(ipv4, Qt::CaseInsensitive).indexIn(_urlString) != -1) - || (QRegExp(ipv6, Qt::CaseInsensitive).indexIn(_urlString) != -1); + return _typedString.startsWith("http://") + || _typedString.startsWith("https://") + || (QRegExp(address, Qt::CaseInsensitive).indexIn(_typedString) != -1) + || (QRegExp(ipv4, Qt::CaseInsensitive).indexIn(_typedString) != -1) + || (QRegExp(ipv6, Qt::CaseInsensitive).indexIn(_typedString) != -1); } + ////////////////////////////////////////////////////////////////////////// // PRIVATE ENGINES @@ -159,8 +166,18 @@ bool UrlResolver::isHttp() // STEP 1 = QUrl from User Input (easily the best solution... ) UrlSearchList UrlResolver::qurlFromUserInputResolution() { - UrlSearchItem gItem(UrlSearchItem::Browse, KUrl(_urlString), QString()); - return UrlSearchList() << gItem; + UrlSearchList list; + QString url2 = _typedString; + QUrl urlFromUserInput = QUrl::fromUserInput(url2); + if(urlFromUserInput.isValid()) + { + KUrl gUrl(urlFromUserInput); + QString gTitle = i18n("Browse"); + UrlSearchItem gItem(UrlSearchItem::Browse, gUrl, gTitle); + list << gItem; + } + + return list; } @@ -169,11 +186,9 @@ UrlSearchList UrlResolver::webSearchesResolution() { UrlSearchList list; - if(KUrl(_urlString).isRelative()) - { - QString gUrl = QString("http://www.google.com/search?q=%1&ie=UTF-8&oe=UTF-8").arg(_urlString); - QString gTitle = i18n("Search Google for ") + _urlString; - UrlSearchItem gItem(UrlSearchItem::Search, KUrl(), gTitle); + if(KUrl(_typedString).isRelative()) + { + UrlSearchItem gItem(UrlSearchItem::Search, KUrl(), QString() ); // others will find this url.. list << gItem; } @@ -187,7 +202,7 @@ UrlSearchList UrlResolver::historyResolution() UrlSearchList list; KCompletion *historyCompletion = Application::historyManager()->completionObject(); - QStringList historyResults = historyCompletion->substringCompletion(_urlString); + QStringList historyResults = historyCompletion->substringCompletion(_typedString); Q_FOREACH(const QString &s, historyResults) { UrlSearchItem it(UrlSearchItem::History, KUrl(s), Application::historyManager()->titleForHistoryUrl(s)); @@ -204,13 +219,12 @@ UrlSearchList UrlResolver::bookmarksResolution() UrlSearchList list; KCompletion *bookmarkCompletion = Application::bookmarkProvider()->completionObject(); - QStringList bookmarkResults = bookmarkCompletion->substringCompletion(_urlString); + QStringList bookmarkResults = bookmarkCompletion->substringCompletion(_typedString); Q_FOREACH(const QString &s, bookmarkResults) { UrlSearchItem it(UrlSearchItem::Bookmark, KUrl(s), Application::bookmarkProvider()->titleForBookmarkUrl(s)); list << it; } - return list; } diff --git a/src/urlbar/urlresolver.h b/src/urlbar/urlresolver.h index 610b1fd0..22a9de4f 100644 --- a/src/urlbar/urlresolver.h +++ b/src/urlbar/urlresolver.h @@ -51,10 +51,9 @@ class UrlSearchItem int type; KUrl url; QString title; - QString icon; - UrlSearchItem(const int &_type, const KUrl &_url, const QString &_title = QString(), const QString &_icon = QString()) - : type(_type), url(_url), title(_title), icon(_icon) + UrlSearchItem(const int &_type, const KUrl &_url, const QString &_title = QString()) + : type(_type), url(_url), title(_title) {}; bool operator==(UrlSearchItem i); @@ -74,7 +73,7 @@ public: UrlSearchList orderedSearchItems(); private: - QString _urlString; //TODO: give a better name + QString _typedString; UrlSearchList webSearchesResolution(); UrlSearchList historyResolution(); -- 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 +++++--- src/urlbar/listitem.h | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'src/urlbar') 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+""); } diff --git a/src/urlbar/listitem.h b/src/urlbar/listitem.h index e355160a..2f6f898a 100644 --- a/src/urlbar/listitem.h +++ b/src/urlbar/listitem.h @@ -114,7 +114,7 @@ class ItemText : public QLabel Q_OBJECT public: - ItemText(const QString &text, const QString &textToPointOut, QWidget *parent = 0); + ItemText(const QString &text, const QString &textToPointOut = QString(), QWidget *parent = 0); }; -- cgit v1.2.1 From dbb6991b2fd9a2b76fd954d214e9c907c8123ea6 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Sat, 17 Apr 2010 18:03:19 +0200 Subject: Based on Lionel's merge request #80: letting CompletionWidget being independent from the Urlbar --- src/urlbar/completionwidget.cpp | 38 ++++++++++++++++++++++++++++++++------ src/urlbar/completionwidget.h | 10 +++++----- src/urlbar/urlbar.cpp | 40 +++++----------------------------------- src/urlbar/urlbar.h | 11 +++-------- 4 files changed, 45 insertions(+), 54 deletions(-) (limited to 'src/urlbar') diff --git a/src/urlbar/completionwidget.cpp b/src/urlbar/completionwidget.cpp index 83e99f9d..d6777b18 100644 --- a/src/urlbar/completionwidget.cpp +++ b/src/urlbar/completionwidget.cpp @@ -30,6 +30,7 @@ // Local Includes #include "application.h" +#include "urlresolver.h" // KDE Includes #include @@ -173,6 +174,8 @@ bool CompletionWidget::eventFilter( QObject *o, QEvent *e ) //actions on the CompletionWidget if (wid && wid->isAncestorOf(_parent) && isVisible()) { + ListItem *child; + if ( type == QEvent::KeyPress ) { QKeyEvent *ev = static_cast( e ); @@ -196,7 +199,7 @@ bool CompletionWidget::eventFilter( QObject *o, QEvent *e ) ev->accept(); return true; } - else if (ev->modifiers() & Qt::ControlModifier) + if (ev->modifiers() & Qt::ControlModifier) { emit nextItemSubChoice(); ev->accept(); @@ -206,18 +209,19 @@ bool CompletionWidget::eventFilter( QObject *o, QEvent *e ) case Qt::Key_Enter: case Qt::Key_Return: - - // need this to let ListItem magic work.. - ListItem *child = findChild( QString::number(_currentIndex) ); + child = findChild( QString::number(_currentIndex) ); emit chosenUrl( child->url(), Rekonq::CurrentTab); ev->accept(); hide(); return true; - break; + + case Qt::Key_Escape: + hide(); + return true; } } } - + return QFrame::eventFilter(o,e); } @@ -246,3 +250,25 @@ void CompletionWidget::itemChosen(ListItem *item, Qt::MouseButton button) emit chosenUrl( item->url(), Rekonq::CurrentTab); hide(); } + + + + +void CompletionWidget::suggestUrls(const QString &text) +{ + if(text.isEmpty()) + { + hide(); + return; + } + + UrlResolver res(text); + UrlSearchList list = res.orderedSearchItems(); + + if(list.count() > 0) + { + clear(); + insertSearchList(list, text); + popup(); + } +} diff --git a/src/urlbar/completionwidget.h b/src/urlbar/completionwidget.h index 125e186a..896518fc 100644 --- a/src/urlbar/completionwidget.h +++ b/src/urlbar/completionwidget.h @@ -30,7 +30,6 @@ // Local Includes #include "application.h" -#include "urlresolver.h" #include "listitem.h" // KDE Includes @@ -47,21 +46,22 @@ class CompletionWidget : public QFrame public: CompletionWidget(QWidget *parent); - void insertSearchList(const UrlSearchList &list, const QString& text); - void popup(); - void clear(); - virtual bool eventFilter(QObject *obj, QEvent *ev); void setVisible(bool visible); private slots: void itemChosen(ListItem *item, Qt::MouseButton = Qt::LeftButton); + void suggestUrls(const QString &text); signals: void chosenUrl(const KUrl &, Rekonq::OpenType); void nextItemSubChoice(); private: + void insertSearchList(const UrlSearchList &list, const QString& text); + void popup(); + void clear(); + void sizeAndPosition(); void up(); void down(); diff --git a/src/urlbar/urlbar.cpp b/src/urlbar/urlbar.cpp index 4e7310bf..a4c7a0e0 100644 --- a/src/urlbar/urlbar.cpp +++ b/src/urlbar/urlbar.cpp @@ -38,8 +38,9 @@ #include "application.h" #include "lineedit.h" #include "mainwindow.h" +#include "webtab.h" #include "webview.h" -#include "urlresolver.h" +#include "completionwidget.h" // KDE Includes #include @@ -71,7 +72,7 @@ UrlBar::UrlBar(QWidget *parent) // suggestions installEventFilter(_box); - connect(_box, SIGNAL(chosenUrl(const KUrl &, Rekonq::OpenType)), SLOT(activated(const KUrl &, Rekonq::OpenType))); + connect(_box, SIGNAL(chosenUrl(const KUrl &, Rekonq::OpenType)), this, SLOT(activated(const KUrl &, Rekonq::OpenType))); // load typed urls connect(this, SIGNAL(returnPressed(const QString &)), this, SLOT(loadTyped(const QString &))); @@ -103,7 +104,7 @@ void UrlBar::setQUrl(const QUrl& url) void UrlBar::activated(const KUrl& url, Rekonq::OpenType type) { - disconnect(this, SIGNAL(textChanged(const QString &)), this, SLOT(suggestUrls(const QString &))); + disconnect(this, SIGNAL(textChanged(const QString &)), _box, SLOT(suggestUrls(const QString &))); clearFocus(); setUrl(url); @@ -152,12 +153,6 @@ void UrlBar::paintEvent(QPaintEvent *event) void UrlBar::keyPressEvent(QKeyEvent *event) { - if(event->key() == Qt::Key_Escape) - { - _box->hide(); - return; - } - // this handles the Modifiers + Return key combinations QString currentText = text().trimmed(); if ((event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) @@ -191,35 +186,10 @@ void UrlBar::keyPressEvent(QKeyEvent *event) } -void UrlBar::suggestUrls(const QString &text) -{ - if (!hasFocus()) - { - return; - } - - if(text.isEmpty()) - { - _box->hide(); - return; - } - - UrlResolver res(text); - UrlSearchList list = res.orderedSearchItems(); - - if(list.count() > 0) - { - _box->clear(); - _box->insertSearchList(list, text); - _box->popup(); - } -} - - void UrlBar::focusInEvent(QFocusEvent *event) { // activate suggestions on edit text - connect(this, SIGNAL(textChanged(const QString &)), this, SLOT(suggestUrls(const QString &))); + connect(this, SIGNAL(textChanged(const QString &)), _box, SLOT(suggestUrls(const QString &))); LineEdit::focusInEvent(event); } diff --git a/src/urlbar/urlbar.h b/src/urlbar/urlbar.h index 804188f7..3ecd914e 100644 --- a/src/urlbar/urlbar.h +++ b/src/urlbar/urlbar.h @@ -33,20 +33,16 @@ // Local Includes #include "lineedit.h" -#include "completionwidget.h" -#include "webtab.h" +#include "application.h" // KDE Includes #include -#include - -// Qt Includes -#include -#include // Forward Declarations class QLinearGradient; class QWidget; +class CompletionWidget; +class WebTab; class UrlBar : public LineEdit @@ -61,7 +57,6 @@ public: private slots: void activated(const KUrl& url, Rekonq::OpenType = Rekonq::CurrentTab); - void suggestUrls(const QString &editedText); void setQUrl(const QUrl &url); void loadFinished(); -- 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 +++--------------------- src/urlbar/listitem.h | 3 --- 2 files changed, 3 insertions(+), 24 deletions(-) (limited to 'src/urlbar') 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; -} - - // --------------------------------------------------------------- diff --git a/src/urlbar/listitem.h b/src/urlbar/listitem.h index 2f6f898a..8a6f520f 100644 --- a/src/urlbar/listitem.h +++ b/src/urlbar/listitem.h @@ -193,9 +193,6 @@ class ItemPreview : public QLabel public: ItemPreview(const QString &url, int width, int height, QWidget *parent = 0); - -private: - static QString guessNameFromUrl(QUrl url); }; -- cgit v1.2.1 From ceba6a65a94b69f495977b24dc592b53896f25f1 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Sat, 17 Apr 2010 18:51:58 +0200 Subject: Workaound the focus bar problem --- src/urlbar/completionwidget.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/urlbar') diff --git a/src/urlbar/completionwidget.cpp b/src/urlbar/completionwidget.cpp index d6777b18..be86238d 100644 --- a/src/urlbar/completionwidget.cpp +++ b/src/urlbar/completionwidget.cpp @@ -256,6 +256,10 @@ void CompletionWidget::itemChosen(ListItem *item, Qt::MouseButton button) void CompletionWidget::suggestUrls(const QString &text) { + QWidget *w = qobject_cast(parent()); + if(!w->hasFocus()) + return; + if(text.isEmpty()) { hide(); -- cgit v1.2.1 From 708e029be1c2d790aa6891841f5425d8671e0bf3 Mon Sep 17 00:00:00 2001 From: Yoann Laissus Date: Sat, 17 Apr 2010 23:22:48 +0200 Subject: Fix the completition widget opening when the urlbar has the focus and we want to load an url It fix also the same issue with redirection --- src/urlbar/urlbar.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/urlbar') diff --git a/src/urlbar/urlbar.cpp b/src/urlbar/urlbar.cpp index a4c7a0e0..8c6c0749 100644 --- a/src/urlbar/urlbar.cpp +++ b/src/urlbar/urlbar.cpp @@ -95,6 +95,7 @@ void UrlBar::setQUrl(const QUrl& url) } else { + clearFocus(); LineEdit::setUrl(url); setCursorPosition(0); iconButton()->setIcon( Application::icon(url) ); -- 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') 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 ++++++++++++++++++++++++++++++++++++--------- src/urlbar/listitem.h | 1 + 2 files changed, 37 insertions(+), 9 deletions(-) (limited to 'src/urlbar') 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; } diff --git a/src/urlbar/listitem.h b/src/urlbar/listitem.h index 8a6f520f..a9dc8213 100644 --- a/src/urlbar/listitem.h +++ b/src/urlbar/listitem.h @@ -127,6 +127,7 @@ class EngineBar : public KToolBar public: EngineBar(const QString &text, const QString &selectedEngine, QWidget *parent = 0); + static QString defaultEngine(); void selectNextEngine(); KUrl url() { return m_url; }; -- cgit v1.2.1 From 1fda71fe3d8a2cbbfd25a7fc0e687219267c8eb2 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Mon, 19 Apr 2010 11:54:46 +0200 Subject: Suggestions activation on demand --- src/urlbar/urlbar.cpp | 37 ++++++++++++++++++++++++++++--------- src/urlbar/urlbar.h | 7 ++++++- 2 files changed, 34 insertions(+), 10 deletions(-) (limited to 'src/urlbar') diff --git a/src/urlbar/urlbar.cpp b/src/urlbar/urlbar.cpp index 8c6c0749..6d1b19c9 100644 --- a/src/urlbar/urlbar.cpp +++ b/src/urlbar/urlbar.cpp @@ -60,7 +60,6 @@ UrlBar::UrlBar(QWidget *parent) : LineEdit(parent) - , _box(new CompletionWidget(this)) , _tab(0) , _privateMode(false) { @@ -69,19 +68,18 @@ UrlBar::UrlBar(QWidget *parent) connect(_tab->view(), SIGNAL(urlChanged(const QUrl &)), this, SLOT(setQUrl(const QUrl &))); connect(_tab->view(), SIGNAL(loadFinished(bool)), this, SLOT(loadFinished())); connect(_tab->view(), SIGNAL(loadStarted()), this, SLOT(clearRightIcons())); - - // suggestions - installEventFilter(_box); - connect(_box, SIGNAL(chosenUrl(const KUrl &, Rekonq::OpenType)), this, SLOT(activated(const KUrl &, Rekonq::OpenType))); // load typed urls connect(this, SIGNAL(returnPressed(const QString &)), this, SLOT(loadTyped(const QString &))); + + activateSuggestions(true); } UrlBar::~UrlBar() { - delete _box; + activateSuggestions(false); + _box.clear(); } @@ -105,7 +103,7 @@ void UrlBar::setQUrl(const QUrl& url) void UrlBar::activated(const KUrl& url, Rekonq::OpenType type) { - disconnect(this, SIGNAL(textChanged(const QString &)), _box, SLOT(suggestUrls(const QString &))); + activateSuggestions(false); clearFocus(); setUrl(url); @@ -189,8 +187,7 @@ void UrlBar::keyPressEvent(QKeyEvent *event) void UrlBar::focusInEvent(QFocusEvent *event) { - // activate suggestions on edit text - connect(this, SIGNAL(textChanged(const QString &)), _box, SLOT(suggestUrls(const QString &))); + activateSuggestions(true); LineEdit::focusInEvent(event); } @@ -249,3 +246,25 @@ void UrlBar::loadTyped(const QString &text) { activated(KUrl(text)); } + + +void UrlBar::activateSuggestions(bool b) +{ + if(b) + { + if(_box.isNull()) + { + _box = new CompletionWidget(this); + installEventFilter(_box.data()); + connect(_box.data(), SIGNAL(chosenUrl(const KUrl &, Rekonq::OpenType)), this, SLOT(activated(const KUrl &, Rekonq::OpenType))); + + // activate suggestions on edit text + connect(this, SIGNAL(textChanged(const QString &)), _box.data(), SLOT(suggestUrls(const QString &))); + } + } + else + { + removeEventFilter(_box.data()); + _box.data()->deleteLater(); + } +} diff --git a/src/urlbar/urlbar.h b/src/urlbar/urlbar.h index 3ecd914e..9adc35a3 100644 --- a/src/urlbar/urlbar.h +++ b/src/urlbar/urlbar.h @@ -38,6 +38,9 @@ // KDE Includes #include +// Qt Includes +#include + // Forward Declarations class QLinearGradient; class QWidget; @@ -69,7 +72,9 @@ protected: virtual void dropEvent(QDropEvent *event); private: - CompletionWidget *_box; + void activateSuggestions(bool); + + QWeakPointer _box; WebTab *_tab; bool _privateMode; }; -- cgit v1.2.1 From 1f8a013b182660c6f12c75f740cd5beac70f0949 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Mon, 19 Apr 2010 16:21:33 +0200 Subject: Fix urlbar string as suggested by Johannes Zellner --- src/urlbar/lineedit.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/urlbar') diff --git a/src/urlbar/lineedit.cpp b/src/urlbar/lineedit.cpp index 09c158fa..6236512f 100644 --- a/src/urlbar/lineedit.cpp +++ b/src/urlbar/lineedit.cpp @@ -129,7 +129,7 @@ void LineEdit::paintEvent(QPaintEvent *event) painter.setPen(Qt::gray); painter.drawText( textRect, Qt::AlignCenter, - i18n("Search Bookmarks, History, Google.. just start typing here!") + i18n("Search Bookmarks, History, Web.. just start typing here!") ); } } -- 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 +++++++++++++++++++++++++---------------------- src/urlbar/listitem.h | 20 ++++++++++---------- 2 files changed, 35 insertions(+), 32 deletions(-) (limited to 'src/urlbar') 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) ); } diff --git a/src/urlbar/listitem.h b/src/urlbar/listitem.h index a9dc8213..67bfb764 100644 --- a/src/urlbar/listitem.h +++ b/src/urlbar/listitem.h @@ -82,12 +82,12 @@ protected: // ------------------------------------------------------------------------- -class TypeIcon : public QLabel +class TypeIconLabel : public QLabel { Q_OBJECT public: - TypeIcon(int type, QWidget *parent = 0); + TypeIconLabel(int type, QWidget *parent = 0); private: QLabel *getIcon(QString icon); @@ -97,24 +97,24 @@ private: // ------------------------------------------------------------------------- -class ItemIcon : public QLabel +class IconLabel : public QLabel { Q_OBJECT public: - ItemIcon(const QString &icon, QWidget *parent = 0); + IconLabel(const QString &icon, QWidget *parent = 0); }; // ------------------------------------------------------------------------- -class ItemText : public QLabel +class TextLabel : public QLabel { Q_OBJECT public: - ItemText(const QString &text, const QString &textToPointOut = QString(), QWidget *parent = 0); + TextLabel(const QString &text, const QString &textToPointOut = QString(), QWidget *parent = 0); }; @@ -164,8 +164,8 @@ private slots: private: QString searchItemTitle(QString engine, QString text); - ItemText* m_titleLabel; - ItemIcon* m_iconLabel; + TextLabel* m_titleLabel; + IconLabel* m_iconLabel; EngineBar* m_engineBar; QString m_text; @@ -188,12 +188,12 @@ public: // ------------------------------------------------------------------------- -class ItemPreview : public QLabel +class PreviewLabel : public QLabel { Q_OBJECT public: - ItemPreview(const QString &url, int width, int height, QWidget *parent = 0); + PreviewLabel(const QString &url, int width, int height, QWidget *parent = 0); }; -- 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/completionwidget.cpp | 44 ++++++++++++++++-- src/urlbar/completionwidget.h | 8 +++- src/urlbar/listitem.cpp | 98 +++++++++++++++-------------------------- src/urlbar/listitem.h | 7 ++- 4 files changed, 86 insertions(+), 71 deletions(-) (limited to 'src/urlbar') diff --git a/src/urlbar/completionwidget.cpp b/src/urlbar/completionwidget.cpp index be86238d..8307940b 100644 --- a/src/urlbar/completionwidget.cpp +++ b/src/urlbar/completionwidget.cpp @@ -28,6 +28,9 @@ #include "completionwidget.h" #include "completionwidget.moc" +// Auto Includes +#include "rekonq.h" + // Local Includes #include "application.h" #include "urlresolver.h" @@ -45,11 +48,15 @@ #include #include +// Defines +#define QL1S(x) QLatin1String(x) + CompletionWidget::CompletionWidget(QWidget *parent) - : QFrame( parent, Qt::ToolTip) + : QFrame(parent, Qt::ToolTip) , _parent(parent) , _currentIndex(-1) + , _searchEngine( defaultSearchEngine() ) { setFrameStyle(QFrame::Panel); setLayoutDirection(Qt::LeftToRight); @@ -66,8 +73,8 @@ void CompletionWidget::insertSearchList(const UrlSearchList &list, const QString int i = 0; foreach(UrlSearchItem item, _list) { - ListItem *suggestion = ListItemFactory::create(item, text); - suggestion->setBackgroundRole(i%2 ? QPalette::AlternateBase: QPalette::Base); + ListItem *suggestion = ListItemFactory::create(item, text, this); + suggestion->setBackgroundRole(i%2 ? QPalette::AlternateBase : QPalette::Base); connect(suggestion, SIGNAL(itemClicked(ListItem *, Qt::MouseButton)), this, SLOT(itemChosen(ListItem *, Qt::MouseButton))); connect(this, SIGNAL(nextItemSubChoice()), suggestion, SLOT(nextItemSubChoice())); suggestion->setObjectName( QString::number(i++) ); @@ -268,7 +275,6 @@ void CompletionWidget::suggestUrls(const QString &text) UrlResolver res(text); UrlSearchList list = res.orderedSearchItems(); - if(list.count() > 0) { clear(); @@ -276,3 +282,33 @@ void CompletionWidget::suggestUrls(const QString &text) popup(); } } + + +QString CompletionWidget::defaultSearchEngine() +{ + 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; +} diff --git a/src/urlbar/completionwidget.h b/src/urlbar/completionwidget.h index 896518fc..e9851484 100644 --- a/src/urlbar/completionwidget.h +++ b/src/urlbar/completionwidget.h @@ -49,6 +49,9 @@ public: virtual bool eventFilter(QObject *obj, QEvent *ev); void setVisible(bool visible); + QString searchEngine() { return _searchEngine; }; + void setCurrentEngine(const QString &engine) { _searchEngine = engine; }; + private slots: void itemChosen(ListItem *item, Qt::MouseButton = Qt::LeftButton); void suggestUrls(const QString &text); @@ -58,6 +61,8 @@ signals: void nextItemSubChoice(); private: + QString defaultSearchEngine(); + void insertSearchList(const UrlSearchList &list, const QString& text); void popup(); void clear(); @@ -70,7 +75,8 @@ private: UrlSearchList _list; int _currentIndex; - QString *_searchEngine; + + QString _searchEngine; }; #endif // COMPLETION_WIDGET_H 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; } diff --git a/src/urlbar/listitem.h b/src/urlbar/listitem.h index 67bfb764..de42fd03 100644 --- a/src/urlbar/listitem.h +++ b/src/urlbar/listitem.h @@ -128,7 +128,6 @@ class EngineBar : public KToolBar public: EngineBar(const QString &text, const QString &selectedEngine, QWidget *parent = 0); - static QString defaultEngine(); void selectNextEngine(); KUrl url() { return m_url; }; @@ -164,12 +163,12 @@ private slots: private: QString searchItemTitle(QString engine, QString text); + TextLabel* m_titleLabel; IconLabel* m_iconLabel; EngineBar* m_engineBar; - QString m_text; - static QString m_currentEngine; + QString m_text; }; @@ -215,7 +214,7 @@ public: class ListItemFactory { public: - static ListItem *create(const UrlSearchItem &item, const QString &text, QWidget *parent = 0); + static ListItem *create(const UrlSearchItem &item, const QString &text, QWidget *parent); }; -- 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') 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 From a708a0e447af81412599ec16e8d47e06dc584eb0 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Tue, 20 Apr 2010 16:43:10 +0200 Subject: New (empty) urlbar test and improved protocolhandler test --- src/urlbar/urlbar.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/urlbar') diff --git a/src/urlbar/urlbar.h b/src/urlbar/urlbar.h index 9adc35a3..28afc21e 100644 --- a/src/urlbar/urlbar.h +++ b/src/urlbar/urlbar.h @@ -32,6 +32,7 @@ // Local Includes +#include "rekonqprivate_export.h" #include "lineedit.h" #include "application.h" @@ -48,7 +49,7 @@ class CompletionWidget; class WebTab; -class UrlBar : public LineEdit +class REKONQ_TESTS_EXPORT UrlBar : public LineEdit { Q_OBJECT -- cgit v1.2.1