source: trunk/examples/widgets/tetrix/tetrixwindow.cpp@ 651

Last change on this file since 651 was 651, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.6.2 sources.

File size: 4.1 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the examples of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
24** In addition, as a special exception, Nokia gives you certain additional
25** rights. These rights are described in the Nokia Qt LGPL Exception
26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include <QtGui>
43
44#include "tetrixboard.h"
45#include "tetrixwindow.h"
46
47//! [0]
48TetrixWindow::TetrixWindow()
49{
50 board = new TetrixBoard;
51//! [0]
52
53 nextPieceLabel = new QLabel;
54 nextPieceLabel->setFrameStyle(QFrame::Box | QFrame::Raised);
55 nextPieceLabel->setAlignment(Qt::AlignCenter);
56 board->setNextPieceLabel(nextPieceLabel);
57
58//! [1]
59 scoreLcd = new QLCDNumber(5);
60 scoreLcd->setSegmentStyle(QLCDNumber::Filled);
61//! [1]
62 levelLcd = new QLCDNumber(2);
63 levelLcd->setSegmentStyle(QLCDNumber::Filled);
64 linesLcd = new QLCDNumber(5);
65 linesLcd->setSegmentStyle(QLCDNumber::Filled);
66
67//! [2]
68 startButton = new QPushButton(tr("&Start"));
69 startButton->setFocusPolicy(Qt::NoFocus);
70 quitButton = new QPushButton(tr("&Quit"));
71 quitButton->setFocusPolicy(Qt::NoFocus);
72 pauseButton = new QPushButton(tr("&Pause"));
73//! [2] //! [3]
74 pauseButton->setFocusPolicy(Qt::NoFocus);
75//! [3] //! [4]
76
77 connect(startButton, SIGNAL(clicked()), board, SLOT(start()));
78//! [4] //! [5]
79 connect(quitButton , SIGNAL(clicked()), qApp, SLOT(quit()));
80 connect(pauseButton, SIGNAL(clicked()), board, SLOT(pause()));
81 connect(board, SIGNAL(scoreChanged(int)), scoreLcd, SLOT(display(int)));
82 connect(board, SIGNAL(levelChanged(int)), levelLcd, SLOT(display(int)));
83 connect(board, SIGNAL(linesRemovedChanged(int)),
84 linesLcd, SLOT(display(int)));
85//! [5]
86
87//! [6]
88 QGridLayout *layout = new QGridLayout;
89 layout->addWidget(createLabel(tr("NEXT")), 0, 0);
90 layout->addWidget(nextPieceLabel, 1, 0);
91 layout->addWidget(createLabel(tr("LEVEL")), 2, 0);
92 layout->addWidget(levelLcd, 3, 0);
93 layout->addWidget(startButton, 4, 0);
94 layout->addWidget(board, 0, 1, 6, 1);
95 layout->addWidget(createLabel(tr("SCORE")), 0, 2);
96 layout->addWidget(scoreLcd, 1, 2);
97 layout->addWidget(createLabel(tr("LINES REMOVED")), 2, 2);
98 layout->addWidget(linesLcd, 3, 2);
99 layout->addWidget(quitButton, 4, 2);
100 layout->addWidget(pauseButton, 5, 2);
101 setLayout(layout);
102
103 setWindowTitle(tr("Tetrix"));
104 resize(550, 370);
105}
106//! [6]
107
108//! [7]
109QLabel *TetrixWindow::createLabel(const QString &text)
110{
111 QLabel *lbl = new QLabel(text);
112 lbl->setAlignment(Qt::AlignHCenter | Qt::AlignBottom);
113 return lbl;
114}
115//! [7]
116
Note: See TracBrowser for help on using the repository browser.