Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef HOMEPAGE_H
- #define HOMEPAGE_H
- #include <QMainWindow>
- #include <QSqlDatabase>
- #include <QPushButton>
- #include <QGroupBox>
- #include <QApplication>
- #include <QGridLayout>
- #include <QWidget>
- #include <QCloseEvent>
- #include <QLabel>
- #include <QLineEdit>
- #include <QComboBox>
- #include <QMessageBox>
- #include <QLayout>
- #include "legami.h"
- #include "account.h"
- #include "businessaccount.h"
- #include "executiveaccount.h"
- class Homepage : public QWidget {
- Q_OBJECT
- public:
- Homepage(QWidget* p=0);
- //~MainWindow();
- void closeEvent(QCloseEvent*);
- void hideAll();
- void hideAll1();
- void hideReg();
- private:
- QSqlDatabase db;
- Legami* gestore;
- QPushButton* admin;
- QPushButton* utente;
- QPushButton* quit;
- QPushButton* iscriviti;
- bool user_amm; //0= user, 1=amm
- QGroupBox* tipi_accesso;
- QGroupBox* esci_iscrivi;
- QGridLayout* reglayout;
- QHBoxLayout* loglayout;
- QVBoxLayout* homelayout;
- //Tab* tab;
- //Logo* logo;
- //metodi qui sotto son public!!
- void altri_buttons();
- void scegli_accesso();
- //void init_db() throw(logic_error, database_error, wrongdatabase_error);
- QLabel* label1;
- QLabel* label2;
- QLabel* label3;
- QLabel* label4;
- QLabel* label5;
- QLabel* label6;
- QLabel* label7;
- QLineEdit* le1;
- QLineEdit* le2;
- QLineEdit* le3;
- QLineEdit* le4;
- QLineEdit* le6;
- QLineEdit* le7;
- QLabel* username;
- QLabel* password;
- QLineEdit* usline;
- QLineEdit* pwdline;
- QComboBox *gg;
- QComboBox *mm;
- QComboBox *aa;
- QPushButton* conferma;
- QPushButton* back;
- QPushButton* accedi;
- Account* current;
- public slots:
- void login_utente();
- void login_admin();
- void form_iscrivi();
- void backtohome();
- void backtohome1();
- void controlli();
- void verifica();
- };
- #endif
- #include "homepage.h"
- Homepage::Homepage(QWidget* p):QWidget(p) {
- gestore=new Legami();
- setWindowTitle("Legami"); //titolo window
- setAutoFillBackground(true);
- QPalette pal = this->palette();
- pal.setColor(QPalette::Window, Qt::white); //QPalette::Window indica che voglio cambiare il colore di sfondo
- this->setPalette(pal);
- scegli_accesso();
- altri_buttons();
- QVBoxLayout* vlayout = new QVBoxLayout; //layout vericale generale
- vlayout->addWidget(tipi_accesso);
- vlayout->addWidget(esci_iscrivi);
- setLayout(vlayout);
- setFixedSize(450,320);
- //invocazione database
- /*try {init_db();}
- catch(database_error){
- QMessageBox::about(this,"Errore Database","<p>Database al momento non disponibile</p>Riprovare in un secondo momento.");
- user->setEnabled(false);
- amm->setEnabled(false);
- }
- catch(wrongdatabase_error){
- QMessageBox::about(this,"Errore Database","Database corrotto o non esistente");
- user->setEnabled(false);
- amm->setEnabled(false);
- }
- catch(logic_error){
- QMessageBox::about(this,"Attenzione!","Database vuoto.");
- }*/
- }
- void Homepage::backtohome() {
- hideReg();
- setFixedSize(450,320);
- setWindowTitle("Legami"); //titolo window
- setAutoFillBackground(true);
- QPalette pal = this->palette();
- pal.setColor(QPalette::Window, Qt::white); //QPalette::Window indica che voglio cambiare il colore di sfondo
- this->setPalette(pal);
- scegli_accesso();
- altri_buttons();
- QVBoxLayout* homelayout = new QVBoxLayout; //layout vericale generale
- homelayout->addWidget(tipi_accesso);
- homelayout->addWidget(esci_iscrivi);
- QLayout* oldlayout2=layout();
- delete oldlayout2;
- setLayout(homelayout);
- }
- void Homepage::backtohome1() {
- hideAll1();
- setFixedSize(450,320);
- setWindowTitle("Legami"); //titolo window
- setAutoFillBackground(true);
- QPalette pal = this->palette();
- pal.setColor(QPalette::Window, Qt::white); //QPalette::Window indica che voglio cambiare il colore di sfondo
- this->setPalette(pal);
- scegli_accesso();
- altri_buttons();
- QVBoxLayout* homelayout = new QVBoxLayout; //layout vericale generale
- homelayout->addWidget(tipi_accesso);
- homelayout->addWidget(esci_iscrivi);
- QLayout* oldlayout2=layout();
- delete oldlayout2;
- setLayout(homelayout);
- }
- void Homepage::scegli_accesso(){
- tipi_accesso = new QGroupBox(); //gruppo di button
- QHBoxLayout* layout_o1 = new QHBoxLayout; //layout orizzontale
- utente= new QPushButton("Accedi - Utente", this); //nuovo bottone accesso utente
- layout_o1->addWidget(utente);
- admin= new QPushButton("Accedi - Admin", this); //nuvovo......
- layout_o1->addWidget(admin);
- connect(utente, SIGNAL(clicked()), this, SLOT(login_utente()));
- connect(admin, SIGNAL(clicked()), this, SLOT(login_admin()));
- tipi_accesso->setLayout(layout_o1);
- }
- void Homepage::login_utente(){
- hideAll();
- setFixedSize(600,400);
- setAutoFillBackground(true);
- QPalette pal = this->palette();
- pal.setColor(QPalette::Window, Qt::white);
- this->setPalette(pal);
- setWindowTitle("Login Utente");
- QHBoxLayout* loglayout=new QHBoxLayout;
- username=new QLabel("Username");
- password=new QLabel("Password");
- usline=new QLineEdit();
- pwdline=new QLineEdit();
- pwdline->setEchoMode(QLineEdit::Password);
- accedi=new QPushButton("Accedi");
- back=new QPushButton("Back");
- connect(accedi, SIGNAL(clicked()), this, SLOT(verifica()));
- connect(back,SIGNAL(clicked()),SLOT(backtohome1()));
- loglayout->addWidget(back);
- loglayout->addWidget(username);
- loglayout->addWidget(usline);
- loglayout->addWidget(password);
- loglayout->addWidget(pwdline);
- loglayout->addWidget(accedi);
- QLayout* oldlayout=layout();
- delete oldlayout;
- setLayout(loglayout);
- }
- /*void Homepage::login_utente(){
- setFixedSize(600,400);
- setAutoFillBackground(true);
- QPalette pal = this->palette();
- pal.setColor(QPalette::Window, Qt::white);
- this->setPalette(pal);
- setWindowTitle("Login Utente");
- QLayout* oldlayout1=layout();
- delete oldlayout1;
- hideAll();
- QHBoxLayout* loglayout=new QHBoxLayout;
- username=new QLabel("Username",this);
- cout << "1" << endl;
- password=new QLabel("Password",this);
- usline=new QLineEdit(this);
- pwdline=new QLineEdit(this);
- cout << "2" << endl;
- pwdline->setEchoMode(QLineEdit::Password);
- accedi=new QPushButton("Accedi",this);
- connect(accedi, SIGNAL(clicked()), this, SLOT(verifica()));
- username->setText("Username:");
- password->setText("Password:");
- cout << "3" << endl;
- username->show();
- cout << "4" << endl;
- usline->show();
- password->show();
- pwdline->show();
- accedi->show();
- */
- /*loglayout->addWidget(username);
- loglayout->addWidget(usline);
- loglayout->addWidget(password);
- loglayout->addWidget(pwdline);
- loglayout->addWidget(accedi);
- cout << "6" << endl;
- setLayout(loglayout);
- }*/
- void Homepage::verifica(){
- QString username=usline->text();
- QString pwd=pwdline->text();
- cout << "gestore verifica:" << gestore << endl;
- current=gestore->login(username,pwd);
- if(current)
- cout << "utente iscritto";
- else {
- cout << "NON iscritto" << endl;
- //attention->setText("Dati non validi, riprova o iscriviti");
- //attention->show();
- }
- }
- void Homepage::login_admin(){
- hideAll();
- setAutoFillBackground(true);
- QPalette pal = this->palette();
- pal.setColor(QPalette::Window, Qt::white); //QPalette::Window indica che voglio cambiare il colore di sfondo
- this->setPalette(pal);
- setWindowTitle("Login Utente");
- QHBoxLayout* loglayout=new QHBoxLayout;
- username=new QLabel("Username");
- password=new QLabel("Password");
- usline=new QLineEdit();
- pwdline=new QLineEdit();
- pwdline->setEchoMode(QLineEdit::Password);
- accedi=new QPushButton("Accedi");
- username->setText("Username Admin:");
- password->setText("Password Admin:");
- /*username->show();
- usline->show();
- password->show();
- pwdline->show();
- accedi->show();*/
- loglayout->addWidget(username);
- loglayout->addWidget(usline);
- loglayout->addWidget(password);
- loglayout->addWidget(pwdline);
- loglayout->addWidget(accedi);
- QLayout* oldlayout1=layout();
- delete oldlayout1;
- setLayout(loglayout);
- setFixedSize(600,400);
- }
- void Homepage::altri_buttons(){
- esci_iscrivi = new QGroupBox();
- QHBoxLayout* layout_o2 = new QHBoxLayout();
- //logo=new Logo("img/lwb.jpg", this);
- quit=new QPushButton("Esci",this);
- layout_o2->addWidget(quit);
- iscriviti=new QPushButton ("Non sei registrato? Iscriviti!", this);
- layout_o2->addWidget(iscriviti);
- connect(quit, SIGNAL(clicked()), this, SLOT(close()));
- connect(iscriviti, SIGNAL(clicked()), this, SLOT(form_iscrivi()));
- iscriviti->setFixedWidth(200);
- //quit->setFixedSize(140,40);
- //layout->addWidget(logo, 0, 2);
- esci_iscrivi->setLayout(layout_o2);
- }
- void Homepage::hideAll(){
- utente->hide();
- admin->hide();
- iscriviti->hide();
- quit->hide();
- return;
- }
- void Homepage::hideAll1(){
- username->hide();
- usline->hide();
- password->hide();
- pwdline->hide();
- accedi->hide();
- back->hide();
- return;
- }
- void Homepage::hideReg(){
- label1->hide();
- label2->hide();
- label3->hide();
- label4->hide();
- label5->hide();
- label6->hide();
- label7->hide();
- le1->hide();
- le2->hide();
- le3->hide();
- le4->hide();
- le6->hide();
- le7->hide();
- gg->hide();
- mm->hide();
- aa->hide();
- conferma->hide();
- back->hide();
- return;
- }
- void Homepage::form_iscrivi(){
- hideAll();
- setFixedSize(550,500);
- setAutoFillBackground(true);
- QPalette pal = this->palette();
- pal.setColor(QPalette::Window, Qt::white); //QPalette::Window indica che voglio cambiare il colore di sfondo
- this->setPalette(pal);
- setWindowTitle("Registrazione");
- QGridLayout* reglayout=new QGridLayout;
- //clear_le();
- label1=new QLabel("Username");
- le1=new QLineEdit();
- cout << "prova" << endl;
- label2=new QLabel("Password");
- le2= new QLineEdit();
- le2->setEchoMode(QLineEdit::Password);
- label3=new QLabel("Nome");
- cout << "1" << endl;
- le3=new QLineEdit();
- label4=new QLabel("Cognome");
- le4=new QLineEdit();
- label5=new QLabel("Data di nascita");
- gg= new QComboBox();
- for(int id=1; id<=31; id++){
- QString day;
- day.setNum(id);
- gg->addItem(day);
- }
- mm= new QComboBox();
- mm->addItem("Gennaio");
- mm->addItem("Febbraio");
- mm->addItem("Marzo");
- mm->addItem("Aprile");
- mm->addItem("Maggio");
- mm->addItem("Giugno");
- mm->addItem("Luglio");
- mm->addItem("Agosto");
- mm->addItem("Settembre");
- mm->addItem("Ottobre");
- mm->addItem("Novembre");
- mm->addItem("Dicembre");
- aa= new QComboBox();
- for(int iy=1993; iy>1920; iy--){
- QString year;
- year.setNum(iy);
- aa->addItem(year);
- }
- label6=new QLabel("Citta'");
- le6=new QLineEdit();
- label7=new QLabel("Sito Web");
- le7=new QLineEdit();
- cout << "2" << endl;
- conferma=new QPushButton("Conferma",this);
- back=new QPushButton("Back",this);
- cout << "3" << endl;
- label1->setText("Username:");
- label2->setText("Password:");
- label3->setText("Nome:");
- label4->setText("Cognome:");
- label5->setText("Data di nascita:");
- label6->setText("Citta':");
- label7->setText("Sitoweb:");
- cout << "4" << endl;
- //disconnect(registro,0,0,0);
- connect(conferma, SIGNAL(clicked()), this, SLOT(controlli()));
- connect(back, SIGNAL(clicked()), this, SLOT(backtohome()));
- /*label1->show();
- label2->show();
- label3->show();
- label4->show();
- label5->show();
- label6->show();
- label7->show();
- le1->show();
- le2->show();
- le3->show();
- le4->show();
- le6->show();
- le7->show();
- conferma->show();
- back->show();
- cout << "5" << endl;*/
- //nuovo layout
- reglayout->addWidget(label1, 1,1, Qt::AlignRight| Qt::AlignTop);
- reglayout->addWidget(le1, 1,2, Qt::AlignLeft| Qt::AlignTop);
- reglayout->addWidget(label2, 2,1, Qt::AlignRight| Qt::AlignTop);
- reglayout->addWidget(le2, 2,2, Qt::AlignLeft| Qt::AlignTop);
- reglayout->addWidget(label3, 3,1, Qt::AlignRight| Qt::AlignTop);
- reglayout->addWidget(le3, 3,2,Qt::AlignLeft| Qt::AlignTop);
- reglayout->addWidget(label4,4,1, Qt::AlignRight| Qt::AlignTop);
- reglayout->addWidget(le4,4,2, Qt::AlignLeft| Qt::AlignTop);
- reglayout->addWidget(label5,5,1, Qt::AlignRight| Qt::AlignTop);
- reglayout->addWidget(gg, 5,2, Qt::AlignLeft| Qt::AlignTop);
- reglayout->addWidget(mm, 5,3, Qt::AlignCenter| Qt::AlignTop);
- reglayout->addWidget(aa, 5,4, Qt::AlignLeft| Qt::AlignTop);
- reglayout->addWidget(label6,6,1, Qt::AlignRight| Qt::AlignTop);
- reglayout->addWidget(le6,6,2,Qt::AlignLeft| Qt::AlignTop);
- reglayout->addWidget(label7,7,1, Qt::AlignRight| Qt::AlignTop);
- reglayout->addWidget(le7,7,2,Qt::AlignLeft| Qt::AlignTop);
- reglayout->addWidget(back,8,1, Qt::AlignLeft| Qt::AlignTop);
- reglayout->addWidget(conferma,8,4, Qt::AlignRight| Qt::AlignTop);
- //dimensione colonne
- reglayout->setColumnStretch(0,5);
- reglayout->setColumnStretch(1, 45);
- reglayout->setColumnStretch(2, 40);
- reglayout->setColumnStretch(3, 20);
- reglayout->setColumnStretch(4, 20);
- //dimensione righe
- reglayout->setRowStretch(0,5);
- reglayout->setRowStretch(1,5);
- reglayout->setRowStretch(2,5);
- reglayout->setRowStretch(3,5);
- reglayout->setRowStretch(4,5);
- reglayout->setRowStretch(5,5);
- reglayout->setRowStretch(6,5);
- reglayout->setRowStretch(7,5);
- reglayout->setRowStretch(8,5);
- QLayout* oldlayout=layout();
- delete oldlayout;
- setLayout(reglayout);
- }
- void Homepage::controlli(){
- QMessageBox msg;
- if(le1->text().isEmpty()||le2->text().isEmpty()||le3->text().isEmpty()||le4->text().isEmpty()||le6->text().isEmpty()||le7->text().isEmpty()){
- msg.warning(this, "Attenzione", "Informazioni mancanti");
- }
- /*else if(!check_free(le1->text())){
- alert->setText("Formato nome non valido. Riprovare");
- alert->show();
- }
- else if(!check_free(le2->text())){
- alert->setText("Formato cognome non valido. Riprovare");
- alert->show();
- }*/
- else if(!gestore->disp_username(le1->text())){ //username non disponibile
- msg.warning(this, "Attenzione", "Username già in uso.");
- }
- /*else{
- newuser= new Username(le1->text(), le2->text());
- stepinfo();
- }*/
- }
- /*void TabUser::end(){
- QString mese= mm->currentText();
- if(mese=="Aprile" || mese=="Giugno" || mese=="Settembre" || mese=="Novembre"){
- if(gg->currentIndex()==30){ //index parte da 0, il giorno 31 e' indicato dall'index 30
- alert->setText("Data di nascita non corretta.");
- alert->show();
- }
- else check_other(); //ok,check su altri campi
- }
- else if(mese=="Febbraio"){
- if(gg->currentIndex()>28){ //idem di sopra
- alert->setText("Data di nascita non corretta.");
- alert->show();
- }
- else check_other(); //ok,check su altri campi
- }
- else check_other(); //ok,check su altri campi
- }
- }*/
- void Homepage::closeEvent(QCloseEvent* event){
- if(db.isOpen())
- db.close();
- event->accept();
- }
Add Comment
Please, Sign In to add comment