summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/urlbar/urlbar.cpp37
-rw-r--r--src/urlbar/urlbar.h7
2 files changed, 34 insertions, 10 deletions
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 <KUrl>
+// Qt Includes
+#include <QWeakPointer>
+
// Forward Declarations
class QLinearGradient;
class QWidget;
@@ -69,7 +72,9 @@ protected:
virtual void dropEvent(QDropEvent *event);
private:
- CompletionWidget *_box;
+ void activateSuggestions(bool);
+
+ QWeakPointer<CompletionWidget> _box;
WebTab *_tab;
bool _privateMode;
};