2011-03-03 18:29:20 +01:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
2014-01-11 16:11:42 +01:00
|
|
|
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com>
|
2011-03-03 18:29:20 +01:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
* ============================================================ */
|
2014-02-19 22:07:21 +01:00
|
|
|
#include "browserwindow.h"
|
2011-03-02 16:57:41 +01:00
|
|
|
#include "tabwidget.h"
|
|
|
|
#include "tabbar.h"
|
|
|
|
#include "webpage.h"
|
2012-01-21 20:27:45 +01:00
|
|
|
#include "tabbedwebview.h"
|
2011-03-02 16:57:41 +01:00
|
|
|
#include "lineedit.h"
|
2012-04-30 16:33:14 +02:00
|
|
|
#include "history.h"
|
2011-03-02 16:57:41 +01:00
|
|
|
#include "locationbar.h"
|
|
|
|
#include "searchtoolbar.h"
|
|
|
|
#include "websearchbar.h"
|
2013-01-17 15:24:30 +01:00
|
|
|
#include "pluginproxy.h"
|
|
|
|
#include "sidebar.h"
|
2011-03-02 16:57:41 +01:00
|
|
|
#include "downloadmanager.h"
|
|
|
|
#include "cookiejar.h"
|
|
|
|
#include "cookiemanager.h"
|
|
|
|
#include "bookmarkstoolbar.h"
|
|
|
|
#include "clearprivatedata.h"
|
|
|
|
#include "sourceviewer.h"
|
|
|
|
#include "networkmanager.h"
|
2013-01-24 17:47:50 +01:00
|
|
|
#include "autofill.h"
|
2011-03-02 16:57:41 +01:00
|
|
|
#include "networkmanagerproxy.h"
|
|
|
|
#include "rssmanager.h"
|
|
|
|
#include "mainapplication.h"
|
2012-03-15 19:35:37 +01:00
|
|
|
#include "checkboxdialog.h"
|
2011-03-27 21:59:40 +02:00
|
|
|
#include "adblockmanager.h"
|
|
|
|
#include "clickablelabel.h"
|
2011-04-15 20:45:22 +02:00
|
|
|
#include "docktitlebarwidget.h"
|
2011-04-25 20:56:45 +02:00
|
|
|
#include "iconprovider.h"
|
2011-04-25 15:06:59 +02:00
|
|
|
#include "progressbar.h"
|
2011-05-07 12:59:53 +02:00
|
|
|
#include "adblockicon.h"
|
|
|
|
#include "closedtabsmanager.h"
|
2011-05-09 17:58:19 +02:00
|
|
|
#include "statusbarmessage.h"
|
2011-07-29 15:39:43 +02:00
|
|
|
#include "browsinglibrary.h"
|
2011-09-11 19:15:06 +02:00
|
|
|
#include "navigationbar.h"
|
2011-09-21 14:20:49 +02:00
|
|
|
#include "pagescreen.h"
|
2011-10-14 20:14:57 +02:00
|
|
|
#include "webinspectordockwidget.h"
|
2014-02-15 01:49:12 +01:00
|
|
|
#include "bookmarksimport/bookmarksimportdialog.h"
|
2013-01-22 19:04:22 +01:00
|
|
|
#include "qztools.h"
|
2013-03-08 21:01:55 +01:00
|
|
|
#include "actioncopy.h"
|
2012-10-20 11:31:45 +02:00
|
|
|
#include "reloadstopbutton.h"
|
2011-12-14 22:30:05 +01:00
|
|
|
#include "enhancedmenu.h"
|
2013-02-11 13:08:11 +01:00
|
|
|
#include "navigationcontainer.h"
|
2012-01-11 21:58:25 +01:00
|
|
|
#include "settings.h"
|
2013-02-09 13:00:45 +01:00
|
|
|
#include "qzsettings.h"
|
2012-01-21 23:19:38 +01:00
|
|
|
#include "webtab.h"
|
2012-02-05 17:13:08 +01:00
|
|
|
#include "speeddial.h"
|
2013-02-09 14:08:12 +01:00
|
|
|
#include "menubar.h"
|
2012-04-02 19:33:05 +02:00
|
|
|
#include "qtwin.h"
|
2014-02-08 23:01:01 +01:00
|
|
|
#include "bookmarkstools.h"
|
2014-02-09 01:09:08 +01:00
|
|
|
#include "bookmarksmenu.h"
|
2014-02-27 22:53:56 +01:00
|
|
|
#include "historymenu.h"
|
2014-03-10 16:55:11 +01:00
|
|
|
#include "mainmenu.h"
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-08-31 15:19:07 +02:00
|
|
|
#include <QKeyEvent>
|
2012-02-29 18:33:50 +01:00
|
|
|
#include <QSplitter>
|
|
|
|
#include <QStatusBar>
|
|
|
|
#include <QMenuBar>
|
|
|
|
#include <QTimer>
|
|
|
|
#include <QShortcut>
|
|
|
|
#include <QStackedWidget>
|
|
|
|
#include <QSqlQuery>
|
|
|
|
#include <QTextCodec>
|
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QNetworkRequest>
|
|
|
|
#include <QDesktopServices>
|
|
|
|
#include <QPrintPreviewDialog>
|
2013-05-31 10:46:50 +02:00
|
|
|
#include <QPrinter>
|
2012-02-29 18:33:50 +01:00
|
|
|
#include <QWebFrame>
|
2012-04-04 13:21:53 +02:00
|
|
|
#include <QWebHistory>
|
2012-02-29 18:33:50 +01:00
|
|
|
#include <QMessageBox>
|
2013-03-23 17:37:58 +01:00
|
|
|
#include <QDesktopWidget>
|
2013-05-12 10:59:33 +02:00
|
|
|
#include <QToolTip>
|
2013-11-26 14:14:36 +01:00
|
|
|
#include <QScrollArea>
|
2012-02-29 18:33:50 +01:00
|
|
|
|
2012-12-22 12:47:45 +01:00
|
|
|
#if QT_VERSION < 0x050000
|
|
|
|
#include "qwebkitversion.h"
|
2012-12-22 15:01:55 +01:00
|
|
|
#endif
|
|
|
|
|
2014-03-03 14:47:47 +01:00
|
|
|
#ifdef QZ_WS_X11
|
2012-09-06 11:39:42 +02:00
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <X11/Xatom.h>
|
2012-12-22 15:01:55 +01:00
|
|
|
#endif
|
2012-12-20 14:45:35 +01:00
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
const QString BrowserWindow::WEBKITVERSION = qWebKitVersion();
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2014-03-10 16:55:11 +01:00
|
|
|
BrowserWindow::BrowserWindow(Qz::BrowserWindowType type, const QUrl &startUrl)
|
2012-04-17 14:00:32 +02:00
|
|
|
: QMainWindow(0)
|
2011-10-31 21:27:52 +01:00
|
|
|
, m_isClosing(false)
|
2012-03-13 17:51:37 +01:00
|
|
|
, m_isStarting(false)
|
2014-03-10 16:55:11 +01:00
|
|
|
, m_startUrl(startUrl)
|
2013-02-15 22:18:46 +01:00
|
|
|
, m_windowType(type)
|
2013-05-13 22:01:36 +02:00
|
|
|
, m_startTab(0)
|
2012-04-01 16:36:38 +02:00
|
|
|
, m_sideBarManager(new SideBarManager(this))
|
2011-10-15 16:37:32 +02:00
|
|
|
, m_statusBarMessage(new StatusBarMessage(this))
|
2014-03-10 16:55:11 +01:00
|
|
|
, m_useTransparentBackground(false)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2011-09-11 19:15:06 +02:00
|
|
|
setObjectName("mainwindow");
|
2011-03-05 10:57:36 +01:00
|
|
|
setAttribute(Qt::WA_DeleteOnClose);
|
2012-01-16 18:28:56 +01:00
|
|
|
setWindowTitle(tr("QupZilla"));
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2014-03-10 00:47:07 +01:00
|
|
|
if (mApp->isPrivate()) {
|
2012-06-26 11:49:39 +02:00
|
|
|
setProperty("private", QVariant(true));
|
|
|
|
}
|
|
|
|
|
2012-03-13 17:51:37 +01:00
|
|
|
m_isStarting = true;
|
2011-03-02 16:57:41 +01:00
|
|
|
|
|
|
|
setupUi();
|
|
|
|
setupMenu();
|
2012-01-08 11:38:15 +01:00
|
|
|
|
2013-02-09 15:44:17 +01:00
|
|
|
m_hideNavigationTimer = new QTimer(this);
|
|
|
|
m_hideNavigationTimer->setInterval(1000);
|
|
|
|
m_hideNavigationTimer->setSingleShot(true);
|
|
|
|
connect(m_hideNavigationTimer, SIGNAL(timeout()), this, SLOT(hideNavigationSlot()));
|
|
|
|
|
2014-03-10 00:47:07 +01:00
|
|
|
connect(mApp, SIGNAL(settingsReloaded()), this, SLOT(loadSettings()));
|
2013-02-09 15:44:17 +01:00
|
|
|
|
|
|
|
QTimer::singleShot(0, this, SLOT(postLaunch()));
|
2013-07-07 12:32:55 +02:00
|
|
|
|
2014-03-10 00:47:07 +01:00
|
|
|
if (mApp->isPrivate()) {
|
2013-10-21 15:59:25 +02:00
|
|
|
QzTools::setWmClass("QupZilla Browser (Private Window)", this);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
QzTools::setWmClass("QupZilla Browser", this);
|
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2014-03-10 19:41:44 +01:00
|
|
|
BrowserWindow::~BrowserWindow()
|
|
|
|
{
|
2014-03-13 11:24:19 +01:00
|
|
|
mApp->plugins()->emitMainWindowDeleted(this);
|
|
|
|
|
|
|
|
foreach (const QPointer<QWidget> &pointer, m_deleteOnCloseWidgets) {
|
|
|
|
if (pointer) {
|
|
|
|
pointer->deleteLater();
|
|
|
|
}
|
|
|
|
}
|
2014-03-10 19:41:44 +01:00
|
|
|
}
|
|
|
|
|
2014-03-10 16:55:11 +01:00
|
|
|
void BrowserWindow::setStartTab(WebTab* tab)
|
2013-05-13 22:01:36 +02:00
|
|
|
{
|
|
|
|
m_startTab = tab;
|
|
|
|
}
|
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
void BrowserWindow::postLaunch()
|
2011-05-07 12:59:53 +02:00
|
|
|
{
|
|
|
|
loadSettings();
|
2012-01-18 18:36:10 +01:00
|
|
|
|
2012-01-11 21:58:25 +01:00
|
|
|
Settings settings;
|
2014-02-11 15:44:47 +01:00
|
|
|
int afterLaunch = settings.value("Web-URL-Settings/afterLaunch", 3).toInt();
|
2012-03-10 13:57:50 +01:00
|
|
|
bool addTab = true;
|
2011-05-07 12:59:53 +02:00
|
|
|
QUrl startUrl;
|
2012-03-14 14:04:20 +01:00
|
|
|
|
2011-12-04 20:35:49 +01:00
|
|
|
switch (afterLaunch) {
|
|
|
|
case 0:
|
2012-09-02 11:42:41 +02:00
|
|
|
startUrl = QUrl();
|
2011-12-04 20:35:49 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
startUrl = QUrl("qupzilla:speeddial");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
case 3:
|
|
|
|
startUrl = m_homepage;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-02-15 22:18:46 +01:00
|
|
|
switch (m_windowType) {
|
2012-01-21 23:19:38 +01:00
|
|
|
case Qz::BW_FirstAppWindow:
|
2012-08-21 20:28:38 +02:00
|
|
|
if (mApp->isStartingAfterCrash()) {
|
|
|
|
addTab = true;
|
|
|
|
startUrl = QUrl("qupzilla:restore");
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2012-08-21 20:28:38 +02:00
|
|
|
else if (afterLaunch == 3 && mApp->restoreManager()) {
|
2014-03-10 00:47:07 +01:00
|
|
|
addTab = !mApp->restoreSession(this, mApp->restoreManager()->restoreData());
|
2012-03-14 14:04:20 +01:00
|
|
|
}
|
2014-02-24 11:38:18 +01:00
|
|
|
else {
|
|
|
|
// Pinned tabs are restored in MainApplication::restoreStateSlot
|
|
|
|
// Make sure they will be restored also when not restoring session
|
|
|
|
m_tabWidget->restorePinnedTabs();
|
|
|
|
}
|
2011-11-03 18:51:46 +01:00
|
|
|
break;
|
|
|
|
|
2013-02-07 14:01:01 +01:00
|
|
|
case Qz::BW_MacFirstWindow:
|
2014-02-24 11:38:18 +01:00
|
|
|
m_tabWidget->restorePinnedTabs();
|
|
|
|
// fallthrough
|
|
|
|
|
2012-01-21 23:19:38 +01:00
|
|
|
case Qz::BW_NewWindow:
|
2011-11-03 18:51:46 +01:00
|
|
|
addTab = true;
|
|
|
|
break;
|
|
|
|
|
2012-01-21 23:19:38 +01:00
|
|
|
case Qz::BW_OtherRestoredWindow:
|
2011-11-03 18:51:46 +01:00
|
|
|
addTab = false;
|
|
|
|
break;
|
|
|
|
}
|
2011-05-07 12:59:53 +02:00
|
|
|
|
2012-09-06 11:39:42 +02:00
|
|
|
show();
|
|
|
|
|
2014-03-10 16:55:11 +01:00
|
|
|
if (!m_startUrl.isEmpty()) {
|
|
|
|
startUrl = m_startUrl;
|
2011-05-07 12:59:53 +02:00
|
|
|
addTab = true;
|
|
|
|
}
|
|
|
|
|
2013-05-13 22:01:36 +02:00
|
|
|
if (m_startTab) {
|
|
|
|
addTab = false;
|
|
|
|
m_tabWidget->addView(m_startTab);
|
|
|
|
}
|
|
|
|
|
2011-12-05 19:54:17 +01:00
|
|
|
if (addTab) {
|
2012-07-13 11:04:14 +02:00
|
|
|
QNetworkRequest request(startUrl);
|
|
|
|
request.setRawHeader("X-QupZilla-UserLoadAction", QByteArray("1"));
|
|
|
|
|
|
|
|
m_tabWidget->addView(request, Qz::NT_CleanSelectedTabAtTheEnd);
|
2011-12-05 19:54:17 +01:00
|
|
|
|
2012-09-04 12:42:45 +02:00
|
|
|
if (startUrl.isEmpty() || startUrl.toString() == QLatin1String("qupzilla:speeddial")) {
|
2011-12-05 19:54:17 +01:00
|
|
|
locationBar()->setFocus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-15 22:18:46 +01:00
|
|
|
if (m_tabWidget->getTabBar()->normalTabsCount() <= 0 && m_windowType != Qz::BW_OtherRestoredWindow) {
|
2013-05-13 22:01:36 +02:00
|
|
|
// Something went really wrong .. add one tab
|
2012-07-13 11:04:14 +02:00
|
|
|
QNetworkRequest request(m_homepage);
|
|
|
|
request.setRawHeader("X-QupZilla-UserLoadAction", QByteArray("1"));
|
|
|
|
|
|
|
|
m_tabWidget->addView(request, Qz::NT_SelectedTabAtTheEnd);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-05-07 12:59:53 +02:00
|
|
|
|
2013-02-07 14:01:01 +01:00
|
|
|
#ifdef Q_OS_MAC
|
2013-05-13 22:01:36 +02:00
|
|
|
// Fill menus even if user don't call them
|
2013-02-18 21:03:46 +01:00
|
|
|
if (m_windowType == Qz::BW_FirstAppWindow) {
|
2013-02-07 14:01:01 +01:00
|
|
|
aboutToShowBookmarksMenu();
|
|
|
|
aboutToShowHistoryMostMenu();
|
|
|
|
aboutToShowHistoryRecentMenu();
|
|
|
|
aboutToShowEncodingMenu();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-03-05 13:16:34 +01:00
|
|
|
mApp->plugins()->emitMainWindowCreated(this);
|
2011-05-07 12:59:53 +02:00
|
|
|
emit startingCompleted();
|
2012-03-13 17:51:37 +01:00
|
|
|
|
|
|
|
m_isStarting = false;
|
|
|
|
|
2013-03-16 10:36:29 +01:00
|
|
|
raise();
|
|
|
|
activateWindow();
|
2013-11-26 14:14:36 +01:00
|
|
|
|
|
|
|
QTimer::singleShot(0, tabWidget()->getTabBar(), SLOT(ensureVisible()));
|
2011-05-07 12:59:53 +02:00
|
|
|
}
|
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
void BrowserWindow::setupUi()
|
2011-05-07 12:59:53 +02:00
|
|
|
{
|
2011-10-17 09:59:09 +02:00
|
|
|
int locationBarWidth;
|
|
|
|
int websearchBarWidth;
|
|
|
|
|
2012-01-11 21:58:25 +01:00
|
|
|
Settings settings;
|
2011-09-21 12:43:27 +02:00
|
|
|
settings.beginGroup("Browser-View-Settings");
|
|
|
|
if (settings.value("WindowMaximised", false).toBool()) {
|
|
|
|
resize(800, 550);
|
2011-10-01 20:06:38 +02:00
|
|
|
setWindowState(Qt::WindowMaximized);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
else {
|
2013-03-23 17:37:58 +01:00
|
|
|
// Let the WM decides where to put new browser window
|
2013-08-03 22:17:15 +02:00
|
|
|
if ((m_windowType != Qz::BW_FirstAppWindow && m_windowType != Qz::BW_MacFirstWindow) && mApp->getWindow()) {
|
2013-03-23 17:37:58 +01:00
|
|
|
#ifdef Q_WS_WIN
|
|
|
|
// Windows WM places every new window in the middle of screen .. for some reason
|
|
|
|
QPoint p = mApp->getWindow()->geometry().topLeft();
|
|
|
|
p.setX(p.x() + 30);
|
|
|
|
p.setY(p.y() + 30);
|
|
|
|
|
2013-08-03 22:17:15 +02:00
|
|
|
if (!mApp->desktop()->availableGeometry(mApp->getWindow()).contains(p)) {
|
|
|
|
p.setX(mApp->desktop()->availableGeometry(mApp->getWindow()).x() + 30);
|
|
|
|
p.setY(mApp->desktop()->availableGeometry(mApp->getWindow()).y() + 30);
|
2013-03-23 17:37:58 +01:00
|
|
|
}
|
|
|
|
setGeometry(QRect(p, mApp->getWindow()->size()));
|
|
|
|
#else
|
|
|
|
resize(mApp->getWindow()->size());
|
|
|
|
#endif
|
2012-02-01 20:31:51 +01:00
|
|
|
}
|
2013-03-23 17:37:58 +01:00
|
|
|
else if (!restoreGeometry(settings.value("WindowGeometry").toByteArray())) {
|
|
|
|
#ifdef Q_WS_WIN
|
2013-08-03 22:17:15 +02:00
|
|
|
setGeometry(QRect(mApp->desktop()->availableGeometry(mApp->getWindow()).x() + 30,
|
|
|
|
mApp->desktop()->availableGeometry(mApp->getWindow()).y() + 30, 800, 550));
|
2013-03-23 17:37:58 +01:00
|
|
|
#else
|
|
|
|
resize(800, 550);
|
|
|
|
#endif
|
2011-11-09 16:58:25 +01:00
|
|
|
}
|
2011-09-21 12:43:27 +02:00
|
|
|
}
|
|
|
|
|
2011-12-03 11:27:53 +01:00
|
|
|
locationBarWidth = settings.value("LocationBarWidth", 480).toInt();
|
|
|
|
websearchBarWidth = settings.value("WebSearchBarWidth", 140).toInt();
|
2012-04-04 18:48:54 +02:00
|
|
|
settings.endGroup();
|
2011-10-17 09:59:09 +02:00
|
|
|
|
2011-08-02 16:19:20 +02:00
|
|
|
QWidget* widget = new QWidget(this);
|
2011-12-03 12:07:10 +01:00
|
|
|
widget->setCursor(Qt::ArrowCursor);
|
2011-09-11 19:15:06 +02:00
|
|
|
setCentralWidget(widget);
|
|
|
|
|
2011-08-02 16:19:20 +02:00
|
|
|
m_mainLayout = new QVBoxLayout(widget);
|
2011-11-06 17:01:23 +01:00
|
|
|
m_mainLayout->setContentsMargins(0, 0, 0, 0);
|
2011-08-02 16:19:20 +02:00
|
|
|
m_mainLayout->setSpacing(0);
|
2011-09-11 19:15:06 +02:00
|
|
|
m_mainSplitter = new QSplitter(this);
|
2011-10-28 23:17:38 +02:00
|
|
|
m_mainSplitter->setObjectName("sidebar-splitter");
|
2011-09-11 19:15:06 +02:00
|
|
|
m_mainSplitter->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
|
2011-07-11 20:30:49 +02:00
|
|
|
m_tabWidget = new TabWidget(this);
|
2011-05-07 12:59:53 +02:00
|
|
|
m_superMenu = new QMenu(this);
|
2014-03-10 16:55:11 +01:00
|
|
|
m_navigationToolbar = new NavigationBar(this);
|
|
|
|
m_navigationToolbar->setSplitterSizes(locationBarWidth, websearchBarWidth);
|
2011-09-11 19:15:06 +02:00
|
|
|
m_bookmarksToolbar = new BookmarksToolbar(this);
|
2012-08-30 10:46:58 +02:00
|
|
|
|
2013-02-11 13:08:11 +01:00
|
|
|
m_navigationContainer = new NavigationContainer(this);
|
2013-02-09 13:00:45 +01:00
|
|
|
QVBoxLayout* l = new QVBoxLayout(m_navigationContainer);
|
|
|
|
l->setContentsMargins(0, 0, 0, 0);
|
|
|
|
l->setSpacing(0);
|
2014-03-10 16:55:11 +01:00
|
|
|
l->addWidget(m_navigationToolbar);
|
2013-02-09 13:00:45 +01:00
|
|
|
l->addWidget(m_bookmarksToolbar);
|
|
|
|
m_navigationContainer->setLayout(l);
|
|
|
|
|
2011-09-11 19:15:06 +02:00
|
|
|
m_mainSplitter->addWidget(m_tabWidget);
|
2014-03-10 16:55:11 +01:00
|
|
|
toggleTabsOnTop(qzSettings->tabsOnTop);
|
2011-09-11 19:15:06 +02:00
|
|
|
m_mainLayout->addWidget(m_mainSplitter);
|
|
|
|
m_mainSplitter->setCollapsible(0, false);
|
2011-05-07 12:59:53 +02:00
|
|
|
|
2011-09-11 19:15:06 +02:00
|
|
|
statusBar()->setObjectName("mainwindow-statusbar");
|
2011-12-03 12:07:10 +01:00
|
|
|
statusBar()->setCursor(Qt::ArrowCursor);
|
2011-05-07 12:59:53 +02:00
|
|
|
m_progressBar = new ProgressBar(statusBar());
|
|
|
|
m_privateBrowsing = new QLabel(this);
|
|
|
|
m_privateBrowsing->setPixmap(QPixmap(":/icons/locationbar/privatebrowsing.png"));
|
|
|
|
m_privateBrowsing->setVisible(false);
|
|
|
|
m_privateBrowsing->setToolTip(tr("Private Browsing Enabled"));
|
|
|
|
m_adblockIcon = new AdBlockIcon(this);
|
|
|
|
m_ipLabel = new QLabel(this);
|
2011-09-11 19:15:06 +02:00
|
|
|
m_ipLabel->setObjectName("statusbar-ip-label");
|
2011-05-07 12:59:53 +02:00
|
|
|
m_ipLabel->setToolTip(tr("IP Address of current page"));
|
|
|
|
|
2013-05-26 15:46:21 +02:00
|
|
|
statusBar()->addPermanentWidget(m_progressBar);
|
|
|
|
statusBar()->addPermanentWidget(m_ipLabel);
|
|
|
|
statusBar()->addPermanentWidget(m_privateBrowsing);
|
|
|
|
statusBar()->addPermanentWidget(m_adblockIcon);
|
2013-05-12 10:59:33 +02:00
|
|
|
|
|
|
|
// Workaround for Oxygen tooltips not having transparent background
|
|
|
|
QPalette pal = QToolTip::palette();
|
|
|
|
QColor col = pal.window().color();
|
|
|
|
col.setAlpha(0);
|
|
|
|
pal.setColor(QPalette::Window, col);
|
|
|
|
QToolTip::setPalette(pal);
|
2011-05-07 12:59:53 +02:00
|
|
|
}
|
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
void BrowserWindow::setupMenu()
|
2011-05-07 12:59:53 +02:00
|
|
|
{
|
2014-03-10 16:55:11 +01:00
|
|
|
// TODO: Mac menu
|
2014-03-13 13:38:14 +01:00
|
|
|
#ifdef Q_OS_MAC
|
2013-03-16 14:57:08 +01:00
|
|
|
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));
|
2014-03-10 16:55:11 +01:00
|
|
|
#else
|
|
|
|
setMenuBar(new MenuBar(this));
|
2013-03-23 00:47:55 +01:00
|
|
|
|
2014-03-10 16:55:11 +01:00
|
|
|
m_mainMenu = new MainMenu(this, this);
|
|
|
|
m_mainMenu->initMenuBar(menuBar());
|
|
|
|
m_mainMenu->initSuperMenu(m_superMenu);
|
2013-02-08 15:21:00 +01:00
|
|
|
#endif
|
2014-03-10 16:55:11 +01:00
|
|
|
}
|
2011-05-07 12:59:53 +02:00
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
void BrowserWindow::loadSettings()
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2012-01-11 21:58:25 +01:00
|
|
|
Settings settings;
|
2011-03-02 16:57:41 +01:00
|
|
|
|
|
|
|
//Url settings
|
|
|
|
settings.beginGroup("Web-URL-Settings");
|
2011-11-06 17:01:23 +01:00
|
|
|
m_homepage = settings.value("homepage", "qupzilla:start").toUrl();
|
2011-03-02 16:57:41 +01:00
|
|
|
settings.endGroup();
|
|
|
|
|
|
|
|
//Browser Window settings
|
|
|
|
settings.beginGroup("Browser-View-Settings");
|
2011-11-06 17:01:23 +01:00
|
|
|
bool showStatusBar = settings.value("showStatusBar", true).toBool();
|
2012-10-20 11:31:45 +02:00
|
|
|
bool showReloadButton = settings.value("showReloadButton", true).toBool();
|
|
|
|
bool showHomeButton = settings.value("showHomeButton", true).toBool();
|
|
|
|
bool showBackForwardButtons = settings.value("showBackForwardButtons", true).toBool();
|
|
|
|
bool showAddTabButton = settings.value("showAddTabButton", false).toBool();
|
2012-07-19 19:56:58 +02:00
|
|
|
bool showWebSearchBar = settings.value("showWebSearchBar", true).toBool();
|
2011-11-06 17:01:23 +01:00
|
|
|
bool showBookmarksToolbar = settings.value("showBookmarksToolbar", true).toBool();
|
|
|
|
bool showNavigationToolbar = settings.value("showNavigationToolbar", true).toBool();
|
|
|
|
bool showMenuBar = settings.value("showMenubar", true).toBool();
|
|
|
|
bool makeTransparent = settings.value("useTransparentBackground", false).toBool();
|
2012-01-14 11:46:06 +01:00
|
|
|
m_sideBarWidth = settings.value("SideBarWidth", 250).toInt();
|
2012-02-02 15:54:38 +01:00
|
|
|
m_webViewWidth = settings.value("WebViewWidth", 2000).toInt();
|
2013-12-30 13:43:48 +01:00
|
|
|
const QString activeSideBar = settings.value("SideBar", "None").toString();
|
2013-03-01 22:53:50 +01:00
|
|
|
|
|
|
|
// Make sure both menubar and navigationbar are not hidden
|
|
|
|
// Fixes #781
|
|
|
|
if (!showNavigationToolbar) {
|
|
|
|
showMenuBar = true;
|
|
|
|
settings.setValue("showMenubar", true);
|
|
|
|
}
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
settings.endGroup();
|
2012-11-28 11:27:30 +01:00
|
|
|
|
|
|
|
settings.beginGroup("Shortcuts");
|
|
|
|
m_useTabNumberShortcuts = settings.value("useTabNumberShortcuts", true).toBool();
|
|
|
|
m_useSpeedDialNumberShortcuts = settings.value("useSpeedDialNumberShortcuts", true).toBool();
|
|
|
|
settings.endGroup();
|
2011-03-29 20:30:05 +02:00
|
|
|
|
2012-12-02 00:59:17 +01:00
|
|
|
m_adblockIcon->setEnabled(settings.value("AdBlock/enabled", true).toBool());
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2014-01-02 13:10:23 +01:00
|
|
|
statusBar()->setVisible(!isFullScreen() && showStatusBar);
|
2011-03-02 16:57:41 +01:00
|
|
|
m_bookmarksToolbar->setVisible(showBookmarksToolbar);
|
2014-03-10 16:55:11 +01:00
|
|
|
m_navigationToolbar->setVisible(showNavigationToolbar);
|
2014-01-02 13:10:23 +01:00
|
|
|
menuBar()->setVisible(!isFullScreen() && showMenuBar);
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-09-03 22:48:52 +02:00
|
|
|
#ifndef Q_OS_MAC
|
2014-03-10 16:55:11 +01:00
|
|
|
m_navigationToolbar->setSuperMenuVisible(!showMenuBar);
|
2012-01-26 16:22:09 +01:00
|
|
|
#endif
|
2014-03-10 16:55:11 +01:00
|
|
|
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);
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-04-30 16:33:14 +02:00
|
|
|
m_sideBarManager->showSideBar(activeSideBar, false);
|
2011-04-28 18:31:48 +02:00
|
|
|
|
2013-05-12 10:59:33 +02:00
|
|
|
// Private browsing
|
2014-03-10 00:47:07 +01:00
|
|
|
m_privateBrowsing->setVisible(mApp->isPrivate());
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-09-03 22:48:52 +02:00
|
|
|
#ifdef Q_OS_WIN
|
2011-12-26 21:23:21 +01:00
|
|
|
if (m_usingTransparentBackground && !makeTransparent) {
|
2012-08-30 10:46:58 +02:00
|
|
|
QtWin::extendFrameIntoClientArea(this, 0, 0, 0, 0);
|
2011-12-26 21:23:21 +01:00
|
|
|
QtWin::enableBlurBehindWindow(this, false);
|
2013-11-26 14:14:36 +01:00
|
|
|
m_tabWidget->getTabBar()->enableBluredBackground(false);
|
2011-12-26 21:23:21 +01:00
|
|
|
m_usingTransparentBackground = false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!makeTransparent) {
|
2011-03-02 16:57:41 +01:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2013-05-12 10:59:33 +02:00
|
|
|
|
|
|
|
// Transparency on X11 (no blur like on Windows)
|
2012-12-22 12:47:45 +01:00
|
|
|
#ifdef QZ_WS_X11
|
2011-03-02 16:57:41 +01:00
|
|
|
setAttribute(Qt::WA_TranslucentBackground);
|
|
|
|
setAttribute(Qt::WA_NoSystemBackground, false);
|
|
|
|
QPalette pal = palette();
|
|
|
|
QColor bg = pal.window().color();
|
|
|
|
bg.setAlpha(180);
|
|
|
|
pal.setColor(QPalette::Window, bg);
|
|
|
|
setPalette(pal);
|
|
|
|
ensurePolished(); // workaround Oxygen filling the background
|
|
|
|
setAttribute(Qt::WA_StyledBackground, false);
|
|
|
|
#endif
|
2012-08-30 10:46:58 +02:00
|
|
|
|
2012-09-03 22:48:52 +02:00
|
|
|
#ifdef Q_OS_WIN
|
2011-03-02 16:57:41 +01:00
|
|
|
if (QtWin::isCompositionEnabled()) {
|
|
|
|
setContentsMargins(0, 0, 0, 0);
|
2011-12-26 21:23:21 +01:00
|
|
|
|
|
|
|
m_usingTransparentBackground = true;
|
2012-08-30 10:46:58 +02:00
|
|
|
|
2013-11-26 14:14:36 +01:00
|
|
|
if (!isFullScreen()) {
|
|
|
|
m_tabWidget->getTabBar()->enableBluredBackground(true);
|
|
|
|
QtWin::extendFrameIntoClientArea(this);
|
|
|
|
}
|
2013-01-19 23:22:30 +01:00
|
|
|
|
2014-03-10 16:55:11 +01:00
|
|
|
// Install event filters
|
2012-08-30 10:46:58 +02:00
|
|
|
menuBar()->installEventFilter(this);
|
2013-11-26 14:14:36 +01:00
|
|
|
m_tabWidget->getTabBar()->installEventFilter(this);
|
2012-08-30 10:46:58 +02:00
|
|
|
m_navigationBar->installEventFilter(this);
|
|
|
|
m_bookmarksToolbar->installEventFilter(this);
|
|
|
|
statusBar()->installEventFilter(this);
|
2013-02-16 13:32:33 +01:00
|
|
|
m_navigationContainer->installEventFilter(this);
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
2012-08-30 10:46:58 +02:00
|
|
|
#endif
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2014-02-27 22:53:56 +01:00
|
|
|
void BrowserWindow::goForward()
|
2012-02-01 17:01:08 +01:00
|
|
|
{
|
|
|
|
weView()->forward();
|
|
|
|
}
|
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
void BrowserWindow::goBack()
|
2012-02-01 17:01:08 +01:00
|
|
|
{
|
|
|
|
weView()->back();
|
|
|
|
}
|
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
QMenuBar* BrowserWindow::menuBar() const
|
2012-02-01 17:01:08 +01:00
|
|
|
{
|
2012-09-03 22:48:52 +02:00
|
|
|
#ifdef Q_OS_MAC
|
2013-02-08 15:21:00 +01:00
|
|
|
return mApp->macMenuReceiver()->menuBar();
|
2012-02-01 17:01:08 +01:00
|
|
|
#else
|
|
|
|
return QMainWindow::menuBar();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
TabbedWebView* BrowserWindow::weView() const
|
2012-02-01 17:01:08 +01:00
|
|
|
{
|
|
|
|
return weView(m_tabWidget->currentIndex());
|
|
|
|
}
|
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
TabbedWebView* BrowserWindow::weView(int index) const
|
2012-02-01 17:01:08 +01:00
|
|
|
{
|
|
|
|
WebTab* webTab = qobject_cast<WebTab*>(m_tabWidget->widget(index));
|
|
|
|
if (!webTab) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return webTab->view();
|
|
|
|
}
|
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
LocationBar* BrowserWindow::locationBar() const
|
2012-02-01 17:01:08 +01:00
|
|
|
{
|
|
|
|
return qobject_cast<LocationBar*>(m_tabWidget->locationBars()->currentWidget());
|
|
|
|
}
|
|
|
|
|
2014-03-10 16:55:11 +01:00
|
|
|
TabWidget* BrowserWindow::tabWidget() const
|
2013-02-15 22:18:46 +01:00
|
|
|
{
|
2014-03-10 16:55:11 +01:00
|
|
|
return m_tabWidget;
|
2013-02-15 22:18:46 +01:00
|
|
|
}
|
|
|
|
|
2014-03-10 16:55:11 +01:00
|
|
|
BookmarksToolbar* BrowserWindow::bookmarksToolbar() const
|
2013-02-09 14:08:12 +01:00
|
|
|
{
|
2014-03-10 16:55:11 +01:00
|
|
|
return m_bookmarksToolbar;
|
2013-02-09 14:08:12 +01:00
|
|
|
}
|
|
|
|
|
2014-03-10 16:55:11 +01:00
|
|
|
StatusBarMessage* BrowserWindow::statusBarMessage() const
|
2013-03-23 20:39:55 +01:00
|
|
|
{
|
2014-03-10 16:55:11 +01:00
|
|
|
return m_statusBarMessage;
|
2013-03-23 20:39:55 +01:00
|
|
|
}
|
|
|
|
|
2014-03-10 16:55:11 +01:00
|
|
|
NavigationBar* BrowserWindow::navigationBar() const
|
2013-08-03 22:09:54 +02:00
|
|
|
{
|
2014-03-10 16:55:11 +01:00
|
|
|
return m_navigationToolbar;
|
2013-08-03 22:09:54 +02:00
|
|
|
}
|
|
|
|
|
2014-03-10 16:55:11 +01:00
|
|
|
SideBarManager* BrowserWindow::sideBarManager() const
|
2011-09-17 11:13:38 +02:00
|
|
|
{
|
2014-03-10 16:55:11 +01:00
|
|
|
return m_sideBarManager;
|
2011-09-17 11:13:38 +02:00
|
|
|
}
|
|
|
|
|
2014-03-10 16:55:11 +01:00
|
|
|
QLabel* BrowserWindow::ipLabel() const
|
2011-12-17 15:09:17 +01:00
|
|
|
{
|
2014-03-10 16:55:11 +01:00
|
|
|
return m_ipLabel;
|
2011-12-17 15:09:17 +01:00
|
|
|
}
|
|
|
|
|
2014-03-10 16:55:11 +01:00
|
|
|
AdBlockIcon* BrowserWindow::adBlockIcon() const
|
2011-12-17 15:09:17 +01:00
|
|
|
{
|
2014-03-10 16:55:11 +01:00
|
|
|
return m_adblockIcon;
|
2011-12-17 15:09:17 +01:00
|
|
|
}
|
|
|
|
|
2014-03-10 16:55:11 +01:00
|
|
|
QMenu* BrowserWindow::superMenu() const
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2014-03-10 16:55:11 +01:00
|
|
|
return m_superMenu;
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2014-03-10 16:55:11 +01:00
|
|
|
bool BrowserWindow::isClosing() const
|
2013-01-26 21:58:09 +01:00
|
|
|
{
|
2014-03-10 16:55:11 +01:00
|
|
|
return m_isClosing;
|
2013-01-26 21:58:09 +01:00
|
|
|
}
|
|
|
|
|
2014-03-10 16:55:11 +01:00
|
|
|
QUrl BrowserWindow::homepageUrl() const
|
2011-11-27 15:43:54 +01:00
|
|
|
{
|
2014-03-10 16:55:11 +01:00
|
|
|
return m_homepage;
|
2011-11-27 15:43:54 +01:00
|
|
|
}
|
|
|
|
|
2014-03-10 16:55:11 +01:00
|
|
|
Qz::BrowserWindowType BrowserWindow::windowType() const
|
2011-11-27 15:43:54 +01:00
|
|
|
{
|
2014-03-10 16:55:11 +01:00
|
|
|
return m_windowType;
|
2011-11-27 15:43:54 +01:00
|
|
|
}
|
|
|
|
|
2014-03-10 16:55:11 +01:00
|
|
|
bool BrowserWindow::isTransparentBackgroundAllowed() const
|
2013-01-26 21:58:09 +01:00
|
|
|
{
|
2014-03-10 16:55:11 +01:00
|
|
|
return m_useTransparentBackground && !isFullScreen();
|
2013-01-26 21:58:09 +01:00
|
|
|
}
|
|
|
|
|
2014-03-10 16:55:11 +01:00
|
|
|
QAction* BrowserWindow::action(const QString &name) const
|
2013-01-26 21:58:09 +01:00
|
|
|
{
|
2014-03-10 16:55:11 +01:00
|
|
|
return m_mainMenu->action(name);
|
2013-01-26 21:58:09 +01:00
|
|
|
}
|
|
|
|
|
2014-03-10 16:55:11 +01:00
|
|
|
void BrowserWindow::setWindowTitle(const QString &t)
|
2011-03-17 20:46:53 +01:00
|
|
|
{
|
2014-03-10 16:55:11 +01:00
|
|
|
QString title = t;
|
2011-03-17 20:46:53 +01:00
|
|
|
|
2014-03-10 16:55:11 +01:00
|
|
|
if (mApp->isPrivate()) {
|
|
|
|
title.append(tr(" (Private Browsing)"));
|
2011-03-17 20:46:53 +01:00
|
|
|
}
|
|
|
|
|
2014-03-10 16:55:11 +01:00
|
|
|
QMainWindow::setWindowTitle(title);
|
2011-03-17 20:46:53 +01:00
|
|
|
}
|
|
|
|
|
2014-03-10 16:55:11 +01:00
|
|
|
void BrowserWindow::changeEncoding()
|
2011-03-17 20:46:53 +01:00
|
|
|
{
|
2014-03-10 16:55:11 +01:00
|
|
|
if (QAction* action = qobject_cast<QAction*>(sender())) {
|
2013-12-30 13:43:48 +01:00
|
|
|
const QString encoding = action->data().toString();
|
2014-03-10 00:47:07 +01:00
|
|
|
QWebSettings::globalSettings()->setDefaultTextEncoding(encoding);
|
2012-03-30 12:02:49 +02:00
|
|
|
|
|
|
|
Settings settings;
|
|
|
|
settings.setValue("Web-Browser-Settings/DefaultEncoding", encoding);
|
|
|
|
|
2014-03-10 16:55:11 +01:00
|
|
|
weView()->reload();
|
2011-03-17 20:46:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
void BrowserWindow::bookmarkPage()
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2014-02-08 23:01:01 +01:00
|
|
|
TabbedWebView* view = weView();
|
|
|
|
BookmarksTools::addBookmarkDialog(this, view->url(), view->title());
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
void BrowserWindow::bookmarkAllTabs()
|
2014-02-09 11:02:51 +01:00
|
|
|
{
|
|
|
|
BookmarksTools::bookmarkAllTabsDialog(this, m_tabWidget);
|
|
|
|
}
|
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
void BrowserWindow::addBookmark(const QUrl &url, const QString &title)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2014-02-08 23:01:01 +01:00
|
|
|
BookmarksTools::addBookmarkDialog(this, url, title);
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
void BrowserWindow::goHome()
|
2011-10-26 19:23:50 +02:00
|
|
|
{
|
|
|
|
loadAddress(m_homepage);
|
|
|
|
}
|
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
void BrowserWindow::goHomeInNewTab()
|
2011-10-26 19:23:50 +02:00
|
|
|
{
|
2012-01-21 23:19:38 +01:00
|
|
|
m_tabWidget->addView(m_homepage, Qz::NT_SelectedTab);
|
|
|
|
}
|
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
void BrowserWindow::loadActionUrl(QObject* obj)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2013-02-07 14:01:01 +01:00
|
|
|
if (!obj) {
|
|
|
|
obj = sender();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (QAction* action = qobject_cast<QAction*>(obj)) {
|
2011-03-02 16:57:41 +01:00
|
|
|
loadAddress(action->data().toUrl());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
void BrowserWindow::loadActionUrlInNewTab(QObject* obj)
|
2011-09-19 20:49:39 +02:00
|
|
|
{
|
2013-02-07 14:01:01 +01:00
|
|
|
if (!obj) {
|
|
|
|
obj = sender();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (QAction* action = qobject_cast<QAction*>(obj)) {
|
2012-02-07 18:37:44 +01:00
|
|
|
m_tabWidget->addView(action->data().toUrl(), Qz::NT_SelectedTabAtTheEnd);
|
2011-09-19 20:49:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
void BrowserWindow::loadAddress(const QUrl &url)
|
2011-07-31 00:50:40 +02:00
|
|
|
{
|
2014-02-09 15:07:19 +01:00
|
|
|
if (weView()->webTab()->isPinned()) {
|
|
|
|
int index = m_tabWidget->addView(url, qzSettings->newTabPosition);
|
|
|
|
weView(index)->setFocus();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
weView()->setFocus();
|
|
|
|
weView()->load(url);
|
|
|
|
}
|
2011-07-31 00:50:40 +02:00
|
|
|
}
|
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
void BrowserWindow::showHistoryManager()
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2011-07-29 15:39:43 +02:00
|
|
|
mApp->browsingLibrary()->showHistory(this);
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
void BrowserWindow::showSource(QWebFrame* frame, const QString &selectedHtml)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2012-01-02 13:56:52 +01:00
|
|
|
if (!frame) {
|
|
|
|
frame = weView()->page()->mainFrame();
|
|
|
|
}
|
|
|
|
|
|
|
|
SourceViewer* source = new SourceViewer(frame, selectedHtml);
|
2013-01-22 19:04:22 +01:00
|
|
|
QzTools::centerWidgetToParent(source, this);
|
2011-03-02 16:57:41 +01:00
|
|
|
source->show();
|
|
|
|
}
|
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
SideBar* BrowserWindow::addSideBar()
|
2011-09-11 19:15:06 +02:00
|
|
|
{
|
2012-01-18 18:36:10 +01:00
|
|
|
if (m_sideBar) {
|
2012-04-01 16:36:38 +02:00
|
|
|
return m_sideBar.data();
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-09-11 19:15:06 +02:00
|
|
|
|
2012-04-01 16:36:38 +02:00
|
|
|
m_sideBar = new SideBar(m_sideBarManager, this);
|
2011-09-11 19:15:06 +02:00
|
|
|
|
2011-12-09 21:56:01 +01:00
|
|
|
m_mainSplitter->insertWidget(0, m_sideBar.data());
|
2011-09-11 19:15:06 +02:00
|
|
|
m_mainSplitter->setCollapsible(0, false);
|
2011-10-17 09:59:09 +02:00
|
|
|
|
2012-01-14 11:46:06 +01:00
|
|
|
m_mainSplitter->setSizes(QList<int>() << m_sideBarWidth << m_webViewWidth);
|
2012-04-01 16:36:38 +02:00
|
|
|
|
2012-09-03 22:48:52 +02:00
|
|
|
#ifdef Q_OS_WIN
|
2012-08-30 10:46:58 +02:00
|
|
|
if (QtWin::isCompositionEnabled()) {
|
2013-09-03 07:44:51 +02:00
|
|
|
applyBlurToMainWindow();
|
2012-08-30 10:46:58 +02:00
|
|
|
m_sideBar.data()->installEventFilter(this);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-04-01 16:36:38 +02:00
|
|
|
return m_sideBar.data();
|
2011-10-17 09:59:09 +02:00
|
|
|
}
|
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
void BrowserWindow::saveSideBarWidth()
|
2011-10-17 09:59:09 +02:00
|
|
|
{
|
|
|
|
// That +1 is important here, without it, the sidebar width would
|
|
|
|
// decrease by 1 pixel every close
|
2012-01-13 16:51:58 +01:00
|
|
|
|
2012-01-14 11:46:06 +01:00
|
|
|
m_sideBarWidth = m_mainSplitter->sizes().at(0) + 1;
|
|
|
|
m_webViewWidth = width() - m_sideBarWidth;
|
2011-04-15 20:45:22 +02:00
|
|
|
}
|
|
|
|
|
2014-03-13 12:31:08 +01:00
|
|
|
void BrowserWindow::toggleShowMenubar()
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2014-03-13 12:31:08 +01:00
|
|
|
#ifdef Q_OS_MAC
|
|
|
|
// We use one shared menubar on Mac
|
|
|
|
return;
|
|
|
|
#endif
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2014-02-12 14:23:23 +01:00
|
|
|
setUpdatesEnabled(false);
|
|
|
|
|
2014-03-13 12:31:08 +01:00
|
|
|
menuBar()->setVisible(!menuBar()->isVisible());
|
|
|
|
m_navigationToolbar->setSuperMenuVisible(!menuBar()->isVisible());
|
2014-02-12 14:23:23 +01:00
|
|
|
|
|
|
|
setUpdatesEnabled(true);
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2014-03-13 12:31:08 +01:00
|
|
|
Settings().setValue("Browser-View-Settings/showMenubar", menuBar()->isVisible());
|
|
|
|
|
|
|
|
// Make sure we show Navigation Toolbar when Menu Bar is hidden
|
2014-03-10 16:55:11 +01:00
|
|
|
if (!m_navigationToolbar->isVisible() && !menuBar()->isVisible()) {
|
2014-03-13 12:31:08 +01:00
|
|
|
toggleShowNavigationToolbar();
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2014-03-13 12:31:08 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2014-03-13 13:38:14 +01:00
|
|
|
void BrowserWindow::toggleShowStatusBar()
|
|
|
|
{
|
|
|
|
setUpdatesEnabled(false);
|
|
|
|
|
|
|
|
statusBar()->setVisible(!statusBar()->isVisible());
|
|
|
|
|
|
|
|
setUpdatesEnabled(true);
|
|
|
|
|
|
|
|
Settings().setValue("Browser-View-Settings/showStatusbar", statusBar()->isVisible());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-03-13 12:31:08 +01:00
|
|
|
void BrowserWindow::toggleShowBookmarksToolbar()
|
|
|
|
{
|
2014-02-12 14:23:23 +01:00
|
|
|
setUpdatesEnabled(false);
|
|
|
|
|
2014-03-13 12:31:08 +01:00
|
|
|
m_bookmarksToolbar->setVisible(!m_bookmarksToolbar->isVisible());
|
2011-04-04 20:04:29 +02:00
|
|
|
|
2014-03-13 12:31:08 +01:00
|
|
|
setUpdatesEnabled(true);
|
|
|
|
|
|
|
|
Settings().setValue("Browser-View-Settings/showBookmarksToolbar", m_bookmarksToolbar->isVisible());
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWindow::toggleShowNavigationToolbar()
|
|
|
|
{
|
|
|
|
setUpdatesEnabled(false);
|
|
|
|
|
|
|
|
m_navigationToolbar->setVisible(!m_navigationToolbar->isVisible());
|
2014-02-12 14:23:23 +01:00
|
|
|
|
|
|
|
setUpdatesEnabled(true);
|
2014-03-13 12:31:08 +01:00
|
|
|
|
|
|
|
Settings().setValue("Browser-View-Settings/showNavigationToolbar", m_navigationToolbar->isVisible());
|
|
|
|
|
|
|
|
// Make sure we show Menu Bar when Navigation Toolbar is hidden
|
|
|
|
if (!m_navigationToolbar->isVisible() && !menuBar()->isVisible()) {
|
|
|
|
toggleShowMenubar();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWindow::toggleTabsOnTop(bool enable)
|
|
|
|
{
|
|
|
|
if (enable) {
|
|
|
|
m_mainLayout->insertWidget(0, m_tabWidget->getTabBar());
|
|
|
|
m_mainLayout->insertWidget(1, m_navigationContainer);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
m_mainLayout->insertWidget(0, m_navigationContainer);
|
|
|
|
m_mainLayout->insertWidget(1, m_tabWidget->getTabBar());
|
|
|
|
}
|
|
|
|
|
|
|
|
qzSettings->tabsOnTop = enable;
|
|
|
|
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
// workaround for changing TabsOnTop state when sidebar is visible
|
|
|
|
// TODO: we need a solution that changing TabsOnTop state
|
|
|
|
// doesn't call applyBlurToMainWindow() from eventFilter()
|
|
|
|
QTimer::singleShot(0, this, SLOT(applyBlurToMainWindow()));
|
2012-01-26 16:22:09 +01:00
|
|
|
#endif
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2014-03-13 13:38:14 +01:00
|
|
|
void BrowserWindow::toggleCaretBrowsing()
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2014-03-13 13:38:14 +01:00
|
|
|
#if QTWEBKIT_FROM_2_3
|
|
|
|
bool enable = !QWebSettings::globalSettings()->testAttribute(QWebSettings::CaretBrowsingEnabled);
|
2014-02-12 14:23:23 +01:00
|
|
|
|
2014-03-13 13:38:14 +01:00
|
|
|
Settings().setValue("Web-Browser-Settings/CaretBrowsing", enable);
|
2011-04-04 20:04:29 +02:00
|
|
|
|
2014-03-13 13:38:14 +01:00
|
|
|
QWebSettings::globalSettings()->setAttribute(QWebSettings::CaretBrowsingEnabled, enable);
|
|
|
|
#endif
|
|
|
|
}
|
2014-02-12 14:23:23 +01:00
|
|
|
|
2014-03-13 13:38:14 +01:00
|
|
|
void BrowserWindow::toggleFullScreen()
|
|
|
|
{
|
|
|
|
if (isFullScreen()) {
|
|
|
|
showNormal();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
showFullScreen();
|
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
void BrowserWindow::showWebInspector(bool toggle)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2012-01-18 18:36:10 +01:00
|
|
|
if (m_webInspectorDock) {
|
2012-02-04 18:45:59 +01:00
|
|
|
if (toggle) {
|
2012-03-16 16:57:24 +01:00
|
|
|
m_webInspectorDock.data()->toggleVisibility();
|
2012-02-04 18:45:59 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
m_webInspectorDock.data()->show();
|
|
|
|
}
|
2011-10-14 20:14:57 +02:00
|
|
|
return;
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
2011-10-14 20:14:57 +02:00
|
|
|
|
|
|
|
m_webInspectorDock = new WebInspectorDockWidget(this);
|
2014-03-13 12:47:01 +01:00
|
|
|
connect(m_tabWidget, SIGNAL(currentChanged(int)), m_webInspectorDock.data(), SLOT(tabChanged(int)));
|
2011-12-09 21:56:01 +01:00
|
|
|
addDockWidget(Qt::BottomDockWidgetArea, m_webInspectorDock.data());
|
2012-08-30 10:46:58 +02:00
|
|
|
|
2012-09-03 22:48:52 +02:00
|
|
|
#ifdef Q_OS_WIN
|
2012-08-30 10:46:58 +02:00
|
|
|
if (QtWin::isCompositionEnabled()) {
|
|
|
|
applyBlurToMainWindow();
|
|
|
|
m_webInspectorDock.data()->installEventFilter(this);
|
|
|
|
}
|
|
|
|
#endif
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
void BrowserWindow::refreshHistory()
|
2011-09-11 19:15:06 +02:00
|
|
|
{
|
2014-03-10 16:55:11 +01:00
|
|
|
m_navigationToolbar->refreshHistory();
|
2011-09-11 19:15:06 +02:00
|
|
|
}
|
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
void BrowserWindow::currentTabChanged()
|
2012-01-14 09:54:51 +01:00
|
|
|
{
|
2012-01-21 20:27:45 +01:00
|
|
|
TabbedWebView* view = weView();
|
2012-01-14 09:54:51 +01:00
|
|
|
if (!view) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-01-21 20:27:45 +01:00
|
|
|
setWindowTitle(tr("%1 - QupZilla").arg(view->title()));
|
2012-01-14 09:54:51 +01:00
|
|
|
m_ipLabel->setText(view->getIp());
|
|
|
|
view->setFocus();
|
|
|
|
|
2013-01-25 19:52:30 +01:00
|
|
|
SearchToolBar* search = searchToolBar();
|
|
|
|
if (search) {
|
|
|
|
search->setWebView(view);
|
|
|
|
}
|
|
|
|
|
2012-01-14 09:54:51 +01:00
|
|
|
updateLoadingActions();
|
|
|
|
|
|
|
|
// Setting correct tab order (LocationBar -> WebSearchBar -> WebView)
|
2014-03-10 16:55:11 +01:00
|
|
|
setTabOrder(locationBar(), m_navigationToolbar->webSearchBar());
|
|
|
|
setTabOrder(m_navigationToolbar->webSearchBar(), view);
|
2012-01-14 09:54:51 +01:00
|
|
|
}
|
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
void BrowserWindow::updateLoadingActions()
|
2012-01-14 09:54:51 +01:00
|
|
|
{
|
2012-01-21 20:27:45 +01:00
|
|
|
TabbedWebView* view = weView();
|
2012-01-14 09:54:51 +01:00
|
|
|
if (!view) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isLoading = view->isLoading();
|
|
|
|
|
|
|
|
m_ipLabel->setVisible(!isLoading);
|
|
|
|
m_progressBar->setVisible(isLoading);
|
2014-03-10 16:55:11 +01:00
|
|
|
|
|
|
|
action(QSL("View/Stop"))->setEnabled(isLoading);
|
|
|
|
action(QSL("View/Reload"))->setEnabled(!isLoading);
|
2012-01-14 09:54:51 +01:00
|
|
|
|
|
|
|
if (isLoading) {
|
2012-06-27 18:29:00 +02:00
|
|
|
m_progressBar->setValue(view->loadingProgress());
|
2014-03-10 16:55:11 +01:00
|
|
|
m_navigationToolbar->showStopButton();
|
2012-01-14 09:54:51 +01:00
|
|
|
}
|
|
|
|
else {
|
2014-03-10 16:55:11 +01:00
|
|
|
m_navigationToolbar->showReloadButton();
|
2012-01-14 09:54:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
void BrowserWindow::addDeleteOnCloseWidget(QWidget* widget)
|
2012-01-21 20:27:45 +01:00
|
|
|
{
|
|
|
|
if (!m_deleteOnCloseWidgets.contains(widget)) {
|
|
|
|
m_deleteOnCloseWidgets.append(widget);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
void BrowserWindow::restoreWindowState(const RestoreManager::WindowData &d)
|
2012-03-13 17:51:37 +01:00
|
|
|
{
|
2012-09-06 11:39:42 +02:00
|
|
|
restoreState(d.windowState);
|
2012-08-21 20:28:38 +02:00
|
|
|
m_tabWidget->restoreState(d.tabsState, d.currentTab);
|
2012-03-13 17:51:37 +01:00
|
|
|
}
|
|
|
|
|
2014-03-10 16:55:11 +01:00
|
|
|
void BrowserWindow::createToolbarsMenu(QMenu* menu)
|
|
|
|
{
|
2014-03-13 12:31:08 +01:00
|
|
|
QAction* action = menu->addAction(tr("&Menu Bar"), this, SLOT(toggleShowMenubar()));
|
2014-03-10 16:55:11 +01:00
|
|
|
action->setCheckable(true);
|
|
|
|
action->setChecked(menuBar()->isVisible());
|
|
|
|
|
2014-03-13 12:31:08 +01:00
|
|
|
action = menu->addAction(tr("&Navigation Toolbar"), this, SLOT(toggleShowNavigationToolbar()));
|
2014-03-10 16:55:11 +01:00
|
|
|
action->setCheckable(true);
|
|
|
|
action->setChecked(m_navigationToolbar->isVisible());
|
|
|
|
|
2014-03-13 12:31:08 +01:00
|
|
|
action = menu->addAction(tr("&Bookmarks Toolbar"), this, SLOT(toggleShowBookmarksToolbar()));
|
2014-03-10 16:55:11 +01:00
|
|
|
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)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2014-03-10 16:55:11 +01:00
|
|
|
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<QByteArray> 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);
|
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
void BrowserWindow::addTab()
|
2012-01-21 23:19:38 +01:00
|
|
|
{
|
2013-01-25 23:49:46 +01:00
|
|
|
m_tabWidget->addView(QUrl(), Qz::NT_SelectedNewEmptyTab, true);
|
2012-01-21 23:19:38 +01:00
|
|
|
}
|
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
void BrowserWindow::webSearch()
|
2011-09-11 19:15:06 +02:00
|
|
|
{
|
2014-03-10 16:55:11 +01:00
|
|
|
m_navigationToolbar->webSearchBar()->setFocus();
|
|
|
|
m_navigationToolbar->webSearchBar()->selectAll();
|
2011-09-11 19:15:06 +02:00
|
|
|
}
|
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
void BrowserWindow::searchOnPage()
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2013-01-25 19:52:30 +01:00
|
|
|
SearchToolBar* toolBar = searchToolBar();
|
2011-09-11 19:15:06 +02:00
|
|
|
|
2013-01-25 19:52:30 +01:00
|
|
|
if (!toolBar) {
|
2013-11-26 14:14:36 +01:00
|
|
|
const int searchPos = 3;
|
|
|
|
|
2013-01-25 19:52:30 +01:00
|
|
|
toolBar = new SearchToolBar(weView(), this);
|
2013-02-09 13:00:45 +01:00
|
|
|
m_mainLayout->insertWidget(searchPos, toolBar);
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
2011-08-02 16:19:20 +02:00
|
|
|
|
2013-01-25 19:52:30 +01:00
|
|
|
toolBar->focusSearchLine();
|
2012-08-30 10:46:58 +02:00
|
|
|
|
2012-09-03 22:48:52 +02:00
|
|
|
#ifdef Q_OS_WIN
|
2012-08-30 10:46:58 +02:00
|
|
|
if (QtWin::isCompositionEnabled()) {
|
|
|
|
applyBlurToMainWindow();
|
2013-01-28 10:52:55 +01:00
|
|
|
toolBar->installEventFilter(this);
|
2012-08-30 10:46:58 +02:00
|
|
|
}
|
|
|
|
#endif
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
void BrowserWindow::openFile()
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2013-12-30 13:43:48 +01:00
|
|
|
const QString fileTypes = QString("%1(*.html *.htm *.shtml *.shtm *.xhtml);;"
|
|
|
|
"%2(*.png *.jpg *.jpeg *.bmp *.gif *.svg *.tiff);;"
|
|
|
|
"%3(*.txt);;"
|
|
|
|
"%4(*.*)").arg(tr("HTML files"), tr("Image files"), tr("Text files"), tr("All files"));
|
2012-03-04 18:30:34 +01:00
|
|
|
|
2013-12-30 13:43:48 +01:00
|
|
|
const QString filePath = QzTools::getOpenFileName("MainWindow-openFile", this, tr("Open file..."), QDir::homePath(), fileTypes);
|
2012-03-04 18:30:34 +01:00
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!filePath.isEmpty()) {
|
2011-12-17 14:30:54 +01:00
|
|
|
loadAddress(QUrl::fromLocalFile(filePath));
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
void BrowserWindow::openLocation()
|
2011-12-16 19:07:36 +01:00
|
|
|
{
|
|
|
|
locationBar()->setFocus();
|
|
|
|
locationBar()->selectAll();
|
|
|
|
}
|
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
bool BrowserWindow::fullScreenNavigationVisible() const
|
2011-04-22 07:45:15 +02:00
|
|
|
{
|
2013-02-09 15:44:17 +01:00
|
|
|
return m_navigationContainer->isVisible();
|
|
|
|
}
|
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
void BrowserWindow::showNavigationWithFullScreen()
|
2013-02-09 15:44:17 +01:00
|
|
|
{
|
|
|
|
if (m_hideNavigationTimer->isActive()) {
|
|
|
|
m_hideNavigationTimer->stop();
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-10-24 17:46:45 +02:00
|
|
|
|
2013-02-09 15:44:17 +01:00
|
|
|
m_navigationContainer->show();
|
|
|
|
m_tabWidget->getTabBar()->updateVisibilityWithFullscreen(true);
|
|
|
|
}
|
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
void BrowserWindow::hideNavigationWithFullScreen()
|
2013-02-09 15:44:17 +01:00
|
|
|
{
|
|
|
|
if (!m_hideNavigationTimer->isActive()) {
|
|
|
|
m_hideNavigationTimer->start();
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2013-02-09 15:44:17 +01:00
|
|
|
}
|
2011-10-24 17:46:45 +02:00
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
void BrowserWindow::hideNavigationSlot()
|
2013-02-09 15:44:17 +01:00
|
|
|
{
|
|
|
|
TabbedWebView* view = weView();
|
2013-02-24 10:57:58 +01:00
|
|
|
bool mouseInView = view && view->underMouse();
|
2011-10-24 17:46:45 +02:00
|
|
|
|
2013-02-09 15:44:17 +01:00
|
|
|
if (isFullScreen() && mouseInView) {
|
|
|
|
m_navigationContainer->hide();
|
|
|
|
m_tabWidget->getTabBar()->updateVisibilityWithFullscreen(false);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-04-22 07:45:15 +02:00
|
|
|
}
|
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
bool BrowserWindow::event(QEvent* event)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2013-02-17 11:05:35 +01:00
|
|
|
switch (event->type()) {
|
|
|
|
case QEvent::WindowStateChange: {
|
|
|
|
QWindowStateChangeEvent* ev = static_cast<QWindowStateChangeEvent*>(event);
|
2011-10-24 17:46:45 +02:00
|
|
|
|
2013-02-17 11:05:35 +01:00
|
|
|
if (!(ev->oldState() & Qt::WindowFullScreen) && windowState() & Qt::WindowFullScreen) {
|
|
|
|
// Enter fullscreen
|
|
|
|
m_windowStates = ev->oldState();
|
2011-10-24 17:46:45 +02:00
|
|
|
|
2013-02-17 11:05:35 +01:00
|
|
|
m_menuBarVisible = menuBar()->isVisible();
|
|
|
|
m_statusBarVisible = statusBar()->isVisible();
|
|
|
|
menuBar()->hide();
|
|
|
|
statusBar()->hide();
|
|
|
|
m_navigationContainer->hide();
|
|
|
|
m_tabWidget->getTabBar()->hide();
|
2012-09-21 07:13:27 +02:00
|
|
|
#ifndef Q_OS_MAC
|
2014-03-10 16:55:11 +01:00
|
|
|
m_navigationToolbar->setSuperMenuVisible(false);
|
2012-09-21 07:13:27 +02:00
|
|
|
#endif
|
2013-02-17 11:05:35 +01:00
|
|
|
m_hideNavigationTimer->stop();
|
2014-03-10 16:55:11 +01:00
|
|
|
m_navigationToolbar->buttonExitFullscreen()->setVisible(true);
|
2012-09-03 22:48:52 +02:00
|
|
|
#ifdef Q_OS_WIN
|
2013-02-17 11:05:35 +01:00
|
|
|
if (m_usingTransparentBackground) {
|
2013-11-26 14:14:36 +01:00
|
|
|
m_tabWidget->getTabBar()->enableBluredBackground(false);
|
2013-02-17 11:05:35 +01:00
|
|
|
QtWin::extendFrameIntoClientArea(this, 0, 0, 0 , 0);
|
|
|
|
QtWin::enableBlurBehindWindow(this, false);
|
|
|
|
}
|
2012-08-20 21:44:29 +02:00
|
|
|
#endif
|
2013-02-17 11:05:35 +01:00
|
|
|
}
|
|
|
|
else if (ev->oldState() & Qt::WindowFullScreen && !(windowState() & Qt::WindowFullScreen)) {
|
|
|
|
// Leave fullscreen
|
|
|
|
setWindowState(m_windowStates);
|
|
|
|
|
|
|
|
menuBar()->setVisible(m_menuBarVisible);
|
|
|
|
statusBar()->setVisible(m_statusBarVisible);
|
|
|
|
m_navigationContainer->show();
|
2013-02-26 12:58:04 +01:00
|
|
|
m_tabWidget->getTabBar()->updateVisibilityWithFullscreen(true);
|
2013-06-06 13:14:12 +02:00
|
|
|
m_tabWidget->getTabBar()->setVisible(true);
|
2012-09-21 07:13:27 +02:00
|
|
|
#ifndef Q_OS_MAC
|
2014-03-10 16:55:11 +01:00
|
|
|
m_navigationToolbar->setSuperMenuVisible(!m_menuBarVisible);
|
2012-09-21 07:13:27 +02:00
|
|
|
#endif
|
2013-02-17 11:05:35 +01:00
|
|
|
m_hideNavigationTimer->stop();
|
2014-03-10 16:55:11 +01:00
|
|
|
m_navigationToolbar->buttonExitFullscreen()->setVisible(false);
|
2012-09-03 22:48:52 +02:00
|
|
|
#ifdef Q_OS_WIN
|
2013-02-17 11:05:35 +01:00
|
|
|
if (m_usingTransparentBackground) {
|
2013-11-26 14:14:36 +01:00
|
|
|
m_tabWidget->getTabBar()->enableBluredBackground(true);
|
2013-02-17 11:05:35 +01:00
|
|
|
applyBlurToMainWindow(true);
|
|
|
|
}
|
2012-08-20 21:44:29 +02:00
|
|
|
#endif
|
2013-02-17 11:05:35 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
2011-10-24 17:46:45 +02:00
|
|
|
|
2013-02-17 11:05:35 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2011-10-24 17:46:45 +02:00
|
|
|
|
2013-02-17 11:05:35 +01:00
|
|
|
return QMainWindow::event(event);
|
|
|
|
}
|
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
void BrowserWindow::printPage(QWebFrame* frame)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
|
|
|
QPrintPreviewDialog* dialog = new QPrintPreviewDialog(this);
|
2012-01-06 17:31:44 +01:00
|
|
|
dialog->resize(800, 750);
|
2014-02-19 22:07:21 +01:00
|
|
|
dialog->printer()->setCreator(tr("QupZilla %1 (%2)").arg(Qz::VERSION, Qz::WWWADDRESS));
|
2012-01-02 13:56:52 +01:00
|
|
|
|
|
|
|
if (!frame) {
|
2013-05-31 10:46:50 +02:00
|
|
|
dialog->printer()->setDocName(QzTools::getFileNameFromUrl(weView()->url()));
|
|
|
|
|
2012-01-02 13:56:52 +01:00
|
|
|
connect(dialog, SIGNAL(paintRequested(QPrinter*)), weView(), SLOT(print(QPrinter*)));
|
|
|
|
}
|
|
|
|
else {
|
2013-05-31 10:46:50 +02:00
|
|
|
dialog->printer()->setDocName(QzTools::getFileNameFromUrl(frame->url()));
|
|
|
|
|
2012-01-02 13:56:52 +01:00
|
|
|
connect(dialog, SIGNAL(paintRequested(QPrinter*)), frame, SLOT(print(QPrinter*)));
|
|
|
|
}
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
dialog->exec();
|
2011-12-04 20:09:44 +01:00
|
|
|
|
|
|
|
dialog->deleteLater();
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
void BrowserWindow::savePageScreen()
|
2011-09-21 14:20:49 +02:00
|
|
|
{
|
2011-10-26 19:23:50 +02:00
|
|
|
PageScreen* p = new PageScreen(weView(), this);
|
2011-09-21 14:20:49 +02:00
|
|
|
p->show();
|
|
|
|
}
|
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
void BrowserWindow::resizeEvent(QResizeEvent* event)
|
2011-12-29 15:21:26 +01:00
|
|
|
{
|
|
|
|
m_bookmarksToolbar->setMaximumWidth(width());
|
|
|
|
|
|
|
|
QMainWindow::resizeEvent(event);
|
|
|
|
}
|
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
void BrowserWindow::keyPressEvent(QKeyEvent* event)
|
2011-11-06 12:05:16 +01:00
|
|
|
{
|
2014-02-26 19:55:49 +01:00
|
|
|
if (mApp->plugins()->processKeyPress(Qz::ON_BrowserWindow, this, event)) {
|
2012-03-05 13:16:34 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-02-05 17:13:08 +01:00
|
|
|
int number = -1;
|
2013-02-17 11:05:35 +01:00
|
|
|
TabbedWebView* view = weView();
|
2012-02-05 17:13:08 +01:00
|
|
|
|
2011-11-06 12:05:16 +01:00
|
|
|
switch (event->key()) {
|
|
|
|
case Qt::Key_Back:
|
2013-02-17 11:05:35 +01:00
|
|
|
if (view) {
|
2014-03-10 16:55:11 +01:00
|
|
|
view->back();
|
2013-02-17 11:05:35 +01:00
|
|
|
event->accept();
|
|
|
|
}
|
2011-11-06 12:05:16 +01:00
|
|
|
break;
|
2012-02-05 16:00:23 +01:00
|
|
|
|
2011-11-06 12:05:16 +01:00
|
|
|
case Qt::Key_Forward:
|
2013-02-17 11:05:35 +01:00
|
|
|
if (view) {
|
2014-03-10 16:55:11 +01:00
|
|
|
view->forward();
|
2013-02-17 11:05:35 +01:00
|
|
|
event->accept();
|
|
|
|
}
|
2011-11-06 12:05:16 +01:00
|
|
|
break;
|
2012-02-05 16:00:23 +01:00
|
|
|
|
2011-11-06 12:05:16 +01:00
|
|
|
case Qt::Key_Stop:
|
2013-02-17 11:05:35 +01:00
|
|
|
if (view) {
|
2014-03-10 16:55:11 +01:00
|
|
|
view->stop();
|
2013-02-17 11:05:35 +01:00
|
|
|
event->accept();
|
|
|
|
}
|
2011-11-06 12:05:16 +01:00
|
|
|
break;
|
2012-02-05 16:00:23 +01:00
|
|
|
|
2011-11-06 12:05:16 +01:00
|
|
|
case Qt::Key_Refresh:
|
2013-02-17 11:05:35 +01:00
|
|
|
if (view) {
|
2014-03-10 16:55:11 +01:00
|
|
|
view->reload();
|
|
|
|
event->accept();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Qt::Key_F5:
|
|
|
|
if (view && event->modifiers() == Qt::ControlModifier) {
|
|
|
|
view->reload();
|
2013-02-17 11:05:35 +01:00
|
|
|
event->accept();
|
|
|
|
}
|
2011-11-06 12:05:16 +01:00
|
|
|
break;
|
2012-02-05 16:00:23 +01:00
|
|
|
|
2014-03-10 16:55:11 +01:00
|
|
|
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;
|
|
|
|
|
2011-11-06 12:05:16 +01:00
|
|
|
case Qt::Key_HomePage:
|
|
|
|
goHome();
|
|
|
|
event->accept();
|
|
|
|
break;
|
2012-02-05 16:00:23 +01:00
|
|
|
|
2011-11-06 12:05:16 +01:00
|
|
|
case Qt::Key_Favorites:
|
2014-03-10 16:55:11 +01:00
|
|
|
mApp->browsingLibrary()->showBookmarks(this);
|
2011-11-06 12:05:16 +01:00
|
|
|
event->accept();
|
|
|
|
break;
|
2012-02-05 16:00:23 +01:00
|
|
|
|
2011-11-06 12:05:16 +01:00
|
|
|
case Qt::Key_Search:
|
|
|
|
searchOnPage();
|
|
|
|
event->accept();
|
|
|
|
break;
|
2012-02-05 16:00:23 +01:00
|
|
|
|
2011-12-16 19:07:36 +01:00
|
|
|
case Qt::Key_F6:
|
2011-11-06 12:05:16 +01:00
|
|
|
case Qt::Key_OpenUrl:
|
|
|
|
openLocation();
|
|
|
|
event->accept();
|
|
|
|
break;
|
2012-02-05 16:00:23 +01:00
|
|
|
|
2011-11-06 12:05:16 +01:00
|
|
|
case Qt::Key_History:
|
|
|
|
showHistoryManager();
|
|
|
|
event->accept();
|
|
|
|
break;
|
2012-02-05 16:00:23 +01:00
|
|
|
|
2011-11-06 12:05:16 +01:00
|
|
|
case Qt::Key_AddFavorite:
|
|
|
|
bookmarkPage();
|
|
|
|
event->accept();
|
|
|
|
break;
|
2012-02-05 16:00:23 +01:00
|
|
|
|
2011-11-06 12:05:16 +01:00
|
|
|
case Qt::Key_News:
|
2014-03-10 16:55:11 +01:00
|
|
|
action(QSL("Tools/RssReader"))->trigger();
|
2011-11-06 12:05:16 +01:00
|
|
|
event->accept();
|
|
|
|
break;
|
2012-02-05 16:00:23 +01:00
|
|
|
|
2011-11-06 12:05:16 +01:00
|
|
|
case Qt::Key_Tools:
|
2014-03-10 16:55:11 +01:00
|
|
|
action(QSL("Standard/Preferences"))->trigger();
|
2011-11-06 12:05:16 +01:00
|
|
|
event->accept();
|
|
|
|
break;
|
2012-02-05 16:00:23 +01:00
|
|
|
|
2011-11-07 19:56:53 +01:00
|
|
|
case Qt::Key_Tab:
|
|
|
|
if (event->modifiers() == Qt::ControlModifier) {
|
2012-03-22 17:19:10 +01:00
|
|
|
m_tabWidget->nextTab();
|
|
|
|
event->accept();
|
2011-11-07 19:56:53 +01:00
|
|
|
}
|
|
|
|
break;
|
2012-02-05 16:00:23 +01:00
|
|
|
|
2011-11-07 19:56:53 +01:00
|
|
|
case Qt::Key_Backtab:
|
|
|
|
if (event->modifiers() == (Qt::ControlModifier + Qt::ShiftModifier)) {
|
2012-03-22 17:19:10 +01:00
|
|
|
m_tabWidget->previousTab();
|
|
|
|
event->accept();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Qt::Key_PageDown:
|
|
|
|
if (event->modifiers() == Qt::ControlModifier) {
|
|
|
|
m_tabWidget->nextTab();
|
|
|
|
event->accept();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Qt::Key_PageUp:
|
|
|
|
if (event->modifiers() == Qt::ControlModifier) {
|
|
|
|
m_tabWidget->previousTab();
|
|
|
|
event->accept();
|
2011-11-07 19:56:53 +01:00
|
|
|
}
|
|
|
|
break;
|
2011-11-06 12:05:16 +01:00
|
|
|
|
2012-07-14 11:46:53 +02:00
|
|
|
case Qt::Key_Equal:
|
2013-02-17 11:05:35 +01:00
|
|
|
if (view && event->modifiers() == Qt::ControlModifier) {
|
2014-03-10 16:55:11 +01:00
|
|
|
view->zoomIn();
|
2012-07-14 11:46:53 +02:00
|
|
|
event->accept();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2013-01-26 21:58:09 +01:00
|
|
|
case Qt::Key_I:
|
|
|
|
if (event->modifiers() == Qt::ControlModifier) {
|
2014-03-10 16:55:11 +01:00
|
|
|
action(QSL("Tools/SiteInfo"))->trigger();
|
2013-01-26 21:58:09 +01:00
|
|
|
event->accept();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Qt::Key_U:
|
|
|
|
if (event->modifiers() == Qt::ControlModifier) {
|
2014-03-10 16:55:11 +01:00
|
|
|
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();
|
2013-01-26 21:58:09 +01:00
|
|
|
event->accept();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2012-02-05 16:00:23 +01:00
|
|
|
case Qt::Key_1:
|
2012-02-05 17:13:08 +01:00
|
|
|
number = 1;
|
|
|
|
break;
|
2012-02-05 16:00:23 +01:00
|
|
|
case Qt::Key_2:
|
2012-02-05 17:13:08 +01:00
|
|
|
number = 2;
|
|
|
|
break;
|
2012-02-05 16:00:23 +01:00
|
|
|
case Qt::Key_3:
|
2012-02-05 17:13:08 +01:00
|
|
|
number = 3;
|
|
|
|
break;
|
2012-02-05 16:00:23 +01:00
|
|
|
case Qt::Key_4:
|
2012-02-05 17:13:08 +01:00
|
|
|
number = 4;
|
|
|
|
break;
|
2012-02-05 16:00:23 +01:00
|
|
|
case Qt::Key_5:
|
2012-02-05 17:13:08 +01:00
|
|
|
number = 5;
|
|
|
|
break;
|
2012-02-05 16:00:23 +01:00
|
|
|
case Qt::Key_6:
|
2012-02-05 17:13:08 +01:00
|
|
|
number = 6;
|
|
|
|
break;
|
2012-02-05 16:00:23 +01:00
|
|
|
case Qt::Key_7:
|
2012-02-05 17:13:08 +01:00
|
|
|
number = 7;
|
|
|
|
break;
|
2012-02-05 16:00:23 +01:00
|
|
|
case Qt::Key_8:
|
2012-02-05 17:13:08 +01:00
|
|
|
number = 8;
|
2012-02-05 16:00:23 +01:00
|
|
|
break;
|
|
|
|
case Qt::Key_9:
|
2012-02-05 17:13:08 +01:00
|
|
|
number = 9;
|
|
|
|
break;
|
2012-02-05 16:00:23 +01:00
|
|
|
|
2011-11-06 12:05:16 +01:00
|
|
|
default:
|
2012-02-05 17:13:08 +01:00
|
|
|
break;
|
2011-11-06 12:05:16 +01:00
|
|
|
}
|
2012-02-05 16:00:23 +01:00
|
|
|
|
2012-02-05 17:13:08 +01:00
|
|
|
if (number != -1) {
|
2012-11-28 11:27:30 +01:00
|
|
|
if (event->modifiers() & Qt::AltModifier && m_useTabNumberShortcuts) {
|
2012-02-05 17:13:08 +01:00
|
|
|
if (number == 9) {
|
|
|
|
number = m_tabWidget->count();
|
|
|
|
}
|
|
|
|
m_tabWidget->setCurrentIndex(number - 1);
|
|
|
|
return;
|
|
|
|
}
|
2012-11-28 11:27:30 +01:00
|
|
|
if (event->modifiers() & Qt::ControlModifier && m_useSpeedDialNumberShortcuts) {
|
2013-12-30 13:43:48 +01:00
|
|
|
const QUrl url = mApp->plugins()->speedDial()->urlForShortcut(number - 1);
|
2012-02-05 17:13:08 +01:00
|
|
|
if (url.isValid()) {
|
|
|
|
loadAddress(url);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-02-05 16:00:23 +01:00
|
|
|
|
|
|
|
QMainWindow::keyPressEvent(event);
|
2011-11-06 12:05:16 +01:00
|
|
|
}
|
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
void BrowserWindow::keyReleaseEvent(QKeyEvent* event)
|
2012-03-05 13:16:34 +01:00
|
|
|
{
|
2014-02-26 19:55:49 +01:00
|
|
|
if (mApp->plugins()->processKeyRelease(Qz::ON_BrowserWindow, this, event)) {
|
2012-03-05 13:16:34 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QMainWindow::keyReleaseEvent(event);
|
|
|
|
}
|
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
void BrowserWindow::closeEvent(QCloseEvent* event)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
if (mApp->isClosing()) {
|
2011-03-02 16:57:41 +01:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-29 19:55:21 +02:00
|
|
|
|
2012-08-14 12:35:24 +02:00
|
|
|
Settings settings;
|
2014-02-11 15:44:47 +01:00
|
|
|
int afterLaunch = settings.value("Web-URL-Settings/afterLaunch", 3).toInt();
|
2012-08-14 12:35:24 +02:00
|
|
|
bool askOnClose = settings.value("Browser-Tabs-Settings/AskOnClosing", true).toBool();
|
|
|
|
|
|
|
|
if (afterLaunch == 3 && mApp->windowCount() == 1) {
|
|
|
|
askOnClose = false;
|
|
|
|
}
|
|
|
|
|
2012-09-08 19:28:47 +02:00
|
|
|
if (askOnClose && m_tabWidget->normalTabsCount() > 1) {
|
2012-08-14 12:35:24 +02:00
|
|
|
CheckBoxDialog dialog(QDialogButtonBox::Yes | QDialogButtonBox::No, this);
|
2014-01-21 23:09:53 +01:00
|
|
|
dialog.setText(tr("There are still %1 open tabs and your session won't be stored. \nAre you sure to close this window?").arg(m_tabWidget->count()));
|
2012-08-14 12:35:24 +02:00
|
|
|
dialog.setCheckBoxText(tr("Don't ask again"));
|
|
|
|
dialog.setWindowTitle(tr("There are still open tabs"));
|
2014-03-07 18:03:42 +01:00
|
|
|
dialog.setIcon(IconProvider::standardIcon(QStyle::SP_MessageBoxWarning));
|
2012-08-14 12:35:24 +02:00
|
|
|
|
|
|
|
if (dialog.exec() != QDialog::Accepted) {
|
|
|
|
event->ignore();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dialog.isChecked()) {
|
|
|
|
settings.setValue("Browser-Tabs-Settings/AskOnClosing", false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-31 21:27:52 +01:00
|
|
|
m_isClosing = true;
|
2011-03-29 19:55:21 +02:00
|
|
|
|
2012-09-03 22:48:52 +02:00
|
|
|
#ifndef Q_OS_MAC
|
2012-01-18 18:36:10 +01:00
|
|
|
if (mApp->windowCount() == 1) {
|
2012-01-10 19:10:16 +01:00
|
|
|
if (quitApp()) {
|
2012-01-10 21:15:03 +01:00
|
|
|
event->accept();
|
2012-01-10 19:10:16 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
event->ignore();
|
|
|
|
}
|
|
|
|
|
2011-03-05 10:57:36 +01:00
|
|
|
return;
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
2012-01-06 15:03:48 +01:00
|
|
|
#endif
|
2011-03-02 16:57:41 +01:00
|
|
|
|
|
|
|
event->accept();
|
|
|
|
}
|
|
|
|
|
2014-03-10 16:55:11 +01:00
|
|
|
SearchToolBar* BrowserWindow::searchToolBar() const
|
2013-01-25 19:52:30 +01:00
|
|
|
{
|
|
|
|
SearchToolBar* toolBar = 0;
|
2013-11-26 14:14:36 +01:00
|
|
|
const int searchPos = 3;
|
2013-01-25 19:52:30 +01:00
|
|
|
|
2013-02-09 13:00:45 +01:00
|
|
|
if (m_mainLayout->count() == searchPos + 1) {
|
|
|
|
toolBar = qobject_cast<SearchToolBar*>(m_mainLayout->itemAt(searchPos)->widget());
|
2013-01-25 19:52:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return toolBar;
|
|
|
|
}
|
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
void BrowserWindow::closeWindow()
|
2012-02-01 17:01:08 +01:00
|
|
|
{
|
2013-02-07 14:01:01 +01:00
|
|
|
#ifdef Q_OS_MAC
|
2014-03-10 16:55:11 +01:00
|
|
|
if (true) {
|
2013-02-07 14:01:01 +01:00
|
|
|
#else
|
2012-02-01 17:01:08 +01:00
|
|
|
if (mApp->windowCount() > 1) {
|
2014-03-10 16:55:11 +01:00
|
|
|
#endif
|
2012-02-01 17:01:08 +01:00
|
|
|
close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
bool BrowserWindow::quitApp()
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2012-01-18 18:36:10 +01:00
|
|
|
if (m_sideBar) {
|
2011-10-17 09:59:09 +02:00
|
|
|
saveSideBarWidth();
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-10-17 09:59:09 +02:00
|
|
|
|
2014-03-10 00:47:07 +01:00
|
|
|
if (!mApp->isPrivate()) {
|
2012-07-04 19:13:44 +02:00
|
|
|
Settings settings;
|
|
|
|
settings.beginGroup("Browser-View-Settings");
|
|
|
|
settings.setValue("WindowMaximised", windowState().testFlag(Qt::WindowMaximized));
|
2014-03-10 16:55:11 +01:00
|
|
|
settings.setValue("LocationBarWidth", m_navigationToolbar->splitter()->sizes().at(0));
|
|
|
|
settings.setValue("WebSearchBarWidth", m_navigationToolbar->splitter()->sizes().at(1));
|
2012-07-04 19:13:44 +02:00
|
|
|
settings.setValue("SideBarWidth", m_sideBarWidth);
|
|
|
|
settings.setValue("WebViewWidth", m_webViewWidth);
|
2013-02-09 15:47:06 +01:00
|
|
|
|
|
|
|
if (!isFullScreen()) {
|
|
|
|
settings.setValue("WindowGeometry", saveGeometry());
|
|
|
|
}
|
2012-07-04 19:13:44 +02:00
|
|
|
settings.endGroup();
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-09-06 11:39:42 +02:00
|
|
|
mApp->quitApplication();
|
2011-03-05 13:16:13 +01:00
|
|
|
return true;
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
void BrowserWindow::closeTab()
|
2013-02-07 15:01:25 +01:00
|
|
|
{
|
2014-02-12 11:16:57 +01:00
|
|
|
// Don't close pinned tabs with keyboard shortcuts (Ctrl+W, Ctrl+F4)
|
|
|
|
if (weView() && !weView()->webTab()->isPinned()) {
|
|
|
|
m_tabWidget->closeTab();
|
|
|
|
}
|
2013-02-07 15:01:25 +01:00
|
|
|
}
|
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
QByteArray BrowserWindow::saveState(int version) const
|
2012-09-06 11:39:42 +02:00
|
|
|
{
|
2014-03-03 14:47:47 +01:00
|
|
|
#ifdef QZ_WS_X11
|
2012-09-06 11:39:42 +02:00
|
|
|
QByteArray data;
|
|
|
|
QDataStream stream(&data, QIODevice::WriteOnly);
|
|
|
|
|
|
|
|
stream << QMainWindow::saveState(version);
|
|
|
|
stream << getCurrentVirtualDesktop();
|
|
|
|
|
|
|
|
return data;
|
|
|
|
#else
|
|
|
|
return QMainWindow::saveState(version);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
bool BrowserWindow::restoreState(const QByteArray &state, int version)
|
2012-09-06 11:39:42 +02:00
|
|
|
{
|
2014-03-03 14:47:47 +01:00
|
|
|
#ifdef QZ_WS_X11
|
2012-09-06 11:39:42 +02:00
|
|
|
QByteArray windowState;
|
|
|
|
int desktopId = -1;
|
|
|
|
|
|
|
|
QDataStream stream(state);
|
|
|
|
stream >> windowState;
|
|
|
|
stream >> desktopId;
|
|
|
|
|
|
|
|
moveToVirtualDesktop(desktopId);
|
|
|
|
|
|
|
|
return QMainWindow::restoreState(windowState, version);
|
|
|
|
#else
|
2012-09-07 20:31:55 +02:00
|
|
|
return QMainWindow::restoreState(state, version);
|
2012-09-06 11:39:42 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-03-03 14:47:47 +01:00
|
|
|
#ifdef QZ_WS_X11
|
2014-02-19 22:07:21 +01:00
|
|
|
int BrowserWindow::getCurrentVirtualDesktop() const
|
2012-09-06 11:39:42 +02:00
|
|
|
{
|
2013-01-22 19:04:22 +01:00
|
|
|
Display* display = static_cast<Display*>(QzTools::X11Display(this));
|
2012-09-06 11:39:42 +02:00
|
|
|
Atom actual_type;
|
|
|
|
int actual_format;
|
|
|
|
unsigned long nitems;
|
|
|
|
unsigned long bytes;
|
|
|
|
unsigned long* data;
|
|
|
|
|
|
|
|
Atom net_wm_desktop = XInternAtom(display, "_NET_WM_DESKTOP", False);
|
|
|
|
if (net_wm_desktop == None) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int status = XGetWindowProperty(display, winId(), net_wm_desktop, 0, 1,
|
|
|
|
False, XA_CARDINAL, &actual_type, &actual_format,
|
|
|
|
&nitems, &bytes, (unsigned char**) &data);
|
|
|
|
|
|
|
|
if (status != Success || data == NULL) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int desktop = *data;
|
|
|
|
XFree(data);
|
|
|
|
|
|
|
|
return desktop;
|
|
|
|
}
|
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
void BrowserWindow::moveToVirtualDesktop(int desktopId)
|
2012-09-06 11:39:42 +02:00
|
|
|
{
|
|
|
|
// Don't move when window is already visible or it is first app window
|
2013-02-15 22:18:46 +01:00
|
|
|
if (desktopId < 0 || isVisible() || m_windowType == Qz::BW_FirstAppWindow) {
|
2012-09-06 11:39:42 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-01-22 19:04:22 +01:00
|
|
|
Display* display = static_cast<Display*>(QzTools::X11Display(this));
|
2012-09-06 11:39:42 +02:00
|
|
|
|
|
|
|
Atom net_wm_desktop = XInternAtom(display, "_NET_WM_DESKTOP", False);
|
|
|
|
if (net_wm_desktop == None) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
XChangeProperty(display, winId(), net_wm_desktop, XA_CARDINAL,
|
|
|
|
32, PropModeReplace, (unsigned char*) &desktopId, 1L);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-09-03 22:48:52 +02:00
|
|
|
#ifdef Q_OS_WIN
|
2014-03-10 19:41:44 +01:00
|
|
|
void BrowserWindow::applyBlurToMainWindow(bool force)
|
|
|
|
{
|
|
|
|
if (isClosing() || m_isStarting) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!force && !isTransparentBackgroundAllowed()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int topMargin = 0;
|
|
|
|
int bottomMargin = 1;
|
|
|
|
int rightMargin = 1;
|
|
|
|
int leftMargin = 1;
|
|
|
|
|
|
|
|
if (m_sideBar) {
|
|
|
|
if (isRightToLeft()) {
|
|
|
|
rightMargin += m_sideBar.data()->width() + m_mainSplitter->handleWidth();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
leftMargin += m_sideBar.data()->width() + m_mainSplitter->handleWidth();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
topMargin += menuBar()->isVisible() ? menuBar()->height() : 0;
|
|
|
|
topMargin += m_navigationBar->isVisible() ? m_navigationBar->height() : 0;
|
|
|
|
topMargin += m_bookmarksToolbar->isVisible() ? m_bookmarksToolbar->height() : 0;
|
|
|
|
topMargin += m_tabWidget->getTabBar()->height();
|
|
|
|
|
|
|
|
SearchToolBar* search = searchToolBar();
|
|
|
|
if (search) {
|
|
|
|
bottomMargin += search->height();
|
|
|
|
}
|
|
|
|
|
|
|
|
bottomMargin += statusBar()->isVisible() ? statusBar()->height() : 0;
|
|
|
|
|
|
|
|
if (m_webInspectorDock) {
|
|
|
|
bottomMargin += m_webInspectorDock.data()->isVisible()
|
|
|
|
? m_webInspectorDock.data()->height()
|
|
|
|
+ m_webInspectorDock.data()->style()->pixelMetric(QStyle::PM_DockWidgetSeparatorExtent)
|
|
|
|
: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
QtWin::extendFrameIntoClientArea(this, leftMargin, topMargin, rightMargin, bottomMargin);
|
|
|
|
}
|
|
|
|
|
2013-01-19 23:22:30 +01:00
|
|
|
#if (QT_VERSION < 0x050000)
|
2014-02-25 19:36:13 +01:00
|
|
|
bool BrowserWindow::winEvent(MSG* message, long* result)
|
2012-08-30 10:46:58 +02:00
|
|
|
{
|
2013-01-19 23:22:30 +01:00
|
|
|
#else
|
2014-02-25 19:36:13 +01:00
|
|
|
bool BrowserWindow::nativeEvent(const QByteArray &eventType, void* _message, long* result)
|
2013-01-19 23:22:30 +01:00
|
|
|
{
|
|
|
|
Q_UNUSED(eventType)
|
|
|
|
MSG* message = static_cast<MSG*>(_message);
|
|
|
|
#endif
|
2012-08-30 10:46:58 +02:00
|
|
|
if (message && message->message == WM_DWMCOMPOSITIONCHANGED) {
|
|
|
|
Settings settings;
|
|
|
|
settings.beginGroup("Browser-View-Settings");
|
|
|
|
m_usingTransparentBackground = settings.value("useTransparentBackground", false).toBool();
|
|
|
|
settings.endGroup();
|
|
|
|
if (m_usingTransparentBackground && QtWin::isCompositionEnabled()) {
|
|
|
|
setUpdatesEnabled(false);
|
|
|
|
|
|
|
|
QtWin::extendFrameIntoClientArea(this, 0, 0, 0, 0);
|
|
|
|
QTimer::singleShot(0, this, SLOT(applyBlurToMainWindow()));
|
|
|
|
|
|
|
|
//install event filter
|
|
|
|
menuBar()->installEventFilter(this);
|
|
|
|
m_navigationBar->installEventFilter(this);
|
|
|
|
m_bookmarksToolbar->installEventFilter(this);
|
|
|
|
statusBar()->installEventFilter(this);
|
|
|
|
|
|
|
|
if (m_sideBar) {
|
|
|
|
m_sideBar.data()->installEventFilter(this);
|
|
|
|
}
|
|
|
|
|
2013-02-09 13:00:45 +01:00
|
|
|
SearchToolBar* search = searchToolBar();
|
|
|
|
if (search) {
|
|
|
|
search->installEventFilter(this);
|
2012-08-30 10:46:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (m_webInspectorDock) {
|
|
|
|
m_webInspectorDock.data()->installEventFilter(this);
|
|
|
|
}
|
|
|
|
|
2012-08-31 15:19:07 +02:00
|
|
|
if (isVisible()) {
|
2012-08-30 10:46:58 +02:00
|
|
|
hide();
|
|
|
|
show();
|
|
|
|
}
|
|
|
|
setUpdatesEnabled(true);
|
|
|
|
}
|
2013-09-03 07:44:51 +02:00
|
|
|
else {
|
|
|
|
m_usingTransparentBackground = false;
|
|
|
|
}
|
2012-08-30 10:46:58 +02:00
|
|
|
}
|
2013-01-19 23:22:30 +01:00
|
|
|
#if (QT_VERSION < 0x050000)
|
2012-08-30 10:46:58 +02:00
|
|
|
return QMainWindow::winEvent(message, result);
|
2013-01-19 23:22:30 +01:00
|
|
|
#else
|
|
|
|
return QMainWindow::nativeEvent(eventType, _message, result);
|
|
|
|
#endif
|
2012-08-30 10:46:58 +02:00
|
|
|
}
|
|
|
|
|
2014-02-25 19:36:13 +01:00
|
|
|
void BrowserWindow::paintEvent(QPaintEvent* event)
|
2013-03-16 19:46:22 +01:00
|
|
|
{
|
2013-09-03 07:44:51 +02:00
|
|
|
if (isTransparentBackgroundAllowed()) {
|
2013-03-16 19:46:22 +01:00
|
|
|
QPainter p(this);
|
|
|
|
p.setCompositionMode(QPainter::CompositionMode_Clear);
|
|
|
|
p.fillRect(event->rect(), QColor(0, 0, 0, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
QMainWindow::paintEvent(event);
|
|
|
|
}
|
|
|
|
|
2014-02-25 19:36:13 +01:00
|
|
|
bool BrowserWindow::eventFilter(QObject* object, QEvent* event)
|
2012-08-30 10:46:58 +02:00
|
|
|
{
|
|
|
|
switch (event->type()) {
|
|
|
|
case QEvent::Hide:
|
2013-02-16 13:32:33 +01:00
|
|
|
if (object == m_navigationContainer) {
|
|
|
|
m_navigationBar->removeEventFilter(this);
|
|
|
|
m_bookmarksToolbar->removeEventFilter(this);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case QEvent::Show:
|
|
|
|
if (object == m_navigationContainer) {
|
|
|
|
m_navigationBar->installEventFilter(this);
|
|
|
|
m_bookmarksToolbar->installEventFilter(this);
|
|
|
|
break;
|
|
|
|
}
|
2012-08-30 10:46:58 +02:00
|
|
|
case QEvent::Resize:
|
2013-02-16 13:32:33 +01:00
|
|
|
case QEvent::DeferredDelete:
|
|
|
|
if (object == m_navigationContainer) {
|
|
|
|
break;
|
|
|
|
}
|
2012-08-30 10:46:58 +02:00
|
|
|
applyBlurToMainWindow();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return QMainWindow::eventFilter(object, event);
|
|
|
|
}
|
|
|
|
#endif
|