1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include "tictactoe.h"
#include "tictactoedialog.h"
#include <QtDesigner/QDesignerFormWindowInterface>
#include <QtDesigner/QDesignerFormWindowCursorInterface>
#include <QDialogButtonBox>
#include <QPushButton>
#include <QVBoxLayout>
#include <QVariant>
//! [0]
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(this);
mainLayout->addWidget(editor);
mainLayout->addWidget(buttonBox);
setWindowTitle(tr("Edit State"));
}
//! [0]
//! [1]
QSize TicTacToeDialog::sizeHint() const
{
return QSize(250, 250);
}
//! [1]
//! [2]
void TicTacToeDialog::resetState()
{
editor->clearBoard();
}
//! [2]
//! [3]
void TicTacToeDialog::saveState()
{
//! [3] //! [4]
if (QDesignerFormWindowInterface *formWindow
= QDesignerFormWindowInterface::findFormWindow(ticTacToe)) {
formWindow->cursor()->setProperty("state", editor->state());
}
//! [4] //! [5]
accept();
}
//! [5]
|