2012-01-21 20:24:36 +01:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
2014-01-11 16:11:42 +01:00
|
|
|
* Copyright (C) 2010-2014 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"
|
|
|
|
#include "popupwebpage.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"
|
2013-01-25 19:52:30 +01:00
|
|
|
#include "iconprovider.h"
|
2012-01-21 20:24:36 +01:00
|
|
|
|
2012-02-29 18:33:50 +01:00
|
|
|
#include <QVBoxLayout>
|
|
|
|
#include <QStatusBar>
|
|
|
|
#include <QWebFrame>
|
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)
|
2012-04-03 20:23:15 +02:00
|
|
|
, m_page(qobject_cast<PopupWebPage*>(view->page()))
|
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()));
|
|
|
|
menuFile->addAction(QIcon::fromTheme("document-print"), tr("&Print..."), m_view, SLOT(printPage()))->setShortcut(QKeySequence("Ctrl+P"));
|
|
|
|
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"));
|
|
|
|
m_menuEdit->addAction(QIcon::fromTheme("edit-undo"), tr("&Undo"), this, SLOT(editUndo()))->setShortcut(QKeySequence("Ctrl+Z"));
|
|
|
|
m_menuEdit->addAction(QIcon::fromTheme("edit-redo"), tr("&Redo"), this, SLOT(editRedo()))->setShortcut(QKeySequence("Ctrl+Shift+Z"));
|
|
|
|
m_menuEdit->addSeparator();
|
|
|
|
m_menuEdit->addAction(QIcon::fromTheme("edit-cut"), tr("&Cut"), this, SLOT(editCut()))->setShortcut(QKeySequence("Ctrl+X"));
|
|
|
|
m_menuEdit->addAction(QIcon::fromTheme("edit-copy"), tr("C&opy"), this, SLOT(editCopy()))->setShortcut(QKeySequence("Ctrl+C"));
|
|
|
|
m_menuEdit->addAction(QIcon::fromTheme("edit-paste"), tr("&Paste"), this, SLOT(editPaste()))->setShortcut(QKeySequence("Ctrl+V"));
|
|
|
|
m_menuEdit->addSeparator();
|
|
|
|
m_menuEdit->addAction(QIcon::fromTheme("edit-select-all"), tr("Select All"), m_view, SLOT(selectAll()))->setShortcut(QKeySequence("Ctrl+A"));
|
|
|
|
m_menuEdit->addAction(QIcon::fromTheme("edit-find"), tr("Find"), this, SLOT(searchOnPage()))->setShortcut(QKeySequence("Ctrl+F"));
|
|
|
|
connect(m_menuEdit, SIGNAL(aboutToShow()), this, SLOT(aboutToShowEditMenu()));
|
2013-02-10 11:17:44 +01:00
|
|
|
connect(m_menuEdit, SIGNAL(aboutToHide()), this, SLOT(aboutToHideEditMenu()));
|
2013-01-25 19:52:30 +01:00
|
|
|
m_menuBar->addMenu(m_menuEdit);
|
|
|
|
|
|
|
|
m_menuView = new QMenu(tr("View"));
|
2014-03-07 18:03:42 +01:00
|
|
|
m_actionStop = m_menuView->addAction(IconProvider::standardIcon(QStyle::SP_BrowserStop), tr("&Stop"), m_view, SLOT(stop()));
|
2013-01-25 19:52:30 +01:00
|
|
|
m_actionStop->setShortcut(QKeySequence("Esc"));
|
2014-03-07 18:03:42 +01:00
|
|
|
m_actionReload = m_menuView->addAction(IconProvider::standardIcon(QStyle::SP_BrowserReload), 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();
|
|
|
|
m_menuView->addAction(QIcon::fromTheme("text-html"), tr("&Page Source"), m_view, SLOT(showSource()))->setShortcut(QKeySequence("Ctrl+U"));
|
|
|
|
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);
|
|
|
|
|
2013-02-10 11:17:44 +01:00
|
|
|
aboutToHideEditMenu();
|
|
|
|
|
2012-01-21 20:24:36 +01:00
|
|
|
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()));
|
2012-03-04 14:25:52 +01:00
|
|
|
connect(m_view, SIGNAL(statusBarMessage(QString)), this, SLOT(showStatusBarMessage(QString)));
|
|
|
|
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
|
|
|
|
2013-03-06 09:05:41 +01:00
|
|
|
connect(m_page, SIGNAL(linkHovered(QString,QString,QString)), this, SLOT(showStatusBarMessage(QString)));
|
2012-01-21 20:24:36 +01:00
|
|
|
connect(m_page, SIGNAL(geometryChangeRequested(QRect)), this, SLOT(setWindowGeometry(QRect)));
|
|
|
|
connect(m_page, SIGNAL(statusBarVisibilityChangeRequested(bool)), this, SLOT(setStatusBarVisibility(bool)));
|
|
|
|
connect(m_page, SIGNAL(menuBarVisibilityChangeRequested(bool)), this, SLOT(setMenuBarVisibility(bool)));
|
|
|
|
connect(m_page, SIGNAL(toolBarVisibilityChangeRequested(bool)), this, SLOT(setToolBarVisibility(bool)));
|
|
|
|
|
|
|
|
m_view->setFocus();
|
|
|
|
titleChanged();
|
2012-01-22 15:15:43 +01:00
|
|
|
|
|
|
|
QUrl urlToShow = m_view->url();
|
|
|
|
if (urlToShow.isEmpty()) {
|
|
|
|
urlToShow = m_view->page()->mainFrame()->requestedUrl();
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
if (m_page->isRunningLoop()) {
|
|
|
|
event->ignore();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_page->disconnectObjects();
|
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::editSelectAll()
|
|
|
|
{
|
|
|
|
m_view->selectAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupWindow::aboutToShowEditMenu()
|
|
|
|
{
|
|
|
|
m_menuEdit->actions().at(0)->setEnabled(m_view->pageAction(QWebPage::Undo)->isEnabled());
|
|
|
|
m_menuEdit->actions().at(1)->setEnabled(m_view->pageAction(QWebPage::Redo)->isEnabled());
|
|
|
|
// Separator
|
|
|
|
m_menuEdit->actions().at(3)->setEnabled(m_view->pageAction(QWebPage::Cut)->isEnabled());
|
|
|
|
m_menuEdit->actions().at(4)->setEnabled(m_view->pageAction(QWebPage::Copy)->isEnabled());
|
|
|
|
m_menuEdit->actions().at(5)->setEnabled(m_view->pageAction(QWebPage::Paste)->isEnabled());
|
|
|
|
// Separator
|
|
|
|
m_menuEdit->actions().at(7)->setEnabled(m_view->pageAction(QWebPage::SelectAll)->isEnabled());
|
|
|
|
}
|
|
|
|
|
2013-02-10 11:17:44 +01:00
|
|
|
void PopupWindow::aboutToHideEditMenu()
|
|
|
|
{
|
|
|
|
m_menuEdit->actions().at(0)->setEnabled(false);
|
|
|
|
m_menuEdit->actions().at(1)->setEnabled(false);
|
|
|
|
// Separator
|
|
|
|
m_menuEdit->actions().at(3)->setEnabled(false);
|
|
|
|
m_menuEdit->actions().at(4)->setEnabled(false);
|
|
|
|
m_menuEdit->actions().at(5)->setEnabled(false);
|
|
|
|
// Separator
|
|
|
|
m_menuEdit->actions().at(7)->setEnabled(false);
|
|
|
|
}
|
|
|
|
|
2013-01-25 19:52:30 +01:00
|
|
|
void PopupWindow::savePageScreen()
|
|
|
|
{
|
|
|
|
PageScreen* pageScreen = new PageScreen(m_view, this);
|
|
|
|
pageScreen->show();
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupWindow::editUndo()
|
|
|
|
{
|
|
|
|
m_view->triggerPageAction(QWebPage::Undo);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupWindow::editRedo()
|
|
|
|
{
|
|
|
|
m_view->triggerPageAction(QWebPage::Redo);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupWindow::editCut()
|
|
|
|
{
|
|
|
|
m_view->triggerPageAction(QWebPage::Cut);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupWindow::editCopy()
|
|
|
|
{
|
|
|
|
m_view->triggerPageAction(QWebPage::Copy);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupWindow::editPaste()
|
|
|
|
{
|
|
|
|
m_view->triggerPageAction(QWebPage::Paste);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|