QGraphicsWidget *createSpacer()
{
    QGraphicsWidget *spacer = new QGraphicsWidget();

    spacer->hide();
    spacer->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
    spacer->setMinimumSize(0, 0);
    spacer->setPreferredSize(0, 0);

    return spacer;
}
Ejemplo n.º 2
0
bool TitleWidget::removeWidget( TitleWidget::WidgetType widgetType, RemoveWidgetOptions options )
{
    if ( !m_widgets.contains(widgetType) ) {
        return false;
    }

    if ( widgetType == WidgetFilter || widgetType == WidgetQuickJourneySearch ||
         widgetType == WidgetTitle )
    {
        // Don't delete widgets that are also stored in a member variable
        // (m_filterWidget, m_journeySearchWidget, m_title)
        options ^= DeleteWidget;
        options |= HideAndRemoveWidget;
    }

    QGraphicsWidget *widget;
    if ( options.testFlag(RemoveWidget) || options.testFlag(DeleteWidget) ) {
        widget = m_widgets.take(widgetType);
        m_layout->removeItem(widget);
    } else {
        widget = m_widgets[widgetType];
    }
    if ( !widget ) {
        // A null value is stored in m_widgets, can happen if a default value gets constructed
        kDebug() << "Null value stored for widget type" << widgetType << "This can happen if a "
                "default value gets constructed for that widget type, ie. when a widget of that "
                "type gets requested from TitleWidget::m_widgets without checking if it is contained.";
        m_widgets.remove( widgetType );
        return false;
    }

    if ( options == DeleteWidget ) {
        widget->deleteLater();
    } else if ( options.testFlag(HideWidget) ) {
        widget->hide();
    }
    return true;
}
Ejemplo n.º 3
0
PassRefPtr<Widget> FrameLoaderClientQt::createPlugin(const IntSize& pluginSize, HTMLPlugInElement* element, const KURL& url, const Vector<String>& paramNames,
                                          const Vector<String>& paramValues, const String& mimeType, bool loadManually)
{
//     qDebug()<<"------ Creating plugin in FrameLoaderClientQt::createPlugin for "<<url.prettyURL() << mimeType;
//     qDebug()<<"------\t url = "<<url.prettyURL();

    if (!m_webFrame)
        return 0;

    QStringList params;
    QStringList values;
    QString classid(element->getAttribute("classid"));

    for (unsigned i = 0; i < paramNames.size(); ++i) {
        params.append(paramNames[i]);
        if (paramNames[i] == "classid")
            classid = paramValues[i];
    }
    for (unsigned i = 0; i < paramValues.size(); ++i)
        values.append(paramValues[i]);

    QString urlStr(url.string());
    QUrl qurl = urlStr;

    QObject* object = 0;

    if (mimeType == "application/x-qt-plugin" || mimeType == "application/x-qt-styled-widget") {
        object = m_webFrame->page()->createPlugin(classid, qurl, params, values);
#ifndef QT_NO_STYLE_STYLESHEET
        QWidget* widget = qobject_cast<QWidget*>(object);
        if (widget && mimeType == "application/x-qt-styled-widget") {

            QString styleSheet = element->getAttribute("style");
            if (!styleSheet.isEmpty())
                styleSheet += QLatin1Char(';');

            for (unsigned i = 0; i < numqStyleSheetProperties; ++i) {
                CSSPropertyID property = qstyleSheetProperties[i];

                styleSheet += QString::fromLatin1(::getPropertyName(property));
                styleSheet += QLatin1Char(':');
                styleSheet += computedStyle(element)->getPropertyValue(property);
                styleSheet += QLatin1Char(';');
            }

            widget->setStyleSheet(styleSheet);
        }
#endif // QT_NO_STYLE_STYLESHEET
    }

        if (!object) {
            QWebPluginFactory* factory = m_webFrame->page()->pluginFactory();
            if (factory)
                object = factory->create(mimeType, qurl, params, values);
        }

        if (object) {
            QWidget* widget = qobject_cast<QWidget*>(object);
            if (widget) {
                QWidget* parentWidget = 0;
                if (m_webFrame->page()->d->client)
                    parentWidget = qobject_cast<QWidget*>(m_webFrame->page()->d->client->pluginParent());
                if (parentWidget) // don't reparent to nothing (i.e. keep whatever parent QWebPage::createPlugin() chose.
                    widget->setParent(parentWidget);
                widget->hide();
                RefPtr<QtPluginWidget> w = adoptRef(new QtPluginWidget());
                w->setPlatformWidget(widget);
                // Make sure it's invisible until properly placed into the layout
                w->setFrameRect(IntRect(0, 0, 0, 0));
                return w;
            }
#if QT_VERSION >= 0x040600
            QGraphicsWidget* graphicsWidget = qobject_cast<QGraphicsWidget*>(object);
            if (graphicsWidget) {
                QGraphicsObject* parentWidget = 0;
                if (m_webFrame->page()->d->client)
                    parentWidget = qobject_cast<QGraphicsObject*>(m_webFrame->page()->d->client->pluginParent());
                graphicsWidget->hide();
                if (parentWidget) // don't reparent to nothing (i.e. keep whatever parent QWebPage::createPlugin() chose.
                    graphicsWidget->setParentItem(parentWidget);
                RefPtr<QtPluginGraphicsWidget> w = QtPluginGraphicsWidget::create(graphicsWidget);
                // Make sure it's invisible until properly placed into the layout
                w->setFrameRect(IntRect(0, 0, 0, 0));
                return w;
            }
#endif
            // FIXME: make things work for widgetless plugins as well
            delete object;
    } else { // NPAPI Plugins
        Vector<String> params = paramNames;
        Vector<String> values = paramValues;
        if (mimeType == "application/x-shockwave-flash") {
            QWebPageClient* client = m_webFrame->page()->d->client;
            const bool isQWebView = client && qobject_cast<QWidget*>(client->pluginParent());
#if defined(MOZ_PLATFORM_MAEMO) && (MOZ_PLATFORM_MAEMO == 5)
            size_t wmodeIndex = params.find("wmode");
            if (wmodeIndex == -1) {
                // Disable XEmbed mode and force it to opaque mode
                params.append("wmode");
                values.append("opaque");
            } else if (!isQWebView) {
                // Disable transparency if client is not a QWebView
                values[wmodeIndex] = "opaque";
            }
#else
            if (!isQWebView) {
                // inject wmode=opaque when there is no client or the client is not a QWebView
                size_t wmodeIndex = params.find("wmode");
                if (wmodeIndex == -1) {
                    params.append("wmode");
                    values.append("opaque");
                } else
                    values[wmodeIndex] = "opaque";
            }
#endif
        }

        RefPtr<PluginView> pluginView = PluginView::create(m_frame, pluginSize, element, url,
            params, values, mimeType, loadManually);
        return pluginView;
    }

    return 0;
}