blob: d9640dc2168869125cdd517f0e470788171fe0a3 [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);
9 nickEdit->setPlaceholderText(nick);
10 roomEdit->setPlaceholderText(chatroom);
11 prefixEdit->setPlaceholderText(prefix);
Zhenkai Zhu56a60ce2012-06-02 12:55:07 -070012
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 Zhu85845d22012-06-01 23:10:43 -070020 connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
Zhenkai Zhu7e9b06d2012-06-02 00:44:42 -070021 connect(okButton, SIGNAL(clicked()), this, SLOT(update()));
22}
23
24void
25SettingDialog::update()
26{
27 emit updated(nickEdit->text(), roomEdit->text(), prefixEdit->text());
28 accept();
Zhenkai Zhu85845d22012-06-01 23:10:43 -070029}
Zhenkai Zhu56a60ce2012-06-02 12:55:07 -070030
31void
32SettingDialog::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}