From d4ee1b6a519d342109cd2cda52d30ea776065e11 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Thu, 27 Nov 2008 16:45:38 +0100 Subject: New step forwad in the street from QAction to KAction.. --- src/browsermainwindow.cpp | 11 +-- src/browsermainwindow.h | 4 +- src/tabwidget.cpp | 185 ++++++++++++++++++++++++---------------------- src/tabwidget.h | 35 +++++---- src/urlbar.cpp | 18 ++--- 5 files changed, 131 insertions(+), 122 deletions(-) (limited to 'src') diff --git a/src/browsermainwindow.cpp b/src/browsermainwindow.cpp index 4ea1d444..64f9c56f 100644 --- a/src/browsermainwindow.cpp +++ b/src/browsermainwindow.cpp @@ -225,6 +225,7 @@ void BrowserMainWindow::setupMenu() fileMenu->addAction( i18n("Open Location"), this, SLOT( slotSelectLineEdit() ) ); fileMenu->addSeparator(); + fileMenu->addAction( m_tabWidget->newTabAction() ); fileMenu->addAction( m_tabWidget->closeTabAction() ); fileMenu->addSeparator(); @@ -239,7 +240,7 @@ void BrowserMainWindow::setupMenu() action->setCheckable(true); fileMenu->addSeparator(); - fileMenu->addAction( KStandardAction::close( this , SLOT( close() ), this ) ); + fileMenu->addAction( KStandardAction::quit( this , SLOT( close() ), this ) ); // ------------------------------------------------------------- EDIT -------------------------------------------------------------------------------------------------- KMenu *editMenu = (KMenu *) menuBar()->addMenu( i18n("&Edit") ); @@ -313,14 +314,14 @@ void BrowserMainWindow::setupMenu() menuBar()->addMenu(historyMenu); QList historyActions; - m_historyBack = new QAction( i18n("Back"), this); + m_historyBack = new KAction( i18n("Back"), this); m_tabWidget->addWebAction(m_historyBack, QWebPage::Back); - m_historyBack->setShortcuts(QKeySequence::Back); +// m_historyBack->setShortcuts(QKeySequence::Back); FIXME m_historyBack->setIconVisibleInMenu(false); - m_historyForward = new QAction( i18n("Forward"), this); + m_historyForward = new KAction( i18n("Forward"), this); m_tabWidget->addWebAction(m_historyForward, QWebPage::Forward); - m_historyForward->setShortcuts(QKeySequence::Forward); +// m_historyForward->setShortcuts(QKeySequence::Forward); FIXME m_historyForward->setIconVisibleInMenu(false); m_restoreLastSession = new QAction( i18n("Restore Last Session"), this); diff --git a/src/browsermainwindow.h b/src/browsermainwindow.h index c5db7bba..fc57c6b9 100644 --- a/src/browsermainwindow.h +++ b/src/browsermainwindow.h @@ -132,9 +132,9 @@ private: TabWidget *m_tabWidget; AutoSaver *m_autoSaver; - QAction *m_historyBack; + KAction *m_historyBack; KMenu *m_historyBackMenu; - QAction *m_historyForward; + KAction *m_historyForward; KMenu *m_windowMenu; KAction *m_stop; diff --git a/src/tabwidget.cpp b/src/tabwidget.cpp index d66b6ba3..e54dbee5 100644 --- a/src/tabwidget.cpp +++ b/src/tabwidget.cpp @@ -179,18 +179,6 @@ void TabBar::dropEvent(QDropEvent *event) QTabBar::dropEvent(event); } -// When index is -1 index chooses the current tab -void TabWidget::reloadTab(int index) -{ - if (index < 0) - index = currentIndex(); - if (index < 0 || index >= count()) - return; - - QWidget *widget = this->widget(index); - if (WebView *tab = qobject_cast(widget)) - tab->reload(); -} void TabBar::reloadTab() { @@ -226,17 +214,17 @@ TabWidget::TabWidget(QWidget *parent) setTabBar(m_tabBar); // Actions - m_newTabAction = new QAction(KIcon("tab-new"), i18n("New &Tab"), this); - m_newTabAction->setShortcuts(QKeySequence::AddTab); + m_newTabAction = new KAction(KIcon("tab-new"), i18n("New &Tab"), this); +// m_newTabAction->setShortcuts(QKeySequence::AddTab); FIXME m_newTabAction->setIconVisibleInMenu(false); connect(m_newTabAction, SIGNAL(triggered()), this, SLOT(newTab())); - m_closeTabAction = new QAction(KIcon("tab-close"), i18n("&Close Tab"), this); - m_closeTabAction->setShortcuts(QKeySequence::Close); + m_closeTabAction = new KAction(KIcon("tab-close"), i18n("&Close Tab"), this); +// m_closeTabAction->setShortcuts(QKeySequence::Close); FIXME m_closeTabAction->setIconVisibleInMenu(false); connect(m_closeTabAction, SIGNAL(triggered()), this, SLOT(closeTab())); - m_nextTabAction = new QAction(i18n("Show Next Tab"), this); + m_nextTabAction = new KAction(i18n("Show Next Tab"), this); QList shortcuts; shortcuts.append(QKeySequence(Qt::CTRL | Qt::Key_BraceRight)); shortcuts.append(QKeySequence(Qt::CTRL | Qt::Key_PageDown)); @@ -245,7 +233,7 @@ TabWidget::TabWidget(QWidget *parent) m_nextTabAction->setShortcuts(shortcuts); connect(m_nextTabAction, SIGNAL(triggered()), this, SLOT(nextTab())); - m_previousTabAction = new QAction(i18n("Show Previous Tab"), this); + m_previousTabAction = new KAction(i18n("Show Previous Tab"), this); shortcuts.clear(); shortcuts.append(QKeySequence(Qt::CTRL | Qt::Key_BraceLeft)); shortcuts.append(QKeySequence(Qt::CTRL | Qt::Key_PageUp)); @@ -255,11 +243,9 @@ TabWidget::TabWidget(QWidget *parent) connect(m_previousTabAction, SIGNAL(triggered()), this, SLOT(previousTab())); m_recentlyClosedTabsMenu = new QMenu(this); - connect(m_recentlyClosedTabsMenu, SIGNAL(aboutToShow()), - this, SLOT(aboutToShowRecentTabsMenu())); - connect(m_recentlyClosedTabsMenu, SIGNAL(triggered(QAction *)), - this, SLOT(aboutToShowRecentTriggeredAction(QAction *))); - m_recentlyClosedTabsAction = new QAction(i18n("Recently Closed Tabs"), this); + connect(m_recentlyClosedTabsMenu, SIGNAL(aboutToShow()), this, SLOT(aboutToShowRecentTabsMenu())); + connect(m_recentlyClosedTabsMenu, SIGNAL(triggered(QAction *)), this, SLOT(aboutToShowRecentTriggeredAction(QAction *))); + m_recentlyClosedTabsAction = new KAction(i18n("Recently Closed Tabs"), this); m_recentlyClosedTabsAction->setMenu(m_recentlyClosedTabsMenu); m_recentlyClosedTabsAction->setEnabled(false); @@ -304,12 +290,25 @@ void TabWidget::moveTab(int fromIndex, int toIndex) removeTab(fromIndex); insertTab(toIndex, tabWidget, icon, text); m_tabBar->setTabData(toIndex, data); - connect(this, SIGNAL(currentChanged(int)), - this, SLOT(currentChanged(int))); + connect(this, SIGNAL(currentChanged(int)), this, SLOT(currentChanged(int))); setCurrentIndex(toIndex); } -void TabWidget::addWebAction(QAction *action, QWebPage::WebAction webAction) +// When index is -1 index chooses the current tab +void TabWidget::reloadTab(int index) +{ + if (index < 0) + index = currentIndex(); + if (index < 0 || index >= count()) + return; + + QWidget *widget = this->widget(index); + if (WebView *tab = qobject_cast(widget)) + tab->reload(); +} + + +void TabWidget::addWebAction(KAction *action, QWebPage::WebAction webAction) { if (!action) return; @@ -325,7 +324,8 @@ void TabWidget::currentChanged(int index) Q_ASSERT(m_lineEdits->count() == count()); WebView *oldWebView = this->webView(m_lineEdits->currentIndex()); - if (oldWebView) { + if (oldWebView) + { disconnect(oldWebView, SIGNAL(statusBarMessage(const QString&)), this, SIGNAL(showStatusBarMessage(const QString&))); disconnect(oldWebView->page(), SIGNAL(linkHovered(const QString&, const QString&, const QString&)), @@ -341,7 +341,8 @@ void TabWidget::currentChanged(int index) connect(webView, SIGNAL(loadProgress(int)), this, SIGNAL(loadProgress(int))); - for (int i = 0; i < m_actions.count(); ++i) { + for (int i = 0; i < m_actions.count(); ++i) + { WebActionMapper *mapper = m_actions[i]; mapper->updateCurrent(webView->page()); } @@ -355,27 +356,27 @@ void TabWidget::currentChanged(int index) webView->setFocus(); } -QAction *TabWidget::newTabAction() const +KAction *TabWidget::newTabAction() const { return m_newTabAction; } -QAction *TabWidget::closeTabAction() const +KAction *TabWidget::closeTabAction() const { return m_closeTabAction; } -QAction *TabWidget::recentlyClosedTabsAction() const +KAction *TabWidget::recentlyClosedTabsAction() const { return m_recentlyClosedTabsAction; } -QAction *TabWidget::nextTabAction() const +KAction *TabWidget::nextTabAction() const { return m_nextTabAction; } -QAction *TabWidget::previousTabAction() const +KAction *TabWidget::previousTabAction() const { return m_previousTabAction; } @@ -406,11 +407,15 @@ KLineEdit *TabWidget::lineEdit(int index) const WebView *TabWidget::webView(int index) const { QWidget *widget = this->widget(index); - if (WebView *webView = qobject_cast(widget)) { + if (WebView *webView = qobject_cast(widget)) + { return webView; - } else { + } + else + { // optimization to delay creating the first webview - if (count() == 1) { + if (count() == 1) + { TabWidget *that = const_cast(this); that->setUpdatesEnabled(false); that->newTab(); @@ -457,47 +462,36 @@ WebView *TabWidget::newTab(bool makeCurrent) p.setColor(QPalette::Window, palette().color(QPalette::Base)); emptyWidget->setPalette(p); emptyWidget->setAutoFillBackground(true); - disconnect(this, SIGNAL(currentChanged(int)), - this, SLOT(currentChanged(int))); + disconnect(this, SIGNAL(currentChanged(int)), this, SLOT(currentChanged(int))); addTab(emptyWidget, i18n("(Untitled)")); - connect(this, SIGNAL(currentChanged(int)), - this, SLOT(currentChanged(int))); + connect(this, SIGNAL(currentChanged(int)), this, SLOT(currentChanged(int))); return 0; } // webview WebView *webView = new WebView; urlLineEdit->setWebView(webView); - connect(webView, SIGNAL(loadStarted()), - this, SLOT(webViewLoadStarted())); - connect(webView, SIGNAL(loadFinished(bool)), - this, SLOT(webViewIconChanged())); - connect(webView, SIGNAL(iconChanged()), - this, SLOT(webViewIconChanged())); - connect(webView, SIGNAL(titleChanged(const QString &)), - this, SLOT(webViewTitleChanged(const QString &))); - connect(webView, SIGNAL(urlChanged(const QUrl &)), - this, SLOT(webViewUrlChanged(const QUrl &))); - connect(webView->page(), SIGNAL(windowCloseRequested()), - this, SLOT(windowCloseRequested())); - connect(webView->page(), SIGNAL(geometryChangeRequested(const QRect &)), - this, SIGNAL(geometryChangeRequested(const QRect &))); - connect(webView->page(), SIGNAL(printRequested(QWebFrame *)), - this, SIGNAL(printRequested(QWebFrame *))); - connect(webView->page(), SIGNAL(menuBarVisibilityChangeRequested(bool)), - this, SIGNAL(menuBarVisibilityChangeRequested(bool))); - connect(webView->page(), SIGNAL(statusBarVisibilityChangeRequested(bool)), - this, SIGNAL(statusBarVisibilityChangeRequested(bool))); - connect(webView->page(), SIGNAL(toolBarVisibilityChangeRequested(bool)), - this, SIGNAL(toolBarVisibilityChangeRequested(bool))); + + connect(webView, SIGNAL(loadStarted()), this, SLOT(webViewLoadStarted())); + connect(webView, SIGNAL(loadFinished(bool)), this, SLOT(webViewIconChanged())); + connect(webView, SIGNAL(iconChanged()), this, SLOT(webViewIconChanged())); + connect(webView, SIGNAL(titleChanged(const QString &)), this, SLOT(webViewTitleChanged(const QString &))); + connect(webView, SIGNAL(urlChanged(const QUrl &)), this, SLOT(webViewUrlChanged(const QUrl &))); + connect(webView->page(), SIGNAL(windowCloseRequested()), this, SLOT(windowCloseRequested())); + connect(webView->page(), SIGNAL(geometryChangeRequested(const QRect &)), this, SIGNAL(geometryChangeRequested(const QRect &))); + connect(webView->page(), SIGNAL(printRequested(QWebFrame *)), this, SIGNAL(printRequested(QWebFrame *))); + connect(webView->page(), SIGNAL(menuBarVisibilityChangeRequested(bool)), this, SIGNAL(menuBarVisibilityChangeRequested(bool))); + connect(webView->page(), SIGNAL(statusBarVisibilityChangeRequested(bool)), this, SIGNAL(statusBarVisibilityChangeRequested(bool))); + connect(webView->page(), SIGNAL(toolBarVisibilityChangeRequested(bool)), this, SIGNAL(toolBarVisibilityChangeRequested(bool))); addTab(webView, i18n("(Untitled)")); if (makeCurrent) setCurrentWidget(webView); // webview actions - for (int i = 0; i < m_actions.count(); ++i) { + for (int i = 0; i < m_actions.count(); ++i) + { WebActionMapper *mapper = m_actions[i]; - mapper->addChild(webView->page()->action(mapper->webAction())); + mapper->addChild( new KAction( webView->page()->action( mapper->webAction() ) ) ); } if (count() == 1) @@ -508,9 +502,11 @@ WebView *TabWidget::newTab(bool makeCurrent) void TabWidget::reloadAllTabs() { - for (int i = 0; i < count(); ++i) { + for (int i = 0; i < count(); ++i) + { QWidget *tabWidget = widget(i); - if (WebView *tab = qobject_cast(tabWidget)) { + if (WebView *tab = qobject_cast(tabWidget)) + { tab->reload(); } } @@ -531,7 +527,8 @@ void TabWidget::windowCloseRequested() WebPage *webPage = qobject_cast(sender()); WebView *webView = qobject_cast(webPage->view()); int index = webViewIndex(webView); - if (index >= 0) { + if (index >= 0) + { if (count() == 1) webView->webPage()->mainWindow()->close(); else @@ -608,7 +605,7 @@ void TabWidget::webViewLoadStarted() WebView *webView = qobject_cast(sender()); int index = webViewIndex(webView); if (-1 != index) { - QIcon icon(QLatin1String(":loading.gif")); + QIcon icon(QLatin1String(":loading.gif")); // FIXME setTabIcon(index, icon); } } @@ -617,7 +614,8 @@ void TabWidget::webViewIconChanged() { WebView *webView = qobject_cast(sender()); int index = webViewIndex(webView); - if (-1 != index) { + if (-1 != index) + { QIcon icon = BrowserApplication::instance()->icon(webView->url()); setTabIcon(index, icon); } @@ -648,8 +646,9 @@ void TabWidget::webViewUrlChanged(const QUrl &url) void TabWidget::aboutToShowRecentTabsMenu() { m_recentlyClosedTabsMenu->clear(); - for (int i = 0; i < m_recentlyClosedTabs.count(); ++i) { - QAction *action = new QAction(m_recentlyClosedTabsMenu); + for (int i = 0; i < m_recentlyClosedTabs.count(); ++i) + { + KAction *action = new KAction(m_recentlyClosedTabsMenu); action->setData(m_recentlyClosedTabs.at(i)); QIcon icon = BrowserApplication::instance()->icon(m_recentlyClosedTabs.at(i)); action->setIcon(icon); @@ -658,7 +657,7 @@ void TabWidget::aboutToShowRecentTabsMenu() } } -void TabWidget::aboutToShowRecentTriggeredAction(QAction *action) +void TabWidget::aboutToShowRecentTriggeredAction(KAction *action) { QUrl url = action->data().toUrl(); loadUrlInCurrentTab(url); @@ -688,9 +687,11 @@ void TabWidget::mouseReleaseEvent(QMouseEvent *event) { if (event->button() == Qt::MidButton && !childAt(event->pos()) // Remove the line below when QTabWidget does not have a one pixel frame - && event->pos().y() < (tabBar()->y() + tabBar()->height())) { + && event->pos().y() < (tabBar()->y() + tabBar()->height())) + { QUrl url(QApplication::clipboard()->text(QClipboard::Selection)); - if (!url.isEmpty() && url.isValid() && !url.scheme().isEmpty()) { + if (!url.isEmpty() && url.isValid() && !url.scheme().isEmpty()) + { WebView *webView = newTab(); webView->setUrl(url); } @@ -700,7 +701,8 @@ void TabWidget::mouseReleaseEvent(QMouseEvent *event) void TabWidget::loadUrlInCurrentTab(const QUrl &url) { WebView *webView = currentWebView(); - if (webView) { + if (webView) + { webView->loadUrl(url); webView->setFocus(); } @@ -734,10 +736,14 @@ QByteArray TabWidget::saveState() const stream << qint32(version); QStringList tabs; - for (int i = 0; i < count(); ++i) { - if (WebView *tab = qobject_cast(widget(i))) { + for (int i = 0; i < count(); ++i) + { + if (WebView *tab = qobject_cast(widget(i))) + { tabs.append(tab->url().toString()); - } else { + } + else + { tabs.append(QString::null); } } @@ -764,7 +770,8 @@ bool TabWidget::restoreState(const QByteArray &state) QStringList openTabs; stream >> openTabs; - for (int i = 0; i < openTabs.count(); ++i) { + for (int i = 0; i < openTabs.count(); ++i) + { if (i != 0) newTab(); loadPage(openTabs.at(i)); @@ -777,7 +784,7 @@ bool TabWidget::restoreState(const QByteArray &state) return true; } -WebActionMapper::WebActionMapper(QAction *root, QWebPage::WebAction webAction, QObject *parent) +WebActionMapper::WebActionMapper(KAction *root, QWebPage::WebAction webAction, QObject *parent) : QObject(parent) , m_currentParent(0) , m_root(root) @@ -800,7 +807,7 @@ void WebActionMapper::currentDestroyed() updateCurrent(0); } -void WebActionMapper::addChild(QAction *action) +void WebActionMapper::addChild(KAction *action) { if (!action) return; @@ -814,18 +821,21 @@ QWebPage::WebAction WebActionMapper::webAction() const void WebActionMapper::rootTriggered() { - if (m_currentParent) { - QAction *gotoAction = m_currentParent->action(m_webAction); + if (m_currentParent) + { + KAction *gotoAction = new KAction( m_currentParent->action(m_webAction) ); gotoAction->trigger(); } } void WebActionMapper::childChanged() { - if (QAction *source = qobject_cast(sender())) { + if (KAction *source = qobject_cast(sender())) + { if (m_root && m_currentParent - && source->parent() == m_currentParent) { + && source->parent() == m_currentParent) + { m_root->setChecked(source->isChecked()); m_root->setEnabled(source->isEnabled()); } @@ -846,9 +856,8 @@ void WebActionMapper::updateCurrent(QWebPage *currentParent) m_root->setChecked(false); return; } - QAction *source = m_currentParent->action(m_webAction); + 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())); + connect(m_currentParent, SIGNAL(destroyed(QObject *)), this, SLOT(currentDestroyed())); } diff --git a/src/tabwidget.h b/src/tabwidget.h index e6399971..7323c59d 100644 --- a/src/tabwidget.h +++ b/src/tabwidget.h @@ -24,6 +24,8 @@ #define TABWIDGET_H #include +#include + #include /* Tab bar with a few more features such as a context menu and shortcuts @@ -70,9 +72,6 @@ private: #include -QT_BEGIN_NAMESPACE -class QAction; -QT_END_NAMESPACE class WebView; /*! A proxy object that connects a single browser action @@ -86,9 +85,9 @@ class WebActionMapper : public QObject Q_OBJECT public: - WebActionMapper(QAction *root, QWebPage::WebAction webAction, QObject *parent); + WebActionMapper(KAction *root, QWebPage::WebAction webAction, QObject *parent); QWebPage::WebAction webAction() const; - void addChild(QAction *action); + void addChild(KAction *action); void updateCurrent(QWebPage *currentParent); private slots: @@ -99,7 +98,7 @@ private slots: private: QWebPage *m_currentParent; - QAction *m_root; + KAction *m_root; QWebPage::WebAction m_webAction; }; @@ -146,13 +145,13 @@ signals: public: TabWidget(QWidget *parent = 0); void clear(); - void addWebAction(QAction *action, QWebPage::WebAction webAction); + void addWebAction(KAction *action, QWebPage::WebAction webAction); - QAction *newTabAction() const; - QAction *closeTabAction() const; - QAction *recentlyClosedTabsAction() const; - QAction *nextTabAction() const; - QAction *previousTabAction() const; + KAction *newTabAction() const; + KAction *closeTabAction() const; + KAction *recentlyClosedTabsAction() const; + KAction *nextTabAction() const; + KAction *previousTabAction() const; QWidget *lineEditStack() const; KLineEdit *currentLineEdit() const; @@ -183,7 +182,7 @@ public slots: private slots: void currentChanged(int index); void aboutToShowRecentTabsMenu(); - void aboutToShowRecentTriggeredAction(QAction *action); + void aboutToShowRecentTriggeredAction(KAction *action); void webViewLoadStarted(); void webViewIconChanged(); void webViewTitleChanged(const QString &title); @@ -193,11 +192,11 @@ private slots: void moveTab(int fromIndex, int toIndex); private: - QAction *m_recentlyClosedTabsAction; - QAction *m_newTabAction; - QAction *m_closeTabAction; - QAction *m_nextTabAction; - QAction *m_previousTabAction; + KAction *m_recentlyClosedTabsAction; + KAction *m_newTabAction; + KAction *m_closeTabAction; + KAction *m_nextTabAction; + KAction *m_previousTabAction; QMenu *m_recentlyClosedTabsMenu; static const int m_recentlyClosedTabsSize = 10; diff --git a/src/urlbar.cpp b/src/urlbar.cpp index e7ce461a..16783313 100644 --- a/src/urlbar.cpp +++ b/src/urlbar.cpp @@ -81,18 +81,18 @@ void UrlBar::setWebView(WebView *webView) void UrlBar::paintEvent(QPaintEvent *event) { QPainter p(this); - QStyleOptionFrameV2 *optionPanel; + QStyleOptionFrameV2 optionPanel; - optionPanel->initFrom(this); - optionPanel->rect = contentsRect(); - optionPanel->lineWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth, optionPanel, this); - optionPanel->midLineWidth = 0; - optionPanel->state |= QStyle::State_Sunken; + optionPanel.initFrom(this); + optionPanel.rect = contentsRect(); + optionPanel.lineWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth, &optionPanel, this); + optionPanel.midLineWidth = 0; + optionPanel.state |= QStyle::State_Sunken; if (m_lineEdit->isReadOnly()) - optionPanel->state |= QStyle::State_ReadOnly; - optionPanel->features = QStyleOptionFrameV2::None; + optionPanel.state |= QStyle::State_ReadOnly; + optionPanel.features = QStyleOptionFrameV2::None; - style()->drawPrimitive(QStyle::PE_PanelLineEdit, optionPanel, &p, (QWidget *) this); + style()->drawPrimitive(QStyle::PE_PanelLineEdit, &optionPanel, &p, (QWidget *) this); } void UrlBar::focusOutEvent(QFocusEvent *event) -- cgit v1.2.1