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"
|
2011-12-17 14:26:34 +01:00
|
|
|
|
2012-02-29 18:33:50 +01:00
|
|
|
#include <QApplication>
|
|
|
|
|
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) {
|
|
|
|
m_dragStartPosition = mapFromGlobal(e->globalPos());
|
|
|
|
}
|
|
|
|
|
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-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;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
mime->setUrls(QList<QUrl>() << m_locationBar->webView()->url());
|
|
|
|
mime->setText(m_locationBar->webView()->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);
|
2011-12-17 16:04:04 +01:00
|
|
|
drag->setPixmap(icon().pixmap(16, 16));
|
2011-12-17 14:26:34 +01:00
|
|
|
|
|
|
|
drag->exec();
|
|
|
|
}
|