summaryrefslogtreecommitdiff
path: root/src/mainview.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mainview.cpp')
-rw-r--r--src/mainview.cpp342
1 files changed, 180 insertions, 162 deletions
diff --git a/src/mainview.cpp b/src/mainview.cpp
index b26e7466..4dc95b26 100644
--- a/src/mainview.cpp
+++ b/src/mainview.cpp
@@ -2,9 +2,10 @@
*
* This file is a part of the rekonq project
*
-* Copyright (C) 2008-2009 by Andrea Diamantini <adjam7 at gmail dot com>
+* Copyright (C) 2008-2010 by Andrea Diamantini <adjam7 at gmail dot com>
* Copyright (C) 2009 by Paweł Prażak <pawelprazak at gmail dot com>
-* Copyright (C) 2009 by Lionel Chauvin <megabigbug@yahoo.fr>
+* Copyright (C) 2009-2010 by Lionel Chauvin <megabigbug@yahoo.fr>
+* Copyright (C) 2010 by Matthieu Gicquel <matgic78 at gmail dot com>
*
*
* This program is free software; you can redistribute it and/or
@@ -12,9 +13,9 @@
* published by the Free Software Foundation; either version 2 of
* the License or (at your option) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
-* by the membership of KDE e.V.), which shall act as a proxy
+* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
-*
+*
* 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
@@ -45,7 +46,6 @@
#include <KShortcut>
#include <KStandardShortcut>
#include <KMessageBox>
-#include <KDebug>
#include <KStandardDirs>
#include <KPassivePopup>
#include <KLocalizedString>
@@ -63,37 +63,39 @@
MainView::MainView(MainWindow *parent)
: KTabWidget(parent)
- , m_urlBar(new UrlBar(this))
- , m_tabBar(new TabBar(this))
- , m_addTabButton(new QToolButton(this))
+ , _bars(new QStackedWidget(this))
+ , m_addTabButton(0)
, m_currentTabIndex(0)
, m_parentWindow(parent)
{
// setting tabbar
- setTabBar(m_tabBar);
+ TabBar *tabBar = new TabBar(this);
+ m_addTabButton = new QToolButton(this);
+ setTabBar(tabBar);
// set mouse tracking for tab previews
setMouseTracking(true);
-
+
// loading pixmap path
m_loadingGitPath = KStandardDirs::locate("appdata" , "pics/loading.mng");
// connecting tabbar signals
- connect(m_tabBar, SIGNAL(closeTab(int)), this, SLOT(closeTab(int)));
- connect(m_tabBar, SIGNAL(mouseMiddleClick(int)), this, SLOT(closeTab(int)));
- connect(m_tabBar, SIGNAL(newTabRequest()), this, SLOT(newTab()));
-
- connect(m_tabBar, SIGNAL(cloneTab(int)), this, SLOT(cloneTab(int)));
- connect(m_tabBar, SIGNAL(closeOtherTabs(int)), this, SLOT(closeOtherTabs(int)));
- connect(m_tabBar, SIGNAL(reloadTab(int)), this, SLOT(reloadTab(int)));
- connect(m_tabBar, SIGNAL(reloadAllTabs()), this, SLOT(reloadAllTabs()));
- connect(m_tabBar, SIGNAL(detachTab(int)), this, SLOT(detachTab(int)));
-
- connect(m_tabBar, SIGNAL(tabCloseRequested(int)), this, SLOT(closeTab(int)));
-
+ connect(tabBar, SIGNAL(closeTab(int)), this, SLOT(closeTab(int)));
+ connect(tabBar, SIGNAL(mouseMiddleClick(int)), this, SLOT(closeTab(int)));
+ connect(tabBar, SIGNAL(newTabRequest()), this, SLOT(newTab()));
+
+ connect(tabBar, SIGNAL(cloneTab(int)), this, SLOT(cloneTab(int)));
+ connect(tabBar, SIGNAL(closeOtherTabs(int)), this, SLOT(closeOtherTabs(int)));
+ connect(tabBar, SIGNAL(reloadTab(int)), this, SLOT(reloadTab(int)));
+ connect(tabBar, SIGNAL(reloadAllTabs()), this, SLOT(reloadAllTabs()));
+ connect(tabBar, SIGNAL(detachTab(int)), this, SLOT(detachTab(int)));
+
+ connect(tabBar, SIGNAL(tabCloseRequested(int)), this, SLOT(closeTab(int)));
+ connect(tabBar, SIGNAL(tabMoved(int, int)), this, SLOT(movedTab(int, int)));
+
// current page index changing
connect(this, SIGNAL(currentChanged(int)), this, SLOT(currentChanged(int)));
-
+
QTimer::singleShot(0, this, SLOT(postLaunch()));
}
@@ -106,8 +108,8 @@ MainView::~MainView()
void MainView::postLaunch()
{
// Session Manager
- connect (this, SIGNAL(tabsChanged()), Application::sessionManager(), SLOT(saveSession()));
-
+ connect(this, SIGNAL(tabsChanged()), Application::sessionManager(), SLOT(saveSession()));
+
m_addTabButton->setDefaultAction(m_parentWindow->actionByName("new_tab"));
m_addTabButton->setAutoRaise(true);
@@ -117,23 +119,21 @@ void MainView::postLaunch()
void MainView::updateTabButtonPosition()
{
- kDebug() << "updating new tab button position..";
-
static bool ButtonInCorner = false;
int tabWidgetWidth = frameSize().width();
- int tabBarWidth = m_tabBar->tabSizeHint(0).width()*m_tabBar->count();
+ int tabBarWidth = tabBar()->tabSizeHint(0).width() * tabBar()->count();
if (tabBarWidth + m_addTabButton->width() > tabWidgetWidth)
{
- if(ButtonInCorner)
+ if (ButtonInCorner)
return;
setCornerWidget(m_addTabButton);
ButtonInCorner = true;
}
else
{
- if(ButtonInCorner)
+ if (ButtonInCorner)
{
setCornerWidget(0);
m_addTabButton->show();
@@ -141,16 +141,12 @@ void MainView::updateTabButtonPosition()
}
// detecting X position
- int newPosX = tabBarWidth;
- int tabWidthHint = m_tabBar->tabSizeHint(0).width();
- if (tabWidthHint < sizeHint().width()/4)
+ int newPosX = tabBarWidth;
+ int tabWidthHint = tabBar()->tabSizeHint(0).width();
+ if (tabWidthHint < sizeHint().width() / 4)
newPosX = tabWidgetWidth - m_addTabButton->width();
- // Y position is fixed
- // Here I noticed with some emphiric valutations ( :D )
- // that 2 look better than 0, just that..
-
- m_addTabButton->move(newPosX, 2);
+ m_addTabButton->move(newPosX, 0);
}
}
@@ -163,13 +159,20 @@ QToolButton *MainView::addTabButton() const
TabBar *MainView::tabBar() const
{
- return m_tabBar;
+ TabBar *tabBar = qobject_cast<TabBar *>(KTabWidget::tabBar());
+ return tabBar;
+}
+
+
+UrlBar *MainView::urlBar() const
+{
+ return qobject_cast<UrlBar *>(_bars->widget(m_currentTabIndex));
}
-UrlBar *MainView::urlBar() const
-{
- return m_urlBar;
+QWidget *MainView::urlBarWidget() const
+{
+ return _bars;
}
@@ -185,9 +188,9 @@ void MainView::updateTabBar()
{
if (!isTabBarHidden())
{
- if (m_tabBar->isHidden())
+ if (tabBar()->isHidden())
{
- m_tabBar->show();
+ tabBar()->show();
m_addTabButton->show();
}
updateTabButtonPosition();
@@ -195,16 +198,16 @@ void MainView::updateTabBar()
return;
}
- if (m_tabBar->count() == 1)
+ if (tabBar()->count() == 1)
{
- m_tabBar->hide();
+ tabBar()->hide();
m_addTabButton->hide();
}
else if (!isTabBarHidden())
{
- if (m_tabBar->isHidden())
+ if (tabBar()->isHidden())
{
- m_tabBar->show();
+ tabBar()->show();
m_addTabButton->show();
}
updateTabButtonPosition();
@@ -235,17 +238,6 @@ void MainView::webStop()
}
-void MainView::clear()
-{
- // FIXME (the programmer, not the code)
- // What exactly do we need to clear here?
- m_urlBar->clearHistory();
- m_urlBar->clear();
-
- m_recentlyClosedTabs.clear();
-}
-
-
// When index is -1 index chooses the current tab
void MainView::reloadTab(int index)
{
@@ -268,17 +260,12 @@ void MainView::currentChanged(int index)
// retrieve the old webview (that where we move from)
WebTab *oldTab = this->webTab(m_currentTabIndex);
-
+
// set current index
m_currentTabIndex = index;
if (oldTab)
- {
- // disconnecting webview from urlbar
- disconnect(oldTab->view(), SIGNAL(loadProgress(int)), urlBar(), SLOT(updateProgress(int)));
- disconnect(oldTab->view(), SIGNAL(loadFinished(bool)), urlBar(), SLOT(loadFinished(bool)));
- disconnect(oldTab->view(), SIGNAL(urlChanged(const QUrl &)), urlBar(), SLOT(setUrl(const QUrl &)));
-
+ {
// disconnecting webpage from mainview
disconnect(oldTab->page(), SIGNAL(statusBarMessage(const QString&)),
this, SIGNAL(showStatusBarMessage(const QString&)));
@@ -286,36 +273,40 @@ void MainView::currentChanged(int index)
this, SIGNAL(linkHovered(const QString&)));
}
- // connecting webview with urlbar
- connect(tab->view(), SIGNAL(loadProgress(int)), urlBar(), SLOT(updateProgress(int)));
- connect(tab->view(), SIGNAL(loadFinished(bool)), urlBar(), SLOT(loadFinished(bool)));
- connect(tab->view(), SIGNAL(urlChanged(const QUrl &)), urlBar(), SLOT(setUrl(const QUrl &)));
-
- connect(tab->view()->page(), SIGNAL(statusBarMessage(const QString&)),
+ connect(tab->page(), SIGNAL(statusBarMessage(const QString&)),
this, SIGNAL(showStatusBarMessage(const QString&)));
- connect(tab->view()->page(), SIGNAL(linkHovered(const QString&, const QString&, const QString&)),
+ connect(tab->page(), SIGNAL(linkHovered(const QString&, const QString&, const QString&)),
this, SIGNAL(linkHovered(const QString&)));
- emit setCurrentTitle(tab->view()->title());
- urlBar()->setUrl(tab->view()->url());
- urlBar()->setProgress(tab->progress());
- emit showStatusBarMessage(tab->lastStatusBarText());
+ emit currentTitle(tab->view()->title());
+ _bars->setCurrentIndex(index);
+
+ // clean up "status bar"
+ emit showStatusBarMessage(QString());
// notify UI to eventually switch stop/reload button
- if(urlBar()->isLoading())
- emit browserTabLoading(true);
- else
+ int progr = tab->progress();
+ if (progr == 0)
emit browserTabLoading(false);
+ else
+ emit browserTabLoading(true);
+
+ // update zoom slider
+ if (!Application::instance()->mainWindowList().isEmpty())
+ Application::instance()->mainWindow()->setZoomSliderFactor(tab->view()->zoomFactor());
// set focus to the current webview
- tab->setFocus();
+ if (tab->url().scheme() == QL1S("about"))
+ _bars->currentWidget()->setFocus();
+ else
+ tab->view()->setFocus();
}
WebTab *MainView::webTab(int index) const
{
- WebTab *tab = qobject_cast<WebTab *>( this->widget(index) );
- if(tab)
+ WebTab *tab = qobject_cast<WebTab *>(this->widget(index));
+ if (tab)
{
return tab;
}
@@ -328,6 +319,7 @@ WebTab *MainView::webTab(int index) const
WebTab *MainView::newWebTab(bool focused, bool nearParent)
{
WebTab* tab = new WebTab(this);
+ UrlBar *bar = new UrlBar(tab);
// connecting webview with mainview
connect(tab->view(), SIGNAL(loadStarted()), this, SLOT(webViewLoadStarted()));
@@ -339,21 +331,26 @@ WebTab *MainView::newWebTab(bool focused, bool nearParent)
// connecting webPage signals with mainview
connect(tab->view()->page(), SIGNAL(windowCloseRequested()), this, SLOT(windowCloseRequested()));
connect(tab->view()->page(), SIGNAL(printRequested(QWebFrame *)), this, SIGNAL(printRequested(QWebFrame *)));
-
+
if (nearParent)
+ {
insertTab(currentIndex() + 1, tab, i18n("(Untitled)"));
+ _bars->insertWidget(currentIndex() + 1, bar);
+ }
else
+ {
addTab(tab, i18n("(Untitled)"));
-
+ _bars->addWidget(bar);
+ }
updateTabBar();
-
+
if (focused)
{
setCurrentWidget(tab);
}
emit tabsChanged();
-
+
return tab;
}
@@ -362,21 +359,21 @@ void MainView::newTab()
{
WebView *w = newWebTab()->view();
- switch(ReKonfig::newTabsBehaviour())
+ switch (ReKonfig::newTabsBehaviour())
{
case 0: // new tab page
- w->load( KUrl("about:home") );
+ w->load(KUrl("about:home"));
break;
case 1: // blank page
- urlBar()->setUrl(KUrl(""));
+ urlBar()->clear();
break;
case 2: // homepage
- w->load( KUrl(ReKonfig::homePage()) );
+ w->load(KUrl(ReKonfig::homePage()));
break;
default:
break;
}
- urlBar()->setFocus();
+ _bars->currentWidget()->setFocus();
}
@@ -391,9 +388,9 @@ void MainView::reloadAllTabs()
void MainView::windowCloseRequested()
{
- WebPage *page = qobject_cast<WebPage *>( sender() );
- WebView *view = qobject_cast<WebView *>( page->view() );
- int index = indexOf( view->parentWidget() );
+ WebPage *page = qobject_cast<WebPage *>(sender());
+ WebView *view = qobject_cast<WebView *>(page->view());
+ int index = indexOf(view->parentWidget());
if (index >= 0)
{
@@ -437,10 +434,10 @@ void MainView::cloneTab(int index)
index = currentIndex();
if (index < 0 || index >= count())
return;
-
+
WebTab *tab = newWebTab();
KUrl url = webTab(index)->url();
-
+
// workaround against bug in webkit:
// only set url if it is not empty
// otherwise the current working directory will be used
@@ -452,26 +449,25 @@ void MainView::cloneTab(int index)
// When index is -1 index chooses the current tab
-void MainView::closeTab(int index)
+void MainView::closeTab(int index, bool del)
{
// open default homePage if just one tab is opened
if (count() == 1)
{
WebView *w = currentWebTab()->view();
- urlBar()->setUrl(KUrl(""));
- switch(ReKonfig::newTabsBehaviour())
+ switch (ReKonfig::newTabsBehaviour())
{
case 0: // new tab page
case 1: // blank page
- w->load( KUrl("about:home") );
+ w->load(KUrl("about:home"));
+ urlBar()->setFocus();
break;
case 2: // homepage
- w->load( KUrl(ReKonfig::homePage()) );
+ w->load(KUrl(ReKonfig::homePage()));
break;
default:
break;
}
- urlBar()->setFocus();
return;
}
@@ -480,50 +476,51 @@ void MainView::closeTab(int index)
if (index < 0 || index >= count())
return;
- bool hasFocus = false;
WebTab *tab = webTab(index);
- if (tab)
+ if (!tab)
+ return;
+
+ if (tab->view()->isModified())
{
- if (tab->view()->isModified())
- {
- int risp = KMessageBox::questionYesNo(this,
- i18n("This tab contains changes that have not been submitted.\n"
- "Closing the tab will discard these changes.\n"
- "Do you really want to close this tab?\n"),
- i18n("Closing Modified Tab"));
- if (risp == KMessageBox::No)
- return;
- }
- hasFocus = tab->hasFocus();
+ int risp = KMessageBox::warningContinueCancel(this,
+ i18n("This tab contains changes that have not been submitted.\n"
+ "Closing the tab will discard these changes.\n"
+ "Do you really want to close this tab?\n"),
+ i18n("Closing Modified Tab"), KGuiItem(i18n("Close &Tab"), "tab-close"), KStandardGuiItem::cancel());
+ if (risp != KMessageBox::Continue)
+ return;
+ }
- //store close tab except homepage
- if (!tab->url().prettyUrl().startsWith( QLatin1String("about:") ) && !tab->url().isEmpty())
- {
- QString title = tab->view()->title();
- QString url = tab->url().prettyUrl();
- HistoryItem item(url, QDateTime::currentDateTime(), title);
- m_recentlyClosedTabs.removeAll(item);
- m_recentlyClosedTabs.prepend(item);
- }
+ // store close tab except homepage
+ if (!tab->url().prettyUrl().startsWith(QL1S("about:")) && !tab->url().isEmpty())
+ {
+ QString title = tab->view()->title();
+ QString url = tab->url().prettyUrl();
+ HistoryItem item(url, QDateTime::currentDateTime(), title);
+ m_recentlyClosedTabs.removeAll(item);
+ m_recentlyClosedTabs.prepend(item);
+ }
- removeTab(index);
- updateTabBar(); // UI operation: do it ASAP!!
- tab->deleteLater(); // webView is scheduled for deletion.
-
- emit tabsChanged();
+ removeTab(index);
+ updateTabBar(); // UI operation: do it ASAP!!
- if (hasFocus && count() > 0)
- {
- currentWebTab()->setFocus();
- }
+ QWidget *urlbar = _bars->widget(index);
+ _bars->removeWidget(urlbar);
+
+ if (del)
+ {
+ tab->deleteLater(); // tab is scheduled for deletion.
+ urlbar->deleteLater();
}
+
+ emit tabsChanged();
}
void MainView::webViewLoadStarted()
{
- WebView *view = qobject_cast<WebView *>( sender() );
- int index = indexOf( view->parentWidget() );
+ WebView *view = qobject_cast<WebView *>(sender());
+ int index = indexOf(view->parentWidget());
if (-1 != index)
{
QLabel *label = animatedLoading(index, true);
@@ -533,21 +530,20 @@ void MainView::webViewLoadStarted()
}
}
- emit browserTabLoading(true);
-
if (index != currentIndex())
return;
+ emit browserTabLoading(true);
emit showStatusBarMessage(i18n("Loading..."));
}
void MainView::webViewLoadFinished(bool ok)
{
- WebView *view = qobject_cast<WebView *>( sender() );
+ WebView *view = qobject_cast<WebView *>(sender());
int index = -1;
- if(view)
- index = indexOf( view->parentWidget() );
+ if (view)
+ index = indexOf(view->parentWidget());
if (-1 != index)
{
@@ -565,28 +561,26 @@ void MainView::webViewLoadFinished(bool ok)
{
return;
}
-
+
if (ok)
emit showStatusBarMessage(i18n("Done"), Rekonq::Success);
- else
- emit showStatusBarMessage(i18n("Failed to load"), Rekonq::Error);
+// else
+// emit showStatusBarMessage(i18n("Failed to load"), Rekonq::Error);
}
void MainView::webViewIconChanged()
{
- WebView *view = qobject_cast<WebView *>( sender() );
- int index = indexOf( view->parentWidget() );
+ WebView *view = qobject_cast<WebView *>(sender());
+ int index = indexOf(view->parentWidget());
if (-1 != index)
{
- QIcon icon = Application::icon(view->url());
+ KIcon icon = Application::icon(view->url());
QLabel *label = animatedLoading(index, false);
QMovie *movie = label->movie();
delete movie;
label->setMovie(0);
label->setPixmap(icon.pixmap(16, 16));
-
- urlBar()->updateUrl();
}
}
@@ -598,15 +592,15 @@ void MainView::webViewTitleChanged(const QString &title)
{
tabTitle = i18n("(Untitled)");
}
- WebView *view = qobject_cast<WebView *>( sender() );
- int index = indexOf( view->parentWidget() );
+ WebView *view = qobject_cast<WebView *>(sender());
+ int index = indexOf(view->parentWidget());
if (-1 != index)
{
setTabText(index, tabTitle);
}
if (currentIndex() == index)
{
- emit setCurrentTitle(tabTitle);
+ emit currentTitle(tabTitle);
}
Application::historyManager()->updateHistoryEntry(view->url(), tabTitle);
}
@@ -614,11 +608,11 @@ void MainView::webViewTitleChanged(const QString &title)
void MainView::webViewUrlChanged(const QUrl &url)
{
- WebView *view = qobject_cast<WebView *>( sender() );
- int index = indexOf( view->parentWidget() );
+ WebView *view = qobject_cast<WebView *>(sender());
+ int index = indexOf(view->parentWidget());
if (-1 != index)
{
- m_tabBar->setTabData(index, url);
+ tabBar()->setTabData(index, url);
}
emit tabsChanged();
}
@@ -647,7 +641,7 @@ QLabel *MainView::animatedLoading(int index, bool addMovie)
if (index == -1)
return 0;
- QLabel *label = qobject_cast<QLabel*>(m_tabBar->tabButton(index, QTabBar::LeftSide));
+ QLabel *label = qobject_cast<QLabel* >(tabBar()->tabButton(index, QTabBar::LeftSide));
if (!label)
{
label = new QLabel(this);
@@ -659,8 +653,8 @@ QLabel *MainView::animatedLoading(int index, bool addMovie)
label->setMovie(movie);
movie->start();
}
- m_tabBar->setTabButton(index, QTabBar::LeftSide, 0);
- m_tabBar->setTabButton(index, QTabBar::LeftSide, label);
+ tabBar()->setTabButton(index, QTabBar::LeftSide, 0);
+ tabBar()->setTabButton(index, QTabBar::LeftSide, label);
return label;
}
@@ -685,8 +679,32 @@ void MainView::detachTab(int index)
if (index < 0 || index >= count())
return;
- KUrl url = webTab(index)->view()->url();
- closeTab(index);
-
- Application::instance()->loadUrl(url, Rekonq::NewWindow);
+ WebTab *tab = webTab(index);
+ KUrl u = tab->url();
+ kDebug() << u;
+ if (u.scheme() == QL1S("about"))
+ {
+ closeTab(index);
+ Application::instance()->loadUrl(u, Rekonq::NewWindow);
+ }
+ else
+ {
+ QString label = tab->view()->title();
+ QWidget *bar = _bars->widget(index);
+ closeTab(index, false);
+
+ MainWindow *w = Application::instance()->newMainWindow(false);
+ w->mainView()->addTab(tab, Application::icon(u), label);
+ QStackedWidget *stack = qobject_cast<QStackedWidget *>(w->mainView()->urlBarWidget());
+ stack->insertWidget(0, bar);
+ w->mainView()->updateTabBar();
+ }
+}
+
+
+void MainView::movedTab(int from, int to)
+{
+ QWidget *bar = _bars->widget(from);
+ _bars->removeWidget(bar);
+ _bars->insertWidget(to, bar);
}