2011-12-17 14:26:34 +01:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
2012-01-01 15:29:55 +01:00
|
|
|
* Copyright (C) 2010-2012 David Rosca <nowrep@gmail.com>
|
2011-12-17 14:26:34 +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 "siteicon.h"
|
|
|
|
#include "locationbar.h"
|
2012-01-21 20:27:45 +01:00
|
|
|
#include "tabbedwebview.h"
|
2012-05-27 14:05:28 +02:00
|
|
|
#include "globalfunctions.h"
|
2011-12-17 14:26:34 +01:00
|
|
|
|
2012-02-29 18:33:50 +01:00
|
|
|
#include <QApplication>
|
2012-08-31 15:19:07 +02:00
|
|
|
#include <QContextMenuEvent>
|
2012-02-29 18:33:50 +01:00
|
|
|
|
2011-12-17 16:04:04 +01:00
|
|
|
SiteIcon::SiteIcon(LocationBar* parent)
|
2011-12-17 14:26:34 +01:00
|
|
|
: ToolButton(parent)
|
|
|
|
, m_locationBar(parent)
|
|
|
|
{
|
|
|
|
setObjectName("locationbar-siteicon");
|
|
|
|
setToolButtonStyle(Qt::ToolButtonIconOnly);
|
|
|
|
setCursor(Qt::ArrowCursor);
|
2012-01-21 20:27:45 +01:00
|
|
|
setToolTip(LocationBar::tr("Show information about this page"));
|
2011-12-17 14:26:34 +01:00
|
|
|
setFocusPolicy(Qt::ClickFocus);
|
|
|
|
}
|
|
|
|
|
2012-03-05 11:30:18 +01:00
|
|
|
void SiteIcon::contextMenuEvent(QContextMenuEvent* e)
|
|
|
|
{
|
|
|
|
// Prevent propagating to LocationBar
|
|
|
|
e->accept();
|
|
|
|
}
|
|
|
|
|
2011-12-17 16:04:04 +01:00
|
|
|
void SiteIcon::mousePressEvent(QMouseEvent* e)
|
2011-12-17 14:26:34 +01:00
|
|
|
{
|
|
|
|
if (e->buttons() & Qt::LeftButton) {
|
2012-05-27 14:05:28 +02:00
|
|
|
m_dragStartPosition = e->pos();
|
2011-12-17 14:26:34 +01:00
|
|
|
}
|
|
|
|
|
2011-12-27 18:50:52 +01:00
|
|
|
// Prevent propagating to LocationBar
|
|
|
|
e->accept();
|
2012-03-05 11:30:18 +01:00
|
|
|
|
|
|
|
ToolButton::mousePressEvent(e);
|
2011-12-17 14:26:34 +01:00
|
|
|
}
|
|
|
|
|
2011-12-17 16:04:04 +01:00
|
|
|
void SiteIcon::mouseMoveEvent(QMouseEvent* e)
|
2011-12-17 14:26:34 +01:00
|
|
|
{
|
2012-03-05 11:30:18 +01:00
|
|
|
if (!m_locationBar || !(e->buttons() & Qt::LeftButton)) {
|
2012-05-27 14:05:28 +02:00
|
|
|
ToolButton::mouseMoveEvent(e);
|
2012-01-21 20:27:45 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-12-17 14:26:34 +01:00
|
|
|
int manhattanLength = (e->pos() - m_dragStartPosition).manhattanLength();
|
2011-12-27 18:50:52 +01:00
|
|
|
if (manhattanLength <= QApplication::startDragDistance()) {
|
2011-12-17 14:26:34 +01:00
|
|
|
ToolButton::mouseMoveEvent(e);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-09-06 11:29:05 +02:00
|
|
|
const QUrl &url = m_locationBar->webView()->url();
|
|
|
|
const QString &title = m_locationBar->webView()->title();
|
|
|
|
|
|
|
|
if (url.isEmpty() || title.isEmpty()) {
|
|
|
|
ToolButton::mouseMoveEvent(e);
|
|
|
|
return;
|
|
|
|
}
|
2012-05-27 14:05:28 +02:00
|
|
|
|
2011-12-17 16:04:04 +01:00
|
|
|
QDrag* drag = new QDrag(this);
|
2011-12-17 14:26:34 +01:00
|
|
|
QMimeData* mime = new QMimeData;
|
2012-05-27 14:05:28 +02:00
|
|
|
mime->setUrls(QList<QUrl>() << url);
|
|
|
|
mime->setText(title);
|
2012-01-22 20:13:50 +01:00
|
|
|
mime->setImageData(icon().pixmap(16, 16).toImage());
|
2011-12-17 14:26:34 +01:00
|
|
|
|
|
|
|
drag->setMimeData(mime);
|
2012-05-27 14:05:28 +02:00
|
|
|
drag->setPixmap(qz_createPixmapForSite(icon(), title, url.toString()));
|
2011-12-17 14:26:34 +01:00
|
|
|
|
|
|
|
drag->exec();
|
|
|
|
}
|