int MPPrefs::handleMessage( unsigned long message, unsigned long who ) { switch ( who ) { case MB_MSG_NEXT: status = DOWN; saveSettings( ); break; case MB_MSG_PREV: status = DOWN; cancelSettings(); break; case MB_MSG_MAINMENU: status = MAINMENU; break; case MP_PREFS_BASE: case MP_PREFS_STRIPE: { getButton( MP_PREFS_BASE )->press( 0 ); getButton( MP_PREFS_STRIPE )->press( 0 ); getButton( who )->press( 1 ); } break; } return 0; }
SettingDialog::SettingDialog(QWidget *parent) : QDialog(parent), ui(new Ui::SettingDialog) { ui->setupUi(this); connect(ui->saveButton, SIGNAL(clicked()), this, SLOT(saveSettings())); connect(ui->cancelButton, SIGNAL(clicked()), this, SLOT(cancelSettings())); connect(ui->createChannelButton, SIGNAL(clicked()), this, SLOT(createChannel())); connect(ui->enterChannelButton, SIGNAL(clicked()), this, SLOT(enterChannel())); QSettings *settings = DanmakuEngineSingleton::Instance()->getSettings(); if(settings->value("firstrun").toString()=="false"){ ui->serverLineEdit->setText(settings->value("server").toString()); ui->channelLineEdit->setText(settings->value("channel").toString()); ui->passwordLineEdit->setText(settings->value("password").toString()); }else { settings->setValue("firstrun","false"); settings->sync(); } this->raise(); }
HardwareSettingsDialog::HardwareSettingsDialog(QWidget *parent, QString file, Hardware *module) : QDialog(parent), descriptorFile(file) { hardwareModule = module; readDescriptorFromFile(descriptorFile); refreshRegisters(); buttonOk = new QPushButton(this); buttonCancel = new QPushButton(this); buttonOk->resize(100, 25); buttonOk->setText(QString::fromLocal8Bit("Применить")); buttonCancel->resize(100, 25); buttonCancel->setText(QString::fromLocal8Bit("Отмена")); connect(buttonOk, SIGNAL(clicked()), this, SLOT(applySettings())); connect(buttonCancel, SIGNAL(clicked()), this, SLOT(cancelSettings())); // отрисовка найденых регистров на форме QVector<ModbusRegister*>::Iterator reg = registerVector.begin(); int yPos = 10; int yStep = 30; int labelXsize = 200; int labelYsize = 25; int lineEditXsize = 150; int xDistance = 20; for (reg = registerVector.begin(); reg != registerVector.end(); ++reg) { if ((*reg)->getType() == ModbusRegister::reservType) continue; QLabel* text = new QLabel(this); text->show(); text->move(5, yPos); text->resize(labelXsize, labelYsize); text->setText((*reg)->name); labelVector.push_back(text); switch ((*reg)->getType()) { case ModbusRegister::intType : { QLineEdit* edit = new QLineEdit(this); edit->move(labelXsize + xDistance, yPos); edit->resize(lineEditXsize, labelYsize); edit->setText(QString::number((*reg)->getData())); edit->show(); lineeditVector.push_back(edit); } break; case ModbusRegister::textType : { QComboBox *box = new QComboBox(this); // заполняем список фозможными значениями int nText = (*reg)->stringText_.size(); for (int j = 0; j < nText; j++) { box->addItem((*reg)->stringText_[j]); } box->setCurrentIndex((*reg)->getData()); // пихаем на форму box->move(labelXsize + xDistance, yPos); box->resize(lineEditXsize, labelYsize); box->show(); boxVector.push_back(box); } break; default : break; } yPos += yStep; } yPos += yStep; buttonOk->move(400 - 100 - (400 - xDistance - labelXsize - lineEditXsize), yPos); // это придумал мой пьяный мозг, на самом деле нужно просто добавить компоновщик buttonCancel->move(400 - 100 - xDistance - 100 - (400 - xDistance - labelXsize - lineEditXsize), yPos); buttonCancel->show(); buttonOk->show(); yPos += yStep; this->resize(400, yPos + 25); this->exec(); }