28#include <QApplication>
29#include <QContextMenuEvent>
34 , m_locationBar(parent)
37 setObjectName(
"locationbar-siteicon");
38 setToolButtonStyle(Qt::ToolButtonIconOnly);
39 setCursor(Qt::ArrowCursor);
40 setToolTip(LocationBar::tr(
"Show information about this page"));
41 setFocusPolicy(Qt::NoFocus);
43 m_updateTimer =
new QTimer(
this);
44 m_updateTimer->setInterval(100);
45 m_updateTimer->setSingleShot(
true);
46 connect(m_updateTimer, &QTimer::timeout,
this, &SiteIcon::updateIcon);
61 bool wasNull = m_icon.isNull();
69 m_updateTimer->start();
73void SiteIcon::updateIcon()
78void SiteIcon::popupClosed()
83void SiteIcon::contextMenuEvent(QContextMenuEvent* e)
89void SiteIcon::mousePressEvent(QMouseEvent* e)
91 if (e->buttons() == Qt::LeftButton) {
92 m_dragStartPosition = e->pos();
101void SiteIcon::mouseReleaseEvent(QMouseEvent* e)
106 bool activated =
false;
108 if (e->button() == Qt::LeftButton && rect().contains(e->pos())) {
110 activated = showPopup();
114 setUpdatesEnabled(
false);
121 setUpdatesEnabled(
true);
125void SiteIcon::mouseMoveEvent(QMouseEvent* e)
127 if (!m_locationBar || e->buttons() != Qt::LeftButton) {
128 ToolButton::mouseMoveEvent(e);
132 int manhattanLength = (e->pos() - m_dragStartPosition).manhattanLength();
133 if (manhattanLength <= QApplication::startDragDistance()) {
134 ToolButton::mouseMoveEvent(e);
138 const QUrl url = m_locationBar->
webView()->url();
139 const QString title = m_locationBar->
webView()->
title();
141 if (url.isEmpty() || title.isEmpty()) {
142 ToolButton::mouseMoveEvent(e);
146 auto* drag =
new QDrag(
this);
147 auto* mime =
new QMimeData;
148 mime->setUrls(QList<QUrl>() << url);
149 mime->setText(title);
150 mime->setImageData(
icon().pixmap(16).toImage());
152 drag->setMimeData(mime);
160bool SiteIcon::showPopup()
162 if (!m_view || !m_window) {
166 QUrl url = m_view->url();
174 info->showAt(parentWidget());
176 connect(info, &QObject::destroyed,
this, &SiteIcon::popupClosed);
TabbedWebView * webView() const
void setIcon(const QIcon &icon)
SiteIcon(LocationBar *parent)
void setBrowserWindow(BrowserWindow *window)
void setWebView(WebView *view)
static bool canShowSiteInfo(const QUrl &url)
QString title(bool allowEmpty=false) const