2011-03-03 18:29:20 +01:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
2016-02-27 17:12:39 +01:00
|
|
|
* Copyright (C) 2010-2016 David Rosca <nowrep@gmail.com>
|
2011-03-03 18:29:20 +01:00
|
|
|
*
|
|
|
|
* 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"
|
2014-02-19 22:07:21 +01:00
|
|
|
#include "browserwindow.h"
|
2012-01-21 20:27:45 +01:00
|
|
|
#include "tabbedwebview.h"
|
2011-03-02 16:57:41 +01:00
|
|
|
#include "mainapplication.h"
|
2011-03-22 21:36:15 +01:00
|
|
|
#include "webpage.h"
|
2012-01-21 23:19:38 +01:00
|
|
|
#include "tabwidget.h"
|
2014-02-09 12:22:49 +01:00
|
|
|
#include "bookmarksicon.h"
|
2014-04-24 11:56:03 +02:00
|
|
|
#include "bookmarks.h"
|
|
|
|
#include "bookmarkitem.h"
|
2011-12-17 14:26:34 +01:00
|
|
|
#include "siteicon.h"
|
2011-12-27 18:50:52 +01:00
|
|
|
#include "goicon.h"
|
|
|
|
#include "downicon.h"
|
2013-01-22 19:04:22 +01:00
|
|
|
#include "qztools.h"
|
2012-03-13 17:51:06 +01:00
|
|
|
#include "iconprovider.h"
|
2012-08-10 21:16:43 +02:00
|
|
|
#include "qzsettings.h"
|
2012-09-19 20:24:41 +02:00
|
|
|
#include "colors.h"
|
2013-02-08 18:44:26 +01:00
|
|
|
#include "autofillicon.h"
|
2014-03-16 13:06:38 +01:00
|
|
|
#include "searchenginesmanager.h"
|
2014-03-01 13:02:57 +01:00
|
|
|
#include "completer/locationcompleter.h"
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-08-24 20:53:53 +02:00
|
|
|
#include <QTimer>
|
2014-03-16 13:06:38 +01:00
|
|
|
#include <QMimeData>
|
2014-03-15 23:22:35 +01:00
|
|
|
#include <QCompleter>
|
|
|
|
#include <QStringListModel>
|
2014-03-16 13:06:38 +01:00
|
|
|
#include <QContextMenuEvent>
|
2014-03-16 13:55:37 +01:00
|
|
|
#include <QStyleOptionFrameV3>
|
2012-02-29 18:33:50 +01:00
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
LocationBar::LocationBar(BrowserWindow* window)
|
|
|
|
: LineEdit(window)
|
|
|
|
, m_window(window)
|
2011-11-06 12:05:16 +01:00
|
|
|
, m_webView(0)
|
2012-01-18 16:52:30 +01:00
|
|
|
, m_holdingAlt(false)
|
2014-11-18 12:45:37 +01:00
|
|
|
, m_oldTextLength(0)
|
|
|
|
, m_currentTextLength(0)
|
2012-08-24 20:53:53 +02:00
|
|
|
, m_loadProgress(0)
|
2012-09-19 10:08:30 +02:00
|
|
|
, m_progressVisible(false)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2011-09-11 19:15:06 +02:00
|
|
|
setObjectName("locationbar");
|
2012-05-27 14:05:28 +02:00
|
|
|
setDragEnabled(true);
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2014-03-16 11:21:24 +01:00
|
|
|
// Disable Oxygen QLineEdit transitions, it breaks with setText() && home()
|
|
|
|
setProperty("_kde_no_animations", QVariant(true));
|
|
|
|
|
2014-02-09 12:22:49 +01:00
|
|
|
m_bookmarkIcon = new BookmarksIcon(this);
|
2011-12-27 18:50:52 +01:00
|
|
|
m_goIcon = new GoIcon(this);
|
2014-02-19 22:07:21 +01:00
|
|
|
m_siteIcon = new SiteIcon(m_window, this);
|
2013-02-08 18:44:26 +01:00
|
|
|
m_autofillIcon = new AutoFillIcon(this);
|
2011-12-27 18:50:52 +01:00
|
|
|
DownIcon* down = new DownIcon(this);
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-08-11 13:13:37 +02:00
|
|
|
addWidget(m_siteIcon, LineEdit::LeftSide);
|
2013-02-08 18:44:26 +01:00
|
|
|
addWidget(m_autofillIcon, LineEdit::RightSide);
|
2012-08-13 15:41:08 +02:00
|
|
|
addWidget(m_bookmarkIcon, LineEdit::RightSide);
|
2013-06-05 00:02:43 +02:00
|
|
|
addWidget(m_goIcon, LineEdit::RightSide);
|
2012-08-13 15:41:08 +02:00
|
|
|
addWidget(down, LineEdit::RightSide);
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2014-03-01 13:02:57 +01:00
|
|
|
m_completer = new LocationCompleter(this);
|
|
|
|
m_completer->setMainWindow(m_window);
|
|
|
|
m_completer->setLocationBar(this);
|
|
|
|
connect(m_completer, SIGNAL(showCompletion(QString)), this, SLOT(showCompletion(QString)));
|
2014-03-15 23:22:35 +01:00
|
|
|
connect(m_completer, SIGNAL(showDomainCompletion(QString)), this, SLOT(showDomainCompletion(QString)));
|
2014-03-16 12:11:24 +01:00
|
|
|
connect(m_completer, SIGNAL(loadCompletion()), this, SLOT(requestLoadUrl()));
|
2014-03-01 13:02:57 +01:00
|
|
|
connect(m_completer, SIGNAL(clearCompletion()), this, SLOT(clearCompletion()));
|
2014-03-15 23:22:35 +01:00
|
|
|
|
|
|
|
m_domainCompleterModel = new QStringListModel(this);
|
|
|
|
QCompleter* domainCompleter = new QCompleter(this);
|
|
|
|
domainCompleter->setCompletionMode(QCompleter::InlineCompletion);
|
|
|
|
domainCompleter->setModel(m_domainCompleterModel);
|
|
|
|
setCompleter(domainCompleter);
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2016-02-27 17:12:39 +01:00
|
|
|
m_progressTimer = new QTimer(this);
|
|
|
|
m_progressTimer->setInterval(700);
|
|
|
|
m_progressTimer->setSingleShot(true);
|
|
|
|
connect(m_progressTimer, &QTimer::timeout, this, &LocationBar::hideProgress);
|
|
|
|
|
2014-10-18 16:33:37 +02:00
|
|
|
editAction(PasteAndGo)->setText(tr("Paste And &Go"));
|
|
|
|
editAction(PasteAndGo)->setIcon(QIcon::fromTheme(QSL("edit-paste")));
|
|
|
|
connect(editAction(PasteAndGo), SIGNAL(triggered()), this, SLOT(pasteAndGo()));
|
|
|
|
|
2014-11-18 12:45:37 +01:00
|
|
|
connect(this, SIGNAL(textEdited(QString)), this, SLOT(textEdited(QString)));
|
2014-03-16 12:11:24 +01:00
|
|
|
connect(m_goIcon, SIGNAL(clicked(QPoint)), this, SLOT(requestLoadUrl()));
|
2014-03-01 13:02:57 +01:00
|
|
|
connect(down, SIGNAL(clicked(QPoint)), m_completer, SLOT(showMostVisited()));
|
2011-11-06 12:05:16 +01:00
|
|
|
connect(mApp->searchEnginesManager(), SIGNAL(activeEngineChanged()), this, SLOT(updatePlaceHolderText()));
|
2012-09-27 11:59:09 +02:00
|
|
|
connect(mApp->searchEnginesManager(), SIGNAL(defaultEngineChanged()), this, SLOT(updatePlaceHolderText()));
|
2014-03-10 00:47:07 +01:00
|
|
|
connect(mApp, SIGNAL(settingsReloaded()), SLOT(loadSettings()));
|
2012-09-19 10:08:30 +02:00
|
|
|
|
|
|
|
loadSettings();
|
2014-03-16 12:11:24 +01:00
|
|
|
|
|
|
|
updateSiteIcon();
|
2013-02-08 18:44:26 +01:00
|
|
|
|
|
|
|
// Hide icons by default
|
2014-03-16 12:11:24 +01:00
|
|
|
m_goIcon->setVisible(qzSettings->alwaysShowGoIcon);
|
2013-02-08 18:44:26 +01:00
|
|
|
m_autofillIcon->hide();
|
2014-02-13 16:44:00 +01:00
|
|
|
|
|
|
|
QTimer::singleShot(0, this, SLOT(updatePlaceHolderText()));
|
2011-11-06 12:05:16 +01:00
|
|
|
}
|
|
|
|
|
2014-03-15 23:22:35 +01:00
|
|
|
TabbedWebView* LocationBar::webView() const
|
|
|
|
{
|
|
|
|
return m_webView;
|
|
|
|
}
|
|
|
|
|
2012-08-24 20:53:53 +02:00
|
|
|
void LocationBar::setWebView(TabbedWebView* view)
|
|
|
|
{
|
|
|
|
m_webView = view;
|
|
|
|
|
2013-02-10 12:28:53 +01:00
|
|
|
m_bookmarkIcon->setWebView(m_webView);
|
|
|
|
m_siteIcon->setWebView(m_webView);
|
|
|
|
m_autofillIcon->setWebView(m_webView);
|
|
|
|
|
2014-03-16 12:11:24 +01:00
|
|
|
connect(m_webView, SIGNAL(loadStarted()), SLOT(loadStarted()));
|
|
|
|
connect(m_webView, SIGNAL(loadProgress(int)), SLOT(loadProgress(int)));
|
|
|
|
connect(m_webView, SIGNAL(loadFinished(bool)), SLOT(loadFinished()));
|
|
|
|
connect(m_webView, SIGNAL(urlChanged(QUrl)), this, SLOT(showUrl(QUrl)));
|
|
|
|
connect(m_webView, SIGNAL(privacyChanged(bool)), this, SLOT(setPrivacyState(bool)));
|
2015-01-27 11:01:52 +01:00
|
|
|
connect(m_webView, SIGNAL(iconChanged()), this, SLOT(updateSiteIcon()));
|
2012-08-24 20:53:53 +02:00
|
|
|
}
|
|
|
|
|
2011-12-17 14:26:34 +01:00
|
|
|
void LocationBar::setText(const QString &text)
|
|
|
|
{
|
2014-11-18 12:45:37 +01:00
|
|
|
m_oldTextLength = text.length();
|
|
|
|
m_currentTextLength = m_oldTextLength;
|
|
|
|
|
2011-12-17 14:26:34 +01:00
|
|
|
LineEdit::setText(text);
|
2014-03-15 23:22:35 +01:00
|
|
|
|
|
|
|
refreshTextFormat();
|
2011-12-17 14:26:34 +01:00
|
|
|
}
|
|
|
|
|
2011-11-06 12:05:16 +01:00
|
|
|
void LocationBar::updatePlaceHolderText()
|
|
|
|
{
|
2016-01-14 03:29:47 +01:00
|
|
|
if (qzSettings->searchFromAddressBar) {
|
|
|
|
QString engineName = qzSettings->searchWithDefaultEngine ?
|
|
|
|
mApp->searchEnginesManager()->defaultEngine().name :
|
|
|
|
mApp->searchEnginesManager()->activeEngine().name;
|
|
|
|
setPlaceholderText(tr("Enter URL address or search on %1").arg(engineName));
|
|
|
|
} else
|
|
|
|
setPlaceholderText(tr("Enter URL address"));
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2014-03-15 19:36:03 +01:00
|
|
|
void LocationBar::showCompletion(const QString &completion)
|
2012-04-22 17:09:43 +02:00
|
|
|
{
|
2014-03-15 19:36:03 +01:00
|
|
|
LineEdit::setText(completion);
|
2012-09-02 15:19:12 +02:00
|
|
|
|
|
|
|
// Move cursor to the end
|
2012-04-22 17:09:43 +02:00
|
|
|
end(false);
|
|
|
|
}
|
|
|
|
|
2014-03-01 13:02:57 +01:00
|
|
|
void LocationBar::clearCompletion()
|
|
|
|
{
|
|
|
|
m_webView->setFocus();
|
|
|
|
showUrl(m_webView->url());
|
|
|
|
}
|
|
|
|
|
2014-03-15 23:22:35 +01:00
|
|
|
void LocationBar::showDomainCompletion(const QString &completion)
|
2014-03-15 19:36:03 +01:00
|
|
|
{
|
2014-03-15 23:22:35 +01:00
|
|
|
m_domainCompleterModel->setStringList(QStringList() << completion);
|
2014-06-26 15:42:38 +02:00
|
|
|
|
|
|
|
// We need to manually force the completion because model is updated asynchronously
|
2014-11-18 12:45:37 +01:00
|
|
|
// But only force completion when the user actually added new text
|
|
|
|
if (m_oldTextLength < m_currentTextLength)
|
2014-06-26 15:42:38 +02:00
|
|
|
completer()->complete();
|
2014-03-15 19:36:03 +01:00
|
|
|
}
|
|
|
|
|
2014-03-19 21:27:43 +01:00
|
|
|
LoadRequest LocationBar::createLoadRequest() const
|
2011-07-11 20:30:49 +02:00
|
|
|
{
|
2014-03-19 21:27:43 +01:00
|
|
|
LoadRequest req;
|
2011-10-21 23:26:34 +02:00
|
|
|
|
2015-10-01 19:25:17 +02:00
|
|
|
const QString &t = text().trimmed();
|
|
|
|
|
2013-05-10 22:33:36 +02:00
|
|
|
// Check for Search Engine shortcut
|
2015-10-01 19:25:17 +02:00
|
|
|
int firstSpacePos = t.indexOf(QLatin1Char(' '));
|
2011-10-21 23:26:34 +02:00
|
|
|
if (firstSpacePos != -1) {
|
2015-10-01 19:25:17 +02:00
|
|
|
const QString shortcut = t.left(firstSpacePos);
|
|
|
|
const QString searchedString = t.mid(firstSpacePos).trimmed();
|
2011-10-21 23:26:34 +02:00
|
|
|
|
|
|
|
SearchEngine en = mApp->searchEnginesManager()->engineForShortcut(shortcut);
|
|
|
|
if (!en.name.isEmpty()) {
|
2014-03-19 21:27:43 +01:00
|
|
|
req = mApp->searchEnginesManager()->searchResult(en, searchedString);
|
2011-10-21 23:26:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-24 11:56:03 +02:00
|
|
|
// Check for Bookmark keyword
|
2015-10-01 19:25:17 +02:00
|
|
|
QList<BookmarkItem*> items = mApp->bookmarks()->searchKeyword(t);
|
2014-04-24 11:56:03 +02:00
|
|
|
if (!items.isEmpty()) {
|
2015-10-23 11:55:14 +02:00
|
|
|
BookmarkItem* item = items.at(0);
|
2014-04-24 11:56:03 +02:00
|
|
|
item->updateVisitCount();
|
|
|
|
req.setUrl(item->url());
|
|
|
|
}
|
|
|
|
|
2014-03-19 21:27:43 +01:00
|
|
|
if (req.isEmpty()) {
|
2015-10-01 19:25:17 +02:00
|
|
|
// One word needs special handling, because QUrl::fromUserInput
|
|
|
|
// would convert it to QUrl("http://WORD")
|
|
|
|
if (!t.contains(QL1C(' ')) && !t.contains(QL1C('.'))) {
|
|
|
|
req.setUrl(QUrl(t));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
const QUrl &guessed = QUrl::fromUserInput(t);
|
|
|
|
if (!guessed.isEmpty())
|
|
|
|
req.setUrl(guessed);
|
|
|
|
else
|
|
|
|
req.setUrl(QUrl::fromEncoded(t.toUtf8()));
|
|
|
|
}
|
2011-10-21 23:26:34 +02:00
|
|
|
}
|
|
|
|
|
2014-03-19 21:27:43 +01:00
|
|
|
return req;
|
2012-01-18 16:52:30 +01:00
|
|
|
}
|
|
|
|
|
2015-01-21 12:38:12 +01:00
|
|
|
QString LocationBar::convertUrlToText(const QUrl &url)
|
2012-09-06 10:53:37 +02:00
|
|
|
{
|
2014-02-10 21:58:25 +01:00
|
|
|
// It was most probably entered by user, so don't urlencode it
|
|
|
|
if (url.scheme().isEmpty()) {
|
2015-01-21 12:38:12 +01:00
|
|
|
return QUrl::fromPercentEncoding(url.toEncoded());
|
2014-02-10 21:58:25 +01:00
|
|
|
}
|
|
|
|
|
2013-01-22 19:04:22 +01:00
|
|
|
QString stringUrl = QzTools::urlEncodeQueryString(url);
|
2012-09-06 10:53:37 +02:00
|
|
|
|
2015-10-14 12:34:49 +02:00
|
|
|
if (stringUrl == QL1S("qupzilla:speeddial") || stringUrl.startsWith(QL1S("qupzilla:adblock")) || stringUrl == QL1S("about:blank")) {
|
2013-02-22 15:20:28 +01:00
|
|
|
stringUrl.clear();
|
2012-09-06 10:53:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return stringUrl;
|
|
|
|
}
|
|
|
|
|
2014-03-15 23:22:35 +01:00
|
|
|
void LocationBar::refreshTextFormat()
|
2014-01-08 10:39:41 +01:00
|
|
|
{
|
2014-03-15 23:22:35 +01:00
|
|
|
if (!m_webView) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
TextFormat textFormat;
|
|
|
|
const QString hostName = m_webView->url().isEmpty() ? QUrl(text()).host() : m_webView->url().host();
|
|
|
|
|
|
|
|
if (!hostName.isEmpty()) {
|
|
|
|
const int hostPos = text().indexOf(hostName);
|
|
|
|
|
|
|
|
if (hostPos > 0) {
|
|
|
|
QTextCharFormat format;
|
|
|
|
format.setForeground(Colors::mid(palette().color(QPalette::Base), palette().color(QPalette::Text), 1, 1));
|
|
|
|
|
|
|
|
QTextLayout::FormatRange schemePart;
|
|
|
|
schemePart.start = 0;
|
|
|
|
schemePart.length = hostPos;
|
|
|
|
schemePart.format = format;
|
|
|
|
|
|
|
|
QTextLayout::FormatRange hostPart;
|
|
|
|
hostPart.start = hostPos;
|
|
|
|
hostPart.length = hostName.size();
|
|
|
|
|
|
|
|
QTextLayout::FormatRange remainingPart;
|
|
|
|
remainingPart.start = hostPos + hostName.size();
|
|
|
|
remainingPart.length = text().size() - remainingPart.start;
|
|
|
|
remainingPart.format = format;
|
|
|
|
|
|
|
|
textFormat.append(schemePart);
|
|
|
|
textFormat.append(hostPart);
|
|
|
|
textFormat.append(remainingPart);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setTextFormat(textFormat);
|
2014-01-08 10:39:41 +01:00
|
|
|
}
|
|
|
|
|
2014-03-16 12:11:24 +01:00
|
|
|
void LocationBar::requestLoadUrl()
|
2012-01-18 16:52:30 +01:00
|
|
|
{
|
2014-03-19 21:27:43 +01:00
|
|
|
const LoadRequest req = createLoadRequest();
|
|
|
|
const QString urlString = convertUrlToText(req.url());
|
2013-05-10 22:33:36 +02:00
|
|
|
|
2014-03-01 13:02:57 +01:00
|
|
|
m_completer->closePopup();
|
2011-07-11 20:30:49 +02:00
|
|
|
m_webView->setFocus();
|
2012-01-21 23:51:24 +01:00
|
|
|
|
2013-05-10 22:33:36 +02:00
|
|
|
if (urlString != text()) {
|
2014-03-16 12:11:24 +01:00
|
|
|
setText(urlString);
|
2013-05-10 22:33:36 +02:00
|
|
|
}
|
|
|
|
|
2014-03-19 21:27:43 +01:00
|
|
|
m_webView->userLoadAction(req);
|
2011-07-11 20:30:49 +02:00
|
|
|
}
|
|
|
|
|
2014-11-18 12:45:37 +01:00
|
|
|
void LocationBar::textEdited(const QString &text)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2014-11-18 12:45:37 +01:00
|
|
|
m_oldTextLength = m_currentTextLength;
|
|
|
|
m_currentTextLength = text.length();
|
|
|
|
|
|
|
|
if (!text.isEmpty()) {
|
|
|
|
m_completer->complete(text);
|
2012-04-22 17:09:43 +02:00
|
|
|
}
|
|
|
|
else {
|
2014-03-01 13:02:57 +01:00
|
|
|
m_completer->closePopup();
|
2012-04-22 17:09:43 +02:00
|
|
|
}
|
|
|
|
|
2014-03-16 12:11:24 +01:00
|
|
|
setGoIconVisible(true);
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2014-03-16 12:11:24 +01:00
|
|
|
void LocationBar::setGoIconVisible(bool state)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2014-03-16 12:11:24 +01:00
|
|
|
if (state) {
|
|
|
|
m_bookmarkIcon->hide();
|
|
|
|
m_goIcon->show();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
m_bookmarkIcon->show();
|
2013-06-05 00:02:43 +02:00
|
|
|
|
2014-03-16 12:11:24 +01:00
|
|
|
if (!qzSettings->alwaysShowGoIcon) {
|
|
|
|
m_goIcon->hide();
|
|
|
|
}
|
2013-06-05 00:02:43 +02:00
|
|
|
}
|
2012-03-16 15:55:34 +01:00
|
|
|
|
|
|
|
updateTextMargins();
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-01-21 20:27:45 +01:00
|
|
|
void LocationBar::showUrl(const QUrl &url)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2012-01-21 20:27:45 +01:00
|
|
|
if (hasFocus() || url.isEmpty()) {
|
2011-03-02 16:57:41 +01:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2013-12-30 13:43:48 +01:00
|
|
|
const QString stringUrl = convertUrlToText(url);
|
2011-12-12 18:30:08 +01:00
|
|
|
|
2014-03-16 11:21:24 +01:00
|
|
|
if (text() == stringUrl) {
|
|
|
|
home(false);
|
2014-04-20 09:51:20 +02:00
|
|
|
refreshTextFormat();
|
2012-03-30 13:43:47 +02:00
|
|
|
return;
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
2011-05-09 17:58:19 +02:00
|
|
|
|
2014-03-16 11:21:24 +01:00
|
|
|
// Set converted url as text
|
2014-12-13 01:07:41 +01:00
|
|
|
setText(stringUrl);
|
2014-03-16 11:21:24 +01:00
|
|
|
|
|
|
|
// Move cursor to the start
|
|
|
|
home(false);
|
2012-03-30 13:43:47 +02:00
|
|
|
|
2011-04-15 20:45:22 +02:00
|
|
|
m_bookmarkIcon->checkBookmark(url);
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2014-03-16 12:11:24 +01:00
|
|
|
void LocationBar::updateSiteIcon()
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2016-01-24 13:49:15 +01:00
|
|
|
QIcon icon = m_webView ? m_webView->icon() : IconProvider::emptyWebIcon();
|
|
|
|
if (m_webView && m_webView->url().scheme() == QL1S("https"))
|
|
|
|
icon = QIcon::fromTheme(QSL("document-encrypted"), icon);
|
2015-10-24 12:43:15 +02:00
|
|
|
m_siteIcon->setIcon(QIcon(icon.pixmap(16)));
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2014-03-16 12:11:24 +01:00
|
|
|
void LocationBar::setPrivacyState(bool state)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2012-06-26 11:49:39 +02:00
|
|
|
m_siteIcon->setProperty("secured", QVariant(state));
|
2011-09-11 19:15:06 +02:00
|
|
|
m_siteIcon->style()->unpolish(m_siteIcon);
|
|
|
|
m_siteIcon->style()->polish(m_siteIcon);
|
2011-12-12 21:47:32 +01:00
|
|
|
|
2012-06-26 11:49:39 +02:00
|
|
|
setProperty("secured", QVariant(state));
|
2011-12-12 21:47:32 +01:00
|
|
|
style()->unpolish(this);
|
|
|
|
style()->polish(this);
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-01-21 19:26:47 +01:00
|
|
|
void LocationBar::pasteAndGo()
|
|
|
|
{
|
|
|
|
clear();
|
|
|
|
paste();
|
2014-03-16 12:11:24 +01:00
|
|
|
requestLoadUrl();
|
2012-01-21 19:26:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void LocationBar::contextMenuEvent(QContextMenuEvent* event)
|
|
|
|
{
|
2014-10-18 16:33:37 +02:00
|
|
|
QMenu* menu = createContextMenu();
|
2014-03-16 13:06:38 +01:00
|
|
|
menu->setAttribute(Qt::WA_DeleteOnClose);
|
2012-01-21 19:26:47 +01:00
|
|
|
|
2012-10-11 19:57:12 +02:00
|
|
|
// Prevent choosing first option with double rightclick
|
2012-03-23 17:29:12 +01:00
|
|
|
QPoint pos = event->globalPos();
|
2014-03-16 13:06:38 +01:00
|
|
|
pos.setY(pos.y() + 1);
|
|
|
|
menu->popup(pos);
|
2012-01-21 19:26:47 +01:00
|
|
|
}
|
|
|
|
|
2014-03-15 23:22:35 +01:00
|
|
|
void LocationBar::showEvent(QShowEvent* event)
|
|
|
|
{
|
|
|
|
LineEdit::showEvent(event);
|
|
|
|
|
|
|
|
refreshTextFormat();
|
|
|
|
}
|
|
|
|
|
2012-09-06 10:53:37 +02:00
|
|
|
void LocationBar::focusInEvent(QFocusEvent* event)
|
|
|
|
{
|
2013-11-26 14:14:36 +01:00
|
|
|
if (m_webView) {
|
2013-12-30 13:43:48 +01:00
|
|
|
const QString stringUrl = convertUrlToText(m_webView->url());
|
2012-09-06 10:53:37 +02:00
|
|
|
|
2013-11-26 14:14:36 +01:00
|
|
|
// Text has been edited, let's show go button
|
|
|
|
if (stringUrl != text()) {
|
2014-03-16 12:11:24 +01:00
|
|
|
setGoIconVisible(true);
|
2013-11-26 14:14:36 +01:00
|
|
|
}
|
2012-09-06 10:53:37 +02:00
|
|
|
}
|
|
|
|
|
2014-03-15 23:22:35 +01:00
|
|
|
clearTextFormat();
|
2012-09-06 10:53:37 +02:00
|
|
|
LineEdit::focusInEvent(event);
|
|
|
|
}
|
|
|
|
|
2014-03-15 23:22:35 +01:00
|
|
|
void LocationBar::focusOutEvent(QFocusEvent* event)
|
|
|
|
{
|
|
|
|
// Context menu or completer popup were opened
|
|
|
|
// Let's block focusOutEvent to trick QLineEdit and paint cursor properly
|
|
|
|
if (event->reason() == Qt::PopupFocusReason) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
LineEdit::focusOutEvent(event);
|
|
|
|
|
2014-03-16 12:11:24 +01:00
|
|
|
setGoIconVisible(false);
|
2014-03-15 23:22:35 +01:00
|
|
|
|
|
|
|
if (text().trimmed().isEmpty()) {
|
|
|
|
clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
refreshTextFormat();
|
|
|
|
}
|
|
|
|
|
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-12-15 17:43:06 +01:00
|
|
|
|
|
|
|
m_webView->setFocus();
|
2014-03-19 21:27:43 +01:00
|
|
|
m_webView->userLoadAction(dropUrl);
|
2011-12-15 17:43:06 +01:00
|
|
|
|
2012-03-01 18:32:53 +01:00
|
|
|
QFocusEvent event(QFocusEvent::FocusOut);
|
2013-03-15 11:46:07 +01:00
|
|
|
LineEdit::focusOutEvent(&event);
|
2011-03-02 16:57:41 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2011-06-12 09:54:36 +02:00
|
|
|
else if (event->mimeData()->hasText()) {
|
2011-07-21 17:16:53 +02:00
|
|
|
QUrl dropUrl = QUrl(event->mimeData()->text().trimmed());
|
2011-03-02 16:57:41 +01:00
|
|
|
if (WebView::isUrlValid(dropUrl)) {
|
2011-05-17 21:54:13 +02:00
|
|
|
setText(dropUrl.toString());
|
2011-12-15 17:43:06 +01:00
|
|
|
|
|
|
|
m_webView->setFocus();
|
2014-03-19 21:27:43 +01:00
|
|
|
m_webView->userLoadAction(dropUrl);
|
2011-12-15 17:43:06 +01:00
|
|
|
|
2012-03-01 18:32:53 +01:00
|
|
|
QFocusEvent event(QFocusEvent::FocusOut);
|
2013-03-15 11:46:07 +01:00
|
|
|
LineEdit::focusOutEvent(&event);
|
2011-03-02 16:57:41 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2013-03-15 11:46:07 +01:00
|
|
|
|
|
|
|
LineEdit::dropEvent(event);
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
void LocationBar::keyPressEvent(QKeyEvent* event)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2011-12-23 11:11:14 +01:00
|
|
|
switch (event->key()) {
|
2012-01-21 23:51:24 +01:00
|
|
|
case Qt::Key_V:
|
|
|
|
if (event->modifiers() == (Qt::ControlModifier | Qt::ShiftModifier)) {
|
|
|
|
pasteAndGo();
|
|
|
|
event->accept();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2012-04-22 17:09:43 +02:00
|
|
|
case Qt::Key_Down:
|
2014-03-01 13:02:57 +01:00
|
|
|
m_completer->complete(text());
|
2012-04-22 17:09:43 +02:00
|
|
|
break;
|
|
|
|
|
2013-05-11 00:17:38 +02:00
|
|
|
case Qt::Key_Left:
|
2014-03-15 23:22:35 +01:00
|
|
|
m_completer->closePopup();
|
2013-06-09 12:27:25 +02:00
|
|
|
break;
|
|
|
|
|
2011-12-23 11:11:14 +01:00
|
|
|
case Qt::Key_Escape:
|
2012-01-21 20:27:45 +01:00
|
|
|
m_webView->setFocus();
|
|
|
|
showUrl(m_webView->url());
|
2011-03-02 16:57:41 +01:00
|
|
|
event->accept();
|
2011-12-23 11:11:14 +01:00
|
|
|
break;
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2011-12-23 11:11:14 +01:00
|
|
|
case Qt::Key_Alt:
|
2012-01-18 16:52:30 +01:00
|
|
|
m_holdingAlt = true;
|
2011-12-23 11:11:14 +01:00
|
|
|
break;
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2011-12-23 11:11:14 +01:00
|
|
|
case Qt::Key_Return:
|
|
|
|
case Qt::Key_Enter:
|
2012-01-18 16:52:30 +01:00
|
|
|
switch (event->modifiers()) {
|
|
|
|
case Qt::ControlModifier:
|
2015-11-06 17:37:15 +01:00
|
|
|
if (!text().endsWith(QL1S(".com")))
|
|
|
|
setText(text().append(QL1S(".com")));
|
2014-03-16 12:11:24 +01:00
|
|
|
requestLoadUrl();
|
2012-03-03 21:35:02 +01:00
|
|
|
m_holdingAlt = false;
|
2012-01-18 16:52:30 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Qt::AltModifier:
|
2014-03-01 13:02:57 +01:00
|
|
|
m_completer->closePopup();
|
2014-03-19 21:27:43 +01:00
|
|
|
m_window->tabWidget()->addView(createLoadRequest());
|
2012-03-03 21:35:02 +01:00
|
|
|
m_holdingAlt = false;
|
2012-01-18 16:52:30 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2014-03-16 12:11:24 +01:00
|
|
|
requestLoadUrl();
|
2012-03-03 21:35:02 +01:00
|
|
|
m_holdingAlt = false;
|
2011-12-23 11:11:14 +01:00
|
|
|
}
|
2012-02-05 16:00:23 +01:00
|
|
|
|
2012-03-03 21:35:02 +01:00
|
|
|
break;
|
|
|
|
|
2012-02-05 16:00:23 +01:00
|
|
|
case Qt::Key_0:
|
|
|
|
case Qt::Key_1:
|
|
|
|
case Qt::Key_2:
|
|
|
|
case Qt::Key_3:
|
|
|
|
case Qt::Key_4:
|
|
|
|
case Qt::Key_5:
|
|
|
|
case Qt::Key_6:
|
|
|
|
case Qt::Key_7:
|
|
|
|
case Qt::Key_8:
|
|
|
|
case Qt::Key_9:
|
|
|
|
if (event->modifiers() & Qt::AltModifier || event->modifiers() & Qt::ControlModifier) {
|
|
|
|
event->ignore();
|
2012-03-03 21:35:02 +01:00
|
|
|
m_holdingAlt = false;
|
2012-02-05 16:00:23 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2011-12-23 11:11:14 +01:00
|
|
|
default:
|
2012-01-18 16:52:30 +01:00
|
|
|
m_holdingAlt = false;
|
2011-12-23 11:11:14 +01:00
|
|
|
}
|
2012-01-21 23:51:24 +01:00
|
|
|
|
|
|
|
LineEdit::keyPressEvent(event);
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2014-03-16 12:11:24 +01:00
|
|
|
void LocationBar::loadStarted()
|
2012-09-19 10:08:30 +02:00
|
|
|
{
|
|
|
|
m_progressVisible = true;
|
2016-02-27 17:12:39 +01:00
|
|
|
m_progressTimer->stop();
|
2013-02-08 18:44:26 +01:00
|
|
|
m_autofillIcon->hide();
|
2014-03-16 12:11:24 +01:00
|
|
|
m_siteIcon->setIcon(IconProvider::emptyWebIcon());
|
2012-09-19 10:08:30 +02:00
|
|
|
}
|
|
|
|
|
2014-03-16 12:11:24 +01:00
|
|
|
void LocationBar::loadProgress(int progress)
|
2012-08-24 20:53:53 +02:00
|
|
|
{
|
|
|
|
if (qzSettings->showLoadingProgress) {
|
|
|
|
m_loadProgress = progress;
|
2012-09-19 10:08:30 +02:00
|
|
|
update();
|
2012-08-24 20:53:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-16 12:11:24 +01:00
|
|
|
void LocationBar::loadFinished()
|
2012-08-24 20:53:53 +02:00
|
|
|
{
|
|
|
|
if (qzSettings->showLoadingProgress) {
|
2016-02-27 17:12:39 +01:00
|
|
|
m_progressTimer->start();
|
2012-08-24 20:53:53 +02:00
|
|
|
}
|
2013-02-08 18:44:26 +01:00
|
|
|
|
|
|
|
WebPage* page = qobject_cast<WebPage*>(m_webView->page());
|
|
|
|
|
|
|
|
if (page && page->hasMultipleUsernames()) {
|
|
|
|
m_autofillIcon->setFormData(page->autoFillData());
|
|
|
|
m_autofillIcon->show();
|
|
|
|
}
|
2014-03-16 12:11:24 +01:00
|
|
|
|
|
|
|
updateSiteIcon();
|
2012-08-24 20:53:53 +02:00
|
|
|
}
|
|
|
|
|
2012-09-19 10:08:30 +02:00
|
|
|
void LocationBar::loadSettings()
|
|
|
|
{
|
|
|
|
Settings settings;
|
|
|
|
settings.beginGroup("AddressBar");
|
|
|
|
m_progressStyle = static_cast<ProgressStyle>(settings.value("ProgressStyle", 0).toInt());
|
|
|
|
bool customColor = settings.value("UseCustomProgressColor", false).toBool();
|
|
|
|
m_progressColor = customColor ? settings.value("CustomProgressColor", palette().color(QPalette::Highlight)).value<QColor>() : QColor();
|
|
|
|
settings.endGroup();
|
|
|
|
}
|
|
|
|
|
2012-08-24 20:53:53 +02:00
|
|
|
void LocationBar::hideProgress()
|
|
|
|
{
|
2016-02-27 17:12:39 +01:00
|
|
|
if (qzSettings->showLoadingProgress) {
|
2012-09-19 10:08:30 +02:00
|
|
|
m_progressVisible = false;
|
|
|
|
update();
|
2012-08-24 20:53:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocationBar::paintEvent(QPaintEvent* event)
|
|
|
|
{
|
2014-03-16 13:55:37 +01:00
|
|
|
LineEdit::paintEvent(event);
|
|
|
|
|
|
|
|
// Show loading progress
|
2014-03-15 23:22:35 +01:00
|
|
|
if (qzSettings->showLoadingProgress && m_progressVisible) {
|
2016-04-24 10:17:13 +02:00
|
|
|
QStyleOptionFrame option;
|
2014-03-15 23:22:35 +01:00
|
|
|
initStyleOption(&option);
|
2013-12-23 19:21:47 +01:00
|
|
|
|
2014-03-15 23:22:35 +01:00
|
|
|
int lm, tm, rm, bm;
|
|
|
|
getTextMargins(&lm, &tm, &rm, &bm);
|
2013-12-23 19:21:47 +01:00
|
|
|
|
2014-03-15 23:22:35 +01:00
|
|
|
QRect contentsRect = style()->subElementRect(QStyle::SE_LineEditContents, &option, this);
|
|
|
|
contentsRect.adjust(lm, tm, -rm, -bm);
|
2013-12-23 19:21:47 +01:00
|
|
|
|
2012-09-19 10:08:30 +02:00
|
|
|
QColor bg = m_progressColor;
|
|
|
|
if (!bg.isValid() || bg.alpha() == 0) {
|
2014-03-15 23:22:35 +01:00
|
|
|
bg = Colors::mid(palette().color(QPalette::Base), palette().color(QPalette::Text), m_progressStyle > 0 ? 4 : 8, 1);
|
2012-09-19 10:08:30 +02:00
|
|
|
}
|
2014-03-15 23:22:35 +01:00
|
|
|
|
|
|
|
QPainter p(this);
|
2012-09-19 10:08:30 +02:00
|
|
|
p.setBrush(QBrush(bg));
|
|
|
|
|
2014-04-20 11:03:53 +02:00
|
|
|
// We are painting over text, make sure the text stays visible
|
|
|
|
p.setOpacity(0.5);
|
|
|
|
|
2012-09-19 10:08:30 +02:00
|
|
|
QPen outlinePen(bg.darker(110), 0.8);
|
|
|
|
p.setPen(outlinePen);
|
|
|
|
|
|
|
|
switch (m_progressStyle) {
|
|
|
|
case ProgressFilled: {
|
2012-09-30 10:55:44 +02:00
|
|
|
QRect bar = contentsRect.adjusted(0, 1, 0, -1);
|
2013-01-23 01:34:15 +01:00
|
|
|
bar.setWidth(bar.width() * m_loadProgress / 100);
|
2012-09-19 10:08:30 +02:00
|
|
|
const int roundness = bar.height() / 4.0;
|
|
|
|
p.drawRoundedRect(bar, roundness, roundness);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ProgressBottom: {
|
|
|
|
outlinePen.setWidthF(0.3);
|
|
|
|
outlinePen.setColor(outlinePen.color().darker(130));
|
|
|
|
p.setPen(outlinePen);
|
2012-09-30 10:55:44 +02:00
|
|
|
QRect bar(contentsRect.x(), contentsRect.bottom() - 3,
|
2013-01-23 01:34:15 +01:00
|
|
|
contentsRect.width() * m_loadProgress / 100.0, 3);
|
2012-09-19 10:08:30 +02:00
|
|
|
p.drawRoundedRect(bar, 1, 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ProgressTop: {
|
|
|
|
outlinePen.setWidthF(0.3);
|
|
|
|
outlinePen.setColor(outlinePen.color().darker(130));
|
|
|
|
p.setPen(outlinePen);
|
2014-03-15 23:22:35 +01:00
|
|
|
QRect bar(contentsRect.x(), contentsRect.top() + 1, contentsRect.width() * m_loadProgress / 100.0, 3);
|
2012-09-19 10:08:30 +02:00
|
|
|
p.drawRoundedRect(bar, 1, 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2012-09-19 20:24:41 +02:00
|
|
|
}
|
2013-02-08 18:44:26 +01:00
|
|
|
}
|