Преглед изворни кода

Replaced SiteDocumentView with ZoomPanel

Kenric Nugteren пре 2 недеља
родитељ
комит
bcefca788a

+ 4 - 1
PRS.Avalonia/PRS.Avalonia/HomePage/HomePageViewModel.cs

@@ -51,7 +51,10 @@ public partial class HomePageViewModel : ViewModelBase
         Modules.Add<ViewMobilePurchaseOrdersModule, PurchaseOrdersViewModel>("Orders", "", Images.shoppingcart, isVisible: false);
         Modules.Add<ViewMobileDocumentScannerModule, DocumentScannerViewModel>("Doc Scanner", "", Images.camera, isVisible: false);
         Modules.Add<ViewMobileSiteModule, SiteViewModel>("Site Module", "", Images.construction);
-        Modules.Add<ViewMobileMyTasksModule, MyTasksViewModel>("My Tasks", "", Images.task, isVisible: false);
+        Modules.Add<ViewMobileMyTasksModule, MyTasksViewModel>("My Tasks", "", Images.task, isVisible: false, configure: model =>
+        {
+            // model.Model = Repositories;
+        });
         Modules.Add<ViewMobileWarehousingModule, WarehouseModuleViewModel>("Warehouse", "", Images.warehouse, isVisible: true);
         Modules.Add("Update App", "", Images.version, UpdateApp, isVisible: false);
     }

+ 6 - 49
PRS.Avalonia/PRS.Avalonia/Modules/Site/SiteDocuments/SiteDocument/SiteDocumentView.axaml

@@ -3,56 +3,13 @@
              xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
              xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
              xmlns:siteDocumentViewer="clr-namespace:PRS.Avalonia.Modules"
+			 xmlns:components="using:InABox.Avalonia.Components"
              mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
              x:Class="PRS.Avalonia.Modules.SiteDocumentView"
              x:DataType="siteDocumentViewer:SiteDocumentViewModel">
-    <Grid>
-        <ScrollViewer
-            Name="_scroll"
-            Grid.Row="0"
-            Grid.Column="0"
-            HorizontalScrollBarVisibility="Auto" 
-            VerticalScrollBarVisibility="Auto"
-            PropertyChanged="OnPropertyChanged">
-            <Image  
-                Name="_image"
-                Stretch="UniformToFill"
-                Source="{Binding Bitmap, Converter={StaticResource ByteArrayToImageSourceConverter}}"
-                PropertyChanged="OnPropertyChanged">
-                <Image.GestureRecognizers>
-                    <PinchGestureRecognizer/>
-                </Image.GestureRecognizers>
-            </Image>
-        </ScrollViewer>
-        <StackPanel 
-            Grid.Row="0"
-            Grid.Column="0"
-            VerticalAlignment="Top"
-            HorizontalAlignment="Right"
-            Margin="0,10,10,0"
-            Orientation="Horizontal">
-            <Button 
-                Classes="Transparent"
-                Click="ZoomInClick">
-                <Image
-                    Classes="Large">
-                    <Image.Source>
-                        <SvgImage Source="/Images/plus.svg" />
-                    </Image.Source>
-                </Image>
-            </Button>
-            <Button 
-                Classes="Transparent"
-                Click="ZoomOutClick">
-                <Image
-                    Classes="Large">
-                    <Image.Source>
-                        <SvgImage Source="/Images/minus.svg" />
-                    </Image.Source>
-                </Image>
-            </Button>
-        </StackPanel>
-
-
-    </Grid>
+	<components:ZoomPanel>
+		<Image Name="_image"
+			   Stretch="UniformToFill"
+			   Source="{Binding Bitmap, Converter={StaticResource ByteArrayToImageSourceConverter}}"/>
+	</components:ZoomPanel>
 </UserControl>

+ 5 - 143
PRS.Avalonia/PRS.Avalonia/Modules/Site/SiteDocuments/SiteDocument/SiteDocumentView.axaml.cs

@@ -19,153 +19,15 @@ public partial class SiteDocumentView : UserControl
     public SiteDocumentView()
     {
         InitializeComponent();
-    }
 
-    // private Bitmap? _bitmap = null;
-    //
-    // protected override void OnDataContextChanged(EventArgs e)
-    // {
-    //     base.OnDataContextChanged(e);
-    //     if (DataContext is SiteDocumentViewModel viewModel)
-    //     {
-    //         viewModel.DataLoaded += (data) =>
-    //         {
-    //             var _bmpData = PlatformTools.PdfRenderer.RenderPdf(data,0,300);
-    //             using var ms = new MemoryStream(_bmpData);
-    //             _bitmap = new Bitmap(ms);
-    //             //CheckAndLoadPdf();
-    //         };
-    //     }
-    // }
-    //
-    protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
-    {
-        base.OnAttachedToVisualTree(e);                
-        _image.AddHandler(Gestures.PinchEvent, PinchHandler);
-        _image.AddHandler(Gestures.PinchEndedEvent, PinchEndedHandler);
-    }
-
-    private void OnPropertyChanged(object? sender, AvaloniaPropertyChangedEventArgs e)
-    {
-        if (e.Sender == _scroll && e.Property == BoundsProperty && e.NewValue is Rect rect)
+        _image.GetPropertyChangedObservable(Image.SourceProperty).Subscribe(x =>
         {
-            _minHeight = rect.Height;
-            _minWidth = rect.Width;
-        }
-        else if (e.Sender == _image && e.Property == Image.SourceProperty)
-        {
-
-            if (e.NewValue is Bitmap bitmap)
+            if (_image.Source is not null)
             {
-
-                var maxSize = ScaleToFit(_minWidth, _minHeight, bitmap.Size.Width, bitmap.Size.Height);
-
-                _maxHeight = maxSize.ScaledHeight;
-                _maxWidth = maxSize.ScaledWidth;
-
-                var initialsize = ScaleToFit(bitmap.Size.Width, bitmap.Size.Height, _minWidth, _minHeight);
-
-                _currentHeight = initialsize.ScaledHeight;
-                _currentWidth = initialsize.ScaledWidth;
-
-                ScaleImage(_scroll.Offset, 1.0, false);
-                
+                _image.Width = _image.Source.Size.Width;
+                _image.Height = _image.Source.Size.Height;
             }
-
-        }
-    }
-
-    private double _minHeight;
-    private double _minWidth;
-    
-    private double _currentHeight;
-    private double _currentWidth;
-    
-    private double _maxHeight;
-    private double _maxWidth;
-    
-    public (double ScaledWidth, double ScaledHeight) ScaleToFit(
-        double originalWidth, 
-        double originalHeight, 
-        double containerWidth, 
-        double containerHeight)
-    {
-        // Calculate the scale factors for width and height
-        double widthScale = containerWidth / originalWidth;
-        double heightScale = containerHeight / originalHeight;
-
-        // Use the smaller scale factor to maintain aspect ratio
-        double scale = Math.Min(widthScale, heightScale);
-
-        // Calculate the new dimensions
-        double scaledWidth = originalWidth * scale;
-        double scaledHeight = originalHeight * scale;
-
-        return (scaledWidth, scaledHeight);
-    }
-    
-    private void ScaleImage(Vector origin, double scale, bool reset)
-    {
-        var newHeight = _currentHeight * scale;
-        var newWidth = _currentWidth * scale;
-        
-        // var deltaHeight = newHeight - _currentHeight;
-        // var deltaWidth = newWidth - _currentWidth;
-        // var _offsetX = _scroll.Offset.X + (deltaWidth / 2.0);
-        // var _offsetY = _scroll.Offset.Y + (deltaHeight / 2.0);
-        _scroll.Offset = origin;
-
-        _image.Height = _currentHeight * scale;
-        _image.Width = _currentWidth * scale;
-        if (reset)
-        {
-            _currentHeight = _image.Height;
-            _currentWidth = _image.Width;        
-        }
-    }
-
-    // private void CheckAndLoadPdf()
-    // {
-    //     
-    //
-    // }
-    
-    // private void OnPropertyChanged(object? sender, AvaloniaPropertyChangedEventArgs e)
-    // {
-    //     if (e.Sender is ScrollViewer && e.Property == ScrollViewer.BoundsProperty)
-    //         CheckAndLoadPdf();
-    //
-    //     else if (e.Sender is Image && e.Property == Image.SourceProperty)
-    //     {
-    //         CheckAndLoadPdf();
-    //     }
-    //
-    // }
-    
-    private void PinchHandler(object? sender, PinchEventArgs e)
-    {
-        
-        ScaleImage(e.ScaleOrigin, e.Scale, false);
-        e.Handled = true;
-    }
-    
-    private void PinchEndedHandler(object? sender, PinchEndedEventArgs e)
-    {
-        _currentHeight = _image.Height;
-        _currentWidth = _image.Width;
-        e.Handled = true;
+        });
     }
-
-    private void ZoomInClick(object? sender, RoutedEventArgs e)
-    {
-        ScaleImage(_scroll.Offset, 1.25, true);
-    }
-
-    private void ZoomOutClick(object? sender, RoutedEventArgs e)
-    {
-        ScaleImage(_scroll.Offset, 0.80, true);
-    }
-
-
 }
 

+ 3 - 9
PRS.Avalonia/PRS.Avalonia/TestView.axaml

@@ -7,13 +7,7 @@
              mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
              x:Class="PRS.Avalonia.TestView"
 			 x:DataType="prs:TestViewModel">
-	<Grid>
-		<components:ImageEditor Name="Editor"
-								Source="{Binding Source}"
-								BorderBrush="Black"
-								BorderThickness="1"
-								CornerRadius="4"
-								IsVisible="{Binding IsEditing}"/>
-		<Image Name="Image" Source="{Binding Source}" IsVisible="{Binding !IsEditing}"/>
-	</Grid>
+	<components:ZoomPanel>
+		<Button Width="100" Height="100" Content="asdf"/>
+	</components:ZoomPanel>
 </UserControl>

+ 0 - 17
PRS.Avalonia/PRS.Avalonia/TestView.axaml.cs

@@ -13,21 +13,4 @@ public partial class TestView : UserControl
     {
         InitializeComponent();
     }
-
-    protected override void OnDataContextChanged(EventArgs e)
-    {
-        base.OnDataContextChanged(e);
-
-        if(DataContext is TestViewModel model)
-        {
-            model.GetBitmap = GetBitmap;
-        }
-    }
-
-    private Bitmap? GetBitmap()
-    {
-        var image = Editor.GetImage();
-        Editor.Reset();
-        return image;
-    }
 }

+ 0 - 20
PRS.Avalonia/PRS.Avalonia/TestViewModel.cs

@@ -16,27 +16,7 @@ public partial class TestViewModel : ModuleViewModel
 {
     public override string Title => "Test";
 
-    [ObservableProperty]
-    private IImage? _source = Images.cross;
-
-    [ObservableProperty]
-    private bool _isEditing = true;
-
-    [ObservableProperty]
-    private Func<Bitmap?>? _getBitmap;
-
     public TestViewModel()
     {
-        PrimaryMenu.Add(new(Images.tick, Toggle));
-    }
-
-    private Task<bool> Toggle()
-    {
-        if (IsEditing)
-        {
-            Source = GetBitmap?.Invoke();
-        }
-        IsEditing = !IsEditing;
-        return Task.FromResult(true);
     }
 }