2011-03-03 18:29:20 +01:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
2012-01-01 15:29:55 +01:00
|
|
|
* Copyright (C) 2010-2012 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"
|
|
|
|
#include "qupzilla.h"
|
2012-01-21 20:27:45 +01:00
|
|
|
#include "tabbedwebview.h"
|
2011-03-02 16:57:41 +01:00
|
|
|
#include "rssmanager.h"
|
|
|
|
#include "mainapplication.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"
|
2012-01-21 23:19:38 +01:00
|
|
|
#include "tabwidget.h"
|
2011-04-15 20:45:22 +02:00
|
|
|
#include "bookmarkicon.h"
|
2012-09-14 22:09:58 +02:00
|
|
|
#include "bookmarkswidget.h"
|
2011-04-25 15:06:59 +02:00
|
|
|
#include "progressbar.h"
|
2011-05-09 17:58:19 +02:00
|
|
|
#include "statusbarmessage.h"
|
2011-09-11 19:15:06 +02:00
|
|
|
#include "toolbutton.h"
|
2011-10-21 23:26:34 +02:00
|
|
|
#include "searchenginesmanager.h"
|
2011-12-17 14:26:34 +01:00
|
|
|
#include "siteicon.h"
|
2011-12-27 18:50:52 +01:00
|
|
|
#include "goicon.h"
|
|
|
|
#include "rssicon.h"
|
|
|
|
#include "downicon.h"
|
2012-02-21 21:28:19 +01:00
|
|
|
#include "globalfunctions.h"
|
2012-03-13 17:51:06 +01:00
|
|
|
#include "iconprovider.h"
|
2012-08-10 21:16:43 +02:00
|
|
|
#include "qzsettings.h"
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-02-29 18:33:50 +01:00
|
|
|
#include <QClipboard>
|
2012-08-24 20:53:53 +02:00
|
|
|
#include <QTimer>
|
2012-08-31 15:19:07 +02:00
|
|
|
#include <QContextMenuEvent>
|
2012-02-29 18:33:50 +01:00
|
|
|
|
2011-07-11 20:30:49 +02:00
|
|
|
LocationBar::LocationBar(QupZilla* mainClass)
|
2012-04-22 20:51:28 +02:00
|
|
|
: LineEdit(mainClass)
|
2011-11-06 12:05:16 +01:00
|
|
|
, p_QupZilla(mainClass)
|
|
|
|
, m_webView(0)
|
2012-01-21 19:26:47 +01:00
|
|
|
, m_menu(new QMenu(this))
|
|
|
|
, m_pasteAndGoAction(0)
|
|
|
|
, m_clearAction(0)
|
2012-01-18 16:52:30 +01:00
|
|
|
, m_holdingAlt(false)
|
2012-08-24 20:53:53 +02:00
|
|
|
, m_loadProgress(0)
|
|
|
|
, m_loadFinished(true)
|
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
|
|
|
|
2011-04-15 20:45:22 +02:00
|
|
|
m_bookmarkIcon = new BookmarkIcon(p_QupZilla);
|
2011-12-27 18:50:52 +01:00
|
|
|
m_goIcon = new GoIcon(this);
|
|
|
|
m_rssIcon = new RssIcon(this);
|
|
|
|
m_rssIcon->setToolTip(tr("Add RSS from this page..."));
|
|
|
|
m_siteIcon = new SiteIcon(this);
|
|
|
|
DownIcon* down = new DownIcon(this);
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-08-11 13:13:37 +02:00
|
|
|
////RTL Support
|
|
|
|
////if we don't add 'm_siteIcon' by following code, then we should use suitable padding-left value
|
|
|
|
//// but then, when typing RTL text the layout dynamically changed and within RTL layout direction
|
|
|
|
//// padding-left is equivalent to padding-right and vice versa, and because style sheet is
|
|
|
|
//// not changed dynamically this create padding problems.
|
|
|
|
addWidget(m_siteIcon, LineEdit::LeftSide);
|
|
|
|
|
2011-12-27 18:50:52 +01:00
|
|
|
addWidget(m_goIcon, LineEdit::RightSide);
|
2012-08-13 15:41:08 +02:00
|
|
|
addWidget(m_bookmarkIcon, LineEdit::RightSide);
|
2011-03-02 16:57:41 +01:00
|
|
|
addWidget(m_rssIcon, LineEdit::RightSide);
|
2012-08-13 15:41:08 +02:00
|
|
|
addWidget(down, LineEdit::RightSide);
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-04-22 17:09:43 +02:00
|
|
|
m_completer.setLocationBar(this);
|
2012-09-08 22:52:32 +02:00
|
|
|
connect(&m_completer, SIGNAL(showCompletion(QString)), this, SLOT(showCompletion(QString)));
|
2012-04-22 17:09:43 +02:00
|
|
|
connect(&m_completer, SIGNAL(completionActivated()), this, SLOT(urlEnter()));
|
2011-03-02 16:57:41 +01:00
|
|
|
|
|
|
|
connect(this, SIGNAL(textEdited(QString)), this, SLOT(textEdit()));
|
|
|
|
connect(m_siteIcon, SIGNAL(clicked()), this, SLOT(showSiteInfo()));
|
2011-12-27 18:50:52 +01:00
|
|
|
connect(m_goIcon, SIGNAL(clicked(QPoint)), this, SLOT(urlEnter()));
|
2011-03-03 14:25:02 +01:00
|
|
|
connect(m_rssIcon, SIGNAL(clicked(QPoint)), this, SLOT(rssIconClicked()));
|
2012-09-14 22:09:58 +02:00
|
|
|
connect(m_bookmarkIcon, SIGNAL(clicked(QPoint)), this, SLOT(bookmarkIconClicked()));
|
2011-12-11 14:12:40 +01:00
|
|
|
connect(down, SIGNAL(clicked(QPoint)), this, SLOT(showMostVisited()));
|
2011-11-06 12:05:16 +01:00
|
|
|
connect(mApp->searchEnginesManager(), SIGNAL(activeEngineChanged()), this, SLOT(updatePlaceHolderText()));
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2011-07-11 20:30:49 +02:00
|
|
|
clearIcon();
|
2011-11-06 12:05:16 +01:00
|
|
|
updatePlaceHolderText();
|
|
|
|
}
|
|
|
|
|
2012-08-24 20:53:53 +02:00
|
|
|
void LocationBar::setWebView(TabbedWebView* view)
|
|
|
|
{
|
|
|
|
m_webView = view;
|
|
|
|
|
|
|
|
connect(m_webView, SIGNAL(loadProgress(int)), SLOT(onLoadProgress(int)));
|
|
|
|
connect(m_webView, SIGNAL(loadFinished(bool)), SLOT(onLoadFinished()));
|
|
|
|
}
|
|
|
|
|
2011-12-17 14:26:34 +01:00
|
|
|
void LocationBar::setText(const QString &text)
|
|
|
|
{
|
|
|
|
LineEdit::setText(text);
|
|
|
|
setCursorPosition(0);
|
|
|
|
}
|
|
|
|
|
2011-11-06 12:05:16 +01:00
|
|
|
void LocationBar::updatePlaceHolderText()
|
|
|
|
{
|
|
|
|
setPlaceholderText(tr("Enter URL address or search on %1").arg(mApp->searchEnginesManager()->activeEngine().name));
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-09-08 22:52:32 +02:00
|
|
|
void LocationBar::showCompletion(const QString &newText)
|
2012-04-22 17:09:43 +02:00
|
|
|
{
|
|
|
|
LineEdit::setText(newText);
|
2012-09-02 15:19:12 +02:00
|
|
|
|
|
|
|
// Move cursor to the end
|
2012-04-22 17:09:43 +02:00
|
|
|
end(false);
|
|
|
|
}
|
|
|
|
|
2012-01-18 16:52:30 +01:00
|
|
|
QUrl LocationBar::createUrl()
|
2011-07-11 20:30:49 +02:00
|
|
|
{
|
2011-10-21 23:26:34 +02:00
|
|
|
QUrl urlToLoad;
|
|
|
|
|
|
|
|
//Check for Search Engine shortcut
|
2012-09-04 12:42:45 +02:00
|
|
|
int firstSpacePos = text().indexOf(QLatin1Char(' '));
|
2011-10-21 23:26:34 +02:00
|
|
|
if (firstSpacePos != -1) {
|
2012-07-01 18:11:43 +02:00
|
|
|
QString shortcut = text().left(firstSpacePos);
|
2012-05-22 12:11:27 +02:00
|
|
|
QString searchedString = QUrl::toPercentEncoding(text().mid(firstSpacePos).trimmed());
|
2011-10-21 23:26:34 +02:00
|
|
|
|
|
|
|
SearchEngine en = mApp->searchEnginesManager()->engineForShortcut(shortcut);
|
|
|
|
if (!en.name.isEmpty()) {
|
2012-09-04 12:42:45 +02:00
|
|
|
urlToLoad = QUrl::fromEncoded(en.url.replace(QLatin1String("%s"), searchedString).toUtf8());
|
2011-10-21 23:26:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (urlToLoad.isEmpty()) {
|
|
|
|
QUrl guessedUrl = WebView::guessUrlFromString(text());
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!guessedUrl.isEmpty()) {
|
2011-10-21 23:26:34 +02:00
|
|
|
urlToLoad = guessedUrl;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
else {
|
2012-01-31 21:10:22 +01:00
|
|
|
urlToLoad = QUrl::fromEncoded(text().toUtf8());
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-10-21 23:26:34 +02:00
|
|
|
}
|
|
|
|
|
2012-01-18 16:52:30 +01:00
|
|
|
return urlToLoad;
|
|
|
|
}
|
|
|
|
|
2012-09-06 10:53:37 +02:00
|
|
|
QString LocationBar::convertUrlToText(const QUrl &url) const
|
|
|
|
{
|
|
|
|
QString stringUrl = qz_urlEncodeQueryString(url);
|
|
|
|
|
|
|
|
if (stringUrl == QLatin1String("qupzilla:speeddial") || stringUrl == QLatin1String("about:blank")) {
|
|
|
|
stringUrl = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
return stringUrl;
|
|
|
|
}
|
|
|
|
|
2012-01-18 16:52:30 +01:00
|
|
|
void LocationBar::urlEnter()
|
|
|
|
{
|
2012-04-22 17:09:43 +02:00
|
|
|
m_completer.closePopup();
|
2011-07-11 20:30:49 +02:00
|
|
|
m_webView->setFocus();
|
2012-01-21 23:51:24 +01:00
|
|
|
|
2012-01-18 16:52:30 +01:00
|
|
|
emit loadUrl(createUrl());
|
2011-07-11 20:30:49 +02:00
|
|
|
}
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
void LocationBar::textEdit()
|
|
|
|
{
|
2012-04-22 17:09:43 +02:00
|
|
|
if (!text().isEmpty()) {
|
|
|
|
m_completer.complete(text());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
m_completer.closePopup();
|
|
|
|
}
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
showGoButton();
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocationBar::showGoButton()
|
|
|
|
{
|
2011-12-27 18:50:52 +01:00
|
|
|
if (m_goIcon->isVisible()) {
|
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
|
|
|
|
|
|
|
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();
|
2011-12-27 18:50:52 +01:00
|
|
|
m_goIcon->show();
|
2012-03-16 15:55:34 +01:00
|
|
|
|
|
|
|
updateTextMargins();
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void LocationBar::hideGoButton()
|
|
|
|
{
|
2011-12-27 18:50:52 +01:00
|
|
|
if (!m_goIcon->isVisible()) {
|
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
|
|
|
|
|
|
|
m_rssIcon->setVisible(m_rssIconVisible);
|
2011-04-15 20:45:22 +02:00
|
|
|
m_bookmarkIcon->show();
|
2011-12-27 18:50:52 +01:00
|
|
|
m_goIcon->hide();
|
2012-03-16 15:55:34 +01:00
|
|
|
|
|
|
|
updateTextMargins();
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2011-12-11 14:12:40 +01:00
|
|
|
void LocationBar::showMostVisited()
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2012-04-22 17:09:43 +02:00
|
|
|
m_completer.complete(QString());
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void LocationBar::showSiteInfo()
|
|
|
|
{
|
2011-11-07 19:56:53 +01:00
|
|
|
QUrl url = p_QupZilla->weView()->url();
|
|
|
|
|
2012-09-04 12:42:45 +02:00
|
|
|
if (url.isEmpty() || url.scheme() == QLatin1String("qupzilla")) {
|
2011-11-07 19:56:53 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
SiteInfoWidget* info = new SiteInfoWidget(p_QupZilla);
|
|
|
|
info->showAt(this);
|
|
|
|
}
|
|
|
|
|
2011-03-03 14:25:02 +01:00
|
|
|
void LocationBar::rssIconClicked()
|
|
|
|
{
|
2011-10-30 17:20:22 +01:00
|
|
|
RSSWidget* rss = new RSSWidget(m_webView, this);
|
2011-03-03 14:25:02 +01:00
|
|
|
rss->showAt(this);
|
|
|
|
}
|
|
|
|
|
2012-09-14 22:09:58 +02:00
|
|
|
void LocationBar::bookmarkIconClicked()
|
|
|
|
{
|
|
|
|
BookmarksWidget* bWidget = new BookmarksWidget(p_QupZilla, m_webView, this);
|
|
|
|
bWidget->showAt(this);
|
|
|
|
}
|
|
|
|
|
2011-07-11 20:30:49 +02:00
|
|
|
void LocationBar::showRSSIcon(bool state)
|
|
|
|
{
|
|
|
|
m_rssIcon->setVisible(state);
|
2012-03-16 15:55:34 +01:00
|
|
|
|
|
|
|
updateTextMargins();
|
2011-07-11 20:30:49 +02: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
|
|
|
|
2012-09-06 10:53:37 +02:00
|
|
|
const QString &stringUrl = convertUrlToText(url);
|
2011-12-12 18:30:08 +01:00
|
|
|
|
2012-03-30 13:43:47 +02:00
|
|
|
if (stringUrl == text()) {
|
|
|
|
return;
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
2011-05-09 17:58:19 +02:00
|
|
|
|
2012-03-30 13:43:47 +02:00
|
|
|
setText(stringUrl);
|
|
|
|
|
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()
|
|
|
|
{
|
2012-01-21 20:27:45 +01:00
|
|
|
QIcon icon_ = m_webView->icon();
|
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-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
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()
|
|
|
|
{
|
2012-04-22 20:51:28 +02:00
|
|
|
m_siteIcon->setIcon(qIconProvider->emptyWebIcon());
|
2011-07-11 20:30:49 +02:00
|
|
|
}
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
void LocationBar::setPrivacy(bool state)
|
|
|
|
{
|
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();
|
|
|
|
urlEnter();
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocationBar::contextMenuEvent(QContextMenuEvent* event)
|
|
|
|
{
|
|
|
|
Q_UNUSED(event)
|
|
|
|
|
|
|
|
if (!m_pasteAndGoAction) {
|
|
|
|
m_pasteAndGoAction = new QAction(QIcon::fromTheme("edit-paste"), tr("Paste And &Go"), this);
|
|
|
|
m_pasteAndGoAction->setShortcut(QKeySequence("Ctrl+Shift+V"));
|
2012-01-22 18:40:49 +01:00
|
|
|
connect(m_pasteAndGoAction, SIGNAL(triggered()), this, SLOT(pasteAndGo()));
|
2012-01-21 19:26:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!m_clearAction) {
|
|
|
|
m_clearAction = new QAction(QIcon::fromTheme("edit-clear"), tr("Clear All"), this);
|
|
|
|
connect(m_clearAction, SIGNAL(triggered()), this, SLOT(clear()));
|
|
|
|
}
|
|
|
|
|
|
|
|
QMenu* tempMenu = createStandardContextMenu();
|
|
|
|
m_menu->clear();
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
foreach(QAction * act, tempMenu->actions()) {
|
|
|
|
act->setParent(m_menu);
|
|
|
|
tempMenu->removeAction(act);
|
|
|
|
m_menu->addAction(act);
|
|
|
|
|
|
|
|
switch (i) {
|
|
|
|
case 0:
|
|
|
|
act->setIcon(QIcon::fromTheme("edit-undo"));
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
act->setIcon(QIcon::fromTheme("edit-redo"));
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
act->setIcon(QIcon::fromTheme("edit-cut"));
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
act->setIcon(QIcon::fromTheme("edit-copy"));
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
act->setIcon(QIcon::fromTheme("edit-paste"));
|
|
|
|
m_menu->addAction(act);
|
|
|
|
m_menu->addAction(m_pasteAndGoAction);
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
act->setIcon(QIcon::fromTheme("edit-delete"));
|
|
|
|
m_menu->addAction(act);
|
|
|
|
m_menu->addAction(m_clearAction);
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
act->setIcon(QIcon::fromTheme("edit-select-all"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
2012-02-14 17:01:31 +01:00
|
|
|
tempMenu->deleteLater();
|
2012-01-21 19:26:47 +01:00
|
|
|
|
|
|
|
m_pasteAndGoAction->setEnabled(!QApplication::clipboard()->text().isEmpty());
|
|
|
|
|
|
|
|
//Prevent choosing first option with double rightclick
|
2012-03-23 17:29:12 +01:00
|
|
|
QPoint pos = event->globalPos();
|
2012-01-21 19:26:47 +01:00
|
|
|
QPoint p(pos.x(), pos.y() + 1);
|
|
|
|
m_menu->popup(p);
|
|
|
|
}
|
|
|
|
|
2012-09-06 10:53:37 +02:00
|
|
|
void LocationBar::focusInEvent(QFocusEvent* event)
|
|
|
|
{
|
|
|
|
const QString &stringUrl = convertUrlToText(m_webView->url());
|
|
|
|
|
|
|
|
// Text has been edited, let's show go button
|
|
|
|
if (stringUrl != text()) {
|
|
|
|
showGoButton();
|
|
|
|
}
|
|
|
|
|
|
|
|
LineEdit::focusInEvent(event);
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
emit loadUrl(dropUrl);
|
|
|
|
|
2012-03-01 18:32:53 +01:00
|
|
|
QFocusEvent event(QFocusEvent::FocusOut);
|
|
|
|
QLineEdit::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();
|
|
|
|
emit loadUrl(dropUrl);
|
|
|
|
|
2012-03-01 18:32:53 +01:00
|
|
|
QFocusEvent event(QFocusEvent::FocusOut);
|
|
|
|
QLineEdit::focusOutEvent(&event);
|
2011-03-02 16:57:41 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
QLineEdit::dropEvent(event);
|
|
|
|
}
|
|
|
|
|
2012-09-06 10:53:37 +02:00
|
|
|
void LocationBar::focusOutEvent(QFocusEvent* event)
|
2011-11-16 16:47:08 +01:00
|
|
|
{
|
2012-09-06 10:53:37 +02:00
|
|
|
QLineEdit::focusOutEvent(event);
|
|
|
|
|
|
|
|
if (event->reason() == Qt::PopupFocusReason
|
|
|
|
|| (!selectedText().isEmpty() && event->reason() != Qt::TabFocusReason)) {
|
2011-11-16 16:47:08 +01:00
|
|
|
return;
|
|
|
|
}
|
2011-12-17 14:26:34 +01:00
|
|
|
|
2011-11-16 16:47:08 +01:00
|
|
|
setCursorPosition(0);
|
|
|
|
hideGoButton();
|
2012-01-26 16:22:09 +01:00
|
|
|
|
|
|
|
if (text().trimmed().isEmpty()) {
|
|
|
|
clear();
|
|
|
|
}
|
2011-11-16 16:47:08 +01:00
|
|
|
}
|
|
|
|
|
2011-03-17 17:03:04 +01:00
|
|
|
void LocationBar::mouseDoubleClickEvent(QMouseEvent* event)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2012-08-10 21:16:43 +02:00
|
|
|
if (event->button() == Qt::LeftButton && qzSettings->selectAllOnDoubleClick) {
|
2011-03-02 16:57:41 +01:00
|
|
|
selectAll();
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
else {
|
2011-03-02 16:57:41 +01:00
|
|
|
QLineEdit::mouseDoubleClickEvent(event);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2011-11-16 16:47:08 +01:00
|
|
|
void LocationBar::mousePressEvent(QMouseEvent* event)
|
|
|
|
{
|
2012-08-10 21:16:43 +02:00
|
|
|
if (cursorPosition() == 0 && qzSettings->selectAllOnClick) {
|
2011-11-16 16:47:08 +01:00
|
|
|
selectAll();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
LineEdit::mousePressEvent(event);
|
|
|
|
}
|
|
|
|
|
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:
|
|
|
|
m_completer.complete(text());
|
|
|
|
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:
|
2012-09-04 12:42:45 +02:00
|
|
|
setText(text().append(QLatin1String(".com")));
|
2011-12-23 11:11:14 +01:00
|
|
|
urlEnter();
|
2012-03-03 21:35:02 +01:00
|
|
|
m_holdingAlt = false;
|
2012-01-18 16:52:30 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Qt::AltModifier:
|
2012-09-06 12:02:03 +02:00
|
|
|
p_QupZilla->tabWidget()->addView(createUrl());
|
2012-03-03 21:35:02 +01:00
|
|
|
m_holdingAlt = false;
|
2012-01-18 16:52:30 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2011-12-23 11:11:14 +01:00
|
|
|
urlEnter();
|
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
|
|
|
}
|
|
|
|
|
2012-01-18 16:52:30 +01:00
|
|
|
void LocationBar::keyReleaseEvent(QKeyEvent* event)
|
|
|
|
{
|
|
|
|
QString localDomain = tr(".co.uk", "Append domain name on ALT + Enter = Should be different for every country");
|
|
|
|
|
2012-08-10 21:16:43 +02:00
|
|
|
if (event->key() == Qt::Key_Alt && m_holdingAlt && qzSettings->addCountryWithAlt &&
|
2012-09-04 12:42:45 +02:00
|
|
|
!text().endsWith(localDomain) && !text().endsWith(QLatin1Char('/'))) {
|
2012-03-03 21:35:02 +01:00
|
|
|
LineEdit::setText(text().append(localDomain));
|
2012-01-18 16:52:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
LineEdit::keyReleaseEvent(event);
|
|
|
|
}
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
LocationBar::~LocationBar()
|
|
|
|
{
|
2011-04-15 20:45:22 +02:00
|
|
|
delete m_bookmarkIcon;
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
2012-08-24 20:53:53 +02:00
|
|
|
|
|
|
|
void LocationBar::onLoadProgress(int progress)
|
|
|
|
{
|
|
|
|
if (qzSettings->showLoadingProgress) {
|
|
|
|
m_loadFinished = false;
|
|
|
|
m_loadProgress = progress;
|
|
|
|
repaint();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocationBar::onLoadFinished()
|
|
|
|
{
|
|
|
|
if (qzSettings->showLoadingProgress) {
|
|
|
|
m_loadFinished = false;
|
|
|
|
QTimer::singleShot(700, this, SLOT(hideProgress()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocationBar::hideProgress()
|
|
|
|
{
|
|
|
|
if (qzSettings->showLoadingProgress) {
|
|
|
|
m_loadFinished = true;
|
|
|
|
repaint();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocationBar::paintEvent(QPaintEvent* event)
|
|
|
|
{
|
|
|
|
if (hasFocus() || !qzSettings->showLoadingProgress || m_loadFinished) {
|
|
|
|
LineEdit::paintEvent(event);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QStyleOptionFrameV3 option;
|
|
|
|
initStyleOption(&option);
|
|
|
|
|
|
|
|
QPainter p(this);
|
|
|
|
p.setRenderHint(QPainter::Antialiasing, true);
|
|
|
|
p.setRenderHint(QPainter::TextAntialiasing, true);
|
|
|
|
|
|
|
|
style()->drawPrimitive(QStyle::PE_PanelLineEdit, &option, &p, this);
|
|
|
|
|
|
|
|
QRect contentsRect = style()->subElementRect(QStyle::SE_LineEditContents, &option, this);
|
|
|
|
int lm, tm, rm, bm;
|
|
|
|
getTextMargins(&lm, &tm, &rm, &bm);
|
|
|
|
contentsRect.adjust(lm, tm, -rm, -bm);
|
|
|
|
QFontMetrics fm = fontMetrics();
|
|
|
|
const int x = contentsRect.x() + 3;
|
|
|
|
const int y = contentsRect.y() + (contentsRect.height() - fm.height() + 1) / 2;
|
|
|
|
const int width = contentsRect.width() - 6;
|
|
|
|
const int height = fm.height();
|
|
|
|
QRect textRect(x, y, width, height);
|
|
|
|
|
|
|
|
QColor bg = palette().color(QPalette::Base);
|
|
|
|
if (!bg.isValid() || bg.alpha() == 0) {
|
|
|
|
bg = p_QupZilla->palette().color(QPalette::Base);
|
|
|
|
}
|
|
|
|
bg = bg.darker(110);
|
|
|
|
p.setBrush(QBrush(bg));
|
|
|
|
|
|
|
|
QPen oldPen = p.pen();
|
|
|
|
QPen outlinePen(bg.darker(110), 0.8);
|
|
|
|
p.setPen(outlinePen);
|
|
|
|
|
|
|
|
QRect bar = textRect.adjusted(-3, 0, 6 - (textRect.width() * (100.0 - m_loadProgress) / 100), 0);
|
|
|
|
const int roundness = bar.height() / 4.0;
|
|
|
|
p.drawRoundedRect(bar, roundness, roundness);
|
|
|
|
|
|
|
|
p.setPen(oldPen);
|
|
|
|
// Qt::Alignment va = QStyle::visualAlignment(QApplication::layoutDirection(), QFlag(alignment()));
|
|
|
|
p.drawText(textRect, text());
|
|
|
|
}
|