Skip to content

Commit

Permalink
due to recent events, a calculator has been added to musecx
Browse files Browse the repository at this point in the history
  • Loading branch information
Liis17 committed Jun 12, 2024
1 parent 000bac7 commit 2fb3f0e
Show file tree
Hide file tree
Showing 4 changed files with 249 additions and 16 deletions.
50 changes: 34 additions & 16 deletions MusicX/Controls/PlayerControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
xmlns:converters="clr-namespace:MusicX.Converters"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:hc="https://handyorg.github.io/handycontrol"
xmlns:helpers="clr-namespace:MusicX.Helpers"
xmlns:local="clr-namespace:MusicX.Controls"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:player="clr-namespace:MusicX.Shared.Player;assembly=MusicX.Shared"
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
xmlns:wpfui="clr-namespace:Wpf.Ui.Controls;assembly=Wpf.Ui"
xmlns:helpers="clr-namespace:MusicX.Helpers"
x:Name="Control"
d:DataContext="{d:DesignInstance player:PlaylistTrack}"
d:Width="1500"
Loaded="UserControl_Loaded"
mc:Ignorable="d">
<UserControl.Resources>
Expand Down Expand Up @@ -331,14 +332,14 @@
</wpfui:Button>

<wpfui:Button
x:Name="DislikeButton"
Width="40"
Height="40"
Margin="5,0,0,0"
Padding="0"
Click="DislikeButton_Click"
HorizontalContentAlignment="Center"
Appearance="Transparent">
x:Name="DislikeButton"
Width="40"
Height="40"
Margin="5,0,0,0"
Padding="0"
HorizontalContentAlignment="Center"
Appearance="Transparent"
Click="DislikeButton_Click">

<ui:SymbolIcon x:Name="DislikeIcon" Symbol="ThumbDislike24" />

Expand All @@ -365,7 +366,7 @@
Grid.Column="1"
HorizontalAlignment="Center"
Orientation="Horizontal">

<ToggleButton
x:Name="ShuffleButton"
Width="40"
Expand Down Expand Up @@ -407,8 +408,8 @@
Padding="0"
HorizontalContentAlignment="Center"
Appearance="Transparent"
FontSize="20"
Click="PlayPauseButton_Click">
Click="PlayPauseButton_Click"
FontSize="20">

<wpfui:Button.Style>
<Style BasedOn="{StaticResource {x:Type wpfui:Button}}" TargetType="{x:Type wpfui:Button}">
Expand Down Expand Up @@ -496,7 +497,21 @@
HorizontalAlignment="Right"
VerticalAlignment="Center"
Orientation="Horizontal">
<wpfui:Button
x:Name="CalculatorButton"
Width="40"
Height="40"
Margin="0,0,20,0"
Padding="0"
HorizontalContentAlignment="Center"
Appearance="Transparent"
Click="CalculatorButton_Click">
<ui:SymbolIcon Symbol="Calculator16" />

<wpfui:Button.ToolTip>
<ToolTip Content="Открыть калькулятор" />
</wpfui:Button.ToolTip>
</wpfui:Button>
<wpfui:Button
x:Name="DownloadButton"
Width="40"
Expand Down Expand Up @@ -616,7 +631,10 @@
x:Name="QueueGrid"
Grid.Row="1"
Height="0">
<ui:ListView x:Name="Queue" Style="{StaticResource ItemsListViewStyle}" AllowDrop="True">
<ui:ListView
x:Name="Queue"
AllowDrop="True"
Style="{StaticResource ItemsListViewStyle}">
<ui:ListView.ItemTemplate>
<DataTemplate DataType="{x:Type player:PlaylistTrack}">
<Grid>
Expand Down Expand Up @@ -651,16 +669,16 @@
<hc:ScrollViewer
Name="PART_ScrollViewer"
Padding="{TemplateBinding Control.Padding}"
hc:ScrollViewerAttach.AutoHide="True"
CanContentScroll="{TemplateBinding ScrollViewer.CanContentScroll}"
Focusable="False"
IsInertiaEnabled="True"
hc:ScrollViewerAttach.AutoHide="True">
IsInertiaEnabled="True">
<ItemsPresenter />
</hc:ScrollViewer>
</ControlTemplate>
</ui:ListView.Template>
</ui:ListView>

<wpfui:ProgressRing
x:Name="QueueLoadingRing"
HorizontalAlignment="Center"
Expand Down
9 changes: 9 additions & 0 deletions MusicX/Controls/PlayerControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
using MusicX.Views.Modals;
using NLog;
using ProtoBuf.Meta;
using VkNet.Model.Attachments;

using Wpf.Ui;
using Wpf.Ui.Controls;
using Wpf.Ui.Extensions;
Expand Down Expand Up @@ -712,5 +714,12 @@ private async void DislikeButton_Click(object sender, RoutedEventArgs e)
snackbarService.ShowException("Мы не смогли указать, что Вам этот трек не нравится", ex);
}
}

private void CalculatorButton_Click(object sender, RoutedEventArgs e)
{
var navigationService = StaticService.Container.GetRequiredService<NavigationService>();

navigationService.OpenModal<CalculatorModal>();
}
}
}
152 changes: 152 additions & 0 deletions MusicX/Views/Modals/CalculatorModal.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
<Page
x:Class="MusicX.Views.Modals.CalculatorModal"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:MusicX.Views.Modals"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Title="CalculatorModal"
Width="700"
Height="550"
d:DesignHeight="450"
d:DesignWidth="800"
mc:Ignorable="d">

<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Top">
<TextBox
Name="txtExpression"
Height="50"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
VerticalContentAlignment="Center"
FontSize="24"
IsReadOnly="True"
Opacity="0.5"
Text="2+2"
TextAlignment="Left"
TextWrapping="Wrap" />
<TextBox
Name="txtResult"
Height="50"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
VerticalContentAlignment="Center"
Background="Transparent"
FontSize="24"
IsReadOnly="True"
Text="5"
TextAlignment="Right"
TextWrapping="Wrap" />
</Grid>
<Grid
Margin="0,53,0,0"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch">
<UniformGrid
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Columns="4"
Rows="4">
<Button
Margin="2"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Click="Number_Click"
Content="7" />
<Button
Margin="2"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Click="Number_Click"
Content="8" />
<Button
Margin="2"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Click="Number_Click"
Content="9" />
<Button
Margin="2"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Click="Operator_Click"
Content="/" />
<Button
Margin="2"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Click="Number_Click"
Content="4" />
<Button
Margin="2"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Click="Number_Click"
Content="5" />
<Button
Margin="2"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Click="Number_Click"
Content="6" />
<Button
Margin="2"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Click="Operator_Click"
Content="*" />
<Button
Margin="2"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Click="Number_Click"
Content="1" />
<Button
Margin="2"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Click="Number_Click"
Content="2" />
<Button
Margin="2"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Click="Number_Click"
Content="3" />
<Button
Margin="2"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Click="Operator_Click"
Content="-" />
<Button
Margin="2"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Click="Number_Click"
Content="0" />
<Button
Margin="2"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Click="Clear_Click"
Content="C" />
<Button
Margin="2"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Click="Equal_Click"
Content="=" />
<Button
Margin="2"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Click="Operator_Click"
Content="+" />
</UniformGrid>
</Grid>
</Grid>
</Grid>
</Page>
54 changes: 54 additions & 0 deletions MusicX/Views/Modals/CalculatorModal.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System;
using System.Data;
using System.Windows;
using System.Windows.Controls;

namespace MusicX.Views.Modals
{
public partial class CalculatorModal : Page
{
public CalculatorModal()
{
InitializeComponent();
Clear_Click(null, null);
}

private void Number_Click(object sender, RoutedEventArgs e)
{
var button = sender as System.Windows.Controls.Button;
if (button != null)
{
txtExpression.Text += button.Content.ToString();
}
}

private void Operator_Click(object sender, RoutedEventArgs e)
{
var button = sender as System.Windows.Controls.Button;
if (button != null)
{
txtExpression.Text += " " + button.Content.ToString() + " ";
}
}

private void Equal_Click(object sender, RoutedEventArgs e)
{
try
{
var expression = txtExpression.Text;
var result = new DataTable().Compute(expression, null);
txtResult.Text = result.ToString();
}
catch (Exception ex)
{
txtResult.Text = "Ошибка";
}
}

private void Clear_Click(object sender, RoutedEventArgs e)
{
txtExpression.Text = string.Empty;
txtResult.Text = string.Empty;
}
}
}

0 comments on commit 2fb3f0e

Please sign in to comment.