From 94186b36d9b3b74b87ed892e573c747a24f63b51 Mon Sep 17 00:00:00 2001 From: Lionel Chauvin Date: Sat, 22 Aug 2009 17:43:17 +0200 Subject: Remove url stack --- src/urlbar.cpp | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 56 insertions(+), 5 deletions(-) (limited to 'src/urlbar.cpp') diff --git a/src/urlbar.cpp b/src/urlbar.cpp index 94f248e3..6ece4783 100644 --- a/src/urlbar.cpp +++ b/src/urlbar.cpp @@ -55,11 +55,16 @@ UrlBar::UrlBar(QWidget *parent) : KHistoryComboBox(true, parent) , m_lineEdit(new LineEdit) , m_progress(0) + , m_completion(0) + , m_completionModel(0) { setUrlDropsEnabled(true); setAutoDeleteCompletionObject(true); - setMinimumWidth(180); + //cosmetic + setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + setMinimumWidth(180); + setTrapReturnKey(true); setupLineEdit(); @@ -72,7 +77,8 @@ UrlBar::UrlBar(QWidget *parent) // setup completion box completionBox()->setTabHandling(true); // Konqueror bug #167135 - + setCompletionObject(completion()); + // set dropdown list background QPalette p = view()->palette(); p.setColor(QPalette::Base, palette().color(QPalette::Base)); @@ -132,14 +138,17 @@ void UrlBar::setupLineEdit() void UrlBar::setUrl(const QUrl& url) { - if (url.isEmpty()) - return; - m_currentUrl = url; slotUpdateUrl(); } +void UrlBar::setProgress(int progress) +{ + m_progress = progress; + repaint(); +} + void UrlBar::slotUpdateUrl() { if (count()) @@ -279,3 +288,45 @@ bool UrlBar::isLoading() } return true; } + + + +KCompletion *UrlBar::completion() +{ + // make sure completion was created + if (!m_completion) + { + m_completion = new KCompletion(); + m_completion->setCompletionMode(KGlobalSettings::CompletionPopupAuto); + m_completion->setOrder(KCompletion::Weighted); + m_completion->setIgnoreCase(true); + + kDebug() << "Initialize completion list..."; + HistoryCompletionModel *model = completionModel(); + int count = model->rowCount(); + kDebug() << "...initialize history items" << count; + + // change order to insertion to avoid confusion of the addItem method + // in weighted it expects format string:number and it thinks http it the whole string + m_completion->setOrder(KCompletion::Insertion); + for (int i = 0; i < count; ++i) + { + QString item = model->data(model->index(i, 0)).toString(); + item.remove(QRegExp("^http://|/$")); + m_completion->addItem(item); + } + + m_completion->setOrder(KCompletion::Weighted); + } + return m_completion; +} + +HistoryCompletionModel *UrlBar::completionModel() +{ + if (!m_completionModel) + { + m_completionModel = new HistoryCompletionModel(this); + m_completionModel->setSourceModel(Application::historyManager()->historyFilterModel()); + } + return m_completionModel; +} \ No newline at end of file -- cgit v1.2.1 From bb0be61558032932ca1775a5068a3e331f5be292 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Sat, 22 Aug 2009 21:22:46 +0200 Subject: Some stupid fixes on style, spaces and some comments added --- src/urlbar.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'src/urlbar.cpp') diff --git a/src/urlbar.cpp b/src/urlbar.cpp index 6ece4783..4b253773 100644 --- a/src/urlbar.cpp +++ b/src/urlbar.cpp @@ -51,6 +51,7 @@ QColor UrlBar::s_defaultBaseColor; + UrlBar::UrlBar(QWidget *parent) : KHistoryComboBox(true, parent) , m_lineEdit(new LineEdit) @@ -149,6 +150,7 @@ void UrlBar::setProgress(int progress) repaint(); } + void UrlBar::slotUpdateUrl() { if (count()) @@ -172,7 +174,7 @@ void UrlBar::slotUpdateUrl() } -inline void UrlBar::slotActivated(const QString& url) +void UrlBar::slotActivated(const QString& url) { if (url.isEmpty()) return; @@ -185,7 +187,7 @@ inline void UrlBar::slotActivated(const QString& url) } -inline void UrlBar::slotCleared() +void UrlBar::slotCleared() { // clear the history on user's request from context menu clear(); @@ -193,7 +195,7 @@ inline void UrlBar::slotCleared() } -inline void UrlBar::slotLoadFinished(bool) +void UrlBar::slotLoadFinished(bool) { // reset progress bar after small delay m_progress = 0; @@ -201,7 +203,7 @@ inline void UrlBar::slotLoadFinished(bool) } -inline void UrlBar::slotUpdateProgress(int progress) +void UrlBar::slotUpdateProgress(int progress) { m_progress = progress; repaint(); @@ -290,7 +292,6 @@ bool UrlBar::isLoading() } - KCompletion *UrlBar::completion() { // make sure completion was created @@ -321,6 +322,7 @@ KCompletion *UrlBar::completion() return m_completion; } + HistoryCompletionModel *UrlBar::completionModel() { if (!m_completionModel) @@ -329,4 +331,4 @@ HistoryCompletionModel *UrlBar::completionModel() m_completionModel->setSourceModel(Application::historyManager()->historyFilterModel()); } return m_completionModel; -} \ No newline at end of file +} -- cgit v1.2.1