blob: 284b1a35b5a525cdf148d90de7fc0d111b0b4b84 [file] [log] [blame]
Zhenkai Zhu85845d22012-06-01 23:10:43 -07001#include "settingdialog.h"
Zhenkai Zhu56a60ce2012-06-02 12:55:07 -07002#include <QRegExp>
3#include <QValidator>
Zhenkai Zhu85845d22012-06-01 23:10:43 -07004
5SettingDialog::SettingDialog(QWidget *parent, QString nick, QString chatroom, QString prefix)
6 : QDialog(parent)
7{
8 setupUi(this);
Zhenkai Zhu716addc2012-06-05 20:57:41 -07009
10 QRegExp noWhiteSpace("^\\S+.*$");
11 QValidator *nwsValidator = new QRegExpValidator(noWhiteSpace, this);
Zhenkai Zhu85845d22012-06-01 23:10:43 -070012 nickEdit->setPlaceholderText(nick);
Zhenkai Zhu716addc2012-06-05 20:57:41 -070013 nickEdit->setValidator(nwsValidator);
Zhenkai Zhu85845d22012-06-01 23:10:43 -070014 roomEdit->setPlaceholderText(chatroom);
Zhenkai Zhu716addc2012-06-05 20:57:41 -070015 roomEdit->setValidator(nwsValidator);
Zhenkai Zhu85845d22012-06-01 23:10:43 -070016 prefixEdit->setPlaceholderText(prefix);
Zhenkai Zhu56a60ce2012-06-02 12:55:07 -070017
18 // simple validator for ccnx prefix
19 QRegExp rx("(^(/[^/]+)+$)|(^/$)");
20 QValidator *validator = new QRegExpValidator(rx, this);
21 prefixEdit->setValidator(validator);
22
Zhenkai Zhud616b582012-10-10 00:04:07 -070023 if (nick.isEmpty() && chatroom.isEmpty())
24 {
25 prefixEdit->hide();
26 prefixLabel->hide();
27 }
28
Zhenkai Zhu5b0e3232012-06-05 20:28:44 -070029 okButton->setDefault(true);
Zhenkai Zhu56a60ce2012-06-02 12:55:07 -070030
Zhenkai Zhu85845d22012-06-01 23:10:43 -070031 connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
Zhenkai Zhu7e9b06d2012-06-02 00:44:42 -070032 connect(okButton, SIGNAL(clicked()), this, SLOT(update()));
33}
34
35void
36SettingDialog::update()
37{
38 emit updated(nickEdit->text(), roomEdit->text(), prefixEdit->text());
39 accept();
Zhenkai Zhu85845d22012-06-01 23:10:43 -070040}
Zhenkai Zhu56a60ce2012-06-02 12:55:07 -070041
42void
43SettingDialog::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}