demos/browser/tabwidget.cpp
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
2:56cd8111b7f7 3:41300fa6a67c
    62 TabBar::TabBar(QWidget *parent)
    62 TabBar::TabBar(QWidget *parent)
    63     : QTabBar(parent)
    63     : QTabBar(parent)
    64 {
    64 {
    65     setContextMenuPolicy(Qt::CustomContextMenu);
    65     setContextMenuPolicy(Qt::CustomContextMenu);
    66     setAcceptDrops(true);
    66     setAcceptDrops(true);
    67     connect(this, SIGNAL(customContextMenuRequested(const QPoint &)),
    67     connect(this, SIGNAL(customContextMenuRequested(QPoint)),
    68             this, SLOT(contextMenuRequested(const QPoint &)));
    68             this, SLOT(contextMenuRequested(QPoint)));
    69 
    69 
    70     QString alt = QLatin1String("Alt+%1");
    70     QString alt = QLatin1String("Alt+%1");
    71     for (int i = 1; i <= 10; ++i) {
    71     for (int i = 1; i <= 10; ++i) {
    72         int key = i;
    72         int key = i;
    73         if (key == 10)
    73         if (key == 10)
   219     connect(m_tabBar, SIGNAL(closeTab(int)), this, SLOT(closeTab(int)));
   219     connect(m_tabBar, SIGNAL(closeTab(int)), this, SLOT(closeTab(int)));
   220     connect(m_tabBar, SIGNAL(cloneTab(int)), this, SLOT(cloneTab(int)));
   220     connect(m_tabBar, SIGNAL(cloneTab(int)), this, SLOT(cloneTab(int)));
   221     connect(m_tabBar, SIGNAL(closeOtherTabs(int)), this, SLOT(closeOtherTabs(int)));
   221     connect(m_tabBar, SIGNAL(closeOtherTabs(int)), this, SLOT(closeOtherTabs(int)));
   222     connect(m_tabBar, SIGNAL(reloadTab(int)), this, SLOT(reloadTab(int)));
   222     connect(m_tabBar, SIGNAL(reloadTab(int)), this, SLOT(reloadTab(int)));
   223     connect(m_tabBar, SIGNAL(reloadAllTabs()), this, SLOT(reloadAllTabs()));
   223     connect(m_tabBar, SIGNAL(reloadAllTabs()), this, SLOT(reloadAllTabs()));
   224     connect(m_tabBar, SIGNAL(tabMoved(int, int)), this, SLOT(moveTab(int, int)));
   224     connect(m_tabBar, SIGNAL(tabMoved(int,int)), this, SLOT(moveTab(int,int)));
   225     setTabBar(m_tabBar);
   225     setTabBar(m_tabBar);
   226     setDocumentMode(true);
   226     setDocumentMode(true);
   227 
   227 
   228     // Actions
   228     // Actions
   229     m_newTabAction = new QAction(QIcon(QLatin1String(":addtab.png")), tr("New &Tab"), this);
   229     m_newTabAction = new QAction(QIcon(QLatin1String(":addtab.png")), tr("New &Tab"), this);
   255     connect(m_previousTabAction, SIGNAL(triggered()), this, SLOT(previousTab()));
   255     connect(m_previousTabAction, SIGNAL(triggered()), this, SLOT(previousTab()));
   256 
   256 
   257     m_recentlyClosedTabsMenu = new QMenu(this);
   257     m_recentlyClosedTabsMenu = new QMenu(this);
   258     connect(m_recentlyClosedTabsMenu, SIGNAL(aboutToShow()),
   258     connect(m_recentlyClosedTabsMenu, SIGNAL(aboutToShow()),
   259             this, SLOT(aboutToShowRecentTabsMenu()));
   259             this, SLOT(aboutToShowRecentTabsMenu()));
   260     connect(m_recentlyClosedTabsMenu, SIGNAL(triggered(QAction *)),
   260     connect(m_recentlyClosedTabsMenu, SIGNAL(triggered(QAction*)),
   261             this, SLOT(aboutToShowRecentTriggeredAction(QAction *)));
   261             this, SLOT(aboutToShowRecentTriggeredAction(QAction*)));
   262     m_recentlyClosedTabsAction = new QAction(tr("Recently Closed Tabs"), this);
   262     m_recentlyClosedTabsAction = new QAction(tr("Recently Closed Tabs"), this);
   263     m_recentlyClosedTabsAction->setMenu(m_recentlyClosedTabsMenu);
   263     m_recentlyClosedTabsAction->setMenu(m_recentlyClosedTabsMenu);
   264     m_recentlyClosedTabsAction->setEnabled(false);
   264     m_recentlyClosedTabsAction->setEnabled(false);
   265 
   265 
   266     connect(this, SIGNAL(currentChanged(int)),
   266     connect(this, SIGNAL(currentChanged(int)),
   302 
   302 
   303     Q_ASSERT(m_lineEdits->count() == count());
   303     Q_ASSERT(m_lineEdits->count() == count());
   304 
   304 
   305     WebView *oldWebView = this->webView(m_lineEdits->currentIndex());
   305     WebView *oldWebView = this->webView(m_lineEdits->currentIndex());
   306     if (oldWebView) {
   306     if (oldWebView) {
   307         disconnect(oldWebView, SIGNAL(statusBarMessage(const QString&)),
   307         disconnect(oldWebView, SIGNAL(statusBarMessage(QString)),
   308                 this, SIGNAL(showStatusBarMessage(const QString&)));
   308                 this, SIGNAL(showStatusBarMessage(QString)));
   309         disconnect(oldWebView->page(), SIGNAL(linkHovered(const QString&, const QString&, const QString&)),
   309         disconnect(oldWebView->page(), SIGNAL(linkHovered(QString,QString,QString)),
   310                 this, SIGNAL(linkHovered(const QString&)));
   310                 this, SIGNAL(linkHovered(QString)));
   311         disconnect(oldWebView, SIGNAL(loadProgress(int)),
   311         disconnect(oldWebView, SIGNAL(loadProgress(int)),
   312                 this, SIGNAL(loadProgress(int)));
   312                 this, SIGNAL(loadProgress(int)));
   313     }
   313     }
   314 
   314 
   315     connect(webView, SIGNAL(statusBarMessage(const QString&)),
   315     connect(webView, SIGNAL(statusBarMessage(QString)),
   316             this, SIGNAL(showStatusBarMessage(const QString&)));
   316             this, SIGNAL(showStatusBarMessage(QString)));
   317     connect(webView->page(), SIGNAL(linkHovered(const QString&, const QString&, const QString&)),
   317     connect(webView->page(), SIGNAL(linkHovered(QString,QString,QString)),
   318             this, SIGNAL(linkHovered(const QString&)));
   318             this, SIGNAL(linkHovered(QString)));
   319     connect(webView, SIGNAL(loadProgress(int)),
   319     connect(webView, SIGNAL(loadProgress(int)),
   320             this, SIGNAL(loadProgress(int)));
   320             this, SIGNAL(loadProgress(int)));
   321 
   321 
   322     for (int i = 0; i < m_actions.count(); ++i) {
   322     for (int i = 0; i < m_actions.count(); ++i) {
   323         WebActionMapper *mapper = m_actions[i];
   323         WebActionMapper *mapper = m_actions[i];
   448             this, SLOT(webViewLoadStarted()));
   448             this, SLOT(webViewLoadStarted()));
   449     connect(webView, SIGNAL(loadFinished(bool)),
   449     connect(webView, SIGNAL(loadFinished(bool)),
   450             this, SLOT(webViewIconChanged()));
   450             this, SLOT(webViewIconChanged()));
   451     connect(webView, SIGNAL(iconChanged()),
   451     connect(webView, SIGNAL(iconChanged()),
   452             this, SLOT(webViewIconChanged()));
   452             this, SLOT(webViewIconChanged()));
   453     connect(webView, SIGNAL(titleChanged(const QString &)),
   453     connect(webView, SIGNAL(titleChanged(QString)),
   454             this, SLOT(webViewTitleChanged(const QString &)));
   454             this, SLOT(webViewTitleChanged(QString)));
   455     connect(webView, SIGNAL(urlChanged(const QUrl &)),
   455     connect(webView, SIGNAL(urlChanged(QUrl)),
   456             this, SLOT(webViewUrlChanged(const QUrl &)));
   456             this, SLOT(webViewUrlChanged(QUrl)));
   457     connect(webView->page(), SIGNAL(windowCloseRequested()),
   457     connect(webView->page(), SIGNAL(windowCloseRequested()),
   458             this, SLOT(windowCloseRequested()));
   458             this, SLOT(windowCloseRequested()));
   459     connect(webView->page(), SIGNAL(geometryChangeRequested(const QRect &)),
   459     connect(webView->page(), SIGNAL(geometryChangeRequested(QRect)),
   460             this, SIGNAL(geometryChangeRequested(const QRect &)));
   460             this, SIGNAL(geometryChangeRequested(QRect)));
   461     connect(webView->page(), SIGNAL(printRequested(QWebFrame *)),
   461     connect(webView->page(), SIGNAL(printRequested(QWebFrame*)),
   462             this, SIGNAL(printRequested(QWebFrame *)));
   462             this, SIGNAL(printRequested(QWebFrame*)));
   463     connect(webView->page(), SIGNAL(menuBarVisibilityChangeRequested(bool)),
   463     connect(webView->page(), SIGNAL(menuBarVisibilityChangeRequested(bool)),
   464             this, SIGNAL(menuBarVisibilityChangeRequested(bool)));
   464             this, SIGNAL(menuBarVisibilityChangeRequested(bool)));
   465     connect(webView->page(), SIGNAL(statusBarVisibilityChangeRequested(bool)),
   465     connect(webView->page(), SIGNAL(statusBarVisibilityChangeRequested(bool)),
   466             this, SIGNAL(statusBarVisibilityChangeRequested(bool)));
   466             this, SIGNAL(statusBarVisibilityChangeRequested(bool)));
   467     connect(webView->page(), SIGNAL(toolBarVisibilityChangeRequested(bool)),
   467     connect(webView->page(), SIGNAL(toolBarVisibilityChangeRequested(bool)),
   762     , m_webAction(webAction)
   762     , m_webAction(webAction)
   763 {
   763 {
   764     if (!m_root)
   764     if (!m_root)
   765         return;
   765         return;
   766     connect(m_root, SIGNAL(triggered()), this, SLOT(rootTriggered()));
   766     connect(m_root, SIGNAL(triggered()), this, SLOT(rootTriggered()));
   767     connect(root, SIGNAL(destroyed(QObject *)), this, SLOT(rootDestroyed()));
   767     connect(root, SIGNAL(destroyed(QObject*)), this, SLOT(rootDestroyed()));
   768     root->setEnabled(false);
   768     root->setEnabled(false);
   769 }
   769 }
   770 
   770 
   771 void WebActionMapper::rootDestroyed()
   771 void WebActionMapper::rootDestroyed()
   772 {
   772 {
   811 }
   811 }
   812 
   812 
   813 void WebActionMapper::updateCurrent(QWebPage *currentParent)
   813 void WebActionMapper::updateCurrent(QWebPage *currentParent)
   814 {
   814 {
   815     if (m_currentParent)
   815     if (m_currentParent)
   816         disconnect(m_currentParent, SIGNAL(destroyed(QObject *)),
   816         disconnect(m_currentParent, SIGNAL(destroyed(QObject*)),
   817                    this, SLOT(currentDestroyed()));
   817                    this, SLOT(currentDestroyed()));
   818 
   818 
   819     m_currentParent = currentParent;
   819     m_currentParent = currentParent;
   820     if (!m_root)
   820     if (!m_root)
   821         return;
   821         return;
   825         return;
   825         return;
   826     }
   826     }
   827     QAction *source = m_currentParent->action(m_webAction);
   827     QAction *source = m_currentParent->action(m_webAction);
   828     m_root->setChecked(source->isChecked());
   828     m_root->setChecked(source->isChecked());
   829     m_root->setEnabled(source->isEnabled());
   829     m_root->setEnabled(source->isEnabled());
   830     connect(m_currentParent, SIGNAL(destroyed(QObject *)),
   830     connect(m_currentParent, SIGNAL(destroyed(QObject*)),
   831             this, SLOT(currentDestroyed()));
   831             this, SLOT(currentDestroyed()));
   832 }
   832 }
   833 
   833