summaryrefslogtreecommitdiff
path: root/src/urlbar
diff options
context:
space:
mode:
authorAndrea Diamantini <adjam7@gmail.com>2010-04-05 01:31:13 +0200
committerAndrea Diamantini <adjam7@gmail.com>2010-04-05 01:31:13 +0200
commit352168759ea96b35296eaf33790fbe073b69f69b (patch)
treef30a483162d84101b142825823872e64489620ce /src/urlbar
parentA "nice" hack to fix bug 211557 (diff)
downloadrekonq-352168759ea96b35296eaf33790fbe073b69f69b.tar.xz
This commit is the first implementation of a new new new urlbar
Here are its features: - KLineEdit based - ability to easily add "icons" :) - SSL informations shown (a-la firefox) - smoother animation - cleaner code - data QString, not KUrl based (Users type string, not urls!!!)
Diffstat (limited to 'src/urlbar')
-rw-r--r--src/urlbar/iconbutton.cpp76
-rw-r--r--src/urlbar/iconbutton.h51
-rw-r--r--src/urlbar/lineedit.cpp71
-rw-r--r--src/urlbar/lineedit.h19
-rw-r--r--src/urlbar/urlbar.cpp208
-rw-r--r--src/urlbar/urlbar.h20
6 files changed, 296 insertions, 149 deletions
diff --git a/src/urlbar/iconbutton.cpp b/src/urlbar/iconbutton.cpp
new file mode 100644
index 00000000..60008993
--- /dev/null
+++ b/src/urlbar/iconbutton.cpp
@@ -0,0 +1,76 @@
+/* ============================================================
+*
+* This file is a part of the rekonq project
+*
+* Copyright (C) 2010 by Andrea Diamantini <adjam7 at gmail dot com>
+*
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License as
+* published by the Free Software Foundation; either version 2 of
+* the License or (at your option) version 3 or any later version
+* accepted by the membership of KDE e.V. (or its successor approved
+* by the membership of KDE e.V.), which shall act as a proxy
+* defined in Section 14 of version 3 of the license.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program. If not, see <http://www.gnu.org/licenses/>.
+*
+* ============================================================ */
+
+
+// Self Includes
+#include "iconbutton.h"
+#include "iconbutton.moc"
+
+// Local Includes
+#include "application.h"
+
+// KDE Includes
+#include <KDebug>
+
+
+IconButton::IconButton(QWidget *parent)
+ : QToolButton(parent)
+{
+ QPalette p = palette();
+ p.setColor( QPalette::Button, Qt::transparent );
+ setPalette(p);
+
+ setCursor(Qt::ArrowCursor);
+ setStyleSheet("IconButton { border: none; padding: 0px}");
+}
+
+
+void IconButton::setIconUrl(const KUrl &url, bool trusted)
+{
+ setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
+ setIcon( Application::icon(url) );
+ setText( url.host() );
+
+ if(trusted)
+ {
+ setStyleSheet("IconButton { background-color:#0F0; padding: 2px }");
+ }
+ else
+ {
+ setStyleSheet("IconButton { background-color:#F00; padding: 2px}");
+ }
+
+ adjustSize();
+}
+
+
+void IconButton::updateIcon(KIcon icon)
+{
+ setToolButtonStyle(Qt::ToolButtonIconOnly);
+ setIcon( icon );
+
+ setStyleSheet("IconButton { background-color:transparent; border: none; padding: 0px}");
+ adjustSize();
+}
diff --git a/src/urlbar/iconbutton.h b/src/urlbar/iconbutton.h
new file mode 100644
index 00000000..b66e212b
--- /dev/null
+++ b/src/urlbar/iconbutton.h
@@ -0,0 +1,51 @@
+/* ============================================================
+*
+* This file is a part of the rekonq project
+*
+* Copyright (C) 2010 by Andrea Diamantini <adjam7 at gmail dot com>
+*
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License as
+* published by the Free Software Foundation; either version 2 of
+* the License or (at your option) version 3 or any later version
+* accepted by the membership of KDE e.V. (or its successor approved
+* by the membership of KDE e.V.), which shall act as a proxy
+* defined in Section 14 of version 3 of the license.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program. If not, see <http://www.gnu.org/licenses/>.
+*
+* ============================================================ */
+
+
+
+#ifndef ICON_BUTTON_H
+#define ICON_BUTTON_H
+
+
+// KDE Includes
+#include <KUrl>
+#include <KIcon>
+
+// Qt Includes
+#include <QToolButton>
+
+
+class IconButton : public QToolButton
+{
+ Q_OBJECT
+
+public:
+ IconButton(QWidget *parent = 0);
+
+ void setIconUrl(const KUrl &url, bool trusted);
+ void updateIcon(KIcon icon);
+};
+
+#endif // ICON_BUTTON_H
diff --git a/src/urlbar/lineedit.cpp b/src/urlbar/lineedit.cpp
index ac92b858..f7af1f61 100644
--- a/src/urlbar/lineedit.cpp
+++ b/src/urlbar/lineedit.cpp
@@ -30,24 +30,64 @@
#include "lineedit.h"
#include "lineedit.moc"
+// KDE Includes
+#include <klocalizedstring.h>
+#include <KDebug>
+
// Qt Includes
#include <QtGui/QContextMenuEvent>
#include <QtGui/QFocusEvent>
#include <QtGui/QKeyEvent>
+#include <QStyleOptionFrameV2>
+#include <QPainter>
LineEdit::LineEdit(QWidget* parent)
- : KLineEdit(parent)
+ : KLineEdit(parent)
+ , _icon( new IconButton(this) )
{
+ // cosmetic
+ setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
setMinimumWidth(200);
- setFocusPolicy(Qt::WheelFocus);
- setHandleSignals(true);
+ setMinimumHeight(26);
+ updateStyles();
+
+ // doesn't show the clear button
setClearButtonShown(false);
+
+ // trap Key_Enter & Key_Return events, while emitting the returnPressed signal
+ setTrapReturnKey(true);
+
+ // insert decoded URLs
+ setUrlDropsEnabled(true);
+
+ // accept focus, via tabbing, clicking & wheeling
+ setFocusPolicy(Qt::WheelFocus);
+
+ // disable completion object (we have our own :) )
+ setCompletionObject(0);
}
LineEdit::~LineEdit()
{
+ delete _icon;
+}
+
+
+void LineEdit::updateStyles()
+{
+ adjustSize();
+ _icon->adjustSize();
+ if(_icon->toolButtonStyle() == Qt::ToolButtonIconOnly)
+ _icon->move( 4, 3);
+ else
+ _icon->move( 2, 1);
+
+ int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
+ setStyleSheet(QString("LineEdit { padding-left: %1px; } ").arg(_icon->sizeHint().width() + frameWidth + 1));
+
+ update();
}
@@ -67,3 +107,28 @@ void LineEdit::mouseDoubleClickEvent(QMouseEvent *)
{
selectAll();
}
+
+
+IconButton *LineEdit::iconButton() const
+{
+ return _icon;
+}
+
+
+void LineEdit::paintEvent(QPaintEvent *event)
+{
+ KLineEdit::paintEvent(event);
+
+ if (text().isEmpty() && !hasFocus())
+ {
+ QStyleOptionFrame option;
+ initStyleOption(&option);
+ QRect textRect = style()->subElementRect(QStyle::SE_LineEditContents, &option, this);
+ QPainter painter(this);
+ painter.setPen(Qt::gray);
+ painter.drawText( textRect,
+ Qt::AlignLeft | Qt::AlignVCenter,
+ i18n("Search Bookmarks, History, Google.. and the Kitchen Sink!")
+ );
+ }
+}
diff --git a/src/urlbar/lineedit.h b/src/urlbar/lineedit.h
index 67ded052..96f25918 100644
--- a/src/urlbar/lineedit.h
+++ b/src/urlbar/lineedit.h
@@ -30,13 +30,20 @@
#define LINEEDIT_H
+// Local Includes
+#include "iconbutton.h"
+
// KDE Includes
#include <KLineEdit>
+#include <KIcon>
+
+#include <QToolButton>
// Forward Declarations
class QContextMenuEvent;
class QFocusEvent;
class QKeyEvent;
+class QStyleOptionFrameV2;
class LineEdit : public KLineEdit
@@ -46,10 +53,18 @@ class LineEdit : public KLineEdit
public:
explicit LineEdit(QWidget *parent = 0);
virtual ~LineEdit();
-
+
+ IconButton *iconButton() const;
+
+ void updateStyles();
+
protected:
- virtual void keyPressEvent(QKeyEvent*);
+ virtual void keyPressEvent(QKeyEvent *);
virtual void mouseDoubleClickEvent(QMouseEvent *);
+ virtual void paintEvent(QPaintEvent *);
+
+private:
+ IconButton *_icon;
};
#endif // LINEEDIT_H
diff --git a/src/urlbar/urlbar.cpp b/src/urlbar/urlbar.cpp
index 0dc91a1e..dd14a4a3 100644
--- a/src/urlbar/urlbar.cpp
+++ b/src/urlbar/urlbar.cpp
@@ -50,124 +50,59 @@
#include <QTimer>
#include <QVBoxLayout>
+// Defines
+#define QL1S(x) QLatin1String(x)
+
UrlBar::UrlBar(QWidget *parent)
- : KComboBox(true, parent)
- , m_lineEdit(new LineEdit)
- , m_box(new CompletionWidget(this))
+ : LineEdit(parent)
+ , _box(new CompletionWidget(this))
, _tab(0)
, _privateMode(false)
{
- //cosmetic
- setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
- setMinimumWidth(180);
-
- // signal handlings
- setTrapReturnKey(true);
- setUrlDropsEnabled(true);
-
- // Make m_lineEdit background transparent
- QPalette p = m_lineEdit->palette();
- p.setColor(QPalette::Base, Qt::transparent);
- m_lineEdit->setPalette(p);
-
- setLineEdit(m_lineEdit);
-
- // clear the URL bar
- m_lineEdit->clear();
// load urls on activated urlbar signal
- connect(this, SIGNAL(returnPressed(const QString&)), SLOT(activated(const QString&)));
-
- installEventFilter(m_box);
- connect(m_box, SIGNAL(chosenUrl(const QString&, Rekonq::OpenType)), SLOT(activated(const QString&, Rekonq::OpenType)));
-}
-
-
-UrlBar::~UrlBar()
-{
-}
+ connect(this, SIGNAL(returnPressed(const QString&)), this, SLOT(activated(const QString&)));
-
-void UrlBar::selectAll() const
-{
- m_lineEdit->selectAll();
+ // suggestions
+ installEventFilter(_box);
+ connect(_box, SIGNAL(chosenUrl(const QString&, Rekonq::OpenType)), SLOT(activated(const QString&, Rekonq::OpenType)));
}
-KUrl UrlBar::url() const
+UrlBar::~UrlBar()
{
- return m_currentUrl;
+ delete _box;
}
-void UrlBar::setUrl(const QUrl& url)
+void UrlBar::setQUrl(const QUrl& url)
{
- if(url.scheme() == "about")
+ if(url.scheme() == QL1S("about") )
{
- m_currentUrl = KUrl();
- updateUrl();
+ iconButton()->updateIcon( KIcon("arrow-right") );
setFocus();
}
else
{
- m_currentUrl = KUrl(url);
- updateUrl();
+ LineEdit::setUrl(url);
+ setCursorPosition(0);
+ iconButton()->updateIcon( Application::icon(url) );
}
-}
-
-
-void UrlBar::updateUrl()
-{
- // Don't change my typed url...
- // FIXME this is not a proper solution (also if it works...)
- if(hasFocus())
- {
- kDebug() << "Don't change my typed url...";
- return;
- }
-
- KIcon icon;
- if(m_currentUrl.isEmpty())
- {
- icon = KIcon("arrow-right");
- }
- else
- {
- icon = Application::icon(m_currentUrl);
- }
-
- if (count())
- {
- changeUrl(0, icon, m_currentUrl);
- }
- else
- {
- insertUrl(0, icon, 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())
- {
- m_lineEdit->setCursorPosition(0);
- }
+ updateStyles();
}
void UrlBar::activated(const QString& urlString, Rekonq::OpenType type)
{
- disconnect(this, SIGNAL(editTextChanged(const QString &)), this, SLOT(suggestUrls(const QString &)));
+ disconnect(this, SIGNAL(textChanged(const QString &)), this, SLOT(suggestUrls(const QString &)));
if (urlString.isEmpty())
return;
clearFocus();
- setUrl(urlString);
- Application::instance()->loadUrl(m_currentUrl, type);
+ setText(urlString);
+ Application::instance()->loadUrl(urlString, type);
}
@@ -185,17 +120,16 @@ void UrlBar::paintEvent(QPaintEvent *event)
// set background color of UrlBar
QPalette p = palette();
- p.setColor(QPalette::Base, backgroundColor);
- setPalette(p);
- KComboBox::paintEvent(event);
-
- if (!hasFocus())
+ int progr = _tab->progress();
+ if (progr == 0)
+ {
+ p.setBrush(QPalette::Base, backgroundColor);
+ }
+ else
{
- QPainter painter(this);
-
QColor loadingColor;
- if (m_currentUrl.scheme() == QLatin1String("https"))
+ if ( _tab->url().scheme() == QLatin1String("https"))
{
loadingColor = QColor(248, 248, 100);
}
@@ -203,30 +137,16 @@ void UrlBar::paintEvent(QPaintEvent *event)
{
loadingColor = QColor(116, 192, 250);
}
- int progr = _tab->progress();
-
- backgroundColor.setAlpha(0);
- backgroundColor.setAlpha(200);
- QLinearGradient gradient(0, 0, width(), height() );
+
+
+ QLinearGradient gradient(0, 0, width(), 0);
gradient.setColorAt(0, loadingColor);
gradient.setColorAt(((double)progr)/100, backgroundColor);
-
- painter.setBrush( gradient );
- painter.setPen(Qt::transparent);
-
-
- QRect backgroundRect = m_lineEdit->frameGeometry();
- int mid = backgroundRect.width() * progr / 100;
- QRect progressRect(backgroundRect.x(), backgroundRect.y(), mid, backgroundRect.height());
- painter.drawRect(progressRect);
- painter.end();
+ p.setBrush(QPalette::Base, gradient);
}
-}
-
-
-QSize UrlBar::sizeHint() const
-{
- return m_lineEdit->sizeHint();
+ setPalette(p);
+
+ LineEdit::paintEvent(event);
}
@@ -234,12 +154,12 @@ void UrlBar::keyPressEvent(QKeyEvent *event)
{
if(event->key() == Qt::Key_Escape)
{
- m_box->hide();
+ _box->hide();
return;
}
// this handles the Modifiers + Return key combinations
- QString currentText = m_lineEdit->text().trimmed();
+ QString currentText = text().trimmed();
if ((event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return)
&& !currentText.startsWith(QLatin1String("http://"), Qt::CaseInsensitive))
{
@@ -263,11 +183,11 @@ void UrlBar::keyPressEvent(QKeyEvent *event)
{
host += append;
url.setHost(host);
- m_lineEdit->setText(url.toString());
+ setText(url.toString());
}
}
- KComboBox::keyPressEvent(event);
+ LineEdit::keyPressEvent(event);
}
@@ -280,7 +200,7 @@ void UrlBar::suggestUrls(const QString &text)
if(text.isEmpty())
{
- m_box->hide();
+ _box->hide();
return;
}
@@ -289,31 +209,41 @@ void UrlBar::suggestUrls(const QString &text)
if(list.count() > 0)
{
- m_box->clear();
- m_box->insertSearchList(list);
- m_box->popup();
+ _box->clear();
+ _box->insertSearchList(list);
+ _box->popup();
}
}
+
void UrlBar::focusInEvent(QFocusEvent *event)
{
// activate suggestions on edit text
- connect(this, SIGNAL(editTextChanged(const QString &)), this, SLOT(suggestUrls(const QString &)));
+ connect(this, SIGNAL(textChanged(const QString &)), this, SLOT(suggestUrls(const QString &)));
- KComboBox::focusInEvent(event);
+ LineEdit::focusInEvent(event);
}
void UrlBar::setCurrentTab(WebTab *tab)
{
if(_tab)
- disconnect(_tab->view(), SIGNAL(urlChanged(const QUrl &)), this, SLOT(setUrl(const QUrl &)));
+ {
+ disconnect(_tab->view(), SIGNAL(urlChanged(const QUrl &)), this, SLOT(setQUrl(const QUrl &)));
+ disconnect(_tab->view(), SIGNAL(loadFinished(bool)), this, SLOT(loadFinished()));
+ disconnect(_tab->page(), SIGNAL(validSSLInfo(bool)), this, SLOT(setTrustedHost(bool)));
+ disconnect(iconButton(), SIGNAL(clicked()), _tab->page(), SLOT(showSSLInfo()));
+ }
_tab = tab;
- connect(_tab->view(), SIGNAL(urlChanged(const QUrl &)), this, SLOT(setUrl(const QUrl &)));
-
+ connect(_tab->view(), SIGNAL(urlChanged(const QUrl &)), this, SLOT(setQUrl(const QUrl &)));
+ connect(_tab->view(), SIGNAL(loadFinished(bool)), this, SLOT(loadFinished()));
+ connect(_tab->page(), SIGNAL(validSSLInfo(bool)), this, SLOT(setTrustedHost(bool)));
+ connect(iconButton(), SIGNAL(clicked()), _tab->page(), SLOT(showSSLInfo()));
+
// update it now (the first time)
- setUrl( _tab->url() );
- update();
+ updateStyles();
+ _tab->view()->setFocus();
+ setQUrl( _tab->url() );
}
@@ -321,3 +251,21 @@ void UrlBar::setPrivateMode(bool on)
{
_privateMode = on;
}
+
+
+void UrlBar::loadFinished()
+{
+ // show RSS
+
+ // show KGet downloads??
+
+ // last, but not least
+ updateStyles();
+}
+
+
+void UrlBar::setTrustedHost(bool on)
+{
+ kDebug() << "SET TRUSTED HOST..";
+ iconButton()->setIconUrl( _tab->url() , on );
+}
diff --git a/src/urlbar/urlbar.h b/src/urlbar/urlbar.h
index 991b9038..848073db 100644
--- a/src/urlbar/urlbar.h
+++ b/src/urlbar/urlbar.h
@@ -49,7 +49,7 @@ class QLinearGradient;
class QWidget;
-class UrlBar : public KComboBox
+class UrlBar : public LineEdit
{
Q_OBJECT
@@ -57,32 +57,24 @@ public:
UrlBar(QWidget *parent = 0);
~UrlBar();
- void selectAll() const;
- KUrl url() const;
- QSize sizeHint() const;
-
void setCurrentTab(WebTab *);
void setPrivateMode(bool on);
-
-public slots:
- void setUrl(const QUrl &url);
- void updateUrl();
private slots:
void activated(const QString& url, Rekonq::OpenType = Rekonq::CurrentTab);
void suggestUrls(const QString &editedText);
+ void setQUrl(const QUrl &url);
+ void loadFinished();
+ void setTrustedHost(bool on);
+
protected:
virtual void paintEvent(QPaintEvent *event);
virtual void keyPressEvent(QKeyEvent *event);
virtual void focusInEvent(QFocusEvent *event);
private:
- LineEdit *m_lineEdit;
-
- KUrl m_currentUrl;
-
- CompletionWidget *m_box;
+ CompletionWidget *_box;
WebTab *_tab;
bool _privateMode;
};