Skip to content

Commit

Permalink
common: port to new style signal slot syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfikl committed Jul 7, 2024
1 parent 9294cc6 commit a640c37
Show file tree
Hide file tree
Showing 11 changed files with 91 additions and 74 deletions.
21 changes: 12 additions & 9 deletions common/templatewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <QtGui/QTextDocument>
#include <QtWidgets/QApplication>
#include <QtWidgets/QLineEdit>
#include <QtWidgets/QPushButton>

#include "utils/combobox.h"
#include "utils/filedialog.h"
Expand All @@ -53,11 +54,13 @@ TemplateWidget::TemplateWidget(QWidget *parent) : QWidget(parent)
m_urlCompletion = new UrlCompletion(this);
ui.templateCombo->setCompletionObject(m_urlCompletion);

connect(ui.templateChooseButton, SIGNAL(clicked()), this, SLOT(selectTemplateFile()));
connect(ui.templateEditButton, SIGNAL(clicked()), this, SLOT(editTemplateFile()));
connect(ui.templateReloadButton, SIGNAL(clicked()), this, SLOT(reloadTemplateFile()));
connect(ui.templateCombo->lineEdit(), SIGNAL(textChanged(QString)), this,
SIGNAL(fileNameChanged(QString)));
connect(ui.templateChooseButton, &QPushButton::clicked, this,
&TemplateWidget::selectTemplateFile);
connect(ui.templateEditButton, &QPushButton::clicked, this, &TemplateWidget::editTemplateFile);
connect(ui.templateReloadButton, &QPushButton::clicked, this,
&TemplateWidget::reloadTemplateFile);
connect(ui.templateCombo->lineEdit(), &QLineEdit::textChanged, this,
&TemplateWidget::fileNameChanged);

readRecentTemplates();
}
Expand Down Expand Up @@ -98,15 +101,15 @@ void TemplateWidget::saveRecentTemplates()

void TemplateWidget::setFileName(const QString &fileName)
{
disconnect(ui.templateCombo->lineEdit(), SIGNAL(textChanged(QString)), this,
SIGNAL(fileNameChanged(QString)));
disconnect(ui.templateCombo->lineEdit(), &QLineEdit::textChanged, this,
&TemplateWidget::fileNameChanged);
const int index = ui.templateCombo->findText(fileName);
if (index >= 0) // then remove item in order to re-add it at the top
ui.templateCombo->removeItem(index);
ui.templateCombo->insertItem(0, fileName);
ui.templateCombo->lineEdit()->setText(QString());
connect(ui.templateCombo->lineEdit(), SIGNAL(textChanged(QString)), this,
SIGNAL(fileNameChanged(QString)));
connect(ui.templateCombo->lineEdit(), &QLineEdit::textChanged, this,
&TemplateWidget::fileNameChanged);
ui.templateCombo->setCurrentIndex(0);
}

Expand Down
14 changes: 7 additions & 7 deletions common/tikzpreview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ TikzPreview::TikzPreview(QWidget *parent)
createActions();

m_tikzPreviewRenderer = new TikzPreviewRenderer();
connect(this, SIGNAL(generatePreview(Poppler::Document *, qreal, int)), m_tikzPreviewRenderer,
SLOT(generatePreview(Poppler::Document *, qreal, int)));
connect(m_tikzPreviewRenderer, SIGNAL(showPreview(QImage, qreal)), this,
SLOT(showPreview(QImage, qreal)));
connect(this, &TikzPreview::generatePreview, m_tikzPreviewRenderer,
&TikzPreviewRenderer::generatePreview);
connect(m_tikzPreviewRenderer, &TikzPreviewRenderer::showPreview, this,
&TikzPreview::showPreview);
}

TikzPreview::~TikzPreview()
Expand Down Expand Up @@ -116,23 +116,23 @@ void TikzPreview::createActions()
m_zoomToAction = new ZoomAction(Icon(QLatin1String("zoom-original")), tr("&Zoom"), this,
QLatin1String("zoom_to"));
m_zoomToAction->setZoomFactor(m_zoomFactor);
connect(m_zoomToAction, SIGNAL(zoomFactorAdded(qreal)), this, SLOT(setZoomFactor(qreal)));
connect(m_zoomToAction, &ZoomAction::zoomFactorAdded, this, &TikzPreview::setZoomFactor);

m_previousPageAction = new Action(Icon(QLatin1String("go-previous")), tr("&Previous image"),
this, QLatin1String("view_previous_image"));
m_previousPageAction->setShortcut(tr("Alt+Left", "View|Go to previous page"));
m_previousPageAction->setStatusTip(tr("Show previous image in preview"));
m_previousPageAction->setWhatsThis(
tr("<p>Show the preview of the previous tikzpicture in the TikZ code.</p>"));
connect(m_previousPageAction, SIGNAL(triggered()), this, SLOT(showPreviousPage()));
connect(m_previousPageAction, &Action::triggered, this, &TikzPreview::showPreviousPage);

m_nextPageAction = new Action(Icon(QLatin1String("go-next")), tr("&Next image"), this,
QLatin1String("view_next_image"));
m_nextPageAction->setShortcut(tr("Alt+Right", "View|Go to next page"));
m_nextPageAction->setStatusTip(tr("Show next image in preview"));
m_nextPageAction->setWhatsThis(
tr("<p>Show the preview of the next tikzpicture in the TikZ code.</p>"));
connect(m_nextPageAction, SIGNAL(triggered()), this, SLOT(showNextPage()));
connect(m_nextPageAction, &Action::triggered, this, &TikzPreview::showNextPage);

m_previousPageAction->setVisible(false);
m_previousPageAction->setEnabled(false);
Expand Down
60 changes: 33 additions & 27 deletions common/tikzpreviewcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#include <QtWidgets/QMenu>
#include <QtWidgets/QPushButton>

#include <poppler-qt5.h>

#include "templatewidget.h"
#include "tikzpreview.h"
#include "mainwidget.h"
Expand Down Expand Up @@ -61,24 +63,24 @@ TikzPreviewController::TikzPreviewController(MainWidget *mainWidget)
createActions();

qRegisterMetaType<QList<qreal>>("QList<qreal>");
connect(m_tikzPreviewGenerator, SIGNAL(pixmapUpdated(Poppler::Document *, QList<qreal>)),
m_tikzPreview, SLOT(pixmapUpdated(Poppler::Document *, QList<qreal>)));
connect(m_tikzPreviewGenerator, SIGNAL(showErrorMessage(QString)), m_tikzPreview,
SLOT(showErrorMessage(QString)));
connect(m_tikzPreviewGenerator, SIGNAL(setExportActionsEnabled(bool)), this,
SLOT(setExportActionsEnabled(bool)));
connect(m_tikzPreviewGenerator, SIGNAL(updateLog(QString, bool)), this,
SIGNAL(updateLog(QString, bool)));
connect(m_tikzPreviewGenerator, SIGNAL(appendLog(QString, bool)), this,
SIGNAL(appendLog(QString, bool)));
connect(m_templateWidget, SIGNAL(fileNameChanged(QString)), this,
SLOT(setTemplateFileAndRegenerate(QString)));
connect(m_tikzPreview, SIGNAL(showMouseCoordinates(qreal, qreal, int, int)), this,
SIGNAL(showMouseCoordinates(qreal, qreal, int, int)));
connect(m_tikzPreviewGenerator, &TikzPreviewGenerator::pixmapUpdated, m_tikzPreview,
&TikzPreview::pixmapUpdated);
connect(m_tikzPreviewGenerator, &TikzPreviewGenerator::showErrorMessage, m_tikzPreview,
&TikzPreview::showErrorMessage);
connect(m_tikzPreviewGenerator, &TikzPreviewGenerator::setExportActionsEnabled, this,
&TikzPreviewController::setExportActionsEnabled);
connect(m_tikzPreviewGenerator, &TikzPreviewGenerator::updateLog, this,
&TikzPreviewController::updateLog);
connect(m_tikzPreviewGenerator, &TikzPreviewGenerator::appendLog, this,
&TikzPreviewController::appendLog);
connect(m_templateWidget, &TemplateWidget::fileNameChanged, this,
&TikzPreviewController::setTemplateFileAndRegenerate);
connect(m_tikzPreview, &TikzPreview::showMouseCoordinates, this,
&TikzPreviewController::showMouseCoordinates);

m_regenerateTimer = new QTimer(this);
m_regenerateTimer->setSingleShot(true);
connect(m_regenerateTimer, SIGNAL(timeout()), this, SLOT(regeneratePreview()));
connect(m_regenerateTimer, &QTimer::timeout, this, &TikzPreviewController::regeneratePreview);

m_tempDir = new TempDir();
m_tikzPreviewGenerator->setTikzFileBaseName(tempFileBaseName());
Expand Down Expand Up @@ -149,7 +151,7 @@ void TikzPreviewController::createActions()
exportEpsAction->setData(QLatin1String("image/x-eps"));
exportEpsAction->setStatusTip(tr("Export to EPS"));
exportEpsAction->setWhatsThis(tr("<p>Export to EPS.</p>"));
connect(exportEpsAction, SIGNAL(triggered()), this, SLOT(exportImage()));
connect(exportEpsAction, &Action::triggered, this, &TikzPreviewController::exportImage);
exportMenu->addAction(exportEpsAction);

Action *exportPdfAction = new Action(Icon(QLatin1String("application-pdf")),
Expand All @@ -158,7 +160,7 @@ void TikzPreviewController::createActions()
exportPdfAction->setData(QLatin1String("application/pdf"));
exportPdfAction->setStatusTip(tr("Export to PDF"));
exportPdfAction->setWhatsThis(tr("<p>Export to PDF.</p>"));
connect(exportPdfAction, SIGNAL(triggered()), this, SLOT(exportImage()));
connect(exportPdfAction, &Action::triggered, this, &TikzPreviewController::exportImage);
exportMenu->addAction(exportPdfAction);

QStringList mimeTypes;
Expand All @@ -177,16 +179,16 @@ void TikzPreviewController::createActions()
exportImageAction->setData(QLatin1String("image/") + mimeTypes.at(i));
exportImageAction->setStatusTip(tr("Export to %1").arg(mimeTypes.at(i).toUpper()));
exportImageAction->setWhatsThis(tr("<p>Export to %1.</p>").arg(mimeTypes.at(i).toUpper()));
connect(exportImageAction, SIGNAL(triggered()), this, SLOT(exportImage()));
connect(exportImageAction, &Action::triggered, this, &TikzPreviewController::exportImage);
exportMenu->addAction(exportImageAction);
}

#ifndef KTIKZ_KPART // don't have two "Print" actions in the kpart
m_printPreviewAction = StandardAction::printPreview(this, SLOT(printPreviewImage()), this);
m_printPreviewAction = StandardAction::printPreview(this, "printPreviewImage", this);
m_printPreviewAction->setStatusTip(tr("Print preview image"));
m_printPreviewAction->setWhatsThis(tr("<p>Show print preview of the preview image.</p>"));

m_printAction = StandardAction::print(this, SLOT(printImage()), this);
m_printAction = StandardAction::print(this, "printImage", this);
m_printAction->setStatusTip(tr("Print image"));
m_printAction->setWhatsThis(tr("<p>Print the preview image.</p>"));
#endif
Expand All @@ -201,7 +203,7 @@ void TikzPreviewController::createActions()
m_procStopAction->setWhatsThis(
tr("<p>Abort the execution of the currently running process.</p>"));
m_procStopAction->setEnabled(false);
connect(m_procStopAction, SIGNAL(triggered()), this, SLOT(abortProcess()));
connect(m_procStopAction, &Action::triggered, this, &TikzPreviewController::abortProcess);

m_shellEscapeAction =
new ToggleAction(Icon(QLatin1String("application-x-executable")), tr("S&hell Escape"),
Expand All @@ -212,10 +214,11 @@ void TikzPreviewController::createActions()
"using gnuplot within TikZ."
"</p><p><strong>Warning:</strong> Enabling this may cause malicious software to be run "
"on your computer! Check the LaTeX code to see which commands are executed.</p>"));
connect(m_shellEscapeAction, SIGNAL(toggled(bool)), this, SLOT(toggleShellEscaping(bool)));
connect(m_shellEscapeAction, &ToggleAction::toggled, this,
&TikzPreviewController::toggleShellEscaping);

connect(m_tikzPreviewGenerator, SIGNAL(processRunning(bool)), this,
SLOT(setProcessRunning(bool)));
connect(m_tikzPreviewGenerator, &TikzPreviewGenerator::processRunning, this,
&TikzPreviewController::setProcessRunning);
}

#ifndef KTIKZ_USE_KDE
Expand Down Expand Up @@ -384,7 +387,8 @@ void TikzPreviewController::printPreviewImage()

// show print preview
PrintPreviewDialog preview(&printer);
connect(&preview, SIGNAL(paintRequested(QPrinter *)), this, SLOT(printImage(QPrinter *)));
connect(&preview, &PrintPreviewDialog::paintRequested, this,
[this](QPrinter *printer) { printImage(printer); });
preview.exec();
}

Expand Down Expand Up @@ -520,10 +524,12 @@ void TikzPreviewController::applySettings()
settings.value(QLatin1String("PdftopsCommand"), QLatin1String("pdftops")).toString());
const bool useShellEscaping = settings.value(QLatin1String("UseShellEscaping"), false).toBool();

disconnect(m_shellEscapeAction, SIGNAL(toggled(bool)), this, SLOT(toggleShellEscaping(bool)));
disconnect(m_shellEscapeAction, &Action::toggled, this,
&TikzPreviewController::toggleShellEscaping);
m_shellEscapeAction->setChecked(useShellEscaping);
m_tikzPreviewGenerator->setShellEscaping(useShellEscaping);
connect(m_shellEscapeAction, SIGNAL(toggled(bool)), this, SLOT(toggleShellEscaping(bool)));
connect(m_shellEscapeAction, &Action::toggled, this,
&TikzPreviewController::toggleShellEscaping);

setTemplateFile(settings.value(QLatin1String("TemplateFile")).toString());
const QString replaceText =
Expand Down
4 changes: 2 additions & 2 deletions common/utils/colorbutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@

ColorButton::ColorButton(QWidget *parent) : QToolButton(parent)
{
connect(this, SIGNAL(clicked()), this, SLOT(showColorDialog()));
connect(this, &ColorButton::clicked, this, &ColorButton::showColorDialog);
}

ColorButton::ColorButton(const QColor &color, QWidget *parent) : QToolButton(parent)
{
setColor(color);
connect(this, SIGNAL(clicked()), this, SLOT(showColorDialog()));
connect(this, &ColorButton::clicked, this, &ColorButton::showColorDialog);
}

void ColorButton::showColorDialog()
Expand Down
4 changes: 2 additions & 2 deletions common/utils/lineedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ void LineEdit::init()
m_clearButton->setStyleSheet(QLatin1String("QToolButton { border: none; padding: 0px; }"));
m_clearButton->setToolTip(tr("Clear input field"));
m_clearButton->hide();
connect(m_clearButton, SIGNAL(clicked()), this, SLOT(clear()));
connect(this, SIGNAL(textChanged(QString)), this, SLOT(updateClearButton(QString)));
connect(m_clearButton, &QToolButton::clicked, this, &LineEdit::clear);
connect(this, &LineEdit::textChanged, this, &LineEdit::updateClearButton);
// const int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
// setStyleSheet(QString("QLineEdit { padding-right: %1px; width: %2px; height: %3px; }")
// .arg(m_clearButton->sizeHint().width() + frameWidth + 1)
Expand Down
16 changes: 9 additions & 7 deletions common/utils/pagedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ PageDialog::PageDialog(QWidget *parent) : KPageDialog(parent)
QPushButton *okButton = buttonBox()->button(QDialogButtonBox::Ok);
okButton->setDefault(true);
okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
connect(buttonBox()->button(QDialogButtonBox::Apply), SIGNAL(clicked()), this, SLOT(accept()));
connect(okButton, SIGNAL(clicked()), this, SLOT(accept()));
connect(okButton, &QPushButton::clicked, this, &PageDialog::accept);

QPushButton *applyButton = buttonBox()->button(QDialogButtonBox::Apply);
connect(applyButton, &QPushButton::clicked, this, &PageDialog::accept);
}

void PageDialog::addPage(QWidget *widget, const QString &title, const QString &iconName)
Expand Down Expand Up @@ -73,8 +75,8 @@ PageDialog::PageDialog(QWidget *parent) : QDialog(parent)
buttonBox->addButton(whatsThisButton, QDialogButtonBox::HelpRole);
buttonBox->addButton(QDialogButtonBox::Ok);
buttonBox->addButton(QDialogButtonBox::Cancel);
connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
connect(buttonBox, &QDialogButtonBox::accepted, this, &PageDialog::accept);
connect(buttonBox, &QDialogButtonBox::rejected, this, &PageDialog::reject);

QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(centerWidget());
Expand Down Expand Up @@ -104,9 +106,9 @@ QWidget *PageDialog::centerWidget()

// add pages
m_pagesStackedWidget = new QStackedWidget;
connect(m_pagesListWidget, SIGNAL(currentRowChanged(int)), m_pagesStackedWidget,
SLOT(setCurrentIndex(int)));
connect(m_pagesListWidget, SIGNAL(currentRowChanged(int)), this, SLOT(setCurrentPage(int)));
connect(m_pagesListWidget, &QListWidget::currentRowChanged, m_pagesStackedWidget,
&QStackedWidget::setCurrentIndex);
connect(m_pagesListWidget, &QListWidget::currentRowChanged, this, &PageDialog::setCurrentPage);

QWidget *mainWidget = new QWidget;
QGridLayout *mainLayout = new QGridLayout;
Expand Down
22 changes: 12 additions & 10 deletions common/utils/printpreviewdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,32 +35,33 @@ PrintPreviewDialog::PrintPreviewDialog(QPrinter *printer, QWidget *parent) : QDi
QVBoxLayout *mainLayout = new QVBoxLayout;

m_printPreviewWidget = new QPrintPreviewWidget(printer, this);
connect(m_printPreviewWidget, SIGNAL(paintRequested(QPrinter *)), this,
SIGNAL(paintRequested(QPrinter *)));
connect(m_printPreviewWidget, SIGNAL(previewChanged()), this, SLOT(updateZoomFactor()));
connect(m_printPreviewWidget, &QPrintPreviewWidget::paintRequested, this,
&PrintPreviewDialog::paintRequested);
connect(m_printPreviewWidget, &QPrintPreviewWidget::previewChanged, this,
&PrintPreviewDialog::updateZoomFactor);

ToolBar *toolBar = new ToolBar(QLatin1String("printpreview_toolbar"), this);
Action *action = new Action(Icon(QLatin1String("zoom-fit-width")), tr("Fit &width"), this,
QLatin1String("printpreview_fit_width"));
connect(action, SIGNAL(triggered()), m_printPreviewWidget, SLOT(fitToWidth()));
connect(action, &Action::triggered, m_printPreviewWidget, &QPrintPreviewWidget::fitToWidth);
toolBar->addAction(action);
action = new Action(Icon(QLatin1String("zoom-fit-best")), tr("Fit p&age"), this,
QLatin1String("printpreview_fit_page"));
connect(action, SIGNAL(triggered()), m_printPreviewWidget, SLOT(fitInView()));
connect(action, &Action::triggered, m_printPreviewWidget, &QPrintPreviewWidget::fitInView);
toolBar->addAction(action);
m_zoomToAction = new ZoomAction(Icon(QLatin1String("zoom-original")), tr("&Zoom"), this,
QLatin1String("printpreview_zoom_to"));
connect(m_zoomToAction, SIGNAL(zoomFactorAdded(qreal)), this, SLOT(setZoomFactor(qreal)));
connect(m_zoomToAction, &ZoomAction::zoomFactorAdded, this, &PrintPreviewDialog::setZoomFactor);
toolBar->addAction(m_zoomToAction);
toolBar->addAction(StandardAction::zoomIn(this, SLOT(zoomIn()), this));
toolBar->addAction(StandardAction::zoomOut(this, SLOT(zoomOut()), this));
action = new Action(Icon(QLatin1String("document-print")), tr("&Print"), this,
QLatin1String("printpreview_print"));
connect(action, SIGNAL(triggered()), this, SLOT(print()));
connect(action, &Action::triggered, this, &PrintPreviewDialog::print);
toolBar->addAction(action);
action = new Action(Icon(QLatin1String("window-close")), tr("&Close"), this,
QLatin1String("printpreview_close"));
connect(action, SIGNAL(triggered()), this, SLOT(reject()));
connect(action, &Action::triggered, this, &PrintPreviewDialog::reject);
toolBar->addAction(action);

mainLayout->addWidget(toolBar);
Expand All @@ -87,9 +88,10 @@ void PrintPreviewDialog::setZoomFactor(qreal zoomFactor)

void PrintPreviewDialog::updateZoomFactor()
{
disconnect(m_zoomToAction, SIGNAL(zoomFactorAdded(qreal)), this, SLOT(setZoomFactor(qreal)));
disconnect(m_zoomToAction, &ZoomAction::zoomFactorAdded, this,
&PrintPreviewDialog::setZoomFactor);
m_zoomToAction->setZoomFactor(m_printPreviewWidget->zoomFactor());
connect(m_zoomToAction, SIGNAL(zoomFactorAdded(qreal)), this, SLOT(setZoomFactor(qreal)));
connect(m_zoomToAction, &ZoomAction::zoomFactorAdded, this, &PrintPreviewDialog::setZoomFactor);
}

void PrintPreviewDialog::zoomIn()
Expand Down
Loading

0 comments on commit a640c37

Please sign in to comment.