diff --git a/src/bookmarks/bookmarkstoolbar.cpp b/src/bookmarks/bookmarkstoolbar.cpp index e136342dd..473f39247 100644 --- a/src/bookmarks/bookmarkstoolbar.cpp +++ b/src/bookmarks/bookmarkstoolbar.cpp @@ -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(); + + m_bookmarksModel->saveBookmark(url, title, icon, "bookmarksToolbar"); +} + void BookmarksToolbar::refreshMostVisited() { m_menuMostVisited->clear(); diff --git a/src/bookmarks/bookmarkstoolbar.h b/src/bookmarks/bookmarkstoolbar.h index c02d2b905..3e9a14ebf 100644 --- a/src/bookmarks/bookmarkstoolbar.h +++ b/src/bookmarks/bookmarkstoolbar.h @@ -21,6 +21,7 @@ #include #include #include +#include #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; diff --git a/src/navigation/locationbar.cpp b/src/navigation/locationbar.cpp index eb8ce4965..ee3bbb786 100644 --- a/src/navigation/locationbar.cpp +++ b/src/navigation/locationbar.cpp @@ -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(); } diff --git a/src/navigation/locationbar.h b/src/navigation/locationbar.h index 4d2ed6248..d33abaaa0 100644 --- a/src/navigation/locationbar.h +++ b/src/navigation/locationbar.h @@ -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; diff --git a/src/navigation/siteicon.cpp b/src/navigation/siteicon.cpp new file mode 100644 index 000000000..ab7dc0b89 --- /dev/null +++ b/src/navigation/siteicon.cpp @@ -0,0 +1,60 @@ +/* ============================================================ +* QupZilla - WebKit based browser +* Copyright (C) 2010-2011 David Rosca +* +* 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 . +* ============================================================ */ +#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() << 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(); +} diff --git a/src/navigation/siteicon.h b/src/navigation/siteicon.h new file mode 100644 index 000000000..891686d60 --- /dev/null +++ b/src/navigation/siteicon.h @@ -0,0 +1,45 @@ +/* ============================================================ +* QupZilla - WebKit based browser +* Copyright (C) 2010-2011 David Rosca +* +* 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 . +* ============================================================ */ +#ifndef SITEICON_H +#define SITEICON_H + +#include + +#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