new game/toggle fullscreen buttons
authorSerge Ziryukin <ftrvxmtrx@gmail.com>
Tue, 13 Apr 2010 17:28:37 +0000 (20:28 +0300)
committerSerge Ziryukin <ftrvxmtrx@gmail.com>
Tue, 13 Apr 2010 17:28:37 +0000 (20:28 +0300)
colorflood/src/colorflood.qm
colorflood/src/colorflood.ts
colorflood/src/field.cpp
colorflood/src/field.hpp
colorflood/src/window.cpp
colorflood/src/window.hpp

index 1d5f4e8..4282c75 100644 (file)
Binary files a/colorflood/src/colorflood.qm and b/colorflood/src/colorflood.qm differ
index 7711989..0672e6c 100644 (file)
@@ -4,13 +4,13 @@
 <context>
     <name>Field</name>
     <message>
-        <location filename="field.cpp" line="268"/>
+        <location filename="field.cpp" line="262"/>
         <source>You won!</source>
         <extracomment>win message</extracomment>
         <translation type="unfinished">Вы победили!</translation>
     </message>
     <message>
-        <location filename="field.cpp" line="274"/>
+        <location filename="field.cpp" line="268"/>
         <source>You lost!</source>
         <extracomment>fail message</extracomment>
         <translation type="unfinished">Вы проиграли!</translation>
 <context>
     <name>Window</name>
     <message>
-        <location filename="window.cpp" line="73"/>
+        <location filename="window.cpp" line="52"/>
+        <source>Toggle fullscreen</source>
+        <translation type="unfinished">Полноэкранный режим</translation>
+    </message>
+    <message>
+        <location filename="window.cpp" line="54"/>
+        <source>New game</source>
+        <oldsource>New Game</oldsource>
+        <translation type="unfinished">Новая игра</translation>
+    </message>
+    <message>
+        <location filename="window.cpp" line="84"/>
         <source>&lt;font size=&quot;24&quot;&gt;Turns: %1/%2&lt;/font&gt;</source>
         <extracomment>number of turns</extracomment>
         <translation type="unfinished">&lt;font size=&quot;24&quot;&gt;Шагов: %1/%2&lt;/font&gt;</translation>
index c2c556c..44e3259 100644 (file)
@@ -189,12 +189,6 @@ void Field::floodNeighbours (quint8 brush, int x, int y)
         tryFloodRecurse(brush, x, y + 1);
 }
 
-void Field::mousePressEvent (QMouseEvent *event)
-{
-    if (event->button() == Qt::LeftButton)
-        randomize();
-}
-
 void Field::paintEvent (QPaintEvent *event)
 {
     QPainter painter;
index 9009857..81deb1b 100644 (file)
@@ -54,7 +54,6 @@ private:
     static const int numRects[NUM_SIZES];
     static const int numTurns[NUM_SIZES];
 
-    void randomize ();
     static int getRectSize (FieldSize size);
     void tryFloodRecurse (quint8 brush, int x, int y);
     void floodNeighbours (quint8 brush, int x, int y);
@@ -65,13 +64,13 @@ private:
     bool       finished;
 
 protected:
-    void mousePressEvent (QMouseEvent *event);
     void paintEvent (QPaintEvent *event);
 
 signals:
     void turnsChanged (int turns);
 
 public slots:
+    void randomize ();
     void flood (int colorIndex);
 };
 
index 625022b..63b485b 100644 (file)
@@ -15,6 +15,7 @@
 #include <QVBoxLayout>
 #include <QHBoxLayout>
 #include <QLabel>
+#include <QSettings>
 #include "window.hpp"
 #include "colorbuttons.hpp"
 #include "field.hpp"
@@ -26,12 +27,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;
@@ -53,11 +48,22 @@ Window::Window ()
 
     updateTurns(turns);
 
+    QHBoxLayout *secondary = new QHBoxLayout;
+    QPushButton *toggleFS = new QPushButton(QIcon("/usr/share/icons/hicolor/64x64/hildon/general_fullsize.png"), tr("Toggle fullscreen"), this);
+    QObject::connect(toggleFS, SIGNAL(pressed()), this, SLOT(toggleFullscreen()));
+    QPushButton *newGame = new QPushButton(tr("New game"), this);
+    QObject::connect(newGame, SIGNAL(pressed()), field, SLOT(randomize()));
+
+    secondary->addWidget(newGame);
+    secondary->addWidget(toggleFS);
+
     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->addLayout(secondary);
+    vl->setAlignment(secondary, Qt::AlignRight | Qt::AlignBottom);
 
     QHBoxLayout *hl = new QHBoxLayout;
     hl->addWidget(field);
@@ -65,6 +71,11 @@ Window::Window ()
     hl->addLayout(vl);
 
     setLayout(hl);
+
+    QSettings settings;
+
+    if (settings.value("fullscreen", true).toBool())
+        showFullScreen();
 }
 
 void Window::updateTurns (int turns)
@@ -74,3 +85,16 @@ void Window::updateTurns (int turns)
                         .arg(turns)
                         .arg(field->getNumTurnsOfSize(field->getSize())));
 }
+
+void Window::toggleFullscreen ()
+{
+    bool isFullscreen = windowState() & Qt::WindowFullScreen;
+
+    QSettings settings;
+    settings.setValue("fullscreen", !isFullscreen);
+
+    if (isFullscreen)
+        showNormal();
+    else
+        showFullScreen();
+}
index e97b602..dd1f4a1 100644 (file)
@@ -29,6 +29,7 @@ public:
 
 private slots:
     void updateTurns (int turns);
+    void toggleFullscreen ();
 
 private:
     ColorButtons *colorButtons;