diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/corelib/ipc/ipc.pro | 2 | ||||
-rw-r--r-- | examples/corelib/threads/mandelbrot/mandelbrot.pro | 2 | ||||
-rw-r--r-- | examples/corelib/tools/customtype/message.cpp | 3 | ||||
-rw-r--r-- | examples/opengl/hellowindow/hellowindow.cpp | 16 | ||||
-rw-r--r-- | examples/opengl/hellowindow/hellowindow.h | 4 | ||||
-rw-r--r-- | examples/opengl/hellowindow/main.cpp | 18 | ||||
-rw-r--r-- | examples/opengl/qopenglwindow/background.frag | 13 | ||||
-rw-r--r-- | examples/opengl/qopenglwindow/background_renderer.cpp | 16 | ||||
-rw-r--r-- | examples/opengl/qopenglwindow/main.cpp | 2 | ||||
-rw-r--r-- | examples/widgets/gestures/imagegestures/imagewidget.cpp | 4 | ||||
-rw-r--r-- | examples/widgets/gestures/imagegestures/main.cpp | 9 | ||||
-rw-r--r-- | examples/widgets/itemviews/chart/chart.pro | 2 | ||||
-rw-r--r-- | examples/widgets/painting/painterpaths/painterpaths.pro | 2 |
13 files changed, 57 insertions, 36 deletions
diff --git a/examples/corelib/ipc/ipc.pro b/examples/corelib/ipc/ipc.pro index 4b4b3870a4..5fc3c7457f 100644 --- a/examples/corelib/ipc/ipc.pro +++ b/examples/corelib/ipc/ipc.pro @@ -2,5 +2,5 @@ requires(qtHaveModule(widgets)) TEMPLATE = subdirs # no QSharedMemory -!vxworks:!qnx:SUBDIRS = sharedmemory +!vxworks:SUBDIRS = sharedmemory !wince*:qtHaveModule(network): SUBDIRS += localfortuneserver localfortuneclient diff --git a/examples/corelib/threads/mandelbrot/mandelbrot.pro b/examples/corelib/threads/mandelbrot/mandelbrot.pro index 5a01a405f2..92010fdc1f 100644 --- a/examples/corelib/threads/mandelbrot/mandelbrot.pro +++ b/examples/corelib/threads/mandelbrot/mandelbrot.pro @@ -6,7 +6,7 @@ SOURCES = main.cpp \ mandelbrotwidget.cpp \ renderthread.cpp -unix:!mac:!vxworks:!integrity:LIBS += -lm +unix:!mac:!vxworks:!integrity:!haiku:LIBS += -lm # install target.path = $$[QT_INSTALL_EXAMPLES]/corelib/threads/mandelbrot diff --git a/examples/corelib/tools/customtype/message.cpp b/examples/corelib/tools/customtype/message.cpp index c470ab116e..eb8befc36f 100644 --- a/examples/corelib/tools/customtype/message.cpp +++ b/examples/corelib/tools/customtype/message.cpp @@ -65,7 +65,8 @@ Message::Message(const QString &body, const QStringList &headers) //! [custom type streaming operator] QDebug operator<<(QDebug dbg, const Message &message) { - QStringList pieces = message.body().split("\r\n", QString::SkipEmptyParts); + const QString body = message.body(); + QVector<QStringRef> pieces = body.splitRef("\r\n", QString::SkipEmptyParts); if (pieces.isEmpty()) dbg.nospace() << "Message()"; else if (pieces.size() == 1) diff --git a/examples/opengl/hellowindow/hellowindow.cpp b/examples/opengl/hellowindow/hellowindow.cpp index 57eb111edb..ac5bfea280 100644 --- a/examples/opengl/hellowindow/hellowindow.cpp +++ b/examples/opengl/hellowindow/hellowindow.cpp @@ -56,9 +56,14 @@ Renderer::Renderer(const QSurfaceFormat &format, Renderer *share, QScreen *scree if (share) m_context->setShareContext(share->m_context); m_context->create(); + + m_backgroundColor = QColor::fromRgbF(0.1f, 0.1f, 0.2f, 1.0f); + m_backgroundColor.setRed(qrand() % 64); + m_backgroundColor.setGreen(qrand() % 128); + m_backgroundColor.setBlue(qrand() % 256); } -HelloWindow::HelloWindow(const QSharedPointer<Renderer> &renderer) +HelloWindow::HelloWindow(const QSharedPointer<Renderer> &renderer, QScreen *screen) : m_colorIndex(0), m_renderer(renderer) { setSurfaceType(QWindow::OpenGLSurface); @@ -67,6 +72,8 @@ HelloWindow::HelloWindow(const QSharedPointer<Renderer> &renderer) setGeometry(QRect(10, 10, 640, 480)); setFormat(renderer->format()); + if (screen) + setScreen(screen); create(); @@ -147,7 +154,7 @@ void Renderer::render() f->glViewport(0, 0, viewSize.width() * surface->devicePixelRatio(), viewSize.height() * surface->devicePixelRatio()); f->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - f->glClearColor(0.1f, 0.1f, 0.2f, 1.0f); + f->glClearColor(m_backgroundColor.redF(), m_backgroundColor.greenF(), m_backgroundColor.blueF(), m_backgroundColor.alphaF()); f->glFrontFace(GL_CW); f->glCullFace(GL_FRONT); f->glEnable(GL_CULL_FACE); @@ -180,8 +187,13 @@ void Renderer::render() QTimer::singleShot(0, this, SLOT(render())); } +Q_GLOBAL_STATIC(QMutex, initMutex) + void Renderer::initialize() { + // Threaded shader compilation can confuse some drivers. Avoid it. + QMutexLocker lock(initMutex()); + QOpenGLShader *vshader = new QOpenGLShader(QOpenGLShader::Vertex, this); vshader->compileSourceCode( "attribute highp vec4 vertex;" diff --git a/examples/opengl/hellowindow/hellowindow.h b/examples/opengl/hellowindow/hellowindow.h index 6a6fa275e2..cba4b34db6 100644 --- a/examples/opengl/hellowindow/hellowindow.h +++ b/examples/opengl/hellowindow/hellowindow.h @@ -90,12 +90,14 @@ private: int m_currentWindow; QMutex m_windowLock; + + QColor m_backgroundColor; }; class HelloWindow : public QWindow { public: - explicit HelloWindow(const QSharedPointer<Renderer> &renderer); + explicit HelloWindow(const QSharedPointer<Renderer> &renderer, QScreen *screen = 0); QColor color() const; void updateColor(); diff --git a/examples/opengl/hellowindow/main.cpp b/examples/opengl/hellowindow/main.cpp index 62b6bfca3f..e7ad9722c2 100644 --- a/examples/opengl/hellowindow/main.cpp +++ b/examples/opengl/hellowindow/main.cpp @@ -50,7 +50,9 @@ int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); + // Some platforms can only have one window per screen. Therefore we need to differentiate. const bool multipleWindows = QGuiApplication::arguments().contains(QStringLiteral("--multiple")); + const bool multipleScreens = QGuiApplication::arguments().contains(QStringLiteral("--multiscreen")); QScreen *screen = QGuiApplication::primaryScreen(); @@ -93,12 +95,13 @@ int main(int argc, char *argv[]) windowC->setTitle(QStringLiteral("Thread B - Context B")); windowC->setVisible(true); windows.prepend(windowC); - + } + if (multipleScreens) { for (int i = 1; i < QGuiApplication::screens().size(); ++i) { QScreen *screen = QGuiApplication::screens().at(i); QSharedPointer<Renderer> renderer(new Renderer(format, rendererA.data(), screen)); - renderThread = new QThread; + QThread *renderThread = new QThread; renderer->moveToThread(renderThread); renderThreads.prepend(renderThread); @@ -107,8 +110,7 @@ int main(int argc, char *argv[]) QSize windowSize = screenGeometry.size() * 0.8; - HelloWindow *window = new HelloWindow(renderer); - window->setScreen(screen); + HelloWindow *window = new HelloWindow(renderer, screen); window->setGeometry(QRect(center, windowSize).translated(-windowSize.width() / 2, -windowSize.height() / 2)); QChar id = QChar('B' + i); @@ -123,10 +125,16 @@ int main(int argc, char *argv[]) renderThreads.at(i)->start(); } + // Quit after 10 seconds. For platforms that do not have windows that are closeable. + if (QCoreApplication::arguments().contains(QStringLiteral("--timeout"))) + QTimer::singleShot(10000, qGuiApp, SLOT(quit())); + const int exitValue = app.exec(); - for (int i = 0; i < renderThreads.size(); ++i) + for (int i = 0; i < renderThreads.size(); ++i) { + renderThreads.at(i)->quit(); // some platforms may not have windows to close so ensure quit() renderThreads.at(i)->wait(); + } qDeleteAll(windows); qDeleteAll(renderThreads); diff --git a/examples/opengl/qopenglwindow/background.frag b/examples/opengl/qopenglwindow/background.frag index 572c941f08..eecb6d3120 100644 --- a/examples/opengl/qopenglwindow/background.frag +++ b/examples/opengl/qopenglwindow/background.frag @@ -1,3 +1,6 @@ +#define M_PI 3.1415926535897932384626433832795 +#define SPEED 10000.0 + uniform int currentTime; uniform highp vec2 windowSize; @@ -8,18 +11,20 @@ highp float noise(highp vec2 co) highp float curvSpeed() { - return mod(float(currentTime), 1000000.0) / 500.0; + return (mod(float(currentTime), SPEED) / SPEED) * (2.0 * M_PI); } -highp float curv() +highp float curv(int curvCount) { - return 1.0 - abs((gl_FragCoord.y / (windowSize.y / 10.0) - 5.0) - sin((gl_FragCoord.x / (windowSize.x/20.0)) - curvSpeed())); + highp float curv_y = 0.1 *(cos((gl_FragCoord.x / windowSize.x) * (float(curvCount * 2) * M_PI) - curvSpeed())) + 0.5; + highp float frag_y = gl_FragCoord.y / windowSize.y; + return 1.0 - abs(curv_y - frag_y); } void main() { highp float coordNoise = noise(gl_FragCoord.xy); - highp float proximity = smoothstep(0.5, 1.0, (curv() + 1.0) * (coordNoise )); + highp float proximity = smoothstep(0.85, 1.0, (curv(6) + 1.0) * (coordNoise )); highp vec3 color = vec3(coordNoise) * proximity; gl_FragColor = vec4(color, 1.0); } diff --git a/examples/opengl/qopenglwindow/background_renderer.cpp b/examples/opengl/qopenglwindow/background_renderer.cpp index 2c830ac13c..01807866d4 100644 --- a/examples/opengl/qopenglwindow/background_renderer.cpp +++ b/examples/opengl/qopenglwindow/background_renderer.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the examples of the Qt Toolkit. @@ -75,8 +75,8 @@ FragmentToy::FragmentToy(const QString &fragmentSource, QObject *parent) m_fragment_file_last_modified = info.lastModified(); m_fragment_file = fragmentSource; #ifndef QT_NO_FILESYSTEMWATCHER - m_watcher.addPath(info.canonicalFilePath()); - QObject::connect(&m_watcher, &QFileSystemWatcher::fileChanged, this, &FragmentToy::fileChanged); + m_watcher.addPath(info.canonicalPath()); + QObject::connect(&m_watcher, &QFileSystemWatcher::directoryChanged, this, &FragmentToy::fileChanged); #endif } } @@ -94,7 +94,7 @@ void FragmentToy::draw(const QSize &windowSize) if (!m_vao.isCreated()) m_vao.create(); - m_vao.bind(); + QOpenGLVertexArrayObject::Binder binder(&m_vao); if (!m_vertex_buffer.isCreated()) { m_vertex_buffer.create(); @@ -115,7 +115,7 @@ void FragmentToy::draw(const QSize &windowSize) } } - if (!m_fragment_shader) { + if (!m_fragment_shader && m_recompile_shaders) { QByteArray data; if (m_fragment_file.size()) { QFile file(m_fragment_file); @@ -160,6 +160,9 @@ void FragmentToy::draw(const QSize &windowSize) } + if (!m_program->isLinked()) + return; + m_program->bind(); m_vertex_buffer.bind(); @@ -167,15 +170,12 @@ void FragmentToy::draw(const QSize &windowSize) m_program->enableAttributeArray("vertexCoord"); m_vertex_buffer.release(); - float radiens = (QTime::currentTime().msecsSinceStartOfDay() / 60) / (2 * M_PI); m_program->setUniformValue("currentTime", (uint) QDateTime::currentDateTime().toMSecsSinceEpoch()); - m_program->setUniformValue("radiens", radiens); m_program->setUniformValue("windowSize", windowSize); QOpenGLContext::currentContext()->functions()->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); m_program->release(); - m_vao.release(); } void FragmentToy::fileChanged(const QString &path) diff --git a/examples/opengl/qopenglwindow/main.cpp b/examples/opengl/qopenglwindow/main.cpp index bf95d09ecd..996feb5e96 100644 --- a/examples/opengl/qopenglwindow/main.cpp +++ b/examples/opengl/qopenglwindow/main.cpp @@ -97,7 +97,7 @@ private: // typical in pure QWindow-based applications. OpenGLWindow::OpenGLWindow() : QOpenGLWindow(QOpenGLWindow::NoPartialUpdate) - , m_fragment_toy("background.frag") + , m_fragment_toy("./background.frag") , m_text_layout("The triangle and this text is rendered with QPainter") , m_animate(true) { diff --git a/examples/widgets/gestures/imagegestures/imagewidget.cpp b/examples/widgets/gestures/imagegestures/imagewidget.cpp index 57c2af4502..81783f211d 100644 --- a/examples/widgets/gestures/imagegestures/imagewidget.cpp +++ b/examples/widgets/gestures/imagegestures/imagewidget.cpp @@ -108,7 +108,7 @@ void ImageWidget::mouseDoubleClickEvent(QMouseEvent *) //! [gesture event handler] bool ImageWidget::gestureEvent(QGestureEvent *event) { - qCDebug(lcExample) << "gestureEvent():" << event->gestures().size(); + qCDebug(lcExample) << "gestureEvent():" << event; if (QGesture *swipe = event->gesture(Qt::SwipeGesture)) swipeTriggered(static_cast<QSwipeGesture *>(swipe)); else if (QGesture *pan = event->gesture(Qt::PanGesture)) @@ -132,7 +132,7 @@ void ImageWidget::panTriggered(QPanGesture *gesture) } #endif QPointF delta = gesture->delta(); - qCDebug(lcExample) << "panTriggered():" << delta; + qCDebug(lcExample) << "panTriggered():" << gesture; horizontalOffset += delta.x(); verticalOffset += delta.y(); update(); diff --git a/examples/widgets/gestures/imagegestures/main.cpp b/examples/widgets/gestures/imagegestures/main.cpp index 80f275bd5f..5fca0d6895 100644 --- a/examples/widgets/gestures/imagegestures/main.cpp +++ b/examples/widgets/gestures/imagegestures/main.cpp @@ -82,14 +82,7 @@ int main(int argc, char *argv[]) "qt.examples.imagegestures.debug=true\n"); commandLineParser.setApplicationDescription(description); - if (!commandLineParser.parse(QCoreApplication::arguments())) { - showHelp(commandLineParser, commandLineParser.errorText()); - return -1; - } - if (commandLineParser.isSet(helpOption)) { - showHelp(commandLineParser); - return 0; - } + commandLineParser.process(QCoreApplication::arguments()); QStringList arguments = commandLineParser.positionalArguments(); if (!arguments.isEmpty() && !QFileInfo(arguments.front()).isDir()) { diff --git a/examples/widgets/itemviews/chart/chart.pro b/examples/widgets/itemviews/chart/chart.pro index caa28276bc..4b64b01e8a 100644 --- a/examples/widgets/itemviews/chart/chart.pro +++ b/examples/widgets/itemviews/chart/chart.pro @@ -6,7 +6,7 @@ RESOURCES = chart.qrc SOURCES = main.cpp \ mainwindow.cpp \ pieview.cpp -unix:!mac:!vxworks:!integrity:LIBS+= -lm +unix:!mac:!vxworks:!integrity:!haiku:LIBS += -lm # install target.path = $$[QT_INSTALL_EXAMPLES]/widgets/itemviews/chart diff --git a/examples/widgets/painting/painterpaths/painterpaths.pro b/examples/widgets/painting/painterpaths/painterpaths.pro index 2d2db30739..dfff238dd1 100644 --- a/examples/widgets/painting/painterpaths/painterpaths.pro +++ b/examples/widgets/painting/painterpaths/painterpaths.pro @@ -5,7 +5,7 @@ HEADERS = renderarea.h \ SOURCES = main.cpp \ renderarea.cpp \ window.cpp -unix:!mac:!vxworks:!integrity:LIBS += -lm +unix:!mac:!vxworks:!integrity:!haiku:LIBS += -lm # install target.path = $$[QT_INSTALL_EXAMPLES]/widgets/painting/painterpaths |