/** This function displays text and color formatting in order to help the user understand what channels have not yet been configured. */ bool ConfigFixedWingWidget::throwConfigError(QString airframeType) { // Initialize configuration error flag bool error = false; QList<QComboBox *> comboChannelsName; comboChannelsName << m_aircraft->fwEngineChannelBox << m_aircraft->fwAileron1ChannelBox << m_aircraft->fwAileron2ChannelBox << m_aircraft->fwElevator1ChannelBox << m_aircraft->fwElevator2ChannelBox << m_aircraft->fwRudder1ChannelBox << m_aircraft->fwRudder2ChannelBox; QString channelNames = ""; for (int i = 0; i < 7; i++) { QComboBox *combobox = comboChannelsName[i]; if (combobox && (combobox->isEnabled())) { if (combobox->currentText() == "None") { int size = combobox->style()->pixelMetric(QStyle::PM_SmallIconSize); QPixmap pixmap(size, size); if ((airframeType == "FixedWingElevon") && (i > 2)) { pixmap.fill(QColor("green")); // Rudders are optional for elevon frame combobox->setToolTip(tr("Rudders are optional for Elevon frame")); } else if (((airframeType == "FixedWing") || (airframeType == "FixedWingVtail")) && (i == 2)) { pixmap.fill(QColor("green")); // Second aileron servo is optional for FixedWing frame combobox->setToolTip(tr("Second aileron servo is optional")); } else if ((airframeType == "FixedWing") && (i > 3)) { pixmap.fill(QColor("green")); // Second elevator and rudders are optional for FixedWing frame combobox->setToolTip(tr("Second elevator servo is optional")); if (i > 4) { combobox->setToolTip(tr("Rudder is highly recommended for fixed wing.")); } } else { pixmap.fill(QColor("red")); combobox->setToolTip(tr("Please assign Channel")); m_aircraft->fwStatusLabel->setText(tr("<font color='red'>ERROR: Assign all necessary channels</font>")); error = true; } combobox->setItemData(0, pixmap, Qt::DecorationRole); // Set color palettes } else if (channelNames.contains(combobox->currentText(), Qt::CaseInsensitive)) { int size = combobox->style()->pixelMetric(QStyle::PM_SmallIconSize); QPixmap pixmap(size, size); pixmap.fill(QColor("orange")); combobox->setItemData(combobox->currentIndex(), pixmap, Qt::DecorationRole); // Set color palettes combobox->setToolTip(tr("Channel already used")); error = true; } else { for (int index = 0; index < (int)ConfigFixedWingWidget::CHANNEL_NUMELEM; index++) { combobox->setItemData(index, 0, Qt::DecorationRole); // Reset all color palettes combobox->setToolTip(""); } } channelNames += (combobox->currentText() == "None") ? "" : combobox->currentText(); } } return error; }
void BaseForm::select() { QComboBox* b = (QComboBox*)sender()->property(PROP_TARG).value<void*>(); if (b && b->isEnabled()) { qint32 i = sender()->objectName().toInt(); if (i < 0) { i = b->currentIndex() + 1; if (i >= b->count()) i = 0; } b->setCurrentIndex(i); } }
/** * Returns true if all relevant children of the widget managed by this * instance are valid AND if #isOtherValid() returns true; otherwise returns * false. Disabled children and children without validation * are skipped and don't affect the result. * * The method emits the #isValidRequested() signal before calling * #isOtherValid(), thus giving someone an opportunity to affect its result by * calling #setOtherValid() from the signal handler. Note that #isOtherValid() * returns true by default, until #setOtherValid( false ) is called. * * @note If #isOtherValid() returns true this method does a hierarchy scan, so * it's a good idea to store the returned value in a local variable if needed * more than once within a context of a single check. */ bool QIWidgetValidator::isValid() const { // wgt is null, we assume we're valid if (!mWidget) return true; QIWidgetValidator *that = const_cast <QIWidgetValidator *> (this); emit that->isValidRequested (that); if (!isOtherValid()) return false; QValidator::State state = QValidator::Acceptable; foreach (Watched watched, mWatched) { if (watched.widget->inherits ("QLineEdit")) { QLineEdit *le = ((QLineEdit *) watched.widget); Assert (le->validator()); if (!le->validator() || !le->isEnabled()) continue; QString text = le->text(); int pos; state = le->validator()->validate (text, pos); } else if (watched.widget->inherits ("QComboBox")) { QComboBox *cb = ((QComboBox *) watched.widget); Assert (cb->validator()); if (!cb->validator() || !cb->isEnabled()) continue; QString text = cb->lineEdit()->text(); int pos; state = cb->lineEdit()->validator()->validate (text, pos); } if (state != QValidator::Acceptable) { that->mLastInvalid = watched; that->mLastInvalid.state = state; return false; } } /* reset last invalid */ that->mLastInvalid = Watched(); return true; }
QByteArray TableItem::GenHTMLForm() { QString ret; QString objTypeName = obj->metaObject()->className(); if(objTypeName == "QPlainTextEdit") { QPlainTextEdit *item = (QPlainTextEdit *) obj; #if 0 ret = QString("<form method=\"post\">" " <input type=\"hidden\" name=\"action\" value=\"%2\">" "<div class=\"form_info\">%1</div>" "<div class=\"form_editor\"><textarea name=\"%2\" cols=\"20\" rows=\"4\">%3</textarea></div>" "<div class=\"form_submitter\"><input type=\"submit\" value=\">>\"></div>" "<div class=\"form_tooltip\">%4</div>" "</form>") .arg(desc).arg(short_d).arg(item->toPlainText()).arg(item->toolTip()); #endif ret = QString("<form method=\"post\"><input type=\"hidden\" name=\"action\" value=\"%2\" />" "<div class=\"row\">" "<div class=\"prop\"><p>%1:</p></div>" "<div class=\"val\"><p><textarea name=\"%2\" cols=\"16\" rows=\"3\">%3</textarea></p></div>" "<div class=\"submit\"><p> %4</p></div>" "<div class=\"tooltip\"><p> %5</p></div>" "</div></form>\n") .arg(desc) .arg(short_d) .arg(item->toPlainText()) .arg((!item->isEnabled() || item->isReadOnly()) ? "" : "<input type=\"submit\" value=\">>\" />") .arg(item->toolTip()); } else if(objTypeName == "QLineEdit") { QLineEdit *item = (QLineEdit *) obj; ret = QString("<form method=\"post\"><input type=\"hidden\" name=\"action\" value=\"%2\" />" "<div class=\"row\">" "<div class=\"prop\"><p>%1:</p></div>" "<div class=\"val\"><p><input type=\"text\" name=\"%2\" value=\"%3\" /></p></div>" "<div class=\"submit\"><p> %4</p></div>" "<div class=\"tooltip\"><p> %5</p></div>" "</div></form>\n") .arg(desc) .arg(short_d) .arg(item->text()) .arg((!item->isEnabled() || item->isReadOnly()) ? "" : "<input type=\"submit\" value=\">>\" />") .arg(item->toolTip()); } else if(objTypeName == "QCheckBox") { QCheckBox *item = (QCheckBox *) obj; ret = QString("<form method=\"post\"><input type=\"hidden\" name=\"action\" value=\"%2\" />" "<div class=\"row\">" "<div class=\"prop\"><p>%1:</p></div>" "<div class=\"val\"><p><input type=\"checkbox\" name=\"%2\" value=\"true\" %3/></p></div>" "<div class=\"submit\"><p> %4</p></div>" "<div class=\"tooltip\"><p> %5</p></div>" "</div></form>\n") .arg(desc) .arg(short_d) .arg(item->isChecked() ? "checked" : "") .arg((!item->isEnabled()) ? "" : "<input type=\"submit\" value=\">>\" />") .arg(item->toolTip()); } else if(objTypeName == "QSpinBox") { QSpinBox *item = (QSpinBox *) obj; ret = QString("<form method=\"post\"><input type=\"hidden\" name=\"action\" value=\"%2\" />" "<div class=\"row\">" "<div class=\"prop\"><p>%1:</p></div>" "<div class=\"val\"><p><input type=\"number\" name=\"%2\" value=\"%3\" min=\"%4\" max=\"%5\" step=\"%6\" /></p></div>" "<div class=\"submit\"><p> %7</p></div>" "<div class=\"tooltip\"><p> %8</p></div>" "</div></form>\n") .arg(desc) .arg(short_d) .arg(item->value()) .arg(item->minimum()) .arg(item->maximum()) .arg(item->singleStep()) .arg((!item->isEnabled() || item->isReadOnly()) ? "" : "<input type=\"submit\" value=\">>\" />") .arg(item->toolTip()); } else if(objTypeName == "QDoubleSpinBox") { QDoubleSpinBox *item = (QDoubleSpinBox *) obj; ret = QString("<form method=\"post\"><input type=\"hidden\" name=\"action\" value=\"%2\" />" "<div class=\"row\">" "<div class=\"prop\"><p>%1:</p></div>" "<div class=\"val\"><p><input type=\"number\" name=\"%2\" value=\"%3\" min=\"%4\" max=\"%5\" step=\"%6\" /></p></div>" "<div class=\"submit\"><p> %7</p></div>" "<div class=\"tooltip\"><p> %8</p></div>" "</div></form>\n") .arg(desc) .arg(short_d) .arg(item->value()) .arg(item->minimum()) .arg(item->maximum()) .arg(item->singleStep()) .arg((!item->isEnabled() || item->isReadOnly()) ? "" : "<input type=\"submit\" value=\">>\" />") .arg(item->toolTip()); } else if(objTypeName == "QComboBox") { QComboBox *item = (QComboBox *) obj; ret = QString("<form method=\"post\"><input type=\"hidden\" name=\"action\" value=\"%2\" />" "<div class=\"row\">" "<div class=\"prop\"><p>%1:</p></div>" "<div class=\"val\"><p>\n<select name=\"%2\" style=\"max-width:170px;\">\n").arg(desc).arg(short_d); int current = item->currentIndex(); for (int i = 0; i < item->count(); i++) { ret.append(QString("<option value=\"%1\" %2>%3</option>\n").arg(i).arg(i==current ? "selected" : "").arg(item->itemText(i))); } ret.append(QString("</select>\n</p></div>" "<div class=\"submit\"><p> %1</p></div>" "<div class=\"tooltip\"><p> %2</p></div>" "</div></form>\n") .arg((!item->isEnabled()) ? "" : "<input type=\"submit\" value=\">>\" />") .arg(item->toolTip())); } else if(objTypeName == "QRadioButton") { QRadioButton *item = (QRadioButton *) obj; QString rb_vals; if(item->objectName() == "radioButton_rds_music") { rb_vals = QString("<input type=\"radio\" name=\"%1\" value=\"true\" %2/> Music <input type=\"radio\" name=\"%1\" value=\"false\" %3/> Speech") .arg(short_d).arg(item->isChecked() ? "checked" : "").arg(item->isChecked() ? "" : "checked"); } ret = QString("<form method=\"post\"><input type=\"hidden\" name=\"action\" value=\"%2\" />" "<div class=\"row\">" "<div class=\"prop\"><p>%1:</p></div>" "<div class=\"val\"><p>%3</p></div>" "<div class=\"submit\"><p> %4</p></div>" "<div class=\"tooltip\"><p> %5</p></div>" "</div></form>\n") .arg(desc) .arg(short_d) .arg(rb_vals) .arg((!item->isEnabled()) ? "" : "<input type=\"submit\" value=\">>\" />") .arg(item->toolTip()); } else if(objTypeName == "QPushButton") { QPushButton *item = (QPushButton *) obj; ret = QString("<form method=\"post\"><input type=\"hidden\" name=\"action\" value=\"%2\" />" "<div class=\"row\">" "<div class=\"prop\"><p>%1:</p></div>" "<div class=\"val\"><p>%3</p></div>" "<div class=\"submit\"><p> %4</p></div>" "<div class=\"tooltip\"><p> %5</p></div>" "</div></form>\n") .arg(desc) .arg(short_d) .arg("action") .arg((!item->isEnabled()) ? "" : "<input type=\"submit\" value=\">>\" />") .arg(item->toolTip()); } else { qDebug() << "unimplemented obj_type: " << objTypeName; } return ret.toUtf8(); };