X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;f=colorflood%2Fsrc%2Fwindow.cpp;h=49084406b62609891af814888a53eef7a950443e;hb=27e33bd9936eba25baf492a097cfed4e89ddbea8;hp=affafdc431b4cc5aab8e180f1703ab47da0d24bb;hpb=7376453b0a57a4848c86f127d217b34ac3f25830;p=colorflood diff --git a/colorflood/src/window.cpp b/colorflood/src/window.cpp index affafdc..4908440 100644 --- a/colorflood/src/window.cpp +++ b/colorflood/src/window.cpp @@ -15,10 +15,13 @@ #include #include #include +#include +#include #include "window.hpp" #include "colorbuttons.hpp" #include "field.hpp" -//#include "fullscreenexitbutton.hpp" +#include "fullscreenexitbutton.hpp" +#include "colorscheme.hpp" Window::Window () : QWidget() @@ -26,14 +29,6 @@ Window::Window () setWindowTitle("Color Flood"); setWindowIcon(QIcon(":/images/icon_48x48.png")); -#if defined(Q_WS_HILDON) || defined(Q_WS_MAEMO_5) - setWindowState(windowState() | Qt::WindowFullScreen); -#else - setFixedSize(800, 480); -#endif - - //new FullScreenExitButton(this); - int turns; field = new Field(this, &turns); colorButtons = new ColorButtons(this); @@ -44,6 +39,7 @@ Window::Window () SLOT(flood(int))); turnsLabel = new QLabel(this); + turnsLabel->setAlignment(Qt::AlignRight); QObject::connect(field, SIGNAL(turnsChanged(int)), @@ -52,11 +48,16 @@ Window::Window () updateTurns(turns); + QPushButton *newGame = new QPushButton(tr("New game"), this); + QObject::connect(newGame, SIGNAL(pressed()), field, SLOT(randomize())); + QVBoxLayout *vl = new QVBoxLayout; vl->addWidget(colorButtons); vl->setAlignment(colorButtons, Qt::AlignRight | Qt::AlignTop); vl->addWidget(turnsLabel); - vl->setAlignment(turnsLabel, Qt::AlignRight | Qt::AlignTop); + vl->setAlignment(turnsLabel, Qt::AlignRight | Qt::AlignBottom); + vl->addWidget(newGame); + vl->setAlignment(newGame, Qt::AlignRight | Qt::AlignTop); QHBoxLayout *hl = new QHBoxLayout; hl->addWidget(field); @@ -64,6 +65,43 @@ Window::Window () hl->addLayout(vl); setLayout(hl); + + /* menu bar */ + QMenuBar *bar = new QMenuBar(this); + + QObject::connect(bar->addAction(tr("Fullscreen mode")), + SIGNAL(triggered()), + this, + SLOT(fullScreenMode())); + + QObject::connect(bar->addAction( + ColorScheme::getSchemeName( + ColorScheme::getNextColorScheme())), + SIGNAL(triggered()), + this, + SLOT(colorScheme())); + + less = bar->addAction(tr("Less cells")); + + QObject::connect(less, + SIGNAL(triggered()), + this, + SLOT(lessCells())); + + more = bar->addAction(tr("More cells")); + + QObject::connect(more, + SIGNAL(triggered()), + this, + SLOT(moreCells())); + + if (!field->getSize()) + less->setEnabled(false); + else if (field->getSize() == Field::NUM_SIZES - 1) + more->setEnabled(false); + + new FullScreenExitButton(this); + showFullScreen(); } void Window::updateTurns (int turns) @@ -73,3 +111,43 @@ void Window::updateTurns (int turns) .arg(turns) .arg(field->getNumTurnsOfSize(field->getSize()))); } + +void Window::fullScreenMode () +{ + showFullScreen(); +} + +void Window::lessCells () +{ + int s = field->getSize() - 1; + + field->setSize(s); + more->setEnabled(true); + + if (!s) + less->setEnabled(false); +} + +void Window::moreCells () +{ + int s = field->getSize() + 1; + + field->setSize(s); + less->setEnabled(true); + + if (s == Field::NUM_SIZES - 1) + more->setEnabled(false); +} + +void Window::colorScheme () +{ + QAction *action = static_cast(QObject::sender()); + + ColorScheme::setScheme(ColorScheme::getNextColorScheme()); + + field->update(); + colorButtons->update(); + + action->setText(ColorScheme::getSchemeName( + ColorScheme::getNextColorScheme())); +}