Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#9 Propojení GUI a knihovny #22

Merged
merged 11 commits into from
Apr 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Calculator/Calculator/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Calculator"
xmlns:mvvm="clr-namespace:Calculator.ViewModel"
xmlns:converters="clr-namespace:Calculator.ViewModel.Converters"
StartupUri="CalculatorWindow.xaml">
<Application.Resources>
<mvvm:MainViewModel x:Key="MainViewModel" />
<converters:DoubleToShortStringConverter x:Key="DoubleToShortStringConverter"/>
<converters:ValueLengthToFontSizeConverter x:Key="ValueLengthToFontSizeConverter" />
<converters:LongStringToShortStringConverter x:Key="LongStringToShortStringConverter" />
</Application.Resources>
</Application>
19 changes: 15 additions & 4 deletions src/Calculator/Calculator/Calculator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,17 @@
<DependentUpon>SpecialKey.xaml</DependentUpon>
</Compile>
<Compile Include="Model\Entities\HistoryItem.cs" />
<Compile Include="Model\Enums\FunctionKeysEnum.cs" />
<Compile Include="Model\Enums\SpecialKeysEnum.cs" />
<Compile Include="Model\Enums\Helpers\StringEnum.cs" />
<Compile Include="Model\Enums\OperationEnum.cs" />
<Compile Include="Model\Enums\FunctionEnum.cs" />
<Compile Include="Model\Enums\Helpers\StringValue.cs" />
<Compile Include="Model\MainModel.cs" />
<Compile Include="Model\Entities\MemoryItem.cs" />
<Compile Include="ViewModel\CommandsMainViewModel.cs" />
<Compile Include="ViewModel\Commands\RelayCommand.cs" />
<Compile Include="ViewModel\Converters\DoubleToShortStringConverter.cs" />
<Compile Include="ViewModel\Converters\LongStringToShortStringConverter.cs" />
<Compile Include="ViewModel\Converters\ValueLengthToFontSizeConverter.cs" />
<Compile Include="ViewModel\MainViewModel.cs" />
<Compile Include="ViewModel\PropertiesViewModel.cs" />
<Page Include="CalculatorWindow.xaml">
Expand Down Expand Up @@ -143,11 +150,15 @@
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Folder Include="ViewModel\Converters\" />
<Resource Include="Images\icon.ico" />
</ItemGroup>
<ItemGroup>
<Resource Include="Images\icon.ico" />
<ProjectReference Include="..\MathLib\MathLib.csproj">
<Project>{9a484f30-4e61-4f4e-ba54-026ab5a8445e}</Project>
<Name>MathLib</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
17 changes: 10 additions & 7 deletions src/Calculator/Calculator/CalculatorWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:controls="clr-namespace:Calculator.Controls"
xmlns:enums="clr-namespace:Calculator.Model.Enums"
DataContext="{StaticResource MainViewModel}"
mc:Ignorable="d"
MouseLeftButtonDown="WindowDragAndMove" Icon="Images/icon.ico"
Title="Calculator" Height="600" Width="350" WindowStyle="None" ResizeMode="NoResize">
<Grid>
<Grid Name="Background">
<Grid Name="CvsBackground">
<Canvas VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Opacity="1">
<Canvas.Background>
<LinearGradientBrush EndPoint="0.3,1" StartPoint="0.5,0">
Expand Down Expand Up @@ -47,7 +48,7 @@
</Grid>
</Grid>
<Window.InputBindings>
<KeyBinding Command="{Binding KeyPressCommand}" CommandParameter="." Key="Decimal"/>
<KeyBinding Command="{Binding KeyPressCommand}" CommandParameter="," Key="Decimal"/>
<KeyBinding Command="{Binding KeyPressCommand}" CommandParameter="0" Key="NumPad0"/>
<KeyBinding Command="{Binding KeyPressCommand}" CommandParameter="1" Key="NumPad1"/>
<KeyBinding Command="{Binding KeyPressCommand}" CommandParameter="2" Key="NumPad2"/>
Expand All @@ -58,10 +59,12 @@
<KeyBinding Command="{Binding KeyPressCommand}" CommandParameter="7" Key="NumPad7"/>
<KeyBinding Command="{Binding KeyPressCommand}" CommandParameter="8" Key="NumPad8"/>
<KeyBinding Command="{Binding KeyPressCommand}" CommandParameter="9" Key="NumPad9"/>
<KeyBinding Command="{Binding KeyPressCommand}" CommandParameter="/" Key="Divide"/>
<KeyBinding Command="{Binding KeyPressCommand}" CommandParameter="*" Key="Multiply"/>
<KeyBinding Command="{Binding KeyPressCommand}" CommandParameter="-" Key="Subtract"/>
<KeyBinding Command="{Binding KeyPressCommand}" CommandParameter="+" Key="Add"/>
<KeyBinding Command="{Binding KeyPressCommand}" CommandParameter="=" Key="Enter"/>
<KeyBinding Command="{Binding KeyPressCommand}" CommandParameter="{x:Static enums:OperationEnum.Divide}" Key="Divide"/>
<KeyBinding Command="{Binding KeyPressCommand}" CommandParameter="{x:Static enums:OperationEnum.Multiply}" Key="Multiply"/>
<KeyBinding Command="{Binding KeyPressCommand}" CommandParameter="{x:Static enums:OperationEnum.Minus}" Key="Subtract"/>
<KeyBinding Command="{Binding KeyPressCommand}" CommandParameter="{x:Static enums:OperationEnum.Plus}" Key="Add"/>
<KeyBinding Command="{Binding KeyPressCommand}" CommandParameter="{x:Static enums:FunctionEnum.Result}" Key="Enter"/>
<KeyBinding Command="{Binding KeyPressCommand}" CommandParameter="{x:Static enums:FunctionEnum.RemoveLastDigit}" Key="Back"/>
<KeyBinding Command="{Binding KeyPressCommand}" CommandParameter="{x:Static enums:FunctionEnum.Clear}" Key="Delete"/>
</Window.InputBindings>
</Window>
25 changes: 16 additions & 9 deletions src/Calculator/Calculator/Controls/Display.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,37 @@
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<ListView x:Name="MyHistoryView" Grid.Row="0" Grid.Column="0" Grid.RowSpan="2" VirtualizingStackPanel.IsVirtualizing="False" ItemsSource="{Binding HistoryItemsSource}" BorderThickness="0" Background="Transparent" >
<ListView x:Name="MyHistoryView" Grid.Row="0" Grid.Column="0" Grid.RowSpan="2" VirtualizingStackPanel.IsVirtualizing="False"
ItemsSource="{Binding HistoryItemsSource}" BorderThickness="0" Background="Transparent"
ScrollViewer.HorizontalScrollBarVisibility="Disabled" >
<ListView.InputBindings>
<MouseBinding MouseAction="LeftClick" Command="{Binding HistoryClickCommand}" CommandParameter="{Binding ElementName=MyHistoryView}"/>
</ListView.InputBindings>
<ListView.ItemTemplate>
<DataTemplate>
<DockPanel>
<TextBlock/>
<TextBlock Text="{Binding DisplayString}" Foreground="White" TextAlignment="Right" HorizontalAlignment="Right" FontSize="18" ToolTip="{Binding DisplayString}">
<TextBlock.InputBindings>
<MouseBinding MouseAction="LeftClick" Command="{Binding Source={StaticResource MainViewModel}, Path=HistoryClickCommand}" CommandParameter="{Binding}" />
</TextBlock.InputBindings>
</TextBlock>
</DockPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<TextBlock x:Name="TbConsole" Text="{Binding ConsoleText}" ToolTip="{Binding ConsoleText}" Grid.Row="2" Grid.Column="0" Grid.RowSpan="3" Foreground="White" FontSize="50" VerticalAlignment="Bottom" HorizontalAlignment="Right" Margin="15,0,0,0"/>
<TextBlock Text="{Binding SelectedOperation, Converter={StaticResource LongStringToShortStringConverter}}" Grid.Row="2" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Right" FontSize="30" Foreground="White" Opacity=".75" Margin="0,0,15,0"/>
<TextBlock x:Name="TbConsole" Text="{Binding ConsoleText, Converter={StaticResource DoubleToShortStringConverter}}" ToolTip="{Binding ConsoleText}" Grid.Row="2" Grid.Column="0" Grid.RowSpan="3" Foreground="White" FontSize="{Binding ConsoleText, Converter={StaticResource ValueLengthToFontSizeConverter}}" VerticalAlignment="Center" HorizontalAlignment="Right" Margin="10,15,0,0"/>
<Border Grid.Row="1" Grid.Column="1" Grid.RowSpan="2" Padding="10" Background="Transparent" Focusable="True" FocusVisualStyle="{x:Null}">
<Border.InputBindings>
<MouseBinding MouseAction="LeftClick" Command="{Binding CopyClickCommand}" CommandParameter="{Binding ElementName=TbConsole}" />
<MouseBinding MouseAction="LeftDoubleClick" Command="{Binding CopyClickCommand}" CommandParameter="{Binding ElementName=TbConsole}" />
<KeyBinding Key="Enter" Command="{Binding CopyClickCommand}" CommandParameter="{Binding ElementName=TbConsole}"/>
<MouseBinding MouseAction="LeftClick" Command="{Binding ClearClickCommand}" CommandParameter="{Binding ElementName=TbConsole}" />
<MouseBinding MouseAction="LeftDoubleClick" Command="{Binding ClearClickCommand}" CommandParameter="{Binding ElementName=TbConsole}" />
<KeyBinding Key="Enter" Command="{Binding ClearClickCommand}" CommandParameter="{Binding ElementName=TbConsole}"/>
</Border.InputBindings>
<Border.Resources>
<Storyboard x:Key="Select" TargetName="CopyButton">
<Storyboard x:Key="Select" TargetName="ClearButton">
<DoubleAnimation Storyboard.TargetProperty="Opacity" From="1" To=".5" Duration="0:0:.05"/>
</Storyboard>
<Storyboard x:Key="UnSelect" TargetName="CopyButton">
<Storyboard x:Key="UnSelect" TargetName="ClearButton">
<DoubleAnimation Storyboard.TargetProperty="Opacity" From=".5" To="1" Duration="0:0:.2"/>
</Storyboard>
</Border.Resources>
Expand All @@ -59,7 +66,7 @@
<BeginStoryboard Storyboard="{StaticResource UnSelect}" />
</EventTrigger>
</Border.Triggers>
<Path x:Name="CopyButton" Stretch="Uniform" Fill="White">
<Path x:Name="ClearButton" Stretch="Uniform" Fill="White">
<Path.Data>
M451.717,99.715l-71.434-71.431C364.729,12.728,334,0,312,0H72C50,0,32,18,32,40v432c0,22,18,40,40,40h368
c22,0,40-18,40-40V168C480,146,467.271,115.271,451.717,99.715z M429.09,122.343c1.564,1.565,3.125,3.487,4.639,5.657H352V46.272
Expand Down
33 changes: 17 additions & 16 deletions src/Calculator/Calculator/Controls/Keyboard.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:uc="clr-namespace:Calculator.Controls.UserControls"
xmlns:enums="clr-namespace:Calculator.Model.Enums"
DataContext="{StaticResource MainViewModel}"
mc:Ignorable="d"
d:DesignHeight="439" d:DesignWidth="350">
Expand Down Expand Up @@ -48,10 +49,10 @@
<RowDefinition Height="*"/>
<RowDefinition Height="10"/>
</Grid.RowDefinitions>
<uc:SpecialKey KeyValue="ms" Grid.Row="0" />
<uc:FunctionKey Grid.Row="2" >
<uc:SpecialKey Tag="{x:Static enums:FunctionEnum.MemorySave}" KeyValue="ms" Grid.Row="0" />
<uc:FunctionKey Grid.Row="2" Tag="{x:Static enums:OperationEnum.Power}">
<uc:FunctionKey.KeyValue>
<Path Tag="Power" RenderTransformOrigin="0.5,0.5" Margin="17,20">
<Path RenderTransformOrigin="0.5,0.5" Margin="17,20">
<Path.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleY="-1"/>
Expand Down Expand Up @@ -112,10 +113,10 @@
<RowDefinition Height="*"/>
<RowDefinition Height="10"/>
</Grid.RowDefinitions>
<uc:SpecialKey KeyValue="m+" Grid.Row="0" />
<uc:FunctionKey Grid.Row="2" >
<uc:SpecialKey Tag="{x:Static enums:FunctionEnum.MemoryAddition}" KeyValue="m+" Grid.Row="0" />
<uc:FunctionKey Grid.Row="2" Tag="{x:Static enums:OperationEnum.Root}">
<uc:FunctionKey.KeyValue>
<Path Tag="Root" RenderTransformOrigin="0.5,0.5" Margin="17,20">
<Path RenderTransformOrigin="0.5,0.5" Margin="17,20">
<Path.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleY="-1"/>
Expand Down Expand Up @@ -159,7 +160,7 @@
<Label Content="2"/>
</uc:FunctionKey.KeyValue>
</uc:FunctionKey>
<uc:FunctionKey Grid.Row="10" >
<uc:FunctionKey Grid.Row="10" Tag="{x:Static enums:OperationEnum.Negation}">
<uc:FunctionKey.KeyValue>
<Label Content="+/-" FontSize="24"/>
</uc:FunctionKey.KeyValue>
Expand All @@ -180,8 +181,8 @@
<RowDefinition Height="*"/>
<RowDefinition Height="10"/>
</Grid.RowDefinitions>
<uc:SpecialKey KeyValue="m-" Grid.Row="0" />
<uc:FunctionKey Grid.Row="2" >
<uc:SpecialKey Tag="{x:Static enums:FunctionEnum.MemorySubstraction}" KeyValue="m-" Grid.Row="0" />
<uc:FunctionKey Grid.Row="2" Tag="{x:Static enums:OperationEnum.Factorial}" >
<uc:FunctionKey.KeyValue>
<Label Content="!"/>
</uc:FunctionKey.KeyValue>
Expand All @@ -203,7 +204,7 @@
</uc:FunctionKey>
<uc:FunctionKey Grid.Row="10" >
<uc:FunctionKey.KeyValue>
<Label Content="."/>
<Label Content=","/>
</uc:FunctionKey.KeyValue>
</uc:FunctionKey>
</Grid>
Expand All @@ -222,28 +223,28 @@
<RowDefinition Height="*"/>
<RowDefinition Height="10"/>
</Grid.RowDefinitions>
<uc:SpecialKey KeyValue="mr" Grid.Row="0" />
<uc:FunctionKey Grid.Row="2" >
<uc:SpecialKey Tag="{x:Static enums:FunctionEnum.MemoryRecall}" KeyValue="mr" Grid.Row="0" />
<uc:FunctionKey Grid.Row="2" Tag="{x:Static enums:OperationEnum.Divide}">
<uc:FunctionKey.KeyValue>
<Label Content="÷" FontSize="40" Margin="0,-10,0,0" />
</uc:FunctionKey.KeyValue>
</uc:FunctionKey>
<uc:FunctionKey Grid.Row="4" >
<uc:FunctionKey Grid.Row="4" Tag="{x:Static enums:OperationEnum.Multiply}">
<uc:FunctionKey.KeyValue>
<Label Content="×" FontSize="40" Margin="0,-10,0,0" />
</uc:FunctionKey.KeyValue>
</uc:FunctionKey>
<uc:FunctionKey Grid.Row="6" >
<uc:FunctionKey Grid.Row="6" Tag="{x:Static enums:OperationEnum.Minus}">
<uc:FunctionKey.KeyValue>
<Label Content="-"/>
</uc:FunctionKey.KeyValue>
</uc:FunctionKey>
<uc:FunctionKey Grid.Row="8" >
<uc:FunctionKey Grid.Row="8" Tag="{x:Static enums:OperationEnum.Plus}">
<uc:FunctionKey.KeyValue>
<Label Content="+"/>
</uc:FunctionKey.KeyValue>
</uc:FunctionKey>
<uc:FunctionKey Grid.Row="10" >
<uc:FunctionKey Grid.Row="10" Tag="{x:Static enums:FunctionEnum.Result}">
<uc:FunctionKey.KeyValue>
<Label Content="="/>
</uc:FunctionKey.KeyValue>
Expand Down
2 changes: 1 addition & 1 deletion src/Calculator/Calculator/Controls/TopToolbar.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
</Style.Triggers>
</Style>
</Grid.Resources>
<Canvas x:Name="Background" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Background="Black" Opacity="0.3"/>
<Canvas x:Name="CvsBackground" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Background="Black" Opacity="0.3"/>
<Label Content="Calculator" FontSize="16" FontWeight="DemiBold" Foreground="White" Margin="5,0"/>
<Border x:Name="CloseButton" HorizontalAlignment="Right" Width="35" Focusable="True" FocusVisualStyle="{x:Null}" Background="Transparent" Margin="5,0">
<Border.InputBindings>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<Grid VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<Ellipse x:Name="ButtonBackground" Fill="LightGray" Opacity="0" Stroke="White" StrokeThickness="2" Stretch="Fill"/>
<Ellipse Stroke="White" StrokeThickness="2" Stretch="Fill"/>
<ContentControl IsTabStop="False" Focusable="False" Margin="0" x:Name="FunctionName" Content="{Binding KeyValue, RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl}}" Tag="{Binding KeyValue, RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl}}"/>
<ContentControl IsTabStop="False" Focusable="False" Margin="0" x:Name="FunctionName" Content="{Binding KeyValue, RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl}}" Tag="{Binding Tag, RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl}}"/>
</Grid>
</Border>
</UserControl>
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
<Grid>
<Border x:Name="ButtonBackground" Background="LightGray" Opacity="0" Grid.Row="0" CornerRadius="8" Width="{Binding ElementName='KeyButton', Path='ActualWidth'}" />
<Border BorderBrush="White" BorderThickness="2" Grid.Row="0" CornerRadius="8" Width="{Binding ElementName='KeyButton', Path='ActualWidth'}"/>
<Label x:Name="FunctionName" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Foreground="White" FontSize="16" FontFamily="Segoe UI" Margin="0,-6,0,0" Content="{Binding KeyValue, RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl}}"/>
<Label x:Name="FunctionName" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Foreground="White" FontSize="16" FontFamily="Segoe UI" Margin="0,-6,0,0"
Content="{Binding KeyValue, RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl}}" Tag="{Binding Tag, RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl}}"/>
</Grid>
</Border>
</UserControl>
43 changes: 41 additions & 2 deletions src/Calculator/Calculator/Model/Entities/HistoryItem.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,46 @@
namespace Calculator.Model.Entities
using System.Globalization;
using Calculator.Model.Enums;
using Calculator.Model.Enums.Helpers;

namespace Calculator.Model.Entities
{
class HistoryItem
public class HistoryItem
{
public double FirstOperand { get; set; }
public double? SecondOperand { get; set; }
public OperationEnum Function { get; set; }
public double Result { get; set; }

public HistoryItem(double firstOperand, OperationEnum function, double result)
{
this.FirstOperand = firstOperand;
this.Function = function;
this.Result = result;
}

public HistoryItem(double firstOperand, double secondOperand, OperationEnum function, double result)
{
this.FirstOperand = firstOperand;
this.SecondOperand = secondOperand;
this.Function = function;
this.Result = result;
}

public string DisplayString
{
get
{
if (this.SecondOperand.HasValue)
{
if ($"{this.FirstOperand} {StringEnum.GetStringValue(this.Function)} {this.SecondOperand.Value} = {this.Result}".Length > 25)
{
return this.Result.ToString();
}
return $"{this.FirstOperand} {StringEnum.GetStringValue(this.Function)} {this.SecondOperand.Value} = {this.Result}";
}

return $"{this.FirstOperand}{StringEnum.GetStringValue(this.Function)} = {this.Result}";
}
}
}
}
Loading