blob: d9640dc2168869125cdd517f0e470788171fe0a3 [file] [log] [blame]
Zhenkai Zhu275ba3a2012-06-01 23:10:43 -07001#include "settingdialog.h"
Zhenkai Zhu7d385562012-06-02 12:55:07 -07002#include <QRegExp>
3#include <QValidator>
Zhenkai Zhu275ba3a2012-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 Zhu7d385562012-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 Zhu275ba3a2012-06-01 23:10:43 -070020 connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
Zhenkai Zhu3472e3f2012-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 Zhu275ba3a2012-06-01 23:10:43 -070029}
Zhenkai Zhu7d385562012-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}