summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrea Diamantini <adjam7@gmail.com>2008-11-23 00:09:49 +0100
committerAndrea Diamantini <adjam7@gmail.com>2008-11-23 00:09:49 +0100
commitaca0bf7ec9a98c1ef7a4147798c76e90e4cc7992 (patch)
tree186b0fac14b5d35f2e957646bff25ca539ba4dc8
parentKDE-izing cookie dialogs.. (diff)
downloadrekonq-aca0bf7ec9a98c1ef7a4147798c76e90e4cc7992.tar.xz
1st implementation of new (K)urlbar.
It compiles but doesn't work (yet..)
-rw-r--r--src/CMakeLists.txt5
-rw-r--r--src/tabwidget.cpp24
-rw-r--r--src/tabwidget.h7
-rw-r--r--src/urlbar.cpp114
-rw-r--r--src/urlbar.h36
5 files changed, 171 insertions, 15 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index b9d6a600..4498c543 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -9,13 +9,14 @@ SET( rekonq_SRCS
history.cpp
modelmenu.cpp
networkaccessmanager.cpp
- searchlineedit.cpp # ready to be removed..
+ urlbar.cpp
+# searchlineedit.cpp # ready to be removed..
findbar.cpp
searchbar.cpp
settings.cpp
squeezelabel.cpp
tabwidget.cpp
- urllineedit.cpp # ready to be removed..
+# urllineedit.cpp # ready to be removed..
webview.cpp
main.cpp
)
diff --git a/src/tabwidget.cpp b/src/tabwidget.cpp
index 892c4cc5..d66b6ba3 100644
--- a/src/tabwidget.cpp
+++ b/src/tabwidget.cpp
@@ -25,7 +25,8 @@
#include "browserapplication.h"
#include "browsermainwindow.h"
#include "history.h"
-#include "urllineedit.h"
+// #include "urllineedit.h"
+#include "urlbar.h"
#include "webview.h"
// Qt Includes
@@ -286,7 +287,7 @@ void TabWidget::clear()
m_recentlyClosedTabs.clear();
// clear the line edit history
for (int i = 0; i < m_lineEdits->count(); ++i) {
- QLineEdit *qLineEdit = lineEdit(i);
+ KLineEdit *qLineEdit = lineEdit(i);
qLineEdit->setText(qLineEdit->text());
}
}
@@ -384,7 +385,7 @@ QWidget *TabWidget::lineEditStack() const
return m_lineEdits;
}
-QLineEdit *TabWidget::currentLineEdit() const
+KLineEdit *TabWidget::currentLineEdit() const
{
return lineEdit(m_lineEdits->currentIndex());
}
@@ -394,9 +395,9 @@ WebView *TabWidget::currentWebView() const
return webView(currentIndex());
}
-QLineEdit *TabWidget::lineEdit(int index) const
+KLineEdit *TabWidget::lineEdit(int index) const
{
- UrlLineEdit *urlLineEdit = qobject_cast<UrlLineEdit*>(m_lineEdits->widget(index));
+ UrlBar *urlLineEdit = qobject_cast<UrlBar*>(m_lineEdits->widget(index));
if (urlLineEdit)
return urlLineEdit->lineEdit();
return 0;
@@ -430,9 +431,10 @@ int TabWidget::webViewIndex(WebView *webView) const
WebView *TabWidget::newTab(bool makeCurrent)
{
// line edit
- UrlLineEdit *urlLineEdit = new UrlLineEdit;
- QLineEdit *lineEdit = urlLineEdit->lineEdit();
- if (!m_lineEditCompleter && count() > 0) {
+ UrlBar *urlLineEdit = new UrlBar;
+ KLineEdit *lineEdit = urlLineEdit->lineEdit();
+ if (!m_lineEditCompleter && count() > 0)
+ {
HistoryCompletionModel *completionModel = new HistoryCompletionModel(this);
completionModel->setSourceModel(BrowserApplication::historyManager()->historyFilterModel());
m_lineEditCompleter = new QCompleter(completionModel, this);
@@ -448,7 +450,8 @@ WebView *TabWidget::newTab(bool makeCurrent)
m_lineEdits->setSizePolicy(lineEdit->sizePolicy());
// optimization to delay creating the more expensive WebView, history, etc
- if (count() == 0) {
+ if (count() == 0)
+ {
QWidget *emptyWidget = new QWidget;
QPalette p = emptyWidget->palette();
p.setColor(QPalette::Window, palette().color(QPalette::Base));
@@ -515,7 +518,8 @@ void TabWidget::reloadAllTabs()
void TabWidget::lineEditReturnPressed()
{
- if (QLineEdit *lineEdit = qobject_cast<QLineEdit*>(sender())) {
+ if (KLineEdit *lineEdit = qobject_cast<KLineEdit*>(sender()))
+ {
emit loadPage(lineEdit->text());
if (m_lineEdits->currentWidget() == lineEdit)
currentWebView()->setFocus();
diff --git a/src/tabwidget.h b/src/tabwidget.h
index b3c31c0e..e6399971 100644
--- a/src/tabwidget.h
+++ b/src/tabwidget.h
@@ -109,9 +109,10 @@ private:
#include <QUrl>
#include <QTabWidget>
+#include <KLineEdit>
+
QT_BEGIN_NAMESPACE
class QCompleter;
-class QLineEdit;
class QMenu;
class QStackedWidget;
QT_END_NAMESPACE
@@ -154,10 +155,10 @@ public:
QAction *previousTabAction() const;
QWidget *lineEditStack() const;
- QLineEdit *currentLineEdit() const;
+ KLineEdit *currentLineEdit() const;
WebView *currentWebView() const;
WebView *webView(int index) const;
- QLineEdit *lineEdit(int index) const;
+ KLineEdit *lineEdit(int index) const;
int webViewIndex(WebView *webView) const;
QByteArray saveState() const;
diff --git a/src/urlbar.cpp b/src/urlbar.cpp
index 62b28614..e7ce461a 100644
--- a/src/urlbar.cpp
+++ b/src/urlbar.cpp
@@ -17,9 +17,123 @@
 *
 * ============================================================ */
+// Local Includes
+#include "urlbar.h"
+#include "urlbar.moc"
+#include "browserapplication.h"
+// Qt Includes
+#include <QVBoxLayout>
+#include <QCompleter>
+#include <QFocusEvent>
+#include <QPainter>
+#include <QStyle>
+#include <QStyleOptionFrameV2>
+UrlBar::UrlBar(QWidget *parent)
+ : QWidget(parent)
+ , m_webView(0)
+ , m_iconLabel(0)
+ , m_lineEdit(0)
+{
+ // icon
+ m_iconLabel = new QLabel;
+ m_iconLabel->resize(16, 16);
+
+ m_lineEdit = new KLineEdit;
+
+ QVBoxLayout *layout = new QVBoxLayout;
+ layout->addWidget(m_iconLabel);
+ layout->addWidget(m_lineEdit);
+ setLayout(layout);
+
+ m_defaultBaseColor = palette().color(QPalette::Base);
+
+ webViewIconChanged();
+}
+
+UrlBar::~UrlBar()
+{
+// delete m_webView;
+ delete m_iconLabel;
+ delete m_lineEdit;
+}
+
+KLineEdit *UrlBar::lineEdit()
+{
+ return m_lineEdit;
+}
+
+void UrlBar::setWebView(WebView *webView)
+{
+ Q_ASSERT(!m_webView);
+ m_webView = webView;
+// m_iconLabel->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()));
+}
+
+void UrlBar::paintEvent(QPaintEvent *event)
+{
+ QPainter p(this);
+ QStyleOptionFrameV2 *optionPanel;
+
+ optionPanel->initFrom(this);
+ optionPanel->rect = contentsRect();
+ optionPanel->lineWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth, optionPanel, this);
+ optionPanel->midLineWidth = 0;
+ optionPanel->state |= QStyle::State_Sunken;
+ if (m_lineEdit->isReadOnly())
+ optionPanel->state |= QStyle::State_ReadOnly;
+ optionPanel->features = QStyleOptionFrameV2::None;
+
+ style()->drawPrimitive(QStyle::PE_PanelLineEdit, optionPanel, &p, (QWidget *) this);
+}
+
+void UrlBar::focusOutEvent(QFocusEvent *event)
+{
+ if (m_lineEdit->text().isEmpty() && m_webView)
+ {
+ m_lineEdit->setText(m_webView->url().toString());
+ }
+
+// m_lineEdit->event(event); // FIXME
+
+ if (m_lineEdit->completer())
+ {
+ connect(m_lineEdit->completer(), SIGNAL(activated(QString)), m_lineEdit, SLOT(setText(QString)));
+ connect(m_lineEdit->completer(), SIGNAL(highlighted(QString)), m_lineEdit, SLOT(_q_completionHighlighted(QString)));
+ }
+ QWidget::focusOutEvent(event);
+}
+
+void UrlBar::webViewUrlChanged(const QUrl &url)
+{
+ m_lineEdit->setText(url.toString());
+ m_lineEdit->setCursorPosition(0);
+}
+
+void UrlBar::webViewIconChanged()
+{
+ QUrl url = (m_webView) ? m_webView->url() : QUrl();
+ QIcon icon = BrowserApplication::instance()->icon(url);
+ QPixmap pixmap(icon.pixmap(16, 16));
+ m_iconLabel->setPixmap(pixmap);
+}
+
+QLinearGradient UrlBar::generateGradient(const QColor &color) const
+{
+ 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;
+}
diff --git a/src/urlbar.h b/src/urlbar.h
index 13c4c320..db6304da 100644
--- a/src/urlbar.h
+++ b/src/urlbar.h
@@ -20,9 +20,45 @@
#ifndef URLBAR_H
#define URLBAR_H
+// Local Includes
+#include "webview.h"
+// KDE Includes
+#include <KLineEdit>
+// Qt Includes
+#include <QWidget>
+#include <QLabel>
+class UrlBar : public QWidget
+{
+Q_OBJECT
+
+public:
+ UrlBar(QWidget *parent = 0);
+ ~UrlBar();
+
+ KLineEdit *lineEdit();
+
+ void setWebView(WebView *webView);
+
+protected:
+ void paintEvent(QPaintEvent *event);
+ void focusOutEvent(QFocusEvent *event);
+
+private slots:
+ void webViewUrlChanged(const QUrl &url);
+ void webViewIconChanged();
+
+private:
+ QLinearGradient generateGradient(const QColor &color) const;
+
+ WebView *m_webView;
+
+ QLabel *m_iconLabel;
+ KLineEdit *m_lineEdit;
+ QColor m_defaultBaseColor;
+};
#endif