Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef MAINWINDOW_H
- #define MAINWINDOW_H
- #include <QtGui>
- // register via meta obejct system
- class Contact {
- public:
- enum AvailableMedia {
- // Video,
- Audio,
- Text
- };
- Q_DECLARE_FLAGS(AvailableMedias, AvailableMedia)
- private:
- QString m_name;
- AvailableMedias m_medias;
- public:
- void setMedias(AvailableMedias medias);
- void setName(const QString & name);
- AvailableMedias medias() const;
- QString name() const;
- };
- class AddContactDialog : public QDialog {
- Q_OBJECT
- private:
- QLineEdit * m_name;
- QPushButton * m_validateButton;
- QPushButton * m_cancelButton;
- bool m_validateClicked;
- public:
- AddContactDialog(QWidget * parent = 0) : QDialog(parent) {
- m_validateClicked = false;
- m_name = new QLineEdit(this);
- m_validateButton = new QPushButton("Validate", this);
- m_cancelButton = new QPushButton("Cancel", this);
- QFormLayout * layout = new QFormLayout(this);
- layout->addRow("User", m_name);
- layout->addWidget(m_validateButton);
- layout->addWidget(m_cancelButton);
- QObject::connect(m_validateButton, SIGNAL(clicked()), this, SLOT(validate()));
- QObject::connect(m_cancelButton, SIGNAL(clicked()), this, SLOT(close()));
- }
- QString user() const { return m_name->text(); }
- bool validateClicked() const { return m_validateClicked; }
- private slots:
- void validate() {
- m_validateClicked = true;
- close();
- }
- };
- class SubscribeDialog : public QDialog {
- Q_OBJECT
- private:
- QLineEdit * m_name;
- QLineEdit * m_password;
- QPushButton * m_validateButton;
- QPushButton * m_cancelButton;
- bool m_validateClicked;
- public:
- SubscribeDialog(QWidget * parent = 0) : QDialog(parent) {
- m_validateClicked = false;
- m_name = new QLineEdit(this);
- m_password = new QLineEdit(this);
- m_password->setEchoMode(QLineEdit::Password);
- m_validateButton = new QPushButton("Validate", this);
- m_cancelButton = new QPushButton("Cancel", this);
- QFormLayout * layout = new QFormLayout(this);
- layout->addRow("User", m_name);
- layout->addRow("Pass", m_password);
- layout->addWidget(m_validateButton);
- layout->addWidget(m_cancelButton);
- QObject::connect(m_validateButton, SIGNAL(clicked()), this, SLOT(validate()));
- QObject::connect(m_cancelButton, SIGNAL(clicked()), this, SLOT(close()));
- }
- void setUser(const QString & user) { m_name->setText(user); }
- void setPassword(const QString & password) { m_password->setText(password); }
- QString password() const { return m_password->text(); }
- QString user() const { return m_name->text(); }
- bool validateClicked() const { return m_validateClicked; }
- private slots:
- void validate() {
- m_validateClicked = true;
- close();
- }
- };
- class LogginPannel : public QWidget {
- Q_OBJECT
- private:
- QLineEdit * m_username;
- QLineEdit * m_password;
- QPushButton * m_logginButton;
- QPushButton * m_subscribeButton;
- public:
- enum LogginStatus {
- LoggedIn,
- LogginError
- };
- LogginPannel(QWidget * parent = 0) : QWidget(parent) {
- m_username = new QLineEdit(this);
- m_password = new QLineEdit(this);
- m_logginButton = new QPushButton("Connect", this);
- m_subscribeButton = new QPushButton("Subscribe", this);
- m_password->setEchoMode(QLineEdit::PasswordEchoOnEdit);
- QFormLayout * layout = new QFormLayout(this);
- layout->setFormAlignment(Qt::AlignVCenter);
- layout->addRow("User", m_username);
- layout->addRow("Pass", m_password);
- QWidget * dummy = new QWidget(this);
- QHBoxLayout * buttonLayout = new QHBoxLayout(dummy);
- dummy->setLayout(buttonLayout);
- buttonLayout->addWidget(m_logginButton);
- buttonLayout->addWidget(m_subscribeButton);
- layout->addWidget(dummy);
- QObject::connect(m_logginButton, SIGNAL(clicked()), this, SLOT(loginClicked()));
- QObject::connect(m_subscribeButton, SIGNAL(clicked()), this, SLOT(subscribeClicked()));
- }
- signals:
- void tryLoggin(const QString & userName, const QString & password);
- void trySubscribe(const QString & userName, const QString & password);
- private slots:
- void treatLoggin(LogginStatus status, const QString & errorMessage) {
- }
- void loginClicked() {
- emit tryLoggin(m_username->text(), m_password->text());
- }
- void subscribeClicked() {
- SubscribeDialog dialog(this);
- dialog.setUser(m_username->text());
- dialog.setPassword(m_password->text());
- dialog.exec();
- if(dialog.validateClicked()) {
- qDebug() << "validate !";
- m_username->setText(dialog.user());
- m_password->setText(dialog.password());
- emit trySubscribe(dialog.user(), dialog.password());
- }
- }
- void subscribeSuccesful() {
- loginClicked();
- }
- };
- class BabelPannel : public QWidget {
- Q_OBJECT
- private:
- /*QListWidget * m_contactView;
- QList < Contact > m_contacts;*/
- QComboBox * m_contactList;
- public:
- BabelPannel(QWidget * parent = 0) : QWidget(parent) {
- QVBoxLayout * layout = new QVBoxLayout(this);
- m_contactList = new QComboBox(this);
- m_contactList->addItem("JCDuss", "JCDuss");
- m_contactList->addItem("JCDuss1", "JCDuss1");
- m_contactList->addItem("JCDuss2", "JCDuss2");
- m_contactList->addItem("JCDuss3", "JCDuss3");
- layout->addWidget(m_contactList);
- QObject::connect(this, SIGNAL(addContact(QString)), this, SLOT(updateViewAdd(QString)));
- QObject::connect(this, SIGNAL(deleteContact(QString)), this, SLOT(updateViewRemove(QString)));
- }
- public slots:
- void addContact() {
- // adding contat dialog
- AddContactDialog dialog(this);
- dialog.exec();
- if(dialog.validateClicked()) {
- emit addContact(dialog.user());
- }
- }
- void deleteContact() {
- if(QMessageBox::question(this, "Confirmation", "Etes vous sur ?", QMessageBox::Yes | QMessageBox::No, QMessageBox::No) == QMessageBox::Yes)
- emit deleteContact(m_contactList->currentText());
- }
- void updateViewAdd(const QString & contact) {
- m_contactList->addItem(contact, contact);
- }
- void updateViewRemove(const QString & contact) {
- m_contactList->removeItem(m_contactList->findText(contact));
- }
- void audioClick() {
- qDebug() << "audioClick";
- }
- void textClick() {
- qDebug() << "textClick";
- }
- signals:
- void disconnectBabel();
- void startAudio(const Contact & contact);
- void startText(const Contact & contact);
- void addContact(const QString & contact);
- void deleteContact(const QString & contact);
- };
- class MainWindow : public QMainWindow
- {
- Q_OBJECT
- private:
- QStackedWidget * m_view;
- QMenu * m_fileMenu;
- QMenu * m_contactMenu;
- QAction * m_addContact;
- QAction * m_deleteContact;
- QAction * m_editConnection;
- QAction * m_quit;
- QAction * m_startAudio;
- QAction * m_startText;
- void createActions() {
- m_addContact = new QAction(tr("Add contact"), this);
- connect(m_addContact, SIGNAL(triggered()), m_view->widget(1), SLOT(addContact()));
- m_deleteContact = new QAction(tr("Delete contact"), this);
- connect(m_deleteContact, SIGNAL(triggered()), m_view->widget(1), SLOT(deleteContact()));
- m_quit = new QAction(tr("Delete contact"), this);
- connect(m_quit, SIGNAL(triggered()), this, SLOT(close()));
- }
- void createMenus() {
- m_fileMenu = menuBar()->addMenu(tr("&Menu"));
- m_fileMenu->addAction(m_addContact);
- m_fileMenu->addAction(m_deleteContact);
- m_fileMenu->addSeparator();
- m_fileMenu->addAction(m_quit);
- }
- public:
- enum PannelView {
- LogginPannelView,
- BabelPannelView
- };
- MainWindow(QWidget * parent = 0) : QMainWindow(parent) {
- LogginPannel * login = new LogginPannel(this);
- BabelPannel * babel = new BabelPannel(this);
- m_view = new QStackedWidget(this);
- m_view->addWidget(login);
- m_view->addWidget(babel);
- createActions();
- createMenus();
- setCentralWidget(m_view);
- setFixedSize(QSize(300, 600));
- QObject::connect((LogginPannel *)m_view->widget(0), SIGNAL(tryLoggin(QString, QString)), this, SLOT(switchPannel()));
- switchPannel(LogginPannelView);
- }
- void setBabelMenu() {
- m_addContact->setEnabled(true);
- }
- void setLogginMenu() {
- m_addContact->setEnabled(false);
- }
- public slots:
- void switchPannel(PannelView view = BabelPannelView) {
- switch(view) {
- case LogginPannelView:
- setLogginMenu();
- m_view->setCurrentIndex(0);
- break;
- case BabelPannelView:
- setBabelMenu();
- m_view->setCurrentIndex(1);
- break;
- }
- }
- signals:
- void startAudioClicked();
- void startTextClicked();
- };
- #endif // MAINWINDOW_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement