2011-03-03 18:29:20 +01:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
2011-10-17 09:57:07 +02:00
|
|
|
* Copyright (C) 2010-2011 David Rosca
|
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/>.
|
|
|
|
* ============================================================ */
|
2011-03-02 16:57:41 +01:00
|
|
|
#include "webtab.h"
|
|
|
|
#include "qupzilla.h"
|
|
|
|
#include "webview.h"
|
2011-07-11 20:30:49 +02:00
|
|
|
#include "webpage.h"
|
2011-03-25 19:16:21 +01:00
|
|
|
#include "tabbar.h"
|
2011-07-11 20:30:49 +02:00
|
|
|
#include "locationbar.h"
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2011-07-11 20:30:49 +02:00
|
|
|
WebTab::WebTab(QupZilla* mainClass, LocationBar* locationBar)
|
2011-10-14 20:14:57 +02:00
|
|
|
: QWidget()
|
|
|
|
, p_QupZilla(mainClass)
|
|
|
|
, m_view(0)
|
|
|
|
, m_locationBar(locationBar)
|
|
|
|
, m_pinned(false)
|
|
|
|
, m_inspectorVisible(false)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
|
|
|
m_layout = new QVBoxLayout(this);
|
2011-11-06 17:01:23 +01:00
|
|
|
m_layout->setContentsMargins(0, 0, 0, 0);
|
2011-03-02 16:57:41 +01:00
|
|
|
m_layout->setSpacing(0);
|
2011-07-19 15:18:49 +02:00
|
|
|
|
2011-05-22 10:47:03 +02:00
|
|
|
m_view = new WebView(p_QupZilla, this);
|
2011-07-21 17:16:53 +02:00
|
|
|
m_view->setLocationBar(locationBar);
|
2011-03-02 16:57:41 +01:00
|
|
|
m_layout->addWidget(m_view);
|
|
|
|
|
2011-07-19 15:18:49 +02:00
|
|
|
setLayout(m_layout);
|
2011-05-07 12:59:53 +02:00
|
|
|
setAutoFillBackground(true); // We don't want this transparent
|
2011-03-02 16:57:41 +01:00
|
|
|
|
|
|
|
connect(m_view, SIGNAL(showNotification(QWidget*)), this, SLOT(showNotification(QWidget*)));
|
2011-07-11 20:30:49 +02:00
|
|
|
connect(m_view, SIGNAL(iconChanged()), m_locationBar, SLOT(siteIconChanged()));
|
|
|
|
connect(m_view, SIGNAL(loadStarted()), m_locationBar, SLOT(clearIcon()));
|
|
|
|
connect(m_view, SIGNAL(loadFinished(bool)), m_locationBar, SLOT(siteIconChanged()));
|
2011-10-15 18:08:52 +02:00
|
|
|
connect(m_view, SIGNAL(showUrl(QUrl)), m_locationBar, SLOT(showUrl(QUrl)));
|
2011-07-11 20:30:49 +02:00
|
|
|
connect(m_view, SIGNAL(rssChanged(bool)), m_locationBar, SLOT(showRSSIcon(bool)));
|
|
|
|
connect(m_view->webPage(), SIGNAL(privacyChanged(bool)), m_locationBar, SLOT(setPrivacy(bool)));
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2011-03-17 17:03:04 +01:00
|
|
|
void WebTab::showNotification(QWidget* notif)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
if (m_layout->count() > 1) {
|
2011-03-02 16:57:41 +01:00
|
|
|
delete m_layout->itemAt(0)->widget();
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
|
|
|
m_layout->insertWidget(0, notif);
|
2011-03-02 17:54:12 +01:00
|
|
|
notif->show();
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2011-03-25 19:16:21 +01:00
|
|
|
int WebTab::tabIndex()
|
|
|
|
{
|
|
|
|
return m_view->tabIndex();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebTab::pinTab(int index)
|
|
|
|
{
|
|
|
|
TabWidget* tabWidget = p_QupZilla->tabWidget();
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!tabWidget) {
|
2011-03-25 19:16:21 +01:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-25 19:16:21 +01:00
|
|
|
|
|
|
|
if (m_pinned) { //Unpin tab
|
|
|
|
m_pinned = false;
|
|
|
|
tabWidget->setTabText(index, m_view->title());
|
|
|
|
tabWidget->getTabBar()->updateCloseButton(index);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
else { // Pin tab
|
2011-03-25 19:16:21 +01:00
|
|
|
m_pinned = true;
|
|
|
|
tabWidget->setCurrentIndex(0); // <<-- those 2 lines fixes
|
2011-05-07 12:59:53 +02:00
|
|
|
tabWidget->getTabBar()->moveTab(index, 0); // | weird behavior with bad
|
|
|
|
tabWidget->setTabText(0, ""); // | tabwidget update if we
|
2011-03-25 19:16:21 +01:00
|
|
|
tabWidget->setCurrentIndex(0); // <<-- are moving current tab
|
|
|
|
tabWidget->getTabBar()->updateCloseButton(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
WebTab::~WebTab()
|
|
|
|
{
|
2011-12-04 20:35:49 +01:00
|
|
|
if (m_locationBar) {
|
2011-12-04 20:09:44 +01:00
|
|
|
delete m_locationBar;
|
2011-12-04 20:35:49 +01:00
|
|
|
}
|
2011-12-04 20:09:44 +01:00
|
|
|
|
|
|
|
m_view->deleteLater();
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|