2011-03-03 18:29:20 +01:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
|
|
|
* Copyright (C) 2010-2011 nowrep
|
|
|
|
*
|
|
|
|
* 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 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
* ============================================================ */
|
2011-03-02 16:57:41 +01:00
|
|
|
#include "locationbar.h"
|
|
|
|
#include "qupzilla.h"
|
|
|
|
#include "webview.h"
|
|
|
|
#include "rssmanager.h"
|
|
|
|
#include "mainapplication.h"
|
|
|
|
#include "locationcompleter.h"
|
|
|
|
#include "clickablelabel.h"
|
|
|
|
#include "siteinfowidget.h"
|
2011-03-03 14:25:02 +01:00
|
|
|
#include "rsswidget.h"
|
2011-03-22 21:36:15 +01:00
|
|
|
#include "webpage.h"
|
2011-04-15 20:45:22 +02:00
|
|
|
#include "bookmarkicon.h"
|
2011-04-25 15:06:59 +02:00
|
|
|
#include "progressbar.h"
|
2011-05-09 17:58:19 +02:00
|
|
|
#include "statusbarmessage.h"
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2011-07-11 20:30:49 +02:00
|
|
|
LocationBar::LocationBar(QupZilla* mainClass)
|
|
|
|
: LineEdit()
|
2011-03-02 16:57:41 +01:00
|
|
|
,m_selectAllOnDoubleClick(false)
|
|
|
|
,m_addComWithCtrl(false)
|
|
|
|
,m_addCountryWithAlt(false)
|
|
|
|
,p_QupZilla(mainClass)
|
2011-07-11 20:30:49 +02:00
|
|
|
,m_webView(0)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
|
|
|
m_siteIcon = new QToolButton(this);
|
|
|
|
m_siteIcon->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
|
|
|
m_siteIcon->setCursor(Qt::ArrowCursor);
|
|
|
|
m_siteIcon->setMaximumSize(35, 25);
|
|
|
|
m_siteIcon->setMinimumSize(35, 25);
|
|
|
|
m_siteIcon->setToolTip(tr("Show informations about this page"));
|
|
|
|
m_siteIcon->setStyleSheet("QToolButton{border-image: url(:/icons/locationbar/searchchoose.png); margin-left:2px;}");
|
2011-03-02 17:54:22 +01:00
|
|
|
m_siteIcon->setFocusPolicy(Qt::ClickFocus);
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2011-03-03 14:25:02 +01:00
|
|
|
m_rssIcon = new ClickableLabel(this);
|
|
|
|
m_rssIcon->setPixmap(QPixmap(":/icons/menu/rss.png"));
|
|
|
|
m_rssIcon->setCursor(Qt::PointingHandCursor);
|
2011-03-02 16:57:41 +01:00
|
|
|
m_rssIcon->setToolTip(tr("Add RSS from this page..."));
|
|
|
|
m_rssIcon->setStyleSheet("margin-bottom:2px");
|
2011-03-02 17:54:22 +01:00
|
|
|
m_rssIcon->setFocusPolicy(Qt::ClickFocus);
|
2011-03-03 18:29:20 +01:00
|
|
|
m_rssIcon->setVisible(false);
|
2011-03-02 16:57:41 +01:00
|
|
|
|
|
|
|
m_goButton = new ClickableLabel(this);
|
|
|
|
m_goButton->setPixmap(QPixmap(":/icons/locationbar/gotoaddress.png"));
|
|
|
|
m_goButton->setCursor(Qt::PointingHandCursor);
|
|
|
|
m_goButton->setHidden(true);
|
|
|
|
m_goButton->setStyleSheet("margin-bottom:2px;");
|
|
|
|
|
2011-04-15 20:45:22 +02:00
|
|
|
m_bookmarkIcon = new BookmarkIcon(p_QupZilla);
|
2011-03-02 16:57:41 +01:00
|
|
|
|
|
|
|
ClickableLabel* down = new ClickableLabel(this);
|
|
|
|
down->setPixmap(QPixmap(":icons/locationbar/arrow-down.gif"));
|
|
|
|
down->setCursor(Qt::ArrowCursor);
|
|
|
|
|
|
|
|
addWidget(down, LineEdit::RightSide);
|
2011-04-15 20:45:22 +02:00
|
|
|
addWidget(m_bookmarkIcon, LineEdit::RightSide);
|
2011-03-02 16:57:41 +01:00
|
|
|
addWidget(m_goButton, LineEdit::RightSide);
|
|
|
|
addWidget(m_rssIcon, LineEdit::RightSide);
|
|
|
|
|
|
|
|
setPlaceholderText(tr("Enter URL address or search on Google.com"));
|
|
|
|
|
|
|
|
setWidgetSpacing(0);
|
|
|
|
this->setMinimumHeight(25);
|
|
|
|
this->setMaximumHeight(25);
|
|
|
|
loadSettings();
|
|
|
|
|
|
|
|
m_locationCompleter = new LocationCompleter();
|
|
|
|
setCompleter(m_locationCompleter);
|
|
|
|
|
2011-03-04 13:59:07 +01:00
|
|
|
// LocationPopup* com = new LocationPopup(this);
|
2011-03-02 16:57:41 +01:00
|
|
|
connect(this, SIGNAL(textEdited(QString)), this, SLOT(textEdit()));
|
|
|
|
connect(this, SIGNAL(textEdited(QString)), m_locationCompleter, SLOT(refreshCompleter(QString)));
|
2011-07-11 20:30:49 +02:00
|
|
|
connect(this, SIGNAL(returnPressed()), this, SLOT(urlEnter()));
|
2011-03-02 16:57:41 +01:00
|
|
|
connect(m_locationCompleter->popup(), SIGNAL(clicked(QModelIndex)), p_QupZilla, SLOT(urlEnter()));
|
|
|
|
connect(m_siteIcon, SIGNAL(clicked()), this, SLOT(showSiteInfo()));
|
2011-03-04 13:59:07 +01:00
|
|
|
// connect(down, SIGNAL(clicked(QPoint)), com, SLOT(show()));
|
2011-07-11 20:30:49 +02:00
|
|
|
connect(m_goButton, SIGNAL(clicked(QPoint)), this, SLOT(urlEnter()));
|
2011-03-03 14:25:02 +01:00
|
|
|
connect(m_rssIcon, SIGNAL(clicked(QPoint)), this, SLOT(rssIconClicked()));
|
2011-03-02 16:57:41 +01:00
|
|
|
|
|
|
|
setStyleSheet("QLineEdit { background: transparent; border-image: url(:/icons/locationbar/lineedit.png); border-width:4; color:black;}");
|
2011-03-05 11:16:23 +01:00
|
|
|
setLeftMargin(33);
|
2011-07-11 20:30:49 +02:00
|
|
|
clearIcon();
|
2011-03-05 11:16:23 +01:00
|
|
|
// setLeftMargin(m_siteIcon->sizeHint().width()+1);
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void LocationBar::loadSettings()
|
|
|
|
{
|
|
|
|
QSettings settings(p_QupZilla->activeProfil()+"settings.ini", QSettings::IniFormat);
|
|
|
|
settings.beginGroup("AddressBar");
|
|
|
|
m_selectAllOnDoubleClick = settings.value("SelectAllTextOnDoubleClick",true).toBool();
|
|
|
|
m_addComWithCtrl = settings.value("AddComDomainWithCtrlKey",false).toBool();
|
|
|
|
m_addCountryWithAlt = settings.value("AddCountryDomainWithAltKey",true).toBool();
|
|
|
|
}
|
|
|
|
|
2011-07-11 20:30:49 +02:00
|
|
|
void LocationBar::urlEnter()
|
|
|
|
{
|
|
|
|
m_webView->setFocus();
|
|
|
|
QUrl guessedUrl = WebView::guessUrlFromString(text());
|
|
|
|
m_webView->load(guessedUrl);
|
|
|
|
setText(guessedUrl.toString());
|
|
|
|
}
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
void LocationBar::textEdit()
|
|
|
|
{
|
|
|
|
m_locationCompleter->popup()->setUpdatesEnabled(false);
|
|
|
|
showGoButton();
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocationBar::showGoButton()
|
|
|
|
{
|
|
|
|
if (m_goButton->isVisible())
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_rssIconVisible = m_rssIcon->isVisible();
|
|
|
|
|
2011-04-15 20:45:22 +02:00
|
|
|
m_bookmarkIcon->hide();
|
2011-03-02 16:57:41 +01:00
|
|
|
m_rssIcon->hide();
|
|
|
|
m_goButton->show();
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocationBar::hideGoButton()
|
|
|
|
{
|
|
|
|
if (!m_goButton->isVisible())
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_rssIcon->setVisible(m_rssIconVisible);
|
2011-04-15 20:45:22 +02:00
|
|
|
m_bookmarkIcon->show();
|
2011-03-02 16:57:41 +01:00
|
|
|
m_goButton->hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocationBar::showPopup()
|
|
|
|
{
|
|
|
|
//TODO: Fix to next version
|
|
|
|
return;
|
|
|
|
emit textEdited("");
|
|
|
|
m_locationCompleter->popup()->showNormal();
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocationBar::showSiteInfo()
|
|
|
|
{
|
|
|
|
SiteInfoWidget* info = new SiteInfoWidget(p_QupZilla);
|
|
|
|
info->showAt(this);
|
|
|
|
}
|
|
|
|
|
2011-03-03 14:25:02 +01:00
|
|
|
void LocationBar::rssIconClicked()
|
|
|
|
{
|
2011-07-11 20:30:49 +02:00
|
|
|
QList<QPair<QString,QString> > _rss = m_webView->getRss();
|
2011-03-03 14:25:02 +01:00
|
|
|
|
2011-07-11 20:30:49 +02:00
|
|
|
RSSWidget* rss = new RSSWidget(m_webView, _rss, this);
|
2011-03-03 14:25:02 +01:00
|
|
|
rss->showAt(this);
|
|
|
|
}
|
|
|
|
|
2011-07-11 20:30:49 +02:00
|
|
|
void LocationBar::showRSSIcon(bool state)
|
|
|
|
{
|
|
|
|
m_rssIcon->setVisible(state);
|
|
|
|
}
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
void LocationBar::showUrl(const QUrl &url, bool empty)
|
|
|
|
{
|
2011-07-11 20:30:49 +02:00
|
|
|
if (hasFocus() || (url.isEmpty() && empty))
|
2011-03-02 16:57:41 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (url.toEncoded()!=text()) {
|
|
|
|
setText(url.toEncoded());
|
|
|
|
setCursorPosition(0);
|
|
|
|
}
|
|
|
|
|
2011-07-11 20:30:49 +02:00
|
|
|
// if (m_webView->isLoading()) {
|
|
|
|
// p_QupZilla->ipLabel()->hide();
|
|
|
|
// p_QupZilla->progressBar()->setVisible(true);
|
|
|
|
// p_QupZilla->progressBar()->setValue(m_webView->getLoading());
|
|
|
|
// p_QupZilla->buttonStop()->setVisible(true);
|
|
|
|
// p_QupZilla->buttonReload()->setVisible(false);
|
|
|
|
// } else {
|
|
|
|
// p_QupZilla->progressBar()->setVisible(false);
|
|
|
|
// p_QupZilla->buttonStop()->setVisible(false);
|
|
|
|
// p_QupZilla->buttonReload()->setVisible(true);
|
|
|
|
// p_QupZilla->ipLabel()->show();
|
|
|
|
// }
|
2011-04-15 20:45:22 +02:00
|
|
|
|
2011-05-09 17:58:19 +02:00
|
|
|
p_QupZilla->statusBarMessage()->clearMessage();
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
hideGoButton();
|
2011-04-15 20:45:22 +02:00
|
|
|
|
|
|
|
m_bookmarkIcon->checkBookmark(url);
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void LocationBar::siteIconChanged()
|
|
|
|
{
|
2011-04-04 16:00:27 +02:00
|
|
|
// const QPixmap* icon_ = 0;
|
|
|
|
QIcon icon_;
|
|
|
|
// if (!p_QupZilla->weView()->isLoading())
|
|
|
|
// icon_ = p_QupZilla->weView()->animationLoading( p_QupZilla->tabWidget()->currentIndex(), false)->pixmap();
|
2011-07-11 20:30:49 +02:00
|
|
|
icon_ = m_webView->siteIcon();
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2011-04-04 16:00:27 +02:00
|
|
|
if (icon_.isNull()) {
|
2011-07-11 20:30:49 +02:00
|
|
|
clearIcon();
|
2011-03-02 16:57:41 +01:00
|
|
|
} else {
|
2011-04-04 16:00:27 +02:00
|
|
|
// QIcon icon(*icon_);
|
2011-04-04 16:29:25 +02:00
|
|
|
m_siteIcon->setIcon(QIcon(icon_.pixmap(16,16)));
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-11 20:30:49 +02:00
|
|
|
void LocationBar::clearIcon()
|
|
|
|
{
|
|
|
|
m_siteIcon->setIcon(QIcon(QWebSettings::webGraphic(QWebSettings::DefaultFrameIconGraphic)));
|
|
|
|
}
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
void LocationBar::setPrivacy(bool state)
|
|
|
|
{
|
|
|
|
if (state)
|
|
|
|
m_siteIcon->setStyleSheet("QToolButton{border-image: url(:/icons/locationbar/safeline.png); margin-left:2px;}");
|
|
|
|
else
|
|
|
|
m_siteIcon->setStyleSheet("QToolButton{border-image: url(:/icons/locationbar/searchchoose.png); margin-left:2px;}");
|
|
|
|
}
|
|
|
|
|
2011-03-17 17:03:04 +01:00
|
|
|
void LocationBar::focusOutEvent(QFocusEvent* e)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
|
|
|
QLineEdit::focusOutEvent(e);
|
2011-06-12 09:54:36 +02:00
|
|
|
if (!selectedText().isEmpty() && e->reason() != Qt::TabFocusReason)
|
2011-03-02 16:57:41 +01:00
|
|
|
return;
|
|
|
|
setCursorPosition(0);
|
|
|
|
hideGoButton();
|
|
|
|
}
|
|
|
|
|
2011-03-17 17:03:04 +01:00
|
|
|
void LocationBar::dropEvent(QDropEvent* event)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
|
|
|
if (event->mimeData()->hasUrls()) {
|
|
|
|
QUrl dropUrl = event->mimeData()->urls().at(0);
|
|
|
|
if (WebView::isUrlValid(dropUrl)) {
|
2011-05-17 21:54:13 +02:00
|
|
|
setText(dropUrl.toString());
|
2011-03-02 16:57:41 +01:00
|
|
|
p_QupZilla->loadAddress(dropUrl);
|
|
|
|
QLineEdit::focusOutEvent(new QFocusEvent(QFocusEvent::FocusOut));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2011-06-12 09:54:36 +02:00
|
|
|
else if (event->mimeData()->hasText()) {
|
2011-03-02 16:57:41 +01:00
|
|
|
QUrl dropUrl = QUrl(event->mimeData()->text());
|
|
|
|
if (WebView::isUrlValid(dropUrl)) {
|
2011-05-17 21:54:13 +02:00
|
|
|
setText(dropUrl.toString());
|
2011-03-02 16:57:41 +01:00
|
|
|
p_QupZilla->loadAddress(dropUrl);
|
|
|
|
QLineEdit::focusOutEvent(new QFocusEvent(QFocusEvent::FocusOut));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
QLineEdit::dropEvent(event);
|
|
|
|
}
|
|
|
|
|
2011-03-17 17:03:04 +01:00
|
|
|
void LocationBar::mouseDoubleClickEvent(QMouseEvent* event)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
|
|
|
if (event->button() == Qt::LeftButton && m_selectAllOnDoubleClick)
|
|
|
|
selectAll();
|
|
|
|
else
|
|
|
|
QLineEdit::mouseDoubleClickEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocationBar::keyPressEvent(QKeyEvent *event)
|
|
|
|
{
|
|
|
|
if (event->key() == Qt::Key_Escape) {
|
2011-07-11 20:30:49 +02:00
|
|
|
setText(m_webView->url().toEncoded());
|
2011-03-02 16:57:41 +01:00
|
|
|
event->accept();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString localDomain = tr(".co.uk","Append domain name on ALT key = Should be different for every country");
|
|
|
|
if (event->key() == Qt::Key_Control && m_addComWithCtrl && !text().endsWith(".com")) //Disabled for a while
|
|
|
|
setText(text().append(".com"));
|
|
|
|
if (event->key() == Qt::Key_Alt && m_addCountryWithAlt && !text().endsWith(localDomain) && !text().endsWith("/"))
|
|
|
|
setText(text().append(localDomain));
|
|
|
|
|
|
|
|
QLineEdit::keyPressEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
LocationBar::~LocationBar()
|
|
|
|
{
|
2011-04-15 20:45:22 +02:00
|
|
|
delete m_bookmarkIcon;
|
2011-03-02 16:57:41 +01:00
|
|
|
delete m_goButton;
|
|
|
|
delete m_siteIcon;
|
|
|
|
delete m_rssIcon;
|
|
|
|
delete m_locationCompleter;
|
|
|
|
}
|