tictactoedialog.cpp Example File
taskmenuextension/tictactoedialog.cpp
#include "tictactoe.h"
#include "tictactoedialog.h"
#include <QtDesigner/QDesignerFormWindowInterface>
#include <QtDesigner/QDesignerFormWindowCursorInterface>
#include <QDialogButtonBox>
#include <QPushButton>
#include <QVBoxLayout>
#include <QVariant>
TicTacToeDialog::TicTacToeDialog(TicTacToe *tic, QWidget *parent)
: QDialog(parent)
, editor(new TicTacToe)
, ticTacToe(tic)
, buttonBox(new QDialogButtonBox(QDialogButtonBox::Ok
| QDialogButtonBox::Cancel
| QDialogButtonBox::Reset))
{
editor->setState(ticTacToe->state());
connect(buttonBox->button(QDialogButtonBox::Reset), &QAbstractButton::clicked,
this, &TicTacToeDialog::resetState);
connect(buttonBox, &QDialogButtonBox::accepted, this, &TicTacToeDialog::saveState);
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(editor);
mainLayout->addWidget(buttonBox);
setLayout(mainLayout);
setWindowTitle(tr("Edit State"));
}
QSize TicTacToeDialog::sizeHint() const
{
return QSize(250, 250);
}
void TicTacToeDialog::resetState()
{
editor->clearBoard();
}
void TicTacToeDialog::saveState()
{
if (QDesignerFormWindowInterface *formWindow
= QDesignerFormWindowInterface::findFormWindow(ticTacToe)) {
formWindow->cursor()->setProperty("state", editor->state());
}
accept();
}