void WebViewRecipe::onMaxContentScaleChanged(float maxContentScale)
{
    ScrollViewProperties* scrollViewProp = mScrollView->scrollViewProperties();

    // Update the scroll view properties to match the content scale
    // given by the WebView.
    scrollViewProp->setMaxContentScale(maxContentScale);
}
SegmentedControlRecipe::SegmentedControlRecipe(Container *parent) :
		CustomControl(parent) {

	// A recipe showing how to listen to changes in SegmentedControl
	// and use this to change the look of the interface.

	ScrollView *scrollView = new ScrollView();
	ScrollViewProperties* scrollViewProp = scrollView->scrollViewProperties();
	scrollViewProp->setScrollMode(ScrollMode::Vertical);

	Container *recipeContainer = Container::create().left(20.0).right(20.0).bottom(20);
	recipeContainer->setHorizontalAlignment(HorizontalAlignment::Center);
	recipeContainer->setVerticalAlignment(VerticalAlignment::Top);

	StackLayout *recipeLayout = new StackLayout();
	recipeContainer->setLayout(recipeLayout);

	// This labels text is altered when the segmentedControl value is changed.
	mTitleLabel = new Label();
	mTitleLabel->setText("Potato Leek Soup");
	mTitleLabel->textStyle()->setBase(SystemDefaults::TextStyles::bigText());

	// This ImageView's imageSource is altered when the segmentedControl value is changed.
	mImage = ImageView::create("asset:///images/segmentedcontrol/soup_green.png");

	Label *ingredientsTitleLabel = new Label();
	ingredientsTitleLabel->setMultiline(true);
	ingredientsTitleLabel->textStyle()->setBase(SystemDefaults::TextStyles::titleText());
	ingredientsTitleLabel->setText("Ingredients");

	// The segmented control is implemented and given three values and text
	// to represent those values.
	SegmentedControl *segmented = SegmentedControl::create().add(
			bb::cascades::Option::create().text("Leek").value("1").selected(
					true)).add(
			bb::cascades::Option::create().text("Beetroot").value("2")).add(
			bb::cascades::Option::create().text("Garlic").value("3"));

	connect(segmented, SIGNAL(selectedIndexChanged(int)), this, SLOT(onSegmentedIndexChanged(int)));

	Label *ingredientsLabel = new Label();
	ingredientsLabel->setMultiline(true);
	ingredientsTitleLabel->textStyle()->setBase(SystemDefaults::TextStyles::bodyText());
	ingredientsLabel->setText("3 cups chicken broth \n2-3 chopped potatoes \nSalt & Pepper");

	// Add the controls to the recipe Container and scrollView and set it as the root component.
	scrollView->setContent(recipeContainer);
	recipeContainer->add(mTitleLabel);
	recipeContainer->add(mImage);
	recipeContainer->add(ingredientsTitleLabel);
	recipeContainer->add(segmented);
	recipeContainer->add(ingredientsLabel);

	setRoot(scrollView);
}
void WebViewRecipe::onMinContentScaleChanged(float minContentScale)
{
    ScrollViewProperties* scrollViewProp = mScrollView->scrollViewProperties();

    // Update the scroll view properties to match the content scale
    // given by the WebView.
    scrollViewProp->setMinContentScale(minContentScale);

    // Let's show the entire page to start with.
    mScrollView->zoomToPoint(0, 0, minContentScale, ScrollAnimation::None);
}
DateTimePickerRecipe::DateTimePickerRecipe(Container *parent) :
CustomControl(parent)
{
    // The recipe Container.
    ScrollView *scrollView = new ScrollView();
    ScrollViewProperties* scrollViewProp = scrollView->scrollViewProperties();
    scrollViewProp->setScrollMode(ScrollMode::Vertical);

    Container *recipeContainer = new Container();
    recipeContainer->setLayout(StackLayout::create().top(50.0f));
    recipeContainer->setMinHeight(1024.0f);

    // The recipe title, we add it to a Container in order to get some padding around it.
    Container *titleContainer = new Container();
    titleContainer->setLayout(StackLayout::create().left(20.0f).bottom(20.0f));
    QDateTime date = QDateTime::currentDateTime();
    Label *title = new Label(titleContainer);
    title->setText("Today is: " + date.toString("M/d/yy"));
    title->textStyle()->setBase(SystemDefaults::TextStyles::bodyText());

    // This is where we create the DateTimePicker, we set the mode so that we 
    // can change the date and update the state of the fruit depending on that.
    DateTimePicker *datePicker = new DateTimePicker();
    datePicker->setTitle("Banana at date:");
    datePicker->setMode(DateTimePickerMode::Date);
    datePicker->setLayoutProperties(StackLayoutProperties::create().horizontal(HorizontalAlignment::Center));
    connect(datePicker, SIGNAL(valueChanged(QDateTime )), this, SLOT(onValueChanged(QDateTime )));

    // An image of a fruit is used to show how one can use the QDateTime value 
    // reported by the picker.
    mTimeWarpFruit = ImageView::create("asset:///images/picker/banana_new.png");
    mTimeWarpFruit ->setTopMargin(20.0f);


    recipeContainer->add(titleContainer);
    recipeContainer->add(datePicker);
    recipeContainer->add(mTimeWarpFruit);

    // Add the scrollable content to the ScrollView.
    scrollView->setContent(recipeContainer);

    setRoot(scrollView);
}
ColorRecipe::ColorRecipe(Container *parent) :
        CustomControl(parent)
{
    // Get the application padding values.
    int tinyPadding = UiValues::instance()->intValue(UiValues::UI_PADDING_TINY);
    int standardPadding = UiValues::instance()->intValue(UiValues::UI_PADDING_STANDARD);

    ScrollView *scrollView = new ScrollView();
    ScrollViewProperties* scrollViewProp = scrollView->scrollViewProperties();
    scrollViewProp->setScrollMode(ScrollMode::Vertical);

    // Create a Container that stacks our Labels and Containers from top to bottom.
    Container *recipeContainer = Container::create()
                .left(standardPadding).right(standardPadding)
                .top(standardPadding).bottom(standardPadding);

    Container *functionalContainer = Container::create();
    functionalContainer->setHorizontalAlignment(HorizontalAlignment::Fill);
    functionalContainer->setLayout(new DockLayout());

    // Header for functional colors
    Label *functionalLabel = new Label();
    functionalLabel->setText("Functional");
    functionalLabel->textStyle()->setBase(SystemDefaults::TextStyles::bigText());

    // Header for brand colors
    Label *brandLabel = new Label();
    brandLabel->setText("Brand");
    brandLabel->textStyle()->setBase(SystemDefaults::TextStyles::bigText());

    // Header for application colors
    Label *applicationLabel = new Label();
    applicationLabel->setText("Application");
    applicationLabel->textStyle()->setBase(SystemDefaults::TextStyles::bigText());

    // Header for background colors
    Label *backgroundLabel = new Label();
    backgroundLabel->setText("Background");
    backgroundLabel->textStyle()->setBase(SystemDefaults::TextStyles::bigText());

    scrollView->setContent(recipeContainer);
    recipeContainer->add(functionalLabel);

    // Call the createLabel function and the createIcon function with all our different colors and add them to the recipe.

    // Functional colors.
    recipeContainer->add(functionalContainer);
    functionalContainer->add(createIcon(Color(Color::fromARGB(0xff00B800)), "#00B800",
                    "asset:///images/color/icon_outgoing.png", HorizontalAlignment::Left));
    functionalContainer->add(createIcon(Color(Color::fromARGB(0xffE6B400)), "#E6B400",
                    "asset:///images/color/icon_waiting.png", HorizontalAlignment::Center));
    functionalContainer->add(createIcon(Color(Color::fromARGB(0xffD60000)), "#D60000",
                    "asset:///images/color/icon_missed.png", HorizontalAlignment::Right));

    // Brand colors.
    recipeContainer->add(brandLabel);
    recipeContainer->add(createLabel(Color(Color::fromARGB(0xff0073BC)), "#0073BC"));
    recipeContainer->add(createLabel(Color(Color::fromARGB(0xff00A8DF)), "#00A8DF"));

    // Application colors.
    recipeContainer->add(applicationLabel);
    recipeContainer->add(createLabel(Color(Color::fromARGB(0xff96B800)), "#96B800"));
    recipeContainer->add(createLabel(Color(Color::fromARGB(0xffCC3F10)), "#CC3F10"));
    recipeContainer->add(createLabel(Color(Color::fromARGB(0xff0098F0)), "#0098F0"));
    recipeContainer->add(createLabel(Color(Color::fromARGB(0xffA30D7E)), "#A30D7E"));
    recipeContainer->add(createLabel(Color(Color::fromARGB(0xff667B94)), "#667B94"));

    // Background colors.
    recipeContainer->add(backgroundLabel);
    recipeContainer->add(createLabel(Color(Color::fromARGB(0xff121212)), "#121212"));

    // The white background example is put in a container with a gray background so it will be visible.
    Container *whiteBackgroundContainer = Container::create().topMargin(tinyPadding).left(
            tinyPadding).right(tinyPadding).bottom(tinyPadding);
    whiteBackgroundContainer->setBackground(Color::fromARGB(0xff667B94));

    recipeContainer->add(whiteBackgroundContainer);
    whiteBackgroundContainer->add(createLabel(Color(Color::fromARGB(0xffF8F8F8)), "#F8F8F8"));
    recipeContainer->add(createLabel(Color(Color::fromARGB(0xff262626)), "#262626"));

    setRoot(scrollView);
}
InputRecipe::InputRecipe(Container *parent) :
        CustomControl(parent)
{
    bool connectResult;
    Q_UNUSED(connectResult);

    ScrollView *scrollView = new ScrollView();
    ScrollViewProperties* scrollViewProp = scrollView->scrollViewProperties();
    scrollViewProp->setScrollMode(ScrollMode::Vertical);

    Container *recipeContainer = Container::create().left(80).right(80);

    // Label used to display the entered text
    mInputLabel = new Label();
    mInputLabel->setMultiline(true);
    mInputLabel->setText((const QString) " ");
    mInputLabel->setHorizontalAlignment(HorizontalAlignment::Fill);
    mInputLabel->setBottomMargin(50.0);
    mInputLabel->textStyle()->setBase(SystemDefaults::TextStyles::bodyText());

    // A multi line text input
    TextArea *textArea = new TextArea();
    textArea->setHintText("Enter text into multi-line TextArea");
    textArea->setPreferredHeight(140);
    textArea->setBottomMargin(50.0);
    textArea->textStyle()->setBase(SystemDefaults::TextStyles::bodyText());
    textArea->setHorizontalAlignment(HorizontalAlignment::Fill);

    // Connect the TextArea textChanging signal to the onTextChanging function to update the text.
    connectResult = connect(textArea, SIGNAL(textChanging(const QString &)), this,
            SLOT(onTextChanging(const QString &)));
    Q_ASSERT(connectResult);

    // A single line input field with a clear functionality
    TextField *textField = new TextField();
    textField->setHintText("Enter text into a single line TextField");
    textField->setHorizontalAlignment(HorizontalAlignment::Fill);
    textField->setBottomMargin(50.0);

    // Connect the TextField textChanging signal to the onTextChanging function to update the text.
    connectResult = connect(textField, SIGNAL(textChanging(const QString &)), this,
            SLOT(onTextChanging(const QString &)));
    Q_ASSERT(connectResult);

    // A disabled text field
    TextField *disabledTextField = new TextField();
    disabledTextField->setHintText("This is a disabled text field");
    disabledTextField->setEnabled(false);
    disabledTextField->setHorizontalAlignment(HorizontalAlignment::Fill);
    disabledTextField->setBottomMargin(50.0);

    // Add the controls to the recipe Container and ScrollView and set it as the CustomControl root.
    scrollView->setContent(recipeContainer);
    recipeContainer->add(mInputLabel);
    recipeContainer->add(textField);
    recipeContainer->add(disabledTextField);
    recipeContainer->add(textArea);

    //recipeContainer->add(inputContainer);
    setRoot(scrollView);
}