Exemplo n.º 1
0
WebView *TabWidget::webView(int index) const
{
    QWidget *widget = this->widget(index);
    if (WebViewWithSearch *webViewWithSearch = qobject_cast<WebViewWithSearch*>(widget)) {
        return webViewWithSearch->m_webView;
    } else if (widget) {
        // optimization to delay creating the first webview
        if (count() == 1) {
            TabWidget *that = const_cast<TabWidget*>(this);
            that->setUpdatesEnabled(false);
            LocationBar *currentLocationBar = qobject_cast<LocationBar*>(m_locationBars->widget(0));
            bool giveBackFocus = currentLocationBar->hasFocus();
            m_locationBars->removeWidget(currentLocationBar);
            m_locationBars->addWidget(new QWidget());
            that->newTab();
            that->closeTab(0);
            QWidget *newEmptyLineEdit = m_locationBars->widget(0);
            m_locationBars->removeWidget(newEmptyLineEdit);
            newEmptyLineEdit->deleteLater();
            m_locationBars->addWidget(currentLocationBar);
            currentLocationBar->setWebView(currentWebView());
            if (giveBackFocus)
                currentLocationBar->setFocus();
            that->setUpdatesEnabled(true);
            that->m_swappedDelayedWidget = true;
            return currentWebView();
        }
    }
    return 0;
}
Exemplo n.º 2
0
WebView *TabWidget::webView(int index) const
{
    QWidget *widget = this->widget(index);
    if (WebView *webView = qobject_cast<WebView*>(widget)) {
        return webView;
    } else {
        // optimization to delay creating the first webview
        if (count() == 1) {
            TabWidget *that = const_cast<TabWidget*>(this);
            that->setUpdatesEnabled(false);
            that->newTab();
            that->closeTab(0);
            that->setUpdatesEnabled(true);
            return currentWebView();
        }
    }
    return 0;
}