private void iInvalidateSpeakers() { //TODO: remove try catch try { Transcription transc = _subtitlesData; // WaveformData currentWave = wave; if (transc == null) return; // if (currentWave == null) return; foreach (Button pL in speakerButtons) { wavegrid.Children.Remove(pL); } this.speakerButtons.Clear(); for (int i = 0; i < transc.Chapters.Count; i++) { TranscriptionChapter pChapter = transc.Chapters[i]; for (int j = 0; j < pChapter.Sections.Count; j++) { TranscriptionSection pSection = pChapter.Sections[j]; for (int k = 0; k < pSection.Paragraphs.Count; k++) { TranscriptionParagraph pParagraph = pSection.Paragraphs[k]; double pBegin = pParagraph.Begin.TotalMilliseconds; double pEnd = pParagraph.End.TotalMilliseconds; double wavebegin = WaveBegin.TotalMilliseconds; double waveend = WaveEnd.TotalMilliseconds; double wavelength = WaveLength.TotalMilliseconds; if (pEnd < pBegin) pEnd = pBegin; if (pBegin >= 0 && pEnd != pBegin && pEnd >= 0 && pParagraph.End >= TimeSpan.Zero) { if ((pParagraph.Begin < WaveBegin && pParagraph.End < WaveBegin) || (pParagraph.Begin > WaveEnd)) { } else { Button speaker = new Button(); speaker.PreviewMouseMove += new MouseEventHandler(pSpeaker_MouseMove); speaker.PreviewMouseLeftButtonUp += new MouseButtonEventHandler(pSpeaker_PreviewMouseLeftButtonUp); speaker.PreviewMouseLeftButtonDown += new MouseButtonEventHandler(pSpeaker_PreviewMouseLeftButtonDown); speaker.VerticalAlignment = VerticalAlignment.Top; speaker.HorizontalAlignment = HorizontalAlignment.Left; double aLeft = (double)(this.ActualWidth * (pBegin - wavebegin) / wavelength); double aRight = gridTimeline.ActualWidth - (double)(this.ActualWidth * (pEnd - wavebegin) / wavelength); speaker.Margin = new Thickness(aLeft, speaker.Margin.Top, speaker.Margin.Right, selectionRectangle.Margin.Bottom); speaker.Width = gridTimeline.ActualWidth - aLeft - aRight; speaker.Background = Properties.Settings.Default.WaveformSpeakerBackground; Speaker pSpeaker = pParagraph.Speaker; string pText = ""; if (pSpeaker != null) pText = pSpeaker.FullName; speaker.Visibility = Visibility.Visible; speaker.BringIntoView(); speaker.Focusable = false; speaker.IsTabStop = false; speaker.Cursor = Cursors.Arrow; if (pText != null && pText != "") speaker.ToolTip = speaker.Content; speaker.Tag = pParagraph; speaker.Click += new RoutedEventHandler(pSpeaker_Click); speaker.MouseDoubleClick += new MouseButtonEventHandler(pSepaker_MouseDoubleClick); DockPanel dp = new DockPanel() { LastChildFill = true, Margin = new Thickness(0, 0, 0, 0) }; dp.Height = 15; DockPanel dp2 = new DockPanel() { LastChildFill = true, Margin = new Thickness(0, 0, 0, 0) }; dp2.FlowDirection = System.Windows.FlowDirection.RightToLeft; dp2.Height = 15; if (k == 0) //prvni zaznam v sekci { Ellipse el = new Ellipse(); el.Width = 10; el.Height = 10; el.Margin = new Thickness(0, 0, 0, 0); el.Stroke = null; el.Fill = Properties.Settings.Default.WaveformBlockMarkColor; dp.Children.Add(el); } if ( (k == pSection.Paragraphs.Count - 2 && j == pChapter.Sections.Count - 1) || (k == pSection.Paragraphs.Count - 1 && j != pChapter.Sections.Count - 1) ) { Ellipse el = new Ellipse(); el.Width = 10; el.Height = 10; el.Margin = new Thickness(0, 0, 0, 0); el.Stroke = null; el.Fill = Brushes.DarkRed; dp2.Children.Add(el); } Label lab = new Label() { Content = pText, HorizontalAlignment = System.Windows.HorizontalAlignment.Center, Margin = new Thickness(0, 0, 0, 0) }; lab.Padding = new Thickness(0, 0, 0, 0); lab.Height = 15; dp2.Children.Add(lab); dp.Children.Add(dp2); speaker.Content = dp; speaker.SizeChanged += new SizeChangedEventHandler(pSpeaker_SizeChanged); //speaker.SetValue(Grid.RowProperty, 1); this.speakerButtons.Add(speaker); } } } } } //TODO: change speaker adding that int not require wavegrid.UpdateLayout(); TranscriptionParagraph previous = null; TranscriptionParagraph next = null; for (int i = 0; i < this.speakerButtons.Count; i++) { Button pSpeaker = this.speakerButtons[i]; Grid.SetRow(pSpeaker, 1); Grid.SetColumn(pSpeaker, 0); TranscriptionParagraph pPar = pSpeaker.Tag as TranscriptionParagraph; if (i < this.speakerButtons.Count - 1) { next = this.speakerButtons[i + 1].Tag as TranscriptionParagraph; } if (previous != null && previous.End > pPar.Begin && speakerButtons[i - 1].Margin.Top < 5) { wavegrid.Children.Add(pSpeaker); wavegrid.UpdateLayout(); pSpeaker.Margin = new Thickness(pSpeaker.Margin.Left, pSpeaker.ActualHeight, pSpeaker.Margin.Right, pSpeaker.Margin.Bottom); } else { wavegrid.Children.Add(pSpeaker); } previous = pPar; } } catch { } }