summaryrefslogtreecommitdiff
path: root/src/mainview.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mainview.cpp')
-rw-r--r--src/mainview.cpp178
1 files changed, 52 insertions, 126 deletions
diff --git a/src/mainview.cpp b/src/mainview.cpp
index b8d063b8..9dfa797d 100644
--- a/src/mainview.cpp
+++ b/src/mainview.cpp
@@ -38,7 +38,6 @@
#include "application.h"
#include "mainwindow.h"
#include "history.h"
-#include "stackedurlbar.h"
#include "urlbar.h"
#include "webview.h"
@@ -65,9 +64,10 @@
MainView::MainView(QWidget *parent)
: KTabWidget(parent)
- , m_urlBars(new StackedUrlBar(this))
+ , m_urlBar(new UrlBar(this))
, m_tabBar(new TabBar(this))
, m_addTabButton(new QToolButton(this))
+ , m_currentTabIndex(0)
{
// setting tabbar
setTabBar(m_tabBar);
@@ -77,15 +77,20 @@ MainView::MainView(QWidget *parent)
// connecting tabbar signals
connect(m_tabBar, SIGNAL(closeTab(int)), this, SLOT(slotCloseTab(int)));
+ connect(m_tabBar, SIGNAL(mouseMiddleClick(int)), this, SIGNAL(slotCloseTab(int)));
+
connect(m_tabBar, SIGNAL(cloneTab(int)), this, SLOT(slotCloneTab(int)));
connect(m_tabBar, SIGNAL(closeOtherTabs(int)), this, SLOT(slotCloseOtherTabs(int)));
connect(m_tabBar, SIGNAL(reloadTab(int)), this, SLOT(slotReloadTab(int)));
connect(m_tabBar, SIGNAL(reloadAllTabs()), this, SLOT(slotReloadAllTabs()));
connect(m_tabBar, SIGNAL(tabMoved(int, int)), this, SLOT(moveTab(int, int)));
+ // connecting urlbar signals
+ connect(urlBar(), SIGNAL(activated(const KUrl&)), Application::instance(), SLOT(loadUrl(const KUrl&)));
+
// current page index changing
connect(this, SIGNAL(currentChanged(int)), this, SLOT(slotCurrentChanged(int)));
-
+
setTabsClosable(true);
connect(m_tabBar, SIGNAL(tabCloseRequested(int)), this, SLOT(slotCloseTab(int)));
@@ -140,25 +145,21 @@ void MainView::addTabButtonPosition()
}
-UrlBar *MainView::currentUrlBar() const
-{
- return urlBar(-1);
-}
-
-
TabBar *MainView::tabBar() const
{
return m_tabBar;
}
+
QToolButton *MainView::addTabButton() const
{
return m_addTabButton;
}
-StackedUrlBar *MainView::urlBarStack() const
+
+UrlBar *MainView::urlBar() const
{
- return m_urlBars;
+ return m_urlBar;
}
@@ -218,71 +219,11 @@ void MainView::slotWebStop()
}
-void MainView::slotWebBack()
-{
- WebView *webView = currentWebView();
- QAction *action = webView->page()->action(QWebPage::Back);
- action->trigger();
-}
-
-
-void MainView::slotWebForward()
-{
- WebView *webView = currentWebView();
- QAction *action = webView->page()->action(QWebPage::Forward);
- action->trigger();
-}
-
-
-void MainView::slotWebUndo()
-{
- WebView *webView = currentWebView();
- QAction *action = webView->page()->action(QWebPage::Undo);
- action->trigger();
-}
-
-
-void MainView::slotWebRedo()
-{
- WebView *webView = currentWebView();
- QAction *action = webView->page()->action(QWebPage::Redo);
- action->trigger();
-}
-
-
-void MainView::slotWebCut()
-{
- WebView *webView = currentWebView();
- QAction *action = webView->page()->action(QWebPage::Cut);
- action->trigger();
-}
-
-
-void MainView::slotWebCopy()
-{
- WebView *webView = currentWebView();
- QAction *action = webView->page()->action(QWebPage::Copy);
- action->trigger();
-}
-
-
-void MainView::slotWebPaste()
-{
- WebView *webView = currentWebView();
- QAction *action = webView->page()->action(QWebPage::Paste);
- action->trigger();
-}
-
-
void MainView::clear()
{
- // clear the line edit history
- for (int i = 0; i < m_urlBars->count(); ++i)
- {
- /// TODO What exactly do we need to clear here?
- urlBar(i)->clearHistory();
- urlBar(i)->clear();
- }
+ /// TODO What exactly do we need to clear here?
+ m_urlBar->clearHistory();
+ m_urlBar->clear();
}
@@ -300,35 +241,48 @@ void MainView::slotReloadTab(int index)
}
+// TODO need some extra comments to better understand what happens here..
void MainView::slotCurrentChanged(int index)
{
WebView *webView = this->webView(index);
if (!webView)
return;
- Q_ASSERT(m_urlBars->count() == count());
+ WebView *oldWebView = this->webView(m_currentTabIndex);
+ m_currentTabIndex=index;
- WebView *oldWebView = this->webView(m_urlBars->currentIndex());
if (oldWebView)
- {
+ {
+ // disconnecting webview with urlbar
+ disconnect(oldWebView, SIGNAL(loadProgress(int)), urlBar(), SLOT(slotUpdateProgress(int)));
+ disconnect(oldWebView, SIGNAL(loadFinished(bool)), urlBar(), SLOT(slotLoadFinished(bool)));
+ disconnect(oldWebView, SIGNAL(urlChanged(const QUrl &)), urlBar(), SLOT(setUrl(const QUrl &)));
+ disconnect(oldWebView, SIGNAL(iconChanged()), urlBar(), SLOT(slotUpdateUrl()));
+
disconnect(oldWebView->page(), SIGNAL(statusBarMessage(const QString&)),
this, SIGNAL(showStatusBarMessage(const QString&)));
disconnect(oldWebView->page(), SIGNAL(linkHovered(const QString&, const QString&, const QString&)),
this, SIGNAL(linkHovered(const QString&)));
}
+ // connecting webview with urlbar
+ connect(webView, SIGNAL(loadProgress(int)), urlBar(), SLOT(slotUpdateProgress(int)));
+ connect(webView, SIGNAL(loadFinished(bool)), urlBar(), SLOT(slotLoadFinished(bool)));
+ connect(webView, SIGNAL(urlChanged(const QUrl &)), urlBar(), SLOT(setUrl(const QUrl &)));
+ connect(webView, SIGNAL(iconChanged()), urlBar(), SLOT(slotUpdateUrl()));
+
connect(webView->page(), SIGNAL(statusBarMessage(const QString&)),
this, SIGNAL(showStatusBarMessage(const QString&)));
connect(webView->page(), SIGNAL(linkHovered(const QString&, const QString&, const QString&)),
this, SIGNAL(linkHovered(const QString&)));
emit setCurrentTitle(webView->title());
- m_urlBars->setCurrentIndex(index);
- currentUrlBar()->setUrl(webView->url());
+ urlBar()->setUrl(webView->url());
+ urlBar()->setProgress(webView->progress());
emit showStatusBarMessage(webView->lastStatusBarText());
// notify UI to eventually switch stop/reload button
- if(currentUrlBar()->isLoading())
+ if(urlBar()->isLoading())
emit browserTabLoading(true);
else
emit browserTabLoading(false);
@@ -338,22 +292,6 @@ void MainView::slotCurrentChanged(int index)
}
-UrlBar *MainView::urlBar(int index) const
-{
- if (index == -1)
- {
- index = m_urlBars->currentIndex();
- }
- UrlBar *urlBar = m_urlBars->urlBar(index);
- if (urlBar)
- {
- return urlBar;
- }
- kWarning() << "URL bar with index" << index << "not found. Returning NULL. (line:" << __LINE__ << ")";
- return NULL;
-}
-
-
WebView *MainView::webView(int index) const
{
QWidget *widget = this->widget(index);
@@ -367,21 +305,10 @@ WebView *MainView::webView(int index) const
}
-WebView *MainView::newTab(bool focused)
+WebView *MainView::newWebView(bool focused)
{
- // line edit
- UrlBar *urlBar = new UrlBar; // Ownership of widget is passed on to the QStackedWidget (addWidget method).
- connect(urlBar, SIGNAL(activated(const KUrl&)), Application::instance(), SLOT(loadUrl(const KUrl&)));
- m_urlBars->addUrlBar(urlBar);
-
WebView *webView = new WebView; // should be deleted on tab close?
- // connecting webview with urlbar
- connect(webView, SIGNAL(loadProgress(int)), urlBar, SLOT(slotUpdateProgress(int)));
- connect(webView, SIGNAL(loadFinished(bool)), urlBar, SLOT(slotLoadFinished(bool)));
- connect(webView, SIGNAL(urlChanged(const QUrl &)), urlBar, SLOT(setUrl(const QUrl &)));
- connect(webView, SIGNAL(iconChanged()), urlBar, SLOT(slotUpdateUrl()));
-
// connecting webview with mainview
connect(webView, SIGNAL(loadStarted()), this, SLOT(webViewLoadStarted()));
connect(webView, SIGNAL(loadFinished(bool)), this, SLOT(webViewLoadFinished(bool)));
@@ -397,23 +324,35 @@ WebView *MainView::newTab(bool focused)
connect(webView->page(), SIGNAL(printRequested(QWebFrame *)), this, SIGNAL(printRequested(QWebFrame *)));
addTab(webView, i18n("(Untitled)"));
-
+
if (focused)
{
setCurrentWidget(webView);
}
-
- urlBar->setFocus();
emit tabsChanged();
showTabBar();
addTabButtonPosition();
-
+
return webView;
}
+void MainView::newTab()
+{
+ WebView *w = newWebView();
+
+ urlBar()->setUrl(KUrl(""));
+ urlBar()->setFocus();
+
+ if (ReKonfig::newTabsOpenHomePage())
+ {
+ w->load(QUrl(ReKonfig::homePage()));
+ }
+}
+
+
void MainView::slotReloadAllTabs()
{
for (int i = 0; i < count(); ++i)
@@ -429,7 +368,6 @@ void MainView::slotReloadAllTabs()
void MainView::windowCloseRequested()
{
-
WebPage *webPage = qobject_cast<WebPage*>(sender());
WebView *webView = qobject_cast<WebView*>(webPage->view());
int index = webViewIndex(webView);
@@ -479,7 +417,7 @@ void MainView::slotCloneTab(int index)
index = currentIndex();
if (index < 0 || index >= count())
return;
- WebView *tab = newTab();
+ WebView *tab = newWebView();
tab->setUrl(webView(index)->url());
showTabBar();
@@ -514,10 +452,6 @@ void MainView::slotCloseTab(int index)
hasFocus = tab->hasFocus();
}
- QWidget *urlBar = m_urlBars->urlBar(index);
- m_urlBars->removeWidget(urlBar);
- urlBar->deleteLater(); // urlBar is scheduled for deletion.
-
QWidget *webView = widget(index);
removeTab(index);
webView->deleteLater(); // webView is scheduled for deletion.
@@ -652,14 +586,6 @@ void MainView::previousTab()
}
-void MainView::moveTab(int fromIndex, int toIndex)
-{
- QWidget *lineEdit = m_urlBars->widget(fromIndex);
- m_urlBars->removeWidget(lineEdit);
- m_urlBars->insertWidget(toIndex, lineEdit);
-}
-
-
QLabel *MainView::animatedLoading(int index, bool addMovie)
{
if (index == -1)