Skip to content

Commit

Permalink
Convert old-style signal/slot connections to modern Qt 5 style
Browse files Browse the repository at this point in the history
  • Loading branch information
realnc committed Mar 26, 2019
1 parent 988e9a3 commit 60b982b
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 62 deletions.
78 changes: 44 additions & 34 deletions src/confdialog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ ConfDialog::ConfDialog(HMainWindow* parent)
ui_->volumeSlider->setDisabled(true);
#else
ui_->volumeSlider->setValue(sett->sound_volume);
connect(ui_->volumeSlider, SIGNAL(valueChanged(int)), SLOT(setSoundVolume(int)));
connect(ui_->volumeSlider, &QSlider::valueChanged, this, &ConfDialog::setSoundVolume);
#endif
ui_->soundFontGroupBox->setChecked(sett->use_custom_soundfont);
ui_->soundFontLineEdit->setText(sett->soundfont);
Expand All @@ -132,8 +132,8 @@ ConfDialog::ConfDialog(HMainWindow* parent)
ui_->bannerBgColorButton->setColor(sett->status_bg_color);
ui_->bannerTextColorButton->setColor(sett->status_text_color);
ui_->fsMarginColorButton->setColor(sett->fs_margin_color);
connect(ui_->customFsMarginColorCheckBox, SIGNAL(toggled(bool)), ui_->fsMarginColorButton,
SLOT(setEnabled(bool)));
connect(ui_->customFsMarginColorCheckBox, &QCheckBox::toggled, ui_->fsMarginColorButton,
&KColorButton::setEnabled);
ui_->customFsMarginColorCheckBox->setChecked(sett->custom_fs_margin_color);

ui_->mainFontSizeSpinBox->setValue(sett->prop_font.pointSize());
Expand Down Expand Up @@ -191,10 +191,10 @@ ConfDialog::ConfDialog(HMainWindow* parent)
// Assume KDE/MS Windows standards. No instant apply, and use OK/Apply/Cancel buttons.
ui_->buttonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Apply
| QDialogButtonBox::Cancel);
connect(ui_->buttonBox->button(QDialogButtonBox::Apply), SIGNAL(clicked()), this,
SLOT(applySettings()));
connect(this, SIGNAL(accepted()), this, SLOT(applySettings()));
connect(this, SIGNAL(rejected()), SLOT(cancel()));
connect(ui_->buttonBox->button(QDialogButtonBox::Apply), &QPushButton::clicked, this,
&ConfDialog::applySettings);
connect(this, &ConfDialog::accepted, this, &ConfDialog::applySettings);
connect(this, &ConfDialog::rejected, this, &ConfDialog::cancel);
}
#endif

Expand Down Expand Up @@ -226,41 +226,51 @@ void ConfDialog::changeEvent(QEvent* e)

void ConfDialog::makeInstantApply()
{
connect(ui_->mainFontBox, SIGNAL(currentFontChanged(QFont)), this, SLOT(applySettings()));
connect(ui_->fixedFontBox, SIGNAL(currentFontChanged(QFont)), this, SLOT(applySettings()));
connect(ui_->scrollbackFontBox, SIGNAL(currentFontChanged(QFont)), this, SLOT(applySettings()));
connect(ui_->mainFontSizeSpinBox, SIGNAL(valueChanged(int)), this, SLOT(applySettings()));
connect(ui_->fixedFontSizeSpinBox, SIGNAL(valueChanged(int)), this, SLOT(applySettings()));
connect(ui_->scrollbackFontSizeSpinBox, SIGNAL(valueChanged(int)), this, SLOT(applySettings()));
connect(ui_->softScrollCheckBox, SIGNAL(toggled(bool)), this, SLOT(applySettings()));
connect(ui_->smartFormattingCheckBox, SIGNAL(toggled(bool)), this, SLOT(applySettings()));
connect(ui_->marginSizeSpinBox, SIGNAL(valueChanged(int)), this, SLOT(applySettings()));
connect(ui_->fullscreenWidthSpinBox, SIGNAL(valueChanged(int)), this, SLOT(applySettings()));
connect(ui_->scriptWrapSpinBox, SIGNAL(valueChanged(int)), this, SLOT(applySettings()));
connect(ui_->mainFontBox, &QFontComboBox::currentFontChanged, this, &ConfDialog::applySettings);
connect(ui_->fixedFontBox, &QFontComboBox::currentFontChanged, this,
&ConfDialog::applySettings);
connect(ui_->scrollbackFontBox, &QFontComboBox::currentFontChanged, this,
&ConfDialog::applySettings);
connect(ui_->mainFontSizeSpinBox, qOverload<int>(&QSpinBox::valueChanged), this,
&ConfDialog::applySettings);
connect(ui_->fixedFontSizeSpinBox, qOverload<int>(&QSpinBox::valueChanged), this,
&ConfDialog::applySettings);
connect(ui_->scrollbackFontSizeSpinBox, qOverload<int>(&QSpinBox::valueChanged), this,
&ConfDialog::applySettings);
connect(ui_->softScrollCheckBox, &QCheckBox::toggled, this, &ConfDialog::applySettings);
connect(ui_->smartFormattingCheckBox, &QCheckBox::toggled, this, &ConfDialog::applySettings);
connect(ui_->marginSizeSpinBox, qOverload<int>(&QSpinBox::valueChanged), this,
&ConfDialog::applySettings);
connect(ui_->fullscreenWidthSpinBox, qOverload<int>(&QSpinBox::valueChanged), this,
&ConfDialog::applySettings);
connect(ui_->scriptWrapSpinBox, qOverload<int>(&QSpinBox::valueChanged), this,
&ConfDialog::applySettings);
connect(ui_->cursorShapeComboBox, qOverload<int>(&QComboBox::currentIndexChanged), this,
&ConfDialog::applySettings);
connect(ui_->cursorThicknessComboBox, qOverload<int>(&QComboBox::currentIndexChanged), this,
&ConfDialog::applySettings);
connect(ui_->allowGraphicsCheckBox, SIGNAL(toggled(bool)), this, SLOT(applySettings()));
connect(ui_->allowVideoCheckBox, SIGNAL(toggled(bool)), this, SLOT(applySettings()));
connect(ui_->allowSoundEffectsCheckBox, SIGNAL(toggled(bool)), this, SLOT(applySettings()));
connect(ui_->allowMusicCheckBox, SIGNAL(toggled(bool)), this, SLOT(applySettings()));
connect(ui_->muteWhenMinimizedCheckBox, SIGNAL(toggled(bool)), this, SLOT(applySettings()));
connect(ui_->volumeSlider, SIGNAL(valueChanged(int)), SLOT(applySettings()));
connect(ui_->allowGraphicsCheckBox, &QCheckBox::toggled, this, &ConfDialog::applySettings);
connect(ui_->allowVideoCheckBox, &QCheckBox::toggled, this, &ConfDialog::applySettings);
connect(ui_->allowSoundEffectsCheckBox, &QCheckBox::toggled, this, &ConfDialog::applySettings);
connect(ui_->allowMusicCheckBox, &QCheckBox::toggled, this, &ConfDialog::applySettings);
connect(ui_->muteWhenMinimizedCheckBox, &QCheckBox::toggled, this, &ConfDialog::applySettings);
connect(ui_->volumeSlider, &QSlider::valueChanged, this, &ConfDialog::applySettings);
connect(ui_->soundFontGroupBox, &QGroupBox::toggled, this, &ConfDialog::applySettings);
connect(ui_->soundFontLineEdit, &QLineEdit::textChanged, this, &ConfDialog::applySettings);
connect(ui_->gainSpinBox, qOverload<double>(&QDoubleSpinBox::valueChanged), this,
&ConfDialog::applySettings);
connect(ui_->adlibRadioButton, SIGNAL(toggled(bool)), this, SLOT(applySettings()));
connect(ui_->overlayScrollbackCheckBox, SIGNAL(toggled(bool)), this, SLOT(applySettings()));
connect(ui_->scrollWheelCheckBox, SIGNAL(toggled(bool)), this, SLOT(applySettings()));
connect(ui_->mainTextColorButton, SIGNAL(changed(QColor)), this, SLOT(applySettings()));
connect(ui_->mainBgColorButton, SIGNAL(changed(QColor)), this, SLOT(applySettings()));
connect(ui_->bannerTextColorButton, SIGNAL(changed(QColor)), this, SLOT(applySettings()));
connect(ui_->bannerBgColorButton, SIGNAL(changed(QColor)), this, SLOT(applySettings()));
connect(ui_->customFsMarginColorCheckBox, SIGNAL(toggled(bool)), this, SLOT(applySettings()));
connect(ui_->fsMarginColorButton, SIGNAL(changed(QColor)), this, SLOT(applySettings()));
connect(ui_->startInButtonGroup, SIGNAL(buttonClicked(int)), SLOT(applySettings()));
connect(ui_->adlibRadioButton, &QRadioButton::toggled, this, &ConfDialog::applySettings);
connect(ui_->overlayScrollbackCheckBox, &QCheckBox::toggled, this, &ConfDialog::applySettings);
connect(ui_->scrollWheelCheckBox, &QCheckBox::toggled, this, &ConfDialog::applySettings);
connect(ui_->mainTextColorButton, &KColorButton::changed, this, &ConfDialog::applySettings);
connect(ui_->mainBgColorButton, &KColorButton::changed, this, &ConfDialog::applySettings);
connect(ui_->bannerTextColorButton, &KColorButton::changed, this, &ConfDialog::applySettings);
connect(ui_->bannerBgColorButton, &KColorButton::changed, this, &ConfDialog::applySettings);
connect(ui_->customFsMarginColorCheckBox, &QCheckBox::toggled, this,
&ConfDialog::applySettings);
connect(ui_->fsMarginColorButton, &KColorButton::changed, this, &ConfDialog::applySettings);
connect(ui_->startInButtonGroup, qOverload<int>(&QButtonGroup::buttonClicked), this,
&ConfDialog::applySettings);
}

void ConfDialog::applySettings()
Expand Down
12 changes: 6 additions & 6 deletions src/happlication.cc
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,11 @@ void HApplication::runGame()
hugo_thread_->setObjectName("engine");
engine_runner_ = new EngineRunner(gamefile_, hugo_thread_);
engine_runner_->moveToThread(hugo_thread_);
connect(engine_runner_, SIGNAL(finished()), hugo_thread_, SLOT(quit()));
connect(hugo_thread_, SIGNAL(started()), engine_runner_, SLOT(runEngine()));
connect(hugo_thread_, SIGNAL(finished()), engine_runner_, SLOT(deleteLater()));
connect(hugo_thread_, SIGNAL(finished()), hugo_thread_, SLOT(deleteLater()));
connect(hugo_thread_, SIGNAL(finished()), SLOT(handleEngineFinished()));
connect(engine_runner_, &EngineRunner::finished, hugo_thread_, &EngineThread::quit);
connect(hugo_thread_, &QThread::started, engine_runner_, &EngineRunner::runEngine);
connect(hugo_thread_, &QThread::finished, engine_runner_, &EngineRunner::deleteLater);
connect(hugo_thread_, &QThread::finished, hugo_thread_, &EngineThread::deleteLater);
connect(hugo_thread_, &QThread::finished, this, &HApplication::handleEngineFinished);
hugo_thread_->start();
}
}
Expand Down Expand Up @@ -316,7 +316,7 @@ void HApplication::entryPoint(QString gameFileName)
}

// Automatically quit the application when the last window has closed.
connect(this, SIGNAL(lastWindowClosed()), this, SLOT(quit()));
connect(this, &HApplication::lastWindowClosed, this, &HApplication::quit);

// If we have a filename, load it.
if (not next_game_.isEmpty()) {
Expand Down
13 changes: 6 additions & 7 deletions src/hframe.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,19 @@ HFrame::HFrame(QWidget* parent)
// We handle player input, so we need to accept focus.
setFocusPolicy(Qt::WheelFocus);

connect(blink_timer_, SIGNAL(timeout()), this, SLOT(blinkCursor()));
connect(blink_timer_, &QTimer::timeout, this, &HFrame::blinkCursor);
resetCursorBlinking();
// setCursorVisible(true);

// We need to check whether the application lost focus.
connect(qApp, SIGNAL(focusChanged(QWidget*, QWidget*)),
SLOT(handleFocusChange(QWidget*, QWidget*)));
connect(qApp, &QApplication::focusChanged, this, &HFrame::handleFocusChange);

minimize_timer_->setSingleShot(true);
connect(minimize_timer_, SIGNAL(timeout()), SLOT(handleFocusLost()));
connect(minimize_timer_, &QTimer::timeout, this, &HFrame::handleFocusLost);

// Requesting scrollback simply triggers the scrollback window. Since focus is lost, subsequent
// scrolling/paging events will work as expected.
connect(this, SIGNAL(requestScrollback()), hMainWin, SLOT(showScrollback()));
connect(this, &HFrame::requestScrollback, hMainWin, &HMainWindow::showScrollback);

setAttribute(Qt::WA_InputMethodEnabled);
setAttribute(Qt::WA_OpaquePaintEvent);
Expand Down Expand Up @@ -632,8 +631,8 @@ void HFrame::scrollUp(int left, int top, int right, int bottom, int h)
QEventLoop idleLoop;
QTimer timer;
timer.setSingleShot(true);
QObject::connect(&timer, SIGNAL(timeout()), &idleLoop, SLOT(quit()));
QObject::connect(hApp, SIGNAL(gameQuitting()), &idleLoop, SLOT(quit()));
connect(&timer, &QTimer::timeout, &idleLoop, &QEventLoop::quit);
connect(hApp, &HApplication::gameQuitting, &idleLoop, &QEventLoop::quit);
timer.start(12);
idleLoop.exec();
}
Expand Down
14 changes: 7 additions & 7 deletions src/hmainwindow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ HMainWindow::HMainWindow(QWidget* parent)
act->setMenuRole(QAction::PreferencesRole);
menu->addAction(act);
addAction(act);
connect(act, SIGNAL(triggered()), SLOT(showConfDialog()));
connect(act, &QAction::triggered, this, &HMainWindow::showConfDialog);
preferences_action_ = act;

// "View" menu.
menu = menuBar->addMenu(tr("&View"));
act = new QAction(tr("Show &Scrollback"), this);
menu->addAction(act);
addAction(act);
connect(act, SIGNAL(triggered()), SLOT(showScrollback()));
connect(act, &QAction::triggered, this, &HMainWindow::showScrollback);
scrollback_action_ = act;

act = new QAction(tr("Enter &Full Screen"), this);
Expand Down Expand Up @@ -93,7 +93,7 @@ HMainWindow::HMainWindow(QWidget* parent)
menu->addAction(act);
#endif
addAction(act);
connect(act, SIGNAL(triggered()), SLOT(toggleFullscreen()));
connect(act, &QAction::triggered, this, &HMainWindow::toggleFullscreen);
fullscreen_action_ = act;

// "Help" menu.
Expand All @@ -102,7 +102,7 @@ HMainWindow::HMainWindow(QWidget* parent)
act->setIcon(QIcon::fromTheme(QString::fromLatin1("help-about")));
act->setMenuRole(QAction::AboutRole);
menu->addAction(act);
connect(act, SIGNAL(triggered()), SLOT(showAbout()));
connect(act, &QAction::triggered, this, &HMainWindow::showAbout);

// Handle "close window" shortcut.
connect(new QShortcut(QKeySequence::Close, this), &QShortcut::activated, this,
Expand Down Expand Up @@ -152,7 +152,7 @@ void HMainWindow::showConfDialog()
}
conf_dialog_ = new ConfDialog(this);
conf_dialog_->setWindowTitle(HApplication::applicationName() + ' ' + tr("Preferences"));
connect(conf_dialog_, SIGNAL(finished(int)), this, SLOT(hideConfDialog()));
connect(conf_dialog_, &ConfDialog::finished, this, &HMainWindow::hideConfDialog);
conf_dialog_->show();
}

Expand All @@ -174,7 +174,7 @@ void HMainWindow::showAbout()
}

about_dialog_ = new AboutDialog(this);
connect(about_dialog_, SIGNAL(finished(int)), SLOT(hideAbout()));
connect(about_dialog_, &AboutDialog::finished, this, &HMainWindow::hideAbout);
about_dialog_->show();
}

Expand Down Expand Up @@ -236,7 +236,7 @@ void HMainWindow::showScrollback()
+ QKeySequence(QKeySequence::Close).toString(QKeySequence::NativeText)
+ " or click here to exit</a>)</body></html>";
banner->setText(bannerText);
connect(banner, SIGNAL(linkActivated(QString)), SLOT(hideScrollback()));
connect(banner, &QLabel::linkActivated, this, &HMainWindow::hideScrollback);

hApp->marginWidget()->setBannerWidget(banner);
hFrame->hide();
Expand Down
8 changes: 4 additions & 4 deletions src/hugohandlers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,10 @@ void HugoHandlers::playvideo(HUGO_FILE infile, long len, char loop, char bg, int
physical_windowheight);
if (not bg) {
QEventLoop idleLoop;
QObject::connect(vid_player_, SIGNAL(videoFinished()), &idleLoop, SLOT(quit()));
QObject::connect(vid_player_, SIGNAL(errorOccurred()), &idleLoop, SLOT(quit()));
QObject::connect(hApp, SIGNAL(gameQuitting()), &idleLoop, SLOT(quit()));
QObject::connect(hFrame, SIGNAL(escKeyPressed()), &idleLoop, SLOT(quit()));
connect(vid_player_, &VideoPlayer::videoFinished, &idleLoop, &QEventLoop::quit);
connect(vid_player_, &VideoPlayer::errorOccurred, &idleLoop, &QEventLoop::quit);
connect(hApp, &HApplication::gameQuitting, &idleLoop, &QEventLoop::quit);
connect(hFrame, &HFrame::escKeyPressed, &idleLoop, &QEventLoop::quit);
vid_player_->play();
idleLoop.exec();
} else {
Expand Down
9 changes: 5 additions & 4 deletions src/videoplayerqt5.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "hugorfile.h"
#include "rwopsbundle.h"
#include "rwopsqiodev.h"
#include "util.h"
#include "videoplayerqt5_p.h"

void initVideoEngine(int& /*argc*/, char* /*argv*/[])
Expand Down Expand Up @@ -46,10 +47,10 @@ VideoPlayer::VideoPlayer(QWidget* parent)
setMouseTracking(true);
d_->setMouseTracking(true);

connect(d_->media_player, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)), d_,
SLOT(onStatusChange(QMediaPlayer::MediaStatus)));
connect(d_->media_player, SIGNAL(error(QMediaPlayer::Error)), d_,
SLOT(onError(QMediaPlayer::Error)));
connect(d_->media_player, &QMediaPlayer::mediaStatusChanged, d_,
&VideoPlayer_priv::onStatusChange);
connect(d_->media_player, qOverload<QMediaPlayer::Error>(&QMediaPlayer::error), d_,
&VideoPlayer_priv::onError);
}

VideoPlayer::~VideoPlayer()
Expand Down

0 comments on commit 60b982b

Please sign in to comment.