/// <summary>
        /// Position choice boxes inside vertically oriented grid
        /// </summary>
        /// <param name="count">amount of child choice boxes</param>
        private void FitChoiceBoxesVertical(int count)
        {
            double questionWidth  = this.Width - 2 * BorderOffset - 2 * BorderThickness;
            double questionHeight = this.Height - 2 * BorderOffset - 2 * BorderThickness;

            double choiceBoxHeight = (questionHeight - (count - 1) * ItemsOffset) / count;
            double choiceBoxWidth  = questionWidth;

            // if can't fit bubbles by height, do not add any bubbles
            if (choiceBoxWidth < MinChoiceBoxSize)
            {
                return;
            }

            // if can't fit bubbles by width, reduce bubbles count and recalculate
            while (choiceBoxHeight < MinChoiceBoxSize)
            {
                count--;
                choiceBoxHeight = (questionHeight - (count - 1) * ItemsOffset) / count;
            }

            for (int i = 0; i < count; i++)
            {
                double topPosition   = BorderOffset + i * ItemsOffset + i * choiceBoxHeight;
                Rect   choiceBoxArea = new Rect(BorderOffset, topPosition, choiceBoxWidth, choiceBoxHeight);

                var choiceBox = new ChoiceBoxViewModel(string.Empty, choiceBoxArea, null, this);
                this.ChoiceBoxes.Add(choiceBox);
            }

            this.optionsCount = this.ChoiceBoxes[0].BubblesCount;
        }
Example #2
0
        /// <summary>
        /// Creates copy of current question
        /// </summary>
        /// <returns>Question copy</returns>
        public override BaseQuestionViewModel CreateCopy()
        {
            ChoiceBoxViewModel elementCopy = new ChoiceBoxViewModel(this.Name, this.Top, this.Left, this.Width, this.Height);

            elementCopy.SelectedMapping = this.SelectedMapping;

            foreach (BubbleViewModel bubble in this.Bubbles)
            {
                var bubbleCopy = new BubbleViewModel(bubble.Width, bubble.Height, bubble.Top, bubble.Left);
                bubbleCopy.Name = bubble.Name;
                elementCopy.bubbles.Add(bubbleCopy);
            }

            return(elementCopy);
        }
Example #3
0
        /// <summary>
        /// Applyes to current element style and properties of provided element
        /// </summary>
        /// <param name="ethalon">Ethalon element</param>
        public void ApplyStyle(ChoiceBoxViewModel ethalon)
        {
            // update size
            this.Width  = ethalon.Width;
            this.Height = ethalon.Height;

            this.SelectedMapping = ethalon.SelectedMapping;

            // update bubbles collection
            this.Bubbles.Clear();
            foreach (BubbleViewModel bubble in ethalon.Bubbles)
            {
                var newBubble = new BubbleViewModel(bubble.Width, bubble.Height, bubble.Top, bubble.Left);
                newBubble.Name = bubble.Name;
                this.Bubbles.Add(newBubble);
            }
        }
        /// <summary>
        /// Add new element via selection rectangle
        /// </summary>
        /// <param name="area">Element area</param>
        public void AddQuestion(Rect area)
        {
            string nextName = NamingManager.GetNextAvailableElementName(this.PageQuestions);

            BaseQuestionViewModel newQuestion;

            if (this.IsAddingChoiceBox)
            {
                newQuestion            = new ChoiceBoxViewModel(nextName, area);
                this.IsAddingChoiceBox = false;
            }
            else
            {
                newQuestion       = new GridViewModel(nextName, area);
                this.IsAddingGrid = false;
            }

            this.OnAddQuestion(newQuestion);
            newQuestion.IsSelected = true;

            ActionTracker.TrackAction(new AddElementsAction(new[] { newQuestion }, this.PageQuestions));
        }