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 | 8e180ae | 2012-10-10 14:01:05 -0700 | [diff] [blame] | 23 | if (nick.isEmpty()) |
Zhenkai Zhu | d616b58 | 2012-10-10 00:04:07 -0700 | [diff] [blame] | 24 | { |
| 25 | prefixEdit->hide(); |
| 26 | prefixLabel->hide(); |
| 27 | } |
| 28 | |
Zhenkai Zhu | 5b0e323 | 2012-06-05 20:28:44 -0700 | [diff] [blame] | 29 | okButton->setDefault(true); |
Zhenkai Zhu | 56a60ce | 2012-06-02 12:55:07 -0700 | [diff] [blame] | 30 | |
Zhenkai Zhu | 85845d2 | 2012-06-01 23:10:43 -0700 | [diff] [blame] | 31 | connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject())); |
Zhenkai Zhu | 7e9b06d | 2012-06-02 00:44:42 -0700 | [diff] [blame] | 32 | connect(okButton, SIGNAL(clicked()), this, SLOT(update())); |
| 33 | } |
| 34 | |
| 35 | void |
| 36 | SettingDialog::update() |
| 37 | { |
| 38 | emit updated(nickEdit->text(), roomEdit->text(), prefixEdit->text()); |
| 39 | accept(); |
Zhenkai Zhu | 85845d2 | 2012-06-01 23:10:43 -0700 | [diff] [blame] | 40 | } |
Zhenkai Zhu | 56a60ce | 2012-06-02 12:55:07 -0700 | [diff] [blame] | 41 | |
| 42 | void |
| 43 | SettingDialog::keyPressEvent(QKeyEvent *e) |
| 44 | { |
| 45 | switch(e->key()) { |
| 46 | case Qt::Key_Enter: |
| 47 | update(); |
| 48 | break; |
| 49 | default: |
| 50 | QDialog::keyPressEvent(e); |
| 51 | } |
| 52 | } |
Alexander Afanasyev | b4b9229 | 2013-07-09 13:54:59 -0700 | [diff] [blame] | 53 | |
| 54 | #if WAF |
| 55 | #include "settingdialog.moc" |
| 56 | #include "settingdialog.cpp.moc" |
| 57 | #endif |