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

Last change on this file since 507 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 4.1 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the examples of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** 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 are unsure which license is appropriate for your use, please
37** contact the sales department 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.