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

Drag&Drop siteicon to bookmarks toolbar creates bookmark. Closes #63

- initial drag&drop implementation
- will be probably extended to other widgets too
This commit is contained in:
nowrep 2011-12-17 14:26:34 +01:00
parent df01a3efef
commit 88d15cd3b8
6 changed files with 152 additions and 9 deletions

View File

@ -36,6 +36,8 @@ BookmarksToolbar::BookmarksToolbar(QupZilla* mainClass, QWidget* parent)
m_layout->setSpacing(0);
setLayout(m_layout);
setAcceptDrops(true);
setContextMenuPolicy(Qt::CustomContextMenu);
connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(customContextMenuRequested(QPoint)));
@ -480,6 +482,34 @@ void BookmarksToolbar::aboutToShowFolderMenu()
}
}
void BookmarksToolbar::dragEnterEvent(QDragEnterEvent *e)
{
const QMimeData* mime = e->mimeData();
if (mime->hasUrls() || mime->hasText()) {
e->acceptProposedAction();
return;
}
QWidget::dropEvent(e);
}
void BookmarksToolbar::dropEvent(QDropEvent *e)
{
const QMimeData* mime = e->mimeData();
if (!mime->hasUrls() || !mime->hasText()) {
QWidget::dropEvent(e);
return;
}
QString title = mime->text();
QUrl url = mime->urls().at(0);
QIcon icon = mime->imageData().value<QIcon>();
m_bookmarksModel->saveBookmark(url, title, icon, "bookmarksToolbar");
}
void BookmarksToolbar::refreshMostVisited()
{
m_menuMostVisited->clear();

View File

@ -21,6 +21,7 @@
#include <QMenu>
#include <QToolButton>
#include <QHBoxLayout>
#include <QDropEvent>
#include "bookmarksmodel.h"
@ -64,6 +65,9 @@ private slots:
void folderRenamed(const QString &before, const QString &after);
private:
void dropEvent(QDropEvent *e);
void dragEnterEvent(QDragEnterEvent *e);
int indexOfLastBookmark();
QupZilla* p_QupZilla;

View File

@ -31,6 +31,7 @@
#include "locationbarsettings.h"
#include "toolbutton.h"
#include "searchenginesmanager.h"
#include "siteicon.h"
LocationBar::LocationBar(QupZilla* mainClass)
: LineEdit()
@ -39,12 +40,7 @@ LocationBar::LocationBar(QupZilla* mainClass)
, m_locationBarSettings(LocationBarSettings::instance())
{
setObjectName("locationbar");
m_siteIcon = new ToolButton(this);
m_siteIcon->setObjectName("locationbar-siteicon");
m_siteIcon->setToolButtonStyle(Qt::ToolButtonIconOnly);
m_siteIcon->setCursor(Qt::ArrowCursor);
m_siteIcon->setToolTip(tr("Show informations about this page"));
m_siteIcon->setFocusPolicy(Qt::ClickFocus);
m_siteIcon = new SiteIcon(this);
m_rssIcon = new ClickableLabel(this);
m_rssIcon->setObjectName("locationbar-rss-icon");
@ -91,6 +87,12 @@ LocationBar::LocationBar(QupZilla* mainClass)
updatePlaceHolderText();
}
void LocationBar::setText(const QString &text)
{
LineEdit::setText(text);
setCursorPosition(0);
}
void LocationBar::updatePlaceHolderText()
{
setPlaceholderText(tr("Enter URL address or search on %1").arg(mApp->searchEnginesManager()->activeEngine().name));
@ -204,7 +206,6 @@ void LocationBar::showUrl(const QUrl &url, bool empty)
if (url.toEncoded() != text()) {
setText(encodedUrl);
setCursorPosition(0);
}
p_QupZilla->statusBarMessage()->clearMessage();
@ -275,6 +276,7 @@ void LocationBar::focusOutEvent(QFocusEvent* e)
if (!selectedText().isEmpty() && e->reason() != Qt::TabFocusReason) {
return;
}
setCursorPosition(0);
hideGoButton();
}

View File

@ -39,7 +39,7 @@ class ClickableLabel;
class BookmarkIcon;
class WebView;
class LocationBarSettings;
class ToolButton;
class SiteIcon;
class LocationBar : public LineEdit
{
Q_OBJECT
@ -52,12 +52,14 @@ public:
~LocationBar();
void setWebView(WebView* view) { m_webView = view; }
WebView* webView() { return m_webView; }
signals:
void loadUrl(const QUrl &url);
public slots:
void showUrl(const QUrl &url, bool empty = true);
virtual void setText(const QString &text);
private slots:
void siteIconChanged();
@ -85,7 +87,7 @@ private:
BookmarkIcon* m_bookmarkIcon;
ClickableLabel* m_goButton;
ClickableLabel* m_rssIcon;
ToolButton* m_siteIcon;
SiteIcon* m_siteIcon;
QupZilla* p_QupZilla;
WebView* m_webView;

View File

@ -0,0 +1,60 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-2011 David Rosca <nowrep@gmail.com>
*
* 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"
#include "webview.h"
SiteIcon::SiteIcon(LocationBar *parent)
: ToolButton(parent)
, m_locationBar(parent)
{
setObjectName("locationbar-siteicon");
setToolButtonStyle(Qt::ToolButtonIconOnly);
setCursor(Qt::ArrowCursor);
setToolTip(tr("Show informations about this page"));
setFocusPolicy(Qt::ClickFocus);
}
void SiteIcon::mousePressEvent(QMouseEvent *e)
{
if (e->buttons() & Qt::LeftButton) {
m_dragStartPosition = mapFromGlobal(e->globalPos());
}
ToolButton::mousePressEvent(e);
}
void SiteIcon::mouseMoveEvent(QMouseEvent *e)
{
int manhattanLength = (e->pos() - m_dragStartPosition).manhattanLength();
if (manhattanLength > QApplication::startDragDistance()) {
ToolButton::mouseMoveEvent(e);
return;
}
QDrag *drag = new QDrag(this);
QMimeData* mime = new QMimeData;
mime->setUrls(QList<QUrl>() << m_locationBar->webView()->url());
mime->setText(m_locationBar->webView()->title());
mime->setImageData(QVariant::fromValue(icon()));
drag->setMimeData(mime);
drag->setPixmap(icon().pixmap(16,16));
drag->exec();
}

45
src/navigation/siteicon.h Normal file
View File

@ -0,0 +1,45 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-2011 David Rosca <nowrep@gmail.com>
*
* 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/>.
* ============================================================ */
#ifndef SITEICON_H
#define SITEICON_H
#include <QApplication>
#include "toolbutton.h"
class LocationBar;
class SiteIcon : public ToolButton
{
Q_OBJECT
public:
explicit SiteIcon(LocationBar *parent);
signals:
public slots:
private:
void mousePressEvent(QMouseEvent *e);
void mouseMoveEvent(QMouseEvent *e);
LocationBar* m_locationBar;
QPoint m_dragStartPosition;
};
#endif // SITEICON_H