diff options
-rw-r--r-- | src/CMakeLists.txt | 4 | ||||
-rw-r--r-- | src/browserapplication.cpp | 2 | ||||
-rw-r--r-- | src/findbar.cpp | 6 | ||||
-rw-r--r-- | src/findbar.h | 2 | ||||
-rw-r--r-- | src/mainview.cpp (renamed from src/tabwidget.cpp) | 357 | ||||
-rw-r--r-- | src/mainview.h (renamed from src/tabwidget.h) | 86 | ||||
-rw-r--r-- | src/mainwindow.cpp | 6 | ||||
-rw-r--r-- | src/mainwindow.h | 6 | ||||
-rw-r--r-- | src/tabbar.cpp | 207 | ||||
-rw-r--r-- | src/tabbar.h | 74 | ||||
-rw-r--r-- | src/webview.cpp | 2 |
11 files changed, 419 insertions, 333 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 938c98cd..83297551 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,7 +2,8 @@ SET( rekonq_SRCS autosaver.cpp browserapplication.cpp mainwindow.cpp -# rekonqview.cpp + mainview.cpp + tabbar.cpp cookiejar.cpp downloadmanager.cpp edittableview.cpp @@ -16,7 +17,6 @@ SET( rekonq_SRCS searchbar.cpp settings.cpp squeezelabel.cpp - tabwidget.cpp webview.cpp main.cpp ) diff --git a/src/browserapplication.cpp b/src/browserapplication.cpp index 696b2cd8..bc29d64e 100644 --- a/src/browserapplication.cpp +++ b/src/browserapplication.cpp @@ -27,7 +27,7 @@ #include "downloadmanager.h" #include "history.h" #include "networkaccessmanager.h" -#include "tabwidget.h" +#include "mainview.h" #include "webview.h" // KDE Includes diff --git a/src/findbar.cpp b/src/findbar.cpp index 6df09de1..a1c867c2 100644 --- a/src/findbar.cpp +++ b/src/findbar.cpp @@ -17,9 +17,11 @@ * * ============================================================ */ +// Self Includes #include "findbar.h" -#include "moc_findbar.cpp" +#include "findbar.moc" +// KDE Includes #include <KLineEdit> #include <KAction> #include <KIcon> @@ -27,8 +29,10 @@ #include <KDialog> #include <KPushButton> +// Qt Includes #include <QtGui> + FindBar::FindBar(KXmlGuiWindow *parent) : KToolBar( "Find Bar" , parent, Qt::BottomToolBarArea, true, false, false) , m_lineEdit(0) diff --git a/src/findbar.h b/src/findbar.h index 4c73767c..d70a9de1 100644 --- a/src/findbar.h +++ b/src/findbar.h @@ -20,9 +20,9 @@ #ifndef FINDBAR_H #define FINDBAR_H +// KDE Includes #include <KLineEdit> #include <KToolBar> - #include <KXmlGuiWindow> class FindBar : public KToolBar diff --git a/src/tabwidget.cpp b/src/mainview.cpp index 4af3ef60..79cb865d 100644 --- a/src/tabwidget.cpp +++ b/src/mainview.cpp @@ -20,8 +20,9 @@ // Local Includes -#include "tabwidget.h" +#include "mainview.h" +#include "tabbar.h" #include "browserapplication.h" #include "mainwindow.h" #include "history.h" @@ -38,174 +39,105 @@ #include <QDebug> -TabBar::TabBar(QWidget *parent) - : KTabBar(parent) -{ - setElideMode(Qt::ElideRight); - setContextMenuPolicy(Qt::CustomContextMenu); - setAcceptDrops(true); - connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(contextMenuRequested(const QPoint &))); - - QString alt = QLatin1String("Alt+%1"); - for (int i = 1; i <= 10; ++i) - { - int key = i; - if (key == 10) - key = 0; - QShortcut *shortCut = new QShortcut(alt.arg(key), this); - m_tabShortcuts.append(shortCut); - connect(shortCut, SIGNAL(activated()), this, SLOT(selectTabAction())); - } -} -TabBar::~TabBar() -{ -} - - -void TabBar::selectTabAction() -{ - if (QShortcut *shortCut = qobject_cast<QShortcut*>(sender())) - { - int index = m_tabShortcuts.indexOf(shortCut); - if (index == 0) - index = 10; - setCurrentIndex(index); - } -} - - -void TabBar::contextMenuRequested(const QPoint &position) +WebActionMapper::WebActionMapper(KAction *root, QWebPage::WebAction webAction, QObject *parent) + : QObject(parent) + , m_currentParent(0) + , m_root(root) + , m_webAction(webAction) { - KMenu menu; - menu.addAction(i18n("New &Tab"), this, SIGNAL( newTab() ), QKeySequence::AddTab); - int index = tabAt(position); - if (-1 != index) - { - KAction *action = (KAction * ) menu.addAction(i18n("Clone Tab"), this, SLOT(cloneTab())); - action->setData(index); - - menu.addSeparator(); - - action = (KAction * ) menu.addAction(i18n("&Close Tab"), this, SLOT(closeTab()), QKeySequence::Close); - action->setData(index); - - action = (KAction * ) menu.addAction(i18n("Close &Other Tabs"), this, SLOT(closeOtherTabs())); - action->setData(index); - - menu.addSeparator(); - - action = (KAction * ) menu.addAction(i18n("Reload Tab"), this, SLOT(reloadTab()), QKeySequence::Refresh); - action->setData(index); - } - else + if ( !m_root ) { - menu.addSeparator(); + return; } - menu.addAction(i18n("Reload All Tabs"), this, SIGNAL(reloadAllTabs())); - menu.exec(QCursor::pos()); + connect(m_root, SIGNAL( triggered() ), this, SLOT( rootTriggered() ) ); + connect(root, SIGNAL( destroyed(QObject *) ), this, SLOT( rootDestroyed() ) ); + + root->setEnabled(false); } -void TabBar::cloneTab() +void WebActionMapper::rootDestroyed() { - if (KAction *action = qobject_cast<KAction*>(sender())) - { - int index = action->data().toInt(); - emit cloneTab(index); - } + m_root = 0; } -void TabBar::closeTab() +void WebActionMapper::currentDestroyed() { - if (KAction *action = qobject_cast<KAction*>(sender())) - { - int index = action->data().toInt(); - emit closeTab(index); - } + updateCurrent(0); } -void TabBar::closeOtherTabs() +void WebActionMapper::addChild(KAction *action) { - if (KAction *action = qobject_cast<KAction*>(sender())) + if ( !action ) { - int index = action->data().toInt(); - emit closeOtherTabs(index); + return; } + connect(action, SIGNAL( changed() ), this, SLOT( childChanged() ) ); } - -void TabBar::mousePressEvent(QMouseEvent *event) +QWebPage::WebAction WebActionMapper::webAction() const { - if (event->button() == Qt::LeftButton) - m_dragStartPos = event->pos(); - QTabBar::mousePressEvent(event); + return m_webAction; } -void TabBar::mouseMoveEvent(QMouseEvent *event) +void WebActionMapper::rootTriggered() { - if (event->buttons() == Qt::LeftButton && (event->pos() - m_dragStartPos).manhattanLength() > QApplication::startDragDistance()) + if (m_currentParent) { - QDrag *drag = new QDrag(this); - QMimeData *mimeData = new QMimeData; - QList<QUrl> urls; - int index = tabAt(event->pos()); - QUrl url = tabData(index).toUrl(); - urls.append(url); - mimeData->setUrls(urls); - mimeData->setText(tabText(index)); - mimeData->setData(QLatin1String("action"), "tab-reordering"); - drag->setMimeData(mimeData); - drag->exec(); + KAction *gotoAction = new KAction( m_currentParent->action(m_webAction) ); + gotoAction->trigger(); } - QTabBar::mouseMoveEvent(event); } -void TabBar::dragEnterEvent(QDragEnterEvent *event) +void WebActionMapper::childChanged() { - const QMimeData *mimeData = event->mimeData(); - QStringList formats = mimeData->formats(); - - if (formats.contains(QLatin1String("action")) && (mimeData->data(QLatin1String("action")) == "tab-reordering")) + if (KAction *source = qobject_cast<KAction*>(sender())) { - event->acceptProposedAction(); + if (m_root + && m_currentParent + && source->parent() == m_currentParent) + { + m_root->setChecked(source->isChecked()); + m_root->setEnabled(source->isEnabled()); + } } - QTabBar::dragEnterEvent(event); } -void TabBar::dropEvent(QDropEvent *event) +void WebActionMapper::updateCurrent(QWebPage *currentParent) { - int fromIndex = tabAt(m_dragStartPos); - int toIndex = tabAt(event->pos()); - if (fromIndex != toIndex) + if (m_currentParent) + disconnect(m_currentParent, SIGNAL(destroyed(QObject *)), + this, SLOT(currentDestroyed())); + + m_currentParent = currentParent; + if (!m_root) { - emit tabMoveRequested(fromIndex, toIndex); - event->acceptProposedAction(); + return; } - QTabBar::dropEvent(event); -} - - -void TabBar::reloadTab() -{ - if (KAction *action = qobject_cast<KAction*>(sender())) + if (!m_currentParent) { - int index = action->data().toInt(); - emit reloadTab(index); + m_root->setEnabled(false); + m_root->setChecked(false); + return; } + KAction *source = new KAction( m_currentParent->action(m_webAction) ); + m_root->setChecked(source->isChecked()); + m_root->setEnabled(source->isEnabled()); + connect(m_currentParent, SIGNAL( destroyed(QObject *) ), this, SLOT( currentDestroyed() ) ); } -// --------------------------------------------------------------------------------------------------------------------------- +// ---------------------------------------------------------------------------------------------------------- -TabWidget::TabWidget(QWidget *parent) +MainView::MainView(QWidget *parent) : KTabWidget(parent) , m_recentlyClosedTabsAction(0) , m_newTabAction(0) @@ -273,14 +205,14 @@ TabWidget::TabWidget(QWidget *parent) } -TabWidget::~TabWidget() +MainView::~MainView() { delete m_lineEditCompleter; delete m_recentlyClosedTabsMenu; } -void TabWidget::clear() +void MainView::clear() { // clear the recently closed tabs m_recentlyClosedTabs.clear(); @@ -293,7 +225,7 @@ void TabWidget::clear() } -void TabWidget::moveTab(int fromIndex, int toIndex) +void MainView::moveTab(int fromIndex, int toIndex) { disconnect(this, SIGNAL(currentChanged(int)), this, SLOT(currentChanged(int))); @@ -310,7 +242,7 @@ void TabWidget::moveTab(int fromIndex, int toIndex) // When index is -1 index chooses the current tab -void TabWidget::reloadTab(int index) +void MainView::reloadTab(int index) { if (index < 0) index = currentIndex(); @@ -323,15 +255,15 @@ void TabWidget::reloadTab(int index) } -void TabWidget::addWebAction(KAction *action, QWebPage::WebAction webAction) +void MainView::addWebAction(KAction *action, QWebPage::WebAction webAction) { if (!action) return; - m_actions.append(new WebActionMapper(action, webAction, this)); + m_webActionList.append(new WebActionMapper(action, webAction, this)); } -void TabWidget::currentChanged(int index) +void MainView::currentChanged(int index) { WebView *webView = this->webView(index); if (!webView) @@ -351,9 +283,9 @@ void TabWidget::currentChanged(int index) connect(webView->page(), SIGNAL(linkHovered(const QString&, const QString&, const QString&)), this, SIGNAL(linkHovered(const QString&))); connect(webView, SIGNAL(loadProgress(int)), this, SIGNAL(loadProgress(int))); - for (int i = 0; i < m_actions.count(); ++i) + for (int i = 0; i < m_webActionList.count(); ++i) { - WebActionMapper *mapper = m_actions[i]; + WebActionMapper *mapper = m_webActionList[i]; mapper->updateCurrent(webView->page()); } emit setCurrentTitle(webView->title()); @@ -366,55 +298,55 @@ void TabWidget::currentChanged(int index) } -KAction *TabWidget::newTabAction() const +KAction *MainView::newTabAction() const { return m_newTabAction; } -KAction *TabWidget::closeTabAction() const +KAction *MainView::closeTabAction() const { return m_closeTabAction; } -KAction *TabWidget::recentlyClosedTabsAction() const +KAction *MainView::recentlyClosedTabsAction() const { return m_recentlyClosedTabsAction; } -KAction *TabWidget::nextTabAction() const +KAction *MainView::nextTabAction() const { return m_nextTabAction; } -KAction *TabWidget::previousTabAction() const +KAction *MainView::previousTabAction() const { return m_previousTabAction; } -QWidget *TabWidget::lineEditStack() const +QWidget *MainView::lineEditStack() const { return m_lineEdits; } -QLineEdit *TabWidget::currentLineEdit() const +QLineEdit *MainView::currentLineEdit() const { return lineEdit(m_lineEdits->currentIndex()); } -WebView *TabWidget::currentWebView() const +WebView *MainView::currentWebView() const { return webView(currentIndex()); } -QLineEdit *TabWidget::lineEdit(int index) const +QLineEdit *MainView::lineEdit(int index) const { UrlBar *urlLineEdit = qobject_cast<UrlBar*>(m_lineEdits->widget(index)); if (urlLineEdit) @@ -423,7 +355,7 @@ QLineEdit *TabWidget::lineEdit(int index) const } -WebView *TabWidget::webView(int index) const +WebView *MainView::webView(int index) const { QWidget *widget = this->widget(index); if (WebView *webView = qobject_cast<WebView*>(widget)) @@ -435,7 +367,7 @@ WebView *TabWidget::webView(int index) const // optimization to delay creating the first webview if (count() == 1) { - TabWidget *that = const_cast<TabWidget*>(this); + MainView *that = const_cast<MainView*>(this); that->setUpdatesEnabled(false); that->newTab(); that->closeTab(0); @@ -447,14 +379,14 @@ WebView *TabWidget::webView(int index) const } -int TabWidget::webViewIndex(WebView *webView) const +int MainView::webViewIndex(WebView *webView) const { int index = indexOf(webView); return index; } -WebView *TabWidget::newTab(bool makeCurrent) +WebView *MainView::newTab(bool makeCurrent) { // line edit UrlBar *urlLineEdit = new UrlBar; @@ -468,7 +400,9 @@ WebView *TabWidget::newTab(bool makeCurrent) QAbstractItemView *popup = m_lineEditCompleter->popup(); QListView *listView = qobject_cast<QListView*>(popup); if (listView) + { listView->setUniformItemSizes(true); + } } lineEdit->setCompleter(m_lineEditCompleter); connect(lineEdit, SIGNAL(returnPressed()), this, SLOT(lineEditReturnPressed())); @@ -513,9 +447,9 @@ WebView *TabWidget::newTab(bool makeCurrent) setCurrentWidget(webView); // webview actions - for (int i = 0; i < m_actions.count(); ++i) + for (int i = 0; i < m_webActionList.count(); ++i) { - WebActionMapper *mapper = m_actions[i]; + WebActionMapper *mapper = m_webActionList[i]; mapper->addChild( new KAction( webView->page()->action( mapper->webAction() ) ) ); } @@ -526,7 +460,7 @@ WebView *TabWidget::newTab(bool makeCurrent) } -void TabWidget::reloadAllTabs() +void MainView::reloadAllTabs() { for (int i = 0; i < count(); ++i) { @@ -539,7 +473,7 @@ void TabWidget::reloadAllTabs() } -void TabWidget::lineEditReturnPressed() +void MainView::lineEditReturnPressed() { if (QLineEdit *lineEdit = qobject_cast<QLineEdit*>(sender())) { @@ -550,7 +484,7 @@ void TabWidget::lineEditReturnPressed() } -void TabWidget::windowCloseRequested() +void MainView::windowCloseRequested() { WebPage *webPage = qobject_cast<WebPage*>(sender()); WebView *webView = qobject_cast<WebView*>(webPage->view()); @@ -565,7 +499,7 @@ void TabWidget::windowCloseRequested() } -void TabWidget::closeOtherTabs(int index) +void MainView::closeOtherTabs(int index) { if (-1 == index) return; @@ -577,7 +511,7 @@ void TabWidget::closeOtherTabs(int index) // When index is -1 index chooses the current tab -void TabWidget::cloneTab(int index) +void MainView::cloneTab(int index) { if (index < 0) index = currentIndex(); @@ -589,7 +523,7 @@ void TabWidget::cloneTab(int index) // When index is -1 index chooses the current tab -void TabWidget::closeTab(int index) +void MainView::closeTab(int index) { if (index < 0) index = currentIndex(); @@ -613,7 +547,7 @@ void TabWidget::closeTab(int index) m_recentlyClosedTabsAction->setEnabled(true); m_recentlyClosedTabs.prepend(tab->url()); - if (m_recentlyClosedTabs.size() >= TabWidget::m_recentlyClosedTabsSize) + if (m_recentlyClosedTabs.size() >= MainView::m_recentlyClosedTabsSize) m_recentlyClosedTabs.removeLast(); } QWidget *lineEdit = m_lineEdits->widget(index); @@ -630,7 +564,7 @@ void TabWidget::closeTab(int index) } -void TabWidget::webViewLoadStarted() +void MainView::webViewLoadStarted() { WebView *webView = qobject_cast<WebView*>(sender()); int index = webViewIndex(webView); @@ -641,7 +575,7 @@ void TabWidget::webViewLoadStarted() } -void TabWidget::webViewIconChanged() +void MainView::webViewIconChanged() { WebView *webView = qobject_cast<WebView*>(sender()); int index = webViewIndex(webView); @@ -653,7 +587,7 @@ void TabWidget::webViewIconChanged() } -void TabWidget::webViewTitleChanged(const QString &title) +void MainView::webViewTitleChanged(const QString &title) { WebView *webView = qobject_cast<WebView*>(sender()); int index = webViewIndex(webView); @@ -666,7 +600,7 @@ void TabWidget::webViewTitleChanged(const QString &title) } -void TabWidget::webViewUrlChanged(const QUrl &url) +void MainView::webViewUrlChanged(const QUrl &url) { WebView *webView = qobject_cast<WebView*>(sender()); int index = webViewIndex(webView); @@ -677,7 +611,7 @@ void TabWidget::webViewUrlChanged(const QUrl &url) } -void TabWidget::aboutToShowRecentTabsMenu() +void MainView::aboutToShowRecentTabsMenu() { m_recentlyClosedTabsMenu->clear(); for (int i = 0; i < m_recentlyClosedTabs.count(); ++i) @@ -692,14 +626,14 @@ void TabWidget::aboutToShowRecentTabsMenu() } -void TabWidget::aboutToShowRecentTriggeredAction(QAction *action) +void MainView::aboutToShowRecentTriggeredAction(QAction *action) { KUrl url = action->data().toUrl(); loadUrlInCurrentTab(url); } -void TabWidget::mouseDoubleClickEvent(QMouseEvent *event) +void MainView::mouseDoubleClickEvent(QMouseEvent *event) { if ( !childAt(event->pos() ) // Remove the line below when QTabWidget does not have a one pixel frame @@ -712,7 +646,7 @@ void TabWidget::mouseDoubleClickEvent(QMouseEvent *event) } -void TabWidget::contextMenuEvent(QContextMenuEvent *event) +void MainView::contextMenuEvent(QContextMenuEvent *event) { if (!childAt(event->pos())) { m_tabBar->contextMenuRequested(event->pos()); @@ -722,7 +656,7 @@ void TabWidget::contextMenuEvent(QContextMenuEvent *event) } -void TabWidget::mouseReleaseEvent(QMouseEvent *event) +void MainView::mouseReleaseEvent(QMouseEvent *event) { if (event->button() == Qt::MidButton && !childAt(event->pos()) // Remove the line below when QTabWidget does not have a one pixel frame @@ -738,7 +672,7 @@ void TabWidget::mouseReleaseEvent(QMouseEvent *event) } -void TabWidget::loadUrlInCurrentTab(const KUrl &url) +void MainView::loadUrlInCurrentTab(const KUrl &url) { WebView *webView = currentWebView(); if (webView) @@ -749,7 +683,7 @@ void TabWidget::loadUrlInCurrentTab(const KUrl &url) } -void TabWidget::nextTab() +void MainView::nextTab() { int next = currentIndex() + 1; if (next == count()) @@ -758,7 +692,7 @@ void TabWidget::nextTab() } -void TabWidget::previousTab() +void MainView::previousTab() { int next = currentIndex() - 1; if (next < 0) @@ -768,96 +702,3 @@ void TabWidget::previousTab() // ---------------------------------------------------------------------------------------------------------------------------- - - -WebActionMapper::WebActionMapper(KAction *root, QWebPage::WebAction webAction, QObject *parent) - : QObject(parent) - , m_currentParent(0) - , m_root(root) - , m_webAction(webAction) -{ - if ( !m_root ) - { - return; - } - connect(m_root, SIGNAL( triggered() ), this, SLOT( rootTriggered() ) ); - connect(root, SIGNAL( destroyed(QObject *) ), this, SLOT( rootDestroyed() ) ); - - root->setEnabled(false); -} - - -void WebActionMapper::rootDestroyed() -{ - m_root = 0; -} - - -void WebActionMapper::currentDestroyed() -{ - updateCurrent(0); -} - - -void WebActionMapper::addChild(KAction *action) -{ - if ( !action ) - { - return; - } - connect(action, SIGNAL( changed() ), this, SLOT( childChanged() ) ); -} - -QWebPage::WebAction WebActionMapper::webAction() const -{ - return m_webAction; -} - - -void WebActionMapper::rootTriggered() -{ - if (m_currentParent) - { - KAction *gotoAction = new KAction( m_currentParent->action(m_webAction) ); - gotoAction->trigger(); - } -} - - -void WebActionMapper::childChanged() -{ - if (KAction *source = qobject_cast<KAction*>(sender())) - { - if (m_root - && m_currentParent - && source->parent() == m_currentParent) - { - m_root->setChecked(source->isChecked()); - m_root->setEnabled(source->isEnabled()); - } - } -} - - -void WebActionMapper::updateCurrent(QWebPage *currentParent) -{ - if (m_currentParent) - disconnect(m_currentParent, SIGNAL(destroyed(QObject *)), - this, SLOT(currentDestroyed())); - - m_currentParent = currentParent; - if (!m_root) - { - return; - } - if (!m_currentParent) - { - m_root->setEnabled(false); - m_root->setChecked(false); - return; - } - KAction *source = new KAction( m_currentParent->action(m_webAction) ); - m_root->setChecked(source->isChecked()); - m_root->setEnabled(source->isEnabled()); - connect(m_currentParent, SIGNAL( destroyed(QObject *) ), this, SLOT( currentDestroyed() ) ); -} diff --git a/src/tabwidget.h b/src/mainview.h index 4edba9b9..3ffeef32 100644 --- a/src/tabwidget.h +++ b/src/mainview.h @@ -23,65 +23,19 @@ #ifndef TABWIDGET_H #define TABWIDGET_H -#include <KTabBar> +// KDE Includes #include <KAction> -#include <QShortcut> -/* - Tab bar with a few more features such as a context menu and shortcuts - */ -class TabBar : public KTabBar -{ - Q_OBJECT - -signals: - void newTab(); - void cloneTab(int index); - void closeTab(int index); - void closeOtherTabs(int index); - void reloadTab(int index); - void reloadAllTabs(); - void tabMoveRequested(int fromIndex, int toIndex); - -public: - TabBar(QWidget *parent = 0); - ~TabBar(); - -protected: - void mousePressEvent(QMouseEvent* event); - void mouseMoveEvent(QMouseEvent* event); - void dragEnterEvent(QDragEnterEvent *event); - void dropEvent(QDropEvent *event); - -private slots: - void selectTabAction(); - void cloneTab(); - void closeTab(); - void closeOtherTabs(); - void reloadTab(); - void contextMenuRequested(const QPoint &position); - -private: - QList<QShortcut*> m_tabShortcuts; - friend class TabWidget; - - QPoint m_dragStartPos; - int m_dragCurrentIndex; -}; - - -// ---------------------------------------------------------------------------------------------------------------------------- - - +// Qt Includes #include <QWebPage> class WebView; -/*! - A proxy object that connects a single browser action - to one child webpage action at a time. - - Example usage: used to keep the main window stop action in sync with - the current tabs webview's stop action. +/** + * A proxy object that connects a single browser action + * to one child webpage action at a time. + * + * Example usage: used to keep the main window stop action in sync with + * the current tabs webview's stop action. */ class WebActionMapper : public QObject { @@ -108,6 +62,9 @@ private: // ---------------------------------------------------------------------------------------------------------------------------- +// Local Includes +#include "tabbar.h" + // KDE Includes #include <KUrl> #include <KMenu> @@ -121,16 +78,22 @@ class QCompleter; class QMenu; class QStackedWidget; QT_END_NAMESPACE -/*! - TabWidget that contains WebViews and a stack widget of associated line edits. - Connects up the current tab's signals to this class's signal and uses WebActionMapper - to proxy the actions. +/** + * TabWidget that contains WebViews and a stack widget of associated line edits. + * + * Connects up the current tab's signals to this class's signal and uses WebActionMapper + * to proxy the actions. */ -class TabWidget : public KTabWidget +class MainView : public KTabWidget { Q_OBJECT +public: + MainView(QWidget *parent = 0); + ~MainView(); + + signals: // tab widget signals void loadPage(const QString &url); @@ -149,9 +112,6 @@ signals: void printRequested(QWebFrame *frame); public: - TabWidget(QWidget *parent = 0); - ~TabWidget(); - void clear(); void addWebAction(KAction *action, QWebPage::WebAction webAction); @@ -207,7 +167,7 @@ private: KMenu *m_recentlyClosedTabsMenu; static const int m_recentlyClosedTabsSize = 10; QList<KUrl> m_recentlyClosedTabs; - QList<WebActionMapper*> m_actions; + QList<WebActionMapper*> m_webActionList; QCompleter *m_lineEditCompleter; QStackedWidget *m_lineEdits; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 9813cf1e..481bac96 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -21,13 +21,13 @@ // Self Includes #include "mainwindow.h" +#include "mainwindow.moc" // Local Includes #include "browserapplication.h" #include "downloadmanager.h" #include "history.h" #include "settings.h" -#include "tabwidget.h" #include "bookmarks.h" #include "webview.h" @@ -57,7 +57,7 @@ MainWindow::MainWindow() : KXmlGuiWindow() - , m_tabWidget( new TabWidget(this) ) + , m_tabWidget( new MainView(this) ) { // accept dnd setAcceptDrops(true); @@ -587,7 +587,7 @@ void MainWindow::loadPage(const QString &page) } -TabWidget *MainWindow::tabWidget() const +MainView *MainWindow::tabWidget() const { return m_tabWidget; } diff --git a/src/mainwindow.h b/src/mainwindow.h index aa8e3d65..8a13d7f9 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -25,6 +25,7 @@ // Local Includes #include "findbar.h" #include "searchbar.h" +#include "mainview.h" // KDE Includes #include <KUrl> @@ -37,7 +38,6 @@ class QWebFrame; -class TabWidget; class WebView; /** @@ -53,7 +53,7 @@ public: ~MainWindow(); static KUrl guessUrlFromString(const QString &url); - TabWidget *tabWidget() const; + MainView *tabWidget() const; WebView *currentTab() const; private: @@ -118,7 +118,7 @@ private: QString m_lastSearch; - TabWidget *m_tabWidget; + MainView *m_tabWidget; }; #endif // MAINWINDOW_H diff --git a/src/tabbar.cpp b/src/tabbar.cpp new file mode 100644 index 00000000..9aae3644 --- /dev/null +++ b/src/tabbar.cpp @@ -0,0 +1,207 @@ +/* ============================================================ + * + * This file is a part of the rekonq project + * + * Copyright (C) 2007-2008 Trolltech ASA. All rights reserved + * Copyright (C) 2008 by Andrea Diamantini <adjam7 at gmail dot 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 2, 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. + * + * ============================================================ */ + + +// Local Includes +#include "tabbar.h" + +#include "browserapplication.h" +#include "mainwindow.h" +#include "history.h" +#include "urlbar.h" +#include "webview.h" + +// KDE Includes +#include <KShortcut> +#include <KStandardShortcut> +#include <KMessageBox> +#include <KAction> + +// Qt Includes +#include <QtGui> +#include <QDebug> + + +TabBar::TabBar(QWidget *parent) + : KTabBar(parent) +{ + setElideMode(Qt::ElideRight); + setContextMenuPolicy(Qt::CustomContextMenu); + setAcceptDrops(true); + connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(contextMenuRequested(const QPoint &))); + + QString alt = QLatin1String("Alt+%1"); + for (int i = 1; i <= 10; ++i) + { + int key = i; + if (key == 10) + { + key = 0; + } + QShortcut *shortCut = new QShortcut(alt.arg(key), this); + m_tabShortcuts.append(shortCut); + connect(shortCut, SIGNAL(activated()), this, SLOT(selectTabAction())); + } +} + + +TabBar::~TabBar() +{ +} + + +void TabBar::selectTabAction() +{ + if (QShortcut *shortCut = qobject_cast<QShortcut*>(sender())) + { + int index = m_tabShortcuts.indexOf(shortCut); + if (index == 0) + index = 10; + setCurrentIndex(index); + } +} + + +void TabBar::contextMenuRequested(const QPoint &position) +{ + // FIXME: use right actions + KMenu menu; + menu.addAction(i18n("New &Tab"), this, SIGNAL( newTab() ), QKeySequence::AddTab); + int index = tabAt(position); + if (-1 != index) + { + KAction *action = (KAction * ) menu.addAction(i18n("Clone Tab"), this, SLOT(cloneTab())); + action->setData(index); + + menu.addSeparator(); + + action = (KAction * ) menu.addAction(i18n("&Close Tab"), this, SLOT(closeTab()), QKeySequence::Close); + action->setData(index); + + action = (KAction * ) menu.addAction(i18n("Close &Other Tabs"), this, SLOT(closeOtherTabs())); + action->setData(index); + + menu.addSeparator(); + + action = (KAction * ) menu.addAction(i18n("Reload Tab"), this, SLOT(reloadTab()), QKeySequence::Refresh); + action->setData(index); + } + else + { + menu.addSeparator(); + } + menu.addAction(i18n("Reload All Tabs"), this, SIGNAL(reloadAllTabs())); + menu.exec(QCursor::pos()); +} + + +void TabBar::cloneTab() +{ + if (KAction *action = qobject_cast<KAction*>(sender())) + { + int index = action->data().toInt(); + emit cloneTab(index); + } +} + + +void TabBar::closeTab() +{ + if (KAction *action = qobject_cast<KAction*>(sender())) + { + int index = action->data().toInt(); + emit closeTab(index); + } +} + + +void TabBar::closeOtherTabs() +{ + if (KAction *action = qobject_cast<KAction*>(sender())) + { + int index = action->data().toInt(); + emit closeOtherTabs(index); + } +} + + +void TabBar::mousePressEvent(QMouseEvent *event) +{ + if (event->button() == Qt::LeftButton) + m_dragStartPos = event->pos(); + QTabBar::mousePressEvent(event); +} + + +void TabBar::mouseMoveEvent(QMouseEvent *event) +{ + if (event->buttons() == Qt::LeftButton && (event->pos() - m_dragStartPos).manhattanLength() > QApplication::startDragDistance()) + { + QDrag *drag = new QDrag(this); + QMimeData *mimeData = new QMimeData; + QList<QUrl> urls; + int index = tabAt(event->pos()); + QUrl url = tabData(index).toUrl(); + urls.append(url); + mimeData->setUrls(urls); + mimeData->setText(tabText(index)); + mimeData->setData(QLatin1String("action"), "tab-reordering"); + drag->setMimeData(mimeData); + drag->exec(); + } + QTabBar::mouseMoveEvent(event); +} + + +void TabBar::dragEnterEvent(QDragEnterEvent *event) +{ + const QMimeData *mimeData = event->mimeData(); + QStringList formats = mimeData->formats(); + + if (formats.contains(QLatin1String("action")) && (mimeData->data(QLatin1String("action")) == "tab-reordering")) + { + event->acceptProposedAction(); + } + QTabBar::dragEnterEvent(event); +} + + +void TabBar::dropEvent(QDropEvent *event) +{ + int fromIndex = tabAt(m_dragStartPos); + int toIndex = tabAt(event->pos()); + if (fromIndex != toIndex) + { + emit tabMoveRequested(fromIndex, toIndex); + event->acceptProposedAction(); + } + QTabBar::dropEvent(event); +} + + +void TabBar::reloadTab() +{ + if (KAction *action = qobject_cast<KAction*>(sender())) + { + int index = action->data().toInt(); + emit reloadTab(index); + } +} + diff --git a/src/tabbar.h b/src/tabbar.h new file mode 100644 index 00000000..0692fcd6 --- /dev/null +++ b/src/tabbar.h @@ -0,0 +1,74 @@ +/* ============================================================ + * + * This file is a part of the rekonq project + * + * Copyright (C) 2007-2008 Trolltech ASA. All rights reserved + * Copyright (C) 2008 by Andrea Diamantini <adjam7 at gmail dot 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 2, 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. + * + * ============================================================ */ + + + +#ifndef TABBAR_H +#define TABBAR_H + +// KDE Includes +#include <KTabBar> + +// Qt Includes +#include <QShortcut> + +/** + * Tab bar with a few more features such as a context menu and shortcuts + */ +class TabBar : public KTabBar +{ + Q_OBJECT + +signals: + void newTab(); + void cloneTab(int index); + void closeTab(int index); + void closeOtherTabs(int index); + void reloadTab(int index); + void reloadAllTabs(); + void tabMoveRequested(int fromIndex, int toIndex); + +public: + TabBar(QWidget *parent = 0); + ~TabBar(); + +protected: + void mousePressEvent(QMouseEvent* event); + void mouseMoveEvent(QMouseEvent* event); + void dragEnterEvent(QDragEnterEvent *event); + void dropEvent(QDropEvent *event); + +private slots: + void selectTabAction(); + void cloneTab(); + void closeTab(); + void closeOtherTabs(); + void reloadTab(); + void contextMenuRequested(const QPoint &position); + +private: + QList<QShortcut*> m_tabShortcuts; + friend class MainView; + + QPoint m_dragStartPos; + int m_dragCurrentIndex; +}; + +#endif diff --git a/src/webview.cpp b/src/webview.cpp index e17a961a..96167816 100644 --- a/src/webview.cpp +++ b/src/webview.cpp @@ -21,10 +21,10 @@ #include "browserapplication.h" #include "mainwindow.h" +#include "mainview.h" #include "cookiejar.h" #include "downloadmanager.h" #include "networkaccessmanager.h" -#include "tabwidget.h" #include "webview.h" #include <KStandardDirs> |