2011-03-03 18:29:20 +01:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
|
|
|
* Copyright (C) 2010-2011 nowrep
|
|
|
|
*
|
|
|
|
* 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 "tabbar.h"
|
|
|
|
#include "tabwidget.h"
|
|
|
|
#include "qupzilla.h"
|
2011-03-25 19:16:21 +01:00
|
|
|
#include "webtab.h"
|
|
|
|
|
2011-03-17 17:03:04 +01:00
|
|
|
TabBar::TabBar(QupZilla* mainClass, QWidget* parent) :
|
2011-03-02 16:57:41 +01:00
|
|
|
QTabBar(parent)
|
|
|
|
,p_QupZilla(mainClass)
|
|
|
|
,m_clickedTab(0)
|
|
|
|
{
|
|
|
|
setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
|
setObjectName("tabBar");
|
|
|
|
setElideMode(Qt::ElideRight);
|
2011-03-25 19:16:21 +01:00
|
|
|
setTabsClosable(true);
|
2011-03-02 16:57:41 +01:00
|
|
|
setDocumentMode(true);
|
|
|
|
loadSettings();
|
|
|
|
|
|
|
|
connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(contextMenuRequested(const QPoint &)));
|
|
|
|
}
|
|
|
|
|
|
|
|
void TabBar::loadSettings()
|
|
|
|
{
|
2011-03-04 13:59:07 +01:00
|
|
|
QSettings settings(mApp->getActiveProfil()+"settings.ini", QSettings::IniFormat);
|
2011-03-02 16:57:41 +01:00
|
|
|
settings.beginGroup("Browser-Tabs-Settings");
|
|
|
|
|
|
|
|
setMovable( settings.value("makeTabsMovable",true).toBool() );
|
|
|
|
if (settings.value("ActivateLastTabWhenClosingActual", false).toBool())
|
|
|
|
setSelectionBehaviorOnRemove(QTabBar::SelectPreviousTab);
|
|
|
|
|
|
|
|
settings.endGroup();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TabBar::contextMenuRequested(const QPoint &position)
|
|
|
|
{
|
2011-03-25 19:16:21 +01:00
|
|
|
int index = tabAt(position);
|
|
|
|
m_clickedTab = index;
|
|
|
|
|
2011-03-17 17:03:04 +01:00
|
|
|
TabWidget* tabWidget = qobject_cast<TabWidget*>(parentWidget());
|
2011-03-02 16:57:41 +01:00
|
|
|
if (!tabWidget)
|
|
|
|
return;
|
|
|
|
|
|
|
|
QMenu menu;
|
2011-04-09 00:22:50 +02:00
|
|
|
menu.addAction(QIcon(":/icons/menu/popup.png"),tr("&New tab"), p_QupZilla, SLOT(addTab()));
|
2011-03-02 16:57:41 +01:00
|
|
|
menu.addSeparator();
|
|
|
|
if (index!=-1) {
|
2011-03-26 13:34:08 +01:00
|
|
|
WebTab* webTab = qobject_cast<WebTab*>(tabWidget->widget(m_clickedTab));
|
|
|
|
if (!webTab)
|
|
|
|
return;
|
2011-04-08 17:27:08 +02:00
|
|
|
if (p_QupZilla->weView(m_clickedTab)->isLoading()) {
|
|
|
|
menu.addAction(
|
2011-03-02 16:57:41 +01:00
|
|
|
#ifdef Q_WS_X11
|
|
|
|
style()->standardIcon(QStyle::SP_BrowserStop)
|
|
|
|
#else
|
|
|
|
QIcon(":/icons/faenza/stop.png")
|
|
|
|
#endif
|
2011-04-09 00:22:50 +02:00
|
|
|
,tr("&Stop Tab"), this, SLOT(stopTab()));
|
2011-04-08 17:27:08 +02:00
|
|
|
} else {
|
|
|
|
menu.addAction(
|
2011-03-02 16:57:41 +01:00
|
|
|
#ifdef Q_WS_X11
|
|
|
|
style()->standardIcon(QStyle::SP_BrowserReload)
|
|
|
|
#else
|
|
|
|
QIcon(":/icons/faenza/reload.png")
|
|
|
|
#endif
|
2011-04-09 00:22:50 +02:00
|
|
|
,tr("&Reload Tab"), this, SLOT(reloadTab()));
|
2011-04-08 17:27:08 +02:00
|
|
|
}
|
2011-04-09 00:22:50 +02:00
|
|
|
menu.addAction(tr("&Duplicate Tab"), this, SLOT(duplicateTab()));
|
|
|
|
menu.addAction(webTab->isPinned() ? tr("Un&pin Tab") : tr("&Pin Tab"), this, SLOT(pinTab()));
|
2011-03-25 19:16:21 +01:00
|
|
|
menu.addSeparator();
|
2011-04-09 00:22:50 +02:00
|
|
|
menu.addAction(tr("Re&load All Tabs"), tabWidget, SLOT(reloadAllTabs()));
|
|
|
|
menu.addAction(tr("&Bookmark This Tab"), this, SLOT(bookmarkTab()));
|
|
|
|
menu.addAction(tr("Bookmark &All Tabs"), p_QupZilla, SLOT(bookmarkAllTabs()));
|
2011-03-02 16:57:41 +01:00
|
|
|
menu.addSeparator();
|
2011-05-07 12:59:53 +02:00
|
|
|
QAction* action = p_QupZilla->actionRestoreTab();
|
2011-03-02 16:57:41 +01:00
|
|
|
tabWidget->canRestoreTab() ? action->setEnabled(true) : action->setEnabled(false);
|
2011-05-07 12:59:53 +02:00
|
|
|
menu.addAction(action);
|
2011-03-02 16:57:41 +01:00
|
|
|
menu.addSeparator();
|
2011-04-09 00:22:50 +02:00
|
|
|
menu.addAction(tr("Close Ot&her Tabs"), this, SLOT(closeAllButCurrent()));
|
|
|
|
menu.addAction(QIcon::fromTheme("window-close"),tr("Cl&ose"), this, SLOT(closeTab()));
|
2011-03-02 16:57:41 +01:00
|
|
|
menu.addSeparator();
|
2011-04-08 17:27:08 +02:00
|
|
|
} else {
|
2011-04-09 00:22:50 +02:00
|
|
|
menu.addAction(tr("Reloa&d All Tabs"), tabWidget, SLOT(reloadAllTabs()));
|
|
|
|
menu.addAction(tr("Bookmark &All Ta&bs"), p_QupZilla, SLOT(bookmarkAllTabs()));
|
2011-03-02 16:57:41 +01:00
|
|
|
menu.addSeparator();
|
2011-04-09 00:22:50 +02:00
|
|
|
QAction* action = menu.addAction(QIcon::fromTheme("user-trash"),tr("Restore &Closed Tab"), tabWidget, SLOT(restoreClosedTab()));
|
2011-03-02 16:57:41 +01:00
|
|
|
tabWidget->canRestoreTab() ? action->setEnabled(true) : action->setEnabled(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
//Prevent choosing first option with double rightclick
|
|
|
|
QPoint pos = QCursor::pos();
|
|
|
|
QPoint p(pos.x(), pos.y()+1);
|
|
|
|
menu.exec(p);
|
2011-05-07 12:59:53 +02:00
|
|
|
p_QupZilla->actionRestoreTab()->setEnabled(true);
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2011-03-25 19:16:21 +01:00
|
|
|
QSize TabBar::tabSizeHint(int index) const
|
|
|
|
{
|
|
|
|
QSize size = QTabBar::tabSizeHint(index);
|
|
|
|
TabWidget* tabWidget = qobject_cast<TabWidget*>(parentWidget());
|
|
|
|
if (tabWidget) {
|
|
|
|
WebTab* webTab = qobject_cast<WebTab*>(tabWidget->widget(index));
|
|
|
|
if (webTab && webTab->isPinned())
|
2011-03-26 13:34:08 +01:00
|
|
|
#ifdef Q_WS_WIN
|
|
|
|
size.setWidth(38);
|
|
|
|
#else
|
2011-03-25 19:33:00 +01:00
|
|
|
size.setWidth(31);
|
2011-03-26 13:34:08 +01:00
|
|
|
#endif
|
2011-03-25 19:16:21 +01:00
|
|
|
}
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2011-07-19 15:18:49 +02:00
|
|
|
#if 0
|
2011-03-25 19:16:21 +01:00
|
|
|
void TabBar::tabInserted(int index)
|
|
|
|
{
|
|
|
|
// CloseButton* closeButton = new CloseButton(this);
|
|
|
|
// closeButton->setAutoRaise(true);
|
|
|
|
// closeButton->setMaximumSize(17,17);
|
|
|
|
// closeButton->setIcon(style()->standardIcon(QStyle::SP_TitleBarMaxButton));
|
|
|
|
// connect(closeButton, SIGNAL(clicked()), this, SLOT(closeCurrentTab()));
|
|
|
|
// setTabButton(index, QTabBar::RightSide, closeButton);
|
|
|
|
QAbstractButton* button = (QAbstractButton*)tabButton(index, QTabBar::RightSide);
|
|
|
|
if (!button)
|
|
|
|
return;
|
2011-07-19 15:18:49 +02:00
|
|
|
button->resize(17,17);
|
2011-03-25 19:16:21 +01:00
|
|
|
}
|
|
|
|
|
2011-07-19 15:18:49 +02:00
|
|
|
void TabBar::showCloseButton(int index)
|
|
|
|
{
|
|
|
|
TabWidget* tabWidget = qobject_cast<TabWidget*>(parentWidget());
|
|
|
|
if (!tabWidget)
|
|
|
|
return;
|
|
|
|
|
|
|
|
WebTab* webTab = qobject_cast<WebTab*>(tabWidget->widget(index));
|
|
|
|
if (webTab && webTab->isPinned())
|
|
|
|
return;
|
|
|
|
|
|
|
|
CloseButton* button = (CloseButton*)tabButton(index, QTabBar::RightSide);
|
|
|
|
if (!button)
|
|
|
|
return;
|
|
|
|
|
|
|
|
button->show();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TabBar::hideCloseButton(int index)
|
|
|
|
{
|
|
|
|
CloseButton* button = (CloseButton*)tabButton(index, QTabBar::RightSide);
|
|
|
|
if (!button)
|
|
|
|
return;
|
|
|
|
button->hide();
|
|
|
|
}
|
|
|
|
#endif
|
2011-03-25 19:16:21 +01:00
|
|
|
|
|
|
|
void TabBar::updateCloseButton(int index)
|
|
|
|
{
|
|
|
|
QAbstractButton* button = (QAbstractButton*)tabButton(index, QTabBar::RightSide);
|
|
|
|
if (!button)
|
|
|
|
return;
|
|
|
|
|
|
|
|
TabWidget* tabWidget = qobject_cast<TabWidget*>(parentWidget());
|
|
|
|
if (!tabWidget)
|
|
|
|
return;
|
|
|
|
|
|
|
|
WebTab* webTab = qobject_cast<WebTab*>(tabWidget->widget(index));
|
|
|
|
if (webTab && webTab->isPinned())
|
|
|
|
button->hide();
|
|
|
|
else
|
|
|
|
button->show();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TabBar::closeCurrentTab()
|
|
|
|
{
|
|
|
|
int id = currentIndex();
|
|
|
|
TabWidget* tabWidget = qobject_cast<TabWidget*>(parentWidget());
|
|
|
|
if (!tabWidget || id < 0)
|
|
|
|
return;
|
|
|
|
tabWidget->closeTab(id);
|
|
|
|
}
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
void TabBar::bookmarkTab()
|
|
|
|
{
|
2011-07-30 17:57:14 +02:00
|
|
|
p_QupZilla->addBookmark(p_QupZilla->weView(m_clickedTab)->url(), p_QupZilla->weView(m_clickedTab)->title(), p_QupZilla->weView(m_clickedTab)->siteIcon());
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2011-03-25 19:16:21 +01:00
|
|
|
void TabBar::pinTab()
|
|
|
|
{
|
|
|
|
TabWidget* tabWidget = qobject_cast<TabWidget*>(parentWidget());
|
|
|
|
if (!tabWidget)
|
|
|
|
return;
|
|
|
|
|
|
|
|
WebTab* webTab = qobject_cast<WebTab*>(tabWidget->widget(m_clickedTab));
|
|
|
|
if (!webTab)
|
|
|
|
return;
|
|
|
|
|
|
|
|
webTab->pinTab(m_clickedTab);
|
|
|
|
}
|
|
|
|
|
2011-03-17 17:03:04 +01:00
|
|
|
void TabBar::mouseDoubleClickEvent(QMouseEvent* event)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2011-03-17 17:03:04 +01:00
|
|
|
TabWidget* tabWidget = qobject_cast<TabWidget*>(parentWidget());
|
2011-03-02 16:57:41 +01:00
|
|
|
if (!tabWidget)
|
|
|
|
return;
|
|
|
|
if (event->button() == Qt::LeftButton && tabAt(event->pos()) == -1) {
|
|
|
|
tabWidget->addView(QUrl(),tr("New tab"), TabWidget::NewTab, true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
QTabBar::mouseDoubleClickEvent(event);
|
|
|
|
}
|