🐛 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[]) int main(int argc, char *argv[])
{ {
initialise_settings();
QApplication a(argc, argv); QApplication a(argc, argv);
initialise_settings();
MainWindow w; MainWindow w;
w.show(); w.show();
return a.exec(); return a.exec();

@ -3,30 +3,33 @@
extern std::unique_ptr<QSettings> settings; extern std::unique_ptr<QSettings> settings;
// event functions // slots
void MainWindow::buttonPressed(QPushButton *button) { void MainWindow::buttonPressed(QPushButton *button) {
QString text = "\u2605"; QString text = "\u2605";
button->setText(text); button->setText(text);
} }
// initialisation functions void MainWindow::newGame() {
void MainWindow::initialiseGameGrid() { initialiseGame();
double max_width = MainWindow::width(); }
double max_height = MainWindow::height() - ui->menuBar->height() - ui->labelScore->height();
qDebug() << "gameGridLayout width: " << max_width << " height: " << max_height;
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); QPushButton * button = new QPushButton(this);
button->setFixedSize(button_size); 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); ui->gameGridLayout->addWidget(button, j, i);
// Set size text etc. for each button // Set size text etc. for each button
@ -44,26 +47,31 @@ void MainWindow::initialiseWindow() {
} }
void MainWindow::initialiseMenuBar() { 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(); ui->menuPlay->addSeparator();
} }
MainWindow::MainWindow(QWidget *parent) MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent) : QMainWindow(parent)
, ui(new Ui::MainWindow) , ui(new Ui::MainWindow)
, n_rows(settings->value("size/rows", 9).toInt()) , rows(settings->value("size/rows", 9).toInt())
, n_columns(settings->value("size/columns", 9).toInt()) , columns(settings->value("size/columns", 9).toInt())
, game(n_rows, n_columns) , max_width(800)
, max_height(544)
{ {
ui->setupUi(this); ui->setupUi(this);
initialiseGameGrid(); game = new SameGame(rows, columns);
initialiseGame();
initialiseWindow(); initialiseWindow();
initialiseMenuBar(); initialiseMenuBar();
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()
{ {
delete game;
delete ui; delete ui;
} }

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

Loading…
Cancel
Save