diff options
author | Andrea Diamantini <adjam7@gmail.com> | 2009-04-25 23:55:14 +0200 |
---|---|---|
committer | Andrea Diamantini <adjam7@gmail.com> | 2009-04-25 23:55:14 +0200 |
commit | 2399843ceb70b45b2c1a47b680e11ba1e623ef45 (patch) | |
tree | a89b1e859a110041e0bda829f3fcf0406075bcd3 /src/urlbar.cpp | |
parent | Fixing strings: pano suggestions (diff) | |
download | rekonq-2399843ceb70b45b2c1a47b680e11ba1e623ef45.tar.xz |
Another importing step.
Need to fix cookies' classes and then (I think) we are near the goal..
Diffstat (limited to 'src/urlbar.cpp')
-rw-r--r-- | src/urlbar.cpp | 243 |
1 files changed, 168 insertions, 75 deletions
diff --git a/src/urlbar.cpp b/src/urlbar.cpp index d6b1beca..1987ff8c 100644 --- a/src/urlbar.cpp +++ b/src/urlbar.cpp @@ -3,7 +3,8 @@ * This file is a part of the rekonq project * * Copyright (C) 2008-2009 by Andrea Diamantini <adjam7 at gmail dot com> -* Copyright (C) 2009 rekonq team. Please, see AUTHORS file for details +* Copyright (C) 2009 by Domrachev Alexandr <alexandr.domrachev@gmail.com> +* Copyright (C) 2009 by Paweł Prażak <pawelprazak at gmail dot com> * * * This program is free software; you can redistribute it @@ -23,123 +24,215 @@ #include "urlbar.h" #include "urlbar.moc" +// Qt Includes +#include <QtCore> +#include <QtGui> + +// KDE Includes +#include <KDebug> +#include <KCompletionBox> +#include <KUrl> + // Local Includes #include "application.h" +#include "history.h" +#include "lineedit.h" #include "mainwindow.h" #include "webview.h" -// Qt Includes -#include <QtCore> -#include <QtGui> +QColor UrlBar::s_defaultBaseColor; UrlBar::UrlBar(QWidget *parent) : KHistoryComboBox(true, parent) - , m_webView(0) - , m_lineEdit(new QLineEdit) + , m_lineEdit(new LineEdit) + , m_progress(0) { - setLineEdit(m_lineEdit); - - QSizePolicy policy = sizePolicy(); - setSizePolicy(QSizePolicy::Preferred, policy.verticalPolicy()); - - m_defaultBaseColor = palette().color(QPalette::Base); - + setUrlDropsEnabled(true); + setAutoDeleteCompletionObject(true); + setMinimumWidth(180); + + setTrapReturnKey(true); + + setupLineEdit(); + // add every item to history - connect(this, SIGNAL(activated(const QString&)), this, SLOT(addToHistory(const QString&))); - - webViewIconChanged(); + connect(this, SIGNAL(returnPressed(const QString&)), SLOT(slotActivated(const QString&))); + connect(completionBox(), SIGNAL(activated(const QString&)), SLOT(slotActivated(const QString&))); + + connect(this, SIGNAL(cleared()), SLOT(slotCleared())); + + // setup completion box + completionBox()->setTabHandling(true); // Konqueror bug #167135 + + // set dropdown list background + QPalette p = view()->palette(); + p.setColor(QPalette::Base, palette().color(QPalette::Base)); + view()->setPalette(p); + + // set empty item with default icon + slotUpdateUrl(); } - UrlBar::~UrlBar() { } +void UrlBar::setupLineEdit() +{ + // Make m_lineEdit background transparent + QPalette p = m_lineEdit->palette(); + p.setColor(QPalette::Base, Qt::transparent); + m_lineEdit->setPalette(p); + + if (!s_defaultBaseColor.isValid()) + { + s_defaultBaseColor = palette().color(QPalette::Base); + } + + setLineEdit(m_lineEdit); + + // Make the lineedit consume the Qt::Key_Enter event... + lineEdit()->setTrapReturnKey(true); + + lineEdit()->setHandleSignals(true); + + // clear the URL bar + lineEdit()->clear(); +} + -QLineEdit *UrlBar::lineEdit() +void UrlBar::setUrl(const QUrl& url) { - return m_lineEdit; + if (url.isEmpty()) + return; + + m_currentUrl = url; + slotUpdateUrl(); } +void UrlBar::slotUpdateUrl() +{ + if (count()) + { + changeUrl(0, Application::instance()->icon(m_currentUrl), m_currentUrl); + } + else + { + insertUrl(0, Application::instance()->icon(m_currentUrl), m_currentUrl); + } + + setCurrentIndex(0); + + // important security consideration: always display the beginning + // of the url rather than its end to prevent spoofing attempts. + // Must be AFTER setCurrentIndex + if (!hasFocus()) + { + lineEdit()->setCursorPosition(0); + } +} -void UrlBar::setWebView(WebView *webView) + +inline void UrlBar::slotActivated(const QString& url) { - Q_ASSERT(!m_webView); - m_webView = webView; - connect(webView, SIGNAL(urlChanged(const QUrl &)), this, SLOT(webViewUrlChanged(const QUrl &))); - connect(webView, SIGNAL(loadFinished(bool)), this, SLOT(webViewIconChanged())); - connect(webView, SIGNAL(iconChanged()), this, SLOT(webViewIconChanged())); - connect(webView, SIGNAL(loadProgress(int)), this, SLOT(update())); + if (url.isEmpty()) + return; + + setUrl(url); + + Application::historyManager()->addHistoryEntry(url); + + emit activated(m_currentUrl); } +inline void UrlBar::slotCleared() +{ + // clear the history on user's request from context menu + clear(); + Application::historyManager()->clear(); +} + -void UrlBar::webViewUrlChanged(const QUrl &url) +inline void UrlBar::slotLoadFinished(bool) { - m_lineEdit->setText(url.toString()); - m_lineEdit->setCursorPosition(0); + // reset progress bar after small delay + m_progress = 0; + QTimer::singleShot(200, this, SLOT(repaint())); } +inline void UrlBar::slotUpdateProgress(int progress) +{ + m_progress = progress; + repaint(); +} + -void UrlBar::webViewIconChanged() +void UrlBar::paintEvent(QPaintEvent *event) { - KUrl url = (m_webView) ? m_webView->url() : KUrl(); - QIcon icon = Application::instance()->icon(url); - QPixmap pixmap(icon.pixmap(16, 16)); - QIcon urlIcon = QIcon(pixmap); - - // FIXME simple hack to show Icon in the urlbar, as calling changeUrl() doesn't affect it - insertUrl(0, urlIcon, url); - if (count() > 1) + QColor baseColor = s_defaultBaseColor; + if (m_currentUrl.scheme() == QLatin1String("https")) { - removeItem(1); + baseColor = QColor(248, 248, 100); + } + // set background color of UrlBar + QPalette p = palette(); + p.setColor(QPalette::Base, baseColor); + setPalette(p); + + KHistoryComboBox::paintEvent(event); + + if (!hasFocus()) + { + QPainter painter(this); + + QColor loadingColor = QColor(116, 192, 250); + + painter.setBrush(generateGradient(loadingColor, height())); + painter.setPen(Qt::transparent); + + QRect backgroundRect = lineEdit()->frameGeometry(); + int mid = backgroundRect.width() / 100 * m_progress; + QRect progressRect(backgroundRect.x(), backgroundRect.y(), mid, backgroundRect.height()); + painter.drawRect(progressRect); + painter.end(); } } -QLinearGradient UrlBar::generateGradient(const QColor &color) const +void UrlBar::focusOutEvent(QFocusEvent *event) { - QLinearGradient gradient(0, 0, 0, height()); - gradient.setColorAt(0, m_defaultBaseColor); - gradient.setColorAt(0.15, color.lighter(120)); - gradient.setColorAt(0.5, color); - gradient.setColorAt(0.85, color.lighter(120)); - gradient.setColorAt(1, m_defaultBaseColor); - return gradient; + // set back last loaded url in case user cleared it + setUrl(m_currentUrl); + + KHistoryComboBox::focusOutEvent(event); } -// void UrlBar::paintEvent( QPaintEvent *event ) -// { -// QPalette p = palette(); -// if (m_webView && m_webView->url().scheme() == QLatin1String("https")) -// { -// QColor lightYellow(248, 248, 210); -// p.setBrush(QPalette::Base, generateGradient(lightYellow)); -// } -// else -// { -// p.setBrush(QPalette::Base, m_defaultBaseColor); -// } -// setPalette(p); -// KHistoryComboBox::paintEvent(event); -// -// QPainter painter( this ); -// QRect backgroundRect = m_lineEdit->frameGeometry(); // contentsRect(); // FIXME perhaps better working with contentsRect -// if ( m_webView && !hasFocus() ) // and modifying colours.. -// { -// int progress = m_webView->progress(); -// QColor loadingColor = QColor(116, 192, 250); -// painter.setBrush( generateGradient(loadingColor) ); -// painter.setPen(Qt::transparent); -// int mid = backgroundRect.width() / 100 * progress; -// QRect progressRect(backgroundRect.x(), backgroundRect.y(), mid, backgroundRect.height()); -// painter.drawRect(progressRect); -// } -// } +QSize UrlBar::sizeHint() const +{ + QSize size(lineEdit()->sizeHint()); + // make it (more or less) the same height with search bar (at least on oxygen) +// size.setHeight(size.height() + 2); + return size; +} +QLinearGradient UrlBar::generateGradient(const QColor &color, int height) +{ + QColor base = s_defaultBaseColor; + base.setAlpha(0); + QColor barColor = color; + barColor.setAlpha(200); + QLinearGradient gradient(0, 0, 0, height); + gradient.setColorAt(0, base); + gradient.setColorAt(0.25, barColor.lighter(120)); + gradient.setColorAt(0.5, barColor); + gradient.setColorAt(0.75, barColor.lighter(120)); + gradient.setColorAt(1, base); + return gradient; +} |