change layout and styling, window now hides instead of segfaulting

This commit is contained in:
2024-06-24 08:40:36 +02:00
parent ccee4c7df1
commit 558eceee19

View File

@@ -1,8 +1,7 @@
# include "LoginFrame.hpp" # include "LoginFrame.hpp"
LoginFrame::LoginFrame(QWidget* parent) LoginFrame::LoginFrame(QWidget* parent)
:QFrame(parent) :QFrame(parent) {
{
//configure LoginFrame //configure LoginFrame
setObjectName("LoginFrame"); setObjectName("LoginFrame");
setStyleSheet(R"( setStyleSheet(R"(
@@ -13,11 +12,10 @@ LoginFrame::LoginFrame(QWidget* parent)
)"); )");
setFrameStyle(QFrame::Box); setFrameStyle(QFrame::Box);
//create QWidgets and add LoginFrame as parent //create QWidgets and add LoginFrame as parent
header_m = new QLabel("Einsatzplan", this); header_m = new QLabel("Einsatzplan", this);
header_m->setFrameStyle(QFrame::Box); header_m->setFrameStyle(QFrame::Box);
header_m->setAlignment(Qt::AlignCenter);
header_m->setObjectName("Header"); header_m->setObjectName("Header");
header_m->setStyleSheet(R"( header_m->setStyleSheet(R"(
#Header{ #Header{
@@ -27,74 +25,68 @@ LoginFrame::LoginFrame(QWidget* parent)
border: none; border: none;
} }
)"); )");
header_m->show(); header_m->show( );
id_m = new QLineEdit( this);
id_m = new QLineEdit(this);
id_m->setPlaceholderText("ID..."); id_m->setPlaceholderText("ID...");
id_m->setObjectName("ID"); id_m->setObjectName("ID");
id_m->setFixedSize(300, 40);
id_m->setStyleSheet(R"( id_m->setStyleSheet(R"(
#ID{ #ID{
color: #333333; color: #DADADA;
font-size: 25px; font-size: 16px;
font-weight: bold; background-color: #313131;
background-color: #444444;
border-radius: 10px; border-radius: 10px;
padding: 5px; padding: 5px;
border: 2px solid #414141;
} }
)"); )");
id_m->show(); id_m->show( );
password_m = new QLineEdit(this); password_m = new QLineEdit(this);
password_m->setPlaceholderText("Passwort..."); password_m->setPlaceholderText("Passwort...");
password_m->setObjectName("Password"); password_m->setObjectName("Password");
password_m->setEchoMode(QLineEdit::Password);
password_m->setFixedSize(300, 40);
password_m->setStyleSheet(R"( password_m->setStyleSheet(R"(
#Password{ #Password{
color: #333333; color: #DADADA;
font-size: 25px; font-size: 16px;
font-weight: bold; background-color: #313131;
background-color: #444444;
border-radius: 10px; border-radius: 10px;
padding: 5px; padding: 5px;
border: 2px solid #414141;
} }
)"); )");
password_m->show(); password_m->show( );
loginButton_m = new QPushButton("Login",this); loginButton_m = new QPushButton("Login", this);
loginButton_m->setObjectName("loginButton"); loginButton_m->setObjectName("loginButton");
loginButton_m->setFixedSize(QSize(150, 50));
loginButton_m->setStyleSheet(R"( loginButton_m->setStyleSheet(R"(
#loginButton{ #loginButton{
color: #212121; color: #212121;
font-size: 30px; font-size: 24px;
font-weight: bold; font-weight: bold;
background-color: #00C800; background-color: #53EC87;
border-radius: 10px; border-radius: 10px;
} }
#loginButton:pressed { #loginButton:pressed {
background-color: #00A800; background-color: #43DC77;
} }
)"); )");
loginButton_m->show(); loginButton_m->show( );
//create layout //create layout
QVBoxLayout* layout = new QVBoxLayout(); QVBoxLayout* layout = new QVBoxLayout( );
layout->setContentsMargins(50, 20, 50, 20); //layout->setContentsMargins(50, 20, 50, 20);
layout->addWidget(header_m, 3, Qt::AlignCenter);
layout->addStretch(1); layout->addWidget(id_m, 1, Qt::AlignCenter);
layout->addWidget(header_m); layout->addWidget(password_m, 1, Qt::AlignCenter);
header_m->setAlignment(Qt::AlignHCenter); layout->addWidget(loginButton_m, 3, Qt::AlignCenter);
layout->addStretch(2);
layout->addWidget(id_m);
id_m->setAlignment(Qt::AlignHCenter);
layout->addStretch(1);
layout->addWidget(password_m);
password_m->setAlignment(Qt::AlignHCenter);
layout->addStretch(2);
layout->addWidget(loginButton_m);
layout->addStretch(1);
//add Layout to LoginFrame //add Layout to LoginFrame
setLayout(layout); setLayout(layout);
@@ -103,30 +95,29 @@ LoginFrame::LoginFrame(QWidget* parent)
connect(loginButton_m, &QPushButton::clicked, this, &LoginFrame::loginButtonClicked); connect(loginButton_m, &QPushButton::clicked, this, &LoginFrame::loginButtonClicked);
} }
//try Login if Button clicked //try Login if Button clicked
void LoginFrame::loginButtonClicked(){ void LoginFrame::loginButtonClicked( ) {
QString id = id_m->text(); QString id = id_m->text( );
QString password = password_m->text(); QString password = password_m->text( );
//check if Contents Valid //check if Contents Valid
if (id.isEmpty() || password.isEmpty()){ if (id.isEmpty( ) || password.isEmpty( )) {
QMessageBox::warning(this, "Error", "Bitte füllen Sie sowohl die ID als auch das Passwort aus."); QMessageBox::warning(this, "Error", "Bitte füllen Sie sowohl die ID als auch das Passwort aus.");
} } else {
else { LoginFrameController* controller = new LoginFrameController( );
LoginFrameController* controller = new LoginFrameController(); if (!controller->tryLogin(id, password)) {
if (!controller->tryLogin(id, password)){ QMessageBox::warning(this, "Error", "ID und Passwort stimmen nicht überein!");
QMessageBox:: warning(this, "Error", "ID und Passwort stimmen nicht überein!"); } else {
} ((QWidget*)(this->parent( )))->hide( );
else{ //TODO: Create new window
this->~LoginFrame();
} }
} }
} }
LoginFrame::~LoginFrame(){ LoginFrame::~LoginFrame( ) {
header_m->~QLabel(); header_m->~QLabel( );
id_m->~QLineEdit(); id_m->~QLineEdit( );
password_m->~QLineEdit(); password_m->~QLineEdit( );
loginButton_m->~QPushButton(); loginButton_m->~QPushButton( );
parent_m->~QMainWindow(); parent_m->~QMainWindow( );
} }