From c9371ba06d07bf654792588bd008af0efe940dc0 Mon Sep 17 00:00:00 2001 From: Serge Ziryukin Date: Wed, 14 Apr 2010 00:06:07 +0300 Subject: [PATCH 1/1] size/scheme options; better translation --- colorflood/src/colorflood.ts | 38 +++++++++++++----- colorflood/src/colorscheme.cpp | 13 ++++-- colorflood/src/colorscheme.hpp | 1 + colorflood/src/field.cpp | 11 +++++ colorflood/src/field.hpp | 1 + colorflood/src/window.cpp | 86 +++++++++++++++++++++++++++++++++++----- colorflood/src/window.hpp | 8 +++- 7 files changed, 132 insertions(+), 26 deletions(-) diff --git a/colorflood/src/colorflood.ts b/colorflood/src/colorflood.ts index d940f0a..b928848 100644 --- a/colorflood/src/colorflood.ts +++ b/colorflood/src/colorflood.ts @@ -4,13 +4,13 @@ Field - + You won! win message Вы выиграли! - + You lost! fail message Вы проиграли! @@ -20,29 +20,47 @@ QObject - Default + Default scheme + Default default color scheme name - Стандартная + Стандартная схема - Black-and-white + Black-and-white scheme + Black-and-white black-and-white color scheme name - Чёрно-белая + Чёрно-белая схема Window - + New game Новая игра - - <font size="16">Turns: %1/%2</font> + + Fullscreen mode + Полноэкранный режим + + + + Less cells + Меньше клеток + + + + More cells + Больше клеток + + + + <font size="12">Turns: %1/%2</font> + <font size="16">Turns: %1/%2</font> number of turns - <font size="16">Шагов: %1/%2</font> + <font size="12">Шагов: %1/%2</font> diff --git a/colorflood/src/colorscheme.cpp b/colorflood/src/colorscheme.cpp index bb7af78..096cd33 100644 --- a/colorflood/src/colorscheme.cpp +++ b/colorflood/src/colorscheme.cpp @@ -30,17 +30,17 @@ ColorScheme::ColorScheme () s << QColor(0xf0, 0x70, 0xa0); s << QColor(0xdc, 0x4a, 0x20); /*: default color scheme name */ - schemes << QPair >(QObject::tr("Default"), s); + schemes << QPair >(QObject::tr("Default scheme"), s); s.clear(); s << QBrush(QColor(0x00, 0x00, 0x00), Qt::SolidPattern); - s << QBrush(QColor(0x33, 0x33, 0x33), Qt::Dense3Pattern); + s << QBrush(QColor(0x20, 0x20, 0x20), Qt::Dense3Pattern); s << QBrush(QColor(0x66, 0x66, 0x66), Qt::Dense1Pattern); s << QBrush(QColor(0x99, 0x99, 0x99), Qt::SolidPattern); s << QBrush(QColor(0xcc, 0xcc, 0xcc), Qt::CrossPattern); s << QBrush(QColor(0xff, 0xff, 0xff), Qt::SolidPattern); /*: black-and-white color scheme name */ - schemes << QPair >(QObject::tr("Black-and-white"), s); + schemes << QPair >(QObject::tr("Black-and-white scheme"), s); QSettings settings; currentScheme = settings.value("colorScheme", 0).toInt(); @@ -60,9 +60,14 @@ int ColorScheme::getNumSchemes () return schemes.size(); } +int ColorScheme::getNextColorScheme () +{ + return (currentScheme + 1) % schemes.size(); +} + QString ColorScheme::getSchemeName (int scheme) { - Q_ASSERT(scheme > 0 && scheme < getNumSchemes()); + Q_ASSERT(scheme >= 0 && scheme < getNumSchemes()); return schemes.at(scheme).first; } diff --git a/colorflood/src/colorscheme.hpp b/colorflood/src/colorscheme.hpp index c366def..db6b786 100644 --- a/colorflood/src/colorscheme.hpp +++ b/colorflood/src/colorscheme.hpp @@ -29,6 +29,7 @@ public: } static int getNumSchemes (); + static int getNextColorScheme (); static QString getSchemeName (int scheme); const QVector &getScheme (int scheme); static QString getSchemeName (); diff --git a/colorflood/src/field.cpp b/colorflood/src/field.cpp index 44e3259..89b5d17 100644 --- a/colorflood/src/field.cpp +++ b/colorflood/src/field.cpp @@ -114,6 +114,17 @@ Field::FieldSize Field::getSize () const return size; } +void Field::setSize (int size) +{ + Q_ASSERT(size >= 0 && size < NUM_SIZES); + + if (this->size == size) + return; + + this->size = (FieldSize)size; + randomize(); +} + void Field::randomize () { FieldRect rect; diff --git a/colorflood/src/field.hpp b/colorflood/src/field.hpp index 81deb1b..c3b81f9 100644 --- a/colorflood/src/field.hpp +++ b/colorflood/src/field.hpp @@ -46,6 +46,7 @@ public: ~Field (); FieldSize getSize () const; + void setSize (int size); static int getNumRectsOfSize (FieldSize size); static int getNumTurnsOfSize (FieldSize size); diff --git a/colorflood/src/window.cpp b/colorflood/src/window.cpp index e0b64ea..7ade0a3 100644 --- a/colorflood/src/window.cpp +++ b/colorflood/src/window.cpp @@ -16,10 +16,12 @@ #include #include #include +#include #include "window.hpp" #include "colorbuttons.hpp" #include "field.hpp" #include "fullscreenexitbutton.hpp" +#include "colorscheme.hpp" Window::Window () : QWidget() @@ -64,26 +66,88 @@ Window::Window () setLayout(hl); - QSettings settings; + /* menu bar */ + QMenuBar *bar = new QMenuBar(this); - if (settings.value("fullscreen", true).toBool()) - showFullScreen(); + QObject::connect(bar->addAction(tr("Fullscreen mode")), + SIGNAL(triggered()), + this, + SLOT(fullScreenMode())); - new FullScreenExitButton(this); -} + QObject::connect(bar->addAction( + ColorScheme::getSchemeName( + ColorScheme::getNextColorScheme())), + SIGNAL(triggered()), + this, + SLOT(colorScheme())); -Window::~Window () -{ - bool isFullscreen = windowState() & Qt::WindowFullScreen; + less = bar->addAction(tr("Less cells")); + + QObject::connect(less, + SIGNAL(triggered()), + this, + SLOT(lessCells())); + + more = bar->addAction(tr("More cells")); - QSettings settings; - settings.setValue("fullscreen", isFullscreen); + 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) { /*: number of turns */ - turnsLabel->setText(tr("Turns: %1/%2") + turnsLabel->setText(tr("Turns: %1/%2") .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())); +} diff --git a/colorflood/src/window.hpp b/colorflood/src/window.hpp index 6429eae..9942a28 100644 --- a/colorflood/src/window.hpp +++ b/colorflood/src/window.hpp @@ -19,6 +19,7 @@ class ColorButtons; class Field; class QLabel; +class QAction; class Window : public QWidget { @@ -26,15 +27,20 @@ class Window : public QWidget public: Window (); - ~Window (); private slots: void updateTurns (int turns); + void fullScreenMode (); + void colorScheme (); + void lessCells (); + void moreCells (); private: ColorButtons *colorButtons; Field *field; QLabel *turnsLabel; + QAction *less; + QAction *more; }; #endif // !_WINDOW_HPP -- 1.7.9.5