rearrange controls
[colorflood] / colorflood / src / window.cpp
1 /*
2   Copyright 2010 Serge Ziryukin <ftrvxmtrx@gmail.com>
3
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU General Public License as published by
6   the Free Software Foundation; version 2 of the License.
7
8   This program is distributed in the hope that it will be useful,
9   but WITHOUT ANY WARRANTY; without even the implied warranty of
10   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11   GNU General Public License for more details.
12 */
13
14 #include <QPushButton>
15 #include <QVBoxLayout>
16 #include <QHBoxLayout>
17 #include <QLabel>
18 #include "window.hpp"
19 #include "colorbuttons.hpp"
20 #include "field.hpp"
21 //#include "fullscreenexitbutton.hpp"
22
23 Window::Window ()
24     : QWidget()
25 {
26     setWindowTitle("Color Flood");
27     setWindowIcon(QIcon(":/images/icon_48x48.png"));
28
29 #if defined(Q_WS_HILDON) || defined(Q_WS_MAEMO_5)
30     setWindowState(windowState() | Qt::WindowFullScreen);
31 #else
32     setFixedSize(800, 480);
33 #endif
34
35     //new FullScreenExitButton(this);
36
37     int turns;
38     field = new Field(this, &turns);
39     colorButtons = new ColorButtons(this);
40
41     QObject::connect(colorButtons,
42                      SIGNAL(flood(int)),
43                      field,
44                      SLOT(flood(int)));
45
46     turnsLabel = new QLabel(this);
47
48     QObject::connect(field,
49                      SIGNAL(turnsChanged(int)),
50                      this,
51                      SLOT(updateTurns(int)));
52
53     updateTurns(turns);
54
55     QVBoxLayout *vl = new QVBoxLayout;
56     vl->addWidget(colorButtons);
57     vl->setAlignment(colorButtons, Qt::AlignRight | Qt::AlignTop);
58     vl->addWidget(turnsLabel);
59     vl->setAlignment(turnsLabel, Qt::AlignRight | Qt::AlignTop);
60
61     QHBoxLayout *hl = new QHBoxLayout;
62     hl->addWidget(field);
63     hl->setAlignment(field, Qt::AlignLeft);
64     hl->addLayout(vl);
65
66     setLayout(hl);
67 }
68
69 void Window::updateTurns (int turns)
70 {
71     /*: number of turns */
72     turnsLabel->setText(tr("Turns: %1/%2")
73                         .arg(turns)
74                         .arg(field->getNumTurnsOfSize(field->getSize())));
75 }