1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-24 12:46:35 +01:00

Small improvements in drag&drop.

- dragging is now enabled in locationbar and websearchbar
- dragging site icon has now new pixmap
This commit is contained in:
nowrep 2012-05-27 14:05:28 +02:00
parent 07e4b7d559
commit 1e179b3b83
5 changed files with 51 additions and 4 deletions

View File

@ -50,6 +50,7 @@ LocationBar::LocationBar(QupZilla* mainClass)
, m_holdingAlt(false)
{
setObjectName("locationbar");
setDragEnabled(true);
m_bookmarkIcon = new BookmarkIcon(p_QupZilla);
m_goIcon = new GoIcon(this);

View File

@ -18,6 +18,7 @@
#include "siteicon.h"
#include "locationbar.h"
#include "tabbedwebview.h"
#include "globalfunctions.h"
#include <QApplication>
@ -41,7 +42,7 @@ void SiteIcon::contextMenuEvent(QContextMenuEvent* e)
void SiteIcon::mousePressEvent(QMouseEvent* e)
{
if (e->buttons() & Qt::LeftButton) {
m_dragStartPosition = mapFromGlobal(e->globalPos());
m_dragStartPosition = e->pos();
}
// Prevent propagating to LocationBar
@ -53,6 +54,7 @@ void SiteIcon::mousePressEvent(QMouseEvent* e)
void SiteIcon::mouseMoveEvent(QMouseEvent* e)
{
if (!m_locationBar || !(e->buttons() & Qt::LeftButton)) {
ToolButton::mouseMoveEvent(e);
return;
}
@ -62,14 +64,17 @@ void SiteIcon::mouseMoveEvent(QMouseEvent* e)
return;
}
QUrl url = m_locationBar->webView()->url();
QString title = m_locationBar->webView()->title();
QDrag* drag = new QDrag(this);
QMimeData* mime = new QMimeData;
mime->setUrls(QList<QUrl>() << m_locationBar->webView()->url());
mime->setText(m_locationBar->webView()->title());
mime->setUrls(QList<QUrl>() << url);
mime->setText(title);
mime->setImageData(icon().pixmap(16, 16).toImage());
drag->setMimeData(mime);
drag->setPixmap(icon().pixmap(16, 16));
drag->setPixmap(qz_createPixmapForSite(icon(), title, url.toString()));
drag->exec();
}

View File

@ -56,6 +56,7 @@ WebSearchBar::WebSearchBar(QupZilla* mainClass, QWidget* parent)
, m_reloadingEngines(false)
{
setObjectName("websearchbar");
setDragEnabled(true);
m_buttonSearch = new WebSearchBar_Button(this);

View File

@ -19,6 +19,7 @@
#include <QByteArray>
#include <QPixmap>
#include <QPainter>
#include <QBuffer>
#include <QFile>
#include <QDir>
@ -261,6 +262,42 @@ QString qz_alignTextToWidth(const QString &string, const QString &text, const QF
return returnString;
}
QPixmap qz_createPixmapForSite(const QIcon &icon, const QString &title, const QString &url)
{
const QFontMetrics fontMetrics = QApplication::fontMetrics();
const int padding = 4;
const int maxWidth = fontMetrics.width(title.length() > url.length() ? title : url) + 3 * padding + 16;
const int width = qMin(maxWidth, 150);
const int height = fontMetrics.height() * 2 + fontMetrics.leading() + 2 * padding;
QPixmap pixmap(width, height);
QPainter painter(&pixmap);
// Draw background
QPen pen(Qt::black);
pen.setWidth(1);
painter.setPen(pen);
painter.fillRect(QRect(0, 0, width, height), Qt::white);
painter.drawRect(0, 0, width - 1, height - 1);
// Draw icon
QRect iconRect(0, 0, 16 + 2 * padding, height);
icon.paint(&painter, iconRect);
// Draw title
QRect titleRect(iconRect.width(), padding, width - padding - iconRect.width(), fontMetrics.height());
painter.drawText(titleRect, fontMetrics.elidedText(title, Qt::ElideRight, titleRect.width()));
// Draw url
QRect urlRect(titleRect.x(), titleRect.bottom() + fontMetrics.leading(), titleRect.width(), titleRect.height());
painter.setPen(QApplication::palette().color(QPalette::Link));
painter.drawText(urlRect, fontMetrics.elidedText(url, Qt::ElideRight, urlRect.width()));
return pixmap;
}
QString qz_buildSystem()
{
#ifdef Q_OS_LINUX

View File

@ -22,6 +22,7 @@
class QFontMetrics;
class QPixmap;
class QIcon;
class QWidget;
class QUrl;
@ -46,6 +47,8 @@ QString QT_QUPZILLA_EXPORT qz_filterCharsFromFilename(const QString &name);
QString QT_QUPZILLA_EXPORT qz_alignTextToWidth(const QString &string, const QString &text, const QFontMetrics &metrics, int width);
QPixmap QT_QUPZILLA_EXPORT qz_createPixmapForSite(const QIcon &icon, const QString &title, const QString &url);
QString QT_QUPZILLA_EXPORT qz_buildSystem();
#endif // GLOBALFUNCTIONS_H