Exemplo n.º 1
0
        public static void LoadVerses(List <SongVerse> listToLoad, int autoNumber, bool removeFormatting)
        {
            listToLoad.Clear();
            using (FBirdTask t = new FBirdTask())
            {
                t.CommandText =
                    "SELECT [AutoNumber], [IsChorus], [Verse], [OrderNum] " +
                    "FROM [SongVerses] " +
                    "WHERE [AutoNumber] = @AutoNumber " +
                    "ORDER BY [OrderNum]";
                t.Parameters.Add("@AutoNumber", FbDbType.Integer);
                t.Parameters["@AutoNumber"].Value = autoNumber;

                t.ExecuteReader();
                int verseNumber = 1;
                while (t.DR.Read())
                {
                    bool   isChorus  = t.GetInt32(1) == 1;
                    int    vnum      = isChorus ? -1 : verseNumber;
                    string verseData = t.GetString(2);
                    if (removeFormatting)
                    {
                        verseData = RemoveVerseFormatting(verseData);
                    }
                    SongVerse sv = new SongVerse(isChorus, verseData, vnum);
                    listToLoad.Add(sv);
                    if (!isChorus)
                    {
                        verseNumber++;
                    }
                }
            }
        }
Exemplo n.º 2
0
        private int PaintSong(Graphics g)
        {
            int w = this.Width;

            if (w > 350)
            {
                w = 350;
            }
            int cx          = (int)(((double)this.Width - w) / 2);
            int margin      = 5;
            int itemSpacing = 4;
            int cy          = margin;

            for (int i = 0; i < lSongVerses.Count; i++)
            {
                // Build the item to paint
                SongVerse sv = lSongVerses[i];
                string    s  = "";
                if (i == 0)
                {
                    s += songnum + ". ";
                }
                if (sv.IsChorus)
                {
                    s += Loc.Get("Chorus:") + " ";
                }
                else
                {
                    if (i != 0)
                    {
                        s += sv.VerseNumber + ". ";
                    }
                }
                s += sv.Text;

                // Measure string
                int h       = (int)g.MeasureString(s, this.Font, w).Height;
                int xadjust = 0;
                if (sv.IsChorus) // Chorus indent
                {
                    w      -= 15;
                    xadjust = 15;
                }
                Rectangle r = new Rectangle(cx + xadjust, cy, w, h);

                // Measure and fill highlights
                StringFormat sf = new StringFormat();
                sf.SetMeasurableCharacterRanges(SearchHelper.FindCharacterRanges(s, searchTerms));
                foreach (Region rg in g.MeasureCharacterRanges(s, this.Font, r, sf))
                {
                    g.FillRegion(new SolidBrush(Color.FromArgb(100, Color.Yellow)), rg);
                }


                g.DrawString(s, this.Font, Brushes.Black, r);
                cy += h + itemSpacing;
            }
            return(cy);
        }
Exemplo n.º 3
0
        // Graphic prep
        private void PrepareForDisplay()
        {
            // Clear
            int slideNumberBackup = currentSlideNum;

            songSlides.Clear();
            currentSlideNum = -1;

            // Build the slides for all verses
            SongVerse lastChorusFound = null;

            for (int i = 0; i < songVerses.Count; i++)
            {
                SongVerse sv            = songVerses[i];
                bool      isLast        = (i == (songVerses.Count - 1));           // check if this is the last verse
                bool      isNextAChorus = (!isLast && songVerses[i + 1].IsChorus); // check if next verse is a chorus
                lastChorusFound = sv.IsChorus ? sv : lastChorusFound;              // update the chorus if we hit a new one

                // Add the current verse
                InternalSplitVerse(sv, isLast, songVerses[i].VerseNumber);

                // Add the chorus
                if (lastChorusFound != null && !sv.IsChorus && !isNextAChorus)
                {
                    InternalSplitVerse(lastChorusFound, isLast, -1);
                }
            }

            // Set the last slide
            if (songSlides.Count > 0)
            {
                songSlides[songSlides.Count - 1].isLast = true;
            }

            // Reset the current slide number
            if (songSlides.Count > 0)
            {
                if (slideNumberBackup != -1)
                {
                    currentSlideNum = slideNumberBackup;
                }
                else
                {
                    currentSlideNum = 0;
                }
            }
        }
Exemplo n.º 4
0
        private void InternalSplitVerse(SongVerse sv, bool isLast, int verseNumber)
        {
            char[] trimChars = "\r\n ".ToCharArray();

            string tmp = sv.Text;

            if (sv.Text.IndexOf("<br/>") != -1 && !stripFormatting)
            {
                bool first = true;
                while (tmp.IndexOf("<br/>") != -1) // Verses with breaks are handled here
                {
                    // Create a slide from the verse part
                    string vPart = tmp.Substring(0, tmp.IndexOf("<br/>"));
                    tmp = tmp.Substring(tmp.IndexOf("<br/>") + 5);
                    string verseData = vPart.Trim(trimChars);

                    // Verse number support
                    if (includeVerseNumbers && first)
                    {
                        verseData = IncludeVerseNumber(sv, verseNumber, verseData);
                    }

                    // Add slide
                    songSlides.Add(new SongSlideData(songSlides.Count, sv.IsChorus, verseData, true, verseNumber));
                    first = false;
                }
                if (tmp.Length > 0)
                {
                    string verseData = tmp.Trim(trimChars);
                    songSlides.Add(new SongSlideData(songSlides.Count, sv.IsChorus, verseData, true, verseNumber));
                }
            }
            else
            {
                string verseData = sv.Text.Trim(trimChars);

                // Verse number support
                if (includeVerseNumbers)
                {
                    verseData = IncludeVerseNumber(sv, verseNumber, verseData);
                }

                songSlides.Add(new SongSlideData(songSlides.Count, sv.IsChorus, verseData, false, verseNumber));
            }
        }
Exemplo n.º 5
0
        private string IncludeVerseNumber(SongVerse sv, int verseNumber, string verseData)
        {
            string chorus = "Припев: ";

            if (sv.IsChorus)
            {
                verseData = chorus + verseData;
            }
            else if (verseNumber == 1)
            {
                verseData = currentSong.Number + ". " + verseData;
            }
            else
            {
                verseData = verseNumber + ". " + verseData;
            }
            return(verseData);
        }