Пример #1
0
        private void LayoutRoot_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
        {
            base.OnPreviewMouseWheel(e);
            CircuitGridVM vm = DataContext as CircuitGridVM;

            vm.LayoutRoot_PreviewMouseWheel(e);
        }
Пример #2
0
        private void GateButton_MouseDown(object sender, MouseButtonEventArgs e)
        {
            Control source = sender as Control;

            bool shiftPressed = false;

            if ((Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift)
            {
                shiftPressed = true;
            }

            if (HomeVM.SelectedAction == ActionName.Control && !shiftPressed)
            {
                Button button      = source as Button;
                Point  coordinates = button.TransformToVisual(drawing).Transform(new Point(0, 0));

                CircuitGridVM circuitVM = DataContext as CircuitGridVM;

                double diameter = 12;
                double centerX  = coordinates.X + 0.5 * CircuitGridVM.GateWidth;
                double centerY  = coordinates.Y + 0.5 * CircuitGridVM.QubitSize;

                Ellipse ctrlPoint = new Ellipse();
                ctrlPoint.Width  = diameter;
                ctrlPoint.Height = diameter;

                ctrlPoint.Fill            = black;
                ctrlPoint.Stroke          = black;
                ctrlPoint.StrokeThickness = 1;
                ctrlPoint.AllowDrop       = true;
                ctrlPoint.Drop           += ctrlPoint_Drop;

                drawing.Children.Add(ctrlPoint);
                Canvas.SetTop(ctrlPoint, centerY - 0.5 * diameter);
                Canvas.SetLeft(ctrlPoint, centerX - 0.5 * diameter);

                line    = new Line();
                line.X1 = line.X2 = centerX;
                line.Y1 = line.Y2 = centerY;

                line.Stroke          = black;
                line.StrokeThickness = 1;
                drawing.Children.Add(line);

                Action emptyDelegate = delegate { };
                drawing.Dispatcher.Invoke(emptyDelegate, DispatcherPriority.Render);
            }

            GateVM vm = source.DataContext as GateVM;
            Tuple <int, RegisterRefModel> data = new Tuple <int, RegisterRefModel>(vm.Column, vm.Row);

            DragDrop.DoDragDrop(source, data, DragDropEffects.All);
        }
Пример #3
0
        private void GateButton_Drop(object sender, DragEventArgs e)
        {
            Control target = sender as Control;
            Tuple <int, RegisterRefModel> data = e.Data.GetData(typeof(Tuple <int, RegisterRefModel>)) as Tuple <int, RegisterRefModel>;
            GateVM vm = target.DataContext as GateVM;

            vm.SetGate(data.Item1, data.Item2, e.KeyStates);

            line = null;
            drawing.Children.Clear();

            CircuitGridVM circuitVM = DataContext as CircuitGridVM;

            circuitVM.SelectedObject = vm;
        }
Пример #4
0
        private void GatesScroll_ScrollChanged(object sender, ScrollChangedEventArgs e)
        {
            if (e.VerticalChange != 0)
            {
                RegisterScroll.ScrollToVerticalOffset(e.VerticalOffset);
                GatesScroll.ScrollToVerticalOffset(RegisterScroll.VerticalOffset);
            }

            // if added step
            if (e.ExtentWidthChange > 0)
            {
                CircuitGridVM circuitVM   = DataContext as CircuitGridVM;
                int           addedColumn = circuitVM.LastStepAdded;
                if (addedColumn > 0)
                {
                    // if newly added step is not fully visible
                    double scrollNeeded = e.ExtentWidthChange * (addedColumn + 1) - GatesScroll.HorizontalOffset - GatesScroll.ViewportWidth;
                    if (scrollNeeded > 0)
                    {
                        GatesScroll.ScrollToHorizontalOffset(GatesScroll.HorizontalOffset + scrollNeeded);
                    }
                }
            }
        }