//写函数,在数值发生变化是才发信号 void Widget::setNickName(const QString &strNewName) { if(strNewName == m_nickName) { //数值没变化,直接返回 return; } //修改数值并触发信号 m_nickName = strNewName; emit nickNameChanged(strNewName); }
SessionItem::SessionItem(Session* session) : AbstractSessionItem(session), m_closing(false) { setTitle(session->host()); setSubtitle(session->nickName()); connect(session, SIGNAL(hostChanged(QString)), this, SLOT(setTitle(QString))); connect(session, SIGNAL(nickNameChanged(QString)), this, SLOT(setSubtitle(QString))); connect(session, SIGNAL(socketError(QAbstractSocket::SocketError)), this, SLOT(updateState())); connect(session, SIGNAL(connectedChanged(bool)), this, SLOT(updateState())); connect(session, SIGNAL(activeChanged(bool)), this, SLOT(updateState())); setSession(session); m_handler.setSession(session); m_handler.setDefaultReceiver(this); m_handler.setCurrentReceiver(this); connect(&m_handler, SIGNAL(receiverToBeAdded(QString)), SLOT(addChild(QString))); connect(&m_handler, SIGNAL(receiverToBeRenamed(QString,QString)), SLOT(renameChild(QString,QString))); connect(&m_handler, SIGNAL(receiverToBeRemoved(QString)), SLOT(removeChild(QString))); updateCurrent(this); updateState(); }
//----------------------------------------------------------------------------- ConfigDialog::ConfigDialog(QWidget *parent) : QDialog(parent), _saved(false), _WWHEnabled(0) { // kDebug(11001) << ": ConfigDialog"; setWindowTitle( i18n("Configure Highscores") ); setModal( true ); QWidget *page = 0; QTabWidget *tab = 0; QVBoxLayout *layout = new QVBoxLayout; setLayout(layout); if ( internal->isWWHSAvailable() ) { tab = new QTabWidget(this); layout->addWidget(tab); page = new QWidget; tab->addTab(page, i18n("Main")); } else { page = new QWidget(this); layout->addWidget(page); } QGridLayout *pageTop = new QGridLayout(page); //pageTop->setMargin(QApplication::style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing)); //pageTop->setSpacing(QApplication::style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing)); layout->addLayout(pageTop); QLabel *label = new QLabel(i18n("Nickname:"), page); pageTop->addWidget(label, 0, 0); _nickname = new QLineEdit(page); connect(_nickname, SIGNAL(textChanged(QString)), SLOT(modifiedSlot())); connect(_nickname, SIGNAL(textChanged(QString)), SLOT(nickNameChanged(QString))); _nickname->setMaxLength(16); pageTop->addWidget(_nickname, 0, 1); label = new QLabel(i18n("Comment:"), page); pageTop->addWidget(label, 1, 0); _comment = new QLineEdit(page); connect(_comment, SIGNAL(textChanged(QString)), SLOT(modifiedSlot())); _comment->setMaxLength(50); pageTop->addWidget(_comment, 1, 1); if (tab) { _WWHEnabled = new QCheckBox(i18n("World-wide highscores enabled"), page); connect(_WWHEnabled, SIGNAL(toggled(bool)), SLOT(modifiedSlot())); pageTop->addWidget(_WWHEnabled, 2, 0, 1, 2 ); // advanced tab QWidget *page = new QWidget; tab->addTab(page, i18n("Advanced")); QVBoxLayout *pageTop = new QVBoxLayout(page); //pageTop->setMargin(QApplication::style()->pixelMetric(QStyle::PM_DefaultChildMargin)); //pageTop->setSpacing(QApplication::style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing)); QGroupBox *group = new QGroupBox(page); group->setTitle( i18n("Registration Data") ); pageTop->addWidget(group); QGridLayout *groupLayout = new QGridLayout(group); //groupLayout->setSpacing(QApplication::style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing)); label = new QLabel(i18n("Nickname:"), group); groupLayout->addWidget(label, 0, 0); _registeredName = new KLineEdit(group); _registeredName->setReadOnly(true); groupLayout->addWidget(_registeredName, 0, 1); label = new QLabel(i18n("Key:"), group); groupLayout->addWidget(label, 1, 0); _key = new KLineEdit(group); _key->setReadOnly(true); groupLayout->addWidget(_key, 1, 1); KGuiItem gi = KStandardGuiItem::clear(); gi.setText(i18n("Remove")); _removeButton = new QPushButton(group); KGuiItem::assign(_removeButton, gi); groupLayout->addWidget(_removeButton, 2, 0); connect(_removeButton, SIGNAL(clicked()), SLOT(removeSlot())); } buttonBox = new QDialogButtonBox(this); buttonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Apply | QDialogButtonBox::Cancel); connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); // TODO mapping for Apply button pageTop->addWidget(buttonBox); load(); buttonBox->button(QDialogButtonBox::Ok)->setEnabled( !_nickname->text().isEmpty() ); buttonBox->button(QDialogButtonBox::Apply)->setEnabled( false ); }