diff options
author | Friedemann Kleint <Friedemann.Kleint@theqtcompany.com> | 2014-12-17 13:39:42 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@theqtcompany.com> | 2014-12-17 14:04:57 +0100 |
commit | 1209493113dbf8f43837ee935e705f0776aead38 (patch) | |
tree | 77410c3c389ab157f7ef419b6f24e76e5ba1796a | |
parent | 8a13b5fdd462ee7e064c6f6d565424de5d0a82d1 (diff) |
Use Qt 5 signals & slot syntax.
Change-Id: I548076eebc2c8f1204ef76bb4e6e09ed00352553
Reviewed-by: J-P Nurmi <jpnurmi@theqtcompany.com>
-rw-r--r-- | examples/winextras/musicplayer/musicplayer.cpp | 55 | ||||
-rw-r--r-- | examples/winextras/musicplayer/volumebutton.cpp | 6 | ||||
-rw-r--r-- | src/imports/winextras/qquickjumplist.cpp | 12 | ||||
-rw-r--r-- | src/imports/winextras/qquickthumbnailtoolbutton.cpp | 2 | ||||
-rw-r--r-- | src/winextras/qwinthumbnailtoolbar.cpp | 10 | ||||
-rw-r--r-- | src/winextras/qwinthumbnailtoolbar.h | 3 | ||||
-rw-r--r-- | tests/manual/dwmfeatures/testwidget.cpp | 25 | ||||
-rw-r--r-- | tests/manual/jumplist/testwidget.cpp | 6 | ||||
-rw-r--r-- | tests/manual/thumbnail/main.cpp | 12 |
9 files changed, 70 insertions, 61 deletions
diff --git a/examples/winextras/musicplayer/musicplayer.cpp b/examples/winextras/musicplayer/musicplayer.cpp index c44d387..ddc8929 100644 --- a/examples/winextras/musicplayer/musicplayer.cpp +++ b/examples/winextras/musicplayer/musicplayer.cpp @@ -56,12 +56,15 @@ MusicPlayer::MusicPlayer(QWidget *parent) : QWidget(parent), createTaskbar(); createThumbnailToolBar(); - connect(&mediaPlayer, SIGNAL(positionChanged(qint64)), this, SLOT(updatePosition(qint64))); - connect(&mediaPlayer, SIGNAL(durationChanged(qint64)), this, SLOT(updateDuration(qint64))); - connect(&mediaPlayer, SIGNAL(metaDataAvailableChanged(bool)), this, SLOT(updateInfo())); - connect(&mediaPlayer, SIGNAL(error(QMediaPlayer::Error)), this, SLOT(handleError())); - connect(&mediaPlayer, SIGNAL(stateChanged(QMediaPlayer::State)), - this, SLOT(updateState(QMediaPlayer::State))); + connect(&mediaPlayer, &QMediaPlayer::positionChanged, this, &MusicPlayer::updatePosition); + connect(&mediaPlayer, &QMediaPlayer::durationChanged, this, &MusicPlayer::updateDuration); + connect(&mediaPlayer, &QMediaObject::metaDataAvailableChanged, this, &MusicPlayer::updateInfo); + + typedef void(QMediaPlayer::*ErrorSignal)(QMediaPlayer::Error); + connect(&mediaPlayer, static_cast<ErrorSignal>(&QMediaPlayer::error), + this, &MusicPlayer::handleError); + connect(&mediaPlayer, &QMediaPlayer::stateChanged, + this, &MusicPlayer::updateState); stylize(); } @@ -247,23 +250,23 @@ void MusicPlayer::createWidgets() playButton->setEnabled(false); playButton->setToolTip(tr("Play")); playButton->setIcon(style()->standardIcon(QStyle::SP_MediaPlay)); - connect(playButton, SIGNAL(clicked()), this, SLOT(togglePlayback())); + connect(playButton, &QAbstractButton::clicked, this, &MusicPlayer::togglePlayback); QAbstractButton *openButton = new QToolButton(this); openButton->setText(tr("...")); openButton->setToolTip(tr("Open a file...")); openButton->setFixedSize(playButton->sizeHint()); - connect(openButton, SIGNAL(clicked()), this, SLOT(openFile())); + connect(openButton, &QAbstractButton::clicked, this, &MusicPlayer::openFile); volumeButton = new VolumeButton(this); volumeButton->setToolTip(tr("Adjust volume")); volumeButton->setVolume(mediaPlayer.volume()); - connect(volumeButton, SIGNAL(volumeChanged(int)), &mediaPlayer, SLOT(setVolume(int))); + connect(volumeButton, &VolumeButton::volumeChanged, &mediaPlayer, &QMediaPlayer::setVolume); positionSlider = new QSlider(Qt::Horizontal, this); positionSlider->setEnabled(false); positionSlider->setToolTip(tr("Seek")); - connect(positionSlider, SIGNAL(valueChanged(int)), this, SLOT(setPosition(int))); + connect(positionSlider, &QAbstractSlider::valueChanged, this, &MusicPlayer::setPosition); infoLabel = new QLabel(this); positionLabel = new QLabel(tr("00:00"), this); @@ -285,25 +288,25 @@ void MusicPlayer::createWidgets() void MusicPlayer::createShortcuts() { QShortcut *quitShortcut = new QShortcut(QKeySequence::Quit, this); - connect(quitShortcut, SIGNAL(activated()), qApp, SLOT(quit())); + connect(quitShortcut, &QShortcut::activated, QCoreApplication::quit); QShortcut *openShortcut = new QShortcut(QKeySequence::Open, this); - connect(openShortcut, SIGNAL(activated()), this, SLOT(openFile())); + connect(openShortcut, &QShortcut::activated, this, &MusicPlayer::openFile); QShortcut *toggleShortcut = new QShortcut(Qt::Key_Space, this); - connect(toggleShortcut, SIGNAL(activated()), this, SLOT(togglePlayback())); + connect(toggleShortcut, &QShortcut::activated, this, &MusicPlayer::togglePlayback); QShortcut *forwardShortcut = new QShortcut(Qt::Key_Right, this); - connect(forwardShortcut, SIGNAL(activated()), this, SLOT(seekForward())); + connect(forwardShortcut, &QShortcut::activated, this, &MusicPlayer::seekForward); QShortcut *backwardShortcut = new QShortcut(Qt::Key_Left, this); - connect(backwardShortcut, SIGNAL(activated()), this, SLOT(seekBackward())); + connect(backwardShortcut, &QShortcut::activated, this, &MusicPlayer::seekBackward); QShortcut *increaseShortcut = new QShortcut(Qt::Key_Up, this); - connect(increaseShortcut, SIGNAL(activated()), volumeButton, SLOT(increaseVolume())); + connect(increaseShortcut, &QShortcut::activated, volumeButton, &VolumeButton::increaseVolume); QShortcut *decreaseShortcut = new QShortcut(Qt::Key_Down, this); - connect(decreaseShortcut, SIGNAL(activated()), volumeButton, SLOT(descreaseVolume())); + connect(decreaseShortcut, &QShortcut::activated, volumeButton, &VolumeButton::descreaseVolume); } //! [4] @@ -321,10 +324,10 @@ void MusicPlayer::createTaskbar() taskbarButton->setWindow(windowHandle()); taskbarProgress = taskbarButton->progress(); - connect(positionSlider, SIGNAL(valueChanged(int)), taskbarProgress, SLOT(setValue(int))); - connect(positionSlider, SIGNAL(rangeChanged(int,int)), taskbarProgress, SLOT(setRange(int,int))); + connect(positionSlider, &QAbstractSlider::valueChanged, taskbarProgress, &QWinTaskbarProgress::setValue); + connect(positionSlider, &QAbstractSlider::rangeChanged, taskbarProgress, &QWinTaskbarProgress::setRange); - connect(&mediaPlayer, SIGNAL(stateChanged(QMediaPlayer::State)), this, SLOT(updateTaskbar())); + connect(&mediaPlayer, &QMediaPlayer::stateChanged, this, &MusicPlayer::updateTaskbar); } //! [5] @@ -338,26 +341,26 @@ void MusicPlayer::createThumbnailToolBar() playToolButton->setEnabled(false); playToolButton->setToolTip(tr("Play")); playToolButton->setIcon(style()->standardIcon(QStyle::SP_MediaPlay)); - connect(playToolButton, SIGNAL(clicked()), this, SLOT(togglePlayback())); + connect(playToolButton, &QWinThumbnailToolButton::clicked, this, &MusicPlayer::togglePlayback); forwardToolButton = new QWinThumbnailToolButton(thumbnailToolBar); forwardToolButton->setEnabled(false); forwardToolButton->setToolTip(tr("Fast forward")); forwardToolButton->setIcon(style()->standardIcon(QStyle::SP_MediaSeekForward)); - connect(forwardToolButton, SIGNAL(clicked()), this, SLOT(seekForward())); + connect(forwardToolButton, &QWinThumbnailToolButton::clicked, this, &MusicPlayer::seekForward); backwardToolButton = new QWinThumbnailToolButton(thumbnailToolBar); backwardToolButton->setEnabled(false); backwardToolButton->setToolTip(tr("Rewind")); backwardToolButton->setIcon(style()->standardIcon(QStyle::SP_MediaSeekBackward)); - connect(backwardToolButton, SIGNAL(clicked()), this, SLOT(seekBackward())); + connect(backwardToolButton, &QWinThumbnailToolButton::clicked, this, &MusicPlayer::seekBackward); thumbnailToolBar->addButton(backwardToolButton); thumbnailToolBar->addButton(playToolButton); thumbnailToolBar->addButton(forwardToolButton); - connect(&mediaPlayer, SIGNAL(positionChanged(qint64)), this, SLOT(updateThumbnailToolBar())); - connect(&mediaPlayer, SIGNAL(durationChanged(qint64)), this, SLOT(updateThumbnailToolBar())); - connect(&mediaPlayer, SIGNAL(stateChanged(QMediaPlayer::State)), this, SLOT(updateThumbnailToolBar())); + connect(&mediaPlayer, &QMediaPlayer::positionChanged, this, &MusicPlayer::updateThumbnailToolBar); + connect(&mediaPlayer, &QMediaPlayer::durationChanged, this, &MusicPlayer::updateThumbnailToolBar); + connect(&mediaPlayer, &QMediaPlayer::stateChanged, this, &MusicPlayer::updateThumbnailToolBar); } //! [6] diff --git a/examples/winextras/musicplayer/volumebutton.cpp b/examples/winextras/musicplayer/volumebutton.cpp index 5fe940c..b419a0f 100644 --- a/examples/winextras/musicplayer/volumebutton.cpp +++ b/examples/winextras/musicplayer/volumebutton.cpp @@ -53,13 +53,15 @@ VolumeButton::VolumeButton(QWidget *parent) : slider = new QSlider(Qt::Horizontal, popup); slider->setRange(0, 100); - connect(slider, SIGNAL(valueChanged(int)), this, SIGNAL(volumeChanged(int))); + connect(slider, &QAbstractSlider::valueChanged, this, &VolumeButton::volumeChanged); label = new QLabel(popup); label->setAlignment(Qt::AlignCenter); label->setNum(100); label->setMinimumWidth(label->sizeHint().width()); - connect(slider, SIGNAL(valueChanged(int)), label, SLOT(setNum(int))); + + typedef void(QLabel::*IntSlot)(int); + connect(slider, &QAbstractSlider::valueChanged, label, static_cast<IntSlot>(&QLabel::setNum)); QBoxLayout *popupLayout = new QHBoxLayout(popup); popupLayout->setMargin(2); diff --git a/src/imports/winextras/qquickjumplist.cpp b/src/imports/winextras/qquickjumplist.cpp index 49879b2..49bf067 100644 --- a/src/imports/winextras/qquickjumplist.cpp +++ b/src/imports/winextras/qquickjumplist.cpp @@ -78,7 +78,7 @@ QQuickJumpListCategory *QQuickJumpList::recent() const if (!m_recent) { QQuickJumpList *that = const_cast<QQuickJumpList *>(this); that->m_recent = new QQuickJumpListCategory(that); - connect(m_recent, SIGNAL(visibilityChanged()), that, SLOT(rebuild())); + connect(m_recent, &QQuickJumpListCategory::visibilityChanged, that, &QQuickJumpList::rebuild); m_recent->setVisible(false); } return m_recent; @@ -95,7 +95,7 @@ QQuickJumpListCategory *QQuickJumpList::frequent() const if (!m_frequent) { QQuickJumpList *that = const_cast<QQuickJumpList *>(this); that->m_frequent = new QQuickJumpListCategory(that); - connect(m_frequent, SIGNAL(visibilityChanged()), that, SLOT(rebuild())); + connect(m_frequent, &QQuickJumpListCategory::visibilityChanged, that, &QQuickJumpList::rebuild); m_frequent->setVisible(false); } return m_frequent; @@ -111,7 +111,7 @@ QQuickJumpListCategory *QQuickJumpList::tasks() const if (!m_tasks) { QQuickJumpList *that = const_cast<QQuickJumpList *>(this); that->m_tasks = new QQuickJumpListCategory(that); - connect(m_tasks, SIGNAL(visibilityChanged()), that, SLOT(rebuild())); + connect(m_tasks, &QQuickJumpListCategory::visibilityChanged, that, &QQuickJumpList::rebuild); } return m_tasks; } @@ -120,11 +120,11 @@ void QQuickJumpList::setTasks(QQuickJumpListCategory *tasks) { if (m_tasks != tasks) { if (m_tasks) - disconnect(m_tasks, SIGNAL(visibilityChanged()), this, SLOT(rebuild())); + disconnect(m_tasks, &QQuickJumpListCategory::visibilityChanged, this, &QQuickJumpList::rebuild); delete m_tasks; m_tasks = tasks; if (m_tasks) - connect(m_tasks, SIGNAL(visibilityChanged()), this, SLOT(rebuild())); + connect(m_tasks, &QQuickJumpListCategory::visibilityChanged, this, &QQuickJumpList::rebuild); emit tasksChanged(); } } @@ -177,7 +177,7 @@ void QQuickJumpList::data_append(QQmlListProperty<QObject> *property, QObject *o { if (QQuickJumpListCategory *category = qobject_cast<QQuickJumpListCategory *>(object)) { QQuickJumpList *jumpList = static_cast<QQuickJumpList *>(property->object); - connect(category, SIGNAL(visibilityChanged()), jumpList, SLOT(rebuild())); + connect(category, &QQuickJumpListCategory::visibilityChanged, jumpList, &QQuickJumpList::rebuild); jumpList->m_categories.append(category); emit jumpList->categoriesChanged(); } diff --git a/src/imports/winextras/qquickthumbnailtoolbutton.cpp b/src/imports/winextras/qquickthumbnailtoolbutton.cpp index cc7a771..8beafbd 100644 --- a/src/imports/winextras/qquickthumbnailtoolbutton.cpp +++ b/src/imports/winextras/qquickthumbnailtoolbutton.cpp @@ -58,7 +58,7 @@ QT_BEGIN_NAMESPACE QQuickThumbnailToolButton::QQuickThumbnailToolButton(QObject *parent) : QObject(parent), m_button(new QWinThumbnailToolButton(this)) { - connect(m_button, SIGNAL(clicked()), SIGNAL(clicked())); + connect(m_button, &QWinThumbnailToolButton::clicked, this, &QQuickThumbnailToolButton::clicked); } QQuickThumbnailToolButton::~QQuickThumbnailToolButton() diff --git a/src/winextras/qwinthumbnailtoolbar.cpp b/src/winextras/qwinthumbnailtoolbar.cpp index 5a208d4..2aaa69f 100644 --- a/src/winextras/qwinthumbnailtoolbar.cpp +++ b/src/winextras/qwinthumbnailtoolbar.cpp @@ -161,7 +161,8 @@ void QWinThumbnailToolBar::addButton(QWinThumbnailToolButton *button) button->d_func()->toolbar->removeButton(button); } button->d_func()->toolbar = this; - connect(button, SIGNAL(changed()), this, SLOT(_q_scheduleUpdate())); + connect(button, &QWinThumbnailToolButton::changed, + d, &QWinThumbnailToolBarPrivate::_q_scheduleUpdate); d->buttonList.append(button); d->_q_scheduleUpdate(); } @@ -175,7 +176,9 @@ void QWinThumbnailToolBar::removeButton(QWinThumbnailToolButton *button) Q_D(QWinThumbnailToolBar); if (button && d->buttonList.contains(button)) { button->d_func()->toolbar = 0; - disconnect(button, SIGNAL(changed()), this, SLOT(_q_scheduleUpdate())); + disconnect(button, &QWinThumbnailToolButton::changed, + d, &QWinThumbnailToolBarPrivate::_q_scheduleUpdate); + d->buttonList.removeAll(button); d->_q_scheduleUpdate(); } @@ -530,9 +533,8 @@ void QWinThumbnailToolBarPrivate::_q_scheduleUpdate() { if (updateScheduled) return; - Q_Q(QWinThumbnailToolBar); updateScheduled = true; - QTimer::singleShot(0, q, SLOT(_q_updateToolbar())); + QTimer::singleShot(0, this, &QWinThumbnailToolBarPrivate::_q_updateToolbar); } bool QWinThumbnailToolBarPrivate::eventFilter(QObject *object, QEvent *event) diff --git a/src/winextras/qwinthumbnailtoolbar.h b/src/winextras/qwinthumbnailtoolbar.h index 4e8295a..0eb26f2 100644 --- a/src/winextras/qwinthumbnailtoolbar.h +++ b/src/winextras/qwinthumbnailtoolbar.h @@ -87,9 +87,6 @@ private: Q_DECLARE_PRIVATE(QWinThumbnailToolBar) QScopedPointer<QWinThumbnailToolBarPrivate> d_ptr; friend class QWinThumbnailToolButton; - - Q_PRIVATE_SLOT(d_func(), void _q_updateToolbar()) - Q_PRIVATE_SLOT(d_func(), void _q_scheduleUpdate()) }; QT_END_NAMESPACE diff --git a/tests/manual/dwmfeatures/testwidget.cpp b/tests/manual/dwmfeatures/testwidget.cpp index 78361de..29525f4 100644 --- a/tests/manual/dwmfeatures/testwidget.cpp +++ b/tests/manual/dwmfeatures/testwidget.cpp @@ -45,16 +45,21 @@ TestWidget::TestWidget(QWidget *parent) : { ui->setupUi(this); - connect(ui->btnPeekDisallow, SIGNAL(clicked()), SLOT(onDisallowPeekClicked())); - connect(ui->btnPeekExclude, SIGNAL(clicked()), SLOT(onExcludeFromPeekClicked())); - connect(ui->radioFlipDefault, SIGNAL(clicked()), SLOT(onFlip3DPolicyChanged())); - connect(ui->radioFlipAbove, SIGNAL(clicked()), SLOT(onFlip3DPolicyChanged())); - connect(ui->radioFlipBelow, SIGNAL(clicked()), SLOT(onFlip3DPolicyChanged())); - connect(ui->btnFrameReset, SIGNAL(clicked()), SLOT(onResetGlassFrameClicked())); - connect(ui->frameTop, SIGNAL(valueChanged(int)), SLOT(onGlassMarginsChanged())); - connect(ui->frameRight, SIGNAL(valueChanged(int)), SLOT(onGlassMarginsChanged())); - connect(ui->frameBottom, SIGNAL(valueChanged(int)), SLOT(onGlassMarginsChanged())); - connect(ui->frameLeft, SIGNAL(valueChanged(int)), SLOT(onGlassMarginsChanged())); + connect(ui->btnPeekDisallow, &QAbstractButton::clicked, this, &TestWidget::onDisallowPeekClicked); + connect(ui->btnPeekExclude, &QAbstractButton::clicked, this, &TestWidget::onExcludeFromPeekClicked); + connect(ui->radioFlipDefault, &QAbstractButton::clicked, this, &TestWidget::onFlip3DPolicyChanged); + connect(ui->radioFlipAbove, &QAbstractButton::clicked, this, &TestWidget::onFlip3DPolicyChanged); + connect(ui->radioFlipBelow, &QAbstractButton::clicked, this, &TestWidget::onFlip3DPolicyChanged); + connect(ui->btnFrameReset, &QAbstractButton::clicked, this, &TestWidget::onResetGlassFrameClicked); + typedef void(QSpinBox::*IntSignal)(int); + connect(ui->frameTop, static_cast<IntSignal>(&QSpinBox::valueChanged), + this, &TestWidget::onGlassMarginsChanged); + connect(ui->frameRight, static_cast<IntSignal>(&QSpinBox::valueChanged), + this, &TestWidget::onGlassMarginsChanged); + connect(ui->frameBottom, static_cast<IntSignal>(&QSpinBox::valueChanged), + this, &TestWidget::onGlassMarginsChanged); + connect(ui->frameLeft, static_cast<IntSignal>(&QSpinBox::valueChanged), + this, &TestWidget::onGlassMarginsChanged); } TestWidget::~TestWidget() diff --git a/tests/manual/jumplist/testwidget.cpp b/tests/manual/jumplist/testwidget.cpp index 32ad81b..a493286 100644 --- a/tests/manual/jumplist/testwidget.cpp +++ b/tests/manual/jumplist/testwidget.cpp @@ -63,9 +63,9 @@ TestWidget::TestWidget(QWidget *parent) : } } - connect(ui->btnUpdate, SIGNAL(clicked()), SLOT(updateJumpList())); - connect(ui->btnOpenFile, SIGNAL(clicked()), SLOT(openFile())); - connect(ui->btnClose, SIGNAL(clicked()), qApp, SLOT(quit())); + connect(ui->btnUpdate, &QAbstractButton::clicked, this, &TestWidget::updateJumpList); + connect(ui->btnOpenFile, &QAbstractButton::clicked, this, &TestWidget::openFile); + connect(ui->btnClose, &QAbstractButton::clicked, QCoreApplication::quit); } TestWidget::~TestWidget() diff --git a/tests/manual/thumbnail/main.cpp b/tests/manual/thumbnail/main.cpp index 0dcab8b..96b10fd 100644 --- a/tests/manual/thumbnail/main.cpp +++ b/tests/manual/thumbnail/main.cpp @@ -92,7 +92,7 @@ MainWindow::MainWindow() QMenu *fileMenu = menuBar()->addMenu("&File"); QAction *quitAction = fileMenu->addAction("&Quit"); quitAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q)); - connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); + connect(quitAction, &QAction::triggered, QCoreApplication::quit); setCentralWidget(m_logEdit); } @@ -102,13 +102,13 @@ void MainWindow::initThumbnailToolBar() QWinThumbnailToolButton *testButton = new QWinThumbnailToolButton(m_thumbnailToolBar); testButton->setToolTip("Test"); testButton->setIcon(style()->standardIcon(QStyle::SP_ComputerIcon)); - connect(testButton, SIGNAL(clicked()), this, SLOT(testButtonClicked())); + connect(testButton, &QWinThumbnailToolButton::clicked, this, &MainWindow::testButtonClicked); m_thumbnailToolBar->addButton(testButton); m_thumbnailToolBar->setIconicPixmapNotificationsEnabled(true); - connect(m_thumbnailToolBar, SIGNAL(iconicLivePreviewPixmapRequested()), - this, SLOT(updateIconicLivePreviewPixmap())); - connect(m_thumbnailToolBar, SIGNAL(iconicThumbnailPixmapRequested()), - this, SLOT(updateIconicThumbnailPixmap())); + connect(m_thumbnailToolBar, &QWinThumbnailToolBar::iconicLivePreviewPixmapRequested, + this, &MainWindow::updateIconicLivePreviewPixmap); + connect(m_thumbnailToolBar, &QWinThumbnailToolBar::iconicThumbnailPixmapRequested, + this, &MainWindow::updateIconicThumbnailPixmap); } void MainWindow::logText(const QString &text) |