examples/widgets/tetrix/tetrixwindow.cpp
changeset 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the examples of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    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 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #include <QtGui>
       
    43 
       
    44 #include "tetrixboard.h"
       
    45 #include "tetrixwindow.h"
       
    46 
       
    47 //! [0]
       
    48 TetrixWindow::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]
       
   109 QLabel *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