Zhenkai Zhu | 275ba3a | 2012-06-01 23:10:43 -0700 | [diff] [blame] | 1 | #include "settingdialog.h" |
Zhenkai Zhu | 7d38556 | 2012-06-02 12:55:07 -0700 | [diff] [blame] | 2 | #include <QRegExp> |
| 3 | #include <QValidator> |
Zhenkai Zhu | 275ba3a | 2012-06-01 23:10:43 -0700 | [diff] [blame] | 4 | |
| 5 | SettingDialog::SettingDialog(QWidget *parent, QString nick, QString chatroom, QString prefix) |
| 6 | : QDialog(parent) |
| 7 | { |
| 8 | setupUi(this); |
| 9 | nickEdit->setPlaceholderText(nick); |
| 10 | roomEdit->setPlaceholderText(chatroom); |
| 11 | prefixEdit->setPlaceholderText(prefix); |
Zhenkai Zhu | 7d38556 | 2012-06-02 12:55:07 -0700 | [diff] [blame] | 12 | |
| 13 | // simple validator for ccnx prefix |
| 14 | QRegExp rx("(^(/[^/]+)+$)|(^/$)"); |
| 15 | QValidator *validator = new QRegExpValidator(rx, this); |
| 16 | prefixEdit->setValidator(validator); |
| 17 | |
| 18 | cancelButton->setDefault(true); |
| 19 | |
Zhenkai Zhu | 275ba3a | 2012-06-01 23:10:43 -0700 | [diff] [blame] | 20 | connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject())); |
Zhenkai Zhu | 3472e3f | 2012-06-02 00:44:42 -0700 | [diff] [blame] | 21 | connect(okButton, SIGNAL(clicked()), this, SLOT(update())); |
| 22 | } |
| 23 | |
| 24 | void |
| 25 | SettingDialog::update() |
| 26 | { |
| 27 | emit updated(nickEdit->text(), roomEdit->text(), prefixEdit->text()); |
| 28 | accept(); |
Zhenkai Zhu | 275ba3a | 2012-06-01 23:10:43 -0700 | [diff] [blame] | 29 | } |
Zhenkai Zhu | 7d38556 | 2012-06-02 12:55:07 -0700 | [diff] [blame] | 30 | |
| 31 | void |
| 32 | SettingDialog::keyPressEvent(QKeyEvent *e) |
| 33 | { |
| 34 | switch(e->key()) { |
| 35 | case Qt::Key_Enter: |
| 36 | update(); |
| 37 | break; |
| 38 | default: |
| 39 | QDialog::keyPressEvent(e); |
| 40 | } |
| 41 | } |