File indexing completed on 2024-05-12 04:57:55

0001 /* ============================================================
0002 * Falkon - Qt web browser
0003 * Copyright (C) 2013-2018 David Rosca <nowrep@gmail.com>
0004 *
0005 * This program is free software: you can redistribute it and/or modify
0006 * it under the terms of the GNU General Public License as published by
0007 * the Free Software Foundation, either version 3 of the License, or
0008 * (at your option) any later version.
0009 *
0010 * This program is distributed in the hope that it will be useful,
0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013 * GNU General Public License for more details.
0014 *
0015 * You should have received a copy of the GNU General Public License
0016 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
0017 * ============================================================ */
0018 #include "autofillicon.h"
0019 #include "autofillwidget.h"
0020 
0021 #include <QContextMenuEvent>
0022 
0023 AutoFillIcon::AutoFillIcon(QWidget* parent)
0024     : ClickableLabel(parent)
0025     , m_view(nullptr)
0026 {
0027     setObjectName(QSL("locationbar-autofillicon"));
0028     setCursor(Qt::PointingHandCursor);
0029     setToolTip(AutoFillWidget::tr("Choose username to login"));
0030     setFocusPolicy(Qt::ClickFocus);
0031 
0032     connect(this, &ClickableLabel::clicked, this, &AutoFillIcon::iconClicked);
0033 }
0034 
0035 void AutoFillIcon::setWebView(WebView* view)
0036 {
0037     m_view = view;
0038 }
0039 
0040 void AutoFillIcon::setUsernames(const QStringList &usernames)
0041 {
0042     m_usernames = usernames;
0043 }
0044 
0045 void AutoFillIcon::iconClicked()
0046 {
0047     if (!m_view) {
0048         return;
0049     }
0050 
0051     auto* widget = new AutoFillWidget(m_view, this);
0052     widget->setUsernames(m_usernames);
0053     widget->showAt(parentWidget());
0054 }
0055 
0056 void AutoFillIcon::contextMenuEvent(QContextMenuEvent* ev)
0057 {
0058     // Prevent propagating to LocationBar
0059     ev->accept();
0060 }
0061 
0062 void AutoFillIcon::mousePressEvent(QMouseEvent* ev)
0063 {
0064     ClickableLabel::mousePressEvent(ev);
0065 
0066     // Prevent propagating to LocationBar
0067     ev->accept();
0068 }