diff options
Diffstat (limited to 'src/urlbar')
-rw-r--r-- | src/urlbar/completionwidget.cpp | 69 | ||||
-rw-r--r-- | src/urlbar/completionwidget.h | 6 | ||||
-rw-r--r-- | src/urlbar/urlbar.cpp | 18 |
3 files changed, 41 insertions, 52 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()); diff --git a/src/urlbar/completionwidget.h b/src/urlbar/completionwidget.h index fbca5b81..e14535f4 100644 --- a/src/urlbar/completionwidget.h +++ b/src/urlbar/completionwidget.h @@ -78,16 +78,12 @@ private: void sizeAndPosition(); void up(); void down(); + void activateCurrentListItem(); QWidget *_parent; UrlSearchList _list; - /** - * The current index of the pointed out item - * - * -1 means no item, so the actual typed text is considered - */ int _currentIndex; KService::Ptr _searchEngine; diff --git a/src/urlbar/urlbar.cpp b/src/urlbar/urlbar.cpp index 5c3cba28..d924a30d 100644 --- a/src/urlbar/urlbar.cpp +++ b/src/urlbar/urlbar.cpp @@ -185,9 +185,23 @@ void UrlBar::paintEvent(QPaintEvent *event) } else { - QColor loadingColor = Application::palette().color(QPalette::ToolTipBase); + QColor highlight = Application::palette().color(QPalette::Highlight); - QLinearGradient gradient( QPoint(0, 0), QPoint(width(), height()) ); + int r = (highlight.red()+2*backgroundColor.red())/3; + int g = (highlight.green()+2*backgroundColor.green())/3; + int b = (highlight.blue()+2*backgroundColor.blue())/3; + + QColor loadingColor(r, g, b); + + if (abs(loadingColor.lightness() - backgroundColor.lightness()) < 20) //eg. Gaia color scheme + { + r = (2*highlight.red()+backgroundColor.red())/3; + g = (2*highlight.green()+backgroundColor.green())/3; + b = (2*highlight.blue()+backgroundColor.blue())/3; + loadingColor = QColor(r, g, b); + } + + QLinearGradient gradient( QPoint(0, 0), QPoint(width(), 0) ); gradient.setColorAt(0, loadingColor); gradient.setColorAt(((double)progr) / 100 - .000001, loadingColor); gradient.setColorAt(((double)progr) / 100, backgroundColor); |