void NineSliceRecipe::selectedRecipeChanged(int selected) { RadioGroup* myRadioGroup = dynamic_cast<RadioGroup*>(sender()); QString selectedName = myRadioGroup->at(selected)->objectName(); if (mRecipeText2) { // Change the text in TextArea depending on which option was selected. if (selectedName.compare("fast") == 0) { mRecipeText->setText("1. Pour Mix.\n2. Add Water.\n3. Stir and heat."); mRecipeText2->setText(""); } else { mRecipeText->setText( "1. Grind tomatoes.\n2. Fry minced meat.\n3. Add lasagna plates."); mRecipeText2->setText( "4. Grind Cheese.\n 5. Season with salt.\n6. Voila! Its ready!"); } } else { // Change the text in TextArea depending on which option was selected. if (selectedName.compare("fast") == 0) { mRecipeText->setText("1. Pour Mix.\n2. Add Water.\n3. Stir and heat."); } else { mRecipeText->setText( "1. Grind tomatoes.\n2. Fry minced meat.\n3. Add lasagna plates.\n4. Grind Cheese.\n5. Season with salt."); } } }
// To show how a nine-sliced image is scaled, we provide the possibility to // alter the text between two different lengths. This will cause the text // area to change size and consequently the image to change size. Container *NineSliceRecipe::createControlPanel() { bool connectResult; Q_UNUSED(connectResult); Container *controlPanel = Container::create(); controlPanel->setVerticalAlignment(VerticalAlignment::Bottom); RadioGroup *ninesliceOptions = new RadioGroup(); Option *fastRecipe = new Option(); fastRecipe->setText("Five Minutes"); fastRecipe->setObjectName("fast"); Option *slowRecipe = new Option(); slowRecipe->setText("Two Hours"); slowRecipe->setObjectName("slow"); ninesliceOptions->add(fastRecipe); ninesliceOptions->add(slowRecipe); connectResult = connect(ninesliceOptions, SIGNAL(selectedIndexChanged(int)), this, SLOT(selectedRecipeChanged(int))); Q_ASSERT(connectResult); ninesliceOptions->setSelectedIndex(1); controlPanel->add(new Divider()); controlPanel->add(ninesliceOptions); return controlPanel; }
void ItemHandlerRadio::Handle (const QDomElement& item, QWidget *pwidget) { QGridLayout *lay = qobject_cast<QGridLayout*> (pwidget->layout ()); RadioGroup *group = new RadioGroup (XSD_); group->setObjectName (item.attribute ("property")); QDomElement option = item.firstChildElement ("option"); while (!option.isNull ()) { QRadioButton *button = new QRadioButton (XSD_->GetLabel (option)); button->setObjectName (option.attribute ("name")); group->AddButton (button, option.hasAttribute ("default") && option.attribute ("default") == "true"); option = option.nextSiblingElement ("option"); } QVariant value = XSD_->GetValue (item); connect (group, SIGNAL (valueChanged ()), this, SLOT (updatePreferences ())); QGroupBox *box = new QGroupBox (XSD_->GetLabel (item)); QVBoxLayout *layout = new QVBoxLayout (); box->setLayout (layout); layout->addWidget (group); group->setProperty ("ItemHandler", QVariant::fromValue<QObject*> (this)); lay->addWidget (box, lay->rowCount (), 0); }
void ApplicationSettingsDelegate::setNodeData( QWidget* editor, SettingsNode& node ) const { if ( node.guiType() < int( QVariant::UserType ) ) { SettingsNodeDialogBuilderDelegate::setNodeData( editor, node ); return; } switch ( node.guiType() ) { case ApplicationSettingsDelegate::Eol: case ApplicationSettingsDelegate::Indent: case ApplicationSettingsDelegate::Ruler: case ApplicationSettingsDelegate::Wrap: { RadioGroup* rg = qobject_cast<RadioGroup*>( editor ); Q_ASSERT( rg ); node.setValue( rg->checkedId() ); break; } case ApplicationSettingsDelegate::CodeEditorAbstractor: { AbstractorComboBox* acb = qobject_cast<AbstractorComboBox*>( editor ); Q_ASSERT( acb ); node.setValue( acb->itemData( acb->currentIndex() ) ); break; } default: qWarning() << Q_FUNC_INFO << "Unhandled type" << node.name() << node.value() << node.guiType() << QVariant::typeToName( QVariant::Type( node.guiType() ) ); break; } }
void ApplicationSettingsDelegate::setEditorData( QWidget* editor, const SettingsNode& node ) const { if ( node.guiType() < int( QVariant::UserType ) ) { SettingsNodeDialogBuilderDelegate::setEditorData( editor, node ); return; } const QVariant value = node.value(); editor->setToolTip( node.help() ); switch ( node.guiType() ) { case ApplicationSettingsDelegate::Eol: case ApplicationSettingsDelegate::Indent: case ApplicationSettingsDelegate::Ruler: case ApplicationSettingsDelegate::Wrap: { RadioGroup* rg = qobject_cast<RadioGroup*>( editor ); Q_ASSERT( rg ); rg->setCheckedId( value.toInt() ); break; } case ApplicationSettingsDelegate::CodeEditorAbstractor: { AbstractorComboBox* acb = qobject_cast<AbstractorComboBox*>( editor ); Q_ASSERT( acb ); acb->setCurrentIndex( acb->findData( value.toString() ) ); break; } default: qWarning() << Q_FUNC_INFO << "Unhandled type" << node.name() << node.value() << node.guiType() << QVariant::typeToName( QVariant::Type( node.guiType() ) ); break; } }
void SelectionRecipe::fillingSelectedOptionChanged(int selected) { RadioGroup *radioGroup = dynamic_cast<RadioGroup*>(sender()); if(radioGroup != 0) { // When a new option is selected we print the selection to the console. Option *option = radioGroup->at(selected); qDebug() << "New filling set: " << option->text(); } }
void ItemHandlerRadio::SetValue (QWidget *widget, const QVariant& value) const { RadioGroup *radiogroup = qobject_cast<RadioGroup*> (widget); if (!radiogroup) { qWarning () << Q_FUNC_INFO << "not a RadioGroup" << widget; return; } radiogroup->SetValue (value.toString ()); }
QVariant ItemHandlerRadio::GetObjectValue (QObject *object) const { RadioGroup *radiogroup = qobject_cast<RadioGroup*> (object); if (!radiogroup) { qWarning () << Q_FUNC_INFO << "not a RadioGroup" << object; return QVariant (); } return radiogroup->GetValue (); }
SelectionRecipe::SelectionRecipe(Container * parent) : CustomControl(parent) { Container *recipeContainer = new Container(); StackLayout *recipeLayout = new StackLayout(); recipeLayout->setLeftPadding(80); recipeLayout->setRightPadding(80); recipeContainer->setLayout(recipeLayout); Container *checkBoxContainer = new Container(); Label *typeLabel = new Label(); typeLabel->setText("Olive Type"); typeLabel->textStyle()->setBase(SystemDefaults::TextStyles::titleText()); typeLabel->textStyle()->setFontWeight(FontWeight::Bold); typeLabel->setBottomMargin(0); checkBoxContainer->add(typeLabel); // Since we want the CheckBox Control to also have a colored box to represent the // selection of which olives should be in the mix a CustomControl is used, see SelectionCheckBox.cpp. SelectionCheckBox *limonCello = new SelectionCheckBox(); limonCello->setOliveColor(QVariant::fromValue<Color>(Color::fromARGB(0xff808000))); limonCello->setTitle("Limoncello"); limonCello->setLayoutProperties( StackLayoutProperties::create().horizontal(HorizontalAlignment::Fill)); SelectionCheckBox *greek = new SelectionCheckBox(); greek->setOliveColor(QVariant::fromValue<Color>(Color::fromARGB(0xff698B22))); greek->setTitle("Greek"); SelectionCheckBox *kalamata = new SelectionCheckBox(); kalamata->setOliveColor(QVariant::fromValue<Color>(Color::fromARGB(0xff733D1A))); kalamata->setTitle("Kalamata"); checkBoxContainer->add(limonCello); checkBoxContainer->add(greek); checkBoxContainer->add(kalamata); // The two menu selections are separated by a Divider. Divider *divider = new Divider(); divider->setBottomMargin(60); Label *fillingLabel = new Label(); fillingLabel->setText("Filling"); fillingLabel->textStyle()->setBase(SystemDefaults::TextStyles::titleText()); fillingLabel->textStyle()->setFontWeight(FontWeight::Bold); fillingLabel->setBottomMargin(9); // The RadioGroup is a Control that one use if only one option can // be selected at the time. RadioGroupOptions are added to the Control // and by listening for the onSelectedOptionChanged signal its possible // to keep track of what the current selection is. RadioGroup *radioGroup = new RadioGroup(); radioGroup->setDividersVisible(false); Option *stoneOption = new Option(); stoneOption->setText("Stone"); Option *pimentoOption = new Option(); pimentoOption->setText("Pimento"); radioGroup->add(stoneOption); radioGroup->add(pimentoOption); // We listen for changes in selected options on the RadioGroup. connect(radioGroup, SIGNAL(selectedIndexChanged(int)), this, SLOT(fillingSelectedOptionChanged(int))); // Add the controls. recipeContainer->add(checkBoxContainer); recipeContainer->add(divider); recipeContainer->add(fillingLabel); recipeContainer->add(radioGroup); setRoot(recipeContainer); }