Better_Software_Header_MobileBetter_Software_Header_Web

Find what you need - explore our website and developer resources

SlideViewer and the Display Window

qmlRegisterType<DisplayWindow>("Cpp", 1, 0, "DisplayWindow");
import Cpp 1.0

ApplicationWindow
{
    id: rootWindow
    ...

    DisplayWindow {
        id: displayWindow
        title: "Presentation Window"
        visible: _settings.showPresentationWindow && !_settings.isPrinting
    }

    ...
}
ApplicationWindow
{
    id: rootWindow
    ...

    ShaderEffectSource {
        id: displayWindowSource
        sourceItem: content
        hideSource: false
        width: sourceItem ? sourceItem.width : 0
        height: sourceItem ? sourceItem.height : 0
    }

    DisplayWindow {
        id: displayWindow
        source: displayWindowSource
        title: "Presentation Window"
        visible: _settings.showPresentationWindow && !_settings.isPrinting
    }
}
class DisplayWindow : public QWindow
{
    Q_OBJECT
    Q_PROPERTY(QQuickItem * source READ source WRITE setSource NOTIFY sourceChanged)
    ...

    void setSource(QQuickItem *source);
    QQuickItem * source() const;

    int currentScreen() const;

signals:
    void sourceChanged();

private:
    QQuickItem *m_source = nullptr;
};
QQuickWindow * const newWindow = m_source ? m_source->window() : nullptr;
connect(newWindow, &QQuickWindow::afterRendering,
        this, &DisplayWindow::update, Qt::DirectConnection);
auto * const window = m_source->window();
Q_ASSERT(window);
if (!m_context) {
    m_context.reset(new QOpenGLContext);
    m_context->setFormat(window->openglContext()->format());
    m_context->setShareContext(window->openglContext());
    m_context->create();
}
const QQuickShaderEffectSource * const sourceItem = qobject_cast(m_source);
const QSGTextureProvider * const provider = sourceItem->textureProvider();
const QSGTexture * const texture = provider->texture();
const GLint textureId = texture->textureId();
m_program->bind();
m_positions.bind();
...
m_indexBuffer.bind();

glBindTexture(GL_TEXTURE_2D, textureId);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
m_program->setUniformValue("texture0", 0);

glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
m_context->swapBuffers(this);
m_context->doneCurrent();

About KDAB


SeanHarmer

Sean Harmer

Managing Director KDAB UK