void diaElemAspectRatio::enable(uint32_t onoff) { QSpinBox *numBox = (QSpinBox*)myWidget; QSpinBox *denBox = (QSpinBox*)denControl; QLabel *label = (QLabel*)this->label; numBox->setEnabled(onoff); denBox->setEnabled(onoff); label->setEnabled(onoff); }
void CTariffSetting::ControlRuleUI( bool bInner, int nIndex, bool bEnabled ) { int nItems = 6; if ( nIndex > nItems ) { return; } QString strNameRule; QString strNameFoot; QString strRule = QString( "rule%1Min%2" ); QString strFoot = QString( "rule%1Foot%2" ); QSpinBox* pSB; QGroupBox* pGB = bInner ? ui->gbInnerFirst : ui->gbOuterFirst; for ( int nItem = nIndex + 1; nItem <= nItems; nItem++ ) { strNameRule = strRule.arg( QString::number( nItem ), bInner ? "Inner" : "Outer" ); strNameFoot = strFoot.arg( QString::number( nItem ), bInner ? "Inner" : "Outer" ); pSB = pGB->findChild< QSpinBox* >( strNameRule ); pSB->setEnabled( false ); pSB->setValue( 0 ); pSB = pGB->findChild< QSpinBox* >( strNameFoot ); pSB->setEnabled( false ); pSB->setValue( 0 ); } strNameFoot = strFoot.arg( QString::number( nIndex ), bInner ? "Inner" : "Outer" ); pSB = pGB->findChild< QSpinBox* >( strNameFoot ); pSB->setEnabled( bEnabled ); if ( !bEnabled ) { pSB->setValue( 0 ); } if ( nItems > nIndex ) { strNameRule = strRule.arg( QString::number( nIndex + 1 ), bInner ? "Inner" : "Outer" ); pSB = pGB->findChild< QSpinBox* >( strNameRule ); pSB->setEnabled( bEnabled ); if ( !bEnabled ) { pSB->setValue( 0 ); } } }
QWidget* createWidgets(BasePropertyWidget* parent) { m_spinBox = new QSpinBox(parent); m_spinBox->setMinimum(INT_MIN); m_spinBox->setMaximum(INT_MAX); m_spinBox->setSingleStep(1); m_spinBox->setEnabled(!parent->readOnly()); void(QSpinBox::*valueChanged)(int) = &QSpinBox::valueChanged; // Get the right overload QObject::connect(m_spinBox, valueChanged, parent, &BasePropertyWidget::setWidgetDirty); return m_spinBox; }
void CTariffSetting::ControlPerMinUI( bool bInner, bool bEnabled ) { QString strPerOuter = "perMinFoot%1"; QGroupBox* pGB = bInner ? ui->gbInner : ui->gbOuter; QSpinBox* pSB = pGB->findChild< QSpinBox* >( strPerOuter.arg( bInner ? "Inner" : "Outer" ) ); pSB->setEnabled( bEnabled ); if( !bEnabled ) { pSB->setValue( 0 ); } }
void AlignsPropertyGridWidget::UpdateSpinBoxState(QCheckBox *buddyWidget) { WidgetSignalsBlocker blocker(buddyWidget); // Get current state of checkbox bool state = buddyWidget->isChecked(); // Update appropriate spinbox state ALIGNWIDGETSMAPITER iter = this->alignWidgetsMap.find(buddyWidget); if (iter != this->alignWidgetsMap.end()) { QSpinBox *spinBox = iter->second; // Change spinbox state according to checkbox state spinBox->setEnabled(state); } }
// Create new integer spin widget QtWidgetObject* AtenTreeGuiDialog::addIntegerSpin(TreeGuiWidget* widget, QString label, int step) { QtWidgetObject* qtwo = widgetObjects_.add(); QSpinBox *spin = new QSpinBox(this); qtwo->set(widget, spin, label); spin->setRange(widget->minimumI(), widget->maximumI()); spin->setValue(widget->valueI()); spin->setSingleStep(step); spin->setEnabled(widget->enabled()); spin->setVisible(widget->visible()); spin->setMinimumHeight(WIDGETHEIGHT); spin->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); // Connect signal to master slot QObject::connect(spin, SIGNAL(valueChanged(int)), this, SLOT(integerSpinWidget_valueChanged(int))); return qtwo; }
void Joysticks::setupIndicators (int row) { /* Remove all joystick indicators in the widget */ foreach (QSpinBox * b, findChildren<QSpinBox*>()) delete b; foreach (QPushButton * c, findChildren<QPushButton*>()) delete c; foreach (QProgressBar * p, findChildren<QProgressBar*>()) delete p; /* Clear joystick data */ m_axes.clear(); m_povs.clear(); m_buttons.clear(); /* Avoid crashing the application when there are no joysticks */ if (row < 0) return; /* Get joystick information */ int povCount = JOYSTICK_MANAGER()->getInputDevice (row).numPOVs; int axisCount = JOYSTICK_MANAGER()->getInputDevice (row).numAxes; int buttonCount = JOYSTICK_MANAGER()->getInputDevice (row).numButtons; /* Make the indicator containers visible */ m_POVIndicators->setVisible (povCount > 0); m_axisIndicators->setVisible (axisCount > 0); m_buttonIndicators->setVisible (buttonCount > 0); /* Create a progress bar for each axis */ for (int i = 0; i < axisCount; ++i) { QProgressBar* bar = new QProgressBar (this); bar->setFixedHeight (DPI_SCALE (19)); bar->setValue (0); bar->setMaximum (100); bar->setMinimum (-100); bar->setFormat (tr ("Axis %1").arg (i)); m_axes.append (bar); m_axesBox->addWidget (bar); } /* Create a button for each joystick button */ for (int i = 0; i < buttonCount; ++i) { QPushButton* button = new QPushButton (this); button->setEnabled (false); button->setCheckable (true); button->setFixedSize (DPI_SCALE (18), DPI_SCALE (12)); button->setToolTip (tr ("Button %1").arg (i)); /* Distribute the button items in a nice layout */ int row = (i <= 7) ? i : i - 8; int column = (i <= 7) ? 0 : (i / 8); m_buttons.append (button); m_buttonsBox->addWidget (button, row, column); } /* Create a spinbox for each joystick hat */ for (int i = 0; i < povCount; ++i) { QSpinBox* box = new QSpinBox (this); box->setRange (0, 360); box->setEnabled (false); m_povs.append (box); m_povsBox->addWidget (box); } }
QFrame *AbstractController::telexFrame() { /** * Telextext QFrame **/ QFrame *telexFrame = new QFrame( this ); QHBoxLayout *telexLayout = new QHBoxLayout( telexFrame ); telexLayout->setSpacing( 0 ); telexLayout->setMargin( 0 ); CONNECT( THEMIM->getIM(), teletextPossible( bool ), telexFrame, setVisible( bool ) ); /* On/Off button */ QToolButton *telexOn = new QToolButton; setupButton( telexOn ); BUTTON_SET_BAR2( telexOn, toolbar/tv, qtr( "Teletext Activation" ) ); telexOn->setEnabled( false ); telexOn->setCheckable( true ); telexLayout->addWidget( telexOn ); /* Teletext Activation and set */ CONNECT( telexOn, clicked( bool ), THEMIM->getIM(), activateTeletext( bool ) ); CONNECT( THEMIM->getIM(), teletextPossible( bool ), telexOn, setEnabled( bool ) ); /* Transparency button */ QToolButton *telexTransparent = new QToolButton; setupButton( telexTransparent ); BUTTON_SET_BAR2( telexTransparent, toolbar/tvtelx, qtr( "Toggle Transparency " ) ); telexTransparent->setEnabled( false ); telexTransparent->setCheckable( true ); telexLayout->addWidget( telexTransparent ); /* Transparency change and set */ CONNECT( telexTransparent, clicked( bool ), THEMIM->getIM(), telexSetTransparency( bool ) ); CONNECT( THEMIM->getIM(), teletextTransparencyActivated( bool ), telexTransparent, setChecked( bool ) ); /* Page setting */ QSpinBox *telexPage = new QSpinBox( telexFrame ); telexPage->setRange( 100, 899 ); telexPage->setValue( 100 ); telexPage->setAccelerated( true ); telexPage->setWrapping( true ); telexPage->setAlignment( Qt::AlignRight ); telexPage->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum ); telexPage->setEnabled( false ); telexLayout->addWidget( telexPage ); /* Contextual & Index Buttons */ QSignalMapper *contextButtonMapper = new QSignalMapper( this ); QToolButton *contextButton = NULL; int i_iconminsize = __MAX( 16, telexOn->minimumHeight() ); QPixmap iconPixmap( i_iconminsize, i_iconminsize ); iconPixmap.fill( Qt::transparent ); QPainter iconPixmapPainter( &iconPixmap ); QLinearGradient iconPixmapPainterGradient( iconPixmap.rect().center() / 2, iconPixmap.rect().center() ); #define CREATE_CONTEXT_BUTTON(color, key) \ iconPixmapPainterGradient.setColorAt( 0, QColor( color ).lighter(150) );\ iconPixmapPainterGradient.setColorAt( 1.0, QColor( color ) );\ iconPixmapPainter.setBrush( iconPixmapPainterGradient );\ iconPixmapPainter.drawEllipse( iconPixmap.rect().adjusted( 4, 4, -5, -5 ) );\ contextButton = new QToolButton();\ setupButton( contextButton );\ contextButton->setIcon( iconPixmap );\ contextButton->setEnabled( false );\ contextButtonMapper->setMapping( contextButton, key << 16 );\ CONNECT( contextButton, clicked(), contextButtonMapper, map() );\ CONNECT( contextButtonMapper, mapped( int ),\ THEMIM->getIM(), telexSetPage( int ) );\ CONNECT( THEMIM->getIM(), teletextActivated( bool ), contextButton, setEnabled( bool ) );\ telexLayout->addWidget( contextButton ) CREATE_CONTEXT_BUTTON("grey", 'i'); /* index */ CREATE_CONTEXT_BUTTON("red", 'r'); CREATE_CONTEXT_BUTTON("green", 'g'); CREATE_CONTEXT_BUTTON("yellow", 'y'); CREATE_CONTEXT_BUTTON("blue", 'b'); #undef CREATE_CONTEXT_BUTTON /* Page change and set */ CONNECT( telexPage, valueChanged( int ), THEMIM->getIM(), telexSetPage( int ) ); CONNECT( THEMIM->getIM(), newTelexPageSet( int ), telexPage, setValue( int ) ); CONNECT( THEMIM->getIM(), teletextActivated( bool ), telexPage, setEnabled( bool ) ); CONNECT( THEMIM->getIM(), teletextActivated( bool ), telexTransparent, setEnabled( bool ) ); CONNECT( THEMIM->getIM(), teletextActivated( bool ), telexOn, setChecked( bool ) ); return telexFrame; }
QFrame *AbstractController::telexFrame() { /** * Telextext QFrame **/ QFrame *telexFrame = new QFrame( this ); QHBoxLayout *telexLayout = new QHBoxLayout( telexFrame ); telexLayout->setSpacing( 0 ); telexLayout->setMargin( 0 ); CONNECT( THEMIM->getIM(), teletextPossible( bool ), telexFrame, setVisible( bool ) ); /* On/Off button */ QToolButton *telexOn = new QToolButton; setupButton( telexOn ); BUTTON_SET_BAR2( telexOn, toolbar/tv, qtr( "Teletext Activation" ) ); telexOn->setEnabled( false ); telexOn->setCheckable( true ); telexLayout->addWidget( telexOn ); /* Teletext Activation and set */ CONNECT( telexOn, clicked( bool ), THEMIM->getIM(), activateTeletext( bool ) ); CONNECT( THEMIM->getIM(), teletextPossible( bool ), telexOn, setEnabled( bool ) ); /* Transparency button */ QToolButton *telexTransparent = new QToolButton; setupButton( telexTransparent ); BUTTON_SET_BAR2( telexTransparent, toolbar/tvtelx, qtr( "Toggle Transparency " ) ); telexTransparent->setEnabled( false ); telexTransparent->setCheckable( true ); telexLayout->addWidget( telexTransparent ); /* Transparency change and set */ CONNECT( telexTransparent, clicked( bool ), THEMIM->getIM(), telexSetTransparency( bool ) ); CONNECT( THEMIM->getIM(), teletextTransparencyActivated( bool ), telexTransparent, setChecked( bool ) ); /* Page setting */ QSpinBox *telexPage = new QSpinBox( telexFrame ); telexPage->setRange( 0, 999 ); telexPage->setValue( 100 ); telexPage->setAccelerated( true ); telexPage->setWrapping( true ); telexPage->setAlignment( Qt::AlignRight ); telexPage->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum ); telexPage->setEnabled( false ); telexLayout->addWidget( telexPage ); /* Page change and set */ CONNECT( telexPage, valueChanged( int ), THEMIM->getIM(), telexSetPage( int ) ); CONNECT( THEMIM->getIM(), newTelexPageSet( int ), telexPage, setValue( int ) ); CONNECT( THEMIM->getIM(), teletextActivated( bool ), telexPage, setEnabled( bool ) ); CONNECT( THEMIM->getIM(), teletextActivated( bool ), telexTransparent, setEnabled( bool ) ); CONNECT( THEMIM->getIM(), teletextActivated( bool ), telexOn, setChecked( bool ) ); return telexFrame; }
void WidgetIOProperties::createIOProperties() { ui->mainLayout->setColumnMinimumWidth(0, 150); ui->optionLayout->setColumnMinimumWidth(0, 150); QString lang = Utils::GetLocale(); QString rsc = QString(":/doc/%1/io_doc.json").arg(lang); QFile f(rsc); if (!f.open(QIODevice::ReadOnly | QIODevice::Text)) { QMessageBox::warning(this, tr("Error"), tr("Failed to load IO documentation from %1").arg(rsc)); return; } QJsonParseError jerr; QJsonDocument jdoc = QJsonDocument::fromJson(f.readAll(), &jerr); if (jerr.error != QJsonParseError::NoError || !jdoc.isObject()) { QMessageBox::warning(this, tr("Error"), tr("Failed to parse JSON IO documentation from %1").arg(rsc)); return; } QString iotype = QString::fromUtf8(params["type"].c_str()); QJsonObject jobj = jdoc.object(); for (auto it = jobj.begin();it != jobj.end();it++) jobj.insert(it.key().toLower(), it.value()); QJsonObject jobjAlias; if (!jobj.contains(iotype)) { //Search in aliases bool aliasfound = false; for (auto it = jobj.constBegin();it != jobj.constEnd();it++) { QJsonObject o = it.value().toObject(); QJsonArray jalias = o["alias"].toArray(); for (int i = 0;i < jalias.size();i++) { if (jalias.at(i).toString() == iotype) { aliasfound = true; jobjAlias = o; } } } if (!aliasfound) { QMessageBox::warning(this, tr("Error"), tr("IO type %1 is not found in %2").arg(iotype).arg(rsc)); return; } } QJsonObject jioobj; if (jobjAlias.isEmpty()) jioobj = jobj[iotype].toObject(); else jioobj = jobjAlias; ui->labelTitle->setText(iotype); ui->labelDesc->setText(jioobj["description"].toString()); int rowMain = 0, rowOption = 0; QJsonArray jparams = jioobj["parameters"].toArray(); for (int i = 0;i < jparams.size();i++) { QJsonObject jparam = jparams[i].toObject(); QGridLayout *layout = jparam["mandatory"].toString() == "true"?ui->mainLayout:ui->optionLayout; int row = jparam["mandatory"].toBool()?rowMain:rowOption; QLabel *title = new QLabel(jparam["name"].toString()); layout->addWidget(title, row, 0); QPushButton *revert = new QPushButton(); revert->setIcon(QIcon(":/img/document-revert.png")); revert->setToolTip(tr("Revert modification")); layout->addWidget(revert, row, 1); hider.hide(revert); QString pvalue; string prop = jparam["name"].toString().toUtf8().constData(); if (params.Exists(prop)) pvalue = QString::fromUtf8(params[prop].c_str()); else pvalue = jparam["default"].toString(); if (jparam["type"].toString() == "string") { QLineEdit *w = new QLineEdit(); w->setEnabled(jparam["readonly"].toString() != "true" && editable); w->setText(pvalue); layout->addWidget(w, row, 2); UiObject uiObject; uiObject.type = UiObjectType::LineEdit; uiObject.lineEdit = w; uiObjectMap[prop] = uiObject; connect(w, &QLineEdit::textChanged, [=]() { updateChangedParam(prop, w->text(), pvalue, title, revert); }); connect(revert, &QPushButton::clicked, [=]() { w->setText(pvalue); }); } else if (jparam["type"].toString() == "bool") { QCheckBox *w = new QCheckBox(); w->setEnabled(jparam["readonly"].toString() != "true" && editable); w->setChecked(pvalue == "true"); layout->addWidget(w, row, 2); UiObject uiObject; uiObject.type = UiObjectType::CheckBox; uiObject.checkBox = w; uiObjectMap[prop] = uiObject; connect(w, &QCheckBox::stateChanged, [=]() { updateChangedParam(prop, w->isChecked()?"true":"false", pvalue, title, revert); }); connect(revert, &QPushButton::clicked, [=]() { w->setChecked(pvalue == "true"); }); } else if (jparam["type"].toString() == "int") { QSpinBox *w = new QSpinBox(); w->setEnabled(jparam["readonly"].toString() != "true" && editable); if (!jparam["min"].toString().isEmpty()) w->setMinimum(jparam["min"].toString().toInt()); else w->setMinimum(-999999999); if (!jparam["max"].toString().isEmpty()) w->setMaximum(jparam["max"].toString().toInt()); else w->setMaximum(999999999); w->setValue(pvalue.toInt()); layout->addWidget(w, row, 2); UiObject uiObject; uiObject.type = UiObjectType::SpinBox; uiObject.spinBox = w; uiObjectMap[prop] = uiObject; connect(w, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), [=]() { updateChangedParam(prop, QString("%1").arg(w->value()), pvalue.isEmpty()?"0":pvalue, title, revert); }); connect(revert, &QPushButton::clicked, [=]() { w->setValue(pvalue.toInt()); }); } else if (jparam["type"].toString() == "float") { QDoubleSpinBox *w = new QDoubleSpinBox(); w->setEnabled(jparam["readonly"].toString() != "true" && editable); if (!jparam["min"].toString().isEmpty()) w->setMinimum(jparam["min"].toString().toDouble()); else w->setMinimum(-999999999.0); if (!jparam["max"].toString().isEmpty()) w->setMaximum(jparam["max"].toString().toDouble()); else w->setMaximum(999999999.0); w->setValue(pvalue.toDouble()); layout->addWidget(w, row, 2); w->setDecimals(3); UiObject uiObject; uiObject.type = UiObjectType::DoubleSpinBox; uiObject.doubleSpinBox = w; uiObjectMap[prop] = uiObject; connect(w, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), [=]() { updateChangedParam(prop, QString("%1").arg(w->value()), pvalue.isEmpty()?"0":pvalue, title, revert); }); connect(revert, &QPushButton::clicked, [=]() { w->setValue(pvalue.toDouble()); }); } else if (jparam["type"].toString() == "list") { QComboBox *w = new QComboBox(); int defIndex = 0; w->setEnabled(jparam["readonly"].toString() != "true" && editable); //fill combobox with values, if no value, set editable to true QJsonObject jvalues = jparam["list_value"].toObject(); if (jvalues.empty()) w->setEditable(true); else { w->setEditable(false); for (auto it = jvalues.begin();it != jvalues.end();it++) { w->addItem(it.value().toString(), it.key()); if (it.key() == pvalue) { defIndex = w->count() - 1; w->setCurrentIndex(defIndex); } } } layout->addWidget(w, row, 2); UiObject uiObject; uiObject.type = UiObjectType::ComboBox; uiObject.comboBox = w; uiObjectMap[prop] = uiObject; if (w->isEditable()) { connect(w, &QComboBox::currentTextChanged, [=]() { updateChangedParam(prop, w->currentText(), pvalue, title, revert); }); } else { connect(w, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), [=]() { updateChangedParam(prop, w->currentData().toString(), pvalue, title, revert); }); } connect(revert, &QPushButton::clicked, [=]() { if (w->isEditable()) w->setEditText(pvalue); else w->setCurrentIndex(defIndex); }); } QPushButton *help = new QPushButton(); help->setIcon(QIcon(":/img/icon_unkown.png")); help->setFlat(true); layout->addWidget(help, row, 3); if((i==0)&&(entryHelper != nullptr)) { QPushButton *entryHelperButton = new QPushButton(); entryHelperButton->setIcon(QIcon(":/img/icon_entry_helper.png")); entryHelperButton->setFlat(true); layout->addWidget(entryHelperButton, row, 4); connect(entryHelperButton, &QPushButton::clicked, [=]() { if (entryHelper->exec() == QDialog::Accepted) setValues(entryHelper->getParams()); }); } //avoid copy the QJsonObject in the lambda QString helpInfo = jparam["description"].toString(); connect(help, &QPushButton::clicked, [=]() { if (balloonTip) delete balloonTip; balloonTip = new BalloonTip(QPixmap(":/img/icon_unkown.png"), title->text(), helpInfo, 800, help); balloonTip->setArrowPosition(BalloonTip::TopLeft); balloonTip->move(QCursor::pos()); balloonTip->show(); }); if (jparam["mandatory"].toBool()) rowMain++; else rowOption++; } }