Falkon Develop
Cross-platform Qt-based web browser
popuplocationbar.cpp
Go to the documentation of this file.
1/* ============================================================
2* Falkon - Qt web browser
3* Copyright (C) 2010-2018 David Rosca <nowrep@gmail.com>
4*
5* This program is free software: you can redistribute it and/or modify
6* it under the terms of the GNU General Public License as published by
7* the Free Software Foundation, either version 3 of the License, or
8* (at your option) any later version.
9*
10* This program is distributed in the hope that it will be useful,
11* but WITHOUT ANY WARRANTY; without even the implied warranty of
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13* GNU General Public License for more details.
14*
15* You should have received a copy of the GNU General Public License
16* along with this program. If not, see <http://www.gnu.org/licenses/>.
17* ============================================================ */
18#include "popuplocationbar.h"
19#include "popupwebview.h"
20#include "toolbutton.h"
21#include "qztools.h"
22#include "iconprovider.h"
23#include "bookmarksicon.h"
24#include "autofillicon.h"
25#include "webpage.h"
26
27class FALKON_EXPORT PopupSiteIcon : public QWidget
28{
29public:
30 explicit PopupSiteIcon(QWidget* parent = nullptr) : QWidget(parent) { }
31 void setIcon(const QIcon &icon) {
32 m_icon = QIcon(icon.pixmap(16));
33 update();
34 }
35
36private:
37 QIcon m_icon;
38
39 void paintEvent(QPaintEvent*) override {
40 QPainter p(this);
41 m_icon.paint(&p, rect());
42 }
43};
44
46 : LineEdit(parent)
47 , m_view(nullptr)
48{
49 m_siteIcon = new PopupSiteIcon(this);
51 m_siteIcon->setFixedSize(26, 26);
52
53 m_bookmarkIcon = new BookmarksIcon(this);
54 m_autofillIcon = new AutoFillIcon(this);
55
56 auto* rightSpacer = new QWidget(this);
57 rightSpacer->setFixedWidth(3);
58
59 addWidget(m_siteIcon, LineEdit::LeftSide);
60 addWidget(m_autofillIcon, LineEdit::RightSide);
61 addWidget(m_bookmarkIcon, LineEdit::RightSide);
62 addWidget(rightSpacer, LineEdit::RightSide);
63 setLeftMargin(24);
64
65 setFixedHeight(26);
66 setReadOnly(true);
67
68 // Hide icons by default
69 m_autofillIcon->hide();
70}
71
73{
74 m_view = view;
75
76 m_bookmarkIcon->setWebView(m_view);
77 m_autofillIcon->setWebView(m_view);
78}
79
81{
82 m_autofillIcon->hide();
83
85}
86
88{
89 m_bookmarkIcon->checkBookmark(m_view->url());
90
91 auto* page = qobject_cast<WebPage*>(m_view->page());
92
93 if (page && !page->autoFillUsernames().isEmpty()) {
94 m_autofillIcon->setUsernames(page->autoFillUsernames());
95 m_autofillIcon->show();
96 }
97
99}
100
101void PopupLocationBar::showUrl(const QUrl &url)
102{
103 setText(QzTools::urlEncodeQueryString(url));
104 setCursorPosition(0);
105}
106
108{
109 QIcon icon = IconProvider::emptyWebIcon();
110 if (property("secured").toBool()) {
111 icon = QIcon::fromTheme(QSL("document-encrypted"), icon);
112 }
113 m_siteIcon->setIcon(QIcon(icon.pixmap(16)));
114}
115
117{
118 setProperty("secured", QVariant(state));
119}
void setWebView(WebView *view)
void setUsernames(const QStringList &usernames)
void checkBookmark(const QUrl &url, bool forceCheck=false)
void setWebView(WebView *view)
static QIcon emptyWebIcon()
void addWidget(QWidget *widget, WidgetPosition position)
Definition: lineedit.cpp:259
@ LeftSide
Definition: lineedit.h:79
@ RightSide
Definition: lineedit.h:80
void updateTextMargins()
Definition: lineedit.cpp:348
void setLeftMargin(int margin)
Definition: lineedit.cpp:69
void showUrl(const QUrl &url)
void setPrivacyState(bool state)
PopupLocationBar(QWidget *parent=nullptr)
void setView(PopupWebView *view)
PopupSiteIcon(QWidget *parent=nullptr)
void setIcon(const QIcon &icon)
static QString urlEncodeQueryString(const QUrl &url)
Definition: qztools.cpp:220
WebPage * page() const
Definition: webview.cpp:132
State state
#define FALKON_EXPORT
Definition: qzcommon.h:28
#define QSL(x)
Definition: qzcommon.h:40