2012-01-21 20:24:36 +01:00
|
|
|
/* ============================================================
|
2017-08-25 17:11:29 +02:00
|
|
|
* Falkon - Qt web browser
|
2018-01-28 12:24:19 +01:00
|
|
|
* Copyright (C) 2010-2018 David Rosca <nowrep@gmail.com>
|
2012-01-21 20:24:36 +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/>.
|
|
|
|
* ============================================================ */
|
|
|
|
#include "popuplocationbar.h"
|
|
|
|
#include "popupwebview.h"
|
|
|
|
#include "toolbutton.h"
|
2013-01-22 19:04:22 +01:00
|
|
|
#include "qztools.h"
|
2012-03-13 17:51:06 +01:00
|
|
|
#include "iconprovider.h"
|
2014-02-09 12:22:49 +01:00
|
|
|
#include "bookmarksicon.h"
|
2013-02-10 14:09:28 +01:00
|
|
|
#include "autofillicon.h"
|
|
|
|
#include "webpage.h"
|
2012-01-21 20:24:36 +01:00
|
|
|
|
2017-08-25 17:11:29 +02:00
|
|
|
class FALKON_EXPORT PopupSiteIcon : public QWidget
|
2012-01-21 20:24:36 +01:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit PopupSiteIcon(QWidget* parent = 0) : QWidget(parent) { }
|
|
|
|
void setIcon(const QIcon &icon) {
|
2015-10-24 12:43:15 +02:00
|
|
|
m_icon = QIcon(icon.pixmap(16));
|
2014-03-25 17:06:50 +01:00
|
|
|
update();
|
2012-01-21 20:24:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
QIcon m_icon;
|
|
|
|
|
|
|
|
void paintEvent(QPaintEvent*) {
|
|
|
|
QPainter p(this);
|
|
|
|
m_icon.paint(&p, rect());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
PopupLocationBar::PopupLocationBar(QWidget* parent)
|
|
|
|
: LineEdit(parent)
|
|
|
|
, m_view(0)
|
|
|
|
{
|
|
|
|
m_siteIcon = new PopupSiteIcon(this);
|
2014-03-07 18:03:42 +01:00
|
|
|
m_siteIcon->setIcon(IconProvider::emptyWebIcon());
|
2012-08-13 15:41:08 +02:00
|
|
|
m_siteIcon->setFixedSize(26, 26);
|
2012-01-21 20:24:36 +01:00
|
|
|
|
2014-02-09 12:22:49 +01:00
|
|
|
m_bookmarkIcon = new BookmarksIcon(this);
|
2013-02-10 14:09:28 +01:00
|
|
|
m_autofillIcon = new AutoFillIcon(this);
|
|
|
|
|
|
|
|
QWidget* rightSpacer = new QWidget(this);
|
|
|
|
rightSpacer->setFixedWidth(3);
|
2012-06-27 18:29:00 +02:00
|
|
|
|
2012-01-21 20:24:36 +01:00
|
|
|
addWidget(m_siteIcon, LineEdit::LeftSide);
|
2013-02-10 14:09:28 +01:00
|
|
|
addWidget(m_autofillIcon, LineEdit::RightSide);
|
|
|
|
addWidget(m_bookmarkIcon, LineEdit::RightSide);
|
|
|
|
addWidget(rightSpacer, LineEdit::RightSide);
|
2016-02-14 10:54:19 +01:00
|
|
|
setLeftMargin(24);
|
2012-01-21 20:24:36 +01:00
|
|
|
|
|
|
|
setFixedHeight(26);
|
|
|
|
setReadOnly(true);
|
2013-02-10 14:09:28 +01:00
|
|
|
|
|
|
|
// Hide icons by default
|
|
|
|
m_autofillIcon->hide();
|
2012-01-21 20:24:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void PopupLocationBar::setView(PopupWebView* view)
|
|
|
|
{
|
|
|
|
m_view = view;
|
2013-02-10 14:09:28 +01:00
|
|
|
|
|
|
|
m_bookmarkIcon->setWebView(m_view);
|
|
|
|
m_autofillIcon->setWebView(m_view);
|
2012-01-21 20:24:36 +01:00
|
|
|
}
|
|
|
|
|
2012-06-27 18:29:00 +02:00
|
|
|
void PopupLocationBar::startLoading()
|
|
|
|
{
|
2013-02-10 14:09:28 +01:00
|
|
|
m_autofillIcon->hide();
|
|
|
|
|
2012-06-27 18:29:00 +02:00
|
|
|
updateTextMargins();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupLocationBar::stopLoading()
|
|
|
|
{
|
2013-02-10 14:09:28 +01:00
|
|
|
m_bookmarkIcon->checkBookmark(m_view->url());
|
|
|
|
|
|
|
|
WebPage* page = qobject_cast<WebPage*>(m_view->page());
|
|
|
|
|
2018-01-28 12:24:19 +01:00
|
|
|
if (page && !page->autoFillUsernames().isEmpty()) {
|
|
|
|
m_autofillIcon->setUsernames(page->autoFillUsernames());
|
2013-02-10 14:09:28 +01:00
|
|
|
m_autofillIcon->show();
|
|
|
|
}
|
|
|
|
|
2012-06-27 18:29:00 +02:00
|
|
|
updateTextMargins();
|
|
|
|
}
|
|
|
|
|
2012-01-21 20:24:36 +01:00
|
|
|
void PopupLocationBar::showUrl(const QUrl &url)
|
|
|
|
{
|
2013-01-22 19:04:22 +01:00
|
|
|
setText(QzTools::urlEncodeQueryString(url));
|
2012-01-21 20:24:36 +01:00
|
|
|
setCursorPosition(0);
|
|
|
|
}
|
|
|
|
|
2013-02-10 14:09:28 +01:00
|
|
|
void PopupLocationBar::showSiteIcon()
|
2012-01-21 20:24:36 +01:00
|
|
|
{
|
2012-06-27 18:29:00 +02:00
|
|
|
m_siteIcon->setIcon(m_view->icon());
|
2012-01-21 20:24:36 +01:00
|
|
|
}
|