blob: 8f0bbcad9278031ff65d34adaceab17341bd529a [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 Zhu5b0e3232012-06-05 20:28:44 -070023 okButton->setDefault(true);
Zhenkai Zhu56a60ce2012-06-02 12:55:07 -070024
Zhenkai Zhu85845d22012-06-01 23:10:43 -070025 connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
Zhenkai Zhu7e9b06d2012-06-02 00:44:42 -070026 connect(okButton, SIGNAL(clicked()), this, SLOT(update()));
27}
28
29void
30SettingDialog::update()
31{
32 emit updated(nickEdit->text(), roomEdit->text(), prefixEdit->text());
33 accept();
Zhenkai Zhu85845d22012-06-01 23:10:43 -070034}
Zhenkai Zhu56a60ce2012-06-02 12:55:07 -070035
36void
37SettingDialog::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}