2012-01-21 20:24:36 +01:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
2015-05-22 23:57:24 +02:00
|
|
|
* Copyright (C) 2010-2015 David Rosca <nowrep@gmail.com>
|
2012-01-21 20:24:36 +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/>.
|
|
|
|
* ============================================================ */
|
|
|
|
#include "popupwindow.h"
|
|
|
|
#include "popupwebview.h"
|
2015-05-22 23:57:24 +02:00
|
|
|
#include "webpage.h"
|
2012-03-04 14:25:52 +01:00
|
|
|
#include "popupstatusbarmessage.h"
|
|
|
|
#include "progressbar.h"
|
2013-01-25 19:52:30 +01:00
|
|
|
#include "pagescreen.h"
|
|
|
|
#include "searchtoolbar.h"
|
2013-01-19 01:05:17 +01:00
|
|
|
#include "qzsettings.h"
|
2012-01-21 20:24:36 +01:00
|
|
|
#include "popuplocationbar.h"
|
2013-01-22 19:04:22 +01:00
|
|
|
#include "qztools.h"
|
2012-01-21 20:24:36 +01:00
|
|
|
|
2012-02-29 18:33:50 +01:00
|
|
|
#include <QVBoxLayout>
|
|
|
|
#include <QStatusBar>
|
2012-08-31 15:19:07 +02:00
|
|
|
#include <QCloseEvent>
|
2013-01-25 19:52:30 +01:00
|
|
|
#include <QMenuBar>
|
2012-01-21 20:24:36 +01:00
|
|
|
|
2013-01-25 19:52:30 +01:00
|
|
|
PopupWindow::PopupWindow(PopupWebView* view)
|
2012-01-21 20:24:36 +01:00
|
|
|
: QWidget()
|
|
|
|
, m_view(view)
|
2013-01-25 19:52:30 +01:00
|
|
|
, m_search(0)
|
2012-01-21 20:24:36 +01:00
|
|
|
{
|
|
|
|
m_layout = new QVBoxLayout(this);
|
|
|
|
m_layout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
m_layout->setSpacing(0);
|
|
|
|
|
|
|
|
m_locationBar = new PopupLocationBar(this);
|
|
|
|
m_locationBar->setView(m_view);
|
|
|
|
|
|
|
|
m_statusBar = new QStatusBar(this);
|
|
|
|
m_statusBar->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
|
2012-03-04 14:25:52 +01:00
|
|
|
|
|
|
|
m_progressBar = new ProgressBar(m_statusBar);
|
|
|
|
m_statusBar->addPermanentWidget(m_progressBar);
|
|
|
|
m_progressBar->hide();
|
|
|
|
|
2013-01-25 19:52:30 +01:00
|
|
|
m_view->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
2012-03-04 14:25:52 +01:00
|
|
|
m_statusBarMessage = new PopupStatusBarMessage(this);
|
2012-01-21 20:24:36 +01:00
|
|
|
|
2013-01-25 19:52:30 +01:00
|
|
|
m_menuBar = new QMenuBar(this);
|
|
|
|
|
|
|
|
QMenu* menuFile = new QMenu(tr("File"));
|
|
|
|
menuFile->addAction(QIcon::fromTheme("document-save"), tr("&Save Page As..."), m_view, SLOT(savePageAs()))->setShortcut(QKeySequence("Ctrl+S"));
|
|
|
|
menuFile->addAction(tr("Save Page Screen"), this, SLOT(savePageScreen()));
|
|
|
|
menuFile->addAction(QIcon::fromTheme("mail-message-new"), tr("Send Link..."), m_view, SLOT(sendPageByMail()));
|
2015-05-22 23:57:24 +02:00
|
|
|
//menuFile->addAction(QIcon::fromTheme("document-print"), tr("&Print..."), m_view, SLOT(printPage()))->setShortcut(QKeySequence("Ctrl+P"));
|
2013-01-25 19:52:30 +01:00
|
|
|
menuFile->addSeparator();
|
|
|
|
menuFile->addAction(QIcon::fromTheme("window-close"), tr("Close"), this, SLOT(close()))->setShortcut(QKeySequence("Ctrl+W"));
|
|
|
|
m_menuBar->addMenu(menuFile);
|
|
|
|
|
|
|
|
m_menuEdit = new QMenu(tr("Edit"));
|
2015-01-27 11:01:52 +01:00
|
|
|
m_menuEdit->addAction(m_view->pageAction(QWebEnginePage::Undo));
|
|
|
|
m_menuEdit->addAction(m_view->pageAction(QWebEnginePage::Redo));
|
2013-01-25 19:52:30 +01:00
|
|
|
m_menuEdit->addSeparator();
|
2015-01-27 11:01:52 +01:00
|
|
|
m_menuEdit->addAction(m_view->pageAction(QWebEnginePage::Cut));
|
|
|
|
m_menuEdit->addAction(m_view->pageAction(QWebEnginePage::Copy));
|
|
|
|
m_menuEdit->addAction(m_view->pageAction(QWebEnginePage::Paste));
|
2013-01-25 19:52:30 +01:00
|
|
|
m_menuEdit->addSeparator();
|
2015-01-27 11:01:52 +01:00
|
|
|
m_menuEdit->addAction(m_view->pageAction(QWebEnginePage::SelectAll));
|
2013-01-25 19:52:30 +01:00
|
|
|
m_menuEdit->addAction(QIcon::fromTheme("edit-find"), tr("Find"), this, SLOT(searchOnPage()))->setShortcut(QKeySequence("Ctrl+F"));
|
|
|
|
m_menuBar->addMenu(m_menuEdit);
|
|
|
|
|
|
|
|
m_menuView = new QMenu(tr("View"));
|
2014-03-24 16:08:33 +01:00
|
|
|
m_actionStop = m_menuView->addAction(QIcon::fromTheme(QSL("process-stop")), tr("&Stop"), m_view, SLOT(stop()));
|
2013-01-25 19:52:30 +01:00
|
|
|
m_actionStop->setShortcut(QKeySequence("Esc"));
|
2014-03-24 16:08:33 +01:00
|
|
|
m_actionReload = m_menuView->addAction(QIcon::fromTheme(QSL("view-refresh")), tr("&Reload"), m_view, SLOT(reload()));
|
2013-01-25 19:52:30 +01:00
|
|
|
m_actionReload->setShortcut(QKeySequence("F5"));
|
|
|
|
m_menuView->addSeparator();
|
|
|
|
m_menuView->addAction(QIcon::fromTheme("zoom-in"), tr("Zoom &In"), m_view, SLOT(zoomIn()))->setShortcut(QKeySequence("Ctrl++"));
|
|
|
|
m_menuView->addAction(QIcon::fromTheme("zoom-out"), tr("Zoom &Out"), m_view, SLOT(zoomOut()))->setShortcut(QKeySequence("Ctrl+-"));
|
|
|
|
m_menuView->addAction(QIcon::fromTheme("zoom-original"), tr("Reset"), m_view, SLOT(zoomReset()))->setShortcut(QKeySequence("Ctrl+0"));
|
|
|
|
m_menuView->addSeparator();
|
2015-05-24 21:26:17 +02:00
|
|
|
m_menuView->addAction(QIcon::fromTheme("text-html"), tr("&Page Source"), m_view, SLOT(showSource()))->setShortcut(QKeySequence("Ctrl+U"));
|
2013-01-25 19:52:30 +01:00
|
|
|
m_menuBar->addMenu(m_menuView);
|
|
|
|
|
|
|
|
// Make shortcuts available even with hidden menubar
|
|
|
|
QList<QAction*> actions = m_menuBar->actions();
|
2013-03-06 09:05:41 +01:00
|
|
|
foreach (QAction* action, actions) {
|
2013-01-25 19:52:30 +01:00
|
|
|
if (action->menu()) {
|
|
|
|
actions += action->menu()->actions();
|
|
|
|
}
|
|
|
|
addAction(action);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_layout->insertWidget(0, m_menuBar);
|
2012-01-21 20:24:36 +01:00
|
|
|
m_layout->addWidget(m_locationBar);
|
|
|
|
m_layout->addWidget(m_view);
|
|
|
|
m_layout->addWidget(m_statusBar);
|
|
|
|
setLayout(m_layout);
|
|
|
|
|
|
|
|
connect(m_view, SIGNAL(showNotification(QWidget*)), this, SLOT(showNotification(QWidget*)));
|
|
|
|
connect(m_view, SIGNAL(titleChanged(QString)), this, SLOT(titleChanged()));
|
|
|
|
connect(m_view, SIGNAL(urlChanged(QUrl)), m_locationBar, SLOT(showUrl(QUrl)));
|
2013-02-10 14:09:28 +01:00
|
|
|
connect(m_view, SIGNAL(iconChanged()), m_locationBar, SLOT(showSiteIcon()));
|
2015-05-22 23:57:24 +02:00
|
|
|
//connect(m_view, SIGNAL(statusBarMessage(QString)), this, SLOT(showStatusBarMessage(QString)));
|
2012-03-04 14:25:52 +01:00
|
|
|
connect(m_view, SIGNAL(loadStarted()), this, SLOT(loadStarted()));
|
|
|
|
connect(m_view, SIGNAL(loadProgress(int)), this, SLOT(loadProgress(int)));
|
|
|
|
connect(m_view, SIGNAL(loadFinished(bool)), this, SLOT(loadFinished()));
|
2012-01-21 20:24:36 +01:00
|
|
|
|
2015-05-22 23:57:24 +02:00
|
|
|
connect(m_view->page(), &WebPage::linkHovered, this, &PopupWindow::showStatusBarMessage);
|
|
|
|
connect(m_view->page(), &WebPage::geometryChangeRequested, this, &PopupWindow::setWindowGeometry);
|
2012-01-21 20:24:36 +01:00
|
|
|
|
|
|
|
m_view->setFocus();
|
|
|
|
titleChanged();
|
2012-01-22 15:15:43 +01:00
|
|
|
|
|
|
|
QUrl urlToShow = m_view->url();
|
|
|
|
if (urlToShow.isEmpty()) {
|
2015-08-31 21:55:42 +02:00
|
|
|
urlToShow = m_view->page()->requestedUrl();
|
2012-01-22 15:15:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
m_locationBar->showUrl(urlToShow);
|
2012-02-02 15:54:38 +01:00
|
|
|
|
|
|
|
// Ensuring correct sizes for widgets in layout are calculated even
|
|
|
|
// before calling QWidget::show()
|
2012-03-10 14:59:43 +01:00
|
|
|
m_layout->invalidate();
|
2012-02-02 15:54:38 +01:00
|
|
|
m_layout->activate();
|
2012-01-21 20:24:36 +01:00
|
|
|
}
|
|
|
|
|
2012-03-04 14:25:52 +01:00
|
|
|
QStatusBar* PopupWindow::statusBar()
|
|
|
|
{
|
|
|
|
return m_statusBar;
|
|
|
|
}
|
|
|
|
|
|
|
|
PopupWebView* PopupWindow::webView()
|
|
|
|
{
|
|
|
|
return m_view;
|
|
|
|
}
|
|
|
|
|
2012-01-21 20:24:36 +01:00
|
|
|
void PopupWindow::showNotification(QWidget* notif)
|
|
|
|
{
|
2013-02-10 14:09:28 +01:00
|
|
|
if (m_layout->count() > 4) {
|
|
|
|
delete m_layout->itemAt(2)->widget();
|
2012-01-21 20:24:36 +01:00
|
|
|
}
|
|
|
|
|
2013-02-10 14:09:28 +01:00
|
|
|
m_layout->insertWidget(2, notif);
|
2012-01-21 20:24:36 +01:00
|
|
|
notif->show();
|
|
|
|
}
|
|
|
|
|
2012-03-04 14:25:52 +01:00
|
|
|
void PopupWindow::showStatusBarMessage(const QString &message)
|
|
|
|
{
|
|
|
|
if (message.isEmpty()) {
|
|
|
|
m_statusBarMessage->clearMessage();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
m_statusBarMessage->showMessage(message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupWindow::loadStarted()
|
|
|
|
{
|
|
|
|
m_progressBar->setValue(0);
|
|
|
|
m_progressBar->show();
|
2012-06-27 18:29:00 +02:00
|
|
|
|
|
|
|
m_locationBar->startLoading();
|
2013-01-25 19:52:30 +01:00
|
|
|
|
|
|
|
if (m_actionStop) {
|
|
|
|
m_actionStop->setEnabled(true);
|
|
|
|
m_actionReload->setEnabled(false);
|
|
|
|
}
|
2012-03-04 14:25:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void PopupWindow::loadProgress(int value)
|
|
|
|
{
|
|
|
|
m_progressBar->show();
|
|
|
|
m_progressBar->setValue(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupWindow::loadFinished()
|
|
|
|
{
|
|
|
|
m_progressBar->hide();
|
2012-06-27 18:29:00 +02:00
|
|
|
|
|
|
|
m_locationBar->stopLoading();
|
2013-01-25 19:52:30 +01:00
|
|
|
|
|
|
|
if (m_actionStop) {
|
|
|
|
m_actionStop->setEnabled(false);
|
|
|
|
m_actionReload->setEnabled(true);
|
|
|
|
}
|
2012-03-04 14:25:52 +01:00
|
|
|
}
|
|
|
|
|
2012-01-21 20:24:36 +01:00
|
|
|
void PopupWindow::closeEvent(QCloseEvent* event)
|
|
|
|
{
|
2015-05-22 23:57:24 +02:00
|
|
|
if (m_view->page()->isRunningLoop()) {
|
2012-01-21 20:24:36 +01:00
|
|
|
event->ignore();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-01-22 15:15:43 +01:00
|
|
|
m_view->deleteLater();
|
2012-01-21 20:24:36 +01:00
|
|
|
|
|
|
|
event->accept();
|
|
|
|
}
|
|
|
|
|
2013-01-25 19:52:30 +01:00
|
|
|
void PopupWindow::savePageScreen()
|
|
|
|
{
|
2015-01-27 11:01:52 +01:00
|
|
|
#if QTWEBENGINE_DISABLED
|
2013-01-25 19:52:30 +01:00
|
|
|
PageScreen* pageScreen = new PageScreen(m_view, this);
|
|
|
|
pageScreen->show();
|
2015-01-27 11:01:52 +01:00
|
|
|
#endif
|
2013-01-25 19:52:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void PopupWindow::searchOnPage()
|
|
|
|
{
|
|
|
|
if (!m_search) {
|
|
|
|
m_search = new SearchToolBar(m_view, this);
|
2013-02-10 11:25:44 +01:00
|
|
|
m_search.data()->showMinimalInPopupWindow();
|
2013-01-25 19:52:30 +01:00
|
|
|
m_layout->insertWidget(m_layout->count() - 1, m_search);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_search->focusSearchLine();
|
|
|
|
}
|
|
|
|
|
2013-01-19 01:05:17 +01:00
|
|
|
void PopupWindow::titleChanged()
|
|
|
|
{
|
|
|
|
setWindowTitle(tr("%1 - QupZilla").arg(m_view->title()));
|
|
|
|
}
|
|
|
|
|
2013-01-25 19:52:30 +01:00
|
|
|
void PopupWindow::setWindowGeometry(QRect newRect)
|
2012-01-21 20:24:36 +01:00
|
|
|
{
|
2013-01-19 01:05:17 +01:00
|
|
|
if (!qzSettings->allowJsGeometryChange) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-01-25 19:52:30 +01:00
|
|
|
// left/top was set while width/height not
|
|
|
|
if (!newRect.topLeft().isNull() && newRect.size().isNull()) {
|
|
|
|
newRect.setSize(QSize(550, 585));
|
|
|
|
}
|
|
|
|
|
2012-01-22 15:15:43 +01:00
|
|
|
if (newRect.isValid()) {
|
|
|
|
QRect oldRect = rect();
|
2012-02-02 15:54:38 +01:00
|
|
|
move(newRect.topLeft());
|
|
|
|
|
|
|
|
QSize newSize = newRect.size();
|
|
|
|
int additionalHeight = height() - m_view->height();
|
|
|
|
newSize.setHeight(newSize.height() + additionalHeight);
|
|
|
|
resize(newSize);
|
2012-01-22 15:15:43 +01:00
|
|
|
|
|
|
|
if (newRect.topLeft() == QPoint(0, 0) && oldRect.topLeft() == QPoint(0, 0)) {
|
2013-01-22 19:04:22 +01:00
|
|
|
QzTools::centerWidgetOnScreen(this);
|
2012-01-22 15:15:43 +01:00
|
|
|
}
|
2012-01-21 20:24:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupWindow::setStatusBarVisibility(bool visible)
|
|
|
|
{
|
2013-01-25 19:52:30 +01:00
|
|
|
m_statusBar->setVisible(qzSettings->allowJsHideStatusBar ? visible : true);
|
2012-01-21 20:24:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void PopupWindow::setMenuBarVisibility(bool visible)
|
|
|
|
{
|
2013-01-25 19:52:30 +01:00
|
|
|
m_menuBar->setVisible(qzSettings->allowJsHideMenuBar ? visible : true);
|
2012-01-21 20:24:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void PopupWindow::setToolBarVisibility(bool visible)
|
|
|
|
{
|
2013-01-25 19:52:30 +01:00
|
|
|
// Does nothing now
|
|
|
|
// m_toolBar->setVisible(qzSettings->allowJsHideToolBar ? visible : true);
|
2013-01-19 01:05:17 +01:00
|
|
|
Q_UNUSED(visible)
|
2012-01-21 20:24:36 +01:00
|
|
|
}
|