hildon fullscreen button is back
[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 <QSettings>
19 #include "window.hpp"
20 #include "colorbuttons.hpp"
21 #include "field.hpp"
22 #include "fullscreenexitbutton.hpp"
23
24 Window::Window ()
25     : QWidget()
26 {
27     setWindowTitle("Color Flood");
28     setWindowIcon(QIcon(":/images/icon_48x48.png"));
29
30     new FullScreenExitButton(this);
31
32     int turns;
33     field = new Field(this, &turns);
34     colorButtons = new ColorButtons(this);
35
36     QObject::connect(colorButtons,
37                      SIGNAL(flood(int)),
38                      field,
39                      SLOT(flood(int)));
40
41     turnsLabel = new QLabel(this);
42     turnsLabel->setAlignment(Qt::AlignRight);
43
44     QObject::connect(field,
45                      SIGNAL(turnsChanged(int)),
46                      this,
47                      SLOT(updateTurns(int)));
48
49     updateTurns(turns);
50
51     QHBoxLayout *secondary = new QHBoxLayout;
52     QPushButton *toggleFS = new QPushButton(QPixmap("/usr/share/icons/hicolor/64x64/hildon/general_fullsize"), tr("Toggle fullscreen"), this);
53     QObject::connect(toggleFS, SIGNAL(pressed()), this, SLOT(toggleFullscreen()));
54     QPushButton *newGame = new QPushButton(tr("New game"), this);
55     QObject::connect(newGame, SIGNAL(pressed()), field, SLOT(randomize()));
56
57     secondary->addWidget(newGame);
58     secondary->addWidget(toggleFS);
59
60     QVBoxLayout *vl = new QVBoxLayout;
61     vl->addWidget(colorButtons);
62     vl->setAlignment(colorButtons, Qt::AlignRight | Qt::AlignTop);
63     vl->addWidget(turnsLabel);
64     vl->setAlignment(turnsLabel, Qt::AlignRight | Qt::AlignTop);
65     vl->addLayout(secondary);
66     vl->setAlignment(secondary, Qt::AlignRight | Qt::AlignBottom);
67
68     QHBoxLayout *hl = new QHBoxLayout;
69     hl->addWidget(field);
70     hl->setAlignment(field, Qt::AlignLeft);
71     hl->addLayout(vl);
72
73     setLayout(hl);
74
75     QSettings settings;
76
77     if (settings.value("fullscreen", true).toBool())
78         showFullScreen();
79 }
80
81 void Window::updateTurns (int turns)
82 {
83     /*: number of turns */
84     turnsLabel->setText(tr("<font size=\"16\">Turns: %1/%2</font>")
85                         .arg(turns)
86                         .arg(field->getNumTurnsOfSize(field->getSize())));
87 }
88
89 void Window::toggleFullscreen ()
90 {
91     bool isFullscreen = windowState() & Qt::WindowFullScreen;
92
93     QSettings settings;
94     settings.setValue("fullscreen", !isFullscreen);
95
96     if (isFullscreen)
97         showNormal();
98     else
99         showFullScreen();
100 }