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

TabBar now accepts drops so you can drop url on it and open new tab.

- small modifications in locationbar regarding focus handling
This commit is contained in:
nowrep 2012-03-05 11:30:18 +01:00
parent f92df65819
commit 7dff6ad103
25 changed files with 164 additions and 100 deletions

View File

@ -1548,6 +1548,7 @@ void QupZilla::startPrivate(bool state)
QMessageBox::StandardButton button = QMessageBox::question(this, tr("Start Private Browsing"), QMessageBox::StandardButton button = QMessageBox::question(this, tr("Start Private Browsing"),
message, QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); message, QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
if (button != QMessageBox::Yes) { if (button != QMessageBox::Yes) {
m_actionPrivateBrowsing->setChecked(false);
return; return;
} }

View File

@ -102,6 +102,12 @@ void BookmarkIcon::setBookmarkDisabled()
setToolTip(tr("Bookmark this Page")); setToolTip(tr("Bookmark this Page"));
} }
void BookmarkIcon::contextMenuEvent(QContextMenuEvent* ev)
{
// Prevent propagating to LocationBar
ev->accept();
}
void BookmarkIcon::mousePressEvent(QMouseEvent* ev) void BookmarkIcon::mousePressEvent(QMouseEvent* ev)
{ {
ClickableLabel::mousePressEvent(ev); ClickableLabel::mousePressEvent(ev);

View File

@ -41,6 +41,7 @@ private slots:
void speedDialChanged(); void speedDialChanged();
private: private:
void contextMenuEvent(QContextMenuEvent* ev);
void mousePressEvent(QMouseEvent* ev); void mousePressEvent(QMouseEvent* ev);
void setBookmarkSaved(); void setBookmarkSaved();

View File

@ -579,16 +579,32 @@ void BookmarksToolbar::aboutToShowFolderMenu()
} }
} }
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 = IconProvider::iconFromImage(qvariant_cast<QImage>(mime->imageData()));
m_bookmarksModel->saveBookmark(url, title, icon, "bookmarksToolbar");
}
void BookmarksToolbar::dragEnterEvent(QDragEnterEvent* e) void BookmarksToolbar::dragEnterEvent(QDragEnterEvent* e)
{ {
const QMimeData* mime = e->mimeData(); const QMimeData* mime = e->mimeData();
if (mime->hasUrls() || mime->hasText()) { if (mime->hasUrls() && mime->hasText()) {
e->acceptProposedAction(); e->acceptProposedAction();
return; return;
} }
QWidget::dropEvent(e); QWidget::dragEnterEvent(e);
} }
void BookmarksToolbar::showOnlyIconsChanged() void BookmarksToolbar::showOnlyIconsChanged()
@ -608,22 +624,6 @@ void BookmarksToolbar::showOnlyIconsChanged()
} }
} }
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 = IconProvider::iconFromImage(qvariant_cast<QImage>(mime->imageData()));
m_bookmarksModel->saveBookmark(url, title, icon, "bookmarksToolbar");
}
void BookmarksToolbar::refreshMostVisited() void BookmarksToolbar::refreshMostVisited()
{ {
m_menuMostVisited->clear(); m_menuMostVisited->clear();

View File

@ -26,6 +26,12 @@ DownIcon::DownIcon(QWidget* parent)
setCursor(Qt::ArrowCursor); setCursor(Qt::ArrowCursor);
} }
void DownIcon::contextMenuEvent(QContextMenuEvent* ev)
{
// Prevent propagating to LocationBar
ev->accept();
}
void DownIcon::mousePressEvent(QMouseEvent* ev) void DownIcon::mousePressEvent(QMouseEvent* ev)
{ {
ClickableLabel::mousePressEvent(ev); ClickableLabel::mousePressEvent(ev);

View File

@ -27,6 +27,7 @@ public:
explicit DownIcon(QWidget* parent = 0); explicit DownIcon(QWidget* parent = 0);
private: private:
void contextMenuEvent(QContextMenuEvent* ev);
void mousePressEvent(QMouseEvent* ev); void mousePressEvent(QMouseEvent* ev);
}; };

View File

@ -27,6 +27,13 @@ GoIcon::GoIcon(QWidget* parent)
setHidden(true); setHidden(true);
} }
void GoIcon::contextMenuEvent(QContextMenuEvent* ev)
{
// Prevent propagating to LocationBar
ev->accept();
}
void GoIcon::mousePressEvent(QMouseEvent* ev) void GoIcon::mousePressEvent(QMouseEvent* ev)
{ {
ClickableLabel::mousePressEvent(ev); ClickableLabel::mousePressEvent(ev);

View File

@ -27,6 +27,7 @@ public:
explicit GoIcon(QWidget* parent = 0); explicit GoIcon(QWidget* parent = 0);
private: private:
void contextMenuEvent(QContextMenuEvent* ev);
void mousePressEvent(QMouseEvent* ev); void mousePressEvent(QMouseEvent* ev);
}; };

View File

@ -32,21 +32,27 @@ SiteIcon::SiteIcon(LocationBar* parent)
setFocusPolicy(Qt::ClickFocus); setFocusPolicy(Qt::ClickFocus);
} }
void SiteIcon::contextMenuEvent(QContextMenuEvent* e)
{
// Prevent propagating to LocationBar
e->accept();
}
void SiteIcon::mousePressEvent(QMouseEvent* e) void SiteIcon::mousePressEvent(QMouseEvent* e)
{ {
if (e->buttons() & Qt::LeftButton) { if (e->buttons() & Qt::LeftButton) {
m_dragStartPosition = mapFromGlobal(e->globalPos()); m_dragStartPosition = mapFromGlobal(e->globalPos());
} }
ToolButton::mousePressEvent(e);
// Prevent propagating to LocationBar // Prevent propagating to LocationBar
e->accept(); e->accept();
ToolButton::mousePressEvent(e);
} }
void SiteIcon::mouseMoveEvent(QMouseEvent* e) void SiteIcon::mouseMoveEvent(QMouseEvent* e)
{ {
if (!m_locationBar) { if (!m_locationBar || !(e->buttons() & Qt::LeftButton)) {
return; return;
} }

View File

@ -29,6 +29,7 @@ public:
explicit SiteIcon(LocationBar* parent); explicit SiteIcon(LocationBar* parent);
private: private:
void contextMenuEvent(QContextMenuEvent* e);
void mousePressEvent(QMouseEvent* e); void mousePressEvent(QMouseEvent* e);
void mouseMoveEvent(QMouseEvent* e); void mouseMoveEvent(QMouseEvent* e);

View File

@ -18,7 +18,7 @@
#include "licenseviewer.h" #include "licenseviewer.h"
#include "globalfunctions.h" #include "globalfunctions.h"
LicenseViewer::LicenseViewer(QWidget *parent) LicenseViewer::LicenseViewer(QWidget* parent)
: QTextBrowser() : QTextBrowser()
{ {
setAttribute(Qt::WA_DeleteOnClose); setAttribute(Qt::WA_DeleteOnClose);

View File

@ -27,7 +27,7 @@ class QT_QUPZILLA_EXPORT LicenseViewer : public QTextBrowser
Q_OBJECT Q_OBJECT
public: public:
explicit LicenseViewer(QWidget *parent = 0); explicit LicenseViewer(QWidget* parent = 0);
void setLicenseFile(const QString &fileName); void setLicenseFile(const QString &fileName);
}; };

View File

@ -56,7 +56,7 @@ void SpeedDial::loadSettings()
"url:\"http://www.qupzilla.com\"|title:\"QupZilla\";" "url:\"http://www.qupzilla.com\"|title:\"QupZilla\";"
"url:\"http://blog.qupzilla.com\"|title:\"QupZilla Blog\";" "url:\"http://blog.qupzilla.com\"|title:\"QupZilla Blog\";"
"url:\"https://github.com/nowrep/QupZilla\"|title:\"QupZilla GitHub\";" "url:\"https://github.com/nowrep/QupZilla\"|title:\"QupZilla GitHub\";"
"url:\"http://facebook.com\"|title:\"Facebook\";"; "url:\"https://facebook.com\"|title:\"Facebook\";";
} }
changed(allPages); changed(allPages);

View File

@ -32,7 +32,7 @@
#define DEFAULT_THEME_NAME "linux" #define DEFAULT_THEME_NAME "linux"
#endif #endif
ThemeManager::ThemeManager(QWidget* parent, Preferences *preferences) ThemeManager::ThemeManager(QWidget* parent, Preferences* preferences)
: QWidget() : QWidget()
, ui(new Ui::ThemeManager) , ui(new Ui::ThemeManager)
, m_preferences(preferences) , m_preferences(preferences)

View File

@ -37,7 +37,7 @@ class QT_QUPZILLA_EXPORT ThemeManager : public QWidget
Q_OBJECT Q_OBJECT
public: public:
explicit ThemeManager(QWidget *parent, Preferences *preferences); explicit ThemeManager(QWidget* parent, Preferences* preferences);
~ThemeManager(); ~ThemeManager();
void save(); void save();

View File

@ -28,6 +28,12 @@ RssIcon::RssIcon(QWidget* parent)
setVisible(false); setVisible(false);
} }
void RssIcon::contextMenuEvent(QContextMenuEvent* ev)
{
// Prevent propagating to LocationBar
ev->accept();
}
void RssIcon::mousePressEvent(QMouseEvent* ev) void RssIcon::mousePressEvent(QMouseEvent* ev)
{ {
ClickableLabel::mousePressEvent(ev); ClickableLabel::mousePressEvent(ev);

View File

@ -28,6 +28,7 @@ public:
explicit RssIcon(QWidget* parent = 0); explicit RssIcon(QWidget* parent = 0);
private: private:
void contextMenuEvent(QContextMenuEvent* ev);
void mousePressEvent(QMouseEvent* ev); void mousePressEvent(QMouseEvent* ev);
}; };

View File

@ -57,6 +57,8 @@ TabBar::TabBar(QupZilla* mainClass, TabWidget* tabWidget)
setFocusPolicy(Qt::NoFocus); setFocusPolicy(Qt::NoFocus);
loadSettings(); loadSettings();
setAcceptDrops(true);
connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(contextMenuRequested(const QPoint &))); connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(contextMenuRequested(const QPoint &)));
connect(m_tabWidget, SIGNAL(pinnedTabClosed()), this, SLOT(pinnedTabClosed())); connect(m_tabWidget, SIGNAL(pinnedTabClosed()), this, SLOT(pinnedTabClosed()));
connect(m_tabWidget, SIGNAL(pinnedTabAdded()), this, SLOT(pinnedTabAdded())); connect(m_tabWidget, SIGNAL(pinnedTabAdded()), this, SLOT(pinnedTabAdded()));
@ -386,6 +388,38 @@ void TabBar::mouseReleaseEvent(QMouseEvent* event)
QTabBar::mouseReleaseEvent(event); QTabBar::mouseReleaseEvent(event);
} }
void TabBar::dragEnterEvent(QDragEnterEvent* event)
{
const QMimeData* mime = event->mimeData();
if (mime->hasUrls()) {
event->acceptProposedAction();
return;
}
QTabBar::dragEnterEvent(event);
}
void TabBar::dropEvent(QDropEvent* event)
{
const QMimeData* mime = event->mimeData();
if (!mime->hasUrls()) {
QTabBar::dropEvent(event);
return;
}
int index = tabAt(event->pos());
if (index == -1) {
foreach(const QUrl & url, mime->urls()) {
m_tabWidget->addView(url, Qz::NT_SelectedTabAtTheEnd);
}
}
else {
p_QupZilla->weView(index)->load(mime->urls().first());
}
}
void TabBar::disconnectObjects() void TabBar::disconnectObjects()
{ {
disconnect(this); disconnect(this);

View File

@ -83,6 +83,9 @@ private:
void mouseMoveEvent(QMouseEvent* event); void mouseMoveEvent(QMouseEvent* event);
void mouseDoubleClickEvent(QMouseEvent* event); void mouseDoubleClickEvent(QMouseEvent* event);
void mouseReleaseEvent(QMouseEvent* event); void mouseReleaseEvent(QMouseEvent* event);
void dragEnterEvent(QDragEnterEvent* event);
void dropEvent(QDropEvent* event);
QSize tabSizeHint(int index) const; QSize tabSizeHint(int index) const;
// void tabInserted(int index); // void tabInserted(int index);

View File

@ -15,11 +15,11 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */ * ============================================================ */
#include "tabwidget.h"
#include "tabbar.h"
#include "tabbedwebview.h" #include "tabbedwebview.h"
#include "webpage.h" #include "webpage.h"
#include "qupzilla.h" #include "qupzilla.h"
#include "tabwidget.h"
#include "tabbar.h"
#include "iconprovider.h" #include "iconprovider.h"
#include "mainapplication.h" #include "mainapplication.h"
#include "webtab.h" #include "webtab.h"
@ -27,7 +27,6 @@
#include "closedtabsmanager.h" #include "closedtabsmanager.h"
#include "progressbar.h" #include "progressbar.h"
#include "navigationbar.h" #include "navigationbar.h"
#include "toolbutton.h"
#include "locationbar.h" #include "locationbar.h"
#include "websearchbar.h" #include "websearchbar.h"
#include "settings.h" #include "settings.h"
@ -38,70 +37,43 @@
#include <QStackedWidget> #include <QStackedWidget>
#include <QWebHistory> #include <QWebHistory>
class QT_QUPZILLA_EXPORT NewTabButton : public QToolButton AddTabButton::AddTabButton(TabWidget* tabWidget, TabBar* tabBar)
: ToolButton(tabWidget)
, m_tabBar(tabBar)
, m_tabWidget(tabWidget)
{ {
public: setObjectName("tabwidget-button-addtab");
explicit NewTabButton(QWidget* parent) : QToolButton(parent) {
#ifndef Q_WS_WIN
setIcon(QIcon::fromTheme("list-add"));
setIconSize(QSize(16, 16));
setAutoRaise(true); setAutoRaise(true);
#endif setFocusPolicy(Qt::NoFocus);
} setAcceptDrops(true);
QSize sizeHint() const { setToolTip(TabWidget::tr("New Tab"));
QSize siz = QToolButton::sizeHint(); }
siz.setWidth(26);
return siz;
}
#ifdef Q_WS_WIN void AddTabButton::dragEnterEvent(QDragEnterEvent* event)
private:
void paintEvent(QPaintEvent*) {
QPainter p(this);
QStyleOptionTabV3 opt;
opt.init(this);
style()->drawControl(QStyle::CE_TabBarTab, &opt, &p, this);
QPixmap pix(":/icons/other/list-add.png");
QRect r = this->rect();
r.setHeight(r.height() + 3);
r.setWidth(r.width() + 3);
style()->drawItemPixmap(&p, r, Qt::AlignCenter, pix);
}
#endif
};
class QT_QUPZILLA_EXPORT TabListButton : public QToolButton
{ {
public: const QMimeData* mime = event->mimeData();
explicit TabListButton(QWidget* parent) : QToolButton(parent) {
if (mime->hasUrls()) {
event->acceptProposedAction();
return;
} }
QSize sizeHint() const { ToolButton::dragEnterEvent(event);
QSize siz = QToolButton::sizeHint(); }
siz.setWidth(20);
return siz; void AddTabButton::dropEvent(QDropEvent* event)
{
const QMimeData* mime = event->mimeData();
if (!mime->hasUrls()) {
ToolButton::dropEvent(event);
return;
} }
private: foreach(const QUrl & url, mime->urls()) {
void paintEvent(QPaintEvent*) { m_tabWidget->addView(url, Qz::NT_SelectedTabAtTheEnd);
QPainter p(this);
QStyleOptionToolButton opt;
opt.init(this);
if (isDown()) {
opt.state |= QStyle::State_On;
} }
if (opt.state & QStyle::State_MouseOver) { }
opt.activeSubControls = QStyle::SC_ToolButton;
}
if (!isChecked() && !isDown()) {
opt.state |= QStyle::State_Raised;
}
opt.state |= QStyle::State_AutoRaise;
style()->drawComplexControl(QStyle::CC_ToolButton, &opt, &p, this);
}
};
TabWidget::TabWidget(QupZilla* mainClass, QWidget* parent) TabWidget::TabWidget(QupZilla* mainClass, QWidget* parent)
: QTabWidget(parent) : QTabWidget(parent)
@ -142,11 +114,7 @@ TabWidget::TabWidget(QupZilla* mainClass, QWidget* parent)
m_buttonListTabs->setAutoRaise(true); m_buttonListTabs->setAutoRaise(true);
m_buttonListTabs->setFocusPolicy(Qt::NoFocus); m_buttonListTabs->setFocusPolicy(Qt::NoFocus);
m_buttonAddTab = new ToolButton(this); m_buttonAddTab = new AddTabButton(this, m_tabBar);
m_buttonAddTab->setObjectName("tabwidget-button-addtab");
m_buttonAddTab->setAutoRaise(true);
m_buttonAddTab->setToolTip(tr("New Tab"));
m_buttonAddTab->setFocusPolicy(Qt::NoFocus);
connect(m_buttonAddTab, SIGNAL(clicked()), p_QupZilla, SLOT(addTab())); connect(m_buttonAddTab, SIGNAL(clicked()), p_QupZilla, SLOT(addTab()));
connect(m_menuTabs, SIGNAL(aboutToShow()), this, SLOT(aboutToShowClosedTabsMenu())); connect(m_menuTabs, SIGNAL(aboutToShow()), this, SLOT(aboutToShowClosedTabsMenu()));

View File

@ -21,6 +21,7 @@
#include <QTabWidget> #include <QTabWidget>
#include <QUrl> #include <QUrl>
#include "toolbutton.h"
#include "qz_namespace.h" #include "qz_namespace.h"
class QStackedWidget; class QStackedWidget;
@ -29,11 +30,22 @@ class QMenu;
class QupZilla; class QupZilla;
class TabbedWebView; class TabbedWebView;
class TabBar; class TabBar;
class TabWidget;
class WebTab; class WebTab;
class TabListButton;
class NewTabButton;
class ClosedTabsManager; class ClosedTabsManager;
class ToolButton;
class QT_QUPZILLA_EXPORT AddTabButton : public ToolButton
{
public:
explicit AddTabButton(TabWidget* tabWidget, TabBar* tabBar);
private:
void dragEnterEvent(QDragEnterEvent* event);
void dropEvent(QDropEvent* event);
TabBar* m_tabBar;
TabWidget* m_tabWidget;
};
class QT_QUPZILLA_EXPORT TabWidget : public QTabWidget class QT_QUPZILLA_EXPORT TabWidget : public QTabWidget
{ {
@ -56,7 +68,7 @@ public:
QList<WebTab*> allTabs(bool withPinned = true); QList<WebTab*> allTabs(bool withPinned = true);
QStackedWidget* locationBars() { return m_locationBars; } QStackedWidget* locationBars() { return m_locationBars; }
ToolButton* buttonListTabs() { return m_buttonListTabs; } ToolButton* buttonListTabs() { return m_buttonListTabs; }
ToolButton* buttonAddTab() { return m_buttonAddTab; } AddTabButton* buttonAddTab() { return m_buttonAddTab; }
void createKeyPressEvent(QKeyEvent* event); void createKeyPressEvent(QKeyEvent* event);
void showTabBar(); void showTabBar();
@ -114,7 +126,7 @@ private:
QMenu* m_menuTabs; QMenu* m_menuTabs;
ToolButton* m_buttonListTabs; ToolButton* m_buttonListTabs;
ToolButton* m_buttonAddTab; AddTabButton* m_buttonAddTab;
ClosedTabsManager* m_closedTabsManager; ClosedTabsManager* m_closedTabsManager;
QStackedWidget* m_locationBars; QStackedWidget* m_locationBars;

View File

@ -167,6 +167,10 @@ void AKN_Handler::handleAccessKey(QKeyEvent* event)
return; return;
} }
if (!m_view) {
return;
}
QChar key = text.at(0).toUpper(); QChar key = text.at(0).toUpper();
if (m_accessKeyNodes.contains(key)) { if (m_accessKeyNodes.contains(key)) {
@ -196,6 +200,10 @@ void AKN_Handler::handleAccessKey(QKeyEvent* event)
void AKN_Handler::showAccessKeys() void AKN_Handler::showAccessKeys()
{ {
if (!m_view) {
return;
}
QWebPage* page = m_view->page(); QWebPage* page = m_view->page();
// Install event filter and connect loadStarted // Install event filter and connect loadStarted
@ -284,7 +292,7 @@ void AKN_Handler::showAccessKeys()
void AKN_Handler::hideAccessKeys() void AKN_Handler::hideAccessKeys()
{ {
if (!m_accessKeyLabels.isEmpty()) { if (!m_accessKeyLabels.isEmpty() && m_view) {
for (int i = 0; i < m_accessKeyLabels.count(); ++i) { for (int i = 0; i < m_accessKeyLabels.count(); ++i) {
QLabel* label = m_accessKeyLabels[i]; QLabel* label = m_accessKeyLabels[i];
label->hide(); label->hide();

View File

@ -25,6 +25,7 @@
AKN_Plugin::AKN_Plugin() AKN_Plugin::AKN_Plugin()
: QObject() : QObject()
, m_handler(0)
{ {
} }

View File

@ -24,7 +24,7 @@
#include <QSettings> #include <QSettings>
#include <QTextBrowser> #include <QTextBrowser>
AKN_Settings::AKN_Settings(AKN_Handler *handler, QWidget *parent) AKN_Settings::AKN_Settings(AKN_Handler* handler, QWidget* parent)
: QDialog(parent) : QDialog(parent)
, ui(new Ui::AKN_Settings) , ui(new Ui::AKN_Settings)
, m_handler(handler) , m_handler(handler)

View File

@ -20,7 +20,8 @@
#include <QDialog> #include <QDialog>
namespace Ui { namespace Ui
{
class AKN_Settings; class AKN_Settings;
} }
@ -31,7 +32,7 @@ class AKN_Settings : public QDialog
Q_OBJECT Q_OBJECT
public: public:
explicit AKN_Settings(AKN_Handler* handler, QWidget *parent = 0); explicit AKN_Settings(AKN_Handler* handler, QWidget* parent = 0);
~AKN_Settings(); ~AKN_Settings();
private slots: private slots:
@ -39,7 +40,7 @@ private slots:
void showLicence(); void showLicence();
private: private:
Ui::AKN_Settings *ui; Ui::AKN_Settings* ui;
AKN_Handler* m_handler; AKN_Handler* m_handler;
QString m_settingsPath; QString m_settingsPath;