Port examples/opengl to new connection syntax.

Change-Id: I486a4a2326bf57ec5ea08bccdcef79c3e5553db5
Reviewed-by: Laszlo Agocs <laszlo.agocs@theqtcompany.com>
This commit is contained in:
Friedemann Kleint 2015-08-28 15:16:57 +02:00
parent 4b340402b9
commit c726bc85da
9 changed files with 38 additions and 37 deletions

View File

@ -66,8 +66,8 @@ Window::Window()
setLayout(layout);
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), native, SLOT(animate()));
connect(timer, SIGNAL(timeout()), openGL, SLOT(animate()));
connect(timer, &QTimer::timeout, native, &Widget::animate);
connect(timer, &QTimer::timeout, openGL, &GLWidget::animate);
timer->start(50);
}
//! [0]

View File

@ -221,5 +221,5 @@ void RenderWindow::render()
// only here to make the UI widgets more responsive on slower machines. We
// can afford it since our rendering is so lightweight.
const int interval = 5;
QTimer::singleShot(interval, this, SLOT(render()));
QTimer::singleShot(interval, this, &RenderWindow::render);
}

View File

@ -92,7 +92,7 @@ GLWindow::GLWindow()
rAnim->setLoopCount(-1);
rAnim->start();
QTimer::singleShot(4000, this, SLOT(startSecondStage()));
QTimer::singleShot(4000, this, &GLWindow::startSecondStage);
}
GLWindow::~GLWindow()

View File

@ -119,7 +119,7 @@ void Renderer::setAnimating(HelloWindow *window, bool animating)
if (animating) {
m_windows << window;
if (m_windows.size() == 1)
QTimer::singleShot(0, this, SLOT(render()));
QTimer::singleShot(0, this, &Renderer::render);
} else {
m_currentWindow = 0;
m_windows.removeOne(window);
@ -184,7 +184,7 @@ void Renderer::render()
m_fAngle += 1.0f;
QTimer::singleShot(0, this, SLOT(render()));
QTimer::singleShot(0, this, &Renderer::render);
}
Q_GLOBAL_STATIC(QMutex, initMutex)

View File

@ -121,13 +121,13 @@ int main(int argc, char *argv[])
}
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();
}
// 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()));
QTimer::singleShot(10000, qGuiApp, &QCoreApplication::quit);
const int exitValue = app.exec();

View File

@ -83,9 +83,11 @@ PaintedWindow::PaintedWindow()
m_targetOrientation = contentOrientation();
m_nextTargetOrientation = Qt::PrimaryOrientation;
connect(screen(), SIGNAL(orientationChanged(Qt::ScreenOrientation)), this, SLOT(orientationChanged(Qt::ScreenOrientation)));
connect(m_animation, SIGNAL(finished()), this, SLOT(rotationDone()));
connect(this, SIGNAL(rotationChanged(qreal)), this, SLOT(paint()));
connect(screen(), &QScreen::orientationChanged, this, &PaintedWindow::orientationChanged);
connect(m_animation, &QAbstractAnimation::finished, this, &PaintedWindow::rotationDone);
typedef void (PaintedWindow::*PaintedWindowVoidSlot)();
connect(this, &PaintedWindow::rotationChanged,
this, static_cast<PaintedWindowVoidSlot>(&PaintedWindow::paint));
}
void PaintedWindow::exposeEvent(QExposeEvent *)

View File

@ -51,6 +51,8 @@
#include "glwidget.h"
typedef void (QWidget::*QWidgetVoidSlot)();
MainWindow::MainWindow()
: m_nextX(1), m_nextY(1)
{
@ -107,34 +109,27 @@ MainWindow::MainWindow()
groupBox->setLayout(m_layout);
QMenu *fileMenu = menuBar()->addMenu("&File");
fileMenu->addAction("E&xit", this, &QWidget::close);
QMenu *showMenu = menuBar()->addMenu("&Show");
QMenu *helpMenu = menuBar()->addMenu("&Help");
QAction *exit = new QAction("E&xit", fileMenu);
QAction *aboutQt = new QAction("About Qt", helpMenu);
QAction *showLogo = new QAction("Show 3D Logo", showMenu);
QAction *showTexture = new QAction("Show 2D Texture", showMenu);
QAction *showBubbles = new QAction("Show bubbles", showMenu);
showMenu->addAction("Show 3D Logo", glwidget, &GLWidget::setLogo);
showMenu->addAction("Show 2D Texture", glwidget, &GLWidget::setTexture);
QAction *showBubbles = showMenu->addAction("Show bubbles", glwidget, &GLWidget::setShowBubbles);
showBubbles->setCheckable(true);
showBubbles->setChecked(true);
fileMenu->addAction(exit);
helpMenu->addAction(aboutQt);
showMenu->addAction(showLogo);
showMenu->addAction(showTexture);
showMenu->addAction(showBubbles);
QMenu *helpMenu = menuBar()->addMenu("&Help");
helpMenu->addAction("About Qt", qApp, &QApplication::aboutQt);
connect(exit, SIGNAL(triggered(bool)), this, SLOT(close()));
connect(aboutQt, SIGNAL(triggered(bool)), qApp, SLOT(aboutQt()));
connect(m_timer, &QTimer::timeout,
glwidget, static_cast<QWidgetVoidSlot>(&QWidget::update));
connect(m_timer, SIGNAL(timeout()), glwidget, SLOT(update()));
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(slider, &QAbstractSlider::valueChanged, glwidget, &GLWidget::setScaling);
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, updateInterval, &QWidget::setEnabled);
@ -157,7 +152,7 @@ void MainWindow::addNew()
return;
GLWidget *w = new GLWidget(this, false, qRgb(qrand() % 256, qrand() % 256, qrand() % 256));
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);
if (m_nextX == 3) {
m_nextX = 1;

View File

@ -163,16 +163,20 @@ void OpenGLWindow::keyPressEvent(QKeyEvent *e)
void OpenGLWindow::setAnimating(bool enabled)
{
typedef void (QPaintDeviceWindow::*QPaintDeviceWindowVoidSlot)();
if (enabled) {
// Animate continuously, throttled by the blocking swapBuffers() call the
// QOpenGLWindow internally executes after each paint. Once that is done
// (frameSwapped signal is emitted), we schedule a new update. This
// obviously assumes that the swap interval (see
// QSurfaceFormat::setSwapInterval()) is non-zero.
connect(this, SIGNAL(frameSwapped()), this, SLOT(update()));
connect(this, &QOpenGLWindow::frameSwapped,
this, static_cast<QPaintDeviceWindowVoidSlot>(&QPaintDeviceWindow::update));
update();
} else {
disconnect(this, SIGNAL(frameSwapped()), this, SLOT(update()));
disconnect(this, &QOpenGLWindow::frameSwapped,
this, static_cast<QPaintDeviceWindowVoidSlot>(&QPaintDeviceWindow::update));
}
}

View File

@ -59,8 +59,8 @@ Window::Window()
glWidgets[i][j]->rotateBy(+42 * 16, +42 * 16, -21 * 16);
mainLayout->addWidget(glWidgets[i][j], i, j);
connect(glWidgets[i][j], SIGNAL(clicked()),
this, SLOT(setCurrentGlWidget()));
connect(glWidgets[i][j], &GLWidget::clicked,
this, &Window::setCurrentGlWidget);
}
}
setLayout(mainLayout);
@ -68,7 +68,7 @@ Window::Window()
currentGlWidget = glWidgets[0][0];
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(rotateOneStep()));
connect(timer, &QTimer::timeout, this, &Window::rotateOneStep);
timer->start(20);
setWindowTitle(tr("Textures"));