Guest User

Untitled

a guest
Oct 18th, 2017
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 15.73 KB | None | 0 0
  1. #ifndef HOMEPAGE_H
  2. #define HOMEPAGE_H
  3.  
  4. #include <QMainWindow>
  5. #include <QSqlDatabase>
  6. #include <QPushButton>
  7. #include <QGroupBox>
  8. #include <QApplication>
  9. #include <QGridLayout>
  10. #include <QWidget>
  11. #include <QCloseEvent>
  12. #include <QLabel>
  13. #include <QLineEdit>
  14. #include <QComboBox>
  15. #include <QMessageBox>
  16. #include <QLayout>
  17. #include "legami.h"
  18. #include "account.h"
  19. #include "businessaccount.h"
  20. #include "executiveaccount.h"
  21.  
  22.  
  23. class Homepage : public QWidget {
  24.     Q_OBJECT
  25. public:
  26.     Homepage(QWidget* p=0);
  27.     //~MainWindow();
  28.     void closeEvent(QCloseEvent*);
  29.     void hideAll();
  30.     void hideAll1();
  31.     void hideReg();
  32.  
  33.  
  34. private:
  35.     QSqlDatabase db;
  36.     Legami* gestore;
  37.  
  38.     QPushButton* admin;
  39.     QPushButton* utente;
  40.     QPushButton* quit;
  41.     QPushButton* iscriviti;
  42.     bool user_amm;      //0= user, 1=amm
  43.     QGroupBox* tipi_accesso;
  44.     QGroupBox* esci_iscrivi;
  45.     QGridLayout* reglayout;
  46.     QHBoxLayout* loglayout;
  47.     QVBoxLayout* homelayout;
  48.  
  49.     //Tab* tab;
  50.     //Logo* logo;
  51.  
  52.     //metodi qui sotto son public!!
  53.     void altri_buttons();
  54.     void scegli_accesso();
  55.     //void init_db() throw(logic_error, database_error, wrongdatabase_error);
  56.  
  57.     QLabel* label1;
  58.     QLabel* label2;
  59.     QLabel* label3;
  60.     QLabel* label4;
  61.     QLabel* label5;
  62.     QLabel* label6;
  63.     QLabel* label7;
  64.     QLineEdit* le1;
  65.     QLineEdit* le2;
  66.     QLineEdit* le3;
  67.     QLineEdit* le4;
  68.     QLineEdit* le6;
  69.     QLineEdit* le7;
  70.     QLabel* username;
  71.     QLabel* password;
  72.     QLineEdit* usline;
  73.     QLineEdit* pwdline;
  74.     QComboBox *gg;
  75.     QComboBox *mm;
  76.     QComboBox *aa;
  77.     QPushButton* conferma;
  78.     QPushButton* back;
  79.     QPushButton* accedi;
  80.     Account* current;
  81.  
  82. public slots:
  83.     void login_utente();
  84.     void login_admin();
  85.     void form_iscrivi();
  86.     void backtohome();
  87.     void backtohome1();
  88.     void controlli();
  89.     void verifica();
  90. };
  91.  
  92. #endif
  93.  
  94.  
  95.  
  96.  
  97. #include "homepage.h"
  98.  
  99. Homepage::Homepage(QWidget* p):QWidget(p) {
  100.  
  101.     gestore=new Legami();
  102.     setWindowTitle("Legami"); //titolo window
  103.     setAutoFillBackground(true);
  104.     QPalette pal = this->palette();
  105.     pal.setColor(QPalette::Window, Qt::white); //QPalette::Window indica che voglio cambiare il colore di sfondo
  106.     this->setPalette(pal);
  107.  
  108.     scegli_accesso();
  109.     altri_buttons();
  110.     QVBoxLayout* vlayout = new QVBoxLayout; //layout vericale generale
  111.     vlayout->addWidget(tipi_accesso);
  112.     vlayout->addWidget(esci_iscrivi);
  113.     setLayout(vlayout);
  114.     setFixedSize(450,320);
  115.  
  116.     //invocazione database
  117.     /*try {init_db();}
  118.     catch(database_error){
  119.         QMessageBox::about(this,"Errore Database","<p>Database al momento non disponibile</p>Riprovare in un secondo momento.");
  120.         user->setEnabled(false);
  121.         amm->setEnabled(false);
  122.     }
  123.     catch(wrongdatabase_error){
  124.         QMessageBox::about(this,"Errore Database","Database corrotto o non esistente");
  125.         user->setEnabled(false);
  126.         amm->setEnabled(false);
  127.     }
  128.     catch(logic_error){
  129.         QMessageBox::about(this,"Attenzione!","Database vuoto.");
  130.     }*/
  131. }
  132.  
  133. void Homepage::backtohome() {
  134.     hideReg();
  135.     setFixedSize(450,320);
  136.     setWindowTitle("Legami"); //titolo window
  137.     setAutoFillBackground(true);
  138.     QPalette pal = this->palette();
  139.     pal.setColor(QPalette::Window, Qt::white); //QPalette::Window indica che voglio cambiare il colore di sfondo
  140.     this->setPalette(pal);
  141.     scegli_accesso();
  142.     altri_buttons();
  143.     QVBoxLayout* homelayout = new QVBoxLayout; //layout vericale generale
  144.     homelayout->addWidget(tipi_accesso);
  145.     homelayout->addWidget(esci_iscrivi);
  146.     QLayout* oldlayout2=layout();
  147.     delete oldlayout2;
  148.     setLayout(homelayout);
  149. }
  150.  
  151.  
  152. void Homepage::backtohome1() {
  153.     hideAll1();
  154.     setFixedSize(450,320);
  155.     setWindowTitle("Legami"); //titolo window
  156.     setAutoFillBackground(true);
  157.     QPalette pal = this->palette();
  158.     pal.setColor(QPalette::Window, Qt::white); //QPalette::Window indica che voglio cambiare il colore di sfondo
  159.     this->setPalette(pal);
  160.     scegli_accesso();
  161.     altri_buttons();
  162.     QVBoxLayout* homelayout = new QVBoxLayout; //layout vericale generale
  163.     homelayout->addWidget(tipi_accesso);
  164.     homelayout->addWidget(esci_iscrivi);
  165.     QLayout* oldlayout2=layout();
  166.     delete oldlayout2;
  167.     setLayout(homelayout);
  168. }
  169.  
  170. void Homepage::scegli_accesso(){
  171.  
  172.     tipi_accesso = new QGroupBox(); //gruppo di button
  173.     QHBoxLayout* layout_o1 = new QHBoxLayout; //layout orizzontale
  174.  
  175.     utente= new QPushButton("Accedi - Utente", this); //nuovo bottone accesso utente
  176.     layout_o1->addWidget(utente);
  177.     admin= new QPushButton("Accedi - Admin", this); //nuvovo......
  178.     layout_o1->addWidget(admin);
  179.     connect(utente, SIGNAL(clicked()), this, SLOT(login_utente()));
  180.     connect(admin, SIGNAL(clicked()), this, SLOT(login_admin()));
  181.     tipi_accesso->setLayout(layout_o1);
  182. }
  183.  
  184. void Homepage::login_utente(){
  185.     hideAll();
  186.     setFixedSize(600,400);
  187.     setAutoFillBackground(true);
  188.     QPalette pal = this->palette();
  189.     pal.setColor(QPalette::Window, Qt::white);
  190.     this->setPalette(pal);
  191.     setWindowTitle("Login Utente");
  192.     QHBoxLayout* loglayout=new QHBoxLayout;
  193.  
  194.     username=new QLabel("Username");
  195.     password=new QLabel("Password");
  196.     usline=new QLineEdit();
  197.     pwdline=new QLineEdit();
  198.     pwdline->setEchoMode(QLineEdit::Password);
  199.     accedi=new QPushButton("Accedi");
  200.     back=new QPushButton("Back");
  201.     connect(accedi, SIGNAL(clicked()), this, SLOT(verifica()));
  202.     connect(back,SIGNAL(clicked()),SLOT(backtohome1()));
  203.     loglayout->addWidget(back);
  204.     loglayout->addWidget(username);
  205.     loglayout->addWidget(usline);
  206.     loglayout->addWidget(password);
  207.     loglayout->addWidget(pwdline);
  208.     loglayout->addWidget(accedi);
  209.     QLayout* oldlayout=layout();
  210.     delete oldlayout;
  211.     setLayout(loglayout);
  212. }
  213.  
  214. /*void Homepage::login_utente(){
  215.     setFixedSize(600,400);
  216.     setAutoFillBackground(true);
  217.     QPalette pal = this->palette();
  218.     pal.setColor(QPalette::Window, Qt::white);
  219.     this->setPalette(pal);
  220.     setWindowTitle("Login Utente");
  221.     QLayout* oldlayout1=layout();
  222.     delete oldlayout1;
  223.     hideAll();
  224.     QHBoxLayout* loglayout=new QHBoxLayout;
  225.  
  226.     username=new QLabel("Username",this);
  227.     cout << "1" << endl;
  228.     password=new QLabel("Password",this);
  229.     usline=new QLineEdit(this);
  230.     pwdline=new QLineEdit(this);
  231.     cout << "2" << endl;
  232.     pwdline->setEchoMode(QLineEdit::Password);
  233.     accedi=new QPushButton("Accedi",this);
  234.     connect(accedi, SIGNAL(clicked()), this, SLOT(verifica()));
  235.  
  236.     username->setText("Username:");
  237.     password->setText("Password:");
  238.     cout << "3" << endl;
  239.     username->show();
  240.     cout << "4" << endl;
  241.     usline->show();
  242.     password->show();
  243.     pwdline->show();
  244.     accedi->show();
  245.     */
  246.     /*loglayout->addWidget(username);
  247.     loglayout->addWidget(usline);
  248.     loglayout->addWidget(password);
  249.     loglayout->addWidget(pwdline);
  250.     loglayout->addWidget(accedi);
  251.     cout << "6" << endl;
  252.     setLayout(loglayout);
  253.  
  254. }*/
  255.  
  256. void Homepage::verifica(){
  257.     QString username=usline->text();
  258.     QString pwd=pwdline->text();
  259.     cout << "gestore verifica:" << gestore << endl;
  260.     current=gestore->login(username,pwd);
  261.     if(current)
  262.         cout << "utente iscritto";
  263.     else {
  264.         cout << "NON iscritto" << endl;
  265.         //attention->setText("Dati non validi, riprova o iscriviti");
  266.         //attention->show();
  267.     }
  268. }
  269.  
  270. void Homepage::login_admin(){
  271.     hideAll();
  272.     setAutoFillBackground(true);
  273.     QPalette pal = this->palette();
  274.     pal.setColor(QPalette::Window, Qt::white); //QPalette::Window indica che voglio cambiare il colore di sfondo
  275.     this->setPalette(pal);
  276.     setWindowTitle("Login Utente");
  277.     QHBoxLayout* loglayout=new QHBoxLayout;
  278.  
  279.     username=new QLabel("Username");
  280.     password=new QLabel("Password");
  281.     usline=new QLineEdit();
  282.     pwdline=new QLineEdit();
  283.     pwdline->setEchoMode(QLineEdit::Password);
  284.     accedi=new QPushButton("Accedi");
  285.  
  286.     username->setText("Username Admin:");
  287.     password->setText("Password Admin:");
  288.  
  289.     /*username->show();
  290.     usline->show();
  291.     password->show();
  292.     pwdline->show();
  293.     accedi->show();*/
  294.  
  295.     loglayout->addWidget(username);
  296.     loglayout->addWidget(usline);
  297.     loglayout->addWidget(password);
  298.     loglayout->addWidget(pwdline);
  299.     loglayout->addWidget(accedi);
  300.  
  301.     QLayout* oldlayout1=layout();
  302.     delete oldlayout1;
  303.     setLayout(loglayout);
  304.     setFixedSize(600,400);
  305. }
  306.  
  307. void Homepage::altri_buttons(){
  308.     esci_iscrivi = new QGroupBox();
  309.     QHBoxLayout* layout_o2 = new QHBoxLayout();
  310.  
  311.     //logo=new Logo("img/lwb.jpg", this);
  312.     quit=new QPushButton("Esci",this);
  313.     layout_o2->addWidget(quit);
  314.     iscriviti=new QPushButton ("Non sei registrato? Iscriviti!", this);
  315.     layout_o2->addWidget(iscriviti);
  316.     connect(quit, SIGNAL(clicked()), this, SLOT(close()));
  317.     connect(iscriviti, SIGNAL(clicked()), this, SLOT(form_iscrivi()));
  318.     iscriviti->setFixedWidth(200);
  319.     //quit->setFixedSize(140,40);
  320.     //layout->addWidget(logo, 0, 2);
  321.     esci_iscrivi->setLayout(layout_o2);
  322. }
  323.  
  324. void Homepage::hideAll(){
  325.     utente->hide();
  326.     admin->hide();
  327.     iscriviti->hide();
  328.     quit->hide();
  329.     return;
  330. }
  331.  
  332. void Homepage::hideAll1(){
  333.     username->hide();
  334.     usline->hide();
  335.     password->hide();
  336.     pwdline->hide();
  337.     accedi->hide();
  338.     back->hide();
  339.     return;
  340. }
  341.  
  342. void Homepage::hideReg(){
  343.     label1->hide();
  344.     label2->hide();
  345.     label3->hide();
  346.     label4->hide();
  347.     label5->hide();
  348.     label6->hide();
  349.     label7->hide();
  350.     le1->hide();
  351.     le2->hide();
  352.     le3->hide();
  353.     le4->hide();
  354.     le6->hide();
  355.     le7->hide();
  356.     gg->hide();
  357.     mm->hide();
  358.     aa->hide();
  359.     conferma->hide();
  360.     back->hide();
  361.     return;
  362. }
  363.  
  364. void Homepage::form_iscrivi(){
  365.     hideAll();
  366.     setFixedSize(550,500);
  367.     setAutoFillBackground(true);
  368.  
  369.     QPalette pal = this->palette();
  370.     pal.setColor(QPalette::Window, Qt::white); //QPalette::Window indica che voglio cambiare il colore di sfondo
  371.     this->setPalette(pal);
  372.     setWindowTitle("Registrazione");
  373.     QGridLayout* reglayout=new QGridLayout;
  374.     //clear_le();
  375.  
  376.     label1=new QLabel("Username");
  377.     le1=new QLineEdit();
  378.     cout << "prova" << endl;
  379.     label2=new QLabel("Password");
  380.     le2= new QLineEdit();
  381.     le2->setEchoMode(QLineEdit::Password);
  382.     label3=new QLabel("Nome");
  383.     cout << "1" << endl;
  384.     le3=new QLineEdit();
  385.     label4=new QLabel("Cognome");
  386.     le4=new QLineEdit();
  387.     label5=new QLabel("Data di nascita");
  388.     gg= new QComboBox();
  389.         for(int id=1; id<=31; id++){
  390.             QString day;
  391.             day.setNum(id);
  392.             gg->addItem(day);
  393.         }
  394.  
  395.     mm= new QComboBox();
  396.     mm->addItem("Gennaio");
  397.     mm->addItem("Febbraio");
  398.     mm->addItem("Marzo");
  399.     mm->addItem("Aprile");
  400.     mm->addItem("Maggio");
  401.     mm->addItem("Giugno");
  402.     mm->addItem("Luglio");
  403.     mm->addItem("Agosto");
  404.     mm->addItem("Settembre");
  405.     mm->addItem("Ottobre");
  406.     mm->addItem("Novembre");
  407.     mm->addItem("Dicembre");
  408.     aa= new QComboBox();
  409.     for(int iy=1993; iy>1920; iy--){
  410.           QString year;
  411.           year.setNum(iy);
  412.           aa->addItem(year);
  413.     }
  414.  
  415.     label6=new QLabel("Citta'");
  416.     le6=new QLineEdit();
  417.     label7=new QLabel("Sito Web");
  418.     le7=new QLineEdit();
  419.     cout << "2" << endl;
  420.     conferma=new QPushButton("Conferma",this);
  421.     back=new QPushButton("Back",this);
  422.     cout << "3" << endl;
  423.  
  424.     label1->setText("Username:");
  425.     label2->setText("Password:");
  426.     label3->setText("Nome:");
  427.     label4->setText("Cognome:");
  428.     label5->setText("Data di nascita:");
  429.     label6->setText("Citta':");
  430.     label7->setText("Sitoweb:");
  431.     cout << "4" << endl;
  432.     //disconnect(registro,0,0,0);
  433.     connect(conferma, SIGNAL(clicked()), this, SLOT(controlli()));
  434.     connect(back, SIGNAL(clicked()), this, SLOT(backtohome()));
  435.  
  436.     /*label1->show();
  437.     label2->show();
  438.     label3->show();
  439.     label4->show();
  440.     label5->show();
  441.     label6->show();
  442.     label7->show();
  443.     le1->show();
  444.     le2->show();
  445.     le3->show();
  446.     le4->show();
  447.     le6->show();
  448.     le7->show();
  449.     conferma->show();
  450.     back->show();
  451.     cout << "5" << endl;*/
  452.  
  453.     //nuovo layout
  454.     reglayout->addWidget(label1, 1,1, Qt::AlignRight| Qt::AlignTop);
  455.     reglayout->addWidget(le1, 1,2, Qt::AlignLeft| Qt::AlignTop);
  456.     reglayout->addWidget(label2, 2,1, Qt::AlignRight| Qt::AlignTop);
  457.     reglayout->addWidget(le2, 2,2, Qt::AlignLeft| Qt::AlignTop);
  458.     reglayout->addWidget(label3, 3,1, Qt::AlignRight| Qt::AlignTop);
  459.     reglayout->addWidget(le3, 3,2,Qt::AlignLeft| Qt::AlignTop);
  460.     reglayout->addWidget(label4,4,1, Qt::AlignRight| Qt::AlignTop);
  461.     reglayout->addWidget(le4,4,2, Qt::AlignLeft| Qt::AlignTop);
  462.     reglayout->addWidget(label5,5,1, Qt::AlignRight| Qt::AlignTop);
  463.     reglayout->addWidget(gg, 5,2, Qt::AlignLeft| Qt::AlignTop);
  464.     reglayout->addWidget(mm, 5,3, Qt::AlignCenter| Qt::AlignTop);
  465.     reglayout->addWidget(aa, 5,4, Qt::AlignLeft| Qt::AlignTop);
  466.     reglayout->addWidget(label6,6,1, Qt::AlignRight| Qt::AlignTop);
  467.     reglayout->addWidget(le6,6,2,Qt::AlignLeft| Qt::AlignTop);
  468.     reglayout->addWidget(label7,7,1, Qt::AlignRight| Qt::AlignTop);
  469.     reglayout->addWidget(le7,7,2,Qt::AlignLeft| Qt::AlignTop);
  470.     reglayout->addWidget(back,8,1, Qt::AlignLeft| Qt::AlignTop);
  471.     reglayout->addWidget(conferma,8,4, Qt::AlignRight| Qt::AlignTop);
  472.  
  473.     //dimensione colonne
  474.     reglayout->setColumnStretch(0,5);
  475.     reglayout->setColumnStretch(1, 45);
  476.     reglayout->setColumnStretch(2, 40);
  477.     reglayout->setColumnStretch(3, 20);
  478.     reglayout->setColumnStretch(4, 20);
  479.  
  480.     //dimensione righe
  481.     reglayout->setRowStretch(0,5);
  482.     reglayout->setRowStretch(1,5);
  483.     reglayout->setRowStretch(2,5);
  484.     reglayout->setRowStretch(3,5);
  485.     reglayout->setRowStretch(4,5);
  486.     reglayout->setRowStretch(5,5);
  487.     reglayout->setRowStretch(6,5);
  488.     reglayout->setRowStretch(7,5);
  489.     reglayout->setRowStretch(8,5);
  490.  
  491.     QLayout* oldlayout=layout();
  492.     delete oldlayout;
  493.     setLayout(reglayout);
  494.  
  495. }
  496.  
  497. void Homepage::controlli(){
  498.     QMessageBox msg;
  499.     if(le1->text().isEmpty()||le2->text().isEmpty()||le3->text().isEmpty()||le4->text().isEmpty()||le6->text().isEmpty()||le7->text().isEmpty()){
  500.         msg.warning(this, "Attenzione", "Informazioni mancanti");
  501.     }
  502.     /*else if(!check_free(le1->text())){
  503.         alert->setText("Formato nome non valido. Riprovare");
  504.         alert->show();
  505.     }
  506.     else if(!check_free(le2->text())){
  507.         alert->setText("Formato cognome non valido. Riprovare");
  508.         alert->show();
  509.     }*/
  510.     else if(!gestore->disp_username(le1->text())){ //username non disponibile
  511.       msg.warning(this, "Attenzione", "Username già in uso.");
  512.     }
  513.     /*else{
  514.        newuser= new Username(le1->text(), le2->text());
  515.        stepinfo();
  516.     }*/
  517. }
  518.  
  519. /*void TabUser::end(){
  520.     QString mese= mm->currentText();
  521.     if(mese=="Aprile" || mese=="Giugno" || mese=="Settembre" || mese=="Novembre"){
  522.                 if(gg->currentIndex()==30){ //index parte da 0, il giorno 31 e' indicato dall'index 30
  523.                     alert->setText("Data di nascita non corretta.");
  524.                     alert->show();
  525.                 }
  526.                 else check_other(); //ok,check su altri campi
  527.     }
  528.     else if(mese=="Febbraio"){
  529.         if(gg->currentIndex()>28){  //idem di sopra
  530.             alert->setText("Data di nascita non corretta.");
  531.             alert->show();
  532.         }
  533.         else check_other(); //ok,check su altri campi
  534.     }
  535.     else check_other(); //ok,check su altri campi
  536. }
  537.  
  538.  
  539. }*/
  540.  
  541.  
  542. void Homepage::closeEvent(QCloseEvent* event){
  543.     if(db.isOpen())
  544.         db.close();
  545.     event->accept();
  546. }
Add Comment
Please, Sign In to add comment