2011-03-03 18:29:20 +01:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
2014-01-08 10:39:41 +01:00
|
|
|
* Copyright (C) 2010-2014 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"
|
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"
|
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"
|
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"
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-12-20 14:45:35 +01:00
|
|
|
#include <QMimeData>
|
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>
|
2013-02-10 12:28:53 +01:00
|
|
|
#include <QAction>
|
|
|
|
#include <QMenu>
|
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_pasteAndGoAction(0)
|
|
|
|
, m_clearAction(0)
|
2013-06-06 11:54:22 +02:00
|
|
|
, m_rssIconVisible(false)
|
2012-01-18 16:52:30 +01:00
|
|
|
, m_holdingAlt(false)
|
2012-08-24 20:53:53 +02:00
|
|
|
, m_loadProgress(0)
|
2012-09-19 10:08:30 +02:00
|
|
|
, m_progressVisible(false)
|
2013-02-22 15:20:28 +01:00
|
|
|
, m_forcePaintEvent(false)
|
2013-05-11 00:17:38 +02:00
|
|
|
, m_inlineCompletionVisible(false)
|
2013-02-22 15:20:28 +01:00
|
|
|
, m_popupClosed(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-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);
|
|
|
|
m_rssIcon = new RssIcon(this);
|
2013-02-10 12:28:53 +01:00
|
|
|
m_siteIcon = new SiteIcon(p_QupZilla, 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
|
|
|
|
2013-02-08 18:44:26 +01: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.
|
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);
|
2011-03-02 16:57:41 +01:00
|
|
|
addWidget(m_rssIcon, 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
|
|
|
|
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()));
|
2013-02-22 15:20:28 +01:00
|
|
|
connect(&m_completer, SIGNAL(popupClosed()), this, SLOT(completionPopupClosed()));
|
2011-03-02 16:57:41 +01:00
|
|
|
|
|
|
|
connect(this, SIGNAL(textEdited(QString)), this, SLOT(textEdit()));
|
2011-12-27 18:50:52 +01:00
|
|
|
connect(m_goIcon, SIGNAL(clicked(QPoint)), this, SLOT(urlEnter()));
|
2013-02-11 13:33:02 +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()));
|
2013-03-06 09:05:41 +01:00
|
|
|
connect(mApp, SIGNAL(message(Qz::AppMessageType,bool)), SLOT(onMessage(Qz::AppMessageType,bool)));
|
2012-09-19 10:08:30 +02:00
|
|
|
|
|
|
|
loadSettings();
|
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();
|
2013-02-08 18:44:26 +01:00
|
|
|
|
|
|
|
// Hide icons by default
|
2013-06-05 00:02:43 +02:00
|
|
|
hideGoButton();
|
2013-02-08 18:44:26 +01:00
|
|
|
m_rssIcon->hide();
|
|
|
|
m_autofillIcon->hide();
|
2011-11-06 12:05:16 +01:00
|
|
|
}
|
|
|
|
|
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_rssIcon->setWebView(m_webView);
|
|
|
|
m_siteIcon->setWebView(m_webView);
|
|
|
|
m_autofillIcon->setWebView(m_webView);
|
|
|
|
|
2012-09-19 10:08:30 +02:00
|
|
|
connect(m_webView, SIGNAL(loadStarted()), SLOT(onLoadStarted()));
|
2012-08-24 20:53:53 +02:00
|
|
|
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);
|
2013-02-22 15:20:28 +01:00
|
|
|
m_forcePaintEvent = true;
|
2011-12-17 14:26:34 +01:00
|
|
|
setCursorPosition(0);
|
|
|
|
}
|
|
|
|
|
2011-11-06 12:05:16 +01:00
|
|
|
void LocationBar::updatePlaceHolderText()
|
|
|
|
{
|
2012-09-27 11:59:09 +02:00
|
|
|
QString engineName = qzSettings->searchWithDefaultEngine ?
|
|
|
|
mApp->searchEnginesManager()->defaultEngine().name :
|
|
|
|
mApp->searchEnginesManager()->activeEngine().name;
|
|
|
|
setPlaceholderText(tr("Enter URL address or search on %1").arg(engineName));
|
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
|
|
|
{
|
2013-05-11 00:17:38 +02:00
|
|
|
m_inlineCompletionVisible = false;
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2013-02-22 15:20:28 +01:00
|
|
|
void LocationBar::completionPopupClosed()
|
|
|
|
{
|
2013-05-11 00:17:38 +02:00
|
|
|
m_inlineCompletionVisible = false;
|
2013-02-22 15:20:28 +01:00
|
|
|
m_popupClosed = true;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2013-05-10 22:33:36 +02:00
|
|
|
// 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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-08 10:39:41 +01:00
|
|
|
if (isInlineCompletionVisible()) {
|
2013-05-10 22:33:36 +02:00
|
|
|
urlToLoad = WebView::guessUrlFromString(text() + m_completer.domainCompletion());
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
{
|
2013-01-22 19:04:22 +01:00
|
|
|
QString stringUrl = QzTools::urlEncodeQueryString(url);
|
2012-09-06 10:53:37 +02:00
|
|
|
|
|
|
|
if (stringUrl == QLatin1String("qupzilla:speeddial") || stringUrl == QLatin1String("about:blank")) {
|
2013-02-22 15:20:28 +01:00
|
|
|
stringUrl.clear();
|
2012-09-06 10:53:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return stringUrl;
|
|
|
|
}
|
|
|
|
|
2014-01-08 10:39:41 +01:00
|
|
|
bool LocationBar::isInlineCompletionVisible() const
|
|
|
|
{
|
|
|
|
return m_inlineCompletionVisible && !m_completer.domainCompletion().isEmpty();
|
|
|
|
}
|
|
|
|
|
2012-01-18 16:52:30 +01:00
|
|
|
void LocationBar::urlEnter()
|
|
|
|
{
|
2013-12-30 13:43:48 +01:00
|
|
|
const QUrl url = createUrl();
|
|
|
|
const QString urlString = convertUrlToText(url);
|
2013-05-10 22:33:36 +02:00
|
|
|
|
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
|
|
|
|
2013-05-10 22:33:36 +02:00
|
|
|
if (urlString != text()) {
|
|
|
|
setText(convertUrlToText(url));
|
|
|
|
}
|
|
|
|
|
|
|
|
emit loadUrl(url);
|
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());
|
2013-05-11 00:17:38 +02:00
|
|
|
m_inlineCompletionVisible = true;
|
2012-04-22 17:09:43 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
m_completer.closePopup();
|
|
|
|
}
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
showGoButton();
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocationBar::showGoButton()
|
|
|
|
{
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
m_rssIcon->setVisible(m_rssIconVisible);
|
2011-04-15 20:45:22 +02:00
|
|
|
m_bookmarkIcon->show();
|
2013-06-05 00:02:43 +02:00
|
|
|
|
|
|
|
if (!qzSettings->alwaysShowGoIcon) {
|
|
|
|
m_goIcon->hide();
|
|
|
|
}
|
2012-03-16 15:55:34 +01:00
|
|
|
|
|
|
|
updateTextMargins();
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2013-12-30 13:43:48 +01: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();
|
2012-10-11 19:57:12 +02:00
|
|
|
QMenu menu(this);
|
2012-01-21 19:26:47 +01:00
|
|
|
|
|
|
|
int i = 0;
|
2013-03-06 09:05:41 +01:00
|
|
|
foreach (QAction* act, tempMenu->actions()) {
|
2012-10-11 19:57:12 +02:00
|
|
|
menu.addAction(act);
|
2012-01-21 19:26:47 +01:00
|
|
|
|
|
|
|
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"));
|
2012-10-11 19:57:12 +02:00
|
|
|
menu.addAction(act);
|
|
|
|
menu.addAction(m_pasteAndGoAction);
|
2012-01-21 19:26:47 +01:00
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
act->setIcon(QIcon::fromTheme("edit-delete"));
|
2012-10-11 19:57:12 +02:00
|
|
|
menu.addAction(act);
|
|
|
|
menu.addAction(m_clearAction);
|
2012-01-21 19:26:47 +01:00
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
act->setIcon(QIcon::fromTheme("edit-select-all"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_pasteAndGoAction->setEnabled(!QApplication::clipboard()->text().isEmpty());
|
|
|
|
|
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();
|
2012-01-21 19:26:47 +01:00
|
|
|
QPoint p(pos.x(), pos.y() + 1);
|
2012-10-11 19:57:12 +02:00
|
|
|
menu.exec(p);
|
|
|
|
|
|
|
|
tempMenu->deleteLater();
|
2012-01-21 19:26:47 +01:00
|
|
|
}
|
|
|
|
|
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()) {
|
|
|
|
showGoButton();
|
|
|
|
}
|
2012-09-06 10:53:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
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();
|
|
|
|
emit loadUrl(dropUrl);
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-09-06 10:53:37 +02:00
|
|
|
void LocationBar::focusOutEvent(QFocusEvent* event)
|
2011-11-16 16:47:08 +01:00
|
|
|
{
|
2013-03-15 11:46:07 +01:00
|
|
|
LineEdit::focusOutEvent(event);
|
2012-09-06 10:53:37 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
2013-02-22 15:20:28 +01:00
|
|
|
m_popupClosed = false;
|
|
|
|
m_forcePaintEvent = true;
|
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-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;
|
|
|
|
|
2013-12-23 19:21:47 +01:00
|
|
|
case Qt::Key_A:
|
2013-12-23 20:32:42 +01:00
|
|
|
if (event->modifiers() == Qt::ControlModifier && m_inlineCompletionVisible) {
|
|
|
|
m_inlineCompletionVisible = false;
|
2013-12-23 19:21:47 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2012-04-22 17:09:43 +02:00
|
|
|
case Qt::Key_Down:
|
|
|
|
m_completer.complete(text());
|
|
|
|
break;
|
|
|
|
|
2013-05-11 00:17:38 +02:00
|
|
|
case Qt::Key_End:
|
2013-08-06 23:32:06 +02:00
|
|
|
case Qt::Key_Right: {
|
2013-12-30 13:43:48 +01:00
|
|
|
const QString completionText = m_completer.domainCompletion();
|
2013-08-06 23:32:06 +02:00
|
|
|
if (m_inlineCompletionVisible && !completionText.isEmpty()) {
|
2013-05-11 00:17:38 +02:00
|
|
|
m_inlineCompletionVisible = false;
|
|
|
|
|
2013-08-06 23:32:06 +02:00
|
|
|
setText(text() + completionText);
|
2013-05-11 00:17:38 +02:00
|
|
|
setCursorPosition(text().size());
|
|
|
|
m_completer.closePopup();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_completer.isPopupVisible()) {
|
|
|
|
m_completer.closePopup();
|
|
|
|
}
|
|
|
|
break;
|
2013-08-06 23:32:06 +02:00
|
|
|
}
|
2013-05-11 00:17:38 +02:00
|
|
|
|
|
|
|
case Qt::Key_Left:
|
|
|
|
if (m_completer.isPopupVisible()) {
|
|
|
|
m_completer.closePopup();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2013-06-09 12:27:25 +02:00
|
|
|
case Qt::Key_Delete:
|
|
|
|
if (m_inlineCompletionVisible) {
|
|
|
|
m_inlineCompletionVisible = false;
|
|
|
|
|
|
|
|
update();
|
|
|
|
event->accept();
|
|
|
|
}
|
|
|
|
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:
|
2013-05-10 22:34:51 +02:00
|
|
|
m_completer.closePopup();
|
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);
|
|
|
|
}
|
|
|
|
|
2012-09-19 10:08:30 +02:00
|
|
|
void LocationBar::onLoadStarted()
|
|
|
|
{
|
|
|
|
m_progressVisible = true;
|
2013-02-08 18:44:26 +01:00
|
|
|
m_autofillIcon->hide();
|
2012-09-19 10:08:30 +02:00
|
|
|
}
|
|
|
|
|
2012-08-24 20:53:53 +02:00
|
|
|
void LocationBar::onLoadProgress(int progress)
|
|
|
|
{
|
|
|
|
if (qzSettings->showLoadingProgress) {
|
|
|
|
m_loadProgress = progress;
|
2012-09-19 10:08:30 +02:00
|
|
|
update();
|
2012-08-24 20:53:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocationBar::onLoadFinished()
|
|
|
|
{
|
|
|
|
if (qzSettings->showLoadingProgress) {
|
|
|
|
QTimer::singleShot(700, this, SLOT(hideProgress()));
|
|
|
|
}
|
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();
|
|
|
|
}
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocationBar::onMessage(Qz::AppMessageType msg, bool state)
|
|
|
|
{
|
|
|
|
Q_UNUSED(state)
|
|
|
|
if (!qzSettings->showLoadingProgress) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (msg == Qz::AM_ReloadSettings) {
|
|
|
|
loadSettings();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-24 20:53:53 +02:00
|
|
|
void LocationBar::hideProgress()
|
|
|
|
{
|
2012-09-20 10:04:18 +02:00
|
|
|
if (qzSettings->showLoadingProgress && m_loadProgress == 100) {
|
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)
|
|
|
|
{
|
2013-05-10 22:33:36 +02:00
|
|
|
QStyleOptionFrameV3 option;
|
|
|
|
initStyleOption(&option);
|
|
|
|
|
|
|
|
int lm, tm, rm, bm;
|
|
|
|
getTextMargins(&lm, &tm, &rm, &bm);
|
|
|
|
|
|
|
|
QRect contentsRect = style()->subElementRect(QStyle::SE_LineEditContents, &option, this);
|
|
|
|
contentsRect.adjust(lm, tm, -rm, -bm);
|
|
|
|
|
2013-12-30 13:43:48 +01:00
|
|
|
const QFontMetrics fm = fontMetrics();
|
2013-05-11 13:22:16 +02:00
|
|
|
const int x = contentsRect.x() + 4;
|
2013-05-10 22:33:36 +02:00
|
|
|
const int y = contentsRect.y() + (contentsRect.height() - fm.height() + 1) / 2;
|
|
|
|
const int width = contentsRect.width() - 6;
|
|
|
|
const int height = fm.height();
|
|
|
|
const QRect textRect(x, y, width, height);
|
|
|
|
|
|
|
|
QTextOption opt;
|
|
|
|
opt.setWrapMode(QTextOption::NoWrap);
|
|
|
|
|
2013-05-11 13:22:16 +02:00
|
|
|
QPainter p(this);
|
|
|
|
p.setRenderHint(QPainter::Antialiasing, true);
|
|
|
|
p.setRenderHint(QPainter::TextAntialiasing, true);
|
|
|
|
|
2013-05-11 00:17:38 +02:00
|
|
|
if (hasFocus() && m_inlineCompletionVisible) {
|
2013-05-10 22:33:36 +02:00
|
|
|
// Draw inline domain completion if available
|
2013-12-30 13:43:48 +01:00
|
|
|
const QString completionText = m_completer.domainCompletion();
|
2013-05-10 22:33:36 +02:00
|
|
|
|
|
|
|
if (!completionText.isEmpty()) {
|
|
|
|
QRect completionRect = textRect;
|
|
|
|
completionRect.setX(completionRect.x() + fm.width(text()) + 1);
|
|
|
|
completionRect.setWidth(fm.width(completionText) + 1);
|
|
|
|
|
2013-05-11 13:22:16 +02:00
|
|
|
style()->drawPrimitive(QStyle::PE_PanelLineEdit, &option, &p, this);
|
|
|
|
// Text part
|
|
|
|
p.drawText(textRect, text(), opt);
|
|
|
|
// Completion part
|
2013-05-10 22:33:36 +02:00
|
|
|
p.fillRect(completionRect, palette().color(QPalette::Highlight));
|
|
|
|
p.setPen(palette().color(QPalette::HighlightedText));
|
|
|
|
p.drawText(completionRect, completionText, opt);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-11 13:22:16 +02:00
|
|
|
if (m_completer.isPopupVisible() && !m_completer.showingMostVisited()) {
|
2013-02-11 13:33:02 +01:00
|
|
|
// We need to draw cursor when popup is visible
|
|
|
|
// But don't paint it if we are just showing most visited sites
|
2013-05-11 13:22:16 +02:00
|
|
|
const int cursorWidth = style()->pixelMetric(QStyle::PM_TextCursorWidth, &option, this);
|
|
|
|
const int cursorHeight = fm.height();
|
2013-01-28 19:38:03 +01:00
|
|
|
|
2013-02-22 00:25:13 +01:00
|
|
|
QString textPart = text().left(cursorPosition());
|
2013-05-10 22:33:36 +02:00
|
|
|
int cursorXpos = x + fontMetrics().width(textPart);
|
2013-01-28 19:38:03 +01:00
|
|
|
|
2013-05-11 13:22:16 +02:00
|
|
|
QRect cursor = cursorRect();
|
|
|
|
cursor.setX(cursorXpos + 1);
|
|
|
|
cursor.setWidth(cursorWidth);
|
|
|
|
cursor.setHeight(cursorHeight);
|
2013-05-10 22:33:36 +02:00
|
|
|
|
2013-05-11 13:22:16 +02:00
|
|
|
style()->drawPrimitive(QStyle::PE_PanelLineEdit, &option, &p, this);
|
2013-12-23 19:21:47 +01:00
|
|
|
|
|
|
|
QRect actualTextRect = textRect;
|
|
|
|
actualTextRect.setWidth(fontMetrics().width(text()) + 1);
|
|
|
|
|
|
|
|
// When popup is visible, Ctrl + A (Select All) is the only way to select text
|
|
|
|
if (selectedText() == text()) {
|
|
|
|
p.fillRect(actualTextRect, palette().color(QPalette::Highlight));
|
|
|
|
p.setPen(palette().color(QPalette::HighlightedText));
|
|
|
|
}
|
|
|
|
|
|
|
|
p.drawText(actualTextRect, text(), opt);
|
2013-05-11 13:22:16 +02:00
|
|
|
|
|
|
|
if (textRect.contains(cursor.center().x(), cursor.center().y())) {
|
|
|
|
p.fillRect(cursor, option.palette.text().color());
|
|
|
|
}
|
2013-01-28 19:38:03 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-02-22 15:20:28 +01:00
|
|
|
if (hasFocus() || text().isEmpty() || m_forcePaintEvent) {
|
2012-08-24 20:53:53 +02:00
|
|
|
LineEdit::paintEvent(event);
|
2013-02-22 15:20:28 +01:00
|
|
|
if (m_forcePaintEvent) {
|
|
|
|
m_forcePaintEvent = false;
|
2012-10-07 13:22:45 +02:00
|
|
|
update();
|
|
|
|
}
|
2012-08-24 20:53:53 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
style()->drawPrimitive(QStyle::PE_PanelLineEdit, &option, &p, this);
|
|
|
|
|
|
|
|
QPen oldPen = p.pen();
|
|
|
|
|
2012-09-19 10:08:30 +02:00
|
|
|
if (qzSettings->showLoadingProgress && m_progressVisible) {
|
|
|
|
QColor bg = m_progressColor;
|
|
|
|
if (!bg.isValid() || bg.alpha() == 0) {
|
2012-09-19 20:24:41 +02:00
|
|
|
bg = Colors::mid(palette().color(QPalette::Base),
|
|
|
|
palette().color(QPalette::Text),
|
2012-09-20 10:04:18 +02:00
|
|
|
m_progressStyle > 0 ? 4 : 8, 1);
|
2012-09-19 10:08:30 +02:00
|
|
|
}
|
|
|
|
p.setBrush(QBrush(bg));
|
|
|
|
|
|
|
|
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);
|
|
|
|
QRect bar(contentsRect.x(), contentsRect.top() + 1,
|
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;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-08-24 20:53:53 +02:00
|
|
|
|
|
|
|
p.setPen(oldPen);
|
2012-09-19 20:24:41 +02:00
|
|
|
|
|
|
|
const QString hostName = m_webView->url().host();
|
|
|
|
QString currentText = text();
|
|
|
|
QRect currentRect = textRect;
|
|
|
|
if (!hostName.isEmpty()) {
|
|
|
|
const int hostPos = currentText.indexOf(hostName);
|
|
|
|
if (hostPos > 0) {
|
|
|
|
QPen lightPen = oldPen;
|
|
|
|
QColor lightColor = Colors::mid(palette().color(QPalette::Base),
|
|
|
|
palette().color(QPalette::Text),
|
|
|
|
1, 1);
|
|
|
|
lightPen.setColor(lightColor);
|
|
|
|
|
|
|
|
p.setPen(lightPen);
|
|
|
|
currentText = text().mid(0, hostPos);
|
|
|
|
currentRect.setWidth(fm.width(currentText));
|
|
|
|
p.drawText(currentRect, currentText, opt);
|
|
|
|
|
|
|
|
p.setPen(oldPen);
|
|
|
|
currentRect.setX(currentRect.x() + currentRect.width());
|
|
|
|
const int hostWidth = fm.width(hostName);
|
|
|
|
currentRect.setWidth(hostWidth);
|
|
|
|
p.drawText(currentRect, hostName, opt);
|
|
|
|
|
|
|
|
p.setFont(font());
|
|
|
|
currentText = text().mid(hostPos + hostName.length());
|
|
|
|
currentRect.setX(currentRect.x() + hostWidth);
|
|
|
|
currentRect.setWidth(textRect.width() - currentRect.x() + textRect.x());
|
|
|
|
p.setPen(lightPen);
|
2013-07-05 00:21:07 +02:00
|
|
|
|
|
|
|
if (currentText.isRightToLeft()) {
|
|
|
|
// Insert unicode control characters: prepend LRE then append LRM+PDF
|
|
|
|
currentText.prepend(QChar(0x202A)).append(QChar(0x200E)).append(QChar(0x202C));
|
|
|
|
}
|
2012-09-19 20:24:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
p.drawText(currentRect, currentText, opt);
|
2012-08-24 20:53:53 +02:00
|
|
|
}
|
2013-02-08 18:44:26 +01:00
|
|
|
|
|
|
|
LocationBar::~LocationBar()
|
|
|
|
{
|
|
|
|
}
|