summaryrefslogtreecommitdiff
path: root/src/urlbar/completionwidget.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/urlbar/completionwidget.cpp')
-rw-r--r--src/urlbar/completionwidget.cpp69
1 files changed, 24 insertions, 45 deletions
diff --git a/src/urlbar/completionwidget.cpp b/src/urlbar/completionwidget.cpp
index 62eb72a6..b77e2d7c 100644
--- a/src/urlbar/completionwidget.cpp
+++ b/src/urlbar/completionwidget.cpp
@@ -54,7 +54,7 @@
CompletionWidget::CompletionWidget(QWidget *parent)
: QFrame(parent, Qt::ToolTip)
, _parent(parent)
- , _currentIndex(-1)
+ , _currentIndex(0)
, _searchEngine(SearchEngine::defaultEngine())
{
setFrameStyle(QFrame::Panel);
@@ -107,6 +107,7 @@ void CompletionWidget::sizeAndPosition()
void CompletionWidget::popup()
{
+ findChild<ListItem *>(QString::number(0))->activate(); //activate first listitem
sizeAndPosition();
if (!isVisible())
show();
@@ -116,65 +117,47 @@ void CompletionWidget::popup()
void CompletionWidget::up()
{
// deactivate previous
- if (_currentIndex != -1)
- {
- ListItem *widget = findChild<ListItem *>(QString::number(_currentIndex));
- widget->deactivate();
- }
+ findChild<ListItem *>(QString::number(_currentIndex))->deactivate(); // deactivate previous
- if (_currentIndex >= 0)
+ if (_currentIndex > 0)
_currentIndex--;
else
_currentIndex = layout()->count() - 1;
- kDebug() << _currentIndex;
- kDebug() << _typedString;
- UrlBar *bar = qobject_cast<UrlBar *>(_parent);
- if(_currentIndex != -1)
- {
- // activate "new" current
- ListItem *widget = findChild<ListItem *>(QString::number(_currentIndex));
- widget->activate();
- bar->setQUrl( widget->url() );
- }
- else
- {
- bar->setText(_typedString);
- }
- bar->setFocus();
- bar->setCursorPosition( bar->text().length() );
+ activateCurrentListItem();
}
void CompletionWidget::down()
{
- // deactivate previous
- if (_currentIndex != -1)
- {
- ListItem *widget = findChild<ListItem *>(QString::number(_currentIndex));
- widget->deactivate();
- }
+ findChild<ListItem *>(QString::number(_currentIndex))->deactivate(); // deactivate previous
if (_currentIndex < _list.count() - 1)
_currentIndex++;
else
- _currentIndex = -1;
+ _currentIndex = 0;
+
+ activateCurrentListItem();
+}
+
-
+void CompletionWidget::activateCurrentListItem()
+{
kDebug() << _currentIndex;
kDebug() << _typedString;
UrlBar *bar = qobject_cast<UrlBar *>(_parent);
- if(_currentIndex != -1)
- {
- // activate "new" current
- ListItem *widget = findChild<ListItem *>(QString::number(_currentIndex));
- widget->activate();
+
+ // activate "new" current
+ ListItem *widget = findChild<ListItem *>(QString::number(_currentIndex));
+ widget->activate();
+
+ //update text of the url bar
+ bar->blockSignals(true); //without compute suggestions
+ if (!widget->inherits("SearchListItem"))
bar->setQUrl( widget->url() );
- }
else
- {
- bar->setText(_typedString);
- }
+ bar->setQUrl( _typedString );
+ bar->blockSignals(false);
bar->setFocus();
bar->setCursorPosition( bar->text().length() );
}
@@ -188,7 +171,7 @@ void CompletionWidget::clear()
delete child->widget();
delete child;
}
- _currentIndex = -1;
+ _currentIndex = 0;
}
@@ -309,10 +292,6 @@ void CompletionWidget::itemChosen(ListItem *item, Qt::MouseButton button, Qt::Ke
void CompletionWidget::suggestUrls(const QString &text)
{
- if(_currentIndex != -1)
- return;
-
- kDebug() << "suggesting...";
_typedString = text;
QWidget *w = qobject_cast<QWidget *>(parent());