2012-01-21 20:24:36 +01:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
|
|
|
* Copyright (C) 2010-2012 David Rosca <nowrep@gmail.com>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
* ============================================================ */
|
|
|
|
#include "popupwindow.h"
|
|
|
|
#include "popupwebview.h"
|
|
|
|
#include "popupwebpage.h"
|
2012-03-04 14:25:52 +01:00
|
|
|
#include "popupstatusbarmessage.h"
|
|
|
|
#include "progressbar.h"
|
2013-01-13 00:53:48 +01:00
|
|
|
#include "qupzilla.h"
|
2012-01-21 20:24:36 +01:00
|
|
|
#include "popuplocationbar.h"
|
2012-01-22 15:15:43 +01:00
|
|
|
#include "globalfunctions.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>
|
2012-01-21 20:24:36 +01:00
|
|
|
|
2013-01-13 00:53:48 +01:00
|
|
|
PopupWindow::PopupWindow(PopupWebView* view, QupZilla *mainClass)
|
2012-01-21 20:24:36 +01:00
|
|
|
: QWidget()
|
2013-01-13 00:53:48 +01:00
|
|
|
, p_QupZilla(mainClass)
|
2012-01-21 20:24:36 +01:00
|
|
|
, m_view(view)
|
2012-04-03 20:23:15 +02:00
|
|
|
, m_page(qobject_cast<PopupWebPage*>(view->page()))
|
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);
|
2013-01-13 00:53:48 +01:00
|
|
|
m_statusBar->setVisible(p_QupZilla->statusBar()->isVisible());
|
2012-03-04 14:25:52 +01:00
|
|
|
|
|
|
|
m_progressBar = new ProgressBar(m_statusBar);
|
|
|
|
m_statusBar->addPermanentWidget(m_progressBar);
|
|
|
|
m_progressBar->hide();
|
|
|
|
|
|
|
|
m_statusBarMessage = new PopupStatusBarMessage(this);
|
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)));
|
|
|
|
connect(m_view, SIGNAL(iconChanged()), m_locationBar, SLOT(showIcon()));
|
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
|
|
|
|
2012-03-04 14:25:52 +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)
|
|
|
|
{
|
|
|
|
if (m_layout->count() > 3) {
|
|
|
|
delete m_layout->itemAt(1)->widget();
|
|
|
|
}
|
|
|
|
|
|
|
|
m_layout->insertWidget(1, notif);
|
|
|
|
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();
|
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();
|
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();
|
|
|
|
}
|
|
|
|
|
2012-01-22 15:15:43 +01:00
|
|
|
void PopupWindow::setWindowGeometry(const QRect &newRect)
|
2012-01-21 20:24:36 +01:00
|
|
|
{
|
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)) {
|
|
|
|
qz_centerWidgetOnScreen(this);
|
|
|
|
}
|
2012-01-21 20:24:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-04 14:25:52 +01:00
|
|
|
// From my testing, these 3 slots are always fired with false
|
|
|
|
// visible argument (even if true should be passed)
|
2012-01-22 15:15:43 +01:00
|
|
|
// So for now, we just do nothing here
|
|
|
|
|
2012-01-21 20:24:36 +01:00
|
|
|
void PopupWindow::setStatusBarVisibility(bool visible)
|
|
|
|
{
|
|
|
|
Q_UNUSED(visible)
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupWindow::setMenuBarVisibility(bool visible)
|
|
|
|
{
|
|
|
|
Q_UNUSED(visible)
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupWindow::setToolBarVisibility(bool visible)
|
|
|
|
{
|
|
|
|
Q_UNUSED(visible)
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupWindow::titleChanged()
|
|
|
|
{
|
|
|
|
setWindowTitle(tr("%1 - QupZilla").arg(m_view->title()));
|
|
|
|
}
|