diff --git a/src/lib/sidebar/bookmarkssidebar.cpp b/src/lib/sidebar/bookmarkssidebar.cpp index 73eb7d4a..116c3e5e 100644 --- a/src/lib/sidebar/bookmarkssidebar.cpp +++ b/src/lib/sidebar/bookmarkssidebar.cpp @@ -1,136 +1,142 @@ /* ============================================================ * Falkon - Qt web browser * Copyright (C) 2010-2014 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 "bookmarkssidebar.h" #include "ui_bookmarkssidebar.h" #include "bookmarkstools.h" #include "bookmarkitem.h" #include "bookmarks.h" #include "mainapplication.h" #include "iconprovider.h" #include BookmarksSidebar::BookmarksSidebar(BrowserWindow* window, QWidget* parent) : QWidget(parent) , ui(new Ui::BookmarksSideBar) , m_window(window) , m_bookmarks(mApp->bookmarks()) { ui->setupUi(this); ui->tree->setViewType(BookmarksTreeView::BookmarksSidebarViewType); connect(ui->tree, &BookmarksTreeView::bookmarkActivated, this, &BookmarksSidebar::bookmarkActivated); connect(ui->tree, &BookmarksTreeView::bookmarkCtrlActivated, this, &BookmarksSidebar::bookmarkCtrlActivated); connect(ui->tree, &BookmarksTreeView::bookmarkShiftActivated, this, &BookmarksSidebar::bookmarkShiftActivated); connect(ui->tree, &BookmarksTreeView::contextMenuRequested, this, &BookmarksSidebar::createContextMenu); connect(ui->search, &QLineEdit::textChanged, ui->tree, &BookmarksTreeView::search); } BookmarksSidebar::~BookmarksSidebar() { delete ui; } void BookmarksSidebar::bookmarkActivated(BookmarkItem* item) { openBookmark(item); } void BookmarksSidebar::bookmarkCtrlActivated(BookmarkItem* item) { openBookmarkInNewTab(item); } void BookmarksSidebar::bookmarkShiftActivated(BookmarkItem* item) { openBookmarkInNewWindow(item); } void BookmarksSidebar::openBookmark(BookmarkItem* item) { item = item ? item : ui->tree->selectedBookmark(); BookmarksTools::openBookmark(m_window, item); } void BookmarksSidebar::openBookmarkInNewTab(BookmarkItem* item) { item = item ? item : ui->tree->selectedBookmark(); BookmarksTools::openBookmarkInNewTab(m_window, item); } void BookmarksSidebar::openBookmarkInNewWindow(BookmarkItem* item) { item = item ? item : ui->tree->selectedBookmark(); BookmarksTools::openBookmarkInNewWindow(item); } void BookmarksSidebar::openBookmarkInNewPrivateWindow(BookmarkItem* item) { item = item ? item : ui->tree->selectedBookmark(); BookmarksTools::openBookmarkInNewPrivateWindow(item); } void BookmarksSidebar::deleteBookmarks() { QList items = ui->tree->selectedBookmarks(); foreach (BookmarkItem* item, items) { if (m_bookmarks->canBeModified(item)) { m_bookmarks->removeBookmark(item); } } } void BookmarksSidebar::createContextMenu(const QPoint &pos) { QMenu menu; QAction* actNewTab = menu.addAction(IconProvider::newTabIcon(), tr("Open in new tab")); QAction* actNewWindow = menu.addAction(IconProvider::newWindowIcon(), tr("Open in new window")); QAction* actNewPrivateWindow = menu.addAction(IconProvider::privateBrowsingIcon(), tr("Open in new private window")); menu.addSeparator(); QAction* actDelete = menu.addAction(QIcon::fromTheme("edit-delete"), tr("Delete")); connect(actNewTab, SIGNAL(triggered()), this, SLOT(openBookmarkInNewTab())); connect(actNewWindow, SIGNAL(triggered()), this, SLOT(openBookmarkInNewWindow())); connect(actNewPrivateWindow, SIGNAL(triggered()), this, SLOT(openBookmarkInNewPrivateWindow())); connect(actDelete, &QAction::triggered, this, &BookmarksSidebar::deleteBookmarks); bool canBeDeleted = false; QList items = ui->tree->selectedBookmarks(); foreach (BookmarkItem* item, items) { if (m_bookmarks->canBeModified(item)) { canBeDeleted = true; break; } } if (!canBeDeleted) { actDelete->setDisabled(true); } if (!ui->tree->selectedBookmark() || !ui->tree->selectedBookmark()->isUrl()) { actNewTab->setDisabled(true); actNewWindow->setDisabled(true); actNewPrivateWindow->setDisabled(true); } menu.exec(pos); } + +void BookmarksSidebar::showEvent(QShowEvent *event) +{ + QWidget::showEvent(event); + ui->search->setFocus(); +} diff --git a/src/lib/sidebar/bookmarkssidebar.h b/src/lib/sidebar/bookmarkssidebar.h index 3d72ff7d..57ec44cf 100644 --- a/src/lib/sidebar/bookmarkssidebar.h +++ b/src/lib/sidebar/bookmarkssidebar.h @@ -1,61 +1,63 @@ /* ============================================================ * Falkon - Qt web browser * Copyright (C) 2010-2014 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 BOOKMARKSSIDEBAR_H #define BOOKMARKSSIDEBAR_H #include #include "qzcommon.h" namespace Ui { class BookmarksSideBar; } class BrowserWindow; class Bookmarks; class BookmarkItem; class FALKON_EXPORT BookmarksSidebar : public QWidget { Q_OBJECT public: explicit BookmarksSidebar(BrowserWindow* window, QWidget* parent = 0); ~BookmarksSidebar(); private Q_SLOTS: void bookmarkActivated(BookmarkItem* item); void bookmarkCtrlActivated(BookmarkItem* item); void bookmarkShiftActivated(BookmarkItem* item); void openBookmark(BookmarkItem* item = 0); void openBookmarkInNewTab(BookmarkItem* item = 0); void openBookmarkInNewWindow(BookmarkItem* item = 0); void openBookmarkInNewPrivateWindow(BookmarkItem* item = 0); void deleteBookmarks(); void createContextMenu(const QPoint &pos); private: + void showEvent(QShowEvent *event) override; + Ui::BookmarksSideBar* ui; BrowserWindow* m_window; Bookmarks* m_bookmarks; }; #endif // BOOKMARKSSIDEBAR_H diff --git a/src/lib/sidebar/historysidebar.cpp b/src/lib/sidebar/historysidebar.cpp index 4680c1ca..c6e0a0b0 100644 --- a/src/lib/sidebar/historysidebar.cpp +++ b/src/lib/sidebar/historysidebar.cpp @@ -1,109 +1,115 @@ /* ============================================================ * Falkon - Qt web browser * Copyright (C) 2010-2014 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 "historysidebar.h" #include "ui_historysidebar.h" #include "browserwindow.h" #include "tabwidget.h" #include "tabbedwebview.h" #include "mainapplication.h" #include "qzsettings.h" #include "iconprovider.h" HistorySideBar::HistorySideBar(BrowserWindow* window, QWidget* parent) : QWidget(parent) , ui(new Ui::HistorySideBar) , m_window(window) { ui->setupUi(this); ui->historyTree->setViewType(HistoryTreeView::HistorySidebarViewType); connect(ui->historyTree, &HistoryTreeView::urlActivated, this, &HistorySideBar::urlActivated); connect(ui->historyTree, &HistoryTreeView::urlCtrlActivated, this, &HistorySideBar::urlCtrlActivated); connect(ui->historyTree, &HistoryTreeView::urlShiftActivated, this, &HistorySideBar::urlShiftActivated); connect(ui->historyTree, &HistoryTreeView::contextMenuRequested, this, &HistorySideBar::createContextMenu); connect(ui->search, &QLineEdit::textEdited, ui->historyTree, &HistoryTreeView::search); } void HistorySideBar::urlActivated(const QUrl &url) { openUrl(url); } void HistorySideBar::urlCtrlActivated(const QUrl &url) { openUrlInNewTab(url); } void HistorySideBar::urlShiftActivated(const QUrl &url) { openUrlInNewWindow(url); } void HistorySideBar::openUrl(const QUrl &url) { const QUrl u = !url.isEmpty() ? url : ui->historyTree->selectedUrl(); m_window->weView()->load(u); } void HistorySideBar::openUrlInNewTab(const QUrl &url) { const QUrl u = !url.isEmpty() ? url : ui->historyTree->selectedUrl(); m_window->tabWidget()->addView(u, qzSettings->newTabPosition); } void HistorySideBar::openUrlInNewWindow(const QUrl &url) { const QUrl u = !url.isEmpty() ? url : ui->historyTree->selectedUrl(); mApp->createWindow(Qz::BW_NewWindow, u); } void HistorySideBar::openUrlInNewPrivateWindow(const QUrl &url) { const QUrl u = !url.isEmpty() ? url : ui->historyTree->selectedUrl(); mApp->startPrivateBrowsing(u); } void HistorySideBar::createContextMenu(const QPoint &pos) { QMenu menu; QAction* actNewTab = menu.addAction(IconProvider::newTabIcon(), tr("Open in new tab")); QAction* actNewWindow = menu.addAction(IconProvider::newWindowIcon(), tr("Open in new window")); QAction* actNewPrivateWindow = menu.addAction(IconProvider::privateBrowsingIcon(), tr("Open in new private window")); menu.addSeparator(); QAction* actDelete = menu.addAction(QIcon::fromTheme(QSL("edit-delete")), tr("Delete")); connect(actNewTab, SIGNAL(triggered()), this, SLOT(openUrlInNewTab())); connect(actNewWindow, SIGNAL(triggered()), this, SLOT(openUrlInNewWindow())); connect(actNewPrivateWindow, SIGNAL(triggered()), this, SLOT(openUrlInNewPrivateWindow())); connect(actDelete, &QAction::triggered, ui->historyTree, &HistoryTreeView::removeSelectedItems); if (ui->historyTree->selectedUrl().isEmpty()) { actNewTab->setDisabled(true); actNewWindow->setDisabled(true); actNewPrivateWindow->setDisabled(true); } menu.exec(pos); } +void HistorySideBar::showEvent(QShowEvent *event) +{ + QWidget::showEvent(event); + ui->search->setFocus(); +} + HistorySideBar::~HistorySideBar() { delete ui; } diff --git a/src/lib/sidebar/historysidebar.h b/src/lib/sidebar/historysidebar.h index 369da57e..643e6e81 100644 --- a/src/lib/sidebar/historysidebar.h +++ b/src/lib/sidebar/historysidebar.h @@ -1,58 +1,60 @@ /* ============================================================ * Falkon - Qt web browser * Copyright (C) 2010-2014 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 HISTORYSIDEBAR_H #define HISTORYSIDEBAR_H #include #include #include "qzcommon.h" namespace Ui { class HistorySideBar; } class BrowserWindow; class FALKON_EXPORT HistorySideBar : public QWidget { Q_OBJECT public: explicit HistorySideBar(BrowserWindow* window, QWidget* parent = 0); ~HistorySideBar(); private Q_SLOTS: void urlActivated(const QUrl &url); void urlCtrlActivated(const QUrl &url); void urlShiftActivated(const QUrl &url); void openUrl(const QUrl &url = QUrl()); void openUrlInNewTab(const QUrl &url = QUrl()); void openUrlInNewWindow(const QUrl &url = QUrl()); void openUrlInNewPrivateWindow(const QUrl &url = QUrl()); void createContextMenu(const QPoint &pos); private: + void showEvent(QShowEvent *event) override; + Ui::HistorySideBar* ui; BrowserWindow* m_window; }; #endif // HISTORYSIDEBAR_H