🐛 Initialising settings *after* initialising the QApplication now

main
Isabell Pflug 2 years ago
parent ef147f6655
commit b016f77cae

@ -33,8 +33,8 @@ void initialise_settings() { // sucht für die Config Datei an diversen sinnvoll
int main(int argc, char *argv[])
{
initialise_settings();
QApplication a(argc, argv);
initialise_settings();
MainWindow w;
w.show();
return a.exec();

@ -3,30 +3,33 @@
extern std::unique_ptr<QSettings> settings;
// event functions
// slots
void MainWindow::buttonPressed(QPushButton *button) {
QString text = "\u2605";
button->setText(text);
}
// initialisation functions
void MainWindow::initialiseGameGrid() {
double max_width = MainWindow::width();
double max_height = MainWindow::height() - ui->menuBar->height() - ui->labelScore->height();
qDebug() << "gameGridLayout width: " << max_width << " height: " << max_height;
void MainWindow::newGame() {
initialiseGame();
}
QSize button_size(max_width/n_columns, max_height/n_rows);
// initialisation functions
void MainWindow::initialiseGame() {
game->initialiseGameMatrix(rows, columns);
initialiseGameGrid();
ui->lcdScore->display(0);
}
qDebug() << "Width: " << button_size.width() << " Height: " << button_size.height();
void MainWindow::initialiseGameGrid() {
QSize button_size(max_width/columns, max_height/rows);
for(int i = 0; i < n_columns; i++)
for(int i = 0; i < columns; i++)
{
for(int j = 0; j < n_rows; j++)
for(int j = 0; j < rows; j++)
{
QPushButton * button = new QPushButton(this);
button->setFixedSize(button_size);
button->setStyleSheet("background-color: " + game.getCell(i,j) + "; border: none;");
button->setStyleSheet("background-color: " + game->getCell(i,j) + "; border: none;");
ui->gameGridLayout->addWidget(button, j, i);
// Set size text etc. for each button
@ -44,26 +47,31 @@ void MainWindow::initialiseWindow() {
}
void MainWindow::initialiseMenuBar() {
ui->menuPlay->addAction(QIcon(":/icons/game.png"), "New Game");
QAction *new_game_action = ui->menuPlay->addAction(QIcon(":/icons/game.png"), "New Game");
connect(new_game_action, SIGNAL(triggered()), this, SLOT(newGame()));
ui->menuPlay->addSeparator();
}
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
, n_rows(settings->value("size/rows", 9).toInt())
, n_columns(settings->value("size/columns", 9).toInt())
, game(n_rows, n_columns)
, rows(settings->value("size/rows", 9).toInt())
, columns(settings->value("size/columns", 9).toInt())
, max_width(800)
, max_height(544)
{
ui->setupUi(this);
initialiseGameGrid();
game = new SameGame(rows, columns);
initialiseGame();
initialiseWindow();
initialiseMenuBar();
}
MainWindow::~MainWindow()
{
delete game;
delete ui;
}

@ -24,18 +24,21 @@ public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
// initialisation functions
void initialiseGame();
void initialiseGameGrid();
void initialiseGameMatrix();
void initialiseWindow();
void initialiseMenuBar();
// events
private slots:
void buttonPressed(QPushButton *button);
void newGame();
private:
Ui::MainWindow *ui;
const int n_rows;
const int n_columns;
SameGame game;
const int rows;
const int columns;
const double max_width;
const double max_height;
SameGame *game;
};
#endif // MAINWINDOW_H

Loading…
Cancel
Save