Port examples/opengl to new connection syntax.
Change-Id: I486a4a2326bf57ec5ea08bccdcef79c3e5553db5 Reviewed-by: Laszlo Agocs <laszlo.agocs@theqtcompany.com>
This commit is contained in:
parent
4b340402b9
commit
c726bc85da
@ -66,8 +66,8 @@ Window::Window()
|
|||||||
setLayout(layout);
|
setLayout(layout);
|
||||||
|
|
||||||
QTimer *timer = new QTimer(this);
|
QTimer *timer = new QTimer(this);
|
||||||
connect(timer, SIGNAL(timeout()), native, SLOT(animate()));
|
connect(timer, &QTimer::timeout, native, &Widget::animate);
|
||||||
connect(timer, SIGNAL(timeout()), openGL, SLOT(animate()));
|
connect(timer, &QTimer::timeout, openGL, &GLWidget::animate);
|
||||||
timer->start(50);
|
timer->start(50);
|
||||||
}
|
}
|
||||||
//! [0]
|
//! [0]
|
||||||
|
@ -221,5 +221,5 @@ void RenderWindow::render()
|
|||||||
// only here to make the UI widgets more responsive on slower machines. We
|
// only here to make the UI widgets more responsive on slower machines. We
|
||||||
// can afford it since our rendering is so lightweight.
|
// can afford it since our rendering is so lightweight.
|
||||||
const int interval = 5;
|
const int interval = 5;
|
||||||
QTimer::singleShot(interval, this, SLOT(render()));
|
QTimer::singleShot(interval, this, &RenderWindow::render);
|
||||||
}
|
}
|
||||||
|
@ -92,7 +92,7 @@ GLWindow::GLWindow()
|
|||||||
rAnim->setLoopCount(-1);
|
rAnim->setLoopCount(-1);
|
||||||
rAnim->start();
|
rAnim->start();
|
||||||
|
|
||||||
QTimer::singleShot(4000, this, SLOT(startSecondStage()));
|
QTimer::singleShot(4000, this, &GLWindow::startSecondStage);
|
||||||
}
|
}
|
||||||
|
|
||||||
GLWindow::~GLWindow()
|
GLWindow::~GLWindow()
|
||||||
|
@ -119,7 +119,7 @@ void Renderer::setAnimating(HelloWindow *window, bool animating)
|
|||||||
if (animating) {
|
if (animating) {
|
||||||
m_windows << window;
|
m_windows << window;
|
||||||
if (m_windows.size() == 1)
|
if (m_windows.size() == 1)
|
||||||
QTimer::singleShot(0, this, SLOT(render()));
|
QTimer::singleShot(0, this, &Renderer::render);
|
||||||
} else {
|
} else {
|
||||||
m_currentWindow = 0;
|
m_currentWindow = 0;
|
||||||
m_windows.removeOne(window);
|
m_windows.removeOne(window);
|
||||||
@ -184,7 +184,7 @@ void Renderer::render()
|
|||||||
|
|
||||||
m_fAngle += 1.0f;
|
m_fAngle += 1.0f;
|
||||||
|
|
||||||
QTimer::singleShot(0, this, SLOT(render()));
|
QTimer::singleShot(0, this, &Renderer::render);
|
||||||
}
|
}
|
||||||
|
|
||||||
Q_GLOBAL_STATIC(QMutex, initMutex)
|
Q_GLOBAL_STATIC(QMutex, initMutex)
|
||||||
|
@ -121,13 +121,13 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < renderThreads.size(); ++i) {
|
for (int i = 0; i < renderThreads.size(); ++i) {
|
||||||
QObject::connect(qGuiApp, SIGNAL(lastWindowClosed()), renderThreads.at(i), SLOT(quit()));
|
QObject::connect(qGuiApp, &QGuiApplication::lastWindowClosed, renderThreads.at(i), &QThread::quit);
|
||||||
renderThreads.at(i)->start();
|
renderThreads.at(i)->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Quit after 10 seconds. For platforms that do not have windows that are closeable.
|
// Quit after 10 seconds. For platforms that do not have windows that are closeable.
|
||||||
if (QCoreApplication::arguments().contains(QStringLiteral("--timeout")))
|
if (QCoreApplication::arguments().contains(QStringLiteral("--timeout")))
|
||||||
QTimer::singleShot(10000, qGuiApp, SLOT(quit()));
|
QTimer::singleShot(10000, qGuiApp, &QCoreApplication::quit);
|
||||||
|
|
||||||
const int exitValue = app.exec();
|
const int exitValue = app.exec();
|
||||||
|
|
||||||
|
@ -83,9 +83,11 @@ PaintedWindow::PaintedWindow()
|
|||||||
m_targetOrientation = contentOrientation();
|
m_targetOrientation = contentOrientation();
|
||||||
m_nextTargetOrientation = Qt::PrimaryOrientation;
|
m_nextTargetOrientation = Qt::PrimaryOrientation;
|
||||||
|
|
||||||
connect(screen(), SIGNAL(orientationChanged(Qt::ScreenOrientation)), this, SLOT(orientationChanged(Qt::ScreenOrientation)));
|
connect(screen(), &QScreen::orientationChanged, this, &PaintedWindow::orientationChanged);
|
||||||
connect(m_animation, SIGNAL(finished()), this, SLOT(rotationDone()));
|
connect(m_animation, &QAbstractAnimation::finished, this, &PaintedWindow::rotationDone);
|
||||||
connect(this, SIGNAL(rotationChanged(qreal)), this, SLOT(paint()));
|
typedef void (PaintedWindow::*PaintedWindowVoidSlot)();
|
||||||
|
connect(this, &PaintedWindow::rotationChanged,
|
||||||
|
this, static_cast<PaintedWindowVoidSlot>(&PaintedWindow::paint));
|
||||||
}
|
}
|
||||||
|
|
||||||
void PaintedWindow::exposeEvent(QExposeEvent *)
|
void PaintedWindow::exposeEvent(QExposeEvent *)
|
||||||
|
@ -51,6 +51,8 @@
|
|||||||
|
|
||||||
#include "glwidget.h"
|
#include "glwidget.h"
|
||||||
|
|
||||||
|
typedef void (QWidget::*QWidgetVoidSlot)();
|
||||||
|
|
||||||
MainWindow::MainWindow()
|
MainWindow::MainWindow()
|
||||||
: m_nextX(1), m_nextY(1)
|
: m_nextX(1), m_nextY(1)
|
||||||
{
|
{
|
||||||
@ -107,34 +109,27 @@ MainWindow::MainWindow()
|
|||||||
|
|
||||||
groupBox->setLayout(m_layout);
|
groupBox->setLayout(m_layout);
|
||||||
|
|
||||||
|
|
||||||
QMenu *fileMenu = menuBar()->addMenu("&File");
|
QMenu *fileMenu = menuBar()->addMenu("&File");
|
||||||
|
fileMenu->addAction("E&xit", this, &QWidget::close);
|
||||||
QMenu *showMenu = menuBar()->addMenu("&Show");
|
QMenu *showMenu = menuBar()->addMenu("&Show");
|
||||||
QMenu *helpMenu = menuBar()->addMenu("&Help");
|
showMenu->addAction("Show 3D Logo", glwidget, &GLWidget::setLogo);
|
||||||
QAction *exit = new QAction("E&xit", fileMenu);
|
showMenu->addAction("Show 2D Texture", glwidget, &GLWidget::setTexture);
|
||||||
QAction *aboutQt = new QAction("About Qt", helpMenu);
|
QAction *showBubbles = showMenu->addAction("Show bubbles", glwidget, &GLWidget::setShowBubbles);
|
||||||
QAction *showLogo = new QAction("Show 3D Logo", showMenu);
|
|
||||||
QAction *showTexture = new QAction("Show 2D Texture", showMenu);
|
|
||||||
QAction *showBubbles = new QAction("Show bubbles", showMenu);
|
|
||||||
showBubbles->setCheckable(true);
|
showBubbles->setCheckable(true);
|
||||||
showBubbles->setChecked(true);
|
showBubbles->setChecked(true);
|
||||||
fileMenu->addAction(exit);
|
QMenu *helpMenu = menuBar()->addMenu("&Help");
|
||||||
helpMenu->addAction(aboutQt);
|
helpMenu->addAction("About Qt", qApp, &QApplication::aboutQt);
|
||||||
showMenu->addAction(showLogo);
|
|
||||||
showMenu->addAction(showTexture);
|
|
||||||
showMenu->addAction(showBubbles);
|
|
||||||
|
|
||||||
connect(exit, SIGNAL(triggered(bool)), this, SLOT(close()));
|
connect(m_timer, &QTimer::timeout,
|
||||||
connect(aboutQt, SIGNAL(triggered(bool)), qApp, SLOT(aboutQt()));
|
glwidget, static_cast<QWidgetVoidSlot>(&QWidget::update));
|
||||||
|
|
||||||
connect(m_timer, SIGNAL(timeout()), glwidget, SLOT(update()));
|
connect(slider, &QAbstractSlider::valueChanged, glwidget, &GLWidget::setScaling);
|
||||||
|
|
||||||
connect(showLogo, SIGNAL(triggered(bool)), glwidget, SLOT(setLogo()));
|
|
||||||
connect(showTexture, SIGNAL(triggered(bool)), glwidget, SLOT(setTexture()));
|
|
||||||
connect(showBubbles, SIGNAL(triggered(bool)), glwidget, SLOT(setShowBubbles(bool)));
|
|
||||||
connect(slider, SIGNAL(valueChanged(int)), glwidget, SLOT(setScaling(int)));
|
|
||||||
connect(transparent, &QCheckBox::toggled, glwidget, &GLWidget::setTransparent);
|
connect(transparent, &QCheckBox::toggled, glwidget, &GLWidget::setTransparent);
|
||||||
|
|
||||||
connect(updateInterval, SIGNAL(valueChanged(int)), this, SLOT(updateIntervalChanged(int)));
|
typedef void (QSpinBox::*QSpinBoxIntSignal)(int);
|
||||||
|
connect(updateInterval, static_cast<QSpinBoxIntSignal>(&QSpinBox::valueChanged),
|
||||||
|
this, &MainWindow::updateIntervalChanged);
|
||||||
connect(timerBased, &QCheckBox::toggled, this, &MainWindow::timerUsageChanged);
|
connect(timerBased, &QCheckBox::toggled, this, &MainWindow::timerUsageChanged);
|
||||||
connect(timerBased, &QCheckBox::toggled, updateInterval, &QWidget::setEnabled);
|
connect(timerBased, &QCheckBox::toggled, updateInterval, &QWidget::setEnabled);
|
||||||
|
|
||||||
@ -157,7 +152,7 @@ void MainWindow::addNew()
|
|||||||
return;
|
return;
|
||||||
GLWidget *w = new GLWidget(this, false, qRgb(qrand() % 256, qrand() % 256, qrand() % 256));
|
GLWidget *w = new GLWidget(this, false, qRgb(qrand() % 256, qrand() % 256, qrand() % 256));
|
||||||
m_glWidgets << w;
|
m_glWidgets << w;
|
||||||
connect(m_timer, SIGNAL(timeout()), w, SLOT(update()));
|
connect(m_timer, &QTimer::timeout, w, static_cast<QWidgetVoidSlot>(&QWidget::update));
|
||||||
m_layout->addWidget(w, m_nextY, m_nextX, 1, 1);
|
m_layout->addWidget(w, m_nextY, m_nextX, 1, 1);
|
||||||
if (m_nextX == 3) {
|
if (m_nextX == 3) {
|
||||||
m_nextX = 1;
|
m_nextX = 1;
|
||||||
|
@ -163,16 +163,20 @@ void OpenGLWindow::keyPressEvent(QKeyEvent *e)
|
|||||||
|
|
||||||
void OpenGLWindow::setAnimating(bool enabled)
|
void OpenGLWindow::setAnimating(bool enabled)
|
||||||
{
|
{
|
||||||
|
typedef void (QPaintDeviceWindow::*QPaintDeviceWindowVoidSlot)();
|
||||||
|
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
// Animate continuously, throttled by the blocking swapBuffers() call the
|
// Animate continuously, throttled by the blocking swapBuffers() call the
|
||||||
// QOpenGLWindow internally executes after each paint. Once that is done
|
// QOpenGLWindow internally executes after each paint. Once that is done
|
||||||
// (frameSwapped signal is emitted), we schedule a new update. This
|
// (frameSwapped signal is emitted), we schedule a new update. This
|
||||||
// obviously assumes that the swap interval (see
|
// obviously assumes that the swap interval (see
|
||||||
// QSurfaceFormat::setSwapInterval()) is non-zero.
|
// QSurfaceFormat::setSwapInterval()) is non-zero.
|
||||||
connect(this, SIGNAL(frameSwapped()), this, SLOT(update()));
|
connect(this, &QOpenGLWindow::frameSwapped,
|
||||||
|
this, static_cast<QPaintDeviceWindowVoidSlot>(&QPaintDeviceWindow::update));
|
||||||
update();
|
update();
|
||||||
} else {
|
} else {
|
||||||
disconnect(this, SIGNAL(frameSwapped()), this, SLOT(update()));
|
disconnect(this, &QOpenGLWindow::frameSwapped,
|
||||||
|
this, static_cast<QPaintDeviceWindowVoidSlot>(&QPaintDeviceWindow::update));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,8 +59,8 @@ Window::Window()
|
|||||||
glWidgets[i][j]->rotateBy(+42 * 16, +42 * 16, -21 * 16);
|
glWidgets[i][j]->rotateBy(+42 * 16, +42 * 16, -21 * 16);
|
||||||
mainLayout->addWidget(glWidgets[i][j], i, j);
|
mainLayout->addWidget(glWidgets[i][j], i, j);
|
||||||
|
|
||||||
connect(glWidgets[i][j], SIGNAL(clicked()),
|
connect(glWidgets[i][j], &GLWidget::clicked,
|
||||||
this, SLOT(setCurrentGlWidget()));
|
this, &Window::setCurrentGlWidget);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setLayout(mainLayout);
|
setLayout(mainLayout);
|
||||||
@ -68,7 +68,7 @@ Window::Window()
|
|||||||
currentGlWidget = glWidgets[0][0];
|
currentGlWidget = glWidgets[0][0];
|
||||||
|
|
||||||
QTimer *timer = new QTimer(this);
|
QTimer *timer = new QTimer(this);
|
||||||
connect(timer, SIGNAL(timeout()), this, SLOT(rotateOneStep()));
|
connect(timer, &QTimer::timeout, this, &Window::rotateOneStep);
|
||||||
timer->start(20);
|
timer->start(20);
|
||||||
|
|
||||||
setWindowTitle(tr("Textures"));
|
setWindowTitle(tr("Textures"));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user