diff options
-rw-r--r-- | src/tabwindow/tabwindow.cpp | 3 | ||||
-rw-r--r-- | src/urlbar/completionwidget.cpp | 106 | ||||
-rw-r--r-- | src/urlbar/completionwidget.h | 2 | ||||
-rw-r--r-- | src/urlbar/urlbar.cpp | 42 | ||||
-rw-r--r-- | src/urlbar/urlbar.h | 8 | ||||
-rw-r--r-- | src/webwindow/webwindow.cpp | 33 | ||||
-rw-r--r-- | src/webwindow/webwindow.h | 2 |
7 files changed, 130 insertions, 66 deletions
diff --git a/src/tabwindow/tabwindow.cpp b/src/tabwindow/tabwindow.cpp index bc43085d..bfdc9bcd 100644 --- a/src/tabwindow/tabwindow.cpp +++ b/src/tabwindow/tabwindow.cpp @@ -381,8 +381,7 @@ void TabWindow::closeTab(int index, bool del) if (count() == 1) { kDebug() << "CANNOT CLOSE WINDOW FROM HERE..."; - QUrl u = QUrl::fromUserInput("/DATI/WEBPAGES/HomePage/index.htm"); - currentWebWindow()->load(u); + currentWebWindow()->load(KUrl("about:home")); return; } diff --git a/src/urlbar/completionwidget.cpp b/src/urlbar/completionwidget.cpp index 12051f80..cf00a77c 100644 --- a/src/urlbar/completionwidget.cpp +++ b/src/urlbar/completionwidget.cpp @@ -261,63 +261,68 @@ bool CompletionWidget::eventFilter(QObject *obj, QEvent *ev) case Qt::Key_Enter: case Qt::Key_Return: + { w = qobject_cast<UrlBar *>(parent()); - if (kev->modifiers() == Qt::AltModifier) - { - if (kev->key() == Qt::Key_Return || kev->key() == Qt::Key_Enter) - { - emit chosenUrl(w->text(), Rekonq::NewFocusedTab); - } - } - - if (!w->text().startsWith(QL1S("http://"), Qt::CaseInsensitive)) - { - QString append; - if (kev->modifiers() == Qt::ControlModifier) - { - append = QL1S(".com"); - } - else if (kev->modifiers() == (Qt::ControlModifier | Qt::ShiftModifier)) - { - append = QL1S(".org"); - } - else if (kev->modifiers() == Qt::ShiftModifier) - { - append = QL1S(".net"); - } - - if (!append.isEmpty()) - { - QUrl url(QL1S("http://") + w->text()); - QString host = url.host(); - if (!host.endsWith(append, Qt::CaseInsensitive)) - { - host += append; - url.setHost(host); - } - - emit chosenUrl(url, Rekonq::CurrentTab); - } - } +// if (!w->text().startsWith(QL1S("http://"), Qt::CaseInsensitive)) +// { +// QString append; +// if (kev->modifiers() == Qt::ControlModifier) +// { +// append = QL1S(".com"); +// } +// else if (kev->modifiers() == (Qt::ControlModifier | Qt::ShiftModifier)) +// { +// append = QL1S(".org"); +// } +// else if (kev->modifiers() == Qt::ShiftModifier) +// { +// append = QL1S(".net"); +// } +// +// if (!append.isEmpty()) +// { +// QUrl url(QL1S("http://") + w->text()); +// QString host = url.host(); +// if (!host.endsWith(append, Qt::CaseInsensitive)) +// { +// host += append; +// url.setHost(host); +// } +// +// emit chosenUrl(url, Rekonq::CurrentTab); +// } +// } + + KUrl urlToLoad; + Rekonq::OpenType type = Rekonq::CurrentTab; + if (_currentIndex == -1) _currentIndex = 0; child = findChild<ListItem *>(QString::number(_currentIndex)); if (child) //the completionwidget is visible and the user had press down { - //we can use the url of the listitem - emit chosenUrl(child->url(), Rekonq::CurrentTab); + urlToLoad = child->url(); } else //the user type too fast (completionwidget not visible or suggestion not downloaded) { - KUrl u = UrlResolver::urlFromTextTyped(w->text()); - emit chosenUrl(u, Rekonq::CurrentTab); + urlToLoad = UrlResolver::urlFromTextTyped(w->text()); } - kev->accept(); + + if (kev->modifiers() == Qt::AltModifier) + { + if (kev->key() == Qt::Key_Return || kev->key() == Qt::Key_Enter) + { + type = Rekonq::NewFocusedTab; + } + } + hide(); + emit chosenUrl(urlToLoad, type); + kev->accept(); return true; - + } case Qt::Key_Escape: hide(); return true; @@ -387,3 +392,18 @@ void CompletionWidget::suggestUrls(const QString &text) // NOTE: It's important to call this AFTER orderedSearchItems() to let everything work res->computeSuggestions(); } + + +KUrl CompletionWidget::activeSuggestion() +{ + int index = _currentIndex; + if (_currentIndex == -1) + index = 0; + + ListItem *child = findChild<ListItem *>(QString::number(index)); + if (child) + return child->url(); + + kDebug() << "WARNING: NO URL to LOAD..."; + return KUrl(); +} diff --git a/src/urlbar/completionwidget.h b/src/urlbar/completionwidget.h index 098aa9f9..bd73584a 100644 --- a/src/urlbar/completionwidget.h +++ b/src/urlbar/completionwidget.h @@ -56,6 +56,8 @@ public: void suggestUrls(const QString &text); + KUrl activeSuggestion(); + private Q_SLOTS: void itemChosen(ListItem *item, Qt::MouseButton = Qt::LeftButton, Qt::KeyboardModifiers = Qt::NoModifier); void updateSuggestionList(const UrlSuggestionList &list, const QString& text); diff --git a/src/urlbar/urlbar.cpp b/src/urlbar/urlbar.cpp index 56d1370d..f10360b0 100644 --- a/src/urlbar/urlbar.cpp +++ b/src/urlbar/urlbar.cpp @@ -159,8 +159,6 @@ UrlBar::UrlBar(QWidget *parent) _suggestionTimer->setSingleShot(true); connect(_suggestionTimer, SIGNAL(timeout()), this, SLOT(suggest())); - - activateSuggestions(true); } @@ -200,10 +198,22 @@ void UrlBar::loadRequestedUrl(const KUrl& url, Rekonq::OpenType type) } -void UrlBar::loadDigitedUrl() +void UrlBar::loadTypedUrl() { - KUrl u = UrlResolver::urlFromTextTyped(text()); - loadRequestedUrl(u); + KUrl urlToLoad; + if (!_box.isNull()) + { + urlToLoad = _box.data()->activeSuggestion(); + if (!urlToLoad.isEmpty()) + { + loadRequestedUrl(urlToLoad); + return; + } + } + + // fallback here + urlToLoad = UrlResolver::urlFromTextTyped(text()); + loadRequestedUrl(urlToLoad); } @@ -333,11 +343,19 @@ void UrlBar::keyPressEvent(QKeyEvent *event) void UrlBar::focusInEvent(QFocusEvent *event) { + emit focusIn(); activateSuggestions(true); KLineEdit::focusInEvent(event); } +void UrlBar::focusOutEvent(QFocusEvent *event) +{ + activateSuggestions(false); + KLineEdit::focusOutEvent(event); +} + + void UrlBar::dropEvent(QDropEvent *event) { // handles only plain-text with url format @@ -429,7 +447,6 @@ void UrlBar::activateSuggestions(bool b) if (_box.isNull()) { _box = new CompletionWidget(this); - installEventFilter(_box.data()); connect(_box.data(), SIGNAL(chosenUrl(KUrl, Rekonq::OpenType)), this, SLOT(loadRequestedUrl(KUrl, Rekonq::OpenType))); // activate suggestions on edit text @@ -439,9 +456,13 @@ void UrlBar::activateSuggestions(bool b) else { disconnect(this, SIGNAL(textChanged(QString)), this, SLOT(detectTypedString(QString))); - removeEventFilter(_box.data()); + if (!_box.isNull()) - _box.data()->deleteLater(); + { + // This was just deleted later because of a crash in completionwidget... + delete _box.data(); + _box.clear(); + } } } @@ -637,15 +658,16 @@ void UrlBar::detectTypedString(const QString &typed) if (_suggestionTimer->isActive()) _suggestionTimer->stop(); - _suggestionTimer->start(50); + _suggestionTimer->start(100); } void UrlBar::suggest() { - kDebug() << "SUGGEST ABOUT DIGITED: " << text(); if (!_box.isNull()) + { _box.data()->suggestUrls(text()); + } } diff --git a/src/urlbar/urlbar.h b/src/urlbar/urlbar.h index 3f283e39..304afbe4 100644 --- a/src/urlbar/urlbar.h +++ b/src/urlbar/urlbar.h @@ -122,9 +122,9 @@ private Q_SLOTS: bool isValidURL(QString url); /** - * Load digited url + * Load typed url */ - void loadDigitedUrl(); + void loadTypedUrl(); void showRSSInfo(const QPoint &); @@ -132,11 +132,15 @@ protected: void paintEvent(QPaintEvent *event); void keyPressEvent(QKeyEvent *event); void focusInEvent(QFocusEvent *event); + void focusOutEvent(QFocusEvent *event); void dropEvent(QDropEvent *event); void mouseDoubleClickEvent(QMouseEvent *); void contextMenuEvent(QContextMenuEvent *event); void resizeEvent(QResizeEvent *); +Q_SIGNALS: + void focusIn(); + private: /** * Updates right icon position, given its number in the right icons list diff --git a/src/webwindow/webwindow.cpp b/src/webwindow/webwindow.cpp index e76d1d5d..f7adb1b6 100644 --- a/src/webwindow/webwindow.cpp +++ b/src/webwindow/webwindow.cpp @@ -128,6 +128,8 @@ WebWindow::WebWindow(QWidget *parent, WebPage *pg) connect(_tab->view(), SIGNAL(loadFinished(bool)), this, SLOT(webLoadFinished(bool))); connect(_tab->view(), SIGNAL(loadProgress(int)), this, SLOT(webLoadProgress(int))); + connect(_bar, SIGNAL(focusIn()), this, SLOT(urlbarFocused())); + // page signals connect(page(), SIGNAL(pageCreated(WebPage *)), this, SIGNAL(pageCreated(WebPage *))); @@ -187,10 +189,7 @@ void WebWindow::setupActions() m_loadStopReloadAction = new KAction(this); actionCollection()->addAction(QL1S("load_stop_reload") , m_loadStopReloadAction); m_loadStopReloadAction->setShortcutConfigurable(false); - - m_loadStopReloadAction->setIcon(KIcon("go-jump-locationbar")); - m_loadStopReloadAction->setToolTip(i18n("Go")); - m_loadStopReloadAction->setText(i18n("Go")); + urlbarFocused(); // new window action a = new KAction(KIcon("window-new"), i18n("&New Window"), this); @@ -362,15 +361,31 @@ void WebWindow::webLoadFinished(bool b) { emit loadFinished(b); - m_loadStopReloadAction->setIcon(KIcon("view-refresh")); - m_loadStopReloadAction->setToolTip(i18n("Reload the current page")); - m_loadStopReloadAction->setText(i18n("Reload")); - connect(m_loadStopReloadAction, SIGNAL(triggered(bool)), _tab->view(), SLOT(reload())); - + if (_bar->hasFocus()) + { + urlbarFocused(); + } + else + { + m_loadStopReloadAction->setIcon(KIcon("view-refresh")); + m_loadStopReloadAction->setToolTip(i18n("Reload the current page")); + m_loadStopReloadAction->setText(i18n("Reload")); + connect(m_loadStopReloadAction, SIGNAL(triggered(bool)), _tab->view(), SLOT(reload())); + } + updateHistoryActions(); } +void WebWindow::urlbarFocused() +{ + m_loadStopReloadAction->setIcon(KIcon("go-jump-locationbar")); + m_loadStopReloadAction->setToolTip(i18n("Go")); + m_loadStopReloadAction->setText(i18n("Go")); + connect(m_loadStopReloadAction, SIGNAL(triggered(bool)), _bar, SLOT(loadTypedUrl())); +} + + void WebWindow::aboutToShowBackMenu() { m_historyBackMenu->clear(); diff --git a/src/webwindow/webwindow.h b/src/webwindow/webwindow.h index fa465ddc..a333f310 100644 --- a/src/webwindow/webwindow.h +++ b/src/webwindow/webwindow.h @@ -97,6 +97,8 @@ private Q_SLOTS: void webLoadStarted(); void webLoadFinished(bool); + void urlbarFocused(); + // history related void aboutToShowBackMenu(); void aboutToShowForwardMenu(); |