Zhenkai Zhu | 85845d2 | 2012-06-01 23:10:43 -0700 | [diff] [blame] | 1 | #include "settingdialog.h" |
Zhenkai Zhu | 56a60ce | 2012-06-02 12:55:07 -0700 | [diff] [blame] | 2 | #include <QRegExp> |
| 3 | #include <QValidator> |
Zhenkai Zhu | 85845d2 | 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); |
Zhenkai Zhu | 716addc | 2012-06-05 20:57:41 -0700 | [diff] [blame] | 9 | |
| 10 | QRegExp noWhiteSpace("^\\S+.*$"); |
| 11 | QValidator *nwsValidator = new QRegExpValidator(noWhiteSpace, this); |
Zhenkai Zhu | 85845d2 | 2012-06-01 23:10:43 -0700 | [diff] [blame] | 12 | nickEdit->setPlaceholderText(nick); |
Zhenkai Zhu | 716addc | 2012-06-05 20:57:41 -0700 | [diff] [blame] | 13 | nickEdit->setValidator(nwsValidator); |
Zhenkai Zhu | 85845d2 | 2012-06-01 23:10:43 -0700 | [diff] [blame] | 14 | roomEdit->setPlaceholderText(chatroom); |
Zhenkai Zhu | 716addc | 2012-06-05 20:57:41 -0700 | [diff] [blame] | 15 | roomEdit->setValidator(nwsValidator); |
Zhenkai Zhu | 85845d2 | 2012-06-01 23:10:43 -0700 | [diff] [blame] | 16 | prefixEdit->setPlaceholderText(prefix); |
Zhenkai Zhu | 56a60ce | 2012-06-02 12:55:07 -0700 | [diff] [blame] | 17 | |
| 18 | // simple validator for ccnx prefix |
| 19 | QRegExp rx("(^(/[^/]+)+$)|(^/$)"); |
| 20 | QValidator *validator = new QRegExpValidator(rx, this); |
| 21 | prefixEdit->setValidator(validator); |
| 22 | |
Zhenkai Zhu | 5b0e323 | 2012-06-05 20:28:44 -0700 | [diff] [blame] | 23 | okButton->setDefault(true); |
Zhenkai Zhu | 56a60ce | 2012-06-02 12:55:07 -0700 | [diff] [blame] | 24 | |
Zhenkai Zhu | 85845d2 | 2012-06-01 23:10:43 -0700 | [diff] [blame] | 25 | connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject())); |
Zhenkai Zhu | 7e9b06d | 2012-06-02 00:44:42 -0700 | [diff] [blame] | 26 | connect(okButton, SIGNAL(clicked()), this, SLOT(update())); |
| 27 | } |
| 28 | |
| 29 | void |
| 30 | SettingDialog::update() |
| 31 | { |
| 32 | emit updated(nickEdit->text(), roomEdit->text(), prefixEdit->text()); |
| 33 | accept(); |
Zhenkai Zhu | 85845d2 | 2012-06-01 23:10:43 -0700 | [diff] [blame] | 34 | } |
Zhenkai Zhu | 56a60ce | 2012-06-02 12:55:07 -0700 | [diff] [blame] | 35 | |
| 36 | void |
| 37 | SettingDialog::keyPressEvent(QKeyEvent *e) |
| 38 | { |
| 39 | switch(e->key()) { |
| 40 | case Qt::Key_Enter: |
| 41 | update(); |
| 42 | break; |
| 43 | default: |
| 44 | QDialog::keyPressEvent(e); |
| 45 | } |
| 46 | } |