From 799dba4acf15f7fd5776c3677d3d8b04d5682079 Mon Sep 17 00:00:00 2001 From: Valentino Orlandi Date: Thu, 10 Nov 2022 18:20:47 +0100 Subject: [PATCH] Updated games to use stylesheets Added GameSec shared class. Added Ash theme. --- logdoctor/games/crisscross.cpp | 9 ++- logdoctor/games/crisscross.h | 2 +- logdoctor/games/games.cpp | 134 +++++++++++++++++++++++++++++++++ logdoctor/games/games.h | 16 ++++ logdoctor/games/snake.cpp | 10 ++- logdoctor/games/snake.h | 2 +- 6 files changed, 167 insertions(+), 6 deletions(-) create mode 100644 logdoctor/games/games.cpp create mode 100644 logdoctor/games/games.h diff --git a/logdoctor/games/crisscross.cpp b/logdoctor/games/crisscross.cpp index 2972a27e..322208de 100644 --- a/logdoctor/games/crisscross.cpp +++ b/logdoctor/games/crisscross.cpp @@ -2,15 +2,20 @@ #include "crisscross.h" #include "ui_crisscross.h" +#include "games/games.h" + #include -CrissCross::CrissCross( const QPalette& style, QWidget* parent ) : +CrissCross::CrissCross( const int& theme_id, QWidget* parent ) : QWidget(parent), ui(new Ui::CrissCross) { this->ui->setupUi(this); - this->setPalette( style ); + + QString stylesheet = ""; + GameSec::crisscrossStyleSheet( stylesheet, theme_id ); + this->setStyleSheet( stylesheet ); // verify that one player is human and the other is not if ( !(p1_human^p2_human) ) { diff --git a/logdoctor/games/crisscross.h b/logdoctor/games/crisscross.h index 9632a0c7..592509a0 100644 --- a/logdoctor/games/crisscross.h +++ b/logdoctor/games/crisscross.h @@ -15,7 +15,7 @@ class CrissCross : public QWidget Q_OBJECT public: - explicit CrissCross( const QPalette& style, QWidget* parent=nullptr ); + explicit CrissCross( const int& theme_id, QWidget* parent=nullptr ); ~CrissCross(); private slots: diff --git a/logdoctor/games/games.cpp b/logdoctor/games/games.cpp new file mode 100644 index 00000000..3d5ffd09 --- /dev/null +++ b/logdoctor/games/games.cpp @@ -0,0 +1,134 @@ + +#include "games.h" + +#include "modules/exceptions.h" + + +GameSec::GameSec() +{ + +} + + +void GameSec::crisscrossStyleSheet( QString& stylesheet, const int& theme_id ) +{ + switch ( theme_id ) { + case 0: + break; + case 1: + stylesheet = + "QWidget#CrissCross {" + " background-color: rgb( 32, 32, 32 );" + "}" + "QPushButton#button_NE," + "QPushButton#button_N," + "QPushButton#button_NW," + "QPushButton#button_E," + "QPushButton#button_C," + "QPushButton#button_W," + "QPushButton#button_SE," + "QPushButton#button_S," + "QPushButton#button_SW {" + " border-radius: 4px;" + " border: 1px solid rgb( 32, 32, 32 );" + " background-color: rgb( 32, 32, 32 );" + "}" + "QPushButton#button_NE:hover," + "QPushButton#button_N:hover," + "QPushButton#button_NW:hover," + "QPushButton#button_E:hover," + "QPushButton#button_C:hover," + "QPushButton#button_W:hover," + "QPushButton#button_SE:hover," + "QPushButton#button_S:hover," + "QPushButton#button_SW:hover {" + " border-color: rgb( 64, 64, 64 );" + " background-color: rgb( 40, 40, 40 );" + "}" + "QPushButton#button_NE::flat," + "QPushButton#button_N::flat," + "QPushButton#button_NW::flat," + "QPushButton#button_E::flat," + "QPushButton#button_C::flat," + "QPushButton#button_W::flat," + "QPushButton#button_SE::flat," + "QPushButton#button_S::flat," + "QPushButton#button_SW::flat {" + " border-color: rgb( 32, 32, 32 );" + " background-color: rgb( 32, 32, 32 );" + "}" + "QFrame#line_1," + "QFrame#line_2," + "QFrame#line_3," + "QFrame#line_4," + "QFrame#line_5," + "QFrame#line_6," + "QFrame#line_7," + "QFrame#line_8," + "QFrame#line_9," + "QFrame#line_10," + "QFrame#line_11," + "QFrame#line_12 {" + " border: 1px solid rgb( 16, 16, 16 );" + " background-color: rgb( 192, 192, 192 );" + "}"; + break; + case 2: + break; + case 3: + break; + case 4: + break; + default: + throw GenericException( "Unexpected WindowTheme ID: "+std::to_string(theme_id), true ); + break; + } +} + + +void GameSec::snakeStyleSheet( QString& stylesheet, const int& theme_id ) +{ + switch ( theme_id ) { + case 0: + break; + case 1: + stylesheet = + "QWidget#Snake {" + " background-color: rgb( 16, 16, 16 );" + "}" + "QWidget#stackedPage_GameMenu," + "QWidget#stackedPage_GameBoard {" + " border-radius: 4px;" + " border: 1px solid rgb( 128, 128, 128 );" + " background-color: rgb( 32, 32, 32 );" + "}" + "QPushButton#button_Play {" + " border-radius: 4px;" + " border: 1px solid rgb( 82, 82, 82 );" + " background-color: rgb( 64, 64, 64 );" + "}" + "QPushButton#button_Play:hover {" + " border-color: rgb( 128, 128, 128 );" + " background-color: rgb( 96, 96, 96 );" + "}" + "QFrame#frame_Score {" + " border-radius: 4px;" + " border: 1px solid rgb( 82, 82, 82 );" + " background-color: rgb( 64, 64, 64 );" + "}" + "QLCDNumber#lcd_Score {" + " color: rgb( 248, 248, 248 );" + " background-color: rgb( 0, 0, 0 );" + "}"; + break; + case 2: + break; + case 3: + break; + case 4: + break; + default: + throw GenericException( "Unexpected WindowTheme ID: "+std::to_string(theme_id), true ); + break; + } +} diff --git a/logdoctor/games/games.h b/logdoctor/games/games.h new file mode 100644 index 00000000..ba3c4711 --- /dev/null +++ b/logdoctor/games/games.h @@ -0,0 +1,16 @@ +#ifndef GAMES_H +#define GAMES_H + +#include + + +class GameSec +{ +public: + GameSec(); + + static void crisscrossStyleSheet( QString& stylesheet, const int& theme_id ); + static void snakeStyleSheet( QString& stylesheet, const int& theme_id ); +}; + +#endif // GAMES_H diff --git a/logdoctor/games/snake.cpp b/logdoctor/games/snake.cpp index fb163d48..4a71e48f 100644 --- a/logdoctor/games/snake.cpp +++ b/logdoctor/games/snake.cpp @@ -2,22 +2,28 @@ #include "snake.h" #include "ui_snake.h" +#include "games/games.h" + #include #include #include -Snake:: Snake(const QPalette& style, const QFont& term_font, QWidget* parent ) : +Snake::Snake( const int& theme_id, const QFont& term_font, QWidget* parent ) : QWidget(parent), ui(new Ui::Snake) { this->ui->setupUi(this); - this->setPalette( style ); + QString stylesheet = ""; + GameSec::snakeStyleSheet( stylesheet, theme_id ); + this->setStyleSheet( stylesheet ); + QFont font = QFont( term_font ); font.setPointSize( 64 ); this->ui->button_Play->setFont( font ); + // create the field this->field_scene = new QGraphicsScene( this ); this->field_scene->setSceneRect( 0,0, 544, 544 ); this->field_scene->setBackgroundBrush( Qt::black ); diff --git a/logdoctor/games/snake.h b/logdoctor/games/snake.h index 153657ce..56a943ab 100644 --- a/logdoctor/games/snake.h +++ b/logdoctor/games/snake.h @@ -20,7 +20,7 @@ class Snake : public QWidget Q_OBJECT public: - explicit Snake( const QPalette& style, const QFont& term_font, QWidget* parent=nullptr ); + explicit Snake( const int& theme_id, const QFont& term_font, QWidget* parent=nullptr ); ~Snake(); private slots: