examples: port widget examples to new connection style
Task-number: QTBUG-106893 Change-Id: Ib10fd516fdbeda0087b1c8550ce340acd3973e6b Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
This commit is contained in:
parent
683ddddc6a
commit
283cdb0e70
@ -432,7 +432,7 @@ void MainWindow::createToolbars()
|
||||
|
||||
fontColorToolButton = new QToolButton;
|
||||
fontColorToolButton->setPopupMode(QToolButton::MenuButtonPopup);
|
||||
fontColorToolButton->setMenu(createColorMenu(SLOT(textColorChanged()), Qt::black));
|
||||
fontColorToolButton->setMenu(createColorMenu(&MainWindow::textColorChanged, Qt::black));
|
||||
textAction = fontColorToolButton->menu()->defaultAction();
|
||||
fontColorToolButton->setIcon(createColorToolButtonIcon(":/images/textpointer.png", Qt::black));
|
||||
fontColorToolButton->setAutoFillBackground(true);
|
||||
@ -442,7 +442,7 @@ void MainWindow::createToolbars()
|
||||
//! [26]
|
||||
fillColorToolButton = new QToolButton;
|
||||
fillColorToolButton->setPopupMode(QToolButton::MenuButtonPopup);
|
||||
fillColorToolButton->setMenu(createColorMenu(SLOT(itemColorChanged()), Qt::white));
|
||||
fillColorToolButton->setMenu(createColorMenu(&MainWindow::itemColorChanged, Qt::white));
|
||||
fillAction = fillColorToolButton->menu()->defaultAction();
|
||||
fillColorToolButton->setIcon(createColorToolButtonIcon(
|
||||
":/images/floodfill.png", Qt::white));
|
||||
@ -452,7 +452,7 @@ void MainWindow::createToolbars()
|
||||
|
||||
lineColorToolButton = new QToolButton;
|
||||
lineColorToolButton->setPopupMode(QToolButton::MenuButtonPopup);
|
||||
lineColorToolButton->setMenu(createColorMenu(SLOT(lineColorChanged()), Qt::black));
|
||||
lineColorToolButton->setMenu(createColorMenu(&MainWindow::lineColorChanged, Qt::black));
|
||||
lineAction = lineColorToolButton->menu()->defaultAction();
|
||||
lineColorToolButton->setIcon(createColorToolButtonIcon(
|
||||
":/images/linecolor.png", Qt::black));
|
||||
@ -547,7 +547,8 @@ QWidget *MainWindow::createCellWidget(const QString &text, DiagramItem::DiagramT
|
||||
//! [29]
|
||||
|
||||
//! [30]
|
||||
QMenu *MainWindow::createColorMenu(const char *slot, QColor defaultColor)
|
||||
template<typename PointerToMemberFunction>
|
||||
QMenu *MainWindow::createColorMenu(const PointerToMemberFunction &slot, QColor defaultColor)
|
||||
{
|
||||
QList<QColor> colors;
|
||||
colors << Qt::black << Qt::white << Qt::red << Qt::blue << Qt::yellow;
|
||||
@ -560,7 +561,7 @@ QMenu *MainWindow::createColorMenu(const char *slot, QColor defaultColor)
|
||||
QAction *action = new QAction(names.at(i), this);
|
||||
action->setData(colors.at(i));
|
||||
action->setIcon(createColorIcon(colors.at(i)));
|
||||
connect(action, SIGNAL(triggered()), this, slot);
|
||||
connect(action, &QAction::triggered, this, slot);
|
||||
colorMenu->addAction(action);
|
||||
if (colors.at(i) == defaultColor)
|
||||
colorMenu->setDefaultAction(action);
|
||||
|
@ -64,7 +64,9 @@ private:
|
||||
const QString &image);
|
||||
QWidget *createCellWidget(const QString &text,
|
||||
DiagramItem::DiagramType type);
|
||||
QMenu *createColorMenu(const char *slot, QColor defaultColor);
|
||||
|
||||
template<typename PointerToMemberFunction>
|
||||
QMenu *createColorMenu(const PointerToMemberFunction &slot, QColor defaultColor);
|
||||
QIcon createColorToolButtonIcon(const QString &image, QColor color);
|
||||
QIcon createColorIcon(QColor color);
|
||||
|
||||
|
@ -341,7 +341,7 @@ PathStrokeWidget::PathStrokeWidget(bool smallScreen)
|
||||
|
||||
connect(m_renderer, &PathStrokeRenderer::clicked, this, &PathStrokeWidget::showControls);
|
||||
connect(m_controls, &PathStrokeControls::okPressed, this, &PathStrokeWidget::hideControls);
|
||||
connect(m_controls, SIGNAL(quitPressed()), QApplication::instance(), SLOT(quit()));
|
||||
connect(m_controls, &PathStrokeControls::quitPressed, QApplication::instance(), &QApplication::quit);
|
||||
}
|
||||
|
||||
void PathStrokeWidget::showControls()
|
||||
|
@ -29,29 +29,29 @@ Calculator::Calculator(QWidget *parent)
|
||||
|
||||
//! [4]
|
||||
for (int i = 0; i < NumDigitButtons; ++i)
|
||||
digitButtons[i] = createButton(QString::number(i), SLOT(digitClicked()));
|
||||
digitButtons[i] = createButton(QString::number(i), &Calculator::digitClicked);
|
||||
|
||||
Button *pointButton = createButton(tr("."), SLOT(pointClicked()));
|
||||
Button *changeSignButton = createButton(tr("\302\261"), SLOT(changeSignClicked()));
|
||||
Button *pointButton = createButton(tr("."), &Calculator::pointClicked);
|
||||
Button *changeSignButton = createButton(tr("\302\261"), &Calculator::changeSignClicked);
|
||||
|
||||
Button *backspaceButton = createButton(tr("Backspace"), SLOT(backspaceClicked()));
|
||||
Button *clearButton = createButton(tr("Clear"), SLOT(clear()));
|
||||
Button *clearAllButton = createButton(tr("Clear All"), SLOT(clearAll()));
|
||||
Button *backspaceButton = createButton(tr("Backspace"), &Calculator::backspaceClicked);
|
||||
Button *clearButton = createButton(tr("Clear"), &Calculator::clear);
|
||||
Button *clearAllButton = createButton(tr("Clear All"), &Calculator::clearAll);
|
||||
|
||||
Button *clearMemoryButton = createButton(tr("MC"), SLOT(clearMemory()));
|
||||
Button *readMemoryButton = createButton(tr("MR"), SLOT(readMemory()));
|
||||
Button *setMemoryButton = createButton(tr("MS"), SLOT(setMemory()));
|
||||
Button *addToMemoryButton = createButton(tr("M+"), SLOT(addToMemory()));
|
||||
Button *clearMemoryButton = createButton(tr("MC"), &Calculator::clearMemory);
|
||||
Button *readMemoryButton = createButton(tr("MR"), &Calculator::readMemory);
|
||||
Button *setMemoryButton = createButton(tr("MS"), &Calculator::setMemory);
|
||||
Button *addToMemoryButton = createButton(tr("M+"), &Calculator::addToMemory);
|
||||
|
||||
Button *divisionButton = createButton(tr("\303\267"), SLOT(multiplicativeOperatorClicked()));
|
||||
Button *timesButton = createButton(tr("\303\227"), SLOT(multiplicativeOperatorClicked()));
|
||||
Button *minusButton = createButton(tr("-"), SLOT(additiveOperatorClicked()));
|
||||
Button *plusButton = createButton(tr("+"), SLOT(additiveOperatorClicked()));
|
||||
Button *divisionButton = createButton(tr("\303\267"), &Calculator::multiplicativeOperatorClicked);
|
||||
Button *timesButton = createButton(tr("\303\227"), &Calculator::multiplicativeOperatorClicked);
|
||||
Button *minusButton = createButton(tr("-"), &Calculator::additiveOperatorClicked);
|
||||
Button *plusButton = createButton(tr("+"), &Calculator::additiveOperatorClicked);
|
||||
|
||||
Button *squareRootButton = createButton(tr("Sqrt"), SLOT(unaryOperatorClicked()));
|
||||
Button *powerButton = createButton(tr("x\302\262"), SLOT(unaryOperatorClicked()));
|
||||
Button *reciprocalButton = createButton(tr("1/x"), SLOT(unaryOperatorClicked()));
|
||||
Button *equalButton = createButton(tr("="), SLOT(equalClicked()));
|
||||
Button *squareRootButton = createButton(tr("Sqrt"), &Calculator::unaryOperatorClicked);
|
||||
Button *powerButton = createButton(tr("x\302\262"), &Calculator::unaryOperatorClicked);
|
||||
Button *reciprocalButton = createButton(tr("1/x"), &Calculator::unaryOperatorClicked);
|
||||
Button *equalButton = createButton(tr("="), &Calculator::equalClicked);
|
||||
//! [4]
|
||||
|
||||
//! [5]
|
||||
@ -324,10 +324,11 @@ void Calculator::addToMemory()
|
||||
}
|
||||
//! [32]
|
||||
//! [34]
|
||||
Button *Calculator::createButton(const QString &text, const char *member)
|
||||
template<typename PointerToMemberFunction>
|
||||
Button *Calculator::createButton(const QString &text, const PointerToMemberFunction &member)
|
||||
{
|
||||
Button *button = new Button(text);
|
||||
connect(button, SIGNAL(clicked()), this, member);
|
||||
connect(button, &Button::clicked, this, member);
|
||||
return button;
|
||||
}
|
||||
//! [34]
|
||||
|
@ -39,7 +39,8 @@ private slots:
|
||||
//! [1]
|
||||
private:
|
||||
//! [1] //! [2]
|
||||
Button *createButton(const QString &text, const char *member);
|
||||
template<typename PointerToMemberFunction>
|
||||
Button *createButton(const QString &text, const PointerToMemberFunction &member);
|
||||
void abortOperation();
|
||||
bool calculate(double rightOperand, const QString &pendingOperator);
|
||||
//! [2]
|
||||
|
@ -26,15 +26,15 @@ SortingBox::SortingBox(QWidget *parent)
|
||||
//! [3]
|
||||
newCircleButton = createToolButton(tr("New Circle"),
|
||||
QIcon(":/images/circle.png"),
|
||||
SLOT(createNewCircle()));
|
||||
&SortingBox::createNewCircle);
|
||||
|
||||
newSquareButton = createToolButton(tr("New Square"),
|
||||
QIcon(":/images/square.png"),
|
||||
SLOT(createNewSquare()));
|
||||
&SortingBox::createNewSquare);
|
||||
|
||||
newTriangleButton = createToolButton(tr("New Triangle"),
|
||||
QIcon(":/images/triangle.png"),
|
||||
SLOT(createNewTriangle()));
|
||||
&SortingBox::createNewTriangle);
|
||||
|
||||
circlePath.addEllipse(QRect(0, 0, 100, 100));
|
||||
squarePath.addRect(QRect(0, 0, 100, 100));
|
||||
@ -219,14 +219,15 @@ void SortingBox::createShapeItem(const QPainterPath &path,
|
||||
//! [21]
|
||||
|
||||
//! [22]
|
||||
template<typename PointerToMemberFunction>
|
||||
QToolButton *SortingBox::createToolButton(const QString &toolTip,
|
||||
const QIcon &icon, const char *member)
|
||||
const QIcon &icon, const PointerToMemberFunction &member)
|
||||
{
|
||||
QToolButton *button = new QToolButton(this);
|
||||
button->setToolTip(toolTip);
|
||||
button->setIcon(icon);
|
||||
button->setIconSize(QSize(32, 32));
|
||||
connect(button, SIGNAL(clicked()), this, member);
|
||||
connect(button, &QToolButton::clicked, this, member);
|
||||
|
||||
return button;
|
||||
}
|
||||
|
@ -47,9 +47,10 @@ private:
|
||||
QPoint randomItemPosition();
|
||||
QColor initialItemColor();
|
||||
QColor randomItemColor();
|
||||
template<typename PointerToMemberFunction>
|
||||
QToolButton *createToolButton(const QString &toolTip, const QIcon &icon,
|
||||
//! [1]
|
||||
const char *member);
|
||||
const PointerToMemberFunction &member);
|
||||
|
||||
//! [2]
|
||||
QList<ShapeItem> shapeItems;
|
||||
|
Loading…
Reference in New Issue
Block a user