Updated games to use stylesheets

Added GameSec shared class.
Added Ash theme.
This commit is contained in:
Valentino Orlandi 2022-11-10 18:20:47 +01:00
parent 49dcf6361e
commit 799dba4acf
Signed by: elB4RTO
GPG Key ID: 1719E976DB2D4E71
6 changed files with 167 additions and 6 deletions

View File

@ -2,15 +2,20 @@
#include "crisscross.h"
#include "ui_crisscross.h"
#include "games/games.h"
#include <QMessageBox>
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) ) {

View File

@ -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:

134
logdoctor/games/games.cpp Normal file
View File

@ -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;
}
}

16
logdoctor/games/games.h Normal file
View File

@ -0,0 +1,16 @@
#ifndef GAMES_H
#define GAMES_H
#include <QString>
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

View File

@ -2,22 +2,28 @@
#include "snake.h"
#include "ui_snake.h"
#include "games/games.h"
#include <QMessageBox>
#include <QGraphicsView>
#include <QGraphicsScene>
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 );

View File

@ -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: