1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 18:56:34 +01:00

[MainMenu] Added MainMenu class that holds all menu actions of window

All actions are now saved in QHash with name, this will make possible
to implement own keyboard shortcuts for actions.
+ WIP cleanup of BrowserWindow class
This commit is contained in:
nowrep 2014-03-10 16:55:11 +01:00
parent fb25ef4ba5
commit e827249f50
26 changed files with 1255 additions and 1060 deletions

File diff suppressed because it is too large Load Diff

View File

@ -32,6 +32,7 @@ class QWebFrame;
class QTimer;
class Menu;
class MainMenu;
class TabWidget;
class TabbedWebView;
class LineEdit;
@ -59,11 +60,12 @@ class QUPZILLA_EXPORT BrowserWindow : public QMainWindow
public:
static const QString WEBKITVERSION;
explicit BrowserWindow(Qz::BrowserWindowType type, QUrl startUrl = QUrl());
explicit BrowserWindow(Qz::BrowserWindowType type, const QUrl &url = QUrl());
~BrowserWindow();
void openWithTab(WebTab* tab);
void setStartTab(WebTab* tab);
void restoreWindowState(const RestoreManager::WindowData &d);
void saveSideBarWidth();
bool fullScreenNavigationVisible() const;
@ -76,7 +78,9 @@ public:
void addBookmark(const QUrl &url, const QString &title);
void addDeleteOnCloseWidget(QWidget* widget);
void restoreWindowState(const RestoreManager::WindowData &d);
void createToolbarsMenu(QMenu* menu);
void createSidebarsMenu(QMenu* menu);
void createEncodingMenu(QMenu* menu);
SideBar* addSideBar();
virtual QMenuBar* menuBar() const;
@ -86,33 +90,27 @@ public:
TabbedWebView* weView() const;
TabbedWebView* weView(int index) const;
LocationBar* locationBar() const;
Qz::BrowserWindowType windowType() const;
TabWidget* tabWidget() { return m_tabWidget; }
BookmarksToolbar* bookmarksToolbar() { return m_bookmarksToolbar; }
StatusBarMessage* statusBarMessage() { return m_statusBarMessage; }
NavigationBar* navigationBar() { return m_navigationBar; }
SideBarManager* sideBarManager() { return m_sideBarManager; }
ProgressBar* progressBar() { return m_progressBar; }
QLabel* ipLabel() { return m_ipLabel; }
AdBlockIcon* adBlockIcon() { return m_adblockIcon; }
QAction* actionRestoreTab() { return m_actionRestoreTab; }
QAction* actionReload() { return m_actionReload; }
QMenu* menuHelp() { return m_menuHelp; }
QMenu* superMenu() { return m_superMenu; }
LocationBar* locationBar() const;
TabWidget* tabWidget() const;
BookmarksToolbar* bookmarksToolbar() const;
StatusBarMessage* statusBarMessage() const;
NavigationBar* navigationBar() const;
SideBarManager* sideBarManager() const;
QLabel* ipLabel() const;
AdBlockIcon* adBlockIcon() const;
QMenu* superMenu() const;
void popupToolbarsMenu(const QPoint &pos);
bool isClosing() const;
QUrl homepageUrl() const;
bool isClosing() { return m_isClosing; }
QUrl homepageUrl() { return m_homepage; }
bool isTransparentBackgroundAllowed() const;
bool isTransparentBackgroundAllowed();
bool tabsOnTop() const;
QAction* action(const QString &name) const;
signals:
void startingCompleted();
void setWebViewMouseTracking(bool state);
public slots:
void goHome();
@ -135,76 +133,36 @@ public slots:
void loadAddress(const QUrl &url);
void showSource(QWebFrame* frame = 0, const QString &selectedHtml = QString());
void printPage(QWebFrame* frame = 0);
void showPageInfo();
private slots:
void addTab();
void openLocation();
void openFile();
void closeWindow();
void loadSettings();
void postLaunch();
void stop();
void reload();
void reloadByPassCache();
void aboutQupZilla();
void addTab();
void savePageScreen();
void aboutToShowFileMenu();
void aboutToHideFileMenu();
void aboutToShowViewMenu();
void aboutToHideViewMenu();
void aboutToShowEditMenu();
void aboutToHideEditMenu();
void aboutToShowToolsMenu();
void aboutToHideToolsMenu();
void aboutToShowEncodingMenu();
void searchOnPage();
void showCookieManager();
void showBookmarksManager();
void showRSSManager();
void showDownloadManager();
void showMenubar();
void showNavigationToolbar();
void showStatusbar();
void showClearPrivateData();
void showPreferences();
void showBookmarkImport();
void showStatusBar();
void refreshHistory();
void newWindow();
void openLocation();
void openFile();
void savePage();
void sendLink();
void webSearch();
// Edit menu actions
void editUndo();
void editRedo();
void editCut();
void editCopy();
void editPaste();
void editSelectAll();
void searchOnPage();
void zoomIn();
void zoomOut();
void zoomReset();
void changeEncoding(QObject* obj = 0);
void changeEncoding();
void triggerCaretBrowsing();
void triggerTabsOnTop(bool enable);
void toggleCaretBrowsing();
void toggleTabsOnTop(bool enable);
void closeWindow();
bool quitApp();
void closeTab();
void restoreClosedTab(QObject* obj = 0);
void restoreAllClosedTabs();
void clearClosedTabsList();
void hideNavigationSlot();
#ifdef Q_OS_MAC
void refreshStateOfAllActions();
#endif
#ifdef Q_OS_WIN
void applyBlurToMainWindow(bool force = false);
#endif
@ -216,11 +174,10 @@ private:
void keyReleaseEvent(QKeyEvent* event);
void closeEvent(QCloseEvent* event);
SearchToolBar* searchToolBar();
SearchToolBar* searchToolBar() const;
void setupUi();
void setupMenu();
void setupOtherActions();
#ifdef Q_OS_MAC
void setupMacMenu();
#endif
@ -243,82 +200,39 @@ private:
void moveToVirtualDesktop(int desktopId);
#endif
bool bookmarksMenuChanged();
void setBookmarksMenuChanged(bool changed);
QAction* menuBookmarksAction();
void setMenuBookmarksAction(QAction* action);
QKeySequence actionShortcut(QKeySequence shortcut, QKeySequence fallBack = QKeySequence(),
QKeySequence shortcutRTL = QKeySequence(), QKeySequence fallbackRTL = QKeySequence());
bool m_historyMenuChanged;
bool m_bookmarksMenuChanged;
bool m_isClosing;
bool m_isStarting;
QUrl m_startingUrl;
QUrl m_startUrl;
QUrl m_homepage;
Qz::BrowserWindowType m_windowType;
WebTab* m_startTab;
QVBoxLayout* m_mainLayout;
QSplitter* m_mainSplitter;
QMenu* m_superMenu;
QMenu* m_menuFile;
QMenu* m_menuEdit;
QMenu* m_menuTools;
QMenu* m_menuHelp;
QMenu* m_menuView;
QMenu* m_toolbarsMenu;
BookmarksMenu* m_menuBookmarks;
HistoryMenu* m_menuHistory;
QMenu* m_menuEncoding;
QAction* m_menuBookmarksAction;
QAction* m_actionAbout;
QAction* m_actionPreferences;
QAction* m_actionQuit;
QAction* m_actionCloseWindow;
QAction* m_actionShowToolbar;
QAction* m_actionShowBookmarksToolbar;
QAction* m_actionShowStatusbar;
#ifndef Q_OS_MAC
QAction* m_actionShowMenubar;
#endif
QAction* m_actionTabsOnTop;
QAction* m_actionShowFullScreen;
QAction* m_actionShowBookmarksSideBar;
QAction* m_actionShowHistorySideBar;
QAction* m_actionShowRssSideBar;
QAction* m_actionPrivateBrowsing;
QAction* m_actionStop;
QAction* m_actionReload;
QAction* m_actionCaretBrowsing;
QAction* m_actionRestoreTab;
QAction* m_actionPageInfo;
QAction* m_actionPageSource;
QLabel* m_privateBrowsing;
AdBlockIcon* m_adblockIcon;
QPointer<WebInspectorDockWidget> m_webInspectorDock;
QWidget* m_navigationContainer;
BookmarksToolbar* m_bookmarksToolbar;
TabWidget* m_tabWidget;
QPointer<SideBar> m_sideBar;
SideBarManager* m_sideBarManager;
StatusBarMessage* m_statusBarMessage;
NavigationBar* m_navigationBar;
QWidget* m_navigationContainer;
NavigationBar* m_navigationToolbar;
BookmarksToolbar* m_bookmarksToolbar;
ProgressBar* m_progressBar;
QLabel* m_ipLabel;
QString m_lastWindowTitle;
QMenu* m_superMenu;
MainMenu* m_mainMenu;
int m_sideBarWidth;
int m_webViewWidth;
bool m_usingTransparentBackground;
bool m_useTransparentBackground;
// Shortcuts
bool m_useTabNumberShortcuts;
@ -331,7 +245,6 @@ private:
QTimer* m_hideNavigationTimer;
QList<QPointer<QWidget> > m_deleteOnCloseWidgets;
mutable int m_tabsOnTopState;
};
#endif // QUPZILLA_H

View File

@ -21,7 +21,9 @@
#include <QString>
#include <QHash>
class DataPaths
#include "qzcommon.h"
class QUPZILLA_EXPORT DataPaths
{
public:
enum Path {

View File

@ -793,12 +793,11 @@ void MainApplication::messageReceived(QString message)
void MainApplication::windowDestroyed(QObject *window)
{
Q_ASSERT(qobject_cast<BrowserWindow*>(window));
Q_ASSERT(m_windows.contains(qobject_cast<BrowserWindow*>(window)));
// qobject_cast doesn't work because QObject::destroyed is emitted from destructor
Q_ASSERT(static_cast<BrowserWindow*>(window));
Q_ASSERT(m_windows.contains(static_cast<BrowserWindow*>(window)));
m_windows.removeOne(qobject_cast<BrowserWindow*>(window));
qDebug("Destroyed");
m_windows.removeOne(static_cast<BrowserWindow*>(window));
}
void MainApplication::loadSettings()

681
src/lib/app/mainmenu.cpp Normal file
View File

@ -0,0 +1,681 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2014 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 "mainmenu.h"
#include "siteinfo.h"
#include "tabwidget.h"
#include "historymenu.h"
#include "aboutdialog.h"
#include "preferences.h"
#include "iconprovider.h"
#include "cookiemanager.h"
#include "bookmarksmenu.h"
#include "tabbedwebview.h"
#include "browserwindow.h"
#include "adblockmanager.h"
#include "downloadmanager.h"
#include "mainapplication.h"
#include "browsinglibrary.h"
#include "clearprivatedata.h"
#include <QApplication>
#include <QMetaObject>
#include <QStatusBar>
#include <QWebPage>
#include <QMenuBar>
static QKeySequence actionShortcut(QKeySequence shortcut, QKeySequence fallBack, QKeySequence shortcutRTL = QKeySequence(), QKeySequence fallbackRTL = QKeySequence())
{
if (QApplication::isRightToLeft() && (!shortcutRTL.isEmpty() || !fallbackRTL.isEmpty())) {
return (shortcutRTL.isEmpty() ? fallbackRTL : shortcutRTL);
}
else {
return (shortcut.isEmpty() ? fallBack : shortcut);
}
}
static void callSlot(BrowserWindow* window, const char* slot)
{
if (window) {
QMetaObject::invokeMethod(window, slot);
}
}
MainMenu::MainMenu(BrowserWindow* window, QWidget* parent)
: QMenu(parent)
, m_window(window)
{
Q_ASSERT(m_window);
init();
// TODO: QSL with all strings
}
void MainMenu::setWindow(BrowserWindow* window)
{
Q_ASSERT(window);
m_window = window;
addActionsToWindow();
}
void MainMenu::initMenuBar(QMenuBar* menuBar) const
{
menuBar->addMenu(m_menuFile);
menuBar->addMenu(m_menuEdit);
menuBar->addMenu(m_menuView);
menuBar->addMenu(m_menuHistory);
menuBar->addMenu(m_menuBookmarks);
menuBar->addMenu(m_menuTools);
menuBar->addMenu(m_menuHelp);
}
void MainMenu::initSuperMenu(QMenu* superMenu) const
{
superMenu->addAction(m_actions[QSL("File/NewTab")]);
superMenu->addAction(m_actions[QSL("File/NewWindow")]);
superMenu->addAction(m_actions[QSL("File/NewPrivateWindow")]);
superMenu->addAction(m_actions[QSL("File/OpenFile")]);
superMenu->addSeparator();
superMenu->addAction(m_actions[QSL("File/SavePageScreen")]);
superMenu->addAction(m_actions[QSL("File/SendLink")]);
superMenu->addSeparator();
superMenu->addAction(m_actions[QSL("Edit/SelectAll")]);
superMenu->addAction(m_actions[QSL("Edit/Find")]);
superMenu->addSeparator();
superMenu->addAction(m_menuHistory->actions().at(3));
superMenu->addAction(m_menuBookmarks->actions().at(2));
superMenu->addSeparator();
superMenu->addAction(m_actions[QSL("Standard/Preferences")]);
superMenu->addSeparator();
superMenu->addMenu(m_menuView);
superMenu->addMenu(m_menuHistory);
superMenu->addMenu(m_menuBookmarks);
superMenu->addMenu(m_menuTools);
superMenu->addSeparator();
superMenu->addAction(m_actions[QSL("Standard/About")]);
superMenu->addAction(m_actions[QSL("Help/InfoAboutApp")]);
superMenu->addAction(m_actions[QSL("Help/ConfigInfo")]);
superMenu->addAction(m_actions[QSL("Help/ReportIssue")]);
superMenu->addSeparator();
superMenu->addAction(m_actions[QSL("Standard/Quit")]);
}
QAction* MainMenu::action(const QString &name) const
{
Q_ASSERT(m_actions.value(name));
return m_actions.value(name);
}
void MainMenu::showAboutDialog()
{
AboutDialog about(m_window);
about.exec();
}
void MainMenu::showPreferences()
{
Preferences* prefs = new Preferences(m_window, this);
prefs->show();
}
void MainMenu::quitApplication()
{
mApp->quitApplication();
}
void MainMenu::newTab()
{
callSlot(m_window, "addTab");
}
void MainMenu::newWindow()
{
mApp->createWindow(Qz::BW_NewWindow);
}
void MainMenu::newPrivateWindow()
{
mApp->startPrivateBrowsing();
}
void MainMenu::openLocation()
{
callSlot(m_window, "openLocation");
}
void MainMenu::openFile()
{
callSlot(m_window, "openFile");
}
void MainMenu::closeWindow()
{
callSlot(m_window, "closeWindow");
}
void MainMenu::savePageAs()
{
if (m_window) {
m_window->weView()->savePageAs();
}
}
void MainMenu::savePageScreen()
{
callSlot(m_window, "savePageScreen");
}
void MainMenu::sendLink()
{
if (m_window) {
m_window->weView()->savePageAs();
}
}
void MainMenu::printPage()
{
callSlot(m_window, "printPage");
}
void MainMenu::editUndo()
{
if (m_window) {
m_window->weView()->editUndo();
}
}
void MainMenu::editRedo()
{
if (m_window) {
m_window->weView()->editRedo();
}
}
void MainMenu::editCut()
{
if (m_window) {
m_window->weView()->editCut();
}
}
void MainMenu::editCopy()
{
if (m_window) {
m_window->weView()->editCopy();
}
}
void MainMenu::editPaste()
{
if (m_window) {
m_window->weView()->editPaste();
}
}
void MainMenu::editSelectAll()
{
if (m_window) {
m_window->weView()->editSelectAll();
}
}
void MainMenu::editFind()
{
callSlot(m_window, "searchOnPage");
}
void MainMenu::showStatusBar()
{
callSlot(m_window, "showStatusBar");
}
void MainMenu::stop()
{
if (m_window) {
m_window->weView()->stop();
}
}
void MainMenu::reload()
{
if (m_window) {
m_window->weView()->reload();
}
}
void MainMenu::zoomIn()
{
if (m_window) {
m_window->weView()->zoomIn();
}
}
void MainMenu::zoomOut()
{
if (m_window) {
m_window->weView()->zoomOut();
}
}
void MainMenu::zoomReset()
{
if (m_window) {
m_window->weView()->zoomReset();
}
}
void MainMenu::toggleCaretBrowsing()
{
callSlot(m_window, "toggleCaretBrowsing");
}
void MainMenu::showPageSource()
{
callSlot(m_window, "showSource");
}
void MainMenu::showFullScreen()
{
callSlot(m_window, "toggleFullScreen");
}
void MainMenu::webSearch()
{
callSlot(m_window, "webSearch");
}
void MainMenu::showSiteInfo()
{
if (m_window) {
SiteInfo* info = new SiteInfo(m_window->weView(), m_window);
info->setAttribute(Qt::WA_DeleteOnClose);
info->show();
}
}
void MainMenu::showDownloadManager()
{
DownloadManager* m = mApp->downloadManager();
m->show();
m->raise();
}
void MainMenu::showCookieManager()
{
CookieManager* m = mApp->cookieManager();
m->refreshTable();
m->show();
m->raise();
}
void MainMenu::showAdBlockDialog()
{
AdBlockManager::instance()->showDialog();
}
void MainMenu::showRssManager()
{
if (m_window) {
mApp->browsingLibrary()->showRSS(m_window);
}
}
void MainMenu::showWebInspector()
{
callSlot(m_window, "showWebInspector");
}
void MainMenu::showClearRecentHistoryDialog()
{
ClearPrivateData clear(m_window);
clear.exec();
}
void MainMenu::aboutQt()
{
QApplication::aboutQt();
}
void MainMenu::showInfoAboutApp()
{
if (m_window) {
m_window->tabWidget()->addView(QUrl(QSL("qupzilla:about")), Qz::NT_CleanSelectedTab);
}
}
void MainMenu::showConfigInfo()
{
if (m_window) {
m_window->tabWidget()->addView(QUrl(QSL("qupzilla:config")), Qz::NT_CleanSelectedTab);
}
}
void MainMenu::reportIssue()
{
if (m_window) {
m_window->tabWidget()->addView(QUrl(QSL("qupzilla:reportbug")), Qz::NT_CleanSelectedTab);
}
}
void MainMenu::restoreClosedTab()
{
if (m_window) {
m_window->tabWidget()->restoreClosedTab();
}
}
void MainMenu::aboutToShowFileMenu()
{
#ifndef Q_OS_MAC
m_actions[QSL("File/CloseWindow")]->setEnabled(mApp->windowCount() > 1);
#endif
}
void MainMenu::aboutToHideFileMenu()
{
m_actions[QSL("File/CloseWindow")]->setEnabled(true);
}
void MainMenu::aboutToShowViewMenu()
{
#if 0
m_actionShowToolbar->setChecked(m_navigationBar->isVisible());
#ifndef Q_OS_MAC
m_actionShowMenubar->setChecked(menuBar()->isVisible());
#else
m_sideBarManager->setSideBarMenu(m_menuView->actions().at(1)->menu());
#endif
m_actionTabsOnTop->setChecked(tabsOnTop());
m_actionShowBookmarksToolbar->setChecked(m_bookmarksToolbar->isVisible());
#endif
if (!m_window) {
return;
}
m_actions[QSL("View/ShowStatusBar")]->setChecked(m_window->statusBar()->isVisible());
m_actions[QSL("View/FullScreen")]->setChecked(m_window->isFullScreen());
m_actions[QSL("View/PageSource")]->setEnabled(true);
#if QTWEBKIT_FROM_2_3
m_actions[QSL("View/CaretBrowsing")]->setChecked(m_window->weView()->settings()->testAttribute(QWebSettings::CaretBrowsingEnabled));
#endif
}
void MainMenu::aboutToHideViewMenu()
{
m_actions[QSL("View/PageSource")]->setEnabled(false);
}
void MainMenu::aboutToShowEditMenu()
{
if (!m_window) {
return;
}
WebView* view = m_window->weView();
m_actions[QSL("Edit/Undo")]->setEnabled(view->pageAction(QWebPage::Undo)->isEnabled());
m_actions[QSL("Edit/Redo")]->setEnabled(view->pageAction(QWebPage::Redo)->isEnabled());
m_actions[QSL("Edit/Cut")]->setEnabled(view->pageAction(QWebPage::Cut)->isEnabled());
m_actions[QSL("Edit/Copy")]->setEnabled(view->pageAction(QWebPage::Copy)->isEnabled());
m_actions[QSL("Edit/Paste")]->setEnabled(view->pageAction(QWebPage::Paste)->isEnabled());
m_actions[QSL("Edit/SelectAll")]->setEnabled(view->pageAction(QWebPage::SelectAll)->isEnabled());
}
void MainMenu::aboutToHideEditMenu()
{
m_actions[QSL("Edit/Undo")]->setEnabled(false);
m_actions[QSL("Edit/Redo")]->setEnabled(false);
m_actions[QSL("Edit/Cut")]->setEnabled(false);
m_actions[QSL("Edit/Copy")]->setEnabled(false);
m_actions[QSL("Edit/Paste")]->setEnabled(false);
m_actions[QSL("Edit/SelectAll")]->setEnabled(false);
}
void MainMenu::aboutToShowToolsMenu()
{
m_actions[QSL("Tools/SiteInfo")]->setEnabled(true);
}
void MainMenu::aboutToHideToolsMenu()
{
m_actions[QSL("Tools/SiteInfo")]->setEnabled(false);
}
void MainMenu::aboutToShowToolbarsMenu()
{
QMenu* menu = qobject_cast<QMenu*>(sender());
Q_ASSERT(menu);
if (m_window) {
menu->clear();
m_window->createToolbarsMenu(menu);
}
}
void MainMenu::aboutToShowSidebarsMenu()
{
QMenu* menu = qobject_cast<QMenu*>(sender());
Q_ASSERT(menu);
if (m_window) {
menu->clear();
m_window->createSidebarsMenu(menu);
}
}
void MainMenu::aboutToShowEncodingMenu()
{
QMenu* menu = qobject_cast<QMenu*>(sender());
Q_ASSERT(menu);
if (m_window) {
menu->clear();
m_window->createEncodingMenu(menu);
}
}
void MainMenu::init()
{
#define ADD_ACTION(name, menu, icon, trName, slot, shortcut) \
action = menu->addAction(icon, trName); \
action->setShortcut(QKeySequence(QSL(shortcut))); \
connect(action, SIGNAL(triggered()), this, slot); \
m_actions[QSL(name)] = action
#define ADD_CHECKABLE_ACTION(name, menu, icon, trName, slot, shortcut) \
action = menu->addAction(icon, trName); \
action->setShortcut(QKeySequence(QSL(shortcut))); \
action->setCheckable(true); \
connect(action, SIGNAL(triggered(bool)), this, slot); \
m_actions[QSL(name)] = action
// Standard actions - needed on Mac to be placed correctly in "application" menu
QAction* action = new QAction(QIcon::fromTheme(QSL("help-about")), tr("&About QupZilla"), this);
action->setMenuRole(QAction::AboutRole);
connect(action, SIGNAL(triggered()), this, SLOT(showAboutDialog()));
m_actions[QSL("Standard/About")] = action;
action = new QAction(QIcon::fromTheme(QSL("preferences-desktop"), QIcon(QSL(":/icons/theme/settings.png"))), tr("Pr&eferences"), this);
action->setMenuRole(QAction::PreferencesRole);
action->setShortcut(QKeySequence(QKeySequence::Preferences));
connect(action, SIGNAL(triggered()), this, SLOT(showPreferences()));
m_actions[QSL("Standard/Preferences")] = action;
action = new QAction(QIcon::fromTheme(QSL("application-exit")), tr("Quit"), this);
action->setMenuRole(QAction::QuitRole);
action->setShortcut(actionShortcut(QKeySequence::Quit, QKeySequence(QSL("Ctrl+Q"))));
connect(action, SIGNAL(triggered()), this, SLOT(quitApplication()));
m_actions[QSL("Standard/Quit")] = action;
// File menu
m_menuFile = new QMenu(tr("&File"));
connect(m_menuFile, SIGNAL(aboutToShow()), this, SLOT(aboutToShowFileMenu()));
connect(m_menuFile, SIGNAL(aboutToHide()), this, SLOT(aboutToHideFileMenu()));
ADD_ACTION("File/NewTab", m_menuFile, QIcon::fromTheme(QSL("tab-new"), QIcon(QSL(":/icons/menu/tab-new.png"))), tr("New Tab"), SLOT(newTab()), "Ctrl+T");
ADD_ACTION("File/NewWindow", m_menuFile, QIcon::fromTheme(QSL("window-new")), tr("&New Window"), SLOT(newWindow()), "Ctrl+N");
ADD_ACTION("File/NewPrivateWindow", m_menuFile, QIcon(":/icons/locationbar/privatebrowsing.png"), tr("New &Private Window"), SLOT(newPrivateWindow()), "Ctrl+Shift+P");
ADD_ACTION("File/OpenLocation", m_menuFile, QIcon::fromTheme(QSL("document-open-remote")), tr("Open Location"), SLOT(openLocation()), "Ctrl+L");
ADD_ACTION("File/OpenFile", m_menuFile, QIcon::fromTheme("document-open"), tr("Open &File..."), SLOT(openFile()), "Ctrl+O");
ADD_ACTION("File/CloseWindow", m_menuFile, QIcon::fromTheme("window-close"), tr("Close Window"), SLOT(closeWindow()), "Ctrl+Shift+W");
m_menuFile->addSeparator();
ADD_ACTION("File/SavePageAs", m_menuFile, QIcon::fromTheme("document-save"), tr("&Save Page As..."), SLOT(savePageAs()), "Ctrl+S");
ADD_ACTION("File/SavePageScreen", m_menuFile, QIcon::fromTheme("image-loading"), tr("Save Page Screen"), SLOT(savePageScreen()), "Ctrl+Shift+S");
ADD_ACTION("File/SendLink", m_menuFile, QIcon::fromTheme("mail-message-new"), tr("Send Link..."), SLOT(sendLink()), "");
ADD_ACTION("File/Print", m_menuFile, QIcon::fromTheme("document-print"), tr("&Print..."), SLOT(printPage()), "Ctrl+P");
m_menuFile->addSeparator();
m_menuFile->addAction(m_actions[QSL("Standard/Quit")]);
// Edit menu
m_menuEdit = new QMenu(tr("&Edit"));
connect(m_menuEdit, SIGNAL(aboutToShow()), this, SLOT(aboutToShowEditMenu()));
connect(m_menuEdit, SIGNAL(aboutToHide()), this, SLOT(aboutToHideEditMenu()));
ADD_ACTION("Edit/Undo", m_menuEdit, QIcon::fromTheme("edit-undo"), tr("&Undo"), SLOT(editUndo()), "Ctrl+Z");
ADD_ACTION("Edit/Redo", m_menuEdit, QIcon::fromTheme("edit-redo"), tr("&Redo"), SLOT(editRedo()), "Ctrl+Shift+Z");
m_menuEdit->addSeparator();
ADD_ACTION("Edit/Cut", m_menuEdit, QIcon::fromTheme("edit-cut"), tr("&Cut"), SLOT(editCut()), "Ctrl+X");
ADD_ACTION("Edit/Copy", m_menuEdit, QIcon::fromTheme("edit-copy"), tr("C&opy"), SLOT(editCopy()), "Ctrl+C");
ADD_ACTION("Edit/Paste", m_menuEdit, QIcon::fromTheme("edit-paste"), tr("&Paste"), SLOT(editPaste()), "Ctrl+V");
m_menuEdit->addSeparator();
ADD_ACTION("Edit/SelectAll", m_menuEdit, QIcon::fromTheme("edit-select-all"), tr("Select &All"), SLOT(editSelectAll()), "Ctrl+A");
ADD_ACTION("Edit/Find", m_menuEdit, QIcon::fromTheme("edit-find"), tr("&Find"), SLOT(editFind()), "Ctrl+F");
m_menuEdit->addSeparator();
// View menu
m_menuView = new QMenu(tr("&View"));
connect(m_menuView, SIGNAL(aboutToShow()), this, SLOT(aboutToShowViewMenu()));
connect(m_menuView, SIGNAL(aboutToHide()), this, SLOT(aboutToHideViewMenu()));
QMenu* toolbarsMenu = new QMenu(tr("Toolbars"));
connect(toolbarsMenu, SIGNAL(aboutToShow()), this, SLOT(aboutToShowToolbarsMenu()));
QMenu* sidebarsMenu = new QMenu(tr("Sidebars"));
connect(sidebarsMenu, SIGNAL(aboutToShow()), this, SLOT(aboutToShowSidebarsMenu()));
QMenu* encodingMenu = new QMenu(tr("Character &Encoding"));
connect(encodingMenu, SIGNAL(aboutToShow()), this, SLOT(aboutToShowEncodingMenu()));
m_menuView->addMenu(toolbarsMenu);
m_menuView->addMenu(sidebarsMenu);
ADD_CHECKABLE_ACTION("View/ShowStatusBar", m_menuView, QIcon(), tr("Sta&tus Bar"), SLOT(showStatusBar()), "");
m_menuView->addSeparator();
ADD_ACTION("View/Stop", m_menuView, IconProvider::standardIcon(QStyle::SP_BrowserStop), tr("&Stop"), SLOT(stop()), "Esc");
ADD_ACTION("View/Reload", m_menuView, IconProvider::standardIcon(QStyle::SP_BrowserReload), tr("&Reload"), SLOT(reload()), "F5");
m_menuView->addSeparator();
ADD_ACTION("View/ZoomIn", m_menuView, QIcon::fromTheme("zoom-in"), tr("Zoom &In"), SLOT(zoomIn()), "Ctrl++");
ADD_ACTION("View/ZoomOut", m_menuView, QIcon::fromTheme("zoom-out"), tr("Zoom &Out"), SLOT(zoomOut()), "Ctrl+-");
ADD_ACTION("View/ZoomReset", m_menuView, QIcon::fromTheme("zoom-original"), tr("Reset"), SLOT(zoomReset()), "Ctrl+0");
m_menuView->addSeparator();
ADD_CHECKABLE_ACTION("View/CaretBrowsing", m_menuView, QIcon(), tr("&Caret Browsing"), SLOT(toggleCaretBrowsing()), "F7");
m_menuView->addMenu(encodingMenu);
m_menuView->addSeparator();
ADD_ACTION("View/PageSource", m_menuView, QIcon::fromTheme("text-html"), tr("&Page Source"), SLOT(showPageSource()), "");
ADD_CHECKABLE_ACTION("View/FullScreen", m_menuView, QIcon(), tr("&FullScreen"), SLOT(showFullScreen()), "F11");
// Tools menu
m_menuTools = new QMenu(tr("&Tools"));
connect(m_menuTools, SIGNAL(aboutToShow()), this, SLOT(aboutToShowToolsMenu()));
connect(m_menuTools, SIGNAL(aboutToHide()), this, SLOT(aboutToHideToolsMenu()));
ADD_ACTION("Tools/WebSearch", m_menuTools, QIcon(), tr("&Web Search"), SLOT(webSearch()), "Ctrl+K");
ADD_ACTION("Tools/SiteInfo", m_menuTools, QIcon::fromTheme("dialog-information"), tr("Site &Info"), SLOT(showSiteInfo()), "");
m_menuTools->addSeparator();
ADD_ACTION("Tools/DownloadManager", m_menuTools, QIcon(), tr("&Download Manager"), SLOT(showDownloadManager()), "Ctrl+Y");
ADD_ACTION("Tools/CookiesManager", m_menuTools, QIcon(), tr("&Cookies Manager"), SLOT(showCookieManager()), "");
ADD_ACTION("Tools/AdBlock", m_menuTools, QIcon(), tr("&AdBlock"), SLOT(showAdBlockDialog()), "");
ADD_ACTION("Tools/RssReader", m_menuTools, QIcon(":/icons/menu/rss.png"), tr("RSS &Reader"), SLOT(showRssManager()), "");
ADD_ACTION("Tools/WebInspector", m_menuTools, QIcon(), tr("Web In&spector"), SLOT(showWebInspector()), "Ctrl+Shift+I");
ADD_ACTION("Tools/ClearRecentHistory", m_menuTools, QIcon::fromTheme("edit-clear"), tr("Clear Recent &History"), SLOT(showClearRecentHistoryDialog()), "Ctrl+Shift+Del");
m_menuTools->addSeparator();
// Help menu
m_menuHelp = new QMenu(tr("&Help"));
#ifndef Q_OS_MAC
ADD_ACTION("Help/AboutQt", m_menuHelp, QIcon(":/icons/menu/qt.png"), tr("About &Qt"), SLOT(aboutQt()), "");
m_menuHelp->addAction(m_actions[QSL("Standard/About")]);
m_menuHelp->addSeparator();
#endif
ADD_ACTION("Help/InfoAboutApp", m_menuHelp, QIcon::fromTheme("help-contents"), tr("Information about application"), SLOT(showInfoAboutApp()), "");
ADD_ACTION("Help/ConfigInfo", m_menuHelp, QIcon(), tr("Configuration Information"), SLOT(showConfigInfo()), "");
ADD_ACTION("Help/ReportIssue", m_menuHelp, QIcon(), tr("Report &Issue"), SLOT(reportIssue()), "");
m_actions[QSL("Help/InfoAboutApp")]->setShortcut(QKeySequence(QKeySequence::HelpContents));
// History menu
m_menuHistory = new HistoryMenu();
m_menuHistory->setMainWindow(m_window);
// Bookmarks menu
m_menuBookmarks = new BookmarksMenu();
m_menuBookmarks->setMainWindow(m_window);
// Other actions
action = new QAction(QIcon::fromTheme("user-trash"), tr("Restore &Closed Tab"), this);
action->setShortcut(QKeySequence("Ctrl+Shift+T"));
connect(action, SIGNAL(triggered()), this, SLOT(restoreClosedTab()));
m_actions[QSL("Other/RestoreClosedTab")] = action;
#ifdef Q_OS_MAC
m_actions[QSL("View/FullScreen")]->setShortcut(QKeySequence("F11"));
// Add standard actions to File Menu (as it won't be ever cleared) and Mac menubar should move them to "Application" menu
m_menuFile->addAction(m_actions[QSL("Standard/About")]);
m_menuFile->addAction(m_actions[QSL("Standard/Preferences")]);
#endif
#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC)
m_menuEdit->addAction(m_actions["Standard/Preferences"]);
#elif !defined(Q_OS_MAC)
m_menuTools->addAction(m_actions[QSL("Standard/Preferences")]);
#endif
#ifndef QTWEBKIT_FROM_2_3
m_actions[QSL("View/CaretBrowsing")]->setVisible(false);
#endif
addActionsToWindow();
}
void MainMenu::addActionsToWindow()
{
// Make shortcuts available even in fullscreen (hidden menu)
QList<QAction*> actions;
actions << m_menuFile->actions();
actions << m_menuEdit->actions();
actions << m_menuView->actions();
actions << m_menuTools->actions();
actions << m_menuHelp->actions();
actions << m_menuHistory->actions();
actions << m_menuBookmarks->actions();
actions << m_actions[QSL("Other/RestoreClosedTab")];
for (int i = 0; i < actions.size(); ++i) {
QAction* action = actions.at(i);
if (action->menu()) {
actions += action->menu()->actions();
}
m_window->addAction(action);
}
}

134
src/lib/app/mainmenu.h Normal file
View File

@ -0,0 +1,134 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2014 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 MAINMENU_H
#define MAINMENU_H
#include <QMenu>
#include <QHash>
#include <QPointer>
#include "qzcommon.h"
class QMenuBar;
class HistoryMenu;
class BookmarksMenu;
class BrowserWindow;
class QUPZILLA_EXPORT MainMenu : public QMenu
{
Q_OBJECT
public:
explicit MainMenu(BrowserWindow* window, QWidget* parent = 0);
void setWindow(BrowserWindow* window);
void initMenuBar(QMenuBar* menuBar) const;
void initSuperMenu(QMenu* superMenu) const;
QAction* action(const QString &name) const;
private slots:
// Standard actions
void showAboutDialog();
void showPreferences();
void quitApplication();
// File menu
void newTab();
void newWindow();
void newPrivateWindow();
void openLocation();
void openFile();
void closeWindow();
void savePageAs();
void savePageScreen();
void sendLink();
void printPage();
// Edit menu
void editUndo();
void editRedo();
void editCut();
void editCopy();
void editPaste();
void editSelectAll();
void editFind();
// View menu
void showStatusBar();
void stop();
void reload();
void zoomIn();
void zoomOut();
void zoomReset();
void toggleCaretBrowsing();
void showPageSource();
void showFullScreen();
// Tools menu
void webSearch();
void showSiteInfo();
void showDownloadManager();
void showCookieManager();
void showAdBlockDialog();
void showRssManager();
void showWebInspector();
void showClearRecentHistoryDialog();
// Help menu
void aboutQt();
void showInfoAboutApp();
void showConfigInfo();
void reportIssue();
// Other actions
void restoreClosedTab();
void aboutToShowFileMenu();
void aboutToHideFileMenu();
void aboutToShowViewMenu();
void aboutToHideViewMenu();
void aboutToShowEditMenu();
void aboutToHideEditMenu();
void aboutToShowToolsMenu();
void aboutToHideToolsMenu();
void aboutToShowToolbarsMenu();
void aboutToShowSidebarsMenu();
void aboutToShowEncodingMenu();
private:
void init();
void addActionsToWindow();
QHash<QString, QAction*> m_actions;
QPointer<BrowserWindow> m_window;
QMenu* m_menuFile;
QMenu* m_menuEdit;
QMenu* m_menuView;
QMenu* m_menuTools;
QMenu* m_menuHelp;
HistoryMenu* m_menuHistory;
BookmarksMenu* m_menuBookmarks;
};
#endif // MAINMENU_H

View File

@ -35,6 +35,18 @@
#define Q_LIKELY(x) x
#endif
#ifndef QSL
#if QT_VERSION >= 0x050000
#define QSL(x) QStringLiteral(x)
#else
#define QSL(x) QLatin1String(x)
#endif
#endif
#ifndef QL1S
#define QL1S(x) QLatin1String(x)
#endif
namespace Qz
{
// Version of session.dat file

View File

@ -259,7 +259,8 @@ SOURCES += \
app/browserwindow.cpp \
history/historymenu.cpp \
app/datapaths.cpp \
app/profilemanager.cpp
app/profilemanager.cpp \
app/mainmenu.cpp
HEADERS += \
@ -459,7 +460,8 @@ HEADERS += \
app/qzcommon.h \
history/historymenu.h \
app/datapaths.h \
app/profilemanager.h
app/profilemanager.h \
app/mainmenu.h
FORMS += \
preferences/autofillmanager.ui \

View File

@ -182,8 +182,8 @@ NavigationBar::NavigationBar(BrowserWindow* window)
connect(m_buttonNext, SIGNAL(middleMouseClicked()), this, SLOT(goForwardInNewTab()));
connect(m_buttonNext, SIGNAL(controlClicked()), this, SLOT(goForwardInNewTab()));
connect(m_reloadStop->buttonStop(), SIGNAL(clicked()), m_window, SLOT(stop()));
connect(m_reloadStop->buttonReload(), SIGNAL(clicked()), m_window, SLOT(reload()));
connect(m_reloadStop->buttonStop(), SIGNAL(clicked()), this, SLOT(stop()));
connect(m_reloadStop->buttonReload(), SIGNAL(clicked()), this, SLOT(reload()));
connect(m_buttonHome, SIGNAL(clicked()), m_window, SLOT(goHome()));
connect(m_buttonHome, SIGNAL(middleMouseClicked()), m_window, SLOT(goHomeInNewTab()));
connect(m_buttonHome, SIGNAL(controlClicked()), m_window, SLOT(goHomeInNewTab()));
@ -319,7 +319,9 @@ void NavigationBar::clearHistory()
void NavigationBar::contextMenuRequested(const QPoint &pos)
{
m_window->popupToolbarsMenu(mapToGlobal(pos));
QMenu menu;
m_window->createToolbarsMenu(&menu);
menu.exec(mapToGlobal(pos));
}
void NavigationBar::goAtHistoryIndex()
@ -365,6 +367,16 @@ void NavigationBar::refreshHistory()
m_buttonNext->setEnabled(history->canGoForward());
}
void NavigationBar::stop()
{
m_window->action(QSL("View/Stop"))->trigger();
}
void NavigationBar::reload()
{
m_window->action(QSL("View/Reload"))->trigger();
}
void NavigationBar::goBack()
{
QWebHistory* history = m_window->weView()->page()->history();

View File

@ -52,7 +52,7 @@ public:
ToolButton* buttonAddTab() { return m_buttonAddTab; }
ToolButton* buttonExitFullscreen() { return m_exitFullscreen; }
ReloadStopButton* buttonReloadStop() { return m_reloadStop; }
WebSearchBar* searchLine() { return m_searchLine; }
WebSearchBar* webSearchBar() { return m_searchLine; }
QSplitter* splitter() { return m_navigationSplitter; }
void setSuperMenuVisible(bool visible);
@ -68,6 +68,8 @@ signals:
public slots:
void refreshHistory();
void stop();
void reload();
void goBack();
void goBackInNewTab();
void goForward();

View File

@ -17,13 +17,11 @@
* ============================================================ */
#include "navigationcontainer.h"
#include "qzsettings.h"
#include "browserwindow.h"
#include <QPainter>
NavigationContainer::NavigationContainer(BrowserWindow* parent)
NavigationContainer::NavigationContainer(QWidget* parent)
: QWidget(parent)
, m_window(parent)
{
}
@ -31,12 +29,13 @@ void NavigationContainer::paintEvent(QPaintEvent* event)
{
QWidget::paintEvent(event);
if (m_window->tabsOnTop()) {
// Draw line at the bottom of navigation bar if tabs are on top
// To visually distinguish navigation bar from the page
if (qzSettings->tabsOnTop) {
QPainter p(this);
QRect lineRect(0, height() - 1, width(), 1);
QColor c = m_window->palette().window().color().darker(125);
QColor c = palette().window().color().darker(125);
p.fillRect(lineRect, c);
}
}

View File

@ -22,18 +22,14 @@
#include "qzsettings.h"
class BrowserWindow;
class QUPZILLA_EXPORT NavigationContainer : public QWidget
{
public:
explicit NavigationContainer(BrowserWindow* parent = 0);
explicit NavigationContainer(QWidget* parent = 0);
private:
void paintEvent(QPaintEvent* event);
BrowserWindow* m_window;
};
#endif // NAVIGATIONCONTAINER_H

View File

@ -39,9 +39,8 @@
#include <QCloseEvent>
#include <QFileInfo>
ClearPrivateData::ClearPrivateData(BrowserWindow* window, QWidget* parent)
ClearPrivateData::ClearPrivateData(QWidget* parent)
: QDialog(parent)
, m_window(window)
, ui(new Ui::ClearPrivateData)
{
ui->setupUi(this);

View File

@ -27,12 +27,11 @@ namespace Ui
class ClearPrivateData;
}
class BrowserWindow;
class QUPZILLA_EXPORT ClearPrivateData : public QDialog
{
Q_OBJECT
public:
explicit ClearPrivateData(BrowserWindow* window, QWidget* parent = 0);
explicit ClearPrivateData(QWidget* parent = 0);
static void clearLocalStorage();
static void clearWebDatabases();
@ -50,7 +49,6 @@ private:
void restoreState(const QByteArray &state);
QByteArray saveState();
BrowserWindow* m_window;
Ui::ClearPrivateData* ui;
};

View File

@ -69,6 +69,10 @@ void QzSettings::saveSettings()
settings.setValue("AutomaticallyOpenProtocols", autoOpenProtocols);
settings.setValue("BlockOpeningProtocols", blockedProtocols);
settings.endGroup();
settings.beginGroup("Browser-Tabs-Settings");
settings.setValue("TabsOnTop", tabsOnTop);
settings.endGroup();
}

View File

@ -218,7 +218,7 @@ void PopupWindow::closeEvent(QCloseEvent* event)
void PopupWindow::editSelectAll()
{
m_view->selectAll();
m_view->editSelectAll();
}
void PopupWindow::aboutToShowEditMenu()

View File

@ -88,24 +88,42 @@ void SideBar::close()
SideBarManager::SideBarManager(BrowserWindow* parent)
: QObject(parent)
, m_window(parent)
, m_menu(0)
{
}
void SideBarManager::setSideBarMenu(QMenu* menu)
void SideBarManager::createMenu(QMenu* menu)
{
m_menu = menu;
QAction* act = menu->addAction(SideBar::tr("Bookmarks"), this, SLOT(slotShowSideBar()));
act->setCheckable(true);
act->setShortcut(QKeySequence("Ctrl+Shift+B"));
act->setData("Bookmarks");
act->setChecked(m_activeBar == QL1S("Bookmarks"));
refreshMenu();
act = menu->addAction(SideBar::tr("History"), this, SLOT(slotShowSideBar()));
act->setCheckable(true);
act->setShortcut(QKeySequence("Ctrl+H"));
act->setData("History");
act->setChecked(m_activeBar == QL1S("History"));
foreach (const QPointer<SideBarInterface> &sidebar, s_sidebars) {
if (sidebar) {
QAction* act = sidebar.data()->createMenuAction();
act->setData(s_sidebars.key(sidebar));
act->setChecked(m_activeBar == s_sidebars.key(sidebar));
connect(act, SIGNAL(triggered()), this, SLOT(slotShowSideBar()));
menu->addAction(act);
}
}
m_window->addActions(menu->actions());
// Menu is only valid until hidden
connect(menu, SIGNAL(aboutToHide()), this, SLOT(clearMenu()));
}
void SideBarManager::addSidebar(const QString &id, SideBarInterface* interface)
{
s_sidebars[id] = interface;
foreach (BrowserWindow* window, mApp->windows()) {
window->sideBarManager()->refreshMenu();
}
}
void SideBarManager::removeSidebar(const QString &id)
@ -117,44 +135,6 @@ void SideBarManager::removeSidebar(const QString &id)
}
}
void SideBarManager::refreshMenu()
{
if (!m_menu) {
return;
}
foreach (QAction* action, m_menu->actions()) {
m_window->removeAction(action);
}
m_menu->clear();
QAction* act = m_menu->addAction(SideBar::tr("Bookmarks"), this, SLOT(slotShowSideBar()));
act->setCheckable(true);
act->setShortcut(QKeySequence("Ctrl+Shift+B"));
act->setData("Bookmarks");
act = m_menu->addAction(SideBar::tr("History"), this, SLOT(slotShowSideBar()));
act->setCheckable(true);
act->setShortcut(QKeySequence("Ctrl+H"));
act->setData("History");
foreach (const QPointer<SideBarInterface> &sidebar, s_sidebars) {
if (!sidebar) {
continue;
}
QAction* act = sidebar.data()->createMenuAction();
act->setData(s_sidebars.key(sidebar));
connect(act, SIGNAL(triggered()), this, SLOT(slotShowSideBar()));
m_menu->addAction(act);
}
m_window->addActions(m_menu->actions());
updateActions();
}
void SideBarManager::slotShowSideBar()
{
if (QAction* act = qobject_cast<QAction*>(sender())) {
@ -162,15 +142,12 @@ void SideBarManager::slotShowSideBar()
}
}
void SideBarManager::updateActions()
void SideBarManager::clearMenu()
{
if (!m_menu) {
return;
}
QMenu* menu = qobject_cast<QMenu*>(sender());
Q_ASSERT(menu);
foreach (QAction* act, m_menu->actions()) {
act->setChecked(act->data().toString() == m_activeBar);
}
menu->clear();
}
void SideBarManager::showSideBar(const QString &id, bool toggle)
@ -216,8 +193,6 @@ void SideBarManager::showSideBar(const QString &id, bool toggle)
Settings settings;
settings.setValue("Browser-View-Settings/SideBar", m_activeBar);
updateActions();
}
void SideBarManager::sideBarRemoved(const QString &id)
@ -225,8 +200,6 @@ void SideBarManager::sideBarRemoved(const QString &id)
if (m_activeBar == id && m_sideBar) {
m_sideBar.data()->close();
}
refreshMenu();
}
void SideBarManager::closeSideBar()
@ -240,6 +213,4 @@ void SideBarManager::closeSideBar()
settings.setValue("Browser-View-Settings/SideBar", m_activeBar);
m_window->saveSideBarWidth();
updateActions();
}

View File

@ -60,8 +60,7 @@ class QUPZILLA_EXPORT SideBarManager : public QObject
public:
explicit SideBarManager(BrowserWindow* parent);
void setSideBarMenu(QMenu* menu);
void refreshMenu();
void createMenu(QMenu* menu);
void showSideBar(const QString &id, bool toggle = true);
void sideBarRemoved(const QString &id);
@ -73,10 +72,9 @@ public:
private slots:
void slotShowSideBar();
void clearMenu();
private:
void updateActions();
BrowserWindow* m_window;
QPointer<SideBar> m_sideBar;
QMenu* m_menu;

View File

@ -33,6 +33,8 @@ MenuBar::MenuBar(BrowserWindow* parent)
void MenuBar::contextMenuRequested(const QPoint &pos)
{
if (!actionAt(pos)) {
m_window->popupToolbarsMenu(mapToGlobal(pos));
QMenu menu;
m_window->createToolbarsMenu(&menu);
menu.exec(mapToGlobal(pos));
}
}

View File

@ -178,9 +178,7 @@ void TabBar::contextMenuRequested(const QPoint &position)
menu.addAction(tr("&Bookmark This Tab"), this, SLOT(bookmarkTab()));
menu.addAction(tr("Bookmark &All Tabs"), m_window, SLOT(bookmarkAllTabs()));
menu.addSeparator();
QAction* action = m_window->actionRestoreTab();
action->setEnabled(m_tabWidget->canRestoreTab());
menu.addAction(action);
menu.addAction(m_window->action(QSL("Other/RestoreClosedTab")));
menu.addSeparator();
menu.addAction(tr("Close Ot&her Tabs"), this, SLOT(closeAllButCurrent()));
menu.addAction(QIcon::fromTheme("window-close"), tr("Cl&ose"), this, SLOT(closeTab()));
@ -190,16 +188,17 @@ void TabBar::contextMenuRequested(const QPoint &position)
menu.addAction(tr("Reloa&d All Tabs"), m_tabWidget, SLOT(reloadAllTabs()));
menu.addAction(tr("Bookmark &All Tabs"), m_window, SLOT(bookmarkAllTabs()));
menu.addSeparator();
QAction* action = menu.addAction(QIcon::fromTheme("user-trash"), tr("Restore &Closed Tab"), m_tabWidget, SLOT(restoreClosedTab()));
action->setEnabled(m_tabWidget->canRestoreTab());
menu.addAction(m_window->action(QSL("Other/RestoreClosedTab")));
}
m_window->action(QSL("Other/RestoreClosedTab"))->setEnabled(m_tabWidget->canRestoreTab());
// Prevent choosing first option with double rightclick
const QPoint pos = mapToGlobal(position);
QPoint p(pos.x(), pos.y() + 1);
menu.exec(p);
m_window->actionRestoreTab()->setEnabled(true);
m_window->action(QSL("Other/RestoreClosedTab"))->setEnabled(true);
}
void TabBar::closeAllButCurrent()

View File

@ -43,7 +43,6 @@ TabbedWebView::TabbedWebView(BrowserWindow* window, WebTab* webTab)
, m_window(window)
, m_webTab(webTab)
, m_menu(new Menu(this))
, m_mouseTrack(false)
{
m_menu->setCloseOnMiddleClick(true);
@ -56,10 +55,10 @@ TabbedWebView::TabbedWebView(BrowserWindow* window, WebTab* webTab)
connect(this, SIGNAL(iconChanged()), this, SLOT(showIcon()));
connect(this, SIGNAL(statusBarMessage(QString)), m_window->statusBar(), SLOT(showMessage(QString)));
connect(m_window, SIGNAL(setWebViewMouseTracking(bool)), this, SLOT(trackMouse(bool)));
}
// Tracking mouse also on tabs created in fullscreen
trackMouse(m_window->isFullScreen());
TabbedWebView::~TabbedWebView()
{
}
void TabbedWebView::setWebPage(WebPage* page)
@ -223,15 +222,10 @@ BrowserWindow* TabbedWebView::mainWindow() const
void TabbedWebView::moveToWindow(BrowserWindow* window)
{
disconnect(this, SIGNAL(statusBarMessage(QString)), m_window->statusBar(), SLOT(showMessage(QString)));
disconnect(m_window, SIGNAL(setWebViewMouseTracking(bool)), this, SLOT(trackMouse(bool)));
m_window = window;
connect(this, SIGNAL(statusBarMessage(QString)), m_window->statusBar(), SLOT(showMessage(QString)));
connect(m_window, SIGNAL(setWebViewMouseTracking(bool)), this, SLOT(trackMouse(bool)));
// Tracking mouse also on tabs created in fullscreen
trackMouse(m_window->isFullScreen());
}
QWidget* TabbedWebView::overlayForJsAlert()
@ -300,7 +294,7 @@ void TabbedWebView::setAsCurrentTab()
void TabbedWebView::mouseMoveEvent(QMouseEvent* event)
{
if (m_mouseTrack) {
if (m_window->isFullScreen()) {
if (m_window->fullScreenNavigationVisible()) {
m_window->hideNavigationWithFullScreen();
}
@ -319,7 +313,3 @@ void TabbedWebView::disconnectObjects()
WebView::disconnectObjects();
}
TabbedWebView::~TabbedWebView()
{
}

View File

@ -74,7 +74,6 @@ public slots:
void openNewTab();
private slots:
void trackMouse(bool state) { m_mouseTrack = state; }
void slotLoadFinished();
void urlChanged(const QUrl &url);
void linkHovered(const QString &link, const QString &title, const QString &content);
@ -93,7 +92,6 @@ private:
Menu* m_menu;
QString m_currentIp;
bool m_mouseTrack;
};

View File

@ -723,7 +723,7 @@ void TabWidget::detachTab(int index)
BrowserWindow* window = mApp->createWindow(Qz::BW_NewWindow);
tab->moveToWindow(window);
window->openWithTab(tab);
window->setStartTab(tab);
if (m_isClosingToLastTabIndex && m_lastTabIndex < count() && index == currentIndex()) {
setCurrentIndex(m_lastTabIndex);

View File

@ -67,7 +67,7 @@ QDataStream &operator >>(QDataStream &stream, WebTab::SavedTab &tab)
int version;
stream >> version;
// FIXME: HACK to ensure backwards compatibility
// Hack to ensure backwards compatibility
if (version != savedTabVersion) {
stream.device()->seek(stream.device()->pos() - sizeof(int));
stream >> tab.title;

View File

@ -324,6 +324,42 @@ void WebView::zoomReset()
applyZoom();
}
void WebView::editUndo()
{
triggerPageAction(QWebPage::Undo);
}
void WebView::editRedo()
{
triggerPageAction(QWebPage::Redo);
}
void WebView::editCut()
{
triggerPageAction(QWebPage::Cut);
}
void WebView::editCopy()
{
triggerPageAction(QWebPage::Copy);
}
void WebView::editPaste()
{
triggerPageAction(QWebPage::Paste);
}
void WebView::editSelectAll()
{
triggerPageAction(QWebPage::SelectAll);
}
void WebView::editDelete()
{
QKeyEvent ev(QEvent::KeyPress, Qt::Key_Delete, Qt::NoModifier);
QApplication::sendEvent(this, &ev);
}
void WebView::reload()
{
m_isReloading = true;
@ -335,6 +371,11 @@ void WebView::reload()
QWebView::reload();
}
void WebView::reloadBypassCache()
{
triggerPageAction(QWebPage::ReloadAndBypassCache);
}
void WebView::back()
{
QWebHistory* history = page()->history();
@ -359,17 +400,6 @@ void WebView::forward()
}
}
void WebView::editDelete()
{
QKeyEvent ev(QEvent::KeyPress, Qt::Key_Delete, Qt::NoModifier);
QApplication::sendEvent(this, &ev);
}
void WebView::selectAll()
{
triggerPageAction(QWebPage::SelectAll);
}
void WebView::slotLoadStarted()
{
m_isLoading = true;
@ -974,7 +1004,7 @@ void WebView::createPageContextMenu(QMenu* menu, const QPoint &pos)
menu->addAction(QIcon::fromTheme("mail-message-new"), tr("Send page link..."), this, SLOT(sendPageByMail()));
menu->addAction(QIcon::fromTheme("document-print"), tr("&Print page"), this, SLOT(printPage()));
menu->addSeparator();
menu->addAction(QIcon::fromTheme("edit-select-all"), tr("Select &all"), this, SLOT(selectAll()));
menu->addAction(QIcon::fromTheme("edit-select-all"), tr("Select &all"), this, SLOT(editSelectAll()));
menu->addSeparator();
if (url().scheme() == QLatin1String("http") || url().scheme() == QLatin1String("https")) {
@ -1317,7 +1347,7 @@ void WebView::keyPressEvent(QKeyEvent* event)
case Qt::Key_A:
if (event->modifiers() == Qt::ControlModifier) {
selectAll();
editSelectAll();
event->accept();
return;
}

View File

@ -74,14 +74,21 @@ public slots:
void zoomOut();
void zoomReset();
void editUndo();
void editRedo();
void editCut();
void editCopy();
void editPaste();
void editSelectAll();
void editDelete();
void load(const QUrl &url);
void reload();
void reloadBypassCache();
void back();
void forward();
void editDelete();
void selectAll();
void printPage(QWebFrame* frame = 0);
void sendPageByMail();
void savePageAs();