Advertisement
Guest User

Untitled

a guest
Jul 2nd, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 9.34 KB | None | 0 0
  1. #ifndef MAINWINDOW_H
  2. #define MAINWINDOW_H
  3.  
  4. #include <QtGui>
  5.  
  6. // register via meta obejct system
  7. class Contact {
  8. public:
  9.     enum AvailableMedia {
  10.         // Video,
  11.         Audio,
  12.         Text
  13.     };
  14.  
  15.     Q_DECLARE_FLAGS(AvailableMedias, AvailableMedia)
  16.  
  17. private:
  18.     QString m_name;
  19.     AvailableMedias m_medias;
  20.  
  21. public:
  22.     void setMedias(AvailableMedias medias);
  23.     void setName(const QString & name);
  24.  
  25.     AvailableMedias medias() const;
  26.     QString name() const;
  27. };
  28.  
  29. class AddContactDialog : public QDialog {
  30.     Q_OBJECT
  31.  
  32. private:
  33.     QLineEdit * m_name;
  34.  
  35.     QPushButton * m_validateButton;
  36.     QPushButton * m_cancelButton;
  37.  
  38.     bool m_validateClicked;
  39.  
  40. public:
  41.     AddContactDialog(QWidget * parent = 0) : QDialog(parent) {
  42.         m_validateClicked = false;
  43.  
  44.         m_name = new QLineEdit(this);
  45.  
  46.         m_validateButton = new QPushButton("Validate", this);
  47.         m_cancelButton = new QPushButton("Cancel", this);
  48.  
  49.         QFormLayout * layout = new QFormLayout(this);
  50.  
  51.         layout->addRow("User", m_name);
  52.  
  53.         layout->addWidget(m_validateButton);
  54.         layout->addWidget(m_cancelButton);
  55.  
  56.         QObject::connect(m_validateButton, SIGNAL(clicked()), this, SLOT(validate()));
  57.         QObject::connect(m_cancelButton, SIGNAL(clicked()), this, SLOT(close()));
  58.     }
  59.  
  60.     QString user() const { return m_name->text(); }
  61.     bool validateClicked() const { return m_validateClicked; }
  62.  
  63. private slots:
  64.     void validate() {
  65.         m_validateClicked = true;
  66.         close();
  67.     }
  68. };
  69.  
  70. class SubscribeDialog : public QDialog {
  71.     Q_OBJECT
  72.  
  73. private:
  74.     QLineEdit * m_name;
  75.     QLineEdit * m_password;
  76.  
  77.     QPushButton * m_validateButton;
  78.     QPushButton * m_cancelButton;
  79.  
  80.     bool m_validateClicked;
  81.  
  82. public:
  83.     SubscribeDialog(QWidget * parent = 0) : QDialog(parent) {
  84.         m_validateClicked = false;
  85.  
  86.         m_name = new QLineEdit(this);
  87.         m_password = new QLineEdit(this);
  88.  
  89.         m_password->setEchoMode(QLineEdit::Password);
  90.  
  91.         m_validateButton = new QPushButton("Validate", this);
  92.         m_cancelButton = new QPushButton("Cancel", this);
  93.  
  94.         QFormLayout * layout = new QFormLayout(this);
  95.  
  96.         layout->addRow("User", m_name);
  97.         layout->addRow("Pass", m_password);
  98.  
  99.         layout->addWidget(m_validateButton);
  100.         layout->addWidget(m_cancelButton);
  101.  
  102.         QObject::connect(m_validateButton, SIGNAL(clicked()), this, SLOT(validate()));
  103.         QObject::connect(m_cancelButton, SIGNAL(clicked()), this, SLOT(close()));
  104.     }
  105.  
  106.     void setUser(const QString & user) { m_name->setText(user); }
  107.     void setPassword(const QString & password) { m_password->setText(password); }
  108.  
  109.     QString password() const { return m_password->text(); }
  110.     QString user() const { return m_name->text(); }
  111.     bool validateClicked() const { return m_validateClicked; }
  112.  
  113. private slots:
  114.     void validate() {
  115.         m_validateClicked = true;
  116.         close();
  117.     }
  118. };
  119.  
  120. class LogginPannel : public QWidget {
  121.     Q_OBJECT
  122.  
  123. private:
  124.     QLineEdit * m_username;
  125.     QLineEdit * m_password;
  126.  
  127.     QPushButton * m_logginButton;
  128.     QPushButton * m_subscribeButton;
  129.  
  130. public:
  131.     enum LogginStatus {
  132.         LoggedIn,
  133.         LogginError
  134.     };
  135.  
  136.     LogginPannel(QWidget * parent = 0) : QWidget(parent) {
  137.         m_username = new QLineEdit(this);
  138.         m_password = new QLineEdit(this);
  139.  
  140.         m_logginButton = new QPushButton("Connect", this);
  141.         m_subscribeButton = new QPushButton("Subscribe", this);
  142.  
  143.         m_password->setEchoMode(QLineEdit::PasswordEchoOnEdit);
  144.  
  145.         QFormLayout * layout = new QFormLayout(this);
  146.         layout->setFormAlignment(Qt::AlignVCenter);
  147.  
  148.         layout->addRow("User", m_username);
  149.         layout->addRow("Pass", m_password);
  150.  
  151.         QWidget * dummy = new QWidget(this);
  152.         QHBoxLayout * buttonLayout = new QHBoxLayout(dummy);
  153.         dummy->setLayout(buttonLayout);
  154.  
  155.         buttonLayout->addWidget(m_logginButton);
  156.         buttonLayout->addWidget(m_subscribeButton);
  157.  
  158.         layout->addWidget(dummy);
  159.  
  160.         QObject::connect(m_logginButton, SIGNAL(clicked()), this, SLOT(loginClicked()));
  161.         QObject::connect(m_subscribeButton, SIGNAL(clicked()), this, SLOT(subscribeClicked()));
  162.     }
  163.  
  164. signals:
  165.     void tryLoggin(const QString & userName, const QString & password);
  166.     void trySubscribe(const QString & userName, const QString & password);
  167.  
  168. private slots:
  169.     void treatLoggin(LogginStatus status, const QString & errorMessage) {
  170.  
  171.     }
  172.  
  173.     void loginClicked() {
  174.         emit tryLoggin(m_username->text(), m_password->text());
  175.     }
  176.  
  177.     void subscribeClicked() {
  178.         SubscribeDialog dialog(this);
  179.  
  180.         dialog.setUser(m_username->text());
  181.         dialog.setPassword(m_password->text());
  182.  
  183.         dialog.exec();
  184.         if(dialog.validateClicked()) {
  185.             qDebug() << "validate !";
  186.             m_username->setText(dialog.user());
  187.             m_password->setText(dialog.password());
  188.             emit trySubscribe(dialog.user(), dialog.password());
  189.         }
  190.     }
  191.  
  192.     void subscribeSuccesful() {
  193.         loginClicked();
  194.     }
  195. };
  196.  
  197. class BabelPannel : public QWidget {
  198.     Q_OBJECT
  199.  
  200. private:
  201.     /*QListWidget * m_contactView;
  202.     QList < Contact > m_contacts;*/
  203.     QComboBox * m_contactList;
  204.  
  205. public:
  206.     BabelPannel(QWidget * parent = 0) : QWidget(parent) {
  207.         QVBoxLayout * layout = new QVBoxLayout(this);
  208.  
  209.         m_contactList = new QComboBox(this);
  210.  
  211.         m_contactList->addItem("JCDuss", "JCDuss");
  212.         m_contactList->addItem("JCDuss1", "JCDuss1");
  213.         m_contactList->addItem("JCDuss2", "JCDuss2");
  214.         m_contactList->addItem("JCDuss3", "JCDuss3");
  215.  
  216.         layout->addWidget(m_contactList);
  217.  
  218.         QObject::connect(this, SIGNAL(addContact(QString)), this, SLOT(updateViewAdd(QString)));
  219.         QObject::connect(this, SIGNAL(deleteContact(QString)), this, SLOT(updateViewRemove(QString)));
  220.     }
  221.  
  222. public slots:
  223.     void addContact() {
  224.         // adding contat dialog
  225.         AddContactDialog dialog(this);
  226.         dialog.exec();
  227.         if(dialog.validateClicked()) {
  228.             emit addContact(dialog.user());
  229.         }
  230.     }
  231.  
  232.     void deleteContact() {
  233.         if(QMessageBox::question(this, "Confirmation", "Etes vous sur ?", QMessageBox::Yes | QMessageBox::No, QMessageBox::No) == QMessageBox::Yes)
  234.             emit deleteContact(m_contactList->currentText());
  235.     }
  236.  
  237.     void updateViewAdd(const QString & contact) {
  238.         m_contactList->addItem(contact, contact);
  239.     }
  240.  
  241.     void updateViewRemove(const QString & contact) {
  242.         m_contactList->removeItem(m_contactList->findText(contact));
  243.     }
  244.  
  245.     void audioClick() {
  246.         qDebug() << "audioClick";
  247.     }
  248.  
  249.     void textClick() {
  250.         qDebug() << "textClick";
  251.     }
  252.  
  253. signals:
  254.     void disconnectBabel();
  255.     void startAudio(const Contact & contact);
  256.     void startText(const Contact & contact);
  257.  
  258.     void addContact(const QString & contact);
  259.     void deleteContact(const QString & contact);
  260. };
  261.  
  262. class MainWindow : public QMainWindow
  263. {
  264.     Q_OBJECT
  265.  
  266. private:
  267.     QStackedWidget * m_view;
  268.  
  269.     QMenu * m_fileMenu;
  270.     QMenu * m_contactMenu;
  271.  
  272.     QAction * m_addContact;
  273.     QAction * m_deleteContact;
  274.     QAction * m_editConnection;
  275.     QAction * m_quit;
  276.     QAction * m_startAudio;
  277.     QAction * m_startText;
  278.  
  279.     void createActions() {
  280.         m_addContact = new QAction(tr("Add contact"), this);
  281.         connect(m_addContact, SIGNAL(triggered()), m_view->widget(1), SLOT(addContact()));
  282.  
  283.         m_deleteContact = new QAction(tr("Delete contact"), this);
  284.         connect(m_deleteContact, SIGNAL(triggered()), m_view->widget(1), SLOT(deleteContact()));
  285.  
  286.         m_quit = new QAction(tr("Delete contact"), this);
  287.         connect(m_quit, SIGNAL(triggered()), this, SLOT(close()));
  288.     }
  289.  
  290.     void createMenus() {
  291.         m_fileMenu = menuBar()->addMenu(tr("&Menu"));
  292.         m_fileMenu->addAction(m_addContact);
  293.         m_fileMenu->addAction(m_deleteContact);
  294.         m_fileMenu->addSeparator();
  295.         m_fileMenu->addAction(m_quit);
  296.     }
  297.  
  298. public:
  299.     enum PannelView {
  300.         LogginPannelView,
  301.         BabelPannelView
  302.     };
  303.  
  304.     MainWindow(QWidget * parent = 0) : QMainWindow(parent) {
  305.         LogginPannel * login = new LogginPannel(this);
  306.         BabelPannel * babel = new BabelPannel(this);
  307.  
  308.         m_view = new QStackedWidget(this);
  309.  
  310.         m_view->addWidget(login);
  311.         m_view->addWidget(babel);
  312.  
  313.         createActions();
  314.         createMenus();
  315.  
  316.         setCentralWidget(m_view);
  317.         setFixedSize(QSize(300, 600));
  318.  
  319.         QObject::connect((LogginPannel *)m_view->widget(0), SIGNAL(tryLoggin(QString, QString)), this, SLOT(switchPannel()));
  320.  
  321.         switchPannel(LogginPannelView);
  322.     }
  323.  
  324.     void setBabelMenu() {
  325.         m_addContact->setEnabled(true);
  326.     }
  327.  
  328.     void setLogginMenu() {
  329.         m_addContact->setEnabled(false);
  330.     }
  331.  
  332. public slots:
  333.     void switchPannel(PannelView view = BabelPannelView) {
  334.         switch(view) {
  335.         case LogginPannelView:
  336.             setLogginMenu();
  337.             m_view->setCurrentIndex(0);
  338.             break;
  339.         case BabelPannelView:
  340.             setBabelMenu();
  341.             m_view->setCurrentIndex(1);
  342.             break;
  343.         }
  344.     }
  345.  
  346. signals:
  347.     void startAudioClicked();
  348.     void startTextClicked();
  349. };
  350.  
  351. #endif // MAINWINDOW_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement