Skip to content

Commit d4c09c4

Browse files
authored
Merge pull request #33 from TheJoeFin/dev
1.7 Dev, minimum size and FAQs
2 parents ef77609 + 771b0c3 commit d4c09c4

22 files changed

Lines changed: 853 additions & 351 deletions

Simple QR Code Maker.Core/Simple QR Code Maker.Core.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
</ItemGroup>
1212

1313
<ItemGroup>
14-
<PackageReference Include="System.Text.Json" Version="9.0.0" />
14+
<PackageReference Include="System.Text.Json" Version="9.0.3" />
1515
</ItemGroup>
1616
</Project>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<UserControl
3+
x:Class="Simple_QR_Code_Maker.Controls.FaqsContent"
4+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
5+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
6+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
7+
xmlns:local="using:Simple_QR_Code_Maker.Controls"
8+
xmlns:m="using:Simple_QR_Code_Maker.Models"
9+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
10+
mc:Ignorable="d">
11+
12+
<ScrollViewer>
13+
<StackPanel Padding="12,20,20,80" Orientation="Vertical">
14+
<TextBlock
15+
HorizontalAlignment="Center"
16+
Style="{StaticResource SubheaderTextBlockStyle}"
17+
Text="Frequently Asked Questions" />
18+
<AutoSuggestBox
19+
Margin="20,0"
20+
PlaceholderText="Search for content in the FAQs..."
21+
QueryIcon="Find"
22+
Text="{x:Bind ViewModel.SearchText,
23+
Mode=TwoWay}" />
24+
<ItemsRepeater Margin="20,0" ItemsSource="{x:Bind ViewModel.FaqItems, Mode=OneWay}">
25+
<ItemsRepeater.ItemTemplate>
26+
<DataTemplate x:DataType="m:FaqItem">
27+
<StackPanel Padding="6,12" Orientation="Vertical">
28+
<TextBlock
29+
IsTextSelectionEnabled="True"
30+
Style="{StaticResource SubtitleTextBlockStyle}"
31+
Text="{x:Bind Title,
32+
Mode=OneWay}"
33+
TextWrapping="WrapWholeWords" />
34+
<TextBlock
35+
IsTextSelectionEnabled="True"
36+
Text="{x:Bind Content,
37+
Mode=OneWay}"
38+
TextWrapping="WrapWholeWords" />
39+
</StackPanel>
40+
</DataTemplate>
41+
</ItemsRepeater.ItemTemplate>
42+
</ItemsRepeater>
43+
</StackPanel>
44+
</ScrollViewer>
45+
</UserControl>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using Microsoft.UI.Xaml.Controls;
2+
using Simple_QR_Code_Maker.ViewModels;
3+
4+
namespace Simple_QR_Code_Maker.Controls;
5+
6+
public sealed partial class FaqsContent : UserControl
7+
{
8+
public FaqsContentViewModel ViewModel { get; } = new FaqsContentViewModel();
9+
10+
public FaqsContent()
11+
{
12+
InitializeComponent();
13+
DataContext = ViewModel;
14+
}
15+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using Microsoft.UI.Xaml;
2+
using Microsoft.UI.Xaml.Controls;
3+
using Microsoft.UI.Xaml.Media;
4+
5+
namespace Simple_QR_Code_Maker.Controls;
6+
7+
public partial class HideIcon : FontIcon
8+
{
9+
public HideIcon()
10+
{
11+
this.FontFamily = (FontFamily)Application.Current.Resources["SymbolThemeFontFamily"];
12+
this.Glyph = "\uED1A";
13+
}
14+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using Microsoft.UI.Xaml;
2+
using Microsoft.UI.Xaml.Controls;
3+
using Microsoft.UI.Xaml.Media;
4+
5+
namespace Simple_QR_Code_Maker.Controls;
6+
7+
public partial class HistoryIcon : FontIcon
8+
{
9+
public HistoryIcon()
10+
{
11+
this.FontFamily = (FontFamily)Application.Current.Resources["SymbolThemeFontFamily"];
12+
this.Glyph = "\uE81C";
13+
}
14+
}
15+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using Microsoft.UI.Xaml;
2+
using Microsoft.UI.Xaml.Controls;
3+
using Microsoft.UI.Xaml.Media;
4+
5+
namespace Simple_QR_Code_Maker.Controls;
6+
7+
public partial class QrCodeIcon : FontIcon
8+
{
9+
public QrCodeIcon()
10+
{
11+
this.FontFamily = (FontFamily)Application.Current.Resources["SymbolThemeFontFamily"];
12+
this.Glyph = "\uED14";
13+
}
14+
}
15+

Simple QR Code Maker/Controls/QrCodeImageControl.xaml

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
Margin="4"
1313
HorizontalAlignment="Center"
1414
VerticalAlignment="Center">
15+
<Grid.RowDefinitions>
16+
<RowDefinition Height="*" />
17+
<RowDefinition Height="Auto" />
18+
</Grid.RowDefinitions>
1519
<Image
1620
x:Name="QrCodeImage"
1721
Width="285"
@@ -20,7 +24,7 @@
2024
DragStarting="QrCodeImage_DragStarting"
2125
Source="{x:Bind Data.CodeAsBitmap,
2226
Mode=OneWay}"
23-
ToolTipService.ToolTip="{x:Bind Data.CodeAsText,
27+
ToolTipService.ToolTip="{x:Bind Data.ToolTipText,
2428
Mode=OneWay}">
2529
<Image.ContextFlyout>
2630
<MenuFlyout>
@@ -59,5 +63,32 @@
5963
Message="QR Code not a URL"
6064
Severity="Warning"
6165
ToolTipService.ToolTip="This warning can be disabled in settings" />
66+
<StackPanel
67+
Grid.Row="1"
68+
Margin="0"
69+
Orientation="Horizontal"
70+
Spacing="4"
71+
Visibility="{x:Bind Data.SizeTextVisible,
72+
Mode=TwoWay}">
73+
<HyperlinkButton Command="{x:Bind Data.FaqButtonCommand, Mode=OneWay}" ToolTipService.ToolTip="How was this calculated?">
74+
<local:RulerIcon />
75+
</HyperlinkButton>
76+
<TextBlock VerticalAlignment="Center" Text="Minimum size: " />
77+
<TextBlock VerticalAlignment="Center" Text="{x:Bind Data.SmallestSide, Mode=OneWay}" />
78+
<StackPanel.ContextFlyout>
79+
<MenuFlyout>
80+
<MenuFlyoutItem
81+
Command="{x:Bind Data.CopySizeTextCommand,
82+
Mode=OneWay}"
83+
Icon="Copy"
84+
Text="Copy Size" />
85+
<MenuFlyoutItem Command="{x:Bind Data.HideSizeTextCommand, Mode=OneWay}" Text="Hide min. size text">
86+
<MenuFlyoutItem.Icon>
87+
<local:HideIcon />
88+
</MenuFlyoutItem.Icon>
89+
</MenuFlyoutItem>
90+
</MenuFlyout>
91+
</StackPanel.ContextFlyout>
92+
</StackPanel>
6293
</Grid>
6394
</UserControl>

Simple QR Code Maker/Controls/QrCodeImageControl.xaml.cs

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,12 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.IO;
4-
using System.Linq;
5-
using System.Runtime.InteropServices.WindowsRuntime;
6-
using Windows.Foundation;
7-
using Windows.Foundation.Collections;
1+
using CommunityToolkit.Mvvm.Messaging;
82
using Microsoft.UI.Xaml;
93
using Microsoft.UI.Xaml.Controls;
10-
using Microsoft.UI.Xaml.Controls.Primitives;
11-
using Microsoft.UI.Xaml.Data;
12-
using Microsoft.UI.Xaml.Input;
13-
using Microsoft.UI.Xaml.Media;
14-
using Microsoft.UI.Xaml.Navigation;
15-
using Simple_QR_Code_Maker.Models;
164
using Microsoft.UI.Xaml.Media.Imaging;
5+
using Simple_QR_Code_Maker.Extensions;
176
using Simple_QR_Code_Maker.Helpers;
7+
using Simple_QR_Code_Maker.Models;
188
using Windows.ApplicationModel.DataTransfer;
199
using Windows.Storage;
20-
using Simple_QR_Code_Maker.Extensions;
21-
using CommunityToolkit.Mvvm.Messaging;
22-
2310

2411
namespace Simple_QR_Code_Maker.Controls;
2512

@@ -34,7 +21,6 @@ public BarcodeImageItem Data
3421
public static readonly DependencyProperty DataProperty =
3522
DependencyProperty.Register("Data", typeof(BarcodeImageItem), typeof(QrCodeImageControl), new PropertyMetadata(null));
3623

37-
3824
public QrCodeImageControl()
3925
{
4026
InitializeComponent();
@@ -47,7 +33,7 @@ private async void QrCodeImage_DragStarting(UIElement sender, DragStartingEventA
4733

4834
DragOperationDeferral deferral = args.GetDeferral();
4935
StorageFolder folder = ApplicationData.Current.LocalCacheFolder;
50-
string? imageNameFileName = $"{ToolTipService.GetToolTip(image)}" ?? "QR_Code";
36+
string? imageNameFileName = $"{Data.CodeAsText}" ?? "QR_Code";
5137
// remove characters that are not allowed in file names
5238
imageNameFileName = imageNameFileName.ToSafeFileName();
5339
imageNameFileName += ".png";
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using Microsoft.UI.Xaml;
2+
using Microsoft.UI.Xaml.Controls;
3+
using Microsoft.UI.Xaml.Media;
4+
5+
namespace Simple_QR_Code_Maker.Controls;
6+
7+
public partial class RulerIcon : FontIcon
8+
{
9+
public RulerIcon()
10+
{
11+
this.FontFamily = (FontFamily)Application.Current.Resources["SymbolThemeFontFamily"];
12+
this.Glyph = "\uecc6";
13+
}
14+
}
15+

Simple QR Code Maker/Helpers/BarcodeHelpers.cs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Microsoft.UI.Xaml.Media.Imaging;
22
using System.Drawing;
33
using System.Drawing.Imaging;
4+
using System.Globalization;
45
using Windows.Storage;
56
using ZXing;
67
using ZXing.Common;
@@ -46,6 +47,57 @@ public static WriteableBitmap GetQrCodeBitmapFromText(string text, ErrorCorrecti
4647
return bitmapImage;
4748
}
4849

50+
/// <summary>
51+
/// Calculate the smallest side of a QR code based on the distance between the camera and the QR code
52+
/// </summary>
53+
/// <param name="distance">Distance of camera from QR Code (in)</param>
54+
/// <param name="numberOfBlocks">Number of blocks in the QR Code (Version)</param>
55+
/// <returns>The smallest size (in) of a QR Code scanning at the given distance</returns>
56+
public static double SmallestCodeSide(double distance, int numberOfBlocks)
57+
{
58+
// TODO when margin or padding can be set in settings
59+
// account for padding on both sides
60+
int padding = 2 * 2;
61+
62+
double blockSize = (distance + 2.721) / 1759.1;
63+
double codeSize = blockSize * (numberOfBlocks + padding);
64+
return codeSize;
65+
}
66+
67+
public static double ContrastRatioLossFrac(double constrastRatio)
68+
{
69+
double x1 = 21;
70+
double y1 = 1;
71+
double x2 = 2.5;
72+
double y2 = 0.8;
73+
74+
double slope = (y2 - y1) / (x2 - x1);
75+
double yIntercept = y1 - slope * x1;
76+
77+
return slope * constrastRatio + yIntercept;
78+
}
79+
80+
public static string SmallestSideWithUnits(double distance, int numberOfBlocks, Windows.UI.Color foreground, Windows.UI.Color background)
81+
{
82+
bool isMetric = RegionInfo.CurrentRegion.IsMetric;
83+
double smallestSide = SmallestCodeSide(distance, numberOfBlocks);
84+
85+
double contrastRatio = ColorHelpers.GetContrastRatio(foreground, background);
86+
87+
if (contrastRatio < 2.5)
88+
return "Color contrast too low";
89+
90+
double fractionalLoss = ContrastRatioLossFrac(contrastRatio);
91+
92+
smallestSide /= fractionalLoss;
93+
94+
if (!isMetric)
95+
return $"{smallestSide:F2} x {smallestSide:F2} in";
96+
97+
double smallestSideCm = smallestSide * 2.54;
98+
return $"{smallestSideCm:F2} x {smallestSideCm:F2} cm";
99+
}
100+
49101
public static SvgImage GetSvgQrCodeForText(string text, ErrorCorrectionLevel correctionLevel, System.Drawing.Color foreground, System.Drawing.Color background)
50102
{
51103
SvgRenderer svgRenderer = new()

0 commit comments

Comments
 (0)