CustomDialogAlarm::CustomDialogAlarm(QObject * parent) :
        QObject(parent), mVisible(false)
{
    bool connectResult;
    Q_UNUSED(connectResult);

    mCustomDialog = new Dialog();

    Container *contentContainer = new Container();
    contentContainer->setLayout(new DockLayout());

    // The dialog Container does not automatically fill the entire screen like a Page does, so in order
    // for it to be possible to center the dialog on screen, the width and height must be set.
    contentContainer->setPreferredSize(768, 1280);

    // The background is set to semi-transparent to indicate that it is not possible to interact
    // with the screen behind the dialog.
    contentContainer->setBackground(Color::fromARGB(0x88000000));

    // Dialog Container
    Container *dialogContainer = new Container();
    dialogContainer->setLayout(new DockLayout());
    dialogContainer->setHorizontalAlignment(HorizontalAlignment::Center);
    dialogContainer->setVerticalAlignment(VerticalAlignment::Center);
    dialogContainer->setMaxHeight(397);

    // Dialog background image
    ImageView *dialogBack = ImageView::create(
            "asset:///images/customdialog/customdialog_alarm.png");

    // Dialog content Container
    Container *dialogContent = Container::create().top(5).bottom(23).left(23);
    dialogContent->setHorizontalAlignment(HorizontalAlignment::Fill);
    dialogContent->setVerticalAlignment(VerticalAlignment::Fill);

    // Title label for dialog
    Label *dialogTitle = new Label();
    dialogTitle->setText("FIRE ALARM!");
    dialogTitle->textStyle()->setBase(SystemDefaults::TextStyles::titleText());
    dialogTitle->textStyle()->setColor(Color::fromARGB(0xfffafafa));
    dialogTitle->setLayoutProperties(StackLayoutProperties::create().spaceQuota(1));
    dialogTitle->setHorizontalAlignment(HorizontalAlignment::Center);

    // Text label for dialog
    Label *dialogText = new Label();
    dialogText->setText("BEEP! BEEP! BEEP!");
    dialogText->textStyle()->setBase(SystemDefaults::TextStyles::titleText());
    dialogText->setLayoutProperties(StackLayoutProperties::create().spaceQuota(2.5));

    // Toggle button for alarm
    ToggleButton *toggleAlarm = new ToggleButton();
    toggleAlarm->setLayoutProperties(StackLayoutProperties::create().spaceQuota(1));
    toggleAlarm->setHorizontalAlignment(HorizontalAlignment::Center);

    // Connect to signals
    connectResult = connect(toggleAlarm, SIGNAL(checkedChanged(bool)), this, SLOT(onAlarmSwitch(bool)));
    Q_ASSERT(connectResult);

    connectResult = connect(this, SIGNAL(visibleChanged(bool)), toggleAlarm, SLOT(setChecked(bool)));
    Q_ASSERT(connectResult);

    // Add components to the appropriate Containers
    dialogContent->add(dialogTitle);
    dialogContent->add(dialogText);
    dialogContent->add(toggleAlarm);

    dialogContainer->add(dialogBack);
    dialogContainer->add(dialogContent);
    contentContainer->add(dialogContainer);

    mCustomDialog->setContent(contentContainer);
}
Container *AnimationRecipe::setUpControllerContainer()
{
    // The Controller Container is the bottom part of the animation recipe.
    // It is where the descriptive text and a toggle button for triggering the
    // animations is kept.
    Container *controllerContainer = new Container();
    DockLayout *controllerLayout = new DockLayout();
    controllerLayout->setLeftPadding(30.0f);
    controllerContainer->setLayout(controllerLayout);
    controllerContainer->setBackground(Color::fromRGBA(0.84f, 0.84f, 0.84f));
    controllerContainer->setPreferredSize(768.0f, 360.0f);
    controllerContainer->setLayoutProperties(
            DockLayoutProperties::create().vertical(VerticalAlignment::Bottom));

    // A recipe text.
    Container *descriptionContainer = new Container();
    StackLayout *descriptionLayout = new StackLayout();
    descriptionLayout->setTopPadding(42.0f);
    descriptionContainer->setLayout(descriptionLayout);
    descriptionContainer->setLayoutProperties(
            DockLayoutProperties::create().vertical(VerticalAlignment::Top).horizontal(
                    HorizontalAlignment::Left));

    // A Label is used for the header and a text area for the descriptive text.
    Label *descriptionHeader = new Label();
    descriptionHeader->textStyle()->setBase(SystemDefaults::TextStyles::bigText());
    descriptionHeader->textStyle()->setColor(Color::Black);
    descriptionHeader->setText("Scrambled eggs");
    descriptionHeader->setBottomMargin(32.0f);

    // Three labels for describing how to scramble the eggs.
    Label *line1 = new Label();
    line1->textStyle()->setBase(SystemDefaults::TextStyles::bodyText()); 
    line1->setText("1. Take two eggs.");
    line1->textStyle()->setColor(Color::Black);

    Label *line2 = new Label();
    line2->textStyle()->setBase(SystemDefaults::TextStyles::bodyText()); 
    line2->setText("2. Scramble them.");
    line2->textStyle()->setColor(Color::Black);

    Label *line3 = new Label();
    line3->textStyle()->setBase(SystemDefaults::TextStyles::bodyText()); 
    line3->setText("3. Done.");
    line3->textStyle()->setColor(Color::Black);

    // Add the texts to the description Container.
    descriptionContainer->add(descriptionHeader);
    descriptionContainer->add(line1);
    descriptionContainer->add(line2);
    descriptionContainer->add(line3);

    // The Controller is a toggle Button and it has a descriptive Label.
    // They are stacked in a Container that is aligned to the bottom right corner.
    Container *toggleContainer = new Container();
    StackLayout *toggleLayout = new StackLayout();
    toggleLayout->setBottomPadding(45.0f);
    toggleLayout->setRightPadding(30.0f);
    toggleContainer->setLayout(toggleLayout);
    toggleContainer->setLayoutProperties(
            DockLayoutProperties::create().vertical(VerticalAlignment::Bottom).horizontal(
                    HorizontalAlignment::Right));

    // Set up of a Label with a descriptive text.
    Label *actionLabel = new Label();
    actionLabel->setLayoutProperties(
            StackLayoutProperties::create().horizontal(HorizontalAlignment::Right));
    actionLabel->textStyle()->setBase(SystemDefaults::TextStyles::bodyText()); 
    actionLabel->setText("Super size");
    actionLabel->textStyle()->setColor(Color::Black);

    // Set up of a toggle Button and connect to its onChanged signal, its in
    // the slot function onToggleChanged were animations are triggered.
    ToggleButton *toggle = new ToggleButton();
    toggle->setLayoutProperties(
            StackLayoutProperties::create().horizontal(HorizontalAlignment::Right));
    connect(toggle, SIGNAL(checkedChanged(bool)), this, SLOT(onToggleChanged(bool)));

    // Add the Label and the toggle Button to the toggle Container then add
    // that Container to the main controller Container.
    toggleContainer->add(toggle);
    toggleContainer->add(actionLabel);

    // Add the description and the toggle button Container.
    controllerContainer->add(descriptionContainer);
    controllerContainer->add(toggleContainer);

    return controllerContainer;
}