diff --git a/src/lib/app/browserwindow.cpp b/src/lib/app/browserwindow.cpp index 645555de8..a760e343e 100644 --- a/src/lib/app/browserwindow.cpp +++ b/src/lib/app/browserwindow.cpp @@ -33,14 +33,11 @@ #include "bookmarkstoolbar.h" #include "clearprivatedata.h" #include "sourceviewer.h" -#include "siteinfo.h" -#include "preferences.h" #include "networkmanager.h" #include "autofill.h" #include "networkmanagerproxy.h" #include "rssmanager.h" #include "mainapplication.h" -#include "aboutdialog.h" #include "checkboxdialog.h" #include "adblockmanager.h" #include "clickablelabel.h" @@ -69,6 +66,7 @@ #include "bookmarkstools.h" #include "bookmarksmenu.h" #include "historymenu.h" +#include "mainmenu.h" #include #include @@ -100,29 +98,18 @@ #include #endif -#ifndef Q_OS_MAC -#define MENU_RECEIVER this -#else -#include "macmenureceiver.h" -#define MENU_RECEIVER mApp->macMenuReceiver() -#endif - const QString BrowserWindow::WEBKITVERSION = qWebKitVersion(); -BrowserWindow::BrowserWindow(Qz::BrowserWindowType type, QUrl startUrl) +BrowserWindow::BrowserWindow(Qz::BrowserWindowType type, const QUrl &startUrl) : QMainWindow(0) - , m_bookmarksMenuChanged(true) , m_isClosing(false) , m_isStarting(false) - , m_startingUrl(startUrl) + , m_startUrl(startUrl) , m_windowType(type) , m_startTab(0) - , m_menuBookmarksAction(0) - , m_actionPrivateBrowsing(0) , m_sideBarManager(new SideBarManager(this)) , m_statusBarMessage(new StatusBarMessage(this)) - , m_usingTransparentBackground(false) - , m_tabsOnTopState(-1) + , m_useTransparentBackground(false) { setObjectName("mainwindow"); setAttribute(Qt::WA_DeleteOnClose); @@ -158,7 +145,7 @@ BrowserWindow::BrowserWindow(Qz::BrowserWindowType type, QUrl startUrl) } } -void BrowserWindow::openWithTab(WebTab* tab) +void BrowserWindow::setStartTab(WebTab* tab) { m_startTab = tab; } @@ -211,9 +198,6 @@ void BrowserWindow::postLaunch() break; case Qz::BW_MacFirstWindow: -#ifdef Q_OS_MAC - QTimer::singleShot(0, this, SLOT(refreshStateOfAllActions())); -#endif m_tabWidget->restorePinnedTabs(); // fallthrough @@ -228,8 +212,8 @@ void BrowserWindow::postLaunch() show(); - if (!m_startingUrl.isEmpty()) { - startUrl = m_startingUrl; + if (!m_startUrl.isEmpty()) { + startUrl = m_startUrl; addTab = true; } @@ -257,8 +241,6 @@ void BrowserWindow::postLaunch() m_tabWidget->addView(request, Qz::NT_SelectedTabAtTheEnd); } - aboutToHideEditMenu(); - #ifdef Q_OS_MAC // Fill menus even if user don't call them if (m_windowType == Qz::BW_FirstAppWindow) { @@ -273,7 +255,6 @@ void BrowserWindow::postLaunch() emit startingCompleted(); m_isStarting = false; - QMainWindow::setWindowTitle(m_lastWindowTitle); setUpdatesEnabled(true); raise(); @@ -337,20 +318,20 @@ void BrowserWindow::setupUi() m_mainSplitter->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); m_tabWidget = new TabWidget(this); m_superMenu = new QMenu(this); - m_navigationBar = new NavigationBar(this); - m_navigationBar->setSplitterSizes(locationBarWidth, websearchBarWidth); + m_navigationToolbar = new NavigationBar(this); + m_navigationToolbar->setSplitterSizes(locationBarWidth, websearchBarWidth); m_bookmarksToolbar = new BookmarksToolbar(this); m_navigationContainer = new NavigationContainer(this); QVBoxLayout* l = new QVBoxLayout(m_navigationContainer); l->setContentsMargins(0, 0, 0, 0); l->setSpacing(0); - l->addWidget(m_navigationBar); + l->addWidget(m_navigationToolbar); l->addWidget(m_bookmarksToolbar); m_navigationContainer->setLayout(l); m_mainSplitter->addWidget(m_tabWidget); - triggerTabsOnTop(tabsOnTop()); + toggleTabsOnTop(qzSettings->tabsOnTop); m_mainLayout->addWidget(m_mainSplitter); m_mainSplitter->setCollapsible(0, false); @@ -382,375 +363,21 @@ void BrowserWindow::setupUi() void BrowserWindow::setupMenu() { #ifdef Q_OS_MAC - if (menuBar()) { - setupMacMenu(); - setupOtherActions(); - return; - } - else { - mApp->macMenuReceiver()->setMenuBar(new QMenuBar(0)); - } -#else - setMenuBar(new MenuBar(this)); -#endif - - // Standard actions - needed on Mac to be placed correctly in "application" menu - m_actionAbout = new QAction(QIcon::fromTheme("help-about"), tr("&About QupZilla"), 0); - m_actionAbout->setMenuRole(QAction::AboutRole); - connect(m_actionAbout, SIGNAL(triggered()), MENU_RECEIVER, SLOT(aboutQupZilla())); - - m_actionPreferences = new QAction(QIcon::fromTheme("preferences-desktop", QIcon(":/icons/theme/settings.png")), tr("Pr&eferences"), 0); - m_actionPreferences->setMenuRole(QAction::PreferencesRole); - m_actionPreferences->setShortcut(QKeySequence(QKeySequence::Preferences)); - connect(m_actionPreferences, SIGNAL(triggered()), MENU_RECEIVER, SLOT(showPreferences())); - - m_actionQuit = new QAction(QIcon::fromTheme("application-exit"), tr("Quit"), 0); - m_actionQuit->setMenuRole(QAction::QuitRole); - - // QKeySequence::Quit returns an empty sequence on Windows and X11 when running desktop other than Gnome and Kde - m_actionQuit->setShortcut(actionShortcut(QKeySequence::Quit, Qt::CTRL + Qt::Key_Q)); - connect(m_actionQuit, SIGNAL(triggered()), MENU_RECEIVER, SLOT(quitApp())); - - /************* - * File Menu * - *************/ - m_menuFile = new QMenu(tr("&File")); - m_menuFile->addAction(QIcon::fromTheme("tab-new", QIcon(":/icons/menu/tab-new.png")), tr("New Tab"), MENU_RECEIVER, SLOT(addTab()))->setShortcut(QKeySequence("Ctrl+T")); - m_menuFile->addAction(QIcon::fromTheme("window-new"), tr("&New Window"), MENU_RECEIVER, SLOT(newWindow()))->setShortcut(QKeySequence("Ctrl+N")); - m_menuFile->addAction(QIcon::fromTheme("document-open-remote"), tr("Open Location"), MENU_RECEIVER, SLOT(openLocation()))->setShortcut(QKeySequence("Ctrl+L")); - m_menuFile->addAction(QIcon::fromTheme("document-open"), tr("Open &File..."), MENU_RECEIVER, SLOT(openFile()))->setShortcut(QKeySequence("Ctrl+O")); - m_actionCloseWindow = m_menuFile->addAction(QIcon::fromTheme("window-close"), tr("Close Window"), MENU_RECEIVER, SLOT(closeWindow())); - m_actionCloseWindow->setShortcut(QKeySequence("Ctrl+Shift+W")); - m_menuFile->addSeparator(); - m_menuFile->addAction(QIcon::fromTheme("document-save"), tr("&Save Page As..."), MENU_RECEIVER, SLOT(savePage()))->setShortcut(QKeySequence("Ctrl+S")); - m_menuFile->addAction(QIcon::fromTheme("image-loading"), tr("Save Page Screen"), MENU_RECEIVER, SLOT(savePageScreen()))->setShortcut(QKeySequence("Ctrl+Shift+S")); - m_menuFile->addAction(QIcon::fromTheme("mail-message-new"), tr("Send Link..."), MENU_RECEIVER, SLOT(sendLink())); - m_menuFile->addAction(QIcon::fromTheme("document-print"), tr("&Print..."), MENU_RECEIVER, SLOT(printPage()))->setShortcut(QKeySequence("Ctrl+P")); - m_menuFile->addSeparator(); - m_menuFile->addAction(tr("Import bookmarks..."), MENU_RECEIVER, SLOT(showBookmarkImport())); - m_menuFile->addAction(m_actionQuit); -#ifdef Q_OS_MAC // 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_actionAbout); - m_menuFile->addAction(m_actionPreferences); -#endif - connect(m_menuFile, SIGNAL(aboutToShow()), MENU_RECEIVER, SLOT(aboutToShowFileMenu())); - connect(m_menuFile, SIGNAL(aboutToHide()), MENU_RECEIVER, SLOT(aboutToHideFileMenu())); - - /************* - * Edit Menu * - *************/ - m_menuEdit = new QMenu(tr("&Edit")); - m_menuEdit->addAction(QIcon::fromTheme("edit-undo"), tr("&Undo"), MENU_RECEIVER, SLOT(editUndo()))->setShortcut(QKeySequence("Ctrl+Z")); - m_menuEdit->addAction(QIcon::fromTheme("edit-redo"), tr("&Redo"), MENU_RECEIVER, SLOT(editRedo()))->setShortcut(QKeySequence("Ctrl+Shift+Z")); - m_menuEdit->addSeparator(); - m_menuEdit->addAction(QIcon::fromTheme("edit-cut"), tr("&Cut"), MENU_RECEIVER, SLOT(editCut()))->setShortcut(QKeySequence("Ctrl+X")); - m_menuEdit->addAction(QIcon::fromTheme("edit-copy"), tr("C&opy"), MENU_RECEIVER, SLOT(editCopy()))->setShortcut(QKeySequence("Ctrl+C")); - m_menuEdit->addAction(QIcon::fromTheme("edit-paste"), tr("&Paste"), MENU_RECEIVER, SLOT(editPaste()))->setShortcut(QKeySequence("Ctrl+V")); - m_menuEdit->addSeparator(); - m_menuEdit->addAction(QIcon::fromTheme("edit-select-all"), tr("Select &All"), MENU_RECEIVER, SLOT(editSelectAll()))->setShortcut(QKeySequence("Ctrl+A")); - m_menuEdit->addAction(QIcon::fromTheme("edit-find"), tr("&Find"), MENU_RECEIVER, SLOT(searchOnPage()))->setShortcut(QKeySequence("Ctrl+F")); - m_menuEdit->addSeparator(); -#ifdef Q_OS_UNIX - m_menuEdit->addAction(m_actionPreferences); -#endif - connect(m_menuEdit, SIGNAL(aboutToShow()), MENU_RECEIVER, SLOT(aboutToShowEditMenu())); - connect(m_menuEdit, SIGNAL(aboutToHide()), MENU_RECEIVER, SLOT(aboutToHideEditMenu())); - - /************* - * View Menu * - *************/ - m_menuView = new QMenu(tr("&View")); - m_actionShowToolbar = new QAction(tr("&Navigation Toolbar"), MENU_RECEIVER); - m_actionShowToolbar->setCheckable(true); - connect(m_actionShowToolbar, SIGNAL(triggered(bool)), MENU_RECEIVER, SLOT(showNavigationToolbar())); - m_actionShowBookmarksToolbar = new QAction(tr("&Bookmarks Toolbar"), MENU_RECEIVER); - m_actionShowBookmarksToolbar->setCheckable(true); - connect(m_actionShowBookmarksToolbar, SIGNAL(triggered(bool)), MENU_RECEIVER, SLOT(showBookmarksToolbar())); - m_actionShowStatusbar = new QAction(tr("Sta&tus Bar"), MENU_RECEIVER); - m_actionShowStatusbar->setCheckable(true); - connect(m_actionShowStatusbar, SIGNAL(triggered(bool)), MENU_RECEIVER, SLOT(showStatusbar())); -#ifndef Q_OS_MAC - m_actionShowMenubar = new QAction(tr("&Menu Bar"), this); - m_actionShowMenubar->setCheckable(true); - connect(m_actionShowMenubar, SIGNAL(triggered(bool)), MENU_RECEIVER, SLOT(showMenubar())); - m_menuEncoding = new QMenu(this); -#else - m_menuEncoding = new QMenu(0); -#endif - m_actionTabsOnTop = new QAction(tr("&Tabs on Top"), MENU_RECEIVER); - m_actionTabsOnTop->setCheckable(true); - connect(m_actionTabsOnTop, SIGNAL(triggered(bool)), MENU_RECEIVER, SLOT(triggerTabsOnTop(bool))); - m_actionShowFullScreen = new QAction(tr("&Fullscreen"), MENU_RECEIVER); - m_actionShowFullScreen->setCheckable(true); -#ifndef Q_OS_MAC - m_actionShowFullScreen->setShortcut(QKeySequence("F11")); -#else - m_actionShowFullScreen->setShortcut(QKeySequence("Ctrl+F11")); -#endif - connect(m_actionShowFullScreen, SIGNAL(triggered(bool)), MENU_RECEIVER, SLOT(toggleFullScreen())); - m_actionStop = new QAction(IconProvider::standardIcon(QStyle::SP_BrowserStop), tr("&Stop"), MENU_RECEIVER); - connect(m_actionStop, SIGNAL(triggered()), MENU_RECEIVER, SLOT(stop())); - m_actionStop->setShortcut(QKeySequence("Esc")); - m_actionReload = new QAction(IconProvider::standardIcon(QStyle::SP_BrowserReload), tr("&Reload"), MENU_RECEIVER); - connect(m_actionReload, SIGNAL(triggered()), MENU_RECEIVER, SLOT(reload())); - m_actionReload->setShortcut(QKeySequence("F5")); - QAction* actionEncoding = new QAction(tr("Character &Encoding"), MENU_RECEIVER); - actionEncoding->setMenu(m_menuEncoding); - connect(m_menuEncoding, SIGNAL(aboutToShow()), MENU_RECEIVER, SLOT(aboutToShowEncodingMenu())); - m_actionCaretBrowsing = new QAction(tr("Enable &Caret Browsing"), MENU_RECEIVER); - m_actionCaretBrowsing->setVisible(false); - m_actionCaretBrowsing->setCheckable(true); - m_actionCaretBrowsing->setShortcut(QKeySequence("F7")); - connect(m_actionCaretBrowsing, SIGNAL(triggered()), MENU_RECEIVER, SLOT(triggerCaretBrowsing())); - -#if QTWEBKIT_FROM_2_3 - m_actionCaretBrowsing->setVisible(true); -#endif - - m_toolbarsMenu = new QMenu(tr("Toolbars")); -#ifndef Q_OS_MAC - m_toolbarsMenu->addAction(m_actionShowMenubar); -#endif - m_toolbarsMenu->addAction(m_actionShowToolbar); - m_toolbarsMenu->addAction(m_actionShowBookmarksToolbar); - m_toolbarsMenu->addSeparator(); - m_toolbarsMenu->addAction(m_actionTabsOnTop); - QMenu* sidebarsMenu = new QMenu(tr("Sidebars")); - m_sideBarManager->setSideBarMenu(sidebarsMenu); - - m_menuView->addMenu(m_toolbarsMenu); - m_menuView->addMenu(sidebarsMenu); - m_menuView->addAction(m_actionShowStatusbar); - m_menuView->addSeparator(); - m_menuView->addAction(m_actionStop); - m_menuView->addAction(m_actionReload); - m_menuView->addSeparator(); - m_menuView->addAction(QIcon::fromTheme("zoom-in"), tr("Zoom &In"), MENU_RECEIVER, SLOT(zoomIn()))->setShortcut(QKeySequence("Ctrl++")); - m_menuView->addAction(QIcon::fromTheme("zoom-out"), tr("Zoom &Out"), MENU_RECEIVER, SLOT(zoomOut()))->setShortcut(QKeySequence("Ctrl+-")); - m_menuView->addAction(QIcon::fromTheme("zoom-original"), tr("Reset"), MENU_RECEIVER, SLOT(zoomReset()))->setShortcut(QKeySequence("Ctrl+0")); - m_menuView->addSeparator(); - m_menuView->addAction(m_actionCaretBrowsing); - m_menuView->addAction(actionEncoding); - m_menuView->addSeparator(); - m_actionPageSource = m_menuView->addAction(QIcon::fromTheme("text-html"), tr("&Page Source"), MENU_RECEIVER, SLOT(showSource())); - m_actionPageSource->setShortcut(QKeySequence("Ctrl+U")); - m_actionPageSource->setEnabled(false); - m_menuView->addAction(m_actionShowFullScreen); - connect(m_menuView, SIGNAL(aboutToShow()), MENU_RECEIVER, SLOT(aboutToShowViewMenu())); - connect(m_menuView, SIGNAL(aboutToHide()), MENU_RECEIVER, SLOT(aboutToHideViewMenu())); - - /**************** - * History Menu * - ****************/ - - m_menuHistory = new HistoryMenu(); - m_menuHistory->setMainWindow(this); - - /****************** - * Bookmarks Menu * - ******************/ - m_menuBookmarks = new BookmarksMenu(); - m_menuBookmarks->setMainWindow(this); - - /************** - * Tools Menu * - **************/ - m_menuTools = new QMenu(tr("&Tools")); - m_menuTools->addAction(tr("&Web Search"), MENU_RECEIVER, SLOT(webSearch()))->setShortcut(QKeySequence("Ctrl+K")); - m_actionPageInfo = m_menuTools->addAction(QIcon::fromTheme("dialog-information"), tr("Page &Info"), MENU_RECEIVER, SLOT(showPageInfo())); - m_actionPageInfo->setShortcut(QKeySequence("Ctrl+I")); - m_actionPageInfo->setEnabled(false); - m_menuTools->addSeparator(); - m_menuTools->addAction(tr("&Download Manager"), MENU_RECEIVER, SLOT(showDownloadManager()))->setShortcut(QKeySequence("Ctrl+Y")); - m_menuTools->addAction(tr("&Cookies Manager"), MENU_RECEIVER, SLOT(showCookieManager())); - m_menuTools->addAction(tr("&AdBlock"), AdBlockManager::instance(), SLOT(showDialog())); - m_menuTools->addAction(QIcon(":/icons/menu/rss.png"), tr("RSS &Reader"), MENU_RECEIVER, SLOT(showRSSManager())); - m_menuTools->addAction(tr("Web In&spector"), MENU_RECEIVER, SLOT(showWebInspector()))->setShortcut(QKeySequence("Ctrl+Shift+I")); - m_menuTools->addAction(QIcon::fromTheme("edit-clear"), tr("Clear Recent &History"), MENU_RECEIVER, SLOT(showClearPrivateData()))->setShortcut(QKeySequence("Ctrl+Shift+Del")); - m_actionPrivateBrowsing = new QAction(QIcon(":/icons/locationbar/privatebrowsing.png"), tr("New &Private Window"), MENU_RECEIVER); - m_actionPrivateBrowsing->setShortcut(QKeySequence("Ctrl+Shift+P")); - connect(m_actionPrivateBrowsing, SIGNAL(triggered(bool)), mApp, SLOT(startPrivateBrowsing())); - m_menuTools->addAction(m_actionPrivateBrowsing); - m_menuTools->addSeparator(); -#if !defined(Q_OS_UNIX) && !defined(Q_OS_MAC) - m_menuTools->addAction(m_actionPreferences); -#endif - connect(m_menuTools, SIGNAL(aboutToShow()), MENU_RECEIVER, SLOT(aboutToShowToolsMenu())); - connect(m_menuTools, SIGNAL(aboutToHide()), MENU_RECEIVER, SLOT(aboutToHideToolsMenu())); - - /************* - * Help Menu * - *************/ - m_menuHelp = new QMenu(tr("&Help")); -#ifndef Q_OS_MAC - m_menuHelp->addAction(QIcon(":/icons/menu/qt.png"), tr("About &Qt"), qApp, SLOT(aboutQt())); - m_menuHelp->addAction(m_actionAbout); - m_menuHelp->addSeparator(); -#endif - QAction* infoAction = new QAction(QIcon::fromTheme("help-contents"), tr("Information about application"), m_menuHelp); - infoAction->setData(QUrl("qupzilla:about")); - infoAction->setShortcut(QKeySequence(QKeySequence::HelpContents)); - connect(infoAction, SIGNAL(triggered()), MENU_RECEIVER, SLOT(loadActionUrlInNewTab())); - m_menuHelp->addAction(infoAction); - m_menuHelp->addAction(tr("Configuration Information"), MENU_RECEIVER, SLOT(loadActionUrlInNewTab()))->setData(QUrl("qupzilla:config")); - m_menuHelp->addAction(tr("Report &Issue"), MENU_RECEIVER, SLOT(loadActionUrlInNewTab()))->setData(QUrl("qupzilla:reportbug")); - - /************ - * Menu Bar * - ************/ - 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); - - /***************** - * Other Actions * - *****************/ - setupOtherActions(); - -#ifndef Q_OS_MAC - m_superMenu->addAction(m_menuFile->actions().at(0)); - m_superMenu->addAction(m_menuFile->actions().at(1)); - m_superMenu->addAction(m_actionPrivateBrowsing); - m_superMenu->addAction(m_menuFile->actions().at(3)); - - m_superMenu->addSeparator(); - m_superMenu->addAction(m_menuFile->actions().at(7)); - m_superMenu->addAction(m_menuFile->actions().at(8)); - m_superMenu->addAction(m_menuFile->actions().at(10)); - - m_superMenu->addSeparator(); - m_superMenu->addAction(m_menuEdit->actions().at(7)); - m_superMenu->addAction(m_menuEdit->actions().at(8)); - - m_superMenu->addSeparator(); - m_superMenu->addAction(m_menuHistory->actions().at(3)); - m_superMenu->addAction(m_menuBookmarks->actions().at(2)); - - m_superMenu->addSeparator(); - m_superMenu->addAction(m_actionPreferences); - - m_superMenu->addSeparator(); - m_superMenu->addMenu(m_menuView); - m_superMenu->addMenu(m_menuHistory); - m_superMenu->addMenu(m_menuBookmarks); - m_superMenu->addMenu(m_menuTools); - - m_superMenu->addSeparator(); - m_superMenu->addAction(m_actionAbout); - m_superMenu->addAction(m_menuHelp->actions().at(3)); - m_superMenu->addAction(m_menuHelp->actions().at(4)); - m_superMenu->addAction(m_menuHelp->actions().at(5)); - - m_superMenu->addSeparator(); - m_superMenu->addAction(m_actionQuit); -#else + // TODO: Mac menu ActionCopy* copyActionPrivateBrowsing = new ActionCopy(m_actionPrivateBrowsing); copyActionPrivateBrowsing->setText(copyActionPrivateBrowsing->text().remove(QLatin1Char('&'))); mApp->macDockMenu()->addAction(copyActionPrivateBrowsing); mApp->macDockMenu()->addAction(m_menuFile->actions().at(1)); mApp->macDockMenu()->addAction(m_menuFile->actions().at(0)); +#else + setMenuBar(new MenuBar(this)); + + m_mainMenu = new MainMenu(this, this); + m_mainMenu->initMenuBar(menuBar()); + m_mainMenu->initSuperMenu(m_superMenu); #endif } -void BrowserWindow::setupOtherActions() -{ - m_actionRestoreTab = new QAction(QIcon::fromTheme("user-trash"), tr("Restore &Closed Tab"), this); - m_actionRestoreTab->setShortcut(QKeySequence("Ctrl+Shift+T")); - connect(m_actionRestoreTab, SIGNAL(triggered()), MENU_RECEIVER, SLOT(restoreClosedTab())); - addAction(m_actionRestoreTab); - - QShortcut* reloadByPassCacheAction = new QShortcut(QKeySequence("Ctrl+F5"), this); - QShortcut* reloadByPassCacheAction2 = new QShortcut(QKeySequence("Ctrl+Shift+R"), this); - connect(reloadByPassCacheAction, SIGNAL(activated()), MENU_RECEIVER, SLOT(reloadByPassCache())); - connect(reloadByPassCacheAction2, SIGNAL(activated()), MENU_RECEIVER, SLOT(reloadByPassCache())); - - QShortcut* reloadAction = new QShortcut(QKeySequence("Ctrl+R"), this); - connect(reloadAction, SIGNAL(activated()), MENU_RECEIVER, SLOT(reload())); - - QShortcut* openLocationAction = new QShortcut(QKeySequence("Alt+D"), this); - connect(openLocationAction, SIGNAL(activated()), MENU_RECEIVER, SLOT(openLocation())); - - QShortcut* closeTabAction = new QShortcut(QKeySequence("Ctrl+W"), this); - QShortcut* closeTabAction2 = new QShortcut(QKeySequence("Ctrl+F4"), this); - connect(closeTabAction, SIGNAL(activated()), MENU_RECEIVER, SLOT(closeTab())); - connect(closeTabAction2, SIGNAL(activated()), MENU_RECEIVER, SLOT(closeTab())); - - // Make shortcuts available even in fullscreen (menu hidden) - QList actions = menuBar()->actions(); - for (int i = 0; i < actions.size(); ++i) { - QAction* action = actions.at(i); - if (action->menu()) { - actions += action->menu()->actions(); - } - addAction(action); - } -} - -QKeySequence BrowserWindow::actionShortcut(QKeySequence shortcut, QKeySequence fallBack, - QKeySequence shortcutRTL, QKeySequence fallbackRTL) -{ - if (isRightToLeft() && (!shortcutRTL.isEmpty() || !fallbackRTL.isEmpty())) { - return (shortcutRTL.isEmpty() ? fallbackRTL : shortcutRTL); - } - else { - return (shortcut.isEmpty() ? fallBack : shortcut); - } -} - -#ifdef Q_OS_MAC -void BrowserWindow::setupMacMenu() -{ - // menus - m_menuFile = menuBar()->actions().at(0)->menu(); - m_menuEdit = menuBar()->actions().at(1)->menu(); - m_menuView = menuBar()->actions().at(2)->menu(); - m_menuHistory = qobject_cast(menuBar()->actions().at(3)->menu()); - m_menuBookmarks = qobject_cast(menuBar()->actions().at(4)->menu()); - m_menuTools = menuBar()->actions().at(5)->menu(); - m_menuHelp = menuBar()->actions().at(6)->menu(); - - m_toolbarsMenu = m_menuView->actions().at(0)->menu(); - m_menuEncoding = m_menuView->actions().at(12)->menu(); - - m_menuHistoryRecent = qobject_cast(m_menuHistory->actions().at(5)->menu()); - m_menuHistoryMost = qobject_cast(m_menuHistory->actions().at(6)->menu()); - m_menuClosedTabs = m_menuHistory->actions().at(7)->menu(); - - // actions - m_actionCloseWindow = m_menuFile->actions().at(5); - m_actionQuit = m_menuFile->actions().at(13); - m_actionAbout = m_menuFile->actions().at(14); - m_actionPreferences = m_menuFile->actions().at(15); - - m_actionShowToolbar = m_menuView->actions().at(0)->menu()->actions().at(0); - m_actionShowBookmarksToolbar = m_menuView->actions().at(0)->menu()->actions().at(1); - m_actionTabsOnTop = m_menuView->actions().at(0)->menu()->actions().at(3); - m_actionShowStatusbar = m_menuView->actions().at(2); - m_actionStop = m_menuView->actions().at(4); - m_actionReload = m_menuView->actions().at(5); - m_actionCaretBrowsing = m_menuView->actions().at(11); - m_actionPageSource = m_menuView->actions().at(14); - m_actionShowFullScreen = m_menuView->actions().at(15); - - m_actionPageInfo = m_menuTools->actions().at(1); - m_actionPrivateBrowsing = m_menuTools->actions().at(9); -} - -void BrowserWindow::refreshStateOfAllActions() -{ - mApp->macMenuReceiver()->aboutToShowFileMenu(m_menuFile); - mApp->macMenuReceiver()->aboutToShowHistoryMenu(m_menuHistory); - mApp->macMenuReceiver()->aboutToShowBookmarksMenu(m_menuBookmarks); - mApp->macMenuReceiver()->aboutToShowViewMenu(m_menuView); - mApp->macMenuReceiver()->aboutToShowEditMenu(m_menuEdit); - mApp->macMenuReceiver()->aboutToShowToolsMenu(m_menuTools); -} -#endif - void BrowserWindow::loadSettings() { Settings settings; @@ -794,18 +421,18 @@ void BrowserWindow::loadSettings() statusBar()->setVisible(!isFullScreen() && showStatusBar); m_bookmarksToolbar->setVisible(showBookmarksToolbar); - m_navigationBar->setVisible(showNavigationToolbar); + m_navigationToolbar->setVisible(showNavigationToolbar); menuBar()->setVisible(!isFullScreen() && showMenuBar); #ifndef Q_OS_MAC - m_navigationBar->setSuperMenuVisible(!showMenuBar); + m_navigationToolbar->setSuperMenuVisible(!showMenuBar); #endif - m_navigationBar->buttonReloadStop()->setVisible(showReloadButton); - m_navigationBar->buttonHome()->setVisible(showHomeButton); - m_navigationBar->buttonBack()->setVisible(showBackForwardButtons); - m_navigationBar->buttonNext()->setVisible(showBackForwardButtons); - m_navigationBar->searchLine()->setVisible(showWebSearchBar); - m_navigationBar->buttonAddTab()->setVisible(showAddTabButton); + m_navigationToolbar->buttonReloadStop()->setVisible(showReloadButton); + m_navigationToolbar->buttonHome()->setVisible(showHomeButton); + m_navigationToolbar->buttonBack()->setVisible(showBackForwardButtons); + m_navigationToolbar->buttonNext()->setVisible(showBackForwardButtons); + m_navigationToolbar->webSearchBar()->setVisible(showWebSearchBar); + m_navigationToolbar->buttonAddTab()->setVisible(showAddTabButton); m_sideBarManager->showSideBar(activeSideBar, false); @@ -849,7 +476,7 @@ void BrowserWindow::loadSettings() QtWin::extendFrameIntoClientArea(this); } - //install event filter + // Install event filters menuBar()->installEventFilter(this); m_tabWidget->getTabBar()->installEventFilter(this); m_navigationBar->installEventFilter(this); @@ -899,30 +526,69 @@ LocationBar* BrowserWindow::locationBar() const return qobject_cast(m_tabWidget->locationBars()->currentWidget()); } +TabWidget* BrowserWindow::tabWidget() const +{ + return m_tabWidget; +} + +BookmarksToolbar* BrowserWindow::bookmarksToolbar() const +{ + return m_bookmarksToolbar; +} + +StatusBarMessage* BrowserWindow::statusBarMessage() const +{ + return m_statusBarMessage; +} + +NavigationBar* BrowserWindow::navigationBar() const +{ + return m_navigationToolbar; +} + +SideBarManager* BrowserWindow::sideBarManager() const +{ + return m_sideBarManager; +} + +QLabel* BrowserWindow::ipLabel() const +{ + return m_ipLabel; +} + +AdBlockIcon* BrowserWindow::adBlockIcon() const +{ + return m_adblockIcon; +} + +QMenu* BrowserWindow::superMenu() const +{ + return m_superMenu; +} + +bool BrowserWindow::isClosing() const +{ + return m_isClosing; +} + +QUrl BrowserWindow::homepageUrl() const +{ + return m_homepage; +} + Qz::BrowserWindowType BrowserWindow::windowType() const { return m_windowType; } -void BrowserWindow::popupToolbarsMenu(const QPoint &pos) +bool BrowserWindow::isTransparentBackgroundAllowed() const { - aboutToShowViewMenu(); - m_toolbarsMenu->exec(pos); - aboutToHideViewMenu(); + return m_useTransparentBackground && !isFullScreen(); } -bool BrowserWindow::isTransparentBackgroundAllowed() +QAction* BrowserWindow::action(const QString &name) const { - return m_usingTransparentBackground && !isFullScreen(); -} - -bool BrowserWindow::tabsOnTop() const -{ - if (m_tabsOnTopState == -1) { - m_tabsOnTopState = qzSettings->tabsOnTop ? 1 : 0; - } - - return m_tabsOnTopState == 1; + return m_mainMenu->action(name); } void BrowserWindow::setWindowTitle(const QString &t) @@ -933,176 +599,23 @@ void BrowserWindow::setWindowTitle(const QString &t) title.append(tr(" (Private Browsing)")); } - if (m_isStarting) { - m_lastWindowTitle = title; - return; - } - QMainWindow::setWindowTitle(title); } -void BrowserWindow::aboutToShowFileMenu() +void BrowserWindow::changeEncoding() { -#ifndef Q_OS_MAC - m_actionCloseWindow->setEnabled(mApp->windowCount() > 1); -#endif -} - -void BrowserWindow::aboutToHideFileMenu() -{ - m_actionCloseWindow->setEnabled(true); -} - -void BrowserWindow::aboutToShowViewMenu() -{ - 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_actionShowStatusbar->setChecked(statusBar()->isVisible()); - m_actionShowBookmarksToolbar->setChecked(m_bookmarksToolbar->isVisible()); - m_actionTabsOnTop->setChecked(tabsOnTop()); - - m_actionPageSource->setEnabled(true); - -#if QTWEBKIT_FROM_2_3 - m_actionCaretBrowsing->setChecked(QWebSettings::globalSettings()->testAttribute(QWebSettings::CaretBrowsingEnabled)); -#endif -} - -void BrowserWindow::aboutToHideViewMenu() -{ -#ifndef Q_OS_MAC - m_actionPageSource->setEnabled(false); -#endif -} - -void BrowserWindow::aboutToShowEditMenu() -{ - WebView* view = weView(); - - m_menuEdit->actions().at(0)->setEnabled(view->pageAction(QWebPage::Undo)->isEnabled()); - m_menuEdit->actions().at(1)->setEnabled(view->pageAction(QWebPage::Redo)->isEnabled()); - // Separator - m_menuEdit->actions().at(3)->setEnabled(view->pageAction(QWebPage::Cut)->isEnabled()); - m_menuEdit->actions().at(4)->setEnabled(view->pageAction(QWebPage::Copy)->isEnabled()); - m_menuEdit->actions().at(5)->setEnabled(view->pageAction(QWebPage::Paste)->isEnabled()); - // Separator - m_menuEdit->actions().at(7)->setEnabled(view->pageAction(QWebPage::SelectAll)->isEnabled()); -} - -void BrowserWindow::aboutToHideEditMenu() -{ -#ifndef Q_OS_MAC - foreach (QAction* act, m_menuEdit->actions()) { - act->setEnabled(false); - } -#endif - - m_menuEdit->actions().at(8)->setEnabled(true); - m_actionPreferences->setEnabled(true); -} - -void BrowserWindow::aboutToShowToolsMenu() -{ - m_actionPageInfo->setEnabled(true); -} - -void BrowserWindow::aboutToHideToolsMenu() -{ -#ifndef Q_OS_MAC - m_actionPageInfo->setEnabled(false); -#endif -} - -void BrowserWindow::aboutToShowEncodingMenu() -{ - m_menuEncoding->clear(); - QMenu* menuISO = new QMenu("ISO", this); - QMenu* menuUTF = new QMenu("UTF", this); - QMenu* menuWindows = new QMenu("Windows", this); - QMenu* menuIscii = new QMenu("Iscii", this); - QMenu* menuOther = new QMenu(tr("Other"), this); - - QList available = QTextCodec::availableCodecs(); - qSort(available); - const QString activeCodec = QWebSettings::globalSettings()->defaultTextEncoding(); - - foreach (const QByteArray &name, available) { - QTextCodec* codec = QTextCodec::codecForName(name); - if (codec && codec->aliases().contains(name)) { - continue; - } - - const QString nameString = QString::fromUtf8(name); - - QAction* action = new QAction(nameString, 0); - action->setData(nameString); - action->setCheckable(true); - connect(action, SIGNAL(triggered()), MENU_RECEIVER, SLOT(changeEncoding())); - if (activeCodec.compare(nameString, Qt::CaseInsensitive) == 0) { - action->setChecked(true); - } - - if (nameString.startsWith(QLatin1String("ISO"))) { - menuISO->addAction(action); - } - else if (nameString.startsWith(QLatin1String("UTF"))) { - menuUTF->addAction(action); - } - else if (nameString.startsWith(QLatin1String("windows"))) { - menuWindows->addAction(action); - } - else if (nameString.startsWith(QLatin1String("Iscii"))) { - menuIscii->addAction(action); - } - else if (nameString == QLatin1String("System")) { - m_menuEncoding->addAction(action); - } - else { - menuOther->addAction(action); - } - } - - m_menuEncoding->addSeparator(); - if (!menuISO->isEmpty()) { - m_menuEncoding->addMenu(menuISO); - } - if (!menuUTF->isEmpty()) { - m_menuEncoding->addMenu(menuUTF); - } - if (!menuWindows->isEmpty()) { - m_menuEncoding->addMenu(menuWindows); - } - if (!menuIscii->isEmpty()) { - m_menuEncoding->addMenu(menuIscii); - } - if (!menuOther->isEmpty()) { - m_menuEncoding->addMenu(menuOther); - } -} - -void BrowserWindow::changeEncoding(QObject* obj) -{ - if (!obj) { - obj = sender(); - } - - if (QAction* action = qobject_cast(obj)) { + if (QAction* action = qobject_cast(sender())) { const QString encoding = action->data().toString(); QWebSettings::globalSettings()->setDefaultTextEncoding(encoding); Settings settings; settings.setValue("Web-Browser-Settings/DefaultEncoding", encoding); - reload(); + weView()->reload(); } } -void BrowserWindow::triggerCaretBrowsing() +void BrowserWindow::toggleCaretBrowsing() { #if QTWEBKIT_FROM_2_3 bool enable = !QWebSettings::globalSettings()->testAttribute(QWebSettings::CaretBrowsingEnabled); @@ -1132,81 +645,16 @@ void BrowserWindow::addBookmark(const QUrl &url, const QString &title) BookmarksTools::addBookmarkDialog(this, url, title); } -void BrowserWindow::newWindow() -{ - mApp->createWindow(Qz::BW_NewWindow); -} - void BrowserWindow::goHome() { loadAddress(m_homepage); } -void BrowserWindow::editUndo() -{ - weView()->triggerPageAction(QWebPage::Undo); -} - -void BrowserWindow::editRedo() -{ - weView()->triggerPageAction(QWebPage::Redo); -} - -void BrowserWindow::editCut() -{ - weView()->triggerPageAction(QWebPage::Cut); -} - -void BrowserWindow::editCopy() -{ - weView()->triggerPageAction(QWebPage::Copy); -} - -void BrowserWindow::editPaste() -{ - weView()->triggerPageAction(QWebPage::Paste); -} - -void BrowserWindow::editSelectAll() -{ - weView()->selectAll(); -} - -void BrowserWindow::zoomIn() -{ - weView()->zoomIn(); -} - -void BrowserWindow::zoomOut() -{ - weView()->zoomOut(); -} - -void BrowserWindow::zoomReset() -{ - weView()->zoomReset(); -} - void BrowserWindow::goHomeInNewTab() { m_tabWidget->addView(m_homepage, Qz::NT_SelectedTab); } -void BrowserWindow::stop() -{ - weView()->stop(); -} - -void BrowserWindow::reload() -{ - weView()->reload(); -} - -void BrowserWindow::reloadByPassCache() -{ - weView()->triggerPageAction(QWebPage::ReloadAndBypassCache); -} - void BrowserWindow::loadActionUrl(QObject* obj) { if (!obj) { @@ -1241,48 +689,11 @@ void BrowserWindow::loadAddress(const QUrl &url) } } -void BrowserWindow::showCookieManager() -{ - CookieManager* m = mApp->cookieManager(); - m->refreshTable(); - - m->show(); - m->raise(); -} - - void BrowserWindow::showHistoryManager() { mApp->browsingLibrary()->showHistory(this); } -void BrowserWindow::showRSSManager() -{ - mApp->browsingLibrary()->showRSS(this); -} - -void BrowserWindow::showBookmarksManager() -{ - mApp->browsingLibrary()->showBookmarks(this); -} - -void BrowserWindow::showClearPrivateData() -{ - ClearPrivateData clear(this, this); - clear.exec(); -} - -void BrowserWindow::showDownloadManager() -{ - mApp->downloadManager()->show(); -} - -void BrowserWindow::showPreferences() -{ - Preferences* prefs = new Preferences(this, this); - prefs->show(); -} - void BrowserWindow::showSource(QWebFrame* frame, const QString &selectedHtml) { if (!frame) { @@ -1294,13 +705,6 @@ void BrowserWindow::showSource(QWebFrame* frame, const QString &selectedHtml) source->show(); } -void BrowserWindow::showPageInfo() -{ - SiteInfo* info = new SiteInfo(weView(), this); - info->setAttribute(Qt::WA_DeleteOnClose); - info->show(); -} - void BrowserWindow::showBookmarksToolbar() { bool status = m_bookmarksToolbar->isVisible(); @@ -1347,14 +751,14 @@ void BrowserWindow::saveSideBarWidth() void BrowserWindow::showNavigationToolbar() { - if (!menuBar()->isVisible() && !m_actionShowToolbar->isChecked()) { + if (!menuBar()->isVisible() && !m_navigationToolbar->isVisible()) { showMenubar(); } setUpdatesEnabled(false); - bool status = m_navigationBar->isVisible(); - m_navigationBar->setVisible(!status); + bool status = m_navigationToolbar->isVisible(); + m_navigationToolbar->setVisible(!status); Settings settings; settings.setValue("Browser-View-Settings/showNavigationToolbar", !status); @@ -1365,14 +769,14 @@ void BrowserWindow::showNavigationToolbar() void BrowserWindow::showMenubar() { #ifndef Q_OS_MAC - if (!m_navigationBar->isVisible() && !m_actionShowMenubar->isChecked()) { + if (!m_navigationToolbar->isVisible() && !menuBar()->isVisible()) { showNavigationToolbar(); } setUpdatesEnabled(false); menuBar()->setVisible(!menuBar()->isVisible()); - m_navigationBar->setSuperMenuVisible(!menuBar()->isVisible()); + m_navigationToolbar->setSuperMenuVisible(!menuBar()->isVisible()); Settings settings; settings.setValue("Browser-View-Settings/showMenubar", menuBar()->isVisible()); @@ -1381,7 +785,7 @@ void BrowserWindow::showMenubar() #endif } -void BrowserWindow::showStatusbar() +void BrowserWindow::showStatusBar() { setUpdatesEnabled(false); @@ -1418,13 +822,7 @@ void BrowserWindow::showWebInspector(bool toggle) #endif } -void BrowserWindow::showBookmarkImport() -{ - BookmarksImportDialog* b = new BookmarksImportDialog(this); - b->show(); -} - -void BrowserWindow::triggerTabsOnTop(bool enable) +void BrowserWindow::toggleTabsOnTop(bool enable) { if (enable) { m_mainLayout->insertWidget(0, m_tabWidget->getTabBar()); @@ -1435,12 +833,7 @@ void BrowserWindow::triggerTabsOnTop(bool enable) m_mainLayout->insertWidget(1, m_tabWidget->getTabBar()); } - m_tabsOnTopState = enable ? 1 : 0; - if (enable != qzSettings->tabsOnTop) { - Settings settings; - settings.setValue("Browser-Tabs-Settings/TabsOnTop", enable); - qzSettings->tabsOnTop = enable; - } + qzSettings->tabsOnTop = enable; #ifdef Q_OS_WIN // workaround for changing TabsOnTop state when sidebar is visible @@ -1452,7 +845,7 @@ void BrowserWindow::triggerTabsOnTop(bool enable) void BrowserWindow::refreshHistory() { - m_navigationBar->refreshHistory(); + m_navigationToolbar->refreshHistory(); } void BrowserWindow::currentTabChanged() @@ -1474,8 +867,8 @@ void BrowserWindow::currentTabChanged() updateLoadingActions(); // Setting correct tab order (LocationBar -> WebSearchBar -> WebView) - setTabOrder(locationBar(), m_navigationBar->searchLine()); - setTabOrder(m_navigationBar->searchLine(), view); + setTabOrder(locationBar(), m_navigationToolbar->webSearchBar()); + setTabOrder(m_navigationToolbar->webSearchBar(), view); } void BrowserWindow::updateLoadingActions() @@ -1489,15 +882,16 @@ void BrowserWindow::updateLoadingActions() m_ipLabel->setVisible(!isLoading); m_progressBar->setVisible(isLoading); - m_actionStop->setEnabled(isLoading); - m_actionReload->setEnabled(!isLoading); + + action(QSL("View/Stop"))->setEnabled(isLoading); + action(QSL("View/Reload"))->setEnabled(!isLoading); if (isLoading) { m_progressBar->setValue(view->loadingProgress()); - m_navigationBar->showStopButton(); + m_navigationToolbar->showStopButton(); } else { - m_navigationBar->showReloadButton(); + m_navigationToolbar->showReloadButton(); } } @@ -1514,10 +908,96 @@ void BrowserWindow::restoreWindowState(const RestoreManager::WindowData &d) m_tabWidget->restoreState(d.tabsState, d.currentTab); } -void BrowserWindow::aboutQupZilla() +void BrowserWindow::createToolbarsMenu(QMenu* menu) { - AboutDialog about(this); - about.exec(); + QAction* action = menu->addAction(tr("&Menu Bar"), this, SLOT(showMenubar())); + action->setCheckable(true); + action->setChecked(menuBar()->isVisible()); + + action = menu->addAction(tr("&Navigation Toolbar"), this, SLOT(showNavigationToolbar())); + action->setCheckable(true); + action->setChecked(m_navigationToolbar->isVisible()); + + action = menu->addAction(tr("&Bookmarks Toolbar"), this, SLOT(showBookmarksToolbar())); + action->setCheckable(true); + action->setChecked(m_bookmarksToolbar->isVisible()); + + menu->addSeparator(); + + action = menu->addAction(tr("&Tabs on Top"), this, SLOT(toggleTabsOnTop(bool))); + action->setCheckable(true); + action->setChecked(qzSettings->tabsOnTop); +} + +void BrowserWindow::createSidebarsMenu(QMenu* menu) +{ + m_sideBarManager->createMenu(menu); +} + +void BrowserWindow::createEncodingMenu(QMenu* menu) +{ + QMenu* menuISO = new QMenu("ISO", this); + QMenu* menuUTF = new QMenu("UTF", this); + QMenu* menuWindows = new QMenu("Windows", this); + QMenu* menuIscii = new QMenu("Iscii", this); + QMenu* menuOther = new QMenu(tr("Other"), this); + + QList available = QTextCodec::availableCodecs(); + qSort(available); + const QString activeCodec = QWebSettings::globalSettings()->defaultTextEncoding(); + + foreach (const QByteArray &name, available) { + QTextCodec* codec = QTextCodec::codecForName(name); + if (codec && codec->aliases().contains(name)) { + continue; + } + + const QString nameString = QString::fromUtf8(name); + + QAction* action = new QAction(nameString, 0); + action->setData(nameString); + action->setCheckable(true); + connect(action, SIGNAL(triggered()), this, SLOT(changeEncoding())); + if (activeCodec.compare(nameString, Qt::CaseInsensitive) == 0) { + action->setChecked(true); + } + + if (nameString.startsWith(QLatin1String("ISO"))) { + menuISO->addAction(action); + } + else if (nameString.startsWith(QLatin1String("UTF"))) { + menuUTF->addAction(action); + } + else if (nameString.startsWith(QLatin1String("windows"))) { + menuWindows->addAction(action); + } + else if (nameString.startsWith(QLatin1String("Iscii"))) { + menuIscii->addAction(action); + } + else if (nameString == QLatin1String("System")) { + menu->addAction(action); + } + else { + menuOther->addAction(action); + } + } + + menu->addSeparator(); + if (!menuISO->isEmpty()) { + menu->addMenu(menuISO); + } + if (!menuUTF->isEmpty()) { + menu->addMenu(menuUTF); + } + if (!menuWindows->isEmpty()) { + menu->addMenu(menuWindows); + } + if (!menuIscii->isEmpty()) { + menu->addMenu(menuIscii); + } + if (!menuOther->isEmpty()) { + menu->addMenu(menuOther); + } } void BrowserWindow::addTab() @@ -1527,8 +1007,8 @@ void BrowserWindow::addTab() void BrowserWindow::webSearch() { - m_navigationBar->searchLine()->setFocus(); - m_navigationBar->searchLine()->selectAll(); + m_navigationToolbar->webSearchBar()->setFocus(); + m_navigationToolbar->webSearchBar()->selectAll(); } void BrowserWindow::searchOnPage() @@ -1622,12 +1102,10 @@ bool BrowserWindow::event(QEvent* event) m_navigationContainer->hide(); m_tabWidget->getTabBar()->hide(); #ifndef Q_OS_MAC - m_navigationBar->setSuperMenuVisible(false); + m_navigationToolbar->setSuperMenuVisible(false); #endif m_hideNavigationTimer->stop(); - m_actionShowFullScreen->setChecked(true); - m_navigationBar->buttonExitFullscreen()->setVisible(true); - emit setWebViewMouseTracking(true); + m_navigationToolbar->buttonExitFullscreen()->setVisible(true); #ifdef Q_OS_WIN if (m_usingTransparentBackground) { m_tabWidget->getTabBar()->enableBluredBackground(false); @@ -1646,12 +1124,10 @@ bool BrowserWindow::event(QEvent* event) m_tabWidget->getTabBar()->updateVisibilityWithFullscreen(true); m_tabWidget->getTabBar()->setVisible(true); #ifndef Q_OS_MAC - m_navigationBar->setSuperMenuVisible(!m_menuBarVisible); + m_navigationToolbar->setSuperMenuVisible(!m_menuBarVisible); #endif m_hideNavigationTimer->stop(); - m_actionShowFullScreen->setChecked(false); - m_navigationBar->buttonExitFullscreen()->setVisible(false); - emit setWebViewMouseTracking(false); + m_navigationToolbar->buttonExitFullscreen()->setVisible(false); #ifdef Q_OS_WIN if (m_usingTransparentBackground) { m_tabWidget->getTabBar()->enableBluredBackground(true); @@ -1678,16 +1154,6 @@ void BrowserWindow::toggleFullScreen() } } -void BrowserWindow::savePage() -{ - weView()->savePageAs(); -} - -void BrowserWindow::sendLink() -{ - weView()->sendPageByMail(); -} - void BrowserWindow::printPage(QWebFrame* frame) { QPrintPreviewDialog* dialog = new QPrintPreviewDialog(this); @@ -1735,39 +1201,59 @@ void BrowserWindow::keyPressEvent(QKeyEvent* event) switch (event->key()) { case Qt::Key_Back: if (view) { - weView()->back(); + view->back(); event->accept(); } break; case Qt::Key_Forward: if (view) { - weView()->forward(); + view->forward(); event->accept(); } break; case Qt::Key_Stop: if (view) { - weView()->stop(); + view->stop(); event->accept(); } break; case Qt::Key_Refresh: if (view) { - weView()->reload(); + view->reload(); event->accept(); } break; + case Qt::Key_F5: + if (view && event->modifiers() == Qt::ControlModifier) { + view->reload(); + event->accept(); + } + break; + + case Qt::Key_R: + if (view) { + if (event->modifiers() == Qt::ControlModifier) { + view->reload(); + event->accept(); + } + if (event->modifiers() == (Qt::ControlModifier + Qt::ShiftModifier)) { + view->reloadBypassCache(); + event->accept(); + } + } + break; + case Qt::Key_HomePage: goHome(); event->accept(); break; case Qt::Key_Favorites: - showBookmarksManager(); + mApp->browsingLibrary()->showBookmarks(this); event->accept(); break; @@ -1793,12 +1279,12 @@ void BrowserWindow::keyPressEvent(QKeyEvent* event) break; case Qt::Key_News: - showRSSManager(); + action(QSL("Tools/RssReader"))->trigger(); event->accept(); break; case Qt::Key_Tools: - showPreferences(); + action(QSL("Standard/Preferences"))->trigger(); event->accept(); break; @@ -1832,21 +1318,36 @@ void BrowserWindow::keyPressEvent(QKeyEvent* event) case Qt::Key_Equal: if (view && event->modifiers() == Qt::ControlModifier) { - weView()->zoomIn(); + view->zoomIn(); event->accept(); } break; case Qt::Key_I: if (event->modifiers() == Qt::ControlModifier) { - showPageInfo(); + action(QSL("Tools/SiteInfo"))->trigger(); event->accept(); } break; case Qt::Key_U: if (event->modifiers() == Qt::ControlModifier) { - showSource(); + action(QSL("View/PageSource"))->trigger(); + event->accept(); + } + break; + + case Qt::Key_D: + if (event->modifiers() == Qt::AltModifier) { + openLocation(); + event->accept(); + } + break; + + case Qt::Key_F4: + case Qt::Key_W: + if (event->modifiers() == Qt::ControlModifier) { + closeTab(); event->accept(); } break; @@ -1965,7 +1466,7 @@ void BrowserWindow::closeEvent(QCloseEvent* event) event->accept(); } -SearchToolBar* BrowserWindow::searchToolBar() +SearchToolBar* BrowserWindow::searchToolBar() const { SearchToolBar* toolBar = 0; const int searchPos = 3; @@ -2011,12 +1512,12 @@ void BrowserWindow::disconnectObjects() void BrowserWindow::closeWindow() { #ifdef Q_OS_MAC - close(); + if (true) { #else if (mApp->windowCount() > 1) { +#endif close(); } -#endif } bool BrowserWindow::quitApp() @@ -2029,8 +1530,8 @@ bool BrowserWindow::quitApp() Settings settings; settings.beginGroup("Browser-View-Settings"); settings.setValue("WindowMaximised", windowState().testFlag(Qt::WindowMaximized)); - settings.setValue("LocationBarWidth", m_navigationBar->splitter()->sizes().at(0)); - settings.setValue("WebSearchBarWidth", m_navigationBar->splitter()->sizes().at(1)); + settings.setValue("LocationBarWidth", m_navigationToolbar->splitter()->sizes().at(0)); + settings.setValue("WebSearchBarWidth", m_navigationToolbar->splitter()->sizes().at(1)); settings.setValue("SideBarWidth", m_sideBarWidth); settings.setValue("WebViewWidth", m_webViewWidth); @@ -2052,60 +1553,6 @@ void BrowserWindow::closeTab() } } -void BrowserWindow::restoreClosedTab(QObject* obj) -{ - if (!obj) { - obj = sender(); - } - m_tabWidget->restoreClosedTab(obj); -} - -void BrowserWindow::restoreAllClosedTabs() -{ - m_tabWidget->restoreAllClosedTabs(); -} - -void BrowserWindow::clearClosedTabsList() -{ - m_tabWidget->clearClosedTabsList(); -} - -bool BrowserWindow::bookmarksMenuChanged() -{ -#ifdef Q_OS_MAC - return mApp->macMenuReceiver()->bookmarksMenuChanged(); -#else - return m_bookmarksMenuChanged; -#endif -} - -void BrowserWindow::setBookmarksMenuChanged(bool changed) -{ -#ifdef Q_OS_MAC - mApp->macMenuReceiver()->setBookmarksMenuChanged(changed); -#else - m_bookmarksMenuChanged = changed; -#endif -} - -QAction* BrowserWindow::menuBookmarksAction() -{ -#ifdef Q_OS_MAC - return mApp->macMenuReceiver()->menuBookmarksAction(); -#else - return m_menuBookmarksAction; -#endif -} - -void BrowserWindow::setMenuBookmarksAction(QAction* action) -{ -#ifdef Q_OS_MAC - mApp->macMenuReceiver()->setMenuBookmarksAction(action); -#else - m_menuBookmarksAction = action; -#endif -} - QByteArray BrowserWindow::saveState(int version) const { #ifdef QZ_WS_X11 diff --git a/src/lib/app/browserwindow.h b/src/lib/app/browserwindow.h index e28a831fa..58c61f85a 100644 --- a/src/lib/app/browserwindow.h +++ b/src/lib/app/browserwindow.h @@ -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 m_webInspectorDock; - QWidget* m_navigationContainer; - BookmarksToolbar* m_bookmarksToolbar; TabWidget* m_tabWidget; QPointer 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 > m_deleteOnCloseWidgets; - mutable int m_tabsOnTopState; }; #endif // QUPZILLA_H diff --git a/src/lib/app/datapaths.h b/src/lib/app/datapaths.h index a8b4e8cf0..a17229f25 100644 --- a/src/lib/app/datapaths.h +++ b/src/lib/app/datapaths.h @@ -21,7 +21,9 @@ #include #include -class DataPaths +#include "qzcommon.h" + +class QUPZILLA_EXPORT DataPaths { public: enum Path { diff --git a/src/lib/app/mainapplication.cpp b/src/lib/app/mainapplication.cpp index d6386cb36..5de68b024 100644 --- a/src/lib/app/mainapplication.cpp +++ b/src/lib/app/mainapplication.cpp @@ -791,14 +791,13 @@ void MainApplication::messageReceived(QString message) } } -void MainApplication::windowDestroyed(QObject* window) +void MainApplication::windowDestroyed(QObject *window) { - Q_ASSERT(qobject_cast(window)); - Q_ASSERT(m_windows.contains(qobject_cast(window))); + // qobject_cast doesn't work because QObject::destroyed is emitted from destructor + Q_ASSERT(static_cast(window)); + Q_ASSERT(m_windows.contains(static_cast(window))); - m_windows.removeOne(qobject_cast(window)); - - qDebug("Destroyed"); + m_windows.removeOne(static_cast(window)); } void MainApplication::loadSettings() diff --git a/src/lib/app/mainmenu.cpp b/src/lib/app/mainmenu.cpp new file mode 100644 index 000000000..72515c4fe --- /dev/null +++ b/src/lib/app/mainmenu.cpp @@ -0,0 +1,681 @@ +/* ============================================================ +* QupZilla - WebKit based browser +* Copyright (C) 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 "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 +#include +#include +#include +#include + +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(sender()); + Q_ASSERT(menu); + + if (m_window) { + menu->clear(); + m_window->createToolbarsMenu(menu); + } +} + +void MainMenu::aboutToShowSidebarsMenu() +{ + QMenu* menu = qobject_cast(sender()); + Q_ASSERT(menu); + + if (m_window) { + menu->clear(); + m_window->createSidebarsMenu(menu); + } +} + +void MainMenu::aboutToShowEncodingMenu() +{ + QMenu* menu = qobject_cast(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 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); + } +} diff --git a/src/lib/app/mainmenu.h b/src/lib/app/mainmenu.h new file mode 100644 index 000000000..51f2bb36f --- /dev/null +++ b/src/lib/app/mainmenu.h @@ -0,0 +1,134 @@ +/* ============================================================ +* QupZilla - WebKit based browser +* Copyright (C) 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 MAINMENU_H +#define MAINMENU_H + +#include +#include +#include + +#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 m_actions; + + QPointer 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 diff --git a/src/lib/app/qzcommon.h b/src/lib/app/qzcommon.h index c5831a348..3e8623703 100644 --- a/src/lib/app/qzcommon.h +++ b/src/lib/app/qzcommon.h @@ -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 diff --git a/src/lib/lib.pro b/src/lib/lib.pro index a097d1de4..7d33c56d6 100644 --- a/src/lib/lib.pro +++ b/src/lib/lib.pro @@ -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 \ diff --git a/src/lib/navigation/navigationbar.cpp b/src/lib/navigation/navigationbar.cpp index b2e6fbb16..3aeb4f988 100644 --- a/src/lib/navigation/navigationbar.cpp +++ b/src/lib/navigation/navigationbar.cpp @@ -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(); diff --git a/src/lib/navigation/navigationbar.h b/src/lib/navigation/navigationbar.h index ab2677b2e..7378cc864 100644 --- a/src/lib/navigation/navigationbar.h +++ b/src/lib/navigation/navigationbar.h @@ -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(); diff --git a/src/lib/navigation/navigationcontainer.cpp b/src/lib/navigation/navigationcontainer.cpp index 8f38ea941..150d3fc91 100644 --- a/src/lib/navigation/navigationcontainer.cpp +++ b/src/lib/navigation/navigationcontainer.cpp @@ -17,13 +17,11 @@ * ============================================================ */ #include "navigationcontainer.h" #include "qzsettings.h" -#include "browserwindow.h" #include -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 + // 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); } } diff --git a/src/lib/navigation/navigationcontainer.h b/src/lib/navigation/navigationcontainer.h index 05b216f4b..0390a794f 100644 --- a/src/lib/navigation/navigationcontainer.h +++ b/src/lib/navigation/navigationcontainer.h @@ -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 diff --git a/src/lib/other/clearprivatedata.cpp b/src/lib/other/clearprivatedata.cpp index c7fd57160..bd6b05cbc 100644 --- a/src/lib/other/clearprivatedata.cpp +++ b/src/lib/other/clearprivatedata.cpp @@ -39,9 +39,8 @@ #include #include -ClearPrivateData::ClearPrivateData(BrowserWindow* window, QWidget* parent) +ClearPrivateData::ClearPrivateData(QWidget* parent) : QDialog(parent) - , m_window(window) , ui(new Ui::ClearPrivateData) { ui->setupUi(this); diff --git a/src/lib/other/clearprivatedata.h b/src/lib/other/clearprivatedata.h index 49e9cf506..5cf253869 100644 --- a/src/lib/other/clearprivatedata.h +++ b/src/lib/other/clearprivatedata.h @@ -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; }; diff --git a/src/lib/other/qzsettings.cpp b/src/lib/other/qzsettings.cpp index ef1b98fb3..ca1550102 100644 --- a/src/lib/other/qzsettings.cpp +++ b/src/lib/other/qzsettings.cpp @@ -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(); } diff --git a/src/lib/popupwindow/popupwindow.cpp b/src/lib/popupwindow/popupwindow.cpp index 7ee793692..6d91037ab 100644 --- a/src/lib/popupwindow/popupwindow.cpp +++ b/src/lib/popupwindow/popupwindow.cpp @@ -218,7 +218,7 @@ void PopupWindow::closeEvent(QCloseEvent* event) void PopupWindow::editSelectAll() { - m_view->selectAll(); + m_view->editSelectAll(); } void PopupWindow::aboutToShowEditMenu() diff --git a/src/lib/sidebar/sidebar.cpp b/src/lib/sidebar/sidebar.cpp index eae149299..1f493a9ce 100644 --- a/src/lib/sidebar/sidebar.cpp +++ b/src/lib/sidebar/sidebar.cpp @@ -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 &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 &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(sender())) { @@ -162,15 +142,12 @@ void SideBarManager::slotShowSideBar() } } -void SideBarManager::updateActions() +void SideBarManager::clearMenu() { - if (!m_menu) { - return; - } + QMenu* menu = qobject_cast(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(); } diff --git a/src/lib/sidebar/sidebar.h b/src/lib/sidebar/sidebar.h index 82041bb66..5aa5fed98 100644 --- a/src/lib/sidebar/sidebar.h +++ b/src/lib/sidebar/sidebar.h @@ -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 m_sideBar; QMenu* m_menu; diff --git a/src/lib/tools/menubar.cpp b/src/lib/tools/menubar.cpp index 65fdd820c..dc4c7fd97 100644 --- a/src/lib/tools/menubar.cpp +++ b/src/lib/tools/menubar.cpp @@ -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)); } } diff --git a/src/lib/webview/tabbar.cpp b/src/lib/webview/tabbar.cpp index 4022444dc..8de3808d9 100644 --- a/src/lib/webview/tabbar.cpp +++ b/src/lib/webview/tabbar.cpp @@ -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() diff --git a/src/lib/webview/tabbedwebview.cpp b/src/lib/webview/tabbedwebview.cpp index b100a5408..23db6553f 100644 --- a/src/lib/webview/tabbedwebview.cpp +++ b/src/lib/webview/tabbedwebview.cpp @@ -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() -{ -} diff --git a/src/lib/webview/tabbedwebview.h b/src/lib/webview/tabbedwebview.h index 250e20d87..67140ebfe 100644 --- a/src/lib/webview/tabbedwebview.h +++ b/src/lib/webview/tabbedwebview.h @@ -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; }; diff --git a/src/lib/webview/tabwidget.cpp b/src/lib/webview/tabwidget.cpp index 4dbb78de0..579bda97f 100644 --- a/src/lib/webview/tabwidget.cpp +++ b/src/lib/webview/tabwidget.cpp @@ -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); diff --git a/src/lib/webview/webtab.cpp b/src/lib/webview/webtab.cpp index b44c448f8..ffcdca0b3 100644 --- a/src/lib/webview/webtab.cpp +++ b/src/lib/webview/webtab.cpp @@ -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; diff --git a/src/lib/webview/webview.cpp b/src/lib/webview/webview.cpp index 5ee9f4e43..fe96bb8c8 100644 --- a/src/lib/webview/webview.cpp +++ b/src/lib/webview/webview.cpp @@ -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; } diff --git a/src/lib/webview/webview.h b/src/lib/webview/webview.h index 9c2501619..acb617435 100644 --- a/src/lib/webview/webview.h +++ b/src/lib/webview/webview.h @@ -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();