diff options
Diffstat (limited to 'src/urlbar')
-rw-r--r-- | src/urlbar/completionwidget.cpp | 42 | ||||
-rw-r--r-- | src/urlbar/completionwidget.h | 10 | ||||
-rw-r--r-- | src/urlbar/listitem.cpp | 32 | ||||
-rw-r--r-- | src/urlbar/listitem.h | 5 | ||||
-rw-r--r-- | src/urlbar/urlbar.cpp | 41 | ||||
-rw-r--r-- | src/urlbar/urlbar.h | 11 |
6 files changed, 59 insertions, 82 deletions
diff --git a/src/urlbar/completionwidget.cpp b/src/urlbar/completionwidget.cpp index 83e99f9d..be86238d 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 <KGlobalSettings> @@ -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<QKeyEvent *>( 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<ListItem *>( QString::number(_currentIndex) ); + child = findChild<ListItem *>( 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,29 @@ void CompletionWidget::itemChosen(ListItem *item, Qt::MouseButton button) emit chosenUrl( item->url(), Rekonq::CurrentTab); hide(); } + + + + +void CompletionWidget::suggestUrls(const QString &text) +{ + QWidget *w = qobject_cast<QWidget *>(parent()); + if(!w->hasFocus()) + return; + + 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/listitem.cpp b/src/urlbar/listitem.cpp index 7d1d39b2..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 <KIcon> @@ -199,7 +200,9 @@ ItemText::ItemText(const QString &text, const QString &textToPointOut, QWidget * : QLabel(parent) { QString t = text; - t = t.replace(QRegExp("(" + textToPointOut + ")", Qt::CaseInsensitive), "<b>\\1</b>"); + if (!textToPointOut.isEmpty()) + t = t.replace(QRegExp("(" + textToPointOut + ")", Qt::CaseInsensitive), "<b>\\1</b>"); + setText(t); setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); } @@ -236,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; @@ -246,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; -} - - // --------------------------------------------------------------- @@ -279,7 +263,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 +281,7 @@ SearchListItem::SearchListItem(const UrlSearchItem &item, const QString &text, Q QString SearchListItem::searchItemTitle(QString engine, QString text) { - return QString("Search "+ engine +" for <u>"+text+"</u>"); + return QString("Search "+ engine +" for <b>"+text+"</b>"); } diff --git a/src/urlbar/listitem.h b/src/urlbar/listitem.h index e355160a..8a6f520f 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); }; @@ -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); }; diff --git a/src/urlbar/urlbar.cpp b/src/urlbar/urlbar.cpp index 4e7310bf..8c6c0749 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 <KDebug> @@ -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 &))); @@ -94,6 +95,7 @@ void UrlBar::setQUrl(const QUrl& url) } else { + clearFocus(); LineEdit::setUrl(url); setCursorPosition(0); iconButton()->setIcon( Application::icon(url) ); @@ -103,7 +105,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 +154,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 +187,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 <KUrl> -#include <KComboBox> - -// Qt Includes -#include <QUrl> -#include <QPointer> // 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(); |